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