AliPhysics  a4b41ad (a4b41ad)
 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 #include <algorithm>
15 
16 #include <TChain.h>
17 #include <TSystem.h>
18 #include <TGrid.h>
19 #include <TFile.h>
20 
21 #include "AliVEventHandler.h"
22 #include "AliEMCALGeometry.h"
23 #include "AliVCaloCells.h"
24 #include "AliVCluster.h"
25 #include "AliLog.h"
26 #include "AliMultSelection.h"
27 #include "AliCentrality.h"
28 #include "AliESDEvent.h"
29 #include "AliAnalysisManager.h"
30 #include "AliAODEvent.h"
31 
35 
39 
40 const std::map <std::string, AliVCluster::VCluUserDefEnergy_t> AliEmcalCorrectionTask::fgkClusterEnergyTypeMap = {
41  {"kNonLinCorr", AliVCluster::kNonLinCorr },
42  {"kHadCorr", AliVCluster::kHadCorr },
43  {"kUserDefEnergy1", AliVCluster::kUserDefEnergy1 },
44  {"kUserDefEnergy2", AliVCluster::kUserDefEnergy2 }
45 };
46 
47 const std::map <std::string, AliEmcalTrackSelection::ETrackFilterType_t> AliEmcalCorrectionTask::fgkTrackFilterTypeMap = {
48  {"kNoTrackFilter", AliEmcalTrackSelection::kNoTrackFilter },
49  {"kCustomTrackFilter", AliEmcalTrackSelection::kCustomTrackFilter },
50  {"kHybridTracks", AliEmcalTrackSelection::kHybridTracks },
51  {"kTPCOnlyTracks", AliEmcalTrackSelection::kTPCOnlyTracks }
52 };
53 
58  AliAnalysisTaskSE("AliEmcalCorrectionTask"),
59  fSuffix(""),
60  fUserConfiguration(),
61  fUserConfigurationFilename(""),
62  fUserConfigurationString(""),
63  fDefaultConfiguration(),
64  fDefaultConfigurationFilename(""),
65  fDefaultConfigurationString(""),
66  fCorrectionComponents(),
67  fIsEsd(false),
68  fForceBeamType(kNA),
69  fConfigurationInitialized(false),
70  fOrderedComponentsToExecute(),
71  fEventInitialized(false),
72  fCent(0),
73  fCentBin(-1),
74  fMinCent(-999),
75  fMaxCent(-999),
76  fNcentBins(4),
77  fCentEst("V0M"),
78  fUseNewCentralityEstimation(kFALSE),
79  fVertex{0},
80  fNVertCont(0),
81  fBeamType(kNA),
82  fNeedEmcalGeom(kTRUE),
83  fGeom(0),
84  fParticleCollArray(),
85  fClusterCollArray(),
86  fCellCollArray(),
87  fOutput(0)
88 {
89  // Default constructor
90  AliDebug(3, Form("%s", __PRETTY_FUNCTION__));
91 
92  fParticleCollArray.SetOwner(kTRUE);
93  fClusterCollArray.SetOwner(kTRUE);
94 }
95 
106  AliAnalysisTaskSE(name),
107  fSuffix(""),
108  fUserConfiguration(),
109  fUserConfigurationFilename(""),
110  fUserConfigurationString(""),
111  fDefaultConfiguration(),
112  fDefaultConfigurationFilename(""),
113  fDefaultConfigurationString(""),
114  fCorrectionComponents(),
115  fIsEsd(false),
116  fForceBeamType(kNA),
117  fConfigurationInitialized(false),
118  fOrderedComponentsToExecute(),
119  fEventInitialized(false),
120  fCent(0),
121  fCentBin(-1),
122  fMinCent(-999),
123  fMaxCent(-999),
124  fNcentBins(4),
125  fCentEst("V0M"),
126  fUseNewCentralityEstimation(kFALSE),
127  fVertex{0},
128  fNVertCont(0),
129  fBeamType(kNA),
130  fNeedEmcalGeom(kTRUE),
131  fGeom(0),
132  fParticleCollArray(),
133  fClusterCollArray(),
134  fCellCollArray(),
135  fOutput(0)
136 {
137  // Standard constructor
138  AliDebug(3, Form("%s", __PRETTY_FUNCTION__));
139 
140  fParticleCollArray.SetOwner(kTRUE);
141  fClusterCollArray.SetOwner(kTRUE);
142 
143  DefineInput(0, TChain::Class());
144  DefineOutput(1, TList::Class());
145 }
146 
155  fUserConfiguration(task.fUserConfiguration),
156  fDefaultConfiguration(task.fDefaultConfiguration),
157  fSuffix(task.fSuffix),
158  fUserConfigurationString(task.fUserConfigurationString),
159  fDefaultConfigurationString(task.fDefaultConfigurationString),
160  fUserConfigurationFilename(task.fUserConfigurationFilename),
161  fDefaultConfigurationFilename(task.fDefaultConfigurationFilename),
162  fOrderedComponentsToExecute(task.fOrderedComponentsToExecute),
163  fCorrectionComponents(task.fCorrectionComponents), // TODO: These should be copied!
164  fConfigurationInitialized(task.fConfigurationInitialized),
165  fIsEsd(task.fIsEsd),
166  fEventInitialized(task.fEventInitialized),
167  fCent(task.fCent),
168  fCentBin(task.fCentBin),
169  fMinCent(task.fMinCent),
170  fMaxCent(task.fMaxCent),
171  fNcentBins(task.fNcentBins),
172  fCentEst(task.fCentEst),
173  fUseNewCentralityEstimation(task.fUseNewCentralityEstimation),
174  fVertex{0.},
175  fNVertCont(task.fNVertCont),
176  fBeamType(task.fBeamType),
177  fForceBeamType(task.fForceBeamType),
178  fNeedEmcalGeom(task.fNeedEmcalGeom),
179  fGeom(task.fGeom),
180  fParticleCollArray(*(static_cast<TObjArray *>(task.fParticleCollArray.Clone()))),
181  fClusterCollArray(*(static_cast<TObjArray *>(task.fClusterCollArray.Clone()))),
182  fOutput(task.fOutput) // TODO: More care is needed here!
183 {
184  // Vertex position
185  std::copy(std::begin(task.fVertex), std::end(task.fVertex), std::begin(fVertex));
186 
187  // Cell Collections
188  for (auto cellCont : task.fCellCollArray)
189  {
190  fCellCollArray.push_back(new AliEmcalCorrectionCellContainer(*cellCont));
191  }
192 }
193 
199 {
200  swap(*this, other);
201 }
202 
208 {
209  swap(*this, other);
210 
211  return *this;
212 }
213 
218 {
219  using std::swap;
220 
223  swap(first.fSuffix, second.fSuffix);
231  swap(first.fIsEsd, second.fIsEsd);
233  swap(first.fCent, second.fCent);
234  swap(first.fCentBin, second.fCentBin);
235  swap(first.fMinCent, second.fMinCent);
236  swap(first.fMaxCent, second.fMaxCent);
237  swap(first.fNcentBins, second.fNcentBins);
238  swap(first.fCentEst, second.fCentEst);
240  swap(first.fVertex, second.fVertex);
241  swap(first.fNVertCont, second.fNVertCont);
242  swap(first.fBeamType, second.fBeamType);
243  swap(first.fForceBeamType, second.fForceBeamType);
244  swap(first.fNeedEmcalGeom, second.fNeedEmcalGeom);
245  swap(first.fGeom, second.fGeom);
248  swap(first.fCellCollArray, second.fCellCollArray);
249  swap(first.fOutput, second.fOutput);
250 }
251 
257 {
258  // Destructor
259 }
260 
270 {
271  // Determine file type
272  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
273  if (mgr) {
274  AliVEventHandler *evhand = mgr->GetInputEventHandler();
275  if (evhand) {
276  if (evhand->InheritsFrom("AliESDInputHandler")) {
277  fIsEsd = true;
278  }
279  else {
280  fIsEsd = false;
281  }
282  }
283  else {
284  AliError("Event handler not found!");
285  }
286  }
287  else {
288  AliError("Analysis manager not found!");
289  }
290 
291  // Determine the suffix of the correction task
292  std::string tempName = GetName();
293  std::size_t foundSuffix = tempName.find("_");
294  if (foundSuffix != std::string::npos) {
295  // +1 to skip "_"
296  fSuffix = tempName.substr(foundSuffix + 1).c_str();
297  }
298 
299  // Initialize YAML configuration
301  // Check that the configuration is initialized
302  if (fConfigurationInitialized != true)
303  {
304  AliFatal("YAML configuration must be initialized before running (ie. the AddTask, run macro or wagon)!");
305  }
306 
307  // Determine component execution order
309 
310  // Check for user defined settings that are not in the default file
312 
313  // Setup input objects
314  // Setup Cells
315  // Cannot do this entirely yet because we need input objects
318  // Create cluster input objects
320  PrintRequestedContainersInformation(kCluster, AliDebugStream(1));
321  // Create track input objects
323  PrintRequestedContainersInformation(kTrack, AliDebugStream(1));
324 
325  // Initialize components
327 
328  // Print the results of the initialization
329  // Print outside of the ALICE Log system to ensure that it is always available!
330  std::cout << GetName() << " Settings:\n" << *this;
331 }
332 
342 {
343  // Determine file path
345  {
346  // Use the default if nothing is set
347  fDefaultConfigurationFilename = "$ALICE_PHYSICS/PWG/EMCAL/config/AliEmcalCorrectionConfiguration.yaml";
348  }
349 
350  // Setup the YAML files
351  // Default
353 
355  {
356  AliInfo(TString::Format("Using default EMCal corrections configuration located at %s", fDefaultConfigurationFilename.c_str()));
357 
359  // Check for valid file
360  if (fDefaultConfiguration.IsNull() == true)
361  {
362  AliFatal(TString::Format("Could not open the default configuration file \"%s\"!", fDefaultConfigurationFilename.c_str()));
363  }
364  }
365  else
366  {
367  AliFatal(TString::Format("Default file located at \"%s\" does not exist!", fDefaultConfigurationFilename.c_str()));
368  }
369 
370  // User
372 
374  {
375  AliInfo(TString::Format("Using user EMCal corrections configuration located at %s", fUserConfigurationFilename.c_str()));
376 
378  }
379  else
380  {
381  AliInfo(TString::Format("User file at \"%s\" does not exist! All settings will be from the default file!", fUserConfigurationFilename.c_str()));
382  }
383 
384  // Save configuration into strings so that they can be streamed
385  // Need the stringstream because YAML implements streamers
386  std::stringstream tempConfiguration;
387  tempConfiguration << fUserConfiguration;
388  fUserConfigurationString = tempConfiguration.str();
389  tempConfiguration.str("");
390  tempConfiguration << fDefaultConfiguration;
391  fDefaultConfigurationString = tempConfiguration.str();
392 
393  //AliInfo(TString::Format("User configuration: %s", fUserConfigurationString.c_str()));
394  //AliInfo(TString::Format("Default configuration: %s", fDefaultConfigurationString.c_str()));
395 
396  // Note that it is initialized properly so that the analysis can proceed
398 }
399 
410 void AliEmcalCorrectionTask::DetermineComponentsToExecute(std::vector <std::string> & correctionComponents)
411 {
412  std::vector <std::string> executionOrder;
413  // executionOrder determines the order of tasks to execute, but it doesn't name the particular tasks
415 
416  // Possible components to create from both the user and default configurations
417  // Use set so that the possible components are not repeated
418  std::set <std::string> possibleComponents;
419  for (auto node : fUserConfiguration) {
420  possibleComponents.insert(node.first.as<std::string>());
421  }
422  for (auto node : fDefaultConfiguration) {
423  possibleComponents.insert(node.first.as<std::string>());
424  }
425 
426  // Determine the correction names associated with the correction task
427  std::string expectedComponentName = "";
428  bool foundSuffixComponent = false;
429  bool foundComponent = false;
430  bool componentEnabled = true;
431 
432  // Execution order determines the order that corrections should be added to our execution list
433  for (auto & execName : executionOrder)
434  {
435  // Construct the expected component name with the suffix
436  expectedComponentName = TString::Format("%s_%s", execName.c_str(), fSuffix.c_str()).Data();
437  foundComponent = false;
438  componentEnabled = false;
439 
440  foundComponent = CheckPossibleNamesForComponentName(expectedComponentName, possibleComponents);
441  if (foundComponent)
442  {
443  // Check if the component is enabled
444  AliEmcalCorrectionComponent::GetProperty("enabled", componentEnabled, fUserConfiguration, fDefaultConfiguration, true, expectedComponentName);
445  // If enabled, then store the name so that it can be executed
446  if (componentEnabled == true) {
447  foundSuffixComponent = true;
448  correctionComponents.push_back(expectedComponentName);
449  }
450  else {
451  AliInfo(TString::Format("Component %s is disabled and will not be run!", expectedComponentName.c_str()));
452  }
453 
454  continue;
455  }
456  else
457  {
458  // Look for the normal component
459  expectedComponentName = execName;
460  foundComponent = CheckPossibleNamesForComponentName(expectedComponentName, possibleComponents);
461  // Check if it is enabled
462  AliEmcalCorrectionComponent::GetProperty("enabled", componentEnabled, fUserConfiguration, fDefaultConfiguration, true, expectedComponentName);
463 
464  if (componentEnabled == true) {
465  if (foundSuffixComponent == true) {
466  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()));
467  }
468  else {
469  // Take the normal component and store it to be executed
470  correctionComponents.push_back(expectedComponentName);
471  }
472  }
473  else {
474  AliInfo(TString::Format("Component %s is disabled and will not be run!", expectedComponentName.c_str()));
475  }
476  }
477  }
478 
479  // Need to append "AliEmcalCorrection" to allow the tasks to be found!
480  AliDebug(2, "Found EMCal Correction Components: ");
481  for (auto & component : correctionComponents)
482  {
483  component = "AliEmcalCorrection" + component;
484  AliDebug(2, TString::Format("%s", component.c_str()) );
485  }
486 }
487 
501 {
502  // Names of properties for a particular component in the user and default configurations
503  std::set <std::string> userPropertyNames;
504  std::set <std::string> defaultPropertyNames;
505  // Notes whether a match was found between user and default properties
506  bool foundMatch = false;
507  std::string tempComponentName = "";
508 
509  // Loop over all components
510  for (const auto componentName : fOrderedComponentsToExecute)
511  {
512  // Reset for each loop
513  userPropertyNames.clear();
514  defaultPropertyNames.clear();
515  // We need to remove "AliEmcalCorrection" so that the correction will be found in the configuration
516  // "AliEmcalCorrection" is 18 characters
517  tempComponentName = componentName.substr(componentName.find("AliEmcalCorrection")+18);
518 
519  AliDebugStream(2) << "Checking component " << componentName << " for unmatched user settings" << std::endl;
520 
521  // Get the user property names
522  GetPropertyNamesFromNode(tempComponentName, fUserConfiguration, userPropertyNames, false);
523 
524  // Get the same from default
525  // Not required here because the default configuration may not have the specialized component
526  GetPropertyNamesFromNode(tempComponentName, fDefaultConfiguration, defaultPropertyNames, false);
527 
528  // We need to check the base correction as well to fill out the options
529  if (tempComponentName.find("_") != std::string::npos) {
530  // Get the base user component
531  GetPropertyNamesFromNode(tempComponentName.substr(0, tempComponentName.find("_")), fUserConfiguration, userPropertyNames, false);
532 
533  // Required here because the default must have the base component!
534  GetPropertyNamesFromNode(tempComponentName.substr(0, tempComponentName.find("_")), fDefaultConfiguration, defaultPropertyNames, true);
535  }
536 
537  // Check each property defined in the user file for a match to the properties in the default file
538  for (auto userPropertyName : userPropertyNames)
539  {
540  AliDebugStream(2) << "Checking property " << userPropertyName << std::endl;
541  foundMatch = false;
542  for (auto defaultPropertyName : defaultPropertyNames)
543  {
544  if (userPropertyName == defaultPropertyName) {
545  AliDebugStream(2) << "Found match of " << userPropertyName << " with " << defaultPropertyName << std::endl;
546  foundMatch = true;
547  }
548  }
549  if (foundMatch == false) {
550  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()));
551  }
552  }
553  }
554 }
555 
563 {
564  // Iterate over the ordered components list and create the components
565  AliEmcalCorrectionComponent * component = 0;
566  for (auto componentName : fOrderedComponentsToExecute)
567  {
568  std::string noPrefixComponentName = componentName.substr(0, componentName.find("_" + fSuffix));
569  component = AliEmcalCorrectionComponentFactory::createInstance(noPrefixComponentName);
570  if (!component)
571  {
572  AliFatal(TString::Format("Failed to create requested component %s!", componentName.c_str()));
573  }
574 
575  // For setting names of tasks to differentiate between tasks of the same class
576  component->SetName(componentName.c_str());
577  component->SetTitle(componentName.c_str());
578 
579  // Initialize the YAML configurations in each component
582 
583  // configure needed fields for components to properly initialize
584  component->SetIsESD(fIsEsd);
585 
586  // Add the require containers to the component
587  // Cells must be set during UserExec() because we need to add them as a pointer
589  AddContainersToComponent(component, kTrack);
590 
591  // Initialize each component
592  component->Initialize();
593 
594  if (component)
595  {
596  AliInfo(TString::Format("Successfully added correction task: %s", componentName.c_str()));
597  fCorrectionComponents.push_back(component);
598  }
599  }
600 }
601 
617 {
618  // Get container node
619  std::string inputObjectName = GetInputFieldNameFromInputObjectType(inputObjectType);
620 
621  // Get the user and default input nodes for the object type
622  YAML::Node userInputObjectNode;
623  YAML::Node defaultInputObjectNode;
624  GetNodeForInputObjects(userInputObjectNode, fUserConfiguration, inputObjectName, false);
625  GetNodeForInputObjects(defaultInputObjectNode, fDefaultConfiguration, inputObjectName, true);
626 
627  AliDebugStream(3) << "userInputObjectNode: " << userInputObjectNode << std::endl;
628  AliDebugStream(3) << "defaultInputObjectNode: " << defaultInputObjectNode << std::endl;
629 
630  // Determine which containers we need based on which are requested by the enabled correction tasks
631  std::set <std::string> requestedContainers;
632  std::vector <std::string> componentRequest;
633  for ( const auto & componentName : fOrderedComponentsToExecute )
634  {
635  componentRequest.clear();
636  // Not required because not all components will have all kinds of containers
637  // "AliEmcalCorrection" is 18 characters
638  AliEmcalCorrectionComponent::GetProperty(inputObjectName + "Names", componentRequest, fUserConfiguration, fDefaultConfiguration, false, componentName.substr(componentName.find("AliEmcalCorrection")+18));
639  for ( auto & req : componentRequest )
640  {
641  AliDebugStream(3) << "Component " << componentName << " requested container name " << req << std::endl;
642  requestedContainers.insert(req);
643  }
644  }
645 
646  AliDebugStream(2) << inputObjectName << " Containers requested by components: " << std::endl;
647  for (auto & str : requestedContainers) {
648  AliDebugStream(2) << "\t" << str << std::endl;;
649  }
650 
651  // Create all requested containers
652  AliDebug(2, TString::Format("Setting up requested containers!"));
653  SetupContainersFromInputNodes(inputObjectType, userInputObjectNode, defaultInputObjectNode, requestedContainers);
654 }
655 
664 {
665  std::string inputObjectName = GetInputFieldNameFromInputObjectType(inputObjectType);
666  // Need to be of the form "clusterContainersNames"
667  inputObjectName = inputObjectName + "Names";
668 
669  std::vector <std::string> inputObjects;
670  // Not required, because not all components need Clusters or Tracks
671  AliEmcalCorrectionComponent::GetProperty(inputObjectName.c_str(), inputObjects, fUserConfiguration, fDefaultConfiguration, false, component->GetName());
672 
673  //AliDebugStream(4) << "inputObjects.size(): " << inputObjects.size() << std::endl;
674 
675  // If it is not found, then there will be nothing to iterate over, so we don't need to explicitly check the return value
676  for (auto const & str : inputObjects)
677  {
678  // 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()!
679  if (inputObjectType == kCluster)
680  {
681  AliEmcalContainer * cont = GetClusterContainer(str.c_str());
682  AliDebugStream(2) << "Adding cluster container " << str << " of array " << cont->GetArrayName() << " to component " << component->GetName() << std::endl;
683  component->SetClusterContainer(GetClusterContainer(str.c_str()));
684  }
685  else if (inputObjectType == kTrack)
686  {
687  AliEmcalContainer * cont = GetParticleContainer(str.c_str());
688  AliDebugStream(2) << "Adding particle container " << str << " of array " << cont->GetArrayName() << " to component " << component->GetName() << std::endl;
689  component->SetParticleContainer(GetParticleContainer(str.c_str()));
690  }
691  else if (inputObjectType == kCaloCells)
692  {
693  // NOTE: This operates different than the others. This should be executed during run time rather than during initialization!
694  if (inputObjects.size() > 1) {
695  AliFatal(TString::Format("Component %s requested more than one cell branch, but this is not supported! Check the configuration!", component->GetName()));
696  }
697 
698  // If we've made it here, this must be at least one entry
699  AliDebugStream(2) << "Adding calo cells " << GetCellContainer(str)->GetName() << " of branch name " << GetCellContainer(str)->GetBranchName() << "to component " << component->GetName() << std::endl;
700  component->SetCaloCells(GetCellContainer(str)->GetCells());
701  AliDebugStream(3) << "component GetNumberOfCells: " << component->GetCaloCells()->GetNumberOfCells() << std::endl;
702  }
703  }
704 }
705 
714 void AliEmcalCorrectionTask::SetupContainersFromInputNodes(InputObject_t inputObjectType, YAML::Node & userInputObjectNode, YAML::Node & defaultInputObjectNode, std::set <std::string> & requestedContainers)
715 {
716  // Our node contains all of the objects that we will want to create.
717  for(auto & containerName : requestedContainers)
718  {
719  // The section is the container name
720  //std::string containerName = it->first.as<std::string>();
721  // Skip if the particle or cluster container already exists
722  if (GetParticleContainer(containerName.c_str()) || GetClusterContainer(containerName.c_str())) {
723  continue;
724  }
725 
726  AliDebug(2, TString::Format("Processing container %s of inputType %d", containerName.c_str(), inputObjectType));
727  if (inputObjectType == kCluster || inputObjectType == kTrack) {
728  SetupContainer(inputObjectType, containerName, userInputObjectNode, defaultInputObjectNode);
729  }
730  else if (inputObjectType == kCaloCells) {
731  SetupCellsInfo(containerName, userInputObjectNode, defaultInputObjectNode);
732  }
733  }
734 }
735 
746 void AliEmcalCorrectionTask::SetupCellsInfo(std::string containerName, YAML::Node & userNode, YAML::Node & defaultNode)
747 {
748  // Define cell info
750 
751  AliDebugStream(2) << "User: " << std::endl << userNode << std::endl << "default: " << std::endl << defaultNode << std::endl;
752 
753  // Set properties
754  // Cells (object) name
755  cellObj->SetName(containerName);
756  // Branch name
757  std::string tempString = "";
758  AliEmcalCorrectionComponent::GetProperty("branchName", tempString, userNode, defaultNode, true, containerName);
759  if (tempString == "usedefault") {
761  }
762  cellObj->SetBranchName(tempString);
763 
764  // IsEmbedding
765  bool tempBool = false;
766  AliEmcalCorrectionComponent::GetProperty("embedded", tempString, userNode, defaultNode, false, containerName);
767  cellObj->SetIsEmbedding(tempBool);
768 
769  // Add to the array to keep track of it
770  fCellCollArray.push_back(cellObj);
771 }
772 
790 void AliEmcalCorrectionTask::SetupContainer(InputObject_t inputObjectType, std::string containerName, YAML::Node & userNode, YAML::Node & defaultNode)
791 {
792  // Create container
793  AliDebugStream(2) << "Adding container" << std::endl;
794  AliEmcalContainer * cont = AddContainer(inputObjectType, containerName, userNode, defaultNode);
795  AliDebugStream(2) << "Added container" << std::endl;
796 
797  // Set the container properties
798  //
799  // TODO: Consider if this can be converted to a map to function pointers. There are a number of details
800  // which can make it a bit complicated. Those details include inheritance, pointing to member
801  // functions, etc. It should all be possible, but may not be worth all of the extra work and code.
802  // Example ccode:
803  // SetValueInContainer("minPt", &cont::SetMinPt, tempDouble, userNode, defaultNode);
804  // SetValueInContainer("minE", &cont::SetMinE, tempDouble, userNode, defaultNode);
805 
806  // Temporary variables to store requested properties
807  std::string tempString = "";
808  Double_t tempDouble = 0;
809  bool tempBool = false;
810 
811  // AliEmcalContainer properties
812  // Min Pt
813  bool result = AliEmcalCorrectionComponent::GetProperty("minPt", tempDouble, userNode, defaultNode, false, containerName);
814  if (result) {
815  AliDebugStream(2) << cont->GetName() << ": Setting minPt of " << tempDouble << std::endl;
816  cont->SetMinPt(tempDouble);
817  }
818  // Min E
819  result = AliEmcalCorrectionComponent::GetProperty("minE", tempDouble, userNode, defaultNode, false, containerName);
820  if (result) {
821  AliDebugStream(2) << cont->GetName() << ": Setting minE of " << tempDouble << std::endl;
822  cont->SetMinE(tempDouble);
823  }
824  // Eta min, max
825  result = AliEmcalCorrectionComponent::GetProperty("minEta", tempDouble, userNode, defaultNode, false, containerName);
826  if (result) {
827  // Only continue checking if the min is there, since we must set both together
828  Double_t tempDouble2 = 0;
829  result = AliEmcalCorrectionComponent::GetProperty("maxEta", tempDouble, userNode, defaultNode, false, containerName);
830  if (result) {
831  AliDebugStream(2) << cont->GetName() << ": Setting eta limits of " << tempDouble << " to " << tempDouble2 << std::endl;
832  cont->SetEtaLimits(tempDouble, tempDouble2);
833  }
834  }
835  // Phi min, max
836  result = AliEmcalCorrectionComponent::GetProperty("minPhi", tempDouble, userNode, defaultNode, false, containerName);
837  if (result) {
838  // Only continue checking if the min is there, since we must set both together
839  Double_t tempDouble2 = 0;
840  result = AliEmcalCorrectionComponent::GetProperty("maxPhi", tempDouble, userNode, defaultNode, false, containerName);
841  if (result) {
842  AliDebugStream(2) << cont->GetName() << ": Setting phi limits of " << tempDouble << " to " << tempDouble2 << std::endl;
843  cont->SetPhiLimits(tempDouble, tempDouble2);
844  }
845  }
846  // Embedded
847  // TODO: Enable embedded when that branch is committed!
848  /*result = AliEmcalCorrectionComponent::GetProperty("IsEmbedded", tempBool, userNode, defaultNode, false, containerName);
849  if (result) {
850  AliDebugStream(2) << cont->GetName() << ": Setting embedding to " << (tempBool ? "enabled" : "disabled") << std::endl;
851  cont->SetIsEmbedding(tempBool);
852  }*/
853 
854  // Cluster specific properties
855  AliClusterContainer * clusterContainer = dynamic_cast<AliClusterContainer *>(cont);
856  if (clusterContainer) {
857  // Default energy
858  // Probably not needed for the corrections
859  /*result = AliEmcalCorrectionComponent::GetProperty("defaultClusterEnergy", tempString, userNode, defaultNode, false, containerName);
860  if (result) {
861  // Need to get the enumeration
862  AliVCluster::VCluUserDefEnergy_t clusterEnergyType = fgkClusterEnergyTypeMap.at(tempString);
863  AliDebugStream(2) << clusterContainer->GetName() << ": Setting cluster energy type to " << clusterEnergyType << std::endl;
864  clusterContainer->SetDefaultClusterEnergy(clusterEnergyType);
865  }*/
866 
867  // NonLinCorrEnergyCut
868  result = AliEmcalCorrectionComponent::GetProperty("clusNonLinCorrEnergyCut", tempDouble, userNode, defaultNode, false, containerName);
869  if (result) {
870  AliDebugStream(2) << clusterContainer->GetName() << ": Setting clusNonLinCorrEnergyCut of " << tempDouble << std::endl;
871  clusterContainer->SetClusNonLinCorrEnergyCut(tempDouble);
872  }
873 
874  // HadCorrEnergyCut
875  result = AliEmcalCorrectionComponent::GetProperty("clusHadCorrEnergyCut", tempDouble, userNode, defaultNode, false, containerName);
876  if (result) {
877  AliDebugStream(2) << clusterContainer->GetName() << ": Setting clusHadCorrEnergyCut of " << tempDouble << std::endl;
878  clusterContainer->SetClusHadCorrEnergyCut(tempDouble);
879  }
880 
881  // SetIncludePHOS
882  result = AliEmcalCorrectionComponent::GetProperty("includePHOS", tempBool, userNode, defaultNode, false, containerName);
883  if (result) {
884  AliDebugStream(2) << clusterContainer->GetName() << ": Setting Include PHOS to " << (tempBool ? "enabled" : "disabled") << std::endl;
885  clusterContainer->SetIncludePHOS(tempBool);
886  }
887  }
888 
889  // Track specific
890  AliTrackContainer * trackContainer = dynamic_cast<AliTrackContainer *>(cont);
891  if (trackContainer) {
892  // Track selection
893  // AOD Filter bits as a sequence
894  std::vector <UInt_t> filterBitsVector;
895  result = AliEmcalCorrectionComponent::GetProperty("aodFilterBits", filterBitsVector, userNode, defaultNode, false, containerName);
896  if (result){
897  UInt_t filterBits = 0;
898  for (int filterBit : filterBitsVector) {
899  filterBits += filterBit;
900  }
901  AliDebugStream(2) << trackContainer->GetName() << ": Setting filterBits of " << filterBits << std::endl;
902  trackContainer->SetAODFilterBits(filterBits);
903  }
904 
905  // SetTrackFilterType enum
906  result = AliEmcalCorrectionComponent::GetProperty("trackFilterType", tempString, userNode, defaultNode, false, containerName);
907  if (result) {
908  // Need to get the enumeration
909  AliEmcalTrackSelection::ETrackFilterType_t trackFilterType = fgkTrackFilterTypeMap.at(tempString);
910  AliDebugStream(2) << trackContainer->GetName() << ": Setting trackFilterType of " << trackFilterType << std::endl;
911  trackContainer->SetTrackFilterType(trackFilterType);
912  }
913 
914  // Track cuts period
915  result = AliEmcalCorrectionComponent::GetProperty("trackCutsPeriod", tempString, userNode, defaultNode, false, containerName);
916  if (result) {
917  // Need to get the enumeration
918  AliDebugStream(2) << trackContainer->GetName() << ": Setting track cuts period to " << tempString << std::endl;
919  trackContainer->SetTrackCutsPeriod(tempString.c_str());
920  }
921  }
922 }
923 
941 AliEmcalContainer * AliEmcalCorrectionTask::AddContainer(InputObject_t contType, std::string & containerName, YAML::Node & userNode, YAML::Node & defaultNode)
942 {
943  // Determine the type of branch to request
944  std::string containerBranch = "";
945  if (contType != kCluster && contType != kTrack){
946  AliFatal("Must specify type of container when requesting branch.");
947  }
948 
949  // Retrieve branch name
950  // YAML::Node() is just an empty node
951  AliDebugStream(2) << "User Node: " << userNode << std::endl;
952  AliDebugStream(2) << "Default Node: " << defaultNode << std::endl;
953  AliEmcalCorrectionComponent::GetProperty("branchName", containerBranch, userNode, defaultNode, true, containerName);
954  // Should be unnecessary, since the user can only do this if done explicitly.
955  /*if (containerBranch == "")
956  {
957  AliFatal(TString::Format("Request %i container, but the container branch is empty!", contType));
958  }*/
959 
960  // Determine proper name if using "usedefault" pattern
961  if (containerBranch == "usedefault") {
962  containerBranch = DetermineUseDefaultName(contType, fIsEsd);
963  }
964 
965  // Create containers and set them to the name of the component
966  AliEmcalContainer * cont = 0;
967  if (contType == kCluster)
968  {
969  cont = new AliClusterContainer(containerBranch.c_str());
970  AdoptClusterContainer(dynamic_cast<AliClusterContainer *>(cont));
971  }
972  else if (contType == kTrack)
973  {
974  if (containerBranch == "mcparticles") {
975  cont = new AliMCParticleContainer(containerBranch.c_str());
976  }
977  else {
978  cont = new AliTrackContainer(containerBranch.c_str());
979  }
980  AdoptParticleContainer(dynamic_cast<AliParticleContainer *>(cont));
981  }
982  cont->SetName(containerName.c_str());
983 
984  return cont;
985 }
986 
996 {
997  // Check that the configuration is initialized
998  if (fConfigurationInitialized != true)
999  {
1000  AliFatal("YAML configuration must be initialized before running (ie. the AddTask, run macro or wagon)!");
1001  }
1002 
1003  // Show the configurations info this is available
1004  AliDebugStream(4) << "User configuration string: " << fUserConfigurationString << std::endl;
1005  AliDebugStream(4) << "User configuration: " << fUserConfiguration << std::endl;
1006  AliDebugStream(4) << "Default configuration string: " << fDefaultConfigurationString << std::endl;
1007  AliDebugStream(4) << "Default configuration: " << fDefaultConfiguration << std::endl;
1008 
1009  // YAML Objects cannot be streamed, so we need to reinitialize them here.
1010  // They need reinitialize if they are null
1011  if (fUserConfiguration.IsNull() == true && fUserConfigurationString != "")
1012  {
1013  AliInfo("Reinitializing user configuration from string. Expected if running on grid!");
1015  }
1016  if (fDefaultConfiguration.IsNull() == true)
1017  {
1018  AliInfo("Reinitializing default configuration from string. Expected if running on grid!");
1020  }
1021 
1022  // Debug to check that the configuration has been (re)initiailzied has been completed correctly
1023  AliDebugStream(4) << "(Re)initialized user configuration: " << fUserConfigurationString << std::endl;
1024  AliDebugStream(4) << "(Re)initialized user configuration: " << fUserConfiguration << std::endl;
1025  AliDebugStream(4) << "(Re)initialized default configuration: " << fDefaultConfigurationString << std::endl;
1026  AliDebugStream(4) << "(Re)initialized default configuration: " << fDefaultConfiguration << std::endl;
1027 
1028  if (fForceBeamType == kpp)
1029  fNcentBins = 1;
1030 
1031  // Allow for output files
1032  OpenFile(1);
1033  fOutput = new TList();
1034  fOutput->SetOwner();
1035 
1037 
1038  PostData(1, fOutput);
1039 }
1040 
1048 {
1049  // Run the initialization for all derived classes.
1050  for (auto component : fCorrectionComponents)
1051  {
1052  // Set cent bins (usually used for hist creation)
1053  // It cannot be set until now because it can be changed after initialization
1054  // For instance, by SetForceBeamType()
1055  component->SetNcentralityBins(fNcentBins);
1056 
1057  component->UserCreateOutputObjects();
1058 
1059  if (component->GetOutputList() != 0)
1060  {
1061  // Adds a list to the list -- this doesn't work for some unknown reason
1062  //fOutput->Add(component->GetOutputList());
1063 
1064  // iterate through lists for each component, and fill in output
1065  TList* t = new TList();
1066  t->SetName(component->GetName());
1067  fOutput->AddLast(t);
1068  t = (TList*)fOutput->Last();
1069  TIter next(component->GetOutputList());
1070  while (TObject *obj = next()){
1071  t->Add(obj);
1072  }
1073 
1074  AliDebug(1, TString::Format("Added output list from task %s to output.", component->GetName()));
1075  }
1076  }
1077 }
1078 
1084 {
1085  // Initialize the event if not initialized
1086  if (!fEventInitialized)
1087  ExecOnce();
1088 
1089  // Only continue if we are initialized successfully
1090  if (!fEventInitialized)
1091  return;
1092 
1093  // Get the objects for each event
1094  if (!RetrieveEventObjects())
1095  return;
1096 
1097  // Call run for each correction
1098  if (!Run())
1099  return;
1100 }
1101 
1113 {
1114  if (!InputEvent()) {
1115  AliError("Could not retrieve event! Returning!");
1116  return;
1117  }
1118 
1119  // This warning was extracted out from the cell components
1120  if (dynamic_cast<AliAODEvent*>(InputEvent())) {
1121  AliWarning("=============================================================");
1122  AliWarning("=== Running on AOD is not equivalent to running on ESD! ===");
1123  AliWarning("=============================================================");
1124  }
1125 
1126  if (fNeedEmcalGeom) {
1127  fGeom = AliEMCALGeometry::GetInstanceFromRunNumber(InputEvent()->GetRunNumber());
1128  if (!fGeom) {
1129  AliFatal("Can not get EMCal geometry instance. If you do not need the EMCal geometry, disable it by setting task->SetNeedEmcalGeometry(kFALSE).");
1130  return;
1131  }
1132  }
1133 
1134  // Load all requested track branches - each container knows name already
1135  for (Int_t i =0; i<fParticleCollArray.GetEntriesFast(); i++) {
1136  AliParticleContainer *cont = static_cast<AliParticleContainer*>(fParticleCollArray.At(i));
1138  cont->SetArray(InputEvent());
1139  }
1140 
1141  // Load all requested cluster branches - each container knows name already
1142  for (Int_t i =0; i<fClusterCollArray.GetEntriesFast(); i++) {
1143  AliClusterContainer *cont = static_cast<AliClusterContainer*>(fClusterCollArray.At(i));
1145  cont->SetArray(InputEvent());
1146  }
1147 
1148  // Determine the proper pointer for each cell object and save them to the cell container
1149  // At this point, they should all be created
1150  for (auto cellObj : fCellCollArray)
1151  {
1153  }
1154 
1155  fEventInitialized = kTRUE;
1156 
1157  // Print warning to the user that the rest of the configuration information is available in the generation log
1158  // when the Analysis Manager was created. Using cout to be certain that it is shown on the train!
1159  std::cout << "=== NOTE: Additional EMCal Corrections configuration information can be found when the Analysis Manager is configured. For a run macro, see above, while for a LEGO train, see the generation.log ===\n";
1160 
1161  // Setup the components
1163 }
1164 
1170 {
1171  // Run the initialization for all derived classes.
1172  for (auto component : fCorrectionComponents)
1173  {
1174  // Setup geomertry
1175  component->SetEMCALGeometry(fGeom);
1176 
1177  // Add the requested cells to the component
1178  //AliDebugStream(3) << "Adding CaloCells" << std::endl;
1180  //AliDebugStream(3) << "Added CaloCells" << std::endl;
1181 
1182  // Component ExecOnce()
1183  component->ExecOnce();
1184  }
1185 }
1186 
1192 {
1193  fVertex[0] = 0;
1194  fVertex[1] = 0;
1195  fVertex[2] = 0;
1196  fNVertCont = 0;
1197 
1198  const AliVVertex *vert = InputEvent()->GetPrimaryVertex();
1199  if (vert) {
1200  vert->GetXYZ(fVertex);
1201  fNVertCont = vert->GetNContributors();
1202  }
1203 
1204  fBeamType = GetBeamType();
1205 
1206  if (fBeamType == kAA || fBeamType == kpA ) {
1208  AliMultSelection *MultSelection = static_cast<AliMultSelection*>(InputEvent()->FindListObject("MultSelection"));
1209  if (MultSelection) {
1210  fCent = MultSelection->GetMultiplicityPercentile(fCentEst.Data());
1211  }
1212  else {
1213  AliWarning("Could not retrieve centrality information! Assuming 99");
1214  }
1215  }
1216  else { // old centrality estimation < 2015
1217  AliCentrality *aliCent = InputEvent()->GetCentrality();
1218  if (aliCent) {
1219  fCent = aliCent->GetCentralityPercentile(fCentEst.Data());
1220  }
1221  else {
1222  AliWarning("Could not retrieve centrality information! Assuming 99");
1223  }
1224  }
1225 
1226  if (fNcentBins==4) {
1227  if (fCent >= 0 && fCent < 10) fCentBin = 0;
1228  else if (fCent >= 10 && fCent < 30) fCentBin = 1;
1229  else if (fCent >= 30 && fCent < 50) fCentBin = 2;
1230  else if (fCent >= 50 && fCent <= 100) fCentBin = 3;
1231  else {
1232  AliWarning(Form("Negative centrality: %f. Assuming 99", fCent));
1233  fCentBin = fNcentBins-1;
1234  }
1235  }
1236  else if (fNcentBins==5) { // for PbPb 2015
1237  if (fCent >= 0 && fCent < 10) fCentBin = 0;
1238  else if (fCent >= 10 && fCent < 30) fCentBin = 1;
1239  else if (fCent >= 30 && fCent < 50) fCentBin = 2;
1240  else if (fCent >= 50 && fCent <= 90) fCentBin = 3;
1241  else if (fCent > 90) {
1242  fCent = 99;
1243  fCentBin = 4;
1244  }
1245  else {
1246  AliWarning(Form("Negative centrality: %f. Assuming 99", fCent));
1247  fCentBin = fNcentBins-1;
1248  }
1249  }
1250  else {
1251  Double_t centWidth = (fMaxCent-fMinCent)/(Double_t)fNcentBins;
1252  if(centWidth>0.) {
1253  fCentBin = TMath::FloorNint(fCent/centWidth);
1254  }
1255  else {
1256  fCentBin = 0;
1257  }
1258  if (fCentBin>=fNcentBins) {
1259  AliWarning(Form("fCentBin too large: cent = %f fCentBin = %d. Assuming 99", fCent, fCentBin));
1260  fCentBin = fNcentBins-1;
1261  }
1262  }
1263  }
1264  else {
1265  fCent = 99;
1266  fCentBin = 0;
1267  }
1268 
1269  AliEmcalContainer* cont = 0;
1270 
1271  TIter nextPartColl(&fParticleCollArray);
1272  while ((cont = static_cast<AliEmcalContainer*>(nextPartColl()))) cont->NextEvent();
1273 
1274  TIter nextClusColl(&fClusterCollArray);
1275  while ((cont = static_cast<AliEmcalContainer*>(nextClusColl()))) cont->NextEvent();
1276 
1277  return kTRUE;
1278 }
1279 
1285 {
1286  // Run the initialization for all derived classes.
1287  for (auto component : fCorrectionComponents)
1288  {
1289  component->SetEvent(InputEvent());
1290  component->SetMCEvent(MCEvent());
1291  component->SetCentralityBin(fCentBin);
1292  component->SetCentrality(fCent);
1293 
1294  component->Run();
1295  }
1296 
1297  PostData(1, fOutput);
1298 
1299  return kTRUE;
1300 }
1301 
1306 {
1307  // Run the initialization for all derived classes.
1308  for (auto component : fCorrectionComponents)
1309  {
1310  component->UserNotify();
1311  }
1312 
1313  return kTRUE;
1314 }
1315 
1322 std::ostream & AliEmcalCorrectionTask::PrintConfigurationString(std::ostream & in, bool userConfig) const
1323 {
1324  std::string stringToWrite = userConfig ? fUserConfigurationString : fDefaultConfigurationString;
1325  if (stringToWrite == "") {
1326  AliWarning(TString::Format("%s configuration is empty!", userConfig ? "User" : "Default"));
1327  }
1328  in << stringToWrite;
1329 
1330  return in;
1331 }
1332 
1340 bool AliEmcalCorrectionTask::WriteConfigurationFile(std::string filename, bool userConfig) const
1341 {
1342  bool returnValue = false;
1343  if (filename != "")
1344  {
1345  if (fConfigurationInitialized == true)
1346  {
1347  std::ofstream outFile(filename);
1348  PrintConfigurationString(outFile, userConfig);
1349  outFile.close();
1350 
1351  returnValue = true;
1352  }
1353  else
1354  {
1355  AliWarning(TString::Format("Configuration not properly initialized! Cannot print %s configuration!", userConfig ? "user" : "default"));
1356  }
1357 
1358  }
1359  else
1360  {
1361  AliWarning("Please pass a valid filename instead of empty quotes!");
1362  }
1363  return returnValue;
1364 }
1365 
1381 std::string AliEmcalCorrectionTask::DetermineUseDefaultName(InputObject_t objType, bool esdMode, bool returnObjectType)
1382 {
1383  std::string returnValue = "";
1384  if (objType == kCluster) {
1385  if (esdMode == true) {
1386  if (returnObjectType == true) {
1387  returnValue = "AliESDCaloCluster";
1388  }
1389  else {
1390  returnValue = "CaloClusters";
1391  }
1392  }
1393  else {
1394  if (returnObjectType == true) {
1395  returnValue = "AliAODCaloCluster";
1396  }
1397  else {
1398  returnValue = "caloClusters";
1399  }
1400  }
1401  }
1402  else if (objType == kTrack) {
1403  if (esdMode == true) {
1404  if (returnObjectType == true) {
1405  returnValue = "AliESDtrack";
1406  }
1407  else {
1408  returnValue = "Tracks";
1409  }
1410  }
1411  else {
1412  if (returnObjectType == true) {
1413  returnValue = "AliAODTrack";
1414  }
1415  else {
1416  returnValue = "tracks";
1417  }
1418  }
1419  }
1420  else if (objType == kCaloCells) {
1421  if (esdMode == true) {
1422  if (returnObjectType == true) {
1423  returnValue = "AliESDCaloCells";
1424  }
1425  else {
1426  returnValue = "EMCALCells";
1427  }
1428  }
1429  else {
1430  if (returnObjectType == true) {
1431  returnValue = "AliAODCaloCells";
1432  }
1433  else {
1434  returnValue = "emcalCells";
1435  }
1436  }
1437  }
1438  else {
1439  // Default to empty if we are given an unrecognized type with "usedefault"
1440  returnValue = "";
1441  }
1442 
1443  return returnValue;
1444 }
1445 
1455 AliVEvent * AliEmcalCorrectionTask::GetEvent(AliVEvent * inputEvent, bool isEmbedding)
1456 {
1457  AliVEvent * event = 0;
1458  if (isEmbedding) {
1459  // TODO: Enable embedded when that branch is committed!
1460  /*const AliAnalysisTaskEmcalEmbeddingHelper* embedding = AliAnalysisTaskEmcalEmbeddingHelper::GetInstance();
1461  if (!embedding) return 0;
1462 
1463  event = embedding->GetExternalEvent();*/
1464  }
1465  else {
1466  event = inputEvent;
1467  }
1468 
1469  return event;
1470 }
1471 
1480 inline bool AliEmcalCorrectionTask::DoesFileExist(const std::string & filename)
1481 {
1482  std::ifstream inFile(filename);
1483  return inFile.good();
1484 }
1485 
1495 {
1496  if (filename != "")
1497  {
1498  // Handle if in AliPhysics and includes $ALICE_PHYSICS
1499  filename = gSystem->ExpandPathName(filename.c_str());
1500 
1501  // Handle grid
1502  if(filename.find("alien://") != std::string::npos)
1503  {
1504  AliDebug(2, TString::Format("Opening file \"%s\" on the grid!", filename.c_str()));
1505  // Initialize alien connection if needed
1506  if (!gGrid) {
1507  TGrid::Connect("alien://");
1508  }
1509 
1510  // Determine the local filename and copy file to local directory
1511  std::string localFilename = gSystem->BaseName(filename.c_str());
1512  // Ensures that the default and user files do not conflict if both are taken from the grid and have the same filename
1513  if (userFile == true) {
1514  localFilename = "user" + localFilename;
1515  }
1516  TFile::Cp(filename.c_str(), localFilename.c_str());
1517 
1518  // yaml-cpp should only open the local file
1519  filename = localFilename;
1520  }
1521  }
1522 }
1523 
1531 {
1532  AliDebugStream(2) << "Retrieving cells object " << cellContainer->GetName() << std::endl;
1533  // Check for embedding and return object
1534  AliVEvent * event = GetEvent(InputEvent(), cellContainer->GetIsEmbedding());
1535 
1536  cellContainer->SetCells(dynamic_cast<AliVCaloCells *>(event->FindListObject(cellContainer->GetBranchName().c_str())));
1537 }
1538 
1548 void AliEmcalCorrectionTask::CheckForContainerArray(AliEmcalContainer * cont, InputObject_t objectType)
1549 {
1550  // TODO: Enable embedded when that branch is committed!
1551  //AliVEvent * event = GetEvent(InputEvent(), cont->GetIsEmbedding());
1552  AliVEvent * event = GetEvent(InputEvent());
1553 
1554  TClonesArray * array = dynamic_cast<TClonesArray *>(event->FindListObject(cont->GetArrayName()));
1555  if (!array) {
1556  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()));
1557  array = new TClonesArray(DetermineUseDefaultName(objectType, fIsEsd, true).c_str());
1558  array->SetName(cont->GetArrayName());
1559  event->AddObject(array);
1560  }
1561 }
1562 
1571 {
1572  // Get container node
1573  std::string inputObjectName = "";
1574  if (inputObjectType == kCluster) {
1575  inputObjectName = "clusterContainers";
1576  }
1577  else if (inputObjectType == kTrack) {
1578  inputObjectName = "trackContainers";
1579  }
1580  else if (inputObjectType == kCaloCells) {
1581  inputObjectName = "cells";
1582  }
1583  else {
1584  AliFatal(TString::Format("Unrecognized input object type %d", inputObjectType));
1585  }
1586 
1587  return inputObjectName;
1588 }
1589 
1601 bool AliEmcalCorrectionTask::CheckPossibleNamesForComponentName(std::string & name, std::set <std::string> & possibleComponents)
1602 {
1603  bool foundComponent = false;
1604  for (auto & possibleComponent : possibleComponents)
1605  {
1606  if (possibleComponent == name) {
1607  foundComponent = true;
1608  break;
1609  }
1610  }
1611 
1612  return foundComponent;
1613 }
1614 
1622 {
1623  if (fForceBeamType != kNA)
1624  return fForceBeamType;
1625 
1626  AliESDEvent *esd = dynamic_cast<AliESDEvent*>(InputEvent());
1627  if (esd) {
1628  const AliESDRun *run = esd->GetESDRun();
1629  TString beamType = run->GetBeamType();
1630  if (beamType == "p-p")
1631  return kpp;
1632  else if (beamType == "A-A")
1633  return kAA;
1634  else if (beamType == "p-A")
1635  return kpA;
1636  else
1637  return kNA;
1638  } else {
1639  Int_t runNumber = InputEvent()->GetRunNumber();
1640  // All run number ranges taken from the RCT
1641  if ((runNumber >= 136833 && runNumber <= 139517) || // LHC10h
1642  (runNumber >= 167693 && runNumber <= 170593) || // LHC11h
1643  (runNumber >= 244824 && runNumber <= 246994)) { // LHC15o
1644  return kAA;
1645  } else if ((runNumber >= 188356 && runNumber <= 188366) || // LHC12g
1646  (runNumber >= 195164 && runNumber <= 197388) || // LHC13b-f
1647  (runNumber >= 265015 && runNumber <= 267166)) { // LHC16q-t
1648  return kpA;
1649  } else {
1650  return kpp;
1651  }
1652  }
1653 }
1654 
1658 void AliEmcalCorrectionTask::PrintRequestedContainersInformation(InputObject_t inputObjectType, std::ostream & stream) const
1659 {
1660  if (inputObjectType == kCaloCells) {
1661  stream << "Cells info: " << std::endl;
1662  for (auto cellInfo : fCellCollArray) {
1663  stream << "\tName: " << cellInfo->GetName() << "\tBranch: " << cellInfo->GetBranchName() << "\tIsEmbedding: " << std::boolalpha << cellInfo->GetIsEmbedding() << std::endl;
1664  }
1665  }
1666  else if (inputObjectType == kCluster || inputObjectType == kTrack) {
1667  stream << (inputObjectType == kCluster ? "Cluster" : "Track") << " container info: " << std::endl;
1668  AliEmcalContainer * cont = 0;
1669  for (auto containerInfo : (inputObjectType == kCluster ? fClusterCollArray : fParticleCollArray) ) {
1670  cont = static_cast<AliEmcalContainer *>(containerInfo);
1671  stream << "\tName: " << cont->GetName() << "\tBranch: " << cont->GetArrayName() << "\tTitle: " << cont->GetTitle() << std::endl;
1672  // TODO: Enable in embedding branch
1673  //stream << "\tName: " << cont->GetName() << "\tBranch: " << cont->GetArrayName() << "\tTitle: " << cont->GetTitle() << "\tIsEmbedding:" << std::boolalpha << cont->GetIsEmbedding() << std::endl;
1674  }
1675  }
1676  else {
1677  AliErrorStream() << "Unrecognized input object type " << inputObjectType << std::endl;
1678  }
1679 }
1680 
1690 void AliEmcalCorrectionTask::GetNodeForInputObjects(YAML::Node & inputNode, YAML::Node & nodeToRetrieveFrom, std::string & inputObjectName, bool requiredProperty)
1691 {
1692  // Get the user input node
1693  AliEmcalCorrectionComponent::GetProperty(inputObjectName.c_str(), inputNode, YAML::Node(), nodeToRetrieveFrom, requiredProperty, "inputObjects");
1694 
1695  // Get the user shared node and add it back to the user node so that shared parameters are available
1696  if (nodeToRetrieveFrom["sharedParameters"]) {
1697  inputNode["sharedParameters"] = nodeToRetrieveFrom["sharedParameters"];
1698  }
1699 }
1700 
1711 void AliEmcalCorrectionTask::GetPropertyNamesFromNode(const std::string & componentName, const YAML::Node & node, std::set <std::string> & propertyNames, const bool nodeRequired)
1712 {
1713  YAML::Node tempNode;
1714  AliEmcalCorrectionComponent::GetProperty(componentName, tempNode, YAML::Node(), node, nodeRequired, "");
1715  for (auto propertyName : tempNode)
1716  {
1717  propertyNames.insert(propertyName.first.as<std::string>());
1718  }
1719 }
1720 
1729 {
1730  if (TString(n).IsNull()) return 0;
1731 
1733 
1734  fParticleCollArray.Add(cont);
1735 
1736  return cont;
1737 }
1738 
1747 {
1748  if (TString(n).IsNull()) return 0;
1749 
1750  AliTrackContainer* cont = new AliTrackContainer(n);
1751 
1752  fParticleCollArray.Add(cont);
1753 
1754  return cont;
1755 }
1756 
1765 {
1766  if (TString(n).IsNull()) return 0;
1767 
1769 
1770  fParticleCollArray.Add(cont);
1771 
1772  return cont;
1773 }
1774 
1783 {
1784  if (TString(n).IsNull()) return 0;
1785 
1787 
1788  fClusterCollArray.Add(cont);
1789 
1790  return cont;
1791 }
1792 
1799 {
1800  if (i<0 || i>fParticleCollArray.GetEntriesFast()) return 0;
1801  AliParticleContainer *cont = static_cast<AliParticleContainer*>(fParticleCollArray.At(i));
1802  return cont;
1803 }
1804 
1811 {
1812  if (i<0 || i>fClusterCollArray.GetEntriesFast()) return 0;
1813  AliClusterContainer *cont = static_cast<AliClusterContainer*>(fClusterCollArray.At(i));
1814  return cont;
1815 }
1816 
1823 {
1824  AliParticleContainer *cont = static_cast<AliParticleContainer*>(fParticleCollArray.FindObject(name));
1825  return cont;
1826 }
1827 
1834 {
1835  AliClusterContainer *cont = static_cast<AliClusterContainer*>(fClusterCollArray.FindObject(name));
1836  return cont;
1837 }
1838 
1846 AliEmcalCorrectionCellContainer * AliEmcalCorrectionTask::GetCellContainer(const std::string & cellsContainerName) const
1847 {
1848  for (auto cellContainer : fCellCollArray)
1849  {
1850  if (cellContainer->GetName() == cellsContainerName) {
1851  return cellContainer;
1852  }
1853  }
1854 
1855  return 0;
1856 }
1857 
1859 {
1860  // Get the pointer to the existing analysis manager via the static access method.
1861  //==============================================================================
1862  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
1863  if (!mgr)
1864  {
1865  ::Error("AddTaskEmcalCorrectionTask", "No analysis manager to connect to.");
1866  return 0;
1867  }
1868 
1869  // Check the analysis type using the event handlers connected to the analysis manager.
1870  //==============================================================================
1871  AliVEventHandler* handler = mgr->GetInputEventHandler();
1872  if (!handler)
1873  {
1874  ::Error("AddTaskEmcalCorrectionTask", "This task requires an input event handler");
1875  return 0;
1876  }
1877 
1878  TString name = "AliEmcalCorrectionTask";
1879  if (suffix != "") {
1880  name += TString::Format("_%s", suffix.Data());
1881  }
1882 
1883  AliEmcalCorrectionTask* mgrTask = static_cast<AliEmcalCorrectionTask *>(mgr->GetTask(name.Data()));
1884  if (mgrTask) return mgrTask;
1885 
1886  // Create the task that manages the corrections
1887  AliEmcalCorrectionTask* correctionTask = new AliEmcalCorrectionTask(name.Data());
1888 
1889  //-------------------------------------------------------
1890  // Final settings, pass to manager and set the containers
1891  //-------------------------------------------------------
1892 
1893  mgr->AddTask(correctionTask);
1894 
1895  // Create containers for input/output
1896  AliAnalysisDataContainer* cInput = mgr->GetCommonInputContainer();
1897 
1898  TString outputContainerName(name);
1899  outputContainerName += "_histos";
1900 
1901  AliAnalysisDataContainer * cOutput = mgr->CreateContainer(outputContainerName.Data(),
1902  TList::Class(),
1903  AliAnalysisManager::kOutputContainer,
1904  Form("%s", AliAnalysisManager::GetCommonFileName()));
1905 
1906  mgr->ConnectInput(correctionTask, 0, cInput);
1907  mgr->ConnectOutput(correctionTask, 1, cOutput);
1908 
1909  //TObjArray* cnt = mgr->GetContainers();
1910 
1911  return correctionTask;
1912 }
1913 
1919 std::string AliEmcalCorrectionTask::toString(bool includeYAMLConfigurationInfo) const
1920 {
1921  std::stringstream tempSS;
1922 
1923  // Show the correction components
1924  tempSS << "Correction components:\n";
1925  for (auto component : fOrderedComponentsToExecute) {
1926  tempSS << "\t" << component << "\n";
1927  }
1928  // Input objects
1929  tempSS << "\nInput objects:\n";
1933 
1934  if (includeYAMLConfigurationInfo == true) {
1935  tempSS << "\nUser Configuration:\n";
1936  PrintConfigurationString(tempSS, true);
1937  tempSS << "\n\nDefault Configuration:\n";
1938  PrintConfigurationString(tempSS);
1939  tempSS << "\n";
1940  }
1941 
1942  return tempSS.str();
1943 }
1944 
1951 std::ostream & AliEmcalCorrectionTask::Print(std::ostream & in) const {
1952  in << toString();
1953  return in;
1954 }
1955 
1963 std::ostream & operator<<(std::ostream & in, const AliEmcalCorrectionTask & myTask)
1964 {
1965  std::ostream & result = myTask.Print(in);
1966  return result;
1967 }
1968 
1976 {
1977  std::string temp(opt);
1978  bool includeYAMLConfig = false;
1979  if (temp == "YAML") {
1980  includeYAMLConfig = true;
1981  }
1982  Printf("%s", toString(includeYAMLConfig).c_str());
1983 }
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()
static const std::map< std::string, AliVCluster::VCluUserDefEnergy_t > fgkClusterEnergyTypeMap
Relates string to the cluster energy enumeration for YAML configuration.
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
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)
bool WriteConfigurationFile(std::string filename, bool userConfig=false) const
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)
AliEmcalCorrectionTask & operator=(AliEmcalCorrectionTask other)
YAML::Node fUserConfiguration
! User YAML Configuration
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.
friend void swap(AliEmcalCorrectionTask &first, AliEmcalCorrectionTask &second)
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
void PrintRequestedContainersInformation(InputObject_t inputObjectType, std::ostream &stream) 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)
static AliEmcalCorrectionTask * AddTaskEmcalCorrectionTask(TString suffix="")
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)
void SetupContainersFromInputNodes(InputObject_t inputObjectType, YAML::Node &userInputObjectNode, YAML::Node &defaultInputObjectNode, std::set< std::string > &requestedContainers)
void SetIncludePHOS(Bool_t b)
static std::string DetermineUseDefaultName(InputObject_t contType, bool esdMode, bool returnObjectType=false)
void SetupContainer(InputObject_t inputObjectType, std::string containerName, YAML::Node &userNode, YAML::Node &defaultNode)
Bool_t fNeedEmcalGeom
whether or not the task needs the emcal geometry
static const std::map< std::string, AliEmcalTrackSelection::ETrackFilterType_t > fgkTrackFilterTypeMap
Relates string to the track filter enumeration for YAML configuration.
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
ETrackFilterType_t
Pre-defined track filters.
AliParticleContainer * GetParticleContainer(Int_t i=0) const
void AdoptParticleContainer(AliParticleContainer *cont)
std::ostream & operator<<(std::ostream &in, const AliEmcalCorrectionTask &myTask)
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
Int_t GetRunNumber(TString)
Definition: PlotMuonQA.C:2235
void SetTrackFilterType(ETrackFilterType_t f)
std::string toString(bool includeYAMLConfigurationInfo=false) const
const char Option_t
Definition: External.C:48
YAML::Node fDefaultConfiguration
! Default YAML Configuration
void Print(Option_t *opt="") const
void SetupCellsInfo(std::string containerName, YAML::Node &userNode, YAML::Node &defaultNode)
Int_t fNVertCont
! Event vertex number of contributors
static AliEmcalCorrectionComponent * createInstance(std::string const &s)
Creates an instance of an object based on the name if the name is registered in the map...
void SetName(std::string name)
Set the name of the cells object (NOT the same as the branch!)
bool Bool_t
Definition: External.C:53
Int_t fCentBin
! Event centrality bin
Double_t fMinCent
min centrality for event selection
AliClusterContainer * AddClusterContainer(const char *n)
std::vector< AliEmcalCorrectionCellContainer * > fCellCollArray
Cells collection array.
AliParticleContainer * AddParticleContainer(const char *n)
Container structure for EMCAL clusters.
Container for MC-true particles within the EMCAL framework.
std::string fUserConfigurationString
Store the user YAML configuration as a string so that it can be streamed.
void GetPropertyNamesFromNode(const std::string &componentName, const YAML::Node &node, std::set< std::string > &propertyNames, const bool nodeRequired)
std::ostream & PrintConfigurationString(std::ostream &in, bool userConfig=false) const
InputObject_t
Type of input object to be created
TList * OpenFile(const char *fname)
Definition: DrawAnaELoss.C:65
void SetClusHadCorrEnergyCut(Double_t cut)
void swap(AliEmcalCorrectionTask &first, AliEmcalCorrectionTask &second)
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)