20 #include "AliVEventHandler.h"
21 #include "AliEMCALGeometry.h"
22 #include "AliVCaloCells.h"
23 #include "AliVCluster.h"
25 #include "AliMultSelection.h"
26 #include "AliCentrality.h"
27 #include "AliESDEvent.h"
28 #include "AliAnalysisManager.h"
45 fUserConfigurationFilename(
""),
46 fUserConfigurationString(
""),
47 fDefaultConfiguration(),
48 fDefaultConfigurationFilename(
""),
49 fDefaultConfigurationString(
""),
50 fCorrectionComponents(),
54 fConfigurationInitialized(false),
56 fEventInitialized(false),
63 fUseNewCentralityEstimation(kFALSE),
66 fNeedEmcalGeom(kTRUE),
74 AliDebug(3, Form(
"%s", __PRETTY_FUNCTION__));
91 fUserConfigurationFilename(
""),
92 fUserConfigurationString(
""),
93 fDefaultConfiguration(),
94 fDefaultConfigurationFilename(
""),
95 fDefaultConfigurationString(
""),
96 fCorrectionComponents(),
100 fConfigurationInitialized(false),
102 fEventInitialized(false),
109 fUseNewCentralityEstimation(kFALSE),
112 fNeedEmcalGeom(kTRUE),
114 fParticleCollArray(),
120 AliDebug(3, Form(
"%s", __PRETTY_FUNCTION__));
129 DefineInput(0, TChain::Class());
130 DefineOutput(1, TList::Class());
142 std::ifstream inFile(filename);
143 return inFile.good();
156 std::size_t alicePhysicsPathLocation = filename.find(
"$ALICE_PHYSICS");
157 if (alicePhysicsPathLocation != std::string::npos)
161 filename.replace(alicePhysicsPathLocation, alicePhysicsPathLocation + 14, alicePhysicsPath.Data());
165 if(filename.find(
"alien://") != std::string::npos)
167 AliDebug(2, TString::Format(
"Opening file \"%s\" on the grid!", filename.c_str()));
170 TGrid::Connect(
"alien://");
174 std::string localFilename =
gSystem->BaseName(filename.c_str());
176 if (userFile ==
true) {
177 localFilename =
"user" + localFilename;
179 TFile::Cp(filename.c_str(), localFilename.c_str());
182 filename = localFilename;
232 AliInfo(TString::Format(
"User file at \"%s\" does not exist! All settings will be from the default file!",
fUserConfigurationFilename.c_str()));
238 AliFatal(
"Must pass a run period to the correction task!");
241 TString userRunPeriod =
"kNoUserFile";
251 AliFatal(
"User must specify a period. Leave the period as an empty string to apply to all periods.");
255 AliDebug(3, TString::Format(
"userRunPeriod: %s", userRunPeriod.Data()));
257 userRunPeriod.ToLower();
259 if (userRunPeriod !=
"" && userRunPeriod !=
"knouserfile" && userRunPeriod !=
fRunPeriod)
261 AliFatal(TString::Format(
"User run period \"%s\" does not match the run period of \"%s\" passed to the correction task!", userRunPeriod.Data(),
fRunPeriod.Data()));
265 if (userRunPeriod ==
"")
267 AliWarning(
"User run period is an empty string. Settings apply to all run periods!");
272 std::stringstream tempConfiguration;
275 tempConfiguration.str(
"");
295 bool returnValue =
false;
300 std::ofstream outFile(filename);
302 if (stringToWrite ==
"") {
303 AliWarning(TString::Format(
"%s configuration is empty!", userConfig ?
"User" :
"Default"));
305 outFile << stringToWrite;
312 AliWarning(TString::Format(
"Configuration not properly initialized! Cnanot print %s configuration!", userConfig ?
"user" :
"default"));
318 AliWarning(
"Please pass a valid filename instead of empty qutoes!");
332 AliVEventHandler *evhand = mgr->GetInputEventHandler();
334 if (evhand->InheritsFrom(
"AliESDInputHandler")) {
342 AliError(
"Event handler not found!");
346 AliError(
"Analysis manager not found!");
354 AliFatal(
"YAML configuration must be initialized before running (ie. the AddTask, run macro or wagon)!");
362 AliDebugStream(2) <<
"Cell info: " << std::endl;
364 AliDebugStream(2) <<
"\tName: " << cellInfo->GetName() <<
"\tBranch: " << cellInfo->GetBranchName() <<
"\tIsEmbedding:" << cellInfo->GetIsEmbedding() << std::endl;
390 AliDebug(2,
"Creating EMCal Correction Components: ");
391 for (
auto & component : executionOrder)
393 component =
"AliEmcalCorrection" + component;
394 AliDebug(2, TString::Format(
"%s", component.c_str()) );
405 std::vector<std::string> executionOrder;
410 bool componentEnabled =
false;
411 for (
auto componentName : executionOrder)
413 componentEnabled =
false;
415 if (componentEnabled ==
false)
417 AliInfo(TString::Format(
"Component %s is disabled and will not be run!", componentName.c_str()));
425 AliFatal(TString::Format(
"Failed to create requested component %s!", componentName.c_str()));
429 component->SetName(componentName.c_str());
430 component->SetTitle(componentName.c_str());
449 AliInfo(TString::Format(
"Successfully added correction task: %s", componentName.c_str()));
461 AliDebug(3, Form(
"%s", __PRETTY_FUNCTION__));
466 AliFatal(
"YAML configuration must be initialized before running (ie. the AddTask, run macro or wagon)!");
479 AliInfo(
"Reinitializing user configuration from string. Expected if running on grid!");
484 AliInfo(
"Reinitializing default configuration from string. Expected if running on grid!");
490 AliDebugStream(4) <<
"(Re)initialized user configuration: " <<
fUserConfiguration << std::endl;
492 AliDebugStream(4) <<
"(Re)initialized default configuration: " <<
fDefaultConfiguration << std::endl;
514 AliDebug(3, Form(
"%s", __PRETTY_FUNCTION__));
522 component->UserCreateOutputObjects();
524 if (component->GetOutputList() != 0)
531 t->SetName(component->GetName());
534 TIter next(component->GetOutputList());
539 AliDebug(1, TString::Format(
"Added output list from task %s to output.", component->GetName()));
551 std::string inputObjectName =
"";
553 inputObjectName =
"clusterContainers";
555 else if (inputObjectType ==
kTrack) {
556 inputObjectName =
"trackContainers";
559 inputObjectName =
"cells";
562 AliFatal(TString::Format(
"Unrecognized input object type %d", inputObjectType));
565 return inputObjectName;
578 if (nodeToRetrieveFrom[
"sharedParameters"]) {
579 inputNode[
"sharedParameters"] = nodeToRetrieveFrom[
"sharedParameters"];
590 for(
auto & containerName : requestedContainers)
600 AliDebug(2, TString::Format(
"Processing container %s of inputType %d", containerName.c_str(), inputObjectType));
603 SetupContainer(inputObjectType, containerName, userInputObjectNode, defaultInputObjectNode);
606 SetupCellsInfo(containerName, userInputObjectNode, defaultInputObjectNode);
620 AliDebugStream(2) <<
"User: " << std::endl << userNode << std::endl <<
"default: " << std::endl << defaultNode << std::endl;
624 cellObj->
SetName(containerName);
626 std::string tempString =
"";
628 if (tempString ==
"usedefault") {
637 bool tempBool =
false;
655 YAML::Node userInputObjectNode;
656 YAML::Node defaultInputObjectNode;
660 AliDebugStream(2) <<
"userInputObjectNode: " << userInputObjectNode << std::endl;
661 AliDebugStream(2) <<
"defaultInputObjectNode: " << defaultInputObjectNode << std::endl;
664 std::set <std::string> requestedContainers;
665 std::vector <std::string> executionOrder;
666 std::vector <std::string> componentRequest;
668 for (
auto & componentName : executionOrder )
670 bool componentEnabled =
false;
672 if (componentEnabled)
674 componentRequest.clear();
677 for (
auto & req : componentRequest )
680 requestedContainers.insert(req);
685 AliInfoStream() << inputObjectName <<
" Containers requested by components: " << std::endl;
686 for (
auto &
str : requestedContainers) {
687 AliInfoStream() <<
"\t" <<
str << std::endl;;
691 AliDebug(2, TString::Format(
"Setting up requested containers!"));
702 AliDebugStream(2) <<
"Adding container" << std::endl;
703 AliEmcalContainer * cont =
AddContainer(inputObjectType, containerName, userNode, defaultNode);
704 AliDebugStream(2) <<
"Added container" << std::endl;
716 std::string tempString =
"";
718 bool tempBool =
false;
724 AliDebugStream(2) << cont->GetName() <<
": Setting minPt of " << tempDouble << std::endl;
725 cont->SetMinPt(tempDouble);
730 AliDebugStream(2) << cont->GetName() <<
": Setting minE of " << tempDouble << std::endl;
731 cont->SetMinE(tempDouble);
740 AliDebugStream(2) << cont->GetName() <<
": Setting eta limits of " << tempDouble <<
" to " << tempDouble2 << std::endl;
741 cont->SetEtaLimits(tempDouble, tempDouble2);
751 AliDebugStream(2) << cont->GetName() <<
": Setting phi limits of " << tempDouble <<
" to " << tempDouble2 << std::endl;
752 cont->SetPhiLimits(tempDouble, tempDouble2);
765 if (clusterContainer) {
779 AliDebugStream(2) << clusterContainer->GetName() <<
": Setting clusNonLinCorrEnergyCut of " << tempDouble << std::endl;
786 AliDebugStream(2) << clusterContainer->GetName() <<
": Setting clusHadCorrEnergyCut of " << tempDouble << std::endl;
793 if (trackContainer) {
796 std::vector <UInt_t> filterBitsVector;
800 for (
int filterBit : filterBitsVector) {
801 filterBits += filterBit;
803 AliDebugStream(2) << trackContainer->GetName() <<
": Setting filterBits of " << filterBits << std::endl;
812 AliDebugStream(2) << trackContainer->GetName() <<
": Setting trackFilterType of " << trackFilterType << std::endl;
825 std::string returnValue =
"";
827 if (esdMode ==
true) {
828 if (returnObjectType ==
true) {
829 returnValue =
"AliESDCaloCluster";
832 returnValue =
"CaloClusters";
836 if (returnObjectType ==
true) {
837 returnValue =
"AliAODCaloCluster";
840 returnValue =
"caloClusters";
844 else if (objType ==
kTrack) {
845 if (esdMode ==
true) {
846 if (returnObjectType ==
true) {
847 returnValue =
"AliESDtrack";
850 returnValue =
"Tracks";
854 if (returnObjectType ==
true) {
855 returnValue =
"AliAODTrack";
858 returnValue =
"tracks";
863 if (esdMode ==
true) {
864 if (returnObjectType ==
true) {
865 returnValue =
"AliESDCaloCells";
868 returnValue =
"EMCALCells";
872 if (returnObjectType ==
true) {
873 returnValue =
"AliAODCaloCells";
876 returnValue =
"emcalCells";
904 std::string containerBranch =
"";
906 AliFatal(
"Must specify type of container when requesting branch.");
911 AliDebugStream(2) <<
"User Node: " << userNode << std::endl;
912 AliDebugStream(2) <<
"Default Node: " << defaultNode << std::endl;
921 if (containerBranch ==
"usedefault") {
926 AliEmcalContainer * cont = 0;
932 else if (contType ==
kTrack)
934 if (containerBranch ==
"mcparticles") {
942 cont->SetName(containerName.c_str());
955 inputObjectName = inputObjectName +
"Names";
958 std::vector <std::string> inputObjects;
965 for (
auto const &
str : inputObjects)
971 AliDebugStream(2) <<
"Adding cluster container " <<
str <<
" of array " << cont->GetArrayName() <<
" to component " << component->GetName() << std::endl;
974 else if (inputObjectType ==
kTrack) {
976 AliDebugStream(2) <<
"Adding particle container " <<
str <<
" of array " << cont->GetArrayName() <<
" to component " << component->GetName() << std::endl;
981 if (inputObjects.size() > 1) {
982 AliFatal(TString::Format(
"Component %s requested more than one cell branch, but this is not supported! Check the configuration!", component->GetName()));
987 AliDebugStream(3) <<
"component GetNumberOfCells: " << component->
GetCaloCells()->GetNumberOfCells() << std::endl;
1000 if (cellContainer->GetName() == cellsContainerName) {
1001 return cellContainer;
1014 AliDebugStream(2) <<
"Retrieving cells object " << cellContainer->
GetName() << std::endl;
1018 cellContainer->
SetCells(dynamic_cast<AliVCaloCells *>(event->FindListObject(cellContainer->
GetBranchName().c_str())));
1028 AliDebug(3, Form(
"%s", __PRETTY_FUNCTION__));
1032 component->SetEMCALGeometry(
fGeom);
1035 AliDebugStream(3) <<
"Adding CaloCells" << std::endl;
1037 AliDebugStream(3) <<
"Added CaloCells" << std::endl;
1040 component->ExecOnce();
1057 const AliVVertex *vert = InputEvent()->GetPrimaryVertex();
1067 AliMultSelection *MultSelection =
static_cast<AliMultSelection*
>(InputEvent()->FindListObject(
"MultSelection"));
1068 if (MultSelection) {
1069 fCent = MultSelection->GetMultiplicityPercentile(
fCentEst.Data());
1072 AliWarning(
"Could not retrieve centrality information! Assuming 99");
1076 AliCentrality *aliCent = InputEvent()->GetCentrality();
1081 AliWarning(
"Could not retrieve centrality information! Assuming 99");
1091 AliWarning(Form(
"Negative centrality: %f. Assuming 99",
fCent));
1100 else if (
fCent > 90) {
1105 AliWarning(Form(
"Negative centrality: %f. Assuming 99",
fCent));
1118 AliWarning(Form(
"fCentBin too large: cent = %f fCentBin = %d. Assuming 99",
fCent,
fCentBin));
1128 AliEmcalContainer* cont = 0;
1131 while ((cont = static_cast<AliEmcalContainer*>(nextPartColl()))) cont->NextEvent();
1134 while ((cont = static_cast<AliEmcalContainer*>(nextClusColl()))) cont->NextEvent();
1152 if (!InputEvent()) {
1153 AliError(
"Could not retrieve event! Returning!");
1158 fGeom = AliEMCALGeometry::GetInstanceFromRunNumber(InputEvent()->
GetRunNumber());
1160 AliFatal(
"Can not get EMCal geometry instance. If you do not need the EMCal geometry, disable it by setting task->SetNeedEmcalGeometry(kFALSE).");
1169 cont->SetArray(InputEvent());
1176 cont->SetArray(InputEvent());
1197 AliVEvent *
event = 0;
1220 AliVEvent *
event =
GetEvent(InputEvent());
1222 TClonesArray * array =
dynamic_cast<TClonesArray *
>(
event->FindListObject(cont->GetArrayName()));
1224 AliWarning(TString::Format(
"Container %s requested branch %s, but it does not exist! Creating it for you! Please check that this the proper action!", cont->GetName(), cont->GetArrayName().Data()));
1226 array->SetName(cont->GetArrayName());
1227 event->AddObject(array);
1240 if (
TString(n).IsNull())
return 0;
1258 if (
TString(n).IsNull())
return 0;
1276 if (
TString(n).IsNull())
return 0;
1294 if (
TString(n).IsNull())
return 0;
1356 AliDebug(3, Form(
"%s", __PRETTY_FUNCTION__));
1384 AliDebug(3, Form(
"%s", __PRETTY_FUNCTION__));
1387 component->SetEvent(InputEvent());
1388 component->SetMCEvent(MCEvent());
1389 component->SetCentralityBin(
fCentBin);
1390 component->SetCentrality(
fCent);
1408 AliDebug(3, Form(
"%s", __PRETTY_FUNCTION__));
1411 component->UserNotify();
1439 const AliESDRun *run = esd->GetESDRun();
1440 TString beamType = run->GetBeamType();
1441 if (beamType ==
"p-p")
1443 else if (beamType ==
"A-A")
1445 else if (beamType ==
"p-A")
1450 Int_t runNumber = InputEvent()->GetRunNumber();
1451 if ((runNumber >= 136851 && runNumber <= 139517) ||
1452 (runNumber >= 166529 && runNumber <= 170593)) {
1454 }
else if ((runNumber>=188365 && runNumber <= 188366) ||
1455 (runNumber >= 195344 && runNumber <= 196608)) {
Int_t fNcentBins
how many centrality bins
void SetBranchName(std::string branchName)
Steering task for the EMCal correction frameworkThis class is the steering class for the cell and clu...
AliEMCALGeometry * fGeom
!emcal geometry
return jsonbuilder str().c_str()
static bool DoesFileExist(const std::string &filename)
std::string GetName() const
void InitializeConfiguration()
AliTrackContainer * AddTrackContainer(const char *n)
void SetClusterContainer(AliClusterContainer *cont)
std::string GetInputFieldNameFromInputObjectType(InputObject_t inputObjectType)
AliClusterContainer * GetClusterContainer(Int_t i=0) const
std::vector< AliEmcalCorrectionComponent * > fCorrectionComponents
Contains the correction components.
Container with name, TClonesArray and cuts for particles.
void RetrieveExecutionOrder(std::vector< std::string > &componentsToAdd)
void AdoptClusterContainer(AliClusterContainer *cont)
void SetupConfigurationFilePath(std::string &filename, bool userFile=false)
void UserExec(Option_t *option)
void UserCreateOutputObjectsComponents()
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.
Container for particles within the EMCAL framework.
AliEmcalContainer * AddContainer(InputObject_t contType, std::string &containerName, YAML::Node &userNode, YAML::Node &defaultNode)
void SetUserConfiguration(YAML::Node &node)
Make copy to ensure that the nodes do not point to each other (?)
void AddContainersToComponent(AliEmcalCorrectionComponent *component, InputObject_t inputObjectType)
void SetParticleContainer(AliParticleContainer *cont)
bool fEventInitialized
If the event is initialized properly.
TString fCentEst
name of V0 centrality estimator
void SetAODFilterBits(UInt_t bits)
std::string fUserConfigurationFilename
! User YAML configruation filename
std::string fDefaultConfigurationString
Store the default YAML configuration as a string so that it can be streamed.
void SetClusNonLinCorrEnergyCut(Double_t cut)
TString fRunPeriod
Run period (passed by user)
void SetCells(AliVCaloCells *cells)
Double_t fCent
! Event centrality
void ExecOnceComponents()
Base class for correction components in the EMCal correction framework.
BeamType
Switch for the beam type.
AliMCParticleContainer * AddMCParticleContainer(const char *n)
void InitializeComponents()
std::map< std::string, AliEmcalTrackSelection::ETrackFilterType_t > trackFilterTypeMap
void SetupContainersFromInputNodes(InputObject_t inputObjectType, YAML::Node &userInputObjectNode, YAML::Node &defaultInputObjectNode, std::set< std::string > &requestedContainers)
static std::string DetermineUseDefaultName(InputObject_t contType, bool esdMode, bool returnObjectType=false)
void SetupContainer(InputObject_t inputObjectType, std::string containerName, YAML::Node &userNode, YAML::Node &defaultNode)
bool WriteConfigurationFile(std::string filename, bool userConfig=false)
Bool_t fNeedEmcalGeom
whether or not the task needs the emcal geometry
std::string GetBranchName() const
void SetCellsObjectInCellContainerBasedOnProperties(AliEmcalCorrectionCellContainer *cellContainer)
Bool_t fUseNewCentralityEstimation
Use new centrality estimation (for 2015 data)
bool GetIsEmbedding() const
void CheckForContainerArray(AliEmcalContainer *cont, InputObject_t objectType)
AliEmcalCorrectionCellContainer * GetCellContainer(const std::string &cellsContainerName) const
std::string fDefaultConfigurationFilename
! Default YAML configuration filename
void UserCreateOutputObjects()
void GetNodeForInputObjects(YAML::Node &inputNode, YAML::Node &nodeToRetrieveFrom, std::string &inputObjectName, bool requiredProperty)
TObjArray fParticleCollArray
particle/track collection array
TObjArray fClusterCollArray
cluster collection array
static AliVEvent * GetEvent(AliVEvent *inputEvent, bool isEmbedding=false)
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)
void SetIsESD(Bool_t isESD)
AliVCaloCells * GetCaloCells()
void SetCaloCells(AliVCaloCells *cells)
void SetIsEmbedding(bool isEmbedded)
BeamType fBeamType
!event beam type
Int_t GetRunNumber(TString)
void SetTrackFilterType(ETrackFilterType_t f)
YAML::Node fDefaultConfiguration
User YAML Configuration.
void SetupCellsInfo(std::string containerName, YAML::Node &userNode, YAML::Node &defaultNode)
Int_t fNVertCont
!event vertex number of contributors
static AliEmcalCorrectionComponent * createInstance(std::string const &s)
void SetName(std::string name)
Int_t fCentBin
! Event centrality bin
Double_t fMinCent
min centrality for event selection
AliClusterContainer * AddClusterContainer(const char *n)
std::vector< AliEmcalCorrectionCellContainer * > fCellCollArray
Cells collection array.
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.
InputObject_t
Type of input object to be created.
TList * OpenFile(const char *fname)
void SetClusHadCorrEnergyCut(Double_t cut)
bool GetProperty(std::string propertyName, T &property, bool requiredProperty=true, std::string correctionName="")
Retrieve property.
BeamType fForceBeamType
forced beam type
void CreateInputObjects(InputObject_t inputObjectType)