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