AliPhysics  251aa1e (251aa1e)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliEmcalCorrectionTask.cxx
Go to the documentation of this file.
1 // AliEmcalCorrectionTask
2 //
3 // Runs the cell and cluster level corrections for the EMCal
4 //
5 
8 
9 #include <vector>
10 #include <set>
11 #include <fstream>
12 #include <sstream>
13 #include <iostream>
14 
15 #include <TChain.h>
16 #include <TSystem.h>
17 #include <TGrid.h>
18 #include <TFile.h>
19 
20 #include "AliVEventHandler.h"
21 #include "AliEMCALGeometry.h"
22 #include "AliVCaloCells.h"
23 #include "AliVCluster.h"
24 #include "AliLog.h"
25 #include "AliMultSelection.h"
26 #include "AliCentrality.h"
27 #include "AliESDEvent.h"
28 #include "AliAnalysisManager.h"
29 
33 
37 
43  AliAnalysisTaskSE("AliEmcalCorrectionTask"),
44  fSuffix(""),
45  fUserConfiguration(),
46  fUserConfigurationFilename(""),
47  fUserConfigurationString(""),
48  fDefaultConfiguration(),
49  fDefaultConfigurationFilename(""),
50  fDefaultConfigurationString(""),
51  fCorrectionComponents(),
52  fIsEsd(false),
53  fForceBeamType(kNA),
54  fRunPeriod(""),
55  fConfigurationInitialized(false),
56  fOrderedComponentsToExecute(),
57  fEventInitialized(false),
58  fCent(0),
59  fCentBin(-1),
60  fMinCent(-999),
61  fMaxCent(-999),
62  fNcentBins(4),
63  fCentEst("V0M"),
64  fUseNewCentralityEstimation(kFALSE),
65  fNVertCont(0),
66  fBeamType(kNA),
67  fNeedEmcalGeom(kTRUE),
68  fGeom(0),
69  fParticleCollArray(),
70  fClusterCollArray(),
71  fCellCollArray(),
72  fOutput(0)
73 {
74  // Default constructor
75  AliDebug(3, Form("%s", __PRETTY_FUNCTION__));
76 
77  fVertex[0] = 0;
78  fVertex[1] = 0;
79  fVertex[2] = 0;
80 
81  fParticleCollArray.SetOwner(kTRUE);
82  fClusterCollArray.SetOwner(kTRUE);
83 }
84 
95  AliAnalysisTaskSE(name),
96  fSuffix(""),
97  fUserConfiguration(),
98  fUserConfigurationFilename(""),
99  fUserConfigurationString(""),
100  fDefaultConfiguration(),
101  fDefaultConfigurationFilename(""),
102  fDefaultConfigurationString(""),
103  fCorrectionComponents(),
104  fIsEsd(false),
105  fForceBeamType(kNA),
106  fRunPeriod(""),
107  fConfigurationInitialized(false),
108  fOrderedComponentsToExecute(),
109  fEventInitialized(false),
110  fCent(0),
111  fCentBin(-1),
112  fMinCent(-999),
113  fMaxCent(-999),
114  fNcentBins(4),
115  fCentEst("V0M"),
116  fUseNewCentralityEstimation(kFALSE),
117  fNVertCont(0),
118  fBeamType(kNA),
119  fNeedEmcalGeom(kTRUE),
120  fGeom(0),
121  fParticleCollArray(),
122  fClusterCollArray(),
123  fCellCollArray(),
124  fOutput(0)
125 {
126  // Standard constructor
127  AliDebug(3, Form("%s", __PRETTY_FUNCTION__));
128 
129  fVertex[0] = 0;
130  fVertex[1] = 0;
131  fVertex[2] = 0;
132 
133  fParticleCollArray.SetOwner(kTRUE);
134  fClusterCollArray.SetOwner(kTRUE);
135 
136  DefineInput(0, TChain::Class());
137  DefineOutput(1, TList::Class());
138 }
139 
148 inline bool AliEmcalCorrectionTask::DoesFileExist(const std::string & filename)
149 {
150  std::ifstream inFile(filename);
151  return inFile.good();
152 }
153 
163 {
164  if (filename != "")
165  {
166  // Handle if in AliPhysics and includes $ALICE_PHYSICS
167  filename = gSystem->ExpandPathName(filename.c_str());
168 
169  // Handle grid
170  if(filename.find("alien://") != std::string::npos)
171  {
172  AliDebug(2, TString::Format("Opening file \"%s\" on the grid!", filename.c_str()));
173  // Initialize alien connection if needed
174  if (!gGrid) {
175  TGrid::Connect("alien://");
176  }
177 
178  // Determine the local filename and copy file to local directory
179  std::string localFilename = gSystem->BaseName(filename.c_str());
180  // Ensures that the default and user files do not conflict if both are taken from the grid and have the same filename
181  if (userFile == true) {
182  localFilename = "user" + localFilename;
183  }
184  TFile::Cp(filename.c_str(), localFilename.c_str());
185 
186  // yaml-cpp should only open the local file
187  filename = localFilename;
188  }
189  }
190 }
191 
192 
202 {
203  // Determine file path
205  {
206  // Use the default if nothing is set
207  fDefaultConfigurationFilename = "$ALICE_PHYSICS/PWG/EMCAL/config/AliEmcalCorrectionConfiguration.yaml";
208  }
209 
210  // Setup the YAML files
211  // Default
213 
215  {
216  AliInfo(TString::Format("Using default EMCal corrections configuration located at %s", fDefaultConfigurationFilename.c_str()));
217 
219  // Check for valid file
220  if (fDefaultConfiguration.IsNull() == true)
221  {
222  AliFatal(TString::Format("Could not open the default configuration file \"%s\"!", fDefaultConfigurationFilename.c_str()));
223  }
224  }
225  else
226  {
227  AliFatal(TString::Format("Default file located at \"%s\" does not exist!", fDefaultConfigurationFilename.c_str()));
228  }
229 
230  // User
232 
234  {
235  AliInfo(TString::Format("Using user EMCal corrections configuration located at %s", fUserConfigurationFilename.c_str()));
236 
238  }
239  else
240  {
241  AliInfo(TString::Format("User file at \"%s\" does not exist! All settings will be from the default file!", fUserConfigurationFilename.c_str()));
242  }
243 
244  // Ensure that there is a run period
245  if (fRunPeriod == "")
246  {
247  AliFatal("Must pass a run period to the correction task!");
248  }
249  // Check the user provided run period
250  TString userRunPeriod = "kNoUserFile";
251  // Test if the period exists in the user file
252  if (fUserConfiguration.IsNull() != true)
253  {
254  if (fUserConfiguration["period"])
255  {
256  userRunPeriod = fUserConfiguration["period"].as<std::string>();
257  }
258  else
259  {
260  AliFatal("User must specify a period. Leave the period as an empty string to apply to all periods.");
261  }
262  }
263 
264  AliDebug(3, TString::Format("userRunPeriod: %s", userRunPeriod.Data()));
265  // Normalize the user run period to lower case to ensure that we don't miss any matches
266  userRunPeriod.ToLower();
267  // "" means the user wants their settings to apply to all periods
268  if (userRunPeriod != "" && userRunPeriod != "knouserfile" && userRunPeriod != fRunPeriod)
269  {
270  AliFatal(TString::Format("User run period \"%s\" does not match the run period of \"%s\" passed to the correction task!", userRunPeriod.Data(), fRunPeriod.Data()));
271  }
272 
273  // Ensure that the user is aware
274  if (userRunPeriod == "")
275  {
276  AliWarning("User run period is an empty string. Settings apply to all run periods!");
277  }
278 
279  // Save configuration into strings so that they can be streamed
280  // Need the stringstream because YAML implements streamers
281  std::stringstream tempConfiguration;
282  tempConfiguration << fUserConfiguration;
283  fUserConfigurationString = tempConfiguration.str();
284  tempConfiguration.str("");
285  tempConfiguration << fDefaultConfiguration;
286  fDefaultConfigurationString = tempConfiguration.str();
287 
288  //AliInfo(TString::Format("User configuration: %s", fUserConfigurationString.c_str()));
289  //AliInfo(TString::Format("Default configuration: %s", fDefaultConfigurationString.c_str()));
290 
291  // Note that it is initialized properly so that the analysis can proceed
293 }
294 
303 {
304  bool returnValue = false;
305  if (filename != "")
306  {
307  if (fConfigurationInitialized == true)
308  {
309  std::ofstream outFile(filename);
310  std::string stringToWrite = userConfig ? fUserConfigurationString : fDefaultConfigurationString;
311  if (stringToWrite == "") {
312  AliWarning(TString::Format("%s configuration is empty!", userConfig ? "User" : "Default"));
313  }
314  outFile << stringToWrite;
315  outFile.close();
316 
317  returnValue = true;
318  }
319  else
320  {
321  AliWarning(TString::Format("Configuration not properly initialized! Cannot print %s configuration!", userConfig ? "user" : "default"));
322  }
323 
324  }
325  else
326  {
327  AliWarning("Please pass a valid filename instead of empty quotes!");
328  }
329  return returnValue;
330 }
331 
341 {
342  // Determine file type
343  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
344  if (mgr) {
345  AliVEventHandler *evhand = mgr->GetInputEventHandler();
346  if (evhand) {
347  if (evhand->InheritsFrom("AliESDInputHandler")) {
348  fIsEsd = true;
349  }
350  else {
351  fIsEsd = false;
352  }
353  }
354  else {
355  AliError("Event handler not found!");
356  }
357  }
358  else {
359  AliError("Analysis manager not found!");
360  }
361 
362  // Determine the suffix of the correction task
363  std::string tempName = GetName();
364  std::size_t foundSuffix = tempName.find("_");
365  if (foundSuffix != std::string::npos) {
366  // +1 to skip "_"
367  fSuffix = tempName.substr(foundSuffix + 1).c_str();
368  }
369 
370  // Initialize YAML configuration
372  // Check that the configuration is initialized
373  if (fConfigurationInitialized != true)
374  {
375  AliFatal("YAML configuration must be initialized before running (ie. the AddTask, run macro or wagon)!");
376  }
377 
378  // Determine component execution order
380 
381  // Check for user defined settings that are not in the default file
383 
384  // Setup input objects
385  // Setup Cells
386  // Cannot do this entirely yet because we need input objects
388  // TEMP PRINT
389  AliDebugStream(2) << "Cell info: " << std::endl;
390  for (auto cellInfo : fCellCollArray) {
391  AliDebugStream(2) << "\tName: " << cellInfo->GetName() << "\tBranch: " << cellInfo->GetBranchName() << "\tIsEmbedding:" << cellInfo->GetIsEmbedding() << std::endl;
392  }
393  // END TEMP PRINT
394  // Create cluster input objects
396  // TEMP PRINT
397  fClusterCollArray.Print();
398  // END TEMP PRINT
399  // Create track input objects
401  // TEMP PRINT
402  fParticleCollArray.Print();
403  // END TEMP PRINT
404 
405  // Initialize components
407 }
408 
419 void AliEmcalCorrectionTask::DetermineComponentsToExecute(std::vector <std::string> & correctionComponents)
420 {
421  std::vector <std::string> executionOrder;
422  // executionOrder determines the order of tasks to execute, but it doesn't name the particular tasks
424 
425  // Possible components to create from both the user and default configurations
426  // Use set so that the possible components are not repeated
427  std::set <std::string> possibleComponents;
428  for (auto node : fUserConfiguration) {
429  possibleComponents.insert(node.first.as<std::string>());
430  }
431  for (auto node : fDefaultConfiguration) {
432  possibleComponents.insert(node.first.as<std::string>());
433  }
434 
435  // Determine the correction names associated with the correction task
436  std::string expectedComponentName = "";
437  bool foundSuffixComponent = false;
438  bool foundComponent = false;
439  bool componentEnabled = true;
440 
441  // Execution order determines the order that corrections should be added to our execution list
442  for (auto & execName : executionOrder)
443  {
444  // Construct the expected component name with the suffix
445  expectedComponentName = TString::Format("%s_%s", execName.c_str(), fSuffix.c_str()).Data();
446  foundComponent = false;
447  componentEnabled = false;
448 
449  foundComponent = CheckPossibleNamesForComponentName(expectedComponentName, possibleComponents);
450  if (foundComponent)
451  {
452  // Check if the component is enabled
453  AliEmcalCorrectionComponent::GetProperty("enabled", componentEnabled, fUserConfiguration, fDefaultConfiguration, true, expectedComponentName);
454  // If enabled, then store the name so that it can be executed
455  if (componentEnabled == true) {
456  foundSuffixComponent = true;
457  correctionComponents.push_back(expectedComponentName);
458  }
459  else {
460  AliInfo(TString::Format("Component %s is disabled and will not be run!", expectedComponentName.c_str()));
461  }
462 
463  continue;
464  }
465  else
466  {
467  // Look for the normal component
468  expectedComponentName = execName;
469  foundComponent = CheckPossibleNamesForComponentName(expectedComponentName, possibleComponents);
470  // Check if it is enabled
471  AliEmcalCorrectionComponent::GetProperty("enabled", componentEnabled, fUserConfiguration, fDefaultConfiguration, true, expectedComponentName);
472 
473  if (componentEnabled == true) {
474  if (foundSuffixComponent == true) {
475  AliFatal(TString::Format("Found earlier component %s with suffix \"%s\", but could not found component %s with that same suffix!", correctionComponents.back().c_str(), fSuffix.c_str(), expectedComponentName.c_str()));
476  }
477  else {
478  // Take the normal component and store it to be executed
479  correctionComponents.push_back(expectedComponentName);
480  }
481  }
482  else {
483  AliInfo(TString::Format("Component %s is disabled and will not be run!", expectedComponentName.c_str()));
484  }
485  }
486  }
487 
488  // Need to append "AliEmcalCorrection" to allow the tasks to be found!
489  AliDebug(2, "Found EMCal Correction Components: ");
490  for (auto & component : correctionComponents)
491  {
492  component = "AliEmcalCorrection" + component;
493  AliDebug(2, TString::Format("%s", component.c_str()) );
494  }
495 }
496 
508 bool AliEmcalCorrectionTask::CheckPossibleNamesForComponentName(std::string & name, std::set <std::string> & possibleComponents)
509 {
510  bool foundComponent = false;
511  for (auto & possibleComponent : possibleComponents)
512  {
513  if (possibleComponent == name) {
514  foundComponent = true;
515  break;
516  }
517  }
518 
519  return foundComponent;
520 }
521 
532 void AliEmcalCorrectionTask::GetPropertyNamesFromNode(const std::string & componentName, const YAML::Node & node, std::set <std::string> & propertyNames, const bool nodeRequired)
533 {
534  YAML::Node tempNode;
535  AliEmcalCorrectionComponent::GetProperty(componentName, tempNode, YAML::Node(), node, nodeRequired, "");
536  for (auto propertyName : tempNode)
537  {
538  propertyNames.insert(propertyName.first.as<std::string>());
539  }
540 }
541 
551 {
552  // Names of properties for a particular component in the user and default configurations
553  std::set <std::string> userPropertyNames;
554  std::set <std::string> defaultPropertyNames;
555  // Notes whether a match was found between user and default properties
556  bool foundMatch = false;
557  std::string tempComponentName = "";
558 
559  // Loop over all components
560  for (const auto componentName : fOrderedComponentsToExecute)
561  {
562  // Reset for each loop
563  userPropertyNames.clear();
564  defaultPropertyNames.clear();
565  // We need to remove "AliEmcalCorrection" so that the correction will be found in the configuration
566  // "AliEmcalCorrection" is 18 characters
567  tempComponentName = componentName.substr(componentName.find("AliEmcalCorrection")+18);
568 
569  AliDebugStream(2) << "Checking component " << componentName << " for unmatched user settings" << std::endl;
570 
571  // Get the user property names
572  GetPropertyNamesFromNode(tempComponentName, fUserConfiguration, userPropertyNames, false);
573 
574  // Get the same from default
575  // Not required here because the default configuration may not have the specialized component
576  GetPropertyNamesFromNode(tempComponentName, fDefaultConfiguration, defaultPropertyNames, false);
577 
578  // We need to check the base correction as well to fill out the options
579  if (tempComponentName.find("_") != std::string::npos) {
580  // Get the base user component
581  GetPropertyNamesFromNode(tempComponentName.substr(0, tempComponentName.find("_")), fUserConfiguration, userPropertyNames, false);
582 
583  // Required here because the default must have the base component!
584  GetPropertyNamesFromNode(tempComponentName.substr(0, tempComponentName.find("_")), fDefaultConfiguration, defaultPropertyNames, true);
585  }
586 
587  // Check each property defined in the user file for a match to the properties in the default file
588  for (auto userPropertyName : userPropertyNames)
589  {
590  AliDebugStream(2) << "Checking property " << userPropertyName << std::endl;
591  foundMatch = false;
592  for (auto defaultPropertyName : defaultPropertyNames)
593  {
594  if (userPropertyName == defaultPropertyName) {
595  AliDebugStream(2) << "Found match of " << userPropertyName << " with " << defaultPropertyName << std::endl;
596  foundMatch = true;
597  }
598  }
599  if (foundMatch == false) {
600  AliFatal(TString::Format("Property \"%s:%s\" defined in the user configuration file cannot be found in the default configuration file! Check the spelling in your user file!", tempComponentName.c_str(), userPropertyName.c_str()));
601  }
602  }
603  }
604 }
605 
613 {
614  // Iterate over the ordered components list and create the components
615  AliEmcalCorrectionComponent * component = 0;
616  for (auto componentName : fOrderedComponentsToExecute)
617  {
618  std::string noPrefixComponentName = componentName.substr(0, componentName.find("_" + fSuffix));
619  component = AliEmcalCorrectionComponentFactory::createInstance(noPrefixComponentName);
620  if (!component)
621  {
622  AliFatal(TString::Format("Failed to create requested component %s!", componentName.c_str()));
623  }
624 
625  // For setting names of tasks to differentiate between tasks of the same class
626  component->SetName(componentName.c_str());
627  component->SetTitle(componentName.c_str());
628 
629  // Initialize the YAML configurations in each component
632 
633  // configure needed fields for components to properly initialize
634  component->SetIsESD(fIsEsd);
635 
636  // Add the require containers to the component
637  // Cells must be set during UserExec() because we need to add them as a pointer
639  AddContainersToComponent(component, kTrack);
640 
641  // Initialize each component
642  component->Initialize();
643 
644  if (component)
645  {
646  AliInfo(TString::Format("Successfully added correction task: %s", componentName.c_str()));
647  fCorrectionComponents.push_back(component);
648  }
649  }
650 }
651 
661 {
662  AliDebug(3, Form("%s", __PRETTY_FUNCTION__));
663 
664  // Check that the configuration is initialized
665  if (fConfigurationInitialized != true)
666  {
667  AliFatal("YAML configuration must be initialized before running (ie. the AddTask, run macro or wagon)!");
668  }
669 
670  // Show the configurations info this is available
671  AliDebugStream(4) << "User configuration string: " << fUserConfigurationString << std::endl;
672  AliDebugStream(4) << "User configuration: " << fUserConfiguration << std::endl;
673  AliDebugStream(4) << "Default configuration string: " << fDefaultConfigurationString << std::endl;
674  AliDebugStream(4) << "Default configuration: " << fDefaultConfiguration << std::endl;
675 
676  // YAML Objects cannot be streamed, so we need to reinitialize them here.
677  // They need reinitialize if they are null
678  if (fUserConfiguration.IsNull() == true && fUserConfigurationString != "")
679  {
680  AliInfo("Reinitializing user configuration from string. Expected if running on grid!");
682  }
683  if (fDefaultConfiguration.IsNull() == true)
684  {
685  AliInfo("Reinitializing default configuration from string. Expected if running on grid!");
687  }
688 
689  // Debug to check that the configuration has been (re)initiailzied has been completed correctly
690  AliDebugStream(4) << "(Re)initialized user configuration: " << fUserConfigurationString << std::endl;
691  AliDebugStream(4) << "(Re)initialized user configuration: " << fUserConfiguration << std::endl;
692  AliDebugStream(4) << "(Re)initialized default configuration: " << fDefaultConfigurationString << std::endl;
693  AliDebugStream(4) << "(Re)initialized default configuration: " << fDefaultConfiguration << std::endl;
694 
695  if (fForceBeamType == kpp)
696  fNcentBins = 1;
697 
698  // Allow for output files
699  OpenFile(1);
700  fOutput = new TList();
701  fOutput->SetOwner();
702 
704 
705  PostData(1, fOutput);
706 }
707 
715 {
716  // Run the initialization for all derived classes.
717  AliDebug(3, Form("%s", __PRETTY_FUNCTION__));
718  for (auto component : fCorrectionComponents)
719  {
720  // Set cent bins (usually used for hist creation)
721  // It cannot be set until now because it can be changed after initialization
722  // For instance, by SetForceBeamType()
723  component->SetNcentralityBins(fNcentBins);
724 
725  component->UserCreateOutputObjects();
726 
727  if (component->GetOutputList() != 0)
728  {
729  // Adds a list to the list -- this doesn't work for some unknown reason
730  //fOutput->Add(component->GetOutputList());
731 
732  // iterate through lists for each component, and fill in output
733  TList* t = new TList();
734  t->SetName(component->GetName());
735  fOutput->AddLast(t);
736  t = (TList*)fOutput->Last();
737  TIter next(component->GetOutputList());
738  while (TObject *obj = next()){
739  t->Add(obj);
740  }
741 
742  AliDebug(1, TString::Format("Added output list from task %s to output.", component->GetName()));
743  }
744  }
745 }
746 
755 {
756  // Get container node
757  std::string inputObjectName = "";
758  if (inputObjectType == kCluster) {
759  inputObjectName = "clusterContainers";
760  }
761  else if (inputObjectType == kTrack) {
762  inputObjectName = "trackContainers";
763  }
764  else if (inputObjectType == kCaloCells) {
765  inputObjectName = "cells";
766  }
767  else {
768  AliFatal(TString::Format("Unrecognized input object type %d", inputObjectType));
769  }
770 
771  return inputObjectName;
772 }
773 
783 void AliEmcalCorrectionTask::GetNodeForInputObjects(YAML::Node & inputNode, YAML::Node & nodeToRetrieveFrom, std::string & inputObjectName, bool requiredProperty)
784 {
785  // Get the user input node
786  AliEmcalCorrectionComponent::GetProperty(inputObjectName.c_str(), inputNode, YAML::Node(), nodeToRetrieveFrom, requiredProperty, "inputObjects");
787 
788  // Get the user shared node and add it back to the user node so that shared parameters are available
789  if (nodeToRetrieveFrom["sharedParameters"]) {
790  inputNode["sharedParameters"] = nodeToRetrieveFrom["sharedParameters"];
791  }
792 }
793 
802 void AliEmcalCorrectionTask::SetupContainersFromInputNodes(InputObject_t inputObjectType, YAML::Node & userInputObjectNode, YAML::Node & defaultInputObjectNode, std::set <std::string> & requestedContainers)
803 {
804  // Our node contains all of the objects that we will want to create.
805  for(auto & containerName : requestedContainers)
806  {
807  // The section is the container name
808  //std::string containerName = it->first.as<std::string>();
809  // Skip over the sharedParamters node. TODO: May be able to remove this! Previously was a node, but now is a string
810  // Also skip if the particle or cluster container already exists
811  if (containerName == "sharedParameters" || GetParticleContainer(containerName.c_str()) || GetClusterContainer(containerName.c_str())) {
812  continue;
813  }
814 
815  AliDebug(2, TString::Format("Processing container %s of inputType %d", containerName.c_str(), inputObjectType));
816  if (inputObjectType == kCluster || inputObjectType == kTrack) {
817  SetupContainer(inputObjectType, containerName, userInputObjectNode, defaultInputObjectNode);
818  }
819  else if (inputObjectType == kCaloCells) {
820  SetupCellsInfo(containerName, userInputObjectNode, defaultInputObjectNode);
821  }
822  }
823 }
824 
835 void AliEmcalCorrectionTask::SetupCellsInfo(std::string containerName, YAML::Node & userNode, YAML::Node & defaultNode)
836 {
837  // Define cell info
839 
840  AliDebugStream(2) << "User: " << std::endl << userNode << std::endl << "default: " << std::endl << defaultNode << std::endl;
841 
842  // Set properties
843  // Cells (object) name
844  cellObj->SetName(containerName);
845  // Branch name
846  std::string tempString = "";
847  AliEmcalCorrectionComponent::GetProperty("branchName", tempString, userNode, defaultNode, true, containerName);
848  if (tempString == "usedefault") {
850  }
851  cellObj->SetBranchName(tempString);
852 
853  // IsEmbedding
854  bool tempBool = false;
855  AliEmcalCorrectionComponent::GetProperty("embedded", tempString, userNode, defaultNode, false, containerName);
856  cellObj->SetIsEmbedding(tempBool);
857 
858  // Add to the array to keep track of it
859  fCellCollArray.push_back(cellObj);
860 }
861 
877 {
878  // Get container node
879  std::string inputObjectName = GetInputFieldNameFromInputObjectType(inputObjectType);
880 
881  // Get the user and default input nodes for the object type
882  YAML::Node userInputObjectNode;
883  YAML::Node defaultInputObjectNode;
884  GetNodeForInputObjects(userInputObjectNode, fUserConfiguration, inputObjectName, false);
885  GetNodeForInputObjects(defaultInputObjectNode, fDefaultConfiguration, inputObjectName, true);
886 
887  AliDebugStream(3) << "userInputObjectNode: " << userInputObjectNode << std::endl;
888  AliDebugStream(3) << "defaultInputObjectNode: " << defaultInputObjectNode << std::endl;
889 
890  // Determine which containers we need based on which are requested by the enabled correction tasks
891  std::set <std::string> requestedContainers;
892  std::vector <std::string> componentRequest;
893  for ( const auto & componentName : fOrderedComponentsToExecute )
894  {
895  componentRequest.clear();
896  // Not required because not all components will have all kinds of containers
897  // "AliEmcalCorrection" is 18 characters
898  AliEmcalCorrectionComponent::GetProperty(inputObjectName + "Names", componentRequest, fUserConfiguration, fDefaultConfiguration, false, componentName.substr(componentName.find("AliEmcalCorrection")+18));
899  for ( auto & req : componentRequest )
900  {
901  AliDebugStream(3) << "Component " << componentName << " requested container name " << req << std::endl;
902  requestedContainers.insert(req);
903  }
904  }
905 
906  AliInfoStream() << inputObjectName << " Containers requested by components: " << std::endl;
907  for (auto & str : requestedContainers) {
908  AliInfoStream() << "\t" << str << std::endl;;
909  }
910 
911  // Create all requested containers
912  AliDebug(2, TString::Format("Setting up requested containers!"));
913  SetupContainersFromInputNodes(inputObjectType, userInputObjectNode, defaultInputObjectNode, requestedContainers);
914 }
915 
933 void AliEmcalCorrectionTask::SetupContainer(InputObject_t inputObjectType, std::string containerName, YAML::Node & userNode, YAML::Node & defaultNode)
934 {
935  // Create container
936  AliDebugStream(2) << "Adding container" << std::endl;
937  AliEmcalContainer * cont = AddContainer(inputObjectType, containerName, userNode, defaultNode);
938  AliDebugStream(2) << "Added container" << std::endl;
939 
940  // Set the container properties
941  //
942  // TODO: Consider if this can be converted to a map to function pointers. There are a number of details
943  // which can make it a bit complicated. Those details include inheritance, pointing to member
944  // functions, etc. It should all be possible, but may not be worth all of the extra work and code.
945  // Example ccode:
946  // SetValueInContainer("minPt", &cont::SetMinPt, tempDouble, userNode, defaultNode);
947  // SetValueInContainer("minE", &cont::SetMinE, tempDouble, userNode, defaultNode);
948 
949  // Temporary variables to store requested properties
950  std::string tempString = "";
951  Double_t tempDouble = 0;
952  bool tempBool = false;
953 
954  // AliEmcalContainer properties
955  // Min Pt
956  bool result = AliEmcalCorrectionComponent::GetProperty("minPt", tempDouble, userNode, defaultNode, false, containerName);
957  if (result) {
958  AliDebugStream(2) << cont->GetName() << ": Setting minPt of " << tempDouble << std::endl;
959  cont->SetMinPt(tempDouble);
960  }
961  // Min E
962  result = AliEmcalCorrectionComponent::GetProperty("minE", tempDouble, userNode, defaultNode, false, containerName);
963  if (result) {
964  AliDebugStream(2) << cont->GetName() << ": Setting minE of " << tempDouble << std::endl;
965  cont->SetMinE(tempDouble);
966  }
967  // Eta min, max
968  result = AliEmcalCorrectionComponent::GetProperty("minEta", tempDouble, userNode, defaultNode, false, containerName);
969  if (result) {
970  // Only continue checking if the min is there, since we must set both together
971  Double_t tempDouble2 = 0;
972  result = AliEmcalCorrectionComponent::GetProperty("maxEta", tempDouble, userNode, defaultNode, false, containerName);
973  if (result) {
974  AliDebugStream(2) << cont->GetName() << ": Setting eta limits of " << tempDouble << " to " << tempDouble2 << std::endl;
975  cont->SetEtaLimits(tempDouble, tempDouble2);
976  }
977  }
978  // Phi min, max
979  result = AliEmcalCorrectionComponent::GetProperty("minPhi", tempDouble, userNode, defaultNode, false, containerName);
980  if (result) {
981  // Only continue checking if the min is there, since we must set both together
982  Double_t tempDouble2 = 0;
983  result = AliEmcalCorrectionComponent::GetProperty("maxPhi", tempDouble, userNode, defaultNode, false, containerName);
984  if (result) {
985  AliDebugStream(2) << cont->GetName() << ": Setting phi limits of " << tempDouble << " to " << tempDouble2 << std::endl;
986  cont->SetPhiLimits(tempDouble, tempDouble2);
987  }
988  }
989  // Embedded
990  // TODO: Enable embedded when that branch is committed!
991  /*result = AliEmcalCorrectionComponent::GetProperty("IsEmbedded", tempBool, userNode, defaultNode, false, containerName);
992  if (result) {
993  AliDebugStream(2) << cont->GetName() << ": Setting embedding to " << (tempBool ? "enabled" : "disabled") << std::endl;
994  cont->SetIsEmbedding(tempBool);
995  }*/
996 
997  // Cluster specific properties
998  AliClusterContainer * clusterContainer = dynamic_cast<AliClusterContainer *>(cont);
999  if (clusterContainer) {
1000  // Default energy
1001  // Probably not needed for the corrections
1002  /*result = AliEmcalCorrectionComponent::GetProperty("defaultClusterEnergy", tempString, userNode, defaultNode, false, containerName);
1003  if (result) {
1004  // Need to get the enumeration
1005  AliVCluster::VCluUserDefEnergy_t clusterEnergyType = clusterEnergyTypeMap.at(tempString);
1006  AliDebugStream(2) << clusterContainer->GetName() << ": Setting cluster energy type to " << clusterEnergyType << std::endl;
1007  clusterContainer->SetDefaultClusterEnergy(clusterEnergyType);
1008  }*/
1009 
1010  // NonLinCorrEnergyCut
1011  result = AliEmcalCorrectionComponent::GetProperty("clusNonLinCorrEnergyCut", tempDouble, userNode, defaultNode, false, containerName);
1012  if (result) {
1013  AliDebugStream(2) << clusterContainer->GetName() << ": Setting clusNonLinCorrEnergyCut of " << tempDouble << std::endl;
1014  clusterContainer->SetClusNonLinCorrEnergyCut(tempDouble);
1015  }
1016 
1017  // HadCorrEnergyCut
1018  result = AliEmcalCorrectionComponent::GetProperty("clusHadCorrEnergyCut", tempDouble, userNode, defaultNode, false, containerName);
1019  if (result) {
1020  AliDebugStream(2) << clusterContainer->GetName() << ": Setting clusHadCorrEnergyCut of " << tempDouble << std::endl;
1021  clusterContainer->SetClusHadCorrEnergyCut(tempDouble);
1022  }
1023 
1024  // SetIncludePHOS
1025  result = AliEmcalCorrectionComponent::GetProperty("includePHOS", tempBool, userNode, defaultNode, false, containerName);
1026  if (result) {
1027  AliDebugStream(2) << clusterContainer->GetName() << ": Setting Include PHOS to " << (tempBool ? "enabled" : "disabled") << std::endl;
1028  clusterContainer->SetIncludePHOS(tempBool);
1029  }
1030  }
1031 
1032  // Track specific
1033  AliTrackContainer * trackContainer = dynamic_cast<AliTrackContainer *>(cont);
1034  if (trackContainer) {
1035  // Track selection
1036  // AOD Filter bits as a sequence
1037  std::vector <UInt_t> filterBitsVector;
1038  result = AliEmcalCorrectionComponent::GetProperty("aodFilterBits", filterBitsVector, userNode, defaultNode, false, containerName);
1039  if (result){
1040  UInt_t filterBits = 0;
1041  for (int filterBit : filterBitsVector) {
1042  filterBits += filterBit;
1043  }
1044  AliDebugStream(2) << trackContainer->GetName() << ": Setting filterBits of " << filterBits << std::endl;
1045  trackContainer->SetAODFilterBits(filterBits);
1046  }
1047 
1048  // SetTrackFilterType enum
1049  result = AliEmcalCorrectionComponent::GetProperty("trackFilterType", tempString, userNode, defaultNode, false, containerName);
1050  if (result) {
1051  // Need to get the enumeration
1052  AliEmcalTrackSelection::ETrackFilterType_t trackFilterType = trackFilterTypeMap.at(tempString);
1053  AliDebugStream(2) << trackContainer->GetName() << ": Setting trackFilterType of " << trackFilterType << std::endl;
1054  trackContainer->SetTrackFilterType(trackFilterType);
1055  }
1056  }
1057 }
1058 
1074 std::string AliEmcalCorrectionTask::DetermineUseDefaultName(InputObject_t objType, bool esdMode, bool returnObjectType)
1075 {
1076  std::string returnValue = "";
1077  if (objType == kCluster) {
1078  if (esdMode == true) {
1079  if (returnObjectType == true) {
1080  returnValue = "AliESDCaloCluster";
1081  }
1082  else {
1083  returnValue = "CaloClusters";
1084  }
1085  }
1086  else {
1087  if (returnObjectType == true) {
1088  returnValue = "AliAODCaloCluster";
1089  }
1090  else {
1091  returnValue = "caloClusters";
1092  }
1093  }
1094  }
1095  else if (objType == kTrack) {
1096  if (esdMode == true) {
1097  if (returnObjectType == true) {
1098  returnValue = "AliESDtrack";
1099  }
1100  else {
1101  returnValue = "Tracks";
1102  }
1103  }
1104  else {
1105  if (returnObjectType == true) {
1106  returnValue = "AliAODTrack";
1107  }
1108  else {
1109  returnValue = "tracks";
1110  }
1111  }
1112  }
1113  else if (objType == kCaloCells) {
1114  if (esdMode == true) {
1115  if (returnObjectType == true) {
1116  returnValue = "AliESDCaloCells";
1117  }
1118  else {
1119  returnValue = "EMCALCells";
1120  }
1121  }
1122  else {
1123  if (returnObjectType == true) {
1124  returnValue = "AliAODCaloCells";
1125  }
1126  else {
1127  returnValue = "emcalCells";
1128  }
1129  }
1130  }
1131  else {
1132  // Default to empty if we are given an unrecognized type with "usedefault"
1133  returnValue = "";
1134  }
1135 
1136  return returnValue;
1137 }
1138 
1156 AliEmcalContainer * AliEmcalCorrectionTask::AddContainer(InputObject_t contType, std::string & containerName, YAML::Node & userNode, YAML::Node & defaultNode)
1157 {
1158  // Determine the type of branch to request
1159  std::string containerBranch = "";
1160  if (contType != kCluster && contType != kTrack){
1161  AliFatal("Must specify type of container when requesting branch.");
1162  }
1163 
1164  // Retrieve branch name
1165  // YAML::Node() is just an empty node
1166  AliDebugStream(2) << "User Node: " << userNode << std::endl;
1167  AliDebugStream(2) << "Default Node: " << defaultNode << std::endl;
1168  AliEmcalCorrectionComponent::GetProperty("branchName", containerBranch, userNode, defaultNode, true, containerName);
1169  // Should be unnecessary, since the user can only do this if done explicitly.
1170  /*if (containerBranch == "")
1171  {
1172  AliFatal(TString::Format("Request %i container, but the container branch is empty!", contType));
1173  }*/
1174 
1175  // Determine proper name if using "usedefault" pattern
1176  if (containerBranch == "usedefault") {
1177  containerBranch = DetermineUseDefaultName(contType, fIsEsd);
1178  }
1179 
1180  // Create containers and set them to the name of the component
1181  AliEmcalContainer * cont = 0;
1182  if (contType == kCluster)
1183  {
1184  cont = new AliClusterContainer(containerBranch.c_str());
1185  AdoptClusterContainer(dynamic_cast<AliClusterContainer *>(cont));
1186  }
1187  else if (contType == kTrack)
1188  {
1189  if (containerBranch == "mcparticles") {
1190  cont = new AliMCParticleContainer(containerBranch.c_str());
1191  }
1192  else {
1193  cont = new AliTrackContainer(containerBranch.c_str());
1194  }
1195  AdoptParticleContainer(dynamic_cast<AliParticleContainer *>(cont));
1196  }
1197  cont->SetName(containerName.c_str());
1198 
1199  return cont;
1200 }
1201 
1210 {
1211  std::string inputObjectName = GetInputFieldNameFromInputObjectType(inputObjectType);
1212  // Need to be of the form "clusterContainersNames"
1213  inputObjectName = inputObjectName + "Names";
1214 
1215  std::vector <std::string> inputObjects;
1216  // Not required, because not all components need Clusters or Tracks
1217  AliEmcalCorrectionComponent::GetProperty(inputObjectName.c_str(), inputObjects, fUserConfiguration, fDefaultConfiguration, false, component->GetName());
1218 
1219  //std::cout << "inputObjects.size(): " << inputObjects.size() << std::endl;
1220 
1221  // If it is not found, then there will be nothing to iterate over, so we don't need to explicitly check the return value
1222  for (auto const & str : inputObjects)
1223  {
1224  // TODO: Generalize to arrays for clusters and tracks...
1225  // NOTE: The AliEmcalContainer derived objects operate differently than the cells. The containers should be added during initialization while the cells should be added during ExecOnce()!
1226  if (inputObjectType == kCluster)
1227  {
1228  AliEmcalContainer * cont = GetClusterContainer(str.c_str());
1229  AliDebugStream(2) << "Adding cluster container " << str << " of array " << cont->GetArrayName() << " to component " << component->GetName() << std::endl;
1230  component->SetClusterContainer(GetClusterContainer(str.c_str()));
1231  }
1232  else if (inputObjectType == kTrack)
1233  {
1234  AliEmcalContainer * cont = GetParticleContainer(str.c_str());
1235  AliDebugStream(2) << "Adding particle container " << str << " of array " << cont->GetArrayName() << " to component " << component->GetName() << std::endl;
1236  component->SetParticleContainer(GetParticleContainer(str.c_str()));
1237  }
1238  else if (inputObjectType == kCaloCells)
1239  {
1240  // NOTE: This operates different than the others. This should be executed during run time rather than during initialization!
1241  if (inputObjects.size() > 1) {
1242  AliFatal(TString::Format("Component %s requested more than one cell branch, but this is not supported! Check the configuration!", component->GetName()));
1243  }
1244 
1245  // If we've made it here, this must be at least one entry
1246  AliDebugStream(2) << "Adding calo cells " << GetCellContainer(str)->GetName() << " of branch name " << GetCellContainer(str)->GetBranchName() << "to component " << component->GetName() << std::endl;
1247  component->SetCaloCells(GetCellContainer(str)->GetCells());
1248  AliDebugStream(3) << "component GetNumberOfCells: " << component->GetCaloCells()->GetNumberOfCells() << std::endl;
1249  }
1250  }
1251 }
1252 
1260 AliEmcalCorrectionCellContainer * AliEmcalCorrectionTask::GetCellContainer(const std::string & cellsContainerName) const
1261 {
1262  for (auto cellContainer : fCellCollArray)
1263  {
1264  if (cellContainer->GetName() == cellsContainerName) {
1265  return cellContainer;
1266  }
1267  }
1268 
1269  return 0;
1270 }
1271 
1279 {
1280  AliDebugStream(2) << "Retrieving cells object " << cellContainer->GetName() << std::endl;
1281  // Check for embedding and return object
1282  AliVEvent * event = GetEvent(InputEvent(), cellContainer->GetIsEmbedding());
1283 
1284  cellContainer->SetCells(dynamic_cast<AliVCaloCells *>(event->FindListObject(cellContainer->GetBranchName().c_str())));
1285 }
1286 
1292 {
1293  // Run the initialization for all derived classes.
1294  AliDebug(3, Form("%s", __PRETTY_FUNCTION__));
1295  for (auto component : fCorrectionComponents)
1296  {
1297  // Setup geomertry
1298  component->SetEMCALGeometry(fGeom);
1299 
1300  // Add the requested cells to the component
1301  //AliDebugStream(3) << "Adding CaloCells" << std::endl;
1303  //AliDebugStream(3) << "Added CaloCells" << std::endl;
1304 
1305  // Component ExecOnce()
1306  component->ExecOnce();
1307  }
1308 }
1309 
1315 {
1316  fVertex[0] = 0;
1317  fVertex[1] = 0;
1318  fVertex[2] = 0;
1319  fNVertCont = 0;
1320 
1321  const AliVVertex *vert = InputEvent()->GetPrimaryVertex();
1322  if (vert) {
1323  vert->GetXYZ(fVertex);
1324  fNVertCont = vert->GetNContributors();
1325  }
1326 
1327  fBeamType = GetBeamType();
1328 
1329  if (fBeamType == kAA || fBeamType == kpA ) {
1331  AliMultSelection *MultSelection = static_cast<AliMultSelection*>(InputEvent()->FindListObject("MultSelection"));
1332  if (MultSelection) {
1333  fCent = MultSelection->GetMultiplicityPercentile(fCentEst.Data());
1334  }
1335  else {
1336  AliWarning("Could not retrieve centrality information! Assuming 99");
1337  }
1338  }
1339  else { // old centrality estimation < 2015
1340  AliCentrality *aliCent = InputEvent()->GetCentrality();
1341  if (aliCent) {
1342  fCent = aliCent->GetCentralityPercentile(fCentEst.Data());
1343  }
1344  else {
1345  AliWarning("Could not retrieve centrality information! Assuming 99");
1346  }
1347  }
1348 
1349  if (fNcentBins==4) {
1350  if (fCent >= 0 && fCent < 10) fCentBin = 0;
1351  else if (fCent >= 10 && fCent < 30) fCentBin = 1;
1352  else if (fCent >= 30 && fCent < 50) fCentBin = 2;
1353  else if (fCent >= 50 && fCent <= 100) fCentBin = 3;
1354  else {
1355  AliWarning(Form("Negative centrality: %f. Assuming 99", fCent));
1356  fCentBin = fNcentBins-1;
1357  }
1358  }
1359  else if (fNcentBins==5) { // for PbPb 2015
1360  if (fCent >= 0 && fCent < 10) fCentBin = 0;
1361  else if (fCent >= 10 && fCent < 30) fCentBin = 1;
1362  else if (fCent >= 30 && fCent < 50) fCentBin = 2;
1363  else if (fCent >= 50 && fCent <= 90) fCentBin = 3;
1364  else if (fCent > 90) {
1365  fCent = 99;
1366  fCentBin = 4;
1367  }
1368  else {
1369  AliWarning(Form("Negative centrality: %f. Assuming 99", fCent));
1370  fCentBin = fNcentBins-1;
1371  }
1372  }
1373  else {
1374  Double_t centWidth = (fMaxCent-fMinCent)/(Double_t)fNcentBins;
1375  if(centWidth>0.) {
1376  fCentBin = TMath::FloorNint(fCent/centWidth);
1377  }
1378  else {
1379  fCentBin = 0;
1380  }
1381  if (fCentBin>=fNcentBins) {
1382  AliWarning(Form("fCentBin too large: cent = %f fCentBin = %d. Assuming 99", fCent, fCentBin));
1383  fCentBin = fNcentBins-1;
1384  }
1385  }
1386  }
1387  else {
1388  fCent = 99;
1389  fCentBin = 0;
1390  }
1391 
1392  AliEmcalContainer* cont = 0;
1393 
1394  TIter nextPartColl(&fParticleCollArray);
1395  while ((cont = static_cast<AliEmcalContainer*>(nextPartColl()))) cont->NextEvent();
1396 
1397  TIter nextClusColl(&fClusterCollArray);
1398  while ((cont = static_cast<AliEmcalContainer*>(nextClusColl()))) cont->NextEvent();
1399 
1400  return kTRUE;
1401 }
1402 
1403 
1415 {
1416  if (!InputEvent()) {
1417  AliError("Could not retrieve event! Returning!");
1418  return;
1419  }
1420 
1421  if (fNeedEmcalGeom) {
1422  fGeom = AliEMCALGeometry::GetInstanceFromRunNumber(InputEvent()->GetRunNumber());
1423  if (!fGeom) {
1424  AliFatal("Can not get EMCal geometry instance. If you do not need the EMCal geometry, disable it by setting task->SetNeedEmcalGeometry(kFALSE).");
1425  return;
1426  }
1427  }
1428 
1429  // Load all requested track branches - each container knows name already
1430  for (Int_t i =0; i<fParticleCollArray.GetEntriesFast(); i++) {
1431  AliParticleContainer *cont = static_cast<AliParticleContainer*>(fParticleCollArray.At(i));
1433  cont->SetArray(InputEvent());
1434  }
1435 
1436  // Load all requested cluster branches - each container knows name already
1437  for (Int_t i =0; i<fClusterCollArray.GetEntriesFast(); i++) {
1438  AliClusterContainer *cont = static_cast<AliClusterContainer*>(fClusterCollArray.At(i));
1440  cont->SetArray(InputEvent());
1441  }
1442 
1443  // Determine the proper pointer for each cell object and save them to the cell contianer
1444  // At this point, they should all be created
1445  for (auto cellObj : fCellCollArray)
1446  {
1448  }
1449 
1450  fEventInitialized = kTRUE;
1451 
1453 }
1454 
1464 AliVEvent * AliEmcalCorrectionTask::GetEvent(AliVEvent * inputEvent, bool isEmbedding)
1465 {
1466  AliVEvent * event = 0;
1467  if (isEmbedding) {
1468  // TODO: Enable embedded when that branch is committed!
1469  /*const AliAnalysisTaskEmcalEmbeddingHelper* embedding = AliAnalysisTaskEmcalEmbeddingHelper::GetInstance();
1470  if (!embedding) return 0;
1471 
1472  event = embedding->GetExternalEvent();*/
1473  }
1474  else {
1475  event = inputEvent;
1476  }
1477 
1478  return event;
1479 }
1480 
1490 void AliEmcalCorrectionTask::CheckForContainerArray(AliEmcalContainer * cont, InputObject_t objectType)
1491 {
1492  // TODO: Enable embedded when that branch is committed!
1493  //AliVEvent * event = GetEvent(InputEvent(), cont->GetIsEmbedding());
1494  AliVEvent * event = GetEvent(InputEvent());
1495 
1496  TClonesArray * array = dynamic_cast<TClonesArray *>(event->FindListObject(cont->GetArrayName()));
1497  if (!array) {
1498  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()));
1499  array = new TClonesArray(DetermineUseDefaultName(objectType, fIsEsd, true).c_str());
1500  array->SetName(cont->GetArrayName());
1501  event->AddObject(array);
1502  }
1503 }
1504 
1513 {
1514  if (TString(n).IsNull()) return 0;
1515 
1517 
1518  fParticleCollArray.Add(cont);
1519 
1520  return cont;
1521 }
1522 
1531 {
1532  if (TString(n).IsNull()) return 0;
1533 
1534  AliTrackContainer* cont = new AliTrackContainer(n);
1535 
1536  fParticleCollArray.Add(cont);
1537 
1538  return cont;
1539 }
1540 
1549 {
1550  if (TString(n).IsNull()) return 0;
1551 
1553 
1554  fParticleCollArray.Add(cont);
1555 
1556  return cont;
1557 }
1558 
1567 {
1568  if (TString(n).IsNull()) return 0;
1569 
1571 
1572  fClusterCollArray.Add(cont);
1573 
1574  return cont;
1575 }
1576 
1583 {
1584  if (i<0 || i>fParticleCollArray.GetEntriesFast()) return 0;
1585  AliParticleContainer *cont = static_cast<AliParticleContainer*>(fParticleCollArray.At(i));
1586  return cont;
1587 }
1588 
1595 {
1596  if (i<0 || i>fClusterCollArray.GetEntriesFast()) return 0;
1597  AliClusterContainer *cont = static_cast<AliClusterContainer*>(fClusterCollArray.At(i));
1598  return cont;
1599 }
1600 
1607 {
1608  AliParticleContainer *cont = static_cast<AliParticleContainer*>(fParticleCollArray.FindObject(name));
1609  return cont;
1610 }
1611 
1618 {
1619  AliClusterContainer *cont = static_cast<AliClusterContainer*>(fClusterCollArray.FindObject(name));
1620  return cont;
1621 }
1622 
1623 
1629 {
1630  AliDebug(3, Form("%s", __PRETTY_FUNCTION__));
1631 
1632  // Initialize the event if not intialized
1633  if (!fEventInitialized)
1634  ExecOnce();
1635 
1636  // Only continue if we are initialized successfully
1637  if (!fEventInitialized)
1638  return;
1639 
1640  // Get the objects for each event
1641  if (!RetrieveEventObjects())
1642  return;
1643 
1644  // TODO: Consider adding IsEventSelected()??
1645 
1646  // Call run for each correction
1647  if (!Run())
1648  return;
1649 }
1650 
1657 {
1658  // Run the initialization for all derived classes.
1659  AliDebug(3, Form("%s", __PRETTY_FUNCTION__));
1660  for (auto component : fCorrectionComponents)
1661  {
1662  component->SetEvent(InputEvent());
1663  component->SetMCEvent(MCEvent());
1664  component->SetCentralityBin(fCentBin);
1665  component->SetCentrality(fCent);
1666 
1667  component->Run();
1668  }
1669 
1670  PostData(1, fOutput);
1671 
1672  return kTRUE;
1673 }
1674 
1680 {
1681  // Run the initialization for all derived classes.
1682  AliDebug(3, Form("%s", __PRETTY_FUNCTION__));
1683  for (auto component : fCorrectionComponents)
1684  {
1685  component->UserNotify();
1686  }
1687 
1688  return kTRUE;
1689 }
1690 
1696 {
1697  // Destructor
1698 }
1699 
1707 {
1708  if (fForceBeamType != kNA)
1709  return fForceBeamType;
1710 
1711  AliESDEvent *esd = dynamic_cast<AliESDEvent*>(InputEvent());
1712  if (esd) {
1713  const AliESDRun *run = esd->GetESDRun();
1714  TString beamType = run->GetBeamType();
1715  if (beamType == "p-p")
1716  return kpp;
1717  else if (beamType == "A-A")
1718  return kAA;
1719  else if (beamType == "p-A")
1720  return kpA;
1721  else
1722  return kNA;
1723  } else {
1724  Int_t runNumber = InputEvent()->GetRunNumber();
1725  if ((runNumber >= 136851 && runNumber <= 139517) || // LHC10h
1726  (runNumber >= 166529 && runNumber <= 170593)) { // LHC11h
1727  return kAA;
1728  } else if ((runNumber>=188365 && runNumber <= 188366) || // LHC12g
1729  (runNumber >= 195344 && runNumber <= 196608)) { // LHC13b-f
1730  return kpA;
1731  } else {
1732  return kpp;
1733  }
1734  }
1735 }
Int_t fNcentBins
how many centrality bins
void SetBranchName(std::string branchName)
Set the name of the cells branch (NOT the same as the name!)
std::string fSuffix
Default YAML Configuration.
Steering task for the EMCal correction framework.
AliEMCALGeometry * fGeom
! Emcal geometry
const char * filename
Definition: TestFCM.C:1
return jsonbuilder str().c_str()
static bool DoesFileExist(const std::string &filename)
std::string GetName() const
Get the name of the cells object (NOT the same as the branch!)
double Double_t
Definition: External.C:58
AliTrackContainer * AddTrackContainer(const char *n)
void SetClusterContainer(AliClusterContainer *cont)
std::vector< std::string > fOrderedComponentsToExecute
Ordered set of components to execute.
std::string GetInputFieldNameFromInputObjectType(InputObject_t inputObjectType)
AliClusterContainer * GetClusterContainer(Int_t i=0) const
bool CheckPossibleNamesForComponentName(std::string &name, std::set< std::string > &possibleComponents)
std::vector< AliEmcalCorrectionComponent * > fCorrectionComponents
Contains the correction components.
Container with name, TClonesArray and cuts for particles.
TSystem * gSystem
void AdoptClusterContainer(AliClusterContainer *cont)
void SetupConfigurationFilePath(std::string &filename, bool userFile=false)
void UserExec(Option_t *option)
Double_t fMaxCent
max centrality for event selection
Double_t fVertex[3]
! Event vertex
void DetermineComponentsToExecute(std::vector< std::string > &componentsToExecute)
TList * fOutput
! Output for histograms
Wrapper around cells objects for the EMCal Correction Task.
bool fConfigurationInitialized
True if the YAML configuration 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.
void Load()
Definition: UnfoldingHF.C:238
TString fCentEst
name of V0 centrality estimator
void SetAODFilterBits(UInt_t bits)
int Int_t
Definition: External.C:63
std::string fUserConfigurationFilename
! User YAML configruation filename
unsigned int UInt_t
Definition: External.C:33
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)
Sets the Pointer to the actual CaloCells object.
Double_t fCent
! Event centrality
Base class for correction components in the EMCal correction framework.
BeamType
Switch for the beam type.
AliMCParticleContainer * AddMCParticleContainer(const char *n)
std::map< std::string, AliEmcalTrackSelection::ETrackFilterType_t > trackFilterTypeMap
Relates string to the track filter enumeration for YAML configuration.
void SetupContainersFromInputNodes(InputObject_t inputObjectType, YAML::Node &userInputObjectNode, YAML::Node &defaultInputObjectNode, std::set< std::string > &requestedContainers)
void SetIncludePHOS(Bool_t b)
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
Get the name of the cells branch (NOT the same as the name!)
void SetCellsObjectInCellContainerBasedOnProperties(AliEmcalCorrectionCellContainer *cellContainer)
Bool_t fUseNewCentralityEstimation
Use new centrality estimation (for 2015 data)
bool GetIsEmbedding() const
True if the cells are located in the event that is being embedded.
void CheckForContainerArray(AliEmcalContainer *cont, InputObject_t objectType)
Bool_t Data(TH1F *h, Double_t *rangefit, Bool_t writefit, Double_t &sgn, Double_t &errsgn, Double_t &bkg, Double_t &errbkg, Double_t &sgnf, Double_t &errsgnf, Double_t &sigmafit, Int_t &status)
AliEmcalCorrectionCellContainer * GetCellContainer(const std::string &cellsContainerName) const
std::string fDefaultConfigurationFilename
! Default YAML configuration filename
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)
void SetDefaultConfiguration(YAML::Node &node)
ClassImp(AliAnalysisTaskCRC) AliAnalysisTaskCRC
AliParticleContainer * GetParticleContainer(Int_t i=0) const
void AdoptParticleContainer(AliParticleContainer *cont)
void SetCaloCells(AliVCaloCells *cells)
void SetIsEmbedding(bool isEmbedded)
Set to true if the cells are located in the event that is being embedded.
BeamType fBeamType
! Event beam type
Int_t GetRunNumber(TString)
Definition: PlotMuonQA.C:2235
void SetTrackFilterType(ETrackFilterType_t f)
const char Option_t
Definition: External.C:48
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)
Creates an instance of an object based on the name if the name is registered in the map...
void SetName(std::string name)
Set the name of the cells object (NOT the same as the branch!)
bool Bool_t
Definition: External.C:53
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.
AliParticleContainer * AddParticleContainer(const char *n)
Container structure for EMCAL clusters.
Container for MC-true particles within the EMCAL framework.
std::string fUserConfigurationString
Store the user YAML configuration as a string so that it can be streamed.
void GetPropertyNamesFromNode(const std::string &componentName, const YAML::Node &node, std::set< std::string > &propertyNames, const bool nodeRequired)
InputObject_t
Type of input object to be created
TList * OpenFile(const char *fname)
Definition: DrawAnaELoss.C:65
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)