BmnRoot 26.10.0-233-gb9bbe585
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
dump_hits.C
Go to the documentation of this file.
1/*
2 * Crude macro for dumping hits.
3 *
4 * Made from reconstruction macro by injecting .csv export after
5 * BmnToCbmHitConverter and droppping all other subsequent tasks.
6 *
7 * Author: Polev I.Yu., polev@jinr.int
8 * Date: February 2026
9 */
10
11// Macro for reconstruction of simulated and experimental BM@N events
12//
13// inFileName - input file with data (MC or exp. data)
14// dstFileName - output file with reconstructed data (full DST format)
15// nStartEvent - number of first event to process (starts with zero), default: 0
16// nEvents - number of events to process after nStartEvent, 0 - all events of the given file after nStartEvent to
17// tracking - tracking algorithm: VectorFinder (default), L1Tracking (for online), CellAuto
18// #define USE_GEODB
19R__ADD_INCLUDE_PATH($VMCWORKDIR);
20
28
29/**
30 * @brief Run reconstruction and export the converted hits to .csv.
31 *
32 * The standard reconstruction macro with a BmnHitDumper injected after
33 * BmnToCbmHitConverter and every subsequent task dropped, so it produces hit
34 * dumps rather than a usable DST.
35 *
36 * @param inFileName input file with data, simulated or experimental
37 * @param dstFileName output DST file
38 * @param nStartEvent number of the first event to process, counted from zero
39 * @param nEvents number of events to process, 0 for all of them
40 * @param tracking track finder to use, see enumTracking
41 */
42void dump_hits(TString inFileName = "$VMCWORKDIR/macro/run/bmnsim.root",
43 TString dstFileName = "$VMCWORKDIR/macro/run/bmndst.root",
44 Int_t nStartEvent = 0,
45 Int_t nEvents = 0,
46 enumTracking tracking = VectorFinder)
47{
48 gDebug = 0; // ROOT debug option
49 // if (gEnv) gEnv->SetValue("Root.Stacktrace", 0);
50 // Verbosity level (0 = summary only, 1 = event-level, 2 = track-level, 3 = full debug)
51 Int_t iVerbose = 0;
52 // Log level for LOG(severity): "fatal", "error", "alarm", "important", "warn", "state", "info", "detail", "debug",
53 // "debug[1-4]", "trace", "nolog"
54 FairLogger::GetLogger()->SetLogScreenLevel("info");
55 gRandom->SetSeed(0); // set seed for PRNG
56
57 // ----- Timer ---------------------------------------------------------
58 TStopwatch timer;
59 timer.Start();
60
61 // check input file exists
62 if (!BmnFunctionSet::CheckFileExist(inFileName, 1))
63 exit(-1);
64
65 // ----- Reconstruction run --------------------------------------------
66 FairRunAna* fRunAna = new FairRunAna();
67 fRunAna->SetEventHeader(new DstEventHeader());
68
69 Bool_t isTarget = kTRUE; // flag for tracking (run with target or not)
70 Bool_t isExp = (BmnFunctionSet::isSimulationFile(inFileName)
71 == 0); // flag for FairRunAna tasks whether simulation or experimental data are used
72
73 // Declare input source as simulation file or experimental data
74 FairSource* fFileSource;
75
76 // -1 means use of the BM@N-setup when processing MC-input
77 // DO NOT change it manually!
78 Int_t run_period = 9, run_number = -1;
79 Double_t fieldScale = 0.;
80 if (!isExp) // for simulation files
81 fFileSource = new FairFileSource(inFileName);
82 else // for experimental files
83 {
84 // set source - digit file without auxilary FairRoot directories
85 // returns real run_period and run_number from the source file
86 fFileSource = new BmnFileSource(inFileName, run_period, run_number);
87
88 // get geometry for run
89#ifdef USE_GEODB
90 GeoSetup gSetup;
91 int errStatus = gSetup.LoadSetupToGeoManager("run9_26.01.0");
92 if (errStatus != 0) {
93 cout << "ERROR: Geometry not loaded. Error status " << errStatus << endl;
94 exit(-1);
95 }
96#else
97 TString geoFileName = Form("current_geo_file_%d.root", UInt_t(gRandom->Integer(UINT32_MAX)));
98 Int_t res_code =
99 UniRun::ReadGeometryFile(run_period, run_number, (char*)geoFileName.Data(), usePreviousIfMissing);
100 if (res_code != 0) {
101 cout << "ERROR: could not read geometry file from the database" << endl;
102 exit(-3);
103 }
104
105 // get gGeoManager from ROOT file (if required)
106 TFile* geoFile = new TFile(geoFileName, "READ");
107 if (!geoFile->IsOpen()) {
108 cout << "ERROR: could not open ROOT file with geometry: " + geoFileName << endl;
109 exit(-4);
110 }
111 TList* keyList = geoFile->GetListOfKeys();
112 TIter next(keyList);
113 TKey* key = (TKey*)next();
114 TString className(key->GetClassName());
115 if (className.BeginsWith("TGeoManager"))
116 key->ReadObj();
117 else {
118 cout << "ERROR: TGeoManager is not top element in geometry file " + geoFileName << endl;
119 exit(-5);
120 }
121#endif
122 // set magnetic field with factor corresponding to the given run
123 UniRun* pCurrentRun = UniRun::GetRun(run_period, run_number, usePreviousIfMissing);
124 if (pCurrentRun == 0)
125 exit(-6);
126 Double_t field_voltage = 0;
127 if (pCurrentRun->GetFieldVoltage())
128 field_voltage = *pCurrentRun->GetFieldVoltage();
129 else {
130 if (usePreviousIfMissing) // get value from a previous run with non-null value
131 {
132 int prev_mag_period = run_period, prev_mag_run = run_number;
133 field_voltage = UniRun::FindPreviousFieldVoltage(prev_mag_period, prev_mag_run);
134 if ((field_voltage == 0) and (prev_mag_run == run_number) and (prev_mag_period == run_period)) {
135 cout << "ERROR: no any field voltage was found for run " << run_period << ":" << run_number << endl;
136 exit(-8);
137 }
138 } else {
139 cout << "ERROR: no field voltage was found for run " << run_period << ":" << run_number << endl;
140 exit(-7);
141 }
142 }
143 Double_t map_voltage = (run_period < 8) ? 55.87 : 112.0;
144 FairField* magField = nullptr;
145#ifdef USE_GEODB
146 // the field of the setup is got as it was measured, i.e. at the reference voltage from the Geometry Database
147 magField = gSetup.GetMagneticField();
148 if (gSetup.GetRefVoltage() > 0)
149 map_voltage = gSetup.GetRefVoltage();
150#else
151 magField = new BmnNewFieldMap("FieldMap_1900_extrap_noPed.root");
152#endif
153 if (field_voltage < 10) {
154 fieldScale = 0;
155 } else
156 fieldScale = (field_voltage) / map_voltage;
157 // the scale has to be set before the field initialization, where a field map is read and scaled
158 if (!BmnFunctionSet::SetFieldScale(magField, fieldScale))
159 exit(-9);
160 magField->Init();
161 fRunAna->SetField(magField);
162 isExp = kTRUE;
163 TString targ = "-";
164 if (pCurrentRun->GetTargetParticle() == "") {
165 isTarget = kFALSE;
166 } else {
167 targ = pCurrentRun->GetTargetParticle();
168 isTarget = kTRUE;
169 }
170 TString beam = pCurrentRun->GetBeamParticle();
171 if (beam == "")
172 beam = "-";
173 cout << "\n\n|||||||||||||||| EXPERIMENTAL RUN SUMMARY ||||||||||||||||" << endl;
174 cout << "||\t\t\t\t\t\t\t||" << endl;
175 cout << "||\t\tPeriod:\t\t" << run_period << "\t\t\t||" << endl;
176 cout << "||\t\tNumber:\t\t" << run_number << "\t\t\t||" << endl;
177 cout << "||\t\tBeam:\t\t" << beam << "\t\t\t||" << endl;
178 cout << "||\t\tTarget:\t\t" << targ << "\t\t\t||" << endl;
179 cout << "||\t\tField scale:\t" << setprecision(4) << fieldScale << "\t\t\t||" << endl;
180 cout << "||\t\t\t\t\t\t\t||" << endl;
181 cout << "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||\n\n" << endl;
182#ifndef USE_GEODB
183 remove(geoFileName.Data());
184#endif
185 }
186
187 fRunAna->SetSource(fFileSource);
188
189 if (dstFileName == "")
190 dstFileName = "bmndst.root";
191 // if directory for the output file does not exist, then create
192 if (BmnFunctionSet::CreateDirectoryTree(dstFileName, 1) < 0)
193 exit(-2);
194 fRunAna->SetSink(new FairRootFileSink(dstFileName));
195 fRunAna->SetGenerateRunInfo(false);
196
197 // if nEvents is equal 0 then all events of the given file starting with "nStartEvent" should be processed
198 if (nEvents == 0)
199 nEvents = MpdGetNumEvents::GetNumROOTEvents((char*)inFileName.Data()) - nStartEvent;
200
201 // Digitisation files.
202 // Add TObjectString file names to a TList which is passed as input to the FairParAsciiFileIo.
203 // The FairParAsciiFileIo will create on fly a concatenated input parameter file, which is then used during the
204 // reconstruction.
205 TList* parFileNameList = new TList();
206
207 // ====================================================================== //
208 // === Pileup Event Classification === //
209 // ====================================================================== //
210 if (run_period == 8 && isExp) {
211 BmnEventSelector* eventSelector = new BmnEventSelector();
212 eventSelector->SetRunId(run_number);
213 eventSelector->SetInputFileName("$VMCWORKDIR/input/eventSelector_calib_run8.root");
214 fRunAna->AddTask(eventSelector);
215 }
216
217 // ====================================================================== //
218 // === Fill basic trigger information === //
219 // ====================================================================== //
220 BmnFillTrigInfoDst* trig = new BmnFillTrigInfoDst(isExp);
221 fRunAna->AddTask(trig);
222
223 // ====================================================================== //
224 // === Hits in front of the target === //
225 // ====================================================================== //
226 if (run_period >= 8) {
227 if (isExp) {
228 BmnSiBTHitMaker* sibtHM = new BmnSiBTHitMaker(run_period, run_number, isExp);
229 // fRunAna->AddTask(sibtHM);
230 }
231 } else {
232 if (!isExp) {
234 fRunAna->AddTask(mwpcHP);
235 }
236 BmnMwpcHitFinder* mwpcHM = new BmnMwpcHitFinder(isExp, run_period, run_number);
237 fRunAna->AddTask(mwpcHM);
238 }
239
240 // ====================================================================== //
241 // === VSP hit finder === //
242 // ====================================================================== //
243 BmnVSPHitMaker* vspHM = new BmnVSPHitMaker(run_period, run_number, isExp);
244 if (isExp)
245 vspHM->SetHitMatching(kFALSE);
246 fRunAna->AddTask(vspHM);
247
248 // ====================================================================== //
249 // === Silicon hit finder === //
250 // ====================================================================== //
251 BmnSiliconHitMaker* siliconHM = new BmnSiliconHitMaker(run_period, run_number, isExp);
252 if (isExp)
253 siliconHM->SetHitMatching(kFALSE);
254 fRunAna->AddTask(siliconHM);
255
256 // ====================================================================== //
257 // === GEM hit finder === //
258 // ====================================================================== //
259 BmnGemStripHitMaker* gemHM = new BmnGemStripHitMaker(run_period, run_number, isExp);
260 if (isExp)
261 gemHM->SetHitMatching(kFALSE);
262 fRunAna->AddTask(gemHM);
263
264 // ====================================================================== //
265 // === CSC hit finder === //
266 // ====================================================================== //
267 BmnCSCHitMaker* cscHM = new BmnCSCHitMaker(run_period, run_number, isExp);
268 if (!isExp)
269 cscHM->SetCurrentConfig(BmnCSCConfiguration::FullCSC_Run8); // set explicitly
270 if (isExp)
271 cscHM->SetHitMatching(kFALSE);
272 fRunAna->AddTask(cscHM);
273
274 // ====================================================================== //
275 // === TOF400 hit finder === //
276 // ====================================================================== //
277 BmnTof1HitProducer* tof400HP = new BmnTof1HitProducer("TOF400", kTOF1, !isExp, iVerbose, kFALSE);
278 tof400HP->SetPeriodRun(run_period, run_number);
279 fRunAna->AddTask(tof400HP);
280
281 // ====================================================================== //
282 // === TOF700 hit finder === //
283 // ====================================================================== //
284 BmnTof1HitProducer* tof700HP = new BmnTof1HitProducer("TOF700", kTOF701, !isExp, iVerbose, kFALSE);
285 tof700HP->SetPeriodRun(run_period, run_number);
286 fRunAna->AddTask(tof700HP);
287
288 // ====================================================================== //
289 // === DCH hit finder === //
290 // ====================================================================== //
291 // if (!isExp) {
292 // BmnDchHitProducer* dchHP = new BmnDchHitProducer();
293 // fRunAna->AddTask(dchHP);
294 // }
295
296 // ====================================================================== //
297 // === FHCAL/ZDC === //
298 // ====================================================================== //
299 bool IsGlobalCoordinates = true;
300 if (run_period >= 8) {
301 // TODO check isExp
302 BmnFHCalReconstructor* fhcalReco = new BmnFHCalReconstructor(isExp, IsGlobalCoordinates);
303 fhcalReco->SetRecoCutsFile("FHCAL_reco_cuts_period8.txt");
304 fRunAna->AddTask(fhcalReco);
305 } else {
306 BmnZdcAnalyzer* zdcAna = new BmnZdcAnalyzer();
307 fRunAna->AddTask(zdcAna);
308 }
309
310 // ====================================================================== //
311 // === ScWall === //
312 // ====================================================================== //
313 IsGlobalCoordinates = true;
314 BmnScWallReconstructor* scwallReco = new BmnScWallReconstructor(isExp, IsGlobalCoordinates);
315 scwallReco->SetRecoCutsFile("SCWALL_reco_cuts_period8.txt");
316 fRunAna->AddTask(scwallReco);
317
318 // ====================================================================== //
319 // === Hodo === //
320 // ====================================================================== //
321
322 BmnHodoReconstructor* hodoReco = new BmnHodoReconstructor("HODO_Q_calibration_period8.json", isExp);
323 hodoReco->SetRecoCutsFile("HODO_reco_cuts_period8.json");
324 fRunAna->AddTask(hodoReco);
325
326 // ====================================================================== //
327 // === Ndet === //
328 // ====================================================================== //
329 IsGlobalCoordinates = true;
330 BmnNdetReconstructor* ndetReco = new BmnNdetReconstructor(isExp, IsGlobalCoordinates);
331 ndetReco->SetRecoCutsFile("NDET_reco_cuts_period8.txt");
332 fRunAna->AddTask(ndetReco);
333
334 // ====================================================================== //
335 // === Vacuum Wall === //
336 // ====================================================================== //
337
339 fRunAna->AddTask(vacReco);
340
341 // ====================================================================== //
342 // === Inner Tracking === //
343 // ====================================================================== //
344 TString innerTrackBranchName; // use different track container
345
346 if (tracking == L1Tracking)
347 innerTrackBranchName = "StsTrack";
348 else
349 innerTrackBranchName = "StsVector";
350 if (run_period >= 8) {
351 BmnToCbmHitConverter* hitConverter = new BmnToCbmHitConverter(iVerbose, isExp);
352 // AZ-150224 hitConverter->SetFixedErrors(0.05, 0.25, 0.02, 0.65);
353 // hitConverter->SetFixedErrors(0.08 / sqrt(12) * 1.2, 0.1234, 0.01 / sqrt(12), 0.1234); // AZ-150224
354 // PLV: turn off manual alignment built in BmnToCbmHitConverter
355 hitConverter->EnableAlignment(kFALSE);
356 fRunAna->AddTask(hitConverter);
357
358 // dump all Cbm hits to .csv
359 fRunAna->AddTask(new BmnHitDumper(dstFileName));
360 }
361
362 // ----- Parameter database (input) -------------------------------------
363 FairRuntimeDb* rtdb = fRunAna->GetRuntimeDb();
364 FairParRootFileIo* parIo1 = new FairParRootFileIo();
365 FairParAsciiFileIo* parIo2 = new FairParAsciiFileIo();
366 parIo1->open(inFileName.Data());
367 parIo2->open(parFileNameList, "in");
368 rtdb->setFirstInput(parIo1);
369 rtdb->setSecondInput(parIo2);
370 // -------------------------------------------------------------------------
371
372 // ----- Initialize FaiRunAna --------------------------------------------
373 fRunAna->GetMainTask()->SetVerbose(iVerbose);
374 fRunAna->Init();
375 // -------------------------------------------------------------------------
376
377 // ----- Parameter database (output) ------------------------------------
378 FairParRootFileIo* parOut = new FairParRootFileIo(kTRUE);
379 // parOut->open(dstFileName);
380 parOut->open(gFile);
381 rtdb->setOutput(parOut);
382 rtdb->writeContainer(rtdb->getContainer("FairGeoParSet"), rtdb->getCurrentRun());
383 rtdb->saveOutput();
384 // rtdb->print();
385 // -------------------------------------------------------------------------
386
387 // ----- Run FairRunAna -------------------------------------------------
388 fRunAna->Run(nStartEvent, nStartEvent + nEvents);
389 // -------------------------------------------------------------------------
390
391 // ----- Finish --------------------------------------------------------
392 delete fRunAna;
393 timer.Stop();
394 Double_t rtime = timer.RealTime();
395 Double_t ctime = timer.CpuTime();
396 cout << endl << endl;
397 cout << "Macro finished successfully." << endl; // marker of successful execution
398 cout << "Input file is " + inFileName << endl;
399 cout << "Output file is " + dstFileName << endl;
400 cout << "Real time " << rtime << " s, CPU time " << ctime << " s" << endl;
401 cout << endl;
402 // ------------------------------------------------------------------------
403}
@ kTOF1
@ kTOF701
bool Bool_t
int Int_t
Int_t gDebug
unsigned int UInt_t
constexpr Bool_t kFALSE
double Double_t
constexpr Bool_t kTRUE
#define R__ADD_INCLUDE_PATH(PATH)
#define gFile
R__EXTERN TRandom * gRandom
char * Form(const char *fmt,...)
void SetCurrentConfig(BmnCSCConfiguration::CSC_CONFIG config)
void SetHitMatching(Bool_t opt=kTRUE)
void SetInputFileName(const char *name)
void SetRunId(int runId)
Class for BmnFHCalEvent reconstruction (creation) from BmnFHCalDigi {Data} or BmnFHCalDigit {Sim}...
void SetRecoCutsFile(TString reco_cuts_file)
BmnFileSource.h.
static int CreateDirectoryTree(TString &fileName, int iVerbose=0, EAccessMode mode=kWritePermission)
static bool SetFieldScale(FairField *field, double scale)
static int isSimulationFile(TString fileName="")
static int CheckFileExist(TString &fileName, int iVerbose=0, EAccessMode mode=kFileExists)
void SetHitMatching(Bool_t opt=kTRUE)
Class for BmnHodoEvent reconstruction (creation) from BmnHodoDigi {Data} or BmnHodoDigit {Sim}...
void SetRecoCutsFile(const std::string &cuts)
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 EnableAlignment(Bool_t is_align_enabled=kTRUE)
void SetPeriodRun(Int_t p, Int_t r)
void SetHitMatching(Bool_t opt=kTRUE)
Class for BmnVacWall points info transition on reconstruction stage.
GeoSetup class.
Definition GeoSetup.h:47
FairField * GetMagneticField()
Get magnetic field of the current setup geometry.
double GetRefVoltage()
Get reference voltage of the magnetic field of the current setup geometry, i.e.
Definition GeoSetup.h:111
int LoadSetupToGeoManager(string_view setup_tag)
Load selected geometry setup from the Local Geometry Database and create gGeoManager instance.
Definition GeoSetup.cxx:592
static Int_t GetNumROOTEvents(const char *filename, const char *treename="", int iVerbose=2)
TList * GetListOfKeys() const override
virtual Bool_t IsOpen() const
virtual const char * GetClassName() const
virtual TObject * ReadObj()
Double_t RealTime()
void Start(Bool_t reset=kTRUE)
Double_t CpuTime()
void Stop()
const char * Data() const
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
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
static double FindPreviousFieldVoltage(int &period_number, int &run_number)
get field voltage value if period_number > 0 and run_number > 0: from the closest previous run,...
Definition UniRun.cxx:908
TString GetTargetParticle()
get target particle of the current run
Definition UniRun.h:111
enumTracking
Definition dump_hits.C:23
@ L1Tracking
Definition dump_hits.C:25
@ VectorFinder
Definition dump_hits.C:24
void dump_hits(TString inFileName="$VMCWORKDIR/macro/run/bmnsim.root", TString dstFileName="$VMCWORKDIR/macro/run/bmndst.root", Int_t nStartEvent=0, Int_t nEvents=0, enumTracking tracking=VectorFinder)
Run reconstruction and export the converted hits to .csv.
Definition dump_hits.C:42
bool usePreviousIfMissing
Definition dump_hits.C:21