AliPhysics  9fe175b (9fe175b)
 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 
17 
18 // Definitions of class AliAnalysisTaskDmesonJetsDetectorResponse::AliDmesonMatchInfoSummary
19 
23 
24 // Definitions of class AliAnalysisTaskDmesonJetsDetectorResponse::AliD0MatchInfoSummary
25 
29 
32 {
33  fGenerated.Reset();
35 }
36 
41 {
42  fReconstructed.Set(reco);
43 }
44 
49 {
50  fGenerated.Set(truth);
51 }
52 
53 // Definitions of class AliAnalysisTaskDmesonJetsDetectorResponse::AliDStarMatchInfoSummary
54 
58 
61 {
62  fGenerated.Reset();
63  fReconstructed.Reset();
64 }
65 
70 {
71  fReconstructed.Set(reco);
72 }
73 
78 {
79  fGenerated.Set(truth);
80 }
81 
82 // Definitions of class AliAnalysisTaskDmesonJetsDetectorResponse::ResponseEngine
83 
87 
90  TObject(),
91  fCandidateType(kD0toKpi),
92  fInhibit(kFALSE),
93  fMaxJetDmesonDistance(0),
94  fName(),
95  fTree(0),
96  fCurrentDmeson(0),
97  fCurrentJetInfoReco(0),
98  fCurrentJetInfoTruth(0),
99  fDataSlotNumber(-1),
100  fRecontructed(0),
101  fGenerated(0)
102 {
103 
104 }
105 
110  TObject(),
111  fCandidateType(type),
112  fInhibit(kFALSE),
113  fMaxJetDmesonDistance(1),
114  fName(),
115  fTree(0),
116  fCurrentDmeson(0),
117  fCurrentJetInfoReco(0),
118  fCurrentJetInfoTruth(0),
119  fDataSlotNumber(-1),
120  fRecontructed(0),
121  fGenerated(0)
122 {
123 
124 }
125 
130  TObject(source),
131  fCandidateType(source.fCandidateType),
132  fInhibit(source.fInhibit),
133  fMaxJetDmesonDistance(1),
134  fName(source.fName),
135  fTree(0),
136  fCurrentDmeson(0),
137  fCurrentJetInfoReco(0),
138  fCurrentJetInfoTruth(0),
139  fDataSlotNumber(source.fDataSlotNumber),
140  fRecontructed(source.fRecontructed),
141  fGenerated(source.fGenerated)
142 {
143 }
144 
149 {
150  new (this) ResponseEngine(source);
151  return *this;
152 }
153 
158 {
159  fInhibit = (fRecontructed == 0 || fGenerated == 0);
160  fName = fRecontructed->GetCandidateName();
161  return !fInhibit;
162 }
163 
166 {
167 
168 }
169 
175 {
176  TString classname;
177  switch (fCandidateType) {
178  case kD0toKpi:
179  classname = "AliAnalysisTaskDmesonJetsDetectorResponse::AliD0MatchInfoSummary";
180  fCurrentDmeson = new AliD0MatchInfoSummary();
181  break;
182  case kDstartoKpipi:
183  classname = "AliAnalysisTaskDmesonJetsDetectorResponse::AliDStarMatchInfoSummary";
184  fCurrentDmeson = new AliDStarMatchInfoSummary();
185  break;
186  }
187  TString treeName = TString::Format("%s_%s", taskName, GetName());
188  fTree = new TTree(treeName, treeName);
189  fTree->Branch("DmesonJet", classname, &fCurrentDmeson);
190 
191  fCurrentJetInfoTruth = new AliJetInfoSummary*[fGenerated->GetJetDefinitions().size()];
192  for (Int_t i = 0; i < fGenerated->GetJetDefinitions().size(); i++) {
193  fCurrentJetInfoTruth[i] = new AliJetInfoSummary();
194  TString bname = TString::Format("%s_truth", fGenerated->GetJetDefinitions()[i].GetName());
195  fTree->Branch(bname, "AliAnalysisTaskDmesonJets::AliJetInfoSummary", &fCurrentJetInfoTruth[i]);
196  }
197 
198  fCurrentJetInfoReco = new AliJetInfoSummary*[fRecontructed->GetJetDefinitions().size()];
199  for (Int_t i = 0; i < fRecontructed->GetJetDefinitions().size(); i++) {
200  fCurrentJetInfoReco[i] = new AliJetInfoSummary();
201  TString bname = TString::Format("%s_reco", fRecontructed->GetJetDefinitions()[i].GetName());
202  fTree->Branch(bname, "AliAnalysisTaskDmesonJets::AliJetInfoSummary", &fCurrentJetInfoReco[i]);
203  }
204 
205  return fTree;
206 }
207 
213 {
214  fRecontructed->FillQA(applyKinCuts);
215  fGenerated->FillQA(applyKinCuts);
216 
217  std::map<int, AliDmesonJetInfo>& recoDmesons = fRecontructed->GetDmesons();
218  std::map<int, AliDmesonJetInfo>& truthDmesons = fGenerated->GetDmesons();
219 
220  // Loop over reconstructed D meson and look for their generated counterparts
221  for (auto& dmeson_reco : recoDmesons) {
222  // Reset D meson and jet tree branches
223  fCurrentDmeson->Reset();
224  for (UInt_t ij = 0; ij < fRecontructed->GetJetDefinitions().size(); ij++) {
225  fCurrentJetInfoReco[ij]->Reset();
226  }
227  for (UInt_t ij = 0; ij < fGenerated->GetJetDefinitions().size(); ij++) {
228  fCurrentJetInfoTruth[ij]->Reset();
229  }
230 
231  // Copy the reconstructed D meson information in the tree branch
232  fCurrentDmeson->SetReconstructed(dmeson_reco.second);
233 
234  // Copy the reconstructed jet information in the tree branch
235  for (UInt_t ij = 0; ij < fRecontructed->GetJetDefinitions().size(); ij++) {
236  AliJetInfo* jet = dmeson_reco.second.GetJet(fRecontructed->GetJetDefinitions()[ij].GetName());
237  if (!jet) continue;
238  if (applyKinCuts && !fRecontructed->GetJetDefinitions()[ij].IsJetInAcceptance(*jet)) continue;
239  fCurrentJetInfoReco[ij]->Set(dmeson_reco.second, fRecontructed->GetJetDefinitions()[ij].GetName());
240  }
241 
242  // Look for the generated D meson counterpart
243  if (dmeson_reco.second.fMCLabel >= 0) {
244  std::map<int, AliDmesonJetInfo>::iterator it = truthDmesons.find(dmeson_reco.second.fMCLabel);
245  if (it != truthDmesons.end()) {
246  std::pair<const int, AliDmesonJetInfo>& dmeson_truth = (*it);
247  // Flag the generated D meson as reconstructed
248  dmeson_truth.second.fReconstructed = kTRUE;
249  // Copy the generated D meson information in the tree branch
250  fCurrentDmeson->SetGenerated((*it).second);
251  // Copy the reconstructed jet information in the tree branch
252  for (UInt_t ij = 0; ij < fGenerated->GetJetDefinitions().size(); ij++) {
253  AliJetInfo* jet = dmeson_truth.second.GetJet(fGenerated->GetJetDefinitions()[ij].GetName());
254  if (!jet) continue;
255  fCurrentJetInfoTruth[ij]->Set(dmeson_truth.second, fGenerated->GetJetDefinitions()[ij].GetName());
256  }
257  }
258  }
259 
260  // Fill the tree with the current D meson
261  fTree->Fill();
262  }
263 
264  // Loop over generated D meson that were not reconstructed
265  for (auto& dmeson_truth : truthDmesons) {
266  // Reset D meson tree branch
267  fCurrentDmeson->Reset();
268  // Skip if the generated D meson was reconstructed
269  if (dmeson_truth.second.fReconstructed) continue;
270  // Copy the generated D meson information in the tree branch
271  fCurrentDmeson->SetGenerated(dmeson_truth.second);
272  // Copy the reconstructed jet information in the tree branch
273  for (UInt_t ij = 0; ij < fGenerated->GetJetDefinitions().size(); ij++) {
274  fCurrentJetInfoTruth[ij]->Reset();
275  AliJetInfo* jet = dmeson_truth.second.GetJet(fGenerated->GetJetDefinitions()[ij].GetName());
276  if (!jet) continue;
277  if (applyKinCuts && !fGenerated->GetJetDefinitions()[ij].IsJetInAcceptance(*jet)) continue;
278  fCurrentJetInfoTruth[ij]->Set(dmeson_truth.second, fGenerated->GetJetDefinitions()[ij].GetName());
279  }
280 
281  // Check if a matched reconstructed jet can be found and copy the reconstructed jet information in the tree branch
282  for (UInt_t ij = 0; ij < fRecontructed->GetJetDefinitions().size(); ij++) {
283  // Reset reconstructed jet tree branch
284  fCurrentJetInfoReco[ij]->Reset();
285  // Look for a matched reconstructed jet
286  AliAnalysisTaskDmesonJets::AnalysisEngine::jet_distance_pair jet = fRecontructed->FindJetMacthedToGeneratedDMeson(dmeson_truth.second, fRecontructed->GetJetDefinitions()[ij], fRecontructed->GetJetDefinitions()[ij].GetRadius() * fMaxJetDmesonDistance, applyKinCuts);
287  if (!jet.first) continue;
288  // Copy reconstructed jet information in the tree branch
289  fCurrentJetInfoReco[ij]->Set(*(jet.first));
290  fCurrentJetInfoReco[ij]->fR = jet.second;
291  }
292 
293  // Fill the tree with the current D meson
294  fTree->Fill();
295  }
296 
297  return kTRUE;
298 }
299 
300 // Definitions of class AliAnalysisTaskDmesonJetsDetectorResponse
301 
305 
310 {
312 }
313 
318  AliAnalysisTaskDmesonJets(name, nOutputTrees),
319  fResponseEngines()
320 {
322 }
323 
326 {
327  ::Info("UserCreateOutputObjects", "CreateOutputObjects of task %s", GetName());
328 
330 
331  for (auto &param : fAnalysisEngines) {
332  if (param.IsInhibit()) continue;
333  if (param.GetMCMode() != kSignalOnly && param.GetMCMode() != kMCTruth) continue;
334 
335  std::map<ECandidateType_t, ResponseEngine>::iterator it = fResponseEngines.find(param.GetCandidateType());
336 
337  if (it == fResponseEngines.end()) {
338  it = (fResponseEngines.insert(std::pair<const ECandidateType_t, ResponseEngine>(param.GetCandidateType(), ResponseEngine(param.GetCandidateType())))).first;
339  }
340 
341  if (param.GetMCMode() == kMCTruth) {
342  (*it).second.SetGeneratedAnalysisEngine(&param);
343  }
344  else {
345  (*it).second.SetReconstructedAnalysisEngine(&param);
346  }
347  }
348 
349  Int_t treeSlot = 0;
350 
351  for (auto &resp : fResponseEngines) {
352  if (!resp.second.CheckInit()) continue;
353 
354  resp.second.BuildTree(GetName());
355  if (treeSlot < fNOutputTrees) {
356  resp.second.AssignDataSlot(treeSlot+2);
357  treeSlot++;
358  PostDataFromResponseEngine(resp.second);
359  }
360  else {
361  AliError(Form("Number of data output slots %d not sufficient. Tree of response engine %s will not be posted!", fNOutputTrees, resp.second.GetName()));
362  }
363  }
364 }
365 
369 {
371 }
372 
377 {
379 }
380 
385 {
386  for (auto &resp : fResponseEngines) {
387 
388  if (resp.second.IsInhibit()) continue;
389 
390  resp.second.FillTree(fApplyKinematicCuts);
391 
392  PostDataFromResponseEngine(resp.second);
393  }
394 
395  return kTRUE;
396 
397 }
398 
403 {
405  AliWarning("This class only provides a tree output.");
406  }
407 
408  // Always set it to kNoOutput: base class does not generate any output (other than QA histograms), all the output comes from the derived class
410 }
411 
418 {
419  if (eng.GetDataSlotNumber() >= 0 && eng.GetTree()) {
420  PostData(eng.GetDataSlotNumber(), eng.GetTree());
421  return eng.GetDataSlotNumber();
422  }
423  else {
424  return -1;
425  }
426 }
std::list< AnalysisEngine > fAnalysisEngines
Array of analysis parameters.
Analysis task for D meson jets.
Lightweight class that encapsulates matching between reconstructed and generated D0 mesons...
Analysis task used to build a detector response for D meson jets.
Lightweight class that encapsulates D meson jets.
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.
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...
std::pair< AliJetInfo *, Double_t > jet_distance_pair
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.
Int_t fNOutputTrees
Maximum number of output trees.
void RunAnalysis()
Run the requested analysis for the current event.