14 #include <yaml-cpp/yaml.h>
20 #include "AliVEventHandler.h"
21 #include "AliEMCALGeometry.h"
22 #include "AliVCaloCells.h"
23 #include "AliAODCaloCells.h"
24 #include "AliESDCaloCells.h"
25 #include "AliVCluster.h"
26 #include "AliAODCaloCluster.h"
27 #include "AliESDCaloCluster.h"
28 #include "AliVTrack.h"
29 #include "AliAODTrack.h"
30 #include "AliESDtrack.h"
32 #include "AliMultSelection.h"
45 fUserConfigurationFilename(
""),
46 fUserConfigurationString(
""),
47 fDefaultConfiguration(),
48 fDefaultConfigurationFilename(
""),
49 fDefaultConfigurationString(
""),
50 fCorrectionComponents(),
54 fConfigurationInitialized(false),
56 fCreateNewObjectBranches(false),
57 fCreatedClusterBranchName(
""),
58 fCreatedTrackBranchName(
""),
59 fEventInitialized(false),
66 fUseNewCentralityEstimation(kFALSE),
70 fNeedEmcalGeom(kTRUE),
75 fCaloCellsFromInputEvent(0),
79 AliDebug(3, Form(
"%s", __PRETTY_FUNCTION__));
96 fUserConfigurationFilename(
""),
97 fUserConfigurationString(
""),
98 fDefaultConfiguration(),
99 fDefaultConfigurationFilename(
""),
100 fDefaultConfigurationString(
""),
101 fCorrectionComponents(),
105 fConfigurationInitialized(false),
107 fCreateNewObjectBranches(false),
108 fCreatedClusterBranchName(
""),
109 fCreatedTrackBranchName(
""),
110 fEventInitialized(false),
117 fUseNewCentralityEstimation(kFALSE),
121 fNeedEmcalGeom(kTRUE),
123 fParticleCollArray(),
126 fCaloCellsFromInputEvent(0),
130 AliDebug(3, Form(
"%s", __PRETTY_FUNCTION__));
139 DefineInput(0, TChain::Class());
140 DefineOutput(1, TList::Class());
152 std::ifstream inFile(filename);
153 return inFile.good();
166 std::size_t alicePhysicsPathLocation = filename.find(
"$ALICE_PHYSICS");
167 if (alicePhysicsPathLocation != std::string::npos)
171 filename.replace(alicePhysicsPathLocation, alicePhysicsPathLocation + 14, alicePhysicsPath.Data());
175 if(filename.find(
"alien://") != std::string::npos)
177 AliDebug(2, TString::Format(
"Opening file \"%s\" on the grid!", filename.c_str()));
180 TGrid::Connect(
"alien://");
184 std::string localFilename =
gSystem->BaseName(filename.c_str());
186 if (userFile ==
true) {
187 localFilename =
"user" + localFilename;
189 TFile::Cp(filename.c_str(), localFilename.c_str());
192 filename = localFilename;
242 AliInfo(TString::Format(
"User file at \"%s\" does not exist! All settings will be from the default file!",
fUserConfigurationFilename.c_str()));
248 AliFatal(
"Must pass a run period to the correction task!");
251 TString userRunPeriod =
"kNoUserFile";
261 AliFatal(
"User must specify a period. Leave the period as an empty string to apply to all periods.");
265 AliDebug(3, TString::Format(
"userRunPeriod: %s", userRunPeriod.Data()));
267 userRunPeriod.ToLower();
269 if (userRunPeriod !=
"" && userRunPeriod !=
"knouserfile" && userRunPeriod !=
fRunPeriod)
271 AliFatal(TString::Format(
"User run period \"%s\" does not match the run period of \"%s\" passed to the correction task!", userRunPeriod.Data(),
fRunPeriod.Data()));
275 if (userRunPeriod ==
"")
277 AliWarning(
"User run period is an empty string. Settings apply to all run periods!");
282 std::stringstream tempConfiguration;
285 tempConfiguration.str(
"");
302 bool returnValue =
false;
307 std::ofstream outFile(filename);
309 if (stringToWrite ==
"") {
310 AliWarning(TString::Format(
"%s configuration is empty!", userConfig ?
"User" :
"Default"));
312 outFile << stringToWrite;
319 AliWarning(TString::Format(
"Configuration not properly initialized! Cnanot print %s configuration!", userConfig ?
"user" :
"default"));
325 AliWarning(
"Please pass a valid filename instead of empty qutoes!");
339 AliDebug(2,
"Creating EMCal Correction Components: ");
340 for (
auto & component : executionOrder)
342 component =
"AliEmcalCorrection" + component;
343 AliDebug(2, TString::Format(
"%s", component.c_str()) );
357 AliInfo(TString::Format(
"%s: Reinitializing user configuration from string. Expected if running on grid!", GetName()));
362 AliInfo(TString::Format(
"%s: Reinitializing default configuration from string. Expected if running on grid!", GetName()));
367 std::vector<std::string> executionOrder;
377 bool componentEnabled =
false;
378 for (
auto componentName : executionOrder)
380 componentEnabled =
false;
382 if (componentEnabled ==
false)
384 AliInfo(TString::Format(
"%s: Component %s is disabled and will not be run!", GetName(), componentName.c_str()));
392 AliFatal(TString::Format(
"%s: Failed to create requested component %s!", GetName(), componentName.c_str()));
396 component->SetName(componentName.c_str());
397 component->SetTitle(componentName.c_str());
411 if (tempClusterContainer)
417 if (tempParticleContainer)
424 AliInfo(TString::Format(
"Successfully added correction task: %s", componentName.c_str()));
435 t->SetName(componentName.c_str());
443 AliDebug(1, TString::Format(
"Added output list from task %s to output.", componentName.c_str()));
475 AliDebug(3, Form(
"%s", __PRETTY_FUNCTION__));
480 AliVEventHandler *evhand = mgr->GetInputEventHandler();
482 if (evhand->InheritsFrom(
"AliESDInputHandler")) {
490 AliError(
"Event handler not found!");
494 AliError(
"Analysis manager not found!");
501 AliFatal(TString::Format(
"%s: YAML configuration must be initialized before running (ie. the AddTask, run macro or wagon)!", GetName()));
505 std::string cellsName =
"";
507 if (cellsName ==
"usedefault") {
525 AliDebug(3, Form(
"%s", __PRETTY_FUNCTION__));
528 component->ExecOnce();
543 TClonesArray * existingArray =
dynamic_cast<TClonesArray *
>(InputEvent()->FindListObject(
fCreatedClusterBranchName.c_str()));
545 AliFatal(TString::Format(
"%s: Attempted to create a new cluster branch, \"%s\", with the same name as an existing branch!", GetName(),
fCreatedClusterBranchName.c_str()));
549 TClonesArray * newClusters = 0;
551 newClusters =
new TClonesArray(
"AliESDCaloCluster");
554 newClusters =
new TClonesArray(
"AliAODCaloCluster");
557 InputEvent()->AddObject(newClusters);
566 AliFatal(TString::Format(
"%s: Attempted to create a new track branch, \"%s\", with the same name as existing branch!", GetName(),
fCreatedTrackBranchName.c_str()));
570 TClonesArray * newTracks = 0;
572 newTracks =
new TClonesArray(
"AliESDtrack");
575 newTracks =
new TClonesArray(
"AliAODTrack");
578 InputEvent()->AddObject(newTracks);
604 TClonesArray * newClusters =
dynamic_cast<TClonesArray *
>(InputEvent()->FindListObject(
fCreatedClusterBranchName.c_str()));
606 TClonesArray * currentClusters =
dynamic_cast<TClonesArray *
>(InputEvent()->FindListObject(currentClustersName.c_str()));
607 AliDebug(3, Form(
"before copy:\t currentClusters->GetEntries(): %d \t newClusters->GetEntries(): %d", currentClusters->GetEntries(), newClusters->GetEntries()));
609 AliDebug(3, Form(
"after copy:\t currentClusters->GetEntries(): %d \t newClusters->GetEntries(): %d", currentClusters->GetEntries(), newClusters->GetEntries()));
612 TClonesArray * newTracks =
dynamic_cast<TClonesArray *
>(InputEvent()->FindListObject(
fCreatedTrackBranchName.c_str()));
614 TClonesArray * currentTracks =
dynamic_cast<TClonesArray *
>(InputEvent()->FindListObject(currentTracksName.c_str()));
615 AliDebug(3, Form(
"before copy:\t currentTracks->GetEntries(): %d \t newTracks->GetEntries(): %d", currentTracks->GetEntries(), newTracks->GetEntries()));
616 for (
Int_t i = 0; i < currentTracks->GetEntriesFast(); i++)
621 AliESDtrack *currentTrack =
dynamic_cast<AliESDtrack *
>(currentTracks->At(i));
623 AliESDtrack *newTrack =
dynamic_cast<AliESDtrack *
>(
new ((*newTracks)[i]) AliESDtrack(*currentTrack));
626 TProcessID::AssignID(newTrack);
630 AliAODTrack *currentTrack =
dynamic_cast<AliAODTrack *
>(currentTracks->At(i));
632 AliAODTrack *newTrack =
dynamic_cast<AliAODTrack *
>(
new ((*newTracks)[i]) AliAODTrack(*currentTrack));
645 TProcessID::AssignID(newTrack);
654 AliDebug(3, Form(
"after copy:\t currentTracks->GetEntries(): %d \t newTracks->GetEntries(): %d", currentTracks->GetEntries(), newTracks->GetEntries()));
663 const Int_t Ncls = orig->GetEntries();
665 for(
Int_t i=0; i < Ncls; ++i) {
666 AliVCluster *oc =
static_cast<AliVCluster*
>(orig->At(i));
675 AliVCluster *dc =
static_cast<AliVCluster*
>(dest->New(i));
677 dc->SetType(oc->GetType());
680 oc->GetPosition(pos);
681 dc->SetPosition(pos);
682 dc->SetNCells(oc->GetNCells());
683 dc->SetCellsAbsId(oc->GetCellsAbsId());
684 dc->SetCellsAmplitudeFraction(oc->GetCellsAmplitudeFraction());
685 dc->SetID(oc->GetID());
686 dc->SetDispersion(oc->GetDispersion());
687 dc->SetEmcCpvDistance(-1);
689 dc->SetTOF(oc->GetTOF());
690 dc->SetNExMax(oc->GetNExMax());
691 dc->SetM02(oc->GetM02());
692 dc->SetM20(oc->GetM20());
693 dc->SetDistanceToBadChannel(oc->GetDistanceToBadChannel());
694 dc->SetMCEnergyFraction(oc->GetMCEnergyFraction());
697 UInt_t nlabels = oc->GetNLabels();
698 Int_t *labels = oc->GetLabels();
700 if (nlabels == 0 || !labels)
703 AliESDCaloCluster *esdClus =
dynamic_cast<AliESDCaloCluster*
>(dc);
705 TArrayI parents(nlabels, labels);
706 esdClus->AddLabels(parents);
709 AliAODCaloCluster *aodClus =
dynamic_cast<AliAODCaloCluster*
>(dc);
711 aodClus->SetLabel(labels, nlabels);
742 const AliVVertex *vert = InputEvent()->GetPrimaryVertex();
752 AliMultSelection *MultSelection =
static_cast<AliMultSelection*
>(InputEvent()->FindListObject(
"MultSelection"));
754 fCent = MultSelection->GetMultiplicityPercentile(
fCentEst.Data());
757 AliWarning(Form(
"%s: Could not retrieve centrality information! Assuming 99", GetName()));
761 AliCentrality *aliCent = InputEvent()->GetCentrality();
766 AliWarning(Form(
"%s: Could not retrieve centrality information! Assuming 99", GetName()));
776 AliWarning(Form(
"%s: Negative centrality: %f. Assuming 99", GetName(),
fCent));
785 else if (
fCent > 90) {
790 AliWarning(Form(
"%s: Negative centrality: %f. Assuming 99", GetName(),
fCent));
803 AliWarning(Form(
"%s: fCentBin too large: cent = %f fCentBin = %d. Assuming 99", GetName(),
fCent,
fCentBin));
813 AliEmcalContainer* cont = 0;
816 while ((cont = static_cast<AliEmcalContainer*>(nextPartColl()))) cont->NextEvent();
819 while ((cont = static_cast<AliEmcalContainer*>(nextClusColl()))) cont->NextEvent();
838 AliError(Form(
"%s: Could not retrieve event! Returning!", GetName()));
843 fGeom = AliEMCALGeometry::GetInstanceFromRunNumber(InputEvent()->
GetRunNumber());
845 AliFatal(Form(
"%s: Can not get EMCal geometry instance. If you do not need the EMCal geometry, disable it by setting task->SetNeedEmcalGeometry(kF ALSE).", GetName()));
858 cont->SetArray(InputEvent());
864 cont->SetArray(InputEvent());
870 AliError(Form(
"%s: Could not retrieve cells %s!", GetName(),
fCaloCellsName.Data()));
889 if (
TString(n).IsNull())
return 0;
907 if (
TString(n).IsNull())
return 0;
925 if (
TString(n).IsNull())
return 0;
943 if (
TString(n).IsNull())
return 0;
1006 AliDebug(3, Form(
"%s", __PRETTY_FUNCTION__));
1047 AliDebug(3, Form(
"%s", __PRETTY_FUNCTION__));
1050 component->SetEvent(InputEvent());
1051 component->SetMCEvent(MCEvent());
1053 component->SetEMCALGeometry(
fGeom);
1054 component->SetCentralityBin(
fCentBin);
1055 component->SetCentrality(
fCent);
1058 if (tempClusterContainer)
1060 component->SetClusterContainer(tempClusterContainer);
1063 if (tempParticleContainer)
1067 component->SetParticleContainer(tempParticleContainer);
1086 AliDebug(3, Form(
"%s", __PRETTY_FUNCTION__));
1089 component->UserNotify();
1117 const AliESDRun *run = esd->GetESDRun();
1118 TString beamType = run->GetBeamType();
1119 if (beamType ==
"p-p")
1121 else if (beamType ==
"A-A")
1123 else if (beamType ==
"p-A")
1128 Int_t runNumber = InputEvent()->GetRunNumber();
1129 if ((runNumber >= 136851 && runNumber <= 139517) ||
1130 (runNumber >= 166529 && runNumber <= 170593)) {
1132 }
else if ((runNumber>=188365 && runNumber <= 188366) ||
1133 (runNumber >= 195344 && runNumber <= 196608)) {
Int_t fNcentBins
how many centrality bins
Steering task for the EMCal correction frameworkThis class is the steering class for the cell and clu...
AliEMCALGeometry * fGeom
!emcal geometry
static std::string DetermineUseDefaultName(inputObjectType contType, Bool_t esdMode)
AliParticleContainer * GetParticleContainer()
void InitializeConfiguration()
AliTrackContainer * AddTrackContainer(const char *n)
AliClusterContainer * GetClusterContainer(Int_t i=0) const
std::vector< AliEmcalCorrectionComponent * > fCorrectionComponents
! Contains the correction components
void CopyBranchesToNewObjects()
Container with name, TClonesArray and cuts for particles.
void RetrieveExecutionOrder(std::vector< std::string > &componentsToAdd)
AliVCaloCells * fCaloCellsFromInputEvent
! pointer to calo cells from the input event
void AdoptClusterContainer(AliClusterContainer *cont)
void SetupConfigurationFilePath(std::string &filename, bool userFile=false)
void UserExec(Option_t *option)
void SetNcentralityBins(Int_t n)
YAML::Node fUserConfiguration
Double_t fMaxCent
max centrality for event selection
Double_t fVertex[3]
!event vertex
TList * fOutput
! Output for histograms
bool fConfigurationInitialized
True if the YAML files are initialized.
static bool doesFileExist(const std::string &filename)
Container for particles within the EMCAL framework.
bool fCreateNewObjectBranches
Create new branches for cells and clusters.
void SetUserConfiguration(YAML::Node &node)
Make copy to ensure that the nodes do not point to each other (?)
bool fEventInitialized
If the event is initialized properly.
TString fCentEst
name of V0 centrality estimator
void CreateNewObjectBranches()
std::string fUserConfigurationFilename
! User YAML configruation filename
std::string fDefaultConfigurationString
Store the default YAML configuration as a string so that it can be streamed.
TString fRunPeriod
Run period (passed by user)
Double_t fCent
! Event centrality
void ExecOnceComponents()
BeamType
Switch for the beam type.
AliMCParticleContainer * AddMCParticleContainer(const char *n)
void InitializeComponents()
AliVCaloCells * fCaloCells
! pointer to calo cells
std::string fCreatedTrackBranchName
Name of created track branch.
void GetProperty(std::string propertyName, T &property, bool requiredProperty=true, std::string correctionName="")
Retrieve property.
bool WriteConfigurationFile(std::string filename, bool userConfig=false)
Bool_t fNeedEmcalGeom
whether or not the task needs the emcal geometry
std::string fCreatedClusterBranchName
Name of created cluster branch.
Bool_t fUseNewCentralityEstimation
Use new centrality estimation (for 2015 data)
void CopyClusters(TClonesArray *orig, TClonesArray *dest)
std::string fDefaultConfigurationFilename
! Default YAML configuration filename
void CleanupCreatedBranches()
void UserCreateOutputObjects()
TObjArray fParticleCollArray
particle/track collection array
TObjArray fClusterCollArray
cluster collection array
virtual Bool_t Initialize()
void SetDefaultConfiguration(YAML::Node &node)
virtual ~AliEmcalCorrectionTask()
ClassImp(AliAnalysisTaskCRC) AliAnalysisTaskCRC
AliParticleContainer * GetParticleContainer(Int_t i=0) const
void AdoptParticleContainer(AliParticleContainer *cont)
BeamType fBeamType
!event beam type
Int_t GetRunNumber(TString)
TString fCaloCellsName
name of calo cell collection
YAML::Node fDefaultConfiguration
User YAML Configuration.
Int_t fNVertCont
!event vertex number of contributors
static AliEmcalCorrectionComponent * createInstance(std::string const &s)
AliClusterContainer * GetClusterContainer()
Int_t fCentBin
! Event centrality bin
Double_t fMinCent
min centrality for event selection
AliClusterContainer * AddClusterContainer(const char *n)
Bool_t RetrieveEventObjects()
AliParticleContainer * AddParticleContainer(const char *n)
Container structure for EMCAL clusters.
Container for MC-true particles within the EMCAL framework.
std::string fUserConfigurationString
Default YAML Configuration.
TList * OpenFile(const char *fname)
BeamType fForceBeamType
forced beam type