1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
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)
25 // This part is commented: Mixing analysis can be done, input AOD with events
26 // is opened in the AliCaloTrackReader::Init()
28 //-- Author: Gustavo Conesa (LNF-INFN)
29 //////////////////////////////////////////////////////////////////////////////
32 // --- ROOT system ---
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"
49 //---- PartCorr/EMCAL ---
50 #include "AliEMCALRecoUtils.h"
51 #include "AliCaloTrackReader.h"
53 ClassImp(AliCaloTrackReader)
56 //____________________________________________________________________________
57 AliCaloTrackReader::AliCaloTrackReader() :
58 TObject(), fEventNumber(-1), //fCurrentFileName(""),
59 fDataType(0), fDebug(0),
60 fFiducialCut(0x0), fCheckFidCut(kFALSE), fComparePtHardAndJetPt(kFALSE), fPtHardAndJetPtFactor(7),
61 fCTSPtMin(0), fEMCALPtMin(0),fPHOSPtMin(0), fAODBranchList(new TList ),
62 fAODCTS(new TObjArray()), fAODEMCAL(new TObjArray()), fAODPHOS(new TObjArray()),
63 fEMCALCells(0x0), fPHOSCells(0x0),
64 fInputEvent(0x0), fOutputEvent(0x0),fMC(0x0),
65 fFillCTS(0),fFillEMCAL(0),fFillPHOS(0),
66 fFillEMCALCells(0),fFillPHOSCells(0),
67 fRemoveSuspiciousClusters(kFALSE), fSmearClusterEnergy(kFALSE), fRandom(),
68 // fSecondInputAODTree(0x0), fSecondInputAODEvent(0x0),
69 // fSecondInputFileName(""),fSecondInputFirstEvent(0),
70 // fAODCTSNormalInputEntries(0), fAODEMCALNormalInputEntries(0),
71 // fAODPHOSNormalInputEntries(0),
72 fTrackStatus(0), fESDtrackCuts(0), fTrackMult(0), fTrackMultEtaCut(0.8),
73 fReadStack(kFALSE), fReadAODMCParticles(kFALSE),
74 fDeltaAODFileName("deltaAODPartCorr.root"),fFiredTriggerClassName(""),
75 fAnaLED(kFALSE),fTaskName(""),fCaloUtils(0x0),
76 fMixedEvent(NULL), fNMixedEvent(1), fVertex(NULL),
77 fWriteOutputDeltaAOD(kFALSE),fOldAOD(kFALSE),fCaloFilterPatch(kFALSE),
78 fEMCALClustersListName(""),fZvtxCut(0.),
79 fDoEventSelection(kFALSE), fDoV0ANDEventSelection(kFALSE),
80 fTriggerAnalysis (new AliTriggerAnalysis), fCentralityClass("V0M"),fCentralityOpt(10)
85 //Initialize parameters
89 //_________________________________
90 AliCaloTrackReader::~AliCaloTrackReader() {
93 if(fFiducialCut) delete fFiducialCut ;
96 fAODBranchList->Delete();
97 delete fAODBranchList ;
101 if(fDataType!=kMC)fAODCTS->Clear() ;
102 else fAODCTS->Delete() ;
107 if(fDataType!=kMC)fAODEMCAL->Clear("C") ;
108 else fAODEMCAL->Delete() ;
113 if(fDataType!=kMC)fAODPHOS->Clear("C") ;
114 else fAODPHOS->Delete() ;
119 // delete fEMCALCells ;
123 // delete fPHOSCells ;
127 for (Int_t i = 0; i < fNMixedEvent; i++) {
128 delete [] fVertex[i] ;
134 if(fESDtrackCuts) delete fESDtrackCuts;
135 if(fTriggerAnalysis) delete fTriggerAnalysis;
137 // Pointers not owned, done by the analysis frame
138 // if(fInputEvent) delete fInputEvent ;
139 // if(fOutputEvent) delete fOutputEvent ;
140 // if(fMC) delete fMC ;
142 // if(fSecondInputAODTree){
143 // fSecondInputAODTree->Clear();
144 // delete fSecondInputAODTree;
147 // if(fSecondInputAODEvent) delete fSecondInputAODEvent ;
149 // Pointer not owned, deleted by maker
150 //if (fCaloUtils) delete fCaloUtils ;
154 //_________________________________________________________________________
155 Bool_t AliCaloTrackReader::ComparePtHardAndJetPt(){
156 // Check the event, if the requested ptHard is much larger than the jet pT, then there is a problem.
158 if(!fReadStack) return kTRUE; //Information not filtered to AOD
160 if(!strcmp(GetGenEventHeader()->ClassName(), "AliGenPythiaEventHeader")){
162 AliGenPythiaEventHeader* pygeh= (AliGenPythiaEventHeader*) GetGenEventHeader();
163 Int_t nTriggerJets = pygeh->NTriggerJets();
164 Float_t ptHard = pygeh->GetPtHard();
166 //if(fDebug > 1) printf("AliMCAnalysisUtils::PythiaEventHeader: Njets: %d, pT Hard %f\n",nTriggerJets, ptHard);
167 Float_t tmpjet[]={0,0,0,0};
168 for(Int_t ijet = 0; ijet< nTriggerJets; ijet++){
169 pygeh->TriggerJet(ijet, tmpjet);
170 jet = new TParticle(94, 21, -1, -1, -1, -1, tmpjet[0],tmpjet[1],tmpjet[2],tmpjet[3], 0,0,0,0);
171 //Compare jet pT and pt Hard
172 //if(fDebug > 1) printf("AliMCAnalysisUtils:: %d pycell jet pT %f\n",ijet, jet->Pt());
173 if(jet->Pt() > fPtHardAndJetPtFactor * ptHard) {
174 printf("AliMCAnalysisUtils::PythiaEventHeader: Njets: %d, pT Hard %2.2f, pycell jet pT %2.2f, rejection factor %1.1f\n",
175 nTriggerJets, ptHard, jet->Pt(), fPtHardAndJetPtFactor);
186 //____________________________________________________________________________
187 AliStack* AliCaloTrackReader::GetStack() const {
188 //Return pointer to stack
192 if(fDebug > 1) printf("AliCaloTrackReader::GetStack() - Stack is not available\n");
197 //____________________________________________________________________________
198 AliHeader* AliCaloTrackReader::GetHeader() const {
199 //Return pointer to header
201 return fMC->Header();
203 printf("AliCaloTrackReader::Header is not available\n");
207 //____________________________________________________________________________
208 AliGenEventHeader* AliCaloTrackReader::GetGenEventHeader() const {
209 //Return pointer to Generated event header
211 return fMC->GenEventHeader();
213 printf("AliCaloTrackReader::GenEventHeader is not available\n");
218 //____________________________________________________________________________
219 TClonesArray* AliCaloTrackReader::GetAODMCParticles(Int_t input) const {
220 //Return list of particles in AOD. Do it for the corresponding input event.
222 TClonesArray * rv = NULL ;
223 if(fDataType == kAOD){
227 AliAODEvent * evt = dynamic_cast<AliAODEvent*> (fInputEvent) ;
229 rv = (TClonesArray*)evt->FindListObject("mcparticles");
231 printf("AliCaloTrackReader::GetAODMCParticles() - wrong AOD input index? %d, or non existing tree? \n",input);
233 } //else if(input == 1 && fSecondInputAODEvent){ //Second input AOD
234 // rv = (TClonesArray*) fSecondInputAODEvent->FindListObject("mcparticles");
238 printf("AliCaloTrackReader::GetAODMCParticles() - Input are not AODs\n");
244 //____________________________________________________________________________
245 AliAODMCHeader* AliCaloTrackReader::GetAODMCHeader(Int_t input) const {
246 //Return MC header in AOD. Do it for the corresponding input event.
247 AliAODMCHeader *mch = NULL;
248 if(fDataType == kAOD){
251 mch = (AliAODMCHeader*)((AliAODEvent*)fInputEvent)->FindListObject("mcheader");
253 // //Second input AOD
254 // else if(input == 1){
255 // mch = (AliAODMCHeader*) fSecondInputAODEvent->FindListObject("mcheader");
258 printf("AliCaloTrackReader::GetAODMCHeader() - wrong AOD input index, %d\n",input);
262 printf("AliCaloTrackReader::GetAODMCHeader() - Input are not AODs\n");
268 //_______________________________________________________________
269 void AliCaloTrackReader::Init()
271 //Init reader. Method to be called in AliAnaPartCorrMaker
273 //Get the file with second input events if the filename is given
274 //Get the tree and connect the AODEvent. Only with AODs
276 if(fReadStack && fReadAODMCParticles){
277 printf("AliCaloTrackReader::Init() - Cannot access stack and mcparticles at the same time, change them \n");
279 fReadAODMCParticles = kFALSE;
282 // if(fSecondInputFileName!=""){
283 // if(fDataType == kAOD){
284 // TFile * input2 = new TFile(fSecondInputFileName,"read");
285 // printf("AliCaloTrackReader::Init() - Second input file opened: %s, size %d \n", input2->GetName(), (Int_t) input2->GetSize());
286 // fSecondInputAODTree = (TTree*) input2->Get("aodTree");
287 // if(fSecondInputAODTree) printf("AliCaloTrackReader::Init() - Second input tree opened: %s, entries %d \n",
288 // fSecondInputAODTree->GetName(), (Int_t) fSecondInputAODTree->GetEntries());
290 // printf("AliCaloTrackReader::Init() - Second input tree not available, STOP \n");
293 // fSecondInputAODEvent = new AliAODEvent;
294 // fSecondInputAODEvent->ReadFromTree(fSecondInputAODTree);
295 // if(fSecondInputFirstEvent >= fSecondInputAODTree->GetEntriesFast()){
296 // printf("AliCaloTrackReader::Init() - Requested first event of second input %d, is larger than number of events %d, STOP\n",
297 // fSecondInputFirstEvent, (Int_t) fSecondInputAODTree->GetEntriesFast());
301 // else printf("AliCaloTrackReader::Init() - Second input not added, reader is not AOD\n");
305 //_______________________________________________________________
306 void AliCaloTrackReader::InitParameters()
308 //Initialize the parameters of the analysis.
314 //Do not filter the detectors input by default.
318 fFillEMCALCells = kFALSE;
319 fFillPHOSCells = kFALSE;
321 //fSecondInputFileName = "" ;
322 //fSecondInputFirstEvent = 0 ;
323 fReadStack = kFALSE; // Check in the constructor of the other readers if it was set or in the configuration file
324 fReadAODMCParticles = kFALSE; // Check in the constructor of the other readers if it was set or in the configuration file
325 fDeltaAODFileName = "deltaAODPartCorr.root";
326 fFiredTriggerClassName = "";
330 //We want tracks fitted in the detectors:
331 //fTrackStatus=AliESDtrack::kTPCrefit;
332 //fTrackStatus|=AliESDtrack::kITSrefit;
334 fESDtrackCuts = AliESDtrackCuts::GetStandardITSTPCTrackCuts2010();
336 fV0ADC[0] = 0; fV0ADC[1] = 0;
337 fV0Mul[0] = 0; fV0Mul[1] = 0;
342 fCentralityBin[0]=fCentralityBin[1]=-1;
345 fSmearClusterEnergy = kFALSE;
346 fSmearClusterParam[0] = 0.07; // * sqrt E term
347 fSmearClusterParam[1] = 0.02; // * E term
348 fSmearClusterParam[2] = 0.00; // constant
352 //________________________________________________________________
353 void AliCaloTrackReader::Print(const Option_t * opt) const
356 //Print some relevant parameters set for the analysis
360 printf("***** Print: %s %s ******\n", GetName(), GetTitle() ) ;
361 printf("Task name : %s\n", fTaskName.Data()) ;
362 printf("Data type : %d\n", fDataType) ;
363 printf("CTS Min pT : %2.1f GeV/c\n", fCTSPtMin) ;
364 printf("EMCAL Min pT : %2.1f GeV/c\n", fEMCALPtMin) ;
365 printf("PHOS Min pT : %2.1f GeV/c\n", fPHOSPtMin) ;
366 printf("Use CTS = %d\n", fFillCTS) ;
367 printf("Use EMCAL = %d\n", fFillEMCAL) ;
368 printf("Use PHOS = %d\n", fFillPHOS) ;
369 printf("Use EMCAL Cells = %d\n", fFillEMCALCells) ;
370 printf("Use PHOS Cells = %d\n", fFillPHOSCells) ;
371 printf("Track status = %d\n", (Int_t) fTrackStatus) ;
372 printf("Track Mult Eta Cut = %d\n", (Int_t) fTrackMultEtaCut) ;
373 printf("Write delta AOD = %d\n", fWriteOutputDeltaAOD) ;
375 if(fComparePtHardAndJetPt)
376 printf("Compare jet pt and pt hard to accept event, factor = %2.2f",fPtHardAndJetPtFactor);
378 // if(fSecondInputFileName!="") {
379 // printf("Second Input File Name = %s\n", fSecondInputFileName.Data()) ;
380 // printf("Second Input First Event = %d\n", fSecondInputFirstEvent) ;
383 printf("Read Kine from, stack? %d, AOD ? %d \n", fReadStack, fReadAODMCParticles) ;
384 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]) ;
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.
396 fEventNumber = iEntry;
397 //fCurrentFileName = TString(currentFileName);
399 if(fDebug >= 0) printf("AliCaloTrackReader::FillInputEvent() - Input event not available, skip event analysis\n");
402 //Select events only fired by a certain trigger configuration if it is provided
404 if(fInputEvent->GetHeader())
405 eventType = ((AliVHeader*)fInputEvent->GetHeader())->GetEventType();
406 if( fFiredTriggerClassName !="" && !fAnaLED){
408 return kFALSE; //Only physics event, do not use for simulated events!!!
410 printf("AliCaloTrackReader::FillInputEvent() - FiredTriggerClass <%s>, selected class <%s>, compare name %d\n",
411 GetFiredTriggerClasses().Data(),fFiredTriggerClassName.Data(), GetFiredTriggerClasses().Contains(fFiredTriggerClassName));
412 if( !GetFiredTriggerClasses().Contains(fFiredTriggerClassName) ) return kFALSE;
415 // kStartOfRun = 1, // START_OF_RUN
416 // kEndOfRun = 2, // END_OF_RUN
417 // kStartOfRunFiles = 3, // START_OF_RUN_FILES
418 // kEndOfRunFiles = 4, // END_OF_RUN_FILES
419 // kStartOfBurst = 5, // START_OF_BURST
420 // kEndOfBurst = 6, // END_OF_BURST
421 // kPhysicsEvent = 7, // PHYSICS_EVENT
422 // kCalibrationEvent = 8, // CALIBRATION_EVENT
423 // kFormatError = 9, // EVENT_FORMAT_ERROR
424 // kStartOfData = 10, // START_OF_DATA
425 // kEndOfData = 11, // END_OF_DATA
426 // kSystemSoftwareTriggerEvent = 12, // SYSTEM_SOFTWARE_TRIGGER_EVENT
427 // kDetectorSoftwareTriggerEvent = 13 // DETECTOR_SOFTWARE_TRIGGER_EVENT
429 if(eventType!=7 && fDebug > 1 )printf("AliCaloTrackReader::FillInputEvent() - DO LED, Event Type <%d>, 8 Calibration \n", eventType);
430 if(eventType!=8)return kFALSE;
433 //In case of analysis of events with jets, skip those with jet pt > 5 pt hard
434 if(fComparePtHardAndJetPt && GetStack()) {
435 if(!ComparePtHardAndJetPt()) return kFALSE ;
438 //In case of mixing events with other AOD file
439 // if(fDataType == kAOD && fSecondInputAODTree){
442 // printf("AliCaloTrackReader::FillInputEvent() - Get event %d from second input AOD file \n", iEntry+fSecondInputFirstEvent);
443 // if(fSecondInputAODTree->GetEntriesFast() <= iEntry+fSecondInputFirstEvent) {
444 // if(fSecondInputAODTree->GetEntriesFast() == iEntry+fSecondInputFirstEvent)
445 // printf("AliCaloTrackReader::FillInputEvent() - Skip events from event %d, no more events in second AOD file \n", iEntry);
450 // Int_t nbytes = fSecondInputAODTree->GetEvent(iEntry+fSecondInputFirstEvent);
451 // if ( nbytes == 0 ) {//If nothing in AOD
452 // printf("AliCaloTrackReader::FillInputEvent() - Nothing in Second AOD input, STOP\n");
460 //Reject events with Z vertex too large, only for SE analysis, if not, cut on the analysis code
461 if(!GetMixedEvent() && TMath::Abs(fVertex[0][2]) > fZvtxCut) return kFALSE;
463 //------------------------------------------------------
464 //Event rejection depending on vertex, pileup, v0and
465 //------------------------------------------------------
466 if(fDoEventSelection){
467 if(!fCaloFilterPatch){
468 //Do not analyze events with pileup
469 Bool_t bPileup = fInputEvent->IsPileupFromSPD(3, 0.8, 3., 2., 5.); //Default values, if not it does not compile
470 //Bool_t bPileup = event->IsPileupFromSPD();
471 if(bPileup) return kFALSE;
473 if(fDoV0ANDEventSelection){
474 Bool_t bV0AND = kTRUE;
475 AliESDEvent* esd = dynamic_cast<AliESDEvent*> (fInputEvent);
477 bV0AND = fTriggerAnalysis->IsOfflineTriggerFired(esd, AliTriggerAnalysis::kV0AND);
478 //else bV0AND = //FIXME FOR AODs
479 if(!bV0AND) return kFALSE;
482 if(!CheckForPrimaryVertex()) return kFALSE;
485 if(fInputEvent->GetNumberOfCaloClusters() > 0) {
486 AliVCluster * calo = fInputEvent->GetCaloCluster(0);
487 if(calo->GetNLabels() == 4){
488 Int_t * selection = calo->GetLabels();
489 Bool_t bPileup = selection[0];
490 if(bPileup) return kFALSE;
492 Bool_t bGoodV = selection[1];
493 if(!bGoodV) return kFALSE;
495 if(fDoV0ANDEventSelection){
496 Bool_t bV0AND = selection[2];
497 if(!bV0AND) return kFALSE;
500 fTrackMult = selection[3];
501 if(fTrackMult == 0) return kFALSE;
503 //First filtered AODs, track multiplicity stored there.
504 fTrackMult = (Int_t) ((AliAODHeader*)fInputEvent->GetHeader())->GetCentrality();
505 if(fTrackMult == 0) return kFALSE;
507 }//at least one cluster
509 //printf("AliCaloTrackReader::FillInputEvent() - No clusters in event\n");
510 //Remove events with vertex (0,0,0), bad vertex reconstruction
511 if(TMath::Abs(fVertex[0][0]) < 1.e-6 && TMath::Abs(fVertex[0][1]) < 1.e-6 && TMath::Abs(fVertex[0][2]) < 1.e-6) return kFALSE;
513 //First filtered AODs, track multiplicity stored there.
514 fTrackMult = (Int_t) ((AliAODHeader*)fInputEvent->GetHeader())->GetCentrality();
515 if(fTrackMult == 0) return kFALSE;
517 }// CaloFileter patch
519 //------------------------------------------------------
521 //Check if there is a centrality value, PbPb analysis, and if a centrality bin selection is requested
522 //If we need a centrality bin, we select only those events in the corresponding bin.
523 if(GetCentrality() && fCentralityBin[0]>=0 && fCentralityBin[1]>=0 && fCentralityOpt==100){
524 Int_t cen = GetEventCentrality();
525 if(cen > fCentralityBin[1] || cen < fCentralityBin[0]) return kFALSE; //reject events out of bin.
528 //Fill the arrays with cluster/tracks/cells data
530 FillInputEMCALCells();
532 FillInputPHOSCells();
536 //Accept events with at least one track
537 if(fTrackMult == 0 && fDoEventSelection) return kFALSE;
550 //__________________________________________________
551 void AliCaloTrackReader::ResetLists() {
552 // Reset lists, called by the analysis maker
554 if(fAODCTS) fAODCTS -> Clear();
555 if(fAODEMCAL) fAODEMCAL -> Clear("C");
556 if(fAODPHOS) fAODPHOS -> Clear("C");
557 // if(fEMCALCells) fEMCALCells -> Clear("");
558 // if(fPHOSCells) fPHOSCells -> Clear("");
560 fV0ADC[0] = 0; fV0ADC[1] = 0;
561 fV0Mul[0] = 0; fV0Mul[1] = 0;
565 //____________________________________________________________________________
566 void AliCaloTrackReader::SetInputEvent(AliVEvent* const input)
569 fMixedEvent = dynamic_cast<AliMixedEvent*>(GetInputEvent()) ;
571 fNMixedEvent = fMixedEvent->GetNumberOfEvents() ;
574 //Delete previous vertex
576 for (Int_t i = 0; i < fNMixedEvent; i++) {
577 delete [] fVertex[i] ;
582 fVertex = new Double_t*[fNMixedEvent] ;
583 for (Int_t i = 0; i < fNMixedEvent; i++) {
584 fVertex[i] = new Double_t[3] ;
585 fVertex[i][0] = 0.0 ;
586 fVertex[i][1] = 0.0 ;
587 fVertex[i][2] = 0.0 ;
591 //__________________________________________________
592 Int_t AliCaloTrackReader::GetEventCentrality() const {
593 //Return current event centrality
596 if(fCentralityOpt==100) return (Int_t) GetCentrality()->GetCentralityPercentile(fCentralityClass);
597 else if(fCentralityOpt==10) return GetCentrality()->GetCentralityClass10(fCentralityClass);
598 else if(fCentralityOpt==5) return GetCentrality()->GetCentralityClass5(fCentralityClass);
600 printf("AliAnaPartCorrBaseClass::Unknown centrality option %d, use 5, 10 or 100\n",fCentralityOpt);
608 //____________________________________________________________________________
609 void AliCaloTrackReader::GetVertex(Double_t vertex[3]) const {
610 //Return vertex position to be used for single event analysis
611 vertex[0]=fVertex[0][0];
612 vertex[1]=fVertex[0][1];
613 vertex[2]=fVertex[0][2];
616 //____________________________________________________________________________
617 void AliCaloTrackReader::GetVertex(Double_t vertex[3], const Int_t evtIndex) const {
618 //Return vertex position for mixed event, recover the vertex in a particular event.
620 //Int_t evtIndex = 0; // for single events only one vertex stored in position 0, default value
621 //if (fMixedEvent && clusterID >=0) {
622 // evtIndex=GetMixedEvent()->EventIndexForCaloCluster(clusterID) ;
625 vertex[0]=fVertex[evtIndex][0]; vertex[1]=fVertex[evtIndex][1]; vertex[2]=fVertex[evtIndex][2];
631 //____________________________________________________________________________
632 void AliCaloTrackReader::FillVertexArray() {
634 //Fill data member with vertex
635 //In case of Mixed event, multiple vertices
637 //Delete previous vertex
639 for (Int_t i = 0; i < fNMixedEvent; i++) {
640 delete [] fVertex[i] ;
645 fVertex = new Double_t*[fNMixedEvent] ;
646 for (Int_t i = 0; i < fNMixedEvent; i++) {
647 fVertex[i] = new Double_t[3] ;
648 fVertex[i][0] = 0.0 ;
649 fVertex[i][1] = 0.0 ;
650 fVertex[i][2] = 0.0 ;
653 if (!fMixedEvent) { //Single event analysis
656 if(fInputEvent->GetPrimaryVertex()){
657 fInputEvent->GetPrimaryVertex()->GetXYZ(fVertex[0]);
660 printf("AliCaloTrackReader::FillVertexArray() - NULL primary vertex\n");
661 fVertex[0][0]=0.; fVertex[0][1]=0.; fVertex[0][2]=0.;
662 }//Primary vertex pointer do not exist
664 } else {//MC read event
665 fVertex[0][0]=0.; fVertex[0][1]=0.; fVertex[0][2]=0.;
669 printf("AliCaloTrackReader::FillVertexArray() - Single Event Vertex : %f,%f,%f\n",fVertex[0][0],fVertex[0][1],fVertex[0][2]);
671 } else { // MultiEvent analysis
672 for (Int_t iev = 0; iev < fNMixedEvent; iev++) {
673 if (fMixedEvent->GetVertexOfEvent(iev))
674 fMixedEvent->GetVertexOfEvent(iev)->GetXYZ(fVertex[iev]);
675 else { // no vertex found !!!!
676 AliWarning("No vertex found");
680 printf("AliCaloTrackReader::FillVertexArray() - Multi Event %d Vertex : %f,%f,%f\n",iev,fVertex[iev][0],fVertex[iev][1],fVertex[iev][2]);
687 //____________________________________________________________________________
688 void AliCaloTrackReader::FillInputCTS() {
689 //Return array with Central Tracking System (CTS) tracks
691 if(fDebug > 2 ) printf("AliCaloTrackReader::FillInputCTS()\n");
693 Int_t nTracks = fInputEvent->GetNumberOfTracks() ;
697 for (Int_t itrack = 0; itrack < nTracks; itrack++) {////////////// track loop
698 AliVTrack * track = (AliVTrack*)fInputEvent->GetTrack(itrack) ; // retrieve track from esd
700 //Select tracks under certain conditions, TPCrefit, ITSrefit ... check the set bits
701 if (fTrackStatus && !((track->GetStatus() & fTrackStatus) == fTrackStatus))
706 if(fDataType==kESD && !fESDtrackCuts->AcceptTrack((AliESDtrack*)track)) continue;
708 // Track filter selection
709 //if (fTrackFilter) {
710 // selectInfo = fTrackFilter->IsSelected(esdTrack);
711 // if (!selectInfo && !(esd->GetPrimaryVertex())->UsesTrack(esdTrack->GetID())) continue;
714 //Count the tracks in eta < 0.9
715 //printf("Eta %f cut %f\n",TMath::Abs(track->Eta()),fTrackMultEtaCut);
716 if(TMath::Abs(track->Eta())< fTrackMultEtaCut) fTrackMult++;
718 track->GetPxPyPz(p) ;
719 TLorentzVector momentum(p[0],p[1],p[2],0);
721 if(fCTSPtMin < momentum.Pt()){
723 if(fCheckFidCut && !fFiducialCut->IsInFiducialCut(momentum,"CTS"))
726 if(fDebug > 2 && momentum.Pt() > 0.1)
727 printf("AliCaloTrackReader::FillInputCTS() - Selected tracks E %3.2f, pt %3.2f, phi %3.2f, eta %3.2f\n",
728 momentum.E(),momentum.Pt(),momentum.Phi()*TMath::RadToDeg(),momentum.Eta());
731 track->SetID(itrack);
736 }//Pt and Fiducial cut passed.
739 //fAODCTSNormalInputEntries = fAODCTS->GetEntriesFast();
741 printf("AliCaloTrackReader::FillInputCTS() - aod entries %d, input tracks %d, pass status %d, multipliticy %d\n", fAODCTS->GetEntriesFast(), nTracks, nstatus, fTrackMult);//fAODCTSNormalInputEntries);
743 // //If second input event available, add the clusters.
744 // if(fSecondInputAODTree && fSecondInputAODEvent){
745 // nTracks = fSecondInputAODEvent->GetNumberOfTracks() ;
746 // if(fDebug > 1) printf("AliCaloTrackReader::FillInputCTS() - Add second input tracks, entries %d\n", nTracks) ;
747 // for (Int_t itrack = 0; itrack < nTracks; itrack++) {////////////// track loop
748 // AliAODTrack * track = ((AliAODEvent*)fSecondInputAODEvent)->GetTrack(itrack) ; // retrieve track from esd
750 // //Select tracks under certain conditions, TPCrefit, ITSrefit ... check the set bits
751 // if (fTrackStatus && !((track->GetStatus() & fTrackStatus) == fTrackStatus)) continue ;
753 // track->GetPxPyPz(p) ;
754 // TLorentzVector momentum(p[0],p[1],p[2],0);
756 // if(fCTSPtMin < momentum.Pt()){
758 // if(fCheckFidCut && !fFiducialCut->IsInFiducialCut(momentum,"CTS")) continue;
760 // if(fDebug > 2 && momentum.Pt() > 0.1) printf("AliCaloTrackReader::FillInputCTS() - Selected tracks E %3.2f, pt %3.2f, phi %3.2f, eta %3.2f\n",
761 // momentum.E(),momentum.Pt(),momentum.Phi()*TMath::RadToDeg(),momentum.Eta());
763 // fAODCTS->Add(track);
765 // }//Pt and Fiducial cut passed.
768 // if(fDebug > 1) printf("AliCaloTrackReader::FillInputCTS() - aod normal entries %d, after second input %d\n", fAODCTSNormalInputEntries, fAODCTS->GetEntriesFast());
769 // } //second input loop
773 //____________________________________________________________________________
774 void AliCaloTrackReader::FillInputEMCALAlgorithm(AliVCluster * clus, const Int_t iclus) {
775 //Fill the EMCAL data in the array, do it
779 vindex = fMixedEvent->EventIndexForCaloCluster(iclus);
781 //Check if the cluster contains any bad channel and if close to calorimeter borders
782 if(GetCaloUtils()->ClusterContainsBadChannel("EMCAL",clus->GetCellsAbsId(), clus->GetNCells()))
784 if(!GetCaloUtils()->CheckCellFiducialRegion(clus, (AliVCaloCells*)fInputEvent->GetEMCALCells(), fInputEvent, vindex))
787 //Remove suspicious clusters
788 if(fRemoveSuspiciousClusters){
789 Int_t ncells = clus->GetNCells();
790 Float_t energy = clus->E();
791 Float_t minNCells = 1+energy/3;//-x*x*0.0033
792 if(ncells < minNCells) {
793 //if(energy > 2)printf("AliCaloTrackReader::FillInputEMCALAlgorithm() - Remove cluster: e %2.2f, Ncells %d, min Ncells %2.1f\n",energy,ncells,minNCells);
797 // if(energy > 2)printf("AliCaloTrackReader::FillInputEMCALAlgorithm() - Keep cluster: e %2.2f, Ncells %d, min Ncells %2.1f\n",energy,ncells,minNCells);
802 TLorentzVector momentum ;
804 clus->GetMomentum(momentum, fVertex[vindex]);
806 if(fEMCALPtMin < momentum.Pt()){
808 if(fCheckFidCut && !fFiducialCut->IsInFiducialCut(momentum,"EMCAL"))
811 if(fDebug > 2 && momentum.E() > 0.1)
812 printf("AliCaloTrackReader::FillInputEMCAL() - Selected clusters E %3.2f, pt %3.2f, phi %3.2f, eta %3.2f\n",
813 momentum.E(),momentum.Pt(),momentum.Phi()*TMath::RadToDeg(),momentum.Eta());
816 //clus->GetPosition(pos);
817 //printf("Before Corrections: e %f, x %f, y %f, z %f\n",clus->E(),pos[0],pos[1],pos[2]);
819 //Recalibrate the cluster energy
820 if(GetCaloUtils()->IsRecalibrationOn()) {
821 Float_t energy = GetCaloUtils()->RecalibrateClusterEnergy(clus, GetEMCALCells());
823 //printf("Recalibrated Energy %f\n",clus->E());
824 GetCaloUtils()->RecalculateClusterShowerShapeParameters(GetEMCALCells(),clus);
825 GetCaloUtils()->RecalculateClusterPID(clus);
829 //Recalculate distance to bad channels, if new list of bad channels provided
830 GetCaloUtils()->RecalculateClusterDistanceToBadChannel(GetEMCALCells(),clus);
832 //Recalculate cluster position
833 if(GetCaloUtils()->IsRecalculationOfClusterPositionOn()){
834 GetCaloUtils()->RecalculateClusterPosition(GetEMCALCells(),clus);
835 //clus->GetPosition(pos);
836 //printf("After Corrections: e %f, x %f, y %f, z %f\n",clus->E(),pos[0],pos[1],pos[2]);
839 //Correct non linearity
840 if(GetCaloUtils()->IsCorrectionOfClusterEnergyOn()){
841 GetCaloUtils()->CorrectClusterEnergy(clus) ;
842 //printf("Linearity Corrected Energy %f\n",clus->E());
845 //In case of MC analysis, to match resolution/calibration in real data
846 if(fSmearClusterEnergy){
847 Float_t energy = clus->E();
848 Float_t rdmEnergy = fRandom.Gaus(energy,fSmearClusterParam[0]*TMath::Sqrt(energy)+
849 fSmearClusterParam[1]*energy+fSmearClusterParam[2]);
850 clus->SetE(rdmEnergy);
851 if(fDebug > 2) printf("\t Energy %f, smeared %f\n", energy, clus->E());
857 fAODEMCAL->Add(clus);
861 //____________________________________________________________________________
862 void AliCaloTrackReader::FillInputEMCAL() {
863 //Return array with EMCAL clusters in aod format
865 if(fDebug > 2 ) printf("AliCaloTrackReader::FillInputEMCAL()\n");
867 //Loop to select clusters in fiducial cut and fill container with aodClusters
868 if(fEMCALClustersListName==""){
869 Int_t nclusters = fInputEvent->GetNumberOfCaloClusters();
870 for (Int_t iclus = 0; iclus < nclusters; iclus++) {
871 AliVCluster * clus = 0;
872 if ( (clus = fInputEvent->GetCaloCluster(iclus)) ) {
873 if (IsEMCALCluster(clus)){
874 FillInputEMCALAlgorithm(clus, iclus);
879 //Recalculate track matching
880 if(fDataType==kESD)GetCaloUtils()->RecalculateClusterTrackMatching(fInputEvent);
882 }//Get the clusters from the input event
884 TClonesArray * clusterList = dynamic_cast<TClonesArray*> (fOutputEvent->FindListObject(fEMCALClustersListName));
886 printf("AliCaloTrackReader::FillInputEMCAL() - Wrong name of list with clusters? <%s>\n",fEMCALClustersListName.Data());
889 Int_t nclusters = clusterList->GetEntriesFast();
890 for (Int_t iclus = 0; iclus < nclusters; iclus++) {
891 AliVCluster * clus = dynamic_cast<AliVCluster*> (clusterList->At(iclus));
892 //printf("E %f\n",clus->E());
893 if (clus) FillInputEMCALAlgorithm(clus, iclus);
894 else printf("AliCaloTrackReader::FillInputEMCAL() - Null cluster in list!\n");
898 //Recalculate track matching, not necessary, already done in the reclusterization task
899 //GetCaloUtils()->RecalculateClusterTrackMatching(fInputEvent,clusterList);
903 //fAODEMCALNormalInputEntries = fAODEMCAL->GetEntriesFast();
904 if(fDebug > 1) printf("AliCaloTrackReader::FillInputEMCAL() - aod entries %d\n", fAODEMCAL->GetEntriesFast());//fAODEMCALNormalInputEntries);
906 //If second input event available, add the clusters.
907 // if(fSecondInputAODTree && fSecondInputAODEvent){
908 // GetSecondInputAODVertex(v);
909 // nclusters = ((AliAODEvent*)fSecondInputAODEvent)->GetNumberOfCaloClusters();
910 // if(fDebug > 1) printf("AliCaloTrackReader::FillInputEMCAL() - Add second input clusters, entries %d\n", nclusters) ;
911 // for (Int_t iclus = 0; iclus < nclusters; iclus++) {
912 // AliAODCaloCluster * clus = 0;
913 // if ( (clus = ((AliAODEvent*)fSecondInputAODEvent)->GetCaloCluster(iclus)) ) {
914 // if (clus->IsEMCAL()){
915 // TLorentzVector momentum ;
916 // clus->GetMomentum(momentum, v);
918 // if(fEMCALPtMin < momentum.Pt()){
920 // if(fCheckFidCut && !fFiducialCut->IsInFiducialCut(momentum,"EMCAL")) continue;
922 // if(fDebug > 2 && momentum.E() > 0.1) printf("AliCaloTrackReader::FillInputEMCAL() - Selected clusters E %3.2f, pt %3.2f, phi %3.2f, eta %3.2f\n",
923 // momentum.E(),momentum.Pt(),momentum.Phi()*TMath::RadToDeg(),momentum.Eta());
924 // fAODEMCAL->Add(clus);
925 // }//Pt and Fiducial cut passed.
927 // }// cluster exists
930 // if(fDebug > 1) printf("AliCaloTrackReader::FillInputEMCAL() - aod normal entries %d, after second input %d\n", fAODEMCALNormalInputEntries, fAODEMCAL->GetEntriesFast());
932 // } //second input loop
935 //____________________________________________________________________________
936 void AliCaloTrackReader::FillInputPHOS() {
937 //Return array with PHOS clusters in aod format
939 if(fDebug > 2 ) printf("AliCaloTrackReader::FillInputPHOS()\n");
941 //Loop to select clusters in fiducial cut and fill container with aodClusters
942 Int_t nclusters = fInputEvent->GetNumberOfCaloClusters();
943 for (Int_t iclus = 0; iclus < nclusters; iclus++) {
944 AliVCluster * clus = 0;
945 if ( (clus = fInputEvent->GetCaloCluster(iclus)) ) {
946 if (IsPHOSCluster(clus)){
947 //Check if the cluster contains any bad channel and if close to calorimeter borders
950 vindex = fMixedEvent->EventIndexForCaloCluster(iclus);
951 if( GetCaloUtils()->ClusterContainsBadChannel("PHOS",clus->GetCellsAbsId(), clus->GetNCells()))
953 if(!GetCaloUtils()->CheckCellFiducialRegion(clus, fInputEvent->GetPHOSCells(), fInputEvent, vindex))
956 TLorentzVector momentum ;
958 clus->GetMomentum(momentum, fVertex[vindex]);
960 if(fPHOSPtMin < momentum.Pt()){
962 if(fCheckFidCut && !fFiducialCut->IsInFiducialCut(momentum,"PHOS"))
965 if(fDebug > 2 && momentum.E() > 0.1)
966 printf("AliCaloTrackReader::FillInputPHOS() - Selected clusters E %3.2f, pt %3.2f, phi %3.2f, eta %3.2f\n",
967 momentum.E(),momentum.Pt(),momentum.Phi()*TMath::RadToDeg(),momentum.Eta());
969 //Recalibrate the cluster energy
970 if(GetCaloUtils()->IsRecalibrationOn()) {
971 Float_t energy = GetCaloUtils()->RecalibrateClusterEnergy(clus, (AliAODCaloCells*)GetPHOSCells());
981 }//Pt and Fiducial cut passed.
986 //fAODPHOSNormalInputEntries = fAODPHOS->GetEntriesFast() ;
987 if(fDebug > 1) printf("AliCaloTrackReader::FillInputPHOS() - aod entries %d\n", fAODPHOS->GetEntriesFast());//fAODPHOSNormalInputEntries);
989 //If second input event available, add the clusters.
990 // if(fSecondInputAODTree && fSecondInputAODEvent){
991 // GetSecondInputAODVertex(v);
992 // nclusters = ((AliAODEvent*)fSecondInputAODEvent)->GetNumberOfCaloClusters();
993 // if(fDebug > 1) printf("AliCaloTrackReader::FillInputPHOS() - Add second input clusters, entries %d\n", nclusters);
994 // for (Int_t iclus = 0; iclus < nclusters; iclus++) {
995 // AliAODCaloCluster * clus = 0;
996 // if ( (clus = ((AliAODEvent*)fSecondInputAODEvent)->GetCaloCluster(iclus)) ) {
997 // if (clus->IsPHOS()){
998 // TLorentzVector momentum ;
999 // clus->GetMomentum(momentum, v);
1001 // if(fPHOSPtMin < momentum.Pt()){
1003 // if(fCheckFidCut && !fFiducialCut->IsInFiducialCut(momentum,"PHOS")) continue;
1005 // if(fDebug > 2 && momentum.E() > 0.1) printf("AliCaloTrackReader::FillInputPHOS() - Selected clusters E %3.2f, pt %3.2f, phi %3.2f, eta %3.2f\n",
1006 // momentum.E(),momentum.Pt(),momentum.Phi()*TMath::RadToDeg(),momentum.Eta());
1007 // fAODPHOS->Add(clus);
1008 // }//Pt and Fiducial cut passed.
1010 // }// cluster exists
1012 // if(fDebug > 1) printf("AliCaloTrackReader::FillInputPHOS() - aod normal entries %d, after second input %d\n", fAODPHOSNormalInputEntries, fAODPHOS->GetEntriesFast());
1013 // } //second input loop
1017 //____________________________________________________________________________
1018 void AliCaloTrackReader::FillInputEMCALCells() {
1019 //Return array with EMCAL cells in aod format
1021 fEMCALCells = fInputEvent->GetEMCALCells();
1025 //____________________________________________________________________________
1026 void AliCaloTrackReader::FillInputPHOSCells() {
1027 //Return array with PHOS cells in aod format
1029 fPHOSCells = fInputEvent->GetPHOSCells();
1034 //____________________________________________________________________________
1035 Bool_t AliCaloTrackReader::IsEMCALCluster(AliVCluster* cluster) const {
1036 // Check if it is a cluster from EMCAL. For old AODs cluster type has
1037 // different number and need to patch here
1039 if(fDataType==kAOD && fOldAOD)
1041 if (cluster->GetType() == 2) return kTRUE;
1046 return cluster->IsEMCAL();
1051 //____________________________________________________________________________
1052 Bool_t AliCaloTrackReader::IsPHOSCluster(AliVCluster * cluster) const {
1053 //Check if it is a cluster from PHOS.For old AODs cluster type has
1054 // different number and need to patch here
1056 if(fDataType==kAOD && fOldAOD)
1058 Int_t type = cluster->GetType();
1059 if (type == 0 || type == 1) return kTRUE;
1064 return cluster->IsPHOS();
1069 //____________________________________________________________________________
1070 Bool_t AliCaloTrackReader::CheckForPrimaryVertex(){
1071 //Check if the vertex was well reconstructed, copy from V0Reader of conversion group
1074 AliESDEvent * event = dynamic_cast<AliESDEvent*> (fInputEvent);
1075 if(!event) return kFALSE;
1077 if(event->GetPrimaryVertexTracks()->GetNContributors() > 0) {
1081 if(event->GetPrimaryVertexTracks()->GetNContributors() < 1) {
1083 if(event->GetPrimaryVertexSPD()->GetNContributors() > 0) {
1084 //cout<<"spd vertex type::"<< fESDEvent->GetPrimaryVertex()->GetName() << endl;
1088 if(event->GetPrimaryVertexSPD()->GetNContributors() < 1) {
1089 // cout<<"bad vertex type::"<< event->GetPrimaryVertex()->GetName() << endl;