BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
run8_reco_bmn.cxx
Go to the documentation of this file.
1#if !defined(__CLING__) || defined(__MAKECLING__)
2// ROOT includes
3#include "TKey.h"
4#include "TList.h"
5#include "TPRegexp.h"
6#include "TROOT.h"
7#include "TRandom3.h"
8#include "TStopwatch.h"
9#include "TString.h"
10#include "TSystem.h"
11
12// Fair includes
13#include "FairCave.h"
14#include "FairField.h"
15#include "FairFileSource.h"
16#include "FairMagnet.h"
17#include "FairParAsciiFileIo.h"
18#include "FairParRootFileIo.h"
19#include "FairPipe.h"
20#include "FairRootFileSink.h"
21#include "FairRunAna.h"
22#include "FairRuntimeDb.h"
23#include "FairTask.h"
24#include "FairTrackParP.h"
25
26// BM@N includes
27#include "BmnBeamTracking.h"
28#include "BmnCSCHitMaker.h"
29#include "BmnCounterTask.h"
30#include "BmnDchHitProducer.h"
31#include "BmnDchTrackFinder.h"
32#include "BmnFieldMap.h"
33#include "BmnFileSource.h"
34#include "BmnFillDstTask.h"
35#include "BmnFunctionSet.h"
36#include "BmnGemResiduals.h"
37#include "BmnGemStripHitMaker.h"
38#include "BmnGemTrack.h"
39#include "BmnGlobalTracking.h"
41#include "BmnLANDHitProducer.h"
42#include "BmnMwpcHitFinder.h"
43#include "BmnMwpcHitProducer.h"
44#include "BmnMwpcTrackFinder.h"
45#include "BmnNewFieldMap.h"
46#include "BmnPid.h"
47#include "BmnSiBTHitMaker.h"
48#include "BmnSiResiduals.h"
49#include "BmnSiliconHitMaker.h"
50#include "BmnTof1HitProducer.h"
51#include "BmnTofHitProducer.h"
52#include "BmnTriggersCheck.h"
53#include "BmnVertexFinder.h"
54#include "BmnZdcAnalyzer.h"
55#include "DstEventHeader.h"
56#include "GeoSetup.h"
57#include "MpdGetNumEvents.h"
58#include "UniRun.h"
59// L1 tracking
60#include "BmnToCbmHitConverter.h"
61#include "CbmFindPrimaryVertex.h"
62#include "CbmKF.h"
63#include "CbmL1.h"
64#include "CbmL1StsTrackFinder.h"
65#include "CbmPVFinderKF.h"
66#include "CbmStsFindTracks.h"
67#include "CbmStsTrackFinder.h"
68
69#include <iostream>
70using namespace std;
71#endif
72
73// -----------------------------------------------------------------------------
74// Macro for reconstruction of simulated or experimental events.
75//
76// inputFileName - input file with data.
77//
78// To process experimental data, you must use 'runN-NNN:'-like prefix
79// and then the geometry will be obtained from the Unified Condition Database.
80//
81// bmndstFileName - output file with reconstructed data.
82//
83// nStartEvent - number of first event to process (starts with zero), default: 0.
84//
85// nEvents - number of events to process, 0 - all events of given file will be
86// processed, default: 10000.
87//
88// alignCorrFileName - argument for choosing input file with the alignment
89// corrections.
90//
91// If alignCorrFileName == 'default', (case insensitive) then corrections are
92// retrieved from UniDb according to the running period and run number.
93//
94// If alignCorrFileName == '', then no corrections are applied at all.
95//
96// If alignCorrFileName == '<path>/<file-name>', then the corrections are taken
97// from that file.
98
99// #include "../run/bmnloadlibs.C"
100#define L1
101
102void run8_reco_bmn(TString inputFileName = "$VMCWORKDIR/macro/run8/bmnsim.root",
103 TString bmndstFileName = "$VMCWORKDIR/macro/run8/bmndst.root",
104 Int_t nStartEvent = 0,
105 Int_t nEvents = 10)
106{
107 gDebug = 0; // Debug option
108 // Verbosity level (0 = quiet (progress bar), 1 = event-level, 2 = track-level, 3 = full debug)
109 Int_t iVerbose = 0;
110
111 // ----- Timer ---------------------------------------------------------
112 TStopwatch timer;
113 timer.Start();
114
115 // check input file exists
116 if (!BmnFunctionSet::CheckFileExist(inputFileName, 1))
117 exit(-1);
118
119 // ----- Reconstruction run --------------------------------------------
120 FairRunAna* fRunAna = new FairRunAna();
121 fRunAna->SetEventHeader(new DstEventHeader());
122
123 Bool_t isField =
124 (inputFileName.Contains("noField")) ? kFALSE : kTRUE; // flag for tracking (to use mag.field or not)
125 Bool_t isTarget = kTRUE; // kTRUE; // flag for tracking (run with target or not)
127 inputFileName); // flag for hit finder (to create digits or take them from data-file)
128
129 // Declare input source as simulation file or experimental data
130 FairSource* fFileSource;
131
132 // -1 means use of the BM@N-setup when processing MC-input
133 // DO NOT change it manually!
134 Int_t run_period = 8, run_number = -1;
135 Double_t fieldScale = 0.;
136 if (!isExp) // for simulation files
137 fFileSource = new FairFileSource(inputFileName);
138 else // for experimental files
139 {
140 // set source as raw root data file (without additional directories)
141 fFileSource = new BmnFileSource(inputFileName, run_period, run_number);
142
143 // get geometry for run from the Geometry Database
144 GeoSetup gSetup;
145 string setupTag = gSetup.GetLastApprovedSetupTag(TString::Format("run%d", run_period).Data());
146 Int_t res_code = gSetup.LoadSetupToGeoManager(setupTag);
147 if (res_code != 0) {
148 cout << "ERROR: could not load geometry '" << setupTag << "' from the Geometry Database" << endl;
149 exit(-3);
150 }
151
152 // set magnet field with factor corresponding to the given run
153 UniRun* pCurrentRun = UniRun::GetRun(run_period, run_number);
154 if (pCurrentRun == 0)
155 exit(-6);
156 Double_t* field_voltage = pCurrentRun->GetFieldVoltage();
157 if (field_voltage == NULL) {
158 cout << "ERROR: no field voltage was found for run " << run_period << ":" << run_number << endl;
159 exit(-7);
160 }
161 Double_t map_current = 55.87;
162 if (*field_voltage < 10) {
163 fieldScale = 0;
164 isField = kFALSE;
165 } else
166 fieldScale = (*field_voltage) / map_current;
167
168 BmnFieldMap* magField = new BmnNewFieldMap("field_sp41v5_ascii_Extrap.root");
169 magField->SetScale(fieldScale);
170 magField->Init();
171 fRunAna->SetField(magField);
172 isExp = kTRUE;
173 TString targ = "-";
174 if (pCurrentRun->GetTargetParticle() == "") {
175 isTarget = kFALSE;
176 } else {
177 targ = pCurrentRun->GetTargetParticle();
178 isTarget = kTRUE;
179 }
180 TString beam = pCurrentRun->GetBeamParticle();
181 if (beam == "")
182 beam = "-";
183 cout << "\n\n|||||||||||||||| EXPERIMENTAL RUN SUMMARY ||||||||||||||||" << endl;
184 cout << "||\t\t\t\t\t\t\t||" << endl;
185 cout << "||\t\tPeriod:\t\t" << run_period << "\t\t\t||" << endl;
186 cout << "||\t\tNumber:\t\t" << run_number << "\t\t\t||" << endl;
187 cout << "||\t\tBeam:\t\t" << beam << "\t\t\t||" << endl;
188 cout << "||\t\tTarget:\t\t" << targ << "\t\t\t||" << endl;
189 cout << "||\t\tField scale:\t" << setprecision(4) << fieldScale << "\t\t\t||" << endl;
190 cout << "||\t\t\t\t\t\t\t||" << endl;
191 cout << "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||\n\n" << endl;
192 remove(geoFileName.Data());
193 }
194
195 fRunAna->SetSource(fFileSource);
196 // if directory for the output file does not exist, then create
197 if (BmnFunctionSet::CreateDirectoryTree(bmndstFileName, 1) < 0)
198 exit(-2);
199 fRunAna->SetSink(new FairRootFileSink(bmndstFileName));
200 fRunAna->SetGenerateRunInfo(false);
201
202 // if nEvents is equal 0 then all events of the given file starting with "nStartEvent" should be processed
203 if (nEvents == 0)
204 nEvents = MpdGetNumEvents::GetNumROOTEvents((char*)inputFileName.Data()) - nStartEvent;
205
206 // Digitisation files.
207 // Add TObjectString file names to a TList which is passed as input to the FairParAsciiFileIo.
208 // The FairParAsciiFileIo will create on fly a concatenated input parameter file, which is then used during the
209 // reconstruction.
210 TList* parFileNameList = new TList();
211
212 // ====================================================================== //
213 // === MWPC hit finder === //
214 // ====================================================================== //
215 // if(!isExp) {
216 // BmnMwpcHitProducer *mwpcHP = new BmnMwpcHitProducer();
217 // fRunAna->AddTask(mwpcHP);
218 // }
219 // BmnMwpcHitFinder* mwpcHM = new BmnMwpcHitFinder(isExp, run_period, run_number);
220 // fRunAna->AddTask(mwpcHM);
221
222 // ====================================================================== //
223 // === SiBT hit finder === //
224 // ====================================================================== //
225 BmnSiBTHitMaker* sibtHM = new BmnSiBTHitMaker(run_period, run_number, isExp);
226 fRunAna->AddTask(sibtHM);
227
228 // ====================================================================== //
229 // === Silicon hit finder === //
230 // ====================================================================== //
231 BmnSiliconHitMaker* siliconHM = new BmnSiliconHitMaker(run_period, run_number, isExp);
232 fRunAna->AddTask(siliconHM);
233
234 // ====================================================================== //
235 // === GEM hit finder === //
236 // ====================================================================== //
237 BmnGemStripHitMaker* gemHM = new BmnGemStripHitMaker(run_period, run_number, isExp);
238 gemHM->SetHitMatching(kTRUE);
239 fRunAna->AddTask(gemHM);
240
241 // ====================================================================== //
242 // === CSC hit finder === //
243 // ====================================================================== //
244 BmnCSCHitMaker* cscHM = new BmnCSCHitMaker(run_period, run_number, isExp);
245 if (!isExp)
246 cscHM->SetCurrentConfig(BmnCSCConfiguration::Run8); // set explicitly
247 cscHM->SetHitMatching(kTRUE);
248 fRunAna->AddTask(cscHM);
249
250 // ====================================================================== //
251 // === TOF1 hit finder === //
252 // ====================================================================== //
253 BmnTof1HitProducer* tof1HP = new BmnTof1HitProducer("TOF1", !isExp, iVerbose, kFALSE);
254 tof1HP->SetPeriodRun(run_period, run_number);
255 fRunAna->AddTask(tof1HP);
256
257 // ====================================================================== //
258 // === TOF2 hit finder === //
259 // ====================================================================== //
260 BmnTofHitProducer* tof2HP = new BmnTofHitProducer("TOF", "TOF700_geometry_run7.txt", !isExp, iVerbose, kFALSE);
261 tof2HP->SetTimeResolution(0.115);
262 tof2HP->SetProtonTimeCorrectionFile("bmn_run9687_digi_calibration.root");
263 tof2HP->SetMCTimeFile("TOF700_MC_argon_qgsm_time_run7.txt");
264 tof2HP->SetMainStripSelection(0); // 0 - minimal time, 1 - maximal amplitude
265 tof2HP->SetSelectXYCalibration(2); // 0 - Petukhov, 1 - Panin SRC, 2 - Petukhov Argon (default)
266 tof2HP->SetTimeMin(-2.f); // minimal digit time
267 tof2HP->SetTimeMax(+39.f); // Maximal digit time
268 tof2HP->SetDiffTimeMaxSmall(1.2f); // Abs maximal difference for small chambers
269 tof2HP->SetDiffTimeMaxBig(3.5f); // Abs maximal difference for big chambers
270 fRunAna->AddTask(tof2HP);
271
272 // ====================================================================== //
273 // === DCH hit finder === //
274 // ====================================================================== //
275 // if(!isExp) {
276 // BmnDchHitProducer *dchHP = new BmnDchHitProducer();
277 // fRunAna->AddTask(dchHP);
278 // }
279
280 // ====================================================================== //
281 // === ZDC === //
282 // ====================================================================== //
283 BmnZdcAnalyzer* zdcAna = new BmnZdcAnalyzer();
284 fRunAna->AddTask(zdcAna);
285
286#ifdef L1
287 FairTask* hitConverter = new BmnToCbmHitConverter(iVerbose);
288 fRunAna->AddTask(hitConverter);
289
290 // ====================================================================== //
291 // === STS track finding === //
292 // ====================================================================== //
293 CbmKF* kalman = new CbmKF();
294 fRunAna->AddTask(kalman);
295
296 CbmL1* l1 = new CbmL1();
297 TString stsMatBudgetFile =
298 ""; // paramDir + "/sts/sts_matbudget_v12b_12344444.root"; // paramDir + "/sts_matbudget_var_fr.root";
299 l1->SetMaterialBudgetFileName(stsMatBudgetFile);
300 fRunAna->AddTask(l1);
301
302 CbmStsTrackFinder* stsTrackFinder = new CbmL1StsTrackFinder();
303 FairTask* stsFindTracks = new CbmStsFindTracks(iVerbose, stsTrackFinder);
304 fRunAna->AddTask(stsFindTracks);
305#else
306 // ====================================================================== //
307 // === Tracking (InnerTracker) === //
308 // ====================================================================== //
309 BmnInnerTrackingRun7* innerTF = new BmnInnerTrackingRun7(run_number, isField, isTarget);
310 innerTF->SetFiltration(isExp); // we use filtration for experimental data only now
311 fRunAna->AddTask(innerTF);
312#endif
313
314 // ====================================================================== //
315 // === Tracking (BEAM) === //
316 // ====================================================================== //
317 BmnBeamTracking* beamTF = new BmnBeamTracking(run_period);
318 fRunAna->AddTask(beamTF);
319
320 // ====================================================================== //
321 // === Tracking (MWPC) === //
322 // ====================================================================== //
323 BmnMwpcTrackFinder* mwpcTF = new BmnMwpcTrackFinder(isExp, run_period, run_number);
324 fRunAna->AddTask(mwpcTF);
325
326 // ====================================================================== //
327 // === Tracking (DCH) === //
328 // ====================================================================== //
329 BmnDchTrackFinder* dchTF = new BmnDchTrackFinder(run_period, run_number, isExp);
330 dchTF->SetTransferFunction("transfer_func.txt");
331 fRunAna->AddTask(dchTF);
332
333 // ====================================================================== //
334 // === Global Tracking === //
335 // ====================================================================== //
336 Bool_t doAlign = kTRUE;
337 if (!isExp)
338 doAlign = kFALSE;
339 BmnGlobalTracking* glTF = new BmnGlobalTracking(isField, isExp, kFALSE /*doAlign*/);
340 fRunAna->AddTask(glTF);
341
342 // ====================================================================== //
343 // === Primary vertex finding === //
344 // ====================================================================== //
345#ifdef L1
346 CbmPrimaryVertexFinder* pvFinder = new CbmPVFinderKF();
347 CbmFindPrimaryVertex* findVertex = new CbmFindPrimaryVertex(pvFinder);
348 fRunAna->AddTask(findVertex);
349#else
350 BmnVertexFinder* gemVF = new BmnVertexFinder(run_period, isField);
351 fRunAna->AddTask(gemVF);
352#endif
353
354 // ====================================================================== //
355 // === PID procedure === //
356 // ====================================================================== //
357 BmnPid* pid_analyser = new BmnPid();
358 fRunAna->AddTask(pid_analyser);
359
360 // ====================================================================== //
361 // === Residual analysis === //
362 // ====================================================================== //
363 // BmnResiduals* res = new BmnResiduals(run_period, run_number, isField);
364 // fRunAna->AddTask(res);
365
366 // Fill DST Event Header (if iVerbose = 0, then print progress bar)
367 BmnFillDstTask* dst_task = new BmnFillDstTask(nEvents);
368 dst_task->SetRunNumber(run_period, run_number);
369 fRunAna->AddTask(dst_task);
370
371 // ----- Parameter database --------------------------------------------
372 FairRuntimeDb* rtdb = fRunAna->GetRuntimeDb();
373 FairParRootFileIo* parIo1 = new FairParRootFileIo();
374 FairParAsciiFileIo* parIo2 = new FairParAsciiFileIo();
375 parIo1->open(inputFileName.Data());
376 parIo2->open(parFileNameList, "in");
377 rtdb->setFirstInput(parIo1);
378 rtdb->setSecondInput(parIo2);
379 rtdb->setOutput(parIo1);
380 rtdb->saveOutput();
381 // -------------------------------------------------------------------------
382 // ----- Initialize and run --------------------------------------------
383 fRunAna->GetMainTask()->SetVerbose(iVerbose);
384 fRunAna->Init();
385 cout << "Starting run" << endl;
386 fRunAna->Run(nStartEvent, nStartEvent + nEvents);
387 // -------------------------------------------------------------------------
388 // ----- Finish --------------------------------------------------------
389 timer.Stop();
390 Double_t rtime = timer.RealTime();
391 Double_t ctime = timer.CpuTime();
392 cout << endl << endl;
393 cout << "Macro finished successfully." << endl; // marker of successful execution for CDASH
394 cout << "Input file is " + inputFileName << endl;
395 cout << "Output file is " + bmndstFileName << endl;
396 cout << "Real time " << rtime << " s, CPU time " << ctime << " s" << endl;
397 cout << endl;
398 // ------------------------------------------------------------------------
399 // delete fFileSource;
400 // delete fRunAna;
401}
402
403int main(int argc, char** arg)
404{
406}
bool Bool_t
int Int_t
Int_t gDebug
constexpr Bool_t kFALSE
double Double_t
constexpr Bool_t kTRUE
void SetCurrentConfig(BmnCSCConfiguration::CSC_CONFIG config)
void SetHitMatching(Bool_t opt=kTRUE)
void SetTransferFunction(TString name)
void SetScale(Double_t factor)
Set a global field scaling factor.
Definition BmnFieldMap.h:55
virtual void Init()
BmnFileSource.h.
void SetRunNumber(Int_t period_number, Int_t run_number)
Setting period-number information to fill RunHeader.
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)
Field Map does not have any symmetries w.r.t coordinate axises.
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.)
The CbmKF Kalman Filter algorithm.
Definition CbmKF.h:28
Definition CbmL1.h:48
void SetMaterialBudgetFileName(TString s)
Definition CbmL1.h:86
CbmPVFinderKF.
CbmStsFindTracks.
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
void run8_reco_bmn(TString inputFileName="$VMCWORKDIR/macro/run8/bmnsim.root", TString bmndstFileName="$VMCWORKDIR/macro/run8/bmndst.root", Int_t nStartEvent=0, Int_t nEvents=10)
Definition json.hpp:4446
int main(void)
Definition test_FC.cpp:33