AliPhysics  32b88a8 (32b88a8)
 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  // Note that it is initialized properly so that the analysis can proceed
291 }
292 
301 {
302  bool returnValue = false;
303  if (filename != "")
304  {
305  if (fConfigurationInitialized == true)
306  {
307  std::ofstream outFile(filename);
308  std::string stringToWrite = userConfig ? fUserConfigurationString : fDefaultConfigurationString;
309  if (stringToWrite == "") {
310  AliWarning(TString::Format("%s configuration is empty!", userConfig ? "User" : "Default"));
311  }
312  outFile << stringToWrite;
313  outFile.close();
314 
315  returnValue = true;
316  }
317  else
318  {
319  AliWarning(TString::Format("Configuration not properly initialized! Cnanot print %s configuration!", userConfig ? "user" : "default"));
320  }
321 
322  }
323  else
324  {
325  AliWarning("Please pass a valid filename instead of empty qutoes!");
326  }
327  return returnValue;
328 }
329 
330 
335 void AliEmcalCorrectionTask::RetrieveExecutionOrder(std::vector <std::string> & executionOrder)
336 {
338  // Need to append "AliEmcalCorrection" to allow the tasks to be found!
339  AliDebug(2, "Creating EMCal Correction Components: ");
340  for (auto & component : executionOrder)
341  {
342  component = "AliEmcalCorrection" + component;
343  AliDebug(2, TString::Format("%s", component.c_str()) );
344  }
345 }
346 
352 {
353  // YAML Objects cannot be streamed, so we need to reinitialize them here.
354  // They need reinitialize if they are null
355  if (fUserConfiguration.IsNull() == true && fUserConfigurationString != "")
356  {
357  AliInfo(TString::Format("%s: Reinitializing user configuration from string. Expected if running on grid!", GetName()));
359  }
360  if (fDefaultConfiguration.IsNull() == true)
361  {
362  AliInfo(TString::Format("%s: Reinitializing default configuration from string. Expected if running on grid!", GetName()));
364  }
365 
366  // Create a function to handle creation and configuration of the all of the created module
367  std::vector<std::string> executionOrder;
368  RetrieveExecutionOrder(executionOrder);
369 
370  // Allow for output files
371  OpenFile(1);
372  fOutput = new TList();
373  fOutput->SetOwner();
374 
375  // Iterate over the list
376  AliEmcalCorrectionComponent * component = 0;
377  bool componentEnabled = false;
378  for (auto componentName : executionOrder)
379  {
380  componentEnabled = false;
381  AliEmcalCorrectionComponent::GetProperty("enabled", componentEnabled, fUserConfiguration, fDefaultConfiguration, true, componentName);
382  if (componentEnabled == false)
383  {
384  AliInfo(TString::Format("%s: Component %s is disabled and will not be run!", GetName(), componentName.c_str()));
385  continue;
386  }
387 
388  //Printf("Attempting to add task: %s", tempString->GetString().Data());
389  component = AliEmcalCorrectionComponentFactory::createInstance(componentName);
390  if (!component)
391  {
392  AliFatal(TString::Format("%s: Failed to create requested component %s!", GetName(), componentName.c_str()));
393  }
394 
395  // For setting names of tasks to differentiate between tasks of the same class
396  component->SetName(componentName.c_str());
397  component->SetTitle(componentName.c_str());
398 
399  // Initialize the YAML configurations in each component
402 
403  // configure needed fields for components to properly initialize
404  component->SetNcentralityBins(fNcentBins);
405 
406  // Initialize each component
407  component->Initialize();
408 
409  // Attempt to retrieve any containers they may have created in initialization
410  AliClusterContainer * tempClusterContainer = component->GetClusterContainer();
411  if (tempClusterContainer)
412  {
413  AdoptClusterContainer(tempClusterContainer);
414  }
415 
416  AliParticleContainer * tempParticleContainer = component->GetParticleContainer();
417  if (tempParticleContainer)
418  {
419  AdoptParticleContainer(tempParticleContainer);
420  }
421 
422  if (component)
423  {
424  AliInfo(TString::Format("Successfully added correction task: %s", componentName.c_str()));
425  fCorrectionComponents.push_back(component);
426  }
427 
428  if (component->GetOutputList() != 0)
429  {
430  // Adds a list to the list -- this doesn't work for some unknown reason
431  //fOutput->Add(component->GetOutputList());
432 
433  // iterate through lists for each component, and fill in output
434  TList* t = new TList();
435  t->SetName(componentName.c_str());
436  fOutput->AddLast(t);
437  t = (TList*)fOutput->Last();
438  TIter next(component->GetOutputList());
439  while (TObject *obj = next()){
440  t->Add(obj);
441  }
442 
443  AliDebug(1, TString::Format("Added output list from task %s to output.", componentName.c_str()));
444  }
445  }
446 
447  PostData(1, fOutput);
448 
449  // Just printing in order is probably better
450  // Available components
451  /*AliEmcalCorrectionComponentFactory::map_type * availableComponents = AliEmcalCorrectionComponentFactory::getMap();
452 
453  // Need to sort by execution order
454  Printf("Correction Components:");
455  bool availableFlag = false;
456  for (AliEmcalCorrectionComponentFactory::map_type::const_iterator it = availableComponents->begin(); it != availableComponents->end(); ++it)
457  {
458  if (fCorrectionComponents.FindObject(it->first.c_str()))
459  {
460  availableFlag = true;
461  }
462 
463  Printf("%s:\t(%s)", it->first.c_str(), availableFlag ? "Enabled" : "Disabled");
464 
465  availableFlag = false;
466  }*/
467 }
468 
474 {
475  AliDebug(3, Form("%s", __PRETTY_FUNCTION__));
476 
477  // Determine file type
478  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
479  if (mgr) {
480  AliVEventHandler *evhand = mgr->GetInputEventHandler();
481  if (evhand) {
482  if (evhand->InheritsFrom("AliESDInputHandler")) {
483  fIsEsd = true;
484  }
485  else {
486  fIsEsd = false;
487  }
488  }
489  else {
490  AliError("Event handler not found!");
491  }
492  }
493  else {
494  AliError("Analysis manager not found!");
495  }
496 
497  // Initialize the components
498  //InitializeConfiguration();
499  if (fConfigurationInitialized != true)
500  {
501  AliFatal(TString::Format("%s: YAML configuration must be initialized before running (ie. the AddTask, run macro or wagon)!", GetName()));
502  }
503 
504  // Retrieve cells name from configruation
505  std::string cellsName = "";
507  if (cellsName == "usedefault") {
509  }
510  fCaloCellsName = cellsName;
511 
512  if (fForceBeamType == kpp)
513  fNcentBins = 1;
514 
516 }
517 
523 {
524  // Run the initialization for all derived classes.
525  AliDebug(3, Form("%s", __PRETTY_FUNCTION__));
526  for (auto component : fCorrectionComponents)
527  {
528  component->ExecOnce();
529  }
530 }
531 
537 {
538  // Create new cluster branch
539  // Clusterizer is used since it is the first place that clusters are used.
541 
542  // Check to ensure that we are not trying to create a new branch on top of the old branch
543  TClonesArray * existingArray = dynamic_cast<TClonesArray *>(InputEvent()->FindListObject(fCreatedClusterBranchName.c_str()));
544  if (existingArray) {
545  AliFatal(TString::Format("%s: Attempted to create a new cluster branch, \"%s\", with the same name as an existing branch!", GetName(), fCreatedClusterBranchName.c_str()));
546  }
547 
548  // Create new branch and add it to the event
549  TClonesArray * newClusters = 0;
550  if (fIsEsd) {
551  newClusters = new TClonesArray("AliESDCaloCluster");
552  }
553  else {
554  newClusters = new TClonesArray("AliAODCaloCluster");
555  }
556  newClusters->SetName(fCreatedClusterBranchName.c_str());
557  InputEvent()->AddObject(newClusters);
558 
559  // Create new tracks branch
560  // ClusterTrackMatcher is used since it is the first place that tracks are used.
562 
563  // Check to ensure that we are not trying to create a new branch on top of the old branch
564  existingArray = dynamic_cast<TClonesArray *>(InputEvent()->FindListObject(fCreatedTrackBranchName.c_str()));
565  if (existingArray) {
566  AliFatal(TString::Format("%s: Attempted to create a new track branch, \"%s\", with the same name as existing branch!", GetName(), fCreatedTrackBranchName.c_str()));
567  }
568 
569  // Create new branch and add it to the event
570  TClonesArray * newTracks = 0;
571  if (fIsEsd) {
572  newTracks = new TClonesArray("AliESDtrack");
573  }
574  else {
575  newTracks = new TClonesArray("AliAODTrack");
576  }
577  newTracks->SetName(fCreatedTrackBranchName.c_str());
578  InputEvent()->AddObject(newTracks);
579 }
580 
586 {
587  // Cells
588  // TODO: Handle ESD
589  AliDebug(3, Form("Number of old cells: %d", fCaloCellsFromInputEvent->GetNumberOfCells()));
590  // The function CopyCaloCells() does not work!!!
591  if (fIsEsd)
592  {
593  AliESDCaloCells * tempCells = dynamic_cast<AliESDCaloCells *>(fCaloCellsFromInputEvent);
594  fCaloCells = new AliESDCaloCells(*tempCells);
595  }
596  else
597  {
598  AliAODCaloCells * tempCells = dynamic_cast<AliAODCaloCells *>(fCaloCellsFromInputEvent);
599  fCaloCells = new AliAODCaloCells(*tempCells);
600  }
601  AliDebug(3, Form("Number of old cells: %d \tNumber of new cells: %d", fCaloCellsFromInputEvent->GetNumberOfCells(), fCaloCells->GetNumberOfCells() ));
602 
603  // Clusters
604  TClonesArray * newClusters = dynamic_cast<TClonesArray *>(InputEvent()->FindListObject(fCreatedClusterBranchName.c_str()));
606  TClonesArray * currentClusters = dynamic_cast<TClonesArray *>(InputEvent()->FindListObject(currentClustersName.c_str()));
607  AliDebug(3, Form("before copy:\t currentClusters->GetEntries(): %d \t newClusters->GetEntries(): %d", currentClusters->GetEntries(), newClusters->GetEntries()));
608  CopyClusters(currentClusters, newClusters);
609  AliDebug(3, Form("after copy:\t currentClusters->GetEntries(): %d \t newClusters->GetEntries(): %d", currentClusters->GetEntries(), newClusters->GetEntries()));
610 
611  // Tracks
612  TClonesArray * newTracks = dynamic_cast<TClonesArray *>(InputEvent()->FindListObject(fCreatedTrackBranchName.c_str()));
614  TClonesArray * currentTracks = dynamic_cast<TClonesArray *>(InputEvent()->FindListObject(currentTracksName.c_str()));
615  AliDebug(3, Form("before copy:\t currentTracks->GetEntries(): %d \t newTracks->GetEntries(): %d", currentTracks->GetEntries(), newTracks->GetEntries()));
616  for (Int_t i = 0; i < currentTracks->GetEntriesFast(); i++)
617  {
618  // TODO: Will the assignment operator work right with AliVTrack?
619  if (fIsEsd)
620  {
621  AliESDtrack *currentTrack = dynamic_cast<AliESDtrack *>(currentTracks->At(i));
622  // Calls copy constructor to create a new track at position i in newTracks
623  AliESDtrack *newTrack = dynamic_cast<AliESDtrack *>(new ((*newTracks)[i]) AliESDtrack(*currentTrack));
624 
625  // Assign new process ID so that it is from the current process as opposed to the old one copied from the current track
626  TProcessID::AssignID(newTrack);
627  }
628  else
629  {
630  AliAODTrack *currentTrack = dynamic_cast<AliAODTrack *>(currentTracks->At(i));
631  // Calls copy constructor to create a new track at position i in newTracks
632  AliAODTrack *newTrack = dynamic_cast<AliAODTrack *>(new ((*newTracks)[i]) AliAODTrack(*currentTrack));
633 
634  // TEMP
635  /*if (i == 5 || i == 7)
636  {
637  std::cout << "Track properties:" << std::endl;
638  currentTrack->Print();
639  newTrack->Print();
640  std::cout << "ProcessID for current track: " << TProcessID::GetProcessWithUID(currentTrack)->GetName() << "/" << TProcessID::GetProcessWithUID(currentTrack)->GetTitle() << ". Memory Address: " << TProcessID::GetProcessWithUID(currentTrack) << std::endl;
641  std::cout << "ProcessID for new track: " << TProcessID::GetProcessWithUID(newTrack)->GetName() << "/" << TProcessID::GetProcessWithUID(newTrack)->GetTitle() << ". Memory Address: " << TProcessID::GetProcessWithUID(newTrack) << std::endl;
642  }*/
643 
644  // Assign new process ID so that it is from the current process as opposed to the old one copied from the current track
645  TProcessID::AssignID(newTrack);
646 
647  /*if (i == 5 || i == 7)
648  {
649  std::cout << "ProcessID for new track after assign ID: " << TProcessID::GetProcessWithUID(newTrack)->GetName() << "/" << TProcessID::GetProcessWithUID(newTrack)->GetTitle() << ". Memory Address: " << TProcessID::GetProcessWithUID(newTrack) << std::endl;
650  std::cout << "ProcessID for newTracks: " << TProcessID::GetProcessWithUID(newTracks)->GetName() << "/" << TProcessID::GetProcessWithUID(newTracks)->GetTitle() << ". Memory Address: " << TProcessID::GetProcessWithUID(newTracks) << std::endl;
651  }*/
652  }
653  }
654  AliDebug(3, Form("after copy:\t currentTracks->GetEntries(): %d \t newTracks->GetEntries(): %d", currentTracks->GetEntries(), newTracks->GetEntries()));
655 }
656 
661 void AliEmcalCorrectionTask::CopyClusters(TClonesArray *orig, TClonesArray *dest)
662 {
663  const Int_t Ncls = orig->GetEntries();
664 
665  for(Int_t i=0; i < Ncls; ++i) {
666  AliVCluster *oc = static_cast<AliVCluster*>(orig->At(i));
667 
668  if (!oc)
669  continue;
670 
671  // We likely want to include PHOS cells as well, so the copy we make should avoid this check
672  //if (!oc->IsEMCAL())
673  // continue;
674 
675  AliVCluster *dc = static_cast<AliVCluster*>(dest->New(i));
676  //dc->SetType(AliVCluster::kEMCALClusterv1);
677  dc->SetType(oc->GetType());
678  dc->SetE(oc->E());
679  Float_t pos[3] = {0};
680  oc->GetPosition(pos);
681  dc->SetPosition(pos);
682  dc->SetNCells(oc->GetNCells());
683  dc->SetCellsAbsId(oc->GetCellsAbsId());
684  dc->SetCellsAmplitudeFraction(oc->GetCellsAmplitudeFraction());
685  dc->SetID(oc->GetID());
686  dc->SetDispersion(oc->GetDispersion());
687  dc->SetEmcCpvDistance(-1);
688  dc->SetChi2(-1);
689  dc->SetTOF(oc->GetTOF()); //time-of-flight
690  dc->SetNExMax(oc->GetNExMax()); //number of local maxima
691  dc->SetM02(oc->GetM02());
692  dc->SetM20(oc->GetM20());
693  dc->SetDistanceToBadChannel(oc->GetDistanceToBadChannel());
694  dc->SetMCEnergyFraction(oc->GetMCEnergyFraction());
695 
696  //MC
697  UInt_t nlabels = oc->GetNLabels();
698  Int_t *labels = oc->GetLabels();
699 
700  if (nlabels == 0 || !labels)
701  continue;
702 
703  AliESDCaloCluster *esdClus = dynamic_cast<AliESDCaloCluster*>(dc);
704  if (esdClus) {
705  TArrayI parents(nlabels, labels);
706  esdClus->AddLabels(parents);
707  }
708  else {
709  AliAODCaloCluster *aodClus = dynamic_cast<AliAODCaloCluster*>(dc);
710  if (aodClus)
711  aodClus->SetLabel(labels, nlabels);
712  }
713  }
714 }
715 
721 {
722  // This is a redundant check, strictly speaking, but it seems prudent to ensure
723  // that the CaloCells from an event are not deleted!
725  {
726  // We do this because we created a copy in CreateNewObjectBranches()
727  delete fCaloCells;
728  }
729 }
730 
736 {
737  fVertex[0] = 0;
738  fVertex[1] = 0;
739  fVertex[2] = 0;
740  fNVertCont = 0;
741 
742  const AliVVertex *vert = InputEvent()->GetPrimaryVertex();
743  if (vert) {
744  vert->GetXYZ(fVertex);
745  fNVertCont = vert->GetNContributors();
746  }
747 
749 
750  if (fBeamType == kAA || fBeamType == kpA ) {
752  AliMultSelection *MultSelection = static_cast<AliMultSelection*>(InputEvent()->FindListObject("MultSelection"));
753  if (MultSelection) {
754  fCent = MultSelection->GetMultiplicityPercentile(fCentEst.Data());
755  }
756  else {
757  AliWarning(Form("%s: Could not retrieve centrality information! Assuming 99", GetName()));
758  }
759  }
760  else { // old centrality estimation < 2015
761  AliCentrality *aliCent = InputEvent()->GetCentrality();
762  if (aliCent) {
763  fCent = aliCent->GetCentralityPercentile(fCentEst.Data());
764  }
765  else {
766  AliWarning(Form("%s: Could not retrieve centrality information! Assuming 99", GetName()));
767  }
768  }
769 
770  if (fNcentBins==4) {
771  if (fCent >= 0 && fCent < 10) fCentBin = 0;
772  else if (fCent >= 10 && fCent < 30) fCentBin = 1;
773  else if (fCent >= 30 && fCent < 50) fCentBin = 2;
774  else if (fCent >= 50 && fCent <= 100) fCentBin = 3;
775  else {
776  AliWarning(Form("%s: Negative centrality: %f. Assuming 99", GetName(), fCent));
777  fCentBin = fNcentBins-1;
778  }
779  }
780  else if (fNcentBins==5) { // for PbPb 2015
781  if (fCent >= 0 && fCent < 10) fCentBin = 0;
782  else if (fCent >= 10 && fCent < 30) fCentBin = 1;
783  else if (fCent >= 30 && fCent < 50) fCentBin = 2;
784  else if (fCent >= 50 && fCent <= 90) fCentBin = 3;
785  else if (fCent > 90) {
786  fCent = 99;
787  fCentBin = 4;
788  }
789  else {
790  AliWarning(Form("%s: Negative centrality: %f. Assuming 99", GetName(), fCent));
791  fCentBin = fNcentBins-1;
792  }
793  }
794  else {
796  if(centWidth>0.) {
797  fCentBin = TMath::FloorNint(fCent/centWidth);
798  }
799  else {
800  fCentBin = 0;
801  }
802  if (fCentBin>=fNcentBins) {
803  AliWarning(Form("%s: fCentBin too large: cent = %f fCentBin = %d. Assuming 99", GetName(),fCent,fCentBin));
804  fCentBin = fNcentBins-1;
805  }
806  }
807  }
808  else {
809  fCent = 99;
810  fCentBin = 0;
811  }
812 
813  AliEmcalContainer* cont = 0;
814 
815  TIter nextPartColl(&fParticleCollArray);
816  while ((cont = static_cast<AliEmcalContainer*>(nextPartColl()))) cont->NextEvent();
817 
818  TIter nextClusColl(&fClusterCollArray);
819  while ((cont = static_cast<AliEmcalContainer*>(nextClusColl()))) cont->NextEvent();
820 
821  return kTRUE;
822 }
823 
824 
836 {
837  if (!InputEvent()) {
838  AliError(Form("%s: Could not retrieve event! Returning!", GetName()));
839  return;
840  }
841 
842  if (fNeedEmcalGeom) {
843  fGeom = AliEMCALGeometry::GetInstanceFromRunNumber(InputEvent()->GetRunNumber());
844  if (!fGeom) {
845  AliFatal(Form("%s: Can not get EMCal geometry instance. If you do not need the EMCal geometry, disable it by setting task->SetNeedEmcalGeometry(kF ALSE).", GetName()));
846  return;
847  }
848  }
849 
850  // Create the new object branch here.
851  // The cell pointer already exists. All we need to do is load it later.
854 
855  // Load all requested track branches - each container knows name already
856  for (Int_t i =0; i<fParticleCollArray.GetEntriesFast(); i++) {
857  AliParticleContainer *cont = static_cast<AliParticleContainer*>(fParticleCollArray.At(i));
858  cont->SetArray(InputEvent());
859  }
860 
861  // Load all requested cluster branches - each container knows name already
862  for (Int_t i =0; i<fClusterCollArray.GetEntriesFast(); i++) {
863  AliClusterContainer *cont = static_cast<AliClusterContainer*>(fClusterCollArray.At(i));
864  cont->SetArray(InputEvent());
865  }
866 
867  if (!fCaloCellsName.IsNull() && !fCaloCellsFromInputEvent) {
868  fCaloCellsFromInputEvent = dynamic_cast<AliVCaloCells*>(InputEvent()->FindListObject(fCaloCellsName));
870  AliError(Form("%s: Could not retrieve cells %s!", GetName(), fCaloCellsName.Data()));
871  return;
872  }
873  }
874 
875  fEventInitialized = kTRUE;
876 
878 }
879 
888 {
889  if (TString(n).IsNull()) return 0;
890 
892 
893  fParticleCollArray.Add(cont);
894 
895  return cont;
896 }
897 
906 {
907  if (TString(n).IsNull()) return 0;
908 
909  AliTrackContainer* cont = new AliTrackContainer(n);
910 
911  fParticleCollArray.Add(cont);
912 
913  return cont;
914 }
915 
924 {
925  if (TString(n).IsNull()) return 0;
926 
928 
929  fParticleCollArray.Add(cont);
930 
931  return cont;
932 }
933 
942 {
943  if (TString(n).IsNull()) return 0;
944 
946 
947  fClusterCollArray.Add(cont);
948 
949  return cont;
950 }
951 
958 {
959  if (i<0 || i>fParticleCollArray.GetEntriesFast()) return 0;
960  AliParticleContainer *cont = static_cast<AliParticleContainer*>(fParticleCollArray.At(i));
961  return cont;
962 }
963 
970 {
971  if (i<0 || i>fClusterCollArray.GetEntriesFast()) return 0;
972  AliClusterContainer *cont = static_cast<AliClusterContainer*>(fClusterCollArray.At(i));
973  return cont;
974 }
975 
982 {
983  AliParticleContainer *cont = static_cast<AliParticleContainer*>(fParticleCollArray.FindObject(name));
984  return cont;
985 }
986 
993 {
994  AliClusterContainer *cont = static_cast<AliClusterContainer*>(fClusterCollArray.FindObject(name));
995  return cont;
996 }
997 
998 
999 
1005 {
1006  AliDebug(3, Form("%s", __PRETTY_FUNCTION__));
1007 
1008  // Initialize the event if not intialized
1009  if (!fEventInitialized)
1010  ExecOnce();
1011 
1012  // Only continue if we are initialized successfully
1013  if (!fEventInitialized)
1014  return;
1015 
1016  // Copy cells and cluster to new branches if desired
1018  {
1020  }
1021  else
1022  {
1024  }
1025 
1026  // Get the objects for each event
1027  if (!RetrieveEventObjects())
1028  return;
1029 
1030  // TODO: Consider adding IsEventSelected()??
1031 
1032  // Call run for each correction
1033  if (!Run())
1034  return;
1035 
1038 }
1039 
1045 {
1046  // Run the initialization for all derived classes.
1047  AliDebug(3, Form("%s", __PRETTY_FUNCTION__));
1048  for (auto component : fCorrectionComponents)
1049  {
1050  component->SetEvent(InputEvent());
1051  component->SetMCEvent(MCEvent());
1052  component->SetCaloCells(fCaloCells);
1053  component->SetEMCALGeometry(fGeom);
1054  component->SetCentralityBin(fCentBin);
1055  component->SetCentrality(fCent);
1056  component->SetNcentralityBins(fNcentBins);
1057  AliClusterContainer * tempClusterContainer = GetClusterContainer(component->GetName());
1058  if (tempClusterContainer)
1059  {
1060  component->SetClusterContainer(tempClusterContainer);
1061  }
1062  AliParticleContainer * tempParticleContainer = GetParticleContainer(component->GetName());
1063  if (tempParticleContainer)
1064  {
1065  // TEMP
1066  //Printf("Particle container name: %s, branch: %s", tempParticleContainer->GetName(), tempParticleContainer->GetArrayName().Data());
1067  component->SetParticleContainer(tempParticleContainer);
1068  }
1069 
1070  component->Run();
1071  }
1072 
1073  PostData(1, fOutput);
1074 
1075  // Need something more sophisticated here
1076  return kTRUE;
1077 }
1078 
1084 {
1085  // Run the initialization for all derived classes.
1086  AliDebug(3, Form("%s", __PRETTY_FUNCTION__));
1087  for (auto component : fCorrectionComponents)
1088  {
1089  component->UserNotify();
1090  }
1091 
1092  // Need something more sophisticated here
1093  return kTRUE;
1094 }
1095 
1101 {
1102  // Destructor
1103 }
1104 
1111 {
1112  if (fForceBeamType != kNA)
1113  return fForceBeamType;
1114 
1115  AliESDEvent *esd = dynamic_cast<AliESDEvent*>(InputEvent());
1116  if (esd) {
1117  const AliESDRun *run = esd->GetESDRun();
1118  TString beamType = run->GetBeamType();
1119  if (beamType == "p-p")
1120  return kpp;
1121  else if (beamType == "A-A")
1122  return kAA;
1123  else if (beamType == "p-A")
1124  return kpA;
1125  else
1126  return kNA;
1127  } else {
1128  Int_t runNumber = InputEvent()->GetRunNumber();
1129  if ((runNumber >= 136851 && runNumber <= 139517) || // LHC10h
1130  (runNumber >= 166529 && runNumber <= 170593)) { // LHC11h
1131  return kAA;
1132  } else if ((runNumber>=188365 && runNumber <= 188366) || // LHC12g
1133  (runNumber >= 195344 && runNumber <= 196608)) { // LHC13b-f
1134  return kpA;
1135  } else {
1136  return kpp;
1137  }
1138  }
1139 }
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)
ClassImp(AliAnalysisTaskCRC) AliAnalysisTaskCRC
AliParticleContainer * GetParticleContainer(Int_t i=0) const
void AdoptParticleContainer(AliParticleContainer *cont)
BeamType fBeamType
!event beam type
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.
TList * OpenFile(const char *fname)
Definition: DrawAnaELoss.C:65
BeamType fForceBeamType
forced beam type