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