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