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