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 **************************************************************************/
16 //_________________________________________________________________________
17 // Base class for reading data: MonteCarlo, ESD or AOD, of PHOS EMCAL and
18 // Central Barrel Tracking detectors (CTS).
19 // Not all MC particles/tracks/clusters are kept, some kinematical/fiducial restrictions are done.
20 // Mother class of : AliCaloTrackESDReader: Fills ESD data in 3 TObjArrays (PHOS, EMCAL, CTS)
21 // : AliCaloTrackMCReader : Fills Kinematics data in 3 TObjArrays (PHOS, EMCAL, CTS)
22 // : AliCaloTrackAODReader: Fills AOD data in 3 TObjArrays (PHOS, EMCAL, CTS)
23 //-- Author: Gustavo Conesa (LNF-INFN)
24 //////////////////////////////////////////////////////////////////////////////
27 // --- ROOT system ---
29 #include <TGeoManager.h>
31 // ---- ANALYSIS system ----
32 #include "AliMCEvent.h"
33 #include "AliAODMCHeader.h"
34 #include "AliGenPythiaEventHeader.h"
35 #include "AliESDEvent.h"
36 #include "AliAODEvent.h"
37 #include "AliVTrack.h"
38 #include "AliVParticle.h"
39 #include "AliMixedEvent.h"
40 #include "AliESDtrack.h"
41 #include "AliESDtrackCuts.h"
42 #include "AliTriggerAnalysis.h"
43 #include "AliESDVZERO.h"
44 #include "AliVCaloCells.h"
45 #include "AliAnalysisManager.h"
46 #include "AliInputEventHandler.h"
48 // ---- Detectors ----
49 #include "AliPHOSGeoUtils.h"
50 #include "AliEMCALGeometry.h"
51 #include "AliEMCALRecoUtils.h"
53 // ---- CaloTrackCorr ---
54 #include "AliCalorimeterUtils.h"
55 #include "AliCaloTrackReader.h"
57 ClassImp(AliCaloTrackReader)
60 //________________________________________
61 AliCaloTrackReader::AliCaloTrackReader() :
62 TObject(), fEventNumber(-1), //fCurrentFileName(""),
63 fDataType(0), fDebug(0),
64 fFiducialCut(0x0), fCheckFidCut(kFALSE),
65 fComparePtHardAndJetPt(0), fPtHardAndJetPtFactor(0),
66 fCTSPtMin(0), fEMCALPtMin(0), fPHOSPtMin(0),
67 fCTSPtMax(0), fEMCALPtMax(0), fPHOSPtMax(0),
68 fEMCALTimeCutMin(-10000), fEMCALTimeCutMax(10000),
70 fCTSTracks(0x0), fEMCALClusters(0x0), fPHOSClusters(0x0),
71 fEMCALCells(0x0), fPHOSCells(0x0),
72 fInputEvent(0x0), fOutputEvent(0x0),fMC(0x0),
73 fFillCTS(0), fFillEMCAL(0), fFillPHOS(0),
74 fFillEMCALCells(0), fFillPHOSCells(0),
75 fRecalculateClusters(kFALSE),fSelectEmbeddedClusters(kFALSE),
76 fTrackStatus(0), fTrackFilterMask(0),
77 fESDtrackCuts(0), fConstrainTrack(kFALSE), fSelectHybridTracks(0),
78 fTrackMult(0), fTrackMultEtaCut(0.8),
79 fReadStack(kFALSE), fReadAODMCParticles(kFALSE),
80 fDeltaAODFileName(""), fFiredTriggerClassName(""),
81 fEventTriggerMask(0), fEventTriggerAtSE(0),
83 fTaskName(""), fCaloUtils(0x0),
84 fMixedEvent(NULL), fNMixedEvent(0), fVertex(NULL),
85 fListMixedTracksEvents(), //fListMixedPhotonsEvents(),
86 fLastMixedTracksEvent(-1), //fLastMixedPhotonsEvent(-1),
87 fWriteOutputDeltaAOD(kFALSE),fOldAOD(kFALSE), fCaloFilterPatch(kFALSE),
88 fEMCALClustersListName(""), fZvtxCut(0.),
89 fAcceptFastCluster(kFALSE), fRemoveLEDEvents(kTRUE),
90 fDoEventSelection(kFALSE), fDoV0ANDEventSelection(kFALSE), fUseEventsWithPrimaryVertex(kFALSE),
91 fTriggerAnalysis (0x0),
92 fCentralityClass(""), fCentralityOpt(0),
93 fEventPlaneMethod(""), fImportGeometryFromFile(kFALSE), fImportGeometryFilePath("")
97 //Initialize parameters
101 //_______________________________________
102 AliCaloTrackReader::~AliCaloTrackReader()
106 delete fFiducialCut ;
110 fAODBranchList->Delete();
111 delete fAODBranchList ;
116 if(fDataType!=kMC)fCTSTracks->Clear() ;
117 else fCTSTracks->Delete() ;
123 if(fDataType!=kMC)fEMCALClusters->Clear("C") ;
124 else fEMCALClusters->Delete() ;
125 delete fEMCALClusters ;
130 if(fDataType!=kMC)fPHOSClusters->Clear("C") ;
131 else fPHOSClusters->Delete() ;
132 delete fPHOSClusters ;
137 for (Int_t i = 0; i < fNMixedEvent; i++)
139 delete [] fVertex[i] ;
145 delete fESDtrackCuts;
146 delete fTriggerAnalysis;
148 // Pointers not owned, done by the analysis frame
149 // if(fInputEvent) delete fInputEvent ;
150 // if(fOutputEvent) delete fOutputEvent ;
151 // if(fMC) delete fMC ;
152 // Pointer not owned, deleted by maker
153 // if (fCaloUtils) delete fCaloUtils ;
157 //________________________________________________
158 Bool_t AliCaloTrackReader::ComparePtHardAndJetPt()
160 // Check the event, if the requested ptHard is much larger than the jet pT, then there is a problem.
162 if(!fReadStack) return kTRUE; //Information not filtered to AOD
164 if(!strcmp(GetGenEventHeader()->ClassName(), "AliGenPythiaEventHeader"))
167 AliGenPythiaEventHeader* pygeh= (AliGenPythiaEventHeader*) GetGenEventHeader();
168 Int_t nTriggerJets = pygeh->NTriggerJets();
169 Float_t ptHard = pygeh->GetPtHard();
171 //if(fDebug > 1) printf("AliMCAnalysisUtils::PythiaEventHeader: Njets: %d, pT Hard %f\n",nTriggerJets, ptHard);
172 Float_t tmpjet[]={0,0,0,0};
173 for(Int_t ijet = 0; ijet< nTriggerJets; ijet++)
175 pygeh->TriggerJet(ijet, tmpjet);
176 jet = new TParticle(94, 21, -1, -1, -1, -1, tmpjet[0],tmpjet[1],tmpjet[2],tmpjet[3], 0,0,0,0);
177 //Compare jet pT and pt Hard
178 //if(fDebug > 1) printf("AliMCAnalysisUtils:: %d pycell jet pT %f\n",ijet, jet->Pt());
179 if(jet->Pt() > fPtHardAndJetPtFactor * ptHard)
181 printf("AliMCAnalysisUtils::PythiaEventHeader: Njets: %d, pT Hard %2.2f, pycell jet pT %2.2f, rejection factor %1.1f\n",
182 nTriggerJets, ptHard, jet->Pt(), fPtHardAndJetPtFactor);
193 //____________________________________________
194 AliStack* AliCaloTrackReader::GetStack() const
196 //Return pointer to stack
201 if(fDebug > 1) printf("AliCaloTrackReader::GetStack() - Stack is not available\n");
206 //__________________________________________________
207 TString AliCaloTrackReader::GetFiredTriggerClasses()
209 // List of triggered classes in a TString
211 AliESDEvent* esdevent = dynamic_cast<AliESDEvent*> (GetInputEvent());
212 AliAODEvent* aodevent = dynamic_cast<AliAODEvent*> (GetInputEvent());
214 if (esdevent) return esdevent->GetFiredTriggerClasses();
215 else if(aodevent) return aodevent->GetFiredTriggerClasses();
216 else return ""; // Mixed Event, MC event, does not have this trigger info
220 //______________________________________________
221 AliHeader* AliCaloTrackReader::GetHeader() const
223 //Return pointer to header
226 return fMC->Header();
230 printf("AliCaloTrackReader::Header is not available\n");
235 //______________________________________________________________
236 AliGenEventHeader* AliCaloTrackReader::GetGenEventHeader() const
238 //Return pointer to Generated event header
241 return fMC->GenEventHeader();
245 printf("AliCaloTrackReader::GenEventHeader is not available\n");
250 //____________________________________________________________________
251 TClonesArray* AliCaloTrackReader::GetAODMCParticles(Int_t input) const
253 //Return list of particles in AOD. Do it for the corresponding input event.
255 TClonesArray * rv = NULL ;
256 if(fDataType == kAOD)
261 AliAODEvent * evt = dynamic_cast<AliAODEvent*> (fInputEvent) ;
263 rv = (TClonesArray*)evt->FindListObject("mcparticles");
265 printf("AliCaloTrackReader::GetAODMCParticles() - wrong AOD input index? %d, or non existing tree? \n",input);
271 printf("AliCaloTrackReader::GetAODMCParticles() - Input are not AODs\n");
277 //___________________________________________________________________
278 AliAODMCHeader* AliCaloTrackReader::GetAODMCHeader(Int_t input) const
280 //Return MC header in AOD. Do it for the corresponding input event.
282 AliAODMCHeader *mch = NULL;
284 if(fDataType == kAOD)
289 mch = (AliAODMCHeader*)((AliAODEvent*)fInputEvent)->FindListObject("mcheader");
293 printf("AliCaloTrackReader::GetAODMCHeader() - wrong AOD input index, %d\n",input);
298 printf("AliCaloTrackReader::GetAODMCHeader() - Input are not AODs\n");
304 //_____________________________
305 void AliCaloTrackReader::Init()
307 //Init reader. Method to be called in AliAnaPartCorrMaker
309 //printf(" AliCaloTrackReader::Init() %p \n",gGeoManager);
311 if(fReadStack && fReadAODMCParticles)
313 printf("AliCaloTrackReader::Init() - Cannot access stack and mcparticles at the same time, change them \n");
315 fReadAODMCParticles = kFALSE;
318 // Init geometry, I do not like much to do it like this ...
319 if(fImportGeometryFromFile && !gGeoManager)
321 if(fImportGeometryFilePath=="") // If not specified, set a default location
322 fImportGeometryFilePath = "$ALICE_ROOT/PWGGA/EMCALTasks/macros/geometry.root"; // "$ALICE_ROOT/EVE/alice-data/default_geo.root"
324 printf("AliCaloTrackReader::Init() - Import %s\n",fImportGeometryFilePath.Data());
325 TGeoManager::Import(fImportGeometryFilePath) ; // default need file "geometry.root" in local dir!!!!
330 //_______________________________________
331 void AliCaloTrackReader::InitParameters()
333 //Initialize the parameters of the analysis.
339 fEMCALPtMax = 1000. ;
342 //Do not filter the detectors input by default.
346 fFillEMCALCells = kFALSE;
347 fFillPHOSCells = kFALSE;
349 fReadStack = kFALSE; // Check in the constructor of the other readers if it was set or in the configuration file
350 fReadAODMCParticles = kFALSE; // Check in the constructor of the other readers if it was set or in the configuration file
351 fDeltaAODFileName = "deltaAODPartCorr.root";
352 fFiredTriggerClassName = "";
353 fEventTriggerMask = AliVEvent::kAny;
354 fEventTriggerAtSE = kTRUE; // Use only events that pass event selection at SE base class
356 fAcceptFastCluster = kTRUE;
359 //We want tracks fitted in the detectors:
360 //fTrackStatus=AliESDtrack::kTPCrefit;
361 //fTrackStatus|=AliESDtrack::kITSrefit;
363 fTrackFilterMask = 128; //For AODs, but what is the difference between fTrackStatus and fTrackFilterMask?
365 fESDtrackCuts = AliESDtrackCuts::GetStandardTPCOnlyTrackCuts(); //initialize with TPC only tracks
367 fConstrainTrack = kFALSE ; // constrain tracks to vertex
369 fV0ADC[0] = 0; fV0ADC[1] = 0;
370 fV0Mul[0] = 0; fV0Mul[1] = 0;
376 fPtHardAndJetPtFactor = 7;
379 fCentralityClass = "V0M";
381 fCentralityBin[0] = fCentralityBin[1]=-1;
383 fEventPlaneMethod = "V0";
385 // Allocate memory (not sure this is the right place)
386 fCTSTracks = new TObjArray();
387 fEMCALClusters = new TObjArray();
388 fPHOSClusters = new TObjArray();
389 fTriggerAnalysis = new AliTriggerAnalysis;
390 fAODBranchList = new TList ;
392 fImportGeometryFromFile = kFALSE;
396 //________________________________________________________
397 void AliCaloTrackReader::Print(const Option_t * opt) const
400 //Print some relevant parameters set for the analysis
404 printf("***** Print: %s %s ******\n", GetName(), GetTitle() ) ;
405 printf("Task name : %s\n", fTaskName.Data()) ;
406 printf("Data type : %d\n", fDataType) ;
407 printf("CTS Min pT : %2.1f GeV/c\n", fCTSPtMin) ;
408 printf("EMCAL Min pT : %2.1f GeV/c\n", fEMCALPtMin) ;
409 printf("PHOS Min pT : %2.1f GeV/c\n", fPHOSPtMin) ;
410 printf("CTS Max pT : %2.1f GeV/c\n", fCTSPtMax) ;
411 printf("EMCAL Max pT : %2.1f GeV/c\n", fEMCALPtMax) ;
412 printf("PHOS Max pT : %2.1f GeV/c\n", fPHOSPtMax) ;
413 printf("EMCAL Time Cut: %3.1f < TOF < %3.1f\n", fEMCALTimeCutMin, fEMCALTimeCutMax);
414 printf("Use CTS = %d\n", fFillCTS) ;
415 printf("Use EMCAL = %d\n", fFillEMCAL) ;
416 printf("Use PHOS = %d\n", fFillPHOS) ;
417 printf("Use EMCAL Cells = %d\n", fFillEMCALCells) ;
418 printf("Use PHOS Cells = %d\n", fFillPHOSCells) ;
419 printf("Track status = %d\n", (Int_t) fTrackStatus) ;
420 printf("AODs Track filter mask = %d or hybrid %d\n", (Int_t) fTrackFilterMask,fSelectHybridTracks) ;
421 printf("Track Mult Eta Cut = %d\n", (Int_t) fTrackMultEtaCut) ;
422 printf("Write delta AOD = %d\n", fWriteOutputDeltaAOD) ;
423 printf("Recalculate Clusters = %d\n", fRecalculateClusters) ;
425 printf("Use Triggers selected in SE base class %d; If not what trigger Mask %d? \n",
426 fEventTriggerAtSE, fEventTriggerMask);
428 if(fComparePtHardAndJetPt)
429 printf("Compare jet pt and pt hard to accept event, factor = %2.2f",fPtHardAndJetPtFactor);
431 printf("Read Kine from, stack? %d, AOD ? %d \n", fReadStack, fReadAODMCParticles) ;
432 printf("Delta AOD File Name = %s\n", fDeltaAODFileName.Data()) ;
433 printf("Centrality: Class %s, Option %d, Bin [%d,%d] \n", fCentralityClass.Data(),fCentralityOpt,fCentralityBin[0], fCentralityBin[1]) ;
439 //_________________________________________________________________________
440 Bool_t AliCaloTrackReader::FillInputEvent(const Int_t iEntry,
441 const char * /*currentFileName*/)
443 //Fill the event counter and input lists that are needed, called by the analysis maker.
445 fEventNumber = iEntry;
446 //fCurrentFileName = TString(currentFileName);
449 if(fDebug >= 0) printf("AliCaloTrackReader::FillInputEvent() - Input event not available, skip event analysis\n");
453 //Select events only fired by a certain trigger configuration if it is provided
455 if(fInputEvent->GetHeader())
456 eventType = ((AliVHeader*)fInputEvent->GetHeader())->GetEventType();
458 if (GetFiredTriggerClasses().Contains("FAST") && !GetFiredTriggerClasses().Contains("ALL") && !fAcceptFastCluster)
460 if(fDebug > 0) printf("AliCaloTrackReader::FillInputEvent - Do not count events from fast cluster, trigger name %s\n",fFiredTriggerClassName.Data());
464 //-------------------------------------------------------------------------------------
465 // Reject event if large clusters with large energy
466 // Use only for LHC11a data for the moment, and if input is clusterizer V1 or V1+unfolding
467 // If clusterzer NxN or V2 it does not help
468 //-------------------------------------------------------------------------------------
469 Int_t run = fInputEvent->GetRunNumber();
470 if( fRemoveLEDEvents && run > 140000 && run <= 146860 )
472 //printf("Event %d\n",GetEventNumber());
473 for (Int_t i = 0; i < fInputEvent->GetNumberOfCaloClusters(); i++)
475 AliVCluster *clus = fInputEvent->GetCaloCluster(i);
478 if ((clus->E() > 500 && clus->GetNCells() > 200 ) || clus->GetNCells() > 200)
480 Int_t absID = clus->GetCellsAbsId()[0];
481 Int_t sm = GetCaloUtils()->GetEMCALGeometry()->GetSuperModuleNumber(absID);
482 if(fDebug > 0) printf("AliCaloTrackReader::FillInputEvent - reject event %d with cluster : E %f, ncells %d, absId(0) %d, SM %d\n",GetEventNumber(),clus->E(), clus->GetNCells(),absID, sm);
488 // Count number of cells with energy larger than 0.1 in SM3, cut on this number
491 for(Int_t icell = 0; icell < fInputEvent->GetEMCALCells()->GetNumberOfCells(); icell++)
493 Int_t absID = fInputEvent->GetEMCALCells()->GetCellNumber(icell);
494 Int_t sm = GetCaloUtils()->GetEMCALGeometry()->GetSuperModuleNumber(absID);
495 if(fInputEvent->GetEMCALCells()->GetAmplitude(icell) > 0.1 && sm==3) ncellsSM3++;
496 if(fInputEvent->GetEMCALCells()->GetAmplitude(icell) > 0.1 && sm==4) ncellsSM4++;
500 if(fFiredTriggerClassName.Contains("EMC")) ncellcut = 35;
502 if(ncellsSM3 >= ncellcut || ncellsSM4 >= 100)
504 if(fDebug > 0) printf(" AliCaloTrackReader::FillInputEvent() - reject event with ncells in SM3 %d and SM4 %d\n",ncellsSM3, ncellsSM4);
507 }// Remove LED events
509 // Reject pure LED events?
510 if( fFiredTriggerClassName !="" && !fAnaLED)
512 //printf("Event type %d\n",eventType);
514 return kFALSE; //Only physics event, do not use for simulated events!!!
517 printf("AliCaloTrackReader::FillInputEvent() - FiredTriggerClass <%s>, selected class <%s>, compare name %d\n",
518 GetFiredTriggerClasses().Data(),fFiredTriggerClassName.Data(), GetFiredTriggerClasses().Contains(fFiredTriggerClassName));
520 if( !GetFiredTriggerClasses().Contains(fFiredTriggerClassName) ) return kFALSE;
521 else if(fDebug > 0) printf("AliCaloTrackReader::FillInputEvent() - Accepted triggered event\n");
525 // kStartOfRun = 1, // START_OF_RUN
526 // kEndOfRun = 2, // END_OF_RUN
527 // kStartOfRunFiles = 3, // START_OF_RUN_FILES
528 // kEndOfRunFiles = 4, // END_OF_RUN_FILES
529 // kStartOfBurst = 5, // START_OF_BURST
530 // kEndOfBurst = 6, // END_OF_BURST
531 // kPhysicsEvent = 7, // PHYSICS_EVENT
532 // kCalibrationEvent = 8, // CALIBRATION_EVENT
533 // kFormatError = 9, // EVENT_FORMAT_ERROR
534 // kStartOfData = 10, // START_OF_DATA
535 // kEndOfData = 11, // END_OF_DATA
536 // kSystemSoftwareTriggerEvent = 12, // SYSTEM_SOFTWARE_TRIGGER_EVENT
537 // kDetectorSoftwareTriggerEvent = 13 // DETECTOR_SOFTWARE_TRIGGER_EVENT
539 if(eventType!=7 && fDebug > 1 )printf("AliCaloTrackReader::FillInputEvent() - DO LED, Event Type <%d>, 8 Calibration \n", eventType);
540 if(eventType!=8)return kFALSE;
543 //In case of analysis of events with jets, skip those with jet pt > 5 pt hard
544 if(fComparePtHardAndJetPt && GetStack())
546 if(!ComparePtHardAndJetPt()) return kFALSE ;
551 //Reject events with Z vertex too large, only for SE analysis, if not, cut on the analysis code
552 if(!GetMixedEvent() && TMath::Abs(fVertex[0][2]) > fZvtxCut) return kFALSE;
554 //------------------------------------------------------
555 //Event rejection depending on vertex, pileup, v0and
556 //------------------------------------------------------
558 if(fUseEventsWithPrimaryVertex)
560 if( !CheckForPrimaryVertex() ) return kFALSE;
561 if( TMath::Abs(fVertex[0][0] ) < 1.e-6 &&
562 TMath::Abs(fVertex[0][1] ) < 1.e-6 &&
563 TMath::Abs(fVertex[0][2] ) < 1.e-6 ) return kFALSE;
566 if(fDoEventSelection)
568 if(!fCaloFilterPatch)
570 //Do not analyze events with pileup
571 Bool_t bPileup = fInputEvent->IsPileupFromSPD(3, 0.8, 3., 2., 5.); //Default values, if not it does not compile
572 //Bool_t bPileup = event->IsPileupFromSPD();
573 if(bPileup) return kFALSE;
575 if(fDoV0ANDEventSelection)
577 Bool_t bV0AND = kTRUE;
578 AliESDEvent* esd = dynamic_cast<AliESDEvent*> (fInputEvent);
580 bV0AND = fTriggerAnalysis->IsOfflineTriggerFired(esd, AliTriggerAnalysis::kV0AND);
581 //else bV0AND = //FIXME FOR AODs
582 if(!bV0AND) return kFALSE;
587 if(fInputEvent->GetNumberOfCaloClusters() > 0)
589 AliVCluster * calo = fInputEvent->GetCaloCluster(0);
590 if(calo->GetNLabels() == 4)
592 Int_t * selection = calo->GetLabels();
593 Bool_t bPileup = selection[0];
594 if(bPileup) return kFALSE;
596 Bool_t bGoodV = selection[1];
597 if(fUseEventsWithPrimaryVertex && !bGoodV) return kFALSE;
599 if(fDoV0ANDEventSelection)
601 Bool_t bV0AND = selection[2];
602 if(!bV0AND) return kFALSE;
605 fTrackMult = selection[3];
606 if(fTrackMult == 0) return kFALSE;
610 //First filtered AODs, track multiplicity stored there.
611 fTrackMult = (Int_t) ((AliAODHeader*)fInputEvent->GetHeader())->GetCentrality();
612 if(fTrackMult == 0) return kFALSE;
614 }//at least one cluster
617 //printf("AliCaloTrackReader::FillInputEvent() - No clusters in event\n");
618 //Remove events with vertex (0,0,0), bad vertex reconstruction
619 if(fUseEventsWithPrimaryVertex && TMath::Abs(fVertex[0][0]) < 1.e-6 && TMath::Abs(fVertex[0][1]) < 1.e-6 && TMath::Abs(fVertex[0][2]) < 1.e-6) return kFALSE;
621 //First filtered AODs, track multiplicity stored there.
622 fTrackMult = (Int_t) ((AliAODHeader*)fInputEvent->GetHeader())->GetCentrality();
623 if(fTrackMult == 0) return kFALSE;
625 }// CaloFileter patch
627 //------------------------------------------------------
629 //Check if there is a centrality value, PbPb analysis, and if a centrality bin selection is requested
630 //If we need a centrality bin, we select only those events in the corresponding bin.
631 if(GetCentrality() && fCentralityBin[0]>=0 && fCentralityBin[1]>=0 && fCentralityOpt==100)
633 Int_t cen = GetEventCentrality();
634 if(cen > fCentralityBin[1] || cen < fCentralityBin[0]) return kFALSE; //reject events out of bin.
637 //Fill the arrays with cluster/tracks/cells data
640 FillInputEMCALCells();
643 FillInputPHOSCells();
647 if(fEventTriggerAtSE)
652 //Accept events with at least one track
653 if(fTrackMult == 0 && fDoEventSelection) return kFALSE;
662 // In case of mixing analysis, all triggers accepted, but trigger particles selected
663 // only for the specific trigered events selected here. Mixing done only for MB events,
664 // tracks array filled also for those events and not the others.
666 AliAnalysisManager *manager = AliAnalysisManager::GetAnalysisManager();
667 AliInputEventHandler *inputHandler = dynamic_cast<AliInputEventHandler*>(manager->GetInputEventHandler());
669 if(!inputHandler) return kFALSE ; // to content coverity
671 UInt_t isTrigger = inputHandler->IsEventSelected() & fEventTriggerMask;
672 UInt_t isMB = inputHandler->IsEventSelected() & AliVEvent::kMB;
674 if(fFillCTS && (isMB || isTrigger))
677 //Accept events with at least one track
678 if(fTrackMult == 0 && fDoEventSelection) return kFALSE;
693 //___________________________________
694 void AliCaloTrackReader::ResetLists()
696 // Reset lists, called by the analysis maker
698 if(fCTSTracks) fCTSTracks -> Clear();
699 if(fEMCALClusters) fEMCALClusters -> Clear("C");
700 if(fPHOSClusters) fPHOSClusters -> Clear("C");
702 fV0ADC[0] = 0; fV0ADC[1] = 0;
703 fV0Mul[0] = 0; fV0Mul[1] = 0;
707 //____________________________________________________________
708 void AliCaloTrackReader::SetInputEvent(AliVEvent* const input)
711 fMixedEvent = dynamic_cast<AliMixedEvent*>(GetInputEvent()) ;
713 fNMixedEvent = fMixedEvent->GetNumberOfEvents() ;
715 //Delete previous vertex
718 for (Int_t i = 0; i < fNMixedEvent; i++)
720 delete [] fVertex[i] ;
725 fVertex = new Double_t*[fNMixedEvent] ;
726 for (Int_t i = 0; i < fNMixedEvent; i++)
728 fVertex[i] = new Double_t[3] ;
729 fVertex[i][0] = 0.0 ;
730 fVertex[i][1] = 0.0 ;
731 fVertex[i][2] = 0.0 ;
735 //__________________________________________________
736 Int_t AliCaloTrackReader::GetEventCentrality() const
738 //Return current event centrality
742 if (fCentralityOpt==100) return (Int_t) GetCentrality()->GetCentralityPercentile(fCentralityClass); // 100 bins max
743 else if(fCentralityOpt==10) return GetCentrality()->GetCentralityClass10(fCentralityClass);// 10 bins max
744 else if(fCentralityOpt==20) return GetCentrality()->GetCentralityClass5(fCentralityClass); // 20 bins max
747 printf("AliCaloTrackReader::GetEventCentrality() - Unknown centrality option %d, use 10, 20 or 100\n",fCentralityOpt);
755 //_____________________________________________________
756 Double_t AliCaloTrackReader::GetEventPlaneAngle() const
758 //Return current event centrality
762 Float_t ep = GetEventPlane()->GetEventplane(GetEventPlaneMethod(), GetInputEvent());
764 if(GetEventPlaneMethod()=="Q" && (ep < 0 || ep > TMath::Pi()))
766 printf("AliCaloTrackReader::GetEventPlaneAngle() - Bad EP for <Q> method : %f\n",ep);
769 else if(GetEventPlaneMethod().Contains("V0") )
771 if((ep > TMath::Pi()/2 || ep < -TMath::Pi()/2))
773 printf("AliCaloTrackReader::GetEventPlaneAngle() - Bad EP for <%s> method : %f\n",GetEventPlaneMethod().Data(), ep);
777 ep+=TMath::Pi()/2; // put same range as for <Q> method
781 //printf("AliCaloTrackReader::GetEventPlaneAngle() = %f\n",ep);
782 if (ep > TMath::Pi()) printf("AliCaloTrackReader::GetEventPlaneAngle() - Too large angle = %f\n",ep);
783 else if(ep < 0 ) printf("AliCaloTrackReader::GetEventPlaneAngle() - Negative angle = %f\n" ,ep);
789 printf("AliCaloTrackReader::GetEventPlaneAngle() - No EP pointer\n");
795 //__________________________________________________________
796 void AliCaloTrackReader::GetVertex(Double_t vertex[3]) const
798 //Return vertex position to be used for single event analysis
799 vertex[0]=fVertex[0][0];
800 vertex[1]=fVertex[0][1];
801 vertex[2]=fVertex[0][2];
804 //____________________________________________________________
805 void AliCaloTrackReader::GetVertex(Double_t vertex[3],
806 const Int_t evtIndex) const
808 //Return vertex position for mixed event, recover the vertex in a particular event.
810 vertex[0]=fVertex[evtIndex][0]; vertex[1]=fVertex[evtIndex][1]; vertex[2]=fVertex[evtIndex][2];
814 //________________________________________
815 void AliCaloTrackReader::FillVertexArray()
818 //Fill data member with vertex
819 //In case of Mixed event, multiple vertices
821 //Delete previous vertex
824 for (Int_t i = 0; i < fNMixedEvent; i++)
826 delete [] fVertex[i] ;
831 fVertex = new Double_t*[fNMixedEvent] ;
832 for (Int_t i = 0; i < fNMixedEvent; i++)
834 fVertex[i] = new Double_t[3] ;
835 fVertex[i][0] = 0.0 ;
836 fVertex[i][1] = 0.0 ;
837 fVertex[i][2] = 0.0 ;
841 { //Single event analysis
845 if(fInputEvent->GetPrimaryVertex())
847 fInputEvent->GetPrimaryVertex()->GetXYZ(fVertex[0]);
851 printf("AliCaloTrackReader::FillVertexArray() - NULL primary vertex\n");
852 fVertex[0][0]=0.; fVertex[0][1]=0.; fVertex[0][2]=0.;
853 }//Primary vertex pointer do not exist
857 fVertex[0][0]=0.; fVertex[0][1]=0.; fVertex[0][2]=0.;
861 printf("AliCaloTrackReader::FillVertexArray() - Single Event Vertex : %f,%f,%f\n",fVertex[0][0],fVertex[0][1],fVertex[0][2]);
864 { // MultiEvent analysis
865 for (Int_t iev = 0; iev < fNMixedEvent; iev++)
867 if (fMixedEvent->GetVertexOfEvent(iev))
868 fMixedEvent->GetVertexOfEvent(iev)->GetXYZ(fVertex[iev]);
870 { // no vertex found !!!!
871 AliWarning("No vertex found");
875 printf("AliCaloTrackReader::FillVertexArray() - Multi Event %d Vertex : %f,%f,%f\n",iev,fVertex[iev][0],fVertex[iev][1],fVertex[iev][2]);
882 //_____________________________________
883 void AliCaloTrackReader::FillInputCTS()
885 //Return array with Central Tracking System (CTS) tracks
887 if(fDebug > 2 ) printf("AliCaloTrackReader::FillInputCTS()\n");
889 Double_t pTrack[3] = {0,0,0};
891 Int_t nTracks = fInputEvent->GetNumberOfTracks() ;
895 for (Int_t itrack = 0; itrack < nTracks; itrack++)
896 {////////////// track loop
897 AliVTrack * track = (AliVTrack*)fInputEvent->GetTrack(itrack) ; // retrieve track from esd
899 //Select tracks under certain conditions, TPCrefit, ITSrefit ... check the set bits
900 if (fTrackStatus && !((track->GetStatus() & fTrackStatus) == fTrackStatus))
907 AliESDtrack* esdTrack = dynamic_cast<AliESDtrack*> (track);
909 if(esdTrack && fESDtrackCuts->AcceptTrack(esdTrack))
911 track->GetPxPyPz(pTrack) ;
915 if(esdTrack->GetConstrainedParam())
917 const AliExternalTrackParam* constrainParam = esdTrack->GetConstrainedParam();
918 esdTrack->Set(constrainParam->GetX(),constrainParam->GetAlpha(),constrainParam->GetParameter(),constrainParam->GetCovariance());
919 esdTrack->GetConstrainedPxPyPz(pTrack);
923 } // use constrained tracks
929 else if(fDataType==kAOD)
931 AliAODTrack *aodtrack = dynamic_cast <AliAODTrack*>(track);
935 if(fDebug > 2 ) printf("AliCaloTrackReader::FillInputCTS():AOD track type: %d (primary %d), hybrid? %d \n",
936 aodtrack->GetType(),AliAODTrack::kPrimary,
937 aodtrack->IsHybridGlobalConstrainedGlobal());
940 if (fSelectHybridTracks)
942 if (!aodtrack->IsHybridGlobalConstrainedGlobal()) continue ;
946 if ( aodtrack->TestFilterBit(fTrackFilterMask)==kFALSE) continue ;
949 if (aodtrack->GetType()!= AliAODTrack::kPrimary) continue ;
951 if (fDebug > 2 ) printf("AliCaloTrackReader::FillInputCTS(): \t accepted track! \n");
953 track->GetPxPyPz(pTrack) ;
955 } // aod track exists
960 //Count the tracks in eta < 0.9
961 //printf("Eta %f cut %f\n",TMath::Abs(track->Eta()),fTrackMultEtaCut);
962 if(TMath::Abs(track->Eta())< fTrackMultEtaCut) fTrackMult++;
964 TLorentzVector momentum(pTrack[0],pTrack[1],pTrack[2],0);
966 if(fCTSPtMin < momentum.Pt() && fCTSPtMax > momentum.Pt())
968 if(fCheckFidCut && !fFiducialCut->IsInFiducialCut(momentum,"CTS"))
971 if(fDebug > 2 && momentum.Pt() > 0.1)
972 printf("AliCaloTrackReader::FillInputCTS() - Selected tracks E %3.2f, pt %3.2f, phi %3.2f, eta %3.2f\n",
973 momentum.E(),momentum.Pt(),momentum.Phi()*TMath::RadToDeg(),momentum.Eta());
977 track->SetID(itrack);
980 fCTSTracks->Add(track);
982 }//Pt and Fiducial cut passed.
986 printf("AliCaloTrackReader::FillInputCTS() - aod entries %d, input tracks %d, pass status %d, multipliticy %d\n", fCTSTracks->GetEntriesFast(), nTracks, nstatus, fTrackMult);//fCTSTracksNormalInputEntries);
990 //__________________________________________________________________
991 void AliCaloTrackReader::FillInputEMCALAlgorithm(AliVCluster * clus,
994 //Fill the EMCAL data in the array, do it
998 vindex = fMixedEvent->EventIndexForCaloCluster(iclus);
1000 //Reject clusters with bad channels, close to borders and exotic;
1001 if(!GetCaloUtils()->GetEMCALRecoUtils()->IsGoodCluster(clus,GetCaloUtils()->GetEMCALGeometry(),GetEMCALCells(),fInputEvent->GetBunchCrossNumber())) return;
1003 //Mask all cells in collumns facing ALICE thick material if requested
1004 if(GetCaloUtils()->GetNMaskCellColumns())
1010 Bool_t shared = kFALSE;
1011 GetCaloUtils()->GetEMCALRecoUtils()->GetMaxEnergyCell(GetCaloUtils()->GetEMCALGeometry(), GetEMCALCells(),clus,absId,iSupMod,ieta,iphi,shared);
1012 if(GetCaloUtils()->MaskFrameCluster(iSupMod, ieta)) return;
1015 if(fSelectEmbeddedClusters)
1017 if(clus->GetNLabels()==0 || clus->GetLabel() < 0) return;
1018 //else printf("Embedded cluster, %d, n label %d label %d \n",iclus,clus->GetNLabels(),clus->GetLabel());
1022 //clus->GetPosition(pos);
1023 //printf("Before Corrections: e %f, x %f, y %f, z %f\n",clus->E(),pos[0],pos[1],pos[2]);
1025 if(fRecalculateClusters)
1027 //Recalibrate the cluster energy
1028 if(GetCaloUtils()->IsRecalibrationOn())
1030 Float_t energy = GetCaloUtils()->RecalibrateClusterEnergy(clus, GetEMCALCells());
1033 //printf("Recalibrated Energy %f\n",clus->E());
1035 GetCaloUtils()->RecalculateClusterShowerShapeParameters(GetEMCALCells(),clus);
1036 GetCaloUtils()->RecalculateClusterPID(clus);
1040 //Recalculate distance to bad channels, if new list of bad channels provided
1041 GetCaloUtils()->RecalculateClusterDistanceToBadChannel(GetEMCALCells(),clus);
1043 //Recalculate cluster position
1044 if(GetCaloUtils()->IsRecalculationOfClusterPositionOn())
1046 GetCaloUtils()->RecalculateClusterPosition(GetEMCALCells(),clus);
1047 //clus->GetPosition(pos);
1048 //printf("After Corrections: e %f, x %f, y %f, z %f\n",clus->E(),pos[0],pos[1],pos[2]);
1052 if(GetCaloUtils()->GetEMCALRecoUtils()->IsTimeRecalibrationOn())
1054 Double_t tof = clus->GetTOF();
1056 Int_t absIdMax = GetCaloUtils()->GetMaxEnergyCell(fEMCALCells, clus,frac);
1058 if(fDataType==AliCaloTrackReader::kESD)
1060 tof = fEMCALCells->GetCellTime(absIdMax);
1063 GetCaloUtils()->GetEMCALRecoUtils()->RecalibrateCellTime(absIdMax,fInputEvent->GetBunchCrossNumber(),tof);
1067 }// Time recalibration
1070 //Correct non linearity
1071 if(GetCaloUtils()->IsCorrectionOfClusterEnergyOn())
1073 GetCaloUtils()->CorrectClusterEnergy(clus) ;
1074 //printf("Linearity Corrected Energy %f\n",clus->E());
1076 //In case of MC analysis, to match resolution/calibration in real data
1077 Float_t rdmEnergy = GetCaloUtils()->GetEMCALRecoUtils()->SmearClusterEnergy(clus);
1078 // printf("\t Energy %f, smeared %f\n", clus->E(),rdmEnergy);
1079 clus->SetE(rdmEnergy);
1082 TLorentzVector momentum ;
1084 clus->GetMomentum(momentum, fVertex[vindex]);
1086 if(fCheckFidCut && !fFiducialCut->IsInFiducialCut(momentum,"EMCAL")) return;
1088 if(fEMCALPtMin > momentum.E() || fEMCALPtMax < momentum.E()) return;
1090 Double_t tof = clus->GetTOF()*1e9;
1091 if(tof < fEMCALTimeCutMin || tof > fEMCALTimeCutMax) return;
1093 if(fDebug > 2 && momentum.E() > 0.1)
1094 printf("AliCaloTrackReader::FillInputEMCAL() - Selected clusters E %3.2f, pt %3.2f, phi %3.2f, eta %3.2f\n",
1095 momentum.E(),momentum.Pt(),momentum.Phi()*TMath::RadToDeg(),momentum.Eta());
1098 clus->SetID(iclus) ;
1100 fEMCALClusters->Add(clus);
1104 //_______________________________________
1105 void AliCaloTrackReader::FillInputEMCAL()
1107 //Return array with EMCAL clusters in aod format
1109 if(fDebug > 2 ) printf("AliCaloTrackReader::FillInputEMCAL()\n");
1111 // First recalibrate cells, time or energy
1112 // if(GetCaloUtils()->IsRecalibrationOn())
1113 // GetCaloUtils()->GetEMCALRecoUtils()->RecalibrateCells(GetCaloUtils()->GetEMCALGeometry(),
1115 // fInputEvent->GetBunchCrossNumber());
1117 //Loop to select clusters in fiducial cut and fill container with aodClusters
1118 if(fEMCALClustersListName=="")
1120 Int_t nclusters = fInputEvent->GetNumberOfCaloClusters();
1121 for (Int_t iclus = 0; iclus < nclusters; iclus++)
1123 AliVCluster * clus = 0;
1124 if ( (clus = fInputEvent->GetCaloCluster(iclus)) )
1126 if (IsEMCALCluster(clus))
1128 FillInputEMCALAlgorithm(clus, iclus);
1133 //Recalculate track matching
1134 GetCaloUtils()->RecalculateClusterTrackMatching(fInputEvent);
1136 }//Get the clusters from the input event
1139 TClonesArray * clusterList = 0x0;
1141 if (fInputEvent->FindListObject(fEMCALClustersListName))
1143 clusterList = dynamic_cast<TClonesArray*> (fInputEvent ->FindListObject(fEMCALClustersListName));
1145 else if(fOutputEvent)
1147 clusterList = dynamic_cast<TClonesArray*> (fOutputEvent->FindListObject(fEMCALClustersListName));
1152 //printf("AliCaloTrackReader::FillInputEMCAL() - Wrong name of list with clusters? Try input event <%s>\n",fEMCALClustersListName.Data());
1153 //List not in output event, try input event
1154 clusterList = dynamic_cast<TClonesArray*> (fInputEvent->FindListObject(fEMCALClustersListName));
1157 printf("AliCaloTrackReader::FillInputEMCAL() - Wrong name of list with clusters? <%s>\n",fEMCALClustersListName.Data());
1162 Int_t nclusters = clusterList->GetEntriesFast();
1163 for (Int_t iclus = 0; iclus < nclusters; iclus++)
1165 AliVCluster * clus = dynamic_cast<AliVCluster*> (clusterList->At(iclus));
1166 //printf("E %f\n",clus->E());
1167 if (clus) FillInputEMCALAlgorithm(clus, iclus);
1168 else printf("AliCaloTrackReader::FillInputEMCAL() - Null cluster in list!\n");
1171 // Recalculate track matching, not necessary if already done in the reclusterization task.
1172 // in case it was not done ...
1173 GetCaloUtils()->RecalculateClusterTrackMatching(fInputEvent,clusterList);
1177 if(fDebug > 1) printf("AliCaloTrackReader::FillInputEMCAL() - aod entries %d\n", fEMCALClusters->GetEntriesFast());
1181 //______________________________________
1182 void AliCaloTrackReader::FillInputPHOS()
1184 //Return array with PHOS clusters in aod format
1186 if(fDebug > 2 ) printf("AliCaloTrackReader::FillInputPHOS()\n");
1188 //Loop to select clusters in fiducial cut and fill container with aodClusters
1189 Int_t nclusters = fInputEvent->GetNumberOfCaloClusters();
1190 for (Int_t iclus = 0; iclus < nclusters; iclus++)
1192 AliVCluster * clus = 0;
1193 if ( (clus = fInputEvent->GetCaloCluster(iclus)) )
1195 if (IsPHOSCluster(clus))
1197 //Check if the cluster contains any bad channel and if close to calorimeter borders
1200 vindex = fMixedEvent->EventIndexForCaloCluster(iclus);
1201 if( GetCaloUtils()->ClusterContainsBadChannel("PHOS",clus->GetCellsAbsId(), clus->GetNCells()))
1203 if(!GetCaloUtils()->CheckCellFiducialRegion(clus, fInputEvent->GetPHOSCells(), fInputEvent, vindex))
1206 if(fRecalculateClusters)
1208 //Recalibrate the cluster energy
1209 if(GetCaloUtils()->IsRecalibrationOn())
1211 Float_t energy = GetCaloUtils()->RecalibrateClusterEnergy(clus, (AliAODCaloCells*)GetPHOSCells());
1216 TLorentzVector momentum ;
1218 clus->GetMomentum(momentum, fVertex[vindex]);
1220 if(fCheckFidCut && !fFiducialCut->IsInFiducialCut(momentum,"PHOS")) continue;
1222 if(fPHOSPtMin > momentum.E() || fPHOSPtMax < momentum.E()) continue;
1224 if(fDebug > 2 && momentum.E() > 0.1)
1225 printf("AliCaloTrackReader::FillInputPHOS() - Selected clusters E %3.2f, pt %3.2f, phi %3.2f, eta %3.2f\n",
1226 momentum.E(),momentum.Pt(),momentum.Phi()*TMath::RadToDeg(),momentum.Eta());
1231 clus->SetID(iclus) ;
1234 fPHOSClusters->Add(clus);
1240 if(fDebug > 1) printf("AliCaloTrackReader::FillInputPHOS() - aod entries %d\n", fPHOSClusters->GetEntriesFast());
1244 //____________________________________________
1245 void AliCaloTrackReader::FillInputEMCALCells()
1247 //Return array with EMCAL cells in aod format
1249 fEMCALCells = fInputEvent->GetEMCALCells();
1253 //___________________________________________
1254 void AliCaloTrackReader::FillInputPHOSCells()
1256 //Return array with PHOS cells in aod format
1258 fPHOSCells = fInputEvent->GetPHOSCells();
1262 //_______________________________________
1263 void AliCaloTrackReader::FillInputVZERO()
1265 //Fill VZERO information in data member, add all the channels information.
1266 AliVVZERO* v0 = fInputEvent->GetVZEROData();
1267 //printf("Init V0: ADC (%d,%d), Multiplicity (%d,%d) \n",fV0ADC[0],fV0ADC[1],fV0Mul[0],fV0Mul[1]);
1271 AliESDVZERO* esdV0 = dynamic_cast<AliESDVZERO*> (v0);
1272 for (Int_t i = 0; i < 32; i++)
1275 {//Only available in ESDs
1276 fV0ADC[0] += (Int_t)esdV0->GetAdcV0C(i);
1277 fV0ADC[1] += (Int_t)esdV0->GetAdcV0A(i);
1280 fV0Mul[0] += (Int_t)v0->GetMultiplicityV0C(i);
1281 fV0Mul[1] += (Int_t)v0->GetMultiplicityV0A(i);
1284 printf("V0: ADC (%d,%d), Multiplicity (%d,%d) \n",fV0ADC[0],fV0ADC[1],fV0Mul[0],fV0Mul[1]);
1289 printf("Cannot retrieve V0 ESD! Run w/ null V0 charges\n ");
1294 //___________________________________________________________________
1295 Bool_t AliCaloTrackReader::IsEMCALCluster(AliVCluster* cluster) const
1297 // Check if it is a cluster from EMCAL. For old AODs cluster type has
1298 // different number and need to patch here
1300 if(fDataType==kAOD && fOldAOD)
1302 if (cluster->GetType() == 2) return kTRUE;
1307 return cluster->IsEMCAL();
1312 //___________________________________________________________________
1313 Bool_t AliCaloTrackReader::IsPHOSCluster(AliVCluster * cluster) const
1315 //Check if it is a cluster from PHOS.For old AODs cluster type has
1316 // different number and need to patch here
1318 if(fDataType==kAOD && fOldAOD)
1320 Int_t type = cluster->GetType();
1321 if (type == 0 || type == 1) return kTRUE;
1326 return cluster->IsPHOS();
1331 //________________________________________________
1332 Bool_t AliCaloTrackReader::CheckForPrimaryVertex()
1334 //Check if the vertex was well reconstructed, copy from V0Reader of conversion group
1337 AliESDEvent * event = dynamic_cast<AliESDEvent*> (fInputEvent);
1338 if(!event) return kTRUE;
1340 if(event->GetPrimaryVertexTracks()->GetNContributors() > 0)
1345 if(event->GetPrimaryVertexTracks()->GetNContributors() < 1)
1348 if(event->GetPrimaryVertexSPD()->GetNContributors() > 0)
1350 //cout<<"spd vertex type::"<< fESDEvent->GetPrimaryVertex()->GetName() << endl;
1354 if(event->GetPrimaryVertexSPD()->GetNContributors() < 1)
1356 // cout<<"bad vertex type::"<< event->GetPrimaryVertex()->GetName() << endl;
1365 //____________________________________________________________
1366 void AliCaloTrackReader::SetTrackCuts(AliESDtrackCuts * cuts)
1370 if(fESDtrackCuts) delete fESDtrackCuts ;
1372 fESDtrackCuts = cuts ;