AliPhysics  1168478 (1168478)
 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  if (fGenerated->GetJetDefinitions()[i].GetRhoName().IsNull()) {
201  fCurrentJetInfoTruth[i] = new AliJetInfoSummary();
202  TString bname = TString::Format("%s_truth", fGenerated->GetJetDefinitions()[i].GetName());
203  fTree->Branch(bname, "AliAnalysisTaskDmesonJets::AliJetInfoSummary", &fCurrentJetInfoTruth[i]);
204  }
205  else {
206  fCurrentJetInfoTruth[i] = new AliJetInfoPbPbSummary();
207  TString bname = TString::Format("%s_truth", fGenerated->GetJetDefinitions()[i].GetName());
208  fTree->Branch(bname, "AliAnalysisTaskDmesonJets::AliJetInfoPbPbSummary", &fCurrentJetInfoTruth[i]);
209  }
210  }
211 
212  fCurrentJetInfoReco = new AliJetInfoSummary*[fRecontructed->GetJetDefinitions().size()];
213  for (Int_t i = 0; i < fRecontructed->GetJetDefinitions().size(); i++) {
214  if (fGenerated->GetJetDefinitions()[i].GetRhoName().IsNull()) {
215  fCurrentJetInfoReco[i] = new AliJetInfoSummary();
216  TString bname = TString::Format("%s_reco", fRecontructed->GetJetDefinitions()[i].GetName());
217  fTree->Branch(bname, "AliAnalysisTaskDmesonJets::AliJetInfoSummary", &fCurrentJetInfoReco[i]);
218  }
219  else {
220  fCurrentJetInfoReco[i] = new AliJetInfoPbPbSummary();
221  TString bname = TString::Format("%s_reco", fRecontructed->GetJetDefinitions()[i].GetName());
222  fTree->Branch(bname, "AliAnalysisTaskDmesonJets::AliJetInfoPbPbSummary", &fCurrentJetInfoReco[i]);
223  }
224  }
225 
226  return fTree;
227 }
228 
234 {
235  fRecontructed->FillQA(applyKinCuts);
236  fGenerated->FillQA(applyKinCuts);
237 
238  std::map<int, AliDmesonJetInfo>& recoDmesons = fRecontructed->GetDmesons();
239  std::map<int, AliDmesonJetInfo>& truthDmesons = fGenerated->GetDmesons();
240 
241  // Loop over reconstructed D meson and look for their generated counterparts
242  for (auto& dmeson_reco : recoDmesons) {
243  // Reset D meson and jet tree branches
244  fCurrentDmeson->Reset();
245  for (UInt_t ij = 0; ij < fRecontructed->GetJetDefinitions().size(); ij++) {
246  fCurrentJetInfoReco[ij]->Reset();
247  }
248  for (UInt_t ij = 0; ij < fGenerated->GetJetDefinitions().size(); ij++) {
249  fCurrentJetInfoTruth[ij]->Reset();
250  }
251 
252  // Copy the reconstructed D meson information in the tree branch
253  fCurrentDmeson->SetReconstructed(dmeson_reco.second);
254 
255  Int_t accRecJets = 0;
256  Int_t accGenJets = 0;
257 
258  // Copy the reconstructed jet information in the tree branch
259  for (UInt_t ij = 0; ij < fRecontructed->GetJetDefinitions().size(); ij++) {
260  AliJetInfo* jet = dmeson_reco.second.GetJet(fRecontructed->GetJetDefinitions()[ij].GetName());
261  if (!jet) continue;
262  if (applyKinCuts && !fRecontructed->GetJetDefinitions()[ij].IsJetInAcceptance(*jet)) continue;
263  fCurrentJetInfoReco[ij]->Set(dmeson_reco.second, fRecontructed->GetJetDefinitions()[ij].GetName());
264  accRecJets++;
265  }
266 
267  // Look for the generated D meson counterpart
268  if (dmeson_reco.second.fMCLabel >= 0) {
269  std::map<int, AliDmesonJetInfo>::iterator it = truthDmesons.find(dmeson_reco.second.fMCLabel);
270  if (it != truthDmesons.end()) {
271  std::pair<const int, AliDmesonJetInfo>& dmeson_truth = (*it);
272  // Flag the generated D meson as reconstructed
273  dmeson_truth.second.fReconstructed = kTRUE;
274  // Copy the generated D meson information in the tree branch
275  fCurrentDmeson->SetGenerated((*it).second);
276 
277  // Copy the reconstructed jet information in the tree branch
278  for (UInt_t ij = 0; ij < fGenerated->GetJetDefinitions().size(); ij++) {
279  AliJetInfo* jet = dmeson_truth.second.GetJet(fGenerated->GetJetDefinitions()[ij].GetName());
280  if (!jet) continue;
281  if (!applyKinCuts || fGenerated->GetJetDefinitions()[ij].IsJetInAcceptance(*jet)) accGenJets++;
282  fCurrentJetInfoTruth[ij]->Set(dmeson_truth.second, fGenerated->GetJetDefinitions()[ij].GetName());
283  }
284  }
285  }
286 
287  // Fill the tree with the current D meson
288  if (accRecJets > 0 || accGenJets > 0) fTree->Fill();
289  }
290 
291  // Reset jet tree branches
292  for (UInt_t ij = 0; ij < fRecontructed->GetJetDefinitions().size(); ij++) fCurrentJetInfoReco[ij]->Reset();
293  for (UInt_t ij = 0; ij < fGenerated->GetJetDefinitions().size(); ij++) fCurrentJetInfoTruth[ij]->Reset();
294 
295  // Loop over generated D meson that were not reconstructed
296  for (auto& dmeson_truth : truthDmesons) {
297  // Reset D meson tree branch
298  fCurrentDmeson->Reset();
299  // Skip if the generated D meson was reconstructed
300  if (dmeson_truth.second.fReconstructed) continue;
301  // Copy the generated D meson information in the tree branch
302  fCurrentDmeson->SetGenerated(dmeson_truth.second);
303 
304  Int_t accRecJets = 0;
305  Int_t accGenJets = 0;
306 
307  // Copy the reconstructed jet information in the tree branch
308  for (UInt_t ij = 0; ij < fGenerated->GetJetDefinitions().size(); ij++) {
309  fCurrentJetInfoTruth[ij]->Reset();
310  AliJetInfo* jet = dmeson_truth.second.GetJet(fGenerated->GetJetDefinitions()[ij].GetName());
311  if (!jet) continue;
312  if (applyKinCuts && !fGenerated->GetJetDefinitions()[ij].IsJetInAcceptance(*jet)) continue;
313  fCurrentJetInfoTruth[ij]->Set(dmeson_truth.second, fGenerated->GetJetDefinitions()[ij].GetName());
314  accGenJets++;
315  }
316 
317  // Fill the tree with the current D meson
318  if (accRecJets > 0 || accGenJets > 0) fTree->Fill();
319  }
320 
321  return kTRUE;
322 }
323 
324 // Definitions of class AliAnalysisTaskDmesonJetsDetectorResponse
325 
329 
334 {
336 }
337 
342  AliAnalysisTaskDmesonJets(name, nOutputTrees),
343  fResponseEngines()
344 {
346 }
347 
350 {
351  ::Info("UserCreateOutputObjects", "CreateOutputObjects of task %s", GetName());
352 
354 
355  for (auto &param : fAnalysisEngines) {
356  if (param.IsInhibit()) continue;
357  if (param.GetMCMode() != kSignalOnly && param.GetMCMode() != kMCTruth) continue;
358 
359  std::map<ECandidateType_t, ResponseEngine>::iterator it = fResponseEngines.find(param.GetCandidateType());
360 
361  if (it == fResponseEngines.end()) {
362  it = (fResponseEngines.insert(std::pair<const ECandidateType_t, ResponseEngine>(param.GetCandidateType(), ResponseEngine(param.GetCandidateType())))).first;
363  }
364 
365  if (param.GetMCMode() == kMCTruth) {
366  (*it).second.SetGeneratedAnalysisEngine(&param);
367  }
368  else {
369  (*it).second.SetReconstructedAnalysisEngine(&param);
370  }
371  }
372 
373  Int_t treeSlot = 0;
374 
375  for (auto &resp : fResponseEngines) {
376  if (!resp.second.CheckInit()) continue;
377 
378  resp.second.BuildTree(GetName());
379  if (treeSlot < fNOutputTrees) {
380  resp.second.AssignDataSlot(treeSlot+2);
381  treeSlot++;
382  PostDataFromResponseEngine(resp.second);
383  }
384  else {
385  AliError(Form("Number of data output slots %d not sufficient. Tree of response engine %s will not be posted!", fNOutputTrees, resp.second.GetName()));
386  }
387  }
388 }
389 
393 {
395 }
396 
401 {
403 }
404 
409 {
410  for (auto &resp : fResponseEngines) {
411  if (resp.second.IsInhibit()) continue;
412 
413  resp.second.FillTree(fApplyKinematicCuts);
414 
415  PostDataFromResponseEngine(resp.second);
416  }
417 
419  return kTRUE;
420 
421 }
422 
427 {
429  AliWarning("This class only provides a tree output.");
430  }
431 
432  // Always set it to kNoOutput: base class does not generate any output (other than QA histograms), all the output comes from the derived class
434 }
435 
442 {
443  if (eng.GetDataSlotNumber() >= 0 && eng.GetTree()) {
444  PostData(eng.GetDataSlotNumber(), eng.GetTree());
445  return eng.GetDataSlotNumber();
446  }
447  else {
448  return -1;
449  }
450 }
451 
461 {
462  // Get the pointer to the existing analysis manager via the static access method.
463  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
464  if (!mgr) {
465  ::Error("AddTaskDmesonJetsDetectorResponse", "No analysis manager to connect to.");
466  return 0;
467  }
468 
469  // Check the analysis type using the event handlers connected to the analysis manager.
470  AliVEventHandler* handler = mgr->GetInputEventHandler();
471  if (!handler) {
472  ::Error("AddTaskDmesonJetsDetectorResponse", "This task requires an input event handler");
473  return 0;
474  }
475 
476  EDataType_t dataType = kUnknownDataType;
477 
478  if (handler->InheritsFrom("AliESDInputHandler")) {
479  dataType = kESD;
480  }
481  else if (handler->InheritsFrom("AliAODInputHandler")) {
482  dataType = kAOD;
483  }
484 
485  // Init the task and do settings
486  if (trackName == "usedefault") {
487  if (dataType == kESD) {
488  trackName = "Tracks";
489  }
490  else if (dataType == kAOD) {
491  trackName = "tracks";
492  }
493  else {
494  trackName = "";
495  }
496  }
497 
498  if (clusName == "usedefault") {
499  if (dataType == kESD) {
500  clusName = "CaloClusters";
501  }
502  else if (dataType == kAOD) {
503  clusName = "caloClusters";
504  }
505  else {
506  clusName = "";
507  }
508  }
509 
510  if (mcPartName == "usedefault") {
511  mcPartName = "mcparticles"; // Always needs AliAODMCParticle objects
512  }
513 
514  TString name("AliAnalysisTaskDmesonJetsDetectorResponse");
515  if (!suffix.IsNull()) {
516  name += TString::Format("_%s", suffix.Data());
517  }
518 
520 
521  if (!trackName.IsNull()) {
522  AliHFTrackContainer* trackCont = new AliHFTrackContainer(trackName);
523  jetTask->AdoptParticleContainer(trackCont);
524  }
525 
526  if (!mcPartName.IsNull()) {
527  AliMCParticleContainer* partCont = new AliHFAODMCParticleContainer(mcPartName);
528  partCont->SetEtaLimits(-1.5, 1.5);
529  partCont->SetPtLimits(0, 1000);
530  jetTask->AdoptParticleContainer(partCont);
531  }
532 
533  jetTask->AddClusterContainer(clusName.Data());
534 
535  // Final settings, pass to manager and set the containers
536  mgr->AddTask(jetTask);
537 
538  // Create containers for input/output
539  AliAnalysisDataContainer* cinput1 = mgr->GetCommonInputContainer();
540  TString contname1(name);
541  contname1 += "_histos";
542  AliAnalysisDataContainer* coutput1 = mgr->CreateContainer(contname1.Data(),
543  TList::Class(), AliAnalysisManager::kOutputContainer,
544  Form("%s", AliAnalysisManager::GetCommonFileName()));
545 
546  mgr->ConnectInput(jetTask, 0, cinput1);
547  mgr->ConnectOutput(jetTask, 1, coutput1);
548 
549  for (Int_t i = 0; i < nMaxTrees; i++) {
550  TString contname = TString::Format("%s_tree_%d", name.Data(), i);
551  AliAnalysisDataContainer *coutput = mgr->CreateContainer(contname.Data(),
552  TTree::Class(),AliAnalysisManager::kOutputContainer,
553  Form("%s", AliAnalysisManager::GetCommonFileName()));
554  mgr->ConnectOutput(jetTask, 2+i, coutput);
555  }
556  return jetTask;
557 }
558 
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
Lightweight class that encapsulates D meson jets for PbPb analysis.
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.