]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGPP/TPC/AliTPCPerformanceSummary.cxx
Compatibility with the Root trunk
[u/mrichter/AliRoot.git] / PWGPP / TPC / AliTPCPerformanceSummary.cxx
1 //------------------------------------------------------------------------------
2 // Implementation of AliTPCPerformanceSummary class. 
3 // It has only static member functions to extract some TPC Performance
4 // parameters and produce trend graphs.
5 // The function MakeReport is to be called for every run. It reads AliPerformanceTPC
6 // and AliPerformanceDEdx objects from file and produces a
7 // rootfile with the results stored in a TTree.
8 // The function MakeReport needs a list of these rootfiles as input
9 // and writes the output (tree and histograms) to another rootfile.
10 //
11 // by M.Knichel 15/10/2010
12 //------------------------------------------------------------------------------
13
14 #include <fstream>
15
16 #include "TSystem.h"
17 #include "TMath.h"
18 #include "TVectorD.h"
19 #include "TList.h"
20 #include "TFile.h"
21 #include "TGrid.h"
22 #include "TF1.h"
23 #include "TH1.h"
24 #include "TH2.h"
25 #include "TH3.h"
26 #include "TProfile.h"
27 #include "THnSparse.h"
28 #include "TTree.h"
29 #include "TChain.h"
30 #include "TGraph.h"
31 #include "TPad.h"
32 #include "TCanvas.h"
33
34 #include "AliGRPObject.h"
35 #include "AliTPCcalibDB.h"
36 #include "AliTPCcalibDButil.h"
37 #include "TTreeStream.h"
38 #include "AliPerformanceTPC.h"
39 #include "AliPerformanceDEdx.h"
40 #include "AliPerformanceDCA.h"
41 #include "AliPerformanceMatch.h"
42
43 #include "AliTPCPerformanceSummary.h"
44
45 using std::ifstream;
46
47 ClassImp(AliTPCPerformanceSummary)
48
49 Bool_t AliTPCPerformanceSummary::fgForceTHnSparse = kFALSE;
50
51
52 //_____________________________________________________________________________
53 void AliTPCPerformanceSummary::WriteToTTreeSRedirector(const AliPerformanceTPC* pTPC, const AliPerformanceDEdx* pTPCgain, const AliPerformanceMatch* pTPCMatch,const AliPerformanceMatch* pTPCPull, const AliPerformanceMatch* pConstrain, TTreeSRedirector* const pcstream, Int_t run)
54 {
55    // 
56     // Extracts performance parameters from pTPC and pTPCgain.
57     // Output is written to pcstream.
58     // The run number must be provided since it is not stored in 
59     // AliPerformanceTPC or AliPerformanceDEdx.
60     //
61     if (run <= 0 ) {
62         if (pTPCMatch) {run = pTPCMatch->GetRunNumber(); }
63         if (pTPCgain) {run = pTPCgain->GetRunNumber(); }
64         if (pTPC) { run = pTPC->GetRunNumber(); }
65     }
66     TObjString runType;
67
68     //AliTPCcalibDB     *calibDB=0;
69
70 //     AliTPCcalibDButil *dbutil =0;
71     Int_t startTimeGRP=0;
72     Int_t stopTimeGRP=0;   
73     Int_t time=0;
74     Int_t duration=0;
75
76     //Float_t currentL3 =0;
77     //Int_t polarityL3 = 0;
78     //Float_t bz = 0;
79
80     //calibDB = AliTPCcalibDB::Instance();
81
82 //     dbutil= new AliTPCcalibDButil;   
83         
84     //printf("Processing run %d ...\n",run);
85     //if (calibDB) { 
86     //AliTPCcalibDB::Instance()->SetRun(run); 
87
88 //     dbutil->UpdateFromCalibDB();
89 //     dbutil->SetReferenceRun(run);
90 //     dbutil->UpdateRefDataFromOCDB();     
91      
92     //if (calibDB->GetGRP(run)){
93     //startTimeGRP = AliTPCcalibDB::GetGRP(run)->GetTimeStart();
94     //stopTimeGRP  = AliTPCcalibDB::GetGRP(run)->GetTimeEnd();
95     //currentL3 = AliTPCcalibDB::GetL3Current(run);
96     //polarityL3 = AliTPCcalibDB::GetL3Polarity(run);
97     //bz = AliTPCcalibDB::GetBz(run);
98     
99     //}    
100     //runType = AliTPCcalibDB::GetRunType(run).Data();  
101     //}  
102   time = (startTimeGRP+stopTimeGRP)/2;
103   duration = (stopTimeGRP-startTimeGRP);
104     
105     if (!pcstream) return;
106     (*pcstream)<<"tpcQA"<<      
107       "run="<<run<<
108       "time="<<time<<
109       "startTimeGRP="<<startTimeGRP<<
110       "stopTimeGRP="<<stopTimeGRP<<
111       "duration="<<
112       "runType.="<<&runType;
113     if (pTPC) {
114         pTPC->GetTPCTrackHisto()->GetAxis(9)->SetRangeUser(0.5,1.5);
115         pTPC->GetTPCTrackHisto()->GetAxis(7)->SetRangeUser(0.25,10);
116         pTPC->GetTPCTrackHisto()->GetAxis(5)->SetRangeUser(-1,1);    
117         AnalyzeNCL(pTPC, pcstream);    
118         AnalyzeDrift(pTPC, pcstream);
119         AnalyzeDriftPos(pTPC, pcstream);
120         AnalyzeDriftNeg(pTPC, pcstream);    
121         AnalyzeDCARPhi(pTPC, pcstream);
122         AnalyzeDCARPhiPos(pTPC, pcstream);
123         AnalyzeDCARPhiNeg(pTPC, pcstream);
124         AnalyzeEvent(pTPC, pcstream);         
125
126         AnalyzePt(pTPC,pcstream);
127         AnalyzeChargeOverPt(pTPC,pcstream); 
128         AnalyzeQAPosNegDpT(pTPC,pcstream);
129         AnalyzeQADCAFitParameter(pTPC,pcstream);
130
131         pTPC->GetTPCTrackHisto()->GetAxis(9)->SetRangeUser(-10,10);
132         pTPC->GetTPCTrackHisto()->GetAxis(7)->SetRangeUser(0,100);
133         pTPC->GetTPCTrackHisto()->GetAxis(5)->SetRangeUser(-10,10); 
134     }
135     AnalyzeGain(pTPCgain, pcstream);
136     AnalyzeMatch(pTPCMatch, pcstream);
137     AnalyzePull(pTPCPull, pcstream);
138     AnalyzeConstrain(pConstrain, pcstream);
139    
140     (*pcstream)<<"tpcQA"<<"\n";
141 }
142
143 //_____________________________________________________________________________
144 void AliTPCPerformanceSummary::WriteToFile(const AliPerformanceTPC* pTPC, const AliPerformanceDEdx* pTPCgain, const AliPerformanceMatch* pMatch,  const AliPerformanceMatch* pPull, const AliPerformanceMatch* pConstrain, const Char_t* outfile, Int_t run)
145 {
146     //
147     // Extracts performance parameters from pTPC and pTPCgain.
148     // Output is written to a TTree saved in outfile.
149     // The run number must be provided since it is not stored in 
150     // AliPerformanceTPC or AliPerformanceDEdx.
151     //
152     // The function creates a TTreeSRedirector and calls the 
153     // function WriteToTTreeSRedirector.
154     //
155     
156     if (!outfile) return;
157     TTreeSRedirector* pcstream = 0;
158     pcstream = new TTreeSRedirector(outfile);
159     if (!pcstream) return;
160     WriteToTTreeSRedirector(pTPC, pTPCgain, pMatch, pPull, pConstrain, pcstream, run);
161     if (pcstream) { delete pcstream; pcstream = 0; }    
162     
163 }
164
165 //_____________________________________________________________________________
166 Int_t AliTPCPerformanceSummary::MakeReport(const Char_t* infile, const Char_t* outfile, Int_t run)
167 {
168     //
169     // Reads QA information (AliPerformanceTPC and AliPerformanceDEdx) from
170     // infile (this must be a rootfile) and writes the output to a TTree
171     // stored in outfile.
172     // The run number must be provided since it is not stored in 
173     // AliPerformanceTPC or AliPerformanceDEdx.
174     // 
175     // The input objects must be named "AliPerformanceTPC" and 
176     // "AliPerformanceDEdxTPCInner" and stored in a TList which name must
177     // be one of the following: "TPC", "TPCQA", "TPC_PerformanceQA"
178     // or "TPC_PerformanceQA/TPC" (with directory)
179     //
180     
181     if (!infile) return -1;
182     if (!outfile) return -1;
183     TFile *f =0;
184     f=TFile::Open(infile,"read");
185     if (!f) {
186         printf("File %s not available\n", infile);
187         return -1;
188     } 
189     TList* list = 0;
190     list = dynamic_cast<TList*>(f->Get("TPC")); 
191     if (!list) { list = dynamic_cast<TList*>(f->Get("TPCQA")); }
192     if (!list) { list = dynamic_cast<TList*>(f->Get("TPC_PerformanceQA/TPCQA")); }
193     if (!list) { list = dynamic_cast<TList*>(f->Get("TPC_PerformanceQA")); }
194     if (!list) { list = dynamic_cast<TList*>(f->Get("ITSTPCMatch")); }
195     if (!list) {
196             printf("QA %s not available\n", infile);
197             return -1;
198     } 
199     AliPerformanceTPC* pTPC = 0;
200     AliPerformanceDEdx* pTPCgain = 0; 
201     AliPerformanceMatch* pTPCmatch = 0; 
202     AliPerformanceMatch* pTPCPull = 0; 
203     AliPerformanceMatch* pConstrain = 0;
204     
205     if (list) {  pTPC = dynamic_cast<AliPerformanceTPC*>(list->FindObject("AliPerformanceTPC")); }
206     if (list) {  pTPCgain = dynamic_cast<AliPerformanceDEdx*>(list->FindObject("AliPerformanceDEdxTPCInner")); }
207     if (list) {  pTPCmatch = dynamic_cast<AliPerformanceMatch*>(list->FindObject("AliPerformanceMatchTPCITS")); }
208     if (list) {  pTPCPull = dynamic_cast<AliPerformanceMatch*>(list->FindObject("AliPerformanceMatchITSTPC")); }
209     if (list) {  pConstrain = dynamic_cast<AliPerformanceMatch*>(list->FindObject("AliPerformanceMatchTPCConstrain")); }
210     
211     Int_t returncode = 0;
212     WriteToFile(pTPC, pTPCgain, pTPCmatch , pTPCPull, pConstrain, outfile, run);
213     if (f) { delete f; f=0; }
214     return returncode;
215 }
216
217 //_____________________________________________________________________________
218 Int_t AliTPCPerformanceSummary::ProduceTrends(const Char_t* infilelist, const Char_t* outfile)
219 {
220     //
221     // Produces trend graphs.
222     //
223     // Input: infilelist is a textfile with one rootfile per line.
224     // There should be one rootfile for each run, the rootfile must
225     // contain the output of the MakeReport function
226     // Output: the information for all runs is merged into a TTree
227     // that is saved in outfile along with the trend graphs.
228     // Trend graphs are stored as TCanvas objects to include axis labels etc.
229     //
230     
231     if (!infilelist) return -1;
232     if (!outfile) return -1;
233      
234     TChain* chain = new TChain("tpcQA");
235     if(!chain) return -1;
236
237     ifstream in;
238     in.open(infilelist);
239
240     TString currentFile;    
241     while(in.good()) {
242         in >> currentFile;
243
244         if (!currentFile.Contains("root")) continue; // protection            
245         chain->Add(currentFile.Data());
246     }
247     in.close();
248     //TTree *tree = chain;
249     TTree *tree = chain->CopyTree("1");
250     if(!tree) return -1;
251     if (chain) { delete chain; chain=0; }
252     //TGraph* graph = dynamic_cast<TGraph*>(tree->DrawClone("run:run"));
253     //TGraph *graph = (TGraph*)gPad->GetPrimitive("Graph");
254     
255     TFile* out = new TFile(outfile,"RECREATE");
256     if(!out) return -1;
257
258     out->cd();
259     const Char_t* condition = "meanTPCncl>0";
260     SaveGraph(tree,"meanTPCnclF","run",condition);
261     SaveGraph(tree,"rmsTPCnclF","run",condition);
262     SaveGraph(tree,"meanTPCChi2","run",condition);
263     SaveGraph(tree,"rmsTPCChi2","run",condition);
264     SaveGraph(tree,"slopeATPCnclF","run",condition);
265     SaveGraph(tree,"slopeCTPCnclF","run",condition);
266     SaveGraph(tree,"slopeATPCnclFErr","run",condition);
267     SaveGraph(tree,"slopeCTPCnclFErr","run",condition);
268     SaveGraph(tree,"meanTPCncl","run",condition);
269     SaveGraph(tree,"rmsTPCncl","run",condition);
270     SaveGraph(tree,"slopeATPCncl","run",condition);
271     SaveGraph(tree,"slopeCTPCncl","run",condition);
272     SaveGraph(tree,"slopeATPCnclErr","run",condition);
273     SaveGraph(tree,"slopeCTPCnclErr","run",condition);
274     
275     SaveGraph(tree,"offsetdRA","run",condition);
276     SaveGraph(tree,"slopedRA","run",condition);
277     SaveGraph(tree,"offsetdRC","run",condition);
278     SaveGraph(tree,"slopedRC","run",condition);
279     SaveGraph(tree,"offsetdRAErr","run",condition);
280     SaveGraph(tree,"slopedRAErr","run",condition);    
281     SaveGraph(tree,"offsetdRCErr","run",condition);
282     SaveGraph(tree,"slopedRCErr","run",condition);
283     SaveGraph(tree,"offsetdRAchi2","run",condition);
284     SaveGraph(tree,"slopedRAchi2","run",condition);
285     SaveGraph(tree,"offsetdRCchi2","run",condition);    
286     SaveGraph(tree,"slopedRCchi2","run",condition);    
287     
288     SaveGraph(tree,"offsetdRAPos","run",condition);
289       
290     SaveGraph(tree,"slopedRAPos","run",condition);
291     SaveGraph(tree,"offsetdRCPos","run",condition);
292     SaveGraph(tree,"slopedRCPos","run",condition);
293     SaveGraph(tree,"offsetdRAErrPos","run",condition);
294     SaveGraph(tree,"slopedRAErrPos","run",condition);
295     SaveGraph(tree,"offsetdRCErrPos","run",condition); 
296     SaveGraph(tree,"slopedRCErrPos","run",condition);
297     SaveGraph(tree,"offsetdRAchi2Pos","run",condition);
298     SaveGraph(tree,"slopedRAchi2Pos","run",condition);
299     SaveGraph(tree,"offsetdRCchi2Pos","run",condition);
300     SaveGraph(tree,"slopedRCchi2Pos","run",condition);
301         
302     SaveGraph(tree,"offsetdRANeg","run",condition);
303     SaveGraph(tree,"slopedRANeg","run",condition);
304     SaveGraph(tree,"offsetdRCNeg","run",condition);
305     SaveGraph(tree,"slopedRCNeg","run",condition);
306     SaveGraph(tree,"offsetdRAErrNeg","run",condition);
307     SaveGraph(tree,"slopedRAErrNeg","run",condition);
308     SaveGraph(tree,"offsetdRCErrNeg","run",condition);
309     SaveGraph(tree,"slopedRCErrNeg","run",condition);
310     SaveGraph(tree,"offsetdRAchi2Neg","run",condition);
311     SaveGraph(tree,"slopedRAchi2Neg","run",condition);
312     SaveGraph(tree,"offsetdRCchi2Neg","run",condition);
313     SaveGraph(tree,"slopedRCchi2Neg","run",condition);
314         
315     SaveGraph(tree,"offsetdZAPos","run",condition);
316     SaveGraph(tree,"slopedZAPos","run",condition);
317     SaveGraph(tree,"offsetdZCPos","run",condition);
318     SaveGraph(tree,"slopedZCPos","run",condition);
319     SaveGraph(tree,"offsetdZAErrPos","run",condition);
320     SaveGraph(tree,"slopedZAErrPos","run",condition);
321     SaveGraph(tree,"offsetdZCErrPos","run",condition);
322     SaveGraph(tree,"slopedZCErrPos","run",condition);
323     SaveGraph(tree,"offsetdZAchi2Pos","run",condition);
324     SaveGraph(tree,"slopedZAchi2Pos","run",condition);
325     SaveGraph(tree,"offsetdZCchi2Pos","run",condition);
326     SaveGraph(tree,"slopedZCchi2Pos","run",condition);
327     
328     SaveGraph(tree,"offsetdZANeg","run",condition);
329     SaveGraph(tree,"slopedZANeg","run",condition);
330     SaveGraph(tree,"offsetdZCNeg","run",condition);
331     SaveGraph(tree,"slopedZCNeg","run",condition);
332     SaveGraph(tree,"offsetdZAErrNeg","run",condition);
333     SaveGraph(tree,"slopedZAErrNeg","run",condition);
334     SaveGraph(tree,"offsetdZCErrNeg","run",condition);
335     SaveGraph(tree,"slopedZCErrNeg","run",condition);
336     SaveGraph(tree,"offsetdZAchi2Neg","run",condition);
337     SaveGraph(tree,"slopedZAchi2Neg","run",condition);
338     SaveGraph(tree,"offsetdZCchi2Neg","run",condition);
339     SaveGraph(tree,"slopedZCchi2Neg","run",condition);    
340     
341     SaveGraph(tree,"offsetdZA","run",condition);
342     SaveGraph(tree,"slopedZA","run",condition);
343     SaveGraph(tree,"offsetdZC","run",condition);
344     SaveGraph(tree,"slopedZC","run",condition);
345     SaveGraph(tree,"offsetdZAErr","run",condition);
346     SaveGraph(tree,"slopedZAErr","run",condition);
347     SaveGraph(tree,"offsetdZCErr","run",condition);
348     SaveGraph(tree,"slopedZCErr","run",condition);
349     SaveGraph(tree,"offsetdZAchi2","run",condition);
350     SaveGraph(tree,"slopedZAchi2","run",condition);
351     SaveGraph(tree,"offsetdZCchi2","run",condition);
352     SaveGraph(tree,"slopedZCchi2","run",condition);        
353
354     SaveGraph(tree,"meanVertX","run",condition);
355     SaveGraph(tree,"rmsVertX","run",condition);
356     SaveGraph(tree,"meanVertY","run",condition);
357     SaveGraph(tree,"rmsVertY","run",condition);
358     SaveGraph(tree,"meanVertZ","run",condition);
359     SaveGraph(tree,"rmsVertZ","run",condition);
360     SaveGraph(tree,"vertStatus","run",condition);
361     SaveGraph(tree,"meanMult","run",condition);
362     SaveGraph(tree,"rmsMult","run",condition);
363     SaveGraph(tree,"meanMultPos","run",condition);
364     SaveGraph(tree,"rmsMultPos","run",condition);
365     SaveGraph(tree,"meanMultNeg","run",condition);
366     SaveGraph(tree,"rmsMultNeg","run",condition);
367     SaveGraph(tree,"vertAll","run",condition);
368     SaveGraph(tree,"vertOK","run",condition);
369
370
371     SaveGraph(tree,"meanPtAPos","run",condition);
372     SaveGraph(tree,"mediumPtAPos","run",condition);
373     SaveGraph(tree,"highPtAPos","run",condition);
374     SaveGraph(tree,"meanPtCPos","run",condition);
375     SaveGraph(tree,"mediumPtCPos","run",condition);
376     SaveGraph(tree,"highPtCPos","run",condition);
377     SaveGraph(tree,"meanPtANeg","run",condition);
378     SaveGraph(tree,"mediumPtANeg","run",condition);
379     SaveGraph(tree,"highPtANeg","run",condition);
380     SaveGraph(tree,"meanPtCNeg","run",condition);
381     SaveGraph(tree,"mediumPtCNeg","run",condition);
382     SaveGraph(tree,"highPtCNeg","run",condition);
383  
384     SaveGraph(tree,"qOverPt","run",condition);
385     SaveGraph(tree,"qOverPtA","run",condition);
386     SaveGraph(tree,"qOverPtC","run",condition);
387
388     SaveGraph(tree,"dcarAP0","run",condition);
389     SaveGraph(tree,"dcarAP1","run",condition);
390     SaveGraph(tree,"dcarCP0","run",condition);
391     SaveGraph(tree,"dcarCP1","run",condition);
392
393     condition = "";
394     SaveGraph(tree,"tpcItsMatchA","run",condition);
395     SaveGraph(tree,"tpcItsMatchHighPtA","run",condition);
396     SaveGraph(tree,"tpcItsMatchC","run",condition);
397     SaveGraph(tree,"tpcItsMatchHighPtC","run",condition);
398     
399     SaveGraph(tree,"phiPull","run",condition);
400     SaveGraph(tree,"phiPullHighPt","run",condition);
401     SaveGraph(tree,"ptPull","run",condition);
402     SaveGraph(tree,"ptPullHighPt","run",condition);
403     SaveGraph(tree,"yPull","run",condition);
404     SaveGraph(tree,"yPullHighPt","run",condition);
405     SaveGraph(tree,"zPull","run",condition);
406     SaveGraph(tree,"zPullHighPt","run",condition);
407     SaveGraph(tree,"lambdaPull","run",condition);
408     SaveGraph(tree,"lambdaPullHighPt","run",condition);
409     
410     SaveGraph(tree,"tpcConstrainPhiA","run",condition);
411     SaveGraph(tree,"tpcConstrainPhiC","run",condition);
412      
413     SaveGraph(tree,"deltaPt","run",condition);
414     SaveGraph(tree,"deltaPtchi2","run",condition);
415     SaveGraph(tree,"deltaPtA","run",condition);
416     SaveGraph(tree,"deltaPtchi2A","run",condition);
417     SaveGraph(tree,"deltaPtC","run",condition);
418     SaveGraph(tree,"deltaPtchi2C","run",condition);
419     SaveGraph(tree,"deltaPtA_Err","run",condition);
420     SaveGraph(tree,"deltaPtA_Err","run",condition);
421     SaveGraph(tree,"deltaPtC_Err","run",condition);
422     
423     ////////////////////////////////////////////////////////////////////////////////////////////////////////
424  //save dca fit parameters
425     SaveGraph(tree,"dcar_posA_0","run",condition);
426     SaveGraph(tree,"dcar_posA_1","run",condition);
427     SaveGraph(tree,"dcar_posA_2","run",condition);
428     SaveGraph(tree,"dcar_posA_chi2","run",condition);
429     SaveGraph(tree,"dcar_posA_0_Err","run",condition);
430     SaveGraph(tree,"dcar_posA_1_Err","run",condition);
431     SaveGraph(tree,"dcar_posA_2_Err","run",condition);
432
433     SaveGraph(tree,"dcaz_posA_0","run",condition);
434     SaveGraph(tree,"dcaz_posA_1","run",condition);
435     SaveGraph(tree,"dcaz_posA_2","run",condition);
436     SaveGraph(tree,"dcaz_posA_chi2","run",condition);
437     SaveGraph(tree,"dcaz_posA_0_Err","run",condition);
438     SaveGraph(tree,"dcaz_posA_1_Err","run",condition);
439     SaveGraph(tree,"dcaz_posA_2_Err","run",condition);
440
441     SaveGraph(tree,"dcaz_posC_0","run",condition);
442     SaveGraph(tree,"dcaz_posC_1","run",condition);
443     SaveGraph(tree,"dcaz_posC_2","run",condition);
444     SaveGraph(tree,"dcaz_posC_chi2","run",condition);
445     SaveGraph(tree,"dcaz_posC_0_Err","run",condition);
446     SaveGraph(tree,"dcaz_posC_1_Err","run",condition);
447     SaveGraph(tree,"dcaz_posC_2_Err","run",condition);
448
449     SaveGraph(tree,"dcar_posC_0","run",condition);
450     SaveGraph(tree,"dcar_posC_1","run",condition);
451     SaveGraph(tree,"dcar_posC_2","run",condition);
452     SaveGraph(tree,"dcar_posC_chi2","run",condition);
453     SaveGraph(tree,"dcar_posC_0_Err","run",condition);
454     SaveGraph(tree,"dcar_posC_1_Err","run",condition);
455     SaveGraph(tree,"dcar_posC_2_Err","run",condition);
456
457     SaveGraph(tree,"dcar_negA_0","run",condition);
458     SaveGraph(tree,"dcar_negA_1","run",condition);
459     SaveGraph(tree,"dcar_negA_2","run",condition);
460     SaveGraph(tree,"dcar_negA_chi2","run",condition);
461     SaveGraph(tree,"dcar_negA_0_Err","run",condition);
462     SaveGraph(tree,"dcar_negA_1_Err","run",condition);
463     SaveGraph(tree,"dcar_negA_2_Err","run",condition);
464
465     SaveGraph(tree,"dcaz_negA_0","run",condition);
466     SaveGraph(tree,"dcaz_negA_1","run",condition);
467     SaveGraph(tree,"dcaz_negA_2","run",condition);
468     SaveGraph(tree,"dcaz_negA_chi2","run",condition);
469     SaveGraph(tree,"dcaz_negA_0_Err","run",condition);
470     SaveGraph(tree,"dcaz_negA_1_Err","run",condition);
471     SaveGraph(tree,"dcaz_negA_2_Err","run",condition);
472     
473     SaveGraph(tree,"dcaz_negC_0","run",condition);
474     SaveGraph(tree,"dcaz_negC_1","run",condition);
475     SaveGraph(tree,"dcaz_negC_2","run",condition);
476     SaveGraph(tree,"dcaz_negC_chi2","run",condition);
477     SaveGraph(tree,"dcaz_negC_0_Err","run",condition);
478     SaveGraph(tree,"dcaz_negC_1_Err","run",condition);
479     SaveGraph(tree,"dcaz_negC_2_Err","run",condition);
480     
481     SaveGraph(tree,"dcar_negC_0","run",condition);
482     SaveGraph(tree,"dcar_negC_1","run",condition);
483     SaveGraph(tree,"dcar_negC_2","run",condition);
484     SaveGraph(tree,"dcar_negC_chi2","run",condition);
485     SaveGraph(tree,"dcar_negC_0_Err","run",condition);
486     SaveGraph(tree,"dcar_negC_1_Err","run",condition);
487     SaveGraph(tree,"dcar_negC_2_Err","run",condition);
488     
489
490
491     ////////////////////////////////////////////////////////////////////////////////////////////////////////
492
493
494 tree->Write();
495     
496     out->Close();   
497     if (tree) { delete tree; tree=0; }
498     if (out) { delete out; out=0; }
499     return 0;
500 }
501
502 //_____________________________________________________________________________
503 Int_t AliTPCPerformanceSummary::SaveGraph(TTree* tree, const Char_t* y, const Char_t* x, const Char_t* condition)
504 {    
505     //
506     // Creates a Graph and writes the canvas to the current directory
507     // called by ProduceTrends function.
508     //
509     
510     TString s(y);
511     s += ':';
512     s += x;
513     tree->Draw(s.Data(),condition,"goff");
514     TCanvas* c = new TCanvas(s.Data(),s.Data());
515     c->cd();
516     TPad* p = new TPad("pad0","pad0",0,0,1,1);
517     p->Draw();
518     p->cd();
519     if (tree->GetSelectedRows() > 0) {
520       TGraph* graph = new TGraph(tree->GetSelectedRows(), tree->GetV2(), tree->GetV1());
521       graph->Draw("AP");
522       graph->GetXaxis()->SetTitle(x);
523       graph->GetYaxis()->SetTitle(y);
524       c->Write(s.Data());
525       delete graph;
526     }
527     //graph->Write(s.Data());
528     delete c;
529     
530 return 0;
531 }
532
533 //_____________________________________________________________________________
534 Int_t AliTPCPerformanceSummary::AnalyzeDCARPhi(const AliPerformanceTPC* pTPC, TTreeSRedirector* const pcstream)
535 {
536     //
537     // Analyse DCA R imperfections
538     //
539     
540     if (!pcstream) return 8;
541     if (!pTPC) return 8;
542         
543     // variables:
544     static Double_t offsetdRA=0;
545     static Double_t slopedRA=0;
546     static Double_t offsetdRC=0;
547     static Double_t slopedRC=0;
548     static Double_t offsetdRAErr=0;
549     static Double_t slopedRAErr=0;
550     static Double_t offsetdRCErr=0;
551     static Double_t slopedRCErr=0;
552     static Double_t offsetdRAchi2=0;
553     static Double_t slopedRAchi2=0;
554     static Double_t offsetdRCchi2=0;
555     static Double_t slopedRCchi2=0;
556     static Double_t dcarAP0 = 0;
557     static Double_t dcarAP1 = 0;
558     static Double_t dcarCP0 = 0;
559     static Double_t dcarCP1 = 0;
560
561     //AliPerformanceTPC* pTPC =  dynamic_cast<AliPerformanceTPC*>(pTPCObject);    
562     
563     TH1* his1D=0;
564     TH2* his2D=0;
565     TH3* his3D=0;
566     
567     if (pTPC->GetHistos()->FindObject("h_tpc_track_all_recvertex_3_5_7")) {    
568         his3D = dynamic_cast<TH3*>(pTPC->GetHistos()->FindObject("h_tpc_track_all_recvertex_3_5_7"));
569         if(!his3D) return 8;
570         his3D->GetYaxis()->SetRangeUser(-1,1);
571         his3D->GetZaxis()->SetRangeUser(0.25,10);
572     }
573     
574     static TF1 *fpol1 = new TF1("fpol1","pol1");
575     TObjArray arrayFit;
576     if (his3D && !fgForceTHnSparse) { 
577         his2D = dynamic_cast<TH2*>(his3D->Project3D("xy")); 
578     } else {    
579         his2D = pTPC->GetTPCTrackHisto()->Projection(3,5);
580     }            
581     if(!his2D) return 8;
582
583     
584     his2D->FitSlicesY(0,0,-1,10,"QNR",&arrayFit);
585     delete his2D;
586     his1D = (TH1*) arrayFit.At(1);
587     his1D->Fit(fpol1,"QNRROB=0.8","QNR",-0.8,-0.1);
588     offsetdRC=fpol1->GetParameter(0);
589     slopedRC=fpol1->GetParameter(1);
590     offsetdRCchi2=fpol1->GetChisquare();
591     slopedRCchi2=fpol1->GetChisquare();
592     //
593     his1D->Fit(fpol1,"QNRROB=0.8","QNR",0.1,0.8);
594     offsetdRA=fpol1->GetParameter(0);
595     slopedRA=fpol1->GetParameter(1);
596     offsetdRAErr=fpol1->GetParError(0);
597     slopedRAErr=fpol1->GetParError(1);
598     offsetdRAchi2=fpol1->GetChisquare();
599     slopedRAchi2=fpol1->GetChisquare();
600     //
601     printf("DCA R QA report\n");
602     printf("offsetdRA\t%f\n",offsetdRA);
603     printf("slopedRA\t%f\n",slopedRA);
604     printf("offsetdRC\t%f\n",offsetdRC);
605     printf("slopedRC\t%f\n",slopedRC);
606
607     //
608     //extraction of DCAr versus pt
609     //
610     TLinearFitter linearFit;
611     linearFit.SetFormula("pol1");
612     TObjArray arrayWidth;  
613     TH1 *width;
614     Int_t nXbins;
615     Double_t x,y;
616     Int_t pn = 1;
617
618     if(!his3D)
619       return 8;
620     his3D->GetYaxis()->SetRangeUser(-1,1);
621
622     //get his2D in A Side
623     his3D->GetYaxis()->SetRangeUser(0,1);
624     his3D->GetZaxis()->SetRangeUser(0.35,8);
625     his2D  = dynamic_cast<TH2*>(his3D->Project3D("xz"));
626     if (his2D)
627       his2D->FitSlicesY(0,0,-1,0,"QNR",&arrayWidth);
628
629     width =  dynamic_cast<TH1*>(arrayWidth.At(2));
630     if (width) 
631     {
632       nXbins = width->GetNbinsX();
633     for(Int_t i=2; i<nXbins; i++){
634       x = width->GetBinCenter(i);
635       if(x!=0)
636         x = 1.0/(x*x);
637       y = width->GetBinContent(i);
638       y = y*y;
639       linearFit.AddPoint(&x,y,1);
640     }
641     if(!linearFit.Eval()){
642       
643       dcarAP0 = linearFit.GetParameter(0);
644       if(dcarAP0!=0)
645         pn = Int_t(TMath::Abs(dcarAP0)/dcarAP0);
646       dcarAP0 = pn*TMath::Sqrt(TMath::Abs(dcarAP0));
647
648       dcarAP1 = linearFit.GetParameter(1);
649       if(dcarAP1!=0)
650         pn = Int_t(TMath::Abs(dcarAP1)/dcarAP1);
651       dcarAP1 = pn*TMath::Sqrt(TMath::Abs(dcarAP1));
652     }
653     }
654
655     linearFit.ClearPoints();
656     
657     //get his2D in C Side
658     his3D->GetYaxis()->SetRangeUser(-1,-0.001);
659     his2D  = dynamic_cast<TH2*>(his3D->Project3D("xz"));
660     if (his2D)
661       his2D->FitSlicesY(0,0,-1,0,"QNR",&arrayWidth);
662       width =  dynamic_cast<TH1*>(arrayWidth.At(2));
663     if (width) 
664     {
665       nXbins = width->GetNbinsX();
666     for(Int_t i=2; i<nXbins; i++){
667       x = width->GetBinCenter(i);
668       if(x!=0)
669         x = 1.0/(x*x);
670       y = width->GetBinContent(i);
671       y = y*y;
672       linearFit.AddPoint(&x,y);
673     }
674     if(!linearFit.Eval()){
675       dcarCP0 = linearFit.GetParameter(0);
676       if(dcarCP0!=0)
677         pn = Int_t(TMath::Abs(dcarCP0)/dcarCP0);
678       dcarCP0 = pn*TMath::Sqrt(TMath::Abs(dcarCP0));
679
680       dcarCP1 = linearFit.GetParameter(1);
681       if(dcarCP1!=0)
682         pn = Int_t(TMath::Abs(dcarCP1)/dcarCP1);
683       dcarCP1 = pn*TMath::Sqrt(TMath::Abs(dcarCP1));
684     }
685     }
686     his3D->GetYaxis()->SetRangeUser(-1,1);
687     his3D->GetZaxis()->SetRangeUser(0,20);
688
689     //
690     // dump values
691     //
692     (*pcstream)<<"tpcQA"<<
693         "offsetdRA="<< offsetdRA<<
694         "slopedRA="<< slopedRA<<
695         "offsetdRC="<< offsetdRC<<
696         "slopedRC="<<slopedRC<<
697         //
698         "offsetdRAErr="<< offsetdRAErr<<
699         "slopedRAErr="<< slopedRAErr<<
700         "offsetdRCErr="<< offsetdRCErr<<
701         "slopedRCErr="<<slopedRCErr<<
702         //
703         "offsetdRAchi2="<< offsetdRAchi2<<
704         "slopedRAchi2="<< slopedRAchi2<<
705         "offsetdRCchi2="<< offsetdRCchi2<<
706         "slopedRCchi2="<<slopedRCchi2<<
707         //
708         "dcarAP0="<<dcarAP0<<
709         "dcarAP1="<<dcarAP1<<
710         "dcarCP0="<<dcarCP0<<
711         "dcarCP1="<<dcarCP1;
712         
713     return 0;
714 }
715
716 //_____________________________________________________________________________
717 Int_t AliTPCPerformanceSummary::AnalyzeDCARPhiPos(const AliPerformanceTPC* pTPC, TTreeSRedirector* const pcstream)
718 {
719     //
720     // Analyse DCA R imperfections for positive particles
721     //
722     
723     if (!pcstream) return 16;
724     if (!pTPC) return 16;
725
726     // variables:
727     static Double_t offsetdRAPos=0;
728     static Double_t slopedRAPos=0;
729     static Double_t offsetdRCPos=0;
730     static Double_t slopedRCPos=0;
731     static Double_t offsetdRAErrPos=0;
732     static Double_t slopedRAErrPos=0;
733     static Double_t offsetdRCErrPos=0;
734     static Double_t slopedRCErrPos=0;
735     static Double_t offsetdRAchi2Pos=0;
736     static Double_t slopedRAchi2Pos=0;
737     static Double_t offsetdRCchi2Pos=0;
738     static Double_t slopedRCchi2Pos=0;
739
740     //AliPerformanceTPC* pTPC =  dynamic_cast<AliPerformanceTPC*>(pTPCObject);    
741     TH1* his1D=0;
742     TH2* his2D=0;
743     TH3* his3D=0;
744     
745     if (pTPC->GetHistos()->FindObject("h_tpc_track_pos_recvertex_3_5_7")) {    
746         his3D = dynamic_cast<TH3*>(pTPC->GetHistos()->FindObject("h_tpc_track_pos_recvertex_3_5_7"));
747         if(!his3D) return 16;
748         his3D->GetYaxis()->SetRangeUser(-1,1);
749         his3D->GetZaxis()->SetRangeUser(0.25,10);
750     }
751     
752     static TF1 *fpol1 = new TF1("fpol1","pol1");
753     TObjArray arrayFit;
754     if (his3D && !fgForceTHnSparse) { 
755         his2D = dynamic_cast<TH2*>(his3D->Project3D("xy")); 
756     } else {    
757         pTPC->GetTPCTrackHisto()->GetAxis(8)->SetRangeUser(0,1.5);        
758         his2D = pTPC->GetTPCTrackHisto()->Projection(3,5);
759         pTPC->GetTPCTrackHisto()->GetAxis(8)->SetRangeUser(-1.5,1.5);
760     }            
761     if(!his2D) return 16;
762     
763     his2D->FitSlicesY(0,0,-1,10,"QNR",&arrayFit);
764     delete his2D;    
765     his1D = (TH1*) arrayFit.At(1);
766     his1D->Fit(fpol1,"QNRROB=0.8","QNR",-0.8,-0.1);
767     offsetdRCPos=fpol1->GetParameter(0);
768     slopedRCPos=fpol1->GetParameter(1);
769     offsetdRCchi2Pos=fpol1->GetChisquare();
770     slopedRCchi2Pos=fpol1->GetChisquare();
771     //
772     his1D->Fit(fpol1,"QNRROB=0.8","QNR",0.1,0.8);
773     offsetdRAPos=fpol1->GetParameter(0);
774     slopedRAPos=fpol1->GetParameter(1);
775     offsetdRAErrPos=fpol1->GetParError(0);
776     slopedRAErrPos=fpol1->GetParError(1);
777     offsetdRAchi2Pos=fpol1->GetChisquare();
778     slopedRAchi2Pos=fpol1->GetChisquare();
779     //
780     printf("DCA R QA Pos report\n");
781     printf("offsetdRAPos\t%f\n",offsetdRAPos);
782     printf("slopedRAPos\t%f\n",slopedRAPos);
783     printf("offsetdRCPos\t%f\n",offsetdRCPos);
784     printf("slopedRCPos\t%f\n",slopedRCPos);
785     //
786     // dump values
787     //
788     (*pcstream)<<"tpcQA"<<
789         "offsetdRAPos="<< offsetdRAPos<<
790         "slopedRAPos="<< slopedRAPos<<
791         "offsetdRCPos="<< offsetdRCPos<<
792         "slopedRCPos="<<slopedRCPos<<
793         //
794         "offsetdRAErrPos="<< offsetdRAErrPos<<
795         "slopedRAErrPos="<< slopedRAErrPos<<
796         "offsetdRCErrPos="<< offsetdRCErrPos<<
797         "slopedRCErrPos="<<slopedRCErrPos<<
798         //
799         "offsetdRAchi2Pos="<< offsetdRAchi2Pos<<
800         "slopedRAchi2Pos="<< slopedRAchi2Pos<<
801         "offsetdRCchi2Pos="<< offsetdRCchi2Pos<<
802         "slopedRCchi2Pos="<<slopedRCchi2Pos;
803         
804     return 0;
805 }
806
807 //_____________________________________________________________________________
808 Int_t AliTPCPerformanceSummary::AnalyzeDCARPhiNeg(const AliPerformanceTPC* pTPC, TTreeSRedirector* const pcstream)
809 {
810     //
811     // Analyse DCA R imperfections for negative particles
812     //
813     if (!pcstream) return 32;
814     if (!pTPC) return 32;
815
816     // variables:
817     static Double_t offsetdRANeg=0;
818     static Double_t slopedRANeg=0;
819     static Double_t offsetdRCNeg=0;
820     static Double_t slopedRCNeg=0;
821     static Double_t offsetdRAErrNeg=0;
822     static Double_t slopedRAErrNeg=0;
823     static Double_t offsetdRCErrNeg=0;
824     static Double_t slopedRCErrNeg=0;
825     static Double_t offsetdRAchi2Neg=0;
826     static Double_t slopedRAchi2Neg=0;
827     static Double_t offsetdRCchi2Neg=0;
828     static Double_t slopedRCchi2Neg=0;
829
830     //AliPerformanceTPC* pTPC =  dynamic_cast<AliPerformanceTPC*>(pTPCObject);    
831     TH1* his1D=0;
832     TH2* his2D=0;
833     TH3* his3D=0;
834     
835     if (pTPC->GetHistos()->FindObject("h_tpc_track_neg_recvertex_3_5_7")) {    
836         his3D = dynamic_cast<TH3*>(pTPC->GetHistos()->FindObject("h_tpc_track_neg_recvertex_3_5_7"));
837         if(!his3D) return 32;
838         his3D->GetYaxis()->SetRangeUser(-1,1);
839         his3D->GetZaxis()->SetRangeUser(0.25,10);
840     }
841     
842     static TF1 *fpol1 = new TF1("fpol1","pol1");
843     TObjArray arrayFit;
844     if (his3D && !fgForceTHnSparse) {
845         his2D = dynamic_cast<TH2*>(his3D->Project3D("xy")); 
846     } else {    
847         pTPC->GetTPCTrackHisto()->GetAxis(8)->SetRangeUser(-1.5,0);        
848         his2D = pTPC->GetTPCTrackHisto()->Projection(3,5);
849         pTPC->GetTPCTrackHisto()->GetAxis(8)->SetRangeUser(-1.5,1.5);
850     }            
851     if(!his2D) return 32;
852
853     his2D->FitSlicesY(0,0,-1,10,"QNR",&arrayFit);
854     delete his2D;    
855     his1D = (TH1*) arrayFit.At(1);
856     his1D->Fit(fpol1,"QNRROB=0.8","QNR",-0.8,-0.1);
857     offsetdRCNeg=fpol1->GetParameter(0);
858     slopedRCNeg=fpol1->GetParameter(1);
859     offsetdRCchi2Neg=fpol1->GetChisquare();
860     slopedRCchi2Neg=fpol1->GetChisquare();
861     //
862     his1D->Fit(fpol1,"QNRROB=0.8","QNR",0.1,0.8);
863     offsetdRANeg=fpol1->GetParameter(0);
864     slopedRANeg=fpol1->GetParameter(1);
865     offsetdRAErrNeg=fpol1->GetParError(0);
866     slopedRAErrNeg=fpol1->GetParError(1);
867     offsetdRAchi2Neg=fpol1->GetChisquare();
868     slopedRAchi2Neg=fpol1->GetChisquare();
869     //
870     printf("DCA R QA Neg report\n");
871     printf("offsetdRANeg\t%f\n",offsetdRANeg);
872     printf("slopedRANeg\t%f\n",slopedRANeg);
873     printf("offsetdRCNeg\t%f\n",offsetdRCNeg);
874     printf("slopedRCNeg\t%f\n",slopedRCNeg);
875     //
876     // dump drift QA values
877     //
878     (*pcstream)<<"tpcQA"<<
879         "offsetdRANeg="<< offsetdRANeg<<
880         "slopedRANeg="<< slopedRANeg<<
881         "offsetdRCNeg="<< offsetdRCNeg<<
882         "slopedRCNeg="<<slopedRCNeg<<
883         //
884         "offsetdRAErrNeg="<< offsetdRAErrNeg<<
885         "slopedRAErrNeg="<< slopedRAErrNeg<<
886         "offsetdRCErrNeg="<< offsetdRCErrNeg<<
887         "slopedRCErrNeg="<<slopedRCErrNeg<<
888         //
889         "offsetdRAchi2Neg="<< offsetdRAchi2Neg<<
890         "slopedRAchi2Neg="<< slopedRAchi2Neg<<
891         "offsetdRCchi2Neg="<< offsetdRCchi2Neg<<
892         "slopedRCchi2Neg="<<slopedRCchi2Neg;
893         
894     return 0;
895 }
896
897 //_____________________________________________________________________________
898 Int_t AliTPCPerformanceSummary::AnalyzeNCL(const AliPerformanceTPC* pTPC, TTreeSRedirector* const pcstream)
899 {
900     //
901     // Analyse number of TPC clusters 
902     //
903     
904     if (!pcstream) return 1;
905     if (!pTPC) return 1;
906  
907     // variables:
908     static Double_t meanTPCnclF=0;
909     static Double_t rmsTPCnclF=0;
910     static Double_t meanTPCChi2=0;
911     static Double_t rmsTPCChi2=0;  
912     static Double_t slopeATPCnclF=0;
913     static Double_t slopeCTPCnclF=0;
914     static Double_t slopeATPCnclFErr=0;
915     static Double_t slopeCTPCnclFErr=0;
916     static Double_t meanTPCncl=0;
917     static Double_t rmsTPCncl=0;
918     static Double_t slopeATPCncl=0;
919     static Double_t slopeCTPCncl=0;
920     static Double_t slopeATPCnclErr=0;
921     static Double_t slopeCTPCnclErr=0;  
922     //
923     TH1* his1D=0;
924     TH3* his3D0=0;
925     TH3* his3D1=0;
926     TH3* his3D2=0;
927     TProfile* hprof=0;
928     static TF1 *fpol1 = new TF1("fpol1","pol1");
929     //
930     // all clusters
931     // only events with rec. vertex
932     // eta cut - +-1
933     // pt cut  - 0.250 GeV
934     pTPC->GetTPCTrackHisto()->GetAxis(5)->SetRangeUser(-1.,1.);
935     pTPC->GetTPCTrackHisto()->GetAxis(7)->SetRangeUser(0.25,10);
936     
937     if (pTPC->GetHistos()->FindObject("h_tpc_track_all_recvertex_0_5_7")) {    
938         his3D0 = dynamic_cast<TH3*>(pTPC->GetHistos()->FindObject("h_tpc_track_all_recvertex_0_5_7"));
939         if(!his3D0) return 1;
940         his3D0->GetYaxis()->SetRangeUser(-1,1);
941         his3D0->GetZaxis()->SetRangeUser(0.25,10);
942     }
943     if (pTPC->GetHistos()->FindObject("h_tpc_track_all_recvertex_1_5_7")) {    
944         his3D1 = dynamic_cast<TH3*>(pTPC->GetHistos()->FindObject("h_tpc_track_all_recvertex_1_5_7"));
945         if(!his3D1) return 1;
946         his3D1->GetYaxis()->SetRangeUser(-1,1);
947         his3D1->GetZaxis()->SetRangeUser(0.25,10);
948     }
949     if (pTPC->GetHistos()->FindObject("h_tpc_track_all_recvertex_2_5_7")) {    
950         his3D2 = dynamic_cast<TH3*>(pTPC->GetHistos()->FindObject("h_tpc_track_all_recvertex_2_5_7"));
951         if(!his3D2) return 1;
952         his3D2->GetYaxis()->SetRangeUser(-1,1);
953         his3D2->GetZaxis()->SetRangeUser(0.25,10);
954         his3D2->GetXaxis()->SetRangeUser(0.4,1.1);        
955     }    
956     
957
958     if (his3D0 && !fgForceTHnSparse) { 
959          his1D = his3D0->Project3D("x"); 
960     } else {
961          his1D = pTPC->GetTPCTrackHisto()->Projection(0);
962     }
963  
964     meanTPCncl= his1D->GetMean();
965     rmsTPCncl= his1D->GetRMS();
966     delete his1D;
967     
968     if (his3D1 && !fgForceTHnSparse) {
969          his1D = his3D1->Project3D("x"); 
970     } else {
971          his1D = pTPC->GetTPCTrackHisto()->Projection(1);
972     }
973           
974     meanTPCChi2= his1D->GetMean();
975     rmsTPCChi2= his1D->GetRMS();
976     delete his1D;  
977     
978    if (his3D0 && !fgForceTHnSparse) {
979         hprof = (dynamic_cast<TH2*>(his3D0->Project3D("xy")))->ProfileX(); 
980     } else {
981         hprof = pTPC->GetTPCTrackHisto()->Projection(0,5)->ProfileX();
982     }
983     if(!hprof) return 1;
984     
985     hprof->Fit(fpol1,"QNR","QNR",0.1,0.8);
986     slopeATPCncl= fpol1->GetParameter(1);
987     slopeATPCnclErr= fpol1->GetParError(1);
988     hprof->Fit(fpol1,"QNR","QNR",-0.8,-0.1);
989     slopeCTPCncl= fpol1->GetParameter(1);
990     slopeCTPCnclErr= fpol1->GetParameter(1);
991     delete hprof;
992     
993     //
994     // findable clusters
995     //
996     
997    if (his3D2 && !fgForceTHnSparse) {
998         his1D = his3D2->Project3D("x"); 
999     } else {    
1000         pTPC->GetTPCTrackHisto()->GetAxis(2)->SetRangeUser(0.4,1.1);
1001         his1D = pTPC->GetTPCTrackHisto()->Projection(2);
1002     }    
1003         
1004     meanTPCnclF= his1D->GetMean();
1005     rmsTPCnclF= his1D->GetRMS();
1006     delete his1D;
1007     
1008    if (his3D2 && !fgForceTHnSparse) { 
1009          his1D = (dynamic_cast<TH2*>(his3D2->Project3D("xy")))->ProfileX(); 
1010     } else {    
1011         pTPC->GetTPCTrackHisto()->GetAxis(2)->SetRangeUser(0.4,1.1);
1012         his1D = pTPC->GetTPCTrackHisto()->Projection(2,5)->ProfileX();
1013     }      
1014     if(!his1D) return 1;
1015     
1016     his1D->Fit(fpol1,"QNR","QNR",0.1,0.8);
1017     slopeATPCnclF= fpol1->GetParameter(1);
1018     slopeATPCnclFErr= fpol1->GetParError(1);
1019     his1D->Fit(fpol1,"QNR","QNR",-0.8,-0.1);
1020     slopeCTPCnclF= fpol1->GetParameter(1);
1021     slopeCTPCnclFErr= fpol1->GetParameter(1);
1022     delete his1D;
1023         
1024     pTPC->GetTPCTrackHisto()->GetAxis(2)->SetRangeUser(0,10);
1025     
1026     printf("Cluster QA report\n");
1027     printf("meanTPCnclF=\t%f\n",meanTPCnclF);
1028     printf("rmsTPCnclF=\t%f\n",rmsTPCnclF);
1029     printf("slopeATPCnclF=\t%f\n",slopeATPCnclF);
1030     printf("slopeCTPCnclF=\t%f\n",slopeCTPCnclF);
1031     printf("meanTPCncl=\t%f\n",meanTPCncl);
1032     printf("rmsTPCncl=\t%f\n",rmsTPCncl);
1033     printf("slopeATPCncl=\t%f\n",slopeATPCncl);
1034     printf("slopeCTPCncl=\t%f\n",slopeCTPCncl);
1035     printf("meanTPCChi2=\t%f\n",meanTPCChi2);
1036     printf("rmsTPCChi2=\t%f\n",rmsTPCChi2);
1037     //
1038     // dump results to the tree
1039     //
1040     (*pcstream)<<"tpcQA"<<
1041       "meanTPCnclF="<<meanTPCnclF <<   
1042       "rmsTPCnclF="<<rmsTPCnclF <<
1043       "meanTPCChi2="<<meanTPCChi2 <<
1044       "rmsTPCChi2="<<rmsTPCChi2 <<
1045       "slopeATPCnclF="<< slopeATPCnclF<<
1046       "slopeCTPCnclF="<< slopeCTPCnclF<<
1047       "slopeATPCnclFErr="<< slopeATPCnclFErr<<
1048       "slopeCTPCnclFErr="<< slopeCTPCnclFErr<<
1049       "meanTPCncl="<<meanTPCncl <<
1050       "rmsTPCncl="<< rmsTPCncl<<
1051       "slopeATPCncl="<< slopeATPCncl<<
1052       "slopeCTPCncl="<< slopeCTPCncl<<
1053       "slopeATPCnclErr="<< slopeATPCnclErr<<
1054       "slopeCTPCnclErr="<< slopeCTPCnclErr;
1055     
1056     return 0;
1057 }
1058
1059 //_____________________________________________________________________________
1060 Int_t AliTPCPerformanceSummary::AnalyzeDrift(const AliPerformanceTPC* pTPC, TTreeSRedirector* const pcstream)
1061 {
1062     //
1063     // Analyse DCA Z imperferctions (drift velocity)
1064     //
1065     
1066     if (!pcstream) return 2;
1067     if (!pTPC) return 2;
1068
1069     // variables:
1070     static Double_t offsetdZA=0;
1071     static Double_t slopedZA=0;
1072     static Double_t offsetdZC=0;
1073     static Double_t slopedZC=0;
1074     static Double_t offsetdZAErr=0;
1075     static Double_t slopedZAErr=0;
1076     static Double_t offsetdZCErr=0;
1077     static Double_t slopedZCErr=0;
1078     static Double_t offsetdZAchi2=0;
1079     static Double_t slopedZAchi2=0;
1080     static Double_t offsetdZCchi2=0;
1081     static Double_t slopedZCchi2=0;
1082     TH1* his1D=0;
1083     TH2* his2D=0;
1084     TH3* his3D=0;
1085     
1086    if (pTPC->GetHistos()->FindObject("h_tpc_track_all_recvertex_4_5_7")) {    
1087         his3D = dynamic_cast<TH3*>(pTPC->GetHistos()->FindObject("h_tpc_track_all_recvertex_4_5_7"));
1088         if(!his3D) return 2;
1089         his3D->GetYaxis()->SetRangeUser(-1,1);
1090         his3D->GetZaxis()->SetRangeUser(0.25,10);
1091    }
1092
1093    if (his3D && !fgForceTHnSparse) { 
1094         his2D = dynamic_cast<TH2*>(his3D->Project3D("xy")); 
1095     } else {    
1096         his2D = pTPC->GetTPCTrackHisto()->Projection(4,5);
1097     }        
1098     if(!his2D) return 2;
1099     
1100     static TF1 *fpol1 = new TF1("fpol1","pol1");
1101     TObjArray arrayFit;
1102     his2D->FitSlicesY(0,0,-1,10,"QNR",&arrayFit);
1103     delete his2D;
1104     his1D = (TH1*) arrayFit.At(1);
1105     his1D->Fit(fpol1,"QNRROB=0.8","QNR",-0.8,-0.1);
1106     offsetdZC=fpol1->GetParameter(0);
1107     slopedZC=fpol1->GetParameter(1);
1108     offsetdZCErr=fpol1->GetParError(0);
1109     slopedZCErr=fpol1->GetParError(1);        
1110     offsetdZCchi2=fpol1->GetChisquare();
1111     slopedZCchi2=fpol1->GetChisquare();
1112     //
1113     his1D->Fit(fpol1,"QNRROB=0.8","QNR",0.1,0.8);
1114     offsetdZA=fpol1->GetParameter(0);
1115     slopedZA=fpol1->GetParameter(1);
1116     offsetdZAErr=fpol1->GetParError(0);
1117     slopedZAErr=fpol1->GetParError(1);
1118     offsetdZAchi2=fpol1->GetChisquare();
1119     slopedZAchi2=fpol1->GetChisquare();
1120     //
1121     printf("Drift velocity QA report\n");
1122     printf("offsetdZA\t%f\n",offsetdZA);
1123     printf("slopedZA\t%f\n",slopedZA);
1124     printf("offsetdZC\t%f\n",offsetdZC);
1125     printf("slopedZC\t%f\n",slopedZC);
1126     //
1127     // dump drift QA values
1128     //
1129     (*pcstream)<<"tpcQA"<<
1130         "offsetdZA="<< offsetdZA<<
1131         "slopedZA="<< slopedZA<<
1132         "offsetdZC="<< offsetdZC<<
1133         "slopedZC="<<slopedZC<<
1134         //
1135         "offsetdZAErr="<< offsetdZAErr<<
1136         "slopedZAErr="<< slopedZAErr<<
1137         "offsetdZCErr="<< offsetdZCErr<<
1138         "slopedZCErr="<<slopedZCErr<<
1139         //
1140         "offsetdZAchi2="<< offsetdZAchi2<<
1141         "slopedZAchi2="<< slopedZAchi2<<
1142         "offsetdZCchi2="<< offsetdZCchi2<<
1143         "slopedZCchi2="<<slopedZCchi2;
1144     
1145     return 0;
1146 }
1147
1148 //_____________________________________________________________________________
1149 Int_t AliTPCPerformanceSummary::AnalyzeDriftPos(const AliPerformanceTPC* pTPC, TTreeSRedirector* const pcstream)
1150 {
1151     //
1152     // Analyse DCA Z imperferctions (drift velocity)
1153     // for positive particles
1154     //
1155     if (!pcstream) return 64;
1156     if (!pTPC) return 64;
1157         
1158     // variables:
1159     static Double_t offsetdZAPos=0;
1160     static Double_t slopedZAPos=0;
1161     static Double_t offsetdZCPos=0;
1162     static Double_t slopedZCPos=0;
1163     static Double_t offsetdZAErrPos=0;
1164     static Double_t slopedZAErrPos=0;
1165     static Double_t offsetdZCErrPos=0;
1166     static Double_t slopedZCErrPos=0;
1167     static Double_t offsetdZAchi2Pos=0;
1168     static Double_t slopedZAchi2Pos=0;
1169     static Double_t offsetdZCchi2Pos=0;
1170     static Double_t slopedZCchi2Pos=0;
1171     TH1* his1D=0;
1172     TH2* his2D=0;
1173     TH3* his3D=0;
1174     
1175    if (pTPC->GetHistos()->FindObject("h_tpc_track_pos_recvertex_4_5_7")) {    
1176         his3D = dynamic_cast<TH3*>(pTPC->GetHistos()->FindObject("h_tpc_track_pos_recvertex_4_5_7"));
1177         if(!his3D) return 64;
1178         his3D->GetYaxis()->SetRangeUser(-1,1);
1179         his3D->GetZaxis()->SetRangeUser(0.25,10);
1180     } 
1181
1182     if (his3D && !fgForceTHnSparse) { 
1183         his2D = dynamic_cast<TH2*>(his3D->Project3D("xy")); 
1184     } else {    
1185         his2D = pTPC->GetTPCTrackHisto()->Projection(4,5);
1186     }            
1187     if(!his2D) return 64;
1188     
1189     static TF1 *fpol1 = new TF1("fpol1","pol1");
1190     TObjArray arrayFit;
1191     his2D->FitSlicesY(0,0,-1,10,"QNR",&arrayFit);
1192     delete his2D;
1193     
1194     his1D = (TH1*) arrayFit.At(1);
1195     his1D->Fit(fpol1,"QNRROB=0.8","QNR",-0.8,-0.1);
1196     offsetdZCPos=fpol1->GetParameter(0);
1197     slopedZCPos=fpol1->GetParameter(1);
1198     offsetdZCErrPos=fpol1->GetParError(0);
1199     slopedZCErrPos=fpol1->GetParError(1);        
1200     offsetdZCchi2Pos=fpol1->GetChisquare();
1201     slopedZCchi2Pos=fpol1->GetChisquare();
1202     //
1203     his1D->Fit(fpol1,"QNRROB=0.8","QNR",0.1,0.8);
1204     offsetdZAPos=fpol1->GetParameter(0);
1205     slopedZAPos=fpol1->GetParameter(1);
1206     offsetdZAErrPos=fpol1->GetParError(0);
1207     slopedZAErrPos=fpol1->GetParError(1);
1208     offsetdZAchi2Pos=fpol1->GetChisquare();
1209     slopedZAchi2Pos=fpol1->GetChisquare();
1210     //
1211     printf("Drift velocity QA report\n");
1212     printf("offsetdZAPos\t%f\n",offsetdZAPos);
1213     printf("slopedZAPos\t%f\n",slopedZAPos);
1214     printf("offsetdZCPos\t%f\n",offsetdZCPos);
1215     printf("slopedZCPos\t%f\n",slopedZCPos);
1216     //
1217     // dump drift QA values
1218     //
1219     (*pcstream)<<"tpcQA"<<
1220         "offsetdZAPos="<< offsetdZAPos<<
1221         "slopedZAPos="<< slopedZAPos<<
1222         "offsetdZCPos="<< offsetdZCPos<<
1223         "slopedZCPos="<<slopedZCPos<<
1224         //
1225         "offsetdZAErrPos="<< offsetdZAErrPos<<
1226         "slopedZAErrPos="<< slopedZAErrPos<<
1227         "offsetdZCErrPos="<< offsetdZCErrPos<<
1228         "slopedZCErrPos="<<slopedZCErrPos<<
1229         //
1230         "offsetdZAchi2Pos="<< offsetdZAchi2Pos<<
1231         "slopedZAchi2Pos="<< slopedZAchi2Pos<<
1232         "offsetdZCchi2Pos="<< offsetdZCchi2Pos<<
1233         "slopedZCchi2Pos="<<slopedZCchi2Pos;
1234         
1235     return 0;
1236 }
1237
1238 //_____________________________________________________________________________
1239 Int_t AliTPCPerformanceSummary::AnalyzeDriftNeg(const AliPerformanceTPC* pTPC, TTreeSRedirector* const pcstream)
1240 {
1241     //
1242     // Analyse DCA Z imperferctions (drift velocity)
1243     // for negative particles
1244     //
1245     if (!pcstream) return 128;
1246     if (!pTPC) return 128;
1247             
1248     // variables:
1249     static Double_t offsetdZANeg=0;
1250     static Double_t slopedZANeg=0;
1251     static Double_t offsetdZCNeg=0;
1252     static Double_t slopedZCNeg=0;
1253     static Double_t offsetdZAErrNeg=0;
1254     static Double_t slopedZAErrNeg=0;
1255     static Double_t offsetdZCErrNeg=0;
1256     static Double_t slopedZCErrNeg=0;
1257     static Double_t offsetdZAchi2Neg=0;
1258     static Double_t slopedZAchi2Neg=0;
1259     static Double_t offsetdZCchi2Neg=0;
1260     static Double_t slopedZCchi2Neg=0;
1261     TH1* his1D=0;
1262     TH2* his2D=0;
1263     TH3* his3D=0;
1264     
1265     
1266    if (pTPC->GetHistos()->FindObject("h_tpc_track_neg_recvertex_4_5_7")) {    
1267         his3D = dynamic_cast<TH3*>(pTPC->GetHistos()->FindObject("h_tpc_track_neg_recvertex_4_5_7"));
1268         if(!his3D) return 128;
1269         his3D->GetYaxis()->SetRangeUser(-1,1);
1270         his3D->GetZaxis()->SetRangeUser(0.25,10);
1271     }
1272     if (his3D && !fgForceTHnSparse) { 
1273         his2D = dynamic_cast<TH2*>(his3D->Project3D("xy")); 
1274     } else {    
1275         his2D = pTPC->GetTPCTrackHisto()->Projection(4,5);
1276     }                
1277     if(!his2D) return 128;
1278     
1279     static TF1 *fpol1 = new TF1("fpol1","pol1");
1280     TObjArray arrayFit;
1281     his2D->FitSlicesY(0,0,-1,10,"QNR",&arrayFit);
1282     delete his2D;
1283     
1284     his1D = (TH1*) arrayFit.At(1);
1285     his1D->Fit(fpol1,"QNRROB=0.8","QNR",-0.8,-0.1);
1286     offsetdZCNeg=fpol1->GetParameter(0);
1287     slopedZCNeg=fpol1->GetParameter(1);
1288     offsetdZCErrNeg=fpol1->GetParError(0);
1289     slopedZCErrNeg=fpol1->GetParError(1);        
1290     offsetdZCchi2Neg=fpol1->GetChisquare();
1291     slopedZCchi2Neg=fpol1->GetChisquare();
1292     //
1293     his1D->Fit(fpol1,"QNRROB=0.8","QNR",0.1,0.8);
1294     offsetdZANeg=fpol1->GetParameter(0);
1295     slopedZANeg=fpol1->GetParameter(1);
1296     offsetdZAErrNeg=fpol1->GetParError(0);
1297     slopedZAErrNeg=fpol1->GetParError(1);
1298     offsetdZAchi2Neg=fpol1->GetChisquare();
1299     slopedZAchi2Neg=fpol1->GetChisquare();
1300     //
1301     printf("Drift velocity QA report\n");
1302     printf("offsetdZANeg\t%f\n",offsetdZANeg);
1303     printf("slopedZANeg\t%f\n",slopedZANeg);
1304     printf("offsetdZCNeg\t%f\n",offsetdZCNeg);
1305     printf("slopedZCNeg\t%f\n",slopedZCNeg);
1306     //
1307     // dump drift QA values
1308     //
1309     (*pcstream)<<"tpcQA"<<
1310         "offsetdZANeg="<< offsetdZANeg<<
1311         "slopedZANeg="<< slopedZANeg<<
1312         "offsetdZCNeg="<< offsetdZCNeg<<
1313         "slopedZCNeg="<<slopedZCNeg<<
1314         //
1315         "offsetdZAErrNeg="<< offsetdZAErrNeg<<
1316         "slopedZAErrNeg="<< slopedZAErrNeg<<
1317         "offsetdZCErrNeg="<< offsetdZCErrNeg<<
1318         "slopedZCErrNeg="<<slopedZCErrNeg<<
1319         //
1320         "offsetdZAchi2Neg="<< offsetdZAchi2Neg<<
1321         "slopedZAchi2Neg="<< slopedZAchi2Neg<<
1322         "offsetdZCchi2Neg="<< offsetdZCchi2Neg<<
1323         "slopedZCchi2Neg="<<slopedZCchi2Neg;
1324     
1325     return 0;
1326 }
1327
1328 //_____________________________________________________________________________
1329 Int_t AliTPCPerformanceSummary::AnalyzeGain(const AliPerformanceDEdx* pTPCgain, TTreeSRedirector* const pcstream)
1330 {
1331     //
1332     // Analyse Gain
1333     //
1334     
1335     if (!pcstream) return 4;
1336     if (!pTPCgain) return 4;
1337
1338     static TVectorD meanMIPvsSector(36);
1339     static TVectorD sector(36);
1340     static Float_t meanMIP = 0;
1341     static Float_t resolutionMIP = 0;
1342     static Float_t attachSlopeC = 0;
1343     static Float_t attachSlopeA = 0;
1344
1345     TH1 * his1D = 0;
1346     //TH1 * hisProj1D=0;
1347     TH2* his2D=0;
1348      
1349
1350     meanMIPvsSector.Zero();
1351     //
1352     // select MIP particles
1353     //
1354     pTPCgain->GetDeDxHisto()->GetAxis(7)->SetRangeUser(0.4,0.55);
1355     pTPCgain->GetDeDxHisto()->GetAxis(0)->SetRangeUser(35,60);
1356     pTPCgain->GetDeDxHisto()->GetAxis(6)->SetRangeUser(80,160);
1357     pTPCgain->GetDeDxHisto()->GetAxis(5)->SetRangeUser(-1,1);
1358     //
1359     // MIP position and resolution
1360     //    
1361     TF1 gausFit("gausFit","gaus");
1362    
1363     if (pTPCgain->GetHistos()->FindObject("h_tpc_dedx_mips_0") && !fgForceTHnSparse) {    
1364         his1D = dynamic_cast<TH1*>(pTPCgain->GetHistos()->FindObject("h_tpc_dedx_mips_0")->Clone());
1365     } else {
1366        his1D =  pTPCgain->GetDeDxHisto()->Projection(0);
1367     }
1368     if(!his1D) return 4;
1369     his1D->Fit(&gausFit,"QN","QN");
1370
1371     meanMIP = gausFit.GetParameter(1);
1372     resolutionMIP = 0;
1373     if (meanMIP!=0) resolutionMIP = gausFit.GetParameter(2)/meanMIP;
1374     //removedtotest// delete his1D;
1375     //
1376     // MIP position vs. dip angle (attachment)
1377     //    
1378     pTPCgain->GetDeDxHisto()->GetAxis(5)->SetRangeUser(-3,0); // C side
1379     if (pTPCgain->GetHistos()->FindObject("h_tpc_dedx_mips_c_0_5") && !fgForceTHnSparse) {    
1380         his2D = dynamic_cast<TH2*>(pTPCgain->GetHistos()->FindObject("h_tpc_dedx_mips_c_0_5")->Clone());
1381     } else {
1382         his2D =  pTPCgain->GetDeDxHisto()->Projection(0,5);
1383     }        
1384     if(!his2D) return 4;
1385
1386     TF1 * fpol = new TF1("fpol","pol1");
1387     TObjArray arrayFit;
1388     his2D->FitSlicesY(0,0,-1,10,"QN",&arrayFit);    
1389     his1D = (TH1*) arrayFit.At(1);
1390     his1D->Fit(fpol,"QNROB=0.8","QNR",-1,0);
1391     attachSlopeC = fpol->GetParameter(1);
1392      //removedtotest// delete his2D;
1393      //removedtotest// delete his1D;
1394     //
1395     pTPCgain->GetDeDxHisto()->GetAxis(5)->SetRangeUser(0,3); // A side
1396     if (pTPCgain->GetHistos()->FindObject("h_tpc_dedx_mips_a_0_5") && !fgForceTHnSparse) {    
1397         his2D = dynamic_cast<TH2*>(pTPCgain->GetHistos()->FindObject("h_tpc_dedx_mips_a_0_5")->Clone());
1398     } else {
1399         his2D =  pTPCgain->GetDeDxHisto()->Projection(0,5);
1400     }         
1401     if(!his2D) return 4;
1402
1403     TF1 * fpolA = new TF1("fpolA","pol1");
1404     TObjArray arrayFitA;
1405     his2D->FitSlicesY(0,0,-1,10,"QN",&arrayFit);    
1406     his1D = (TH1*) arrayFit.At(1);
1407     his1D->Fit(fpolA,"QNROB=0.8","QN",0,1);
1408     attachSlopeA = fpolA->GetParameter(1);
1409      //removedtotest// delete his2D;
1410      //removedtotest// delete his1D;
1411     //
1412     // MIP position vs. sector
1413     //
1414     pTPCgain->GetDeDxHisto()->GetAxis(5)->SetRangeUser(-3,0); // C side
1415     if (pTPCgain->GetHistos()->FindObject("h_tpc_dedx_mips_c_0_1") && !fgForceTHnSparse) {    
1416         his2D = dynamic_cast<TH2*>(pTPCgain->GetHistos()->FindObject("h_tpc_dedx_mips_c_0_1")->Clone());
1417     } else {
1418         his2D =  pTPCgain->GetDeDxHisto()->Projection(0,1);
1419     }
1420     if(!his2D) return 4;
1421
1422     for(Int_t i = 0; i < 18; i++) { // loop over sectors; correct mapping to be checked!
1423         //TH1* his1D=0;
1424         Float_t phiLow = -TMath::Pi() + i*(20./360.)*(2*TMath::Pi());
1425         Float_t phiUp    = -TMath::Pi() + (i+1)*(20./360.)*(2*TMath::Pi());
1426         //pTPCgain->GetDeDxHisto()->GetAxis(1)->SetRangeUser(phiLow,phiUp);
1427         his2D->GetXaxis()->SetRangeUser(phiLow,phiUp);
1428         //his1D = pTPCgain->GetDeDxHisto()->Projection(0); 
1429         his1D = his2D->ProjectionY(); 
1430         TF1 gausFunc("gausFunc","gaus");
1431         his1D->Fit(&gausFunc, "QN");
1432         meanMIPvsSector(i) = gausFunc.GetParameter(1);
1433         sector(i)=i;
1434         //removedtotest// delete his1D;
1435     }
1436      //removedtotest// delete his2D;
1437     //
1438     pTPCgain->GetDeDxHisto()->GetAxis(5)->SetRangeUser(0,3); // A side
1439     if (pTPCgain->GetHistos()->FindObject("h_tpc_dedx_mips_a_0_1") && !fgForceTHnSparse) {    
1440         his2D = dynamic_cast<TH2*>(pTPCgain->GetHistos()->FindObject("h_tpc_dedx_mips_a_0_1")->Clone());
1441     } else {
1442         his2D =  pTPCgain->GetDeDxHisto()->Projection(0,1);
1443     }    
1444     if(!his2D) return 4; 
1445
1446     for(Int_t i = 0; i < 18; i++) { // loop over sectors; correct mapping to be checked!
1447         //TH1* his1D=0;
1448         Float_t phiLow = -TMath::Pi() + i*(20./360.)*(2*TMath::Pi());
1449         Float_t phiUp    = -TMath::Pi() + (i+1)*(20./360.)*(2*TMath::Pi());
1450         //pTPCgain->GetDeDxHisto()->GetAxis(1)->SetRangeUser(phiLow,phiUp);
1451         his2D->GetXaxis()->SetRangeUser(phiLow,phiUp);
1452         //his1D = pTPCgain->GetDeDxHisto()->Projection(0);
1453         his1D = his2D->ProjectionY();
1454         TF1 gausFunc("gausFunc","gaus");
1455         his1D->Fit(&gausFunc, "QN");
1456         meanMIPvsSector(i+18) = gausFunc.GetParameter(1);
1457         sector(i+18)=i+18;
1458         //removedtotest// delete his1D;
1459     }
1460      //removedtotest// delete his2D;
1461     //
1462     printf("Gain QA report\n");
1463     printf("MIP mean\t%f\n",meanMIP);
1464     printf("MIP resolution\t%f\n",resolutionMIP);
1465     printf("MIPslopeA\t%f\n",attachSlopeA);
1466     printf("MIPslopeC\t%f\n",attachSlopeC);
1467     // 
1468     
1469     (*pcstream)<<"tpcQA"<<
1470         "MIPattachSlopeC="<<attachSlopeC<<
1471         "MIPattachSlopeA="<<attachSlopeA<<
1472         "resolutionMIP="<<resolutionMIP<<
1473         "meanMIPvsSector.="<<&meanMIPvsSector<<
1474         "sector.="<<&sector<<
1475         "meanMIP="<<meanMIP;
1476
1477     return 0;
1478 }
1479
1480 //_____________________________________________________________________________
1481 Int_t AliTPCPerformanceSummary::AnalyzeEvent(const AliPerformanceTPC* pTPC, TTreeSRedirector* const pcstream)
1482 {
1483     //
1484     // Analyse Primary Vertex Distribution and Multiplicities
1485     //
1486   if (!pcstream) return 1;
1487     if (!pTPC) return 1;
1488     //
1489     // 
1490     //
1491     static Double_t meanVertX=0;
1492     static Double_t rmsVertX=0;
1493     static Double_t meanVertY=0;
1494     static Double_t rmsVertY=0;
1495     static Double_t meanVertZ=0;
1496     static Double_t rmsVertZ=0;
1497     static Double_t vertStatus=0;
1498     static Double_t meanMult=0;
1499     static Double_t rmsMult=0;
1500     static Double_t meanMultPos=0;
1501     static Double_t rmsMultPos=0;
1502     static Double_t meanMultNeg=0;
1503     static Double_t rmsMultNeg=0;
1504     static Double_t vertAll = 0;
1505     static Double_t vertOK = 0;
1506     
1507     TH1* his1D=0;
1508     TH1* hc=0;
1509     if (pTPC->GetHistos()->FindObject("h_tpc_event_6") && !fgForceTHnSparse) {    
1510         his1D = dynamic_cast<TH1*>(pTPC->GetHistos()->FindObject("h_tpc_event_6")->Clone());
1511     } else {
1512        his1D = pTPC->GetTPCEventHisto()->Projection(6);
1513     }
1514     if(!his1D) return 1;
1515
1516     vertAll = his1D->GetEntries();
1517     vertOK  = his1D->GetBinContent(2);
1518     if (vertAll>=1) {
1519             vertStatus = vertOK / vertAll;
1520     }
1521     
1522     delete his1D;
1523     
1524     pTPC->GetTPCEventHisto()->GetAxis(6)->SetRange(2,2);
1525    
1526     if (pTPC->GetHistos()->FindObject("h_tpc_event_recvertex_0") && !fgForceTHnSparse) {    
1527         his1D = dynamic_cast<TH1*>(pTPC->GetHistos()->FindObject("h_tpc_event_recvertex_0")->Clone());
1528     } else {
1529        his1D = pTPC->GetTPCEventHisto()->Projection(0);
1530     }
1531     if(!his1D) return 1;
1532
1533     meanVertX = his1D->GetMean();    
1534     rmsVertX    = his1D->GetRMS();
1535     delete his1D;
1536     
1537     
1538     
1539     
1540     if (pTPC->GetHistos()->FindObject("h_tpc_event_recvertex_1") && !fgForceTHnSparse) {    
1541         his1D = dynamic_cast<TH1*>(pTPC->GetHistos()->FindObject("h_tpc_event_recvertex_1")->Clone());
1542     } else {
1543        his1D = pTPC->GetTPCEventHisto()->Projection(1);
1544     }
1545     if(!his1D) return 1;
1546
1547     meanVertY = his1D->GetMean();
1548     rmsVertY    = his1D->GetRMS();
1549     delete his1D;
1550     
1551     
1552     if (pTPC->GetHistos()->FindObject("h_tpc_event_recvertex_2") && !fgForceTHnSparse) {    
1553         hc = dynamic_cast<TH1*>(pTPC->GetHistos()->FindObject("h_tpc_event_recvertex_2"));
1554         if(!hc) return 1;
1555         //his1D = dynamic_cast<TH1*>(pTPC->GetHistos()->FindObject("h_tpc_event_recvertex_2")->Clone());
1556         his1D = (TH1*)hc->Clone();
1557     } else {
1558        his1D = pTPC->GetTPCEventHisto()->Projection(2);
1559     }    
1560     if(!his1D) return 1;
1561
1562     meanVertZ = his1D->GetMean();
1563     rmsVertZ    = his1D->GetRMS();
1564     delete his1D;
1565     
1566     
1567     if (pTPC->GetHistos()->FindObject("h_tpc_event_recvertex_3") && !fgForceTHnSparse) {    
1568         hc = dynamic_cast<TH1*>(pTPC->GetHistos()->FindObject("h_tpc_event_recvertex_3"));
1569         if(!hc) return 1;
1570         //his1D = dynamic_cast<TH1*>(pTPC->GetHistos()->FindObject("h_tpc_event_recvertex_3")->Clone());
1571         his1D = (TH1*)hc->Clone();
1572     } else {
1573        his1D = pTPC->GetTPCEventHisto()->Projection(3);
1574     }
1575     if(!his1D) return 1;
1576
1577     meanMult    = his1D->GetMean();
1578     rmsMult     = his1D->GetRMS();
1579     delete his1D;
1580     
1581     
1582     if (pTPC->GetHistos()->FindObject("h_tpc_event_recvertex_4") && !fgForceTHnSparse) {    
1583         his1D = dynamic_cast<TH1*>(pTPC->GetHistos()->FindObject("h_tpc_event_recvertex_4")->Clone());
1584     } else {
1585        his1D = pTPC->GetTPCEventHisto()->Projection(4);
1586     }
1587     if(!his1D) return 1;
1588
1589     meanMultPos    = his1D->GetMean();
1590     rmsMultPos     = his1D->GetRMS();
1591     delete his1D;
1592     
1593     if (pTPC->GetHistos()->FindObject("h_tpc_event_recvertex_5") && !fgForceTHnSparse) {    
1594         his1D = dynamic_cast<TH1*>(pTPC->GetHistos()->FindObject("h_tpc_event_recvertex_5")->Clone());
1595     } else {
1596        his1D = pTPC->GetTPCEventHisto()->Projection(5);
1597     }
1598     if(!his1D) return 1;
1599
1600     meanMultNeg    = his1D->GetMean();
1601     rmsMultNeg     = his1D->GetRMS();
1602     delete his1D;
1603     
1604     pTPC->GetTPCEventHisto()->GetAxis(6)->SetRange(1,2);
1605     //
1606     (*pcstream)<<"tpcQA"<<
1607         "meanVertX="<<meanVertX<<
1608         "rmsVertX="<<rmsVertX<<
1609         "meanVertY="<<meanVertY<<
1610         "rmsVertY="<<rmsVertY<<
1611         "meanVertZ="<<meanVertZ<<
1612         "rmsVertZ="<<rmsVertZ<<
1613         "vertStatus="<<vertStatus<<
1614         "vertAll="<<vertAll<<
1615         "vertOK="<<vertOK<<
1616         "meanMult="<<meanMult<<
1617         "rmsMult="<<rmsMult<<
1618         "meanMultPos="<<meanMultPos<<
1619         "rmsMultPos="<<rmsMultPos<<
1620         "meanMultNeg="<<meanMultNeg<<
1621         "rmsMultNeg="<<rmsMultNeg;     
1622      
1623     return 0;
1624 }
1625
1626 //_____________________________________________________________________________
1627 Int_t AliTPCPerformanceSummary::AnalyzePt(const AliPerformanceTPC* pTPC, TTreeSRedirector* const pcstream)
1628 {
1629     //
1630     // Analyse DCA R imperfections for positive particles
1631     //
1632     
1633     if (!pcstream) return 256;
1634     if (!pTPC) return 256;
1635
1636     // variables:
1637     static Double_t meanPtAPos = 0;
1638     static Double_t mediumPtAPos = 0;
1639     static Double_t highPtAPos = 0;
1640     static Double_t meanPtCPos = 0;
1641     static Double_t mediumPtCPos = 0;
1642     static Double_t highPtCPos = 0;
1643
1644     static Double_t meanPtANeg = 0;
1645     static Double_t mediumPtANeg = 0;
1646     static Double_t highPtANeg = 0;
1647     static Double_t meanPtCNeg = 0;
1648     static Double_t mediumPtCNeg = 0;
1649     static Double_t highPtCNeg = 0;
1650
1651     TH3* his3D1=0;
1652     TH3* his3D2=0;
1653     
1654     if (pTPC->GetHistos()->FindObject("h_tpc_track_pos_recvertex_3_5_7")) {    
1655
1656       his3D1 = dynamic_cast<TH3*>(pTPC->GetHistos()->FindObject("h_tpc_track_pos_recvertex_3_5_7"));
1657       if(!his3D1) return 256;
1658         
1659       his3D1->GetYaxis()->SetRangeUser(0.1,0.8);
1660       
1661       his3D1->GetZaxis()->SetRangeUser(0.25,10);
1662       meanPtAPos = his3D1->GetMean(3);
1663       his3D1->GetZaxis()->SetRangeUser(2,5);
1664       mediumPtAPos = his3D1->GetMean(3);
1665       his3D1->GetZaxis()->SetRangeUser(5,10);
1666       highPtAPos = his3D1->GetMean(3);
1667       
1668       his3D1->GetYaxis()->SetRangeUser(-0.8,-0.1);
1669
1670       his3D1->GetZaxis()->SetRangeUser(0.25,10);
1671       meanPtCPos = his3D1->GetMean(3);
1672       his3D1->GetZaxis()->SetRangeUser(2,5);
1673       mediumPtCPos = his3D1->GetMean(3);
1674       his3D1->GetZaxis()->SetRangeUser(5,10);
1675       highPtCPos = his3D1->GetMean(3);
1676
1677       his3D1->GetYaxis()->SetRangeUser(-1,1);
1678       his3D1->GetZaxis()->SetRangeUser(0.25,10);
1679     }
1680
1681
1682     if (pTPC->GetHistos()->FindObject("h_tpc_track_neg_recvertex_3_5_7")) {    
1683
1684       his3D2 = dynamic_cast<TH3*>(pTPC->GetHistos()->FindObject("h_tpc_track_neg_recvertex_3_5_7"));
1685       if(!his3D2) return 256;
1686         
1687       his3D2->GetYaxis()->SetRangeUser(0.1,0.8);
1688
1689       his3D2->GetZaxis()->SetRangeUser(0.25,10);
1690       meanPtANeg = his3D2->GetMean(3);
1691       his3D2->GetZaxis()->SetRangeUser(2,5);
1692       mediumPtANeg = his3D2->GetMean(3);
1693       his3D2->GetZaxis()->SetRangeUser(5,10);
1694       highPtANeg = his3D2->GetMean(3);
1695       
1696       his3D2->GetYaxis()->SetRangeUser(-0.8,-0.1);
1697
1698       his3D2->GetZaxis()->SetRangeUser(0.25,10);
1699       meanPtCNeg = his3D2->GetMean(3);
1700       his3D2->GetZaxis()->SetRangeUser(2,5);
1701       mediumPtCNeg = his3D2->GetMean(3);
1702       his3D2->GetZaxis()->SetRangeUser(5,10);
1703       highPtCNeg = his3D2->GetMean(3);
1704       
1705       his3D2->GetYaxis()->SetRangeUser(-1,1);
1706       his3D2->GetZaxis()->SetRangeUser(0.25,10);
1707     }
1708
1709
1710
1711     // dump values
1712     //
1713     (*pcstream)<<"tpcQA"<<
1714       "meanPtAPos="<< meanPtAPos<<
1715       "mediumPtAPos="<< mediumPtAPos<<
1716       "highPtAPos="<< highPtAPos<<
1717       //
1718       "meanPtCPos="<< meanPtCPos<<
1719       "mediumPtCPos="<< mediumPtCPos<<
1720       "highPtCPos="<< highPtCPos<<
1721       //
1722       "meanPtANeg="<< meanPtANeg<<
1723       "mediumPtANeg="<< mediumPtANeg<<
1724       "highPtANeg="<< highPtANeg<<
1725         //
1726       "meanPtCNeg="<< meanPtCNeg<<
1727       "mediumPtCNeg="<< mediumPtCNeg<<
1728       "highPtCNeg="<< highPtCNeg;
1729
1730         
1731     return 0;
1732 }
1733
1734 //_____________________________________________________________________________
1735
1736 Int_t AliTPCPerformanceSummary::AnalyzeChargeOverPt(const AliPerformanceTPC* pTPC, TTreeSRedirector* const pcstream){
1737     //
1738     // Analyse DCA R imperfections for positive particles
1739     //
1740     
1741     if (!pcstream) return 512;
1742     if (!pTPC) return 512;
1743
1744     // variables:
1745     static Double_t qOverPt = 0;
1746     static Double_t qOverPtA = 0;
1747     static Double_t qOverPtC = 0;
1748
1749     TH2* his2D=0;
1750     TH1* his1D1=0;
1751     TH1* his1D2=0;
1752     TH1* his1D3=0;
1753     TF1 *fp1 = new TF1("fp1","pol2",-1.0,1.0);
1754     TF1 *fp2 = new TF1("fp2","pol2",-1.0,1.0);
1755     TF1 *fp3 = new TF1("fp3","pol2",-1.0,1.0);
1756     
1757     if (pTPC->GetHistos()->FindObject("h_tpc_track_all_recvertex_5_8")) {
1758
1759       his2D = dynamic_cast<TH2*>(pTPC->GetHistos()->FindObject("h_tpc_track_all_recvertex_5_8"));
1760       if(!his2D) return 512;
1761
1762       his1D1 = his2D->ProjectionX();
1763       his1D1->Fit(fp1,"R");
1764       if(fp1->GetParameter(2)!=0){
1765         qOverPt = (-1.0)*(fp1->GetParameter(1)/(2.0*fp1->GetParameter(2)));
1766        }
1767       delete fp1;
1768       delete his1D1;
1769
1770        his2D->GetYaxis()->SetRangeUser(0.1,0.8);
1771        his1D2 = his2D->ProjectionX();
1772        his1D2->Fit(fp2,"R");
1773        if(fp2->GetParameter(2)!=0)
1774          qOverPtA = (-1.0)*(fp2->GetParameter(1)/(2.0*fp2->GetParameter(2)));
1775        delete fp2;
1776        delete his1D2;
1777      
1778        his2D->GetYaxis()->SetRangeUser(-0.8,-0.1);       
1779        his1D3 = his2D->ProjectionX();
1780        his1D3->Fit(fp3,"R");
1781        if(fp3->GetParameter(2)!=0)
1782          qOverPtC = (-1.0)*(fp3->GetParameter(1)/(2.0*fp3->GetParameter(2)));
1783        delete fp3;
1784        delete his1D3;
1785        
1786       his2D->GetYaxis()->SetRangeUser(-1.0,1.0);
1787     }
1788     
1789     
1790     (*pcstream)<<"tpcQA"<<
1791       "qOverPt="<< qOverPt<<
1792       "qOverPtA="<< qOverPtA<<
1793       "qOverPtC="<< qOverPtC;
1794     
1795     return 0;
1796 }
1797
1798 Int_t AliTPCPerformanceSummary::AnalyzeMatch(const AliPerformanceMatch* pMatch, TTreeSRedirector* const pcstream)
1799 {
1800   /* if ((pMatch == 0) or (0 == pcstream)) { printf("this will not work anyway..."); }
1801      printf("funtion not implemented");*/
1802
1803   if (!pcstream) return 1024;
1804   if (!pMatch) return 1024;
1805   static Double_t tpcItsMatchA = 0;
1806   static Double_t tpcItsMatchHighPtA = 0; 
1807   static Double_t tpcItsMatchC = 0;
1808   static Double_t tpcItsMatchHighPtC = 0; 
1809
1810   TH2 *h2D = 0;
1811   TH2 *h2D1 = 0;
1812   if(pMatch->GetHistos()->FindObject("h_tpc_match_trackingeff_all_2_3") &&
1813      pMatch->GetHistos()->FindObject("h_tpc_match_trackingeff_tpc_2_3")){
1814     h2D = dynamic_cast<TH2*>(pMatch->GetHistos()->FindObject("h_tpc_match_trackingeff_all_2_3"));
1815     h2D1 = dynamic_cast<TH2*>(pMatch->GetHistos()->FindObject("h_tpc_match_trackingeff_tpc_2_3"));
1816    
1817     if(!h2D) return 4;
1818     if(!h2D1) return 4;
1819
1820     h2D->GetXaxis()->SetRangeUser(0,1.5);
1821     h2D1->GetXaxis()->SetRangeUser(0,1.5);
1822
1823     Double_t entries,entries1;
1824     entries = h2D->GetEffectiveEntries();
1825     entries1 = h2D1->GetEffectiveEntries();
1826     if(entries > 0)
1827       tpcItsMatchA = entries1/entries;
1828
1829     h2D->GetYaxis()->SetRangeUser(4.01,20.);
1830     h2D1->GetYaxis()->SetRangeUser(4.01,20.);
1831     entries = h2D->GetEffectiveEntries();
1832     entries1 = h2D1->GetEffectiveEntries();
1833     if(entries > 0)
1834     tpcItsMatchHighPtA = entries1/entries;
1835
1836
1837     h2D->GetXaxis()->SetRangeUser(-1.5,-0.01);
1838     h2D1->GetXaxis()->SetRangeUser(-1.5,-0.01);
1839     h2D->GetYaxis()->SetRangeUser(0.0,20.);
1840     h2D1->GetYaxis()->SetRangeUser(0.0,20.);
1841
1842     entries = h2D->GetEffectiveEntries();
1843     entries1 = h2D1->GetEffectiveEntries();
1844     if(entries > 0)
1845       tpcItsMatchC = entries1/entries;
1846
1847     h2D->GetYaxis()->SetRangeUser(4.01,20.);
1848     h2D1->GetYaxis()->SetRangeUser(4.01,20.);
1849     entries = h2D->GetEffectiveEntries();
1850     entries1 = h2D1->GetEffectiveEntries();
1851     if(entries > 0)
1852       tpcItsMatchHighPtC = entries1/entries;
1853
1854     h2D->GetXaxis()->SetRangeUser(-1.5,1.5);
1855     h2D1->GetXaxis()->SetRangeUser(-1.5,1.5);
1856     h2D->GetYaxis()->SetRangeUser(0.0,20.);
1857     h2D1->GetYaxis()->SetRangeUser(0.0,20.);
1858     //    delete h2D;
1859     //    delete h2D1;
1860   }
1861
1862   (*pcstream)<<"tpcQA"<<
1863     "tpcItsMatchA="<< tpcItsMatchA<<
1864     "tpcItsMatchHighPtA="<< tpcItsMatchHighPtA<<
1865     "tpcItsMatchC="<< tpcItsMatchC<<
1866     "tpcItsMatchHighPtC="<< tpcItsMatchHighPtC;
1867
1868   return 0;
1869 }
1870
1871 Int_t AliTPCPerformanceSummary::AnalyzePull(const AliPerformanceMatch* pPull, TTreeSRedirector* const pcstream)
1872 {
1873   /* if ((pPull == 0) or (0 == pcstream)) { printf("this will not work anyway..."); }
1874      printf("funtion not implemented");*/
1875
1876   if (!pcstream) return 2048;
1877   if (!pPull) return 2048;
1878   static Double_t phiPull = 0;
1879   static Double_t phiPullHighPt = 0; 
1880   static Double_t ptPull = 0;
1881   static Double_t ptPullHighPt = 0; 
1882   static Double_t yPull = 0;
1883   static Double_t yPullHighPt = 0; 
1884   static Double_t zPull = 0;
1885   static Double_t zPullHighPt = 0; 
1886   static Double_t lambdaPull = 0;
1887   static Double_t lambdaPullHighPt = 0; 
1888
1889   TH2 *h2D1 = 0;
1890   if(pPull->GetHistos()->FindObject("h_tpc_match_pull_2_7")){
1891     h2D1 = dynamic_cast<TH2*>(pPull->GetHistos()->FindObject("h_tpc_match_pull_2_7"));
1892     if(!h2D1) return 4;
1893     phiPull = h2D1->GetMean(2);
1894     h2D1->SetAxisRange(0.0,1.0/5.0,"X");
1895     phiPullHighPt = h2D1->GetMean(2);
1896     h2D1->SetAxisRange(0.0,10.0,"X");
1897     //    delete h2D1;
1898   }
1899
1900   TH2 *h2D2 = 0;
1901   if(pPull->GetHistos()->FindObject("h_tpc_match_pull_4_7")){
1902     h2D2 = dynamic_cast<TH2*>(pPull->GetHistos()->FindObject("h_tpc_match_pull_4_7"));
1903     if(!h2D2) return 4;
1904     ptPull = h2D2->GetMean(2);
1905
1906     h2D2->SetAxisRange(0.0,1.0/5.0,"X");
1907     ptPullHighPt = h2D2->GetMean(2);
1908     h2D2->SetAxisRange(0.0,10.0,"X");
1909     //    delete h2D2;
1910   }
1911
1912   TH2 *h2D3 = 0;
1913   if(pPull->GetHistos()->FindObject("h_tpc_match_pull_0_7")){
1914     h2D3 = dynamic_cast<TH2*>(pPull->GetHistos()->FindObject("h_tpc_match_pull_0_7"));
1915     if(!h2D3) return 4;
1916     yPull = h2D3->GetMean(2);
1917
1918     h2D3->SetAxisRange(0.0,1.0/5.0,"X");
1919     yPullHighPt = h2D3->GetMean(2);
1920     h2D3->SetAxisRange(0.0,10.0,"X");
1921     //    delete h2D3;
1922   }
1923
1924   TH2 *h2D4 = 0;
1925   if(pPull->GetHistos()->FindObject("h_tpc_match_pull_1_7")){
1926     h2D4 = dynamic_cast<TH2*>(pPull->GetHistos()->FindObject("h_tpc_match_pull_1_7"));
1927     if(!h2D4) return 4;
1928     zPull = h2D4->GetMean(2);
1929
1930     h2D4->SetAxisRange(0.0,1.0/5.0,"X");
1931     zPullHighPt = h2D4->GetMean(2);
1932     h2D4->SetAxisRange(0.0,10.0,"X");
1933     //    delete h2D4;
1934  }
1935
1936   TH2 *h2D5 = 0;
1937   if(pPull->GetHistos()->FindObject("h_tpc_match_pull_3_7")){
1938     h2D5 = dynamic_cast<TH2*>(pPull->GetHistos()->FindObject("h_tpc_match_pull_3_7"));
1939     if(!h2D5) return 4;
1940     lambdaPull = h2D5->GetMean(2);
1941
1942     h2D5->SetAxisRange(0.0,1.0/5.0,"X");
1943     lambdaPullHighPt = h2D5->GetMean(2);
1944     h2D5->SetAxisRange(0.0,10.0,"X");
1945     //    delete h2D5;
1946 }
1947
1948   (*pcstream)<<"tpcQA"<<
1949     "phiPull="<< phiPull<<
1950     "phiPullHighPt="<< phiPullHighPt<<
1951     "ptPull="<< ptPull<<
1952     "ptPullHighPt="<< ptPullHighPt<<
1953     "yPull="<< yPull<<
1954     "yPullHighPt="<< yPullHighPt<<
1955     "zPull="<< zPull<<
1956     "zPullHighPt="<< zPullHighPt<<
1957     "lambdaPull="<< lambdaPull<<
1958     "lambdaPullHighPt="<< lambdaPullHighPt;
1959     
1960   return 0;
1961 }
1962 Int_t AliTPCPerformanceSummary::AnalyzeConstrain(const AliPerformanceMatch* pConstrain, TTreeSRedirector* pcstream)
1963 {
1964   if (!pcstream) return 5126;
1965   if (!pConstrain) return 5126;
1966
1967     TH3* his3D=0;
1968     static Double_t tpcConstrainPhiA = 0;
1969     static Double_t tpcConstrainPhiC = 0;
1970     
1971     if (pConstrain->GetHistos()->FindObject("h_tpc_constrain_tpc_0_2_3")) {    
1972       
1973       his3D = dynamic_cast<TH3*>(pConstrain->GetHistos()->FindObject("h_tpc_constrain_tpc_0_2_3"));//phi pull:pt:eta
1974       if(!his3D) return 5126;
1975       
1976       his3D->GetZaxis()->SetRangeUser(0.0,1.0);
1977       tpcConstrainPhiA = his3D->GetMean(1);
1978       his3D->GetZaxis()->SetRangeUser(-1.0,-0.001);
1979       tpcConstrainPhiC = his3D->GetMean(1);
1980     }
1981
1982   (*pcstream)<<"tpcQA"<<
1983     "tpcConstrainPhiA="<<tpcConstrainPhiA <<
1984     "tpcConstrainPhiC="<< tpcConstrainPhiC;
1985   
1986   return 0;
1987 }
1988
1989 //_____________________________________________________________________________
1990  Int_t AliTPCPerformanceSummary::AnalyzeQAPosNegDpT(const AliPerformanceTPC* pTPC, TTreeSRedirector* const pcstream)
1991 {
1992   //function which plot 1/Pt for negative and 
1993   //positive particles
1994   
1995   if (!pcstream) return 512;
1996   if (!pTPC) return 512;
1997   
1998   TH3D* pos3=0;
1999   TH3D* neg3=0;
2000   TH1D* pos=0;
2001   TH1D* neg=0;
2002   TH1D* posC=0;
2003   TH1D* negC=0;
2004   TH1D* posA=0;
2005   TH1D* negA=0;
2006   static Double_t deltaPtC = 0;
2007   static Double_t deltaPtchi2C = 0;
2008   static Double_t slopeC = 0;
2009   static Double_t deltaPtA = 0;
2010   static Double_t deltaPtchi2A = 0;
2011   static Double_t slopeA = 0;
2012   static Double_t deltaPt = 0;
2013   static Double_t deltaPtchi2 = 0;
2014   static Double_t slope = 0;
2015   static Double_t deltaPt_Err = 0; 
2016   static Double_t deltaPtA_Err = 0;
2017   static Double_t deltaPtC_Err = 0;
2018
2019
2020 //C side
2021
2022   if(pTPC->GetHistos()->FindObject("h_tpc_track_pos_recvertex_0_5_7"))
2023     {
2024     pos3 = dynamic_cast<TH3D*>(pTPC->GetHistos()->FindObject("h_tpc_track_pos_recvertex_0_5_7")); 
2025     if(!pos3) return 512;
2026   
2027     pos = pos3->ProjectionZ("pos",71,-1,6,25);
2028     posC = pos3->ProjectionZ("posC",71,-1,6,15);
2029     posA = pos3->ProjectionZ("posA",71,-1,16,25);
2030     }
2031
2032     if(pTPC->GetHistos()->FindObject("h_tpc_track_neg_recvertex_0_5_7")){
2033     neg3 = dynamic_cast<TH3D*>(pTPC->GetHistos()->FindObject("h_tpc_track_neg_recvertex_0_5_7")); 
2034     if(!neg3) return 512;
2035     
2036     neg = neg3->ProjectionZ("neg",71,-1,6,25);
2037     negC = neg3->ProjectionZ("negC",71,-1,6,15);
2038     negA = neg3->ProjectionZ("negA",71,-1,16,25);
2039 }
2040
2041
2042 pos->Sumw2();
2043 neg->Sumw2();
2044 posA->Sumw2();
2045 negA->Sumw2();
2046 posC->Sumw2();
2047 negC->Sumw2();
2048
2049 pos->Scale(1.,"width");
2050 neg->Scale(1.,"width");
2051 posA->Scale(1.,"width");
2052 negA->Scale(1.,"width");
2053 posC->Scale(1.,"width");
2054 negC->Scale(1.,"width");
2055
2056 //both sides
2057
2058 TF1 fpt("fpt","[1]*exp(-1/((1/x))*[0])",0.1,10);
2059 TF1 fpt2("fpt2","[1]*exp(-1/((1/x))*[0])",0.1,10);
2060 fpt.SetParameters(1,0.5);
2061 fpt2.SetParameters(1,0.5);
2062 pos->Fit(&fpt,"","",1,4); pos->Fit(&fpt,"","",1,4); pos->Fit(&fpt,"","",1,4);
2063 neg->Fit(&fpt2,"","",1,4); neg->Fit(&fpt2,"","",1,4); neg->Fit(&fpt2,"","",1,4);
2064
2065 slope = (fpt.GetParameter(0)+fpt2.GetParameter(0))/2.;
2066
2067 TH1D* ratio = new TH1D(*pos); 
2068 ratio->Divide(neg);
2069
2070 ratio->Draw();
2071 TF1 fptRatio("fptratio","[2]*exp(-1/((1/x)+[1])*[0])/exp(-1/((1/x)-[1])*[0])",0.1,10);
2072 fptRatio.SetParameters(0.5,0.006,1);
2073 fptRatio.FixParameter(0,slope);
2074 fptRatio.Draw();
2075 ratio->Fit(&fptRatio,"","",1,4); ratio->Fit(&fptRatio,"","",1,4); 
2076 ratio->Fit(&fptRatio,"","",1,4);
2077
2078 deltaPt = fptRatio.GetParameter(1);
2079 deltaPtchi2 = fptRatio.GetChisquare();
2080
2081 //get the errors
2082 deltaPt_Err = fptRatio.GetParError(1);
2083
2084
2085 //A side
2086
2087 TF1 fptA("fptA","[1]*exp(-1/((1/x))*[0])",0.1,10);
2088 TF1 fpt2A("fpt2A","[1]*exp(-1/((1/x))*[0])",0.1,10);
2089 fptA.SetParameters(1,0.5);
2090 fpt2A.SetParameters(1,0.5);
2091 posA->Fit(&fptA,"","",1,4); posA->Fit(&fptA,"","",1,4); posA->Fit(&fptA,"","",1,4);
2092 negA->Fit(&fpt2A,"","",1,4); negA->Fit(&fpt2A,"","",1,4); negA->Fit(&fpt2A,"","",1,4);
2093
2094 slopeA = (fptA.GetParameter(0)+fpt2A.GetParameter(0))/2.;
2095
2096 TH1D* ratioA = new TH1D(*posA); 
2097 ratioA->Divide(negA);
2098
2099 ratioA->Draw();
2100 TF1 fptRatioA("fptratioA","[2]*exp(-1/((1/x)+[1])*[0])/exp(-1/((1/x)-[1])*[0])",0.1,10);
2101 fptRatioA.SetParameters(0.5,0.006,1);
2102 fptRatioA.FixParameter(0,slopeA);
2103 fptRatioA.Draw();
2104 ratioA->Fit(&fptRatioA,"","",1,4); ratio->Fit(&fptRatioA,"","",1,4); 
2105 ratioA->Fit(&fptRatioA,"","",1,4);
2106
2107 deltaPtA = fptRatioA.GetParameter(1);
2108 deltaPtchi2A = fptRatioA.GetChisquare();
2109
2110 //get the errors
2111 deltaPtA_Err = fptRatioA.GetParError(1);
2112
2113  delete ratioA;
2114  delete pos;
2115  delete neg;
2116
2117
2118 //C side
2119 TF1 fptC("fptC","[1]*exp(-1/((1/x))*[0])",0.1,10);
2120 TF1 fpt2C("fpt2C","[1]*exp(-1/((1/x))*[0])",0.1,10);
2121 fptC.SetParameters(1,0.5);
2122 fpt2C.SetParameters(1,0.5);
2123 posC->Fit(&fptC,"","",1,4); posC->Fit(&fptC,"","",1,4); posC->Fit(&fptC,"","",1,4);
2124 negC->Fit(&fpt2C,"","",1,4); negC->Fit(&fpt2C,"","",1,4); negC->Fit(&fpt2C,"","",1,4);
2125
2126 slopeC = (fptC.GetParameter(0)+fpt2C.GetParameter(0))/2.;
2127
2128 TH1D* ratioC = new TH1D(*posC); 
2129 ratioC->Divide(negC);
2130
2131 ratioC->Draw();
2132 TF1 fptRatioC("fptratioC","[2]*exp(-1/((1/x)+[1])*[0])/exp(-1/((1/x)-[1])*[0])",0.1,10);
2133 fptRatioC.SetParameters(0.5,0.006,1);
2134 fptRatioC.FixParameter(0,slopeC);
2135 fptRatioC.Draw();
2136 ratioC->Fit(&fptRatioC,"","",1,4); ratio->Fit(&fptRatioC,"","",1,4); 
2137 ratioC->Fit(&fptRatioC,"","",1,4);
2138
2139 deltaPtC = fptRatioC.GetParameter(1);
2140 deltaPtchi2C = fptRatioC.GetChisquare();
2141
2142 //get the errors
2143 deltaPtC_Err = fptRatioC.GetParError(1);
2144
2145
2146  delete posC;
2147  delete negC;
2148  delete ratioC;
2149     
2150     (*pcstream)<<"tpcQA"<<      
2151       "deltaPt="<< deltaPt<<
2152       "deltaPtchi2="<< deltaPtchi2<<
2153       "deltaPtA="<< deltaPtA<<
2154       "deltaPtchi2A="<< deltaPtchi2A<<
2155       "deltaPtC="<< deltaPtC<<
2156       "deltaPtchi2C="<< deltaPtchi2C<<
2157       "deltaPt_Err="<< deltaPt_Err<<
2158       "deltaPtA_Err="<< deltaPtA_Err<<
2159       "deltaPtC_Err="<< deltaPtC_Err;    
2160       
2161     return 0;
2162 }
2163
2164 //_____________________________________________________________________________
2165  Int_t AliTPCPerformanceSummary::AnalyzeQADCAFitParameter(const AliPerformanceTPC* pTPC, TTreeSRedirector* const pcstream)
2166 {
2167   
2168   //
2169   //function which retrieve DCA fit parameters
2170   //
2171   
2172   if (!pcstream) return 16;
2173   if (!pTPC) return 16;
2174   
2175   TH3* dcar_pos3=0;
2176   TH3* dcaz_pos3=0;
2177   TH3* dcar_neg3=0;
2178   TH3* dcaz_neg3=0;
2179
2180   static Double_t dcar_posA_0=0; 
2181   static Double_t dcar_posA_1=0; 
2182   static Double_t dcar_posA_2=0; 
2183   static Double_t dcar_posA_chi2=0; 
2184   static Double_t dcar_posA_0_Err=0; 
2185   static Double_t dcar_posA_1_Err=0; 
2186   static Double_t dcar_posA_2_Err=0; 
2187   
2188   static Double_t dcar_posC_0=0; 
2189   static Double_t dcar_posC_1=0; 
2190   static Double_t dcar_posC_2=0; 
2191   static Double_t dcar_posC_chi2=0; 
2192   static Double_t dcar_posC_0_Err=0; 
2193   static Double_t dcar_posC_1_Err=0; 
2194   static Double_t dcar_posC_2_Err=0; 
2195
2196   static Double_t dcaz_posA_0=0; 
2197   static Double_t dcaz_posA_1=0; 
2198   static Double_t dcaz_posA_2=0; 
2199   static Double_t dcaz_posA_chi2=0; 
2200   static Double_t dcaz_posA_0_Err=0; 
2201   static Double_t dcaz_posA_1_Err=0; 
2202   static Double_t dcaz_posA_2_Err=0; 
2203   
2204   static Double_t dcaz_posC_0=0; 
2205   static Double_t dcaz_posC_1=0; 
2206   static Double_t dcaz_posC_2=0; 
2207   static Double_t dcaz_posC_chi2=0; 
2208   static Double_t dcaz_posC_0_Err=0; 
2209   static Double_t dcaz_posC_1_Err=0; 
2210   static Double_t dcaz_posC_2_Err=0; 
2211   
2212   static Double_t dcar_negA_0=0; 
2213   static Double_t dcar_negA_1=0; 
2214   static Double_t dcar_negA_2=0; 
2215   static Double_t dcar_negA_chi2=0; 
2216   static Double_t dcar_negA_0_Err=0; 
2217   static Double_t dcar_negA_1_Err=0; 
2218   static Double_t dcar_negA_2_Err=0; 
2219   
2220   static Double_t dcar_negC_0=0; 
2221   static Double_t dcar_negC_1=0; 
2222   static Double_t dcar_negC_2=0; 
2223   static Double_t dcar_negC_chi2=0; 
2224   static Double_t dcar_negC_0_Err=0; 
2225   static Double_t dcar_negC_1_Err=0; 
2226   static Double_t dcar_negC_2_Err=0; 
2227
2228   static Double_t dcaz_negA_0=0; 
2229   static Double_t dcaz_negA_1=0; 
2230   static Double_t dcaz_negA_2=0; 
2231   static Double_t dcaz_negA_chi2=0; 
2232   static Double_t dcaz_negA_0_Err=0; 
2233   static Double_t dcaz_negA_1_Err=0; 
2234   static Double_t dcaz_negA_2_Err=0; 
2235  
2236   static Double_t dcaz_negC_0=0; 
2237   static Double_t dcaz_negC_1=0; 
2238   static Double_t dcaz_negC_2=0; 
2239   static Double_t dcaz_negC_chi2=0; 
2240   static Double_t dcaz_negC_0_Err=0; 
2241   static Double_t dcaz_negC_1_Err=0; 
2242   static Double_t dcaz_negC_2_Err=0;
2243  
2244   if (pTPC->GetHistos()->FindObject("h_tpc_track_pos_recvertex_3_5_6")) {  
2245     dcar_pos3 = dynamic_cast<TH3*>(pTPC->GetHistos()->FindObject("h_tpc_track_pos_recvertex_3_5_6"));
2246   }
2247   
2248   if (pTPC->GetHistos()->FindObject("h_tpc_track_pos_recvertex_3_5_6")) {  
2249     dcaz_pos3 = dynamic_cast<TH3*>(pTPC->GetHistos()->FindObject("h_tpc_track_pos_recvertex_4_5_6"));
2250   }
2251   
2252   if (pTPC->GetHistos()->FindObject("h_tpc_track_pos_recvertex_3_5_6")) {  
2253     dcar_neg3 = dynamic_cast<TH3*>(pTPC->GetHistos()->FindObject("h_tpc_track_neg_recvertex_3_5_6")); 
2254   }
2255   
2256   if (pTPC->GetHistos()->FindObject("h_tpc_track_pos_recvertex_3_5_6")) {  
2257     dcaz_neg3 = dynamic_cast<TH3*>(pTPC->GetHistos()->FindObject("h_tpc_track_neg_recvertex_4_5_6"));
2258   }
2259
2260   TF1 fit("fit","[0]+[1]*cos(x)+[2]*sin(x)",0,7); 
2261
2262   dcar_pos3->GetYaxis()->SetRangeUser(0,0.99);    
2263   TH1* dcar_posA = (dynamic_cast<TH2*>(dcar_pos3->Project3D("xz_1")))->ProfileX(); 
2264   dcar_posA->Fit(&fit,"NQ");
2265   dcar_posA_0 = fit.GetParameter(0);
2266   dcar_posA_1 = fit.GetParameter(1);
2267   dcar_posA_2 = fit.GetParameter(2);
2268   dcar_posA_chi2 = fit.GetChisquare();  
2269   dcar_posA_0_Err = fit.GetParError(0);
2270   dcar_posA_1_Err = fit.GetParError(1);
2271   dcar_posA_2_Err = fit.GetParError(2);
2272   
2273   dcar_pos3->GetYaxis()->SetRangeUser(-1.0,-0.01);    
2274   TH1* dcar_posC = (dynamic_cast<TH2*>(dcar_pos3->Project3D("xz_2")))->ProfileX(); 
2275   dcar_posC->Fit(&fit,"NQ");
2276   dcar_posC_0 = fit.GetParameter(0);
2277   dcar_posC_1 = fit.GetParameter(1);
2278   dcar_posC_2 = fit.GetParameter(2);
2279   dcar_posC_chi2 = fit.GetChisquare();    
2280   dcar_posC_0_Err = fit.GetParError(0);
2281   dcar_posC_1_Err = fit.GetParError(1);
2282   dcar_posC_2_Err = fit.GetParError(2);
2283
2284   dcaz_pos3->GetYaxis()->SetRangeUser(0,0.99);    
2285   TH1* dcaz_posA = (dynamic_cast<TH2*>(dcaz_pos3->Project3D("xz_3")))->ProfileX(); 
2286   dcaz_posA->Fit(&fit,"NQ");
2287   dcaz_posA_0 = fit.GetParameter(0);
2288   dcaz_posA_1 = fit.GetParameter(1);
2289   dcaz_posA_2 = fit.GetParameter(2);
2290   dcaz_posA_chi2 = fit.GetChisquare();      
2291   dcaz_posA_0_Err = fit.GetParError(0);
2292   dcaz_posA_1_Err = fit.GetParError(1);
2293   dcaz_posA_2_Err = fit.GetParError(2);  
2294   
2295   dcaz_pos3->GetYaxis()->SetRangeUser(-1.0,-0.01);    
2296   TH1* dcaz_posC = (dynamic_cast<TH2*>(dcaz_pos3->Project3D("xz_4")))->ProfileX(); 
2297   dcaz_posC->Fit(&fit,"NQ");
2298   dcaz_posC_0 = fit.GetParameter(0);
2299   dcaz_posC_1 = fit.GetParameter(1);
2300   dcaz_posC_2 = fit.GetParameter(2);
2301   dcaz_posC_chi2 = fit.GetChisquare();    
2302   dcaz_posC_0_Err = fit.GetParError(0);
2303   dcaz_posC_1_Err = fit.GetParError(1);
2304   dcaz_posC_2_Err = fit.GetParError(2);  
2305     
2306
2307   
2308    dcar_neg3->GetYaxis()->SetRangeUser(0,0.99);    
2309   TH1* dcar_negA = (dynamic_cast<TH2*>(dcar_neg3->Project3D("xz_1")))->ProfileX(); 
2310   dcar_negA->Fit(&fit,"NQ");
2311   dcar_negA_0 = fit.GetParameter(0);
2312   dcar_negA_1 = fit.GetParameter(1);
2313   dcar_negA_2 = fit.GetParameter(2);
2314   dcar_negA_chi2 = fit.GetChisquare();  
2315   dcar_negA_0_Err = fit.GetParError(0);
2316   dcar_negA_1_Err = fit.GetParError(1);
2317   dcar_negA_2_Err = fit.GetParError(2);
2318   
2319   dcar_neg3->GetYaxis()->SetRangeUser(-1.0,-0.01);    
2320   TH1* dcar_negC = (dynamic_cast<TH2*>(dcar_neg3->Project3D("xz_2")))->ProfileX(); 
2321   dcar_negC->Fit(&fit,"NQ");
2322   dcar_negC_0 = fit.GetParameter(0);
2323   dcar_negC_1 = fit.GetParameter(1);
2324   dcar_negC_2 = fit.GetParameter(2);
2325   dcar_negC_chi2 = fit.GetChisquare();    
2326   dcar_negC_0_Err = fit.GetParError(0);
2327   dcar_negC_1_Err = fit.GetParError(1);
2328   dcar_negC_2_Err = fit.GetParError(2);
2329
2330   dcaz_neg3->GetYaxis()->SetRangeUser(0,0.99);    
2331   TH1* dcaz_negA = (dynamic_cast<TH2*>(dcaz_neg3->Project3D("xz_3")))->ProfileX(); 
2332   dcaz_negA->Fit(&fit,"NQ");
2333   dcaz_negA_0 = fit.GetParameter(0);
2334   dcaz_negA_1 = fit.GetParameter(1);
2335   dcaz_negA_2 = fit.GetParameter(2);
2336   dcaz_negA_chi2 = fit.GetChisquare();      
2337   dcaz_negA_0_Err = fit.GetParError(0);
2338   dcaz_negA_1_Err = fit.GetParError(1);
2339   dcaz_negA_2_Err = fit.GetParError(2);  
2340   
2341   dcaz_neg3->GetYaxis()->SetRangeUser(-1.0,-0.01);    
2342   TH1* dcaz_negC = (dynamic_cast<TH2*>(dcaz_neg3->Project3D("xz_4")))->ProfileX(); 
2343   dcaz_negC->Fit(&fit,"NQ");
2344   dcaz_negC_0 = fit.GetParameter(0);
2345   dcaz_negC_1 = fit.GetParameter(1);
2346   dcaz_negC_2 = fit.GetParameter(2);
2347   dcaz_negC_chi2 = fit.GetChisquare();    
2348   dcaz_negC_0_Err = fit.GetParError(0);
2349   dcaz_negC_1_Err = fit.GetParError(1);
2350   dcaz_negC_2_Err = fit.GetParError(2);  
2351     
2352
2353 // store results (shift in dca) in ttree
2354     
2355     (*pcstream)<<"tpcQA"<<      
2356       "dcar_posA_0="<< dcar_posA_0<<
2357       "dcar_posA_1="<< dcar_posA_1<<
2358       "dcar_posA_2="<< dcar_posA_2<<
2359       "dcar_posA_chi2="<< dcar_posA_chi2<<
2360       "dcar_posA_0_Err="<< dcar_posA_0_Err<<
2361       "dcar_posA_1_Err="<< dcar_posA_1_Err<<
2362       "dcar_posA_2_Err="<< dcar_posA_2_Err;    
2363       
2364       (*pcstream)<<"tpcQA"<<            
2365       "dcaz_posA_0="<< dcaz_posA_0<<
2366       "dcaz_posA_1="<< dcaz_posA_1<<
2367       "dcaz_posA_2="<< dcaz_posA_2<<
2368       "dcaz_posA_chi2="<< dcaz_posA_chi2<<
2369       "dcaz_posA_0_Err="<< dcaz_posA_0_Err<<
2370       "dcaz_posA_1_Err="<< dcaz_posA_1_Err<<
2371       "dcaz_posA_2_Err="<< dcaz_posA_2_Err;          
2372       
2373       (*pcstream)<<"tpcQA"<<            
2374       "dcaz_posC_0="<< dcaz_posC_0<<
2375       "dcaz_posC_1="<< dcaz_posC_1<<
2376       "dcaz_posC_2="<< dcaz_posC_2<<
2377       "dcaz_posC_chi2="<< dcaz_posC_chi2<<
2378       "dcaz_posC_0_Err="<< dcaz_posC_0_Err<<
2379       "dcaz_posC_1_Err="<< dcaz_posC_1_Err<<
2380       "dcaz_posC_2_Err="<< dcaz_posC_2_Err;           
2381
2382       (*pcstream)<<"tpcQA"<<            
2383       "dcar_posC_0="<< dcar_posC_0<<
2384       "dcar_posC_1="<< dcar_posC_1<<
2385       "dcar_posC_2="<< dcar_posC_2<<
2386       "dcar_posC_chi2="<< dcar_posC_chi2<<
2387       "dcar_posC_0_Err="<< dcar_posC_0_Err<<
2388       "dcar_posC_1_Err="<< dcar_posC_1_Err<<
2389       "dcar_posC_2_Err="<< dcar_posC_2_Err;           
2390             
2391       
2392      (*pcstream)<<"tpcQA"<<      
2393       "dcar_negA_0="<< dcar_negA_0<<
2394       "dcar_negA_1="<< dcar_negA_1<<
2395       "dcar_negA_2="<< dcar_negA_2<<
2396       "dcar_negA_chi2="<< dcar_negA_chi2<<
2397       "dcar_negA_0_Err="<< dcar_negA_0_Err<<
2398       "dcar_negA_1_Err="<< dcar_negA_1_Err<<
2399       "dcar_negA_2_Err="<< dcar_negA_2_Err;    
2400       
2401       (*pcstream)<<"tpcQA"<<            
2402       "dcaz_negA_0="<< dcaz_negA_0<<
2403       "dcaz_negA_1="<< dcaz_negA_1<<
2404       "dcaz_negA_2="<< dcaz_negA_2<<
2405       "dcaz_negA_chi2="<< dcaz_negA_chi2<<
2406       "dcaz_negA_0_Err="<< dcaz_negA_0_Err<<
2407       "dcaz_negA_1_Err="<< dcaz_negA_1_Err<<
2408       "dcaz_negA_2_Err="<< dcaz_negA_2_Err;          
2409       
2410       (*pcstream)<<"tpcQA"<<            
2411       "dcaz_negC_0="<< dcaz_negC_0<<
2412       "dcaz_negC_1="<< dcaz_negC_1<<
2413       "dcaz_negC_2="<< dcaz_negC_2<<
2414       "dcaz_negC_chi2="<< dcaz_negC_chi2<<
2415       "dcaz_negC_0_Err="<< dcaz_negC_0_Err<<
2416       "dcaz_negC_1_Err="<< dcaz_negC_1_Err<<
2417       "dcaz_negC_2_Err="<< dcaz_negC_2_Err;           
2418
2419       (*pcstream)<<"tpcQA"<<            
2420       "dcar_negC_0="<< dcar_negC_0<<
2421       "dcar_negC_1="<< dcar_negC_1<<
2422       "dcar_negC_2="<< dcar_negC_2<<
2423       "dcar_negC_chi2="<< dcar_negC_chi2<<
2424       "dcar_negC_0_Err="<< dcar_negC_0_Err<<
2425       "dcar_negC_1_Err="<< dcar_negC_1_Err<<
2426       "dcar_negC_2_Err="<< dcar_negC_2_Err;                 
2427       
2428       return 0;
2429 }