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