AliPhysics  c923f52 (c923f52)
 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 <fstream>
11 #include <iostream>
12 #include <sstream>
13 
14 #include <yaml-cpp/yaml.h>
15 
16 #include <TChain.h>
17 #include <TSystem.h>
18 #include <TGrid.h>
19 
20 #include "AliVEventHandler.h"
21 #include "AliEMCALGeometry.h"
22 #include "AliVCaloCells.h"
23 #include "AliAODCaloCells.h"
24 #include "AliESDCaloCells.h"
25 #include "AliVCluster.h"
26 #include "AliAODCaloCluster.h"
27 #include "AliESDCaloCluster.h"
28 #include "AliVTrack.h"
29 #include "AliAODTrack.h"
30 #include "AliESDtrack.h"
31 #include "AliLog.h"
32 #include "AliMultSelection.h"
33 
37 
43  AliAnalysisTaskSE("AliEmcalCorrectionTask"),
44  fUserConfiguration(),
45  fUserConfigurationFilename(""),
46  fUserConfigurationString(""),
47  fDefaultConfiguration(),
48  fDefaultConfigurationFilename(""),
49  fDefaultConfigurationString(""),
50  fCorrectionComponents(),
51  fIsEsd(false),
52  fForceBeamType(kNA),
53  fRunPeriod(""),
54  fConfigurationInitialized(false),
55 
56  fCreateNewObjectBranches(false),
57  fCreatedClusterBranchName(""),
58  fCreatedTrackBranchName(""),
59  fEventInitialized(false),
60  fCent(0),
61  fCentBin(-1),
62  fMinCent(-999),
63  fMaxCent(-999),
64  fNcentBins(4),
65  fCentEst("V0M"),
66  fUseNewCentralityEstimation(kFALSE),
67  fNVertCont(0),
68  fBeamType(kNA),
69  fCaloCellsName(),
70  fNeedEmcalGeom(kTRUE),
71  fGeom(0),
72  fParticleCollArray(),
73  fClusterCollArray(),
74  fCaloCells(0),
75  fCaloCellsFromInputEvent(0),
76  fOutput(0)
77 {
78  // Default constructor
79  AliDebug(3, Form("%s", __PRETTY_FUNCTION__));
80 
81  fVertex[0] = 0;
82  fVertex[1] = 0;
83  fVertex[2] = 0;
84 
85  fParticleCollArray.SetOwner(kTRUE);
86  fClusterCollArray.SetOwner(kTRUE);
87 }
88 
94  AliAnalysisTaskSE(name),
95  fUserConfiguration(),
96  fUserConfigurationFilename(""),
97  fUserConfigurationString(""),
98  fDefaultConfiguration(),
99  fDefaultConfigurationFilename(""),
100  fDefaultConfigurationString(""),
101  fCorrectionComponents(),
102  fIsEsd(false),
103  fForceBeamType(kNA),
104  fRunPeriod(""),
105  fConfigurationInitialized(false),
106 
107  fCreateNewObjectBranches(false),
108  fCreatedClusterBranchName(""),
109  fCreatedTrackBranchName(""),
110  fEventInitialized(false),
111  fCent(0),
112  fCentBin(-1),
113  fMinCent(-999),
114  fMaxCent(-999),
115  fNcentBins(4),
116  fCentEst("V0M"),
117  fUseNewCentralityEstimation(kFALSE),
118  fNVertCont(0),
119  fBeamType(kNA),
120  fCaloCellsName(),
121  fNeedEmcalGeom(kTRUE),
122  fGeom(0),
123  fParticleCollArray(),
124  fClusterCollArray(),
125  fCaloCells(0),
126  fCaloCellsFromInputEvent(0),
127  fOutput(0)
128 {
129  // Standard constructor
130  AliDebug(3, Form("%s", __PRETTY_FUNCTION__));
131 
132  fVertex[0] = 0;
133  fVertex[1] = 0;
134  fVertex[2] = 0;
135 
136  fParticleCollArray.SetOwner(kTRUE);
137  fClusterCollArray.SetOwner(kTRUE);
138 
139  DefineInput(0, TChain::Class());
140  DefineOutput(1, TList::Class());
141 }
142 
150 inline bool AliEmcalCorrectionTask::doesFileExist(const std::string & filename)
151 {
152  std::ifstream inFile(filename);
153  return inFile.good();
154 }
155 
161 {
162  if (filename != "")
163  {
164  // Handle if in AliPhysics
165  // Check for and replace $ALICE_PHYSICS with the actual path if needed
166  std::size_t alicePhysicsPathLocation = filename.find("$ALICE_PHYSICS");
167  if (alicePhysicsPathLocation != std::string::npos)
168  {
169  TString alicePhysicsPath = gSystem->Getenv("ALICE_PHYSICS");
170  // "$ALICE_PHYSICS "is 14 characters
171  filename.replace(alicePhysicsPathLocation, alicePhysicsPathLocation + 14, alicePhysicsPath.Data());
172  }
173 
174  // Handle grid
175  if(filename.find("alien://") != std::string::npos)
176  {
177  AliDebug(2, TString::Format("Opening file \"%s\" on the grid!", filename.c_str()));
178  // Init alien connection if needed
179  if (!gGrid) {
180  TGrid::Connect("alien://");
181  }
182 
183  // Determine the loca filename and copy file to local directory
184  std::string localFilename = gSystem->BaseName(filename.c_str());
185  // Ensures that the default and user files do not conflict if both are taken from the grid and have the same filename
186  if (userFile == true) {
187  localFilename = "user" + localFilename;
188  }
189  TFile::Cp(filename.c_str(), localFilename.c_str());
190 
191  // yaml-cpp should only open the local file
192  filename = localFilename;
193  }
194  }
195 }
196 
197 
203 {
204  // Determine file path
206  {
207  // Use the default if nothing is set
208  fDefaultConfigurationFilename = "$ALICE_PHYSICS/PWG/EMCAL/config/AliEmcalCorrectionConfiguration.yaml";
209  }
210 
211  // Setup the YAML files
212  // Default
214 
216  {
217  AliInfo(TString::Format("Using default EMCal corrections configuration located at %s", fDefaultConfigurationFilename.c_str()));
218 
220  // Check for valid file
221  if (fDefaultConfiguration.IsNull() == true)
222  {
223  AliFatal(TString::Format("Could not open the default configuration file \"%s\"!", fDefaultConfigurationFilename.c_str()));
224  }
225  }
226  else
227  {
228  AliFatal(TString::Format("Default file located at \"%s\" does not exist!", fDefaultConfigurationFilename.c_str()));
229  }
230 
231  // User
233 
235  {
236  AliInfo(TString::Format("Using user EMCal corrections configuration located at %s", fUserConfigurationFilename.c_str()));
237 
239  }
240  else
241  {
242  AliInfo(TString::Format("User file at \"%s\" does not exist! All settings will be from the default file!", fUserConfigurationFilename.c_str()));
243  }
244 
245  // Ensure that there is a run period
246  if (fRunPeriod == "")
247  {
248  AliFatal("Must pass a run period to the correction task!");
249  }
250  // Check the user provided run period
251  TString userRunPeriod = "kNoUserFile";
252  // Test if the period exists in the user file
253  if (fUserConfiguration.IsNull() != true)
254  {
255  if (fUserConfiguration["period"])
256  {
257  userRunPeriod = fUserConfiguration["period"].as<std::string>();
258  }
259  else
260  {
261  AliFatal("User must specify a period. Leave the period as an empty string to apply to all periods.");
262  }
263  }
264 
265  AliDebug(3, TString::Format("userRunPeriod: %s", userRunPeriod.Data()));
266  // Normalize the user run period to lower case to ensure that we don't miss any matches
267  userRunPeriod.ToLower();
268  // "" means the user wants their settings to apply to all periods
269  if (userRunPeriod != "" && userRunPeriod != "knouserfile" && userRunPeriod != fRunPeriod)
270  {
271  AliFatal(TString::Format("User run period \"%s\" does not match the run period of \"%s\" passed to the correction task!", userRunPeriod.Data(), fRunPeriod.Data()));
272  }
273 
274  // Ensure that the user is aware
275  if (userRunPeriod == "")
276  {
277  AliWarning("User run period is an empty string. Settings apply to all run periods!");
278  }
279 
280  // Save configuration into strings so that they can be streamed
281  // Need the stringstream because yaml implements streamers
282  std::stringstream tempConfiguration;
283  tempConfiguration << fUserConfiguration;
284  fUserConfigurationString = tempConfiguration.str();
285  tempConfiguration.str("");
286  tempConfiguration << fDefaultConfiguration;
287  fDefaultConfigurationString = tempConfiguration.str();
288 
289  //AliInfo(TString::Format("User configuration: %s", fUserConfigurationString.c_str()));
290  //AliInfo(TString::Format("Default configuration: %s", fDefaultConfigurationString.c_str()));
291 
292  // Note that it is initialized properly so that the analysis can proceed
294 }
295 
304 {
305  bool returnValue = false;
306  if (filename != "")
307  {
308  if (fConfigurationInitialized == true)
309  {
310  std::ofstream outFile(filename);
311  std::string stringToWrite = userConfig ? fUserConfigurationString : fDefaultConfigurationString;
312  if (stringToWrite == "") {
313  AliWarning(TString::Format("%s configuration is empty!", userConfig ? "User" : "Default"));
314  }
315  outFile << stringToWrite;
316  outFile.close();
317 
318  returnValue = true;
319  }
320  else
321  {
322  AliWarning(TString::Format("Configuration not properly initialized! Cnanot print %s configuration!", userConfig ? "user" : "default"));
323  }
324 
325  }
326  else
327  {
328  AliWarning("Please pass a valid filename instead of empty qutoes!");
329  }
330  return returnValue;
331 }
332 
333 
338 void AliEmcalCorrectionTask::RetrieveExecutionOrder(std::vector <std::string> & executionOrder)
339 {
341  // Need to append "AliEmcalCorrection" to allow the tasks to be found!
342  AliDebug(2, "Creating EMCal Correction Components: ");
343  for (auto & component : executionOrder)
344  {
345  component = "AliEmcalCorrection" + component;
346  AliDebug(2, TString::Format("%s", component.c_str()) );
347  }
348 }
349 
355 {
356  // Create a function to handle creation and configuration of the all of the created module
357  std::vector<std::string> executionOrder;
358  RetrieveExecutionOrder(executionOrder);
359 
360  // Allow for output files
361  OpenFile(1);
362  fOutput = new TList();
363  fOutput->SetOwner();
364 
365  // Iterate over the list
366  AliEmcalCorrectionComponent * component = 0;
367  bool componentEnabled = false;
368  for (auto componentName : executionOrder)
369  {
370  componentEnabled = false;
371  AliEmcalCorrectionComponent::GetProperty("enabled", componentEnabled, fUserConfiguration, fDefaultConfiguration, true, componentName);
372  if (componentEnabled == false)
373  {
374  AliInfo(TString::Format("Component %s is disabled and will not be run!", componentName.c_str()));
375  continue;
376  }
377 
378  //Printf("Attempting to add task: %s", tempString->GetString().Data());
379  component = AliEmcalCorrectionComponentFactory::createInstance(componentName);
380  if (!component)
381  {
382  AliFatal(TString::Format("Failed to create requested component %s!", componentName.c_str()));
383  }
384 
385  // For setting names of tasks to differentiate between tasks of the same class
386  component->SetName(componentName.c_str());
387  component->SetTitle(componentName.c_str());
388 
389  // Initialize the YAML configurations in each component
392 
393  // configure needed fields for components to properly initialize
394  component->SetNcentralityBins(fNcentBins);
395 
396  // Initialize each component
397  component->Initialize();
398 
399  // Attempt to retrieve any containers they may have created in initialization
400  AliClusterContainer * tempClusterContainer = component->GetClusterContainer();
401  if (tempClusterContainer)
402  {
403  AdoptClusterContainer(tempClusterContainer);
404  }
405 
406  AliParticleContainer * tempParticleContainer = component->GetParticleContainer();
407  if (tempParticleContainer)
408  {
409  AdoptParticleContainer(tempParticleContainer);
410  }
411 
412  if (component)
413  {
414  AliInfo(TString::Format("Successfully added correction task: %s", componentName.c_str()));
415  fCorrectionComponents.push_back(component);
416  }
417 
418  if (component->GetOutputList() != 0)
419  {
420  // Adds a list to the list -- this doesn't work for some unknown reason
421  //fOutput->Add(component->GetOutputList());
422 
423  // iterate through lists for each component, and fill in output
424  TList* t = new TList();
425  t->SetName(componentName.c_str());
426  fOutput->AddLast(t);
427  t = (TList*)fOutput->Last();
428  TIter next(component->GetOutputList());
429  while (TObject *obj = next()){
430  t->Add(obj);
431  }
432 
433  AliDebug(1, TString::Format("Added output list from task %s to output.", componentName.c_str()));
434  }
435  }
436 
437  PostData(1, fOutput);
438 
439  // Just printing in order is probably better
440  // Available components
441  /*AliEmcalCorrectionComponentFactory::map_type * availableComponents = AliEmcalCorrectionComponentFactory::getMap();
442 
443  // Need to sort by execution order
444  Printf("Correction Components:");
445  bool availableFlag = false;
446  for (AliEmcalCorrectionComponentFactory::map_type::const_iterator it = availableComponents->begin(); it != availableComponents->end(); ++it)
447  {
448  if (fCorrectionComponents.FindObject(it->first.c_str()))
449  {
450  availableFlag = true;
451  }
452 
453  Printf("%s:\t(%s)", it->first.c_str(), availableFlag ? "Enabled" : "Disabled");
454 
455  availableFlag = false;
456  }*/
457 }
458 
464 {
465  AliDebug(3, Form("%s", __PRETTY_FUNCTION__));
466 
467  // Determine file type
468  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
469  if (mgr) {
470  AliVEventHandler *evhand = mgr->GetInputEventHandler();
471  if (evhand) {
472  if (evhand->InheritsFrom("AliESDInputHandler")) {
473  fIsEsd = true;
474  }
475  else {
476  fIsEsd = false;
477  }
478  }
479  else {
480  AliError("Event handler not found!");
481  }
482  }
483  else {
484  AliError("Analysis manager not found!");
485  }
486 
487  // Initialize the components
488  //InitializeConfiguration();
489  if (fConfigurationInitialized != true)
490  {
491  AliFatal("YAML configuration must be initialized before running (ie. the AddTask, run macro or wagon)!");
492  }
493 
494  // Show the configurations info this is available
495  AliDebug(4, TString::Format("User configuration string: %s", fUserConfigurationString.c_str()));
496  AliDebugStream(4) << "User configuration: " << fUserConfiguration << std::endl;
497  AliDebug(4, TString::Format("Default configuration string: %s", fDefaultConfigurationString.c_str()));
498  AliDebugStream(4) << "Default configuration: " << fDefaultConfiguration << std::endl;
499 
500  // YAML Objects cannot be streamed, so we need to reinitialize them here.
501  // They need reinitialize if they are null
502  if (fUserConfiguration.IsNull() == true && fUserConfigurationString != "")
503  {
504  AliInfo("Reinitializing user configuration from string. Expected if running on grid!");
506  }
507  if (fDefaultConfiguration.IsNull() == true)
508  {
509  AliInfo("Reinitializing default configuration from string. Expected if running on grid!");
511  }
512 
513  // Debug to check that the configuration has been (re)initiailzied has been completed correctly
514  AliDebug(4, TString::Format("(Re)initialized user configuration: %s", fUserConfigurationString.c_str()));
515  AliDebugStream(4) << "(Re)initialized User configuration: " << fUserConfiguration << std::endl;
516  AliDebug(4, TString::Format("(Re)initialized default configuration: %s", fDefaultConfigurationString.c_str()));
517  AliDebugStream(4) << "(Re)initialized Default configuration: " << fDefaultConfiguration << std::endl;
518 
519  // Retrieve cells name from configruation
520  std::string cellsName = "";
522  // In the case of fCreateNewObjectBranches, we need to get the default name to retrieve the normal cells
523  // We will then retrieve the new cells name later
524  if (cellsName == "usedefault" || fCreateNewObjectBranches) {
526  }
527  fCaloCellsName = cellsName;
528 
529  if (fForceBeamType == kpp)
530  fNcentBins = 1;
531 
533 }
534 
540 {
541  // Run the initialization for all derived classes.
542  AliDebug(3, Form("%s", __PRETTY_FUNCTION__));
543  for (auto component : fCorrectionComponents)
544  {
545  component->ExecOnce();
546  }
547 }
548 
554 {
555  // Create new cell branch
556  // cellBranchName doesn't belong to any particular component
558  // While it is wrong to use "usedefault" here, this will provide a more meaningful message error message
559  if (fCreatedCellBranchName == "usedefault") {
561  }
562 
563  // Check to ensure that we are not trying to create a new branch on top of the old branch
564  TObject * existingObject = InputEvent()->FindListObject(fCreatedCellBranchName.c_str());
565  if (existingObject) {
566  AliFatal(TString::Format("Attempted to create a new cell branch, \"%s\", with the same name as an existing branch! Check your configuration! Perhaps \"usedefault\" was used incorrectly?", fCreatedCellBranchName.c_str()));
567  }
568 
569  // Create new branch and add it to the event
570  AliVCaloCells * newCells = 0;
571  if (fIsEsd) {
572  newCells = new AliESDCaloCells(fCreatedCellBranchName.c_str(), fCreatedCellBranchName.c_str(), AliVCaloCells::kEMCALCell);
573  }
574  else {
575  newCells = new AliAODCaloCells(fCreatedCellBranchName.c_str(), fCreatedCellBranchName.c_str(), AliVCaloCells::kEMCALCell);
576  }
577  InputEvent()->AddObject(newCells);
578  // Set fCaloCells here to avoid looking up every event
579  // newCells is the same address as that reference by the TList in the InputEvent
580  fCaloCells = newCells;
581 
582  // Create new cluster branch
583  // Clusterizer is used since it is the first place that clusters are used.
585  // While it is wrong to use "usedefault" here, this will provide a more meaningful message error message
586  if (fCreatedClusterBranchName == "usedefault") {
588  }
589 
590  // Check to ensure that we are not trying to create a new branch on top of the old branch
591  existingObject = InputEvent()->FindListObject(fCreatedClusterBranchName.c_str());
592  if (existingObject) {
593  AliFatal(TString::Format("Attempted to create a new cluster branch, \"%s\", with the same name as an existing branch! Check your configuration! Perhaps \"usedefault\" was used incorrectly?", fCreatedClusterBranchName.c_str()));
594  }
595  TClonesArray * existingArray = dynamic_cast<TClonesArray *>(existingObject);
596 
597  // Create new branch and add it to the event
598  TClonesArray * newClusters = 0;
599  if (fIsEsd) {
600  newClusters = new TClonesArray("AliESDCaloCluster");
601  }
602  else {
603  newClusters = new TClonesArray("AliAODCaloCluster");
604  }
605  newClusters->SetName(fCreatedClusterBranchName.c_str());
606  InputEvent()->AddObject(newClusters);
607 
608  // Create new tracks branch
609  // ClusterTrackMatcher is used since it is the first place that tracks are used.
611  // While it is wrong to use "usedefault" here, this will provide a more meaningful message error message
612  if (fCreatedTrackBranchName == "usedefault") {
614  }
615 
616  // Check to ensure that we are not trying to create a new branch on top of the old branch
617  existingObject = dynamic_cast<TClonesArray *>(InputEvent()->FindListObject(fCreatedTrackBranchName.c_str()));
618  if (existingObject) {
619  AliFatal(TString::Format("Attempted to create a new track branch, \"%s\", with the same name as an existing branch! Check your configuration! Perhaps \"usedefault\" was used incorrectly?", fCreatedTrackBranchName.c_str()));
620  }
621  existingArray = dynamic_cast<TClonesArray *>(existingObject);
622 
623  // Create new branch and add it to the event
624  TClonesArray * newTracks = 0;
625  if (fIsEsd) {
626  newTracks = new TClonesArray("AliESDtrack");
627  }
628  else {
629  newTracks = new TClonesArray("AliAODTrack");
630  }
631  newTracks->SetName(fCreatedTrackBranchName.c_str());
632  InputEvent()->AddObject(newTracks);
633 }
634 
640 {
641  // Cells
642  AliDebug(3, Form("Number of old cells: %d", fCaloCellsFromInputEvent->GetNumberOfCells()));
643  // The function CopyCaloCells() does not work, so we use the assignment operator instead!
644  if (fIsEsd)
645  {
646  AliESDCaloCells * currentCells = dynamic_cast<AliESDCaloCells *>(fCaloCellsFromInputEvent);
647  AliESDCaloCells * newCells = dynamic_cast<AliESDCaloCells *>(fCaloCells);
648  fCaloCells = dynamic_cast<AliESDCaloCells *>(new (newCells) AliESDCaloCells(*currentCells));
649  // The name was changed to the currentCells name, but we want it to be newCells, so we restore it
650  fCaloCells->SetName(fCreatedCellBranchName.c_str());
651  }
652  else
653  {
654  AliAODCaloCells * currentCells = dynamic_cast<AliAODCaloCells *>(fCaloCellsFromInputEvent);
655  AliAODCaloCells * newCells = dynamic_cast<AliAODCaloCells *>(fCaloCells);
656  fCaloCells = dynamic_cast<AliAODCaloCells *>(new (newCells) AliAODCaloCells(*currentCells));
657  // The name was changed to the currentCells name, but we want it to be newCells, so we restore it
658  fCaloCells->SetName(fCreatedCellBranchName.c_str());
659  }
660  AliDebug(3, Form("Number of old cells: %d \tNumber of new cells: %d", fCaloCellsFromInputEvent->GetNumberOfCells(), fCaloCells->GetNumberOfCells() ));
661 
662  // Clusters
663  TClonesArray * newClusters = dynamic_cast<TClonesArray *>(InputEvent()->FindListObject(fCreatedClusterBranchName.c_str()));
665  TClonesArray * currentClusters = dynamic_cast<TClonesArray *>(InputEvent()->FindListObject(currentClustersName.c_str()));
666  AliDebug(3, Form("before copy:\t currentClusters->GetEntries(): %d \t newClusters->GetEntries(): %d", currentClusters->GetEntries(), newClusters->GetEntries()));
667  CopyClusters(currentClusters, newClusters);
668  AliDebug(3, Form("after copy:\t currentClusters->GetEntries(): %d \t newClusters->GetEntries(): %d", currentClusters->GetEntries(), newClusters->GetEntries()));
669 
670  // Tracks
671  TClonesArray * newTracks = dynamic_cast<TClonesArray *>(InputEvent()->FindListObject(fCreatedTrackBranchName.c_str()));
673  TClonesArray * currentTracks = dynamic_cast<TClonesArray *>(InputEvent()->FindListObject(currentTracksName.c_str()));
674  AliDebug(3, Form("before copy:\t currentTracks->GetEntries(): %d \t newTracks->GetEntries(): %d", currentTracks->GetEntries(), newTracks->GetEntries()));
675  for (Int_t i = 0; i < currentTracks->GetEntriesFast(); i++)
676  {
677  if (fIsEsd)
678  {
679  AliESDtrack *currentTrack = dynamic_cast<AliESDtrack *>(currentTracks->At(i));
680  // Calls copy constructor to create a new track at position i in newTracks
681  AliESDtrack *newTrack = dynamic_cast<AliESDtrack *>(new ((*newTracks)[i]) AliESDtrack(*currentTrack));
682 
683  // Assign new process ID so that it is from the current process as opposed to the old one copied from the current track
684  TProcessID::AssignID(newTrack);
685  }
686  else
687  {
688  AliAODTrack *currentTrack = dynamic_cast<AliAODTrack *>(currentTracks->At(i));
689  // Calls copy constructor to create a new track at position i in newTracks
690  AliAODTrack *newTrack = dynamic_cast<AliAODTrack *>(new ((*newTracks)[i]) AliAODTrack(*currentTrack));
691 
692  // TEMP
693  /*if (i == 5 || i == 7)
694  {
695  std::cout << "Track properties:" << std::endl;
696  currentTrack->Print();
697  newTrack->Print();
698  std::cout << "ProcessID for current track: " << TProcessID::GetProcessWithUID(currentTrack)->GetName() << "/" << TProcessID::GetProcessWithUID(currentTrack)->GetTitle() << ". Memory Address: " << TProcessID::GetProcessWithUID(currentTrack) << std::endl;
699  std::cout << "ProcessID for new track: " << TProcessID::GetProcessWithUID(newTrack)->GetName() << "/" << TProcessID::GetProcessWithUID(newTrack)->GetTitle() << ". Memory Address: " << TProcessID::GetProcessWithUID(newTrack) << std::endl;
700  }*/
701 
702  // Assign new process ID so that it is from the current process as opposed to the old one copied from the current track
703  TProcessID::AssignID(newTrack);
704 
705  /*if (i == 5 || i == 7)
706  {
707  std::cout << "ProcessID for new track after assign ID: " << TProcessID::GetProcessWithUID(newTrack)->GetName() << "/" << TProcessID::GetProcessWithUID(newTrack)->GetTitle() << ". Memory Address: " << TProcessID::GetProcessWithUID(newTrack) << std::endl;
708  std::cout << "ProcessID for newTracks: " << TProcessID::GetProcessWithUID(newTracks)->GetName() << "/" << TProcessID::GetProcessWithUID(newTracks)->GetTitle() << ". Memory Address: " << TProcessID::GetProcessWithUID(newTracks) << std::endl;
709  }*/
710  }
711  }
712  AliDebug(3, Form("after copy:\t currentTracks->GetEntries(): %d \t newTracks->GetEntries(): %d", currentTracks->GetEntries(), newTracks->GetEntries()));
713 }
714 
719 void AliEmcalCorrectionTask::CopyClusters(TClonesArray *orig, TClonesArray *dest)
720 {
721  const Int_t Ncls = orig->GetEntries();
722 
723  for(Int_t i=0; i < Ncls; ++i) {
724  AliVCluster *oc = static_cast<AliVCluster*>(orig->At(i));
725 
726  if (!oc)
727  continue;
728 
729  // We likely want to include PHOS cells as well, so the copy we make should avoid this check
730  //if (!oc->IsEMCAL())
731  // continue;
732 
733  AliVCluster *dc = static_cast<AliVCluster*>(dest->New(i));
734  //dc->SetType(AliVCluster::kEMCALClusterv1);
735  dc->SetType(oc->GetType());
736  dc->SetE(oc->E());
737  Float_t pos[3] = {0};
738  oc->GetPosition(pos);
739  dc->SetPosition(pos);
740  dc->SetNCells(oc->GetNCells());
741  dc->SetCellsAbsId(oc->GetCellsAbsId());
742  dc->SetCellsAmplitudeFraction(oc->GetCellsAmplitudeFraction());
743  dc->SetID(oc->GetID());
744  dc->SetDispersion(oc->GetDispersion());
745  dc->SetEmcCpvDistance(-1);
746  dc->SetChi2(-1);
747  dc->SetTOF(oc->GetTOF()); //time-of-flight
748  dc->SetNExMax(oc->GetNExMax()); //number of local maxima
749  dc->SetM02(oc->GetM02());
750  dc->SetM20(oc->GetM20());
751  dc->SetDistanceToBadChannel(oc->GetDistanceToBadChannel());
752  dc->SetMCEnergyFraction(oc->GetMCEnergyFraction());
753 
754  //MC
755  UInt_t nlabels = oc->GetNLabels();
756  Int_t *labels = oc->GetLabels();
757 
758  if (nlabels == 0 || !labels)
759  continue;
760 
761  AliESDCaloCluster *esdClus = dynamic_cast<AliESDCaloCluster*>(dc);
762  if (esdClus) {
763  TArrayI parents(nlabels, labels);
764  esdClus->AddLabels(parents);
765  }
766  else {
767  AliAODCaloCluster *aodClus = dynamic_cast<AliAODCaloCluster*>(dc);
768  if (aodClus)
769  aodClus->SetLabel(labels, nlabels);
770  }
771  }
772 }
773 
779 {
780  fVertex[0] = 0;
781  fVertex[1] = 0;
782  fVertex[2] = 0;
783  fNVertCont = 0;
784 
785  const AliVVertex *vert = InputEvent()->GetPrimaryVertex();
786  if (vert) {
787  vert->GetXYZ(fVertex);
788  fNVertCont = vert->GetNContributors();
789  }
790 
792 
793  if (fBeamType == kAA || fBeamType == kpA ) {
795  AliMultSelection *MultSelection = static_cast<AliMultSelection*>(InputEvent()->FindListObject("MultSelection"));
796  if (MultSelection) {
797  fCent = MultSelection->GetMultiplicityPercentile(fCentEst.Data());
798  }
799  else {
800  AliWarning("Could not retrieve centrality information! Assuming 99");
801  }
802  }
803  else { // old centrality estimation < 2015
804  AliCentrality *aliCent = InputEvent()->GetCentrality();
805  if (aliCent) {
806  fCent = aliCent->GetCentralityPercentile(fCentEst.Data());
807  }
808  else {
809  AliWarning("Could not retrieve centrality information! Assuming 99");
810  }
811  }
812 
813  if (fNcentBins==4) {
814  if (fCent >= 0 && fCent < 10) fCentBin = 0;
815  else if (fCent >= 10 && fCent < 30) fCentBin = 1;
816  else if (fCent >= 30 && fCent < 50) fCentBin = 2;
817  else if (fCent >= 50 && fCent <= 100) fCentBin = 3;
818  else {
819  AliWarning(Form("Negative centrality: %f. Assuming 99", fCent));
820  fCentBin = fNcentBins-1;
821  }
822  }
823  else if (fNcentBins==5) { // for PbPb 2015
824  if (fCent >= 0 && fCent < 10) fCentBin = 0;
825  else if (fCent >= 10 && fCent < 30) fCentBin = 1;
826  else if (fCent >= 30 && fCent < 50) fCentBin = 2;
827  else if (fCent >= 50 && fCent <= 90) fCentBin = 3;
828  else if (fCent > 90) {
829  fCent = 99;
830  fCentBin = 4;
831  }
832  else {
833  AliWarning(Form("Negative centrality: %f. Assuming 99", fCent));
834  fCentBin = fNcentBins-1;
835  }
836  }
837  else {
839  if(centWidth>0.) {
840  fCentBin = TMath::FloorNint(fCent/centWidth);
841  }
842  else {
843  fCentBin = 0;
844  }
845  if (fCentBin>=fNcentBins) {
846  AliWarning(Form("fCentBin too large: cent = %f fCentBin = %d. Assuming 99", fCent, fCentBin));
847  fCentBin = fNcentBins-1;
848  }
849  }
850  }
851  else {
852  fCent = 99;
853  fCentBin = 0;
854  }
855 
856  AliEmcalContainer* cont = 0;
857 
858  TIter nextPartColl(&fParticleCollArray);
859  while ((cont = static_cast<AliEmcalContainer*>(nextPartColl()))) cont->NextEvent();
860 
861  TIter nextClusColl(&fClusterCollArray);
862  while ((cont = static_cast<AliEmcalContainer*>(nextClusColl()))) cont->NextEvent();
863 
864  return kTRUE;
865 }
866 
867 
879 {
880  if (!InputEvent()) {
881  AliError("Could not retrieve event! Returning!");
882  return;
883  }
884 
885  if (fNeedEmcalGeom) {
886  fGeom = AliEMCALGeometry::GetInstanceFromRunNumber(InputEvent()->GetRunNumber());
887  if (!fGeom) {
888  AliFatal("Can not get EMCal geometry instance. If you do not need the EMCal geometry, disable it by setting task->SetNeedEmcalGeometry(kFALSE).");
889  return;
890  }
891  }
892 
893  // Create the new object branch here.
894  // The cell pointer already exists. All we need to do is load it later.
897 
898  // Load all requested track branches - each container knows name already
899  for (Int_t i =0; i<fParticleCollArray.GetEntriesFast(); i++) {
900  AliParticleContainer *cont = static_cast<AliParticleContainer*>(fParticleCollArray.At(i));
901  cont->SetArray(InputEvent());
902  }
903 
904  // Load all requested cluster branches - each container knows name already
905  for (Int_t i =0; i<fClusterCollArray.GetEntriesFast(); i++) {
906  AliClusterContainer *cont = static_cast<AliClusterContainer*>(fClusterCollArray.At(i));
907  cont->SetArray(InputEvent());
908  }
909 
910  if (!fCaloCellsName.IsNull() && !fCaloCellsFromInputEvent) {
911  fCaloCellsFromInputEvent = dynamic_cast<AliVCaloCells*>(InputEvent()->FindListObject(fCaloCellsName));
913  AliError(Form("Could not retrieve cells %s!", fCaloCellsName.Data()));
914  return;
915  }
916  }
917 
918  fEventInitialized = kTRUE;
919 
921 }
922 
931 {
932  if (TString(n).IsNull()) return 0;
933 
935 
936  fParticleCollArray.Add(cont);
937 
938  return cont;
939 }
940 
949 {
950  if (TString(n).IsNull()) return 0;
951 
952  AliTrackContainer* cont = new AliTrackContainer(n);
953 
954  fParticleCollArray.Add(cont);
955 
956  return cont;
957 }
958 
967 {
968  if (TString(n).IsNull()) return 0;
969 
971 
972  fParticleCollArray.Add(cont);
973 
974  return cont;
975 }
976 
985 {
986  if (TString(n).IsNull()) return 0;
987 
989 
990  fClusterCollArray.Add(cont);
991 
992  return cont;
993 }
994 
1001 {
1002  if (i<0 || i>fParticleCollArray.GetEntriesFast()) return 0;
1003  AliParticleContainer *cont = static_cast<AliParticleContainer*>(fParticleCollArray.At(i));
1004  return cont;
1005 }
1006 
1013 {
1014  if (i<0 || i>fClusterCollArray.GetEntriesFast()) return 0;
1015  AliClusterContainer *cont = static_cast<AliClusterContainer*>(fClusterCollArray.At(i));
1016  return cont;
1017 }
1018 
1025 {
1026  AliParticleContainer *cont = static_cast<AliParticleContainer*>(fParticleCollArray.FindObject(name));
1027  return cont;
1028 }
1029 
1036 {
1037  AliClusterContainer *cont = static_cast<AliClusterContainer*>(fClusterCollArray.FindObject(name));
1038  return cont;
1039 }
1040 
1041 
1042 
1048 {
1049  AliDebug(3, Form("%s", __PRETTY_FUNCTION__));
1050 
1051  // Initialize the event if not intialized
1052  if (!fEventInitialized)
1053  ExecOnce();
1054 
1055  // Only continue if we are initialized successfully
1056  if (!fEventInitialized)
1057  return;
1058 
1059  // Copy cells and cluster to new branches if desired
1061  {
1063  }
1064  else
1065  {
1067  }
1068 
1069  // Get the objects for each event
1070  if (!RetrieveEventObjects())
1071  return;
1072 
1073  // TODO: Consider adding IsEventSelected()??
1074 
1075  // Call run for each correction
1076  if (!Run())
1077  return;
1078 }
1079 
1085 {
1086  // Run the initialization for all derived classes.
1087  AliDebug(3, Form("%s", __PRETTY_FUNCTION__));
1088  for (auto component : fCorrectionComponents)
1089  {
1090  component->SetEvent(InputEvent());
1091  component->SetMCEvent(MCEvent());
1092  component->SetCaloCells(fCaloCells);
1093  component->SetEMCALGeometry(fGeom);
1094  component->SetCentralityBin(fCentBin);
1095  component->SetCentrality(fCent);
1096  component->SetNcentralityBins(fNcentBins);
1097  AliClusterContainer * tempClusterContainer = GetClusterContainer(component->GetName());
1098  if (tempClusterContainer)
1099  {
1100  component->SetClusterContainer(tempClusterContainer);
1101  }
1102  AliParticleContainer * tempParticleContainer = GetParticleContainer(component->GetName());
1103  if (tempParticleContainer)
1104  {
1105  // TEMP
1106  //Printf("Particle container name: %s, branch: %s", tempParticleContainer->GetName(), tempParticleContainer->GetArrayName().Data());
1107  component->SetParticleContainer(tempParticleContainer);
1108  }
1109 
1110  component->Run();
1111  }
1112 
1113  PostData(1, fOutput);
1114 
1115  // Need something more sophisticated here
1116  return kTRUE;
1117 }
1118 
1124 {
1125  // Run the initialization for all derived classes.
1126  AliDebug(3, Form("%s", __PRETTY_FUNCTION__));
1127  for (auto component : fCorrectionComponents)
1128  {
1129  component->UserNotify();
1130  }
1131 
1132  // Need something more sophisticated here
1133  return kTRUE;
1134 }
1135 
1141 {
1142  // Destructor
1143 }
1144 
1151 {
1152  if (fForceBeamType != kNA)
1153  return fForceBeamType;
1154 
1155  AliESDEvent *esd = dynamic_cast<AliESDEvent*>(InputEvent());
1156  if (esd) {
1157  const AliESDRun *run = esd->GetESDRun();
1158  TString beamType = run->GetBeamType();
1159  if (beamType == "p-p")
1160  return kpp;
1161  else if (beamType == "A-A")
1162  return kAA;
1163  else if (beamType == "p-A")
1164  return kpA;
1165  else
1166  return kNA;
1167  } else {
1168  Int_t runNumber = InputEvent()->GetRunNumber();
1169  if ((runNumber >= 136851 && runNumber <= 139517) || // LHC10h
1170  (runNumber >= 166529 && runNumber <= 170593)) { // LHC11h
1171  return kAA;
1172  } else if ((runNumber>=188365 && runNumber <= 188366) || // LHC12g
1173  (runNumber >= 195344 && runNumber <= 196608)) { // LHC13b-f
1174  return kpA;
1175  } else {
1176  return kpp;
1177  }
1178  }
1179 }
Int_t fNcentBins
how many centrality bins
Steering task for the EMCal correction frameworkThis class is the steering class for the cell and clu...
AliEMCALGeometry * fGeom
!emcal geometry
const char * filename
Definition: TestFCM.C:1
static std::string DetermineUseDefaultName(inputObjectType contType, Bool_t esdMode)
AliParticleContainer * GetParticleContainer()
double Double_t
Definition: External.C:58
AliTrackContainer * AddTrackContainer(const char *n)
AliClusterContainer * GetClusterContainer(Int_t i=0) const
std::vector< AliEmcalCorrectionComponent * > fCorrectionComponents
! Contains the correction components
Container with name, TClonesArray and cuts for particles.
void RetrieveExecutionOrder(std::vector< std::string > &componentsToAdd)
TSystem * gSystem
AliVCaloCells * fCaloCellsFromInputEvent
! pointer to calo cells from the input event
void AdoptClusterContainer(AliClusterContainer *cont)
void SetupConfigurationFilePath(std::string &filename, bool userFile=false)
void UserExec(Option_t *option)
Double_t fMaxCent
max centrality for event selection
Double_t fVertex[3]
!event vertex
TList * fOutput
! Output for histograms
bool fConfigurationInitialized
True if the YAML files are initialized.
static bool doesFileExist(const std::string &filename)
Container for particles within the EMCAL framework.
bool fCreateNewObjectBranches
Create new branches for cells and clusters.
void SetUserConfiguration(YAML::Node &node)
Make copy to ensure that the nodes do not point to each other (?)
bool fEventInitialized
If the event is initialized properly.
void Load()
Definition: UnfoldingHF.C:238
TString fCentEst
name of V0 centrality estimator
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.
float Float_t
Definition: External.C:68
TString fRunPeriod
Run period (passed by user)
Double_t fCent
! Event centrality
BeamType
Switch for the beam type.
AliMCParticleContainer * AddMCParticleContainer(const char *n)
AliVCaloCells * fCaloCells
! pointer to calo cells
std::string fCreatedTrackBranchName
Name of created track branch.
void GetProperty(std::string propertyName, T &property, bool requiredProperty=true, std::string correctionName="")
Retrieve property.
bool WriteConfigurationFile(std::string filename, bool userConfig=false)
Bool_t fNeedEmcalGeom
whether or not the task needs the emcal geometry
std::string fCreatedClusterBranchName
Name of created cluster branch.
Bool_t fUseNewCentralityEstimation
Use new centrality estimation (for 2015 data)
void CopyClusters(TClonesArray *orig, TClonesArray *dest)
std::string fDefaultConfigurationFilename
! Default YAML configuration filename
TObjArray fParticleCollArray
particle/track collection array
TObjArray fClusterCollArray
cluster collection array
void SetDefaultConfiguration(YAML::Node &node)
AliParticleContainer * GetParticleContainer(Int_t i=0) const
void AdoptParticleContainer(AliParticleContainer *cont)
BeamType fBeamType
!event beam type
std::string fCreatedCellBranchName
Name of created cell branch.
Int_t GetRunNumber(TString)
Definition: PlotMuonQA.C:2235
TString fCaloCellsName
name of calo cell collection
const char Option_t
Definition: External.C:48
YAML::Node fDefaultConfiguration
User YAML Configuration.
Int_t fNVertCont
!event vertex number of contributors
static AliEmcalCorrectionComponent * createInstance(std::string const &s)
AliClusterContainer * GetClusterContainer()
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)
AliParticleContainer * AddParticleContainer(const char *n)
Container structure for EMCAL clusters.
Container for MC-true particles within the EMCAL framework.
std::string fUserConfigurationString
Default YAML Configuration.
ClassImp(AliAnalysisTaskCascadeTester) AliAnalysisTaskCascadeTester
TList * OpenFile(const char *fname)
Definition: DrawAnaELoss.C:65
BeamType fForceBeamType
forced beam type