]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGPP/TRD/AliTRDresolution.cxx
fix compilation
[u/mrichter/AliRoot.git] / PWGPP / TRD / AliTRDresolution.cxx
1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 *                                                                        *
4 * Author: The ALICE Off-line Project.                                    *
5 * Contributors are mentioned in the code where appropriate.              *
6 *                                                                        *
7 * Permission to use, copy, modify and distribute this software and its   *
8 * documentation strictly for non-commercialf purposes is hereby granted   *
9 * without fee, provided that the above copyright notice appears in all   *
10 * copies and that both the copyright notice and this permission notice   *
11 * appear in the supporting documentation. The authors make no claims     *
12 * about the suitability of this software for any purpose. It is          *
13 * provided "as is" without express or implied warranty.                  *
14 **************************************************************************/
15
16 /* $Id: AliTRDresolution.cxx 27496 2008-07-22 08:35:45Z cblume $ */
17
18 ////////////////////////////////////////////////////////////////////////////
19 //                                                                        //
20 //  TRD tracking resolution                                               //
21 //
22 // The class performs resolution and residual studies 
23 // of the TRD tracks for the following quantities :
24 //   - spatial position (y, [z])
25 //   - angular (phi) tracklet
26 //   - momentum at the track level
27 // 
28 // The class has to be used for regular detector performance checks using the official macros:
29 //   - $ALICE_ROOT/TRD/qaRec/run.C
30 //   - $ALICE_ROOT/TRD/qaRec/makeResults.C
31 // 
32 // For stand alone usage please refer to the following example: 
33 // {  
34 //   gSystem->Load("libANALYSIS.so");
35 //   gSystem->Load("libTRDqaRec.so");
36 //   AliTRDresolution *res = new AliTRDresolution();
37 //   //res->SetMCdata();
38 //   //res->SetVerbose();
39 //   //res->SetVisual();
40 //   res->Load();
41 //   if(!res->PostProcess()) return;
42 //   res->GetRefFigure(0);
43 // }  
44 //
45 //  Authors:                                                              //
46 //    Alexandru Bercuci <A.Bercuci@gsi.de>                                //
47 //    Markus Fasel <M.Fasel@gsi.de>                                       //
48 //                                                                        //
49 ////////////////////////////////////////////////////////////////////////////
50
51 #include <TFile.h>
52 #include <TSystem.h>
53 #include <TStyle.h>
54 #include <TROOT.h>
55 #include <TObjArray.h>
56 #include <TH3.h>
57 #include <TH2.h>
58 #include <TH1.h>
59 #include <THnSparse.h>
60 #include <TF1.h>
61 #include <TCanvas.h>
62 #include <TGaxis.h>
63 #include <TBox.h>
64 #include <TLegend.h>
65 #include <TGraphErrors.h>
66 #include <TGraphAsymmErrors.h>
67 #include <TLinearFitter.h>
68 #include <TMath.h>
69 #include <TMatrixT.h>
70 #include <TVectorT.h>
71 #include <TTreeStream.h>
72 #include <TGeoManager.h>
73 #include <TDatabasePDG.h>
74
75 #include "AliPID.h"
76 #include "AliLog.h"
77 #include "AliESDtrack.h"
78 #include "AliMathBase.h"
79 #include "AliTrackPointArray.h"
80
81 #include "AliTRDresolution.h"
82 #include "AliTRDgeometry.h"
83 #include "AliTRDtransform.h"
84 #include "AliTRDpadPlane.h"
85 #include "AliTRDcluster.h"
86 #include "AliTRDseedV1.h"
87 #include "AliTRDtrackV1.h"
88 #include "AliTRDReconstructor.h"
89 #include "AliTRDrecoParam.h"
90 #include "AliTRDpidUtil.h"
91 #include "AliTRDinfoGen.h"
92 #include "AliAnalysisManager.h"
93 #include "info/AliTRDclusterInfo.h"
94 #include "info/AliTRDeventInfo.h"
95
96 ClassImp(AliTRDresolution)
97 ClassImp(AliTRDresolution::AliTRDrecoProjection)
98
99 Int_t const   AliTRDresolution::fgkNbins[kNdim] = {
100   Int_t(kNbunchCross)/*bc*/,
101   180/*phi*/,
102   50/*eta*/,
103   50/*dy*/,
104   40/*dphi*/,
105   50/*dz*/,
106   3/*chg*species*/,
107   kNpt/*pt*/
108 };  //! no of bins/projection
109 Double_t const AliTRDresolution::fgkMin[kNdim] = {
110   -1.5,
111   -TMath::Pi(),
112   -1.,
113   -1.5,
114   -10.,
115   -2.5,
116   -1.5,
117   -0.5
118 };    //! low limits for projections
119 Double_t const AliTRDresolution::fgkMax[kNdim] = {
120   1.5,
121   TMath::Pi(),
122   1.,
123   1.5,
124   10.,
125   2.5,
126   1.5,
127   kNpt-0.5
128 };    //! high limits for projections
129 Char_t const *AliTRDresolution::fgkTitle[kNdim] = {
130   "bunch cross",
131   "#phi [rad]",
132   "#eta",
133   "#Deltay [cm]",
134   "#Delta#phi [deg]",
135   "#Deltaz [cm]",
136   "chg*spec*rc",
137   "bin_p_{t}"
138 };  //! title of projection
139
140 Char_t const * AliTRDresolution::fgPerformanceName[kNclasses] = {
141     "Det2Cluster"
142     ,"Cluster2Track"
143     ,"Tracklet2Track"
144     ,"Tracklet2TRDin"
145     ,"Cluster2MC"
146     ,"Tracklet2MC"
147     ,"TRDin2MC"
148     ,"TRD2MC"
149 //    ,"Tracklet2TRDout"
150 //    ,"TRDout2MC"
151 };
152 Float_t AliTRDresolution::fgPtBin[25];
153
154 //________________________________________________________
155 AliTRDresolution::AliTRDresolution()
156   :AliTRDrecoTask()
157   ,fSteer(0)
158   ,fIdxFrame(0)
159   ,fPtThreshold(.3)
160   ,fDyRange(0.75)
161   ,fBCbinTOF(0)
162   ,fBCbinFill(0)
163   ,fBsign(kFALSE)
164   ,fProj(NULL)
165   ,fDBPDG(NULL)
166   ,fCl(NULL)
167   ,fMCcl(NULL)
168 {
169   //
170   // Default constructor
171   //
172   SetNameTitle("TRDresolution", "TRD spatial and momentum resolution");
173   MakePtSegmentation();
174   SetProcesses(kTRUE, kTRUE, kTRUE, kTRUE);
175 }
176
177 //________________________________________________________
178 AliTRDresolution::AliTRDresolution(char* name, Bool_t xchange)
179   :AliTRDrecoTask(name, "TRD spatial and momentum resolution")
180   ,fSteer(0)
181   ,fIdxFrame(0)
182   ,fPtThreshold(.3)
183   ,fDyRange(0.75)
184   ,fBCbinTOF(0)
185   ,fBCbinFill(0)
186   ,fBsign(kFALSE)
187   ,fProj(NULL)
188   ,fDBPDG(NULL)
189   ,fCl(NULL)
190   ,fMCcl(NULL)
191 {
192   //
193   // Default constructor
194   //
195
196   InitFunctorList();
197   MakePtSegmentation();
198   SetProcesses(kTRUE, kTRUE, kTRUE, kTRUE);
199   if(xchange){
200     SetUseExchangeContainers();
201     DefineOutput(kClToTrk, TObjArray::Class()); // cluster2track
202     DefineOutput(kClToMC, TObjArray::Class()); // cluster2mc
203   }
204 }
205
206 //________________________________________________________
207 AliTRDresolution::~AliTRDresolution()
208 {
209   //
210   // Destructor
211   //
212   if (AliAnalysisManager::GetAnalysisManager() && AliAnalysisManager::GetAnalysisManager()->IsProofMode()) return;
213   if(fProj){fProj->Delete(); delete fProj;}
214   if(fCl){fCl->Delete(); delete fCl;}
215   if(fMCcl){fMCcl->Delete(); delete fMCcl;}
216 }
217
218
219 //________________________________________________________
220 void AliTRDresolution::UserCreateOutputObjects()
221 {
222   // spatial resolution
223
224   AliTRDrecoTask::UserCreateOutputObjects();
225   if(UseExchangeContainers()) InitExchangeContainers();
226 }
227
228 //________________________________________________________
229 void AliTRDresolution::InitExchangeContainers()
230 {
231 // Init containers for subsequent tasks (AliTRDclusterResolution)
232
233   fCl = new TObjArray(200); fCl->SetOwner(kTRUE);
234   fMCcl = new TObjArray(); fMCcl->SetOwner(kTRUE);
235   PostData(kClToTrk, fCl);
236   PostData(kClToMC, fMCcl);
237 }
238
239 //________________________________________________________
240 void AliTRDresolution::UserExec(Option_t *opt)
241 {
242   //
243   // Execution part
244   //
245
246   if(fCl) fCl->Delete();
247   if(fMCcl) fMCcl->Delete();
248   AliTRDrecoTask::UserExec(opt);
249 }
250
251 //________________________________________________________
252 Bool_t AliTRDresolution::Pulls(Double_t* /*dyz[2]*/, Double_t* /*cov[3]*/, Double_t /*tilt*/) const
253 {
254 // Helper function to calculate pulls in the yz plane
255 // using proper tilt rotation
256 // Uses functionality defined by AliTRDseedV1.
257
258   return kTRUE;
259 /*
260   Double_t t2(tilt*tilt);
261   // exit door until a bug fix is found for AliTRDseedV1::GetCovSqrt
262
263   // rotate along pad
264   Double_t cc[3];
265   cc[0] = cov[0] - 2.*tilt*cov[1] + t2*cov[2];
266   cc[1] = cov[1]*(1.-t2) + tilt*(cov[0] - cov[2]);
267   cc[2] = t2*cov[0] + 2.*tilt*cov[1] + cov[2];
268   // do sqrt
269   Double_t sqr[3]={0., 0., 0.};
270   if(AliTRDseedV1::GetCovSqrt(cc, sqr)) return kFALSE;
271   Double_t invsqr[3]={0., 0., 0.};
272   if(AliTRDseedV1::GetCovInv(sqr, invsqr)<1.e-40) return kFALSE;
273   Double_t tmp(dyz[0]);
274   dyz[0] = invsqr[0]*tmp + invsqr[1]*dyz[1];
275   dyz[1] = invsqr[1]*tmp + invsqr[2]*dyz[1];
276   return kTRUE;
277 */
278 }
279
280 //________________________________________________________
281 TH1* AliTRDresolution::DetCluster(const TObjArray *cls)
282 {
283   //
284   // Plot the cluster distributions
285   //
286
287   if(cls) fkClusters = cls;
288   if(!fkClusters){
289     AliDebug(4, "No Clusters defined.");
290     return NULL;
291   }
292   Int_t ncl(0);
293   if(!(ncl = fkClusters->GetEntriesFast())){
294     AliDebug(1, "No RecPoints defined.");
295     return NULL;
296   }
297   Int_t det(-1);
298   AliTRDcluster *cl(NULL);
299   for(Int_t icl(0); icl<ncl; icl++){
300     if(!(cl = (AliTRDcluster*)(*fkClusters)[icl])) continue;
301     det = cl->GetDetector(); break;
302   }
303   if(det<0){
304     AliDebug(1, "No useful clusters defined.");
305     return NULL;
306   }
307   THnSparse *H(NULL);
308   if(!fContainer || !(H = ((THnSparse*)fContainer->At(kDetector)))){
309     AliWarning("No output container defined.");
310     return NULL;
311   }
312   Int_t ly(AliTRDgeometry::GetLayer(det)),
313         stk(AliTRDgeometry::GetStack(det));
314   Double_t val[kNdim],
315            alpha((0.5+AliTRDgeometry::GetSector(det))*AliTRDgeometry::GetAlpha()),
316            cs(TMath::Cos(alpha)),
317            sn(TMath::Sin(alpha));
318   for(Int_t icl(0); icl<ncl; icl++){
319     if(!(cl = (AliTRDcluster*)(*fkClusters)[icl])) continue;
320     val[kBC]  = ly;
321     val[kPhi] = TMath::ATan2(cl->GetX()*sn + cl->GetY()*cs, cl->GetX()*cs - cl->GetY()*sn);
322     val[kEta] = (5-stk)*16-cl->GetPadRow()-1-(stk<3?4:0);
323     val[kYrez]= fEvent->GetMultiplicity();
324     val[4]    = TMath::Abs(cl->GetQ());
325     val[5]    = cl->IsFivePad()?1:cl->GetNPads();
326     H->Fill(val);
327   }
328   return NULL;
329 }
330
331 //________________________________________________________
332 TH1* AliTRDresolution::PlotCluster(const AliTRDtrackV1 *track)
333 {
334   //
335   // Plot the cluster distributions
336   //
337
338   if(track) fkTrack = track;
339   if(!fkTrack){
340     AliDebug(4, "No Track defined.");
341     return NULL;
342   }
343   if(fkESD && TMath::Abs(fkESD->GetTOFbc()) > 1){
344     AliDebug(4, Form("Track with BC_index[%d] not used.", fkESD->GetTOFbc()));
345     return NULL;
346   }
347   if(fkESD && fPt<fPtThreshold){
348     AliDebug(4, Form("Track with pt[%6.4f] under threshold.", fPt));
349     return NULL;
350   }
351   THnSparse *H(NULL);
352   if(!fContainer || !(H = ((THnSparse*)fContainer->At(kCluster)))){
353     AliWarning("No output container defined.");
354     return NULL;
355   }
356
357   AliTRDgeometry *geo(AliTRDinfoGen::Geometry());
358   Double_t val[kNdim+2],
359            alpha(0.), cs(-2.), sn(0.); //Float_t exb, vd, t0, s2, dl, dt;
360   TObjArray     *clInfoArr(NULL);
361   AliTRDseedV1  *fTracklet(NULL);
362   AliTRDcluster *c(NULL), *cc(NULL);
363   for(Int_t ily=0; ily<AliTRDgeometry::kNlayer; ily++){
364     if(!(fTracklet = fkTrack->GetTracklet(ily))) continue;
365     if(!fTracklet->IsOK()) continue;
366     //fTracklet->GetCalibParam(exb, vd, t0, s2, dl, dt);
367     val[kBC]  = ily;
368     if(cs<-1.){
369       alpha = (0.5+AliTRDgeometry::GetSector(fTracklet->GetDetector()))*AliTRDgeometry::GetAlpha();
370       cs    = TMath::Cos(alpha);
371       sn    = TMath::Sin(alpha);
372     }
373     val[kPhi] = TMath::ATan2(fTracklet->GetX()*sn + fTracklet->GetY()*cs, fTracklet->GetX()*cs - fTracklet->GetY()*sn);
374     Float_t tgl = fTracklet->GetZ()/fTracklet->GetX()/TMath::Sqrt(1.+fTracklet->GetY()*fTracklet->GetY()/fTracklet->GetX()/fTracklet->GetX());
375     val[kEta] = -TMath::Log(TMath::Tan(0.5 *  (0.5*TMath::Pi() - TMath::ATan(tgl))));
376     val[kPt]  = TMath::ATan(fTracklet->GetYref(1))*TMath::RadToDeg();
377     Float_t corr = 1./TMath::Sqrt(1.+fTracklet->GetYref(1)*fTracklet->GetYref(1)+fTracklet->GetZref(1)*fTracklet->GetZref(1));
378     Int_t row0(-1);
379     Float_t padCorr(fTracklet->GetTilt()*fTracklet->GetPadLength());
380     fTracklet->ResetClusterIter(kTRUE);
381     while((c = fTracklet->NextCluster())){
382       Float_t xc(c->GetX()),
383               q(TMath::Abs(c->GetQ()));
384       if(row0<0) row0 = c->GetPadRow();
385
386       val[kYrez] = c->GetY() + padCorr*(c->GetPadRow() - row0) -fTracklet->GetYat(xc);
387       val[kPrez] = fTracklet->GetX0()-xc;
388       val[kZrez] = 0.; Int_t ic(0), tb(c->GetLocalTimeBin());;
389       if((cc = fTracklet->GetClusters(tb-1))) {val[kZrez] += TMath::Abs(cc->GetQ()); ic++;}
390       if((cc = fTracklet->GetClusters(tb-2))) {val[kZrez] += TMath::Abs(cc->GetQ()); ic++;}
391       if(ic) val[kZrez] /= (ic*q);
392       val[kSpeciesChgRC]= fTracklet->IsRowCross()?0.:(TMath::Max(q*corr, Float_t(3.)));
393       val[kNdim]   = fEvent?fEvent->GetMultiplicity():0.;
394       val[kNdim+1] = c->IsFivePad()?1:c->GetNPads();
395       H->Fill(val);
396 /*      // tilt rotation of covariance for clusters
397       Double_t sy2(c->GetSigmaY2()), sz2(c->GetSigmaZ2());
398       cov[0] = (sy2+t2*sz2)*corr;
399       cov[1] = tilt*(sz2 - sy2)*corr;
400       cov[2] = (t2*sy2+sz2)*corr;
401       // sum with track covariance
402       cov[0]+=covR[0]; cov[1]+=covR[1]; cov[2]+=covR[2];
403       Double_t dyz[2]= {dy[1], dz[1]};
404       Pulls(dyz, cov, tilt);*/
405
406       // Get z-position with respect to anode wire
407       Float_t yt(fTracklet->GetYref(0)-val[kZrez]*fTracklet->GetYref(1)),
408               zt(fTracklet->GetZref(0)-val[kZrez]*fTracklet->GetZref(1));
409       Int_t istk = geo->GetStack(c->GetDetector());
410       AliTRDpadPlane *pp = geo->GetPadPlane(ily, istk);
411       Float_t rowZ = pp->GetRow0();
412       Float_t d  = rowZ - zt + pp->GetAnodeWireOffset();
413       d -= ((Int_t)(2 * d)) / 2.0;
414       if (d > 0.25) d  = 0.5 - d;
415
416       AliTRDclusterInfo *clInfo(NULL);
417       clInfo = new AliTRDclusterInfo;
418       clInfo->SetCluster(c);
419       //Float_t covF[] = {cov[0], cov[1], cov[2]};
420       clInfo->SetGlobalPosition(yt, zt, fTracklet->GetYref(1), fTracklet->GetZref(1)/*, covF*/);
421       clInfo->SetResolution(val[kYrez]);
422       clInfo->SetAnisochronity(d);
423       clInfo->SetDriftLength(val[kZrez]);
424       clInfo->SetTilt(fTracklet->GetTilt());
425       if(fCl) fCl->Add(clInfo);
426       //else AliDebug(1, "Cl exchange container missing. Activate by calling \"InitExchangeContainers()\"");
427
428       if(DebugLevel()>=2){
429         if(!clInfoArr){
430           clInfoArr=new TObjArray(AliTRDseedV1::kNclusters);
431           clInfoArr->SetOwner(kFALSE);
432         }
433         clInfoArr->Add(clInfo);
434       }
435     }
436     if(DebugLevel()>=2 && clInfoArr){
437       ULong_t status = fkESD->GetStatus();
438       (*DebugStream()) << "cluster"
439         <<"status="  << status
440         <<"clInfo.=" << clInfoArr
441         << "\n";
442       clInfoArr->Clear();
443     }
444   }
445   if(clInfoArr) delete clInfoArr;
446
447   if(!track) return NULL;
448   // special care for EVE usage
449   TH1 *h(NULL);
450   if((h = (TH1*)gDirectory->Get(Form("%s_proj_%d", H->GetName(), kYrez)))) delete h;
451   return H->Projection(kYrez);
452 }
453
454
455 //________________________________________________________
456 TH1* AliTRDresolution::PlotTracklet(const AliTRDtrackV1 *track)
457 {
458 // Plot normalized residuals for tracklets to track.
459 //
460 // We start from the result that if X=N(|m|, |Cov|)
461 // BEGIN_LATEX
462 // (Cov^{-1})^{1/2}X = N((Cov^{-1})^{1/2}*|m|, |1|)
463 // END_LATEX
464 // in our case X=(y_trklt - y_trk z_trklt - z_trk) and |Cov| = |Cov_trklt| + |Cov_trk| at the radial
465 // reference position.
466   if(track) fkTrack = track;
467   if(!fkTrack){
468     AliDebug(4, "No Track defined.");
469     return NULL;
470   }
471   if(fkESD && TMath::Abs(fkESD->GetTOFbc())>1){
472     AliDebug(4, Form("Track with BC_index[%d] not used.", fkESD->GetTOFbc()));
473     //return NULL;
474   }
475   THnSparse *H(NULL);
476   if(!fContainer || !(H = (THnSparse*)fContainer->At(kTracklet))){
477     AliWarning("No output container defined.");
478     return NULL;
479   }
480
481   const Int_t ndim(kNdim+8);
482   Double_t val[ndim],
483            alpha(0.), cs(-2.), sn(0.);
484   Float_t sz[AliTRDseedV1::kNtb], pos[AliTRDseedV1::kNtb];
485   Int_t ntbGap[AliTRDseedV1::kNtb];
486   AliTRDseedV1 *fTracklet(NULL);
487   for(Int_t il(0); il<AliTRDgeometry::kNlayer; il++){
488     if(!(fTracklet = fkTrack->GetTracklet(il))) continue;
489     if(!fTracklet->IsOK() || !fTracklet->IsChmbGood()) continue;
490     val [kBC] = il;
491     if(cs<-1.){
492       alpha = (0.5+AliTRDgeometry::GetSector(fTracklet->GetDetector()))*AliTRDgeometry::GetAlpha();
493       cs    = TMath::Cos(alpha);
494       sn    = TMath::Sin(alpha);
495     }
496     val[kPhi] = TMath::ATan2(fTracklet->GetX()*sn + fTracklet->GetY()*cs, fTracklet->GetX()*cs - fTracklet->GetY()*sn);
497     Float_t tgl = fTracklet->GetZ()/fTracklet->GetX()/TMath::Sqrt(1.+fTracklet->GetY()*fTracklet->GetY()/fTracklet->GetX()/fTracklet->GetX());//fTracklet->GetTgl();
498     val[kEta] = -TMath::Log(TMath::Tan(0.5 *  (0.5*TMath::Pi() - TMath::ATan(tgl))));
499
500     val[kSpeciesChgRC]= fTracklet->IsRowCross()?0:fkTrack->Charge();// fSpecies;
501     val[kPt]  = GetPtBinSignificant(fPt); //fPt<0.8?0:(fPt<1.5?1:2);//GetPtBin(fTracklet->GetMomentum());
502     Double_t dyt(fTracklet->GetYfit(0) - fTracklet->GetYref(0)),
503              dzt(fTracklet->GetZfit(0) - fTracklet->GetZref(0)),
504              dydx(fTracklet->GetYfit(1)),
505              tilt(fTracklet->GetTilt());
506     // correct for tilt rotation
507     val[kYrez] = dyt - dzt*tilt;
508     val[kZrez] = fTracklet->IsRowCross()?(dzt + dyt*tilt):(fTracklet->GetdQdl()*3.e-4-1.5);
509     dydx+= tilt*fTracklet->GetZref(1);
510     val[kPrez] = TMath::ATan((dydx - fTracklet->GetYref(1))/(1.+ fTracklet->GetYref(1)*dydx)) * TMath::RadToDeg();
511     val[kNdim] = fEvent?fEvent->GetMultiplicity():0;
512     val[kNdim+1] = 1.e2*fTracklet->GetTBoccupancy()/AliTRDseedV1::kNtb;
513     Int_t n = fTracklet->GetChargeGaps(sz, pos, ntbGap);
514     val[kNdim+2] = 0.; for(Int_t igap(0); igap<n; igap++) val[kNdim+2] += sz[igap];
515     for(Int_t ifill(0); ifill<3; ifill++){ val[kNdim+3+ifill]=0.;val[kNdim+4+ifill]=0.;}
516     for(Int_t igap(0), ifill(0); igap<n&&ifill<2; igap++){
517       if(ntbGap[igap]<2) continue;
518       val[kNdim+3+ifill] = sz[igap];
519       val[kNdim+4+ifill] = pos[igap];
520       ifill++;
521     }
522     H->Fill(val);
523
524 //     // compute covariance matrix
525 //     fTracklet->GetCovAt(x, cov);
526 //     fTracklet->GetCovRef(covR);
527 //     cov[0] += covR[0]; cov[1] += covR[1]; cov[2] += covR[2];
528 //     Double_t dyz[2]= {dy[1], dz[1]};
529 //     Pulls(dyz, cov, tilt);
530 //     ((TH3S*)arr->At(1))->Fill(sgm[fSegmentLevel], dyz[0], dyz[1]);
531 //     ((TH3S*)arr->At(3))->Fill(tht, dyz[1], rc);
532
533     if(DebugLevel()>=3){
534       Bool_t rc(fTracklet->IsRowCross());
535       UChar_t err(fTracklet->GetErrorMsg());
536       Double_t x(fTracklet->GetX()),
537                pt(fTracklet->GetPt()),
538                yt(fTracklet->GetYref(0)),
539                zt(fTracklet->GetZref(0)),
540                phi(fTracklet->GetYref(1)),
541                tht(fTracklet->GetZref(1));
542       Int_t ncl(fTracklet->GetN()), det(fTracklet->GetDetector());
543       (*DebugStream()) << "tracklet"
544         <<"pt="  << pt
545         <<"x="   << x
546         <<"yt="  << yt
547         <<"zt="  << zt
548         <<"phi=" << phi
549         <<"tht=" << tht
550         <<"det=" << det
551         <<"n="   << ncl
552         <<"dy0=" << dyt
553         <<"dz0=" << dzt
554         <<"dy="  << val[kYrez]
555         <<"dz="  << val[kZrez]
556         <<"dphi="<< val[kPrez]
557         <<"dQ  ="<< val[kNdim]
558         <<"rc="  << rc
559         <<"err=" << err
560         << "\n";
561     }
562   }
563   if(!track) return NULL;
564   // special care for EVE usage
565   TH1 *h(NULL);
566   if((h = (TH1*)gDirectory->Get(Form("%s_proj_%d", H->GetName(), kYrez)))) delete h;
567   return H->Projection(kYrez);
568 }
569
570
571 //________________________________________________________
572 TH1* AliTRDresolution::PlotTrackIn(const AliTRDtrackV1 *track)
573 {
574 // Store resolution/pulls of Kalman before updating with the TRD information
575 // at the radial position of the first tracklet. The following points are used
576 // for comparison
577 //  - the (y,z,snp) of the first TRD tracklet
578 //  - the (y, z, snp, tgl, pt) of the MC track reference
579 //
580 // Additionally the momentum resolution/pulls are calculated for usage in the
581 // PID calculation.
582   //printf("AliTRDresolution::PlotTrackIn() :: track[%p]\n", (void*)track);
583
584   if(track) fkTrack = track;
585   if(!fkTrack){
586     AliDebug(4, "No Track defined.");
587     return NULL;
588   }
589   //fkTrack->Print();
590   TH1 *h(NULL); // EVE projection
591   // check container
592   THnSparseI *H=(THnSparseI*)fContainer->At(kTrackIn);
593   if(!H){
594     AliError(Form("Missing container @ %d", Int_t(kTrackIn)));
595     return NULL;
596   }
597   // check input track status
598   AliExternalTrackParam *tin(NULL);
599   if(!(tin = fkTrack->GetTrackIn())){
600     AliError("Track did not entered TRD fiducial volume.");
601     return NULL;
602   }
603   // check first tracklet
604   AliTRDseedV1 *fTracklet(fkTrack->GetTracklet(0));
605   if(!fTracklet){
606     AliDebug(3, "No Tracklet in ly[0]. Skip track.");
607     if(!track) return NULL;
608     // special care for EVE usage
609     if((h = (TH1*)gDirectory->Get(Form("%s_proj_%d", H->GetName(), kYrez)))) delete h;
610     return H->Projection(kYrez);
611   }
612   if(!fTracklet->IsOK() || !fTracklet->IsChmbGood()){
613     AliDebug(3, "Tracklet or Chamber not OK. Skip track.");
614     if(!track) return NULL;
615     // special care for EVE usage
616     if((h = (TH1*)gDirectory->Get(Form("%s_proj_%d", H->GetName(), kYrez)))) delete h;
617     return H->Projection(kYrez);
618   }
619   // check radial position
620   Double_t x = tin->GetX();
621   if(TMath::Abs(x-fTracklet->GetX())>1.e-3){
622     AliDebug(1, Form("Tracklet did not match Track. dx[cm]=%+4.1f", x-fTracklet->GetX()));
623     if(!track) return NULL;
624     // special care for EVE usage
625     if((h = (TH1*)gDirectory->Get(Form("%s_proj_%d", H->GetName(), kYrez)))) delete h;
626     return H->Projection(kYrez);
627   }
628
629   Int_t bc(fkESD?fkESD->GetTOFbc()/2:0);
630   const Double_t *parR(tin->GetParameter());
631   Double_t dyt(fTracklet->GetYfit(0)-parR[0]), dzt(fTracklet->GetZfit(0)-parR[1]),
632             phit(fTracklet->GetYfit(1)),
633             tilt(fTracklet->GetTilt()),
634             norm(1./TMath::Sqrt((1.-parR[2])*(1.+parR[2])));
635
636   // correct for tilt rotation
637   Double_t dy  = dyt - dzt*tilt,
638            dz  = dzt + dyt*tilt,
639            dx  = dy/(parR[2]*norm-parR[3]*norm*tilt);
640   phit       += tilt*parR[3];
641   Double_t dphi = TMath::ATan(phit) - TMath::ASin(parR[2]);
642
643   Double_t val[kNdim+3];
644   val[kBC]          = bc==0?0:(bc<0?-1.:1.);
645   Double_t alpha = (0.5+AliTRDgeometry::GetSector(fTracklet->GetDetector()))*AliTRDgeometry::GetAlpha(),
646            cs    = TMath::Cos(alpha),
647            sn    = TMath::Sin(alpha);
648   val[kPhi] = TMath::ATan2(fTracklet->GetX()*sn + fTracklet->GetY()*cs, fTracklet->GetX()*cs - fTracklet->GetY()*sn);
649   Float_t tgl = fTracklet->GetZ()/fTracklet->GetX()/TMath::Sqrt(1.+fTracklet->GetY()*fTracklet->GetY()/fTracklet->GetX()/fTracklet->GetX());
650   val[kEta] = -TMath::Log(TMath::Tan(0.5 *  (0.5*TMath::Pi() - TMath::ATan(tgl))));
651   val[kYrez]        = dy;
652   val[kZrez]        = fTracklet->IsRowCross()?dz:(fTracklet->GetdQdl()*5.e-4 - 2.5);
653   val[kPrez]        = dphi*TMath::RadToDeg();
654   // down scale PID resolution
655   Int_t spc(fSpecies); if(spc==3) spc=2; if(spc==-3) spc=-2; 
656   val[kSpeciesChgRC]= fTracklet->IsRowCross()?0:spc;
657   val[kPt]          = GetPtBinSignificant(fPt);
658   val[kNdim]        = GetPtBinSignificant(fTracklet->GetMomentum());
659   val[kNdim+1]      = dx;
660   val[kNdim+2]      = fEvent?fEvent->GetBunchFill():0;
661   H->Fill(val);
662   if(DebugLevel()>=3){
663     (*DebugStream()) << "trackIn"
664       <<"tracklet.="  << fTracklet
665       <<"trackIn.="   << tin
666       << "\n";
667   }
668
669   if(!track) return NULL;
670   // special care for EVE usage
671   if((h = (TH1*)gDirectory->Get(Form("%s_proj_%d", H->GetName(), kYrez)))) delete h;
672   return H->Projection(kYrez);
673 }
674
675 /*
676 //________________________________________________________
677 TH1* AliTRDresolution::PlotTrackOut(const AliTRDtrackV1 *track)
678 {
679 // Store resolution/pulls of Kalman after last update with the TRD information
680 // at the radial position of the first tracklet. The following points are used
681 // for comparison
682 //  - the (y,z,snp) of the first TRD tracklet
683 //  - the (y, z, snp, tgl, pt) of the MC track reference
684 //
685 // Additionally the momentum resolution/pulls are calculated for usage in the
686 // PID calculation.
687
688   if(track) fkTrack = track;
689   return NULL;
690 }
691 */
692 //________________________________________________________
693 TH1* AliTRDresolution::PlotMC(const AliTRDtrackV1 *track)
694 {
695   //
696   // Plot MC distributions
697   //
698
699   if(!HasMCdata()) return NULL;
700   if(track) fkTrack = track;
701   if(!fkTrack){
702     AliDebug(4, "No Track defined.");
703     return NULL;
704   }
705   Int_t bc(TMath::Abs(fkESD->GetTOFbc()));
706
707   THnSparse *H(NULL);
708   if(!fContainer){
709     AliWarning("No output container defined.");
710     return NULL;
711   }
712   // retriev track characteristics
713   Int_t pdg = fkMC->GetPDG(),
714         sIdx(AliTRDpidUtil::Pdg2Pid(TMath::Abs(pdg))+1), // species index
715         sign(0),
716 //        sgm[3],
717         label(fkMC->GetLabel());
718 //        fSegmentLevel(0);
719   if(!fDBPDG) fDBPDG=TDatabasePDG::Instance();
720   TParticlePDG *ppdg(fDBPDG->GetParticle(pdg));
721   if(ppdg) sign = ppdg->Charge() > 0. ? 1 : -1;
722
723   TH1 *h(NULL);
724   AliTRDgeometry *geo(AliTRDinfoGen::Geometry());
725   AliTRDseedV1 *fTracklet(NULL); TObjArray *clInfoArr(NULL);
726   UChar_t s;
727   Double_t x, y, z, pt, dydx, dzdx, dzdl;
728   Float_t pt0, x0, y0, z0, dx, dy, dz, dydx0, dzdx0;
729   Double_t covR[7]/*, cov[3]*/;
730
731 /*  if(DebugLevel()>=3){
732     // get first detector
733     Int_t det = -1;
734     for(Int_t ily=0; ily<AliTRDgeometry::kNlayer; ily++){
735       if(!(fTracklet = fkTrack->GetTracklet(ily))) continue;
736       det = fTracklet->GetDetector();
737       break;
738     }
739     if(det>=0){
740       TVectorD X(12), Y(12), Z(12), dX(12), dY(12), dZ(12), vPt(12), dPt(12), budget(12), cCOV(12*15);
741       Double_t m(-1.);
742       m = fkTrack->GetMass();
743       if(fkMC->PropagateKalman(&X, &Y, &Z, &dX, &dY, &dZ, &vPt, &dPt, &budget, &cCOV, m)){
744         (*DebugStream()) << "MCkalman"
745           << "pdg=" << pdg
746           << "det=" << det
747           << "x="   << &X
748           << "y="   << &Y
749           << "z="   << &Z
750           << "dx="  << &dX
751           << "dy="  << &dY
752           << "dz="  << &dZ
753           << "pt="  << &vPt
754           << "dpt=" << &dPt
755           << "bgt=" << &budget
756           << "cov=" << &cCOV
757           << "\n";
758       }
759     }
760   }*/
761   AliTRDcluster *c(NULL);
762   Double_t val[kNdim+1];
763   for(Int_t ily=0; ily<AliTRDgeometry::kNlayer; ily++){
764     if(!(fTracklet = fkTrack->GetTracklet(ily)))/* ||
765        !fTracklet->IsOK())*/ continue;
766
767     x= x0 = fTracklet->GetX();
768     Bool_t rc(fTracklet->IsRowCross()); Float_t eta, phi;
769     if(!fkMC->GetDirections(x0, y0, z0, dydx0, dzdx0, pt0, eta, phi, s)) continue;
770
771     // MC track position at reference radial position
772     dx  = x0 - x;
773     Float_t ymc = y0 - dx*dydx0;
774     Float_t zmc = z0 - dx*dzdx0;
775     //phi -= TMath::Pi();
776
777     val[kBC]  = ily;
778     val[kPhi] = phi;
779     val[kEta] = eta;
780     val[kSpeciesChgRC]= rc?0.:sign*sIdx;
781     val[kPt]  = pt0<0.8?0:(pt0<1.5?1:2);//GetPtBin(pt0);
782     Double_t tilt(fTracklet->GetTilt());
783 //             ,t2(tilt*tilt)
784 //             ,corr(1./(1. + t2))
785 //             ,cost(TMath::Sqrt(corr));
786
787     AliExternalTrackParam *tin(fkTrack->GetTrackIn());
788     if(ily==0 && tin){ // trackIn residuals
789       // check radial position
790       if(TMath::Abs(tin->GetX()-x)>1.e-3) AliDebug(1, Form("TrackIn radial mismatch. dx[cm]=%+4.1f", tin->GetX()-x));
791       else{
792         val[kBC]          = (bc>=kNbunchCross)?(kNbunchCross-1):bc;
793         val[kYrez]        = tin->GetY()-ymc;
794         val[kZrez]        = rc?(tin->GetZ()-zmc):(fTracklet->GetdQdl()*1.8e-4 - 0.9);
795         val[kPrez]        = (TMath::ASin(tin->GetSnp())-TMath::ATan(dydx0))*TMath::RadToDeg();
796         if((H = (THnSparseI*)fContainer->At(kMCtrackIn))) H->Fill(val);
797       }
798     }
799     //if(bc>1) break; // do nothing for the rest of TRD objects if satellite bunch
800
801     // track residuals
802     dydx = fTracklet->GetYref(1);
803     dzdx = fTracklet->GetZref(1);
804     dzdl = fTracklet->GetTgl();
805     y  = fTracklet->GetYref(0);
806     dy = y - ymc;
807     z  = fTracklet->GetZref(0);
808     dz = z - zmc;
809     pt = TMath::Abs(fTracklet->GetPt());
810     fTracklet->GetCovRef(covR);
811
812     val[kYrez] = dy;
813     val[kPrez] = TMath::ATan((dydx - dydx0)/(1.+ dydx*dydx0))*TMath::RadToDeg();
814     val[kZrez] = dz;
815     val[kNdim] = 1.e2*(pt/pt0-1.);
816     if((H = (THnSparse*)fContainer->At(kMCtrack))) H->Fill(val);
817 /*      // theta resolution/ tgl pulls
818       Double_t dzdl0 = dzdx0/TMath::Sqrt(1.+dydx0*dydx0),
819                 dtgl = (dzdl - dzdl0)/(1.- dzdl*dzdl0);
820       ((TH2I*)arr->At(6))->Fill(dzdl0, TMath::ATan(dtgl));
821       ((TH2I*)arr->At(7))->Fill(dzdl0, (dzdl - dzdl0)/TMath::Sqrt(covR[4]));
822       // pt resolution  \\ 1/pt pulls \\ p resolution for PID
823       Double_t p0 = TMath::Sqrt(1.+ dzdl0*dzdl0)*pt0,
824               p  = TMath::Sqrt(1.+ dzdl*dzdl)*pt;
825       ((TH3S*)((TObjArray*)arr->At(8)))->Fill(pt0, pt/pt0-1., sign*sIdx);
826       ((TH3S*)((TObjArray*)arr->At(9)))->Fill(1./pt0, (1./pt-1./pt0)/TMath::Sqrt(covR[6]), sign*sIdx);
827       ((TH3S*)((TObjArray*)arr->At(10)))->Fill(p0, p/p0-1., sign*sIdx);*/
828
829     // Fill Debug stream for MC track
830     if(DebugLevel()>=4){
831       Int_t det(fTracklet->GetDetector());
832       (*DebugStream()) << "MC"
833         << "det="     << det
834         << "pdg="     << pdg
835         << "sgn="     << sign
836         << "pt="      << pt0
837         << "x="       << x0
838         << "y="       << y0
839         << "z="       << z0
840         << "dydx="    << dydx0
841         << "dzdx="    << dzdx0
842         << "\n";
843
844       // Fill Debug stream for Kalman track
845       (*DebugStream()) << "MCtrack"
846         << "pt="      << pt
847         << "x="       << x
848         << "y="       << y
849         << "z="       << z
850         << "dydx="    << dydx
851         << "dzdx="    << dzdx
852         << "s2y="     << covR[0]
853         << "s2z="     << covR[2]
854         << "\n";
855     }
856
857     // tracklet residuals
858     dydx = fTracklet->GetYfit(1) + tilt*dzdx0;
859     dzdx = fTracklet->GetZfit(1);
860     y  = fTracklet->GetYfit(0);
861     dy = y - ymc;
862     z  = fTracklet->GetZfit(0);
863     dz = z - zmc;
864     val[kYrez] = dy - dz*tilt;
865     val[kPrez] = TMath::ATan((dydx - dydx0)/(1.+ dydx*dydx0))*TMath::RadToDeg();
866     val[kZrez] = rc?(dz + dy*tilt):(fTracklet->GetdQdl()*3.e-4 - 1.5);
867 //      val[kNdim] = pt/pt0-1.;
868     if((H = (THnSparse*)fContainer->At(kMCtracklet))) H->Fill(val);
869
870
871     // Fill Debug stream for tracklet
872     if(DebugLevel()>=4){
873       Float_t s2y = fTracklet->GetS2Y();
874       Float_t s2z = fTracklet->GetS2Z();
875       (*DebugStream()) << "MCtracklet"
876         << "rc="    << rc
877         << "x="     << x
878         << "y="     << y
879         << "z="     << z
880         << "dydx="  << dydx
881         << "s2y="   << s2y
882         << "s2z="   << s2z
883         << "\n";
884     }
885
886     AliTRDpadPlane *pp = geo->GetPadPlane(ily, AliTRDgeometry::GetStack(fTracklet->GetDetector()));
887     Float_t zr0 = pp->GetRow0() + pp->GetAnodeWireOffset();
888     //Double_t exb = AliTRDCommonParam::Instance()->GetOmegaTau(1.5);
889
890     H = (THnSparse*)fContainer->At(kMCcluster);
891     val[kPt]  = TMath::ATan(dydx0)*TMath::RadToDeg();
892     //Float_t corr = 1./TMath::Sqrt(1.+dydx0*dydx0+dzdx0*dzdx0);
893     Int_t row0(-1);
894     Float_t padCorr(tilt*fTracklet->GetPadLength());
895     fTracklet->ResetClusterIter(kTRUE);
896     while((c = fTracklet->NextCluster())){
897       if(row0<0) row0 = c->GetPadRow();
898       x = c->GetX();//+fXcorr[c->GetDetector()][c->GetLocalTimeBin()];
899       y = c->GetY()  + padCorr*(c->GetPadRow() - row0);
900       z = c->GetZ();
901       dx = x0 - x;
902       ymc= y0 - dx*dydx0;
903       zmc= z0 - dx*dzdx0;
904       dy = y - ymc;
905       dz = z - zmc;
906       val[kYrez] = dy - dz*tilt;
907       val[kPrez] = dx;
908       val[kZrez] = 0.; AliTRDcluster *cc(NULL); Int_t ic(0), tb(c->GetLocalTimeBin()); Float_t  q(TMath::Abs(c->GetQ()));
909       if((cc = fTracklet->GetClusters(tb-1))) {val[kZrez] += TMath::Abs(cc->GetQ()); ic++;}
910       if((cc = fTracklet->GetClusters(tb-2))) {val[kZrez] += TMath::Abs(cc->GetQ()); ic++;}
911       if(ic) val[kZrez] /= (ic*q);
912       if(H) H->Fill(val);
913
914
915       // Fill calibration container
916       Float_t d = zr0 - zmc;
917       d -= ((Int_t)(2 * d)) / 2.0;
918       if (d > 0.25) d  = 0.5 - d;
919       AliTRDclusterInfo *clInfo = new AliTRDclusterInfo;
920       clInfo->SetCluster(c);
921       clInfo->SetMC(pdg, label);
922       clInfo->SetGlobalPosition(ymc, zmc, dydx0, dzdx0);
923       clInfo->SetResolution(dy);
924       clInfo->SetAnisochronity(d);
925       clInfo->SetDriftLength(dx);
926       clInfo->SetTilt(tilt);
927       if(fMCcl) fMCcl->Add(clInfo);
928       else AliDebug(1, "MCcl exchange container missing. Activate by calling \"InitExchangeContainers()\"");
929       if(DebugLevel()>=5){
930         if(!clInfoArr){
931           clInfoArr=new TObjArray(AliTRDseedV1::kNclusters);
932           clInfoArr->SetOwner(kFALSE);
933         }
934         clInfoArr->Add(clInfo);
935       }
936     }
937     // Fill Debug Tree
938     if(DebugLevel()>=5 && clInfoArr){
939       (*DebugStream()) << "MCcluster"
940         <<"clInfo.=" << clInfoArr
941         << "\n";
942       clInfoArr->Clear();
943     }
944   }
945   if(clInfoArr) delete clInfoArr;
946   if(!track) return NULL;
947   // special care for EVE usage
948   if(H && (h = (TH1*)gDirectory->Get(Form("%s_proj_%d", H->GetName(), kYrez)))) delete h;
949   return H?H->Projection(kYrez):NULL;
950 }
951
952
953 //__________________________________________________________________________
954 Int_t AliTRDresolution::GetPtBin(Float_t pt)
955 {
956 // Find pt bin according to local pt segmentation
957   Int_t ipt(-1);
958   while(ipt<24){
959     if(pt<fgPtBin[ipt+1]) break;
960     ipt++;
961   }
962   return ipt;
963 }
964
965
966 //________________________________________________________
967 void AliTRDresolution::GetRangeZ(TH2 *h2, Float_t &min, Float_t &max)
968 {
969 // Get range on Z axis such to avoid outliers
970
971   Double_t cnt[20000], c, m, s;
972   Int_t nx(h2->GetXaxis()->GetNbins()), ny(h2->GetYaxis()->GetNbins()), nc(0);
973   for(Int_t ix(1); ix<=nx; ix++){
974     for(Int_t iy(1); iy<=ny; iy++){
975       if((c = h2->GetBinContent(ix, iy))<10) continue;
976       cnt[nc++] = c;
977       if(nc==20000) break;
978     }
979     if(nc==20000) break;
980   }
981   AliMathBase::EvaluateUni(nc, cnt, m, s, 0);
982   min = m-s; max = m+2.*s;
983 }
984
985 //________________________________________________________
986 Bool_t AliTRDresolution::GetRefFigure(Int_t ifig)
987 {
988   //
989   // Get the reference figures
990   //
991
992   if(!gPad){
993     AliWarning("Please provide a canvas to draw results.");
994     return kFALSE;
995   }
996 /*  Int_t selection[100], n(0), selStart(0); //
997   Int_t ly0(0), dly(5);
998   TList *l(NULL); TVirtualPad *pad(NULL); */
999   switch(ifig){
1000   case 0:
1001     break;
1002   }
1003   AliWarning(Form("Reference plot [%d] missing result", ifig));
1004   return kFALSE;
1005 }
1006
1007
1008 //________________________________________________________
1009 void AliTRDresolution::MakePtSegmentation(Float_t pt0, Float_t dpt)
1010 {
1011 // Build pt segments
1012   for(Int_t j(0); j<=24; j++){
1013     pt0+=(TMath::Exp(j*j*dpt)-1.);
1014     fgPtBin[j]=pt0;
1015   }
1016 }
1017
1018 //________________________________________________________
1019 void AliTRDresolution::MakeSummary()
1020 {
1021 // Build summary plots
1022
1023   if(!fProj){
1024     AliError("Missing results");
1025     return;
1026   }
1027   TVirtualPad *p(NULL); TCanvas *cOut(NULL);
1028   TObjArray *arr(NULL); TH2 *h2(NULL);
1029
1030   // cluster resolution
1031   // define palette
1032   gStyle->SetPalette(1);
1033   const Int_t nClViews(9);
1034   const Char_t *vClName[nClViews] = {"ClY", "ClYn", "ClYp", "ClQn", "ClQp", "ClYXTCp", "ClYXTCn", "ClYXPh", "ClYXPh"};
1035   const UChar_t vClOpt[nClViews] = {1, 1, 1, 0, 0, 0, 0, 0, 1};
1036   const Float_t vClSignMin[2] = {2.6e2, 4.4e2},
1037                 vClSignMax[2] = {4.4e2, 6.2e2},
1038                 vClMin[nClViews] = {3.2e2, vClSignMin[Int_t(fBsign)], vClSignMin[Int_t(!fBsign)], 0., 0., 0., 0., 0., 3.2e2},
1039                 vClMax[nClViews] = {5.e2, vClSignMax[Int_t(fBsign)], vClSignMax[Int_t(!fBsign)], 0., 0., 0., 0., 0., 5.e2};
1040   const Int_t nTrkltViews(20);
1041   const Char_t *vTrkltName[nTrkltViews] = {
1042     "TrkltY", "TrkltYn", "TrkltYp", "TrkltY", "TrkltYn", "TrkltYp",
1043     "TrkltRCZ",
1044     "TrkltPh", "TrkltPhn", "TrkltPhp",
1045     "TrkltQ", "TrkltQn", "TrkltQp",
1046     "TrkltQS", "TrkltQSn", "TrkltQSp",
1047     "TrkltTBn", "TrkltTBp", "TrkltTBn", "TrkltTBp"
1048 //    "TrkltYnl0", "TrkltYpl0", "TrkltPhnl0", "TrkltPhpl0", "TrkltQnl0", "TrkltQpl0",  // electrons low pt
1049 /*    "TrkltYnl1", "TrkltYpl1", "TrkltPhnl1", "TrkltPhpl1", "TrkltQnl1", "TrkltQpl1",  // muons low pt
1050     "TrkltYnl2", "TrkltYpl2", "TrkltPhnl2", "TrkltPhpl2", "TrkltQnl2", "TrkltQpl2"  // pions low pt*/
1051   };
1052   const UChar_t vTrkltOpt[nTrkltViews] = {
1053     0, 0, 0, 1, 1, 1,
1054     0,
1055     0, 0, 0,
1056     0, 0, 0,
1057     0, 0, 0,
1058     0, 0, 2, 2
1059   };
1060   const Int_t nTrkInViews(5);
1061   const Char_t *vTrkInName[nTrkInViews][6] = {
1062     {"TrkInY", "TrkInYn", "TrkInYp", "TrkInRCZ", "TrkInPhn", "TrkInPhp"},
1063     {"TrkInY", "TrkInYn", "TrkInYp", "TrkInRCZ", "TrkInPhn", "TrkInPhp"},
1064     {"TrkInYnl", "TrkInYni", "TrkInYnh", "TrkInYpl", "TrkInYpi", "TrkInYph"},
1065     {"TrkInXnl", "TrkInXpl", "TrkInXl", "TrkInYnh", "TrkInYph", "TrkInYh"},
1066     {"TrkInPhnl", "TrkInPhni", "TrkInPhnh", "TrkInPhpl", "TrkInPhpi", "TrkInPhph"},
1067     //{"TrkInRCX", "TrkInRCY", "TrkInRCPh", "TrkInRCZl", "TrkInRCZi", "TrkInRCZh"}
1068   };
1069   const UChar_t vTrkInOpt[nTrkInViews] = {0, 1, 0, 0, 0};
1070   const Float_t min[6] = {0.15, 0.15, 0.15, 0.15, 0.5, 0.5};
1071   const Float_t max[6] = {0.6, 0.6, 0.6, 0.6, 2.3, 2.3};
1072   const Char_t *ttt[6] = {"#sigma(#Deltay) [cm]", "#sigma(#Deltay) [cm]", "#sigma(#Deltay) [cm]", "#sigma(#Deltaz) [cm]", "#sigma(#Delta#phi) [deg]", "#sigma(#Delta#phi) [deg]"};
1073
1074   const Int_t nTrkViews(27);
1075   const Char_t *vTrkName[nTrkViews] = {
1076     "TrkY", "TrkYn", "TrkYp",
1077     "TrkPh", "TrkPhn", "TrkPhp",
1078     "TrkDPt", "TrkDPtn", "TrkDPtp",
1079     "TrkYnl0", "TrkYpl0", "TrkPhnl0", "TrkPhpl0", "TrkDPtnl0", "TrkDPtpl0",  // electrons low pt
1080     "TrkYnl1", "TrkYpl1", "TrkPhnl1", "TrkPhpl1", "TrkDPtnl1", "TrkDPtpl1",  // muons low pt
1081     "TrkYnl2", "TrkYpl2", "TrkPhnl2", "TrkPhpl2", "TrkDPtnl2", "TrkDPtpl2"  // pions low pt
1082   };
1083   const Char_t *typName[] = {"", "MC"};
1084   const Int_t nx(2048), ny(1536);
1085
1086   if((arr = (TObjArray*)fProj->At(kDetector))){
1087     cOut = new TCanvas(Form("%s_DetOccupancy", GetName()), "Detector performance", 2*nx, 2*ny);
1088     cOut->Divide(AliTRDgeometry::kNlayer,AliTRDeventInfo::kCentralityClasses, 1.e-5, 1.e-5);
1089     Int_t n=0;
1090     for(Int_t icen(0); icen<AliTRDeventInfo::kCentralityClasses; icen++){
1091       for(Int_t ily(0); ily<AliTRDgeometry::kNlayer; ily++){
1092         p=cOut->cd(icen*AliTRDgeometry::kNlayer+ily+1); p->SetRightMargin(0.1572581);p->SetTopMargin(0.08262712);
1093         if(!(h2 = (TH2*)arr->FindObject(Form("HDet%d%dEn", ily, icen)))) continue;
1094         if(SetNormZ(h2, 1, -1, 1, -1, 10.) < 1.e3) continue;  // cut all bins with < 10 entries
1095         SetRangeZ(h2, -90., 90, -200.);
1096         //h2->GetXaxis()->SetNdivisions(1010);
1097         h2->GetZaxis()->SetTitle("Rel. Det. Occup. [%]");
1098         h2->GetZaxis()->CenterTitle();
1099         h2->SetContour(9); h2->Draw("colz"); n++;
1100         MakeDetectorPlot(ily, "pad");
1101       }
1102     }
1103     if(n>=AliTRDgeometry::kNlayer) cOut->SaveAs(Form("%s.gif", cOut->GetName()));
1104
1105     cOut = new TCanvas(Form("%s_DetCharge", GetName()), "Detector performance", nx, ny);
1106     cOut->Divide(3,2, 1.e-5, 1.e-5);
1107     for(Int_t ily(0); ily<AliTRDgeometry::kNlayer; ily++){
1108       p=cOut->cd(ily+1); p->SetRightMargin(0.1572581);p->SetTopMargin(0.08262712);
1109       if(!(h2 = (TH2*)arr->FindObject(Form("HDet%d_2D", ily)))) continue;
1110       SetNormZ(h2, 1, -1, 1, -1, 10.); // cut all <q> < 10
1111       SetRangeZ(h2, -30., 30., -200.);
1112       //h2->GetXaxis()->SetNdivisions(1010);
1113       h2->GetZaxis()->SetTitle("Rel. Mean(q) [%]");
1114       h2->GetZaxis()->CenterTitle();
1115       h2->Draw("colz");
1116       MakeDetectorPlot(ily, "pad");
1117     }
1118     cOut->SaveAs(Form("%s.gif", cOut->GetName()));
1119   }
1120   for(Int_t ityp(0); ityp<(HasMCdata()?2:1); ityp++){
1121     if((arr = (TObjArray*)fProj->At(ityp?kMCcluster:kCluster))){
1122       for(Int_t iview(0); iview<nClViews; iview++){
1123         cOut = new TCanvas(Form("%s_%s%s_%d", GetName(), typName[ityp], vClName[iview], vClOpt[iview]), "Cluster Resolution", nx, ny);
1124         cOut->Divide(3,2, 1.e-5, 1.e-5);
1125         Int_t nplot(0);
1126         for(Int_t ily(0); ily<AliTRDgeometry::kNlayer; ily++){
1127           p=cOut->cd(ily+1);    p->SetRightMargin(0.1572581);p->SetTopMargin(0.08262712);
1128           if(!(h2 = (TH2*)arr->FindObject(Form("H%s%s%d_2D", typName[ityp], vClName[iview], ily)))) continue;
1129           nplot++;
1130           if(vClOpt[iview]==0) h2->Draw("colz");
1131           else if(vClOpt[iview]==1) DrawSigma(h2, "#sigma(#Deltay) [#mum]", vClMin[iview], vClMax[iview], 1.e4);
1132           if(iview<5) MakeDetectorPlot(ily);
1133         }
1134         if(nplot==AliTRDgeometry::kNlayer) cOut->SaveAs(Form("%s.gif", cOut->GetName()));
1135         else delete cOut;
1136       }
1137     }
1138     // tracklet systematic
1139     if((arr = (TObjArray*)fProj->At(ityp?kMCtracklet:kTracklet))){
1140       for(Int_t iview(0); iview<nTrkltViews; iview++){
1141         cOut = new TCanvas(Form("%s_%s%s_%d", GetName(), typName[ityp], vTrkltName[iview], vTrkltOpt[iview]), "Tracklet Resolution", nx, ny);
1142         cOut->Divide(3,2, 1.e-5, 1.e-5);
1143         Int_t nplot(0);
1144         for(Int_t iplot(0); iplot<6; iplot++){
1145           p=cOut->cd(iplot+1); p->SetRightMargin(0.1572581); p->SetTopMargin(0.08262712);
1146           if(!(h2 = (TH2*)arr->FindObject(Form("H%s%s%d_2D", typName[ityp], vTrkltName[iview], iplot)))) continue;
1147           nplot++;
1148           if(vTrkltOpt[iview]==0) h2->Draw("colz");
1149           else if (vTrkltOpt[iview]==1) DrawSigma(h2, "#sigma(#Deltay) [cm]", .15, .4);
1150           else if (vTrkltOpt[iview]==2) DrawSigma(h2, "#sigma(occupancy) [%]", 10.5, 15.);
1151           MakeDetectorPlot(iplot);
1152         }
1153         if(nplot==6){
1154           cOut->Modified();cOut->Update();
1155           cOut->SaveAs(Form("%s.gif", cOut->GetName()));
1156         }
1157         delete cOut;
1158       }
1159     }
1160     // trackIn systematic
1161     if((arr = (TObjArray*)fProj->At(ityp?kMCtrackIn:kTrackIn))){
1162       for(Int_t iview(0); iview<nTrkInViews; iview++){
1163         cOut = new TCanvas(Form("%s_%s%s_%d", GetName(), typName[ityp], vTrkInName[iview][0], vTrkInOpt[iview]), "Track IN Resolution", nx, ny);
1164         cOut->Divide(3,2, 1.e-5, 1.e-5);
1165         Int_t nplot(0);
1166         for(Int_t iplot(0); iplot<6; iplot++){
1167           p=cOut->cd(iplot+1); p->SetRightMargin(0.1572581); p->SetTopMargin(0.08262712);
1168           if(!(h2 = (TH2*)arr->FindObject(Form("H%s%s_2D", typName[ityp], vTrkInName[iview][iplot])))){
1169             AliInfo(Form("Missing H%s%s_2D", typName[ityp], vTrkInName[iview][iplot]));
1170             continue;
1171           }
1172           nplot++;
1173           if(vTrkInOpt[iview]==0){
1174             h2->Draw("colz");
1175             PutTrendValue(vTrkInName[iview][iplot], GetMeanStat(h2, -10., ">"));
1176           } else DrawSigma(h2, ttt[iplot], min[iplot], max[iplot]);
1177           MakeDetectorPlot(0);
1178         }
1179         if(nplot==6) cOut->SaveAs(Form("%s.gif", cOut->GetName()));
1180         else delete cOut;
1181       }
1182       // species
1183       const Float_t zmin[] = {1., 61., 15.},
1184                     zmax[] = {10., 79., 33.};
1185       cOut = new TCanvas(Form("%s_%sTrkInSpc", GetName(), typName[ityp]), "Track IN PID", Int_t(1.5*ny), Int_t(1.5*ny));
1186       cOut->Divide(3,3, 1.e-5, 1.e-5);
1187       Int_t nplot(0); const Char_t *chName[] = {"p", "n", ""};
1188       for(Int_t ich(0), ipad(1); ich<3; ich++){
1189         TH2 *h2s(NULL);
1190         if(!(h2s = (TH2*)arr->FindObject(Form("H%sTrkInY%sEn", typName[ityp], chName[ich])))) {
1191           AliInfo(Form("Missing H%sTrkIn%sEn", typName[ityp], chName[ich]));
1192           continue;
1193         }
1194         for(Int_t ispec(0); ispec<kNspc; ispec++){
1195           p=cOut->cd(ipad++); p->SetRightMargin(0.1572581); p->SetTopMargin(0.08262712);
1196           if(!(h2 = (TH2*)arr->FindObject(Form("H%sTrkInY%s%dEn", typName[ityp], chName[ich], ispec)))) {
1197             AliInfo(Form("Missing H%sTrkIn%s%dEn", typName[ityp], chName[ich], ispec));
1198             continue;
1199           }
1200           nplot++;
1201           h2->Divide(h2, h2s, 1.e2);
1202           h2->SetContour(9);
1203           h2->GetZaxis()->SetRangeUser(zmin[ispec], zmax[ispec]);
1204           h2->GetZaxis()->SetTitle("Rel. Abundancy [%]");h2->GetZaxis()->CenterTitle();
1205           TString tit(h2->GetTitle()); h2->SetTitle(Form("%s :: Relative Abundancy", ((*(tit.Tokenize("::")))[0])->GetName()));
1206           h2->Draw("colz");
1207           MakeDetectorPlot(0);
1208         }
1209       }
1210       if(nplot==9) cOut->SaveAs(Form("%s.gif", cOut->GetName()));
1211       else delete cOut;
1212
1213       const char *chQ[] = {"Q", "QS"};
1214       for(Int_t iq(0); iq<2; iq++){
1215         cOut = new TCanvas(Form("%s_%sTrkIn%s", GetName(), typName[ityp], chQ[iq]), "Track IN PID", Int_t(1.5*ny), Int_t(1.5*ny));
1216         cOut->Divide(3,3, 1.e-5, 1.e-5);
1217         nplot=0;
1218         for(Int_t ich(0), ipad(1); ich<3; ich++){
1219           for(Int_t ispec(0); ispec<kNspc; ispec++){
1220             p=cOut->cd(ipad++); p->SetRightMargin(0.1572581); p->SetTopMargin(0.08262712);
1221             if(!(h2 = (TH2*)arr->FindObject(Form("H%sTrkIn%s%s%d_2D", typName[ityp], chQ[iq], chName[ich], ispec)))) {
1222               AliInfo(Form("Missing H%sTrkIn%s%s%d_2D", typName[ityp], chQ[iq], chName[ich], ispec));
1223               continue;
1224             }
1225             nplot++;
1226             h2->Draw("colz");
1227             PutTrendValue(Form("TrkIn%s%s%d", chQ[iq], chName[ich], ispec), GetMeanStat(h2, -10., ">"));
1228             MakeDetectorPlot(0);
1229           }
1230         }
1231         if(nplot==9) cOut->SaveAs(Form("%s.gif", cOut->GetName()));
1232         else delete cOut;
1233       }
1234     }
1235   }
1236   // track MC systematic
1237   if((arr = (TObjArray*)fProj->At(kMCtrack))) {
1238     for(Int_t iview(0); iview<nTrkViews; iview++){
1239       cOut = new TCanvas(Form("%s_MC%s", GetName(), vTrkName[iview]), "Track Resolution", nx, ny);
1240       cOut->Divide(3,2, 1.e-5, 1.e-5);
1241       Int_t nplot(0);
1242       for(Int_t iplot(0); iplot<6; iplot++){
1243         p=cOut->cd(iplot+1); p->SetRightMargin(0.1572581); p->SetTopMargin(0.08262712);
1244         if(!(h2 = (TH2*)arr->FindObject(Form("HMC%s%d_2D", vTrkName[iview], iplot)))) continue;
1245         h2->Draw("colz"); nplot++;
1246       }
1247       if(nplot==6) cOut->SaveAs(Form("%s.gif", cOut->GetName()));
1248       else delete cOut;
1249     }
1250   }
1251
1252
1253   gStyle->SetPalette(1);
1254 }
1255
1256 //________________________________________________________
1257 void AliTRDresolution::DrawSigma(TH2 *h2, const Char_t *title, Float_t m, Float_t M, Float_t scale)
1258 {
1259   // Draw error bars scaled with "scale" instead of content values
1260   //use range [m,M] if limits are specified
1261
1262   if(!h2) return;
1263   TAxis *ax(h2->GetXaxis()), *ay(h2->GetYaxis());
1264   TH2F *h2e = new TH2F(Form("%s_E", h2->GetName()),
1265                 Form("%s;%s;%s;%s", h2->GetTitle(), ax->GetTitle(), ay->GetTitle(), title),
1266                 ax->GetNbins(), ax->GetXmin(), ax->GetXmax(),
1267                 ay->GetNbins(), ay->GetXmin(), ay->GetXmax());
1268   h2e->SetContour(9);
1269   TAxis *az(h2e->GetZaxis());
1270   if(M>m) az->SetRangeUser(m, M);
1271   az->CenterTitle();
1272   az->SetTitleOffset(1.5);
1273   for(Int_t ix(1); ix<=h2->GetNbinsX(); ix++){
1274     for(Int_t iy(1); iy<=h2->GetNbinsY(); iy++){
1275       if(h2->GetBinContent(ix, iy)<-100.) continue;
1276       Float_t v(scale*h2->GetBinError(ix, iy));
1277       if(M>m && v<m) v=m+TMath::Abs((M-m)*1.e-3);
1278       h2e->SetBinContent(ix, iy, v);
1279     }
1280   }
1281   h2e->Draw("colz");
1282 }
1283
1284 //________________________________________________________
1285 void AliTRDresolution::GetRange(TH2 *h2, Char_t mod, Float_t *range)
1286 {
1287 // Returns the range of the bulk of data in histogram h2. Removes outliers.
1288 // The "range" vector should be initialized with 2 elements
1289 // Option "mod" can be any of
1290 //   - 0 : gaussian like distribution
1291 //   - 1 : tailed distribution
1292
1293   Int_t nx(h2->GetNbinsX())
1294       , ny(h2->GetNbinsY())
1295       , n(nx*ny);
1296   Double_t *data=new Double_t[n];
1297   for(Int_t ix(1), in(0); ix<=nx; ix++){
1298     for(Int_t iy(1); iy<=ny; iy++)
1299       data[in++] = h2->GetBinContent(ix, iy);
1300   }
1301   Double_t mean, sigm;
1302   AliMathBase::EvaluateUni(n, data, mean, sigm, Int_t(n*.8));
1303
1304   range[0]=mean-3.*sigm; range[1]=mean+3.*sigm;
1305   if(mod==1) range[0]=TMath::Max(Float_t(1.e-3), range[0]);
1306   AliDebug(2, Form("h[%s] range0[%f %f]", h2->GetName(), range[0], range[1]));
1307   TH1S h1("h1SF0", "", 100, range[0], range[1]);
1308   h1.FillN(n,data,0);
1309   delete [] data;
1310
1311   switch(mod){
1312   case 0:// gaussian distribution
1313   {
1314     TF1 fg("fg", "gaus", mean-3.*sigm, mean+3.*sigm);
1315     h1.Fit(&fg, "QN");
1316     mean=fg.GetParameter(1); sigm=fg.GetParameter(2);
1317     range[0] = mean-2.5*sigm;range[1] = mean+2.5*sigm;
1318     AliDebug(2, Form("     rangeG[%f %f]", range[0], range[1]));
1319     break;
1320   }
1321   case 1:// tailed distribution
1322   {
1323     Int_t bmax(h1.GetMaximumBin());
1324     Int_t jBinMin(1), jBinMax(100);
1325     for(Int_t ibin(bmax); ibin--;){
1326       if(h1.GetBinContent(ibin)<1.){
1327         jBinMin=ibin; break;
1328       }
1329     }
1330     for(Int_t ibin(bmax); ibin++;){
1331       if(h1.GetBinContent(ibin)<1.){
1332         jBinMax=ibin; break;
1333       }
1334     }
1335     range[0]=h1.GetBinCenter(jBinMin); range[1]=h1.GetBinCenter(jBinMax);
1336     AliDebug(2, Form("     rangeT[%f %f]", range[0], range[1]));
1337     break;
1338   }
1339   }
1340
1341   return;
1342 }
1343
1344 //________________________________________________________
1345 Bool_t AliTRDresolution::MakeProjectionDetector()
1346 {
1347 // Analyse cluster
1348   const Int_t kNcontours(9);
1349   const Int_t kNstat(100);
1350   if(fProj && fProj->At(kDetector)) return kTRUE;
1351   if(!fContainer){
1352     AliError("Missing data container.");
1353     return kFALSE;
1354   }
1355   THnSparse *H(NULL);
1356   if(!(H = (THnSparse*)fContainer->FindObject("hDet2Cluster"))){
1357     AliInfo(Form("Missing/Wrong data @ hDet2Cluster."));
1358     return kTRUE;
1359   }
1360   Int_t ndim(H->GetNdimensions());
1361   Int_t coord[kNdim]; memset(coord, 0, sizeof(Int_t) * kNdim); Double_t v = 0.;
1362   TAxis *aa[kNdim], *an(NULL); memset(aa, 0, sizeof(TAxis*) * kNdim);
1363   for(Int_t id(0); id<ndim; id++) aa[id] = H->GetAxis(id);
1364   if(ndim < 5) aa[4] = new TAxis(1, -0.5, 0.5);
1365   Int_t nPad(1);
1366   if(ndim > 5){
1367     an = H->GetAxis(5);
1368     nPad = kNpads+1;
1369   }
1370   // build list of projections
1371   const Int_t nsel(8*AliTRDgeometry::kNlayer*AliTRDeventInfo::kCentralityClasses);
1372   // define rebinning strategy
1373   const Int_t nEtaPhi(4); Int_t rebinEtaPhiX[nEtaPhi] = {1, 2, 2, 1}, rebinEtaPhiY[nEtaPhi] = {2, 1, 1, 5};
1374   //const Char_t *cenName[AliTRDeventInfo::kCentralityClasses] = {"0-10%", "10-20%", "20-50%", "50-80%", "80-100%"};
1375   const Char_t *cenName[AliTRDeventInfo::kCentralityClasses] = {"2800-inf", "2100-2799", "1400-2099", "700-1399", "0-699"};
1376   AliTRDrecoProjection hp[kDetNproj];  TObjArray php(kDetNproj);
1377   Int_t ih(0), isel(-1), np[nsel]; memset(np, 0, nsel*sizeof(Int_t));
1378   for(Int_t ipad(0); ipad<nPad; ipad++){
1379     for(Int_t icen(0); icen<AliTRDeventInfo::kCentralityClasses; icen++){
1380       for(Int_t ily(0); ily<AliTRDgeometry::kNlayer; ily++){
1381         isel++; // new selection
1382         hp[ih].Build(Form("HDet%d%d%d", ily, icen, ipad),
1383                     Form("Detectors :: Ly[%d] Cen[%s] Pads[%s]", ily, cenName[icen], ipad?(ipad<kNpads?Form("%d", ipad+1):Form(">%d", kNpads)):"deconv"),
1384                     kEta, kPhi, 4, aa);
1385         hp[ih].SetRebinStrategy(nEtaPhi, rebinEtaPhiX, rebinEtaPhiY);
1386         hp[ih].SetShowRange(10., 55.);
1387         php.AddLast(&hp[ih++]); np[isel]++;
1388       }
1389     }
1390   }
1391   AliInfo(Form("Build %3d 3D projections.", ih));
1392
1393   Int_t ly(0), cen(0), npad(0);
1394   for (Long64_t ib(0); ib < H->GetNbins(); ib++) {
1395     v = H->GetBinContent(ib, coord); if(v<1.) continue;
1396     ly = coord[kBC]-1;    // layer selection
1397     cen = coord[kYrez]-1; // centrality selection
1398     npad = 0;             // no. of pads selection
1399     if(an) npad = TMath::Min(coord[5]-1, Int_t(kNpads));
1400     isel = npad*AliTRDeventInfo::kCentralityClasses*AliTRDgeometry::kNlayer+cen*AliTRDgeometry::kNlayer+ly;
1401     ((AliTRDrecoProjection*)php.At(isel))->Increment(coord, v);
1402     //Int_t ioff=isel;for(Int_t jh(0); jh<np[isel]; jh++) ((AliTRDrecoProjection*)php.At(ioff+jh))->Increment(coord, v);
1403   }
1404   TObjArray *arr(NULL);
1405   fProj->AddAt(arr = new TObjArray(kDetNproj), kDetector);
1406
1407   TH2 *h2(NULL);  Int_t jh(0);
1408   for(; ih--; ){
1409     if(!hp[ih].H()) continue;
1410     if(!(h2 = hp[ih].Projection2D(kNstat, kNcontours, 0, kFALSE))) continue;
1411     arr->AddAt(h2, jh++);
1412     if(!(h2 = (TH2*)gDirectory->Get(Form("%sEn", hp[ih].H()->GetName())))) continue;
1413     arr->AddAt(h2, jh++);
1414   }
1415   AliTRDrecoProjection *pr0(NULL), *pr1(NULL);
1416   for(Int_t ily(0); ily<AliTRDgeometry::kNlayer; ily++){
1417     for(Int_t icen(0); icen<AliTRDeventInfo::kCentralityClasses; icen++){
1418       if((pr0 = (AliTRDrecoProjection*)php.FindObject(Form("HDet%d%d%d", ily, icen, 0)))){
1419         for(Int_t ipad(1); ipad<nPad; ipad++){
1420           if((pr1 = (AliTRDrecoProjection*)php.FindObject(Form("HDet%d%d%d", ily, icen, ipad)))){
1421             (*pr0)+=(*pr1);
1422           }
1423         }
1424         pr0->H()->SetNameTitle(Form("HDet%d%d", ily, icen), Form("Detectors :: Ly[%d] Cen[%s]", ily, cenName[icen]));
1425         if((h2 = pr0->Projection2D(kNstat, kNcontours, 0, kFALSE))) arr->AddAt(h2, jh++);
1426         if((h2 = (TH2*)gDirectory->Get(Form("%sEn", pr0->H()->GetName())))) arr->AddAt(h2, jh++);
1427         if(icen && (pr1 = (AliTRDrecoProjection*)php.FindObject(Form("HDet%d%d%d", ily, 0, 0)))) (*pr1)+=(*pr0);
1428       }
1429     }
1430     if((pr0 = (AliTRDrecoProjection*)php.FindObject(Form("HDet%d%d%d", ily, 0, 0)))){
1431       pr0->H()->SetNameTitle(Form("HDet%d", ily), Form("Detectors :: Ly[%d]", ily));
1432       if((h2 = pr0->Projection2D(kNstat, kNcontours))) arr->AddAt(h2, jh++);
1433     }
1434   }
1435   AliInfo(Form("Done %3d 2D projections.", jh));
1436   return kTRUE;
1437 }
1438
1439 //________________________________________________________
1440 Bool_t AliTRDresolution::MakeProjectionCluster(Bool_t mc)
1441 {
1442 // Analyse cluster
1443   const Int_t kNcontours(9);
1444   const Int_t kNstat(100);
1445   Int_t cidx=mc?kMCcluster:kCluster;
1446   if(fProj && fProj->At(cidx)) return kTRUE;
1447   if(!fContainer){
1448     AliError("Missing data container.");
1449     return kFALSE;
1450   }
1451   const Char_t *projName[] = {"hCluster2Track", "hCluster2MC"};
1452   THnSparse *H(NULL);
1453   if(!(H = (THnSparse*)fContainer->FindObject(projName[Int_t(mc)]))){
1454     AliError(Form("Missing/Wrong data @ %s.", projName[Int_t(mc)]));
1455     return kFALSE;
1456   }
1457   Int_t ndim(H->GetNdimensions()); Bool_t debug(ndim>Int_t(kNdimCl));
1458   Int_t coord[10]; memset(coord, 0, sizeof(Int_t) * 10); Double_t v = 0.;
1459   TAxis *aa[kNdim], *as(NULL), *apt(NULL), *acen(NULL), *anp(NULL); memset(aa, 0, sizeof(TAxis*) * kNdim);
1460   for(Int_t id(0); id<ndim; id++) aa[id] = H->GetAxis(id);
1461   if(ndim > Int_t(kPt)) apt = H->GetAxis(kPt);
1462   if(ndim > Int_t(kSpeciesChgRC)) as  = H->GetAxis(kSpeciesChgRC);
1463   if(ndim > Int_t(kNdim)) acen  = H->GetAxis(kNdim);
1464   if(ndim > Int_t(kNdim)+1) anp  = H->GetAxis(kNdim+1);
1465   // calculate size depending on debug level
1466   const Int_t nCh(apt?2:1);
1467   const Int_t nCen(acen?Int_t(AliTRDeventInfo::kCentralityClasses):1);
1468   const Int_t nNpad(anp?(Int_t(kNpads)+1):1);
1469   
1470   // build list of projections
1471   const Int_t nsel(AliTRDgeometry::kNlayer*kNcharge*(kNpads+1)*AliTRDeventInfo::kCentralityClasses);
1472   // define rebinning strategy
1473   const Int_t nEtaPhi(4); Int_t rebinEtaPhiX[nEtaPhi] = {1, 2, 5, 1}, rebinEtaPhiY[nEtaPhi] = {2, 1, 1, 5};
1474   AliTRDrecoProjection hp[kClNproj];  TObjArray php(kClNproj);
1475   const Char_t chName[kNcharge] = {'n', 'p'};const Char_t chSgn[kNcharge] = {'-', '+'};
1476   const Char_t *cenName[AliTRDeventInfo::kCentralityClasses] = {"2800-inf", "2100-2799", "1400-2099", "700-1399", "0-699"};
1477   Int_t ih(0), isel(-1), np[nsel]; memset(np, 0, nsel*sizeof(Int_t));
1478   for(Int_t ily(0); ily<AliTRDgeometry::kNlayer; ily++){
1479     for(Int_t ich(0); ich<nCh; ich++){
1480       for(Int_t icen(0); icen<nCen; icen++){
1481         for(Int_t ipad(0); ipad<nNpad; ipad++){
1482           isel++; // new selection
1483           hp[ih].Build(Form("H%sClY%c%d%d%d", mc?"MC":"", chName[ich], ily, icen, ipad),
1484                       Form("Clusters[%c] :: #Deltay Ly[%d] Cen[%s] Pads[%s]", chSgn[ich], ily, cenName[icen], ipad?(ipad<kNpads?Form("%d", ipad+1):Form(">%d", kNpads)):"deconv"),
1485                       kEta, kPhi, kYrez, aa);
1486           hp[ih].SetRebinStrategy(nEtaPhi, rebinEtaPhiX, rebinEtaPhiY);
1487           php.AddLast(&hp[ih++]); np[isel]++;
1488           if(!debug) break;
1489           hp[ih].Build(Form("H%sClQ%c%d%d%d", mc?"MC":"", chName[ich], ily, icen, ipad),
1490                       Form("Clusters[%c] :: Q Ly[%d] Cen[%s] Pads[%s]", chSgn[ich], ily, cenName[icen], ipad?(ipad<kNpads?Form("%d", ipad+1):Form(">%d", kNpads)):"deconv"),
1491                       kEta, kPhi, kSpeciesChgRC, aa);
1492           hp[ih].SetRebinStrategy(nEtaPhi, rebinEtaPhiX, rebinEtaPhiY);
1493           hp[ih].SetShowRange(24., 33.);
1494           php.AddLast(&hp[ih++]); np[isel]++;
1495           hp[ih].Build(Form("H%sClYXTC%c%d%d%d", mc?"MC":"", chName[ich], ily, icen, ipad),
1496                       Form("Clusters[%c] :: #Deltay(x,TC) Ly[%d] Cen[%s] Pads[%s]", chSgn[ich], ily, cenName[icen], ipad?(ipad<kNpads?Form("%d", ipad+1):Form(">%d", kNpads)):"deconv"),
1497                       kPrez, kZrez, kYrez, aa);
1498           php.AddLast(&hp[ih++]); np[isel]++;
1499           hp[ih].Build(Form("H%sClYXPh%c%d%d%d", mc?"MC":"", chName[ich], ily, icen, ipad),
1500                         Form("Clusters[%c] :: #Deltay(x,#Phi) Ly[%d] Cen[%s] Pads[%s]", chSgn[ich], ily, cenName[icen], ipad?(ipad<kNpads?Form("%d", ipad+1):Form(">%d", kNpads)):"deconv"),
1501                         kPrez, kPt, kYrez, aa);
1502           php.AddLast(&hp[ih++]); np[isel]++;
1503         }
1504       }
1505     }
1506   }
1507   AliInfo(Form("Build %3d 3D projections.", ih));
1508
1509   AliTRDrecoProjection *pr0(NULL), *pr1(NULL);
1510   Int_t ly(0), ch(0), rcBin(as?as->FindBin(0.):-1), chBin(apt?apt->FindBin(0.):-1), ioff(0), cen(0), npad(0);
1511   for (Long64_t ib(0); ib < H->GetNbins(); ib++) {
1512     v = H->GetBinContent(ib, coord); if(v<1.) continue;
1513     ly = coord[kBC]-1;
1514     // RC selection
1515     if(rcBin>0 && coord[kSpeciesChgRC] == rcBin) continue;
1516
1517     // charge selection
1518     ch = 0; // [-] track
1519     if(chBin>0 && coord[kPt] > chBin) ch = 1;  // [+] track
1520     cen = 0; // centrality selection
1521     if(acen) cen = coord[kNdim]-1;
1522     npad = 0;             // no. of pads selection
1523     if(anp) npad = TMath::Min(coord[kNdim+1]-1, Int_t(kNpads));
1524
1525     if(debug){
1526       isel = ly*nCh*nCen*nNpad
1527             +ch*nCen*nNpad
1528             +cen*nNpad
1529             +npad;
1530       ioff=isel*4;
1531     } else {
1532       isel = ly; ioff = isel;
1533     }
1534     if(ioff>=ih){
1535       AliError(Form("Wrong selection %d [%3d]", ioff, ih));
1536       return kFALSE;
1537     }
1538     if(!(pr0=(AliTRDrecoProjection*)php.At(ioff))) {
1539       AliError(Form("Missing projection %d", ioff));
1540       return kFALSE;
1541     }
1542     if(strcmp(pr0->H()->GetName(), Form("H%sClY%c%d%d%d", mc?"MC":"", chName[ch], ly, cen, npad))!=0){
1543       AliError(Form("Projection mismatch :: request[H%sClY%c%d%d%d] found[%s]", mc?"MC":"", chName[ch], ly, cen, npad, pr0->H()->GetName()));
1544       return kFALSE;
1545     }
1546     for(Int_t jh(0); jh<np[isel]; jh++) ((AliTRDrecoProjection*)php.At(ioff+jh))->Increment(coord, v);
1547   }
1548   if(HasDump3DFor(kCluster)){
1549     TDirectory *cwd = gDirectory;
1550     TFile::Open(Form("ResDump_%s.root", H->GetName()), "RECREATE");
1551     for(Int_t ip(0); ip<php.GetEntriesFast(); ip++){
1552       if(!(pr0 = (AliTRDrecoProjection*)php.At(ip))) continue;
1553       if(!pr0->H()) continue;
1554       TH3 *h3=(TH3*)pr0->H()->Clone();
1555       h3->Write();
1556     }
1557     gFile->Close();
1558     cwd->cd();
1559   }
1560
1561   TObjArray *arr(NULL);
1562   fProj->AddAt(arr = new TObjArray(kClNproj), cidx);
1563
1564   TH2 *h2(NULL);  Int_t jh(0);
1565   for(; ih--; ){
1566     if(!hp[ih].H()) continue;
1567     if(strchr(hp[ih].H()->GetName(), 'Q')){
1568       if(!(h2 = hp[ih].Projection2D(kNstat, kNcontours, 0, kFALSE))) continue;
1569       arr->AddAt(h2, jh++);
1570       if(!(h2 = (TH2*)gDirectory->Get(Form("%sEn", hp[ih].H()->GetName())))) continue;
1571       arr->AddAt(h2, jh++);
1572     } else {
1573       if((h2 = hp[ih].Projection2D(kNstat, kNcontours, 1))) arr->AddAt(h2, jh++);
1574     }
1575   }
1576   for(Int_t ily(0); ily<AliTRDgeometry::kNlayer; ily++){
1577     for(Int_t ich(0); ich<nCh; ich++){
1578       for(Int_t icen(0); icen<nCen; icen++){
1579         /*!dy*/
1580         if((pr0 = (AliTRDrecoProjection*)php.FindObject(Form("H%sClY%c%d%d%d", mc?"MC":"", chName[ich], ily, icen, 0)))){
1581           for(Int_t ipad(1); ipad<nNpad; ipad++){
1582             if(!(pr1 = (AliTRDrecoProjection*)php.FindObject(Form("H%sClY%c%d%d%d", mc?"MC":"", chName[ich], ily, icen, ipad)))) continue;
1583             (*pr0)+=(*pr1);
1584           }
1585           pr0->H()->SetNameTitle(Form("H%sClY%c%d%d", mc?"MC":"", chName[ich], ily, icen), Form("Clusters[%c] :: #Deltay Ly[%d] Cen[%s]", chSgn[ich], ily, cenName[icen]));
1586           if((h2 = pr0->Projection2D(kNstat, kNcontours, 1))) arr->AddAt(h2, jh++);
1587           if(icen && (pr1 = (AliTRDrecoProjection*)php.FindObject(Form("H%sClY%c%d%d%d", mc?"MC":"", chName[ich], ily, 0, 0)))) (*pr1)+=(*pr0);
1588         }
1589         /*!Q*/
1590         if((pr0 = (AliTRDrecoProjection*)php.FindObject(Form("H%sClQ%c%d%d%d", mc?"MC":"", chName[ich], ily, icen, 0)))){
1591           for(Int_t ipad(1); ipad<nNpad; ipad++){
1592             if(!(pr1 = (AliTRDrecoProjection*)php.FindObject(Form("H%sClQ%c%d%d%d", mc?"MC":"", chName[ich], ily, icen, ipad)))) continue;
1593             (*pr0)+=(*pr1);
1594           }
1595           pr0->H()->SetNameTitle(Form("H%sClQ%c%d%d", mc?"MC":"", chName[ich], ily, icen), Form("Clusters[%c] :: Q Ly[%d] Cen[%s]", chSgn[ich], ily, cenName[icen]));
1596           if((h2 = pr0->Projection2D(kNstat, kNcontours, 2, kFALSE))) arr->AddAt(h2, jh++);
1597           if((h2 = (TH2*)gDirectory->Get(Form("%sEn", pr0->H()->GetName())))) arr->AddAt(h2, jh++);
1598           pr0->H()->SetName(Form("H%sClQS%c%d%d", mc?"MC":"", chName[ich], ily, icen));
1599           if((h2 = pr0->Projection2D(kNstat, kNcontours, 0))) arr->AddAt(h2, jh++);
1600           if(icen && (pr1 = (AliTRDrecoProjection*)php.FindObject(Form("H%sClQ%c%d%d%d", mc?"MC":"", chName[ich], ily, 0, 0)))) (*pr1)+=(*pr0);
1601         }
1602         /*!YXTC*/
1603         if((pr0 = (AliTRDrecoProjection*)php.FindObject(Form("H%sClYXTC%c%d%d%d", mc?"MC":"", chName[ich], ily, icen, 0)))){
1604           for(Int_t ipad(1); ipad<nNpad; ipad++){
1605             if(!(pr1 = (AliTRDrecoProjection*)php.FindObject(Form("H%sClYXTC%c%d%d%d", mc?"MC":"", chName[ich], ily, icen, ipad)))) continue;
1606             (*pr0)+=(*pr1);
1607           }
1608           pr0->H()->SetNameTitle(Form("H%sClYXTC%c%d%d", mc?"MC":"", chName[ich], ily, icen), Form("Clusters[%c] :: #Deltay(x,TC) Ly[%d] Cen[%s]", chSgn[ich], ily, cenName[icen]));
1609           if((h2 = pr0->Projection2D(kNstat, kNcontours, 1))) arr->AddAt(h2, jh++);
1610           if(icen && (pr1 = (AliTRDrecoProjection*)php.FindObject(Form("H%sClYXTC%c%d%d%d", mc?"MC":"", chName[ich], ily, 0, 0)))) (*pr1)+=(*pr0);
1611         }
1612         /*!YXPh*/
1613         if((pr0 = (AliTRDrecoProjection*)php.FindObject(Form("H%sClYXPh%c%d%d%d", mc?"MC":"", chName[ich], ily, icen, 0)))){
1614           for(Int_t ipad(1); ipad<nNpad; ipad++){
1615             if(!(pr1 = (AliTRDrecoProjection*)php.FindObject(Form("H%sClYXPh%c%d%d%d", mc?"MC":"", chName[ich], ily, icen, ipad)))) continue;
1616             (*pr0)+=(*pr1);
1617           }
1618           pr0->H()->SetNameTitle(Form("H%sClYXPh%c%d%d", mc?"MC":"", chName[ich], ily, icen), Form("Clusters[%c] :: #Deltay(x,#Phi) Ly[%d] Cen[%s]", chSgn[ich], ily, cenName[icen]));
1619           if((h2 = pr0->Projection2D(kNstat, kNcontours, 1))) arr->AddAt(h2, jh++);
1620           if(icen && (pr1 = (AliTRDrecoProjection*)php.FindObject(Form("H%sClYXPh%c%d%d%d", mc?"MC":"", chName[ich], ily, 0, 0)))) (*pr1)+=(*pr0);
1621         }
1622       } // end centrality integration
1623       /*!dy*/
1624       if((pr0 = (AliTRDrecoProjection*)php.FindObject(Form("H%sClY%c%d%d%d", mc?"MC":"", chName[ich], ily, 0, 0)))){
1625         pr0->H()->SetNameTitle(Form("H%sClY%c%d", mc?"MC":"", chName[ich], ily),
1626                               Form("Clusters[%c]:: #Deltay Ly[%d]", chSgn[ich], ily));
1627         if((h2 = pr0->Projection2D(kNstat, kNcontours, 1))) arr->AddAt(h2, jh++);
1628         if(ich && (pr1 = (AliTRDrecoProjection*)php.FindObject(Form("H%sClY%c%d%d%d", mc?"MC":"", chName[0], ily, 0, 0)))) (*pr1)+=(*pr0);
1629       }
1630       /*!Q*/
1631       if((pr0 = (AliTRDrecoProjection*)php.FindObject(Form("H%sClQ%c%d%d%d", mc?"MC":"", chName[ich], ily, 0, 0)))){
1632         pr0->H()->SetNameTitle(Form("H%sClQ%c%d", mc?"MC":"", chName[ich], ily),
1633                               Form("Clusters[%c]:: Q Ly[%d]", chSgn[ich], ily));
1634         if((h2 = pr0->Projection2D(kNstat, kNcontours, 2))) arr->AddAt(h2, jh++);
1635         pr0->H()->SetName(Form("H%sClQS%c%d", mc?"MC":"", chName[ich], ily));
1636         if((h2 = pr0->Projection2D(kNstat, kNcontours, 0))) arr->AddAt(h2, jh++);
1637         if(ich && (pr1 = (AliTRDrecoProjection*)php.FindObject(Form("H%sClQ%c%d%d%d", mc?"MC":"", chName[0], ily, 0, 0)))) (*pr1)+=(*pr0);
1638       }
1639       /*!YXTC*/
1640       if((pr0 = (AliTRDrecoProjection*)php.FindObject(Form("H%sClYXTC%c%d%d%d", mc?"MC":"", chName[ich], ily, 0, 0)))){
1641         pr0->H()->SetNameTitle(Form("H%sClYXTC%c%d", mc?"MC":"", chName[ich], ily),
1642                               Form("Clusters[%c]:: #Deltay(x,TC) Ly[%d]", chSgn[ich], ily));
1643         if((h2 = pr0->Projection2D(kNstat, kNcontours, 1))) arr->AddAt(h2, jh++);
1644         if(ich && (pr1 = (AliTRDrecoProjection*)php.FindObject(Form("H%sClYXTC%c%d%d%d", mc?"MC":"", chName[0], ily, 0, 0)))) (*pr1)+=(*pr0);
1645       }
1646       /*!YXPh*/
1647       if((pr0 = (AliTRDrecoProjection*)php.FindObject(Form("H%sClYXPh%c%d%d%d", mc?"MC":"", chName[ich], ily, 0, 0)))){
1648         pr0->H()->SetNameTitle(Form("H%sClYXPh%c%d", mc?"MC":"", chName[ich], ily),
1649                               Form("Clusters[%c]:: #Deltay(x,#Phi) Ly[%d]", chSgn[ich], ily));
1650         if((h2 = pr0->Projection2D(kNstat, kNcontours, 1))) arr->AddAt(h2, jh++);
1651         if(ich && (pr1 = (AliTRDrecoProjection*)php.FindObject(Form("H%sClYXPh%c%d%d%d", mc?"MC":"", chName[0], ily, 0, 0)))) (*pr1)+=(*pr0);
1652       }
1653     } // end charge integration
1654     /*!dy*/
1655     if((pr0 = (AliTRDrecoProjection*)php.FindObject(Form("H%sClY%c%d%d%d", mc?"MC":"", chName[0], ily, 0, 0)))){
1656       pr0->H()->SetNameTitle(Form("H%sClY%d", mc?"MC":"", ily), Form("Clusters :: #Deltay Ly[%d]", ily));
1657       if((h2 = pr0->Projection2D(kNstat, kNcontours, 1))) arr->AddAt(h2, jh++);
1658     }
1659     /*!YXPh*/
1660     if((pr0 = (AliTRDrecoProjection*)php.FindObject(Form("H%sClYXPh%c%d%d%d", mc?"MC":"", chName[0], ily, 0, 0)))){
1661       pr0->H()->SetNameTitle(Form("H%sClYXPh%d", mc?"MC":"", ily), Form("Clusters :: #Deltay Ly[%d]", ily));
1662       if((h2 = pr0->Projection2D(kNstat, kNcontours, 1))) arr->AddAt(h2, jh++);
1663     }
1664
1665   }
1666   AliInfo(Form("Done %3d 2D projections.", jh));
1667   return kTRUE;
1668 }
1669
1670 //________________________________________________________
1671 Bool_t AliTRDresolution::MakeProjectionTracklet(Bool_t mc)
1672 {
1673 // Analyse tracklet
1674   const Int_t kNcontours(9);
1675   const Int_t kNstat(30);
1676   const Int_t kNstatQ(30);
1677   Int_t cidx=mc?kMCtracklet:kTracklet;
1678   if(fProj && fProj->At(cidx)) return kTRUE;
1679   if(!fContainer){
1680     AliError("Missing data container.");
1681     return kFALSE;
1682   }
1683   const Char_t *projName[] = {"hTracklet2Track", "hTracklet2MC"};
1684   THnSparse *H(NULL);
1685   if(!(H = (THnSparse*)fContainer->FindObject(projName[Int_t(mc)]))){
1686     AliError(Form("Missing/Wrong data @ %s.", projName[Int_t(mc)]));
1687     return kFALSE;
1688   }
1689   const Int_t mdim(kNdim+8);
1690   Int_t ndim(H->GetNdimensions()); Bool_t debug(ndim>Int_t(kNdimTrklt));
1691   Int_t coord[mdim]; memset(coord, 0, sizeof(Int_t) * mdim); Double_t v = 0.;
1692   TAxis *aa[mdim], *as(NULL), *ap(NULL), *ac(NULL); memset(aa, 0, sizeof(TAxis*) * mdim);
1693   for(Int_t id(0); id<ndim; id++) aa[id] = H->GetAxis(id);
1694   if(ndim > Int_t(kSpeciesChgRC)) as = H->GetAxis(kSpeciesChgRC); // init species/charge selection
1695   if(ndim > Int_t(kPt))           ap = H->GetAxis(kPt);           // init pt selection
1696   if(ndim > Int_t(kNdim))         ac = H->GetAxis(kNdim);         // init centrality selection
1697   // calculate size depending on debug level
1698   const Int_t nCen(debug?Int_t(AliTRDeventInfo::kCentralityClasses):1);
1699   const Int_t nPt(debug?Int_t(kNpt+2):1);
1700   const Int_t nSpc(1);//ndim>kNdimTrklt?fgkNbins[kSpeciesChgRC]:1);
1701   const Int_t nCh(debug?Int_t(kNcharge):1);
1702
1703   // build list of projections
1704   const Int_t nsel(AliTRDeventInfo::kCentralityClasses*AliTRDgeometry::kNlayer*(kNpt+2)*(AliPID::kSPECIES*kNcharge + 1));
1705   // define rebinning strategy
1706   const Int_t nEtaPhi(4); Int_t rebinEtaPhiX[nEtaPhi] = {1, 2, 5, 1}, rebinEtaPhiY[nEtaPhi] = {2, 1, 1, 5};
1707   AliTRDrecoProjection hp[kTrkltNproj]; TObjArray php(kTrkltNproj);
1708   Int_t ih(0), isel(-1), np[nsel]; memset(np, 0, nsel*sizeof(Int_t));
1709   const Char_t chName[kNcharge] = {'n', 'p'};const Char_t chSgn[kNcharge] = {'-', '+'};
1710   const Char_t ptName[kNpt+2] = {'L', 'l', 'i', 'h', 'H'};
1711   const Char_t *ptCut[kNpt+2] = {"p_{t}[GeV/c]<0.5", "0.5<=p_{t}[GeV/c]<0.8", "0.8<=p_{t}[GeV/c]<1.5", "1.5<=p_{t}[GeV/c]<5.0", "p_{t}[GeV/c]>=5.0"};
1712 //  const Char_t *cenName[AliTRDeventInfo::kCentralityClasses] = {"0-10%", "10-20%", "20-50%", "50-80%", "80-100%"};
1713   const Char_t *cenName[AliTRDeventInfo::kCentralityClasses] = {"2800-inf", "2100-2799", "1400-2099", "700-1399", "0-699"};
1714   for(Int_t icen(0); icen<nCen; icen++){
1715     for(Int_t ily(0); ily<AliTRDgeometry::kNlayer; ily++){
1716       for(Int_t ipt(0); ipt<nPt; ipt++){
1717         for(Int_t isp(0); isp<nSpc; isp++){
1718           for(Int_t ich(0); ich<nCh; ich++){
1719             isel++; // new selection
1720             hp[ih].Build(Form("H%sTrkltY%c%c%d%d%d", mc?"MC":"", chName[ich], ptName[ipt], isp, ily, icen),
1721                         Form("Tracklets[%s%c]:: #Deltay{%s} Ly[%d] Cen[%s]", AliPID::ParticleLatexName(isp), chSgn[ich], ptCut[ipt], ily, cenName[icen]),
1722                         kEta, kPhi, kYrez, aa);
1723             //hp[ih].SetShowRange(-0.1,0.1);
1724             hp[ih].SetRebinStrategy(nEtaPhi, rebinEtaPhiX, rebinEtaPhiY);
1725             php.AddLast(&hp[ih++]); np[isel]++;
1726             hp[ih].Build(Form("H%sTrkltPh%c%c%d%d%d", mc?"MC":"", chName[ich], ptName[ipt], isp, ily, icen),
1727                         Form("Tracklets[%s%c]:: #Delta#phi{%s} Ly[%d] Cen[%s]", AliPID::ParticleLatexName(isp), chSgn[ich], ptCut[ipt], ily, cenName[icen]),
1728                         kEta, kPhi, kPrez, aa);
1729             //hp[ih].SetShowRange(-0.5,0.5);
1730             hp[ih].SetRebinStrategy(nEtaPhi, rebinEtaPhiX, rebinEtaPhiY);
1731             php.AddLast(&hp[ih++]); np[isel]++;
1732             hp[ih].Build(Form("H%sTrkltQ%c%c%d%d%d", mc?"MC":"", chName[ich], ptName[ipt], isp, ily, icen),
1733                         Form("Tracklets[%s%c]:: dQdl{%s} Ly[%d] Cen[%s]", AliPID::ParticleLatexName(isp), chSgn[ich], ptCut[ipt], ily, cenName[icen]),
1734                         kEta, kPhi, kZrez, aa);
1735             hp[ih].SetShowRange(1.,2.3);
1736             hp[ih].SetRebinStrategy(nEtaPhi, rebinEtaPhiX, rebinEtaPhiY);
1737             php.AddLast(&hp[ih++]); np[isel]++;
1738             hp[ih].Build(Form("H%sTrkltTB%c%c%d%d%d", mc?"MC":"", chName[ich], ptName[ipt], isp, ily, icen),
1739                         Form("Tracklets[%s%c]:: OccupancyTB{%s} Ly[%d] Cen[%s]", AliPID::ParticleLatexName(isp), chSgn[ich], ptCut[ipt], ily, cenName[icen]),
1740                         kEta, kPhi, kNdim+1, aa);
1741             hp[ih].SetShowRange(30., 70.);
1742             hp[ih].SetRebinStrategy(nEtaPhi, rebinEtaPhiX, rebinEtaPhiY);
1743             php.AddLast(&hp[ih++]); np[isel]++;
1744           }
1745         }
1746         if(ndim==kNdimTrklt) continue;
1747
1748         isel++; // new selection
1749         hp[ih].Build(Form("H%sTrkltRCZ%c%d%d", mc?"MC":"", ptName[ipt], ily, icen),
1750                     Form("Tracklets[RC]:: #Deltaz{%s} Ly[%d] Cen[%s]", ptCut[ipt], ily, cenName[icen]),
1751                     kEta, kPhi, kZrez, aa);
1752   //      hp[ih].SetShowRange(-0.1,0.1);
1753         hp[ih].SetRebinStrategy(nEtaPhi, rebinEtaPhiX, rebinEtaPhiY);
1754         php.AddLast(&hp[ih++]); np[isel]++;
1755 /*        hp[ih].Build(Form("H%sTrkltRCY%c%d%d", mc?"MC":"", ptName[ipt], ily, icen),
1756                     Form("Tracklets[RC]:: #Deltay{%s} Ly[%d] Cen[%s]", ptCut[ipt], ily, cenName[icen]),
1757                     kEta, kPhi, kYrez, aa);
1758         //hp[ih].SetShowRange(-0.1,0.1);
1759         hp[ih].SetRebinStrategy(nEtaPhi, rebinEtaPhiX, rebinEtaPhiY);
1760         php.AddLast(&hp[ih++]); np[isel]++;
1761         hp[ih].Build(Form("H%sTrkltRCPh%c%d%d", mc?"MC":"", ptName[ipt], ily, icen),
1762                     Form("Tracklets[RC]:: #Delta#phi{%s} Ly[%d] Cen[%s]", ptCut[ipt], ily, cenName[icen]),
1763                     kEta, kPhi, kPrez, aa);
1764         //hp[ih].SetShowRange(-0.1,0.1);
1765         hp[ih].SetRebinStrategy(nEtaPhi, rebinEtaPhiX, rebinEtaPhiY);
1766         php.AddLast(&hp[ih++]); np[isel]++;
1767         hp[ih].Build(Form("H%sTrkltRCQ%c%d%d", mc?"MC":"", ptName[ipt], ily, icen),
1768                     Form("Tracklets[RC]:: dQdl{%s} Ly[%d] Cen[%s]", ptCut[ipt], ily, cenName[icen]),
1769                     kEta, kPhi, kNdim, aa);
1770         //hp[ih].SetShowRange(-0.1,0.1);
1771         hp[ih].SetRebinStrategy(nEtaPhi, rebinEtaPhiX, rebinEtaPhiY);
1772         php.AddLast(&hp[ih++]); np[isel]++;*/
1773       }
1774     }
1775   }
1776   AliInfo(Form("Build %3d 3D projections.", ih));
1777
1778   AliTRDrecoProjection *pr0(NULL), *pr1(NULL);
1779   Int_t ly(0), ch(0), sp(2), rcBin(as?as->FindBin(0.):-1), pt(0), cen(0), ioff(0), jspc(nSpc*nCh+1), kspc(nSpc*nCh*4+1);
1780   for (Long64_t ib(0); ib < H->GetNbins(); ib++) {
1781     v = H->GetBinContent(ib, coord);
1782     if(v<1.) continue;
1783     ly = coord[kBC]-1; // layer selection
1784     // charge selection
1785     ch = 0; sp=0;// [e-] track [dafault]
1786     if(rcBin>0){ // debug mode in which species/charge are also saved
1787       sp = Int_t(TMath::Abs(as->GetBinCenter(coord[kSpeciesChgRC])))-1;
1788       if(coord[kSpeciesChgRC] > rcBin) ch = 1;  // [+] track
1789       else if(coord[kSpeciesChgRC] == rcBin) ch = 2;  // [RC] track
1790     }
1791     // pt selection
1792     pt = 0; // low pt
1793     if(ap) pt = TMath::Min(coord[kPt], Int_t(kNpt)+1);
1794     // centrality selection
1795     cen = 0; // default
1796     if(ac) cen = coord[kNdim]-1;
1797     // global selection
1798     if(ndim==kNdimTrklt){
1799       ioff = ly*4;
1800       isel = ly;
1801     } else {
1802       isel = cen*AliTRDgeometry::kNlayer*nPt*jspc+ly*nPt*jspc+pt*jspc; isel+=sp<0?(nSpc*nCh):ch;
1803       ioff = cen*AliTRDgeometry::kNlayer*nPt*kspc+ly*nPt*kspc+pt*kspc; ioff+=sp<0?((nSpc*nCh)*4):(ch*4);
1804     }
1805     if(ioff>=ih){
1806       AliError(Form("Wrong selection %d [%3d]", ioff, ih));
1807       return kFALSE;
1808     }
1809     if(!(pr0=(AliTRDrecoProjection*)php.At(ioff))) {
1810       AliError(Form("Missing projection %d", ioff));
1811       return kFALSE;
1812     }
1813     if(sp>=0){
1814       if(strcmp(pr0->H()->GetName(), Form("H%sTrkltY%c%c%d%d%d", mc?"MC":"", chName[ch], ptName[pt], sp, ly, cen))!=0){
1815         AliError(Form("Projection mismatch :: request[H%sTrkltY%c%c%d%d%d] found[%s]", mc?"MC":"", chName[ch], ptName[pt], sp, ly, cen, pr0->H()->GetName()));
1816         return kFALSE;
1817       }
1818     } else {
1819       if(strcmp(pr0->H()->GetName(), Form("H%sTrkltRCZ%c%d%d", mc?"MC":"", ptName[pt], ly, cen))!=0){
1820         AliError(Form("Projection mismatch :: request[H%sTrkltRCZ%c%d%d] found[%s]", mc?"MC":"", ptName[pt], ly, cen, pr0->H()->GetName()));
1821         return kFALSE;
1822       }
1823     }
1824     for(Int_t jh(0); jh<np[isel]; jh++) ((AliTRDrecoProjection*)php.At(ioff+jh))->Increment(coord, v);
1825   }
1826   if(HasDump3DFor(kTracklet)){
1827     TDirectory *cwd = gDirectory;
1828     TFile::Open(Form("ResDump_%s.root", H->GetName()), "RECREATE");
1829     for(Int_t ip(0); ip<php.GetEntriesFast(); ip++){
1830       if(!(pr0 = (AliTRDrecoProjection*)php.At(ip))) continue;
1831       if(!pr0->H()) continue;
1832       TH3 *h3=(TH3*)pr0->H()->Clone();
1833       h3->Write();
1834     }
1835     gFile->Close();
1836     cwd->cd();
1837   }
1838
1839   TObjArray *arr(NULL);
1840   fProj->AddAt(arr = new TObjArray(kTrkltNproj), cidx);
1841
1842   TH2 *h2(NULL); Int_t jh(0);
1843   for(; ih--; ){
1844     if(!hp[ih].H()) continue;
1845     Int_t mid(0), nstat(kNstat);
1846     if(strchr(hp[ih].H()->GetName(), 'Q')){ mid=2; nstat=kNstatQ;}
1847     if(!(h2 = hp[ih].Projection2D(nstat, kNcontours, mid))) continue;
1848     arr->AddAt(h2, jh++);
1849   }
1850   // build combined performance plots
1851   for(Int_t ily(0); ily<AliTRDgeometry::kNlayer; ily++){
1852     for(Int_t ich(0); ich<nCh; ich++){
1853       for(Int_t icen(0); icen<nCen; icen++){
1854         for(Int_t ipt(0); ipt<nPt; ipt++){
1855           /*!dy*/
1856           if((pr0 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkltY%c%c%d%d%d", mc?"MC":"", chName[ich], ptName[ipt], 0, ily, icen)))){
1857             for(Int_t isp(1); isp<nSpc; isp++){
1858               if(!(pr1 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkltY%c%c%d%d%d", mc?"MC":"", chName[ich], ptName[ipt], isp, ily, icen)))) continue;
1859               (*pr0)+=(*pr1);
1860             }
1861             pr0->H()->SetNameTitle(Form("H%sTrkltY%c%c%d%d", mc?"MC":"", chName[ich], ptName[ipt], ily, icen),
1862                                       Form("Tracklets[%c]:: #Deltay{%s} Ly[%d] Cen[%s]", chSgn[ich], ptCut[ipt], ily, cenName[icen]));
1863             if((h2 = pr0->Projection2D(kNstat, kNcontours, 1))) arr->AddAt(h2, jh++);
1864             if(ipt && (pr1 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkltY%c%c%d%d%d", mc?"MC":"", chName[ich], ptName[0], 0, ily, icen)))) (*pr1)+=(*pr0);
1865           }
1866           /*!dphi*/
1867           if((pr0 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkltPh%c%c%d%d%d", mc?"MC":"", chName[ich], ptName[ipt], 0, ily, icen)))){
1868             for(Int_t isp(1); isp<nSpc; isp++){
1869               if(!(pr1 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkltPh%c%c%d%d%d", mc?"MC":"", chName[ich], ptName[ipt], isp, ily, icen)))) continue;
1870               (*pr0)+=(*pr1);
1871             }
1872             pr0->H()->SetNameTitle(Form("H%sTrkltPh%c%c%d%d", mc?"MC":"", chName[ich], ptName[ipt], ily, icen),
1873                                       Form("Tracklets[%c]:: #Delta#phi{%s} Ly[%d] Cen[%s]", chSgn[ich], ptCut[ipt], ily, cenName[icen]));
1874             if((h2 = pr0->Projection2D(kNstat, kNcontours, 1))) arr->AddAt(h2, jh++);
1875             if(ipt && (pr1 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkltPh%c%c%d%d%d", mc?"MC":"", chName[ich], ptName[0], 0, ily, icen)))) (*pr1)+=(*pr0);
1876           }
1877           /*!dQ/dl*/
1878           if((pr0 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkltQ%c%c%d%d%d", mc?"MC":"", chName[ich], ptName[ipt], 0, ily, icen)))){
1879             for(Int_t isp(1); isp<nSpc; isp++){
1880               if(!(pr1 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkltQ%c%c%d%d%d", mc?"MC":"", chName[ich], ptName[ipt], isp, ily, icen)))) continue;
1881               (*pr0)+=(*pr1);
1882             }
1883             pr0->H()->SetNameTitle(Form("H%sTrkltQ%c%c%d%d", mc?"MC":"", chName[ich], ptName[ipt], ily, icen),
1884                                       Form("Tracklets[%c]:: dQdl{%s} Ly[%d] Cen[%s]", chSgn[ich], ptCut[ipt], ily, cenName[icen]));
1885             if((h2 = pr0->Projection2D(kNstatQ, kNcontours, 2))) arr->AddAt(h2, jh++);
1886             pr0->H()->SetNameTitle(Form("H%sTrkltQS%c%c%d%d", mc?"MC":"", chName[ich], ptName[ipt], ily, icen),
1887                                       Form("Tracklets[%c]:: dQdl{%s} Ly[%d] Cen[%s]", chSgn[ich], ptCut[ipt], ily, cenName[icen]));
1888             pr0->SetShowRange(2.4, 5.1);
1889             if((h2 = pr0->Projection2D(kNstat, kNcontours, 0))) arr->AddAt(h2, jh++);
1890             if(ipt && (pr1 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkltQ%c%c%d%d%d", mc?"MC":"", chName[ich], ptName[0], 0, ily, icen)))) (*pr1)+=(*pr0);
1891           }
1892           /*!TB occupancy*/
1893           if((pr0 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkltTB%c%c%d%d%d", mc?"MC":"", chName[ich], ptName[ipt], 0, ily, icen)))){
1894             for(Int_t isp(1); isp<nSpc; isp++){
1895               if(!(pr1 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkltTB%c%c%d%d%d", mc?"MC":"", chName[ich], ptName[ipt], isp, ily, icen)))) continue;
1896               (*pr0)+=(*pr1);
1897             }
1898             pr0->H()->SetNameTitle(Form("H%sTrkltTB%c%c%d%d", mc?"MC":"", chName[ich], ptName[ipt], ily, icen),
1899                                       Form("Tracklets[%c]:: OccupancyTB{%s} Ly[%d] Cen[%s]", chSgn[ich], ptCut[ipt], ily, cenName[icen]));
1900             if((h2 = pr0->Projection2D(kNstat, kNcontours))) arr->AddAt(h2, jh++);
1901             if(ipt && (pr1 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkltTB%c%c%d%d%d", mc?"MC":"", chName[ich], ptName[0], 0, ily, icen)))) (*pr1)+=(*pr0);
1902           }
1903         } // end pt integration
1904         /*!dy*/
1905         if((pr0 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkltY%c%c%d%d%d", mc?"MC":"", chName[ich], ptName[0], 0, ily, icen)))){
1906           pr0->H()->SetNameTitle(Form("H%sTrkltY%c%d%d", mc?"MC":"", chName[ich], ily, icen),
1907                                 Form("Tracklets[%c]:: #Deltay Ly[%d] Cen[%s]", chSgn[ich], ily, cenName[icen]));
1908           if((h2 = pr0->Projection2D(kNstat, kNcontours, 1))) arr->AddAt(h2, jh++);
1909           if(icen && (pr1 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkltY%c%c%d%d%d", mc?"MC":"", chName[ich], ptName[0], 0, ily, 0)))) (*pr1)+=(*pr0);
1910         }
1911         /*!dphi*/
1912         if((pr0 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkltPh%c%c%d%d%d", mc?"MC":"", chName[ich], ptName[0], 0, ily, icen)))){
1913           pr0->H()->SetNameTitle(Form("H%sTrkltPh%c%d%d", mc?"MC":"", chName[ich], ily, icen),
1914                                 Form("Tracklets[%c]:: #Delta#phi Ly[%d] Cen[%s]", chSgn[ich], ily, cenName[icen]));
1915           if((h2 = pr0->Projection2D(kNstat, kNcontours, 1))) arr->AddAt(h2, jh++);
1916           if(icen && (pr1 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkltPh%c%c%d%d%d", mc?"MC":"", chName[ich], ptName[0], 0, ily, 0)))) (*pr1)+=(*pr0);
1917         }
1918         /*!dQ/dl*/
1919         if((pr0 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkltQ%c%c%d%d%d", mc?"MC":"", chName[ich], ptName[0], 0, ily, icen)))){
1920           pr0->H()->SetNameTitle(Form("H%sTrkltQ%c%d%d", mc?"MC":"", chName[ich], ily, icen),
1921                                 Form("Tracklets[%c]:: dQdl Ly[%d] Cen[%s]", chSgn[ich], ily, cenName[icen]));
1922           pr0->SetShowRange(1.,2.3);
1923           if((h2 = pr0->Projection2D(kNstatQ, kNcontours, 2))) arr->AddAt(h2, jh++);
1924           pr0->H()->SetNameTitle(Form("H%sTrkltQS%c%d%d", mc?"MC":"", chName[ich], ily, icen),
1925                                 Form("Tracklets[%c]:: dQdl Ly[%d] Cen[%s]", chSgn[ich], ily, cenName[icen]));
1926           pr0->SetShowRange(2.4,5.1);
1927           if((h2 = pr0->Projection2D(kNstat, kNcontours, 0))) arr->AddAt(h2, jh++);
1928           if(icen && (pr1 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkltQ%c%c%d%d%d", mc?"MC":"", chName[ich], ptName[0], 0, ily, 0)))) (*pr1)+=(*pr0);
1929         }
1930         /*!TB occupancy*/
1931         if((pr0 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkltTB%c%c%d%d%d", mc?"MC":"", chName[ich], ptName[0], 0, ily, icen)))){
1932           pr0->H()->SetNameTitle(Form("H%sTrkltTB%c%d%d", mc?"MC":"", chName[ich], ily, icen),
1933                                 Form("Tracklets[%c]:: OccupancyTB Ly[%d] Cen[%s]", chSgn[ich], ily, cenName[icen]));
1934           if((h2 = pr0->Projection2D(kNstat, kNcontours))) arr->AddAt(h2, jh++);
1935           if(icen && (pr1 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkltTB%c%c%d%d%d", mc?"MC":"", chName[ich], ptName[0], 0, ily, 0)))) (*pr1)+=(*pr0);
1936         }
1937       } // end centrality integration
1938       /*!dy*/
1939       if((pr0 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkltY%c%c%d%d%d", mc?"MC":"", chName[ich], ptName[0], 0, ily, 0)))){
1940         pr0->H()->SetNameTitle(Form("H%sTrkltY%c%d", mc?"MC":"", chName[ich], ily), Form("Tracklets[%c] :: #Deltay Ly[%d]", chSgn[ich], ily));
1941         if((h2 = pr0->Projection2D(kNstat, kNcontours, 1))) arr->AddAt(h2, jh++);
1942         if(ich && (pr1 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkltY%c%c%d%d%d", mc?"MC":"", chName[0], ptName[0], 0, ily, 0)))) (*pr1)+=(*pr0);
1943       }
1944       /*!dphi*/
1945       if((pr0 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkltPh%c%c%d%d%d", mc?"MC":"", chName[ich], ptName[0], 0, ily, 0)))){
1946         pr0->H()->SetNameTitle(Form("H%sTrkltPh%c%d", mc?"MC":"", chName[ich], ily), Form("Tracklets[%c] :: #Delta#phi Ly[%d]", chSgn[ich], ily));
1947         pr0->SetShowRange(-.9,.9);
1948         if((h2 = pr0->Projection2D(kNstat, kNcontours, 1))) arr->AddAt(h2, jh++);
1949         if(ich && (pr1 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkltPh%c%c%d%d%d", mc?"MC":"", chName[0], ptName[0], 0, ily, 0)))) (*pr1)+=(*pr0);
1950       }
1951       /*!dQ/dl*/
1952       if((pr0 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkltQ%c%c%d%d%d", mc?"MC":"", chName[ich], ptName[0], 0, ily, 0)))){
1953         pr0->H()->SetNameTitle(Form("H%sTrkltQ%c%d", mc?"MC":"", chName[ich], ily), Form("Tracklets[%c] :: dQdl Ly[%d]", chSgn[ich], ily));
1954         pr0->SetShowRange(1.,2.3);
1955         if((h2 = pr0->Projection2D(kNstatQ, kNcontours, 2))) arr->AddAt(h2, jh++);
1956         pr0->H()->SetNameTitle(Form("H%sTrkltQS%c%d", mc?"MC":"", chName[ich], ily), Form("Tracklets[%c] :: dQdl Ly[%d]", chSgn[ich], ily));
1957         pr0->SetShowRange(2.4,5.1);
1958         if((h2 = pr0->Projection2D(kNstat, kNcontours, 0))) arr->AddAt(h2, jh++);
1959         if(ich && (pr1 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkltQ%c%c%d%d%d", mc?"MC":"", chName[0], ptName[0], 0, ily, 0)))) (*pr1)+=(*pr0);
1960       }
1961       /*!TB occupancy*/
1962       if((pr0 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkltTB%c%c%d%d%d", mc?"MC":"", chName[ich], ptName[0], 0, ily, 0)))){
1963         pr0->H()->SetNameTitle(Form("H%sTrkltTB%c%d", mc?"MC":"", chName[ich], ily), Form("Tracklets[%c] :: OccupancyTB Ly[%d]", chSgn[ich], ily));
1964         if((h2 = pr0->Projection2D(kNstat, kNcontours))) arr->AddAt(h2, jh++);
1965         if(ich && (pr1 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkltTB%c%c%d%d%d", mc?"MC":"", chName[0], ptName[0], 0, ily, 0)))) (*pr1)+=(*pr0);
1966       }
1967     } // end charge integration
1968     /*!dy*/
1969     if((pr0 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkltY%c%c%d%d%d", mc?"MC":"", chName[0], ptName[0], 0, ily, 0)))){
1970       pr0->H()->SetNameTitle(Form("H%sTrkltY%d", mc?"MC":"", ily), Form("Tracklets :: #Deltay Ly[%d]", ily));
1971       if((h2 = pr0->Projection2D(kNstat, kNcontours, 1))) arr->AddAt(h2, jh++);
1972     }
1973     /*!dphi*/
1974     if((pr0 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkltPh%c%c%d%d%d", mc?"MC":"", chName[0], ptName[0], 0, ily, 0)))){
1975       pr0->H()->SetNameTitle(Form("H%sTrkltPh%d", mc?"MC":"", ily), Form("Tracklets :: #Delta#phi Ly[%d]", ily));
1976       pr0->SetShowRange(-.45,.45);
1977       if((h2 = pr0->Projection2D(kNstat, kNcontours, 1))) arr->AddAt(h2, jh++);
1978     }
1979     /*!dQdl*/
1980     if((pr0 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkltQ%c%c%d%d%d", mc?"MC":"", chName[0], ptName[0], 0, ily, 0)))){
1981       pr0->H()->SetNameTitle(Form("H%sTrkltQ%d", mc?"MC":"", ily), Form("Tracklets :: dQdl Ly[%d]", ily));
1982       pr0->SetShowRange(1.,2.3);
1983       if((h2 = pr0->Projection2D(kNstat, kNcontours, 2))) arr->AddAt(h2, jh++);
1984       pr0->H()->SetName(Form("H%sTrkltQS%d", mc?"MC":"", ily));
1985       pr0->SetShowRange(2.4,5.1);
1986       if((h2 = pr0->Projection2D(kNstat, kNcontours, 0))) arr->AddAt(h2, jh++);
1987     }
1988     /*!TB occupancy*/
1989     if((pr0 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkltTB%c%c%d%d%d", mc?"MC":"", chName[0], ptName[0], 0, ily, 0)))){
1990       pr0->H()->SetNameTitle(Form("H%sTrkltTB%d", mc?"MC":"", ily), Form("Tracklets :: OccupancyTB Ly[%d]", ily));
1991       if((h2 = pr0->Projection2D(kNstat, kNcontours))) arr->AddAt(h2, jh++);
1992     }
1993
1994     /*! Row Cross processing*/
1995     for(Int_t icen(0); icen<nCen; icen++){
1996       /*!RC dz*/
1997       if((pr0 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkltRCZ%c%d%d", mc?"MC":"", ptName[0], ily, icen)))){
1998         for(Int_t ipt(0); ipt<kNpt; ipt++){
1999           if(!(pr1 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkltRCZ%c%d%d", mc?"MC":"", ptName[ipt], ily, icen)))) continue;
2000           (*pr0)+=(*pr1);
2001         }
2002         pr0->H()->SetNameTitle(Form("H%sTrkltRCZ%d%d", mc?"MC":"", ily, icen), Form("Tracklets[RC]:: #Deltaz Ly[%d] Cen[%s]", ily, cenName[icen]));
2003         if((h2 = pr0->Projection2D(kNstat, kNcontours, 1))) arr->AddAt(h2, jh++);
2004         if(icen && (pr1 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkltRCZ%c%d%d", mc?"MC":"", ptName[0], ily, 0)))) (*pr1)+=(*pr0);
2005       }
2006     } // end centrality integration for row cross
2007     /*!RC dz*/
2008     if((pr0 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkltRCZ%c%d%d", mc?"MC":"", ptName[0], ily, 0)))){
2009       pr0->H()->SetNameTitle(Form("H%sTrkltRCZ%d", mc?"MC":"", ily), Form("Tracklets[RC] :: #Deltaz Ly[%d]", ily));
2010       if((h2 = pr0->Projection2D(kNstat, kNcontours, 1))) arr->AddAt(h2, jh++);
2011     }
2012   } // end layer loop
2013   AliInfo(Form("Done %3d 2D projections.", jh));
2014   return kTRUE;
2015 }
2016
2017 //________________________________________________________
2018 Bool_t AliTRDresolution::MakeProjectionTrackIn(Bool_t mc)
2019 {
2020 // Analyse track in
2021   const Int_t kNcontours(9);
2022   const Int_t kNstat(30);
2023   Int_t cidx=mc?kMCtrackIn:kTrackIn;
2024   if(fProj && fProj->At(cidx)) return kTRUE;
2025   if(!fContainer){
2026     AliError("Missing data container.");
2027     return kFALSE;
2028   }
2029   const Char_t *projName[] = {"hTracklet2TRDin", "hTRDin2MC"};
2030   THnSparse *H(NULL);
2031   if(!(H = (THnSparse*)fContainer->FindObject(projName[Int_t(mc)]))){
2032     AliError(Form("Missing/Wrong data @ %s.", projName[Int_t(mc)]));
2033     return kFALSE;
2034   }
2035
2036   const Int_t mdim(kNdim+3);
2037   Int_t coord[mdim]; memset(coord, 0, sizeof(Int_t) * mdim); Double_t v = 0.;
2038   Int_t ndim(H->GetNdimensions());
2039   TAxis *aa[mdim], *as(NULL), *ap(NULL), *apt(NULL), *ax(NULL), *abf(NULL); memset(aa, 0, sizeof(TAxis*) * (mdim));
2040   for(Int_t id(0); id<ndim; id++) aa[id] = H->GetAxis(id);
2041   if(ndim > Int_t(kSpeciesChgRC)) as = H->GetAxis(kSpeciesChgRC);
2042   if(ndim > Int_t(kPt))          apt = H->GetAxis(kPt);
2043   if(ndim > Int_t(kNdim))         ap = H->GetAxis(kNdim);
2044   if(ndim > Int_t(kNdim)+1)       ax = H->GetAxis(kNdim+1);
2045   if(ndim > Int_t(kNdim)+2)      abf = H->GetAxis(kNdim+2);
2046   //AliInfo(Form("Using : Species[%c] Pt[%c] BunchFill[%c]", as?'y':'n', ap?'y':'n', abf?'y':'n'));
2047   const Int_t nPt(ndim>Int_t(kNdimTrkIn)?Int_t(kNpt+2):1);
2048
2049   // build list of projections
2050   const Int_t nsel((kNpt+2)*(kNspc*kNcharge + 1));
2051   const Char_t chName[kNcharge] = {'n', 'p'};const Char_t chSgn[kNcharge] = {'-', '+'};
2052   const Char_t *spcName[kNspc] = {"e", "#mu#pi", "Kp"};
2053   const Char_t ptName[kNpt+2] = {'L', 'l', 'i', 'h', 'H'};
2054   const Char_t *ptCut[kNpt+2] = {"p_{t}[GeV/c]<0.5", "0.5<=p_{t}[GeV/c]<0.8", "0.8<=p_{t}[GeV/c]<1.5", "1.5<=p_{t}[GeV/c]<5.0", "p_{t}[GeV/c]>=5.0"};
2055   const Char_t *pCut[kNpt+2] = {"p[GeV/c]<0.5", "0.5<=p[GeV/c]<0.8", "0.8<=p[GeV/c]<1.5", "1.5<=p[GeV/c]<5.0", "p[GeV/c]>=5.0"};
2056   // define rebinning strategy
2057   const Int_t nEtaPhi(4); Int_t rebinEtaPhiX[nEtaPhi] = {1, 2, 5, 1}, rebinEtaPhiY[nEtaPhi] = {2, 1, 1, 5};
2058   AliTRDrecoProjection hp[kMCTrkInNproj]; TObjArray php(kMCTrkInNproj+2);
2059   Int_t ih(0), isel(-1), np[nsel]; memset(np, 0, nsel*sizeof(Int_t));
2060   // define list of projections
2061   for(Int_t ipt(0); ipt<nPt; ipt++){
2062     for(Int_t isp(0); isp<kNspc; isp++){
2063       for(Int_t ich(0); ich<kNcharge; ich++){
2064         isel++; // new selection
2065         hp[ih].Build(Form("H%sTrkInY%c%c%d", mc?"MC":"", chName[ich], ptName[ipt], isp),
2066                      Form("TrackIn[%s%c]:: #Deltay{%s}", spcName[isp], chSgn[ich], ptCut[ipt]),
2067                      kEta, kPhi, kYrez, aa);
2068         hp[ih].SetRebinStrategy(nEtaPhi, rebinEtaPhiX, rebinEtaPhiY);
2069         php.AddLast(&hp[ih++]); np[isel]++;
2070         hp[ih].Build(Form("H%sTrkInPh%c%c%d", mc?"MC":"", chName[ich], ptName[ipt], isp),
2071                      Form("TrackIn[%s%c]:: #Delta#phi{%s}", spcName[isp], chSgn[ich], ptCut[ipt]),
2072                      kEta, kPhi, kPrez, aa);
2073         hp[ih].SetRebinStrategy(nEtaPhi, rebinEtaPhiX, rebinEtaPhiY);
2074         php.AddLast(&hp[ih++]); np[isel]++;
2075         hp[ih].Build(Form("H%sTrkInQ%c%c%d", mc?"MC":"", chName[ich], ptName[ipt], isp),
2076                      Form("TrackIn[%s%c]:: dQdl {%s}", spcName[isp], chSgn[ich], pCut[ipt]),
2077                      kEta, kPhi, kZrez, aa);
2078         hp[ih].SetRebinStrategy(nEtaPhi, rebinEtaPhiX, rebinEtaPhiY);
2079         php.AddLast(&hp[ih++]); np[isel]++;
2080         if(!ax) continue;
2081         hp[ih].Build(Form("H%sTrkInX%c%c%d", mc?"MC":"", chName[ich], ptName[ipt], isp),
2082                      Form("TrackIn[%s%c]:: #Deltax{%s}", spcName[isp], chSgn[ich], ptCut[ipt]),
2083                      kEta, kPhi, kNdim+1, aa);
2084         hp[ih].SetRebinStrategy(nEtaPhi, rebinEtaPhiX, rebinEtaPhiY);
2085         php.AddLast(&hp[ih++]); np[isel]++;
2086       }
2087     }
2088     isel++; // RC tracks
2089     hp[ih].Build(Form("H%sTrkInRCZ%c", mc?"MC":"", ptName[ipt]),
2090                   Form("TrackIn[RC]:: #Deltaz{%s}", ptCut[ipt]),
2091                   kEta, kPhi, kZrez, aa);
2092     hp[ih].SetRebinStrategy(nEtaPhi, rebinEtaPhiX, rebinEtaPhiY);
2093     php.AddLast(&hp[ih++]); np[isel]++;
2094     hp[ih].Build(Form("H%sTrkInRCY%c", mc?"MC":"", ptName[ipt]),
2095                   Form("TrackIn[RC]:: #Deltay{%s}", ptCut[ipt]),
2096                   kEta, kPhi, kYrez, aa);
2097     hp[ih].SetRebinStrategy(nEtaPhi, rebinEtaPhiX, rebinEtaPhiY);
2098     php.AddLast(&hp[ih++]); np[isel]++;
2099     hp[ih].Build(Form("H%sTrkInRCPh%c", mc?"MC":"", ptName[ipt]),
2100                   Form("TrackIn[RC]:: #Delta#phi{%s}", ptCut[ipt]),
2101                   kEta, kPhi, kPrez, aa);
2102     hp[ih].SetRebinStrategy(nEtaPhi, rebinEtaPhiX, rebinEtaPhiY);
2103     php.AddLast(&hp[ih++]); np[isel]++;
2104     if(!ax) continue;
2105     hp[ih].Build(Form("H%sTrkInRCX%c", mc?"MC":"", ptName[ipt]),
2106                   Form("TrackIn[RC]:: #Deltax{%s}", ptCut[ipt]),
2107                   kEta, kPhi, kNdim+1, aa);
2108     hp[ih].SetRebinStrategy(nEtaPhi, rebinEtaPhiX, rebinEtaPhiY);
2109     php.AddLast(&hp[ih++]); np[isel]++;
2110   }
2111   AliInfo(Form("Build %3d 3D projections.", ih));
2112
2113   // fill projections
2114   Int_t ch(0), pt(0), p(0), sp(1), rcBin(as?as->FindBin(0.):-1), ioff(0), joff(0), jsel(0);
2115   AliTRDrecoProjection *pr0(NULL), *pr1(NULL);
2116   for (Long64_t ib(0); ib < H->GetNbins(); ib++) {
2117     v = H->GetBinContent(ib, coord);
2118     if(v<1.) continue;
2119     if(fBCbinTOF>0 && coord[kBC]!=fBCbinTOF) continue; // TOF bunch cross cut
2120     if(fBCbinFill>0 && abf && coord[kNdim+2]!=fBCbinTOF) continue; // Fill bunch cut
2121     // charge selection
2122     ch = 0; sp=1;// [pi-] track
2123     if(rcBin>0){ // debug mode in which species are also saved
2124       sp = Int_t(TMath::Abs(as->GetBinCenter(coord[kSpeciesChgRC])))-1;
2125       // take care of old data format (2*AliPID::kSPECIES+1)
2126       if(as->GetNbins() == kNcharge*AliPID::kSPECIES+1){
2127         if(sp>2) sp=2;
2128         else if(sp==2) sp=1;
2129       }
2130       if(coord[kSpeciesChgRC] > rcBin) ch = 1;  // [+] track
2131       else if(coord[kSpeciesChgRC] == rcBin) ch = 2;  // [RC] track
2132     }
2133     // pt selection
2134     pt = 0; p = 0; // low pt
2135     if(apt) pt = TMath::Min(coord[kPt], Int_t(kNpt)+1);
2136     if(ap ) p  = TMath::Min(coord[kNdim], Int_t(kNpt)+1);
2137     // global selection
2138     isel = pt*(kNspc*kNcharge+1); isel+=(ch==2?(kNspc*kNcharge):(sp*kNcharge+ch)); ioff = isel*(ax?4:3);
2139     jsel = p*(kNspc*kNcharge+1); jsel+=(ch==2?(kNspc*kNcharge):(sp*kNcharge+ch)); joff = jsel*(ax?4:3);
2140     if(ioff>=ih){
2141       AliError(Form("Wrong selection %d [%3d]", ioff, ih));
2142       return kFALSE;
2143     }
2144     if(!(pr0=(AliTRDrecoProjection*)php.At(ioff))) {
2145       AliError(Form("Missing projection %d", ioff));
2146       return kFALSE;
2147     }
2148     if(ch<2){
2149       if(strcmp(pr0->H()->GetName(), Form("H%sTrkInY%c%c%d", mc?"MC":"", chName[ch], ptName[pt], sp))!=0){
2150         AliError(Form("Projection mismatch :: request[H%sTrkInY%c%c%d] found[%s]", mc?"MC":"", chName[ch], ptName[pt], sp, pr0->H()->GetName()));
2151         return kFALSE;
2152       }
2153     } else {
2154       if(strcmp(pr0->H()->GetName(), Form("H%sTrkInRCZ%c", mc?"MC":"", ptName[pt]))!=0){
2155         AliError(Form("Projection mismatch :: request[H%sTrkltRCZ%c] found[%s]", mc?"MC":"", ptName[pt], pr0->H()->GetName()));
2156         return kFALSE;
2157       }
2158     }
2159     AliDebug(2, Form("Found %s for selection sp[%d] ch[%d] pt[%d]", pr0->H()->GetName(), sp, ch, pt));
2160     for(Int_t jh(0); jh<np[isel]; jh++){
2161       if(ch<2 && jh==2) ((AliTRDrecoProjection*)php.At(joff+jh))->Increment(coord, v); // special care for dQdl=f(p)
2162       else ((AliTRDrecoProjection*)php.At(ioff+jh))->Increment(coord, v); // all = f(p_t)
2163     }
2164   }
2165   if(HasDump3DFor(kTrackIn)){
2166     TDirectory *cwd = gDirectory;
2167     TFile::Open(Form("ResDump_%s.root", H->GetName()), "RECREATE");
2168     for(Int_t ip(0); ip<php.GetEntriesFast(); ip++){
2169       if(!(pr0 = (AliTRDrecoProjection*)php.At(ip))) continue;
2170       if(!pr0->H()) continue;
2171       TH3 *h3=(TH3*)pr0->H()->Clone();
2172       h3->Write();
2173     }
2174     gFile->Close();
2175     cwd->cd();
2176   }
2177
2178   TObjArray *arr(NULL);
2179   fProj->AddAt(arr = new TObjArray(mc?kMCTrkInNproj:kTrkInNproj), cidx);
2180
2181   TH2 *h2(NULL); Int_t jh(0);
2182   for(; ih--; ){
2183     if(!hp[ih].H()) continue;
2184     if(!(h2 = hp[ih].Projection2D(kNstat, kNcontours))) continue;
2185     arr->AddAt(h2, jh++);
2186   }
2187   // build combined performance plots
2188   // combine up the tree of projections
2189   AliTRDrecoProjection xlow[2], specY[kNcharge*kNspc], specPh[kNcharge*kNspc], specQ[kNcharge*kNspc];
2190   for(Int_t ich(0); ich<kNcharge; ich++){
2191     // PID dependency - summation over pt
2192     for(Int_t isp(0); isp<kNspc; isp++){
2193       /*!dy*/
2194       Int_t idx(ich*kNspc+isp);
2195       if((pr0 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkInY%c%c%d", mc?"MC":"", chName[ich], ptName[0], isp)))){
2196         specY[idx] = (*pr0);
2197         specY[idx].SetNameTitle(Form("H%sTrkInY%c%d", mc?"MC":"", chName[ich], isp), "Sum over pt");
2198         specY[idx].H()->SetNameTitle(Form("H%sTrkInY%c%d", mc?"MC":"", chName[ich], isp),
2199                               Form("TrackIn[%s%c]:: #Deltay", spcName[isp], chSgn[ich]));
2200         for(Int_t ipt(1); ipt<nPt; ipt++){
2201           if(!(pr1 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkInY%c%c%d", mc?"MC":"", chName[ich], ptName[ipt], isp)))) continue;
2202           specY[idx]+=(*pr1);
2203         }
2204         php.AddLast(&specY[idx]);
2205         if((h2 = specY[idx].Projection2D(kNstat, kNcontours, 1, kFALSE))) arr->AddAt(h2, jh++);
2206         if((h2 = (TH2*)gDirectory->Get(Form("%sEn", specY[idx].H()->GetName())))) arr->AddAt(h2, jh++);
2207         if(ich && (pr1 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkInY%c%d", mc?"MC":"", chName[0], isp)))) (*pr1)+=specY[idx];
2208       }
2209       /*!dphi*/
2210       if((pr0 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkInPh%c%c%d", mc?"MC":"", chName[ich], ptName[0], isp)))){
2211         specPh[idx] = (*pr0);
2212         specPh[idx].SetNameTitle(Form("H%sTrkInPh%c%d", mc?"MC":"", chName[ich], isp), "Sum over pt");
2213         specPh[idx].H()->SetNameTitle(Form("H%sTrkInPh%c%d", mc?"MC":"", chName[ich], isp),
2214                               Form("TrackIn[%s%c]:: #Delta#phi", spcName[isp], chSgn[ich]));
2215         specPh[idx].SetShowRange(-1.5, 1.5);
2216         for(Int_t ipt(1); ipt<nPt; ipt++){
2217           if(!(pr1 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkInPh%c%c%d", mc?"MC":"", chName[ich], ptName[ipt], isp)))) continue;
2218           specPh[idx]+=(*pr1);
2219         }
2220         php.AddLast(&specPh[idx]);
2221         if((h2 = specPh[idx].Projection2D(kNstat, kNcontours, 1))) arr->AddAt(h2, jh++);
2222         if(ich && (pr1 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkInPh%c%d", mc?"MC":"", chName[0], isp)))) (*pr1)+=specPh[idx];
2223       }
2224       /*!dQdl*/
2225       if((pr0 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkInQ%c%c%d", mc?"MC":"", chName[ich], ptName[0], isp)))){
2226         specQ[idx] = (*pr0);
2227         specQ[idx].SetNameTitle(Form("H%sTrkInQ%c%d", mc?"MC":"", chName[ich], isp), "Sum over p");
2228         specQ[idx].H()->SetNameTitle(Form("H%sTrkInQ%c%d", mc?"MC":"", chName[ich], isp),
2229                               Form("TrackIn[%s%c]:: dQdl", spcName[isp], chSgn[ich]));
2230         specQ[idx].SetShowRange(-2.2, -1.75);
2231         specQ[idx].H()->GetZaxis()->SetTitle("dQdl [a.u.]");
2232         for(Int_t ipt(1); ipt<nPt; ipt++){
2233           if(!(pr1 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkInQ%c%c%d", mc?"MC":"", chName[ich], ptName[ipt], isp)))) continue;
2234           specQ[idx]+=(*pr1);
2235         }
2236         php.AddLast(&specQ[idx]);
2237         if((h2 = specQ[idx].Projection2D(kNstat, kNcontours, 2))) arr->AddAt(h2, jh++);
2238         specQ[idx].H()->SetName(Form("H%sTrkInQS%c%d", mc?"MC":"", chName[ich], isp));
2239         specQ[idx].SetShowRange(-1.85, -1.4);
2240         if((h2 = specQ[idx].Projection2D(kNstat, kNcontours, 0))) arr->AddAt(h2, jh++);
2241         if(ich && (pr1 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkInQ%c%d", mc?"MC":"", chName[0], isp)))) (*pr1)+=specQ[idx];
2242       }
2243     } // end PID loop for pt integration
2244
2245     // pt dependency - summation over PID
2246     for(Int_t ipt(0); ipt<nPt; ipt++){
2247       /*!dy*/
2248       if((pr0 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkInY%c%c%d", mc?"MC":"", chName[ich], ptName[ipt], 0)))){
2249         for(Int_t isp(1); isp<kNspc; isp++){
2250           if(!(pr1 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkInY%c%c%d", mc?"MC":"", chName[ich], ptName[ipt], isp)))) continue;
2251           (*pr0)+=(*pr1);
2252         }
2253         pr0->H()->SetNameTitle(Form("H%sTrkInY%c%c", mc?"MC":"", chName[ich], ptName[ipt]),
2254                                   Form("TrackIn[%c]:: #Deltay{%s}", chSgn[ich], ptCut[ipt]));
2255         pr0->SetShowRange(-0.3, 0.3);
2256         if((h2 = pr0->Projection2D(kNstat, kNcontours, 1))) arr->AddAt(h2, jh++);
2257         if(ipt && (pr1 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkInY%c%c%d", mc?"MC":"", chName[ich], ptName[0], 0)))) (*pr1)+=(*pr0);
2258       }
2259       /*!dphi*/
2260       if((pr0 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkInPh%c%c%d", mc?"MC":"", chName[ich], ptName[ipt], 0)))){
2261         for(Int_t isp(1); isp<kNspc; isp++){
2262           if(!(pr1 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkInPh%c%c%d", mc?"MC":"", chName[ich], ptName[ipt], isp)))) continue;
2263           (*pr0)+=(*pr1);
2264         }
2265         pr0->H()->SetNameTitle(Form("H%sTrkInPh%c%c", mc?"MC":"", chName[ich], ptName[ipt]),
2266                                   Form("TrackIn[%c]:: #Delta#phi{%s}", chSgn[ich], ptCut[ipt]));
2267         if((h2 = pr0->Projection2D(kNstat, kNcontours, 1))) arr->AddAt(h2, jh++);
2268         if(ipt && (pr1 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkInPh%c%c%d", mc?"MC":"", chName[ich], ptName[0], 0)))) (*pr1)+=(*pr0);
2269       }
2270       /*!dx*/
2271       if((pr0 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkInX%c%c%d", mc?"MC":"", chName[ich], ptName[ipt], 0)))){
2272         for(Int_t isp(1); isp<kNspc; isp++){
2273           if(!(pr1 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkInX%c%c%d", mc?"MC":"", chName[ich], ptName[ipt], isp)))) continue;
2274           (*pr0)+=(*pr1);
2275         }
2276         pr0->H()->SetNameTitle(Form("H%sTrkInX%c%c", mc?"MC":"", chName[ich], ptName[ipt]),
2277                                   Form("TrackIn[%c]:: #Deltax{%s}", chSgn[ich], ptCut[ipt]));
2278         if((h2 = pr0->Projection2D(kNstat, kNcontours, 1))) arr->AddAt(h2, jh++);
2279         if(!ipt){
2280           xlow[ich] = (*pr0);
2281           xlow[ich].SetNameTitle(Form("H%sTrkInX%c%c%d", mc?"MC":"", chName[ich], ptName[0], 5),
2282                                  Form("TrackIn[%c]:: #Deltax{%s}", chSgn[ich], ptCut[0]));
2283           php.AddLast(&xlow[ich]);
2284         }
2285         if(ipt && (pr1 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkInX%c%c%d", mc?"MC":"", chName[ich], ptName[0], 0)))) (*pr1)+=(*pr0);
2286       }
2287     } // end pt loop for PID integration
2288
2289     /*!dy*/
2290     if((pr0 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkInY%c%c%d", mc?"MC":"", chName[ich], ptName[0], 0)))){
2291       pr0->H()->SetNameTitle(Form("H%sTrkInY%c", mc?"MC":"", chName[ich]),
2292                             Form("TrackIn[%c]:: #Deltay", chSgn[ich]));
2293       pr0->SetShowRange(-0.3, 0.3);
2294       if((h2 = pr0->Projection2D(kNstat, kNcontours, 1, kFALSE))) arr->AddAt(h2, jh++);
2295       if((h2 = (TH2*)gDirectory->Get(Form("%sEn", pr0->H()->GetName())))) arr->AddAt(h2, jh++);
2296       if(ich && (pr1 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkInY%c%c%d", mc?"MC":"", chName[0], ptName[0], 0)))) (*pr1)+=(*pr0);
2297     }
2298     /*!dy high pt*/
2299     if(ich && (pr0 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkInY%c%c%d", mc?"MC":"", chName[0], ptName[3], 0)))){
2300       if((pr1 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkInY%c%c%d", mc?"MC":"", chName[ich], ptName[3], 0)))){
2301         (*pr0)+=(*pr1);
2302         pr0->H()->SetNameTitle(Form("H%sTrkInY%c", mc?"MC":"", ptName[3]), Form("TrackIn :: #Deltay{%s}", ptCut[3]));
2303         pr0->SetShowRange(-0.3, 0.3);
2304         if((h2 = pr0->Projection2D(kNstat, kNcontours, 1))) arr->AddAt(h2, jh++);
2305       }
2306     }
2307     /*!dphi*/
2308     if((pr0 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkInPh%c%c%d", mc?"MC":"", chName[ich], ptName[0], 0)))){
2309       pr0->H()->SetNameTitle(Form("H%sTrkInPh%c", mc?"MC":"", chName[ich]),
2310                             Form("TrackIn[%c]:: #Delta#phi", chSgn[ich]));
2311       pr0->SetShowRange(-1., 1.);
2312       if((h2 = pr0->Projection2D(kNstat, kNcontours, 1))) arr->AddAt(h2, jh++);
2313       if(ich==1 && (pr1 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkInPh%c%c%d", mc?"MC":"", chName[0], ptName[0], 0)))) (*pr1)+=(*pr0);
2314     }
2315     /*!dx*/
2316     if((pr0 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkInX%c%c%d", mc?"MC":"", chName[ich], ptName[0], 0)))){
2317       pr0->H()->SetNameTitle(Form("H%sTrkInX%c", mc?"MC":"", chName[ich]),
2318                             Form("TrackIn[%c]:: #Deltax", chSgn[ich]));
2319       if((h2 = pr0->Projection2D(kNstat, kNcontours, 1))) arr->AddAt(h2, jh++);
2320       if(ich==1 && (pr1 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkInX%c%c%d", mc?"MC":"", chName[0], ptName[0], 0)))) (*pr1)+=(*pr0);
2321     }
2322     /*!dx low pt*/
2323     if(ich && (pr0 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkInX%c%c%d", mc?"MC":"", chName[0], ptName[1], 5)))){
2324       if((pr1 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkInX%c%c%d", mc?"MC":"", chName[ich], ptName[1], 5)))){
2325         (*pr0)+=(*pr1);
2326         pr0->H()->SetNameTitle(Form("H%sTrkInX%c", mc?"MC":"", ptName[1]), Form("TrackIn :: #Deltax{%s}", ptCut[1]));
2327         if((h2 = pr0->Projection2D(kNstat, kNcontours, 1))) arr->AddAt(h2, jh++);
2328       }
2329     }
2330   } // end charge loop
2331
2332   for(Int_t isp(0); isp<kNspc; isp++){
2333     /*!dy*/
2334     if((pr0 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkInY%c%d", mc?"MC":"", chName[0], isp)))){
2335       pr0->H()->SetNameTitle(Form("H%sTrkInY%d", mc?"MC":"", isp), Form("TrackIn[%s] :: #Deltay", spcName[isp]));
2336       pr0->SetShowRange(-0.3, 0.3);
2337       if((h2 = pr0->Projection2D(kNstat, kNcontours, 1, kFALSE))) arr->AddAt(h2, jh++);
2338       if((h2 = (TH2*)gDirectory->Get(Form("%sEn", pr0->H()->GetName())))) arr->AddAt(h2, jh++);
2339     }
2340     /*!dphi*/
2341     if((pr0 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkInPh%c%d", mc?"MC":"", chName[0], isp)))){
2342       pr0->H()->SetNameTitle(Form("H%sTrkInPh%d", mc?"MC":"", isp), Form("TrackIn[%s] :: #Delta#phi", spcName[isp]));
2343       pr0->SetShowRange(-1., 1.);
2344       if((h2 = pr0->Projection2D(kNstat, kNcontours, 1))) arr->AddAt(h2, jh++);
2345     }
2346     /*!dQdl*/
2347     if((pr0 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkInQ%c%d", mc?"MC":"", chName[0], isp)))){
2348       pr0->H()->SetNameTitle(Form("H%sTrkInQ%d", mc?"MC":"", isp), Form("TrackIn[%s] :: dQdl", spcName[isp]));
2349       pr0->SetShowRange(-2.2, -1.75);
2350       if((h2 = pr0->Projection2D(kNstat, kNcontours, 2))) arr->AddAt(h2, jh++);
2351       pr0->H()->SetName(Form("H%sTrkInQS%d", mc?"MC":"", isp));
2352       pr0->SetShowRange(-1.85, -1.4);
2353       if((h2 = pr0->Projection2D(kNstat, kNcontours, 0))) arr->AddAt(h2, jh++);
2354     }
2355   } // end PID processing
2356
2357   /*!dy*/
2358   if((pr0 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkInY%c%c%d", mc?"MC":"", chName[0], ptName[0], 0)))){
2359     pr0->H()->SetNameTitle(Form("H%sTrkInY", mc?"MC":""), "TrackIn :: #Deltay");
2360     pr0->SetShowRange(-0.3, 0.3);
2361     if((h2 = pr0->Projection2D(kNstat, kNcontours, 1, kFALSE))) arr->AddAt(h2, jh++);
2362     if((h2 = (TH2*)gDirectory->Get(Form("%sEn", pr0->H()->GetName())))) arr->AddAt(h2, jh++);
2363   }
2364   /*!dphi*/
2365   if((pr0 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkInPh%c%c%d", mc?"MC":"", chName[0], ptName[0], 0)))){
2366     pr0->H()->SetNameTitle(Form("H%sTrkInPh", mc?"MC":""), "TrackIn :: #Delta#phi");
2367     if((h2 = pr0->Projection2D(kNstat, kNcontours, 1))) arr->AddAt(h2, jh++);
2368   }
2369   /*!dx*/
2370   if((pr0 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkInX%c%c%d", mc?"MC":"", chName[0], ptName[0], 0)))){
2371     pr0->H()->SetNameTitle(Form("H%sTrkInX", mc?"MC":""), "TrackIn :: #Deltax");
2372     if((h2 = pr0->Projection2D(kNstat, kNcontours, 1))) arr->AddAt(h2, jh++);
2373   }
2374
2375   // Row Cross processing
2376   /*!RC dz*/
2377   if((pr0 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkInRCZ%c", mc?"MC":"", ptName[0])))){
2378     for(Int_t ipt(0); ipt<kNpt; ipt++){
2379       if(!(pr1 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkInRCZ%c", mc?"MC":"", ptName[ipt])))) continue;
2380       (*pr0)+=(*pr1);
2381     }
2382     pr0->H()->SetNameTitle(Form("H%sTrkInRCZ", mc?"MC":""), "TrackIn[RC]:: #Deltaz");
2383     if((h2 = pr0->Projection2D(kNstat, kNcontours, 1))) arr->AddAt(h2, jh++);
2384   }
2385   /*!RC dy*/
2386   if((pr0 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkInRCY%c", mc?"MC":"", ptName[0])))){
2387     for(Int_t ipt(0); ipt<kNpt; ipt++){
2388       if(!(pr1 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkInRCY%c", mc?"MC":"", ptName[ipt])))) continue;
2389       (*pr0)+=(*pr1);
2390     }
2391     pr0->H()->SetNameTitle(Form("H%sTrkInRCY", mc?"MC":""), "TrackIn[RC]:: #Deltay");
2392     if((h2 = pr0->Projection2D(kNstat, kNcontours, 1))) arr->AddAt(h2, jh++);
2393   }
2394   /*!RC dphi*/
2395   if((pr0 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkInRCPh%c", mc?"MC":"", ptName[0])))){
2396     for(Int_t ipt(0); ipt<kNpt; ipt++){
2397       if(!(pr1 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkInRCPh%c", mc?"MC":"", ptName[ipt])))) continue;
2398       (*pr0)+=(*pr1);
2399     }
2400     pr0->H()->SetNameTitle(Form("H%sTrkInRCPh", mc?"MC":""), "TrackIn[RC]:: #Delta#phi");
2401     if((h2 = pr0->Projection2D(kNstat, kNcontours, 1))) arr->AddAt(h2, jh++);
2402   }
2403   /*!RC dx*/
2404   if((pr0 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkInRCX%c", mc?"MC":"", ptName[0])))){
2405     for(Int_t ipt(0); ipt<kNpt; ipt++){
2406       if(!(pr1 = (AliTRDrecoProjection*)php.FindObject(Form("H%sTrkInRCX%c", mc?"MC":"", ptName[ipt])))) continue;
2407       (*pr0)+=(*pr1);
2408     }
2409     pr0->H()->SetNameTitle(Form("H%sTrkInRCX", mc?"MC":""), "TrackIn[RC]:: #Deltax");
2410     if((h2 = pr0->Projection2D(kNstat, kNcontours, 1))) arr->AddAt(h2, jh++);
2411   }
2412   AliInfo(Form("Done %3d 2D projections.", jh));
2413   return kTRUE;
2414 }
2415
2416
2417 //________________________________________________________
2418 Bool_t AliTRDresolution::MakeProjectionTrack()
2419 {
2420 // Analyse tracklet
2421   const Int_t kNcontours(9);
2422   const Int_t kNstat(30);
2423   Int_t cidx(kMCtrack);
2424   if(fProj && fProj->At(cidx)) return kTRUE;
2425   if(!fContainer){
2426     AliError("Missing data container.");
2427     return kFALSE;
2428   }
2429   THnSparse *H(NULL);
2430   if(!(H = (THnSparse*)fContainer->FindObject("hTRD2MC"))){
2431     AliError("Missing/Wrong data @ hTRD2MC.");
2432     return kFALSE;
2433   }
2434   Int_t ndim(H->GetNdimensions());
2435   Int_t coord[kNdim+1]; memset(coord, 0, sizeof(Int_t) * (kNdim+1)); Double_t v = 0.;
2436   TAxis *aa[kNdim+1], *as(NULL), *ap(NULL); memset(aa, 0, sizeof(TAxis*) * (kNdim+1));
2437   for(Int_t id(0); id<ndim; id++) aa[id] = H->GetAxis(id);
2438   if(ndim > kSpeciesChgRC) as = H->GetAxis(kSpeciesChgRC);
2439   if(ndim > kPt) ap = H->GetAxis(kPt);
2440
2441   // build list of projections
2442   const Int_t nsel(AliTRDgeometry::kNlayer*kNpt*AliPID::kSPECIES*7);//, npsel(3);
2443   const Char_t chName[kNcharge] = {'n', 'p'};const Char_t chSgn[kNcharge] = {'-', '+'};
2444   const Char_t ptName[kNpt] = {'l', 'i', 'h'};
2445   const Char_t *ptCut[kNpt] = {"p_{t}[GeV/c]<0.8", "0.8<=p_{t}[GeV/c]<1.5", "p_{t}[GeV/c]>=1.5"};
2446   // define rebinning strategy
2447   const Int_t nEtaPhi(4); Int_t rebinEtaPhiX[nEtaPhi] = {1, 2, 5, 1}, rebinEtaPhiY[nEtaPhi] = {2, 1, 1, 5};
2448   AliTRDrecoProjection hp[kTrkNproj]; TObjArray php(kTrkNproj);
2449   Int_t ih(0), isel(-1), np[nsel]; memset(np, 0, nsel*sizeof(Int_t));
2450   for(Int_t ily(0); ily<AliTRDgeometry::kNlayer; ily++){
2451     for(Int_t ipt(0); ipt<kNpt; ipt++){
2452       for(Int_t isp(0); isp<AliPID::kSPECIES; isp++){
2453         for(Int_t ich(0); ich<kNcharge; ich++){
2454           isel++; // new selection
2455           hp[ih].Build(Form("HMCTrkY%c%c%d%d", chName[ich], ptName[ipt], isp, ily),
2456                        Form("Tracks[%s%c]:: #Deltay{%s} Ly[%d]", AliPID::ParticleLatexName(isp), chSgn[ich], ptCut[ipt], ily),
2457                        kEta, kPhi, kYrez, aa);
2458           hp[ih].SetRebinStrategy(nEtaPhi, rebinEtaPhiX, rebinEtaPhiY);
2459           php.AddLast(&hp[ih++]); np[isel]++;
2460           hp[ih].Build(Form("HMCTrkPh%c%c%d%d", chName[ich], ptName[ipt], isp, ily),
2461                        Form("Tracks[%s%c]:: #Delta#phi{%s} Ly[%d]", AliPID::ParticleLatexName(isp), chSgn[ich], ptCut[ipt], ily),
2462                        kEta, kPhi, kPrez, aa);
2463           hp[ih].SetRebinStrategy(nEtaPhi, rebinEtaPhiX, rebinEtaPhiY);
2464           php.AddLast(&hp[ih++]); np[isel]++;
2465           hp[ih].Build(Form("HMCTrkDPt%c%c%d%d", chName[ich], ptName[ipt], isp, ily),
2466                        Form("Tracks[%s%c]:: #Deltap_{t}/p_{t}{%s} Ly[%d]", AliPID::ParticleLatexName(isp), chSgn[ich], ptCut[ipt], ily),
2467                        kEta, kPhi, kNdim, aa);
2468           hp[ih].SetShowRange(0.,10.);
2469           hp[ih].SetRebinStrategy(nEtaPhi, rebinEtaPhiX, rebinEtaPhiY);
2470           php.AddLast(&hp[ih++]); np[isel]++;
2471         }
2472       }
2473       isel++; // new selection
2474       hp[ih].Build(Form("HMCTrkZ%c%d", ptName[ipt], ily),
2475                     Form("Tracks[RC]:: #Deltaz{%s} Ly[%d]", ptCut[ipt], ily),
2476                     kEta, kPhi, kZrez, aa);
2477       hp[ih].SetRebinStrategy(nEtaPhi, rebinEtaPhiX, rebinEtaPhiY);
2478       php.AddLast(&hp[ih++]); np[isel]++;
2479     }
2480   }
2481
2482   Int_t ly(0), ch(0), pt(0), sp(2), rcBin(as?as->FindBin(0.):-1);
2483   for (Long64_t ib(0); ib < H->GetNbins(); ib++) {
2484     v = H->GetBinContent(ib, coord);
2485     if(v<1.) continue;
2486     ly = coord[kBC]-1; // layer selection
2487     // charge selection
2488     ch=0; sp=2;// [pi-] track [dafault]
2489     if(rcBin>0){ // debug mode in which species are also saved
2490       sp = Int_t(TMath::Abs(as->GetBinCenter(coord[kSpeciesChgRC])))-1;
2491       if(coord[kSpeciesChgRC] > rcBin) ch = 1;        // [+] track
2492       else if(coord[kSpeciesChgRC] == rcBin) ch = 2;  // [RC] track
2493     }
2494     // pt selection
2495     pt = 0; // low pt [default]
2496     if(ap) pt = coord[kPt]-1;
2497     // global selection
2498     Int_t ioff = ly*kNpt*31+pt*31; ioff+=3*(sp<0?10:(sp*kNcharge+ch));
2499     isel = ly*kNpt*11+pt*11; isel+=sp<0?10:(sp*kNcharge+ch);
2500     AliDebug(4, Form("SELECTION[%d] :: ch[%c] pt[%c] sp[%d] ly[%d]\n", np[isel], ch==2?'Z':chName[ch], ptName[pt], sp, ly));
2501     for(Int_t jh(0); jh<np[isel]; jh++) ((AliTRDrecoProjection*)php.At(ioff+jh))->Increment(coord, v);
2502   }
2503   TObjArray *arr(NULL);
2504   fProj->AddAt(arr = new TObjArray(kTrkNproj), cidx);
2505
2506   TH2 *h2(NULL); Int_t jh(0);
2507   for(; ih--; ){
2508     if(!hp[ih].H()) continue;
2509     if(!(h2 = hp[ih].Projection2D(kNstat, kNcontours))) continue;
2510     arr->AddAt(h2, jh++);
2511   }
2512
2513   // combine up the tree of projections
2514   AliTRDrecoProjection *pr0(NULL), *pr1(NULL);
2515   //Int_t iproj(0), jproj(0);
2516   for(Int_t ily(0); ily<AliTRDgeometry::kNlayer; ily++){
2517     for(Int_t ich(0); ich<kNcharge; ich++){
2518       for(Int_t ipt(0); ipt<kNpt; ipt++){
2519         /*!dy*/
2520         if((pr0 = (AliTRDrecoProjection*)php.FindObject(Form("HMCTrkY%c%c%d%d", chName[ich], ptName[ipt], 0, ily)))){
2521           for(Int_t isp(1); isp<AliPID::kSPECIES; isp++){
2522             if(!(pr1 = (AliTRDrecoProjection*)php.FindObject(Form("HMCTrkY%c%c%d%d", chName[ich], ptName[ipt], isp, ily)))) continue;
2523             (*pr0)+=(*pr1);
2524           }
2525           AliDebug(2, Form("Rename %s to HMCTrkY%c%c%d", pr0->H()->GetName(), chName[ich], ptName[ipt], ily));
2526           pr0->H()->SetNameTitle(Form("HMCTrkY%c%c%d", chName[ich], ptName[ipt], ily),
2527                                     Form("Tracks[%c]:: #Deltay{%s} Ly[%d]", chSgn[ich], ptCut[ipt], ily));
2528           if((h2 = pr0->Projection2D(kNstat, kNcontours, 1))) arr->AddAt(h2, jh++);
2529           if(ipt && (pr1 = (AliTRDrecoProjection*)php.FindObject(Form("HMCTrkY%c%c%d%d", chName[ich], ptName[0], 0, ily)))) (*pr1)+=(*pr0);
2530         }
2531         /*!dphi*/
2532         if((pr0 = (AliTRDrecoProjection*)php.FindObject(Form("HMCTrkPh%c%c%d%d", chName[ich], ptName[ipt], 0, ily)))){
2533           for(Int_t isp(1); isp<AliPID::kSPECIES; isp++){
2534             if(!(pr1 = (AliTRDrecoProjection*)php.FindObject(Form("HMCTrkPh%c%c%d%d", chName[ich], ptName[ipt], isp, ily)))) continue;
2535             (*pr0)+=(*pr1);
2536           }
2537           AliDebug(2, Form("Rename %s to HMCTrkPh%c%c%d", pr0->H()->GetName(), chName[ich], ptName[ipt], ily));
2538           pr0->H()->SetNameTitle(Form("HMCTrkPh%c%c%d", chName[ich], ptName[ipt], ily),
2539                                     Form("Tracks[%c]:: #Delta#phi{%s} Ly[%d]", chSgn[ich], ptCut[ipt], ily));
2540           if((h2 = pr0->Projection2D(kNstat, kNcontours, 1))) arr->AddAt(h2, jh++);
2541           if(ipt && (pr1 = (AliTRDrecoProjection*)php.FindObject(Form("HMCTrkPh%c%c%d%d", chName[ich], ptName[0], 0, ily)))) (*pr1)+=(*pr0);
2542         }
2543
2544         /*!dpt/pt*/
2545         if((pr0 = (AliTRDrecoProjection*)php.FindObject(Form("HMCTrkDPt%c%c%d%d", chName[ich], ptName[ipt], 0, ily)))){
2546           for(Int_t isp(1); isp<AliPID::kSPECIES; isp++){
2547             if(!(pr1 = (AliTRDrecoProjection*)php.FindObject(Form("HMCTrkDPt%c%c%d%d", chName[ich], ptName[ipt], isp, ily)))) continue;
2548             (*pr0)+=(*pr1);
2549           }
2550           AliDebug(2, Form("Rename %s to HMCTrkDPt%c%c%d", pr0->H()->GetName(), chName[ich], ptName[ipt], ily));
2551           pr0->H()->SetNameTitle(Form("HMCTrkDPt%c%c%d", chName[ich], ptName[ipt], ily),
2552                                     Form("Tracks[%c]:: #Deltap_{t}/p_{t}{%s} Ly[%d]", chSgn[ich], ptCut[ipt], ily));
2553           if((h2 = pr0->Projection2D(kNstat, kNcontours, 1))) arr->AddAt(h2, jh++);
2554           if(ipt && (pr1 = (AliTRDrecoProjection*)php.FindObject(Form("HMCTrkDPt%c%c%d%d", chName[ich], ptName[0], 0, ily)))) (*pr1)+=(*pr0);
2555         }
2556       }
2557       /*!dy*/
2558       if((pr0 = (AliTRDrecoProjection*)php.FindObject(Form("HMCTrkY%c%c%d%d", chName[ich], ptName[0], 0, ily)))){
2559         pr0->H()->SetNameTitle(Form("HMCTrkY%c%d", chName[ich], ily),
2560                               Form("Tracks[%c]:: #Deltay Ly[%d]", chSgn[ich], ily));
2561         if((h2 = pr0->Projection2D(kNstat, kNcontours, 1))) arr->AddAt(h2, jh++);
2562         if(ich==1 && (pr1 = (AliTRDrecoProjection*)php.FindObject(Form("HMCTrkY%c%c%d%d", chName[0], ptName[0], 0, ily)))) (*pr1)+=(*pr0);
2563       }
2564       /*!dphi*/
2565       if((pr0 = (AliTRDrecoProjection*)php.FindObject(Form("HMCTrkPh%c%c%d%d", chName[ich], ptName[0], 0, ily)))){
2566         pr0->H()->SetNameTitle(Form("HMCTrkPh%c%d", chName[ich], ily),
2567                               Form("Tracks[%c]:: #Delta#phi Ly[%d]", chSgn[ich], ily));
2568         if((h2 = pr0->Projection2D(kNstat, kNcontours, 1))) arr->AddAt(h2, jh++);
2569         if(ich==1 && (pr1 = (AliTRDrecoProjection*)php.FindObject(Form("HMCTrkPh%c%c%d%d", chName[0], ptName[0], 0, ily)))) (*pr1)+=(*pr0);
2570       }
2571       /*!dpt/pt*/
2572       if((pr0 = (AliTRDrecoProjection*)php.FindObject(Form("HMCTrkDPt%c%c%d%d", chName[ich], ptName[0], 0, ily)))){
2573         pr0->H()->SetNameTitle(Form("HMCTrkDPt%c%d", chName[ich], ily),
2574                               Form("Tracks[%c]:: #Deltap_{t}/p_{t} Ly[%d]", chSgn[ich], ily));
2575         if((h2 = pr0->Projection2D(kNstat, kNcontours, 1))) arr->AddAt(h2, jh++);
2576         if(ich==1 && (pr1 = (AliTRDrecoProjection*)php.FindObject(Form("HMCTrkDPt%c%c%d%d", chName[0], ptName[0], 0, ily)))) (*pr1)+=(*pr0);
2577       }
2578     }
2579     /*!dy*/
2580     if((pr0 = (AliTRDrecoProjection*)php.FindObject(Form("HMCTrkY%c%c%d%d", chName[0], ptName[0], 0, ily)))){
2581       pr0->H()->SetNameTitle(Form("HMCTrkY%d", ily), Form("Tracks :: #Deltay Ly[%d]", ily));
2582       if((h2 = pr0->Projection2D(kNstat, kNcontours, 1))) arr->AddAt(h2, jh++);
2583     }
2584     /*!dphi*/
2585     if((pr0 = (AliTRDrecoProjection*)php.FindObject(Form("HMCTrkPh%c%c%d%d", chName[0], ptName[0], 0, ily)))){
2586       pr0->H()->SetNameTitle(Form("HMCTrkPh%d", ily), Form("Tracks :: #Delta#phi Ly[%d]", ily));
2587       if((h2 = pr0->Projection2D(kNstat, kNcontours, 1))) arr->AddAt(h2, jh++);
2588     }
2589     /*!dpt/pt*/
2590     if((pr0 = (AliTRDrecoProjection*)php.FindObject(Form("HMCTrkDPt%c%c%d%d", chName[0], ptName[0], 0, ily)))){
2591       pr0->H()->SetNameTitle(Form("HMCTrkDPt%d", ily), Form("Tracks :: #Deltap_{t}/p_{t} Ly[%d]", ily));
2592       if((h2 = pr0->Projection2D(kNstat, kNcontours, 1))) arr->AddAt(h2, jh++);
2593     }
2594   }
2595   AliInfo(Form("Done %3d 2D projections.", jh));
2596   return kTRUE;
2597 }
2598
2599 //________________________________________________________
2600 Bool_t AliTRDresolution::PostProcess()
2601 {
2602 // Fit, Project, Combine, Extract values from the containers filled during execution
2603
2604   if (!fContainer) {
2605     AliError("ERROR: list not available");
2606     return kFALSE;
2607   }
2608   if(!fProj){
2609     AliInfo("Building array of projections ...");
2610     fProj = new TObjArray(kNclasses); fProj->SetOwner(kTRUE);
2611   }
2612
2613   //PROCESS EXPERIMENTAL DISTRIBUTIONS
2614   // Clusters detector
2615   if(HasProcess(kDetector)) if(!MakeProjectionDetector()) return kFALSE;
2616   // Clusters residuals
2617   if(HasProcess(kCluster)) if(!MakeProjectionCluster()) return kFALSE;
2618   fNRefFigures = 3;
2619   // Tracklet residual/pulls
2620   if(HasProcess(kTracklet)) if(!MakeProjectionTracklet()) return kFALSE;
2621   fNRefFigures = 7;
2622   // TRDin residual/pulls
2623   if(HasProcess(kTrackIn)) if(!MakeProjectionTrackIn()) return kFALSE;
2624   fNRefFigures = 11;
2625
2626   if(!HasMCdata()) return kTRUE;
2627   //PROCESS MC RESIDUAL DISTRIBUTIONS
2628
2629   // CLUSTER Y RESOLUTION/PULLS
2630   if(HasProcess(kCluster)) if(!MakeProjectionCluster(kTRUE)) return kFALSE;
2631   fNRefFigures = 17;
2632
2633   // TRACKLET RESOLUTION/PULLS
2634   if(HasProcess(kTracklet)) if(!MakeProjectionTracklet(kTRUE)) return kFALSE;
2635   fNRefFigures = 21;
2636
2637   // TRACK RESOLUTION/PULLS
2638   if(HasProcess(kTracklet)) if(!MakeProjectionTrack()) return kFALSE;
2639   fNRefFigures+=16;
2640
2641   // TRACK TRDin RESOLUTION/PULLS
2642   if(HasProcess(kTrackIn)) if(!MakeProjectionTrackIn(kTRUE)) return kFALSE;
2643   fNRefFigures+=8;
2644
2645   return kTRUE;
2646 }
2647
2648
2649 //________________________________________________________
2650 void AliTRDresolution::Terminate(Option_t *opt)
2651 {
2652   AliTRDrecoTask::Terminate(opt);
2653   if(HasPostProcess()) PostProcess();
2654 }
2655
2656 //________________________________________________________
2657 void AliTRDresolution::AdjustF1(TH1 *h, TF1 *f)
2658 {
2659 // Helper function to avoid duplication of code
2660 // Make first guesses on the fit parameters
2661
2662   // find the intial parameters of the fit !! (thanks George)
2663   Int_t nbinsy = Int_t(.5*h->GetNbinsX());
2664   Double_t sum = 0.;
2665   for(Int_t jbin=nbinsy-4; jbin<=nbinsy+4; jbin++) sum+=h->GetBinContent(jbin); sum/=9.;
2666   f->SetParLimits(0, 0., 3.*sum);
2667   f->SetParameter(0, .9*sum);
2668   Double_t rms = h->GetRMS();
2669   f->SetParLimits(1, -rms, rms);
2670   f->SetParameter(1, h->GetMean());
2671
2672   f->SetParLimits(2, 0., 2.*rms);
2673   f->SetParameter(2, rms);
2674   if(f->GetNpar() <= 4) return;
2675
2676   f->SetParLimits(3, 0., sum);
2677   f->SetParameter(3, .1*sum);
2678
2679   f->SetParLimits(4, -.3, .3);
2680   f->SetParameter(4, 0.);
2681
2682   f->SetParLimits(5, 0., 1.e2);
2683   f->SetParameter(5, 2.e-1);
2684 }
2685
2686 //________________________________________________________
2687 TObjArray* AliTRDresolution::BuildMonitorContainerCluster(const char* name, Bool_t expand, Float_t range)
2688 {
2689 // Build performance histograms for AliTRDcluster.vs TRD track or MC
2690 //  - y reziduals/pulls
2691
2692   TObjArray *arr = new TObjArray(2);
2693   arr->SetName(name); arr->SetOwner();
2694   TH1 *h(NULL); char hname[100], htitle[300];
2695
2696   // tracklet resolution/pull in y direction
2697   snprintf(hname, 100, "%s_%s_Y", GetNameId(), name);
2698   snprintf(htitle, 300, "Y res for \"%s\" @ %s;tg(#phi);#Delta y [cm];%s", GetNameId(), name, "Detector");
2699   Float_t rr = range<0.?fDyRange:range;
2700   if(!(h = (TH3S*)gROOT->FindObject(hname))){
2701     Int_t nybins=50;
2702     if(expand) nybins*=2;
2703     h = new TH3S(hname, htitle,
2704                  48, -.48, .48,            // phi
2705                  60, -rr, rr,              // dy
2706                  nybins, -0.5, nybins-0.5);// segment
2707   } else h->Reset();
2708   arr->AddAt(h, 0);
2709   snprintf(hname, 100, "%s_%s_YZpull", GetNameId(), name);
2710   snprintf(htitle, 300, "YZ pull for \"%s\" @ %s;%s;#Delta y  / #sigma_{y};#Delta z  / #sigma_{z}", GetNameId(), name, "Detector");
2711   if(!(h = (TH3S*)gROOT->FindObject(hname))){
2712     h = new TH3S(hname, htitle, 540, -0.5, 540-0.5, 100, -4.5, 4.5, 100, -4.5, 4.5);
2713   } else h->Reset();
2714   arr->AddAt(h, 1);
2715
2716   return arr;
2717 }
2718
2719 //________________________________________________________
2720 TObjArray* AliTRDresolution::BuildMonitorContainerTracklet(const char* name, Bool_t expand)
2721 {
2722 // Build performance histograms for AliExternalTrackParam.vs TRD tracklet
2723 //  - y reziduals/pulls
2724 //  - z reziduals/pulls
2725 //  - phi reziduals
2726   TObjArray *arr = BuildMonitorContainerCluster(name, expand, 0.05);
2727   arr->Expand(5);
2728   TH1 *h(NULL); char hname[100], htitle[300];
2729
2730   // tracklet resolution/pull in z direction
2731   snprintf(hname, 100, "%s_%s_Z", GetNameId(), name);
2732   snprintf(htitle, 300, "Z res for \"%s\" @ %s;tg(#theta);#Delta z [cm]", GetNameId(), name);
2733   if(!(h = (TH2S*)gROOT->FindObject(hname))){
2734     h = new TH2S(hname, htitle, 50, -1., 1., 100, -.05, .05);
2735   } else h->Reset();
2736   arr->AddAt(h, 2);
2737   snprintf(hname, 100, "%s_%s_Zpull", GetNameId(), name);
2738   snprintf(htitle, 300, "Z pull for \"%s\" @ %s;tg(#theta);#Delta z  / #sigma_{z};row cross", GetNameId(), name);
2739   if(!(h = (TH3S*)gROOT->FindObject(hname))){
2740     h = new TH3S(hname, htitle, 50, -1., 1., 100, -5.5, 5.5, 2, -0.5, 1.5);
2741     h->GetZaxis()->SetBinLabel(1, "no RC");
2742     h->GetZaxis()->SetBinLabel(2, "RC");
2743   } else h->Reset();
2744   arr->AddAt(h, 3);
2745
2746   // tracklet to track phi resolution
2747   snprintf(hname, 100, "%s_%s_PHI", GetNameId(), name);
2748   snprintf(htitle, 300, "#Phi res for \"%s\" @ %s;tg(#phi);#Delta #phi [rad];%s", GetNameId(), name, "Detector");
2749   Int_t nsgms=540;
2750   if(!(h = (TH3S*)gROOT->FindObject(hname))){
2751     h = new TH3S(hname, htitle, 48, -.48, .48, 100, -.5, .5, nsgms, -0.5, nsgms-0.5);
2752   } else h->Reset();
2753   arr->AddAt(h, 4);
2754
2755   return arr;
2756 }
2757
2758 //________________________________________________________
2759 TObjArray* AliTRDresolution::BuildMonitorContainerTrack(const char* name)
2760 {
2761 // Build performance histograms for AliExternalTrackParam.vs MC
2762 //  - y resolution/pulls
2763 //  - z resolution/pulls
2764 //  - phi resolution, snp pulls
2765 //  - theta resolution, tgl pulls
2766 //  - pt resolution, 1/pt pulls, p resolution
2767
2768   TObjArray *arr = BuildMonitorContainerTracklet(name);
2769   arr->Expand(11);
2770   TH1 *h(NULL); char hname[100], htitle[300];
2771   //TAxis *ax(NULL);
2772
2773   // snp pulls
2774   snprintf(hname, 100, "%s_%s_SNPpull", GetNameId(), name);
2775   snprintf(htitle, 300, "SNP pull for \"%s\" @ %s;tg(#phi);#Delta snp  / #sigma_{snp};entries", GetNameId(), name);
2776   if(!(h = (TH2I*)gROOT->FindObject(hname))){
2777     h = new TH2I(hname, htitle, 60, -.3, .3, 100, -4.5, 4.5);
2778   } else h->Reset();
2779   arr->AddAt(h, 5);
2780
2781   // theta resolution
2782   snprintf(hname, 100, "%s_%s_THT", GetNameId(), name);
2783   snprintf(htitle, 300, "#Theta res for \"%s\" @ %s;tg(#theta);#Delta #theta [rad];entries", GetNameId(), name);
2784   if(!(h = (TH2I*)gROOT->FindObject(hname))){
2785     h = new TH2I(hname, htitle, 100, -1., 1., 100, -5e-3, 5e-3);
2786   } else h->Reset();
2787   arr->AddAt(h, 6);
2788   // tgl pulls
2789   snprintf(hname, 100, "%s_%s_TGLpull", GetNameId(), name);
2790   snprintf(htitle, 300, "TGL pull for \"%s\" @ %s;tg(#theta);#Delta tgl  / #sigma_{tgl};entries", GetNameId(), name);
2791   if(!(h = (TH2I*)gROOT->FindObject(hname))){
2792     h = new TH2I(hname, htitle, 100, -1., 1., 100, -4.5, 4.5);
2793   } else h->Reset();
2794   arr->AddAt(h, 7);
2795
2796   const Int_t kNdpt(150);
2797   const Int_t nNspc = 2*kNspc+1;
2798   Float_t lPt=0.1, lDPt=-.1, lSpc=-5.5;
2799   Float_t binsPt[kNpt+1], binsSpc[nNspc+1], binsDPt[kNdpt+1];
2800   for(Int_t i=0;i<kNpt+1; i++,lPt=TMath::Exp(i*.15)-1.) binsPt[i]=lPt;
2801   for(Int_t i=0; i<nNspc+1; i++,lSpc+=1.) binsSpc[i]=lSpc;
2802   for(Int_t i=0; i<kNdpt+1; i++,lDPt+=2.e-3) binsDPt[i]=lDPt;
2803
2804   // Pt resolution
2805   snprintf(hname, 100, "%s_%s_Pt", GetNameId(), name);
2806   snprintf(htitle, 300, "#splitline{P_{t} res for}{\"%s\" @ %s};p_{t} [GeV/c];#Delta p_{t}/p_{t}^{MC};SPECIES", GetNameId(), name);
2807   if(!(h = (TH3S*)gROOT->FindObject(hname))){
2808     h = new TH3S(hname, htitle,
2809                  kNpt, binsPt, kNdpt, binsDPt, nNspc, binsSpc);
2810     //ax = h->GetZaxis();
2811     //for(Int_t ib(1); ib<=ax->GetNbins(); ib++) ax->SetBinLabel(ib, fgParticle[ib-1]);
2812   } else h->Reset();
2813   arr->AddAt(h, 8);
2814   // 1/Pt pulls
2815   snprintf(hname, 100, "%s_%s_1Pt", GetNameId(), name);
2816   snprintf(htitle, 300, "#splitline{1/P_{t} pull for}{\"%s\" @ %s};1/p_{t}^{MC} [c/GeV];#Delta(1/p_{t})/#sigma(1/p_{t});SPECIES", GetNameId(), name);
2817   if(!(h = (TH3S*)gROOT->FindObject(hname))){
2818     h = new TH3S(hname, htitle,
2819                  kNpt, 0., 2., 100, -4., 4., kNspc, -5.5, kNspc-.5);
2820     //ax = h->GetZaxis();
2821     //for(Int_t ib(1); ib<=ax->GetNbins(); ib++) ax->SetBinLabel(ib, fgParticle[ib-1]);
2822   } else h->Reset();
2823   arr->AddAt(h, 9);
2824   // P resolution
2825   snprintf(hname, 100, "%s_%s_P", GetNameId(), name);
2826   snprintf(htitle, 300, "P res for \"%s\" @ %s;p [GeV/c];#Delta p/p^{MC};SPECIES", GetNameId(), name);
2827   if(!(h = (TH3S*)gROOT->FindObject(hname))){
2828     h = new TH3S(hname, htitle,
2829                  kNpt, binsPt, kNdpt, binsDPt, nNspc, binsSpc);
2830     //ax = h->GetZaxis();
2831     //for(Int_t ib(1); ib<=ax->GetNbins(); ib++) ax->SetBinLabel(ib, fgParticle[ib-1]);
2832   } else h->Reset();
2833   arr->AddAt(h, 10);
2834
2835   return arr;
2836 }
2837
2838
2839 //________________________________________________________
2840 TObjArray* AliTRDresolution::Histos()
2841 {
2842   //
2843   // Define histograms
2844   //
2845
2846   if(fContainer) return fContainer;
2847
2848   fContainer  = new TObjArray(kNclasses); fContainer->SetOwner(kTRUE);
2849   THnSparse *H(NULL);
2850   const Int_t nhn(100); Char_t hn[nhn]; TString st;
2851
2852   //++++++++++++++++++++++
2853   // cluster to detector
2854   snprintf(hn, nhn, "h%s", fgPerformanceName[kDetector]);
2855   if(!(H = (THnSparseI*)gROOT->FindObject(hn))){
2856     const Int_t mdim(6);
2857     const Char_t *cldTitle[mdim] = {"layer", fgkTitle[kPhi], "pad row", "centrality", "q [a.u.]", "no. of pads"/*, "tb [10 Hz]"*/};
2858     const Int_t cldNbins[mdim]   = {AliTRDgeometry::kNlayer, fgkNbins[kPhi], 76, AliTRDeventInfo::kCentralityClasses, 50, kNpads};
2859     const Double_t cldMin[mdim]  = {-0.5, fgkMin[kPhi], -0.5, -0.5, 0., 0.5},
2860                    cldMax[mdim]  = {AliTRDgeometry::kNlayer-0.5, fgkMax[kPhi], 75.5, AliTRDeventInfo::kCentralityClasses - 0.5, 1200., kNpads+.5};
2861     st = "cluster proprieties;";
2862     // define minimum info to be saved in non debug mode
2863     Int_t ndim=DebugLevel()>=1?mdim:Int_t(kNdimDet);
2864     for(Int_t idim(0); idim<ndim; idim++){ st += cldTitle[idim]; st+=";";}
2865     H = new THnSparseI(hn, st.Data(), ndim, cldNbins, cldMin, cldMax);
2866   } else H->Reset();
2867   fContainer->AddAt(H, kDetector);
2868   //++++++++++++++++++++++
2869   // cluster to tracklet residuals/pulls
2870   snprintf(hn, nhn, "h%s", fgPerformanceName[kCluster]);
2871   if(!(H = (THnSparseI*)gROOT->FindObject(hn))){
2872     const Int_t mdim(10);
2873     const Char_t *clTitle[mdim] = {"layer", fgkTitle[kPhi], fgkTitle[kEta], fgkTitle[kYrez], "#Deltax [cm]", "Q</Q", "Q/angle", "#Phi [deg]", "centrality", "no. of pads"};
2874     const Int_t clNbins[mdim]   = {AliTRDgeometry::kNlayer, fgkNbins[kPhi], fgkNbins[kEta], fgkNbins[kYrez], 45, 30, 30, 15, AliTRDeventInfo::kCentralityClasses, kNpads};
2875     const Double_t clMin[mdim]  = {-0.5, fgkMin[kPhi], fgkMin[kEta], fgkMin[kYrez]/10., -.5, 0.1, -2., -45, -0.5, 0.5},
2876                    clMax[mdim]  = {AliTRDgeometry::kNlayer-0.5, fgkMax[kPhi], fgkMax[kEta], fgkMax[kYrez]/10., 4., 2.1, 118., 45, AliTRDeventInfo::kCentralityClasses - 0.5, kNpads+.5};
2877     st = "cluster spatial&charge resolution;";
2878     // define minimum info to be saved in non debug mode
2879     Int_t ndim=DebugLevel()>=1?mdim:Int_t(kNdimCl);
2880     for(Int_t idim(0); idim<ndim; idim++){ st += clTitle[idim]; st+=";";}
2881     H = new THnSparseI(hn, st.Data(), ndim, clNbins, clMin, clMax);
2882   } else H->Reset();
2883   fContainer->AddAt(H, kCluster);
2884   //++++++++++++++++++++++
2885   // tracklet to TRD track
2886   snprintf(hn, nhn, "h%s", fgPerformanceName[kTracklet]);
2887   if(!(H = (THnSparseI*)gROOT->FindObject(hn))){
2888     const Int_t mdim(kNdim+8);
2889     Char_t *trTitle[mdim]; memcpy(trTitle, fgkTitle, kNdim*sizeof(Char_t*));
2890     Int_t trNbins[mdim]; memcpy(trNbins, fgkNbins, kNdim*sizeof(Int_t));
2891     Double_t trMin[mdim]; memcpy(trMin, fgkMin, kNdim*sizeof(Double_t));
2892     Double_t trMax[mdim]; memcpy(trMax, fgkMax, kNdim*sizeof(Double_t));
2893     // set specific fields
2894     trMin[kYrez] = -0.45; trMax[kYrez] = 0.45;
2895     trMin[kPrez] = -4.5; trMax[kPrez] = 4.5;
2896     trMin[kZrez] = -1.5; trMax[kZrez] = 1.5;
2897     trTitle[kBC]=StrDup("layer"); trNbins[kBC] = AliTRDgeometry::kNlayer; trMin[kBC] = -0.5; trMax[kBC] = AliTRDgeometry::kNlayer-0.5;
2898     Int_t jdim(kNdim);
2899     trTitle[jdim]=StrDup("centrality"); trNbins[jdim] = AliTRDeventInfo::kCentralityClasses; trMin[jdim] = -.5; trMax[jdim] = AliTRDeventInfo::kCentralityClasses - 0.5;
2900     jdim++; trTitle[jdim]=StrDup("occupancy [%]"); trNbins[jdim] = 12; trMin[jdim] = 25.; trMax[jdim] = 85.;
2901 //    jdim++; trTitle[jdim]=StrDup("gap [cm]"); trNbins[jdim] = 80; trMin[jdim] = 0.1; trMax[jdim] = 2.1;
2902 //     jdim++; trTitle[jdim]=StrDup("size_{0} [cm]"); trNbins[jdim] = 16; trMin[jdim] = 0.15; trMax[jdim] = 1.75;
2903 //     jdim++; trTitle[jdim]=StrDup("pos_{0} [cm]"); trNbins[jdim] = 10; trMin[jdim] = 0.; trMax[jdim] = 3.5;
2904 //     jdim++; trTitle[jdim]=StrDup("size_{1} [cm]"); trNbins[jdim] = 16; trMin[jdim] = 0.15; trMax[jdim] = 1.75;
2905 //     jdim++; trTitle[jdim]=StrDup("pos_{1} [cm]"); trNbins[jdim] = 10; trMin[jdim] = 0.; trMax[jdim] = 3.5;
2906
2907     st = "tracklet spatial&charge resolution;";
2908     // define minimum info to be saved in non debug mode
2909     Int_t ndim=DebugLevel()>=1?(jdim+1):kNdimTrklt;
2910     for(Int_t idim(0); idim<ndim; idim++){ st += trTitle[idim]; st+=";";}
2911     H = new THnSparseI(hn, st.Data(), ndim, trNbins, trMin, trMax);
2912   } else H->Reset();
2913   fContainer->AddAt(H, kTracklet);
2914   //++++++++++++++++++++++
2915   // tracklet to TRDin
2916   snprintf(hn, nhn, "h%s", fgPerformanceName[kTrackIn]);
2917   if(!(H = (THnSparseI*)gROOT->FindObject(hn))){
2918     // set specific fields
2919     const Int_t mdim(kNdim+3);
2920     Char_t *trinTitle[mdim]; memcpy(trinTitle, fgkTitle, kNdim*sizeof(Char_t*));
2921     Int_t trinNbins[mdim];   memcpy(trinNbins, fgkNbins, kNdim*sizeof(Int_t));
2922     Double_t trinMin[mdim];  memcpy(trinMin, fgkMin, kNdim*sizeof(Double_t));
2923     Double_t trinMax[mdim];  memcpy(trinMax, fgkMax, kNdim*sizeof(Double_t));
2924     trinNbins[kSpeciesChgRC] = Int_t(kNcharge)*(kNspc-1)+1; trinMin[kSpeciesChgRC] = -kNspc+0.5; trinMax[kSpeciesChgRC] = kNspc-0.5;
2925     trinTitle[kNdim]=StrDup("bin_p"); trinNbins[kNdim] = kNpt; trinMin[kNdim] = -0.5; trinMax[kNdim] = kNpt-.5;
2926     trinTitle[kNdim+1]=StrDup("dx [cm]"); trinNbins[kNdim+1]=48; trinMin[kNdim+1]=-2.4; trinMax[kNdim+1]=2.4;
2927     trinTitle[kNdim+2]=StrDup("Fill Bunch"); trinNbins[kNdim+2]=3500; trinMin[kNdim+2]=-0.5; trinMax[kNdim+2]=3499.5;
2928     st = "r-#phi/z/angular residuals @ TRD entry;";
2929     // define minimum info to be saved in non debug mode
2930     Int_t ndim=(DebugLevel()>=1?mdim:(kNdim+1));//kNdimTrkIn;
2931     for(Int_t idim(0); idim<ndim; idim++){st+=trinTitle[idim]; st+=";";}
2932     H = new THnSparseI(hn, st.Data(), ndim, trinNbins, trinMin, trinMax);
2933   } else H->Reset();
2934   fContainer->AddAt(H, kTrackIn);
2935   // tracklet to TRDout
2936 //  fContainer->AddAt(BuildMonitorContainerTracklet("TrkOUT"), kTrackOut);
2937
2938
2939   // Resolution histos
2940   if(!HasMCdata()) return fContainer;
2941
2942   //++++++++++++++++++++++
2943   // cluster to TrackRef residuals/pulls
2944   snprintf(hn, nhn, "h%s", fgPerformanceName[kMCcluster]);
2945   if(!(H = (THnSparseI*)gROOT->FindObject(hn))){
2946     const Char_t *clTitle[kNdim] = {"layer", fgkTitle[kPhi], fgkTitle[kEta], fgkTitle[kYrez], "#Deltax [cm]", "Q</Q", fgkTitle[kSpeciesChgRC], "#Phi [deg]"};
2947     const Int_t clNbins[kNdim]   = {AliTRDgeometry::kNlayer, fgkNbins[kPhi], fgkNbins[kEta], fgkNbins[kYrez], 20, 10, Int_t(kNcharge)*AliPID::kSPECIES+1, 15};
2948     const Double_t clMin[kNdim]  = {-0.5, fgkMin[kPhi], fgkMin[kEta], fgkMin[kYrez]/10., 0., 0.1, -AliPID::kSPECIES-0.5, -45},
2949                    clMax[kNdim]  = {AliTRDgeometry::kNlayer-0.5, fgkMax[kPhi], fgkMax[kEta], fgkMax[kYrez]/10., 4., 2.1, AliPID::kSPECIES+0.5, 45};
2950     st = "MC cluster spatial resolution;";
2951     // define minimum info to be saved in non debug mode
2952     Int_t ndim=DebugLevel()>=1?kNdim:4;
2953     for(Int_t idim(0); idim<ndim; idim++){ st += clTitle[idim]; st+=";";}
2954     H = new THnSparseI(hn, st.Data(), ndim, clNbins, clMin, clMax);
2955   } else H->Reset();
2956   fContainer->AddAt(H, kMCcluster);
2957   //++++++++++++++++++++++
2958   // tracklet to TrackRef
2959   snprintf(hn, nhn, "h%s", fgPerformanceName[kMCtracklet]);
2960   if(!(H = (THnSparseI*)gROOT->FindObject(hn))){
2961     Char_t *trTitle[kNdim]; memcpy(trTitle, fgkTitle, kNdim*sizeof(Char_t*));
2962     Int_t trNbins[kNdim]; memcpy(trNbins, fgkNbins, kNdim*sizeof(Int_t));
2963     Double_t trMin[kNdim]; memcpy(trMin, fgkMin, kNdim*sizeof(Double_t));
2964     Double_t trMax[kNdim]; memcpy(trMax, fgkMax, kNdim*sizeof(Double_t));
2965     // set specific fields
2966     trTitle[kBC]=StrDup("layer"); trNbins[kBC] = AliTRDgeometry::kNlayer; trMin[kBC] = -0.5; trMax[kBC] = AliTRDgeometry::kNlayer-0.5;
2967     trMin[kYrez] = -0.54; trMax[kYrez] = -trMin[kYrez];
2968     trMin[kPrez] = -4.5; trMax[kPrez] = -trMin[kPrez];
2969     trMin[kZrez] = -1.5; trMax[kZrez] = -trMin[kZrez];
2970     trNbins[kSpeciesChgRC] = Int_t(kNcharge)*AliPID::kSPECIES+1;trMin[kSpeciesChgRC] = -AliPID::kSPECIES-0.5; trMax[kSpeciesChgRC] = AliPID::kSPECIES+0.5;
2971
2972     st = "MC tracklet spatial resolution;";
2973     // define minimum info to be saved in non debug mode
2974     Int_t ndim=DebugLevel()>=1?kNdim:4;
2975     for(Int_t idim(0); idim<ndim; idim++){ st += trTitle[idim]; st+=";";}
2976     H = new THnSparseI(hn, st.Data(), ndim, trNbins, trMin, trMax);
2977   } else H->Reset();
2978   fContainer->AddAt(H, kMCtracklet);
2979   //++++++++++++++++++++++
2980   // TRDin to TrackRef
2981   snprintf(hn, nhn, "h%s", fgPerformanceName[kMCtrackIn]);
2982   if(!(H = (THnSparseI*)gROOT->FindObject(hn))){
2983     st = "MC r-#phi/z/angular residuals @ TRD entry;";
2984     // set specific fields
2985     Int_t trNbins[kNdim]; memcpy(trNbins, fgkNbins, kNdim*sizeof(Int_t));
2986     Double_t trMin[kNdim]; memcpy(trMin, fgkMin, kNdim*sizeof(Double_t));
2987     Double_t trMax[kNdim]; memcpy(trMax, fgkMax, kNdim*sizeof(Double_t));
2988     trMin[kYrez] = -0.54; trMax[kYrez] = -trMin[kYrez];
2989     trMin[kPrez] = -2.4; trMax[kPrez] = -trMin[kPrez];
2990     trMin[kZrez] = -0.9; trMax[kZrez] = -trMin[kZrez];
2991     trNbins[kSpeciesChgRC] = Int_t(kNcharge)*AliPID::kSPECIES+1;trMin[kSpeciesChgRC] = -AliPID::kSPECIES-0.5; trMax[kSpeciesChgRC] = AliPID::kSPECIES+0.5;
2992     // define minimum info to be saved in non debug mode
2993     Int_t ndim=DebugLevel()>=1?kNdim:7;
2994     for(Int_t idim(0); idim<ndim; idim++){ st += fgkTitle[idim]; st+=";";}
2995     H = new THnSparseI(hn, st.Data(), ndim, trNbins, trMin, trMax);
2996   } else H->Reset();
2997   fContainer->AddAt(H, kMCtrackIn);
2998   //++++++++++++++++++++++
2999   // track to TrackRef
3000   snprintf(hn, nhn, "h%s", fgPerformanceName[kMCtrack]);
3001   if(!(H = (THnSparseI*)gROOT->FindObject(hn))){
3002     Char_t *trTitle[kNdim+1]; memcpy(trTitle, fgkTitle, kNdim*sizeof(Char_t*));
3003     Int_t trNbins[kNdim+1]; memcpy(trNbins, fgkNbins, kNdim*sizeof(Int_t));
3004     Double_t trMin[kNdim+1]; memcpy(trMin, fgkMin, kNdim*sizeof(Double_t));
3005     Double_t trMax[kNdim+1]; memcpy(trMax, fgkMax, kNdim*sizeof(Double_t));
3006     // set specific fields
3007     trTitle[kBC]=StrDup("layer"); trNbins[kBC] = AliTRDgeometry::kNlayer; trMin[kBC] = -0.5; trMax[kBC] = AliTRDgeometry::kNlayer-0.5;
3008     trMin[kYrez] = -0.9; trMax[kYrez] = -trMin[kYrez];
3009     trMin[kPrez] = -1.5; trMax[kPrez] = -trMin[kPrez];
3010     trMin[kZrez] = -0.9; trMax[kZrez] = -trMin[kZrez];
3011     trNbins[kSpeciesChgRC] = Int_t(kNcharge)*AliPID::kSPECIES+1;trMin[kSpeciesChgRC] = -AliPID::kSPECIES-0.5; trMax[kSpeciesChgRC] = AliPID::kSPECIES+0.5;
3012     trTitle[kNdim]=StrDup("#Deltap_{t}/p_{t} [%]"); trNbins[kNdim] = 25; trMin[kNdim] = -4.5; trMax[kNdim] = 20.5;
3013
3014     st = "MC track spatial&p_{t} resolution;";
3015     // define minimum info to be saved in non debug mode
3016     Int_t ndim=DebugLevel()>=1?(kNdim+1):4;
3017     for(Int_t idim(0); idim<ndim; idim++){ st += trTitle[idim]; st+=";";}
3018     H = new THnSparseI(hn, st.Data(), ndim, trNbins, trMin, trMax);
3019   } else H->Reset();
3020   fContainer->AddAt(H, kMCtrack);
3021
3022   return fContainer;
3023 }
3024
3025 //____________________________________________________________________
3026 Bool_t AliTRDresolution::FitTrack(const Int_t np, AliTrackPoint *points, Float_t param[10])
3027 {
3028 //
3029 // Fit track with a staight line using the "np" clusters stored in the array "points".
3030 // The following particularities are stored in the clusters from points:
3031 //   1. pad tilt as cluster charge
3032 //   2. pad row cross or vertex constrain as fake cluster with cluster type 1
3033 // The parameters of the straight line fit are stored in the array "param" in the following order :
3034 //     param[0] - x0 reference radial position
3035 //     param[1] - y0 reference r-phi position @ x0
3036 //     param[2] - z0 reference z position @ x0
3037 //     param[3] - slope dy/dx
3038 //     param[4] - slope dz/dx
3039 //
3040 // Attention :
3041 // Function should be used to refit tracks for B=0T
3042 //
3043
3044   if(np<40){
3045     if(AliLog::GetDebugLevel("PWGPP", "AliTRDresolution")>1) printf("D-AliTRDresolution::FitTrack: Not enough clusters to fit a track [%d].\n", np);
3046     return kFALSE;
3047   }
3048   TLinearFitter yfitter(2, "pol1"), zfitter(2, "pol1");
3049
3050   Double_t x0(0.);
3051   for(Int_t ip(0); ip<np; ip++) x0+=points[ip].GetX();
3052   x0/=Float_t(np);
3053
3054   Double_t x, y, z, dx, tilt(0.);
3055   for(Int_t ip(0); ip<np; ip++){
3056     x = points[ip].GetX(); z = points[ip].GetZ();
3057     dx = x - x0;
3058     zfitter.AddPoint(&dx, z, points[ip].GetClusterType()?1.e-3:1.);
3059   }
3060   if(zfitter.Eval() != 0) return kFALSE;
3061
3062   Double_t z0    = zfitter.GetParameter(0);
3063   Double_t dzdx  = zfitter.GetParameter(1);
3064   for(Int_t ip(0); ip<np; ip++){
3065     if(points[ip].GetClusterType()) continue;
3066     x    = points[ip].GetX();
3067     dx   = x - x0;
3068     y    = points[ip].GetY();
3069     z    = points[ip].GetZ();
3070     tilt = points[ip].GetCharge();
3071     y -= tilt*(-dzdx*dx + z - z0);
3072     Float_t xyz[3] = {x, y, z}; points[ip].SetXYZ(xyz);
3073     yfitter.AddPoint(&dx, y, 1.);
3074   }
3075   if(yfitter.Eval() != 0) return kFALSE;
3076   Double_t y0   = yfitter.GetParameter(0);
3077   Double_t dydx = yfitter.GetParameter(1);
3078
3079   param[0] = x0; param[1] = y0; param[2] = z0; param[3] = dydx; param[4] = dzdx;
3080   if(AliLog::GetDebugLevel("PWGPP", "AliTRDresolution")>3) printf("D-AliTRDresolution::FitTrack: x0[%f] y0[%f] z0[%f] dydx[%f] dzdx[%f].\n", x0, y0, z0, dydx, dzdx);
3081   return kTRUE;
3082 }
3083
3084 //____________________________________________________________________
3085 Bool_t AliTRDresolution::FitTracklet(const Int_t ly, const Int_t np, const AliTrackPoint *points, const Float_t param[10], Float_t par[3])
3086 {
3087 //
3088 // Fit tracklet with a staight line using the coresponding subset of clusters out of the total "np" clusters stored in the array "points".
3089 // See function FitTrack for the data stored in the "clusters" array
3090
3091 // The parameters of the straight line fit are stored in the array "param" in the following order :
3092 //     par[0] - x0 reference radial position
3093 //     par[1] - y0 reference r-phi position @ x0
3094 //     par[2] - slope dy/dx
3095 //
3096 // Attention :
3097 // Function should be used to refit tracks for B=0T
3098 //
3099
3100   TLinearFitter yfitter(2, "pol1");
3101
3102   // grep data for tracklet
3103   Double_t x0(0.), x[60], y[60], dy[60];
3104   Int_t nly(0);
3105   for(Int_t ip(0); ip<np; ip++){
3106     if(points[ip].GetClusterType()) continue;
3107     if(points[ip].GetVolumeID() != ly) continue;
3108     Float_t xt(points[ip].GetX())
3109            ,yt(param[1] + param[3] * (xt - param[0]));
3110     x[nly] = xt;
3111     y[nly] = points[ip].GetY();
3112     dy[nly]= y[nly]-yt;
3113     x0    += xt;
3114     nly++;
3115   }
3116   if(nly<10){
3117     if(AliLog::GetDebugLevel("PWGPP", "AliTRDresolution")>1) printf("D-AliTRDresolution::FitTracklet: Not enough clusters to fit a tracklet [%d].\n", nly);
3118     return kFALSE;
3119   }
3120   // set radial reference for fit
3121   x0 /= Float_t(nly);
3122
3123   // find tracklet core
3124   Double_t mean(0.), sig(1.e3);
3125   AliMathBase::EvaluateUni(nly, dy, mean, sig, 0);
3126
3127   // simple cluster error parameterization
3128   Float_t kSigCut = TMath::Sqrt(5.e-4 + param[3]*param[3]*0.018);
3129
3130   // fit tracklet core
3131   for(Int_t jly(0); jly<nly; jly++){
3132     if(TMath::Abs(dy[jly]-mean)>kSigCut) continue;
3133     Double_t dx(x[jly]-x0);
3134     yfitter.AddPoint(&dx, y[jly], 1.);
3135   }
3136   if(yfitter.Eval() != 0) return kFALSE;
3137   par[0] = x0;
3138   par[1] = yfitter.GetParameter(0);
3139   par[2] = yfitter.GetParameter(1);
3140   return kTRUE;
3141 }
3142
3143 //____________________________________________________________________
3144 Bool_t AliTRDresolution::UseTrack(const Int_t np, const AliTrackPoint *points, Float_t param[10])
3145 {
3146 //
3147 // Global selection mechanism of tracksbased on cluster to fit residuals
3148 // The parameters are the same as used ni function FitTrack().
3149
3150   const Float_t kS(0.6), kM(0.2);
3151   TH1S h("h1", "", 100, -5.*kS, 5.*kS);
3152   Float_t dy, dz, s, m;
3153   for(Int_t ip(0); ip<np; ip++){
3154     if(points[ip].GetClusterType()) continue;
3155     Float_t x0(points[ip].GetX())
3156           ,y0(param[1] + param[3] * (x0 - param[0]))
3157           ,z0(param[2] + param[4] * (x0 - param[0]));
3158     dy=points[ip].GetY() - y0; h.Fill(dy);
3159     dz=points[ip].GetZ() - z0;
3160   }
3161   TF1 fg("fg", "gaus", -5.*kS, 5.*kS);
3162   fg.SetParameter(1, 0.);
3163   fg.SetParameter(2, 2.e-2);
3164   h.Fit(&fg, "QN");
3165   m=fg.GetParameter(1); s=fg.GetParameter(2);
3166   if(s>kS || TMath::Abs(m)>kM) return kFALSE;
3167   return kTRUE;
3168 }
3169
3170 //________________________________________________________
3171 void AliTRDresolution::GetLandauMpvFwhm(TF1 * const f, Float_t &mpv, Float_t &xm, Float_t &xM)
3172 {
3173   //
3174   // Get the most probable value and the full width half mean
3175   // of a Landau distribution
3176   //
3177
3178   const Float_t dx = 1.;
3179   mpv = f->GetParameter(1);
3180   Float_t fx, max = f->Eval(mpv);
3181
3182   xm = mpv - dx;
3183   while((fx = f->Eval(xm))>.5*max){
3184     if(fx>max){
3185       max = fx;
3186       mpv = xm;
3187     }
3188     xm -= dx;
3189   }
3190
3191   xM += 2*(mpv - xm);
3192   while((fx = f->Eval(xM))>.5*max) xM += dx;
3193 }
3194
3195
3196 // #include "TFile.h"
3197 // //________________________________________________________
3198 // Bool_t AliTRDresolution::LoadCorrection(const Char_t *file)
3199 // {
3200 //   if(!file){
3201 //     AliWarning("Use cluster position as in reconstruction.");
3202 //     SetLoadCorrection();
3203 //     return kTRUE;
3204 //   }
3205 //   TDirectory *cwd(gDirectory);
3206 //   TString fileList;
3207 //   FILE *filePtr = fopen(file, "rt");
3208 //   if(!filePtr){
3209 //     AliWarning(Form("Couldn't open correction list \"%s\". Use cluster position as in reconstruction.", file));
3210 //     SetLoadCorrection();
3211 //     return kFALSE;
3212 //   }
3213 //   TH2 *h2 = new TH2F("h2", ";time [time bins];detector;dx [#mum]", 30, -0.5, 29.5, AliTRDgeometry::kNdet, -0.5, AliTRDgeometry::kNdet-0.5);
3214 //   while(fileList.Gets(filePtr)){
3215 //     if(!TFile::Open(fileList.Data())) {
3216 //       AliWarning(Form("Couldn't open \"%s\"", fileList.Data()));
3217 //       continue;
3218 //     } else AliInfo(Form("\"%s\"", fileList.Data()));
3219 //
3220 //     TTree *tSys = (TTree*)gFile->Get("tSys");
3221 //     h2->SetDirectory(gDirectory); h2->Reset("ICE");
3222 //     tSys->Draw("det:t>>h2", "dx", "goff");
3223 //     for(Int_t idet(0); idet<AliTRDgeometry::kNdet; idet++){
3224 //       for(Int_t it(0); it<30; it++) fXcorr[idet][it]+=(1.e-4*h2->GetBinContent(it+1, idet+1));
3225 //     }
3226 //     h2->SetDirectory(cwd);
3227 //     gFile->Close();
3228 //   }
3229 //   cwd->cd();
3230 //
3231 //   if(AliLog::GetDebugLevel("PWGPP", "AliTRDresolution")>=2){
3232 //     for(Int_t il(0); il<184; il++) printf("-"); printf("\n");
3233 //     printf("DET|");for(Int_t it(0); it<30; it++) printf(" tb%02d|", it); printf("\n");
3234 //     for(Int_t il(0); il<184; il++) printf("-"); printf("\n");
3235 //     FILE *fout = fopen("TRD.ClusterCorrection.txt", "at");
3236 //     fprintf(fout, "  static const Double_t dx[AliTRDgeometry::kNdet][30]={\n");
3237 //     for(Int_t idet(0); idet<AliTRDgeometry::kNdet; idet++){
3238 //       printf("%03d|", idet);
3239 //       fprintf(fout, "    {");
3240 //       for(Int_t it(0); it<30; it++){
3241 //         printf("%+5.0f|", 1.e4*fXcorr[idet][it]);
3242 //         fprintf(fout, "%+6.4f%c", fXcorr[idet][it], it==29?' ':',');
3243 //       }
3244 //       printf("\n");
3245 //       fprintf(fout, "}%c\n", idet==AliTRDgeometry::kNdet-1?' ':',');
3246 //     }
3247 //     fprintf(fout, "  };\n");
3248 //   }
3249 //   SetLoadCorrection();
3250 //   return kTRUE;
3251 // }
3252
3253 //________________________________________________________
3254 void AliTRDresolution::SetProcesses(Bool_t det, Bool_t cl, Bool_t trklt, Bool_t trkin)
3255 {
3256 // steer processes
3257   if(det) SETBIT(fSteer, kDetector); else CLRBIT(fSteer, kDetector);
3258   if(cl)  SETBIT(fSteer, kCluster); else CLRBIT(fSteer, kCluster);
3259   if(trklt) SETBIT(fSteer, kTracklet); else CLRBIT(fSteer, kTracklet);
3260   if(trkin) SETBIT(fSteer, kTrackIn); else CLRBIT(fSteer, kTrackIn);
3261 }
3262
3263
3264 //________________________________________________________
3265 void AliTRDresolution::SetDump3D(Bool_t det, Bool_t cl, Bool_t trklt, Bool_t trkin)
3266 {
3267 // steer processes
3268   if(det) SETBIT(fSteer, 4+kDetector); else CLRBIT(fSteer, 4+kDetector);
3269   if(cl)  SETBIT(fSteer, 4+kCluster); else CLRBIT(fSteer, 4+kCluster);
3270   if(trklt) SETBIT(fSteer, 4+kTracklet); else CLRBIT(fSteer, 4+kTracklet);
3271   if(trkin) SETBIT(fSteer, 4+kTrackIn); else CLRBIT(fSteer, 4+kTrackIn);
3272 }
3273