-updates
[u/mrichter/AliRoot.git] / PWGDQ / dielectron / macrosJPSI / ConfigJpsi_jb_PbPb.C
1 void InitHistograms(AliDielectron *die, Int_t cutDefinition);
2 void AddQAHistsPID(AliDielectron *die);
3 void AddQAHistsEP(AliDielectron *die);
4 void AddHistsEleEff(AliDielectron *die);
5
6 void InitCF(AliDielectron* die, Int_t cutDefinition);
7 void InitHF(AliDielectron* die, Int_t cutDefinition);
8
9 void SetupEventCuts(AliDielectron *die, ULong64_t triggers, Int_t cutDefinition);
10 void SetupTrackCuts(AliDielectron *die, Int_t cutDefinition);
11 void SetupV0Cuts( AliDielectron *die,  Int_t cutDefinition);
12 void SetupPairCuts( AliDielectron *die,  Int_t cutDefinition);
13
14 void ConfigEvtPlane(AliDielectron *die,  Int_t cutDefinition);
15 void ConfigBgrd(    AliDielectron *die,  Int_t cutDefinition);
16
17 void AddMCSignals(AliDielectron *die,  Int_t cutDefinition);
18 void SetEtaCorrection(AliDielectron *pid, Bool_t hasMC);
19 TVectorD *GetRunNumbers2011();
20 TVectorD *GetPDGcodes();
21 TVectorD *GetDeltaPhiBins();
22
23 TString names=("Event;PIDqa;Flow;avgPt;Rec;TPC;TOF;TRD;Ionut;TPC-TOF-TRD;NOPID;LegEff;SysPt;SysEta;SysEle;SysPro;SysSPD;SysMC;SysMCele");
24 enum { kEvent, kPIDqa, kFlow, kAvgPt, kRec, kTPC, kTOF, kTRD, kIonut, kTPCTOFTRD, kNoPID, kLegEff, kSysPt, kSysEta, kSysEle, kSysPro, kSysSPD, kSysMC,kSysMCele, kPIDQA };
25
26 TObjArray *arrNames=names.Tokenize(";");
27 const Int_t nDie=arrNames->GetEntries();
28
29 Bool_t  isESD = kTRUE;
30 TString list  = gSystem->Getenv("LIST");
31
32 AliDielectron* ConfigJpsi_jb_PbPb(Int_t cutDefinition, Bool_t hasMC=kFALSE, ULong64_t triggers=AliVEvent::kCentral | AliVEvent::kSemiCentral | AliVEvent::kMB)
33 {
34   //
35   // Setup the instance of AliDielectron
36   //
37
38   // gsi train?
39   TString trainRoot = gSystem->Getenv("TRAIN_ROOT");
40   Bool_t isGSItrain = (trainRoot.IsNull()?kFALSE:kTRUE); 
41   if(isGSItrain) {
42     // find mc or not?
43     if( list.IsNull()) list=prod;
44     if( list.Contains("LHC10h")   || list.Contains("LHC11h")   ) hasMC=kFALSE;
45     if( list.Contains("LHC11a10") || list.Contains("LHC12a17") ||  list.Contains("LHC13c7")) hasMC=kTRUE;
46   }
47
48   //ESD handler?
49   isESD=(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()->IsA()==AliESDInputHandler::Class());
50
51   // switch configurations ON and OFF
52   ///  if(hasMC) { // MONTE CARLO
53   ///  switch(cutDefinition) {
54   ///  case kEvent:   /* */ break;          // event quantities (mult, ep, trigger, ...)
55       //    case kPIDqa:   /* */ break;          // post calibration and validation of TPC PID
56       //    case kRec:     /* */ break;          // to calculate partial efficiencies, in particular the geom. acceptance
57       //case kLegEff:  /* */ break;          // single electron efficiency calculation
58   ///  case kAvgPt:   /* */ break;          // mean pt analysis
59       //    case kTPC:   /* */ break;
60       //    case kTOF:   /* */ break;
61       //    case kTRD:   /* */ break;
62       //    case kIonut: /* */ break;
63       //    case kSysMC: /* */ break;
64       //    case kSysMCele: /* */ break;
65       //    case kNoPID: /* */ break;
66   ///  default:         return 0x0;
67   ///  }
68   ///} else { // COLLISION DATA
69   ///  switch(cutDefinition) {
70   ///  case kEvent:   /* */ break;          // event quantities (mult, ep, trigger, ...)
71       //case kPIDqa:   /* */ break;          // for post calibration and validation of TPC PID 
72       //    case kFlow:    /* */ break;          // flow calculation
73       //    case kNoPID: /* */ break;
74       //    case kTPC:   /* */ break;
75       //    case kTOF:   /* */ break;
76       //    case kTRD:   /* */ break;
77       //    case kIonut:       /* */ break;
78       //    case kTPCTOFTRD:   /* */ break;
79   ///   case kAvgPt:       /* */ break;
80       //    case kSysPt:       /* */ break;
81       // case kSysEta:       /* */ break;
82       // case kSysEle:       /* */ break;
83       // case kSysPro:       /* */ break;
84       //    case kSysSPD:       /* */ break;
85   ///   default:         return 0x0;
86   ///  }
87   ///}
88
89
90   // task name
91   TString name=Form("%02d",cutDefinition);
92   if (cutDefinition<arrNames->GetEntriesFast())  name=arrNames->At(cutDefinition)->GetName();
93   printf(" Adding %s%s config %s for %s \n",(isESD?"ESD":"AOD"),(hasMC?" MC":""),name.Data(),list.Data());
94
95   // init AliDielectron
96   AliDielectron *die = new AliDielectron(Form("%s",name.Data()), Form("%s",name.Data()));
97   die->SetHasMC(hasMC);
98
99   /* vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv CUTS vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv */
100   SetupEventCuts(die,triggers,cutDefinition);
101   SetupV0Cuts(die,cutDefinition);
102   SetupTrackCuts(die,cutDefinition);
103   SetupPairCuts(die,cutDefinition);
104
105   /* vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv MISC vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv */
106   // Monte Carlo Signals
107   if(hasMC)  AddMCSignals(die, cutDefinition);
108   // PID post calibartion
109   //  if(cutDefinition!=kEvent) SetEtaCorrection(die,hasMC); // OLD
110   // bgrd estimators
111   ////  if(!hasMC) 
112   ConfigBgrd(die,cutDefinition);
113   // tpc event plane configuration
114   //  if(!hasMC) 
115   ConfigEvtPlane(die,cutDefinition);
116   // prefilter settings
117   if(cutDefinition==kEvent || cutDefinition==kNoPID || cutDefinition==kPIDqa || cutDefinition==kLegEff)
118     die->SetNoPairing();
119   else
120     die->SetPreFilterAllSigns();
121   //die->SetPreFilterUnlikeOnly();
122   // load single electron effieciency map ATTENTION
123   if(!hasMC && 0)           AliDielectronVarManager::InitEffMap("/home/aliceexp/jbook/gsi-train-trunk/jbook_jpsi/effMap.root");
124   //   AliDielectronVarManager::InitEffMap("/sw/alice/gsi-svn/testtrain/effMap.root");
125   if(cutDefinition==kAvgPt) die->SetEffMapFilename("alien:///alice/cern.ch/user/j/jbook/PWGDQ/dielectron/files/effMap.root");
126
127   /* vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv OUTPUT vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv */
128   // histogram setup
129   InitHistograms(die,cutDefinition);
130   // histogram grid setup
131   InitHF(die,cutDefinition);
132   // CF container setup
133   InitCF(die,cutDefinition);
134
135   // cut QA
136   die->SetCutQA();
137
138   return die;
139 }
140
141 //______________________________________________________________________________________
142 void SetupEventCuts(AliDielectron *die, ULong64_t triggers, Int_t cutDefinition)
143 {
144   //
145   // Setup the event cuts
146   //
147
148   // trigger specific centrality cuts (reject trigger inefficiencies)
149   Double_t minCent=0.0, maxCent=100.;
150   if(!die->GetHasMC()) {
151     switch(triggers) {
152     // case AliVEvent::kCentral:     minCent= 0.; maxCent=10.; break; //0-9
153     // case AliVEvent::kSemiCentral: minCent=10.; maxCent=50.; break; //12-53
154     // case AliVEvent::kMB:          minCent=10.; maxCent=90.; break;
155     default:                      minCent= 0.; maxCent=90.; break;
156     }
157   }
158   //  if(cutDefinition >= kEtaGap01) {minCent=20.; maxCent=50.;} // v2 analysis
159   if(cutDefinition == kSysMC) {minCent=0.; maxCent=50.;}
160   if(cutDefinition == kSysMCele) {minCent=0.; maxCent=50.;}
161
162   // VZERO multiplicity vs. number ob global tracks cut
163   TF1 *fMean  = new TF1("fMean", "pol1",               0,25e+3);
164   fMean->SetParameters(691.633, 1.4892);
165   TF1 *fSigma = new TF1("fSigma","[0]+sqrt([1]*x+[2])",0,25e+3);
166   fSigma->SetParameters(-83.6599, 36.7677, 69530.7);
167
168   AliDielectronEventCuts *eventCuts=new AliDielectronEventCuts("vertex","vertex");
169   if(!isESD) eventCuts->SetVertexType(AliDielectronEventCuts::kVtxAny);
170   eventCuts->SetRequireVertex();
171   eventCuts->SetMinVtxContributors(1);
172   eventCuts->SetVertexZ(-10.,+10.);
173   eventCuts->SetCentralityRange(minCent,maxCent);
174   //  eventCuts->SetCutOnV0MultipicityNTrks(fMean, fSigma, 4.0);
175   //  eventCuts->SetRunRejection(AliDielectronHelper::MakeArbitraryBinning("170592,170593,170594"));
176   eventCuts->Print();
177   die->GetEventFilter().AddCuts(eventCuts);
178
179 }
180
181 //______________________________________________________________________________________
182 void SetupTrackCuts(AliDielectron *die, Int_t cutDefinition)
183 {
184   //
185   // Setup the track cuts
186   //
187   Bool_t hasMC=die->GetHasMC();
188
189   // Quality cuts
190   //  die->GetTrackFilter().AddCuts(cuts);
191
192   /* vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv FILTER CUTS vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv */
193   // AOD track filter (needs to be first cut to speed up)
194   AliDielectronTrackCuts *trkFilter = new AliDielectronTrackCuts("TrkFilter","TrkFilter");
195   trkFilter->SetAODFilterBit(AliDielectronTrackCuts::kTPCqual);
196   //  trkFilter->SetMinNCrossedRowsOverFindable(0.6);
197
198   /* vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv TRACK CUTS vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv */
199   AliDielectronVarCuts *varAccCuts   = new AliDielectronVarCuts("acc","acc");
200   AliDielectronCutGroup  *grpRecCuts = new AliDielectronCutGroup("rec","rec",AliDielectronCutGroup::kCompAND);
201   AliDielectronVarCuts   *varRecCuts = new AliDielectronVarCuts("VarRecCuts","VarRecCuts");
202   AliDielectronTrackCuts *trkRecCuts = new AliDielectronTrackCuts("TrkRecCuts","TrkRecCuts");
203
204   // config specific cuts
205   switch(cutDefinition) {
206   case kPIDqa:
207     varAccCuts->AddCut(AliDielectronVarManager::kPt,           0.85, 1e30);
208     varRecCuts->AddCut(AliDielectronVarManager::kTPCclsSegments,7.,   8.0);
209     break;
210   case kEvent:
211   case kFlow:
212   case kRec:
213   case kIonut:
214   case kTRD:
215   case kTPCTOFTRD:
216   case kAvgPt:
217   case kNoPID:
218   case kSysMCele:
219     varAccCuts->AddCut(AliDielectronVarManager::kPt,           0.85, 1e30); ///ATTENTION
220     varAccCuts->AddCut(AliDielectronVarManager::kEta,         -0.8,   0.8); ////ATTENTION
221   case kLegEff:
222     varRecCuts->AddCut(AliDielectronVarManager::kTPCclsSegments,7.,   8.0);
223     trkRecCuts->SetITSclusterCut(AliDielectronTrackCuts::kOneOf, 3); // SPD any
224     //if(hasMC)  varAccCuts->AddCut(AliDielectronVarManager::kEta,         -0.9,   0.9);
225     //else
226     ///       
227     break;
228   case kTOF:
229   case kTPC:
230     varAccCuts->AddCut(AliDielectronVarManager::kPt,           0.95, 1e30);    //0.8
231     varAccCuts->AddCut(AliDielectronVarManager::kEta,         -0.9,   0.9);
232     varRecCuts->AddCut(AliDielectronVarManager::kNclsTPC,     70.0, 160.0);
233     trkRecCuts->SetITSclusterCut(AliDielectronTrackCuts::kOneOf, 7); // ITS-3 = 1+2+4
234     break;
235     ///////////////////////////////////////////////////////////////////////////////////////////// systematics
236   case kSysPt:
237     varAccCuts->AddCut(AliDielectronVarManager::kPt,           1.1, 20./*1e30*/); ///ATTENTION
238     varAccCuts->AddCut(AliDielectronVarManager::kEta,         -0.8,   0.8); ////ATTENTION
239     varRecCuts->AddCut(AliDielectronVarManager::kTPCclsSegments,7.,   8.0);
240     trkRecCuts->SetITSclusterCut(AliDielectronTrackCuts::kOneOf, 3); // SPD any
241     break;
242   case kSysEta:
243     varAccCuts->AddCut(AliDielectronVarManager::kPt,           0.85, 20./*1e30*/); ///ATTENTION
244     varAccCuts->AddCut(AliDielectronVarManager::kEta,         -0.9,   0.9); ////ATTENTION
245     varRecCuts->AddCut(AliDielectronVarManager::kTPCclsSegments,7.,   8.0);
246     trkRecCuts->SetITSclusterCut(AliDielectronTrackCuts::kOneOf, 3); // SPD any
247     break;
248   case kSysEle:
249   case kSysPro:
250     varAccCuts->AddCut(AliDielectronVarManager::kPt,           0.85, 20./*1e30*/); ///ATTENTION
251     varAccCuts->AddCut(AliDielectronVarManager::kEta,         -0.8,   0.8); ////ATTENTION
252     varRecCuts->AddCut(AliDielectronVarManager::kTPCclsSegments,7.,   8.0);
253     trkRecCuts->SetITSclusterCut(AliDielectronTrackCuts::kOneOf, 3); // SPD any
254     break;
255   case kSysSPD:
256     varAccCuts->AddCut(AliDielectronVarManager::kPt,           0.85, 20./*1e30*/); ///ATTENTION
257     varAccCuts->AddCut(AliDielectronVarManager::kEta,         -0.8,   0.8); ////ATTENTION
258     varRecCuts->AddCut(AliDielectronVarManager::kTPCclsSegments,7.,   8.0);
259     trkRecCuts->SetITSclusterCut(AliDielectronTrackCuts::kOneOf, 1); // SPD any
260     break;
261   case kSysMC:
262     varAccCuts->AddCut(AliDielectronVarManager::kPt,           0.85, 20./*1e30*/); ///ATTENTION
263     varAccCuts->AddCut(AliDielectronVarManager::kEta,         -0.9,   0.9); ////ATTENTION
264     varRecCuts->AddCut(AliDielectronVarManager::kTPCclsSegments,7.,   8.0);
265     trkRecCuts->SetITSclusterCut(AliDielectronTrackCuts::kOneOf, 3); // SPD any
266     break;
267   }
268
269   // standrad reconstruction cuts
270   varRecCuts->AddCut(AliDielectronVarManager::kImpactParXY, -1.0,   1.0);
271   varRecCuts->AddCut(AliDielectronVarManager::kImpactParZ,  -3.0,   3.0);
272   varRecCuts->AddCut(AliDielectronVarManager::kTPCchi2Cl,    0.0,   4.0);
273   varRecCuts->AddCut(AliDielectronVarManager::kKinkIndex0,   0.0);
274   //  varRecCuts->AddCut(AliDielectronVarManager::kV0Index0,     0.0);
275   if(cutDefinition!=kPIDqa) trkRecCuts->SetRequireITSRefit(kTRUE);
276   trkRecCuts->SetRequireTPCRefit(kTRUE);
277
278   /* vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv PID CUTS vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv */
279   AliDielectronCutGroup *grpPIDCuts = new AliDielectronCutGroup("PID","PID",AliDielectronCutGroup::kCompAND);
280   AliDielectronVarCuts  *pidSelCuts = new AliDielectronVarCuts("selPIDCuts","selPIDCuts");
281   pidSelCuts->AddCut(AliDielectronVarManager::kTRDpidQuality,      4.0,   6.0);
282   pidSelCuts->AddCut(AliDielectronVarManager::kTRDchi2,            0.0,   2.0);
283   AliDielectronVarCuts *pidVarCuts = new AliDielectronVarCuts("varPIDCuts","varPIDCuts");
284   AliDielectronVarCuts *pidMCCuts  = new AliDielectronVarCuts("mcPIDCuts","mcPIDCuts");
285   AliDielectronPID *pidCuts        = new AliDielectronPID("PIDCuts","PIDCuts");
286
287   switch(cutDefinition) {
288   case kPIDqa:
289     pidCuts->AddCut(AliDielectronPID::kTPC,AliPID::kElectron,-10.,10.);
290     break;
291   case kTOF:
292     pidVarCuts->AddCut(AliDielectronVarManager::kTOFbeta,      0.2,   0.9, kTRUE);
293     pidCuts->AddCut(AliDielectronPID::kTOF,AliPID::kElectron,-3,3.,0.,0.,kFALSE,
294                     AliDielectronPID::kIfAvailable);
295   case kTPC:
296     pidCuts->AddCut(AliDielectronPID::kTPC,AliPID::kElectron,-3.,4.);
297     pidCuts->AddCut(AliDielectronPID::kTPC,AliPID::kPion,-100.,4.0,0.,0.,kTRUE);
298     pidCuts->AddCut(AliDielectronPID::kTPC,AliPID::kProton,-100.,3.5,0.,0.,kTRUE);
299     break;
300   case kTRD:
301     pidCuts->AddCut(AliDielectronPID::kTRDeleEff,AliPID::kElectron,.95,1.,pidSelCuts,
302                     kFALSE, AliDielectronPID::kIfAvailable);
303   case kEvent:
304   case kFlow:
305   case kIonut:
306   case kLegEff:
307   case kAvgPt:
308     pidCuts->AddCut(AliDielectronPID::kTPC,AliPID::kElectron,-1.5.,3.);
309     pidCuts->AddCut(AliDielectronPID::kTPC,AliPID::kElectron,-0.9,3.0,-0.5,+0.5,kFALSE,
310                     AliDielectronPID::kRequire,AliDielectronVarManager::kEta);
311     // pidCuts->AddCut(AliDielectronPID::kTPC,AliPID::kElectron,-0.65,3.0,-0.3,+0.3,kFALSE,
312     //          AliDielectronPID::kRequire,AliDielectronVarManager::kEta);
313     // pidCuts->AddCut(AliDielectronPID::kTPC,AliPID::kElectron,-0.4,3.0,-0.1,+0.1,kFALSE,
314     //          AliDielectronPID::kRequire,AliDielectronVarManager::kEta);
315     pidCuts->AddCut(AliDielectronPID::kTPC,AliPID::kProton,-100.,4.0,0.,0.,kTRUE);
316     // tof heavy particle exclusion
317     //    pidVarCuts->AddCut(AliDielectronVarManager::kTOFbeta,      0.3,   0.7, kTRUE);
318     //pidCuts->AddCut(AliDielectronPID::kTOF,AliPID::kElectron,-3,3.,0.,0.,kFALSE,
319      //             AliDielectronPID::kIfAvailable);
320     break;
321   case kTPCTOFTRD:
322     pidCuts->AddCut(AliDielectronPID::kTPC,AliPID::kElectron,-1.3.,3.);
323     pidCuts->AddCut(AliDielectronPID::kTPC,AliPID::kElectron,-0.9,3.0,-0.5,+0.5,kFALSE,
324                     AliDielectronPID::kRequire,AliDielectronVarManager::kEta);
325     pidCuts->AddCut(AliDielectronPID::kTPC,AliPID::kElectron,-0.65,3.0,-0.3,+0.3,kFALSE,
326                     AliDielectronPID::kRequire,AliDielectronVarManager::kEta);
327     pidCuts->AddCut(AliDielectronPID::kTPC,AliPID::kElectron,-0.4,3.0,-0.1,+0.1,kFALSE,
328                     AliDielectronPID::kRequire,AliDielectronVarManager::kEta);
329     pidCuts->AddCut(AliDielectronPID::kTPC,AliPID::kProton,-100.,4.0,0.,0.,kTRUE);
330     pidVarCuts->AddCut(AliDielectronVarManager::kTOFbeta,      0.2,   0.9, kTRUE);
331     pidCuts->AddCut(AliDielectronPID::kTOF,AliPID::kElectron,-3,3.,0.,0.,kFALSE,
332                     AliDielectronPID::kIfAvailable);
333     pidCuts->AddCut(AliDielectronPID::kTRDeleEff,AliPID::kElectron,.95,1.,pidSelCuts,
334                     kFALSE, AliDielectronPID::kIfAvailable);
335     break;
336     ///////////////////////////////////////////////////////////////////////////////////////////// systematics
337   case kSysPt:
338   case kSysEta:
339   case kSysSPD:
340     pidCuts->AddCut(AliDielectronPID::kTPC,AliPID::kElectron,-1.5.,3.);
341     pidCuts->AddCut(AliDielectronPID::kTPC,AliPID::kElectron,-0.9,3.0,-0.5,+0.5,kFALSE,
342                     AliDielectronPID::kRequire,AliDielectronVarManager::kEta);
343     pidCuts->AddCut(AliDielectronPID::kTPC,AliPID::kProton,-100.,4.0,0.,0.,kTRUE);
344     break;
345   case kSysEle:
346     pidCuts->AddCut(AliDielectronPID::kTPC,AliPID::kElectron,+0.7.,3.);
347     pidCuts->AddCut(AliDielectronPID::kTPC,AliPID::kProton,-100.,4.0,0.,0.,kTRUE);
348     break;
349   case kSysPro:
350     pidCuts->AddCut(AliDielectronPID::kTPC,AliPID::kElectron,-1.5.,3.);
351     pidCuts->AddCut(AliDielectronPID::kTPC,AliPID::kElectron,-0.9,3.0,-0.5,+0.5,kFALSE,
352                     AliDielectronPID::kRequire,AliDielectronVarManager::kEta);
353     pidCuts->AddCut(AliDielectronPID::kTPC,AliPID::kProton,-100.,3.5,0.,0.,kTRUE);
354     break;
355   case kSysMC:
356     pidCuts->AddCut(AliDielectronPID::kTPC,AliPID::kElectron,-1.5.,3.);
357     pidCuts->AddCut(AliDielectronPID::kTPC,AliPID::kElectron,-0.9,3.0,-0.5,+0.5,kFALSE,
358                     AliDielectronPID::kRequire,AliDielectronVarManager::kEta);
359     pidCuts->AddCut(AliDielectronPID::kTPC,AliPID::kProton,-100.,3.5,0.,0.,kTRUE);
360     break;
361   case kSysMCele:
362     pidCuts->AddCut(AliDielectronPID::kTPC,AliPID::kElectron,-1.5.,3.);
363     pidCuts->AddCut(AliDielectronPID::kTPC,AliPID::kElectron,-0.9,3.0,-0.5,+0.5,kFALSE,
364                     AliDielectronPID::kRequire,AliDielectronVarManager::kEta);
365     pidCuts->AddCut(AliDielectronPID::kTPC,AliPID::kProton,-100.,4.0,0.,0.,kTRUE);
366     break;
367   }
368
369   // mc identification
370   if(cutDefinition==kLegEff && 0) {
371     pidMCCuts->SetCutType(AliDielectronVarCuts::kAny);//only apply any of the two cuts
372     pidMCCuts->AddCut(AliDielectronVarManager::kPdgCode,-11.5,-10.5 );
373     pidMCCuts->AddCut(AliDielectronVarManager::kPdgCode,10.5,11.5 );
374   }
375
376   /* vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv PID POST CORRECTION vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv */
377   //  if(cutDefinition!=kEvent) SetEtaCorrection(pidCuts,hasMC);
378
379
380   /* vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv TENDER CUTS vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv */
381   // exclude conversion electrons selected by the tender
382   AliDielectronTrackCuts *noconv=new AliDielectronTrackCuts("noConv","noConv");
383   noconv->SetV0DaughterCut(AliPID::kElectron,kTRUE);
384
385   // activate the cut sets (order might be CPU timewise important)
386   switch(cutDefinition) {
387   case kNoPID:
388   case kPIDqa:
389     die->GetTrackFilter().AddCuts(varAccCuts);
390     grpRecCuts->AddCut(trkRecCuts);
391     grpRecCuts->AddCut(varRecCuts);
392     die->GetTrackFilter().AddCuts(grpRecCuts);
393     //    die->GetTrackFilter().AddCuts(varRecCuts); 
394     break;
395   case kRec:
396     die->GetTrackFilter().AddCuts(varAccCuts);
397     grpRecCuts->AddCut(trkRecCuts);
398     grpRecCuts->AddCut(varRecCuts);
399     die->GetTrackFilter().AddCuts(grpRecCuts);
400     break;
401   case kEvent:
402   case kFlow:
403   case kIonut:
404   case kLegEff:
405   case kTRD:
406   case kTPCTOFTRD:
407   case kAvgPt:
408   case kTOF:
409   case kTPC:
410   case kSysPt:
411   case kSysEta:
412   case kSysEle:
413   case kSysPro:
414   case kSysSPD:
415   case kSysMC:
416   case kSysMCele:
417     die->GetTrackFilter().AddCuts(varAccCuts);
418     grpRecCuts->AddCut(trkRecCuts);
419     grpRecCuts->AddCut(varRecCuts);
420     die->GetTrackFilter().AddCuts(grpRecCuts);
421     grpPIDCuts->AddCut(pidCuts);
422     grpPIDCuts->AddCut(pidVarCuts);
423     grpPIDCuts->AddCut(pidMCCuts);
424     die->GetTrackFilter().AddCuts(grpPIDCuts);
425     //  if(!isESD) cuts->AddCut(trkFilter);
426     //cuts->AddCut(noconv);
427   }
428   //  cuts->Print();
429
430 }
431
432 //______________________________________________________________________________________
433 void SetupV0Cuts(AliDielectron *die, Int_t cutDefinition)
434 {
435   //
436   // Setup the V0 cuts
437   //
438
439   switch(cutDefinition) {
440   case kEvent:  return;
441   case kLegEff: return;
442   }
443
444   Bool_t bRej  = kTRUE;
445   Int_t defPID = 16;
446   if(cutDefinition==kPIDqa) {
447     bRej   = kFALSE;
448     defPID = 13;
449   }
450
451   AliDielectronV0Cuts *gammaV0Cuts = new AliDielectronV0Cuts("V0","V0");
452   gammaV0Cuts->SetV0finder(AliDielectronV0Cuts::kOnTheFly);
453   gammaV0Cuts->SetPdgCodes(22,11,11);
454   gammaV0Cuts->SetDefaultPID(defPID);
455   gammaV0Cuts->AddCut(AliDielectronVarManager::kCosPointingAngle, TMath::Cos(0.05),   1.0,  kFALSE); //0.02 -- 0.05
456   gammaV0Cuts->AddCut(AliDielectronVarManager::kArmPt,                         0.0,   0.05, kFALSE);
457   gammaV0Cuts->AddCut(AliDielectronVarManager::kArmAlpha,                     -0.35,  0.35, kFALSE);
458   gammaV0Cuts->AddCut(AliDielectronVarManager::kM,                             0.0,   0.1,  kFALSE); //0.05 -- 0.1
459   gammaV0Cuts->AddCut(AliDielectronVarManager::kChi2NDF,                       0.0,  10.0,  kFALSE);
460   gammaV0Cuts->AddCut(AliDielectronVarManager::kLegDist,                       0.0,   0.25, kFALSE);
461   gammaV0Cuts->AddCut(AliDielectronVarManager::kR,                             3.0,  90.0,  kFALSE);
462   gammaV0Cuts->AddCut(AliDielectronVarManager::kPsiPair,                       0.0,   0.2,  kFALSE); //0.05 -- 0.2
463   if(cutDefinition==kPIDqa && 0) {
464     gammaV0Cuts->AddCut(AliDielectronVarManager::kImpactParXY,                   0.0,   1.0,  kFALSE);
465     gammaV0Cuts->AddCut(AliDielectronVarManager::kImpactParZ,                    0.0,   1.0,  kFALSE);
466   }
467   //  gammaV0Cuts->AddCut(AliDielectronVarManager::kOpeningAngle,              0.0,   0.1,  kFALSE);
468   gammaV0Cuts->SetExcludeTracks(bRej);
469   gammaV0Cuts->Print();
470
471  //  const Double_t |cutAlphaG| < 0.35; &&  const Double_t cutQTG < 0.05;
472  //  const Double_t |cutAlphaG2|[2] = {0.6, 0.8}; &&  const Double_t cutQTG2 < 0.04;
473
474   // if(cuts)
475   //   ((AliDielectronCutGroup*)cuts)->AddCut(gammaV0Cuts);
476   // else
477   die->GetTrackFilter().AddCuts(gammaV0Cuts);
478 }
479
480 //______________________________________________________________________________________
481 void SetupPairCuts(AliDielectron *die, Int_t cutDefinition)
482 {
483   //
484   // Setup the pair cuts
485   //
486   Bool_t hasMC=die->GetHasMC();
487
488   // rap and mass rejection
489   Double_t gCut=0.05, yCut=0.9, eCut=0.01;
490   switch(cutDefinition) {
491   case kEvent:      yCut=0.0;  break;
492   case kPIDqa:      return;
493   case kFlow:       yCut=0.8;  break;
494   case kRec:        yCut=0.9;  break;
495   case kNoPID:      return;
496   case kTPC:        yCut=0.9;  break;
497   case kTOF:        yCut=0.9;  break;
498   case kTRD:        yCut=0.8;  break;
499   case kIonut:      yCut=0.8;  break;
500   case kLegEff:     return;
501   case kTPCTOFTRD:  yCut=0.8;  break;
502   case kAvgPt:      yCut=0.8;  break;
503   case kSysMC:      yCut=0.9;  break;
504   case kSysMCele:   yCut=0.8;  break;
505   case kSysEta:     yCut=0.9;  break;
506   case kSysPt:
507   case kSysEle:
508   case kSysPro:
509   case kSysSPD:
510     yCut=0.8;                  break;
511     //  default: gCut=0.05;       // default
512   }
513
514   // MC
515   //if(hasMC) yCut=0.9;
516
517   // rapidity selection
518   AliDielectronVarCuts *rapCut=new AliDielectronVarCuts(Form("|Y|<%.1f",yCut),Form("|Y|<%.1f",yCut));
519   rapCut->AddCut(AliDielectronVarManager::kY,-1.*yCut,yCut);
520   die->GetPairFilter().AddCuts(rapCut);
521
522   // gamma rejection
523   AliDielectronVarCuts *gammaCuts = new AliDielectronVarCuts("GammaCuts","GammaCuts");
524   gammaCuts->AddCut(AliDielectronVarManager::kM,            0.0,   gCut);
525   die->GetPairPreFilter().AddCuts(gammaCuts);
526
527   // pair efficiency cut
528   // if(cutDefinition==kAvgPt && !hasMC) {
529   //   AliDielectronVarCuts *effCut=new AliDielectronVarCuts(Form("(Axe)>%.2f",eCut),Form("(Axe)>%.2f",eCut));
530   //   effCut->AddCut(AliDielectronVarManager::kPairEff,0.0,eCut,kTRUE);
531   //   die->GetPairFilter().AddCuts(effCut);
532   // }
533
534   // random signal rejection
535   AliDielectronCutGroup *grpRNDMCuts = new AliDielectronCutGroup("RNDM","RNDM",AliDielectronCutGroup::kCompOR);
536   AliDielectronVarCuts *exclCutCEN=new AliDielectronVarCuts("exclCEN","exclCEN");
537   exclCutCEN->SetCutType(AliDielectronVarCuts::kAll); // all criteria need to be fullfilled
538   exclCutCEN->AddCut(AliDielectronVarManager::kRndmPair,0.0,1./40);
539   exclCutCEN->AddCut(AliDielectronVarManager::kPdgCode,443);
540   exclCutCEN->AddCut(AliDielectronVarManager::kCentrality,0.,10.);
541   AliDielectronVarCuts *exclCutSEMI=new AliDielectronVarCuts("exclSEMI","exclSEMI");
542   exclCutSEMI->SetCutType(AliDielectronVarCuts::kAll); // all criteria need to be fullfilled
543   exclCutSEMI->AddCut(AliDielectronVarManager::kRndmPair,0.0,1./20);
544   exclCutSEMI->AddCut(AliDielectronVarManager::kPdgCode,443);
545   exclCutSEMI->AddCut(AliDielectronVarManager::kCentrality,10.,90.);
546   AliDielectronVarCuts *inclCut=new AliDielectronVarCuts("incl","incl");
547   inclCut->AddCut(AliDielectronVarManager::kPdgCode,443,443,kTRUE);
548   grpRNDMCuts->AddCut(exclCutCEN);
549   grpRNDMCuts->AddCut(exclCutSEMI);
550   grpRNDMCuts->AddCut(inclCut);
551   if(hasMC && cutDefinition==kIonut && 0) die->GetPairFilter().AddCuts(grpRNDMCuts); //ATTENTION
552
553 }
554
555 //______________________________________________________________________________________
556 void ConfigBgrd(AliDielectron *die, Int_t cutDefinition)
557 {
558   //
559   // Configurate the background estimators
560   //
561
562   // skip event QA
563   switch(cutDefinition) {
564   case kEvent:
565   case kNoPID:
566   case kPIDqa:
567   case kRec:
568   case kLegEff:
569     return;
570   }
571
572   // add track rotations
573   AliDielectronTrackRotator *rot=new AliDielectronTrackRotator;
574   rot->SetIterations(10);
575   rot->SetConeAnglePhi(TMath::Pi());
576   rot->SetStartAnglePhi(TMath::Pi());
577   //      die->SetTrackRotator(rot);
578
579   // add mixed events
580   AliDielectronMixingHandler *mix=new AliDielectronMixingHandler;
581   switch(cutDefinition) {
582   // case kIonut:
583   //   mix->AddVariable(AliDielectronVarManager::kZvPrim,      20, -10., 10.);
584   //   mix->AddVariable(AliDielectronVarManager::kCentrality,  36,   0., 90.);
585   //   mix->AddVariable(AliDielectronVarManager::kv0ACrpH2,    10,   0., TMath::Pi());
586   //   break;
587   default: 
588     mix->AddVariable(AliDielectronVarManager::kZvPrim,      "-10.,-5.,-4.,-3.,-2.,-1.,0.,1.,2.,3.,4.,5.,10.");
589     mix->AddVariable(AliDielectronVarManager::kCentrality,  9,  0.,90.);
590     mix->AddVariable(AliDielectronVarManager::kTPCrpH2,     10, TMath::Pi()/-2, TMath::Pi()/2); // max res: 10%->10bins // 8bins
591     //    mix->AddVariable(AliDielectronVarManager::kTPCmagH2,    "0.,20.,50.,80.,110.,150.,500.");
592     break;
593   }
594   mix->SetSkipFirstEvent(kTRUE); // needed for flow analysis
595   mix->SetMixType(AliDielectronMixingHandler::kAll);
596   mix->SetDepth(150);
597   die->SetMixingHandler(mix);
598
599 }
600
601 //______________________________________________________________________________________
602 void ConfigEvtPlane(AliDielectron *die, Int_t cutDefinition)
603 {
604   //
605   // Configurate the TPC event plane 
606   //
607
608   switch(cutDefinition) {
609     //  case kEvent:
610   case kNoPID:
611   case kPIDqa:
612     //  case kRec:   // TOTHINK: might be needed when checking efficiencies versus dPhi
613   case kLegEff:
614     return;
615   }
616
617   //   Double_t gGap;
618   //   switch(cutDefinition) {
619   //   case kEtaGap01:   gGap=0.1;   break;
620   //   case kEtaGap02:   gGap=0.2;   break;
621   //   case kEtaGap03:   gGap=0.3;   break;
622   //   case kEtaGap04:   gGap=0.4;   break;
623   //   case kEtaGap05:   gGap=0.5;   break;
624   //   default: gGap=0.0;
625   //   }
626   // eta gap in tpc event plane
627   //   AliDielectronVarCuts *etaGap = new AliDielectronVarCuts(AliDielectronVarManager::GetValueName(AliDielectronVarManager::kEta),"etaGap");
628   //   etaGap->AddCut(AliDielectronVarManager::kEta,-1*gGap,gGap,kTRUE);
629   //   die->GetEventPlanePreFilter().AddCuts(etaGap);
630
631   AliDielectronVarCuts *poi = new AliDielectronVarCuts("PoI","PoI");
632   poi->AddCut(AliDielectronVarManager::kM,2.92,3.20);     // particles of interest, jpsi mass window
633   die->GetEventPlanePOIPreFilter().AddCuts(poi);
634
635   // die->SetLikeSignSubEvents();
636   die->SetPreFilterEventPlane();
637 }
638
639 //______________________________________________________________________________________
640 void InitHistograms(AliDielectron *die, Int_t cutDefinition)
641 {
642   //
643   // Initialise the histograms
644   //
645   Bool_t hasMC=die->GetHasMC();
646
647   // booleans for histo selection
648   Bool_t bHistTrackQA=kFALSE, bHistEvts=kFALSE, bHistPair=kFALSE, bHistTrk=kFALSE, bHistPairME=kFALSE, bHistFlow=kFALSE, bHistFlowQA=kFALSE, bHistPID=kFALSE;
649   switch (cutDefinition) {
650   case kEvent: bHistEvts=kTRUE; break;
651   case kPIDqa: bHistTrk=kTRUE; break;
652   case kNoPID: bHistTrk=kTRUE; break;
653   case kRec:   /* */ break;
654   case kTPC:
655   case kTOF:   //bHistEvts=kTRUE; //bHistFlow=kTRUE;
656   case kTRD:   ///bHistEvts=kTRUE; //bHistFlow=kTRUE;
657   case kAvgPt: 
658   case kIonut: ///*bHistEvts=kTRUE;*/ bHistPair=kTRUE; break; //bHistPairME=kTRUE;
659   case kTPCTOFTRD: bHistPair=kTRUE; bHistTrk=kTRUE; bHistPID=kTRUE; break; //bHistPairME=kTRUE;
660   case kSysMCele: bHistPair=kTRUE; bHistPID=kFALSE; break; //bHistPairME=kTRUE;
661   }
662   if(hasMC) {
663     bHistPID=kFALSE;
664   }
665
666   //Setup histogram Manager
667   AliDielectronHistos *histos=new AliDielectronHistos(die->GetName(),die->GetTitle());
668   die->SetHistogramManager(histos);
669
670   //Initialise histogram classes
671   histos->SetReservedWords("Track;Pair");
672
673   //add histograms to event class
674   histos->AddClass("Event");
675   Int_t maxMixBins = (die->GetMixingHandler() ? die->GetMixingHandler()->GetNumberOfBins() : 0);
676   histos->UserHistogram("Event","","", 100, 0.0, 100.0,   AliDielectronVarManager::kCentrality);
677   if(die->GetMixingHandler() )
678     histos->UserHistogram("Event","","", maxMixBins, 0, maxMixBins, AliDielectronVarManager::kMixingBin);
679   // candidates monitoring
680   histos->UserProfile("Event","","", AliDielectronVarManager::kTracks, GetRunNumbers2011(), AliDielectronVarManager::kRunNumber);
681   histos->UserProfile("Event","","", AliDielectronVarManager::kPairs, GetRunNumbers2011(), AliDielectronVarManager::kRunNumber);
682
683
684   //event plane histograms
685   if(cutDefinition==kFlow) {
686     if(!hasMC) AddQAHistsEP(die);
687     histos->UserHistogram("Pair","","", 100,-1*TMath::Pi(),+1*TMath::Pi(), AliDielectronVarManager::kDeltaPhiv0ArpH2);
688     histos->UserHistogram("Pair","","", 100,-1*TMath::Pi(),+1*TMath::Pi(), AliDielectronVarManager::kDeltaPhiv0CrpH2);
689     histos->UserHistogram("Pair","","", 100,-1*TMath::Pi(),+1*TMath::Pi(), AliDielectronVarManager::kDeltaPhiTPCrpH2);
690   }
691
692   ////// EVENT HISTOS /////
693   if(bHistEvts) {
694     histos->UserHistogram("Event","","", GetRunNumbers2011(), AliDielectronVarManager::kRunNumber);
695     histos->UserHistogram("Event","","", 300,-15.,15.,    AliDielectronVarManager::kZvPrim);
696     //    histos->UserHistogram("Event","","", 300,0.,15000.,     AliDielectronVarManager::kRefMult);
697     histos->UserHistogram("Event","","", 300,0.,3000.,    AliDielectronVarManager::kRefMultTPConly);
698
699     //    histos->UserHistogram("Event","","", 100,0.,100.,       AliDielectronVarManager::kRefMultTPConly);
700     histos->UserHistogram("Event","","", GetRunNumbers2011(), AliDielectronHelper::MakeLinBinning(3000, 0., 3000.),
701                           AliDielectronVarManager::kRunNumber, AliDielectronVarManager::kRefMultTPConly);
702     histos->UserHistogram("Event","","", AliDielectronHelper::MakeLinBinning(90, 0., 90.), AliDielectronHelper::MakeLinBinning(3000, 0., 3000.),
703                           AliDielectronVarManager::kCentrality, AliDielectronVarManager::kRefMultTPConly);
704     histos->UserProfile(  "Event","","", AliDielectronVarManager::kRefMultTPConly,        90, 0., 90.,  AliDielectronVarManager::kCentrality);
705     histos->UserProfile(  "Event","","", AliDielectronVarManager::kMultV0A,               90, 0., 90.,  AliDielectronVarManager::kCentrality);
706     histos->UserProfile(  "Event","","", AliDielectronVarManager::kMultV0C,               90, 0., 90.,  AliDielectronVarManager::kCentrality);
707     // histos->UserProfile(  "Event","","", AliDielectronVarManager::kEqMultV0A,               90, 0., 90.,  AliDielectronVarManager::kCentrality);
708     // histos->UserProfile(  "Event","","", AliDielectronVarManager::kEqMultV0C,               90, 0., 90.,  AliDielectronVarManager::kCentrality);
709     histos->UserProfile(  "Event","","", AliDielectronVarManager::kNVtxContrib, 90, 0., 90.,  AliDielectronVarManager::kCentrality);
710     histos->UserHistogram("Event","","", 100, 0., 4000.,  AliDielectronVarManager::kNVtxContribTPC);
711
712     // event plane histograms
713     if(!hasMC) AddQAHistsEP(die);
714     // trigger histograms
715     if(!hasMC) {
716       histos->UserHistogram("Event","","", 29,0.,29.,     AliDielectronVarManager::kTriggerInclONL);
717       histos->UserHistogram("Event","","", 29,0.,29.,     AliDielectronVarManager::kTriggerInclOFF);
718       histos->UserHistogram("Event","","", 29,0.,29.,     AliDielectronVarManager::kTriggerExclOFF);
719       histos->UserHistogram("Event","","", 100,0.,100.,29,0.,29., 
720                             AliDielectronVarManager::kCentrality,AliDielectronVarManager::kTriggerInclONL);
721       histos->UserHistogram("Event","","", 100,0.,100.,29,0.,29., 
722                             AliDielectronVarManager::kCentrality,AliDielectronVarManager::kTriggerExclOFF);
723       histos->UserHistogram("Event","","", 300,0.,3000.,29,0.,29., 
724                             AliDielectronVarManager::kRefMultTPConly,AliDielectronVarManager::kTriggerExclOFF);
725       histos->UserHistogram("Event","","", 300,0.,3000.,29,0.,29., 
726                             AliDielectronVarManager::kRefMultTPConly,AliDielectronVarManager::kTriggerInclOFF);
727     }
728
729   } //hist: event
730
731   ///// PAIR HISTOS /////
732   if(bHistPair) {
733
734     //Pair classes
735     // to fill also mixed event histograms loop until 7 or 10
736     for (Int_t i=0; i<(bHistPairME ? 8 : 3); ++i){
737       histos->AddClass(Form("Pair_%s",AliDielectron::PairClassName(i)));
738     }
739     //add MC signal histograms to pair class
740     if(die->GetMCSignals()) {
741       for (Int_t i=0; i<die->GetMCSignals()->GetEntriesFast(); ++i) {
742         histos->AddClass(Form("Pair_%s",die->GetMCSignals()->At(i)->GetName()));
743         histos->AddClass(Form("Pair_%s_MCtruth",die->GetMCSignals()->At(i)->GetName()));
744       }
745     }
746
747     ///// Pair classes /////
748     histos->UserHistogram("Pair","","",  125,.0,125*0.04, AliDielectronVarManager::kM); // 40MeV bins, 12GeV/c2
749     histos->UserHistogram("Pair","","",  100,-1.,1.,      AliDielectronVarManager::kY);
750     histos->UserHistogram("Pair","","",  400,0,20.,       AliDielectronVarManager::kPt);
751     histos->UserHistogram("Pair","","",  100,0.,3.15,     AliDielectronVarManager::kOpeningAngle);
752     histos->UserHistogram("Pair","","",  100,0.,20,       AliDielectronVarManager::kChi2NDF);
753     histos->UserHistogram("Pair","","",  100,0.,3.15,     AliDielectronVarManager::kPsiPair);
754     histos->UserHistogram("Pair","","",  200,0.,100.,     AliDielectronVarManager::kR);
755     histos->UserHistogram("Pair","","",   50,0.,5.,       AliDielectronVarManager::kLegDist);
756     histos->UserHistogram("Pair","","",   50,0.,5.,       AliDielectronVarManager::kLegDistXY);
757     // histos->UserHistogram("Pair","","", 210,-1.05,1.05, 100,0.,2.5, 
758     //                    AliDielectronVarManager::kArmAlpha,AliDielectronVarManager::kArmPt);
759     histos->UserHistogram("Pair","","", 500,-2.5,2.5, AliDielectronVarManager::kImpactParXY);
760     histos->UserHistogram("Pair","","", 600,-3.,3., AliDielectronVarManager::kImpactParZ);
761
762     if(!hasMC && die->GetMixingHandler() )
763       histos->UserHistogram("Pair","","", maxMixBins, 0, maxMixBins, AliDielectronVarManager::kMixingBin);
764
765     histos->UserHistogram("Pair","","",  100,.0,1., AliDielectronVarManager::kRndmPair);
766     // histos->UserHistogram("Pair","","",  GetPDGcodes(), AliDielectronVarManager::kPdgCode);
767     // histos->UserHistogram("Pair","","",  GetPDGcodes(), AliDielectronVarManager::kPdgCodeMother);
768     // histos->UserHistogram("Pair","","",  GetPDGcodes(), AliDielectronVarManager::kPdgCodeGrandMother);
769
770   } //hist: pairs
771
772
773   ///// TRACK HISTOS /////
774   if(bHistTrk) {
775     //Track classes
776     //legs from pair (fill SE)
777     for (Int_t i=1; i<2; ++i){
778       if(bHistPair) histos->AddClass(Form("Track_Legs_%s",AliDielectron::PairClassName(i)));
779     }
780     //to fill also track info from 2nd event loop until 2
781     //    for (Int_t i=0; i<2; ++i) histos->AddClass(Form("Track_%s",AliDielectron::TrackClassName(i)));
782     histos->AddClass(Form("Track_%s",     AliDielectron::PairClassName(AliDielectron::kEv1PM)));
783
784     // PID post calibration
785     if(cutDefinition==kPIDqa) AddQAHistsPID(die);
786
787     // Vertex
788     // histos->UserHistogram("Track","","", 500,-1.,1., AliDielectronVarManager::kImpactParXY);
789     // histos->UserHistogram("Track","","", 600,-3.,3., AliDielectronVarManager::kImpactParZ);
790     // Kinematics
791     histos->UserHistogram("Track","","", 400,0,20.,  AliDielectronVarManager::kPt);
792     histos->UserHistogram("Track","","", 200,-1,1, 200,0,6.285, AliDielectronVarManager::kEta,AliDielectronVarManager::kPhi);
793     // TPC
794     // histos->UserHistogram("Track","","", 160,-0.5,159.5, AliDielectronVarManager::kNclsTPC);
795     // histos->UserHistogram("Track","","", 160,-0.5,159.5, AliDielectronVarManager::kTPCsignalN);
796     // histos->UserHistogram("Track","","", 160,-0.5,159.5, AliDielectronVarManager::kNFclsTPCr);
797     // histos->UserHistogram("Track","","", 160,-0.5,159.5, 160,-0.5,159.5, AliDielectronVarManager::kNclsTPC,AliDielectronVarManager::kNFclsTPCr);
798     // TRD
799     histos->UserHistogram("Track","","",   8,-0.5,  7.5, AliDielectronVarManager::kTRDpidQuality);
800     histos->UserHistogram("Track","","",   101,-0.5, 100.5, AliDielectronVarManager::kTRDsignal);
801     histos->UserHistogram("Track","","",   101,-0.5, 100.5, AliDielectronVarManager::kTRDchi2);
802     // PID
803     histos->UserHistogram("Track","","", 400,0.2,20.,200,0.,200., AliDielectronVarManager::kPIn,AliDielectronVarManager::kTPCsignal,kTRUE);
804     histos->UserHistogram("Track","","", 400,0.2,20.,200,-10.,10.,AliDielectronVarManager::kPIn,AliDielectronVarManager::kTPCnSigmaEle,kTRUE);
805     histos->UserHistogram("Track","","", 250,0.0,5.0,300,0.,1.2,  AliDielectronVarManager::kPIn,AliDielectronVarManager::kTOFbeta,kTRUE);
806     // histos->UserHistogram("Track","","", 100,-1.,+1.,200,-10.,10.,AliDielectronVarManager::kEta,AliDielectronVarManager::kTPCnSigmaEle);
807
808     // histos->UserHistogram("Track","","", 100,0.2,10.,100,0.,200.,
809     //                    AliDielectronVarManager::kPIn,AliDielectronVarManager::kTPCsignal,kTRUE);
810     // histos->UserHistogram("Track","","", 100,0.2,10.,100,-5.,+5.,
811     //                    AliDielectronVarManager::kPIn,AliDielectronVarManager::kTPCnSigmaEle,kTRUE);
812     histos->UserHistogram("Track","","", 100,0.,4000.,100,0.,200.,
813                           AliDielectronVarManager::kRefMultTPConly,AliDielectronVarManager::kTPCsignal);
814     histos->UserHistogram("Track","","", 100,0.,4000.,100,-5.,+5.,
815                           AliDielectronVarManager::kRefMultTPConly,AliDielectronVarManager::kTPCnSigmaEle);
816     histos->UserHistogram("Track","","", 100,0.,100.,100,0.,200.,
817                           AliDielectronVarManager::kCentrality,AliDielectronVarManager::kTPCsignal);
818     histos->UserHistogram("Track","","", 100,0.,100.,100,-5.,+5.,
819                           AliDielectronVarManager::kCentrality,AliDielectronVarManager::kTPCnSigmaEle);
820     histos->UserHistogram("Track","","", 100,-1.,+1.,100,0.,200.,
821                           AliDielectronVarManager::kEta,AliDielectronVarManager::kTPCsignal);
822     histos->UserHistogram("Track","","", 100,-1.,+1.,100,-5.,+5.,
823                           AliDielectronVarManager::kEta,AliDielectronVarManager::kTPCnSigmaEle);
824     histos->UserHistogram("Track","","", 100,-1.,+1.,100,-5.,+5.,
825                           AliDielectronVarManager::kEta,AliDielectronVarManager::kTPCnSigmaEleRaw);
826   } //hist: tracks
827
828
829   if(cutDefinition==kAvgPt) {
830     // add single electron efficiency histograms
831     AddHistsEleEff(die);
832   }
833
834   ////// MONTE CARLO //////
835   if(cutDefinition==kLegEff) {
836
837     //add MC signal histograms to track class
838     if(die->GetMCSignals()) {
839
840       TString className="";
841       for (Int_t i=0; i<die->GetMCSignals()->GetEntriesFast(); ++i) {
842         TString sigMCname = die->GetMCSignals()->At(i)->GetName();
843
844         // mc truth
845         //      histos->AddClass(Form("Pair_%s_MCtruth",      sigMCname.Data()));
846         // histos->AddClass(Form("Track_Legs_%s_MCtruth",sigMCname.Data()));
847         // mc reconstructed
848         // histos->AddClass(Form("Pair_%s",              sigMCname.Data()));
849         // histos->AddClass(Form("Track_Legs_%s",        sigMCname.Data()));
850         // tracks
851         histos->AddClass(Form("Track_%s_%s",AliDielectron::PairClassName(AliDielectron::kEv1PM),sigMCname.Data()));
852         histos->AddClass(Form("Track_%s_%s_MCtruth",AliDielectron::PairClassName(AliDielectron::kEv1PM),sigMCname.Data()));
853       } //end: loop signals
854     } //end: has signals
855
856     // add single electron histograms
857     AddHistsEleEff(die);
858     // pdg codes
859     //    histos->UserHistogram("Track","","",  GetPDGcodes(), AliDielectronVarManager::kPdgCode);
860     //    histos->UserHistogram("Track","","",  GetPDGcodes(), AliDielectronVarManager::kPdgCodeMother);
861     //    histos->UserHistogram("Track","","",  GetPDGcodes(), AliDielectronVarManager::kPdgCodeGrandMother);
862     //    histos->UserHistogram("Track","","",  GetPDGcodes(), GetPDGcodes(),
863     //                    AliDielectronVarManager::kPdgCodeMother, AliDielectronVarManager::kPdgCodeGrandMother);
864   }
865
866
867
868   die->SetHistogramManager(histos);
869
870
871   ////// LOG //////
872   TIter nextClass(histos->GetHistogramList());
873   THashList *l=0;
874   while ( (l=static_cast<THashList*>(nextClass())) ) {
875     //printf(" [D] HistogramManger: Class %s: Histograms: %04d \n", l->GetName(), l->GetEntries());
876   }
877
878 } //end: init histograms
879
880 void AddQAHistsPID(AliDielectron *die) {
881   //
882   // add histograms for PID validation, comparison, post calibration aso.
883   //
884
885   Bool_t hasMC=die->GetHasMC();
886   AliDielectronHistos *histos = die->GetHistoManager();
887
888   // add MC signal tracks
889   if(hasMC && die->GetMCSignals()) {
890     TString sigMCname = die->GetMCSignals()->Last()->GetName();
891     histos->AddClass(Form("Track_%s_%s",AliDielectron::PairClassName(AliDielectron::kEv1PM),sigMCname.Data()));
892   }
893
894
895   // for TPC post calibration
896
897   // arbitrary binning for variables
898   TVectorD *vcen = AliDielectronHelper::MakeLinBinning( 11,  0.,    55.);
899   (*vcen)[21] = 90.;
900
901   // array of bin limits
902   TObjArray *limits  = new TObjArray();
903   limits->Add(AliDielectronHelper::MakeLinBinning( 75,-10.,     5.));
904   limits->Add(AliDielectronHelper::MakeLinBinning( 75,-10.,     5.));
905   //  limits->Add(AliDielectronHelper::MakeLinBinning(100,  0.,   200.));
906   //  limits->Add(AliDielectronHelper::MakeLinBinning(60,   0.,    1.2));
907   limits->Add(AliDielectronHelper::MakeLinBinning( 50,  0.,  4000.));
908   limits->Add(AliDielectronHelper::MakeLinBinning( 50,  0.,    10.));
909   //  limits->Add(vcen);
910   //    limits->Add(AliDielectronHelper::MakeLinBinning( 36,  0.,    90.));
911   limits->Add(AliDielectronHelper::MakeLinBinning( 20, -1.,     1.));
912   limits->Add(GetRunNumbers2011());
913   UInt_t var[]={AliDielectronVarManager::kTPCnSigmaEleRaw,  // NOTE: raw nsigma w/o corr
914                 AliDielectronVarManager::kTPCnSigmaEle,
915                 //              AliDielectronVarManager::kTOFbeta,
916                 // AliDielectronVarManager::kTPCsignal,
917                 AliDielectronVarManager::kRefMultTPConly,
918                 AliDielectronVarManager::kPIn,
919                 // AliDielectronVarManager::kCentrality,
920                 AliDielectronVarManager::kEta,
921                 AliDielectronVarManager::kRunNumber
922   };
923   // add merged track histogram
924   histos->UserSparse("Track", limits->GetEntriesFast(), limits, var);
925
926   // run dependence of nisgma electron
927   histos->UserHistogram("Track","","", GetRunNumbers2011(),AliDielectronHelper::MakeLinBinning(100,-5.,+5.),
928                         AliDielectronVarManager::kRunNumber,AliDielectronVarManager::kTPCnSigmaEleRaw);
929   histos->UserHistogram("Track","","", GetRunNumbers2011(),AliDielectronHelper::MakeLinBinning(100,-5.,+5.),
930                         AliDielectronVarManager::kRunNumber,AliDielectronVarManager::kTPCnSigmaEle);
931
932   // post calibration check
933   histos->UserHistogram("Track","","", 100,0.2,10.,100,-5.,+5.,
934                         AliDielectronVarManager::kPIn,AliDielectronVarManager::kTPCnSigmaEleRaw,kTRUE);
935   histos->UserHistogram("Track","","", 100,0.2,10.,100,-5.,+5.,
936                         AliDielectronVarManager::kPIn,AliDielectronVarManager::kTPCnSigmaEle,kTRUE);
937
938   // TPC number of points used for nsigma calculation
939   histos->UserHistogram("Track","","", 160,-0.5,159.5, AliDielectronVarManager::kTPCsignalN);
940 }
941
942 void AddQAHistsEP(AliDielectron *die) {
943   //
944   // add histograms for event plane flattening aso.
945   //
946
947   Bool_t hasMC=die->GetHasMC();
948   AliDielectronHistos *histos = die->GetHistoManager();
949
950   // event plane resolutions
951   TObjArray *limits  = new TObjArray();
952   limits->Add(AliDielectronHelper::MakeLinBinning( 18,  0.,    90.));
953   //    limits->Add(GetRunNumbers2011());
954   limits->Add(AliDielectronHelper::MakeLinBinning(100,  -1.,    1.));
955   limits->Add(AliDielectronHelper::MakeLinBinning(100,  -1.,    1.));
956   limits->Add(AliDielectronHelper::MakeLinBinning(100,  -1.,    1.));
957
958   UInt_t var[]={AliDielectronVarManager::kCentrality,
959                 //                 AliDielectronVarManager::kRunNumber,
960                 AliDielectronVarManager::kv0ATPCDiffH2,
961                 AliDielectronVarManager::kv0CTPCDiffH2,
962                 AliDielectronVarManager::kv0Av0CDiffH2 };
963   //  histos->UserSparse("Event", 4, limits, var);
964
965   // event plane angles
966   TObjArray *limits2  = new TObjArray();
967   limits2->Add(AliDielectronHelper::MakeLinBinning( 18,   0.,    90.));
968   //  limits2->Add(GetRunNumbers2011());
969   limits2->Add(AliDielectronHelper::MakeLinBinning(100,  -1.6,   1.6));
970   limits2->Add(AliDielectronHelper::MakeLinBinning(100,  -1.6,   1.6));
971   limits2->Add(AliDielectronHelper::MakeLinBinning(100,  -1.6.,  1.6));
972
973   UInt_t var2[]={AliDielectronVarManager::kCentrality,
974                  //              AliDielectronVarManager::kRunNumber,
975                  AliDielectronVarManager::kv0ArpH2,
976                  AliDielectronVarManager::kv0CrpH2,
977                  AliDielectronVarManager::kTPCrpH2 };
978   histos->UserSparse("Event", limits2->GetEntriesFast(), limits2, var2);
979
980   // VZERO event plane angles (sub rings)
981   histos->UserHistogram("Event","","", 100,-2.,2., AliDielectronVarManager::kv0A0rpH2);
982   histos->UserHistogram("Event","","", 100,-2.,2., AliDielectronVarManager::kv0C0rpH2);
983   histos->UserHistogram("Event","","", 100,-2.,2., AliDielectronVarManager::kv0A3rpH2);
984   histos->UserHistogram("Event","","", 100,-2.,2., AliDielectronVarManager::kv0C3rpH2);
985   histos->UserHistogram("Event","","", 100,-2.,2., AliDielectronVarManager::kv0ACrpH2); // combined A+C
986
987   // run dependence of the angles
988   histos->UserHistogram("Event","","", GetRunNumbers2011(), AliDielectronHelper::MakeLinBinning(100,-1.6,1.6),
989                         AliDielectronVarManager::kRunNumber, AliDielectronVarManager::kv0ArpH2);
990   histos->UserHistogram("Event","","", GetRunNumbers2011(), AliDielectronHelper::MakeLinBinning(100,-1.6,1.6),
991                         AliDielectronVarManager::kRunNumber, AliDielectronVarManager::kv0CrpH2);
992   histos->UserHistogram("Event","","", GetRunNumbers2011(), AliDielectronHelper::MakeLinBinning(100,-1.6,1.6),
993                         AliDielectronVarManager::kRunNumber, AliDielectronVarManager::kTPCrpH2);
994
995
996   // TPC q vector components
997   histos->UserHistogram("Event","","", 100,-1500.,1500., AliDielectronVarManager::kTPCxH2);
998   histos->UserHistogram("Event","","", 100,-1500.,1500., AliDielectronVarManager::kTPCyH2);
999   // histos->UserHistogram("Event","","", 100,   -2.,   2., AliDielectronVarManager::kTPCsub1rpH2);
1000   // histos->UserHistogram("Event","","", 100,   -2.,   2., AliDielectronVarManager::kTPCsub2rpH2);
1001   // histos->UserHistogram("Event","","", 100,   -1.,   1., AliDielectronVarManager::kTPCsub12DiffH2);
1002
1003   // further event plane resolutions (used in 3 sub event method)
1004   histos->UserProfile("Event","","", AliDielectronVarManager::kv0ATPCDiffH2,   18, 0.,90., AliDielectronVarManager::kCentrality);
1005   histos->UserProfile("Event","","", AliDielectronVarManager::kv0CTPCDiffH2,   18, 0.,90., AliDielectronVarManager::kCentrality);
1006   histos->UserProfile("Event","","", AliDielectronVarManager::kv0Av0CDiffH2,   18, 0.,90., AliDielectronVarManager::kCentrality);
1007   histos->UserProfile("Event","","", AliDielectronVarManager::kTPCsub12DiffH2, 18, 0.,90., AliDielectronVarManager::kCentrality);
1008   histos->UserProfile("Event","","", AliDielectronVarManager::kv0Av0C0DiffH2,  18, 0.,90., AliDielectronVarManager::kCentrality);
1009   histos->UserProfile("Event","","", AliDielectronVarManager::kv0Av0C3DiffH2,  18, 0.,90., AliDielectronVarManager::kCentrality);
1010   histos->UserProfile("Event","","", AliDielectronVarManager::kv0Cv0A0DiffH2,  18, 0.,90., AliDielectronVarManager::kCentrality);
1011   histos->UserProfile("Event","","", AliDielectronVarManager::kv0Cv0A3DiffH2,  18, 0.,90., AliDielectronVarManager::kCentrality);
1012   histos->UserProfile("Event","","", AliDielectronVarManager::kv0A0v0A3DiffH2, 18, 0.,90., AliDielectronVarManager::kCentrality);
1013   histos->UserProfile("Event","","", AliDielectronVarManager::kv0C0v0C3DiffH2, 18, 0.,90., AliDielectronVarManager::kCentrality);
1014
1015   // EP angle correlation (range of phi angle)
1016   // histos->UserHistogram("Event","","", 320,-3.2.,3.2, 320,-3.2.,3.2,
1017   //                    AliDielectronVarManager::kTPCrpH2,AliDielectronVarManager::kv0ACrpH2);
1018
1019   // EP Qvector magnitudes
1020   histos->UserHistogram("Event","","", 200,0.,200., AliDielectronVarManager::kTPCmagH2);
1021   histos->UserHistogram("Event","","", 200,0.,800., AliDielectronVarManager::kv0ACmagH2);
1022   histos->UserHistogram("Event","","", 200,0.,800., AliDielectronVarManager::kv0AmagH2);
1023   histos->UserHistogram("Event","","", 200,0.,800., AliDielectronVarManager::kv0CmagH2);
1024
1025   // detector effects checks
1026   histos->UserHistogram("Event","","", 10,0.,100., 300,-1.0,1.0,
1027                         AliDielectronVarManager::kCentrality, AliDielectronVarManager::kTPCsub12DiffH2Sin);
1028
1029   // TPC recentering
1030   // histos->UserProfile("Event","","", AliDielectronVarManager::kTPCxH2,
1031   //                  AliDielectronHelper::MakeLinBinning(9, 0.,90.), GetRunNumbers2011(),
1032   //                  AliDielectronVarManager::kCentrality, AliDielectronVarManager::kRunNumber);
1033   // histos->UserProfile("Event","","", AliDielectronVarManager::kTPCyH2,
1034   //                  AliDielectronHelper::MakeLinBinning(9, 0.,90.), GetRunNumbers2011(),
1035   //                  AliDielectronVarManager::kCentrality, AliDielectronVarManager::kRunNumber);
1036
1037 }
1038
1039 void AddHistsEleEff(AliDielectron *die) {
1040   //
1041   // adding histograms for single electron efficiencies
1042   //
1043
1044   Bool_t hasMC=die->GetHasMC();
1045   AliDielectronHistos *histos = die->GetHistoManager();
1046
1047   // applied efficiencies in collision data
1048   if(1) {
1049     histos->UserHistogram("Track","","", 101,-0.01,1.0, AliDielectronVarManager::kLegEff);
1050     histos->UserProfile("Track","","", AliDielectronVarManager::kLegEff, 18,0.0,90.0,  AliDielectronVarManager::kCentrality);
1051     histos->UserProfile("Track","","", AliDielectronVarManager::kLegEff, 100,0.0,20.0, AliDielectronVarManager::kPt);
1052     histos->UserProfile("Track","","", AliDielectronVarManager::kLegEff, 20,0.0,TMath::TwoPi(), AliDielectronVarManager::kPhi);
1053     histos->UserProfile("Track","","", AliDielectronVarManager::kLegEff, 20,-1.,+1.,   AliDielectronVarManager::kEta);
1054
1055     histos->UserHistogram("Pair","","", 101,-0.01,1.0, AliDielectronVarManager::kPairEff);
1056     histos->UserProfile("Pair","","", AliDielectronVarManager::kPairEff, 125,.0,125*0.04, AliDielectronVarManager::kM);
1057     histos->UserProfile("Pair","","", AliDielectronVarManager::kPairEff, 100,.0,10.0,     AliDielectronVarManager::kPt);
1058     histos->UserProfile("Pair","","", AliDielectronVarManager::kPairEff, 18,0.0,90.0,     AliDielectronVarManager::kCentrality);
1059
1060     histos->UserHistogram("Pair","","", 125,.0,125*0.04, 101,-0.01,1.0, 
1061                           AliDielectronVarManager::kM, AliDielectronVarManager::kPairEff);
1062
1063     histos->UserProfile("Pair","","", AliDielectronVarManager::kPt,125,.0,125*0.04, AliDielectronVarManager::kM);
1064     //weighted
1065     histos->UserHistogram("Pair","","", AliDielectronHelper::MakeLinBinning(125,.0,125*0.04),
1066                           AliDielectronVarManager::kM, AliDielectronVarManager::kOneOverPairEff);
1067     histos->UserProfile("Pair", "","", AliDielectronVarManager::kPt,AliDielectronHelper::MakeLinBinning(125,.0,125*0.04),
1068                         AliDielectronVarManager::kM, "", AliDielectronVarManager::kOneOverPairEff);
1069   }
1070
1071   // single electron efficiecy
1072
1073   // arbitrary binning for variables
1074   // TVectorD *vpt = AliDielectronHelper::MakeLinBinning( 41,  0.0,    10.25);
1075   // (*vpt)[41] = 20.;
1076   TVectorD *vpt1 = AliDielectronHelper::MakeLinBinning( (int)(( 3. - 0.)/0.10),    0.,     3.); //steps of 100MeV
1077   TVectorD *vpt2 = AliDielectronHelper::MakeLinBinning( (int)(( 10.- 3.25)/0.25),  3.25,  10.); //steps of 250MeV
1078   TVectorD *vpt3 = AliDielectronHelper::MakeLinBinning( (int)((100.-20.)/10.0),   20.,   100.); //steps of 10GeV
1079   TVectorD *vpt  = new TVectorD(vpt1->GetNrows()+vpt2->GetNrows()+vpt3->GetNrows());
1080   for(Int_t i=0; i<vpt1->GetNrows(); i++) (*vpt)[i]                                   = (*vpt1)[i];
1081   for(Int_t i=0; i<vpt2->GetNrows(); i++) (*vpt)[vpt1->GetNrows()+i]                  = (*vpt2)[i];
1082   for(Int_t i=0; i<vpt3->GetNrows(); i++) (*vpt)[vpt1->GetNrows()+vpt2->GetNrows()+i] = (*vpt3)[i];
1083   //vpt->Print();
1084
1085   // array of bin limits
1086   TObjArray *limEpm  = new TObjArray();
1087   //    limEpm->Add(AliDielectronHelper::MakeLinBinning( 75,-10.,     5.));
1088   limEpm->Add(AliDielectronHelper::MakeLinBinning( 18,  0.,    90.));
1089   limEpm->Add(vpt);
1090   //  limEpm->Add(AliDielectronHelper::MakeLinBinning( 20,  0.,   TMath::TwoPi()));
1091   limEpm->Add(AliDielectronHelper::MakeLinBinning( 20, -1.,    +1.));
1092   limEpm->Add(AliDielectronHelper::MakeLinBinning(  1, -1.,    +1.));
1093   limEpm->Add(AliDielectronHelper::MakeLinBinning(  1, -1.,    +1.));
1094   limEpm->Add(GetRunNumbers2011());
1095   limEpm->Add(GetPDGcodes());
1096   //  limEpm->Add(GetPDGcodes());
1097   UInt_t varEpm[]={//AliDielectronVarManager::kTPCnSigmaEle,
1098     AliDielectronVarManager::kCentrality
1099     ,AliDielectronVarManager::kPt
1100     //    ,AliDielectronVarManager::kPhi
1101     ,AliDielectronVarManager::kEta
1102     ,AliDielectronVarManager::kImpactParXY
1103     ,AliDielectronVarManager::kImpactParZ
1104     ,AliDielectronVarManager::kRunNumber
1105     ,AliDielectronVarManager::kPdgCodeMother
1106     //    ,AliDielectronVarManager::kPdgCodeGrandMother
1107   };
1108   // adding histogram
1109   //  if(hasMC) histos->UserSparse("Track", limEpm->GetEntriesFast(), limEpm, varEpm);
1110
1111   histos->UserHistogram("Track","","", 500,-1.,1., AliDielectronVarManager::kImpactParXY);
1112   histos->UserHistogram("Track","","", 600,-3.,3., AliDielectronVarManager::kImpactParZ);
1113
1114   // polarisation //
1115   // array of bin limits
1116   TVectorD *vpt = AliDielectronHelper::MakeLinBinning( 21,  0.0,    10.5);
1117   (*vpt)[21] = 100.;
1118   TObjArray *limPair  = new TObjArray();
1119   limPair->Add(AliDielectronHelper::MakeLinBinning( 18,  0.,    90.));
1120   limPair->Add(AliDielectronHelper::MakeLinBinning( 20, -1.,    +1.));
1121   limPair->Add(vpt);
1122   //  limPair->Add(GetPDGcodes());
1123   UInt_t varPair[]={
1124     AliDielectronVarManager::kCentrality
1125     ,AliDielectronVarManager::kThetaCS
1126     ,AliDielectronVarManager::kPt
1127     //    ,AliDielectronVarManager::kPdgCodeMother
1128   };
1129   //  if(hasMC) histos->UserSparse("Pair", limPair->GetEntriesFast(), limPair, varPair); // TAKES 4ever
1130
1131 }
1132
1133 void InitHF(AliDielectron* die, Int_t cutDefinition)
1134 {
1135   //
1136   // Setup the HF arrays
1137   //
1138   // do not fill
1139   switch(cutDefinition) {
1140   case kEvent:
1141   case kPIDqa:
1142   case kLegEff:
1143   case kNoPID:
1144   case kRec:
1145     return;
1146   }
1147
1148   // has mc
1149   Bool_t hasMC=die->GetHasMC();
1150   // booleans for histo selection
1151   Bool_t bHistEff = kFALSE; //ATTENTION
1152   // mixing
1153   AliDielectronMixingHandler *mixH=die->GetMixingHandler();
1154   Int_t maxMixBins = (mixH ? mixH->GetNumberOfBins() : 0);
1155
1156   // container
1157   AliDielectronHF *hf=new AliDielectronHF(die->GetName(),die->GetTitle());
1158   // define pair types and sources
1159   if(hasMC) hf->SetStepForMCGenerated();
1160   hf->SetPairTypes(AliDielectronHF::kOSandMIX);
1161   //  hf->SetPairTypes(AliDielectronHF::kMConly); // only mc truth
1162   //  hf->SetPairTypes(AliDielectronHF::kAll);    // all pair types
1163
1164   //// define the grid size and granularity /////
1165   hf->AddCutVariable(AliDielectronVarManager::kCentrality,               9, 0., 90.);
1166   TVectorD *vpt = AliDielectronHelper::MakeLinBinning( 21,  0.0,    10.5);
1167   (*vpt)[21] = 100.;
1168   hf->AddCutVariable(AliDielectronVarManager::kPt, vpt);
1169   hf->AddCutVariable(AliDielectronVarManager::kY,  1, -0.8,  0.8);
1170
1171   // defaults
1172   hf->UserHistogram("Pair", AliDielectronHelper::MakeLinBinning(125,.0,125*0.04), AliDielectronVarManager::kM);
1173   // for mixed event weighting
1174   // if(mixH) hf->UserHistogram("Pair", AliDielectronHelper::MakeLinBinning(maxMixBins,0,maxMixBins), AliDielectronVarManager::kMixingBin);
1175
1176   // mean pt analysis
1177   if(cutDefinition==kAvgPt) {
1178     hf->AddCutVariable(AliDielectronVarManager::kPairEff,  AliDielectronHelper::MakeArbitraryBinning(".0,.01,.02,.03,.04,.05,.1,1."));
1179     hf->UserProfile("Pair", AliDielectronVarManager::kPt,
1180                     AliDielectronHelper::MakeLinBinning(125,.0,125*0.04), AliDielectronVarManager::kM);
1181     hf->UserProfile("Pair", AliDielectronVarManager::kPtSq,
1182                     AliDielectronHelper::MakeLinBinning(125,.0,125*0.04), AliDielectronVarManager::kM);
1183   }
1184
1185   // flow analysis
1186   if(cutDefinition==kFlow && !hasMC) {
1187     // flow versus minv
1188     hf->UserProfile("Pair", AliDielectronVarManager::kv0ArpH2FlowV2,
1189                     AliDielectronHelper::MakeLinBinning(125,.0,125*0.04), AliDielectronVarManager::kM);
1190     hf->UserProfile("Pair", AliDielectronVarManager::kv0CrpH2FlowV2,
1191                     AliDielectronHelper::MakeLinBinning(125,.0,125*0.04), AliDielectronVarManager::kM);
1192     hf->UserProfile("Pair", AliDielectronVarManager::kTPCrpH2FlowV2,
1193                     AliDielectronHelper::MakeLinBinning(125,.0,125*0.04), AliDielectronVarManager::kM);
1194     // detector effects
1195     hf->UserProfile("Pair", AliDielectronVarManager::kCosTPCrpH2,
1196                     AliDielectronHelper::MakeLinBinning(1,.0,125*0.04), AliDielectronVarManager::kM);
1197     hf->UserProfile("Pair", AliDielectronVarManager::kSinTPCrpH2,
1198                     AliDielectronHelper::MakeLinBinning(1,.0,125*0.04), AliDielectronVarManager::kM);
1199     hf->UserProfile("Pair", AliDielectronVarManager::kCosPhiH2,
1200                     AliDielectronHelper::MakeLinBinning(1,.0,125*0.04), AliDielectronVarManager::kM);
1201     hf->UserProfile("Pair", AliDielectronVarManager::kSinPhiH2,
1202                     AliDielectronHelper::MakeLinBinning(1,.0,125*0.04), AliDielectronVarManager::kM);
1203     hf->UserProfile("Pair", AliDielectronVarManager::kTPCrpH2FlowV2Sin,
1204                     AliDielectronHelper::MakeLinBinning(125,.0,125*0.04), AliDielectronVarManager::kM);
1205
1206     // variables
1207     hf->AddCutVariable(AliDielectronVarManager::kDeltaPhiv0ArpH2, GetDeltaPhiBins());
1208     hf->AddCutVariable(AliDielectronVarManager::kDeltaPhiv0CrpH2, GetDeltaPhiBins());
1209     hf->AddCutVariable(AliDielectronVarManager::kDeltaPhiTPCrpH2, GetDeltaPhiBins());
1210   }
1211
1212   // on the fly efficienies
1213   if(cutDefinition==kAvgPt/* && (!hasMC || 0)*/) {
1214     hf->UserProfile("Pair", AliDielectronVarManager::kPairEff, 
1215                     AliDielectronHelper::MakeLinBinning(125,.0,125*0.04), AliDielectronVarManager::kM);
1216     hf->UserHistogram("Pair", AliDielectronHelper::MakeLinBinning(125,.0,125*0.04), AliDielectronVarManager::kM,
1217                       AliDielectronVarManager::kOneOverPairEff);
1218     //weighted
1219     hf->UserProfile("Pair", AliDielectronVarManager::kPt,
1220                     AliDielectronHelper::MakeLinBinning(125,.0,125*0.04), AliDielectronVarManager::kM, 
1221                     "", AliDielectronVarManager::kOneOverPairEff);
1222     hf->UserProfile("Pair", AliDielectronVarManager::kPtSq,
1223                     AliDielectronHelper::MakeLinBinning(125,.0,125*0.04), AliDielectronVarManager::kM, 
1224                     "", AliDielectronVarManager::kOneOverPairEff);
1225   }
1226
1227
1228   /*
1229 //// define the grid size and granularity /////
1230 // event variables //
1231 //  hf->AddCutVariable(AliDielectronVarManager::kCentrality, AliDielectronHelper::MakeArbitraryBinning("0,10,50,90")); // flow only
1232 if(hasMC) hf->AddCutVariable(AliDielectronVarManager::kCentrality,               18, 0., 90.);
1233 else      hf->AddCutVariable(AliDielectronVarManager::kCentrality,               9, 0., 90.);
1234 //  if(hasMC)  hf->AddCutVariable(AliDielectronVarManager::kRunNumber, GetRunNumbers2011() );
1235 //  if(hasMC)  hf->AddCutVariable(AliDielectronVarManager::kNacc,        3000,0.,3000.);
1236 //  if(hasMC)  hf->AddCutVariable(AliDielectronVarManager::kNVtxContrib,   20,0.,4000.);
1237
1238   // pair variables //ATTENTION
1239   if(hasMC && 0) hf->AddCutVariable(AliDielectronVarManager::kY,  18, -0.9,  0.9);
1240   //  hf->AddCutVariable(AliDielectronVarManager::kPt, 10,  0.0, 10.0);
1241   if(!hasMC)
1242      hf->AddCutVariable(AliDielectronVarManager::kPt, AliDielectronHelper::MakeArbitraryBinning("0,1,2,3,4,5,6,7,8,9,10,100"));
1243   //  hf->AddCutVariable(AliDielectronVarManager::kPt, 20,  0.0, 10.0);
1244   else
1245     hf->AddCutVariable(AliDielectronVarManager::kPt, 50,  0.0, 10.0);
1246
1247   //    if(hasMC) hf->AddCutVariable(AliDielectronVarManager::kTRDpidEffPair,101,0.0,1.01);
1248   //    if(hasMC) hf->AddCutVariable(AliDielectronVarManager::kThetaCS,15,-1.,1.);
1249
1250   // flow variables //
1251   //  if(!hasMC) hf->AddCutVariable(AliDielectronVarManager::kDeltaPhiv0ArpH2, GetDeltaPhiBins());
1252   //  if(!hasMC) hf->AddCutVariable(AliDielectronVarManager::kDeltaPhiv0CrpH2, GetDeltaPhiBins());
1253   if(!hasMC && bHistFlow) hf->AddCutVariable(AliDielectronVarManager::kDeltaPhiTPCrpH2, GetDeltaPhiBins());
1254
1255   // leg variables // NOTE: switched off in HF??
1256   //  if(hasMC) hf->AddCutVariable(AliDielectronVarManager::kPt, "0.85, 0.95, 1.1, 100.0", kTRUE, AliDielectronHF::kBinToMax);
1257   // if(hasMC) hf->AddCutVariable(AliDielectronVarManager::kEta,"-0.9,-0.8,0.8,0.9",      kTRUE, AliDielectronHF::kSymBin);
1258   //  hf->AddCutVariable(AliDielectronVarManager::kY,           1, -0.9, 0.9                     );
1259   //  hf->AddCutVariable(AliDielectronVarManager::kPt,          "0.8, 1.0, 1.1, 1.2, 1.5, 100.0", kTRUE, AliDielectronHF::kBinToMax);
1260   //  hf->AddCutVariable(AliDielectronVarManager::kNclsTPC,     "70,90,100,120,160",              kTRUE, AliDielectronHF::kBinToMax);
1261   //  hf->AddCutVariable(AliDielectronVarManager::kTPCnSigmaEle,"-4,-3,-2.5,-2,2,2.5,3,4",        kTRUE, AliDielectronHF::kSymBin);
1262   //hf->AddCutVariable(AliDielectronVarManager::kTPCnSigmaPio,"3.,3.5,4.,100.",                 kTRUE, AliDielectronHF::kBinToMax);
1263   //hf->AddCutVariable(AliDielectronVarManager::kITSLayerFirstCls,4,0.,4.,              kFALSE, kTRUE, AliDielectronHF::kBinFromMin);
1264   //hf->AddCutVariable(AliDielectronVarManager::kNclsITS,         5,2.,7.,              kFALSE, kTRUE, AliDielectronHF::kBinToMax);
1265   //hf->AddCutVariable(AliDielectronVarManager::kRunNumber,  GetRunNumbers2011());
1266   */
1267   die->SetHistogramArray(hf);
1268 }
1269
1270 void InitCF(AliDielectron* die, Int_t cutDefinition)
1271 {
1272   //
1273   // Setup the CF Manager if needed
1274   //
1275   // do not fill
1276   switch(cutDefinition) {
1277   case kEvent:
1278   case kPIDqa:
1279   case kLegEff:
1280   case kNoPID:
1281     return;
1282   }
1283
1284   // has mc
1285   Bool_t hasMC=die->GetHasMC();
1286
1287   // mixing
1288   AliDielectronMixingHandler *mixH=die->GetMixingHandler();
1289   Int_t maxMixBins = (mixH ? mixH->GetNumberOfBins() : 0);
1290
1291   // container
1292   AliDielectronCF *cf=new AliDielectronCF(die->GetName(),die->GetTitle());
1293
1294   //event variables
1295   //cf->AddVariable(AliDielectronVarManager::kCentrality,"0.,5.0,10.0,15.0,20.0,25.0,30.0,35.0,40.0,50.0");
1296   cf->AddVariable(AliDielectronVarManager::kCentrality,"0.,5.0,10.0,15.0,20.0,25.0,30.0,35.0,40.0,50.0,60.0,70.0,80.,90.");
1297   //  cf->AddVariable(AliDielectronVarManager::kRunNumber, GetRunNumbers2011() );
1298   if(mixH)  cf->AddVariable(AliDielectronVarManager::kMixingBin, AliDielectronHelper::MakeLinBinning(maxMixBins,0,maxMixBins));
1299
1300   //pair variables
1301   TVectorD *vpt = AliDielectronHelper::MakeLinBinning( 21,  0.0,    10.5);
1302   (*vpt)[21] = 100.;
1303   cf->AddVariable(AliDielectronVarManager::kPt, vpt);
1304   // TVectorD *vpt = AliDielectronHelper::MakeLinBinning( 41,  0.0,    10.25);
1305   // (*vpt)[41] = 100.;
1306   //  cf->AddVariable(AliDielectronVarManager::kPt,vpt);
1307   //  cf->AddVariable(AliDielectronVarManager::kPt,80,0.0,100*0.25);
1308
1309   //  cf->AddVariable(AliDielectronVarManager::kY,"-5,-1,-0.9,-0.8,-0.5,0.5,0.8,0.9,1.0,5");
1310   cf->AddVariable(AliDielectronVarManager::kY,"-0.9,-0.8,-0.7,+0.7,+0.8,+0.9");
1311   //  cf->AddVariable(AliDielectronVarManager::kY,18,-0.9,+0.9);
1312   cf->AddVariable(AliDielectronVarManager::kM,125,0.,125*.04); //40Mev Steps
1313   //  cf->AddVariable(AliDielectronVarManager::kPairType,1,1,1);
1314   cf->AddVariable(AliDielectronVarManager::kPairType,11,0,11);
1315   //  cf->AddVariable(AliDielectronVarManager::kThetaCS,20,-1.,+1.);
1316   //  cf->AddVariable(AliDielectronVarManager::kThetaHE,20,-1.,+1.);
1317   //  cf->AddVariable(AliDielectronVarManager::kPhiCS,20,-3.2,+3.2);
1318   //  cf->AddVariable(AliDielectronVarManager::kPhiHE,20,-3.2,+3.2);
1319   ///  cf->AddVariable(AliDielectronVarManager::kDeltaPhiTPCrpH2,GetDeltaPhiBins());
1320
1321   if(cutDefinition==kAvgPt && 0) { //ATTENTION
1322     cf->AddVariable(AliDielectronVarManager::kPairEff,  AliDielectronHelper::MakeArbitraryBinning(".0,.01,.02,.03,.04,.05,.1,1."));
1323   }
1324
1325   //leg variables
1326   if(cutDefinition!=kSysMCele && 0) { //ATTENTION
1327     cf->AddVariable(AliDielectronVarManager::kPt,"0.85, 1.1, 100.0",kTRUE);
1328     //  cf->AddVariable(AliDielectronVarManager::kNclsTPC,"0, 70, 80, 90, 100, 120, 160",kTRUE);
1329     cf->AddVariable(AliDielectronVarManager::kEta,"-0.9,-0.85,-0.8,-0.75,-0.70,0.70,0.75,0.8,0.85,0.9",kTRUE);
1330     cf->AddVariable(AliDielectronVarManager::kITSLayerFirstCls,3,-1.5,1.5,kTRUE);
1331     cf->AddVariable(AliDielectronVarManager::kTPCnSigmaPro,"3.5,4.0,4.5,100",kTRUE);
1332     cf->AddVariable(AliDielectronVarManager::kTPCnSigmaEle,"-1.5,-1.0,-0.6,3.0",kTRUE);
1333   }
1334   else if(0){
1335     cf->AddVariable(AliDielectronVarManager::kTPCnSigmaEle,"-3.0,-1.5,-1.0,-0.6,3.0",kTRUE);
1336   }
1337   /*
1338   // event variables
1339   cf->AddVariable(AliDielectronVarManager::kCentrality,               18,0.,  90.);
1340   if(hasMC)  cf->AddVariable(AliDielectronVarManager::kRunNumber, GetRunNumbers2011() );
1341   //  if(hasMC)  cf->AddVariable(AliDielectronVarManager::kNacc,        3000,0.,3000.);
1342   //  if(hasMC)  cf->AddVariable(AliDielectronVarManager::kNVtxContrib,   20,0.,4000.);
1343
1344   // pair variables
1345   if(hasMC)  cf->AddVariable(AliDielectronVarManager::kPairType,1,1,1);
1346   else       cf->AddVariable(AliDielectronVarManager::kPairType,11,0,11);
1347   cf->AddVariable(AliDielectronVarManager::kM, 125,  0.0,  5.0); //40Mev Steps
1348   if(hasMC)  cf->AddVariable(AliDielectronVarManager::kY,  18, -0.9,  0.9);
1349   if(hasMC)  cf->AddVariable(AliDielectronVarManager::kPt, 100,  0.0, 20.0);
1350   else       cf->AddVariable(AliDielectronVarManager::kPt, AliDielectronHelper::MakeArbitraryBinning("0,1,2,3,4,5,6,7,8,9,10,20"));
1351   //    if(hasMC) cf->AddVariable(AliDielectronVarManager::kTRDpidEffPair,101,0.0,1.01);
1352   //    if(hasMC) cf->AddVariable(AliDielectronVarManager::kThetaCS,15,-1.,1.);
1353
1354   // flow variables
1355   //if(!hasMC) cf->AddVariable(AliDielectronVarManager::kDeltaPhiv0ArpH2, GetDeltaPhiBins());
1356   //if(!hasMC) cf->AddVariable(AliDielectronVarManager::kDeltaPhiv0CrpH2, GetDeltaPhiBins());
1357
1358   // leg variables
1359   if(hasMC) cf->AddVariable(AliDielectronVarManager::kPt,"0.0, 0.85, 0.95, 1.0, 1.1, 100.0",kTRUE);
1360   if(hasMC) cf->AddVariable(AliDielectronVarManager::kEta,"-0.9,-0.8,-0.7, 0.7, 0.8, 0.9",  kTRUE);
1361   //    cf->AddVariable(AliDielectronVarManager::kITSLayerFirstCls,7,-1.5,5.5,kTRUE);
1362   //    cf->AddVariable(AliDielectronVarManager::kNclsITS,"1,2,3,4,5,6",kTRUE);
1363   //    cf->AddVariable(AliDielectronVarManager::kTPCnSigmaEle,"-3,-2.5,-2,2,2.5,3",kTRUE);
1364   //    cf->AddVariable(AliDielectronVarManager::kTPCnSigmaPio,"2.5,3.0,3.5,4.0,4.5,100",kTRUE);
1365   //    cf->AddVariable(AliDielectronVarManager::kNclsTPC,"70, 90, 100, 120, 160",kTRUE);
1366   //    cf->AddVariable(AliDielectronVarManager::kTPCnSigmaPro,"3.5,4.0,4.5,5.0,100",kTRUE);
1367   //    cf->AddVariable(AliDielectronVarManager::kTOFnSigmaEle,"-3,-2,2,3",kTRUE); break;
1368   //    cf->AddVariable(AliDielectronVarManager::kTRDpidQuality,"3.5, 4.5, 5.5, 6.5",kTRUE);
1369   //    if(!hasMC && isESD) cf->AddVariable(AliDielectronVarManager::kTRDchi2,"-1.,0.,2.,4.",kTRUE);
1370   */
1371   // mc steps
1372   if(hasMC) {
1373     cf->SetStepForMCtruth();
1374     //    cf->SetStepForNoCutsMCmotherPid();
1375     //    cf->SetStepForAfterAllCuts();
1376     //    cf->SetStepsForEachCut();
1377     //    cf->SetStepsForSignal();
1378     //    cf->SetStepsForBackground();
1379     //cf->SetStepsForMCtruthOnly();
1380   }
1381   else
1382     cf->SetStepsForSignal();
1383
1384   die->SetCFManagerPair(cf);
1385 }
1386
1387 void AddMCSignals(AliDielectron *die, Int_t cutDefinition){
1388   //Do we have an MC handler?
1389   if (!die->GetHasMC()) return;
1390
1391   AliDielectronSignalMC* inclusiveJpsi = new AliDielectronSignalMC("inclusiveJpsi","Inclusive");
1392   inclusiveJpsi->SetLegPDGs(11,-11);
1393   inclusiveJpsi->SetMotherPDGs(443,443);
1394   inclusiveJpsi->SetMothersRelation(AliDielectronSignalMC::kSame);
1395   inclusiveJpsi->SetFillPureMCStep(kTRUE);
1396   inclusiveJpsi->SetCheckBothChargesLegs(kTRUE,kTRUE);
1397   inclusiveJpsi->SetCheckBothChargesMothers(kTRUE,kTRUE);
1398
1399   AliDielectronSignalMC* beautyJpsi = new AliDielectronSignalMC("beautyJpsi","Beauty");
1400   beautyJpsi->SetLegPDGs(11,-11);
1401   beautyJpsi->SetMotherPDGs(443,443);
1402   beautyJpsi->SetMothersRelation(AliDielectronSignalMC::kSame);
1403   beautyJpsi->SetGrandMotherPDGs(500,500);
1404   beautyJpsi->SetFillPureMCStep(kTRUE);
1405   beautyJpsi->SetCheckBothChargesLegs(kTRUE,kTRUE);
1406   beautyJpsi->SetCheckBothChargesMothers(kTRUE,kTRUE);
1407   beautyJpsi->SetCheckBothChargesGrandMothers(kTRUE,kTRUE);
1408
1409   AliDielectronSignalMC* promptJpsi = new AliDielectronSignalMC("promptJpsi","Prompt");   // prompt J/psi (not from beauty decays)
1410   promptJpsi->SetLegPDGs(11,-11);
1411   promptJpsi->SetMotherPDGs(443,443);
1412   promptJpsi->SetGrandMotherPDGs(503,503,kTRUE,kTRUE);   // not from beauty hadrons
1413   promptJpsi->SetMothersRelation(AliDielectronSignalMC::kSame);
1414   promptJpsi->SetFillPureMCStep(kTRUE);
1415   promptJpsi->SetLegSources(AliDielectronSignalMC::kFinalState, AliDielectronSignalMC::kFinalState);
1416   promptJpsi->SetCheckBothChargesLegs(kTRUE,kTRUE);
1417   promptJpsi->SetCheckBothChargesMothers(kTRUE,kTRUE);
1418   promptJpsi->SetCheckBothChargesGrandMothers(kTRUE,kTRUE);
1419
1420   // prompt J/psi radiative channel
1421   AliDielectronSignalMC* promptJpsiRad = new AliDielectronSignalMC("promptJpsiRad","PromptRadiative");   // prompt J/psi (not from beauty decays)
1422   promptJpsiRad->SetLegPDGs(11,-11);
1423   promptJpsiRad->SetMotherPDGs(443,443);
1424   promptJpsiRad->SetGrandMotherPDGs(503,503,kTRUE,kTRUE);   // not from beauty hadrons
1425   promptJpsiRad->SetMothersRelation(AliDielectronSignalMC::kSame);
1426   promptJpsiRad->SetFillPureMCStep(kTRUE);
1427   promptJpsiRad->SetLegSources(AliDielectronSignalMC::kFinalState, AliDielectronSignalMC::kFinalState);
1428   promptJpsiRad->SetCheckBothChargesLegs(kTRUE,kTRUE);
1429   promptJpsiRad->SetCheckBothChargesMothers(kTRUE,kTRUE);
1430   promptJpsiRad->SetCheckBothChargesGrandMothers(kTRUE,kTRUE);
1431   promptJpsiRad->SetJpsiRadiative(AliDielectronSignalMC::kIsRadiative);
1432
1433   // prompt J/psi Non radiative channel
1434   AliDielectronSignalMC* promptJpsiNonRad = new AliDielectronSignalMC("promptJpsiNonRad","PromptNonRadiative");   // prompt J/psi (not from beauty decays)
1435   promptJpsiNonRad->SetLegPDGs(11,-11);
1436   promptJpsiNonRad->SetMotherPDGs(443,443);
1437   promptJpsiNonRad->SetGrandMotherPDGs(503,503,kTRUE,kTRUE);   // not from beauty hadrons
1438   promptJpsiNonRad->SetMothersRelation(AliDielectronSignalMC::kSame);
1439   promptJpsiNonRad->SetFillPureMCStep(kTRUE);
1440   promptJpsiNonRad->SetLegSources(AliDielectronSignalMC::kFinalState, AliDielectronSignalMC::kFinalState);
1441   promptJpsiNonRad->SetCheckBothChargesLegs(kTRUE,kTRUE);
1442   promptJpsiNonRad->SetCheckBothChargesMothers(kTRUE,kTRUE);
1443   promptJpsiNonRad->SetCheckBothChargesGrandMothers(kTRUE,kTRUE);
1444   promptJpsiNonRad->SetJpsiRadiative(AliDielectronSignalMC::kIsNotRadiative);
1445
1446   AliDielectronSignalMC* directJpsi = new AliDielectronSignalMC("directJpsi","Direct");   // embedded J/psi
1447   directJpsi->SetLegPDGs(11,-11);
1448   directJpsi->SetMotherPDGs(443,443);
1449   directJpsi->SetMothersRelation(AliDielectronSignalMC::kSame);
1450   directJpsi->SetFillPureMCStep(kTRUE);
1451   directJpsi->SetLegSources(AliDielectronSignalMC::kFinalState, AliDielectronSignalMC::kFinalState);
1452   directJpsi->SetMotherSources(AliDielectronSignalMC::kDirect, AliDielectronSignalMC::kDirect);
1453   directJpsi->SetCheckBothChargesLegs(kTRUE,kTRUE);
1454   directJpsi->SetCheckBothChargesMothers(kTRUE,kTRUE);
1455
1456   AliDielectronSignalMC* gammaConversion = new AliDielectronSignalMC("gammaConversion","gamma conversions");
1457   gammaConversion->SetLegPDGs(11,-11);
1458   gammaConversion->SetCheckBothChargesLegs(kTRUE,kTRUE);
1459   gammaConversion->SetLegSources(AliDielectronSignalMC::kSecondary, AliDielectronSignalMC::kSecondary);
1460   gammaConversion->SetMotherPDGs(22,22);
1461   gammaConversion->SetMothersRelation(AliDielectronSignalMC::kSame);
1462
1463
1464   AliDielectronSignalMC* electrons = new AliDielectronSignalMC("electrons","electrons");
1465   electrons->SetLegPDGs(11,1);  //dummy second leg (never MCtrue)
1466   electrons->SetCheckBothChargesLegs(kTRUE,kTRUE);
1467   electrons->SetLegSources(AliDielectronSignalMC::kFinalState, AliDielectronSignalMC::kFinalState);
1468   //  electrons->SetGrandMotherPDGs(500,500,kTRUE,kTRUE); // exclude non-prompt jpsi eletrons
1469   electrons->SetFillPureMCStep(kTRUE);
1470   //  electrons->SetMothersRelation(AliDielectronSignalMC::kSame);
1471
1472   AliDielectronSignalMC* directElec = new AliDielectronSignalMC("directElec","directElec");
1473   directElec->SetLegPDGs(11,11);
1474   directElec->SetCheckBothChargesLegs(kTRUE,kTRUE);
1475   directElec->SetLegSources(AliDielectronSignalMC::kFinalState, AliDielectronSignalMC::kFinalState);
1476   //  directElec->SetGrandMotherPDGs(-1103,-1103);
1477   directElec->SetFillPureMCStep(kTRUE);
1478   directElec->SetMothersRelation(AliDielectronSignalMC::kSame);
1479   directElec->SetMotherSources(AliDielectronSignalMC::kDirect, AliDielectronSignalMC::kDirect);
1480
1481
1482   AliDielectronSignalMC* elecPrim = new AliDielectronSignalMC("elecPrim","elecPrim");
1483   elecPrim->SetLegPDGs(11,1);  //dummy second leg (never MCtrue)
1484   elecPrim->SetCheckBothChargesLegs(kTRUE,kTRUE);
1485   elecPrim->SetLegSources(AliDielectronSignalMC::kFinalState, AliDielectronSignalMC::kFinalState);
1486   elecPrim->SetCheckBothChargesMothers(kTRUE,kTRUE);
1487   elecPrim->SetMotherPDGs(902,902,kTRUE,kTRUE); // exclude non-prompt jpsi eletrons
1488   elecPrim->SetCheckBothChargesGrandMothers(kTRUE,kTRUE);
1489   elecPrim->SetGrandMotherPDGs(902,902,kTRUE,kTRUE); // exclude non-prompt jpsi eletrons
1490   elecPrim->SetFillPureMCStep(kTRUE);
1491
1492   // add direct di lepton resonances
1493   /*
1494   AliDielectronSignalMC* directP[7];
1495   TParticlePDG *ap;
1496   Int_t pdg[] = {111, 113, 221, 223, 331, 333, 443};
1497   for(Int_t i=0; i<7; i++) {
1498     ap = TDatabasePDG::Instance()->GetParticle(pdg[i]);
1499     directP[i] = new AliDielectronSignalMC(Form("direct%s",ap->GetName()),Form("direct%s",ap->GetName()));
1500     directP[i]->SetLegPDGs(11,-11);
1501     directP[i]->SetMotherPDGs(pdg[i],pdg[i]);
1502     directP[i]->SetMothersRelation(AliDielectronSignalMC::kSame);
1503     directP[i]->SetFillPureMCStep(kTRUE);
1504     directP[i]->SetLegSources(AliDielectronSignalMC::kFinalState, AliDielectronSignalMC::kFinalState);
1505     directP[i]->SetMotherSources(AliDielectronSignalMC::kDirect, AliDielectronSignalMC::kDirect);
1506     // directP[i]->SetCheckBothChargesLegs(kTRUE,kTRUE);
1507     // directP[i]->SetCheckBothChargesMothers(kTRUE,kTRUE);
1508   }
1509   */
1510
1511   /*
1512   AliDielectronSignalMC* eleHijing = new AliDielectronSignalMC("eleHijing","eleHijing");
1513   eleHijing->SetLegPDGs(11,1);  //dummy second leg (never MCtrue)
1514   eleHijing->SetCheckBothChargesLegs(kTRUE,kTRUE);
1515   eleHijing->SetLegSources(AliDielectronSignalMC::kNoCocktail, AliDielectronSignalMC::kNoCocktail);
1516   eleHijing->SetFillPureMCStep(kTRUE);
1517   */
1518   /*
1519   AliDielectronSignalMC* electrons = new AliDielectronSignalMC("electrons","electrons");
1520   electrons->SetLegPDGs(11,-11);  //dummy second leg (never MCtrue)
1521   electrons->SetCheckBothChargesLegs(kTRUE,kTRUE);
1522   electrons->SetLegSources(AliDielectronSignalMC::kFinalState, AliDielectronSignalMC::kFinalState);
1523   //  electrons->SetMotherPDGs(111,111,kTRUE,kTRUE);   // not from pi0
1524   //  electrons->SetMothersRelation(AliDielectronSignalMC::kSame);
1525   electrons->SetFillPureMCStep(kTRUE);
1526   */
1527
1528   // selection
1529   switch(cutDefinition) {
1530   case kPIDqa:
1531     return;
1532     //    die->AddSignalMC(directElec);
1533     break;
1534   case kRec:
1535     die->AddSignalMC(inclusiveJpsi);
1536     die->AddSignalMC(directJpsi);
1537     break;
1538   case kIonut:
1539     die->AddSignalMC(inclusiveJpsi);
1540     //  die->AddSignalMC(beautyJpsi);
1541     //die->AddSignalMC(promptJpsi);
1542     //die->AddSignalMC(promptJpsiRad);
1543     //die->AddSignalMC(promptJpsiNonRad);
1544     die->AddSignalMC(directJpsi);
1545     //  die->AddSignalMC(gammaConversion);
1546     break;
1547   case kAvgPt:
1548     die->AddSignalMC(inclusiveJpsi);
1549     die->AddSignalMC(directJpsi);
1550     break;
1551   case kLegEff:
1552     // die->AddSignalMC(directJpsi);
1553     // die->AddSignalMC(inclusiveJpsi);
1554     // die->AddSignalMC(electrons);
1555     // die->AddSignalMC(elecPrim);
1556     die->AddSignalMC(directElec);
1557     //for(Int_t i=0; i<7; i++) die->AddSignalMC(directP[i]);
1558     break;
1559   default:
1560     die->AddSignalMC(directJpsi);
1561     break;
1562   }
1563
1564
1565 }
1566
1567 void SetEtaCorrection(AliDielectron *pid, Bool_t hasMC) {
1568
1569   //  if (pid->GetCentroidCorrFunction()) return;
1570
1571
1572   TF2 *fCntrdCorr=0x0;
1573   TF1 *fWdthCorr=0x0;
1574   /* vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv DATA vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv */
1575   // either data or MC with tune on data option
1576   if( !hasMC || ((AliPIDResponse*)AliAnalysisManager::GetAnalysisManager()->GetTasks()->At(0))->IsTunedOnData()) {
1577     // 2-dimensional eta correction for the centroid of electron sigmas
1578     fCntrdCorr = new TF2("fCntrdCorr", 
1579                          "[0] + [1]*y + [2]*y*y + [3]*TMath::Power(y,3) + [4]*TMath::Power(y,4) + [5]*TMath::Power(y,5) + [6]*TMath::Power(y,6) + [7]*x",
1580                          //                           0.0, 3000.0, -0.9, +0.9);
1581                          0.0, 90.0, -0.9, +0.9);
1582     // fCntrdCorr->SetParameters(0.723106, 0.23958, -6.31221, -0.687976, 15.912, 0.579609, -11.6901, -0.000354381); //Nacc dep.
1583     fCntrdCorr->SetParameters(+0.149002, +0.214644 , -6.034930, -0.529588, +14.97902, +0.402640, -10.890027, +0.011248); //Cent
1584     
1585     // 1-dimensional eta correction for the width of electron sigmas
1586     fWdthCorr = new TF1("fWdthCorr", "pol2", 0.0, 90.0);
1587     //    fWdthCorr->SetParameters(1.06108, 0.000217804,-5.80291e-08); //Nacc dep.
1588     fWdthCorr->SetParameters(+1.290755, -0.005261, +0.000021); //Cent dep.
1589
1590     // apply corrections
1591     // pid->SetCentroidCorrFunction(fCntrdCorr,AliDielectronVarManager::kNacc,AliDielectronVarManager::kEta);
1592     // pid->SetWidthCorrFunction(fWdthCorr,AliDielectronVarManager::kNacc);
1593     pid->SetCentroidCorrFunction(fCntrdCorr,AliDielectronVarManager::kCentrality,AliDielectronVarManager::kEta);
1594     pid->SetWidthCorrFunction(fWdthCorr,AliDielectronVarManager::kCentrality);
1595     printf(" DATA PID correction loaded!!!\n");
1596   }
1597   else  {
1598     /* vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv MONTE CARLO vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv */
1599     // 2-dimensional eta correction for the centroid of electron sigmas
1600     fCntrdCorr = new TF2("fCntrdCorr", "[0] + [1]*y + [2]*y*y + [3]*TMath::Power(y,3) + [4]*TMath::Power(y,4) + [5]*TMath::Power(y,5) + [6]*TMath::Power(y,6) + [7]*x",
1601                               0.0, 3000.0, -0.9, +0.9);
1602     fCntrdCorr->SetParameters(+0.378611, -0.070831, -3.076778, +0.121977, +8.576097, +0.113009, -5.001368, -0.000181);
1603     // 1-dimensional eta correction for the width of electron sigmas
1604     fWdthCorr = new TF1("fWdthCorr", "pol1", 0.0, 3000.0);
1605     fWdthCorr->SetParameters(+0.881894, +0.000053);
1606
1607     // apply corrections
1608     pid->SetCentroidCorrFunction(fCntrdCorr,AliDielectronVarManager::kNacc,AliDielectronVarManager::kEta);
1609     pid->SetWidthCorrFunction(fWdthCorr,AliDielectronVarManager::kNacc);
1610     // pid->SetCentroidCorrFunction(fCntrdCorr,AliDielectronVarManager::kCentrality,AliDielectronVarManager::kEta);
1611     // pid->SetWidthCorrFunction(fWdthCorr,AliDielectronVarManager::kCentrality);
1612     printf(" MC PID correction loaded!!!\n");
1613   }
1614
1615
1616 }
1617
1618 TVectorD *GetRunNumbers2011() {
1619   
1620   Double_t runLHC10h[] = { // all good runs based on RCT 29.Mai
1621     139510, 139507, 139505, 139503, 139465, 139438, 139437, 139360, 139329, 139328, 139314, 139310, 139309, 139173, 139107, 139105, 139038, 139037, 139036, 139029, 139028, 138872, 138871, 138870, 138837, 138732, 138730, 138666, 138662, 138653, 138652, 138638, 138624, 138621, 138583, 138582, 138579, 138578, 138534, 138469, 138442, 138439, 138438, 138396, 138364, 138275, 138225, 138201, 138197, 138192, 138190, 137848, 137844, 137752, 137751, 137724, 137722, 137718, 137704, 137693, 137692, 137691, 137686, 137685, 137639, 137638, 137608, 137595, 137549, 137546, 137544, 137541, 137539, 137531, 137530, 137443, 137441, 137440, 137439, 137434, 137432, 137431, 137430, 137366, 137243, 137236, 137235, 137232, 137231, 137230, 137162, 137161, 137135
1622   };
1623   Double_t runLHC11h[] = { // all good runs based on RCT 29.Mai
1624     167915, 167920, 167985, 167987, 167988, 168069, 168076, 168105, 168107, 168108, 168115, 168310, 168311, 168322, 168325, 168341, 168342, 168361, 168362, 168458, 168460, 168464, 168467, 168511, 168512, 168514, 168777, 168826, 168988, 168992, 169035, 169040, 169044, 169045, 169091, 169094, 169099, 169138, 169144, 169145, 169148, 169156, 169160, 169167, 169238, 169411, 169415, 169417, 169418, 169419, 169420, 169475, 169498, 169504, 169506, 169512, 169515, 169550, 169553, 169554, 169555, 169557, 169586, 169587, 169588, 169590, 169591, 169835, 169837, 169838, 169846, 169855, 169858, 169859, 169923, 169965, 170027, 170040, 170081, 170083, 170084, 170085, 170088, 170089, 170091, 170155, 170159, 170163, 170193, 170203, 170204, 170207, 170228, 170230, 170268, 170269, 170270, 170306, 170308, 170309, 170311, 170312, 170313, 170315, 170387, 170388, 170572, 170593, 
1625     170593+1
1626   };
1627   /*
1628   if(list.Contains("LHC10h") || list.Contains("LHC11a10")) {
1629   if( list.Contains("LHC11h") || list.Contains("LHC12a17") ) {
1630   */  
1631   Int_t size = (int) (sizeof(runLHC11h)/sizeof(Double_t));
1632   TVectorD *vec = new TVectorD(size,runLHC11h);
1633   //vec->Print("");
1634   return vec;
1635 }
1636
1637 TVectorD *GetPDGcodes() {
1638   //
1639   // array of pdgcodes stored in TDatabasePDG
1640   //
1641   TDatabasePDG *pdg = new TDatabasePDG();
1642   pdg->ReadPDGTable();
1643   TGraph *gr = new TGraph();
1644   TIter next(pdg->ParticleList());
1645   TParticlePDG *p;
1646   Int_t i=0;
1647   while ((p = (TParticlePDG *)next())) {
1648     if(TMath::Abs(p->PdgCode()) < 1e+6) {
1649       //      printf("%s -> %d \n",p->GetName(),p->PdgCode());
1650       gr->SetPoint(i++, p->PdgCode(),1.);
1651     }
1652   }
1653   gr->Sort();
1654   TVectorD *vec = new TVectorD(gr->GetN(), gr->GetX());
1655   //  vec->Print();
1656   delete pdg;
1657   delete gr;
1658   return vec;
1659
1660 }
1661
1662 TVectorD *GetDeltaPhiBins() {
1663   //
1664   // for in and out of event plane bins
1665   //
1666   Double_t pi = TMath::Pi();
1667   TVectorD *deltaPhi = new TVectorD(6);
1668   (*deltaPhi)[0] = -1.    *pi;
1669   (*deltaPhi)[1] = -3./4. *pi;
1670   (*deltaPhi)[2] = -1./4. *pi;
1671   (*deltaPhi)[3] = +1./4. *pi;
1672   (*deltaPhi)[4] = +3./4. *pi;
1673   (*deltaPhi)[5] = +1.    *pi;
1674   return deltaPhi;
1675 }