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