BmnRoot 26.10.0-210-gc52d34b0
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 if (field_voltage < 10) {
145 fieldScale = 0;
146 } else
147 fieldScale = (field_voltage) / map_voltage;
148 BmnFieldMap* magField = nullptr;
149#ifdef USE_GEODB
150 magField = dynamic_cast<BmnFieldMap*>(gSetup.GetMagneticField(fieldScale));
151#else
152 magField = new BmnNewFieldMap("FieldMap_1900_extrap_noPed.root");
153 magField->SetScale(fieldScale);
154#endif
155 magField->Init();
156 fRunAna->SetField(magField);
157 isExp = kTRUE;
158 TString targ = "-";
159 if (pCurrentRun->GetTargetParticle() == "") {
160 isTarget = kFALSE;
161 } else {
162 targ = pCurrentRun->GetTargetParticle();
163 isTarget = kTRUE;
164 }
165 TString beam = pCurrentRun->GetBeamParticle();
166 if (beam == "")
167 beam = "-";
168 cout << "\n\n|||||||||||||||| EXPERIMENTAL RUN SUMMARY ||||||||||||||||" << endl;
169 cout << "||\t\t\t\t\t\t\t||" << endl;
170 cout << "||\t\tPeriod:\t\t" << run_period << "\t\t\t||" << endl;
171 cout << "||\t\tNumber:\t\t" << run_number << "\t\t\t||" << endl;
172 cout << "||\t\tBeam:\t\t" << beam << "\t\t\t||" << endl;
173 cout << "||\t\tTarget:\t\t" << targ << "\t\t\t||" << endl;
174 cout << "||\t\tField scale:\t" << setprecision(4) << fieldScale << "\t\t\t||" << endl;
175 cout << "||\t\t\t\t\t\t\t||" << endl;
176 cout << "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||\n\n" << endl;
177#ifndef USE_GEODB
178 remove(geoFileName.Data());
179#endif
180 }
181
182 fRunAna->SetSource(fFileSource);
183
184 if (dstFileName == "")
185 dstFileName = "bmndst.root";
186 // if directory for the output file does not exist, then create
187 if (BmnFunctionSet::CreateDirectoryTree(dstFileName, 1) < 0)
188 exit(-2);
189 fRunAna->SetSink(new FairRootFileSink(dstFileName));
190 fRunAna->SetGenerateRunInfo(false);
191
192 // if nEvents is equal 0 then all events of the given file starting with "nStartEvent" should be processed
193 if (nEvents == 0)
194 nEvents = MpdGetNumEvents::GetNumROOTEvents((char*)inFileName.Data()) - nStartEvent;
195
196 // Digitisation files.
197 // Add TObjectString file names to a TList which is passed as input to the FairParAsciiFileIo.
198 // The FairParAsciiFileIo will create on fly a concatenated input parameter file, which is then used during the
199 // reconstruction.
200 TList* parFileNameList = new TList();
201
202 // ====================================================================== //
203 // === Pileup Event Classification === //
204 // ====================================================================== //
205 if (run_period == 8 && isExp) {
206 BmnEventSelector* eventSelector = new BmnEventSelector();
207 eventSelector->SetRunId(run_number);
208 eventSelector->SetInputFileName("$VMCWORKDIR/input/eventSelector_calib_run8.root");
209 fRunAna->AddTask(eventSelector);
210 }
211
212 // ====================================================================== //
213 // === Fill basic trigger information === //
214 // ====================================================================== //
215 BmnFillTrigInfoDst* trig = new BmnFillTrigInfoDst(isExp);
216 fRunAna->AddTask(trig);
217
218 // ====================================================================== //
219 // === Hits in front of the target === //
220 // ====================================================================== //
221 if (run_period >= 8) {
222 if (isExp) {
223 BmnSiBTHitMaker* sibtHM = new BmnSiBTHitMaker(run_period, run_number, isExp);
224 // fRunAna->AddTask(sibtHM);
225 }
226 } else {
227 if (!isExp) {
229 fRunAna->AddTask(mwpcHP);
230 }
231 BmnMwpcHitFinder* mwpcHM = new BmnMwpcHitFinder(isExp, run_period, run_number);
232 fRunAna->AddTask(mwpcHM);
233 }
234
235 // ====================================================================== //
236 // === VSP hit finder === //
237 // ====================================================================== //
238 BmnVSPHitMaker* vspHM = new BmnVSPHitMaker(run_period, run_number, isExp);
239 if (isExp)
240 vspHM->SetHitMatching(kFALSE);
241 fRunAna->AddTask(vspHM);
242
243 // ====================================================================== //
244 // === Silicon hit finder === //
245 // ====================================================================== //
246 BmnSiliconHitMaker* siliconHM = new BmnSiliconHitMaker(run_period, run_number, isExp);
247 if (isExp)
248 siliconHM->SetHitMatching(kFALSE);
249 fRunAna->AddTask(siliconHM);
250
251 // ====================================================================== //
252 // === GEM hit finder === //
253 // ====================================================================== //
254 BmnGemStripHitMaker* gemHM = new BmnGemStripHitMaker(run_period, run_number, isExp);
255 if (isExp)
256 gemHM->SetHitMatching(kFALSE);
257 fRunAna->AddTask(gemHM);
258
259 // ====================================================================== //
260 // === CSC hit finder === //
261 // ====================================================================== //
262 BmnCSCHitMaker* cscHM = new BmnCSCHitMaker(run_period, run_number, isExp);
263 if (!isExp)
264 cscHM->SetCurrentConfig(BmnCSCConfiguration::FullCSC_Run8); // set explicitly
265 if (isExp)
266 cscHM->SetHitMatching(kFALSE);
267 fRunAna->AddTask(cscHM);
268
269 // ====================================================================== //
270 // === TOF400 hit finder === //
271 // ====================================================================== //
272 BmnTof1HitProducer* tof400HP = new BmnTof1HitProducer("TOF400", kTOF1, !isExp, iVerbose, kFALSE);
273 tof400HP->SetPeriodRun(run_period, run_number);
274 fRunAna->AddTask(tof400HP);
275
276 // ====================================================================== //
277 // === TOF700 hit finder === //
278 // ====================================================================== //
279 BmnTof1HitProducer* tof700HP = new BmnTof1HitProducer("TOF700", kTOF701, !isExp, iVerbose, kFALSE);
280 tof700HP->SetPeriodRun(run_period, run_number);
281 fRunAna->AddTask(tof700HP);
282
283 // ====================================================================== //
284 // === DCH hit finder === //
285 // ====================================================================== //
286 // if (!isExp) {
287 // BmnDchHitProducer* dchHP = new BmnDchHitProducer();
288 // fRunAna->AddTask(dchHP);
289 // }
290
291 // ====================================================================== //
292 // === FHCAL/ZDC === //
293 // ====================================================================== //
294 bool IsGlobalCoordinates = true;
295 if (run_period >= 8) {
296 // TODO check isExp
297 BmnFHCalReconstructor* fhcalReco = new BmnFHCalReconstructor(isExp, IsGlobalCoordinates);
298 fhcalReco->SetRecoCutsFile("FHCAL_reco_cuts_period8.txt");
299 fRunAna->AddTask(fhcalReco);
300 } else {
301 BmnZdcAnalyzer* zdcAna = new BmnZdcAnalyzer();
302 fRunAna->AddTask(zdcAna);
303 }
304
305 // ====================================================================== //
306 // === ScWall === //
307 // ====================================================================== //
308 IsGlobalCoordinates = true;
309 BmnScWallReconstructor* scwallReco = new BmnScWallReconstructor(isExp, IsGlobalCoordinates);
310 scwallReco->SetRecoCutsFile("SCWALL_reco_cuts_period8.txt");
311 fRunAna->AddTask(scwallReco);
312
313 // ====================================================================== //
314 // === Hodo === //
315 // ====================================================================== //
316
317 BmnHodoReconstructor* hodoReco = new BmnHodoReconstructor("HODO_Q_calibration_period8.json", isExp);
318 hodoReco->SetRecoCutsFile("HODO_reco_cuts_period8.json");
319 fRunAna->AddTask(hodoReco);
320
321 // ====================================================================== //
322 // === Ndet === //
323 // ====================================================================== //
324 IsGlobalCoordinates = true;
325 BmnNdetReconstructor* ndetReco = new BmnNdetReconstructor(isExp, IsGlobalCoordinates);
326 ndetReco->SetRecoCutsFile("NDET_reco_cuts_period8.txt");
327 fRunAna->AddTask(ndetReco);
328
329 // ====================================================================== //
330 // === Vacuum Wall === //
331 // ====================================================================== //
332
334 fRunAna->AddTask(vacReco);
335
336 // ====================================================================== //
337 // === Inner Tracking === //
338 // ====================================================================== //
339 TString innerTrackBranchName; // use different track container
340
341 if (tracking == L1Tracking)
342 innerTrackBranchName = "StsTrack";
343 else
344 innerTrackBranchName = "StsVector";
345 if (run_period >= 8) {
346 BmnToCbmHitConverter* hitConverter = new BmnToCbmHitConverter(iVerbose, isExp);
347 // AZ-150224 hitConverter->SetFixedErrors(0.05, 0.25, 0.02, 0.65);
348 // hitConverter->SetFixedErrors(0.08 / sqrt(12) * 1.2, 0.1234, 0.01 / sqrt(12), 0.1234); // AZ-150224
349 // PLV: turn off manual alignment built in BmnToCbmHitConverter
350 hitConverter->EnableAlignment(kFALSE);
351 fRunAna->AddTask(hitConverter);
352
353 // dump all Cbm hits to .csv
354 fRunAna->AddTask(new BmnHitDumper(dstFileName));
355 }
356
357 // ----- Parameter database (input) -------------------------------------
358 FairRuntimeDb* rtdb = fRunAna->GetRuntimeDb();
359 FairParRootFileIo* parIo1 = new FairParRootFileIo();
360 FairParAsciiFileIo* parIo2 = new FairParAsciiFileIo();
361 parIo1->open(inFileName.Data());
362 parIo2->open(parFileNameList, "in");
363 rtdb->setFirstInput(parIo1);
364 rtdb->setSecondInput(parIo2);
365 // -------------------------------------------------------------------------
366
367 // ----- Initialize FaiRunAna --------------------------------------------
368 fRunAna->GetMainTask()->SetVerbose(iVerbose);
369 fRunAna->Init();
370 // -------------------------------------------------------------------------
371
372 // ----- Parameter database (output) ------------------------------------
373 FairParRootFileIo* parOut = new FairParRootFileIo(kTRUE);
374 // parOut->open(dstFileName);
375 parOut->open(gFile);
376 rtdb->setOutput(parOut);
377 rtdb->writeContainer(rtdb->getContainer("FairGeoParSet"), rtdb->getCurrentRun());
378 rtdb->saveOutput();
379 // rtdb->print();
380 // -------------------------------------------------------------------------
381
382 // ----- Run FairRunAna -------------------------------------------------
383 fRunAna->Run(nStartEvent, nStartEvent + nEvents);
384 // -------------------------------------------------------------------------
385
386 // ----- Finish --------------------------------------------------------
387 delete fRunAna;
388 timer.Stop();
389 Double_t rtime = timer.RealTime();
390 Double_t ctime = timer.CpuTime();
391 cout << endl << endl;
392 cout << "Macro finished successfully." << endl; // marker of successful execution
393 cout << "Input file is " + inFileName << endl;
394 cout << "Output file is " + dstFileName << endl;
395 cout << "Real time " << rtime << " s, CPU time " << ctime << " s" << endl;
396 cout << endl;
397 // ------------------------------------------------------------------------
398}
@ 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)
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)
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:40
int LoadSetupToGeoManager(string_view setup_tag)
Load selected geometry setup from the Local Geometry Database and create gGeoManager instance.
Definition GeoSetup.cxx:512
FairField * GetMagneticField(double scale=-1)
Get magnetic field of the current setup geometry.
Definition GeoSetup.cxx:877
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