AliPhysics  07fddbf (07fddbf)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliEmcalCorrectionTask.cxx
Go to the documentation of this file.
1 // AliEmcalCorrectionTask
2 //
3 // Runs the cell and cluster level corrections for the EMCal
4 //
5 
8 
9 #include <vector>
10 #include <set>
11 #include <fstream>
12 #include <sstream>
13 #include <iostream>
14 
15 #include <TChain.h>
16 #include <TSystem.h>
17 #include <TGrid.h>
18 #include <TFile.h>
19 
20 #include "AliVEventHandler.h"
21 #include "AliEMCALGeometry.h"
22 #include "AliVCaloCells.h"
23 #include "AliVCluster.h"
24 #include "AliLog.h"
25 #include "AliMultSelection.h"
26 #include "AliCentrality.h"
27 #include "AliESDEvent.h"
28 #include "AliAnalysisManager.h"
29 
33 
37 
43  AliAnalysisTaskSE("AliEmcalCorrectionTask"),
44  fSuffix(""),
45  fUserConfiguration(),
46  fUserConfigurationFilename(""),
47  fUserConfigurationString(""),
48  fDefaultConfiguration(),
49  fDefaultConfigurationFilename(""),
50  fDefaultConfigurationString(""),
51  fCorrectionComponents(),
52  fIsEsd(false),
53  fForceBeamType(kNA),
54  fRunPeriod("noSetRunPeriod"),
55  fConfigurationInitialized(false),
56  fOrderedComponentsToExecute(),
57  fEventInitialized(false),
58  fCent(0),
59  fCentBin(-1),
60  fMinCent(-999),
61  fMaxCent(-999),
62  fNcentBins(4),
63  fCentEst("V0M"),
64  fUseNewCentralityEstimation(kFALSE),
65  fNVertCont(0),
66  fBeamType(kNA),
67  fNeedEmcalGeom(kTRUE),
68  fGeom(0),
69  fParticleCollArray(),
70  fClusterCollArray(),
71  fCellCollArray(),
72  fOutput(0)
73 {
74  // Default constructor
75  AliDebug(3, Form("%s", __PRETTY_FUNCTION__));
76 
77  fVertex[0] = 0;
78  fVertex[1] = 0;
79  fVertex[2] = 0;
80 
81  fParticleCollArray.SetOwner(kTRUE);
82  fClusterCollArray.SetOwner(kTRUE);
83 }
84 
95  AliAnalysisTaskSE(name),
96  fSuffix(""),
97  fUserConfiguration(),
98  fUserConfigurationFilename(""),
99  fUserConfigurationString(""),
100  fDefaultConfiguration(),
101  fDefaultConfigurationFilename(""),
102  fDefaultConfigurationString(""),
103  fCorrectionComponents(),
104  fIsEsd(false),
105  fForceBeamType(kNA),
106  fRunPeriod("noSetRunPeriod"),
107  fConfigurationInitialized(false),
108  fOrderedComponentsToExecute(),
109  fEventInitialized(false),
110  fCent(0),
111  fCentBin(-1),
112  fMinCent(-999),
113  fMaxCent(-999),
114  fNcentBins(4),
115  fCentEst("V0M"),
116  fUseNewCentralityEstimation(kFALSE),
117  fNVertCont(0),
118  fBeamType(kNA),
119  fNeedEmcalGeom(kTRUE),
120  fGeom(0),
121  fParticleCollArray(),
122  fClusterCollArray(),
123  fCellCollArray(),
124  fOutput(0)
125 {
126  // Standard constructor
127  AliDebug(3, Form("%s", __PRETTY_FUNCTION__));
128 
129  fVertex[0] = 0;
130  fVertex[1] = 0;
131  fVertex[2] = 0;
132 
133  fParticleCollArray.SetOwner(kTRUE);
134  fClusterCollArray.SetOwner(kTRUE);
135 
136  DefineInput(0, TChain::Class());
137  DefineOutput(1, TList::Class());
138 }
139 
145 {
146  // Destructor
147 }
148 
158 {
159  // Determine file type
160  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
161  if (mgr) {
162  AliVEventHandler *evhand = mgr->GetInputEventHandler();
163  if (evhand) {
164  if (evhand->InheritsFrom("AliESDInputHandler")) {
165  fIsEsd = true;
166  }
167  else {
168  fIsEsd = false;
169  }
170  }
171  else {
172  AliError("Event handler not found!");
173  }
174  }
175  else {
176  AliError("Analysis manager not found!");
177  }
178 
179  // Determine the suffix of the correction task
180  std::string tempName = GetName();
181  std::size_t foundSuffix = tempName.find("_");
182  if (foundSuffix != std::string::npos) {
183  // +1 to skip "_"
184  fSuffix = tempName.substr(foundSuffix + 1).c_str();
185  }
186 
187  // Initialize YAML configuration
189  // Check that the configuration is initialized
190  if (fConfigurationInitialized != true)
191  {
192  AliFatal("YAML configuration must be initialized before running (ie. the AddTask, run macro or wagon)!");
193  }
194 
195  // Determine component execution order
197 
198  // Check for user defined settings that are not in the default file
200 
201  // Setup input objects
202  // Setup Cells
203  // Cannot do this entirely yet because we need input objects
206  // Create cluster input objects
209  // Create track input objects
212 
213  // Initialize components
215 }
216 
226 {
227  // Determine file path
229  {
230  // Use the default if nothing is set
231  fDefaultConfigurationFilename = "$ALICE_PHYSICS/PWG/EMCAL/config/AliEmcalCorrectionConfiguration.yaml";
232  }
233 
234  // Setup the YAML files
235  // Default
237 
239  {
240  AliInfo(TString::Format("Using default EMCal corrections configuration located at %s", fDefaultConfigurationFilename.c_str()));
241 
243  // Check for valid file
244  if (fDefaultConfiguration.IsNull() == true)
245  {
246  AliFatal(TString::Format("Could not open the default configuration file \"%s\"!", fDefaultConfigurationFilename.c_str()));
247  }
248  }
249  else
250  {
251  AliFatal(TString::Format("Default file located at \"%s\" does not exist!", fDefaultConfigurationFilename.c_str()));
252  }
253 
254  // User
256 
258  {
259  AliInfo(TString::Format("Using user EMCal corrections configuration located at %s", fUserConfigurationFilename.c_str()));
260 
262  }
263  else
264  {
265  AliInfo(TString::Format("User file at \"%s\" does not exist! All settings will be from the default file!", fUserConfigurationFilename.c_str()));
266  }
267 
268  // Ensure that there is a run period
269  if (fRunPeriod == "noSetRunPeriod")
270  {
271  AliFatal("Must pass a run period to the correction task!");
272  }
273  // Check the user provided run period
274  TString userRunPeriod = "kNoUserFile";
275  // Test if the period exists in the user file
276  if (fUserConfiguration.IsNull() != true)
277  {
278  if (fUserConfiguration["period"])
279  {
280  userRunPeriod = fUserConfiguration["period"].as<std::string>();
281  }
282  else
283  {
284  AliFatal("User must specify a period. Leave the period as an empty string to apply to all periods.");
285  }
286  }
287 
288  AliDebug(3, TString::Format("userRunPeriod: %s", userRunPeriod.Data()));
289  // Normalize the user run period to lower case to ensure that we don't miss any matches
290  userRunPeriod.ToLower();
291  if (userRunPeriod != "knouserfile" && userRunPeriod != fRunPeriod)
292  {
293  AliFatal(TString::Format("User run period \"%s\" does not match the run period of \"%s\" passed to the correction task!", userRunPeriod.Data(), fRunPeriod.Data()));
294  }
295 
296  // "" means the user wants their settings to apply to all periods
297  // Ensure that the user is aware!
298  if (userRunPeriod == "")
299  {
300  AliWarning("User run period is an empty string. Settings apply to all run periods!");
301  }
302 
303  // Save configuration into strings so that they can be streamed
304  // Need the stringstream because YAML implements streamers
305  std::stringstream tempConfiguration;
306  tempConfiguration << fUserConfiguration;
307  fUserConfigurationString = tempConfiguration.str();
308  tempConfiguration.str("");
309  tempConfiguration << fDefaultConfiguration;
310  fDefaultConfigurationString = tempConfiguration.str();
311 
312  //AliInfo(TString::Format("User configuration: %s", fUserConfigurationString.c_str()));
313  //AliInfo(TString::Format("Default configuration: %s", fDefaultConfigurationString.c_str()));
314 
315  // Note that it is initialized properly so that the analysis can proceed
317 }
318 
329 void AliEmcalCorrectionTask::DetermineComponentsToExecute(std::vector <std::string> & correctionComponents)
330 {
331  std::vector <std::string> executionOrder;
332  // executionOrder determines the order of tasks to execute, but it doesn't name the particular tasks
334 
335  // Possible components to create from both the user and default configurations
336  // Use set so that the possible components are not repeated
337  std::set <std::string> possibleComponents;
338  for (auto node : fUserConfiguration) {
339  possibleComponents.insert(node.first.as<std::string>());
340  }
341  for (auto node : fDefaultConfiguration) {
342  possibleComponents.insert(node.first.as<std::string>());
343  }
344 
345  // Determine the correction names associated with the correction task
346  std::string expectedComponentName = "";
347  bool foundSuffixComponent = false;
348  bool foundComponent = false;
349  bool componentEnabled = true;
350 
351  // Execution order determines the order that corrections should be added to our execution list
352  for (auto & execName : executionOrder)
353  {
354  // Construct the expected component name with the suffix
355  expectedComponentName = TString::Format("%s_%s", execName.c_str(), fSuffix.c_str()).Data();
356  foundComponent = false;
357  componentEnabled = false;
358 
359  foundComponent = CheckPossibleNamesForComponentName(expectedComponentName, possibleComponents);
360  if (foundComponent)
361  {
362  // Check if the component is enabled
363  AliEmcalCorrectionComponent::GetProperty("enabled", componentEnabled, fUserConfiguration, fDefaultConfiguration, true, expectedComponentName);
364  // If enabled, then store the name so that it can be executed
365  if (componentEnabled == true) {
366  foundSuffixComponent = true;
367  correctionComponents.push_back(expectedComponentName);
368  }
369  else {
370  AliInfo(TString::Format("Component %s is disabled and will not be run!", expectedComponentName.c_str()));
371  }
372 
373  continue;
374  }
375  else
376  {
377  // Look for the normal component
378  expectedComponentName = execName;
379  foundComponent = CheckPossibleNamesForComponentName(expectedComponentName, possibleComponents);
380  // Check if it is enabled
381  AliEmcalCorrectionComponent::GetProperty("enabled", componentEnabled, fUserConfiguration, fDefaultConfiguration, true, expectedComponentName);
382 
383  if (componentEnabled == true) {
384  if (foundSuffixComponent == true) {
385  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()));
386  }
387  else {
388  // Take the normal component and store it to be executed
389  correctionComponents.push_back(expectedComponentName);
390  }
391  }
392  else {
393  AliInfo(TString::Format("Component %s is disabled and will not be run!", expectedComponentName.c_str()));
394  }
395  }
396  }
397 
398  // Need to append "AliEmcalCorrection" to allow the tasks to be found!
399  AliDebug(2, "Found EMCal Correction Components: ");
400  for (auto & component : correctionComponents)
401  {
402  component = "AliEmcalCorrection" + component;
403  AliDebug(2, TString::Format("%s", component.c_str()) );
404  }
405 }
406 
416 {
417  // Names of properties for a particular component in the user and default configurations
418  std::set <std::string> userPropertyNames;
419  std::set <std::string> defaultPropertyNames;
420  // Notes whether a match was found between user and default properties
421  bool foundMatch = false;
422  std::string tempComponentName = "";
423 
424  // Loop over all components
425  for (const auto componentName : fOrderedComponentsToExecute)
426  {
427  // Reset for each loop
428  userPropertyNames.clear();
429  defaultPropertyNames.clear();
430  // We need to remove "AliEmcalCorrection" so that the correction will be found in the configuration
431  // "AliEmcalCorrection" is 18 characters
432  tempComponentName = componentName.substr(componentName.find("AliEmcalCorrection")+18);
433 
434  AliDebugStream(2) << "Checking component " << componentName << " for unmatched user settings" << std::endl;
435 
436  // Get the user property names
437  GetPropertyNamesFromNode(tempComponentName, fUserConfiguration, userPropertyNames, false);
438 
439  // Get the same from default
440  // Not required here because the default configuration may not have the specialized component
441  GetPropertyNamesFromNode(tempComponentName, fDefaultConfiguration, defaultPropertyNames, false);
442 
443  // We need to check the base correction as well to fill out the options
444  if (tempComponentName.find("_") != std::string::npos) {
445  // Get the base user component
446  GetPropertyNamesFromNode(tempComponentName.substr(0, tempComponentName.find("_")), fUserConfiguration, userPropertyNames, false);
447 
448  // Required here because the default must have the base component!
449  GetPropertyNamesFromNode(tempComponentName.substr(0, tempComponentName.find("_")), fDefaultConfiguration, defaultPropertyNames, true);
450  }
451 
452  // Check each property defined in the user file for a match to the properties in the default file
453  for (auto userPropertyName : userPropertyNames)
454  {
455  AliDebugStream(2) << "Checking property " << userPropertyName << std::endl;
456  foundMatch = false;
457  for (auto defaultPropertyName : defaultPropertyNames)
458  {
459  if (userPropertyName == defaultPropertyName) {
460  AliDebugStream(2) << "Found match of " << userPropertyName << " with " << defaultPropertyName << std::endl;
461  foundMatch = true;
462  }
463  }
464  if (foundMatch == false) {
465  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()));
466  }
467  }
468  }
469 }
470 
478 {
479  // Iterate over the ordered components list and create the components
480  AliEmcalCorrectionComponent * component = 0;
481  for (auto componentName : fOrderedComponentsToExecute)
482  {
483  std::string noPrefixComponentName = componentName.substr(0, componentName.find("_" + fSuffix));
484  component = AliEmcalCorrectionComponentFactory::createInstance(noPrefixComponentName);
485  if (!component)
486  {
487  AliFatal(TString::Format("Failed to create requested component %s!", componentName.c_str()));
488  }
489 
490  // For setting names of tasks to differentiate between tasks of the same class
491  component->SetName(componentName.c_str());
492  component->SetTitle(componentName.c_str());
493 
494  // Initialize the YAML configurations in each component
497 
498  // configure needed fields for components to properly initialize
499  component->SetIsESD(fIsEsd);
500 
501  // Add the require containers to the component
502  // Cells must be set during UserExec() because we need to add them as a pointer
504  AddContainersToComponent(component, kTrack);
505 
506  // Initialize each component
507  component->Initialize();
508 
509  if (component)
510  {
511  AliInfo(TString::Format("Successfully added correction task: %s", componentName.c_str()));
512  fCorrectionComponents.push_back(component);
513  }
514  }
515 }
516 
532 {
533  // Get container node
534  std::string inputObjectName = GetInputFieldNameFromInputObjectType(inputObjectType);
535 
536  // Get the user and default input nodes for the object type
537  YAML::Node userInputObjectNode;
538  YAML::Node defaultInputObjectNode;
539  GetNodeForInputObjects(userInputObjectNode, fUserConfiguration, inputObjectName, false);
540  GetNodeForInputObjects(defaultInputObjectNode, fDefaultConfiguration, inputObjectName, true);
541 
542  AliDebugStream(3) << "userInputObjectNode: " << userInputObjectNode << std::endl;
543  AliDebugStream(3) << "defaultInputObjectNode: " << defaultInputObjectNode << std::endl;
544 
545  // Determine which containers we need based on which are requested by the enabled correction tasks
546  std::set <std::string> requestedContainers;
547  std::vector <std::string> componentRequest;
548  for ( const auto & componentName : fOrderedComponentsToExecute )
549  {
550  componentRequest.clear();
551  // Not required because not all components will have all kinds of containers
552  // "AliEmcalCorrection" is 18 characters
553  AliEmcalCorrectionComponent::GetProperty(inputObjectName + "Names", componentRequest, fUserConfiguration, fDefaultConfiguration, false, componentName.substr(componentName.find("AliEmcalCorrection")+18));
554  for ( auto & req : componentRequest )
555  {
556  AliDebugStream(3) << "Component " << componentName << " requested container name " << req << std::endl;
557  requestedContainers.insert(req);
558  }
559  }
560 
561  AliDebugStream(2) << inputObjectName << " Containers requested by components: " << std::endl;
562  for (auto & str : requestedContainers) {
563  AliDebugStream(2) << "\t" << str << std::endl;;
564  }
565 
566  // Create all requested containers
567  AliDebug(2, TString::Format("Setting up requested containers!"));
568  SetupContainersFromInputNodes(inputObjectType, userInputObjectNode, defaultInputObjectNode, requestedContainers);
569 }
570 
579 {
580  std::string inputObjectName = GetInputFieldNameFromInputObjectType(inputObjectType);
581  // Need to be of the form "clusterContainersNames"
582  inputObjectName = inputObjectName + "Names";
583 
584  std::vector <std::string> inputObjects;
585  // Not required, because not all components need Clusters or Tracks
586  AliEmcalCorrectionComponent::GetProperty(inputObjectName.c_str(), inputObjects, fUserConfiguration, fDefaultConfiguration, false, component->GetName());
587 
588  //AliDebugStream(4) << "inputObjects.size(): " << inputObjects.size() << std::endl;
589 
590  // If it is not found, then there will be nothing to iterate over, so we don't need to explicitly check the return value
591  for (auto const & str : inputObjects)
592  {
593  // TODO: Generalize to arrays for clusters and tracks...
594  // 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()!
595  if (inputObjectType == kCluster)
596  {
597  AliEmcalContainer * cont = GetClusterContainer(str.c_str());
598  AliDebugStream(2) << "Adding cluster container " << str << " of array " << cont->GetArrayName() << " to component " << component->GetName() << std::endl;
599  component->SetClusterContainer(GetClusterContainer(str.c_str()));
600  }
601  else if (inputObjectType == kTrack)
602  {
603  AliEmcalContainer * cont = GetParticleContainer(str.c_str());
604  AliDebugStream(2) << "Adding particle container " << str << " of array " << cont->GetArrayName() << " to component " << component->GetName() << std::endl;
605  component->SetParticleContainer(GetParticleContainer(str.c_str()));
606  }
607  else if (inputObjectType == kCaloCells)
608  {
609  // NOTE: This operates different than the others. This should be executed during run time rather than during initialization!
610  if (inputObjects.size() > 1) {
611  AliFatal(TString::Format("Component %s requested more than one cell branch, but this is not supported! Check the configuration!", component->GetName()));
612  }
613 
614  // If we've made it here, this must be at least one entry
615  AliDebugStream(2) << "Adding calo cells " << GetCellContainer(str)->GetName() << " of branch name " << GetCellContainer(str)->GetBranchName() << "to component " << component->GetName() << std::endl;
616  component->SetCaloCells(GetCellContainer(str)->GetCells());
617  AliDebugStream(3) << "component GetNumberOfCells: " << component->GetCaloCells()->GetNumberOfCells() << std::endl;
618  }
619  }
620 }
621 
630 void AliEmcalCorrectionTask::SetupContainersFromInputNodes(InputObject_t inputObjectType, YAML::Node & userInputObjectNode, YAML::Node & defaultInputObjectNode, std::set <std::string> & requestedContainers)
631 {
632  // Our node contains all of the objects that we will want to create.
633  for(auto & containerName : requestedContainers)
634  {
635  // The section is the container name
636  //std::string containerName = it->first.as<std::string>();
637  // Skip if the particle or cluster container already exists
638  if (GetParticleContainer(containerName.c_str()) || GetClusterContainer(containerName.c_str())) {
639  continue;
640  }
641 
642  AliDebug(2, TString::Format("Processing container %s of inputType %d", containerName.c_str(), inputObjectType));
643  if (inputObjectType == kCluster || inputObjectType == kTrack) {
644  SetupContainer(inputObjectType, containerName, userInputObjectNode, defaultInputObjectNode);
645  }
646  else if (inputObjectType == kCaloCells) {
647  SetupCellsInfo(containerName, userInputObjectNode, defaultInputObjectNode);
648  }
649  }
650 }
651 
662 void AliEmcalCorrectionTask::SetupCellsInfo(std::string containerName, YAML::Node & userNode, YAML::Node & defaultNode)
663 {
664  // Define cell info
666 
667  AliDebugStream(2) << "User: " << std::endl << userNode << std::endl << "default: " << std::endl << defaultNode << std::endl;
668 
669  // Set properties
670  // Cells (object) name
671  cellObj->SetName(containerName);
672  // Branch name
673  std::string tempString = "";
674  AliEmcalCorrectionComponent::GetProperty("branchName", tempString, userNode, defaultNode, true, containerName);
675  if (tempString == "usedefault") {
677  }
678  cellObj->SetBranchName(tempString);
679 
680  // IsEmbedding
681  bool tempBool = false;
682  AliEmcalCorrectionComponent::GetProperty("embedded", tempString, userNode, defaultNode, false, containerName);
683  cellObj->SetIsEmbedding(tempBool);
684 
685  // Add to the array to keep track of it
686  fCellCollArray.push_back(cellObj);
687 }
688 
706 void AliEmcalCorrectionTask::SetupContainer(InputObject_t inputObjectType, std::string containerName, YAML::Node & userNode, YAML::Node & defaultNode)
707 {
708  // Create container
709  AliDebugStream(2) << "Adding container" << std::endl;
710  AliEmcalContainer * cont = AddContainer(inputObjectType, containerName, userNode, defaultNode);
711  AliDebugStream(2) << "Added container" << std::endl;
712 
713  // Set the container properties
714  //
715  // TODO: Consider if this can be converted to a map to function pointers. There are a number of details
716  // which can make it a bit complicated. Those details include inheritance, pointing to member
717  // functions, etc. It should all be possible, but may not be worth all of the extra work and code.
718  // Example ccode:
719  // SetValueInContainer("minPt", &cont::SetMinPt, tempDouble, userNode, defaultNode);
720  // SetValueInContainer("minE", &cont::SetMinE, tempDouble, userNode, defaultNode);
721 
722  // Temporary variables to store requested properties
723  std::string tempString = "";
724  Double_t tempDouble = 0;
725  bool tempBool = false;
726 
727  // AliEmcalContainer properties
728  // Min Pt
729  bool result = AliEmcalCorrectionComponent::GetProperty("minPt", tempDouble, userNode, defaultNode, false, containerName);
730  if (result) {
731  AliDebugStream(2) << cont->GetName() << ": Setting minPt of " << tempDouble << std::endl;
732  cont->SetMinPt(tempDouble);
733  }
734  // Min E
735  result = AliEmcalCorrectionComponent::GetProperty("minE", tempDouble, userNode, defaultNode, false, containerName);
736  if (result) {
737  AliDebugStream(2) << cont->GetName() << ": Setting minE of " << tempDouble << std::endl;
738  cont->SetMinE(tempDouble);
739  }
740  // Eta min, max
741  result = AliEmcalCorrectionComponent::GetProperty("minEta", tempDouble, userNode, defaultNode, false, containerName);
742  if (result) {
743  // Only continue checking if the min is there, since we must set both together
744  Double_t tempDouble2 = 0;
745  result = AliEmcalCorrectionComponent::GetProperty("maxEta", tempDouble, userNode, defaultNode, false, containerName);
746  if (result) {
747  AliDebugStream(2) << cont->GetName() << ": Setting eta limits of " << tempDouble << " to " << tempDouble2 << std::endl;
748  cont->SetEtaLimits(tempDouble, tempDouble2);
749  }
750  }
751  // Phi min, max
752  result = AliEmcalCorrectionComponent::GetProperty("minPhi", tempDouble, userNode, defaultNode, false, containerName);
753  if (result) {
754  // Only continue checking if the min is there, since we must set both together
755  Double_t tempDouble2 = 0;
756  result = AliEmcalCorrectionComponent::GetProperty("maxPhi", tempDouble, userNode, defaultNode, false, containerName);
757  if (result) {
758  AliDebugStream(2) << cont->GetName() << ": Setting phi limits of " << tempDouble << " to " << tempDouble2 << std::endl;
759  cont->SetPhiLimits(tempDouble, tempDouble2);
760  }
761  }
762  // Embedded
763  // TODO: Enable embedded when that branch is committed!
764  /*result = AliEmcalCorrectionComponent::GetProperty("IsEmbedded", tempBool, userNode, defaultNode, false, containerName);
765  if (result) {
766  AliDebugStream(2) << cont->GetName() << ": Setting embedding to " << (tempBool ? "enabled" : "disabled") << std::endl;
767  cont->SetIsEmbedding(tempBool);
768  }*/
769 
770  // Cluster specific properties
771  AliClusterContainer * clusterContainer = dynamic_cast<AliClusterContainer *>(cont);
772  if (clusterContainer) {
773  // Default energy
774  // Probably not needed for the corrections
775  /*result = AliEmcalCorrectionComponent::GetProperty("defaultClusterEnergy", tempString, userNode, defaultNode, false, containerName);
776  if (result) {
777  // Need to get the enumeration
778  AliVCluster::VCluUserDefEnergy_t clusterEnergyType = clusterEnergyTypeMap.at(tempString);
779  AliDebugStream(2) << clusterContainer->GetName() << ": Setting cluster energy type to " << clusterEnergyType << std::endl;
780  clusterContainer->SetDefaultClusterEnergy(clusterEnergyType);
781  }*/
782 
783  // NonLinCorrEnergyCut
784  result = AliEmcalCorrectionComponent::GetProperty("clusNonLinCorrEnergyCut", tempDouble, userNode, defaultNode, false, containerName);
785  if (result) {
786  AliDebugStream(2) << clusterContainer->GetName() << ": Setting clusNonLinCorrEnergyCut of " << tempDouble << std::endl;
787  clusterContainer->SetClusNonLinCorrEnergyCut(tempDouble);
788  }
789 
790  // HadCorrEnergyCut
791  result = AliEmcalCorrectionComponent::GetProperty("clusHadCorrEnergyCut", tempDouble, userNode, defaultNode, false, containerName);
792  if (result) {
793  AliDebugStream(2) << clusterContainer->GetName() << ": Setting clusHadCorrEnergyCut of " << tempDouble << std::endl;
794  clusterContainer->SetClusHadCorrEnergyCut(tempDouble);
795  }
796 
797  // SetIncludePHOS
798  result = AliEmcalCorrectionComponent::GetProperty("includePHOS", tempBool, userNode, defaultNode, false, containerName);
799  if (result) {
800  AliDebugStream(2) << clusterContainer->GetName() << ": Setting Include PHOS to " << (tempBool ? "enabled" : "disabled") << std::endl;
801  clusterContainer->SetIncludePHOS(tempBool);
802  }
803  }
804 
805  // Track specific
806  AliTrackContainer * trackContainer = dynamic_cast<AliTrackContainer *>(cont);
807  if (trackContainer) {
808  // Track selection
809  // AOD Filter bits as a sequence
810  std::vector <UInt_t> filterBitsVector;
811  result = AliEmcalCorrectionComponent::GetProperty("aodFilterBits", filterBitsVector, userNode, defaultNode, false, containerName);
812  if (result){
813  UInt_t filterBits = 0;
814  for (int filterBit : filterBitsVector) {
815  filterBits += filterBit;
816  }
817  AliDebugStream(2) << trackContainer->GetName() << ": Setting filterBits of " << filterBits << std::endl;
818  trackContainer->SetAODFilterBits(filterBits);
819  }
820 
821  // SetTrackFilterType enum
822  result = AliEmcalCorrectionComponent::GetProperty("trackFilterType", tempString, userNode, defaultNode, false, containerName);
823  if (result) {
824  // Need to get the enumeration
825  AliEmcalTrackSelection::ETrackFilterType_t trackFilterType = trackFilterTypeMap.at(tempString);
826  AliDebugStream(2) << trackContainer->GetName() << ": Setting trackFilterType of " << trackFilterType << std::endl;
827  trackContainer->SetTrackFilterType(trackFilterType);
828  }
829 
830  // Track cuts period
831  result = AliEmcalCorrectionComponent::GetProperty("trackCutsPeriod", tempString, userNode, defaultNode, false, containerName);
832  if (result) {
833  // Need to get the enumeration
834  AliDebugStream(2) << trackContainer->GetName() << ": Setting track cuts period to " << tempString << std::endl;
835  trackContainer->SetTrackCutsPeriod(tempString.c_str());
836  }
837  }
838 }
839 
857 AliEmcalContainer * AliEmcalCorrectionTask::AddContainer(InputObject_t contType, std::string & containerName, YAML::Node & userNode, YAML::Node & defaultNode)
858 {
859  // Determine the type of branch to request
860  std::string containerBranch = "";
861  if (contType != kCluster && contType != kTrack){
862  AliFatal("Must specify type of container when requesting branch.");
863  }
864 
865  // Retrieve branch name
866  // YAML::Node() is just an empty node
867  AliDebugStream(2) << "User Node: " << userNode << std::endl;
868  AliDebugStream(2) << "Default Node: " << defaultNode << std::endl;
869  AliEmcalCorrectionComponent::GetProperty("branchName", containerBranch, userNode, defaultNode, true, containerName);
870  // Should be unnecessary, since the user can only do this if done explicitly.
871  /*if (containerBranch == "")
872  {
873  AliFatal(TString::Format("Request %i container, but the container branch is empty!", contType));
874  }*/
875 
876  // Determine proper name if using "usedefault" pattern
877  if (containerBranch == "usedefault") {
878  containerBranch = DetermineUseDefaultName(contType, fIsEsd);
879  }
880 
881  // Create containers and set them to the name of the component
882  AliEmcalContainer * cont = 0;
883  if (contType == kCluster)
884  {
885  cont = new AliClusterContainer(containerBranch.c_str());
886  AdoptClusterContainer(dynamic_cast<AliClusterContainer *>(cont));
887  }
888  else if (contType == kTrack)
889  {
890  if (containerBranch == "mcparticles") {
891  cont = new AliMCParticleContainer(containerBranch.c_str());
892  }
893  else {
894  cont = new AliTrackContainer(containerBranch.c_str());
895  }
896  AdoptParticleContainer(dynamic_cast<AliParticleContainer *>(cont));
897  }
898  cont->SetName(containerName.c_str());
899 
900  return cont;
901 }
902 
912 {
913  AliDebug(3, Form("%s", __PRETTY_FUNCTION__));
914 
915  // Check that the configuration is initialized
916  if (fConfigurationInitialized != true)
917  {
918  AliFatal("YAML configuration must be initialized before running (ie. the AddTask, run macro or wagon)!");
919  }
920 
921  // Show the configurations info this is available
922  AliDebugStream(4) << "User configuration string: " << fUserConfigurationString << std::endl;
923  AliDebugStream(4) << "User configuration: " << fUserConfiguration << std::endl;
924  AliDebugStream(4) << "Default configuration string: " << fDefaultConfigurationString << std::endl;
925  AliDebugStream(4) << "Default configuration: " << fDefaultConfiguration << std::endl;
926 
927  // YAML Objects cannot be streamed, so we need to reinitialize them here.
928  // They need reinitialize if they are null
929  if (fUserConfiguration.IsNull() == true && fUserConfigurationString != "")
930  {
931  AliInfo("Reinitializing user configuration from string. Expected if running on grid!");
933  }
934  if (fDefaultConfiguration.IsNull() == true)
935  {
936  AliInfo("Reinitializing default configuration from string. Expected if running on grid!");
938  }
939 
940  // Debug to check that the configuration has been (re)initiailzied has been completed correctly
941  AliDebugStream(4) << "(Re)initialized user configuration: " << fUserConfigurationString << std::endl;
942  AliDebugStream(4) << "(Re)initialized user configuration: " << fUserConfiguration << std::endl;
943  AliDebugStream(4) << "(Re)initialized default configuration: " << fDefaultConfigurationString << std::endl;
944  AliDebugStream(4) << "(Re)initialized default configuration: " << fDefaultConfiguration << std::endl;
945 
946  if (fForceBeamType == kpp)
947  fNcentBins = 1;
948 
949  // Allow for output files
950  OpenFile(1);
951  fOutput = new TList();
952  fOutput->SetOwner();
953 
955 
956  PostData(1, fOutput);
957 }
958 
966 {
967  // Run the initialization for all derived classes.
968  AliDebug(3, Form("%s", __PRETTY_FUNCTION__));
969  for (auto component : fCorrectionComponents)
970  {
971  // Set cent bins (usually used for hist creation)
972  // It cannot be set until now because it can be changed after initialization
973  // For instance, by SetForceBeamType()
974  component->SetNcentralityBins(fNcentBins);
975 
976  component->UserCreateOutputObjects();
977 
978  if (component->GetOutputList() != 0)
979  {
980  // Adds a list to the list -- this doesn't work for some unknown reason
981  //fOutput->Add(component->GetOutputList());
982 
983  // iterate through lists for each component, and fill in output
984  TList* t = new TList();
985  t->SetName(component->GetName());
986  fOutput->AddLast(t);
987  t = (TList*)fOutput->Last();
988  TIter next(component->GetOutputList());
989  while (TObject *obj = next()){
990  t->Add(obj);
991  }
992 
993  AliDebug(1, TString::Format("Added output list from task %s to output.", component->GetName()));
994  }
995  }
996 }
997 
1003 {
1004  AliDebug(3, Form("%s", __PRETTY_FUNCTION__));
1005 
1006  // Initialize the event if not intialized
1007  if (!fEventInitialized)
1008  ExecOnce();
1009 
1010  // Only continue if we are initialized successfully
1011  if (!fEventInitialized)
1012  return;
1013 
1014  // Get the objects for each event
1015  if (!RetrieveEventObjects())
1016  return;
1017 
1018  // TODO: Consider adding IsEventSelected()??
1019 
1020  // Call run for each correction
1021  if (!Run())
1022  return;
1023 }
1024 
1036 {
1037  if (!InputEvent()) {
1038  AliError("Could not retrieve event! Returning!");
1039  return;
1040  }
1041 
1042  if (fNeedEmcalGeom) {
1043  fGeom = AliEMCALGeometry::GetInstanceFromRunNumber(InputEvent()->GetRunNumber());
1044  if (!fGeom) {
1045  AliFatal("Can not get EMCal geometry instance. If you do not need the EMCal geometry, disable it by setting task->SetNeedEmcalGeometry(kFALSE).");
1046  return;
1047  }
1048  }
1049 
1050  // Load all requested track branches - each container knows name already
1051  for (Int_t i =0; i<fParticleCollArray.GetEntriesFast(); i++) {
1052  AliParticleContainer *cont = static_cast<AliParticleContainer*>(fParticleCollArray.At(i));
1054  cont->SetArray(InputEvent());
1055  }
1056 
1057  // Load all requested cluster branches - each container knows name already
1058  for (Int_t i =0; i<fClusterCollArray.GetEntriesFast(); i++) {
1059  AliClusterContainer *cont = static_cast<AliClusterContainer*>(fClusterCollArray.At(i));
1061  cont->SetArray(InputEvent());
1062  }
1063 
1064  // Determine the proper pointer for each cell object and save them to the cell contianer
1065  // At this point, they should all be created
1066  for (auto cellObj : fCellCollArray)
1067  {
1069  }
1070 
1071  fEventInitialized = kTRUE;
1072 
1074 }
1075 
1081 {
1082  // Run the initialization for all derived classes.
1083  AliDebug(3, Form("%s", __PRETTY_FUNCTION__));
1084  for (auto component : fCorrectionComponents)
1085  {
1086  // Setup geomertry
1087  component->SetEMCALGeometry(fGeom);
1088 
1089  // Add the requested cells to the component
1090  //AliDebugStream(3) << "Adding CaloCells" << std::endl;
1092  //AliDebugStream(3) << "Added CaloCells" << std::endl;
1093 
1094  // Component ExecOnce()
1095  component->ExecOnce();
1096  }
1097 }
1098 
1104 {
1105  fVertex[0] = 0;
1106  fVertex[1] = 0;
1107  fVertex[2] = 0;
1108  fNVertCont = 0;
1109 
1110  const AliVVertex *vert = InputEvent()->GetPrimaryVertex();
1111  if (vert) {
1112  vert->GetXYZ(fVertex);
1113  fNVertCont = vert->GetNContributors();
1114  }
1115 
1116  fBeamType = GetBeamType();
1117 
1118  if (fBeamType == kAA || fBeamType == kpA ) {
1120  AliMultSelection *MultSelection = static_cast<AliMultSelection*>(InputEvent()->FindListObject("MultSelection"));
1121  if (MultSelection) {
1122  fCent = MultSelection->GetMultiplicityPercentile(fCentEst.Data());
1123  }
1124  else {
1125  AliWarning("Could not retrieve centrality information! Assuming 99");
1126  }
1127  }
1128  else { // old centrality estimation < 2015
1129  AliCentrality *aliCent = InputEvent()->GetCentrality();
1130  if (aliCent) {
1131  fCent = aliCent->GetCentralityPercentile(fCentEst.Data());
1132  }
1133  else {
1134  AliWarning("Could not retrieve centrality information! Assuming 99");
1135  }
1136  }
1137 
1138  if (fNcentBins==4) {
1139  if (fCent >= 0 && fCent < 10) fCentBin = 0;
1140  else if (fCent >= 10 && fCent < 30) fCentBin = 1;
1141  else if (fCent >= 30 && fCent < 50) fCentBin = 2;
1142  else if (fCent >= 50 && fCent <= 100) fCentBin = 3;
1143  else {
1144  AliWarning(Form("Negative centrality: %f. Assuming 99", fCent));
1145  fCentBin = fNcentBins-1;
1146  }
1147  }
1148  else if (fNcentBins==5) { // for PbPb 2015
1149  if (fCent >= 0 && fCent < 10) fCentBin = 0;
1150  else if (fCent >= 10 && fCent < 30) fCentBin = 1;
1151  else if (fCent >= 30 && fCent < 50) fCentBin = 2;
1152  else if (fCent >= 50 && fCent <= 90) fCentBin = 3;
1153  else if (fCent > 90) {
1154  fCent = 99;
1155  fCentBin = 4;
1156  }
1157  else {
1158  AliWarning(Form("Negative centrality: %f. Assuming 99", fCent));
1159  fCentBin = fNcentBins-1;
1160  }
1161  }
1162  else {
1163  Double_t centWidth = (fMaxCent-fMinCent)/(Double_t)fNcentBins;
1164  if(centWidth>0.) {
1165  fCentBin = TMath::FloorNint(fCent/centWidth);
1166  }
1167  else {
1168  fCentBin = 0;
1169  }
1170  if (fCentBin>=fNcentBins) {
1171  AliWarning(Form("fCentBin too large: cent = %f fCentBin = %d. Assuming 99", fCent, fCentBin));
1172  fCentBin = fNcentBins-1;
1173  }
1174  }
1175  }
1176  else {
1177  fCent = 99;
1178  fCentBin = 0;
1179  }
1180 
1181  AliEmcalContainer* cont = 0;
1182 
1183  TIter nextPartColl(&fParticleCollArray);
1184  while ((cont = static_cast<AliEmcalContainer*>(nextPartColl()))) cont->NextEvent();
1185 
1186  TIter nextClusColl(&fClusterCollArray);
1187  while ((cont = static_cast<AliEmcalContainer*>(nextClusColl()))) cont->NextEvent();
1188 
1189  return kTRUE;
1190 }
1191 
1197 {
1198  // Run the initialization for all derived classes.
1199  AliDebug(3, Form("%s", __PRETTY_FUNCTION__));
1200  for (auto component : fCorrectionComponents)
1201  {
1202  component->SetEvent(InputEvent());
1203  component->SetMCEvent(MCEvent());
1204  component->SetCentralityBin(fCentBin);
1205  component->SetCentrality(fCent);
1206 
1207  component->Run();
1208  }
1209 
1210  PostData(1, fOutput);
1211 
1212  return kTRUE;
1213 }
1214 
1220 {
1221  // Run the initialization for all derived classes.
1222  AliDebug(3, Form("%s", __PRETTY_FUNCTION__));
1223  for (auto component : fCorrectionComponents)
1224  {
1225  component->UserNotify();
1226  }
1227 
1228  return kTRUE;
1229 }
1230 
1239 {
1240  bool returnValue = false;
1241  if (filename != "")
1242  {
1243  if (fConfigurationInitialized == true)
1244  {
1245  std::ofstream outFile(filename);
1246  std::string stringToWrite = userConfig ? fUserConfigurationString : fDefaultConfigurationString;
1247  if (stringToWrite == "") {
1248  AliWarning(TString::Format("%s configuration is empty!", userConfig ? "User" : "Default"));
1249  }
1250  outFile << stringToWrite;
1251  outFile.close();
1252 
1253  returnValue = true;
1254  }
1255  else
1256  {
1257  AliWarning(TString::Format("Configuration not properly initialized! Cannot print %s configuration!", userConfig ? "user" : "default"));
1258  }
1259 
1260  }
1261  else
1262  {
1263  AliWarning("Please pass a valid filename instead of empty quotes!");
1264  }
1265  return returnValue;
1266 }
1267 
1283 std::string AliEmcalCorrectionTask::DetermineUseDefaultName(InputObject_t objType, bool esdMode, bool returnObjectType)
1284 {
1285  std::string returnValue = "";
1286  if (objType == kCluster) {
1287  if (esdMode == true) {
1288  if (returnObjectType == true) {
1289  returnValue = "AliESDCaloCluster";
1290  }
1291  else {
1292  returnValue = "CaloClusters";
1293  }
1294  }
1295  else {
1296  if (returnObjectType == true) {
1297  returnValue = "AliAODCaloCluster";
1298  }
1299  else {
1300  returnValue = "caloClusters";
1301  }
1302  }
1303  }
1304  else if (objType == kTrack) {
1305  if (esdMode == true) {
1306  if (returnObjectType == true) {
1307  returnValue = "AliESDtrack";
1308  }
1309  else {
1310  returnValue = "Tracks";
1311  }
1312  }
1313  else {
1314  if (returnObjectType == true) {
1315  returnValue = "AliAODTrack";
1316  }
1317  else {
1318  returnValue = "tracks";
1319  }
1320  }
1321  }
1322  else if (objType == kCaloCells) {
1323  if (esdMode == true) {
1324  if (returnObjectType == true) {
1325  returnValue = "AliESDCaloCells";
1326  }
1327  else {
1328  returnValue = "EMCALCells";
1329  }
1330  }
1331  else {
1332  if (returnObjectType == true) {
1333  returnValue = "AliAODCaloCells";
1334  }
1335  else {
1336  returnValue = "emcalCells";
1337  }
1338  }
1339  }
1340  else {
1341  // Default to empty if we are given an unrecognized type with "usedefault"
1342  returnValue = "";
1343  }
1344 
1345  return returnValue;
1346 }
1347 
1357 AliVEvent * AliEmcalCorrectionTask::GetEvent(AliVEvent * inputEvent, bool isEmbedding)
1358 {
1359  AliVEvent * event = 0;
1360  if (isEmbedding) {
1361  // TODO: Enable embedded when that branch is committed!
1362  /*const AliAnalysisTaskEmcalEmbeddingHelper* embedding = AliAnalysisTaskEmcalEmbeddingHelper::GetInstance();
1363  if (!embedding) return 0;
1364 
1365  event = embedding->GetExternalEvent();*/
1366  }
1367  else {
1368  event = inputEvent;
1369  }
1370 
1371  return event;
1372 }
1373 
1382 inline bool AliEmcalCorrectionTask::DoesFileExist(const std::string & filename)
1383 {
1384  std::ifstream inFile(filename);
1385  return inFile.good();
1386 }
1387 
1397 {
1398  if (filename != "")
1399  {
1400  // Handle if in AliPhysics and includes $ALICE_PHYSICS
1401  filename = gSystem->ExpandPathName(filename.c_str());
1402 
1403  // Handle grid
1404  if(filename.find("alien://") != std::string::npos)
1405  {
1406  AliDebug(2, TString::Format("Opening file \"%s\" on the grid!", filename.c_str()));
1407  // Initialize alien connection if needed
1408  if (!gGrid) {
1409  TGrid::Connect("alien://");
1410  }
1411 
1412  // Determine the local filename and copy file to local directory
1413  std::string localFilename = gSystem->BaseName(filename.c_str());
1414  // Ensures that the default and user files do not conflict if both are taken from the grid and have the same filename
1415  if (userFile == true) {
1416  localFilename = "user" + localFilename;
1417  }
1418  TFile::Cp(filename.c_str(), localFilename.c_str());
1419 
1420  // yaml-cpp should only open the local file
1421  filename = localFilename;
1422  }
1423  }
1424 }
1425 
1433 {
1434  AliDebugStream(2) << "Retrieving cells object " << cellContainer->GetName() << std::endl;
1435  // Check for embedding and return object
1436  AliVEvent * event = GetEvent(InputEvent(), cellContainer->GetIsEmbedding());
1437 
1438  cellContainer->SetCells(dynamic_cast<AliVCaloCells *>(event->FindListObject(cellContainer->GetBranchName().c_str())));
1439 }
1440 
1450 void AliEmcalCorrectionTask::CheckForContainerArray(AliEmcalContainer * cont, InputObject_t objectType)
1451 {
1452  // TODO: Enable embedded when that branch is committed!
1453  //AliVEvent * event = GetEvent(InputEvent(), cont->GetIsEmbedding());
1454  AliVEvent * event = GetEvent(InputEvent());
1455 
1456  TClonesArray * array = dynamic_cast<TClonesArray *>(event->FindListObject(cont->GetArrayName()));
1457  if (!array) {
1458  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()));
1459  array = new TClonesArray(DetermineUseDefaultName(objectType, fIsEsd, true).c_str());
1460  array->SetName(cont->GetArrayName());
1461  event->AddObject(array);
1462  }
1463 }
1464 
1473 {
1474  // Get container node
1475  std::string inputObjectName = "";
1476  if (inputObjectType == kCluster) {
1477  inputObjectName = "clusterContainers";
1478  }
1479  else if (inputObjectType == kTrack) {
1480  inputObjectName = "trackContainers";
1481  }
1482  else if (inputObjectType == kCaloCells) {
1483  inputObjectName = "cells";
1484  }
1485  else {
1486  AliFatal(TString::Format("Unrecognized input object type %d", inputObjectType));
1487  }
1488 
1489  return inputObjectName;
1490 }
1491 
1503 bool AliEmcalCorrectionTask::CheckPossibleNamesForComponentName(std::string & name, std::set <std::string> & possibleComponents)
1504 {
1505  bool foundComponent = false;
1506  for (auto & possibleComponent : possibleComponents)
1507  {
1508  if (possibleComponent == name) {
1509  foundComponent = true;
1510  break;
1511  }
1512  }
1513 
1514  return foundComponent;
1515 }
1516 
1524 {
1525  if (fForceBeamType != kNA)
1526  return fForceBeamType;
1527 
1528  AliESDEvent *esd = dynamic_cast<AliESDEvent*>(InputEvent());
1529  if (esd) {
1530  const AliESDRun *run = esd->GetESDRun();
1531  TString beamType = run->GetBeamType();
1532  if (beamType == "p-p")
1533  return kpp;
1534  else if (beamType == "A-A")
1535  return kAA;
1536  else if (beamType == "p-A")
1537  return kpA;
1538  else
1539  return kNA;
1540  } else {
1541  Int_t runNumber = InputEvent()->GetRunNumber();
1542  if ((runNumber >= 136851 && runNumber <= 139517) || // LHC10h
1543  (runNumber >= 166529 && runNumber <= 170593)) { // LHC11h
1544  return kAA;
1545  } else if ((runNumber>=188365 && runNumber <= 188366) || // LHC12g
1546  (runNumber >= 195344 && runNumber <= 196608)) { // LHC13b-f
1547  return kpA;
1548  } else {
1549  return kpp;
1550  }
1551  }
1552 }
1553 
1558 {
1559  if (inputObjectType == kCaloCells) {
1560  AliInfoStream() << "Cells info: " << std::endl;
1561  for (auto cellInfo : fCellCollArray) {
1562  AliInfoStream() << "\tName: " << cellInfo->GetName() << "\tBranch: " << cellInfo->GetBranchName() << "\tIsEmbedding: " << std::boolalpha << cellInfo->GetIsEmbedding() << std::endl;
1563  }
1564  }
1565  else if (inputObjectType == kCluster || inputObjectType == kTrack) {
1566  AliInfoStream() << (inputObjectType == kCluster ? "Cluster" : "Track") << " container info: " << std::endl;
1567  AliEmcalContainer * cont = 0;
1568  for (auto containerInfo : (inputObjectType == kCluster ? fClusterCollArray : fParticleCollArray) ) {
1569  cont = static_cast<AliEmcalContainer *>(containerInfo);
1570  AliInfoStream() << "\tName: " << cont->GetName() << "\tBranch: " << cont->GetArrayName() << "\tTitle: " << cont->GetTitle() << std::endl;
1571  // TODO: Enable in embedding branch
1572  //AliInfoStream() << "\tName: " << cont->GetName() << "\tBranch: " << cont->GetArrayName() << "\tTitle: " << cont->GetTitle() << "\tIsEmbedding:" << std::boolalpha << cont->GetIsEmbedding() << std::endl;
1573  }
1574  }
1575  else {
1576  AliErrorStream() << "Unrecognized input object type " << inputObjectType << std::endl;
1577  }
1578 }
1579 
1589 void AliEmcalCorrectionTask::GetNodeForInputObjects(YAML::Node & inputNode, YAML::Node & nodeToRetrieveFrom, std::string & inputObjectName, bool requiredProperty)
1590 {
1591  // Get the user input node
1592  AliEmcalCorrectionComponent::GetProperty(inputObjectName.c_str(), inputNode, YAML::Node(), nodeToRetrieveFrom, requiredProperty, "inputObjects");
1593 
1594  // Get the user shared node and add it back to the user node so that shared parameters are available
1595  if (nodeToRetrieveFrom["sharedParameters"]) {
1596  inputNode["sharedParameters"] = nodeToRetrieveFrom["sharedParameters"];
1597  }
1598 }
1599 
1610 void AliEmcalCorrectionTask::GetPropertyNamesFromNode(const std::string & componentName, const YAML::Node & node, std::set <std::string> & propertyNames, const bool nodeRequired)
1611 {
1612  YAML::Node tempNode;
1613  AliEmcalCorrectionComponent::GetProperty(componentName, tempNode, YAML::Node(), node, nodeRequired, "");
1614  for (auto propertyName : tempNode)
1615  {
1616  propertyNames.insert(propertyName.first.as<std::string>());
1617  }
1618 }
1619 
1628 {
1629  if (TString(n).IsNull()) return 0;
1630 
1632 
1633  fParticleCollArray.Add(cont);
1634 
1635  return cont;
1636 }
1637 
1646 {
1647  if (TString(n).IsNull()) return 0;
1648 
1649  AliTrackContainer* cont = new AliTrackContainer(n);
1650 
1651  fParticleCollArray.Add(cont);
1652 
1653  return cont;
1654 }
1655 
1664 {
1665  if (TString(n).IsNull()) return 0;
1666 
1668 
1669  fParticleCollArray.Add(cont);
1670 
1671  return cont;
1672 }
1673 
1682 {
1683  if (TString(n).IsNull()) return 0;
1684 
1686 
1687  fClusterCollArray.Add(cont);
1688 
1689  return cont;
1690 }
1691 
1698 {
1699  if (i<0 || i>fParticleCollArray.GetEntriesFast()) return 0;
1700  AliParticleContainer *cont = static_cast<AliParticleContainer*>(fParticleCollArray.At(i));
1701  return cont;
1702 }
1703 
1710 {
1711  if (i<0 || i>fClusterCollArray.GetEntriesFast()) return 0;
1712  AliClusterContainer *cont = static_cast<AliClusterContainer*>(fClusterCollArray.At(i));
1713  return cont;
1714 }
1715 
1722 {
1723  AliParticleContainer *cont = static_cast<AliParticleContainer*>(fParticleCollArray.FindObject(name));
1724  return cont;
1725 }
1726 
1733 {
1734  AliClusterContainer *cont = static_cast<AliClusterContainer*>(fClusterCollArray.FindObject(name));
1735  return cont;
1736 }
1737 
1745 AliEmcalCorrectionCellContainer * AliEmcalCorrectionTask::GetCellContainer(const std::string & cellsContainerName) const
1746 {
1747  for (auto cellContainer : fCellCollArray)
1748  {
1749  if (cellContainer->GetName() == cellsContainerName) {
1750  return cellContainer;
1751  }
1752  }
1753 
1754  return 0;
1755 }
1756 
1758 {
1759  // Get the pointer to the existing analysis manager via the static access method.
1760  //==============================================================================
1761  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
1762  if (!mgr)
1763  {
1764  ::Error("AddTaskEmcalCorrectionTask", "No analysis manager to connect to.");
1765  return 0;
1766  }
1767 
1768  // Check the analysis type using the event handlers connected to the analysis manager.
1769  //==============================================================================
1770  AliVEventHandler* handler = mgr->GetInputEventHandler();
1771  if (!handler)
1772  {
1773  ::Error("AddTaskEmcalCorrectionTask", "This task requires an input event handler");
1774  return 0;
1775  }
1776 
1777  TString name = "AliEmcalCorrectionTask";
1778  if (suffix != "") {
1779  name += TString::Format("_%s", suffix.Data());
1780  }
1781 
1782  AliEmcalCorrectionTask* mgrTask = static_cast<AliEmcalCorrectionTask *>(mgr->GetTask(name.Data()));
1783  if (mgrTask) return mgrTask;
1784 
1785  // Create the task that manages the corrections
1786  AliEmcalCorrectionTask* correctionTask = new AliEmcalCorrectionTask(name.Data());
1787 
1788  //-------------------------------------------------------
1789  // Final settings, pass to manager and set the containers
1790  //-------------------------------------------------------
1791 
1792  mgr->AddTask(correctionTask);
1793 
1794  // Create containers for input/output
1795  AliAnalysisDataContainer* cInput = mgr->GetCommonInputContainer();
1796 
1797  TString outputContainerName(name);
1798  outputContainerName += "_histos";
1799 
1800  AliAnalysisDataContainer * cOutput = mgr->CreateContainer(outputContainerName.Data(),
1801  TList::Class(),
1802  AliAnalysisManager::kOutputContainer,
1803  Form("%s", AliAnalysisManager::GetCommonFileName()));
1804 
1805  mgr->ConnectInput(correctionTask, 0, cInput);
1806  mgr->ConnectOutput(correctionTask, 1, cOutput);
1807 
1808  //TObjArray* cnt = mgr->GetContainers();
1809 
1810  return correctionTask;
1811 }
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
AliTrackContainer * AddTrackContainer(const char *n)
void SetClusterContainer(AliClusterContainer *cont)
std::vector< std::string > fOrderedComponentsToExecute
Ordered set of components to execute.
std::string GetInputFieldNameFromInputObjectType(InputObject_t inputObjectType)
AliClusterContainer * GetClusterContainer(Int_t i=0) const
bool CheckPossibleNamesForComponentName(std::string &name, std::set< std::string > &possibleComponents)
std::vector< AliEmcalCorrectionComponent * > fCorrectionComponents
Contains the correction components.
Container with name, TClonesArray and cuts for particles.
TSystem * gSystem
void AdoptClusterContainer(AliClusterContainer *cont)
void SetupConfigurationFilePath(std::string &filename, bool userFile=false)
void UserExec(Option_t *option)
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.
Container for particles within the EMCAL framework.
AliEmcalContainer * AddContainer(InputObject_t contType, std::string &containerName, YAML::Node &userNode, YAML::Node &defaultNode)
void SetUserConfiguration(YAML::Node &node)
Make copy to ensure that the nodes do not point to each other (?)
void AddContainersToComponent(AliEmcalCorrectionComponent *component, InputObject_t inputObjectType)
void SetParticleContainer(AliParticleContainer *cont)
bool fEventInitialized
If the event is initialized properly.
void Load()
Definition: UnfoldingHF.C:238
TString fCentEst
name of V0 centrality estimator
void SetAODFilterBits(UInt_t bits)
int Int_t
Definition: External.C:63
std::string fUserConfigurationFilename
! User YAML configruation filename
unsigned int UInt_t
Definition: External.C:33
std::string fDefaultConfigurationString
Store the default YAML configuration as a string so that it can be streamed.
void SetClusNonLinCorrEnergyCut(Double_t cut)
TString fRunPeriod
Run period (passed by user)
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)
std::map< std::string, AliEmcalTrackSelection::ETrackFilterType_t > trackFilterTypeMap
Relates string to the track filter enumeration for YAML configuration.
void SetupContainersFromInputNodes(InputObject_t inputObjectType, YAML::Node &userInputObjectNode, YAML::Node &defaultInputObjectNode, std::set< std::string > &requestedContainers)
void SetIncludePHOS(Bool_t b)
static std::string DetermineUseDefaultName(InputObject_t contType, bool esdMode, bool returnObjectType=false)
void SetupContainer(InputObject_t inputObjectType, std::string containerName, YAML::Node &userNode, YAML::Node &defaultNode)
bool WriteConfigurationFile(std::string filename, bool userConfig=false)
Bool_t fNeedEmcalGeom
whether or not the task needs the emcal geometry
std::string GetBranchName() const
Get the name of the cells branch (NOT the same as the name!)
void PrintRequestedContainersInformation(InputObject_t inputObjectType)
void SetCellsObjectInCellContainerBasedOnProperties(AliEmcalCorrectionCellContainer *cellContainer)
Bool_t fUseNewCentralityEstimation
Use new centrality estimation (for 2015 data)
bool GetIsEmbedding() const
True if the cells are located in the event that is being embedded.
void CheckForContainerArray(AliEmcalContainer *cont, InputObject_t objectType)
Bool_t Data(TH1F *h, Double_t *rangefit, Bool_t writefit, Double_t &sgn, Double_t &errsgn, Double_t &bkg, Double_t &errbkg, Double_t &sgnf, Double_t &errsgnf, Double_t &sigmafit, Int_t &status)
AliEmcalCorrectionCellContainer * GetCellContainer(const std::string &cellsContainerName) const
std::string fDefaultConfigurationFilename
! Default YAML configuration filename
void GetNodeForInputObjects(YAML::Node &inputNode, YAML::Node &nodeToRetrieveFrom, std::string &inputObjectName, bool requiredProperty)
TObjArray fParticleCollArray
Particle/track collection array.
TObjArray fClusterCollArray
Cluster collection array.
static AliVEvent * GetEvent(AliVEvent *inputEvent, bool isEmbedding=false)
void SetDefaultConfiguration(YAML::Node &node)
ClassImp(AliAnalysisTaskCRC) AliAnalysisTaskCRC
AliParticleContainer * GetParticleContainer(Int_t i=0) const
void AdoptParticleContainer(AliParticleContainer *cont)
void 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)
const char Option_t
Definition: External.C:48
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
AliClusterContainer * AddClusterContainer(const char *n)
std::vector< AliEmcalCorrectionCellContainer * > fCellCollArray
Cells collection array.
AliParticleContainer * AddParticleContainer(const char *n)
Container structure for EMCAL clusters.
Container for MC-true particles within the EMCAL framework.
std::string fUserConfigurationString
Store the user YAML configuration as a string so that it can be streamed.
void GetPropertyNamesFromNode(const std::string &componentName, const YAML::Node &node, std::set< std::string > &propertyNames, const bool nodeRequired)
InputObject_t
Type of input object to be created
TList * OpenFile(const char *fname)
Definition: DrawAnaELoss.C:65
void SetClusHadCorrEnergyCut(Double_t cut)
bool GetProperty(std::string propertyName, T &property, bool requiredProperty=true, std::string correctionName="")
Retrieve property.
BeamType fForceBeamType
forced beam type
void CreateInputObjects(InputObject_t inputObjectType)