BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
run_reco_bmn.C
Go to the documentation of this file.
1// Macro for reconstruction of simulated and experimental BM@N events
2//
3// inFileName - input file with data (MC or exp. data)
4// dstFileName - output file with reconstructed data (full DST format)
5// nStartEvent - number of first event to process (starts with zero), default: 0
6// nEvents - number of events to process after nStartEvent, 0 - all events of the given file after nStartEvent to
7// process
8R__ADD_INCLUDE_PATH($VMCWORKDIR)
15
16void run_reco_bmn(TString inFileName = "$VMCWORKDIR/macro/run/bmnsim.root",
17 TString dstFileName = "$VMCWORKDIR/macro/run/bmndst.root",
18 Int_t nStartEvent = 0,
19 Int_t nEvents = 10,
20 enumTracking tracking = VectorFinder)
21{
22 gDebug = 0; // Debug option
23 // Verbosity level (0 = summary only, 1 = event-level, 2 = track-level, 3 = full debug)
24 Int_t iVerbose = 0;
25 FairLogger::GetLogger()->SetLogScreenLevel("info");
26
27 // ----- Timer ---------------------------------------------------------
28 TStopwatch timer;
29 timer.Start();
30
31 // check input file exists
32 if (!BmnFunctionSet::CheckFileExist(inFileName, 1))
33 exit(-1);
34
35 // ----- Reconstruction run --------------------------------------------
36 FairRunAna* fRunAna = new FairRunAna();
37 fRunAna->SetEventHeader(new DstEventHeader());
38
39 Bool_t isTarget = kTRUE; // flag for tracking (run with target or not)
40 Bool_t isExp = (BmnFunctionSet::isSimulationFile(inFileName)
41 == 0); // flag for FairRunAna tasks whether simulation or experimental data are used
42
43 // Declare input source as simulation file or experimental data
44 FairSource* fFileSource;
45
46 // -1 means use of the BM@N-setup when processing MC-input
47 // DO NOT change it manually!
48 Int_t run_period = 8, run_number = -1;
49 Double_t fieldScale = 0.;
50 if (!isExp) // for simulation files
51 fFileSource = new FairFileSource(inFileName);
52 else // for experimental files
53 {
54 // set source as raw root data file (without additional directories)
55 fFileSource = new BmnFileSource(inFileName, run_period, run_number);
56
57 // get geometry for run from the Geometry Database
58 GeoSetup gSetup;
59 string setupTag = gSetup.GetLastApprovedSetupTag(TString::Format("run%d", run_period).Data());
60 Int_t res_code = gSetup.LoadSetupToGeoManager(setupTag);
61 if (res_code != 0) {
62 cout << "ERROR: could not load geometry '" << setupTag << "' from the Geometry Database" << endl;
63 exit(-3);
64 }
65
66 // set magnet field with factor corresponding to the given run
67 UniRun* pCurrentRun = UniRun::GetRun(run_period, run_number);
68 if (pCurrentRun == 0)
69 exit(-6);
70 Double_t* field_voltage = pCurrentRun->GetFieldVoltage();
71 if (field_voltage == NULL) {
72 cout << "ERROR: no field voltage was found for run " << run_period << ":" << run_number << endl;
73 exit(-7);
74 }
75 Double_t map_current = (run_period == 8) ? 112.0 : (run_period == 7) ? 55.87 : 0.0;
76 if (*field_voltage < 10) {
77 fieldScale = 0;
78 } else
79 fieldScale = (*field_voltage) / map_current;
80
81 BmnFieldMap* magField = new BmnNewFieldMap("FieldMap_1900_extrap_noPed.root");
82 magField->SetScale(fieldScale);
83 magField->Init();
84 fRunAna->SetField(magField);
85 isExp = kTRUE;
86 TString targ = "-";
87 if (pCurrentRun->GetTargetParticle() == "") {
88 isTarget = kFALSE;
89 } else {
90 targ = pCurrentRun->GetTargetParticle();
91 isTarget = kTRUE;
92 }
93 TString beam = pCurrentRun->GetBeamParticle();
94 if (beam == "")
95 beam = "-";
96 cout << "\n\n|||||||||||||||| EXPERIMENTAL RUN SUMMARY ||||||||||||||||" << endl;
97 cout << "||\t\t\t\t\t\t\t||" << endl;
98 cout << "||\t\tPeriod:\t\t" << run_period << "\t\t\t||" << endl;
99 cout << "||\t\tNumber:\t\t" << run_number << "\t\t\t||" << endl;
100 cout << "||\t\tBeam:\t\t" << beam << "\t\t\t||" << endl;
101 cout << "||\t\tTarget:\t\t" << targ << "\t\t\t||" << endl;
102 cout << "||\t\tField scale:\t" << setprecision(4) << fieldScale << "\t\t\t||" << endl;
103 cout << "||\t\t\t\t\t\t\t||" << endl;
104 cout << "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||\n\n" << endl;
105 remove(geoFileName.Data());
106 }
107
108 fRunAna->SetSource(fFileSource);
109
110 if (dstFileName == "")
111 dstFileName = "bmndst.root";
112 // if directory for the output file does not exist, then create
113 if (BmnFunctionSet::CreateDirectoryTree(dstFileName, 1) < 0)
114 exit(-2);
115 fRunAna->SetSink(new FairRootFileSink(dstFileName));
116 fRunAna->SetGenerateRunInfo(false);
117
118 // if nEvents is equal 0 then all events of the given file starting with "nStartEvent" should be processed
119 if (nEvents == 0)
120 nEvents = MpdGetNumEvents::GetNumROOTEvents((char*)inFileName.Data()) - nStartEvent;
121
122 // Digitisation files.
123 // Add TObjectString file names to a TList which is passed as input to the FairParAsciiFileIo.
124 // The FairParAsciiFileIo will create on fly a concatenated input parameter file, which is then used during the
125 // reconstruction.
126 TList* parFileNameList = new TList();
127
128 // ====================================================================== //
129 // === Fill basic trigger information === //
130 // ====================================================================== //
131 BmnFillTrigInfoDst* trig = new BmnFillTrigInfoDst(isExp);
132 fRunAna->AddTask(trig);
133
134 // ====================================================================== //
135 // === Hits in front of the target === //
136 // ====================================================================== //
137 if (run_period >= 8) {
138 if (isExp) {
139 BmnSiBTHitMaker* sibtHM = new BmnSiBTHitMaker(run_period, run_number, isExp);
140 fRunAna->AddTask(sibtHM);
141 }
142 } else {
143 if (!isExp) {
145 fRunAna->AddTask(mwpcHP);
146 }
147 BmnMwpcHitFinder* mwpcHM = new BmnMwpcHitFinder(isExp, run_period, run_number);
148 fRunAna->AddTask(mwpcHM);
149 }
150
151 // ====================================================================== //
152 // === Silicon hit finder === //
153 // ====================================================================== //
154 BmnSiliconHitMaker* siliconHM = new BmnSiliconHitMaker(run_period, run_number, isExp);
155 if (isExp)
156 siliconHM->SetHitMatching(kFALSE);
157 fRunAna->AddTask(siliconHM);
158
159 // ====================================================================== //
160 // === GEM hit finder === //
161 // ====================================================================== //
162 BmnGemStripHitMaker* gemHM = new BmnGemStripHitMaker(run_period, run_number, isExp);
163 if (isExp)
164 gemHM->SetHitMatching(kFALSE);
165 fRunAna->AddTask(gemHM);
166
167 // ====================================================================== //
168 // === CSC hit finder === //
169 // ====================================================================== //
170 BmnCSCHitMaker* cscHM = new BmnCSCHitMaker(run_period, run_number, isExp);
171 if (!isExp)
172 cscHM->SetCurrentConfig(BmnCSCConfiguration::FullCSC_Run8); // set explicitly
173 if (isExp)
174 cscHM->SetHitMatching(kFALSE);
175 fRunAna->AddTask(cscHM);
176
177 // ====================================================================== //
178 // === TOF1 hit finder === //
179 // ====================================================================== //
180 BmnTof1HitProducer* tof1HP = new BmnTof1HitProducer("TOF1", !isExp, iVerbose, kFALSE);
181 tof1HP->SetPeriodRun(run_period, run_number);
182 fRunAna->AddTask(tof1HP);
183
184 // ====================================================================== //
185 // === TOF2 hit finder === //
186 // ====================================================================== //
187 BmnTofHitProducer* tof2HP = new BmnTofHitProducer("TOF", "TOF700_geometry_run8.txt", !isExp, iVerbose, kFALSE);
188 tof2HP->SetTimeResolution(0.115);
189 tof2HP->SetProtonTimeCorrectionFile("bmn_run9687_digi_calibration.root");
190 tof2HP->SetMCTimeFile("TOF700_MC_xenon_dcmsmm_time_run8.txt");
191 tof2HP->SetMainStripSelection(0); // 0 - minimal time, 1 - maximal amplitude
193 3); // 0 - Petukhov, 1 - Panin SRC, 2 - Petukhov Argon (default), 3 - Petukhov Xenon (preliminary)
194 tof2HP->SetTimeMin(-2.f); // minimal digit time
195 tof2HP->SetTimeMax(+50.f); // Maximal digit time
196 tof2HP->SetDiffTimeMaxSmall(1.2f); // Abs maximal difference for small chambers
197 tof2HP->SetDiffTimeMaxBig(3.5f); // Abs maximal difference for big chambers
198 fRunAna->AddTask(tof2HP);
199
200 // ====================================================================== //
201 // === DCH hit finder === //
202 // ====================================================================== //
203 // if (!isExp) {
204 // BmnDchHitProducer* dchHP = new BmnDchHitProducer();
205 // fRunAna->AddTask(dchHP);
206 // }
207
208 // ====================================================================== //
209 // === FHCAL/ZDC === //
210 // ====================================================================== //
211 bool IsGlobalCoordinates = true;
212 if (run_period >= 8) {
213 // TODO check isExp
214 BmnFHCalReconstructor* fhcalReco = new BmnFHCalReconstructor(isExp, IsGlobalCoordinates);
215 fhcalReco->SetRecoCutsFile("FHCAL_reco_cuts_period8.txt");
216 fRunAna->AddTask(fhcalReco);
217 } else {
218 BmnZdcAnalyzer* zdcAna = new BmnZdcAnalyzer();
219 fRunAna->AddTask(zdcAna);
220 }
221
222 // ====================================================================== //
223 // === ScWall === //
224 // ====================================================================== //
225 IsGlobalCoordinates = true;
226 BmnScWallReconstructor* scwallReco = new BmnScWallReconstructor(isExp, IsGlobalCoordinates);
227 scwallReco->SetRecoCutsFile("SCWALL_reco_cuts_period8.txt");
228 fRunAna->AddTask(scwallReco);
229
230 // ====================================================================== //
231 // === Hodo === //
232 // ====================================================================== //
233
234 BmnHodoReconstructor* hodoReco = new BmnHodoReconstructor("", isExp);
235 hodoReco->SetRecoCutsFile("HODO_reco_cuts_period8.txt");
236 fRunAna->AddTask(hodoReco);
237
238 // ====================================================================== //
239 // === Ndet === //
240 // ====================================================================== //
241 IsGlobalCoordinates = true;
242 BmnNdetReconstructor* ndetReco = new BmnNdetReconstructor(isExp, IsGlobalCoordinates);
243 ndetReco->SetRecoCutsFile("NDET_reco_cuts_period8.txt");
244 fRunAna->AddTask(ndetReco);
245
246 // ====================================================================== //
247 // === Vacuum Wall === //
248 // ====================================================================== //
249
251 fRunAna->AddTask(vacReco);
252
253 // ====================================================================== //
254 // === Inner Tracking === //
255 // ====================================================================== //
256 TString innerTrackBranchName; // use different track container
257 if (tracking == L1Tracking)
258 innerTrackBranchName = "StsTrack";
259 else
260 innerTrackBranchName = "StsVector";
261 if (run_period >= 8) {
262 BmnToCbmHitConverter* hitConverter = new BmnToCbmHitConverter(iVerbose, isExp);
263 // AZ-150224 hitConverter->SetFixedErrors(0.05, 0.25, 0.02, 0.65);
264 hitConverter->SetFixedErrors(0.08 / sqrt(12) * 1.2, 0.1234, 0.01 / sqrt(12), 0.1234); // AZ-150224
265 // hitConverter->EnableAlignment(kFALSE);
266 fRunAna->AddTask(hitConverter);
267
268 CbmKF* kalman = new CbmKF();
269 fRunAna->AddTask(kalman);
270
271 CbmL1* l1 = new CbmL1();
272 TString stsMatBudgetFile = "";
273 l1->SetMaterialBudgetFileName(stsMatBudgetFile);
274 fRunAna->AddTask(l1);
275
276 if (tracking == L1Tracking) {
277 FairTask* stsFindTracks = new CbmStsFindTracks(iVerbose, "CbmL1StsTrackFinder");
278 fRunAna->AddTask(stsFindTracks);
279 }
280 if (tracking == VectorFinder) {
282 vf->SetMatBudgetFileName("$VMCWORKDIR/parameters/sts_matbudget_run8.root");
283 fRunAna->AddTask(vf);
284 }
285
286 BmnStsMatchTracks* stsMatchTracks = new BmnStsMatchTracks(iVerbose);
287 stsMatchTracks->SetTrackBranch(innerTrackBranchName);
288 fRunAna->AddTask(stsMatchTracks);
289
290 } else {
291 BmnInnerTrackingRun7* innerTF = new BmnInnerTrackingRun7(run_number, isTarget);
292 innerTF->SetFiltration(isExp); // we use filtration for experimental data only now
293 fRunAna->AddTask(innerTF);
294 }
295
296 // ====================================================================== //
297 // === Beam Tracking === //
298 // ====================================================================== //
299 if (run_period >= 8) {
300 if (isExp) {
301 BmnBeamTracking* beamTF = new BmnBeamTracking(run_period);
302 fRunAna->AddTask(beamTF);
303 }
304 } else {
305 BmnMwpcTrackFinder* mwpcTF = new BmnMwpcTrackFinder(isExp, run_period, run_number);
306 fRunAna->AddTask(mwpcTF);
307 }
308
309 // ====================================================================== //
310 // === Tracking (DCH) === //
311 // ====================================================================== //
312 // BmnDchTrackFinder* dchTF = new BmnDchTrackFinder(run_period, run_number, isExp);
313 // dchTF->SetTransferFunction("transfer_func.txt");
314 // fRunAna->AddTask(dchTF);
315
316 // ====================================================================== //
317 // === Primary vertex finding === //
318 // ====================================================================== //
319 // if (run_period >= 8) {
320 CbmPrimaryVertexFinder* pvFinder = new CbmPVFinderKF();
321 CbmFindPrimaryVertex* findVertex = new CbmFindPrimaryVertex(pvFinder);
322 findVertex->SetTrackBranch(innerTrackBranchName);
323 fRunAna->AddTask(findVertex);
324
325 // AZ-150224
327 fRunAna->AddTask(pvMPD);
328 //
329 // // } else {
330 // BmnVertexFinder* gemVF = new BmnVertexFinder(run_period);
331 // fRunAna->AddTask(gemVF);
332 //}
333
334 // ====================================================================== //
335 // === Global Tracking === //
336 // ====================================================================== //
338 glTF->SetInnerTracksBranchName(innerTrackBranchName);
339 fRunAna->AddTask(glTF);
340
341 // BmnVertexFinder* gemVF = new BmnVertexFinder(run_period);
342 // fRunAna->AddTask(gemVF);
343
344 // ====================================================================== //
345 // === Matching global track to MC track procedure === //
346 // ====================================================================== //
347 if (!isExp) {
348 BmnMatchRecoToMC* mcMatching = new BmnMatchRecoToMC();
349 mcMatching->SetInnerTracksBranchName(innerTrackBranchName);
350 fRunAna->AddTask(mcMatching);
351 }
352
353 // ====================================================================== //
354 // === PID procedure === //
355 // ====================================================================== //
356 BmnPid* pid_analyser = new BmnPid();
357 fRunAna->AddTask(pid_analyser);
358
359 // ====================================================================== //
360 // === Residual analysis === //
361 // ====================================================================== //
362 if (run_period < 8) {
363 BmnResiduals* res = new BmnResiduals(run_period, run_number);
364 fRunAna->AddTask(res);
365 }
366
367 // ====================================================================== //
368 // === Centrality === //
369 // ====================================================================== //
370 CentralityClusterizer* cclusterizer = new CentralityClusterizer("XeCsI@3.8AGeV_MBT_7clusters_period8.root");
371 fRunAna->AddTask(cclusterizer);
372
373 // Fill DST Event Header
374 BmnFillDstTask* dst_task = new BmnFillDstTask(nEvents, isExp, run_period, run_number);
375 fRunAna->AddTask(dst_task);
376
377 // ----- Parameter database (input) -------------------------------------
378 FairRuntimeDb* rtdb = fRunAna->GetRuntimeDb();
379 FairParRootFileIo* parIo1 = new FairParRootFileIo();
380 FairParAsciiFileIo* parIo2 = new FairParAsciiFileIo();
381 parIo1->open(inFileName.Data());
382 parIo2->open(parFileNameList, "in");
383 rtdb->setFirstInput(parIo1);
384 rtdb->setSecondInput(parIo2);
385 // -------------------------------------------------------------------------
386
387 // ----- Initialize FaiRunAna --------------------------------------------
388 fRunAna->GetMainTask()->SetVerbose(iVerbose);
389 fRunAna->Init();
390 // -------------------------------------------------------------------------
391
392 // ----- Parameter database (output) ------------------------------------
393 FairParRootFileIo* parOut = new FairParRootFileIo(kTRUE);
394 // parOut->open(dstFileName);
395 parOut->open(gFile);
396 rtdb->setOutput(parOut);
397 rtdb->writeContainer(rtdb->getContainer("FairGeoParSet"), rtdb->getCurrentRun());
398 rtdb->saveOutput();
399 // rtdb->print();
400
401 // ----- Run FairRunAna -------------------------------------------------
402 fRunAna->Run(nStartEvent, nStartEvent + nEvents);
403 // -------------------------------------------------------------------------
404
405 // ----- Finish --------------------------------------------------------
406 delete fRunAna;
407 timer.Stop();
408 Double_t rtime = timer.RealTime();
409 Double_t ctime = timer.CpuTime();
410 cout << endl << endl;
411 cout << "Macro finished successfully." << endl; // marker of successful execution
412 cout << "Input file is " + inFileName << endl;
413 cout << "Output file is " + dstFileName << endl;
414 cout << "Real time " << rtime << " s, CPU time " << ctime << " s" << endl;
415 cout << endl;
416 // ------------------------------------------------------------------------
417}
bool Bool_t
int Int_t
Int_t gDebug
constexpr Bool_t kFALSE
double Double_t
constexpr Bool_t kTRUE
#define R__ADD_INCLUDE_PATH(PATH)
#define gFile
enumTracking
@ L1Tracking
@ VectorFinder
void SetCurrentConfig(BmnCSCConfiguration::CSC_CONFIG config)
void SetHitMatching(Bool_t opt=kTRUE)
Class for BmnFHCalEvent reconstruction (creation) from BmnFHCalDigi {Data} or BmnFHCalDigit {Sim}...
void SetRecoCutsFile(TString reco_cuts_file)
void SetScale(Double_t factor)
Set a global field scaling factor.
Definition BmnFieldMap.h:55
virtual void Init()
BmnFileSource.h.
static int CreateDirectoryTree(TString &fileName, int iVerbose=0, EAccessMode mode=kWritePermission)
static int isSimulationFile(TString fileName="")
static int CheckFileExist(TString &fileName, int iVerbose=0, EAccessMode mode=kFileExists)
void SetHitMatching(Bool_t opt=kTRUE)
void SetInnerTracksBranchName(TString name)
Class for BmnHodoEvent reconstruction (creation) from BmnHodoDigi {Data} or BmnHodoDigit {Sim}...
void SetRecoCutsFile(const std::string &cuts)
The BmnKFPrimaryVertexFinder class - adaptation of MpdKfPrimaryVertexFinder.
void SetInnerTracksBranchName(TString name)
Class for BmnNdetEvent reconstruction (creation) from BmnNdetDigi {Data} or BmnNdetDigit {Sim}...
void SetRecoCutsFile(const std::string &cuts)
Field Map does not have any symmetries w.r.t coordinate axises.
Class for BmnScWallEvent reconstruction (creation) from BmnScWallDigi {Data} or BmnScWallDigit {Sim}...
void SetRecoCutsFile(TString reco_cuts_file)
void SetHitMatching(Bool_t opt=kTRUE)
void SetTrackBranch(TString trBranch="StsTrack")
BmnStsVectorFinder.h.
void SetMatBudgetFileName(TString s)
void SetFixedErrors(Float_t dXgem=0.015, Float_t dYgem=0.058, Float_t dXsil=0.003, Float_t dYsil=0.021)
void SetPeriodRun(Int_t p, Int_t r)
void SetTimeResolution(Double_t sigma)
void SetDiffTimeMaxSmall(Double_t ds=0.)
void SetTimeMax(Double_t ma=+15.)
void SetSelectXYCalibration(Int_t s=0)
void SetMCTimeFile(const char *file)
void SetDiffTimeMaxBig(Double_t db=0.)
void SetMainStripSelection(Int_t s=0)
void SetProtonTimeCorrectionFile(const char *file)
void SetTimeMin(Double_t mi=-2.)
Class for BmnVacWall points info transition on reconstruction stage.
void SetTrackBranch(TString trBranch="StsTrack")
The CbmKF Kalman Filter algorithm.
Definition CbmKF.h:28
Definition CbmL1.h:48
void SetMaterialBudgetFileName(TString s)
Definition CbmL1.h:86
CbmPVFinderKF.
CbmStsFindTracks.
Class for event centrality determination through clusterization.
GeoSetup class.
Definition GeoSetup.h:40
int LoadSetupToGeoManager(string_view setup_tag)
Load selected geometry setup from the Local Geometry Database and create gGeoManager instance.
Definition GeoSetup.cxx:512
string GetLastApprovedSetupTag(string_view tag_prefix)
Get tag for the last approved setup corresponding to the pattern.
Definition GeoSetup.cxx:122
static Int_t GetNumROOTEvents(const char *filename, const char *treename="", int iVerbose=2)
Double_t RealTime()
void Start(Bool_t reset=kTRUE)
Double_t CpuTime()
void Stop()
static TString Format(const char *fmt,...)
UniRun.h Class for the table: run_.
Definition UniRun.h:21
static UniRun * GetRun(int period_number, int run_number)
get run from the database
Definition UniRun.cxx:161
TString GetBeamParticle()
get beam particle of the current run
Definition UniRun.h:109
double * GetFieldVoltage()
get field voltage of the current run
Definition UniRun.h:121
TString GetTargetParticle()
get target particle of the current run
Definition UniRun.h:111
RVec< PromoteType< T > > sqrt(const RVec< T > &v)