AliPhysics  7f4dd97 (7f4dd97)
 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 
212 Bool_t AliAnalysisTaskDmesonJetsDetectorResponse::ResponseEngine::FillTree(Bool_t applyKinCuts, Bool_t findNoDMesonRecoJets)
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  Int_t accRecJets = 0;
235  Int_t accGenJets = 0;
236 
237  // Copy the reconstructed jet information in the tree branch
238  for (UInt_t ij = 0; ij < fRecontructed->GetJetDefinitions().size(); ij++) {
239  AliJetInfo* jet = dmeson_reco.second.GetJet(fRecontructed->GetJetDefinitions()[ij].GetName());
240  if (!jet) continue;
241  if (applyKinCuts && !fRecontructed->GetJetDefinitions()[ij].IsJetInAcceptance(*jet)) continue;
242  fCurrentJetInfoReco[ij]->Set(dmeson_reco.second, fRecontructed->GetJetDefinitions()[ij].GetName());
243  accRecJets++;
244  }
245 
246  // Look for the generated D meson counterpart
247  if (dmeson_reco.second.fMCLabel >= 0) {
248  std::map<int, AliDmesonJetInfo>::iterator it = truthDmesons.find(dmeson_reco.second.fMCLabel);
249  if (it != truthDmesons.end()) {
250  std::pair<const int, AliDmesonJetInfo>& dmeson_truth = (*it);
251  // Flag the generated D meson as reconstructed
252  dmeson_truth.second.fReconstructed = kTRUE;
253  // Copy the generated D meson information in the tree branch
254  fCurrentDmeson->SetGenerated((*it).second);
255 
256  // Copy the reconstructed jet information in the tree branch
257  for (UInt_t ij = 0; ij < fGenerated->GetJetDefinitions().size(); ij++) {
258  AliJetInfo* jet = dmeson_truth.second.GetJet(fGenerated->GetJetDefinitions()[ij].GetName());
259  if (!jet) continue;
260  if (!applyKinCuts || fGenerated->GetJetDefinitions()[ij].IsJetInAcceptance(*jet)) accGenJets++;
261  fCurrentJetInfoTruth[ij]->Set(dmeson_truth.second, fGenerated->GetJetDefinitions()[ij].GetName());
262  }
263  }
264  }
265 
266  // Fill the tree with the current D meson
267  if (accRecJets > 0 || accGenJets > 0) fTree->Fill();
268  }
269 
270  // Reset jet tree branches
271  for (UInt_t ij = 0; ij < fRecontructed->GetJetDefinitions().size(); ij++) fCurrentJetInfoReco[ij]->Reset();
272  for (UInt_t ij = 0; ij < fGenerated->GetJetDefinitions().size(); ij++) fCurrentJetInfoTruth[ij]->Reset();
273 
274  // Loop over generated D meson that were not reconstructed
275  for (auto& dmeson_truth : truthDmesons) {
276  // Reset D meson tree branch
277  fCurrentDmeson->Reset();
278  // Skip if the generated D meson was reconstructed
279  if (dmeson_truth.second.fReconstructed) continue;
280  // Copy the generated D meson information in the tree branch
281  fCurrentDmeson->SetGenerated(dmeson_truth.second);
282 
283  Int_t accRecJets = 0;
284  Int_t accGenJets = 0;
285 
286  // Copy the reconstructed jet information in the tree branch
287  for (UInt_t ij = 0; ij < fGenerated->GetJetDefinitions().size(); ij++) {
288  fCurrentJetInfoTruth[ij]->Reset();
289  AliJetInfo* jet = dmeson_truth.second.GetJet(fGenerated->GetJetDefinitions()[ij].GetName());
290  if (!jet) continue;
291  if (applyKinCuts && !fGenerated->GetJetDefinitions()[ij].IsJetInAcceptance(*jet)) continue;
292  fCurrentJetInfoTruth[ij]->Set(dmeson_truth.second, fGenerated->GetJetDefinitions()[ij].GetName());
293  accGenJets++;
294  }
295 
296  // Check if a matched reconstructed jet can be found and copy the reconstructed jet information in the tree branch
297  if (findNoDMesonRecoJets) {
298  for (UInt_t ij = 0; ij < fRecontructed->GetJetDefinitions().size(); ij++) {
299  // Reset reconstructed jet tree branch
300  fCurrentJetInfoReco[ij]->Reset();
301  // Look for a matched reconstructed jet
302  AliAnalysisTaskDmesonJets::AnalysisEngine::jet_distance_pair jet = fRecontructed->FindJetMacthedToGeneratedDMeson(dmeson_truth.second, fRecontructed->GetJetDefinitions()[ij], fRecontructed->GetJetDefinitions()[ij].GetRadius() * fMaxJetDmesonDistance, applyKinCuts);
303  if (!jet.first) continue;
304  // Copy reconstructed jet information in the tree branch
305  fCurrentJetInfoReco[ij]->Set(*(jet.first));
306  fCurrentJetInfoReco[ij]->fR = jet.second;
307  accRecJets++;
308  }
309  }
310 
311  // Fill the tree with the current D meson
312  if (accRecJets > 0 || accGenJets > 0) fTree->Fill();
313  }
314 
315  return kTRUE;
316 }
317 
318 // Definitions of class AliAnalysisTaskDmesonJetsDetectorResponse
319 
323 
329 {
331 }
332 
337  AliAnalysisTaskDmesonJets(name, nOutputTrees),
338  fFindRecoJetsForLostDMesons(kFALSE),
339  fResponseEngines()
340 {
342 }
343 
346 {
347  ::Info("UserCreateOutputObjects", "CreateOutputObjects of task %s", GetName());
348 
350 
351  for (auto &param : fAnalysisEngines) {
352  if (param.IsInhibit()) continue;
353  if (param.GetMCMode() != kSignalOnly && param.GetMCMode() != kMCTruth) continue;
354 
355  std::map<ECandidateType_t, ResponseEngine>::iterator it = fResponseEngines.find(param.GetCandidateType());
356 
357  if (it == fResponseEngines.end()) {
358  it = (fResponseEngines.insert(std::pair<const ECandidateType_t, ResponseEngine>(param.GetCandidateType(), ResponseEngine(param.GetCandidateType())))).first;
359  }
360 
361  if (param.GetMCMode() == kMCTruth) {
362  (*it).second.SetGeneratedAnalysisEngine(&param);
363  }
364  else {
365  (*it).second.SetReconstructedAnalysisEngine(&param);
366  }
367  }
368 
369  Int_t treeSlot = 0;
370 
371  for (auto &resp : fResponseEngines) {
372  if (!resp.second.CheckInit()) continue;
373 
374  resp.second.BuildTree(GetName());
375  if (treeSlot < fNOutputTrees) {
376  resp.second.AssignDataSlot(treeSlot+2);
377  treeSlot++;
378  PostDataFromResponseEngine(resp.second);
379  }
380  else {
381  AliError(Form("Number of data output slots %d not sufficient. Tree of response engine %s will not be posted!", fNOutputTrees, resp.second.GetName()));
382  }
383  }
384 }
385 
389 {
391 }
392 
397 {
399 }
400 
405 {
406  for (auto &resp : fResponseEngines) {
407 
408  if (resp.second.IsInhibit()) continue;
409 
410  resp.second.FillTree(fApplyKinematicCuts, fFindRecoJetsForLostDMesons);
411 
412  PostDataFromResponseEngine(resp.second);
413  }
414 
415  return kTRUE;
416 
417 }
418 
423 {
425  AliWarning("This class only provides a tree output.");
426  }
427 
428  // Always set it to kNoOutput: base class does not generate any output (other than QA histograms), all the output comes from the derived class
430 }
431 
438 {
439  if (eng.GetDataSlotNumber() >= 0 && eng.GetTree()) {
440  PostData(eng.GetDataSlotNumber(), eng.GetTree());
441  return eng.GetDataSlotNumber();
442  }
443  else {
444  return -1;
445  }
446 }
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...
Bool_t fFindRecoJetsForLostDMesons
If switched on, looks for reconstructed jets even when the D meson was lost.
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.