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