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