]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG/CaloTrackCorrBase/AliCaloTrackReader.cxx
Initialize PHOS and EMCAL in AliAnaCalorimeterUtils and geometry matrices during...
[u/mrichter/AliRoot.git] / PWG / CaloTrackCorrBase / AliCaloTrackReader.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 // Base class for reading data: MonteCarlo, ESD or AOD, of PHOS EMCAL and 
18 // Central Barrel Tracking detectors (CTS).
19 // Not all MC particles/tracks/clusters are kept, some kinematical/fiducial restrictions are done.
20 // Mother class of : AliCaloTrackESDReader: Fills ESD data in 3 TObjArrays (PHOS, EMCAL, CTS)
21 //                 : AliCaloTrackMCReader : Fills Kinematics data in 3 TObjArrays (PHOS, EMCAL, CTS)
22 //                 : AliCaloTrackAODReader: Fills AOD data in 3 TObjArrays (PHOS, EMCAL, CTS) 
23 //-- Author: Gustavo Conesa (LNF-INFN) 
24 //////////////////////////////////////////////////////////////////////////////
25
26
27 // --- ROOT system ---
28 #include <TFile.h>
29 #include <TGeoManager.h>
30
31 // ---- ANALYSIS system ----
32 #include "AliMCEvent.h"
33 #include "AliAODMCHeader.h"
34 #include "AliGenPythiaEventHeader.h"
35 #include "AliESDEvent.h"
36 #include "AliAODEvent.h"
37 #include "AliVTrack.h"
38 #include "AliVParticle.h"
39 #include "AliMixedEvent.h"
40 #include "AliESDtrack.h"
41 #include "AliESDtrackCuts.h"
42 #include "AliTriggerAnalysis.h"
43 #include "AliESDVZERO.h"
44 #include "AliVCaloCells.h"
45
46 // ---- Detectors ----
47 #include "AliPHOSGeoUtils.h"
48 #include "AliEMCALGeometry.h"
49 #include "AliEMCALRecoUtils.h"
50
51 // ---- CaloTrackCorr ---
52 #include "AliCalorimeterUtils.h"
53 #include "AliCaloTrackReader.h"
54
55 ClassImp(AliCaloTrackReader)
56   
57   
58 //________________________________________
59 AliCaloTrackReader::AliCaloTrackReader() : 
60 TObject(),                   fEventNumber(-1), //fCurrentFileName(""),
61 fDataType(0),                fDebug(0), 
62 fFiducialCut(0x0),           fCheckFidCut(kFALSE), 
63 fComparePtHardAndJetPt(0),   fPtHardAndJetPtFactor(0),
64 fCTSPtMin(0),                fEMCALPtMin(0),                  fPHOSPtMin(0), 
65 fCTSPtMax(0),                fEMCALPtMax(0),                  fPHOSPtMax(0), 
66 fAODBranchList(0x0),
67 fCTSTracks(0x0),             fEMCALClusters(0x0),             fPHOSClusters(0x0),
68 fEMCALCells(0x0),            fPHOSCells(0x0),
69 fInputEvent(0x0),            fOutputEvent(0x0),fMC(0x0),
70 fFillCTS(0),                 fFillEMCAL(0),                   fFillPHOS(0),
71 fFillEMCALCells(0),          fFillPHOSCells(0), 
72 fRecalculateClusters(kFALSE),fSelectEmbeddedClusters(kFALSE),
73 fTrackStatus(0),             fTrackFilterMask(0),             fESDtrackCuts(0), 
74 fTrackMult(0),               fTrackMultEtaCut(0.8),
75 fReadStack(kFALSE),          fReadAODMCParticles(kFALSE), 
76 fDeltaAODFileName(""),       fFiredTriggerClassName(""),      fAnaLED(kFALSE),
77 fTaskName(""),               fCaloUtils(0x0), 
78 fMixedEvent(NULL),           fNMixedEvent(0),                 fVertex(NULL), 
79 fWriteOutputDeltaAOD(kFALSE),fOldAOD(kFALSE),                 fCaloFilterPatch(kFALSE),
80 fEMCALClustersListName(""),  fZvtxCut(0.),                    
81 fAcceptFastCluster(kFALSE),  fRemoveLEDEvents(kTRUE), 
82 fDoEventSelection(kFALSE),   fDoV0ANDEventSelection(kFALSE),  fUseEventsWithPrimaryVertex(kFALSE),
83 fTriggerAnalysis (0x0), 
84 fCentralityClass(""),        fCentralityOpt(0),
85 fEventPlaneMethod(""),       fImportGeometryFromFile(kFALSE), fImportGeometryFilePath("")
86
87 {
88   //Ctor
89
90   //Initialize parameters
91   InitParameters();
92 }
93
94 //_______________________________________
95 AliCaloTrackReader::~AliCaloTrackReader() 
96 {
97   //Dtor
98   
99   delete fFiducialCut ;
100         
101   if(fAODBranchList){
102     fAODBranchList->Delete();
103     delete fAODBranchList ;
104   }  
105   
106   if(fCTSTracks){
107     if(fDataType!=kMC)fCTSTracks->Clear() ; 
108     else              fCTSTracks->Delete() ; 
109     delete fCTSTracks ;
110   }
111   
112   if(fEMCALClusters){
113     if(fDataType!=kMC)fEMCALClusters->Clear("C") ; 
114     else              fEMCALClusters->Delete() ; 
115     delete fEMCALClusters ;
116   }
117   
118   if(fPHOSClusters){
119     if(fDataType!=kMC)fPHOSClusters->Clear("C") ; 
120     else              fPHOSClusters->Delete() ; 
121     delete fPHOSClusters ;
122   }
123   
124   if(fVertex){
125     for (Int_t i = 0; i < fNMixedEvent; i++) {
126       delete [] fVertex[i] ;
127       
128     }
129     delete [] fVertex ;
130         }
131   
132   delete fESDtrackCuts;
133   delete fTriggerAnalysis;
134   
135   //  Pointers not owned, done by the analysis frame
136   //  if(fInputEvent)  delete fInputEvent ;
137   //  if(fOutputEvent) delete fOutputEvent ;
138   //  if(fMC)          delete fMC ;  
139   //  Pointer not owned, deleted by maker
140   //  if (fCaloUtils) delete fCaloUtils ;
141   
142 }
143
144 //________________________________________________
145 Bool_t AliCaloTrackReader::ComparePtHardAndJetPt()
146 {
147   // Check the event, if the requested ptHard is much larger than the jet pT, then there is a problem.
148   // Only for PYTHIA.
149   if(!fReadStack) return kTRUE; //Information not filtered to AOD
150   
151   if(!strcmp(GetGenEventHeader()->ClassName(), "AliGenPythiaEventHeader")){
152     TParticle * jet =  0;
153     AliGenPythiaEventHeader* pygeh= (AliGenPythiaEventHeader*) GetGenEventHeader();
154     Int_t nTriggerJets =  pygeh->NTriggerJets();
155     Float_t ptHard = pygeh->GetPtHard();
156     
157     //if(fDebug > 1) printf("AliMCAnalysisUtils::PythiaEventHeader: Njets: %d, pT Hard %f\n",nTriggerJets, ptHard);
158     Float_t tmpjet[]={0,0,0,0};
159     for(Int_t ijet = 0; ijet< nTriggerJets; ijet++){
160       pygeh->TriggerJet(ijet, tmpjet);
161       jet = new TParticle(94, 21, -1, -1, -1, -1, tmpjet[0],tmpjet[1],tmpjet[2],tmpjet[3], 0,0,0,0);
162       //Compare jet pT and pt Hard
163       //if(fDebug > 1) printf("AliMCAnalysisUtils:: %d pycell jet pT %f\n",ijet, jet->Pt());
164       if(jet->Pt() > fPtHardAndJetPtFactor * ptHard) {
165         printf("AliMCAnalysisUtils::PythiaEventHeader: Njets: %d, pT Hard %2.2f, pycell jet pT %2.2f, rejection factor %1.1f\n",
166                nTriggerJets, ptHard, jet->Pt(), fPtHardAndJetPtFactor);
167         return kFALSE;
168       }
169     }
170     if(jet) delete jet; 
171   }
172   
173   return kTRUE ;
174   
175 }
176
177 //____________________________________________
178 AliStack* AliCaloTrackReader::GetStack() const 
179 {
180   //Return pointer to stack
181   if(fMC)
182     return fMC->Stack();
183   else{
184     if(fDebug > 1) printf("AliCaloTrackReader::GetStack() - Stack is not available\n"); 
185     return 0x0 ;
186   }
187 }
188
189 //__________________________________________________
190 TString AliCaloTrackReader::GetFiredTriggerClasses() 
191
192   // List of triggered classes in a TString
193
194   AliESDEvent* esdevent = dynamic_cast<AliESDEvent*> (GetInputEvent());
195   AliAODEvent* aodevent = dynamic_cast<AliAODEvent*> (GetInputEvent());
196     
197   if     (esdevent) return esdevent->GetFiredTriggerClasses();
198   else if(aodevent) return aodevent->GetFiredTriggerClasses();
199   else              return ""; // Mixed Event, MC event, does not have this trigger info
200
201 }
202
203 //______________________________________________
204 AliHeader* AliCaloTrackReader::GetHeader() const 
205 {
206   //Return pointer to header
207   if(fMC)
208     return fMC->Header();
209   else{
210     printf("AliCaloTrackReader::Header is not available\n"); 
211     return 0x0 ;
212   }
213 }
214
215 //______________________________________________________________
216 AliGenEventHeader* AliCaloTrackReader::GetGenEventHeader() const 
217 {
218   //Return pointer to Generated event header
219   if(fMC)
220     return fMC->GenEventHeader();
221   else{
222     printf("AliCaloTrackReader::GenEventHeader is not available\n"); 
223     return 0x0 ;
224   }
225 }
226
227 //____________________________________________________________________
228 TClonesArray* AliCaloTrackReader::GetAODMCParticles(Int_t input) const 
229 {
230   //Return list of particles in AOD. Do it for the corresponding input event.
231   
232   TClonesArray * rv = NULL ; 
233   if(fDataType == kAOD){
234     
235     if(input == 0){
236       //Normal input AOD
237       AliAODEvent * evt = dynamic_cast<AliAODEvent*> (fInputEvent) ;
238       if(evt)
239         rv = (TClonesArray*)evt->FindListObject("mcparticles");
240       else  
241         printf("AliCaloTrackReader::GetAODMCParticles() - wrong AOD input index? %d, or non existing tree? \n",input); 
242       
243     }  
244     
245   } else {
246     printf("AliCaloTrackReader::GetAODMCParticles() - Input are not AODs\n"); 
247   }
248   
249   return rv ; 
250 }
251
252 //___________________________________________________________________
253 AliAODMCHeader* AliCaloTrackReader::GetAODMCHeader(Int_t input) const 
254 {
255   //Return MC header in AOD. Do it for the corresponding input event.
256   AliAODMCHeader *mch = NULL;
257   if(fDataType == kAOD){
258     //Normal input AOD
259     if(input == 0) {
260       mch = (AliAODMCHeader*)((AliAODEvent*)fInputEvent)->FindListObject("mcheader");
261     }
262     //          //Second input AOD
263     //          else if(input == 1){ 
264     //       mch = (AliAODMCHeader*) fSecondInputAODEvent->FindListObject("mcheader");
265     //  }
266     else {
267       printf("AliCaloTrackReader::GetAODMCHeader() - wrong AOD input index, %d\n",input);
268     }
269   }
270   else {
271     printf("AliCaloTrackReader::GetAODMCHeader() - Input are not AODs\n");
272   }
273   
274   return mch;
275 }
276
277 //_____________________________
278 void AliCaloTrackReader::Init()
279 {
280   //Init reader. Method to be called in AliAnaPartCorrMaker
281
282   //printf(" AliCaloTrackReader::Init() %p \n",gGeoManager);
283
284   if(fReadStack && fReadAODMCParticles)
285   {
286     printf("AliCaloTrackReader::Init() - Cannot access stack and mcparticles at the same time, change them \n");
287     fReadStack          = kFALSE;
288     fReadAODMCParticles = kFALSE;
289   }
290   
291   // Init geometry, I do not like much to do it like this ...
292   if(fImportGeometryFromFile && !gGeoManager) 
293   {
294     printf("AliCaloTrackReader::Init() - Import %s\n",fImportGeometryFilePath.Data());
295     TGeoManager::Import(fImportGeometryFilePath) ; // default need file "geometry.root" in local dir!!!!
296   }
297
298 }
299
300 //_______________________________________
301 void AliCaloTrackReader::InitParameters()
302 {
303   //Initialize the parameters of the analysis.
304   fDataType   = kESD ;
305   fCTSPtMin   = 0.1 ;
306   fEMCALPtMin = 0.1 ;
307   fPHOSPtMin  = 0.1 ;
308   fCTSPtMax   = 1000. ;
309   fEMCALPtMax = 1000. ;
310   fPHOSPtMax  = 1000. ;
311   
312   //Do not filter the detectors input by default.
313   fFillEMCAL      = kFALSE;
314   fFillPHOS       = kFALSE;
315   fFillCTS        = kFALSE;
316   fFillEMCALCells = kFALSE;
317   fFillPHOSCells  = kFALSE;
318   
319   fReadStack             = kFALSE; // Check in the constructor of the other readers if it was set or in the configuration file
320   fReadAODMCParticles    = kFALSE; // Check in the constructor of the other readers if it was set or in the configuration file
321   fDeltaAODFileName      = "deltaAODPartCorr.root";
322   fFiredTriggerClassName = "";
323   
324   fAcceptFastCluster = kTRUE;
325   fAnaLED            = kFALSE;
326   
327   //We want tracks fitted in the detectors:
328   //fTrackStatus=AliESDtrack::kTPCrefit;
329   //fTrackStatus|=AliESDtrack::kITSrefit; 
330   fTrackStatus     = 0;
331   fTrackFilterMask = 128; //For AODs, but what is the difference between fTrackStatus and fTrackFilterMask?
332   
333   fESDtrackCuts = AliESDtrackCuts::GetStandardTPCOnlyTrackCuts(); //initialize with TPC only tracks 
334   
335   fV0ADC[0] = 0;   fV0ADC[1] = 0; 
336   fV0Mul[0] = 0;   fV0Mul[1] = 0; 
337   
338   fZvtxCut   = 10.;
339   
340   fNMixedEvent = 1;
341   
342   fPtHardAndJetPtFactor = 7;
343   
344   //Centrality
345   fCentralityClass  = "V0M";
346   fCentralityOpt    = 10;
347   fCentralityBin[0] = fCentralityBin[1]=-1;
348   
349   fEventPlaneMethod = "Q";
350
351   // Allocate memory (not sure this is the right place)
352   fCTSTracks       = new TObjArray();
353   fEMCALClusters   = new TObjArray();
354   fPHOSClusters    = new TObjArray(); 
355   fTriggerAnalysis = new AliTriggerAnalysis;
356   fAODBranchList   = new TList ;
357
358   fImportGeometryFromFile = kFALSE;
359   fImportGeometryFilePath = "$ALICE_ROOT/PWGGA/EMCALTasks/macros/geometry.root"; // "$ALICE_ROOT/EVE/alice-data/default_geo.root"
360   
361 }
362
363 //________________________________________________________
364 void AliCaloTrackReader::Print(const Option_t * opt) const
365 {
366   
367   //Print some relevant parameters set for the analysis
368   if(! opt)
369     return;
370   
371   printf("***** Print: %s %s ******\n", GetName(), GetTitle() ) ;
372   printf("Task name      : %s\n", fTaskName.Data()) ;
373   printf("Data type      : %d\n", fDataType) ;
374   printf("CTS Min pT     : %2.1f GeV/c\n", fCTSPtMin) ;
375   printf("EMCAL Min pT   : %2.1f GeV/c\n", fEMCALPtMin) ;
376   printf("PHOS Min pT    : %2.1f GeV/c\n", fPHOSPtMin) ;
377   printf("CTS Max pT     : %2.1f GeV/c\n", fCTSPtMax) ;
378   printf("EMCAL Max pT   : %2.1f GeV/c\n", fEMCALPtMax) ;
379   printf("PHOS Max pT    : %2.1f GeV/c\n", fPHOSPtMax) ;
380   printf("Use CTS         =     %d\n", fFillCTS) ;
381   printf("Use EMCAL       =     %d\n", fFillEMCAL) ;
382   printf("Use PHOS        =     %d\n", fFillPHOS) ;
383   printf("Use EMCAL Cells =     %d\n", fFillEMCALCells) ;
384   printf("Use PHOS  Cells =     %d\n", fFillPHOSCells) ;
385   printf("Track status    =     %d\n", (Int_t) fTrackStatus) ;
386   printf("Track filter mask (AODs) =  %d\n", (Int_t) fTrackFilterMask) ;
387   printf("Track Mult Eta Cut =  %d\n", (Int_t) fTrackMultEtaCut) ;
388   printf("Write delta AOD =     %d\n", fWriteOutputDeltaAOD) ;
389   printf("Recalculate Clusters = %d\n", fRecalculateClusters) ;
390   
391   if(fComparePtHardAndJetPt)
392           printf("Compare jet pt and pt hard to accept event, factor = %2.2f",fPtHardAndJetPtFactor);
393   
394   printf("Read Kine from, stack? %d, AOD ? %d \n", fReadStack, fReadAODMCParticles) ;
395   printf("Delta AOD File Name =     %s\n", fDeltaAODFileName.Data()) ;
396   printf("Centrality: Class %s, Option %d, Bin [%d,%d] \n", fCentralityClass.Data(),fCentralityOpt,fCentralityBin[0], fCentralityBin[1]) ;
397   
398   printf("    \n") ;
399   
400
401
402 //_________________________________________________________________________
403 Bool_t AliCaloTrackReader::FillInputEvent(const Int_t iEntry, 
404                                           const char * /*currentFileName*/) 
405 {
406   //Fill the event counter and input lists that are needed, called by the analysis maker.
407     
408   fEventNumber = iEntry;
409   //fCurrentFileName = TString(currentFileName);
410   if(!fInputEvent)
411   {
412           if(fDebug >= 0) printf("AliCaloTrackReader::FillInputEvent() - Input event not available, skip event analysis\n");
413           return kFALSE;
414   }
415   
416   //Select events only fired by a certain trigger configuration if it is provided
417   Int_t eventType = 0;
418   if(fInputEvent->GetHeader())
419           eventType = ((AliVHeader*)fInputEvent->GetHeader())->GetEventType();
420   
421   if (GetFiredTriggerClasses().Contains("FAST")  && !GetFiredTriggerClasses().Contains("ALL") && !fAcceptFastCluster) 
422   {
423     if(fDebug > 0)  printf("AliCaloTrackReader::FillInputEvent - Do not count events from fast cluster, trigger name %s\n",fFiredTriggerClassName.Data());
424     return kFALSE;
425   }
426   
427   //-------------------------------------------------------------------------------------
428   // Reject event if large clusters with large energy
429   // Use only for LHC11a data for the moment, and if input is clusterizer V1 or V1+unfolding
430   // If clusterzer NxN or V2 it does not help
431   //-------------------------------------------------------------------------------------
432   Int_t run = fInputEvent->GetRunNumber();
433   if( fRemoveLEDEvents && run > 140000  && run <= 146860 )
434   {
435     //printf("Event %d\n",GetEventNumber());
436     for (Int_t i = 0; i < fInputEvent->GetNumberOfCaloClusters(); i++)
437     {
438       AliVCluster *clus = fInputEvent->GetCaloCluster(i);
439       if(clus->IsEMCAL())
440       {               
441         if ((clus->E() > 500 && clus->GetNCells() > 200 ) || clus->GetNCells() > 200) 
442         {
443           Int_t absID = clus->GetCellsAbsId()[0];
444           Int_t sm = GetCaloUtils()->GetEMCALGeometry()->GetSuperModuleNumber(absID);
445           if(fDebug > 0) printf("AliCaloTrackReader::FillInputEvent - reject event %d with cluster : E %f, ncells %d, absId(0) %d, SM %d\n",GetEventNumber(),clus->E(),  clus->GetNCells(),absID, sm);
446           return kFALSE;
447         }
448       }
449     }
450     
451     // Count number of cells with energy larger than 0.1 in SM3, cut on this number
452     Int_t ncellsSM3 = 0;
453     Int_t ncellsSM4 = 0;
454     for(Int_t icell = 0; icell < fInputEvent->GetEMCALCells()->GetNumberOfCells(); icell++)
455     {
456       Int_t absID = fInputEvent->GetEMCALCells()->GetCellNumber(icell);
457       Int_t sm    = GetCaloUtils()->GetEMCALGeometry()->GetSuperModuleNumber(absID);
458       if(fInputEvent->GetEMCALCells()->GetAmplitude(icell) > 0.1 && sm==3) ncellsSM3++;
459       if(fInputEvent->GetEMCALCells()->GetAmplitude(icell) > 0.1 && sm==4) ncellsSM4++;
460     }
461     
462     Int_t ncellcut = 21;
463     if(fFiredTriggerClassName.Contains("EMC")) ncellcut = 35;
464     
465     if(ncellsSM3 >= ncellcut || ncellsSM4 >= 100)
466     {
467       if(fDebug > 0) printf(" AliCaloTrackReader::FillInputEvent() - reject event with ncells in SM3 %d and SM4 %d\n",ncellsSM3, ncellsSM4);
468       return kFALSE;
469     }
470   }// Remove LED events
471   
472   // Reject pure LED events?
473   if( fFiredTriggerClassName  !="" && !fAnaLED)
474   {
475     if(eventType!=7)
476       return kFALSE; //Only physics event, do not use for simulated events!!!
477     if(fDebug > 0) 
478       printf("AliCaloTrackReader::FillInputEvent() - FiredTriggerClass <%s>, selected class <%s>, compare name %d\n",
479              GetFiredTriggerClasses().Data(),fFiredTriggerClassName.Data(), GetFiredTriggerClasses().Contains(fFiredTriggerClassName));
480     if( !GetFiredTriggerClasses().Contains(fFiredTriggerClassName) ) return kFALSE;
481     else if(fDebug > 0) printf("AliCaloTrackReader::FillInputEvent() - Accepted triggered event\n");
482   }
483   else if(fAnaLED)
484   {
485     //    kStartOfRun =       1,    // START_OF_RUN
486     //    kEndOfRun =         2,    // END_OF_RUN
487     //    kStartOfRunFiles =  3,    // START_OF_RUN_FILES
488     //    kEndOfRunFiles =    4,    // END_OF_RUN_FILES
489     //    kStartOfBurst =     5,    // START_OF_BURST
490     //    kEndOfBurst =       6,    // END_OF_BURST
491     //    kPhysicsEvent =     7,    // PHYSICS_EVENT
492     //    kCalibrationEvent = 8,    // CALIBRATION_EVENT
493     //    kFormatError =      9,    // EVENT_FORMAT_ERROR
494     //    kStartOfData =      10,   // START_OF_DATA
495     //    kEndOfData =        11,   // END_OF_DATA
496     //    kSystemSoftwareTriggerEvent   = 12, // SYSTEM_SOFTWARE_TRIGGER_EVENT
497     //    kDetectorSoftwareTriggerEvent = 13  // DETECTOR_SOFTWARE_TRIGGER_EVENT
498     
499           if(eventType!=7 && fDebug > 1 )printf("AliCaloTrackReader::FillInputEvent() - DO LED, Event Type <%d>, 8 Calibration \n",  eventType);
500           if(eventType!=8)return kFALSE;
501   }
502   
503   //In case of analysis of events with jets, skip those with jet pt > 5 pt hard 
504   if(fComparePtHardAndJetPt && GetStack()) 
505   {
506     if(!ComparePtHardAndJetPt()) return kFALSE ;
507   }
508   
509   //Fill Vertex array
510   FillVertexArray();
511   //Reject events with Z vertex too large, only for SE analysis, if not, cut on the analysis code
512   if(!GetMixedEvent() && TMath::Abs(fVertex[0][2]) > fZvtxCut) return kFALSE;  
513   
514   //------------------------------------------------------
515   //Event rejection depending on vertex, pileup, v0and
516   //------------------------------------------------------
517   if(fDoEventSelection)
518   {
519     if(!fCaloFilterPatch)
520     {
521       //Do not analyze events with pileup
522       Bool_t bPileup = fInputEvent->IsPileupFromSPD(3, 0.8, 3., 2., 5.); //Default values, if not it does not compile
523       //Bool_t bPileup = event->IsPileupFromSPD(); 
524       if(bPileup) return kFALSE;
525       
526       if(fDoV0ANDEventSelection)
527       {
528         Bool_t bV0AND = kTRUE; 
529         AliESDEvent* esd = dynamic_cast<AliESDEvent*> (fInputEvent);
530         if(esd) 
531           bV0AND = fTriggerAnalysis->IsOfflineTriggerFired(esd, AliTriggerAnalysis::kV0AND);
532         //else bV0AND = //FIXME FOR AODs
533         if(!bV0AND) return kFALSE;
534       }
535       
536       if(fUseEventsWithPrimaryVertex && !CheckForPrimaryVertex()) return kFALSE;
537       
538     }//CaloFilter patch
539     else
540     { 
541       if(fInputEvent->GetNumberOfCaloClusters() > 0) 
542       {
543         AliVCluster * calo = fInputEvent->GetCaloCluster(0);
544         if(calo->GetNLabels() == 4){
545           Int_t * selection = calo->GetLabels();
546           Bool_t bPileup = selection[0];
547           if(bPileup) return kFALSE;
548           
549           Bool_t bGoodV = selection[1]; 
550           if(fUseEventsWithPrimaryVertex && !bGoodV) return kFALSE;
551           
552           if(fDoV0ANDEventSelection){
553             Bool_t bV0AND = selection[2]; 
554             if(!bV0AND) return kFALSE;
555           }
556           
557           fTrackMult = selection[3];
558           if(fTrackMult == 0) return kFALSE;
559         } else {
560           //First filtered AODs, track multiplicity stored there.  
561           fTrackMult = (Int_t) ((AliAODHeader*)fInputEvent->GetHeader())->GetCentrality();
562           if(fTrackMult == 0) return kFALSE;          
563         }
564       }//at least one cluster
565       else {
566         //printf("AliCaloTrackReader::FillInputEvent() - No clusters in event\n");
567         //Remove events with  vertex (0,0,0), bad vertex reconstruction
568         if(fUseEventsWithPrimaryVertex && TMath::Abs(fVertex[0][0]) < 1.e-6 && TMath::Abs(fVertex[0][1]) < 1.e-6 && TMath::Abs(fVertex[0][2]) < 1.e-6) return kFALSE;
569         
570         //First filtered AODs, track multiplicity stored there.  
571         fTrackMult = (Int_t) ((AliAODHeader*)fInputEvent->GetHeader())->GetCentrality();
572         if(fTrackMult == 0) return kFALSE;
573       }// no cluster
574     }// CaloFileter patch
575   }// Event selection
576   //------------------------------------------------------
577   
578   //Check if there is a centrality value, PbPb analysis, and if a centrality bin selection is requested
579   //If we need a centrality bin, we select only those events in the corresponding bin.
580   if(GetCentrality() && fCentralityBin[0]>=0 && fCentralityBin[1]>=0 && fCentralityOpt==100)
581   {
582     Int_t cen = GetEventCentrality();
583     if(cen > fCentralityBin[1] || cen < fCentralityBin[0]) return kFALSE; //reject events out of bin.
584   }
585   
586   //Fill the arrays with cluster/tracks/cells data
587   if(fFillEMCALCells) 
588     FillInputEMCALCells();
589   if(fFillPHOSCells)  
590     FillInputPHOSCells();
591         
592   if(fFillCTS){   
593     FillInputCTS();
594     //Accept events with at least one track
595     if(fTrackMult == 0 && fDoEventSelection) return kFALSE;
596   }
597   
598   if(fFillEMCAL) 
599     FillInputEMCAL();
600   if(fFillPHOS)  
601     FillInputPHOS();
602   
603   FillInputVZERO();
604         
605   return kTRUE ;
606 }
607
608 //___________________________________
609 void AliCaloTrackReader::ResetLists() 
610 {
611   //  Reset lists, called by the analysis maker 
612   
613   if(fCTSTracks)       fCTSTracks     -> Clear();
614   if(fEMCALClusters)   fEMCALClusters -> Clear("C");
615   if(fPHOSClusters)    fPHOSClusters  -> Clear("C");
616   
617   fV0ADC[0] = 0;   fV0ADC[1] = 0; 
618   fV0Mul[0] = 0;   fV0Mul[1] = 0; 
619   
620 }
621
622 //____________________________________________________________
623 void AliCaloTrackReader::SetInputEvent(AliVEvent* const input)  
624 {
625   fInputEvent  = input;
626   fMixedEvent = dynamic_cast<AliMixedEvent*>(GetInputEvent()) ; 
627   if (fMixedEvent) {
628     fNMixedEvent = fMixedEvent->GetNumberOfEvents() ; 
629   }
630   
631   //Delete previous vertex
632   if(fVertex){
633     for (Int_t i = 0; i < fNMixedEvent; i++) {
634       delete [] fVertex[i] ; 
635     }
636     delete [] fVertex ;
637   }
638   
639   fVertex = new Double_t*[fNMixedEvent] ; 
640   for (Int_t i = 0; i < fNMixedEvent; i++) {
641     fVertex[i] = new Double_t[3] ; 
642     fVertex[i][0] = 0.0 ; 
643     fVertex[i][1] = 0.0 ; 
644     fVertex[i][2] = 0.0 ; 
645   }
646 }
647
648 //__________________________________________________
649 Int_t AliCaloTrackReader::GetEventCentrality() const 
650 {
651   //Return current event centrality
652   
653   if(GetCentrality()){
654     if(fCentralityOpt==100)     return (Int_t) GetCentrality()->GetCentralityPercentile(fCentralityClass); // 100 bins max
655     else if(fCentralityOpt==10) return GetCentrality()->GetCentralityClass10(fCentralityClass);// 10 bins max
656     else if(fCentralityOpt==20) return GetCentrality()->GetCentralityClass5(fCentralityClass); // 20 bins max
657     else {
658       printf("AliAnaPartCorrBaseClass::Unknown centrality option %d, use 10, 20 or 100\n",fCentralityOpt);
659       return 0;
660     } 
661   }
662   else return 0;
663   
664 }
665
666 //__________________________________________________________
667 void AliCaloTrackReader::GetVertex(Double_t vertex[3]) const 
668 {
669   //Return vertex position to be used for single event analysis
670   vertex[0]=fVertex[0][0];  
671   vertex[1]=fVertex[0][1];  
672   vertex[2]=fVertex[0][2];
673 }
674
675 //____________________________________________________________
676 void AliCaloTrackReader::GetVertex(Double_t vertex[3], 
677                                    const Int_t evtIndex) const 
678 {
679   //Return vertex position for mixed event, recover the vertex in a particular event.
680   
681   vertex[0]=fVertex[evtIndex][0];  vertex[1]=fVertex[evtIndex][1];  vertex[2]=fVertex[evtIndex][2];
682   
683 }
684
685 //________________________________________
686 void AliCaloTrackReader::FillVertexArray() 
687 {
688   
689   //Fill data member with vertex
690   //In case of Mixed event, multiple vertices
691   
692   //Delete previous vertex
693   if(fVertex){
694     for (Int_t i = 0; i < fNMixedEvent; i++) {
695       delete [] fVertex[i] ; 
696     }
697     delete [] fVertex ;  
698   }
699   
700   fVertex = new Double_t*[fNMixedEvent] ; 
701   for (Int_t i = 0; i < fNMixedEvent; i++) {
702     fVertex[i] = new Double_t[3] ; 
703     fVertex[i][0] = 0.0 ; 
704     fVertex[i][1] = 0.0 ; 
705     fVertex[i][2] = 0.0 ; 
706   }          
707   
708   if (!fMixedEvent) { //Single event analysis
709     if(fDataType!=kMC){
710       
711       if(fInputEvent->GetPrimaryVertex()){
712         fInputEvent->GetPrimaryVertex()->GetXYZ(fVertex[0]); 
713       }
714       else {
715         printf("AliCaloTrackReader::FillVertexArray() - NULL primary vertex\n");
716         fVertex[0][0]=0.;   fVertex[0][1]=0.;   fVertex[0][2]=0.;
717       }//Primary vertex pointer do not exist
718       
719     } else {//MC read event 
720       fVertex[0][0]=0.;   fVertex[0][1]=0.;   fVertex[0][2]=0.;
721     }
722     
723     if(fDebug > 1)
724       printf("AliCaloTrackReader::FillVertexArray() - Single Event Vertex : %f,%f,%f\n",fVertex[0][0],fVertex[0][1],fVertex[0][2]);
725     
726   } else { // MultiEvent analysis
727     for (Int_t iev = 0; iev < fNMixedEvent; iev++) {
728       if (fMixedEvent->GetVertexOfEvent(iev))
729         fMixedEvent->GetVertexOfEvent(iev)->GetXYZ(fVertex[iev]);
730       else { // no vertex found !!!!
731         AliWarning("No vertex found");
732       }
733       
734       if(fDebug > 1)
735         printf("AliCaloTrackReader::FillVertexArray() - Multi Event %d Vertex : %f,%f,%f\n",iev,fVertex[iev][0],fVertex[iev][1],fVertex[iev][2]);
736       
737     }
738   }
739   
740 }
741
742 //_____________________________________
743 void AliCaloTrackReader::FillInputCTS() 
744 {
745   //Return array with Central Tracking System (CTS) tracks
746   
747   if(fDebug > 2 ) printf("AliCaloTrackReader::FillInputCTS()\n");
748   
749   Int_t nTracks   = fInputEvent->GetNumberOfTracks() ;
750   Double_t p[3];
751   fTrackMult = 0;
752   Int_t nstatus = 0;
753   for (Int_t itrack =  0; itrack <  nTracks; itrack++) {////////////// track loop
754     AliVTrack * track = (AliVTrack*)fInputEvent->GetTrack(itrack) ; // retrieve track from esd
755     
756     //Select tracks under certain conditions, TPCrefit, ITSrefit ... check the set bits
757     if (fTrackStatus && !((track->GetStatus() & fTrackStatus) == fTrackStatus)) 
758       continue ;
759     
760     nstatus++;
761     
762     if     (fDataType==kESD && !fESDtrackCuts->AcceptTrack((AliESDtrack*)track))
763     {
764       continue;
765     }
766     else if(fDataType==kAOD)
767     {
768       AliAODTrack *aodtrack = dynamic_cast <AliAODTrack*>(track);
769       if(aodtrack){
770         if(fDebug > 2 ) 
771           printf("AliCaloTrackReader::FillInputCTS():AOD track type: %c \n", aodtrack->GetType());
772         if (fDataType!=kMC && aodtrack->TestFilterBit(fTrackFilterMask)==kFALSE) continue;
773         if(aodtrack->GetType()!=AliAODTrack::kPrimary) continue;
774       }
775     }
776     
777     //Count the tracks in eta < 0.9
778     //printf("Eta %f cut  %f\n",TMath::Abs(track->Eta()),fTrackMultEtaCut);
779     if(TMath::Abs(track->Eta())< fTrackMultEtaCut) fTrackMult++;
780     
781     track->GetPxPyPz(p) ;
782     TLorentzVector momentum(p[0],p[1],p[2],0);
783     
784     if(fCTSPtMin < momentum.Pt() && fCTSPtMax > momentum.Pt()){
785       
786       if(fCheckFidCut && !fFiducialCut->IsInFiducialCut(momentum,"CTS")) 
787         continue;
788       
789       if(fDebug > 2 && momentum.Pt() > 0.1) 
790         printf("AliCaloTrackReader::FillInputCTS() - Selected tracks E %3.2f, pt %3.2f, phi %3.2f, eta %3.2f\n",
791                momentum.E(),momentum.Pt(),momentum.Phi()*TMath::RadToDeg(),momentum.Eta());
792       
793       if (fMixedEvent) {
794         track->SetID(itrack);
795       }
796       
797       fCTSTracks->Add(track);        
798       
799     }//Pt and Fiducial cut passed. 
800   }// track loop
801         
802   //fCTSTracksNormalInputEntries = fCTSTracks->GetEntriesFast();
803   if(fDebug > 1) 
804     printf("AliCaloTrackReader::FillInputCTS()   - aod entries %d, input tracks %d, pass status %d, multipliticy %d\n", fCTSTracks->GetEntriesFast(), nTracks, nstatus, fTrackMult);//fCTSTracksNormalInputEntries);
805   
806 }
807
808 //__________________________________________________________________
809 void AliCaloTrackReader::FillInputEMCALAlgorithm(AliVCluster * clus, 
810                                                  const Int_t iclus) 
811 {
812   //Fill the EMCAL data in the array, do it
813   
814   Int_t vindex = 0 ;  
815   if (fMixedEvent) 
816     vindex = fMixedEvent->EventIndexForCaloCluster(iclus);
817   
818   //Reject clusters with bad channels, close to borders and exotic;
819   if(!GetCaloUtils()->GetEMCALRecoUtils()->IsGoodCluster(clus,GetCaloUtils()->GetEMCALGeometry(),GetEMCALCells(),fInputEvent->GetBunchCrossNumber())) return;
820   
821   //Mask all cells in collumns facing ALICE thick material if requested
822   if(GetCaloUtils()->GetNMaskCellColumns()){
823     Int_t absId   = -1;
824     Int_t iSupMod = -1;
825     Int_t iphi    = -1;
826     Int_t ieta    = -1;
827     Bool_t shared = kFALSE;
828     GetCaloUtils()->GetEMCALRecoUtils()->GetMaxEnergyCell(GetCaloUtils()->GetEMCALGeometry(), GetEMCALCells(),clus,absId,iSupMod,ieta,iphi,shared);
829     if(GetCaloUtils()->MaskFrameCluster(iSupMod, ieta)) return;
830   }
831   
832   if(fSelectEmbeddedClusters){
833     if(clus->GetNLabels()==0 || clus->GetLabel() < 0) return;
834     //else printf("Embedded cluster,  %d, n label %d label %d  \n",iclus,clus->GetNLabels(),clus->GetLabel());
835   }
836   
837   //Float_t pos[3];
838   //clus->GetPosition(pos);
839   //printf("Before Corrections: e %f, x %f, y %f, z %f\n",clus->E(),pos[0],pos[1],pos[2]);
840   
841   if(fRecalculateClusters){
842     //Recalibrate the cluster energy 
843     if(GetCaloUtils()->IsRecalibrationOn()) {
844       
845       Float_t energy = GetCaloUtils()->RecalibrateClusterEnergy(clus, GetEMCALCells());
846       
847       clus->SetE(energy);
848       //printf("Recalibrated Energy %f\n",clus->E());  
849       
850       GetCaloUtils()->RecalculateClusterShowerShapeParameters(GetEMCALCells(),clus);
851       GetCaloUtils()->RecalculateClusterPID(clus);
852       
853     } // recalculate E
854     
855     //Recalculate distance to bad channels, if new list of bad channels provided
856     GetCaloUtils()->RecalculateClusterDistanceToBadChannel(GetEMCALCells(),clus);
857     
858     //Recalculate cluster position
859     if(GetCaloUtils()->IsRecalculationOfClusterPositionOn()){
860       GetCaloUtils()->RecalculateClusterPosition(GetEMCALCells(),clus); 
861       //clus->GetPosition(pos);
862       //printf("After  Corrections: e %f, x %f, y %f, z %f\n",clus->E(),pos[0],pos[1],pos[2]);
863     }
864   }
865   
866   // Recalculate TOF
867   if(GetCaloUtils()->GetEMCALRecoUtils()->IsTimeRecalibrationOn()) {
868     
869     Double_t tof      = clus->GetTOF();
870     Float_t  frac     =-1;
871     Int_t    absIdMax = GetCaloUtils()->GetMaxEnergyCell(fEMCALCells, clus,frac);
872     
873     if(fDataType==AliCaloTrackReader::kESD){ 
874       tof = fEMCALCells->GetCellTime(absIdMax);
875     }
876     
877     GetCaloUtils()->GetEMCALRecoUtils()->RecalibrateCellTime(absIdMax,fInputEvent->GetBunchCrossNumber(),tof);
878     
879     clus->SetTOF(tof);
880     
881   }// Time recalibration    
882   
883   //Correct non linearity
884   if(GetCaloUtils()->IsCorrectionOfClusterEnergyOn()){
885     GetCaloUtils()->CorrectClusterEnergy(clus) ;
886     //printf("Linearity Corrected Energy %f\n",clus->E());  
887     
888     //In case of MC analysis, to match resolution/calibration in real data
889     Float_t rdmEnergy = GetCaloUtils()->GetEMCALRecoUtils()->SmearClusterEnergy(clus);
890     // printf("\t Energy %f, smeared %f\n", clus->E(),rdmEnergy);
891     clus->SetE(rdmEnergy);
892   }
893   
894   TLorentzVector momentum ;
895   
896   clus->GetMomentum(momentum, fVertex[vindex]);      
897   
898   if(fCheckFidCut && !fFiducialCut->IsInFiducialCut(momentum,"EMCAL")) return;
899   
900   if(fEMCALPtMin > momentum.E() || fEMCALPtMax < momentum.E())         return;
901   
902   if(fDebug > 2 && momentum.E() > 0.1) 
903     printf("AliCaloTrackReader::FillInputEMCAL() - Selected clusters E %3.2f, pt %3.2f, phi %3.2f, eta %3.2f\n",
904            momentum.E(),momentum.Pt(),momentum.Phi()*TMath::RadToDeg(),momentum.Eta());
905   
906   if (fMixedEvent) 
907     clus->SetID(iclus) ; 
908   
909   fEMCALClusters->Add(clus);    
910   
911 }
912
913 //_______________________________________
914 void AliCaloTrackReader::FillInputEMCAL() 
915 {
916   //Return array with EMCAL clusters in aod format
917   
918   if(fDebug > 2 ) printf("AliCaloTrackReader::FillInputEMCAL()\n");
919   
920   // First recalibrate cells, time or energy
921   //  if(GetCaloUtils()->IsRecalibrationOn())
922   //    GetCaloUtils()->GetEMCALRecoUtils()->RecalibrateCells(GetCaloUtils()->GetEMCALGeometry(), 
923   //                                                          GetEMCALCells(), 
924   //                                                          fInputEvent->GetBunchCrossNumber());
925   
926   //Loop to select clusters in fiducial cut and fill container with aodClusters
927   if(fEMCALClustersListName==""){
928     Int_t nclusters = fInputEvent->GetNumberOfCaloClusters();
929     for (Int_t iclus =  0; iclus <  nclusters; iclus++) {
930       AliVCluster * clus = 0;
931       if ( (clus = fInputEvent->GetCaloCluster(iclus)) ) {
932         if (IsEMCALCluster(clus)){          
933           FillInputEMCALAlgorithm(clus, iclus);
934         }//EMCAL cluster
935       }// cluster exists
936     }// cluster loop
937     
938     //Recalculate track matching
939     GetCaloUtils()->RecalculateClusterTrackMatching(fInputEvent);
940     
941   }//Get the clusters from the input event
942   else {
943     TClonesArray * clusterList = 0x0; 
944     if(fOutputEvent) clusterList = dynamic_cast<TClonesArray*> (fOutputEvent->FindListObject(fEMCALClustersListName));
945     if(!clusterList){
946       //printf("AliCaloTrackReader::FillInputEMCAL() - Wrong name of list with clusters? Try input event <%s>\n",fEMCALClustersListName.Data());
947       //List not in output event, try input event
948       clusterList = dynamic_cast<TClonesArray*> (fInputEvent->FindListObject(fEMCALClustersListName));
949       if(!clusterList){
950         printf("AliCaloTrackReader::FillInputEMCAL() - Wrong name of list with clusters?  <%s>\n",fEMCALClustersListName.Data());
951         return;
952       }
953     }
954     
955     Int_t nclusters = clusterList->GetEntriesFast();
956     for (Int_t iclus =  0; iclus <  nclusters; iclus++) {
957       AliVCluster * clus = dynamic_cast<AliVCluster*> (clusterList->At(iclus));
958       //printf("E %f\n",clus->E());
959       if (clus) FillInputEMCALAlgorithm(clus, iclus);
960       else printf("AliCaloTrackReader::FillInputEMCAL() - Null cluster in list!\n");
961       
962     }// cluster loop
963     
964     // Recalculate track matching, not necessary if already done in the reclusterization task.
965     // in case it was not done ...
966     GetCaloUtils()->RecalculateClusterTrackMatching(fInputEvent,clusterList);
967     
968   }
969   
970   if(fDebug > 1) printf("AliCaloTrackReader::FillInputEMCAL() - aod entries %d\n",  fEMCALClusters->GetEntriesFast());
971   
972 }
973
974 //______________________________________
975 void AliCaloTrackReader::FillInputPHOS() 
976 {
977   //Return array with PHOS clusters in aod format
978   
979   if(fDebug > 2 ) printf("AliCaloTrackReader::FillInputPHOS()\n");
980   
981   //Loop to select clusters in fiducial cut and fill container with aodClusters
982   Int_t nclusters = fInputEvent->GetNumberOfCaloClusters();
983   for (Int_t iclus = 0; iclus < nclusters; iclus++) {
984     AliVCluster * clus = 0;
985     if ( (clus = fInputEvent->GetCaloCluster(iclus)) ) {
986       if (IsPHOSCluster(clus)){
987         //Check if the cluster contains any bad channel and if close to calorimeter borders
988         Int_t vindex = 0 ;  
989         if (fMixedEvent) 
990           vindex = fMixedEvent->EventIndexForCaloCluster(iclus);
991         if( GetCaloUtils()->ClusterContainsBadChannel("PHOS",clus->GetCellsAbsId(), clus->GetNCells())) 
992           continue;
993         if(!GetCaloUtils()->CheckCellFiducialRegion(clus, fInputEvent->GetPHOSCells(), fInputEvent, vindex)) 
994           continue;
995         
996         if(fRecalculateClusters){
997           
998           //Recalibrate the cluster energy 
999           if(GetCaloUtils()->IsRecalibrationOn()) {
1000             Float_t energy = GetCaloUtils()->RecalibrateClusterEnergy(clus, (AliAODCaloCells*)GetPHOSCells());
1001             clus->SetE(energy);
1002           }
1003           
1004         }
1005         
1006         TLorentzVector momentum ;
1007         
1008         clus->GetMomentum(momentum, fVertex[vindex]);      
1009         
1010         if(fCheckFidCut && !fFiducialCut->IsInFiducialCut(momentum,"PHOS")) continue;
1011         
1012         if(fPHOSPtMin > momentum.E() || fPHOSPtMax < momentum.E())          continue;
1013         
1014         if(fDebug > 2 && momentum.E() > 0.1) 
1015           printf("AliCaloTrackReader::FillInputPHOS() - Selected clusters E %3.2f, pt %3.2f, phi %3.2f, eta %3.2f\n",
1016                  momentum.E(),momentum.Pt(),momentum.Phi()*TMath::RadToDeg(),momentum.Eta());        
1017         
1018         
1019         if (fMixedEvent) {
1020           clus->SetID(iclus) ; 
1021         }              
1022         
1023         fPHOSClusters->Add(clus);       
1024         
1025       }//PHOS cluster
1026     }//cluster exists
1027   }//esd cluster loop
1028   
1029   if(fDebug > 1) printf("AliCaloTrackReader::FillInputPHOS()  - aod entries %d\n",  fPHOSClusters->GetEntriesFast());
1030   
1031 }
1032
1033 //____________________________________________
1034 void AliCaloTrackReader::FillInputEMCALCells() 
1035 {
1036   //Return array with EMCAL cells in aod format
1037   
1038   fEMCALCells = fInputEvent->GetEMCALCells(); 
1039   
1040 }
1041
1042 //___________________________________________
1043 void AliCaloTrackReader::FillInputPHOSCells() 
1044 {
1045   //Return array with PHOS cells in aod format
1046   
1047   fPHOSCells = fInputEvent->GetPHOSCells(); 
1048   
1049 }
1050
1051 //_______________________________________
1052 void AliCaloTrackReader::FillInputVZERO()
1053 {
1054   //Fill VZERO information in data member, add all the channels information.
1055   AliVVZERO* v0 = fInputEvent->GetVZEROData();
1056   //printf("Init V0: ADC (%d,%d), Multiplicity (%d,%d) \n",fV0ADC[0],fV0ADC[1],fV0Mul[0],fV0Mul[1]);
1057   
1058   if (v0) 
1059   {
1060     AliESDVZERO* esdV0 = dynamic_cast<AliESDVZERO*> (v0);
1061     for (Int_t i = 0; i < 32; i++)
1062     {
1063       if(esdV0){//Only available in ESDs
1064         fV0ADC[0] += (Int_t)esdV0->GetAdcV0C(i);
1065         fV0ADC[1] += (Int_t)esdV0->GetAdcV0A(i);
1066       }
1067       fV0Mul[0] += (Int_t)v0->GetMultiplicityV0C(i);
1068       fV0Mul[1] += (Int_t)v0->GetMultiplicityV0A(i);
1069     }
1070     if(fDebug > 0)
1071       printf("V0: ADC (%d,%d), Multiplicity (%d,%d) \n",fV0ADC[0],fV0ADC[1],fV0Mul[0],fV0Mul[1]);
1072   }
1073   else
1074   {
1075     if(fDebug > 0)
1076       printf("Cannot retrieve V0 ESD! Run w/ null V0 charges\n ");
1077   }
1078 }
1079
1080
1081 //___________________________________________________________________
1082 Bool_t AliCaloTrackReader::IsEMCALCluster(AliVCluster* cluster) const 
1083 {
1084   // Check if it is a cluster from EMCAL. For old AODs cluster type has
1085   // different number and need to patch here
1086   
1087   if(fDataType==kAOD && fOldAOD)
1088   {
1089     if (cluster->GetType() == 2) return kTRUE;
1090     else                         return kFALSE;
1091   }
1092   else 
1093   {
1094     return cluster->IsEMCAL();
1095   }
1096   
1097 }
1098
1099 //___________________________________________________________________
1100 Bool_t AliCaloTrackReader::IsPHOSCluster(AliVCluster * cluster) const 
1101 {
1102   //Check if it is a cluster from PHOS.For old AODs cluster type has
1103   // different number and need to patch here
1104   
1105   if(fDataType==kAOD && fOldAOD)
1106   {
1107     Int_t type = cluster->GetType();
1108     if (type == 0 || type == 1) return kTRUE;
1109     else                        return kFALSE;
1110   }
1111   else 
1112   {
1113     return cluster->IsPHOS();
1114   }
1115   
1116 }
1117
1118 //________________________________________________
1119 Bool_t AliCaloTrackReader::CheckForPrimaryVertex()
1120 {
1121   //Check if the vertex was well reconstructed, copy from V0Reader of conversion group
1122   //Only for ESDs ...
1123   
1124   AliESDEvent * event = dynamic_cast<AliESDEvent*> (fInputEvent);
1125   if(!event) return kTRUE;
1126   
1127   if(event->GetPrimaryVertexTracks()->GetNContributors() > 0) {
1128     return kTRUE;
1129   }
1130   
1131   if(event->GetPrimaryVertexTracks()->GetNContributors() < 1) {
1132     // SPD vertex
1133     if(event->GetPrimaryVertexSPD()->GetNContributors() > 0) {
1134       //cout<<"spd vertex type::"<< fESDEvent->GetPrimaryVertex()->GetName() << endl;
1135       return kTRUE;
1136       
1137     }
1138     if(event->GetPrimaryVertexSPD()->GetNContributors() < 1) {
1139       //      cout<<"bad vertex type::"<< event->GetPrimaryVertex()->GetName() << endl;
1140       return kFALSE;
1141     }
1142   }
1143   
1144   return kFALSE;  
1145   
1146 }
1147
1148 //____________________________________________________________
1149 void  AliCaloTrackReader::SetTrackCuts(AliESDtrackCuts * cuts) 
1150
1151   // Set Track cuts
1152   
1153   if(fESDtrackCuts) delete fESDtrackCuts ;
1154   
1155   fESDtrackCuts = cuts ; 
1156   
1157 }                 
1158