]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGHF/hfe/AliAnalysisTaskHFEemcQA.cxx
Merge branch 'feature-movesplit'
[u/mrichter/AliRoot.git] / PWGHF / hfe / AliAnalysisTaskHFEemcQA.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16
17 //////////////////////////////////////////////
18 //    QA task for EMCAL electron analysis   //
19 //  Author: Deepa Thomas, Shingo Sakai      //
20 //////////////////////////////////////////////
21
22 #include "TChain.h"
23 #include "TTree.h"
24 #include "TH1F.h"
25 #include "TCanvas.h"
26 #include "THnSparse.h"
27
28 #include "AliAnalysisTask.h"
29 #include "AliAnalysisManager.h"
30
31 #include "AliESDEvent.h"
32 #include "AliESDInputHandler.h"
33 #include "AliESDtrackCuts.h"
34 #include "AliAODEvent.h"
35 #include "AliAODHandler.h"
36
37 #include "AliPID.h"
38 #include "AliESDpid.h"
39 #include "AliAODPid.h"
40 #include "AliPIDResponse.h"
41 #include "AliHFEcontainer.h"
42 #include "AliHFEcuts.h"
43 #include "AliHFEpid.h"
44 #include "AliHFEpidBase.h"
45 #include "AliHFEpidQAmanager.h"
46 #include "AliHFEtools.h"
47 #include "AliCFContainer.h"
48 #include "AliCFManager.h"
49
50 #include "AliAnalysisTaskHFEemcQA.h"
51
52 using std::cout;
53 using std::endl;
54
55 ClassImp(AliAnalysisTaskHFEemcQA)
56   //________________________________________________________________________
57   AliAnalysisTaskHFEemcQA::AliAnalysisTaskHFEemcQA(const char *name) 
58 : AliAnalysisTaskSE(name),
59   fVevent(0),
60   fESD(0),
61   fAOD(0),
62   fpidResponse(0),
63   fFlagSparse(kFALSE),
64   fUseTender(kTRUE),
65   fTracks_tender(0),
66   fCaloClusters_tender(0),
67   fOutputList(0),
68   fNevents(0),
69   fVtxZ(0),
70   fVtxX(0),
71   fVtxY(0),
72   fTrigMulti(0),
73   fHistClustE(0),
74   fEMCClsEtaPhi(0),
75   fHistoNCls(0),
76   fHistoNClsE1(0),
77   fHistoNClsE2(0),
78   fHistoNClsE3(0),
79   fHistoNCells(0),
80   fHistoCalCell(0),
81   fHistoCalTime(0),
82   fHistoCalCellTime(0),
83   fNegTrkIDPt(0),
84   fTrkPt(0),
85   fTrketa(0),
86   fTrkphi(0),
87   fdEdx(0),
88   fTPCNpts(0),
89   fTPCnsig(0),
90   fHistPtMatch(0),
91   fEMCTrkMatch(0),
92   fEMCTrkPt(0),
93   fEMCTrketa(0),
94   fEMCTrkphi(0),
95   fEMCdEdx(0),
96   fEMCTPCnsig(0),
97   fEMCTPCNpts(0),
98   fClsEAftMatch(0),
99   fHistdEdxEop(0),
100   fHistNsigEop(0),
101   fHistEop(0),
102   fM20(0),
103   fM02(0),
104   fM20EovP(0),
105   fM02EovP(0),
106   fEleCanTPCNpts(0),
107   fEleCanTPCNCls(0),
108   fEleCanITSNCls(0),
109   fEleCanITShit(0),
110   fEleCanSPD1(0),
111   fEleCanSPD2(0),
112   fEleCanSPDBoth(0),
113   fEleCanSPDOr(0),
114   fSparseElectron(0),
115   fvalueElectron(0)
116 {
117   // Constructor
118
119   fvalueElectron = new Double_t[6];
120   // Define input and output slots here
121   // Input slot #0 works with a TChain
122   DefineInput(0, TChain::Class());
123   // Output slot #0 id reserved by the base class for AOD
124   // Output slot #1 writes into a TH1 container
125   DefineOutput(1, TList::Class());
126 }
127 //________________________________________________________________________
128 AliAnalysisTaskHFEemcQA::AliAnalysisTaskHFEemcQA() 
129   : AliAnalysisTaskSE("DefaultTask_HfeEMCQA"),
130   fVevent(0),
131   fESD(0),
132   fAOD(0),
133   fpidResponse(0),
134   fFlagSparse(kFALSE),
135   fUseTender(kTRUE),
136   fTracks_tender(0),
137   fCaloClusters_tender(0),
138   fOutputList(0),
139   fNevents(0),
140   fVtxZ(0),
141   fVtxX(0),
142   fVtxY(0),
143   fTrigMulti(0),
144   fHistClustE(0),
145   fEMCClsEtaPhi(0),
146   fHistoNCls(0),
147   fHistoNClsE1(0),
148   fHistoNClsE2(0),
149   fHistoNClsE3(0),
150   fHistoNCells(0),
151   fHistoCalCell(0),
152   fHistoCalTime(0),
153   fHistoCalCellTime(0),
154   fNegTrkIDPt(0),
155   fTrkPt(0),
156   fTrketa(0),
157   fTrkphi(0),
158   fdEdx(0),
159   fTPCNpts(0),
160   fTPCnsig(0),
161   fHistPtMatch(0),
162   fEMCTrkMatch(0),
163   fEMCTrkPt(0),
164   fEMCTrketa(0),
165   fEMCTrkphi(0),
166   fEMCdEdx(0),
167   fEMCTPCnsig(0),
168   fEMCTPCNpts(0),
169   fClsEAftMatch(0),
170   fHistdEdxEop(0),
171   fHistNsigEop(0),
172   fHistEop(0),
173   fM20(0),
174   fM02(0),
175   fM20EovP(0),
176   fM02EovP(0),
177   fEleCanTPCNpts(0),
178   fEleCanTPCNCls(0),
179   fEleCanITSNCls(0),
180   fEleCanITShit(0),
181   fEleCanSPD1(0),
182   fEleCanSPD2(0),
183   fEleCanSPDBoth(0),
184   fEleCanSPDOr(0),
185   fSparseElectron(0),
186   fvalueElectron(0)
187 {
188   //Default constructor
189
190   fvalueElectron = new Double_t[6];
191   // Define input and output slots here
192   // Input slot #0 works with a TChain
193   DefineInput(0, TChain::Class());
194   // Output slot #0 id reserved by the base class for AOD
195   // Output slot #1 writes into a TH1 container
196   // DefineOutput(1, TH1I::Class());
197   DefineOutput(1, TList::Class());
198   //DefineOutput(3, TTree::Class());
199 }
200 //________________________________________________________________________
201 AliAnalysisTaskHFEemcQA::~AliAnalysisTaskHFEemcQA()
202 {
203   //Destructor 
204   delete fOutputList;
205   delete fTracks_tender;
206   delete fCaloClusters_tender;
207   delete fSparseElectron;
208   delete []fvalueElectron;
209 }
210 //________________________________________________________________________
211 void AliAnalysisTaskHFEemcQA::UserCreateOutputObjects()
212 {
213   // Create histograms
214   // Called once
215   AliDebug(3, "Creating Output Objects");
216
217   /////////////////////////////////////////////////
218   //Automatic determination of the analysis mode//
219   ////////////////////////////////////////////////
220   AliVEventHandler *inputHandler = dynamic_cast<AliVEventHandler *>(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
221   if(!TString(inputHandler->IsA()->GetName()).CompareTo("AliAODInputHandler")){
222     SetAODAnalysis();
223   } else {
224     SetESDAnalysis();
225   }
226   printf("Analysis Mode: %s Analysis\n", IsAODanalysis() ? "AOD" : "ESD");
227
228   //////////////// 
229   //Output list//
230   ///////////////
231   fOutputList = new TList();
232   fOutputList->SetOwner();  
233
234   fNevents = new TH1F("fNevents","No of events",3,-0.5,2.5);
235   fOutputList->Add(fNevents);
236   fNevents->GetYaxis()->SetTitle("counts");
237   fNevents->GetXaxis()->SetBinLabel(1,"All");
238   fNevents->GetXaxis()->SetBinLabel(2,"With >2 Trks");
239   fNevents->GetXaxis()->SetBinLabel(3,"Vtx_{z}<10cm");
240
241   fVtxZ = new TH1F("fVtxZ","Z vertex position;Vtx_{z};counts",1000,-50,50);
242   fOutputList->Add(fVtxZ);
243
244   fVtxY = new TH1F("fVtxY","Y vertex position;Vtx_{y};counts",1000,-50,50);
245   fOutputList->Add(fVtxY);
246
247   fVtxX = new TH1F("fVtxX","X vertex position;Vtx_{x};counts",1000,-50,50);
248   fOutputList->Add(fVtxX);
249
250   fTrigMulti = new TH2F("fTrigMulti","Multiplicity distribution for different triggers; Trigger type; multiplicity",11,-1,10,2000,0,2000);
251   fOutputList->Add(fTrigMulti);
252
253   fHistClustE = new TH1F("fHistClustE", "EMCAL cluster energy distribution; Cluster E;counts", 5000, 0.0, 50.0);
254   fOutputList->Add(fHistClustE);
255
256   fEMCClsEtaPhi = new TH2F("fEMCClsEtaPhi","EMCAL cluster #eta and #phi distribution;#eta;#phi",100,-0.9,0.9,200,0,6.3);
257   fOutputList->Add(fEMCClsEtaPhi);
258
259   fHistoNCls = new TH1F("fHistoNCls","No of EMCAL cluster in the event;N^{EMC}_{cls};counts",150,0,150);
260   fOutputList->Add(fHistoNCls);
261
262   fHistoNClsE1 = new TH1F("fHistoNClsE1","No of EMCAL cluster in the event (E>0.1 GeV);N^{EMC}_{cls};counts",150,0,150);
263   fOutputList->Add(fHistoNClsE1);
264
265   fHistoNClsE2 = new TH1F("fHistoNClsE2","No of EMCAL cluster in the event (E>0.2 GeV);N^{EMC}_{cls};counts",150,0,150);
266   fOutputList->Add(fHistoNClsE2);
267
268   fHistoNClsE3 = new TH1F("fHistoNClsE3","No of EMCAL cluster in the event (E>0.5 GeV);N^{EMC}_{cls};counts",150,0,150);
269   fOutputList->Add(fHistoNClsE3);
270
271   //fHistoNCells = new TH1F("fHistoNCells","No of EMCAL cells in a cluster;N^{EMC}_{cells};counts",30,0,30);
272   fHistoNCells = new TH2F("fHistoNCells","No of EMCAL cells in a cluster;Cluster E;N^{EMC}_{cells}",300,0,30,30,0,30);
273   fOutputList->Add(fHistoNCells);
274
275   fHistoCalCell = new TH2F("fHistoCalCell","EMCAL cells in a cluster;cell ID;E (GeV)",15000,-0.5,14999.5,600,0,30);
276   fOutputList->Add(fHistoCalCell);
277
278   fHistoCalTime = new TH2F("fHistoCalTime","Cluster Time;  p_{T} (GeV/c); Time (s)",300,0,30,1000,1e-8,1e-5);
279   fOutputList->Add(fHistoCalTime);
280
281   fHistoCalCellTime = new TH2F("fHistoCalCellTime","Cell Time;  ID; Time (s)",15000,-0.5,14999.5,1000,1e-8,1e-5);
282   fOutputList->Add(fHistoCalCellTime);
283
284   fNegTrkIDPt = new TH1F("fNegTrkIDPt", "p_{T} distribution of tracks with negative track id;p_{T} (GeV/c);counts", 500, 0.0, 50.0); 
285   fOutputList->Add(fNegTrkIDPt);
286
287   fTrkPt = new TH1F("fTrkPt","p_{T} distribution of all tracks;p_{T} (GeV/c);counts",1000,0,100);
288   fOutputList->Add(fTrkPt);
289
290   fTrketa = new TH1F("fTrketa","All Track #eta distribution;#eta;counts",100,-1.5,1.5);
291   fOutputList->Add(fTrketa);
292
293   fTrkphi = new TH1F("fTrkphi","All Track #phi distribution;#phi;counts",100,0,6.3);
294   fOutputList->Add(fTrkphi);
295
296   fdEdx = new TH2F("fdEdx","All Track dE/dx distribution;p (GeV/c);dE/dx",200,0,20,500,0,160);
297   fOutputList->Add(fdEdx);
298
299   fTPCNpts = new TH2F("fTPCNpts","All track TPC Npoints used for dE/dx calculation;p (GeV/c);N points",200,0,20,200,0.,200.);
300   fOutputList->Add(fTPCNpts);
301
302   fTPCnsig = new TH2F("fTPCnsig","All Track TPC Nsigma distribution;p (GeV/c);#sigma_{TPC-dE/dx}",1000,0,50,200,-10,10);
303   fOutputList->Add(fTPCnsig);
304
305   fHistPtMatch = new TH1F("fHistPtMatch", "p_{T} distribution of tracks matched to EMCAL;p_{T} (GeV/c);counts",1000, 0.0, 100.0);
306   fOutputList->Add(fHistPtMatch);                                      
307
308   fEMCTrkMatch = new TH2F("fEMCTrkMatch","Distance of EMCAL cluster to its closest track;#phi;z",100,-0.3,0.3,100,-0.3,0.3);
309   fOutputList->Add(fEMCTrkMatch);
310
311   fEMCTrkPt = new TH1F("fEMCTrkPt","p_{T} distribution of tracks with EMCAL cluster;p_{T} (GeV/c);counts",1000,0,100);
312   fOutputList->Add(fEMCTrkPt);
313
314   fEMCTrketa = new TH1F("fEMCTrketa","#eta distribution of tracks matched to EMCAL;#eta;counts",100,-1.5,1.5);
315   fOutputList->Add(fEMCTrketa);
316
317   fEMCTrkphi = new TH1F("fEMCTrkphi","#phi distribution of tracks matched to EMCAL;#phi;counts",100,0,6.3);
318   fOutputList->Add(fEMCTrkphi);
319
320   fEMCdEdx = new TH2F("fEMCdEdx","dE/dx distribution of tracks matched to EMCAL;p (GeV/c);dE/dx",200,0,20,500,0,160);
321   fOutputList->Add(fEMCdEdx);
322
323   fEMCTPCnsig = new TH2F("fEMCTPCnsig","TPC Nsigma distribution of tracks matched to EMCAL;p (GeV/c);#sigma_{TPC-dE/dx}",1000,0,50,200,-10,10);
324   fOutputList->Add(fEMCTPCnsig);
325
326   fEMCTPCNpts = new TH2F("fEMCTPCNpts","TPC Npoints used for dE/dx for tracks matched to EMCAL;p (GeV/c);N points",200,0,20,200,0.,200.);
327   fOutputList->Add(fEMCTPCNpts);
328
329   fClsEAftMatch = new TH1F("fClsEAftMatch", "EMCAL cluster energy distribution after track matching; Cluster E;counts", 500, 0.0, 50.0);
330   fOutputList->Add(fClsEAftMatch);
331
332   fHistEop = new TH2F("fHistEop", "E/p distribution;p_{T} (GeV/c);E/p", 200,0,20,60, 0.0, 3.0);
333   fOutputList->Add(fHistEop);
334
335   fHistdEdxEop = new TH2F("fHistdEdxEop", "E/p vs dE/dx;E/p;dE/dx", 60, 0.0, 3.0, 500,0,160);
336   fOutputList->Add(fHistdEdxEop);
337
338   fHistNsigEop = new TH2F ("fHistNsigEop", "E/p vs TPC nsig",60, 0.0, 3.0, 200, -10,10);
339   fOutputList->Add(fHistNsigEop);
340
341   fM20 = new TH2F ("fM20","M20 vs pt distribution",200,0,20,400,0,2);
342   fOutputList->Add(fM20);
343
344   fM02 = new TH2F ("fM02","M02 vs pt distribution",200,0,20,400,0,2);
345   fOutputList->Add(fM02);
346
347   fM20EovP = new TH2F ("fM20EovP","M20 vs E/p distribution",400,0,3,400,0,2);
348   fOutputList->Add(fM20EovP);
349
350   fM02EovP = new TH2F ("fM02EovP","M02 vs E/p distribution",400,0,3,400,0,2);
351   fOutputList->Add(fM02EovP);
352
353   fEleCanTPCNpts = new TH2F("fEleCanTPCNpts","TPC Npoints used for dE/dx for electron candidates;p_{T} (GeV/c);N points",200,0,20,200,0,200);
354   fOutputList->Add(fEleCanTPCNpts);
355
356   fEleCanTPCNCls = new TH2F("fEleCanTPCNCls","TPC N clusters for electron candidates;p_{T} (GeV/c);N TPC clusters",200,0,20,171,-0.5,170.5);
357   fOutputList->Add(fEleCanTPCNCls);
358
359   fEleCanITSNCls = new TH2F("fEleCanITSNCls","ITS N clusters for electron candidates;p_{T} (GeV/c);N ITS clusters",200,0,20,8,-0.5,7.5);
360   fOutputList->Add(fEleCanITSNCls);
361
362   fEleCanITShit = new TH1F("fEleCanITShit","ITS hit map;ITS layer;counts",7,-0.5,6.5);
363   fOutputList->Add(fEleCanITShit);
364
365   fEleCanSPD1 = new TH2F("fEleCanSPD1","Hit on SPD layer 1;p_{T} (GeV/c);Hit",200,0,20,1,0,1);
366   fOutputList->Add(fEleCanSPD1);
367
368   fEleCanSPD2 = new TH2F("fEleCanSPD2","Hit on SPD layer 2;p_{T} (GeV/c);Hit",200,0,20,1,0,1);
369   fOutputList->Add(fEleCanSPD2);
370
371   fEleCanSPDBoth = new TH2F("fEleCanSPDBoth","Tracks with hits on both SPD layer;p_{T} (GeV/c);Hit",200,0,20,1,0,1);
372   fOutputList->Add(fEleCanSPDBoth);
373
374   fEleCanSPDOr = new TH2F("fEleCanSPDOr","Tracks with hits on both SPD layer;p_{T} (GeV/c);Hit",200,0,20,1,0,1);
375   fOutputList->Add(fEleCanSPDOr);
376
377   Int_t bins[6]={8,500,200,400,400,400}; //trigger, pt, TPCnsig, E/p, M20, M02
378   Double_t xmin[6]={-0.5,0,-10,0,0,0};
379   Double_t xmax[6]={7.5,25,10,2,2,2};
380   fSparseElectron = new THnSparseD ("Electron","Electron",6,bins,xmin,xmax);
381   fOutputList->Add(fSparseElectron);
382
383   PostData(1,fOutputList);
384 }
385
386 //________________________________________________________________________
387 void AliAnalysisTaskHFEemcQA::UserExec(Option_t *) 
388 {
389   // Main loop
390   // Called for each event
391   // Post output data.
392
393   UInt_t evSelMask=((AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()))->IsEventSelected();
394
395   fVevent = dynamic_cast<AliVEvent*>(InputEvent());
396   if (!fVevent) {
397     printf("ERROR: fVEvent not available\n");
398     return;
399   }
400
401   fESD = dynamic_cast<AliESDEvent*>(InputEvent());
402   if (fESD) {
403     //   printf("fESD available\n");
404     //return;
405   }
406
407   //////////////
408   //if Tender //
409   //////////////
410   if(fUseTender){
411     //new branches with calibrated tracks and clusters
412     if(IsAODanalysis()) fTracks_tender = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject("AODFilterTracks"));
413     if(!IsAODanalysis()) fTracks_tender = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject("ESDFilterTracks"));
414
415     fCaloClusters_tender = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject("EmcCaloClusters"));
416   }
417
418   ////////////////////
419   //cuts initialised//
420   ///////////////////
421   AliESDtrackCuts* esdTrackCutsH = AliESDtrackCuts::GetStandardITSTPCTrackCuts2011(kFALSE);
422   esdTrackCutsH->SetMaxDCAToVertexXY(2.4);
423   esdTrackCutsH->SetMaxDCAToVertexZ(3.2);
424   esdTrackCutsH->SetDCAToVertex2D(kTRUE);
425
426   fAOD = dynamic_cast<AliAODEvent*>(InputEvent());
427   if (fAOD) {
428     // printf("fAOD available\n");
429     //return;
430   }
431
432   ///////////////////
433   //PID initialised//
434   //////////////////
435   fpidResponse = fInputHandler->GetPIDResponse();
436
437   ////////////////
438   //Event vertex//
439   ///////////////
440   Int_t ntracks = -999;
441   if(!fUseTender)ntracks = fVevent->GetNumberOfTracks();
442   if(fUseTender) ntracks = fTracks_tender->GetEntries();
443   if(ntracks < 1) printf("There are %d tracks in this event\n",ntracks);
444
445   fNevents->Fill(0); //all events
446   Double_t Zvertex = -100, Xvertex = -100, Yvertex = -100;
447   const AliVVertex *pVtx = fVevent->GetPrimaryVertex();
448   Double_t NcontV = pVtx->GetNContributors();
449   if(NcontV<2)return;
450   fNevents->Fill(1); //events with 2 tracks
451
452   Zvertex = pVtx->GetZ();  
453   Yvertex = pVtx->GetY();  
454   Xvertex = pVtx->GetX();  
455   fVtxZ->Fill(Zvertex);
456   fVtxX->Fill(Xvertex);
457   fVtxY->Fill(Yvertex);
458
459   /////////////////
460   //trigger check//
461   /////////////////
462   TString firedTrigger;
463   TString TriggerEG1("EG1");
464   TString TriggerEG2("EG2");
465   fVevent->GetFiredTriggerClasses();
466
467   Bool_t EG1tr = kFALSE;
468   Bool_t EG2tr = kFALSE;
469
470   if(firedTrigger.Contains(TriggerEG1))EG1tr = kTRUE;
471   if(firedTrigger.Contains(TriggerEG2))EG2tr = kTRUE;
472
473   Int_t trigger = -1;
474   if (fAOD){
475     //Double_t multiplicity=fAOD->GetHeader()->GetRefMultiplicity();
476     AliAODHeader *header = dynamic_cast<AliAODHeader*>(fAOD->GetHeader());
477     if(!header) AliFatal("Not a standard AOD");
478     Double_t multiplicity = header->GetRefMultiplicity();
479
480     fTrigMulti->Fill(-0.5, multiplicity);
481     if(evSelMask & AliVEvent::kAny) fTrigMulti->Fill(0.5, multiplicity);
482     if(evSelMask & AliVEvent::kMB) fTrigMulti->Fill(1.5, multiplicity);
483     if(evSelMask & AliVEvent::kINT7) fTrigMulti->Fill(2.5, multiplicity);
484     if(evSelMask & AliVEvent::kINT8) fTrigMulti->Fill(3.5, multiplicity);
485     if(evSelMask & AliVEvent::kEMC1) fTrigMulti->Fill(4.5, multiplicity);
486     if(evSelMask & AliVEvent::kEMC7) fTrigMulti->Fill(5.5, multiplicity);
487     if(evSelMask & AliVEvent::kEMC8) fTrigMulti->Fill(6.5, multiplicity);
488     if(evSelMask & AliVEvent::kEMCEJE) fTrigMulti->Fill(7.5, multiplicity);
489     if(evSelMask & AliVEvent::kEMCEGA) fTrigMulti->Fill(8.5, multiplicity);
490     if(evSelMask & AliVEvent::kEMCEGA & EG2tr) fTrigMulti->Fill(9.5, multiplicity);
491
492     if(evSelMask & AliVEvent::kMB) trigger =0;
493     if(evSelMask & AliVEvent::kINT7) trigger =1;
494     if(evSelMask & AliVEvent::kINT8) trigger =2;
495     if(evSelMask & AliVEvent::kEMC1) trigger =3;
496     if(evSelMask & AliVEvent::kEMC7) trigger =4;
497     if(evSelMask & AliVEvent::kEMC8) trigger =5;
498     if(evSelMask & AliVEvent::kEMCEJE) trigger =6;
499     if(evSelMask & AliVEvent::kEMCEGA) trigger =7;
500   }
501
502   ////////////////////
503   //event selection//
504   ///////////////////
505   if(fabs(Zvertex>10.0))return; 
506   fNevents->Fill(2); //events after z vtx cut
507
508   /////////////////////////////
509   //EMCAL cluster information//
510   ////////////////////////////
511   Int_t Nclust = -999;
512   if(!fUseTender) Nclust = fVevent->GetNumberOfCaloClusters();
513   if(fUseTender) Nclust = fCaloClusters_tender->GetEntries();
514
515   int NclustAll= 0;
516   int NclustE1 = 0; //# of clust E>0.1
517   int NclustE2 = 0; //# of clust E>0.2
518   int NclustE3 = 0; //# of clust E>0.5
519
520   for(Int_t icl=0; icl<Nclust; icl++)
521   {
522     AliVCluster *clust = 0x0;
523     if(!fUseTender) clust = fVevent->GetCaloCluster(icl);
524     if(fUseTender) clust = dynamic_cast<AliVCluster*>(fCaloClusters_tender->At(icl));
525     if(!clust)  printf("ERROR: Could not receive cluster matched calibrated from track %d\n", icl);
526
527     if(clust && clust->IsEMCAL())
528     {
529       Double_t clustE = clust->E();
530       Float_t  emcx[3]; // cluster pos
531       clust->GetPosition(emcx);
532       TVector3 clustpos(emcx[0],emcx[1],emcx[2]);
533       Double_t emcphi = clustpos.Phi(); 
534       Double_t emceta = clustpos.Eta();
535       fHistClustE->Fill(clustE);
536       fEMCClsEtaPhi->Fill(emceta,emcphi);
537       fHistoNCells->Fill(clustE,clust->GetNCells());
538       //fHistoNCells->Fill(clust->GetNCells());
539     
540       double emctof = clust->GetTOF();
541       fHistoCalTime->Fill(clustE,emctof);
542
543       NclustAll++;  
544       if(clustE>0.1)NclustE1++;
545       if(clustE>0.2)NclustE2++;
546       if(clustE>0.5)NclustE3++;
547     }
548   }
549
550   fHistoNCls->Fill(NclustAll);
551   fHistoNClsE1->Fill(NclustE1);
552   fHistoNClsE2->Fill(NclustE2);
553   fHistoNClsE3->Fill(NclustE3);
554
555   // cell information
556   AliVCaloCells *fCaloCells = fVevent->GetEMCALCells();
557
558   //Int_t nSACell, iSACell, mclabel;
559   Short_t cellAddr, nSACell;
560   Int_t  mclabel;
561   Short_t iSACell;
562   Double_t cellAmp=-1., cellTimeT=-1., efrac=-1.;
563
564   nSACell = fCaloCells->GetNumberOfCells();
565   for(iSACell = 0; iSACell < nSACell; iSACell++ ){ 
566     Bool_t haveCell = fCaloCells->GetCell(iSACell, cellAddr, cellAmp, cellTimeT , mclabel, efrac);
567     //virtual Bool_t   GetCell(Short_t pos, Short_t &cellNumber, Double_t &amplitude, Double_t &time, Int_t &mclabel,    Double_t  &efrac)      
568     if(haveCell)
569        {
570         fHistoCalCell->Fill(cellAddr,cellAmp);
571         fHistoCalCellTime->Fill(cellAddr,cellTimeT);
572         }
573   }
574
575   /////////////////////////////////
576   //Look for kink mother for AOD//
577   /////////////////////////////////
578   Int_t numberofvertices = 100;
579   if(fAOD) numberofvertices = fAOD->GetNumberOfVertices();
580   Double_t listofmotherkink[numberofvertices];
581   Int_t numberofmotherkink = 0;
582   if(IsAODanalysis())
583   {
584     for(Int_t ivertex=0; ivertex < numberofvertices; ivertex++) {
585       AliAODVertex *aodvertex = fAOD->GetVertex(ivertex);
586       if(!aodvertex) continue;
587       if(aodvertex->GetType()==AliAODVertex::kKink) {
588         AliAODTrack *mother = (AliAODTrack *) aodvertex->GetParent();
589         if(!mother) continue;
590         Int_t idmother = mother->GetID();
591         listofmotherkink[numberofmotherkink] = idmother;
592         numberofmotherkink++;
593       }
594     }
595   } //+++
596
597
598   ///////////////
599   //Track loop///
600   ///////////////
601   for (Int_t iTracks = 0; iTracks < ntracks; iTracks++) {
602
603     AliVParticle* Vtrack = 0x0;
604     if(!fUseTender) Vtrack  = fVevent->GetTrack(iTracks);
605     if(fUseTender) Vtrack = dynamic_cast<AliVTrack*>(fTracks_tender->At(iTracks));
606
607     if (!Vtrack) {
608       printf("ERROR: Could not receive track %d\n", iTracks);
609       continue;
610     }
611     AliVTrack *track = dynamic_cast<AliVTrack*>(Vtrack);
612     AliESDtrack *etrack = dynamic_cast<AliESDtrack*>(Vtrack);
613     AliAODTrack *atrack = dynamic_cast<AliAODTrack*>(Vtrack);
614
615     ////////////////////
616     //Apply track cuts//
617     ////////////////////
618     if(fAOD)
619       if(!atrack->TestFilterMask(AliAODTrack::kTrkGlobalNoDCA)) continue; //mimimum cuts
620
621     if(fESD)
622       if(!esdTrackCutsH->AcceptTrack(etrack))continue;
623
624     //reject kink
625     if(IsAODanalysis()){
626       Bool_t kinkmotherpass = kTRUE;
627       for(Int_t kinkmother = 0; kinkmother < numberofmotherkink; kinkmother++) {
628         if(track->GetID() == listofmotherkink[kinkmother]) {
629           kinkmotherpass = kFALSE;
630           continue;
631         }
632       }
633       if(!kinkmotherpass) continue;
634     }
635     else{
636       if(etrack->GetKinkIndex(0) != 0) continue;
637     }
638
639     ////////////////////
640     //Track properties//
641     ///////////////////
642     Double_t dEdx =-999, fTPCnSigma=-999;
643     dEdx = track->GetTPCsignal();
644     fTPCnSigma = fpidResponse->NumberOfSigmasTPC(track, AliPID::kElectron);
645
646     if(track->GetID()<0) fNegTrkIDPt->Fill(track->Pt());
647     fTrkPt->Fill(track->Pt());
648     fTrketa->Fill(track->Eta());
649     fTrkphi->Fill(track->Phi());
650     fdEdx->Fill(track->P(),dEdx);
651     fTPCNpts->Fill(track->P(),track->GetTPCsignalN());
652     fTPCnsig->Fill(track->P(),fTPCnSigma);
653
654     ///////////////////////////
655     //Track matching to EMCAL//
656     //////////////////////////
657     Int_t EMCalIndex = -1;
658     EMCalIndex = track->GetEMCALcluster();
659     if(EMCalIndex < 0) continue;
660     fHistPtMatch->Fill(track->Pt());
661
662     AliVCluster *clustMatch=0x0;
663     if(!fUseTender) clustMatch = (AliVCluster*)fVevent->GetCaloCluster(EMCalIndex);
664     if(fUseTender) clustMatch = dynamic_cast<AliVCluster*>(fCaloClusters_tender->At(EMCalIndex));
665
666     if(clustMatch && clustMatch->IsEMCAL())
667     {
668       /////////////////////////////////////////////
669       //Properties of tracks matched to the EMCAL//
670       /////////////////////////////////////////////
671       fEMCTrkMatch->Fill(clustMatch->GetTrackDx(),clustMatch->GetTrackDz());
672       if(TMath::Abs(clustMatch->GetTrackDx())>0.05 || TMath::Abs(clustMatch->GetTrackDz())>0.05) continue;
673
674       fEMCTrkPt->Fill(track->Pt());
675       fEMCTrketa->Fill(track->Eta());
676       fEMCTrkphi->Fill(track->Phi());
677       fEMCdEdx->Fill(track->P(),dEdx);
678       fEMCTPCnsig->Fill(track->P(),fTPCnSigma);
679       fEMCTPCNpts->Fill(track->P(),track->GetTPCsignalN());
680
681       Double_t clustMatchE = clustMatch->E();
682       fClsEAftMatch->Fill(clustMatchE);
683
684       //EMCAL EID info
685       Double_t eop = -1.0;
686       Double_t m02 = -99999;
687       if(track->P()>0)eop = clustMatchE/track->P();
688       m02 =clustMatch->GetM02();
689
690       if(track->Pt()>1.0){
691         fHistdEdxEop->Fill(eop,dEdx);
692         fHistNsigEop->Fill(eop,fTPCnSigma);
693         fM20EovP->Fill(eop,clustMatch->GetM20());
694         fM02EovP->Fill(eop,clustMatch->GetM02());
695       }
696
697       fHistEop->Fill(track->Pt(),eop);
698       fM20->Fill(track->Pt(),clustMatch->GetM20());
699       fM02->Fill(track->Pt(),clustMatch->GetM02());
700
701       //EID THnsparse
702       fvalueElectron[0] = trigger;
703       fvalueElectron[1] = track->Pt();
704       fvalueElectron[2] = fTPCnSigma;
705       fvalueElectron[3] = eop;
706       fvalueElectron[4] = clustMatch->GetM20();
707       fvalueElectron[5] = clustMatch->GetM02();
708
709       if(fFlagSparse){
710         //cout << "filling sparse"<<endl;
711         fSparseElectron->Fill(fvalueElectron);
712       }
713
714       ////////////////////////////////////////////////
715       //Track properties of EMCAL electron cadidates//
716       ///////////////////////////////////////////////
717       if(fTPCnSigma > -1 && fTPCnSigma < 3 && eop>0.9 && eop<1.2 && m02 > 0.006 && m02 < 0.35){
718         fEleCanTPCNpts->Fill(track->Pt(),track->GetTPCsignalN());
719         fEleCanTPCNCls->Fill(track->Pt(),track->GetTPCNcls());
720
721         Int_t fITSncls=0;
722         for(Int_t l=0;l<6;l++) {
723           if(TESTBIT(track->GetITSClusterMap(),l)) {
724             fEleCanITShit->Fill(l);
725             if(l==0) fEleCanSPD1->Fill(track->Pt(),0.5);
726             if(l==1) fEleCanSPD2->Fill(track->Pt(),0.5);
727             if(l==0 && l==1) fEleCanSPDBoth->Fill(track->Pt(),0.5);
728             if(l==0 || l==1) fEleCanSPDOr->Fill(track->Pt(),0.5);
729             fITSncls++;
730           }
731         }
732         fEleCanITSNCls->Fill(track->Pt(),fITSncls++);
733       }
734     }
735   } //track loop 
736
737   PostData(1, fOutputList);
738 }      
739 //________________________________________________________________________
740 void AliAnalysisTaskHFEemcQA::Terminate(Option_t *) 
741 {
742   // Draw result to the screen
743   // Called once at the end of the query
744
745   fOutputList = dynamic_cast<TList*> (GetOutputData(1));
746   if (!fOutputList) {
747     printf("ERROR: Output list not available\n");
748     return;
749   }
750
751 }