AliPhysics  1a228f7 (1a228f7)
 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 
1025  // Track specific
1026  AliTrackContainer * trackContainer = dynamic_cast<AliTrackContainer *>(cont);
1027  if (trackContainer) {
1028  // Track selection
1029  // AOD Filter bits as a sequence
1030  std::vector <UInt_t> filterBitsVector;
1031  result = AliEmcalCorrectionComponent::GetProperty("aodFilterBits", filterBitsVector, userNode, defaultNode, false, containerName);
1032  if (result){
1033  UInt_t filterBits = 0;
1034  for (int filterBit : filterBitsVector) {
1035  filterBits += filterBit;
1036  }
1037  AliDebugStream(2) << trackContainer->GetName() << ": Setting filterBits of " << filterBits << std::endl;
1038  trackContainer->SetAODFilterBits(filterBits);
1039  }
1040 
1041  // SetTrackFilterType enum
1042  result = AliEmcalCorrectionComponent::GetProperty("trackFilterType", tempString, userNode, defaultNode, false, containerName);
1043  if (result) {
1044  // Need to get the enumeration
1045  AliEmcalTrackSelection::ETrackFilterType_t trackFilterType = trackFilterTypeMap.at(tempString);
1046  AliDebugStream(2) << trackContainer->GetName() << ": Setting trackFilterType of " << trackFilterType << std::endl;
1047  trackContainer->SetTrackFilterType(trackFilterType);
1048  }
1049  }
1050 }
1051 
1067 std::string AliEmcalCorrectionTask::DetermineUseDefaultName(InputObject_t objType, bool esdMode, bool returnObjectType)
1068 {
1069  std::string returnValue = "";
1070  if (objType == kCluster) {
1071  if (esdMode == true) {
1072  if (returnObjectType == true) {
1073  returnValue = "AliESDCaloCluster";
1074  }
1075  else {
1076  returnValue = "CaloClusters";
1077  }
1078  }
1079  else {
1080  if (returnObjectType == true) {
1081  returnValue = "AliAODCaloCluster";
1082  }
1083  else {
1084  returnValue = "caloClusters";
1085  }
1086  }
1087  }
1088  else if (objType == kTrack) {
1089  if (esdMode == true) {
1090  if (returnObjectType == true) {
1091  returnValue = "AliESDtrack";
1092  }
1093  else {
1094  returnValue = "Tracks";
1095  }
1096  }
1097  else {
1098  if (returnObjectType == true) {
1099  returnValue = "AliAODTrack";
1100  }
1101  else {
1102  returnValue = "tracks";
1103  }
1104  }
1105  }
1106  else if (objType == kCaloCells) {
1107  if (esdMode == true) {
1108  if (returnObjectType == true) {
1109  returnValue = "AliESDCaloCells";
1110  }
1111  else {
1112  returnValue = "EMCALCells";
1113  }
1114  }
1115  else {
1116  if (returnObjectType == true) {
1117  returnValue = "AliAODCaloCells";
1118  }
1119  else {
1120  returnValue = "emcalCells";
1121  }
1122  }
1123  }
1124  else {
1125  // Default to empty if we are given an unrecognized type with "usedefault"
1126  returnValue = "";
1127  }
1128 
1129  return returnValue;
1130 }
1131 
1149 AliEmcalContainer * AliEmcalCorrectionTask::AddContainer(InputObject_t contType, std::string & containerName, YAML::Node & userNode, YAML::Node & defaultNode)
1150 {
1151  // Determine the type of branch to request
1152  std::string containerBranch = "";
1153  if (contType != kCluster && contType != kTrack){
1154  AliFatal("Must specify type of container when requesting branch.");
1155  }
1156 
1157  // Retrieve branch name
1158  // YAML::Node() is just an empty node
1159  AliDebugStream(2) << "User Node: " << userNode << std::endl;
1160  AliDebugStream(2) << "Default Node: " << defaultNode << std::endl;
1161  AliEmcalCorrectionComponent::GetProperty("branchName", containerBranch, userNode, defaultNode, true, containerName);
1162  // Should be unnecessary, since the user can only do this if done explicitly.
1163  /*if (containerBranch == "")
1164  {
1165  AliFatal(TString::Format("Request %i container, but the container branch is empty!", contType));
1166  }*/
1167 
1168  // Determine proper name if using "usedefault" pattern
1169  if (containerBranch == "usedefault") {
1170  containerBranch = DetermineUseDefaultName(contType, fIsEsd);
1171  }
1172 
1173  // Create containers and set them to the name of the component
1174  AliEmcalContainer * cont = 0;
1175  if (contType == kCluster)
1176  {
1177  cont = new AliClusterContainer(containerBranch.c_str());
1178  AdoptClusterContainer(dynamic_cast<AliClusterContainer *>(cont));
1179  }
1180  else if (contType == kTrack)
1181  {
1182  if (containerBranch == "mcparticles") {
1183  cont = new AliMCParticleContainer(containerBranch.c_str());
1184  }
1185  else {
1186  cont = new AliTrackContainer(containerBranch.c_str());
1187  }
1188  AdoptParticleContainer(dynamic_cast<AliParticleContainer *>(cont));
1189  }
1190  cont->SetName(containerName.c_str());
1191 
1192  return cont;
1193 }
1194 
1203 {
1204  std::string inputObjectName = GetInputFieldNameFromInputObjectType(inputObjectType);
1205  // Need to be of the form "clusterContainersNames"
1206  inputObjectName = inputObjectName + "Names";
1207 
1208  std::vector <std::string> inputObjects;
1209  // Not required, because not all components need Clusters or Tracks
1210  AliEmcalCorrectionComponent::GetProperty(inputObjectName.c_str(), inputObjects, fUserConfiguration, fDefaultConfiguration, false, component->GetName());
1211 
1212  //std::cout << "inputObjects.size(): " << inputObjects.size() << std::endl;
1213 
1214  // If it is not found, then there will be nothing to iterate over, so we don't need to explicitly check the return value
1215  for (auto const & str : inputObjects)
1216  {
1217  // TODO: Generalize to arrays for clusters and tracks...
1218  // 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()!
1219  if (inputObjectType == kCluster)
1220  {
1221  AliEmcalContainer * cont = GetClusterContainer(str.c_str());
1222  AliDebugStream(2) << "Adding cluster container " << str << " of array " << cont->GetArrayName() << " to component " << component->GetName() << std::endl;
1223  component->SetClusterContainer(GetClusterContainer(str.c_str()));
1224  }
1225  else if (inputObjectType == kTrack)
1226  {
1227  AliEmcalContainer * cont = GetParticleContainer(str.c_str());
1228  AliDebugStream(2) << "Adding particle container " << str << " of array " << cont->GetArrayName() << " to component " << component->GetName() << std::endl;
1229  component->SetParticleContainer(GetParticleContainer(str.c_str()));
1230  }
1231  else if (inputObjectType == kCaloCells)
1232  {
1233  // NOTE: This operates different than the others. This should be executed during run time rather than during initialization!
1234  if (inputObjects.size() > 1) {
1235  AliFatal(TString::Format("Component %s requested more than one cell branch, but this is not supported! Check the configuration!", component->GetName()));
1236  }
1237 
1238  // If we've made it here, this must be at least one entry
1239  AliDebugStream(2) << "Adding calo cells " << GetCellContainer(str)->GetName() << " of branch name " << GetCellContainer(str)->GetBranchName() << "to component " << component->GetName() << std::endl;
1240  component->SetCaloCells(GetCellContainer(str)->GetCells());
1241  AliDebugStream(3) << "component GetNumberOfCells: " << component->GetCaloCells()->GetNumberOfCells() << std::endl;
1242  }
1243  }
1244 }
1245 
1253 AliEmcalCorrectionCellContainer * AliEmcalCorrectionTask::GetCellContainer(const std::string & cellsContainerName) const
1254 {
1255  for (auto cellContainer : fCellCollArray)
1256  {
1257  if (cellContainer->GetName() == cellsContainerName) {
1258  return cellContainer;
1259  }
1260  }
1261 
1262  return 0;
1263 }
1264 
1272 {
1273  AliDebugStream(2) << "Retrieving cells object " << cellContainer->GetName() << std::endl;
1274  // Check for embedding and return object
1275  AliVEvent * event = GetEvent(InputEvent(), cellContainer->GetIsEmbedding());
1276 
1277  cellContainer->SetCells(dynamic_cast<AliVCaloCells *>(event->FindListObject(cellContainer->GetBranchName().c_str())));
1278 }
1279 
1285 {
1286  // Run the initialization for all derived classes.
1287  AliDebug(3, Form("%s", __PRETTY_FUNCTION__));
1288  for (auto component : fCorrectionComponents)
1289  {
1290  // Setup geomertry
1291  component->SetEMCALGeometry(fGeom);
1292 
1293  // Add the requested cells to the component
1294  //AliDebugStream(3) << "Adding CaloCells" << std::endl;
1296  //AliDebugStream(3) << "Added CaloCells" << std::endl;
1297 
1298  // Component ExecOnce()
1299  component->ExecOnce();
1300  }
1301 }
1302 
1308 {
1309  fVertex[0] = 0;
1310  fVertex[1] = 0;
1311  fVertex[2] = 0;
1312  fNVertCont = 0;
1313 
1314  const AliVVertex *vert = InputEvent()->GetPrimaryVertex();
1315  if (vert) {
1316  vert->GetXYZ(fVertex);
1317  fNVertCont = vert->GetNContributors();
1318  }
1319 
1320  fBeamType = GetBeamType();
1321 
1322  if (fBeamType == kAA || fBeamType == kpA ) {
1324  AliMultSelection *MultSelection = static_cast<AliMultSelection*>(InputEvent()->FindListObject("MultSelection"));
1325  if (MultSelection) {
1326  fCent = MultSelection->GetMultiplicityPercentile(fCentEst.Data());
1327  }
1328  else {
1329  AliWarning("Could not retrieve centrality information! Assuming 99");
1330  }
1331  }
1332  else { // old centrality estimation < 2015
1333  AliCentrality *aliCent = InputEvent()->GetCentrality();
1334  if (aliCent) {
1335  fCent = aliCent->GetCentralityPercentile(fCentEst.Data());
1336  }
1337  else {
1338  AliWarning("Could not retrieve centrality information! Assuming 99");
1339  }
1340  }
1341 
1342  if (fNcentBins==4) {
1343  if (fCent >= 0 && fCent < 10) fCentBin = 0;
1344  else if (fCent >= 10 && fCent < 30) fCentBin = 1;
1345  else if (fCent >= 30 && fCent < 50) fCentBin = 2;
1346  else if (fCent >= 50 && fCent <= 100) fCentBin = 3;
1347  else {
1348  AliWarning(Form("Negative centrality: %f. Assuming 99", fCent));
1349  fCentBin = fNcentBins-1;
1350  }
1351  }
1352  else if (fNcentBins==5) { // for PbPb 2015
1353  if (fCent >= 0 && fCent < 10) fCentBin = 0;
1354  else if (fCent >= 10 && fCent < 30) fCentBin = 1;
1355  else if (fCent >= 30 && fCent < 50) fCentBin = 2;
1356  else if (fCent >= 50 && fCent <= 90) fCentBin = 3;
1357  else if (fCent > 90) {
1358  fCent = 99;
1359  fCentBin = 4;
1360  }
1361  else {
1362  AliWarning(Form("Negative centrality: %f. Assuming 99", fCent));
1363  fCentBin = fNcentBins-1;
1364  }
1365  }
1366  else {
1367  Double_t centWidth = (fMaxCent-fMinCent)/(Double_t)fNcentBins;
1368  if(centWidth>0.) {
1369  fCentBin = TMath::FloorNint(fCent/centWidth);
1370  }
1371  else {
1372  fCentBin = 0;
1373  }
1374  if (fCentBin>=fNcentBins) {
1375  AliWarning(Form("fCentBin too large: cent = %f fCentBin = %d. Assuming 99", fCent, fCentBin));
1376  fCentBin = fNcentBins-1;
1377  }
1378  }
1379  }
1380  else {
1381  fCent = 99;
1382  fCentBin = 0;
1383  }
1384 
1385  AliEmcalContainer* cont = 0;
1386 
1387  TIter nextPartColl(&fParticleCollArray);
1388  while ((cont = static_cast<AliEmcalContainer*>(nextPartColl()))) cont->NextEvent();
1389 
1390  TIter nextClusColl(&fClusterCollArray);
1391  while ((cont = static_cast<AliEmcalContainer*>(nextClusColl()))) cont->NextEvent();
1392 
1393  return kTRUE;
1394 }
1395 
1396 
1408 {
1409  if (!InputEvent()) {
1410  AliError("Could not retrieve event! Returning!");
1411  return;
1412  }
1413 
1414  if (fNeedEmcalGeom) {
1415  fGeom = AliEMCALGeometry::GetInstanceFromRunNumber(InputEvent()->GetRunNumber());
1416  if (!fGeom) {
1417  AliFatal("Can not get EMCal geometry instance. If you do not need the EMCal geometry, disable it by setting task->SetNeedEmcalGeometry(kFALSE).");
1418  return;
1419  }
1420  }
1421 
1422  // Load all requested track branches - each container knows name already
1423  for (Int_t i =0; i<fParticleCollArray.GetEntriesFast(); i++) {
1424  AliParticleContainer *cont = static_cast<AliParticleContainer*>(fParticleCollArray.At(i));
1426  cont->SetArray(InputEvent());
1427  }
1428 
1429  // Load all requested cluster branches - each container knows name already
1430  for (Int_t i =0; i<fClusterCollArray.GetEntriesFast(); i++) {
1431  AliClusterContainer *cont = static_cast<AliClusterContainer*>(fClusterCollArray.At(i));
1433  cont->SetArray(InputEvent());
1434  }
1435 
1436  // Determine the proper pointer for each cell object and save them to the cell contianer
1437  // At this point, they should all be created
1438  for (auto cellObj : fCellCollArray)
1439  {
1441  }
1442 
1443  fEventInitialized = kTRUE;
1444 
1446 }
1447 
1457 AliVEvent * AliEmcalCorrectionTask::GetEvent(AliVEvent * inputEvent, bool isEmbedding)
1458 {
1459  AliVEvent * event = 0;
1460  if (isEmbedding) {
1461  // TODO: Enable embedded when that branch is committed!
1462  /*const AliAnalysisTaskEmcalEmbeddingHelper* embedding = AliAnalysisTaskEmcalEmbeddingHelper::GetInstance();
1463  if (!embedding) return 0;
1464 
1465  event = embedding->GetExternalEvent();*/
1466  }
1467  else {
1468  event = inputEvent;
1469  }
1470 
1471  return event;
1472 }
1473 
1483 void AliEmcalCorrectionTask::CheckForContainerArray(AliEmcalContainer * cont, InputObject_t objectType)
1484 {
1485  // TODO: Enable embedded when that branch is committed!
1486  //AliVEvent * event = GetEvent(InputEvent(), cont->GetIsEmbedding());
1487  AliVEvent * event = GetEvent(InputEvent());
1488 
1489  TClonesArray * array = dynamic_cast<TClonesArray *>(event->FindListObject(cont->GetArrayName()));
1490  if (!array) {
1491  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()));
1492  array = new TClonesArray(DetermineUseDefaultName(objectType, fIsEsd, true).c_str());
1493  array->SetName(cont->GetArrayName());
1494  event->AddObject(array);
1495  }
1496 }
1497 
1506 {
1507  if (TString(n).IsNull()) return 0;
1508 
1510 
1511  fParticleCollArray.Add(cont);
1512 
1513  return cont;
1514 }
1515 
1524 {
1525  if (TString(n).IsNull()) return 0;
1526 
1527  AliTrackContainer* cont = new AliTrackContainer(n);
1528 
1529  fParticleCollArray.Add(cont);
1530 
1531  return cont;
1532 }
1533 
1542 {
1543  if (TString(n).IsNull()) return 0;
1544 
1546 
1547  fParticleCollArray.Add(cont);
1548 
1549  return cont;
1550 }
1551 
1560 {
1561  if (TString(n).IsNull()) return 0;
1562 
1564 
1565  fClusterCollArray.Add(cont);
1566 
1567  return cont;
1568 }
1569 
1576 {
1577  if (i<0 || i>fParticleCollArray.GetEntriesFast()) return 0;
1578  AliParticleContainer *cont = static_cast<AliParticleContainer*>(fParticleCollArray.At(i));
1579  return cont;
1580 }
1581 
1588 {
1589  if (i<0 || i>fClusterCollArray.GetEntriesFast()) return 0;
1590  AliClusterContainer *cont = static_cast<AliClusterContainer*>(fClusterCollArray.At(i));
1591  return cont;
1592 }
1593 
1600 {
1601  AliParticleContainer *cont = static_cast<AliParticleContainer*>(fParticleCollArray.FindObject(name));
1602  return cont;
1603 }
1604 
1611 {
1612  AliClusterContainer *cont = static_cast<AliClusterContainer*>(fClusterCollArray.FindObject(name));
1613  return cont;
1614 }
1615 
1616 
1622 {
1623  AliDebug(3, Form("%s", __PRETTY_FUNCTION__));
1624 
1625  // Initialize the event if not intialized
1626  if (!fEventInitialized)
1627  ExecOnce();
1628 
1629  // Only continue if we are initialized successfully
1630  if (!fEventInitialized)
1631  return;
1632 
1633  // Get the objects for each event
1634  if (!RetrieveEventObjects())
1635  return;
1636 
1637  // TODO: Consider adding IsEventSelected()??
1638 
1639  // Call run for each correction
1640  if (!Run())
1641  return;
1642 }
1643 
1650 {
1651  // Run the initialization for all derived classes.
1652  AliDebug(3, Form("%s", __PRETTY_FUNCTION__));
1653  for (auto component : fCorrectionComponents)
1654  {
1655  component->SetEvent(InputEvent());
1656  component->SetMCEvent(MCEvent());
1657  component->SetCentralityBin(fCentBin);
1658  component->SetCentrality(fCent);
1659 
1660  component->Run();
1661  }
1662 
1663  PostData(1, fOutput);
1664 
1665  return kTRUE;
1666 }
1667 
1673 {
1674  // Run the initialization for all derived classes.
1675  AliDebug(3, Form("%s", __PRETTY_FUNCTION__));
1676  for (auto component : fCorrectionComponents)
1677  {
1678  component->UserNotify();
1679  }
1680 
1681  return kTRUE;
1682 }
1683 
1689 {
1690  // Destructor
1691 }
1692 
1700 {
1701  if (fForceBeamType != kNA)
1702  return fForceBeamType;
1703 
1704  AliESDEvent *esd = dynamic_cast<AliESDEvent*>(InputEvent());
1705  if (esd) {
1706  const AliESDRun *run = esd->GetESDRun();
1707  TString beamType = run->GetBeamType();
1708  if (beamType == "p-p")
1709  return kpp;
1710  else if (beamType == "A-A")
1711  return kAA;
1712  else if (beamType == "p-A")
1713  return kpA;
1714  else
1715  return kNA;
1716  } else {
1717  Int_t runNumber = InputEvent()->GetRunNumber();
1718  if ((runNumber >= 136851 && runNumber <= 139517) || // LHC10h
1719  (runNumber >= 166529 && runNumber <= 170593)) { // LHC11h
1720  return kAA;
1721  } else if ((runNumber>=188365 && runNumber <= 188366) || // LHC12g
1722  (runNumber >= 195344 && runNumber <= 196608)) { // LHC13b-f
1723  return kpA;
1724  } else {
1725  return kpp;
1726  }
1727  }
1728 }
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)
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)
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)