CbmRoot
AnalysisTaskMultiPairAnalysis.cxx
Go to the documentation of this file.
1 // //
3 // Basic Analysis Task //
4 //
5 // Authors:
6 // * Copyright(c) 1998-2009, ALICE Experiment at CERN, All rights reserved. *
7 // Julian Book <Julian.Book@cern.ch>
8 /*
9 
10  This task can hold multiple instances of PairAnalysis and a common set
11  of meta data PairAnalysisMetaData.
12 
13  optionally add common event cuts for all PairAnalysis instances via
14  SetEventFilter(AnalysisCuts *const filter)
15 
16 
17 */
18 // //
20 
21 #include "TSystem.h"
22 #include <TChain.h>
23 #include <TFile.h>
24 #include <TH1D.h>
25 #include <TStopwatch.h>
26 
27 #include "FairBaseParSet.h"
28 #include "FairRootManager.h"
29 #include "FairRunAna.h"
30 #include "FairRuntimeDb.h"
31 
32 
33 #include "CbmRichElectronIdAnn.h"
34 
35 #include "PairAnalysis.h"
36 #include "PairAnalysisEvent.h"
37 #include "PairAnalysisHistos.h"
38 #include "PairAnalysisMC.h"
39 #include "PairAnalysisMetaData.h"
40 
42 
44 
45  //_________________________________________________________________________________
48  //
49  // Constructor
50  //
51 }
52 
53 //_________________________________________________________________________________
55  : FairTask(name)
56  , fMetaData()
57  , fListPairAnalysis()
58  , fListHistos()
59  , fTimer()
60  , fProcInfo() {
61  //
62  // Named Constructor
63  //
64  fMetaData.SetName(Form("PairAnalysisMetaData_%s", name));
65  fListHistos.SetName(Form("PairAnalysisHistos_%s", name));
66  fListPairAnalysis.SetOwner();
67  ((TList*) fMetaData.GetMetaData())->SetOwner();
68  fListHistos.SetOwner();
69 }
70 
71 //_________________________________________________________________________________
73  //
74  // Destructor
75  //
76 
77  //histograms and CF are owned by the papa framework.
78  //however they are streamed to file, so in the first place the
79  //lists need to be owner...
80  fListPairAnalysis.SetOwner();
81  ((TList*) fMetaData.GetMetaData())->SetOwner(kFALSE);
82  fListHistos.SetOwner(kFALSE);
83  if (fInputEvent) {
84  delete fInputEvent;
85  fInputEvent = 0;
86  }
87 }
88 
89 //_________________________________________________________________________________
91  //
92  // Add all histogram manager histogram lists to the output TList
93  //
94 
95  fTimer.Start();
96 
98  // Double_t beamEnergy=0.; /// TODO: replace all fBeamEnergy by beamEnergy in NOV16
99  FairRuntimeDb* rtdb = FairRunAna::Instance()->GetRuntimeDb();
100  if (rtdb) {
101  FairBaseParSet* par =
102  dynamic_cast<FairBaseParSet*>(rtdb->getContainer("FairBaseParSet"));
103  if (par) {
104  Double_t parBeamMom = par->GetBeamMom();
105  // if default values of FairBaseParSet(15.) or FairRunSim(0.) are stored take the one set by hand
106  if (parBeamMom > 0. && TMath::Abs(parBeamMom - 15.) > 1.e-10) {
107  fBeamEnergy = parBeamMom;
108  Info("Init", " Use beam momentum from parameter set: %f ", fBeamEnergy);
109  }
110  }
111  }
112 
113  // fill metadata object
114  fMetaData.Init();
115  fMetaData.FillMeta("beamenergy", fBeamEnergy);
116 
117  if (!fListHistos.IsEmpty()) return kERROR; //already initialised
118 
119  // register output for each analysis instance
120  TIter nextDie(&fListPairAnalysis);
121  PairAnalysis* papa = 0;
122  while ((papa = static_cast<PairAnalysis*>(nextDie()))) {
123  papa->Init();
124  if (papa->GetHistogramList())
125  fListHistos.Add(const_cast<THashList*>(papa->GetHistogramList()));
126  if (papa->GetHistogramArray())
127  fListHistos.Add(const_cast<TObjArray*>(papa->GetHistogramArray()));
128  if (papa->GetQAHistList())
129  fListHistos.Add(const_cast<THashList*>(papa->GetQAHistList()));
130  if (papa->GetCutStepHistogramList())
131  fListHistos.Add(static_cast<THashList*>(papa->GetCutStepHistogramList()));
132  }
133 
134  // Get Instance of FairRoot manager
135  FairRootManager* man = FairRootManager::Instance();
136  if (!man) {
137  Fatal("AnalysisTaskMultiPairAnalysis::Init", "No FairRootManager!");
138  }
139 
140  // Init the input event
142  fInputEvent->SetInput(man);
143 
144  // Connect the MC event
146 
147  // set the beam energy to the varmanager
149 
150  // initialization time and memory
151  gSystem->GetProcInfo(&fProcInfo);
152  fprintf(stderr,
153  "AnalysisTaskMultiPairAnalysis::Init:"
154  " Real time %fs, CPU time %fs, Memory %li MB(res.) %li MB(virt.) \n",
155  fTimer.RealTime(),
156  fTimer.CpuTime(),
157  fProcInfo.fMemResident / 1024,
158  fProcInfo.fMemVirtual / 1024);
159  fTimer.Reset();
160 
161  return kSUCCESS;
162 }
163 
164 //_________________________________________________________________________________
166  //
167  // Main loop. Called for every event
168  //
169 
170  fTimer.Start(kFALSE);
171  // printf("\n\nAnalysisTaskMultiPairAnalysis::Exec: NEW event with %04d global tracks !!!!\r",
172  // fInputEvent->GetNumberOfTracks());
173  // printf("AnalysisTaskMultiPairAnalysis::Exec: global tracks %04d\n",fInputEvent->GetNumberOfTracks());
174  // printf("AnalysisTaskMultiPairAnalysis::Exec: mc tracks %04d\n",fInputEvent->GetNumberOfMCTracks());
175 
176  if (fListHistos.IsEmpty()) return;
177  fEventsTotal++;
178  if (!(fEventsTotal % 10)) {
179  gSystem->GetProcInfo(&fProcInfo);
180  fprintf(
181  stderr,
182  "AnalysisTaskMultiPairAnalysis::Exec: Process %.3e events, CPU time "
183  "%.1fs, (%fs per event, eff %.3f), Memory %li MB(res.) %li MB(virt.) \n",
184  (Double_t) fEventsTotal,
185  fTimer.CpuTime(),
186  fTimer.CpuTime() / fEventsTotal,
187  fTimer.CpuTime() / fTimer.RealTime(),
188  fProcInfo.fMemResident / 1024,
189  fProcInfo.fMemVirtual / 1024);
190  fTimer.Continue();
191  }
192 
193  // initialize track arrays and some track based variables
195  ->Init(); // NOTE: tracks are initialized with mass hypo PDG 11, and adapted later!
197 
198  // magnetic field
199 
200  //Fill Event histograms before the event filter for all instances
201  TIter nextDie(&fListPairAnalysis);
202  PairAnalysis* papa = 0;
203  // Bool_t hasMC=kFALSE;//TODO:PairAnalysisMC::Instance()->HasMC();
204  while ((papa = static_cast<PairAnalysis*>(nextDie()))) {
205  PairAnalysisHistos* h = papa->GetHistoManager();
206  if (h) {
207  PairAnalysisVarManager::SetFillMap(h->GetUsedVars());
208  // fill MCtruth information
209  //if (hasMC && PairAnalysisMC::Instance()->ConnectMCEvent() && h->GetHistogramList()->FindObject("MCEvent.noCuts")) {
210  // PairAnalysisVarManager::SetEvent(PairAnalysisMC::Instance()->GetMCEvent());
211  // h->FillClass("MCEvent.noCuts",PairAnalysisVarManager::GetData());
212  // }
213  // fill reconstructed information
214  if (h->GetHistogramList()->FindObject("Event.noCuts")) {
215  h->FillClass("Event.noCuts", PairAnalysisVarManager::GetData());
216  }
217  }
218  }
219  nextDie.Reset();
220 
221  // common event filter for all instances
222  if (fEventFilter) {
223  if (!fEventFilter->IsSelected(fInputEvent)) return;
224  }
225  fEventsSelected++;
226 
227  //Process event in all PairAnalysis instances
228  Bool_t useInternal = kFALSE;
229  Int_t ipapa = 0;
230  while ((papa = static_cast<PairAnalysis*>(nextDie()))) {
231  // event process
232  if (papa->DoEventProcess()) {
233  useInternal = papa->Process(fInputEvent);
234  // input for internal train
235  if (papa->DontClearArrays()) {
236  fPairArray = (*(papa->GetPairArraysPointer()));
237  }
238  } else {
239  // internal train
240  if (useInternal) papa->Process(fPairArray);
241  }
242 
243  // monitor pair candidates
244  // if (papa->HasCandidates()){
245  // Int_t ncandidates=papa->GetPairArray(1)->GetEntriesFast();
246  // }
247 
248  ++ipapa;
249  }
250 
251  fInputEvent->Clear();
252 }
253 
254 //_________________________________________________________________________________
256  //
257  // Write debug tree
258  //
259 
260  // set meta data
262 
263  // write output to file
264  fprintf(
265  stderr,
266  "AnalysisTaskMultiPairAnalysis::FinishTask - write histo list to %s \n",
267  FairRootManager::Instance()->GetOutFile()->GetName());
268  FairRootManager::Instance()->GetOutFile()->cd();
269 
270  fMetaData.GetMetaData()->Write(fMetaData.GetName(), TObject::kSingleKey);
271  fListHistos.Write(fListHistos.GetName(), TObject::kSingleKey);
272 }
AnalysisTaskMultiPairAnalysis
Definition: AnalysisTaskMultiPairAnalysis.h:28
PairAnalysisVarManager::SetEvent
static void SetEvent(PairAnalysisEvent *const ev)
Definition: PairAnalysisVarManager.h:1519
PairAnalysis::Init
void Init()
Definition: PairAnalysis.cxx:141
AnalysisTaskMultiPairAnalysis::Exec
virtual void Exec(Option_t *option)
Definition: AnalysisTaskMultiPairAnalysis.cxx:165
AnalysisTaskMultiPairAnalysis::Init
virtual InitStatus Init()
Definition: AnalysisTaskMultiPairAnalysis.cxx:90
PairAnalysisVarManager::SetFillMap
static void SetFillMap(TBits *map)
Definition: PairAnalysisVarManager.h:368
PairAnalysis::GetQAHistList
const THashList * GetQAHistList() const
Definition: PairAnalysis.h:97
AnalysisTaskMultiPairAnalysis::~AnalysisTaskMultiPairAnalysis
virtual ~AnalysisTaskMultiPairAnalysis()
Definition: AnalysisTaskMultiPairAnalysis.cxx:72
PairAnalysis::Process
void Process(TObjArray *arr)
Definition: PairAnalysis.cxx:211
PairAnalysisVarManager::kEbeam
@ kEbeam
Definition: PairAnalysisVarManager.h:81
PairAnalysisMetaData::FillMeta
void FillMeta(const char *name, Double_t val)
Definition: PairAnalysisMetaData.cxx:146
AnalysisTaskMultiPairAnalysis::FinishTask
virtual void FinishTask()
Definition: AnalysisTaskMultiPairAnalysis.cxx:255
AnalysisTaskMultiPairAnalysis::fEventsSelected
Int_t fEventsSelected
Definition: AnalysisTaskMultiPairAnalysis.h:65
PairAnalysisMC.h
AnalysisTaskMultiPairAnalysis::fTimer
TStopwatch fTimer
Definition: AnalysisTaskMultiPairAnalysis.h:67
ClassImp
ClassImp(AnalysisTaskMultiPairAnalysis) AnalysisTaskMultiPairAnalysis
Definition: AnalysisTaskMultiPairAnalysis.cxx:43
PairAnalysisEvent::Init
void Init()
Definition: PairAnalysisEvent.cxx:181
AnalysisTaskMultiPairAnalysis::fEventFilter
AnalysisCuts * fEventFilter
Definition: AnalysisTaskMultiPairAnalysis.h:62
AnalysisTaskMultiPairAnalysis.h
AnalysisTaskMultiPairAnalysis::fEventsTotal
Int_t fEventsTotal
event handler
Definition: AnalysisTaskMultiPairAnalysis.h:64
PairAnalysisMetaData::GetMetaData
const TList * GetMetaData() const
Definition: PairAnalysisMetaData.h:45
PairAnalysis.h
h
Data class with information on a STS local track.
AnalysisTaskMultiPairAnalysis::fListHistos
TList fListHistos
Definition: AnalysisTaskMultiPairAnalysis.h:58
PairAnalysis::GetHistogramList
const THashList * GetHistogramList() const
Definition: PairAnalysis.h:105
AnalysisTaskMultiPairAnalysis::AnalysisTaskMultiPairAnalysis
AnalysisTaskMultiPairAnalysis()
PairAnalysis::GetPairArraysPointer
TObjArray ** GetPairArraysPointer()
Definition: PairAnalysis.h:87
PairAnalysisMetaData::Init
void Init()
Definition: PairAnalysisMetaData.cxx:63
PairAnalysisEvent::SetInput
void SetInput(FairRootManager *man)
Definition: PairAnalysisEvent.cxx:122
PairAnalysis::GetHistoManager
PairAnalysisHistos * GetHistoManager() const
Definition: PairAnalysis.h:104
PairAnalysisVarManager::SetValue
static void SetValue(ValueTypes var, Double_t val)
Definition: PairAnalysisVarManager.h:372
AnalysisTaskMultiPairAnalysis::fListPairAnalysis
TList fListPairAnalysis
output array
Definition: AnalysisTaskMultiPairAnalysis.h:56
AnalysisCuts::IsSelected
virtual Bool_t IsSelected(Double_t *const)
Definition: AnalysisCuts.h:19
PairAnalysisEvent
Definition: PairAnalysisEvent.h:25
PairAnalysisMC::ConnectMCEvent
Bool_t ConnectMCEvent()
Definition: PairAnalysisMC.cxx:101
PairAnalysis::GetCutStepHistogramList
THashList * GetCutStepHistogramList() const
Definition: PairAnalysis.h:109
PairAnalysis::GetHistogramArray
const TObjArray * GetHistogramArray() const
Definition: PairAnalysis.h:94
PairAnalysis::DontClearArrays
Bool_t DontClearArrays() const
Definition: PairAnalysis.h:147
PairAnalysis
Definition: PairAnalysis.h:22
PairAnalysisMetaData.h
AnalysisTaskMultiPairAnalysis::fBeamEnergy
Double_t fBeamEnergy
List of histogram manager lists in the framework classes.
Definition: AnalysisTaskMultiPairAnalysis.h:60
PairAnalysisVarManager::GetData
static Double_t * GetData()
Definition: PairAnalysisVarManager.h:386
CbmRichElectronIdAnn.h
Implementation of the electron identification algorithm in the RICH detector using Artificial Neural ...
PairAnalysisMC::Instance
static PairAnalysisMC * Instance()
AnalysisTaskMultiPairAnalysis::fInputEvent
PairAnalysisEvent * fInputEvent
Definition: AnalysisTaskMultiPairAnalysis.h:63
AnalysisTaskMultiPairAnalysis::fMetaData
PairAnalysisMetaData fMetaData
Definition: AnalysisTaskMultiPairAnalysis.h:54
AnalysisTaskMultiPairAnalysis::fPairArray
TObjArray * fPairArray
List of meta data in the framework classes.
Definition: AnalysisTaskMultiPairAnalysis.h:55
AnalysisTaskMultiPairAnalysis::fProcInfo
ProcInfo_t fProcInfo
stopwatch for cpu consumption
Definition: AnalysisTaskMultiPairAnalysis.h:68
PairAnalysisHistos.h
PairAnalysis::DoEventProcess
Bool_t DoEventProcess() const
Definition: PairAnalysis.h:173
PairAnalysisEvent.h
PairAnalysisEvent::Clear
virtual void Clear(Option_t *opt="C")
Definition: PairAnalysisEvent.cxx:574