AliPhysics  720d1f3 (720d1f3)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliAnalysisTaskDmesonJetsDetectorResponse.cxx
Go to the documentation of this file.
1 /*************************************************************************
2 * Copyright(c) 1998-2016, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15 
16 #include "AliAnalysisManager.h"
17 #include "AliVEventHandler.h"
18 #include "AliMCEventHandler.h"
19 #include "AliHFTrackContainer.h"
21 
23 
24 // Definitions of class AliAnalysisTaskDmesonJetsDetectorResponse::AliDmesonMatchInfoSummary
25 
29 
30 // Definitions of class AliAnalysisTaskDmesonJetsDetectorResponse::AliD0MatchInfoSummary
31 
35 
38 {
39  fGenerated.Reset();
40  fReconstructed.Reset();
41 }
42 
47 {
48  fReconstructed.Set(reco);
49 }
50 
55 {
56  fGenerated.Set(truth);
57 }
58 
59 // Definitions of class AliAnalysisTaskDmesonJetsDetectorResponse::AliDStarMatchInfoSummary
60 
64 
67 {
68  fGenerated.Reset();
69  fReconstructed.Reset();
70 }
71 
76 {
77  fReconstructed.Set(reco);
78 }
79 
84 {
85  fGenerated.Set(truth);
86 }
87 
88 // Definitions of class AliAnalysisTaskDmesonJetsDetectorResponse::ResponseEngine
89 
93 
96  TObject(),
97  fCandidateType(kD0toKpi),
98  fInhibit(kFALSE),
99  fMaxJetDmesonDistance(0),
100  fName(),
101  fTree(0),
102  fCurrentDmeson(0),
103  fCurrentJetInfoReco(0),
104  fCurrentJetInfoTruth(0),
105  fDataSlotNumber(-1),
106  fRecontructed(0),
107  fGenerated(0)
108 {
109 
110 }
111 
116  TObject(),
117  fCandidateType(type),
118  fInhibit(kFALSE),
119  fMaxJetDmesonDistance(1),
120  fName(),
121  fTree(0),
122  fCurrentDmeson(0),
123  fCurrentJetInfoReco(0),
124  fCurrentJetInfoTruth(0),
125  fDataSlotNumber(-1),
126  fRecontructed(0),
127  fGenerated(0)
128 {
129 
130 }
131 
136  TObject(source),
137  fCandidateType(source.fCandidateType),
138  fInhibit(source.fInhibit),
139  fMaxJetDmesonDistance(1),
140  fName(source.fName),
141  fTree(0),
142  fCurrentDmeson(0),
143  fCurrentJetInfoReco(0),
144  fCurrentJetInfoTruth(0),
145  fDataSlotNumber(source.fDataSlotNumber),
146  fRecontructed(source.fRecontructed),
147  fGenerated(source.fGenerated)
148 {
149 }
150 
155 {
156  new (this) ResponseEngine(source);
157  return *this;
158 }
159 
164 {
165  fInhibit = (fRecontructed == 0 || fGenerated == 0);
166  fName = fRecontructed->GetCandidateName();
167  return !fInhibit;
168 }
169 
172 {
173 
174 }
175 
181 {
182  TString classname;
183  switch (fCandidateType) {
184  case kD0toKpi:
185  case kD0toKpiLikeSign:
186  classname = "AliAnalysisTaskDmesonJetsDetectorResponse::AliD0MatchInfoSummary";
187  fCurrentDmeson = new AliD0MatchInfoSummary();
188  break;
189  case kDstartoKpipi:
190  classname = "AliAnalysisTaskDmesonJetsDetectorResponse::AliDStarMatchInfoSummary";
191  fCurrentDmeson = new AliDStarMatchInfoSummary();
192  break;
193  }
194  TString treeName = TString::Format("%s_%s", taskName, GetName());
195  fTree = new TTree(treeName, treeName);
196  fTree->Branch("DmesonJet", classname, &fCurrentDmeson);
197 
198  fCurrentJetInfoTruth = new AliJetInfoSummary*[fGenerated->GetJetDefinitions().size()];
199  for (Int_t i = 0; i < fGenerated->GetJetDefinitions().size(); i++) {
200  fCurrentJetInfoTruth[i] = new AliJetInfoSummary();
201  TString bname = TString::Format("%s_truth", fGenerated->GetJetDefinitions()[i].GetName());
202  fTree->Branch(bname, "AliAnalysisTaskDmesonJets::AliJetInfoSummary", &fCurrentJetInfoTruth[i]);
203  }
204 
205  fCurrentJetInfoReco = new AliJetInfoSummary*[fRecontructed->GetJetDefinitions().size()];
206  for (Int_t i = 0; i < fRecontructed->GetJetDefinitions().size(); i++) {
207  fCurrentJetInfoReco[i] = new AliJetInfoSummary();
208  TString bname = TString::Format("%s_reco", fRecontructed->GetJetDefinitions()[i].GetName());
209  fTree->Branch(bname, "AliAnalysisTaskDmesonJets::AliJetInfoSummary", &fCurrentJetInfoReco[i]);
210  }
211 
212  return fTree;
213 }
214 
220 {
221  fRecontructed->FillQA(applyKinCuts);
222  fGenerated->FillQA(applyKinCuts);
223 
224  std::map<int, AliDmesonJetInfo>& recoDmesons = fRecontructed->GetDmesons();
225  std::map<int, AliDmesonJetInfo>& truthDmesons = fGenerated->GetDmesons();
226 
227  // Loop over reconstructed D meson and look for their generated counterparts
228  for (auto& dmeson_reco : recoDmesons) {
229  // Reset D meson and jet tree branches
230  fCurrentDmeson->Reset();
231  for (UInt_t ij = 0; ij < fRecontructed->GetJetDefinitions().size(); ij++) {
232  fCurrentJetInfoReco[ij]->Reset();
233  }
234  for (UInt_t ij = 0; ij < fGenerated->GetJetDefinitions().size(); ij++) {
235  fCurrentJetInfoTruth[ij]->Reset();
236  }
237 
238  // Copy the reconstructed D meson information in the tree branch
239  fCurrentDmeson->SetReconstructed(dmeson_reco.second);
240 
241  Int_t accRecJets = 0;
242  Int_t accGenJets = 0;
243 
244  // Copy the reconstructed jet information in the tree branch
245  for (UInt_t ij = 0; ij < fRecontructed->GetJetDefinitions().size(); ij++) {
246  AliJetInfo* jet = dmeson_reco.second.GetJet(fRecontructed->GetJetDefinitions()[ij].GetName());
247  if (!jet) continue;
248  if (applyKinCuts && !fRecontructed->GetJetDefinitions()[ij].IsJetInAcceptance(*jet)) continue;
249  fCurrentJetInfoReco[ij]->Set(dmeson_reco.second, fRecontructed->GetJetDefinitions()[ij].GetName());
250  accRecJets++;
251  }
252 
253  // Look for the generated D meson counterpart
254  if (dmeson_reco.second.fMCLabel >= 0) {
255  std::map<int, AliDmesonJetInfo>::iterator it = truthDmesons.find(dmeson_reco.second.fMCLabel);
256  if (it != truthDmesons.end()) {
257  std::pair<const int, AliDmesonJetInfo>& dmeson_truth = (*it);
258  // Flag the generated D meson as reconstructed
259  dmeson_truth.second.fReconstructed = kTRUE;
260  // Copy the generated D meson information in the tree branch
261  fCurrentDmeson->SetGenerated((*it).second);
262 
263  // Copy the reconstructed jet information in the tree branch
264  for (UInt_t ij = 0; ij < fGenerated->GetJetDefinitions().size(); ij++) {
265  AliJetInfo* jet = dmeson_truth.second.GetJet(fGenerated->GetJetDefinitions()[ij].GetName());
266  if (!jet) continue;
267  if (!applyKinCuts || fGenerated->GetJetDefinitions()[ij].IsJetInAcceptance(*jet)) accGenJets++;
268  fCurrentJetInfoTruth[ij]->Set(dmeson_truth.second, fGenerated->GetJetDefinitions()[ij].GetName());
269  }
270  }
271  }
272 
273  // Fill the tree with the current D meson
274  if (accRecJets > 0 || accGenJets > 0) fTree->Fill();
275  }
276 
277  // Reset jet tree branches
278  for (UInt_t ij = 0; ij < fRecontructed->GetJetDefinitions().size(); ij++) fCurrentJetInfoReco[ij]->Reset();
279  for (UInt_t ij = 0; ij < fGenerated->GetJetDefinitions().size(); ij++) fCurrentJetInfoTruth[ij]->Reset();
280 
281  // Loop over generated D meson that were not reconstructed
282  for (auto& dmeson_truth : truthDmesons) {
283  // Reset D meson tree branch
284  fCurrentDmeson->Reset();
285  // Skip if the generated D meson was reconstructed
286  if (dmeson_truth.second.fReconstructed) continue;
287  // Copy the generated D meson information in the tree branch
288  fCurrentDmeson->SetGenerated(dmeson_truth.second);
289 
290  Int_t accRecJets = 0;
291  Int_t accGenJets = 0;
292 
293  // Copy the reconstructed jet information in the tree branch
294  for (UInt_t ij = 0; ij < fGenerated->GetJetDefinitions().size(); ij++) {
295  fCurrentJetInfoTruth[ij]->Reset();
296  AliJetInfo* jet = dmeson_truth.second.GetJet(fGenerated->GetJetDefinitions()[ij].GetName());
297  if (!jet) continue;
298  if (applyKinCuts && !fGenerated->GetJetDefinitions()[ij].IsJetInAcceptance(*jet)) continue;
299  fCurrentJetInfoTruth[ij]->Set(dmeson_truth.second, fGenerated->GetJetDefinitions()[ij].GetName());
300  accGenJets++;
301  }
302 
303  // Fill the tree with the current D meson
304  if (accRecJets > 0 || accGenJets > 0) fTree->Fill();
305  }
306 
307  return kTRUE;
308 }
309 
310 // Definitions of class AliAnalysisTaskDmesonJetsDetectorResponse
311 
315 
320 {
322 }
323 
328  AliAnalysisTaskDmesonJets(name, nOutputTrees),
329  fResponseEngines()
330 {
332 }
333 
336 {
337  ::Info("UserCreateOutputObjects", "CreateOutputObjects of task %s", GetName());
338 
340 
341  for (auto &param : fAnalysisEngines) {
342  if (param.IsInhibit()) continue;
343  if (param.GetMCMode() != kSignalOnly && param.GetMCMode() != kMCTruth) continue;
344 
345  std::map<ECandidateType_t, ResponseEngine>::iterator it = fResponseEngines.find(param.GetCandidateType());
346 
347  if (it == fResponseEngines.end()) {
348  it = (fResponseEngines.insert(std::pair<const ECandidateType_t, ResponseEngine>(param.GetCandidateType(), ResponseEngine(param.GetCandidateType())))).first;
349  }
350 
351  if (param.GetMCMode() == kMCTruth) {
352  (*it).second.SetGeneratedAnalysisEngine(&param);
353  }
354  else {
355  (*it).second.SetReconstructedAnalysisEngine(&param);
356  }
357  }
358 
359  Int_t treeSlot = 0;
360 
361  for (auto &resp : fResponseEngines) {
362  if (!resp.second.CheckInit()) continue;
363 
364  resp.second.BuildTree(GetName());
365  if (treeSlot < fNOutputTrees) {
366  resp.second.AssignDataSlot(treeSlot+2);
367  treeSlot++;
368  PostDataFromResponseEngine(resp.second);
369  }
370  else {
371  AliError(Form("Number of data output slots %d not sufficient. Tree of response engine %s will not be posted!", fNOutputTrees, resp.second.GetName()));
372  }
373  }
374 }
375 
379 {
381 }
382 
387 {
389 }
390 
395 {
396  for (auto &resp : fResponseEngines) {
397  if (resp.second.IsInhibit()) continue;
398 
399  resp.second.FillTree(fApplyKinematicCuts);
400 
401  PostDataFromResponseEngine(resp.second);
402  }
403 
405  return kTRUE;
406 
407 }
408 
413 {
415  AliWarning("This class only provides a tree output.");
416  }
417 
418  // Always set it to kNoOutput: base class does not generate any output (other than QA histograms), all the output comes from the derived class
420 }
421 
428 {
429  if (eng.GetDataSlotNumber() >= 0 && eng.GetTree()) {
430  PostData(eng.GetDataSlotNumber(), eng.GetTree());
431  return eng.GetDataSlotNumber();
432  }
433  else {
434  return -1;
435  }
436 }
437 
447 {
448  // Get the pointer to the existing analysis manager via the static access method.
449  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
450  if (!mgr) {
451  ::Error("AddTaskDmesonJetsDetectorResponse", "No analysis manager to connect to.");
452  return 0;
453  }
454 
455  // Check the analysis type using the event handlers connected to the analysis manager.
456  AliVEventHandler* handler = mgr->GetInputEventHandler();
457  if (!handler) {
458  ::Error("AddTaskDmesonJetsDetectorResponse", "This task requires an input event handler");
459  return 0;
460  }
461 
462  EDataType_t dataType = kUnknownDataType;
463 
464  if (handler->InheritsFrom("AliESDInputHandler")) {
465  dataType = kESD;
466  }
467  else if (handler->InheritsFrom("AliAODInputHandler")) {
468  dataType = kAOD;
469  }
470 
471  // Init the task and do settings
472  if (trackName == "usedefault") {
473  if (dataType == kESD) {
474  trackName = "Tracks";
475  }
476  else if (dataType == kAOD) {
477  trackName = "tracks";
478  }
479  else {
480  trackName = "";
481  }
482  }
483 
484  if (clusName == "usedefault") {
485  if (dataType == kESD) {
486  clusName = "CaloClusters";
487  }
488  else if (dataType == kAOD) {
489  clusName = "caloClusters";
490  }
491  else {
492  clusName = "";
493  }
494  }
495 
496  if (mcPartName == "usedefault") {
497  mcPartName = "mcparticles"; // Always needs AliAODMCParticle objects
498  }
499 
500  TString name("AliAnalysisTaskDmesonJetsDetectorResponse");
501  if (!suffix.IsNull()) {
502  name += TString::Format("_%s", suffix.Data());
503  }
504 
506 
507  if (!trackName.IsNull()) {
508  AliHFTrackContainer* trackCont = new AliHFTrackContainer(trackName);
509  jetTask->AdoptParticleContainer(trackCont);
510  }
511 
512  if (!mcPartName.IsNull()) {
513  AliMCParticleContainer* partCont = new AliHFAODMCParticleContainer(mcPartName);
514  partCont->SetEtaLimits(-1.5, 1.5);
515  partCont->SetPtLimits(0, 1000);
516  jetTask->AdoptParticleContainer(partCont);
517  }
518 
519  jetTask->AddClusterContainer(clusName.Data());
520 
521  // Final settings, pass to manager and set the containers
522  mgr->AddTask(jetTask);
523 
524  // Create containers for input/output
525  AliAnalysisDataContainer* cinput1 = mgr->GetCommonInputContainer();
526  TString contname1(name);
527  contname1 += "_histos";
528  AliAnalysisDataContainer* coutput1 = mgr->CreateContainer(contname1.Data(),
529  TList::Class(), AliAnalysisManager::kOutputContainer,
530  Form("%s", AliAnalysisManager::GetCommonFileName()));
531 
532  mgr->ConnectInput(jetTask, 0, cinput1);
533  mgr->ConnectOutput(jetTask, 1, coutput1);
534 
535  for (Int_t i = 0; i < nMaxTrees; i++) {
536  TString contname = TString::Format("%s_tree_%d", name.Data(), i);
537  AliAnalysisDataContainer *coutput = mgr->CreateContainer(contname.Data(),
538  TTree::Class(),AliAnalysisManager::kOutputContainer,
539  Form("%s", AliAnalysisManager::GetCommonFileName()));
540  mgr->ConnectOutput(jetTask, 2+i, coutput);
541  }
542  return jetTask;
543 }
544 
AliClusterContainer * AddClusterContainer(std::string branchName, std::string contName="")
std::list< AnalysisEngine > fAnalysisEngines
Array of analysis parameters.
static AliAnalysisTaskDmesonJetsDetectorResponse * AddTaskDmesonJetsDetectorResponse(TString trackName, TString clusName, TString mcPartName, Int_t nMaxTrees, TString suffix)
Analysis task for D meson jets.
Lightweight class that encapsulates matching between reconstructed and generated D0 mesons...
EDataType_t
Switch for the data type.
Analysis task used to build a detector response for D meson jets.
AliHFAODMCParticleContainer * fMCContainer
! MC particle container
std::map< ECandidateType_t, ResponseEngine > fResponseEngines
! Response engines
Analysis engine to produce detector response matrix in the D meson jet analysis.
virtual void UserCreateOutputObjects()
Creates the output containers.
void FillPartonLevelHistograms()
Fill histograms with parton-level information.
virtual void UserCreateOutputObjects()
Creates the output containers.
AliAnalysisTaskDmesonJetsDetectorResponse()
This is the default constructor, used for ROOT I/O purposes.
Lightweight class that encapsulates matching between reconstructed and generated D mesons...
Select tracks based on specific prescriptions of HF analysis.
int Int_t
Definition: External.C:63
unsigned int UInt_t
Definition: External.C:33
Select MC particles based on specific prescriptions of HF analysis.
Lightweight class that encapsulates matching between reconstructed and generated D* mesons...
ClassImp(AliAnalysisTaskCRC) AliAnalysisTaskCRC
Bool_t fApplyKinematicCuts
Apply jet kinematic cuts.
EOutputType_t fOutputType
Output type: none, TTree or THnSparse.
bool Bool_t
Definition: External.C:53
Int_t fNOutputTrees
Maximum number of output trees.
Container for MC-true particles within the EMCAL framework.
void AdoptParticleContainer(AliParticleContainer *cont)
void RunAnalysis()
Run the requested analysis for the current event.