AliPhysics  cdeda5a (cdeda5a)
 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"
30 
34 
38 
44  AliAnalysisTaskSE("AliEmcalCorrectionTask"),
45  fSuffix(""),
46  fUserConfiguration(),
47  fUserConfigurationFilename(""),
48  fUserConfigurationString(""),
49  fDefaultConfiguration(),
50  fDefaultConfigurationFilename(""),
51  fDefaultConfigurationString(""),
52  fCorrectionComponents(),
53  fIsEsd(false),
54  fForceBeamType(kNA),
55  fRunPeriod("noSetRunPeriod"),
56  fConfigurationInitialized(false),
57  fOrderedComponentsToExecute(),
58  fEventInitialized(false),
59  fCent(0),
60  fCentBin(-1),
61  fMinCent(-999),
62  fMaxCent(-999),
63  fNcentBins(4),
64  fCentEst("V0M"),
65  fUseNewCentralityEstimation(kFALSE),
66  fNVertCont(0),
67  fBeamType(kNA),
68  fNeedEmcalGeom(kTRUE),
69  fGeom(0),
70  fParticleCollArray(),
71  fClusterCollArray(),
72  fCellCollArray(),
73  fOutput(0)
74 {
75  // Default constructor
76  AliDebug(3, Form("%s", __PRETTY_FUNCTION__));
77 
78  fVertex[0] = 0;
79  fVertex[1] = 0;
80  fVertex[2] = 0;
81 
82  fParticleCollArray.SetOwner(kTRUE);
83  fClusterCollArray.SetOwner(kTRUE);
84 }
85 
96  AliAnalysisTaskSE(name),
97  fSuffix(""),
98  fUserConfiguration(),
99  fUserConfigurationFilename(""),
100  fUserConfigurationString(""),
101  fDefaultConfiguration(),
102  fDefaultConfigurationFilename(""),
103  fDefaultConfigurationString(""),
104  fCorrectionComponents(),
105  fIsEsd(false),
106  fForceBeamType(kNA),
107  fRunPeriod("noSetRunPeriod"),
108  fConfigurationInitialized(false),
109  fOrderedComponentsToExecute(),
110  fEventInitialized(false),
111  fCent(0),
112  fCentBin(-1),
113  fMinCent(-999),
114  fMaxCent(-999),
115  fNcentBins(4),
116  fCentEst("V0M"),
117  fUseNewCentralityEstimation(kFALSE),
118  fNVertCont(0),
119  fBeamType(kNA),
120  fNeedEmcalGeom(kTRUE),
121  fGeom(0),
122  fParticleCollArray(),
123  fClusterCollArray(),
124  fCellCollArray(),
125  fOutput(0)
126 {
127  // Standard constructor
128  AliDebug(3, Form("%s", __PRETTY_FUNCTION__));
129 
130  fVertex[0] = 0;
131  fVertex[1] = 0;
132  fVertex[2] = 0;
133 
134  fParticleCollArray.SetOwner(kTRUE);
135  fClusterCollArray.SetOwner(kTRUE);
136 
137  DefineInput(0, TChain::Class());
138  DefineOutput(1, TList::Class());
139 }
140 
146 {
147  // Destructor
148 }
149 
159 {
160  // Determine file type
161  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
162  if (mgr) {
163  AliVEventHandler *evhand = mgr->GetInputEventHandler();
164  if (evhand) {
165  if (evhand->InheritsFrom("AliESDInputHandler")) {
166  fIsEsd = true;
167  }
168  else {
169  fIsEsd = false;
170  }
171  }
172  else {
173  AliError("Event handler not found!");
174  }
175  }
176  else {
177  AliError("Analysis manager not found!");
178  }
179 
180  // Determine the suffix of the correction task
181  std::string tempName = GetName();
182  std::size_t foundSuffix = tempName.find("_");
183  if (foundSuffix != std::string::npos) {
184  // +1 to skip "_"
185  fSuffix = tempName.substr(foundSuffix + 1).c_str();
186  }
187 
188  if (fSuffix != "") {
189  AliInfoStream() << "Initializing correction task with suffix \"" << fSuffix << "\"" << std::endl;
190  }
191 
192  // Initialize YAML configuration
194  // Check that the configuration is initialized
195  if (fConfigurationInitialized != true)
196  {
197  AliFatal("YAML configuration must be initialized before running (ie. in the run macro or wagon)!");
198  }
199 
200  // Determine component execution order
202 
203  // Check for user defined settings that are not in the default file
205 
206  // Setup input objects
207  // Setup Cells
208  // Cannot do this entirely yet because we need input objects
211  // Create cluster input objects
214  // Create track input objects
217 
218  // Initialize components
220 }
221 
231 {
232  // Determine file path
234  {
235  // Use the default if nothing is set
236  fDefaultConfigurationFilename = "$ALICE_PHYSICS/PWG/EMCAL/config/AliEmcalCorrectionConfiguration.yaml";
237  }
238 
239  // Setup the YAML files
240  // Default
242 
244  {
245  AliInfo(TString::Format("Using default EMCal corrections configuration located at %s", fDefaultConfigurationFilename.c_str()));
246 
248  // Check for valid file
249  if (fDefaultConfiguration.IsNull() == true)
250  {
251  AliFatal(TString::Format("Could not open the default configuration file \"%s\"!", fDefaultConfigurationFilename.c_str()));
252  }
253  }
254  else
255  {
256  AliFatal(TString::Format("Default file located at \"%s\" does not exist!", fDefaultConfigurationFilename.c_str()));
257  }
258 
259  // User
261 
263  {
264  AliInfo(TString::Format("Using user EMCal corrections configuration located at %s", fUserConfigurationFilename.c_str()));
265 
267  }
268  else
269  {
270  AliInfo(TString::Format("User file at \"%s\" does not exist! All settings will be from the default file!", fUserConfigurationFilename.c_str()));
271  }
272 
273  // Ensure that there is a run period
274  if (fRunPeriod == "noSetRunPeriod")
275  {
276  AliFatal("Must pass a run period to the correction task!");
277  }
278  // Check the user provided run period
279  TString userRunPeriod = "kNoUserFile";
280  // Test if the period exists in the user file
281  if (fUserConfiguration.IsNull() != true)
282  {
283  if (fUserConfiguration["period"])
284  {
285  userRunPeriod = fUserConfiguration["period"].as<std::string>();
286  }
287  else
288  {
289  AliFatal("User must specify a period. Leave the period as an empty string to apply to all periods.");
290  }
291  }
292 
293  AliDebug(3, TString::Format("userRunPeriod: %s", userRunPeriod.Data()));
294  // Normalize the user run period to lower case to ensure that we don't miss any matches
295  userRunPeriod.ToLower();
296  if (userRunPeriod != "knouserfile" && userRunPeriod != fRunPeriod)
297  {
298  AliFatal(TString::Format("User run period \"%s\" does not match the run period of \"%s\" passed to the correction task!", userRunPeriod.Data(), fRunPeriod.Data()));
299  }
300 
301  // "" means the user wants their settings to apply to all periods
302  // Ensure that the user is aware!
303  if (userRunPeriod == "")
304  {
305  AliWarning("User run period is an empty string. Settings apply to all run periods!");
306  }
307 
308  // Save configuration into strings so that they can be streamed
309  // Need the stringstream because YAML implements streamers
310  std::stringstream tempConfiguration;
311  tempConfiguration << fUserConfiguration;
312  fUserConfigurationString = tempConfiguration.str();
313  tempConfiguration.str("");
314  tempConfiguration << fDefaultConfiguration;
315  fDefaultConfigurationString = tempConfiguration.str();
316 
317  //AliInfo(TString::Format("User configuration: %s", fUserConfigurationString.c_str()));
318  //AliInfo(TString::Format("Default configuration: %s", fDefaultConfigurationString.c_str()));
319 
320  // Note that it is initialized properly so that the analysis can proceed
322 }
323 
334 void AliEmcalCorrectionTask::DetermineComponentsToExecute(std::vector <std::string> & correctionComponents)
335 {
336  std::vector <std::string> executionOrder;
337  // executionOrder determines the order of tasks to execute, but it doesn't name the particular tasks
339 
340  // Possible components to create from both the user and default configurations
341  // Use set so that the possible components are not repeated
342  std::set <std::string> possibleComponents;
343  for (auto node : fUserConfiguration) {
344  possibleComponents.insert(node.first.as<std::string>());
345  }
346  for (auto node : fDefaultConfiguration) {
347  possibleComponents.insert(node.first.as<std::string>());
348  }
349 
350  // Determine the correction names associated with the correction task
351  std::string expectedComponentName = "";
352  bool foundSuffixComponent = false;
353  bool foundComponent = false;
354  bool componentEnabled = true;
355 
356  // Execution order determines the order that corrections should be added to our execution list
357  for (auto & execName : executionOrder)
358  {
359  // Construct the expected component name with the suffix
360  expectedComponentName = TString::Format("%s_%s", execName.c_str(), fSuffix.c_str()).Data();
361  foundComponent = false;
362  componentEnabled = false;
363 
364  foundComponent = CheckPossibleNamesForComponentName(expectedComponentName, possibleComponents);
365  if (foundComponent)
366  {
367  // Check if the component is enabled
368  AliEmcalCorrectionComponent::GetProperty("enabled", componentEnabled, fUserConfiguration, fDefaultConfiguration, true, expectedComponentName);
369  // If enabled, then store the name so that it can be executed
370  if (componentEnabled == true) {
371  foundSuffixComponent = true;
372  correctionComponents.push_back(expectedComponentName);
373  }
374  else {
375  AliInfo(TString::Format("Component %s is disabled and will not be run!", expectedComponentName.c_str()));
376  }
377 
378  continue;
379  }
380  else
381  {
382  // Look for the normal component
383  expectedComponentName = execName;
384  foundComponent = CheckPossibleNamesForComponentName(expectedComponentName, possibleComponents);
385  // Check if it is enabled
386  AliEmcalCorrectionComponent::GetProperty("enabled", componentEnabled, fUserConfiguration, fDefaultConfiguration, true, expectedComponentName);
387 
388  if (componentEnabled == true) {
389  if (foundSuffixComponent == true) {
390  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()));
391  }
392  else {
393  // Take the normal component and store it to be executed
394  correctionComponents.push_back(expectedComponentName);
395  }
396  }
397  else {
398  AliInfo(TString::Format("Component %s is disabled and will not be run!", expectedComponentName.c_str()));
399  }
400  }
401  }
402 
403  // Need to append "AliEmcalCorrection" to allow the tasks to be found!
404  AliDebug(2, "Found EMCal Correction Components: ");
405  for (auto & component : correctionComponents)
406  {
407  component = "AliEmcalCorrection" + component;
408  AliDebug(2, TString::Format("%s", component.c_str()) );
409  }
410 }
411 
421 {
422  // Names of properties for a particular component in the user and default configurations
423  std::set <std::string> userPropertyNames;
424  std::set <std::string> defaultPropertyNames;
425  // Notes whether a match was found between user and default properties
426  bool foundMatch = false;
427  std::string tempComponentName = "";
428 
429  // Loop over all components
430  for (const auto componentName : fOrderedComponentsToExecute)
431  {
432  // Reset for each loop
433  userPropertyNames.clear();
434  defaultPropertyNames.clear();
435  // We need to remove "AliEmcalCorrection" so that the correction will be found in the configuration
436  // "AliEmcalCorrection" is 18 characters
437  tempComponentName = componentName.substr(componentName.find("AliEmcalCorrection")+18);
438 
439  AliDebugStream(2) << "Checking component " << componentName << " for unmatched user settings" << std::endl;
440 
441  // Get the user property names
442  GetPropertyNamesFromNode(tempComponentName, fUserConfiguration, userPropertyNames, false);
443 
444  // Get the same from default
445  // Not required here because the default configuration may not have the specialized component
446  GetPropertyNamesFromNode(tempComponentName, fDefaultConfiguration, defaultPropertyNames, false);
447 
448  // We need to check the base correction as well to fill out the options
449  if (tempComponentName.find("_") != std::string::npos) {
450  // Get the base user component
451  GetPropertyNamesFromNode(tempComponentName.substr(0, tempComponentName.find("_")), fUserConfiguration, userPropertyNames, false);
452 
453  // Required here because the default must have the base component!
454  GetPropertyNamesFromNode(tempComponentName.substr(0, tempComponentName.find("_")), fDefaultConfiguration, defaultPropertyNames, true);
455  }
456 
457  // Check each property defined in the user file for a match to the properties in the default file
458  for (auto userPropertyName : userPropertyNames)
459  {
460  AliDebugStream(2) << "Checking property " << userPropertyName << std::endl;
461  foundMatch = false;
462  for (auto defaultPropertyName : defaultPropertyNames)
463  {
464  if (userPropertyName == defaultPropertyName) {
465  AliDebugStream(2) << "Found match of " << userPropertyName << " with " << defaultPropertyName << std::endl;
466  foundMatch = true;
467  }
468  }
469  if (foundMatch == false) {
470  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()));
471  }
472  }
473  }
474 }
475 
483 {
484  // Iterate over the ordered components list and create the components
485  AliEmcalCorrectionComponent * component = 0;
486  for (auto componentName : fOrderedComponentsToExecute)
487  {
488  std::string noPrefixComponentName = componentName.substr(0, componentName.find("_" + fSuffix));
489  component = AliEmcalCorrectionComponentFactory::createInstance(noPrefixComponentName);
490  if (!component)
491  {
492  AliFatal(TString::Format("Failed to create requested component %s!", componentName.c_str()));
493  }
494 
495  // For setting names of tasks to differentiate between tasks of the same class
496  component->SetName(componentName.c_str());
497  component->SetTitle(componentName.c_str());
498 
499  // Initialize the YAML configurations in each component
502 
503  // configure needed fields for components to properly initialize
504  component->SetIsESD(fIsEsd);
505 
506  // Add the require containers to the component
507  // Cells must be set during UserExec() because we need to add them as a pointer
510 
511  // Initialize each component
512  component->Initialize();
513 
514  if (component)
515  {
516  AliInfo(TString::Format("Successfully added correction task: %s", componentName.c_str()));
517  fCorrectionComponents.push_back(component);
518  }
519  }
520 }
521 
537 {
538  // Get container node
539  std::string inputObjectName = GetInputFieldNameFromInputObjectType(inputObjectType);
540 
541  // Get the user and default input nodes for the object type
542  YAML::Node userInputObjectNode;
543  YAML::Node defaultInputObjectNode;
544  GetNodeForInputObjects(userInputObjectNode, fUserConfiguration, inputObjectName, false);
545  GetNodeForInputObjects(defaultInputObjectNode, fDefaultConfiguration, inputObjectName, true);
546 
547  AliDebugStream(3) << "userInputObjectNode: " << userInputObjectNode << std::endl;
548  AliDebugStream(3) << "defaultInputObjectNode: " << defaultInputObjectNode << std::endl;
549 
550  // Determine which containers we need based on which are requested by the enabled correction tasks
551  std::set <std::string> requestedContainers;
552  std::vector <std::string> componentRequest;
553  for ( const auto & componentName : fOrderedComponentsToExecute )
554  {
555  componentRequest.clear();
556  // Not required because not all components will have all kinds of containers
557  // "AliEmcalCorrection" is 18 characters
558  AliEmcalCorrectionComponent::GetProperty(inputObjectName + "Names", componentRequest, fUserConfiguration, fDefaultConfiguration, false, componentName.substr(componentName.find("AliEmcalCorrection")+18));
559  for ( auto & req : componentRequest )
560  {
561  AliDebugStream(3) << "Component " << componentName << " requested container name " << req << std::endl;
562  requestedContainers.insert(req);
563  }
564  }
565 
566  AliDebugStream(2) << inputObjectName << " Containers requested by components: " << std::endl;
567  for (auto & str : requestedContainers) {
568  AliDebugStream(2) << "\t" << str << std::endl;;
569  }
570 
571  // Create all requested containers
572  AliDebug(2, TString::Format("Setting up requested containers!"));
573  SetupContainersFromInputNodes(inputObjectType, userInputObjectNode, defaultInputObjectNode, requestedContainers);
574 }
575 
584 {
585  std::string inputObjectName = GetInputFieldNameFromInputObjectType(inputObjectType);
586  // Need to be of the form "clusterContainersNames"
587  inputObjectName = inputObjectName + "Names";
588 
589  std::vector <std::string> inputObjects;
590  // Not required, because not all components need Clusters or Tracks
591  AliEmcalCorrectionComponent::GetProperty(inputObjectName.c_str(), inputObjects, fUserConfiguration, fDefaultConfiguration, false, component->GetName());
592 
593  //AliDebugStream(4) << "inputObjects.size(): " << inputObjects.size() << std::endl;
594 
595  // If it is not found, then there will be nothing to iterate over, so we don't need to explicitly check the return value
596  for (auto const & str : inputObjects)
597  {
598  // 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()!
599  if (inputObjectType == AliEmcalContainerUtils::kCluster)
600  {
601  AliEmcalContainer * cont = GetClusterContainer(str.c_str());
602  AliDebugStream(2) << "Adding cluster container " << str << " of array " << cont->GetArrayName() << " to component " << component->GetName() << std::endl;
603  component->AdoptClusterContainer(GetClusterContainer(str.c_str()));
604  }
605  else if (inputObjectType == AliEmcalContainerUtils::kTrack)
606  {
607  AliEmcalContainer * cont = GetParticleContainer(str.c_str());
608  AliDebugStream(2) << "Adding particle container " << str << " of array " << cont->GetArrayName() << " to component " << component->GetName() << std::endl;
609  component->AdoptParticleContainer(GetParticleContainer(str.c_str()));
610  }
611  else if (inputObjectType == AliEmcalContainerUtils::kCaloCells)
612  {
613  // NOTE: This operates different than the others. This should be executed during run time rather than during initialization!
614  if (inputObjects.size() > 1) {
615  AliFatal(TString::Format("Component %s requested more than one cell branch, but this is not supported! Check the configuration!", component->GetName()));
616  }
617 
618  // If we've made it here, this must be at least one entry
620  AliDebugStream(2) << "Adding calo cells \"" << cellCont->GetName() << "\" of branch name \"" << cellCont->GetBranchName() << "\" to component " << component->GetName() << std::endl;
621 
622  if (!(cellCont->GetCells())) {
623  // Attempt to re-initialize the cells.
624  // NOTE: This may not succeed. Adding the container may need to be repeated after the
625  // object is created
627  }
628 
629  // Set the calo cells (may be null)
630  component->SetCaloCells(cellCont->GetCells());
631 
632  // It is possible that the cells pointer is null because it may not be created yet. For example,
633  // when combining cells. Thus, we must first check whether the pointer is available before checking
634  // for the number of cells. This could potentially decrease the amount of debug information, but this
635  // should rarely be an issue.
636  if (component->GetCaloCells()) {
637  AliDebugStream(3) << "Component GetNumberOfCells: " << component->GetCaloCells()->GetNumberOfCells() << std::endl;
638  }
639  }
640  }
641 }
642 
651 void AliEmcalCorrectionTask::SetupContainersFromInputNodes(AliEmcalContainerUtils::InputObject_t inputObjectType, YAML::Node & userInputObjectNode, YAML::Node & defaultInputObjectNode, std::set <std::string> & requestedContainers)
652 {
653  // Our node contains all of the objects that we will want to create.
654  for(auto & containerName : requestedContainers)
655  {
656  // The section is the container name
657  //std::string containerName = it->first.as<std::string>();
658  // Skip if the particle or cluster container already exists
659  if (GetParticleContainer(containerName.c_str()) || GetClusterContainer(containerName.c_str())) {
660  continue;
661  }
662 
663  AliDebug(2, TString::Format("Processing container %s of inputType %d", containerName.c_str(), inputObjectType));
664  if (inputObjectType == AliEmcalContainerUtils::kCluster || inputObjectType == AliEmcalContainerUtils::kTrack) {
665  SetupContainer(inputObjectType, containerName, userInputObjectNode, defaultInputObjectNode);
666  }
667  else if (inputObjectType == AliEmcalContainerUtils::kCaloCells) {
668  SetupCellsInfo(containerName, userInputObjectNode, defaultInputObjectNode);
669  }
670  }
671 }
672 
683 void AliEmcalCorrectionTask::SetupCellsInfo(std::string containerName, YAML::Node & userNode, YAML::Node & defaultNode)
684 {
685  // Define cell info
687 
688  AliDebugStream(2) << "User: " << std::endl << userNode << std::endl << "default: " << std::endl << defaultNode << std::endl;
689 
690  // Set properties
691  // Cells (object) name
692  cellObj->SetName(containerName);
693  // Branch name
694  std::string tempString = "";
695  AliEmcalCorrectionComponent::GetProperty("branchName", tempString, userNode, defaultNode, true, containerName);
696  if (tempString == "usedefault") {
698  }
699  cellObj->SetBranchName(tempString);
700 
701  // IsEmbedding
702  bool tempBool = false;
703  AliEmcalCorrectionComponent::GetProperty("embedding", tempBool, userNode, defaultNode, false, containerName);
704  cellObj->SetIsEmbedding(tempBool);
705 
706  // Add to the array to keep track of it
707  fCellCollArray.push_back(cellObj);
708 }
709 
727 void AliEmcalCorrectionTask::SetupContainer(AliEmcalContainerUtils::InputObject_t inputObjectType, std::string containerName, YAML::Node & userNode, YAML::Node & defaultNode)
728 {
729  // Create container
730  AliDebugStream(2) << "Adding container" << std::endl;
731  AliEmcalContainer * cont = AddContainer(inputObjectType, containerName, userNode, defaultNode);
732  AliDebugStream(2) << "Added container" << std::endl;
733 
734  // Set the container properties
735  //
736  // TODO: Consider if this can be converted to a map to function pointers. There are a number of details
737  // which can make it a bit complicated. Those details include inheritance, pointing to member
738  // functions, etc. It should all be possible, but may not be worth all of the extra work and code.
739  // Example ccode:
740  // SetValueInContainer("minPt", &cont::SetMinPt, tempDouble, userNode, defaultNode);
741  // SetValueInContainer("minE", &cont::SetMinE, tempDouble, userNode, defaultNode);
742 
743  // Temporary variables to store requested properties
744  std::string tempString = "";
745  Double_t tempDouble = 0;
746  bool tempBool = false;
747 
748  // AliEmcalContainer properties
749  // Min Pt
750  bool result = AliEmcalCorrectionComponent::GetProperty("minPt", tempDouble, userNode, defaultNode, false, containerName);
751  if (result) {
752  AliDebugStream(2) << cont->GetName() << ": Setting minPt of " << tempDouble << std::endl;
753  cont->SetMinPt(tempDouble);
754  }
755  // Min E
756  result = AliEmcalCorrectionComponent::GetProperty("minE", tempDouble, userNode, defaultNode, false, containerName);
757  if (result) {
758  AliDebugStream(2) << cont->GetName() << ": Setting minE of " << tempDouble << std::endl;
759  cont->SetMinE(tempDouble);
760  }
761  // Eta min, max
762  result = AliEmcalCorrectionComponent::GetProperty("minEta", tempDouble, userNode, defaultNode, false, containerName);
763  if (result) {
764  // Only continue checking if the min is there, since we must set both together
765  Double_t tempDouble2 = 0;
766  result = AliEmcalCorrectionComponent::GetProperty("maxEta", tempDouble, userNode, defaultNode, false, containerName);
767  if (result) {
768  AliDebugStream(2) << cont->GetName() << ": Setting eta limits of " << tempDouble << " to " << tempDouble2 << std::endl;
769  cont->SetEtaLimits(tempDouble, tempDouble2);
770  }
771  }
772  // Phi min, max
773  result = AliEmcalCorrectionComponent::GetProperty("minPhi", tempDouble, userNode, defaultNode, false, containerName);
774  if (result) {
775  // Only continue checking if the min is there, since we must set both together
776  Double_t tempDouble2 = 0;
777  result = AliEmcalCorrectionComponent::GetProperty("maxPhi", tempDouble, userNode, defaultNode, false, containerName);
778  if (result) {
779  AliDebugStream(2) << cont->GetName() << ": Setting phi limits of " << tempDouble << " to " << tempDouble2 << std::endl;
780  cont->SetPhiLimits(tempDouble, tempDouble2);
781  }
782  }
783  // Embedded
784  result = AliEmcalCorrectionComponent::GetProperty("IsEmbedded", tempBool, userNode, defaultNode, false, containerName);
785  if (result) {
786  AliDebugStream(2) << cont->GetName() << ": Setting embedding to " << (tempBool ? "enabled" : "disabled") << std::endl;
787  cont->SetIsEmbedding(tempBool);
788  }
789 
790  // Cluster specific properties
791  AliClusterContainer * clusterContainer = dynamic_cast<AliClusterContainer *>(cont);
792  if (clusterContainer) {
793  // Default energy
794  // Probably not needed for the corrections
795  /*result = AliEmcalCorrectionComponent::GetProperty("defaultClusterEnergy", tempString, userNode, defaultNode, false, containerName);
796  if (result) {
797  // Need to get the enumeration
798  AliVCluster::VCluUserDefEnergy_t clusterEnergyType = clusterEnergyTypeMap.at(tempString);
799  AliDebugStream(2) << clusterContainer->GetName() << ": Setting cluster energy type to " << clusterEnergyType << std::endl;
800  clusterContainer->SetDefaultClusterEnergy(clusterEnergyType);
801  }*/
802 
803  // NonLinCorrEnergyCut
804  result = AliEmcalCorrectionComponent::GetProperty("clusNonLinCorrEnergyCut", tempDouble, userNode, defaultNode, false, containerName);
805  if (result) {
806  AliDebugStream(2) << clusterContainer->GetName() << ": Setting clusNonLinCorrEnergyCut of " << tempDouble << std::endl;
807  clusterContainer->SetClusNonLinCorrEnergyCut(tempDouble);
808  }
809 
810  // HadCorrEnergyCut
811  result = AliEmcalCorrectionComponent::GetProperty("clusHadCorrEnergyCut", tempDouble, userNode, defaultNode, false, containerName);
812  if (result) {
813  AliDebugStream(2) << clusterContainer->GetName() << ": Setting clusHadCorrEnergyCut of " << tempDouble << std::endl;
814  clusterContainer->SetClusHadCorrEnergyCut(tempDouble);
815  }
816 
817  // SetIncludePHOS
818  result = AliEmcalCorrectionComponent::GetProperty("includePHOS", tempBool, userNode, defaultNode, false, containerName);
819  if (result) {
820  AliDebugStream(2) << clusterContainer->GetName() << ": Setting Include PHOS to " << (tempBool ? "enabled" : "disabled") << std::endl;
821  clusterContainer->SetIncludePHOS(tempBool);
822  }
823  }
824 
825  // Track specific
826  AliTrackContainer * trackContainer = dynamic_cast<AliTrackContainer *>(cont);
827  if (trackContainer) {
828  // Track selection
829  // AOD Filter bits as a sequence
830  std::vector <UInt_t> filterBitsVector;
831  result = AliEmcalCorrectionComponent::GetProperty("aodFilterBits", filterBitsVector, userNode, defaultNode, false, containerName);
832  if (result){
833  UInt_t filterBits = 0;
834  for (int filterBit : filterBitsVector) {
835  filterBits += filterBit;
836  }
837  AliDebugStream(2) << trackContainer->GetName() << ": Setting filterBits of " << filterBits << std::endl;
838  trackContainer->SetAODFilterBits(filterBits);
839  }
840 
841  // SetTrackFilterType enum
842  result = AliEmcalCorrectionComponent::GetProperty("trackFilterType", tempString, userNode, defaultNode, false, containerName);
843  if (result) {
844  // Need to get the enumeration
845  AliEmcalTrackSelection::ETrackFilterType_t trackFilterType = trackFilterTypeMap.at(tempString);
846  AliDebugStream(2) << trackContainer->GetName() << ": Setting trackFilterType of " << trackFilterType << std::endl;
847  trackContainer->SetTrackFilterType(trackFilterType);
848  }
849 
850  // Track cuts period
851  result = AliEmcalCorrectionComponent::GetProperty("trackCutsPeriod", tempString, userNode, defaultNode, false, containerName);
852  if (result) {
853  // Need to get the enumeration
854  AliDebugStream(2) << trackContainer->GetName() << ": Setting track cuts period to " << tempString << std::endl;
855  trackContainer->SetTrackCutsPeriod(tempString.c_str());
856  }
857  }
858 }
859 
877 AliEmcalContainer * AliEmcalCorrectionTask::AddContainer(AliEmcalContainerUtils::InputObject_t contType, std::string & containerName, YAML::Node & userNode, YAML::Node & defaultNode)
878 {
879  // Determine the type of branch to request
880  std::string containerBranch = "";
882  AliFatal("Must specify type of container when requesting branch.");
883  }
884 
885  // Retrieve branch name
886  // YAML::Node() is just an empty node
887  AliDebugStream(2) << "User Node: " << userNode << std::endl;
888  AliDebugStream(2) << "Default Node: " << defaultNode << std::endl;
889  AliEmcalCorrectionComponent::GetProperty("branchName", containerBranch, userNode, defaultNode, true, containerName);
890  // Should be unnecessary, since the user can only do this if done explicitly.
891  /*if (containerBranch == "")
892  {
893  AliFatal(TString::Format("Request %i container, but the container branch is empty!", contType));
894  }*/
895 
896  // Determine proper name if using "usedefault" pattern
897  if (containerBranch == "usedefault") {
898  containerBranch = AliEmcalContainerUtils::DetermineUseDefaultName(contType, fIsEsd);
899  }
900 
901  // Create containers and set them to the name of the component
902  AliEmcalContainer * cont = 0;
903  if (contType == AliEmcalContainerUtils::kCluster)
904  {
905  cont = new AliClusterContainer(containerBranch.c_str());
906  AdoptClusterContainer(dynamic_cast<AliClusterContainer *>(cont));
907  }
908  else if (contType == AliEmcalContainerUtils::kTrack)
909  {
910  if (containerBranch == "mcparticles") {
911  cont = new AliMCParticleContainer(containerBranch.c_str());
912  }
913  else {
914  cont = new AliTrackContainer(containerBranch.c_str());
915  }
916  AdoptParticleContainer(dynamic_cast<AliParticleContainer *>(cont));
917  }
918  cont->SetName(containerName.c_str());
919 
920  return cont;
921 }
922 
932 {
933  AliDebug(3, Form("%s", __PRETTY_FUNCTION__));
934 
935  // Check that the configuration is initialized
936  if (fConfigurationInitialized != true)
937  {
938  AliFatal("YAML configuration must be initialized before running (ie. the AddTask, run macro or wagon)!");
939  }
940 
941  // Show the configurations info this is available
942  AliDebugStream(4) << "User configuration string: " << fUserConfigurationString << std::endl;
943  AliDebugStream(4) << "User configuration: " << fUserConfiguration << std::endl;
944  AliDebugStream(4) << "Default configuration string: " << fDefaultConfigurationString << std::endl;
945  AliDebugStream(4) << "Default configuration: " << fDefaultConfiguration << std::endl;
946 
947  // YAML Objects cannot be streamed, so we need to reinitialize them here.
948  // They need reinitialize if they are null
949  if (fUserConfiguration.IsNull() == true && fUserConfigurationString != "")
950  {
951  AliInfo("Reinitializing user configuration from string. Expected if running on grid!");
953  }
954  if (fDefaultConfiguration.IsNull() == true)
955  {
956  AliInfo("Reinitializing default configuration from string. Expected if running on grid!");
958  }
959 
960  // Debug to check that the configuration has been (re)initiailzied has been completed correctly
961  AliDebugStream(4) << "(Re)initialized user configuration: " << fUserConfigurationString << std::endl;
962  AliDebugStream(4) << "(Re)initialized user configuration: " << fUserConfiguration << std::endl;
963  AliDebugStream(4) << "(Re)initialized default configuration: " << fDefaultConfigurationString << std::endl;
964  AliDebugStream(4) << "(Re)initialized default configuration: " << fDefaultConfiguration << std::endl;
965 
966  if (fForceBeamType == kpp)
967  fNcentBins = 1;
968 
969  // Allow for output files
970  OpenFile(1);
971  fOutput = new TList();
972  fOutput->SetOwner();
973 
975 
976  PostData(1, fOutput);
977 }
978 
986 {
987  // Run the initialization for all derived classes.
988  AliDebug(3, Form("%s", __PRETTY_FUNCTION__));
989  for (auto component : fCorrectionComponents)
990  {
991  // Set cent bins (usually used for hist creation)
992  // It cannot be set until now because it can be changed after initialization
993  // For instance, by SetForceBeamType()
994  component->SetNcentralityBins(fNcentBins);
995 
996  component->UserCreateOutputObjects();
997 
998  if (component->GetOutputList() != 0)
999  {
1000  // Adds a list to the list -- this doesn't work for some unknown reason
1001  //fOutput->Add(component->GetOutputList());
1002 
1003  // iterate through lists for each component, and fill in output
1004  TList* t = new TList();
1005  t->SetName(component->GetName());
1006  fOutput->AddLast(t);
1007  t = (TList*)fOutput->Last();
1008  TIter next(component->GetOutputList());
1009  while (TObject *obj = next()){
1010  t->Add(obj);
1011  }
1012 
1013  AliDebug(1, TString::Format("Added output list from task %s to output.", component->GetName()));
1014  }
1015  }
1016 }
1017 
1023 {
1024  AliDebug(3, Form("%s", __PRETTY_FUNCTION__));
1025 
1026  // Initialize the event if not intialized
1027  if (!fEventInitialized)
1028  ExecOnce();
1029 
1030  // Only continue if we are initialized successfully
1031  if (!fEventInitialized)
1032  return;
1033 
1034  // Get the objects for each event
1035  if (!RetrieveEventObjects())
1036  return;
1037 
1038  // TODO: Consider adding IsEventSelected()??
1039 
1040  // Call run for each correction
1041  if (!Run())
1042  return;
1043 }
1044 
1056 {
1057  if (!InputEvent()) {
1058  AliError("Could not retrieve event! Returning!");
1059  return;
1060  }
1061 
1062  if (fNeedEmcalGeom) {
1063  fGeom = AliEMCALGeometry::GetInstanceFromRunNumber(InputEvent()->GetRunNumber());
1064  if (!fGeom) {
1065  AliFatal("Can not get EMCal geometry instance. If you do not need the EMCal geometry, disable it by setting task->SetNeedEmcalGeometry(kFALSE).");
1066  return;
1067  }
1068  }
1069 
1070  // Load all requested track branches - each container knows name already
1071  for (Int_t i =0; i<fParticleCollArray.GetEntriesFast(); i++) {
1072  AliParticleContainer *cont = static_cast<AliParticleContainer*>(fParticleCollArray.At(i));
1074  cont->SetArray(InputEvent());
1075  }
1076 
1077  // Load all requested cluster branches - each container knows name already
1078  for (Int_t i =0; i<fClusterCollArray.GetEntriesFast(); i++) {
1079  AliClusterContainer *cont = static_cast<AliClusterContainer*>(fClusterCollArray.At(i));
1081  cont->SetArray(InputEvent());
1082  }
1083 
1084  // Determine the proper pointer for each cell object and save them to the cell contianer
1085  // At this point, they should all be created
1086  for (auto cellObj : fCellCollArray)
1087  {
1089  }
1090 
1091  fEventInitialized = kTRUE;
1092 
1094 }
1095 
1101 {
1102  // Run the initialization for all derived classes.
1103  AliDebug(3, Form("%s", __PRETTY_FUNCTION__));
1104  for (auto component : fCorrectionComponents)
1105  {
1106  // Setup geometry
1107  component->SetEMCALGeometry(fGeom);
1108 
1109  // Set the input events. This is redundant to where it is set during Run(), but the events need to be
1110  // available to components, and they are only called one extra time.
1111  component->SetEvent(InputEvent());
1112  component->SetMCEvent(MCEvent());
1113 
1114  // Add the requested cells to the component
1116 
1117  // Component ExecOnce()
1118  component->ExecOnce();
1119 
1120  // If the cells were created during ExecOnce(), then we need to re-initialize the pointer to ensure
1121  // that it is not null!
1122  if (!component->GetCaloCells()) {
1123  AliDebugStream(2) << "Re-initializing cells for component " << component->GetName() << std::endl;
1125  }
1126  }
1127 }
1128 
1134 {
1135  fVertex[0] = 0;
1136  fVertex[1] = 0;
1137  fVertex[2] = 0;
1138  fNVertCont = 0;
1139 
1140  const AliVVertex *vert = InputEvent()->GetPrimaryVertex();
1141  if (vert) {
1142  vert->GetXYZ(fVertex);
1143  fNVertCont = vert->GetNContributors();
1144  }
1145 
1146  fBeamType = GetBeamType();
1147 
1148  if (fBeamType == kAA || fBeamType == kpA ) {
1150  AliMultSelection *MultSelection = static_cast<AliMultSelection*>(InputEvent()->FindListObject("MultSelection"));
1151  if (MultSelection) {
1152  fCent = MultSelection->GetMultiplicityPercentile(fCentEst.Data());
1153  }
1154  else {
1155  AliWarning("Could not retrieve centrality information! Assuming 99");
1156  }
1157  }
1158  else { // old centrality estimation < 2015
1159  AliCentrality *aliCent = InputEvent()->GetCentrality();
1160  if (aliCent) {
1161  fCent = aliCent->GetCentralityPercentile(fCentEst.Data());
1162  }
1163  else {
1164  AliWarning("Could not retrieve centrality information! Assuming 99");
1165  }
1166  }
1167 
1168  if (fNcentBins==4) {
1169  if (fCent >= 0 && fCent < 10) fCentBin = 0;
1170  else if (fCent >= 10 && fCent < 30) fCentBin = 1;
1171  else if (fCent >= 30 && fCent < 50) fCentBin = 2;
1172  else if (fCent >= 50 && fCent <= 100) fCentBin = 3;
1173  else {
1174  AliWarning(Form("Negative centrality: %f. Assuming 99", fCent));
1175  fCentBin = fNcentBins-1;
1176  }
1177  }
1178  else if (fNcentBins==5) { // for PbPb 2015
1179  if (fCent >= 0 && fCent < 10) fCentBin = 0;
1180  else if (fCent >= 10 && fCent < 30) fCentBin = 1;
1181  else if (fCent >= 30 && fCent < 50) fCentBin = 2;
1182  else if (fCent >= 50 && fCent <= 90) fCentBin = 3;
1183  else if (fCent > 90) {
1184  fCent = 99;
1185  fCentBin = 4;
1186  }
1187  else {
1188  AliWarning(Form("Negative centrality: %f. Assuming 99", fCent));
1189  fCentBin = fNcentBins-1;
1190  }
1191  }
1192  else {
1193  Double_t centWidth = (fMaxCent-fMinCent)/(Double_t)fNcentBins;
1194  if(centWidth>0.) {
1195  fCentBin = TMath::FloorNint(fCent/centWidth);
1196  }
1197  else {
1198  fCentBin = 0;
1199  }
1200  if (fCentBin>=fNcentBins) {
1201  AliWarning(Form("fCentBin too large: cent = %f fCentBin = %d. Assuming 99", fCent, fCentBin));
1202  fCentBin = fNcentBins-1;
1203  }
1204  }
1205  }
1206  else {
1207  fCent = 99;
1208  fCentBin = 0;
1209  }
1210 
1211  AliEmcalContainer* cont = 0;
1212 
1213  TIter nextPartColl(&fParticleCollArray);
1214  while ((cont = static_cast<AliEmcalContainer*>(nextPartColl()))) cont->NextEvent();
1215 
1216  TIter nextClusColl(&fClusterCollArray);
1217  while ((cont = static_cast<AliEmcalContainer*>(nextClusColl()))) cont->NextEvent();
1218 
1219  return kTRUE;
1220 }
1221 
1227 {
1228  // Run the initialization for all derived classes.
1229  AliDebug(3, Form("%s", __PRETTY_FUNCTION__));
1230  for (auto component : fCorrectionComponents)
1231  {
1232  component->SetEvent(InputEvent());
1233  component->SetMCEvent(MCEvent());
1234  component->SetCentralityBin(fCentBin);
1235  component->SetCentrality(fCent);
1236 
1237  component->Run();
1238  }
1239 
1240  PostData(1, fOutput);
1241 
1242  return kTRUE;
1243 }
1244 
1250 {
1251  // Run the initialization for all derived classes.
1252  AliDebug(3, Form("%s", __PRETTY_FUNCTION__));
1253  for (auto component : fCorrectionComponents)
1254  {
1255  component->UserNotify();
1256  }
1257 
1258  return kTRUE;
1259 }
1260 
1269 {
1270  bool returnValue = false;
1271  if (filename != "")
1272  {
1273  if (fConfigurationInitialized == true)
1274  {
1275  std::ofstream outFile(filename);
1276  std::string stringToWrite = userConfig ? fUserConfigurationString : fDefaultConfigurationString;
1277  if (stringToWrite == "") {
1278  AliWarning(TString::Format("%s configuration is empty!", userConfig ? "User" : "Default"));
1279  }
1280  outFile << stringToWrite;
1281  outFile.close();
1282 
1283  returnValue = true;
1284  }
1285  else
1286  {
1287  AliWarning(TString::Format("Configuration not properly initialized! Cannot print %s configuration!", userConfig ? "user" : "default"));
1288  }
1289 
1290  }
1291  else
1292  {
1293  AliWarning("Please pass a valid filename instead of empty quotes!");
1294  }
1295  return returnValue;
1296 }
1297 
1298 
1307 inline bool AliEmcalCorrectionTask::DoesFileExist(const std::string & filename)
1308 {
1309  std::ifstream inFile(filename);
1310  return inFile.good();
1311 }
1312 
1322 {
1323  if (filename != "")
1324  {
1325  // Handle if in AliPhysics and includes $ALICE_PHYSICS
1326  filename = gSystem->ExpandPathName(filename.c_str());
1327 
1328  // Handle grid
1329  if(filename.find("alien://") != std::string::npos)
1330  {
1331  AliDebug(2, TString::Format("Opening file \"%s\" on the grid!", filename.c_str()));
1332  // Initialize alien connection if needed
1333  if (!gGrid) {
1334  TGrid::Connect("alien://");
1335  }
1336 
1337  // Determine the local filename and copy file to local directory
1338  std::string localFilename = gSystem->BaseName(filename.c_str());
1339  // Ensures that the default and user files do not conflict if both are taken from the grid and have the same filename
1340  if (userFile == true) {
1341  localFilename = "user" + localFilename;
1342  }
1343  TFile::Cp(filename.c_str(), localFilename.c_str());
1344 
1345  // yaml-cpp should only open the local file
1346  filename = localFilename;
1347  }
1348  }
1349 }
1350 
1358 {
1359  AliDebugStream(2) << "Retrieving cells object " << cellContainer->GetName() << std::endl;
1360  // Check for embedding and return object
1361  AliVEvent * event = AliEmcalContainerUtils::GetEvent(InputEvent(), cellContainer->GetIsEmbedding());
1362 
1363  cellContainer->SetCells(dynamic_cast<AliVCaloCells *>(event->FindListObject(cellContainer->GetBranchName().c_str())));
1364 }
1365 
1376 {
1377  AliVEvent * event = AliEmcalContainerUtils::GetEvent(InputEvent(), cont->GetIsEmbedding());
1378 
1379  TClonesArray * array = dynamic_cast<TClonesArray *>(event->FindListObject(cont->GetArrayName()));
1380  if (!array) {
1381  AliWarning(TString::Format("Container %s requested branch %s, but it does not exist! Creating it for you! Please check that this is the proper action!", cont->GetName(), cont->GetArrayName().Data()));
1382  array = new TClonesArray(AliEmcalContainerUtils::DetermineUseDefaultName(objectType, fIsEsd, true).c_str());
1383  array->SetName(cont->GetArrayName());
1384  event->AddObject(array);
1385  }
1386 }
1387 
1396 {
1397  // Get container node
1398  std::string inputObjectName = "";
1399  if (inputObjectType == AliEmcalContainerUtils::kCluster) {
1400  inputObjectName = "clusterContainers";
1401  }
1402  else if (inputObjectType == AliEmcalContainerUtils::kTrack) {
1403  inputObjectName = "trackContainers";
1404  }
1405  else if (inputObjectType == AliEmcalContainerUtils::kCaloCells) {
1406  inputObjectName = "cells";
1407  }
1408  else {
1409  AliFatal(TString::Format("Unrecognized input object type %d", inputObjectType));
1410  }
1411 
1412  return inputObjectName;
1413 }
1414 
1426 bool AliEmcalCorrectionTask::CheckPossibleNamesForComponentName(std::string & name, std::set <std::string> & possibleComponents)
1427 {
1428  bool foundComponent = false;
1429  for (auto & possibleComponent : possibleComponents)
1430  {
1431  if (possibleComponent == name) {
1432  foundComponent = true;
1433  break;
1434  }
1435  }
1436 
1437  return foundComponent;
1438 }
1439 
1447 {
1448  if (fForceBeamType != kNA)
1449  return fForceBeamType;
1450 
1451  AliESDEvent *esd = dynamic_cast<AliESDEvent*>(InputEvent());
1452  if (esd) {
1453  const AliESDRun *run = esd->GetESDRun();
1454  TString beamType = run->GetBeamType();
1455  if (beamType == "p-p")
1456  return kpp;
1457  else if (beamType == "A-A")
1458  return kAA;
1459  else if (beamType == "p-A")
1460  return kpA;
1461  else
1462  return kNA;
1463  } else {
1464  Int_t runNumber = InputEvent()->GetRunNumber();
1465  if ((runNumber >= 136851 && runNumber <= 139517) || // LHC10h
1466  (runNumber >= 166529 && runNumber <= 170593)) { // LHC11h
1467  return kAA;
1468  } else if ((runNumber>=188365 && runNumber <= 188366) || // LHC12g
1469  (runNumber >= 195344 && runNumber <= 196608)) { // LHC13b-f
1470  return kpA;
1471  } else {
1472  return kpp;
1473  }
1474  }
1475 }
1476 
1481 {
1482  if (inputObjectType == AliEmcalContainerUtils::kCaloCells) {
1483  AliInfoStream() << "Cells info: " << std::endl;
1484  for (auto cellInfo : fCellCollArray) {
1485  AliInfoStream() << "\tName: " << cellInfo->GetName() << "\tBranch: " << cellInfo->GetBranchName() << "\tIsEmbedding: " << std::boolalpha << cellInfo->GetIsEmbedding() << std::endl;
1486  }
1487  }
1488  else if (inputObjectType == AliEmcalContainerUtils::kCluster || inputObjectType == AliEmcalContainerUtils::kTrack) {
1489  AliInfoStream() << (inputObjectType == AliEmcalContainerUtils::kCluster ? "Cluster" : "Track") << " container info: " << std::endl;
1490  AliEmcalContainer * cont = 0;
1491  for (auto containerInfo : (inputObjectType == AliEmcalContainerUtils::kCluster ? fClusterCollArray : fParticleCollArray) ) {
1492  cont = static_cast<AliEmcalContainer *>(containerInfo);
1493  AliInfoStream() << "\tName: " << cont->GetName() << "\tBranch: " << cont->GetArrayName() << "\tTitle: " << cont->GetTitle() << "\tIsEmbedding:" << std::boolalpha << cont->GetIsEmbedding() << std::endl;
1494  }
1495  }
1496  else {
1497  AliErrorStream() << "Unrecognized input object type " << inputObjectType << std::endl;
1498  }
1499 }
1500 
1510 void AliEmcalCorrectionTask::GetNodeForInputObjects(YAML::Node & inputNode, YAML::Node & nodeToRetrieveFrom, std::string & inputObjectName, bool requiredProperty)
1511 {
1512  // Get the user input node
1513  AliEmcalCorrectionComponent::GetProperty(inputObjectName.c_str(), inputNode, YAML::Node(), nodeToRetrieveFrom, requiredProperty, "inputObjects");
1514 
1515  // Get the user shared node and add it back to the user node so that shared parameters are available
1516  if (nodeToRetrieveFrom["sharedParameters"]) {
1517  inputNode["sharedParameters"] = nodeToRetrieveFrom["sharedParameters"];
1518  }
1519 }
1520 
1531 void AliEmcalCorrectionTask::GetPropertyNamesFromNode(const std::string & componentName, const YAML::Node & node, std::set <std::string> & propertyNames, const bool nodeRequired)
1532 {
1533  YAML::Node tempNode;
1534  AliEmcalCorrectionComponent::GetProperty(componentName, tempNode, YAML::Node(), node, nodeRequired, "");
1535  for (auto propertyName : tempNode)
1536  {
1537  propertyNames.insert(propertyName.first.as<std::string>());
1538  }
1539 }
1540 
1548 AliEmcalCorrectionCellContainer * AliEmcalCorrectionTask::GetCellContainer(const std::string & cellsContainerName) const
1549 {
1550  for (auto cellContainer : fCellCollArray)
1551  {
1552  if (cellContainer->GetName() == cellsContainerName) {
1553  return cellContainer;
1554  }
1555  }
1556 
1557  return 0;
1558 }
1559 
1561 {
1562  // Get the pointer to the existing analysis manager via the static access method.
1563  //==============================================================================
1564  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
1565  if (!mgr)
1566  {
1567  ::Error("AddTaskEmcalCorrectionTask", "No analysis manager to connect to.");
1568  return 0;
1569  }
1570 
1571  // Check the analysis type using the event handlers connected to the analysis manager.
1572  //==============================================================================
1573  AliVEventHandler* handler = mgr->GetInputEventHandler();
1574  if (!handler)
1575  {
1576  ::Error("AddTaskEmcalCorrectionTask", "This task requires an input event handler");
1577  return 0;
1578  }
1579 
1580  TString name = "AliEmcalCorrectionTask";
1581  if (suffix != "") {
1582  name += TString::Format("_%s", suffix.Data());
1583  }
1584 
1585  AliEmcalCorrectionTask* mgrTask = static_cast<AliEmcalCorrectionTask *>(mgr->GetTask(name.Data()));
1586  if (mgrTask) return mgrTask;
1587 
1588  // Create the task that manages the corrections
1589  AliEmcalCorrectionTask* correctionTask = new AliEmcalCorrectionTask(name.Data());
1590 
1591  //-------------------------------------------------------
1592  // Final settings, pass to manager and set the containers
1593  //-------------------------------------------------------
1594 
1595  mgr->AddTask(correctionTask);
1596 
1597  // Create containers for input/output
1598  AliAnalysisDataContainer* cInput = mgr->GetCommonInputContainer();
1599 
1600  TString outputContainerName(name);
1601  outputContainerName += "_histos";
1602 
1603  AliAnalysisDataContainer * cOutput = mgr->CreateContainer(outputContainerName.Data(),
1604  TList::Class(),
1605  AliAnalysisManager::kOutputContainer,
1606  Form("%s", AliAnalysisManager::GetCommonFileName()));
1607 
1608  mgr->ConnectInput(correctionTask, 0, cInput);
1609  mgr->ConnectOutput(correctionTask, 1, cOutput);
1610 
1611  //TObjArray* cnt = mgr->GetContainers();
1612 
1613  return correctionTask;
1614 }
void AdoptClusterContainer(AliClusterContainer *cont)
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
Suffix of the Correction Task (used to select components)
Steering task for the EMCal correction framework.
AliEMCALGeometry * fGeom
! Emcal geometry
const char * filename
Definition: TestFCM.C:1
return jsonbuilder str().c_str()
void SetTrackCutsPeriod(const char *period)
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
void SetArray(const AliVEvent *event)
AliVCaloCells * GetCaloCells() const
std::vector< std::string > fOrderedComponentsToExecute
Ordered set of components to execute.
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
std::string GetInputFieldNameFromInputObjectType(AliEmcalContainerUtils::InputObject_t inputObjectType)
void AdoptClusterContainer(AliClusterContainer *cont)
void SetupConfigurationFilePath(std::string &filename, bool userFile=false)
void UserExec(Option_t *option)
YAML::Node fUserConfiguration
! User YAML Configuration
Double_t fMaxCent
max centrality for event selection
Double_t fVertex[3]
! Event vertex
Declaration of class AliAnalysisTaskEmcalEmbeddingHelper.
void DetermineComponentsToExecute(std::vector< std::string > &componentsToExecute)
TList * fOutput
! Output for histograms
std::string DetermineUseDefaultName(InputObject_t objType, bool esdMode, bool returnObjectType=false)
Wrapper around cells objects for the EMCal Correction Task.
bool fConfigurationInitialized
True if the YAML configuration files are initialized.
AliEmcalContainer * AddContainer(AliEmcalContainerUtils::InputObject_t contType, std::string &containerName, YAML::Node &userNode, YAML::Node &defaultNode)
void CheckForContainerArray(AliEmcalContainer *cont, AliEmcalContainerUtils::InputObject_t objectType)
AliParticleContainer * GetParticleContainer(Int_t i=0) const
Container for particles within the EMCAL framework.
void SetUserConfiguration(YAML::Node &node)
Make copy to ensure that the nodes do not point to each other (?)
AliVCaloCells * GetCells() const
Pointer to the actual CaloCells object.
bool fEventInitialized
If the event is initialized properly.
void Load()
Definition: UnfoldingHF.C:238
void AddContainersToComponent(AliEmcalCorrectionComponent *component, AliEmcalContainerUtils::InputObject_t inputObjectType)
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
AliClusterContainer * GetClusterContainer(Int_t i=0) const
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)
static AliEmcalCorrectionTask * AddTaskEmcalCorrectionTask(TString suffix="")
void SetCells(AliVCaloCells *cells)
Sets the Pointer to the actual CaloCells object.
Double_t fCent
! Event centrality
void CreateInputObjects(AliEmcalContainerUtils::InputObject_t inputObjectType)
Base class for correction components in the EMCal correction framework.
BeamType
Switch for the beam type.
void AdoptParticleContainer(AliParticleContainer *cont)
std::map< std::string, AliEmcalTrackSelection::ETrackFilterType_t > trackFilterTypeMap
Relates string to the track filter enumeration for YAML configuration.
void SetIncludePHOS(Bool_t b)
bool WriteConfigurationFile(std::string filename, bool userConfig=false)
Bool_t fNeedEmcalGeom
whether or not the task needs the emcal geometry
InputObject_t
Type of input object to be created
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.
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)
void PrintRequestedContainersInformation(AliEmcalContainerUtils::InputObject_t inputObjectType)
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.
void SetDefaultConfiguration(YAML::Node &node)
ClassImp(AliAnalysisTaskCRC) AliAnalysisTaskCRC
AliVEvent * GetEvent(AliVEvent *inputEvent, bool isEmbedding=false)
void AdoptParticleContainer(AliParticleContainer *cont)
void SetIsEmbedding(bool isEmbedded)
Set to true if the cells are located in the event that is being embedded.
void SetCaloCells(AliVCaloCells *cells)
BeamType fBeamType
! Event beam type
void SetArray(const AliVEvent *event)
Int_t GetRunNumber(TString)
Definition: PlotMuonQA.C:2235
void SetTrackFilterType(ETrackFilterType_t f)
const char Option_t
Definition: External.C:48
void SetupContainersFromInputNodes(AliEmcalContainerUtils::InputObject_t inputObjectType, YAML::Node &userInputObjectNode, YAML::Node &defaultInputObjectNode, std::set< std::string > &requestedContainers)
YAML::Node fDefaultConfiguration
! Default 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
std::vector< AliEmcalCorrectionCellContainer * > fCellCollArray
Cells collection array.
void SetupContainer(AliEmcalContainerUtils::InputObject_t inputObjectType, std::string containerName, YAML::Node &userNode, YAML::Node &defaultNode)
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)
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