BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
run_reco_src.cxx
Go to the documentation of this file.
1#if !defined(__CLING__) || defined(__MAKECLING__)
2// ROOT includes
3#include "TDatabasePDG.h"
4#include "TKey.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 "BmnArmTrigHitProducer.h"
28#include "BmnBCHitProducer.h"
29#include "BmnCSCConfiguration.h"
30#include "BmnCSCHitMaker.h"
31#include "BmnCounterTask.h"
32#include "BmnDchHitProducer.h"
33#include "BmnDchTrackFinder.h"
34#include "BmnFieldMap.h"
35#include "BmnFileSource.h"
36#include "BmnFillDstTask.h"
37#include "BmnFunctionSet.h"
38#include "BmnGemResiduals.h"
39#include "BmnGemStripHitMaker.h"
40#include "BmnGemTrack.h"
41#include "BmnGlobalTracking.h"
42#include "BmnLANDHitProducer.h"
43#include "BmnMwpcHitFinder.h"
44#include "BmnMwpcHitProducer.h"
45#include "BmnMwpcTrackFinder.h"
46#include "BmnNewFieldMap.h"
47#include "BmnPidSRC.h"
48#include "BmnSiResiduals.h"
49#include "BmnSiliconHitMaker.h"
50#include "BmnSiliconHitProducerSRC.h"
51#include "BmnTof1HitProducer.h"
52#include "BmnTofHitProducer.h"
53#include "BmnTriggersCheck.h"
54#include "BmnUpstreamTracking.h"
55#include "BmnVertexFinder.h"
56#include "BmnZdcAnalyzer.h"
57#include "DstEventHeader.h"
58#include "GeoSetup.h"
59#include "MpdGetNumEvents.h"
61#include "SrcVertexFinder.h"
62#include "UniRun.h"
63
64#include <iostream>
65using namespace std;
66#endif
67
68// Macro for reconstruction of simulated or experimental events for SRC
69//
70// inputFileName - input file with data (MC or exp. data)
71// bmndstFileName - output file with reconstructed data
72// nStartEvent - number of first event to process (starts with zero), default: 0
73// nEvents - number of events to process, 0 - all events of given file will be processed, default: 1 000 events
74R__ADD_INCLUDE_PATH($VMCWORKDIR)
75
76void run_reco_src(TString inputFileName = "$VMCWORKDIR/macro/run/srcsim.root",
77 TString srcdstFileName = "$VMCWORKDIR/macro/run/srcdst.root",
78 Int_t nStartEvent = 0,
79 Int_t nEvents = 10)
80{
81 gDebug = 0; // Debug option
82 // Verbosity level (0 = quiet (progress bar), 1 = event-level, 2 = track-level, 3 = full debug)
83 Int_t iVerbose = 0;
84
85 // ----- Timer ---------------------------------------------------------
86 TStopwatch timer;
87 timer.Start();
88
89 // check input file exists
90 if (!BmnFunctionSet::CheckFileExist(inputFileName, 1))
91 exit(-1);
92
93 // ----- Reconstruction run --------------------------------------------
94 FairRunAna* fRunAna = new FairRunAna();
95 fRunAna->SetEventHeader(new DstEventHeader());
96
97 Bool_t isField =
98 (inputFileName.Contains("noField")) ? kFALSE : kTRUE; // flag for tracking (to use mag.field or not)
99 Bool_t isTarget = kTRUE; // kTRUE; // flag for tracking (run with target or not)
101 inputFileName); // flag for hit finder (to create digits or take them from data-file)
102
103 // Declare input source as simulation file or experimental data
104 FairSource* fFileSource;
105
106 // -2 means use of the SRC-setup when processing MC-input
107 // DO NOT change it manually!
108 Int_t run_period = 7, run_number = -2;
109 Double_t fieldScale = 0.;
110 if (!isExp) // for simulation files
111 fFileSource = new FairFileSource(inputFileName);
112 else // for experimental files
113 {
114 // set source as raw root data file (without additional directories)
115 fFileSource = new BmnFileSource(inputFileName, run_period, run_number);
116
117 // get geometry for run from the Geometry Database
118 GeoSetup gSetup;
119 string setupTag = gSetup.GetLastApprovedSetupTag(TString::Format("run%d", run_period).Data());
120 Int_t res_code = gSetup.LoadSetupToGeoManager(setupTag);
121 if (res_code != 0) {
122 cout << "ERROR: could not load geometry '" << setupTag << "' from the Geometry Database" << endl;
123 exit(-3);
124 }
125
126 // set magnet field with factor corresponding to the given run
127 UniRun* pCurrentRun = UniRun::GetRun(run_period, run_number);
128 if (pCurrentRun == 0)
129 exit(-6);
130 Double_t* field_voltage = pCurrentRun->GetFieldVoltage();
131 if (field_voltage == NULL) {
132 cout << "ERROR: no field voltage was found for run " << run_period << ":" << run_number << endl;
133 exit(-7);
134 }
135 Double_t map_current = 55.87;
136 if (*field_voltage < 10) {
137 fieldScale = 0;
138 isField = kFALSE;
139 } else
140 fieldScale = (*field_voltage) / map_current;
141
142 BmnFieldMap* magField = new BmnNewFieldMap("field_sp41v5_ascii_Extrap.root");
143 magField->SetScale(fieldScale);
144 magField->Init();
145 fRunAna->SetField(magField);
146 isExp = kTRUE;
147 TString targ = "-";
148 if (pCurrentRun->GetTargetParticle() == "") {
149 isTarget = kFALSE;
150 } else {
151 targ = pCurrentRun->GetTargetParticle();
152 isTarget = kTRUE;
153 }
154 TString beam = pCurrentRun->GetBeamParticle();
155 if (beam == "")
156 beam = "-";
157 cout << "\n\n|||||||||||||||| EXPERIMENTAL RUN SUMMARY ||||||||||||||||" << endl;
158 cout << "||\t\t\t\t\t\t\t||" << endl;
159 cout << "||\t\tPeriod:\t\t" << run_period << "\t\t\t||" << endl;
160 cout << "||\t\tNumber:\t\t" << run_number << "\t\t\t||" << endl;
161 cout << "||\t\tBeam:\t\t" << beam << "\t\t\t||" << endl;
162 cout << "||\t\tTarget:\t\t" << targ << "\t\t\t||" << endl;
163 cout << "||\t\tField scale:\t" << setprecision(4) << fieldScale << "\t\t\t||" << endl;
164 cout << "||\t\t\t\t\t\t\t||" << endl;
165 cout << "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||\n\n" << endl;
166 remove(geoFileName.Data());
167 }
168
169 fRunAna->SetSource(fFileSource);
170 // if directory for the output file does not exist, then create
171 if (BmnFunctionSet::CreateDirectoryTree(srcdstFileName, 1) < 0)
172 exit(-2);
173 fRunAna->SetSink(new FairRootFileSink(srcdstFileName));
174 fRunAna->SetGenerateRunInfo(false);
175
176 // if nEvents is equal 0 then all events of the given file starting with "nStartEvent" should be processed
177 if (nEvents == 0)
178 nEvents = MpdGetNumEvents::GetNumROOTEvents((char*)inputFileName.Data()) - nStartEvent;
179
180 // Digitisation files.
181 // Add TObjectString file names to a TList which is passed as input to the FairParAsciiFileIo.
182 // The FairParAsciiFileIo will create on fly a concatenated input parameter file, which is then used during the
183 // reconstruction.
184 TList* parFileNameList = new TList();
185
186 // ====================================================================== //
187 // === MWPC hit finder === //
188 // ====================================================================== //
189 if (!isExp) {
191 fRunAna->AddTask(mwpcHP);
192 }
193 BmnMwpcHitFinder* mwpcHM = new BmnMwpcHitFinder(isExp, run_period, run_number);
194 fRunAna->AddTask(mwpcHM);
195
196 // ====================================================================== //
197 // === Silicon hit finder === //
198 // ====================================================================== //
199 BmnSiliconHitMaker* siliconHM = new BmnSiliconHitMaker(run_period, run_number, isExp, kTRUE);
200 if (isExp)
201 siliconHM->SetHitMatching(kFALSE);
202 fRunAna->AddTask(siliconHM);
203
204 // ====================================================================== //
205 // === GEM hit finder === //
206 // ====================================================================== //
207 BmnGemStripHitMaker* gemHM = new BmnGemStripHitMaker(run_period, run_number, isExp, kTRUE);
208 if (isExp)
209 gemHM->SetHitMatching(kFALSE);
210 gemHM->SetFieldScale(fieldScale);
211 fRunAna->AddTask(gemHM);
212
213 // ====================================================================== //
214 // === CSC hit finder === //
215 // ====================================================================== //
216 BmnCSCHitMaker* cscHM = new BmnCSCHitMaker(run_period, run_number, isExp);
217 if (!isExp)
218 cscHM->SetCurrentConfig(BmnCSCConfiguration::RunSRC2021); // set explicitly
219 cscHM->SetHitMatching(kTRUE);
220 fRunAna->AddTask(cscHM);
221
222 // ====================================================================== //
223 // === TOF400 hit finder === //
224 // ====================================================================== //
225 BmnTof1HitProducer* tof1HP = new BmnTof1HitProducer("TOF1", !isExp, iVerbose, kFALSE);
226 tof1HP->SetPeriodRun(run_period, run_number);
227 fRunAna->AddTask(tof1HP);
228
229 // ====================================================================== //
230 // === TOF700 hit finder === //
231 // ====================================================================== //
232 BmnTofHitProducer* tof2HP =
233 new BmnTofHitProducer("TOF", "TOF700_geometry_run7_panin.txt", !isExp, iVerbose, kFALSE);
234 tof2HP->SetTimeResolution(0.115);
235 tof2HP->SetMCTimeFile("TOF700_MC_src_qgsm_time_run7.txt");
236 tof2HP->SetMainStripSelection(1); // 0 - minimal time, 1 - maximal amplitude
237 tof2HP->SetSelectXYCalibration(1); // 2 - Petukhov, 1 - Panin
238 tof2HP->SetTimeMin(-2.f); // minimal digit time
239 tof2HP->SetTimeMax(+15.f); // Maximal digit time
240 tof2HP->SetDiffTimeMaxSmall(1.3f); // Abs maximal difference for small chambers
241 tof2HP->SetDiffTimeMaxBig(3.5f); // Abs maximal difference for big chambers
242 fRunAna->AddTask(tof2HP);
243
244 // ====================================================================== //
245 // === ArmTrig hit finder === //
246 // ====================================================================== //
247 if (!isExp) {
248 BmnArmTrigHitProducer* armTrigHitProducer = new BmnArmTrigHitProducer();
249 fRunAna->AddTask(armTrigHitProducer);
250 }
251
252 // ====================================================================== //
253 // === BC hit finder === //
254 // ====================================================================== //
255 if (!isExp) {
256 BmnBCHitProducer* bcHitProducer = new BmnBCHitProducer();
257 fRunAna->AddTask(bcHitProducer);
258 }
259
260 // ====================================================================== //
261 // === LAND hit finder === //
262 // ====================================================================== //
263 // BmnLANDHitProducer* land = new BmnLANDHitProducer("LAND", !isExp, iVerbose, kTRUE);
264 // fRunAna->AddTask(land);
265
266 // ====================================================================== //
267 // === Tracking (MWPC) === //
268 // ====================================================================== //
269 BmnMwpcTrackFinder* mwpcTF = new BmnMwpcTrackFinder(isExp, run_period, run_number);
270 fRunAna->AddTask(mwpcTF);
271
272 // ====================================================================== //
273 // === Tracking (Silicon) === //
274 // ====================================================================== //
275 if (!isExp) {
277 fRunAna->AddTask(siHP);
278 }
279 BmnSiliconTrackFinder* siTF = new BmnSiliconTrackFinder(isExp, run_period, run_number);
280 fRunAna->AddTask(siTF);
281
282 // ====================================================================== //
283 // === Tracking (Upstream magnet) === //
284 // ====================================================================== //
285 BmnUpstreamTracking* upTF = new BmnUpstreamTracking(isExp, run_number);
286 fRunAna->AddTask(upTF);
287
288 // ====================================================================== //
289 // === Tracking (GEM in magnet) === //
290 // ====================================================================== //
291 SrcInnerTrackingRun7* innerTF = new SrcInnerTrackingRun7(run_number, isField, isTarget);
292 fRunAna->AddTask(innerTF);
293
294 // ====================================================================== //
295 // === Tracking (DCH) === //
296 // ====================================================================== //
297
298 if (!isExp) {
300 fRunAna->AddTask(dchHP);
301 }
302
303 BmnDchTrackFinder* dchTF = new BmnDchTrackFinder(run_period, run_number, isExp);
304 dchTF->SetTransferFunction("transfer_func2932.txt");
305 fRunAna->AddTask(dchTF);
306
307 // Residual analysis
308 BmnResiduals* res = new BmnResiduals(run_period, run_number, isField);
309 fRunAna->AddTask(res);
310
311 BmnGlobalTracking* glTF = new BmnGlobalTracking(isField, isExp, kFALSE);
312 glTF->SetSrcSetup(kTRUE);
313 glTF->SetRunNumber(run_number);
314 fRunAna->AddTask(glTF);
315
316 // ====================================================================== //
317 // === Primary vertex finding === //
318 // ====================================================================== //
319 SrcVertexFinder* VF = new SrcVertexFinder(run_period, isField, isExp);
320 fRunAna->AddTask(VF);
321
322 // Fill DST Event Header (if iVerbose = 0, then print progress bar)
323 BmnFillDstTask* dst_task = new BmnFillDstTask(nEvents);
324 dst_task->SetRunNumber(run_period, run_number);
325 dst_task->DoZCalibration(kTRUE);
326 fRunAna->AddTask(dst_task);
327
328 BmnPidSRC* pid = new BmnPidSRC();
329 fRunAna->AddTask(pid);
330
331 // ----- Parameter database --------------------------------------------
332 FairRuntimeDb* rtdb = fRunAna->GetRuntimeDb();
333 FairParRootFileIo* parIo1 = new FairParRootFileIo();
334 FairParAsciiFileIo* parIo2 = new FairParAsciiFileIo();
335 parIo1->open(inputFileName.Data());
336 parIo2->open(parFileNameList, "in");
337 rtdb->setFirstInput(parIo1);
338 rtdb->setSecondInput(parIo2);
339 rtdb->setOutput(parIo1);
340 rtdb->saveOutput();
341 // -------------------------------------------------------------------------
342 // ----- Initialize and run --------------------------------------------
343 fRunAna->GetMainTask()->SetVerbose(iVerbose);
344 fRunAna->Init();
345 cout << "Starting run" << endl;
346 fRunAna->Run(nStartEvent, nStartEvent + nEvents);
347 // -------------------------------------------------------------------------
348 // ----- Finish --------------------------------------------------------
349 timer.Stop();
350 Double_t rtime = timer.RealTime();
351 Double_t ctime = timer.CpuTime();
352 cout << endl << endl;
353 cout << "Macro finished successfully." << endl; // marker of successful execution for CDASH
354 cout << "Input file is " + inputFileName << endl;
355 cout << "Output file is " + srcdstFileName << endl;
356 cout << "Real time " << rtime << " s, CPU time " << ctime << " s" << endl;
357 cout << endl;
358 // ------------------------------------------------------------------------
359 // delete fRunAna;
360}
361
362int main()
363{
364 run_reco_src();
365 return -1;
366}
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)
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.
void DoZCalibration(Bool_t cal)
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 SetFieldScale(Double_t fs)
Field Map does not have any symmetries w.r.t coordinate axises.
void SetHitMatching(Bool_t opt=kTRUE)
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 SetTimeMin(Double_t mi=-2.)
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 run_reco_src(TString inputFileName="$VMCWORKDIR/macro/run/srcsim.root", TString srcdstFileName="$VMCWORKDIR/macro/run/srcdst.root", Int_t nStartEvent=0, Int_t nEvents=10)
int main()
Definition json.hpp:4446