AliPhysics  35e5fca (35e5fca)
 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  // Check if a matched reconstructed jet can be found and copy the reconstructed jet information in the tree branch
304  if (findNoDMesonRecoJets) {
305  for (UInt_t ij = 0; ij < fRecontructed->GetJetDefinitions().size(); ij++) {
306  // Reset reconstructed jet tree branch
307  fCurrentJetInfoReco[ij]->Reset();
308  // Look for a matched reconstructed jet
309  AliAnalysisTaskDmesonJets::AnalysisEngine::jet_distance_pair jet = fRecontructed->FindJetMacthedToGeneratedDMeson(dmeson_truth.second, fRecontructed->GetJetDefinitions()[ij], fRecontructed->GetJetDefinitions()[ij].GetRadius() * fMaxJetDmesonDistance, applyKinCuts);
310  if (!jet.first) continue;
311  // Copy reconstructed jet information in the tree branch
312  fCurrentJetInfoReco[ij]->Set(*(jet.first));
313  fCurrentJetInfoReco[ij]->fR = jet.second;
314  accRecJets++;
315  }
316  }
317 
318  // Fill the tree with the current D meson
319  if (accRecJets > 0 || accGenJets > 0) fTree->Fill();
320  }
321 
322  return kTRUE;
323 }
324 
325 // Definitions of class AliAnalysisTaskDmesonJetsDetectorResponse
326 
330 
336 {
338 }
339 
344  AliAnalysisTaskDmesonJets(name, nOutputTrees),
345  fFindRecoJetsForLostDMesons(kFALSE),
346  fResponseEngines()
347 {
349 }
350 
353 {
354  ::Info("UserCreateOutputObjects", "CreateOutputObjects of task %s", GetName());
355 
357 
358  for (auto &param : fAnalysisEngines) {
359  if (param.IsInhibit()) continue;
360  if (param.GetMCMode() != kSignalOnly && param.GetMCMode() != kMCTruth) continue;
361 
362  std::map<ECandidateType_t, ResponseEngine>::iterator it = fResponseEngines.find(param.GetCandidateType());
363 
364  if (it == fResponseEngines.end()) {
365  it = (fResponseEngines.insert(std::pair<const ECandidateType_t, ResponseEngine>(param.GetCandidateType(), ResponseEngine(param.GetCandidateType())))).first;
366  }
367 
368  if (param.GetMCMode() == kMCTruth) {
369  (*it).second.SetGeneratedAnalysisEngine(&param);
370  }
371  else {
372  (*it).second.SetReconstructedAnalysisEngine(&param);
373  }
374  }
375 
376  Int_t treeSlot = 0;
377 
378  for (auto &resp : fResponseEngines) {
379  if (!resp.second.CheckInit()) continue;
380 
381  resp.second.BuildTree(GetName());
382  if (treeSlot < fNOutputTrees) {
383  resp.second.AssignDataSlot(treeSlot+2);
384  treeSlot++;
385  PostDataFromResponseEngine(resp.second);
386  }
387  else {
388  AliError(Form("Number of data output slots %d not sufficient. Tree of response engine %s will not be posted!", fNOutputTrees, resp.second.GetName()));
389  }
390  }
391 }
392 
396 {
398 }
399 
404 {
406 }
407 
412 {
413  for (auto &resp : fResponseEngines) {
414  if (resp.second.IsInhibit()) continue;
415 
416  resp.second.FillTree(fApplyKinematicCuts, fFindRecoJetsForLostDMesons);
417 
418  PostDataFromResponseEngine(resp.second);
419  }
420 
422  return kTRUE;
423 
424 }
425 
430 {
432  AliWarning("This class only provides a tree output.");
433  }
434 
435  // Always set it to kNoOutput: base class does not generate any output (other than QA histograms), all the output comes from the derived class
437 }
438 
445 {
446  if (eng.GetDataSlotNumber() >= 0 && eng.GetTree()) {
447  PostData(eng.GetDataSlotNumber(), eng.GetTree());
448  return eng.GetDataSlotNumber();
449  }
450  else {
451  return -1;
452  }
453 }
454 
464 {
465  // Get the pointer to the existing analysis manager via the static access method.
466  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
467  if (!mgr) {
468  ::Error("AddTaskDmesonJetsDetectorResponse", "No analysis manager to connect to.");
469  return 0;
470  }
471 
472  // Check the analysis type using the event handlers connected to the analysis manager.
473  AliVEventHandler* handler = mgr->GetInputEventHandler();
474  if (!handler) {
475  ::Error("AddTaskDmesonJetsDetectorResponse", "This task requires an input event handler");
476  return 0;
477  }
478 
479  EDataType_t dataType = kUnknownDataType;
480 
481  if (handler->InheritsFrom("AliESDInputHandler")) {
482  dataType = kESD;
483  }
484  else if (handler->InheritsFrom("AliAODInputHandler")) {
485  dataType = kAOD;
486  }
487 
488  // Init the task and do settings
489  if (trackName == "usedefault") {
490  if (dataType == kESD) {
491  trackName = "Tracks";
492  }
493  else if (dataType == kAOD) {
494  trackName = "tracks";
495  }
496  else {
497  trackName = "";
498  }
499  }
500 
501  if (clusName == "usedefault") {
502  if (dataType == kESD) {
503  clusName = "CaloClusters";
504  }
505  else if (dataType == kAOD) {
506  clusName = "caloClusters";
507  }
508  else {
509  clusName = "";
510  }
511  }
512 
513  if (mcPartName == "usedefault") {
514  mcPartName = "mcparticles"; // Always needs AliAODMCParticle objects
515  }
516 
517  TString name("AliAnalysisTaskDmesonJetsDetectorResponse");
518  if (!suffix.IsNull()) {
519  name += TString::Format("_%s", suffix.Data());
520  }
521 
523 
524  if (!trackName.IsNull()) {
525  AliHFTrackContainer* trackCont = new AliHFTrackContainer(trackName);
526  jetTask->AdoptParticleContainer(trackCont);
527  }
528 
529  if (!mcPartName.IsNull()) {
530  AliMCParticleContainer* partCont = new AliHFAODMCParticleContainer(mcPartName);
531  partCont->SetEtaLimits(-1.5, 1.5);
532  partCont->SetPtLimits(0, 1000);
533  jetTask->AdoptParticleContainer(partCont);
534  }
535 
536  jetTask->AddClusterContainer(clusName);
537 
538  // Final settings, pass to manager and set the containers
539  mgr->AddTask(jetTask);
540 
541  // Create containers for input/output
542  AliAnalysisDataContainer* cinput1 = mgr->GetCommonInputContainer();
543  TString contname1(name);
544  contname1 += "_histos";
545  AliAnalysisDataContainer* coutput1 = mgr->CreateContainer(contname1.Data(),
546  TList::Class(), AliAnalysisManager::kOutputContainer,
547  Form("%s", AliAnalysisManager::GetCommonFileName()));
548 
549  mgr->ConnectInput(jetTask, 0, cinput1);
550  mgr->ConnectOutput(jetTask, 1, coutput1);
551 
552  for (Int_t i = 0; i < nMaxTrees; i++) {
553  TString contname = TString::Format("%s_tree_%d", name.Data(), i);
554  AliAnalysisDataContainer *coutput = mgr->CreateContainer(contname.Data(),
555  TTree::Class(),AliAnalysisManager::kOutputContainer,
556  Form("%s", AliAnalysisManager::GetCommonFileName()));
557  mgr->ConnectOutput(jetTask, 2+i, coutput);
558  }
559  return jetTask;
560 }
561 
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.
Bool_t fFindRecoJetsForLostDMesons
If switched on, looks for reconstructed jets even when the D meson was lost.
AliClusterContainer * AddClusterContainer(const char *n)
std::pair< AliJetInfo *, Double_t > jet_distance_pair
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.