AliPhysics  c2ade29 (c2ade29)
AliAnalysisTaskEmcalJetHPerformance.cxx
Go to the documentation of this file.
1 
6 
7 #include <map>
8 #include <vector>
9 #include <iostream>
10 #include <bitset>
11 
12 #include <TObject.h>
13 #include <TCollection.h>
14 #include <TAxis.h>
15 #include <THnSparse.h>
16 
17 #include <AliAnalysisManager.h>
18 #include <AliInputEventHandler.h>
19 #include <AliLog.h>
20 
21 #include "yaml-cpp/yaml.h"
23 #include "AliTrackContainer.h"
24 #include "AliClusterContainer.h"
25 #include "AliEmcalContainerUtils.h"
26 #include "AliJetContainer.h"
27 #include "AliEmcalJet.h"
28 
30 
32 
33 namespace PWGJE {
34 namespace EMCALJetTasks {
35 
40  AliAnalysisTaskEmcalJet("AliAnalysisTaskEmcalJetHPerformance", kFALSE),
41  fYAMLConfig(),
42  fConfigurationInitialized(false),
43  fHistManager(),
44  fEmbeddingQA(),
45  fCreateQAHists(false),
46  fCreateResponseMatrix(false),
47  fEmbeddedCellsName("emcalCells"),
48  fResponseMatrixFillMap(),
49  fResponseFromThreeJetCollections(true),
50  fMinFractionShared(0.),
51  fLeadingHadronBiasType(AliAnalysisTaskEmcalJetHUtils::kCharged)
52 {
53 }
54 
59  AliAnalysisTaskEmcalJet(name, kTRUE),
60  fYAMLConfig(),
62  fHistManager(name),
63  fEmbeddingQA(),
64  fCreateQAHists(false),
65  fCreateResponseMatrix(false),
66  fEmbeddedCellsName("emcalCells"),
71 {
72  // Ensure that additional general histograms are created
74 }
75 
80  fYAMLConfig(other.fYAMLConfig),
82  fHistManager(other.fHistManager.GetName()),
83  //fEmbeddingQA(other.fEmbeddingQA), // Cannot use because the THistManager (which is in the class) copy constructor is private.
91 {
92  TIter next(other.fHistManager.GetListOfHistograms());
93  TObject* obj = 0;
94  while ((obj = next())) {
95  fHistManager.SetObject(obj, obj->GetName());
96  }
97 }
98 
104 {
105  swap(*this, other);
106  return *this;
107 }
108 
113 {
114  // Base class options
115  // Recycle unused embedded events
116  fYAMLConfig.GetProperty("recycleUnusedEmbeddedEventsMode", fRecycleUnusedEmbeddedEventsMode, false);
117  // Task physics (trigger) selection.
118  std::vector<std::string> physicsSelection;
119  bool res = fYAMLConfig.GetProperty(std::vector<std::string>({"eventCuts", "physicsSelection"}), physicsSelection, false);
120  if (res) {
121  fOfflineTriggerMask = AliEmcalContainerUtils::DeterminePhysicsSelectionFromYAML(physicsSelection);
122  }
123 
124  // Same ordering as in the constructor (for consistency)
125  std::string baseName = "enable";
126  // These are disabled by default.
127  fYAMLConfig.GetProperty({baseName, "QAHists"}, fCreateQAHists, false);
128  fYAMLConfig.GetProperty({baseName, "responseMatrix"}, fCreateResponseMatrix, false);
129 
130  // Event cuts
131  baseName = "eventCuts";
132  // If event cuts are enabled (which they exceptionally are by default), then we want to configure them here.
133  // If the event cuts are explicitly disabled, then we invert that value to enable the AliAnylsisTaskEmcal
134  // builtin event selection.
135  bool tempBool;
136  fYAMLConfig.GetProperty({baseName, "enabled"}, tempBool, false);
137  fUseBuiltinEventSelection = !tempBool;
138  if (fUseBuiltinEventSelection == false) {
139  // Need to include the namespace so that AliDebug will work properly...
140  std::string taskName = "PWGJE::EMCALJetTasks::";
141  taskName += GetName();
142  AliAnalysisTaskEmcalJetHUtils::ConfigureEventCuts(fAliEventCuts, fYAMLConfig, fOfflineTriggerMask, baseName, taskName);
143  }
144 
145  // General task options
146  baseName = "general";
147  fYAMLConfig.GetProperty({baseName, "nCentBins"}, fNcentBins, false);
148 
149  // QA options
150  baseName = "QA";
151  fYAMLConfig.GetProperty({baseName, "cellsName"}, fCaloCellsName, false);
152  // Defaults to "emcalCells" if not set.
153  fYAMLConfig.GetProperty({baseName, "embeddedCellsName"}, fEmbeddedCellsName, false);
154 
155  // Response matrix properties
156  baseName = "responseMatrix";
157  fYAMLConfig.GetProperty({baseName, "useThreeJetCollections"}, fResponseFromThreeJetCollections, false);
158  fYAMLConfig.GetProperty({baseName, "minFractionSharedPt"}, fMinFractionShared, false);
159  std::string hadronBiasStr = "";
160  baseName = "jets";
161  res = fYAMLConfig.GetProperty({baseName, "leadingHadronBiasType"}, hadronBiasStr, false);
162  // Only attempt to set the property if it is retrieved successfully
163  if (res) {
165  }
166 }
167 
172 {
173  std::string baseName = "jets";
174  std::vector <std::string> jetNames = {"hybridLevelJets", "detLevelJets", "partLevelJets", "analysisJets"};
175  for (const auto & jetName : jetNames) {
176  // Retrieve the node just to see if it is exists. If so, then we can proceed
177  YAML::Node node;
178  bool res = fYAMLConfig.GetProperty(std::vector<std::string>({baseName, jetName}), node, false);
179  if (res) {
180  // Retrieve jet container properties
181  std::string collectionName = "", acceptance = "";
182  double R = -1;
183  fYAMLConfig.GetProperty({baseName, jetName, "collection"}, collectionName, true);
184  fYAMLConfig.GetProperty({baseName, jetName, "acceptance"}, acceptance, true);
185  fYAMLConfig.GetProperty({baseName, jetName, "R"}, R, true);
186 
187  // Create jet container and set the name
188  AliDebugStream(1) << "Creating jet from jet collection name " << collectionName << " with acceptance " << acceptance << " and R=" << R << "\n";
189  AliJetContainer * jetCont = AddJetContainer(collectionName.c_str(), acceptance.c_str(), R);
190  jetCont->SetName(jetName.c_str());
191 
192  // Leading hadron type
193  int leadingHadronType = -1;
194  bool res = fYAMLConfig.GetProperty({baseName, jetName, "leadingHadronType"}, leadingHadronType, false);
195  if (res) {
196  AliDebugStream(1) << "Setting leading hadron type of " << leadingHadronType << " for jet cont " << jetName << "\n";
197  jetCont->SetLeadingHadronType(leadingHadronType);
198  }
199  }
200  else {
201  AliInfoStream() << "Unable to find definition of jet container corresponding to \"" << jetName << "\"\n";
202  }
203  }
204 }
205 
210 {
212 
213  // Ensure that we have at least one configuration in the YAML config.
214  if (fYAMLConfig.DoesConfigurationExist(0) == false) {
215  // No configurations exist. Return immediately.
217  }
218 
219  // Always initialize for streaming purposes
221 
222  // Setup task based on the properties defined in the YAML config
223  AliDebugStream(2) << "Configuring task from the YAML configuration.\n";
226  AliDebugStream(2) << "Finished configuring via the YAML configuration.\n";
227 
228  // Print the results of the initialization
229  // Print outside of the ALICE Log system to ensure that it is always available!
230  std::cout << *this;
231 
234 }
235 
240 {
241  // First call the base class
243 
244  // Check that the task was initialized
246  AliFatal("Task was not initialized. Please ensure that Initialize() was called!");
247  }
248  // Reinitialize the YAML configuration
250 
251  // Create histograms
252  if (fCreateQAHists) {
253  SetupQAHists();
254  }
255  if (fCreateResponseMatrix) {
257  }
258 
259  // Store hist manager output in the output list
260  TIter next(fHistManager.GetListOfHistograms());
261  TObject* obj = 0;
262  while ((obj = next())) {
263  fOutput->Add(obj);
264  }
265 
266  // Initialize
268  if (embeddingHelper) {
269  bool res = fEmbeddingQA.Initialize();
270  if (res) {
272  }
273  }
274 
275  // Post the data when finished
276  PostData(1, fOutput);
277 }
278 
286 {
287  std::string name = prefix + "/fHistCellEnergy";
288  std::string title = name + ";\\mathit{E}_{\\mathrm{cell}} (\\mathrm{GeV});counts";
289  fHistManager.CreateTH1(name.c_str(), title.c_str(), 300, 0, 150);
290 
291  name = prefix + "/fHistCellTime";
292  title = name + ";t (s);counts";
293  fHistManager.CreateTH1(name.c_str(), title.c_str(), 1000, -10e-6, 10e-6);
294 
295  name = prefix + "/fHistNCells";
296  title = name + ";\\mathrm{N}_{\\mathrm{cells}};counts";
297  fHistManager.CreateTH1(name.c_str(), title.c_str(), 100, 0, 5000);
298 
299  name = prefix + "/fHistCellID";
300  title = name + ";\\mathrm{N}_{\\mathrm{cell}};counts";
301  fHistManager.CreateTH1(name.c_str(), title.c_str(), 20000, 0, 20000);
302 
303  // Histograms for embedding QA which use the cell timing to determine whether the
304  // embedded event has been double corrected.
305  if (prefix.find("embedding") != std::string::npos) {
306  name = prefix + "/fHistEmbeddedEventUsed";
307  title = name + ";Embedded event used";
308  fHistManager.CreateTH1(name.c_str(), title.c_str(), 2, 0, 2);
309 
310  name = prefix + "/fHistInternalEventSelection";
311  title = name + ";Embedded event used;Trigger bit";
312  fHistManager.CreateTH2(name.c_str(), title.c_str(), 2, 0, 2, 32, -0.5, 31.5);
313  }
314 }
315 
320 {
321  std::string prefix = "QA/";
322  prefix += fCaloCellsName.Data();
324  auto embeddingInstance = AliAnalysisTaskEmcalEmbeddingHelper::GetInstance();
325  if (embeddingInstance) {
326  prefix = "QA/embedding/";
327  prefix += fEmbeddedCellsName;
329  }
330 }
331 
336 {
337  // Cell level QA
339 
340  // Clusters
341  AliEmcalContainer* cont = 0;
342  TIter nextClusColl(&fClusterCollArray);
343  while ((cont = static_cast<AliClusterContainer*>(nextClusColl()))) {
344  // Cluster time vs energy
345  std::string name = "QA/%s/fHistClusterEnergyVsTime";
346  std::string title = name + ";E_{cluster} (GeV);t_{cluster} (s)";
347  fHistManager.CreateTH2(TString::Format(name.c_str(), cont->GetName()), TString::Format(title.c_str(), cont->GetName()), 1000, 0, 100, 300, -300e-9, 300e-9);
348  }
349 
350  // Jets
351  TIter nextJetColl(&fJetCollArray);
352  while ((cont = static_cast<AliJetContainer*>(nextJetColl()))) {
353  // Jet pT
354  std::string name = "QA/%s/fHistJetPt";
355  std::string title = name + ";p_{T} (GeV)";
356  fHistManager.CreateTH1(TString::Format(name.c_str(), cont->GetName()), TString::Format(title.c_str(), cont->GetName()), 500, 0, 250);
357  }
358 }
359 
364 {
365  // Main response matrix THnSparse
366  std::string name = "response/fHistResponseMatrix";
367  std::string title = name;
368 
369  // Retrieve binning from the YAML configuration
370  std::vector<TAxis *> binning;
371  // This structure is designed to preserve the order of the axis in the YAML by using a YAML sequence (decoded into
372  // a vector), while defining a pair of the axis name and axis limts. Using this structure avoids the need to create
373  // a new object and conversion to retrieve the data
374  std::vector<std::pair<std::string, std::vector<double>>> sparseAxes;
375  std::string baseName = "responseMatrix";
376  fYAMLConfig.GetProperty({baseName, "axes"}, sparseAxes, true);
377  for (auto axis : sparseAxes) {
378  auto axisLimits = axis.second;
379  AliDebugStream(3) << "Creating axis " << axis.first << " with nBins " << axisLimits.at(0) << ", min: " << axisLimits.at(1) << ", max: " << axisLimits.at(2) << "\n";
380  binning.emplace_back(new TAxis(axisLimits.at(0), axisLimits.at(1), axisLimits.at(2)));
381  }
382 
383  // "s" ensures that Sumw2() is called
384  // The explicit const_cast is required
385  THnSparse * hist = fHistManager.CreateTHnSparse(name.c_str(), title.c_str(), binning.size(), const_cast<const TAxis **>(binning.data()), "s");
386  // Set the axis titles
387  int axisNumber = 0;
388  for (auto axis = sparseAxes.begin(); axis != sparseAxes.end(); axis++) {
389  AliDebugStream(5) << "ResponseMatrix: Add axis " << axis->first << " to sparse\n";
390  hist->GetAxis(axisNumber)->SetTitle(axis->first.c_str());
391  axisNumber++;
392  }
393 
394  // Define mapping from value name to value (including jet information)
395  for (unsigned int iJet = 1; iJet < 3; iJet++)
396  {
397  // pt
398  // ex: p_{T,1}
399  fResponseMatrixFillMap.insert(std::make_pair(std::string("p_{T,") + std::to_string(iJet) + "}", std::make_pair(iJet, &ResponseMatrixFillWrapper::fPt)));
400  // Area
401  // ex: A_{jet,1}
402  fResponseMatrixFillMap.insert(std::make_pair(std::string("A_{jet,") + std::to_string(iJet) + "}", std::make_pair(iJet, &ResponseMatrixFillWrapper::fArea)));
403  // EP angle
404  // ex: #theta_{jet,1}^{EP}
405  fResponseMatrixFillMap.insert(std::make_pair(std::string("#theta_{jet,") + std::to_string(iJet) + "}^{EP}", std::make_pair(iJet, &ResponseMatrixFillWrapper::fRelativeEPAngle)));
406  // Leading hadron
407  // ex: p_{T,particle,1}^{leading} (GeV/c)
408  fResponseMatrixFillMap.insert(std::make_pair(std::string("p_{T,particle,") + std::to_string(iJet) + "}^{leading} (GeV/c)", std::make_pair(iJet, &ResponseMatrixFillWrapper::fLeadingHadronPt)));
409  }
410  // Distance from one jet to another
411  fResponseMatrixFillMap.insert(std::make_pair("distance", std::make_pair(1, &ResponseMatrixFillWrapper::fDistance)) );
412  // Centrality
413  fResponseMatrixFillMap.insert(std::make_pair("centrality", std::make_pair(1, &ResponseMatrixFillWrapper::fCentrality)) );
414 
415  // Shared momentum fraction
416  name = "fHistFractionSharedPt";
417  title = "Fraction of p_{T} shared between matched jets";
418  // Need to include the bin from 1-1.01 to ensure that jets which shared all of their momentum
419  // due not end up in the overflow bin!
420  fHistManager.CreateTH1(name.c_str(), title.c_str(), 101, 0, 1.01);
421 }
422 
427 {
428  // Only fill the embedding qa plots if:
429  // - We are using the embedding helper
430  // - The class has been initialized
431  if (fEmbeddingQA.IsInitialized()) {
433  }
434 
435  if (fCreateQAHists) {
436  QAHists();
437  }
438  if (fCreateResponseMatrix) {
439  ResponseMatrix();
440  }
441 
442  return kTRUE;
443 }
444 
449 {
450  // No additional processing is necessary
451  // Continue on to filling the histograms
452  FillQAHists();
453 }
454 
462 void AliAnalysisTaskEmcalJetHPerformance::FillCellQAHists(const std::string & prefix, AliVCaloCells * cells)
463 {
464  AliDebugStream(4) << "Storing cells with prefix \"" << prefix << "\". N cells: " << cells->GetNumberOfCells() << "\n";
465  short absId = -1;
466  double eCell = 0;
467  double tCell = 0;
468  double eFrac = 0;
469  int mcLabel = -1;
470 
471  std::string energyName = prefix + "/fHistCellEnergy";
472  std::string timeName = prefix + "/fHistCellTime";
473  std::string idName = prefix + "/fHistCellID";
474  bool embeddedCellWithLateCellTime = false;
475  bool fillingEmbeddedCells = (prefix.find("embedding") != std::string::npos);
476  for (unsigned int iCell = 0; iCell < cells->GetNumberOfCells(); iCell++) {
477  cells->GetCell(iCell, absId, eCell, tCell, mcLabel, eFrac);
478 
479  AliDebugStream(5) << "Cell " << iCell << ": absId: " << absId << ", E: " << eCell << ", t: " << tCell
480  << ", mcLabel: " << mcLabel << ", eFrac: " << eFrac << "\n";
481  fHistManager.FillTH1(energyName.c_str(), eCell);
482  fHistManager.FillTH1(timeName.c_str(), tCell);
483  fHistManager.FillTH1(idName.c_str(), absId);
484 
485  // We will record the event selection if the time is less than -400 ns
486  // This corresponds to a doubly corrected embedded event, which shouldn't be possible, and therefore
487  // indicates that something has gone awry
488  if (tCell < -400e-9 && fillingEmbeddedCells) {
489  embeddedCellWithLateCellTime = true;
490  }
491  }
492 
493  // If we have one embedded cell with late cell time, then we want to fill out the QA to
494  // help identify the event.
495  std::string embeddedEventUsed = prefix + "/fHistEmbeddedEventUsed";
496  std::string embeddedInteranlEventSelection = prefix + "/fHistInternalEventSelection";
497  if (embeddedCellWithLateCellTime)
498  {
499  auto embeddingInstance = AliAnalysisTaskEmcalEmbeddingHelper::GetInstance();
500  if (embeddingInstance) {
501  fHistManager.FillTH1(embeddedEventUsed.c_str(),
502  static_cast<double>(embeddingInstance->EmbeddedEventUsed()));
503 
504  // Determine the physics selection. This isn't quite a perfect way to store it, as it mingles the
505  // selections between different events. But it is simple, which will let us investigate quickly.
506  // Plus, it's a reasonable bet that the event selection when be the same when it goes wrong.
507  UInt_t eventTrigger =
508  ((AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()))
509  ->IsEventSelected();
510  std::bitset<sizeof(UInt_t) * 8> testBits = eventTrigger;
511  std::cout << testBits << "\n";
512  for (unsigned int i = 0; i < 32; i++) {
513  if (testBits.test(i)) {
514  fHistManager.FillTH2(embeddedInteranlEventSelection.c_str(),
515  static_cast<double>(embeddingInstance->EmbeddedEventUsed()), i);
516  }
517  }
518  }
519  }
520 
521  std::string nCellsName = prefix + "/fHistNCells";
522  fHistManager.FillTH1(nCellsName.c_str(), cells->GetNumberOfCells());
523 }
524 
529 {
530  // Fill standard cell QA
531  std::string prefix = "QA/";
532  prefix += fCaloCellsName.Data();
533  FillCellQAHists(prefix, fCaloCells);
534 
535  // Fill embedded cell QA it if's available.
536  auto embeddingInstance = AliAnalysisTaskEmcalEmbeddingHelper::GetInstance();
537  if (embeddingInstance) {
538  auto embeddedCells = dynamic_cast<AliVCaloCells*>(
539  embeddingInstance->GetExternalEvent()->FindListObject(fEmbeddedCellsName.c_str()));
540  if (embeddedCells) {
541  prefix = "QA/embedding/";
542  prefix += fEmbeddedCellsName;
543  FillCellQAHists(prefix, embeddedCells);
544  }
545  }
546 }
547 
552 {
553  FillCellQAHists();
554 
555  // Clusters
556  AliClusterContainer* clusCont = 0;
557  TIter nextClusColl(&fClusterCollArray);
558  AliVCluster * cluster = 0;
559  while ((clusCont = static_cast<AliClusterContainer*>(nextClusColl()))) {
560  for (auto clusIter : clusCont->accepted_momentum())
561  {
562  cluster = clusIter.second;
563  // Intentionally plotting against raw energy
564  fHistManager.FillTH2(TString::Format("QA/%s/fHistClusterEnergyVsTime", clusCont->GetName()), cluster->E(), cluster->GetTOF());
565  }
566  }
567 
568  // Jets
569  AliJetContainer * jetCont = 0;
570  TIter nextJetColl(&fJetCollArray);
571  while ((jetCont = static_cast<AliJetContainer*>(nextJetColl()))) {
572  for (auto jet : jetCont->accepted())
573  {
574  fHistManager.FillTH1(TString::Format("QA/%s/fHistJetPt", jetCont->GetName()), jet->Pt());
575  }
576  }
577 }
578 
583 {
584  AliJetContainer * jetsHybrid = GetJetContainer("hybridLevelJets");
585  AliJetContainer * jetsDetLevel = GetJetContainer("detLevelJets");
586  AliJetContainer * jetsPartLevel = GetJetContainer("partLevelJets");
587  if (!jetsHybrid) {
588  AliErrorStream() << "Could not retrieve hybrid jet collection.\n";
589  return;
590  }
591  if (!jetsDetLevel) {
592  AliErrorStream() << "Could not retrieve det level jet collection.\n";
593  return;
594  }
595  if (fResponseFromThreeJetCollections && !jetsPartLevel) {
596  AliErrorStream() << "Could not retrieve part level jet collection.\n";
597  return;
598  }
599 
600  // Handle matching of jets.
601  for (auto jet1 : jetsHybrid->accepted())
602  {
603  AliDebugStream(4) << "jet1: " << jet1->toString() << "\n";
604  AliDebugStream(4) << "jet1 address: " << jet1 << "\n";
605 
606  // Get jet the det level jet from the hybrid jet
607  AliEmcalJet * jet2 = jet1->ClosestJet();
608  if(!jet2) continue;
609 
610  AliDebugStream(4) << "jet2: " << jet2->toString() << "\n";
611  AliDebugStream(4) << "jet2 address: " << jet2 << "\n";
612 
613  // Check shared fraction
614  double sharedFraction = jetsHybrid->GetFractionSharedPt(jet1);
615  fHistManager.FillTH1("fHistFractionSharedPt", sharedFraction);
616  if (sharedFraction < fMinFractionShared) {
617  AliDebugStream(4) << "Rejecting jet due to momentum fraction of " << sharedFraction << ", smaller than the minimum.\n";
618  continue;
619  }
620  else {
621  AliDebugStream(4) << "Jet passed momentum fraction cut with value of " << sharedFraction << "\n";
622  }
623 
624  // Apply additional selection to jet 2
625  // TODO: Should we apply acceptance criteria to jet 2 here?
626 
627  // Get MC level jet
628  AliEmcalJet * jetToPass = 0;
630  AliEmcalJet * jet3 = jet2->ClosestJet();
631 
632  // Accept jet 3
633  UInt_t rejectionReason = 0;
634  if (!jetsPartLevel->AcceptJet(jet3, rejectionReason)) {
635  // TODO: Store rejection reasons
636  //fHistRejectionReason2->Fill(jets2->GetRejectionReasonBitPosition(rejectionReason), jet2->Pt());
637  continue;
638  }
639 
640  AliDebugStream(4) << "jet3: " << jet3->toString() << "\n";
641  AliDebugStream(4) << "jet3 address: " << jet3 << "\n";
642 
643  // Use for the response
644  AliDebugStream(4) << "Using part level jet for response\n";
645  jetToPass = jet3;
646  }
647  else {
648  // Use for the response
649  AliDebugStream(4) << "Using det level jet for response\n";
650  jetToPass = jet2;
651  }
652 
653  // Fill response
654  FillResponseMatrix(jet1, jetToPass);
655  }
656 
657 }
658 
663 {
664  if (!jet1 || !jet2) {
665  AliErrorStream() << "Null jet passed to fill response matrix";
666  }
667 
668  AliDebugStream(3) << "About to create ResponseMatrixFillWrappers\n";
669  AliDebugStream(4) << "jet1: " << jet1->toString() << "\n";
670  AliDebugStream(4) << "jet2: " << jet2->toString() << "\n";
671  // Create map from jetNumber to jet and initialize the objects
672  std::map<unsigned int, ResponseMatrixFillWrapper> jetNumberToJet = {
673  std::make_pair(1, CreateResponseMatrixFillWrapper(jet1)),
674  std::make_pair(2, CreateResponseMatrixFillWrapper(jet2))
675  };
676 
677  // Fill histograms
678  std::string histName = "response/fHistResponseMatrix";
679  std::vector<double> values;
680  THnSparse * response = static_cast<THnSparse*>(fHistManager.FindObject(histName.c_str()));
681  AliDebugStream(3) << "About to fill response matrix values\n";
682  AliDebugStream(4) << "jet1: " << jet1->toString() << "\n";
683  AliDebugStream(4) << "jet2: " << jet2->toString() << "\n";
684  for (unsigned int i = 0; i < response->GetNdimensions(); i++) {
685  std::string title = response->GetAxis(i)->GetTitle();
686 
687  // Retrieve pair of jet and pointer to extract the fill value
688  auto jetPair = fResponseMatrixFillMap.find(title);
689  if (jetPair != fResponseMatrixFillMap.end()) {
690  auto wrapper = jetNumberToJet.at(jetPair->second.first);
691  auto member = jetPair->second.second;
692  AliDebugStream(4) << "Filling value " << wrapper.*member << " into axis " << title << "\n";
693  values.emplace_back(wrapper.*member);
694  }
695  else {
696  AliWarningStream() << "Unable to fill dimension " << title << "!\n";
697  }
698  }
699 
700  fHistManager.FillTHnSparse(histName.c_str(), values.data());
701 }
702 
707 {
709  if (!jet) {
710  AliErrorStream() << "Must pass valid jet to create object.\n";
711  return wrapper;
712  }
713  wrapper.fPt = jet->Pt();
714  wrapper.fArea = jet->Area();
715  wrapper.fPhi = jet->Phi();
716  wrapper.fDistance = jet->ClosestJetDistance();
717  wrapper.fCentrality = fCent;
720 
721  return wrapper;
722 }
723 
730 {
731  // Get the pointer to the existing analysis manager via the static access method.
732  //==============================================================================
733  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
734  if (!mgr)
735  {
736  AliErrorClass("No analysis manager to connect to.");
737  return nullptr;
738  }
739 
740  // Setup task name
741  std::string taskName = "AliAnalysisTaskEmcalJetHPerformance";
742  std::string suffixName(suffix);
743  if (suffixName != "") {
744  taskName += "_";
745  taskName += suffixName;
746  }
747 
748  // Create task and configure as desired.
750  // Set a few general default.
751  task->SetNCentBins(5);
752  // Configuration is via YAML.
753  mgr->AddTask(task);
754 
755  // Create containers for input/output
756  mgr->ConnectInput(task, 0, mgr->GetCommonInputContainer() );
757  AliAnalysisDataContainer * outputContainer = mgr->CreateContainer(task->GetName(),
758  TList::Class(),
759  AliAnalysisManager::kOutputContainer,
760  Form("%s", AliAnalysisManager::GetCommonFileName()));
761  mgr->ConnectOutput(task, 1, outputContainer);
762 
763  return task;
764 }
765 
772 {
773  std::stringstream tempSS;
774  tempSS << std::boolalpha;
775  tempSS << "Recycle unused embedded events: " << fRecycleUnusedEmbeddedEventsMode << "\n";
776  tempSS << "Jet collections:\n";
777  TIter next(&fJetCollArray);
778  AliJetContainer * jetCont;
779  while ((jetCont = static_cast<AliJetContainer *>(next()))) {
780  tempSS << "\t" << jetCont->GetName() << ": " << jetCont->GetArrayName() << "\n";
781  }
782  tempSS << "AliEventCuts\n";
783  tempSS << "\tEnabled: " << !fUseBuiltinEventSelection << "\n";
784  tempSS << "QA Hists:\n";
785  tempSS << "\tEnabled: " << fCreateQAHists << "\n";
786  tempSS << "Response matrix:\n";
787  tempSS << "\tEnabled: " << fCreateResponseMatrix << "\n";
788  tempSS << "\tConstruct response from 3 jet collections: " << fResponseFromThreeJetCollections << "\n";
789  tempSS << "\tMin fraction shared pt: " << fMinFractionShared << "\n";
790  tempSS << "\tJet leading hadron bias type: " << fLeadingHadronBiasType << "\n";
791  tempSS << "\tResponse matrix fill map: \n";
792  for (auto el : fResponseMatrixFillMap) {
793  tempSS << "\t\tProperty " << el.first << " applied to jet " << el.second.first << "\n";
794  }
795 
796  return tempSS.str();
797 }
798 
805 std::ostream & AliAnalysisTaskEmcalJetHPerformance::Print(std::ostream & in) const {
806  in << toString();
807  return in;
808 }
809 
817 {
818  Printf("%s", toString().c_str());
819 }
820 
821 } /* namespace EMCALJetTasks */
822 } /* namespace PWGJE */
823 
831 std::ostream & operator<<(std::ostream & in, const PWGJE::EMCALJetTasks::AliAnalysisTaskEmcalJetHPerformance & myTask)
832 {
833  std::ostream & result = myTask.Print(in);
834  return result;
835 }
836 
843 {
844  using std::swap;
845 
846  // Same ordering as in the constructors (for consistency)
847  swap(first.fYAMLConfig, second.fYAMLConfig);
849  //swap(first.fHistManager, second.fHistManager); // Skip here, because the THistManager copy constructor is private.
850  //swap(first.fEmbeddingQA, second.fEmbeddingQA); // Skip here, because the THistManager copy constructor is private.
851  swap(first.fCreateQAHists, second.fCreateQAHists);
858 }
Double_t Area() const
Definition: AliEmcalJet.h:130
TObjArray fClusterCollArray
cluster collection array
bool fResponseFromThreeJetCollections
If true, the det level jets in collection 2 are only an intermediate step. They are used to get part ...
const char * title
Definition: MakeQAPdf.C:27
AliEmcalJet * ClosestJet() const
Definition: AliEmcalJet.h:341
AliJetContainer * GetJetContainer(Int_t i=0) const
std::map< std::string, std::pair< int, double ResponseMatrixFillWrapper::* > > fResponseMatrixFillMap
! Map from axis title to pair of (jet number, function to retrieve fill value)
void SetName(const char *n)
Set the name of the class of the objets inside the underlying array.
Double_t ClosestJetDistance() const
Definition: AliEmcalJet.h:342
const AliClusterIterableMomentumContainer accepted_momentum() const
Bool_t fRecycleUnusedEmbeddedEventsMode
Allows the recycling of embedded events which fail internal event selection. See the embedding helper...
void SetLeadingHadronType(Int_t t)
Double_t Phi() const
Definition: AliEmcalJet.h:117
void FillTH2(const char *hname, double x, double y, double weight=1., Option_t *opt="")
Fill a 2D histogram within the container.
double fCentrality
! Centrality of the given jet (an event level property, but useful to here available here) ...
Double_t fEPV0
!event plane V0
Declaration of class AliAnalysisTaskEmcalEmbeddingHelper.
virtual Bool_t AcceptJet(Int_t i, UInt_t &rejectionReason) const
AliJetContainer * AddJetContainer(const char *n, TString defaultCutType, Float_t jetRadius=0.4)
AliAnalysisTaskEmcalJetHPerformance & operator=(AliAnalysisTaskEmcalJetHPerformance other)
bool GetProperty(std::vector< std::string > propertyPath, const std::string &propertyName, T &property, const bool requiredProperty) const
AliEmcalEmbeddingQA fEmbeddingQA
! Embedding QA hists (will only be added if embedding).
void SetObject(TObject *const o, const char *group="/")
Set a new group into the container into the parent group.
ResponseMatrixFillWrapper CreateResponseMatrixFillWrapper(AliEmcalJet *jet) const
PWG::Tools::AliYAMLConfiguration fYAMLConfig
YAML configuration file.
bool fCreateResponseMatrix
If true, create a response matrix with the available jet collections.
Bool_t fUseBuiltinEventSelection
Use builtin event selection of the AliAnalysisTaskEmcal instead of AliEventCuts.
bool DoesConfigurationExist(const int i) const
bool AddQAPlotsToList(TList *list)
std::string fEmbeddedCellsName
Set the embedded cells collection name.
AliAnalysisTaskEmcalJetHUtils::ELeadingHadronBiasType_t fLeadingHadronBiasType
Leading hadron in jet bias type (either charged, neutral, or both)
static void ConfigureEventCuts(AliEventCuts &eventCuts, PWG::Tools::AliYAMLConfiguration &yamlConfig, const UInt_t offlineTriggerMask, const std::string &baseName, const std::string &taskName)
void FillTHnSparse(const char *name, const double *x, double weight=1., Option_t *opt="")
bool IsInitialized() const
TH2 * CreateTH2(const char *name, const char *title, int nbinsx, double xmin, double xmax, int nbinsy, double ymin, double ymax, Option_t *opt="")
Create a new TH2 within the container.
static UInt_t DeterminePhysicsSelectionFromYAML(const std::vector< std::string > &selections)
TObject * FindObject(const char *name) const
Find an object inside the container.
bool fConfigurationInitialized
True if the task configuration has been successfully initialized.
unsigned int UInt_t
Definition: External.C:33
THashList * GetListOfHistograms() const
Get the list of histograms.
Definition: THistManager.h:671
Implementation of task to embed external events.
TString toString() const
TH1 * CreateTH1(const char *name, const char *title, int nbins, double xmin, double xmax, Option_t *opt="")
Create a new TH1 within the container.
Int_t fNcentBins
how many centrality bins
Base class for container structures within the EMCAL framework.
Double_t fCent
!event centrality
TString fCaloCellsName
name of calo cell collection
void FillTH1(const char *hname, double x, double weight=1., Option_t *opt="")
Fill a 1D histogram within the container.
static AliAnalysisTaskEmcalJetHPerformance * AddTaskEmcalJetHPerformance(const char *suffix="")
static double RelativeEPAngle(double jetAngle, double epAngle)
TObjArray fJetCollArray
jet collection array
virtual void SetNCentBins(Int_t n)
AliVCaloCells * fCaloCells
!cells
static double GetLeadingHadronPt(AliEmcalJet *jet, ELeadingHadronBiasType_t leadingHadronType)
Double_t Pt() const
Definition: AliEmcalJet.h:109
const TString & GetArrayName() const
const char * GetName() const
AliEventCuts fAliEventCuts
Event cuts (run2 defaults)
AliEmcalList * fOutput
!output list
void SetMakeGeneralHistograms(Bool_t g)
Enable general histograms.
Base task in the EMCAL jet framework.
Represent a jet reconstructed using the EMCal jet framework.
Definition: AliEmcalJet.h:51
Double_t GetFractionSharedPt(const AliEmcalJet *jet, AliParticleContainer *cont2=0x0) const
const char Option_t
Definition: External.C:48
void UserCreateOutputObjects()
Main initialization function on the worker.
const AliJetIterableContainer accepted() const
bool Bool_t
Definition: External.C:53
THnSparse * CreateTHnSparse(const char *name, const char *title, int ndim, const int *nbins, const double *min, const double *max, Option_t *opt="")
Create a new THnSparse within the container.
Container structure for EMCAL clusters.
void swap(PWGJE::EMCALJetTasks::AliAnalysisTaskEmcalJetHPerformance &first, PWGJE::EMCALJetTasks::AliAnalysisTaskEmcalJetHPerformance &second)
double fMinFractionShared
Minimum fraction of shared jet pt required for matching a hybrid jet to detector level.
Container for jet within the EMCAL jet framework.
static const std::map< std::string, ELeadingHadronBiasType_t > fgkLeadingHadronBiasMap
! Map from name to leading hadron bias used with the YAML config
friend std::ostream & operator<<(std::ostream &in, const AliAnalysisTaskEmcalJetHPerformance &myTask)
static const AliAnalysisTaskEmcalEmbeddingHelper * GetInstance()