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