BmnRoot
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 "MpdGetNumEvents.h"
59#include "SrcInnerTrackingRun7.h"
60#include "SrcVertexFinder.h"
61#include "UniRun.h"
62
63#include <iostream>
64using namespace std;
65#endif
66
67// Macro for reconstruction of simulated or experimental events for SRC
68//
69// inputFileName - input file with data (MC or exp. data)
70// bmndstFileName - output file with reconstructed data
71// nStartEvent - number of first event to process (starts with zero), default: 0
72// nEvents - number of events to process, 0 - all events of given file will be processed, default: 1 000 events
73R__ADD_INCLUDE_PATH($VMCWORKDIR)
74
75void run_reco_src(TString inputFileName = "$VMCWORKDIR/macro/run/srcsim.root",
76 TString srcdstFileName = "$VMCWORKDIR/macro/run/srcdst.root",
77 Int_t nStartEvent = 0,
78 Int_t nEvents = 10)
79{
80 gDebug = 0; // Debug option
81 // Verbosity level (0 = quiet (progress bar), 1 = event-level, 2 = track-level, 3 = full debug)
82 Int_t iVerbose = 0;
83
84 // ----- Timer ---------------------------------------------------------
85 TStopwatch timer;
86 timer.Start();
87
88 // check input file exists
89 if (!BmnFunctionSet::CheckFileExist(inputFileName, 1))
90 exit(-1);
91
92 // ----- Reconstruction run --------------------------------------------
93 FairRunAna* fRunAna = new FairRunAna();
94 fRunAna->SetEventHeader(new DstEventHeader());
95
96 Bool_t isField =
97 (inputFileName.Contains("noField")) ? kFALSE : kTRUE; // flag for tracking (to use mag.field or not)
98 Bool_t isTarget = kTRUE; // kTRUE; // flag for tracking (run with target or not)
100 inputFileName); // flag for hit finder (to create digits or take them from data-file)
101
102 // Declare input source as simulation file or experimental data
103 FairSource* fFileSource;
104
105 // -2 means use of the SRC-setup when processing MC-input
106 // DO NOT change it manually!
107 Int_t run_period = 7, run_number = -2;
108 Double_t fieldScale = 0.;
109 if (!isExp) // for simulation files
110 fFileSource = new FairFileSource(inputFileName);
111 else // for experimental files
112 {
113 // set source as raw root data file (without additional directories)
114 fFileSource = new BmnFileSource(inputFileName, run_period, run_number);
115
116 // get geometry for run
117 gRandom->SetSeed(0);
118 TString geoFileName = Form("current_geo_file_%d.root", UInt_t(gRandom->Integer(UINT32_MAX)));
119 Int_t res_code = UniRun::ReadGeometryFile(run_period, run_number, (char*)geoFileName.Data());
120 if (res_code != 0) {
121 cout << "ERROR: could not read geometry file from the database" << endl;
122 exit(-3);
123 }
124
125 // get gGeoManager from ROOT file (if required)
126 TFile* geoFile = new TFile(geoFileName, "READ");
127 if (!geoFile->IsOpen()) {
128 cout << "ERROR: could not open ROOT file with geometry: " + geoFileName << endl;
129 exit(-4);
130 }
131 TList* keyList = geoFile->GetListOfKeys();
132 TIter next(keyList);
133 TKey* key = (TKey*)next();
134 TString className(key->GetClassName());
135 if (className.BeginsWith("TGeoManager"))
136 key->ReadObj();
137 else {
138 cout << "ERROR: TGeoManager is not top element in geometry file " + geoFileName << endl;
139 exit(-5);
140 }
141
142 // set magnet field with factor corresponding to the given run
143 UniRun* pCurrentRun = UniRun::GetRun(run_period, run_number);
144 if (pCurrentRun == 0)
145 exit(-6);
146 Double_t* field_voltage = pCurrentRun->GetFieldVoltage();
147 if (field_voltage == NULL) {
148 cout << "ERROR: no field voltage was found for run " << run_period << ":" << run_number << endl;
149 exit(-7);
150 }
151 Double_t map_current = 55.87;
152 if (*field_voltage < 10) {
153 fieldScale = 0;
154 isField = kFALSE;
155 } else
156 fieldScale = (*field_voltage) / map_current;
157
158 BmnFieldMap* magField = new BmnNewFieldMap("field_sp41v5_ascii_Extrap.root");
159 magField->SetScale(fieldScale);
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 remove(geoFileName.Data());
183 }
184
185 fRunAna->SetSource(fFileSource);
186 // if directory for the output file does not exist, then create
187 if (BmnFunctionSet::CreateDirectoryTree(srcdstFileName, 1) < 0)
188 exit(-2);
189 fRunAna->SetSink(new FairRootFileSink(srcdstFileName));
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*)inputFileName.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 // === MWPC hit finder === //
204 // ====================================================================== //
205 if (!isExp) {
207 fRunAna->AddTask(mwpcHP);
208 }
209 BmnMwpcHitFinder* mwpcHM = new BmnMwpcHitFinder(isExp, run_period, run_number);
210 fRunAna->AddTask(mwpcHM);
211
212 // ====================================================================== //
213 // === Silicon hit finder === //
214 // ====================================================================== //
215 BmnSiliconHitMaker* siliconHM = new BmnSiliconHitMaker(run_period, run_number, isExp, kTRUE);
216 if (isExp)
217 siliconHM->SetHitMatching(kFALSE);
218 fRunAna->AddTask(siliconHM);
219
220 // ====================================================================== //
221 // === GEM hit finder === //
222 // ====================================================================== //
223 BmnGemStripHitMaker* gemHM = new BmnGemStripHitMaker(run_period, run_number, isExp, kTRUE);
224 if (isExp)
225 gemHM->SetHitMatching(kFALSE);
226 gemHM->SetFieldScale(fieldScale);
227 fRunAna->AddTask(gemHM);
228
229 // ====================================================================== //
230 // === CSC hit finder === //
231 // ====================================================================== //
232 BmnCSCHitMaker* cscHM = new BmnCSCHitMaker(run_period, run_number, isExp);
233 if (!isExp)
234 cscHM->SetCurrentConfig(BmnCSCConfiguration::RunSRC2021); // set explicitly
235 cscHM->SetHitMatching(kTRUE);
236 fRunAna->AddTask(cscHM);
237
238 // ====================================================================== //
239 // === TOF400 hit finder === //
240 // ====================================================================== //
241 BmnTof1HitProducer* tof1HP = new BmnTof1HitProducer("TOF1", !isExp, iVerbose, kFALSE);
242 tof1HP->SetPeriodRun(run_period, run_number);
243 fRunAna->AddTask(tof1HP);
244
245 // ====================================================================== //
246 // === TOF700 hit finder === //
247 // ====================================================================== //
248 BmnTofHitProducer* tof2HP =
249 new BmnTofHitProducer("TOF", "TOF700_geometry_run7_panin.txt", !isExp, iVerbose, kFALSE);
250 tof2HP->SetTimeResolution(0.115);
251 tof2HP->SetMCTimeFile("TOF700_MC_src_qgsm_time_run7.txt");
252 tof2HP->SetMainStripSelection(1); // 0 - minimal time, 1 - maximal amplitude
253 tof2HP->SetSelectXYCalibration(1); // 2 - Petukhov, 1 - Panin
254 tof2HP->SetTimeMin(-2.f); // minimal digit time
255 tof2HP->SetTimeMax(+15.f); // Maximal digit time
256 tof2HP->SetDiffTimeMaxSmall(1.3f); // Abs maximal difference for small chambers
257 tof2HP->SetDiffTimeMaxBig(3.5f); // Abs maximal difference for big chambers
258 fRunAna->AddTask(tof2HP);
259
260 // ====================================================================== //
261 // === ArmTrig hit finder === //
262 // ====================================================================== //
263 if (!isExp) {
264 BmnArmTrigHitProducer* armTrigHitProducer = new BmnArmTrigHitProducer();
265 fRunAna->AddTask(armTrigHitProducer);
266 }
267
268 // ====================================================================== //
269 // === BC hit finder === //
270 // ====================================================================== //
271 if (!isExp) {
272 BmnBCHitProducer* bcHitProducer = new BmnBCHitProducer();
273 fRunAna->AddTask(bcHitProducer);
274 }
275
276 // ====================================================================== //
277 // === LAND hit finder === //
278 // ====================================================================== //
279 // BmnLANDHitProducer* land = new BmnLANDHitProducer("LAND", !isExp, iVerbose, kTRUE);
280 // fRunAna->AddTask(land);
281
282 // ====================================================================== //
283 // === Tracking (MWPC) === //
284 // ====================================================================== //
285 BmnMwpcTrackFinder* mwpcTF = new BmnMwpcTrackFinder(isExp, run_period, run_number);
286 fRunAna->AddTask(mwpcTF);
287
288 // ====================================================================== //
289 // === Tracking (Silicon) === //
290 // ====================================================================== //
291 if (!isExp) {
293 fRunAna->AddTask(siHP);
294 }
295 BmnSiliconTrackFinder* siTF = new BmnSiliconTrackFinder(isExp, run_period, run_number);
296 fRunAna->AddTask(siTF);
297
298 // ====================================================================== //
299 // === Tracking (Upstream magnet) === //
300 // ====================================================================== //
301 BmnUpstreamTracking* upTF = new BmnUpstreamTracking(isExp, run_number);
302 fRunAna->AddTask(upTF);
303
304 // ====================================================================== //
305 // === Tracking (GEM in magnet) === //
306 // ====================================================================== //
307 SrcInnerTrackingRun7* innerTF = new SrcInnerTrackingRun7(run_number, isField, isTarget);
308 fRunAna->AddTask(innerTF);
309
310 // ====================================================================== //
311 // === Tracking (DCH) === //
312 // ====================================================================== //
313
314 if (!isExp) {
316 fRunAna->AddTask(dchHP);
317 }
318
319 BmnDchTrackFinder* dchTF = new BmnDchTrackFinder(run_period, run_number, isExp);
320 dchTF->SetTransferFunction("transfer_func2932.txt");
321 fRunAna->AddTask(dchTF);
322
323 // Residual analysis
324 BmnResiduals* res = new BmnResiduals(run_period, run_number, isField);
325 fRunAna->AddTask(res);
326
327 BmnGlobalTracking* glTF = new BmnGlobalTracking(isField, isExp, kFALSE);
328 glTF->SetSrcSetup(kTRUE);
329 glTF->SetRunNumber(run_number);
330 fRunAna->AddTask(glTF);
331
332 // ====================================================================== //
333 // === Primary vertex finding === //
334 // ====================================================================== //
335 SrcVertexFinder* VF = new SrcVertexFinder(run_period, isField, isExp);
336 fRunAna->AddTask(VF);
337
338 // Fill DST Event Header (if iVerbose = 0, then print progress bar)
339 BmnFillDstTask* dst_task = new BmnFillDstTask(nEvents);
340 dst_task->SetRunNumber(run_period, run_number);
341 dst_task->DoZCalibration(kTRUE);
342 fRunAna->AddTask(dst_task);
343
344 BmnPidSRC* pid = new BmnPidSRC();
345 fRunAna->AddTask(pid);
346
347 // ----- Parameter database --------------------------------------------
348 FairRuntimeDb* rtdb = fRunAna->GetRuntimeDb();
349 FairParRootFileIo* parIo1 = new FairParRootFileIo();
350 FairParAsciiFileIo* parIo2 = new FairParAsciiFileIo();
351 parIo1->open(inputFileName.Data());
352 parIo2->open(parFileNameList, "in");
353 rtdb->setFirstInput(parIo1);
354 rtdb->setSecondInput(parIo2);
355 rtdb->setOutput(parIo1);
356 rtdb->saveOutput();
357 // -------------------------------------------------------------------------
358 // ----- Initialize and run --------------------------------------------
359 fRunAna->GetMainTask()->SetVerbose(iVerbose);
360 fRunAna->Init();
361 cout << "Starting run" << endl;
362 fRunAna->Run(nStartEvent, nStartEvent + nEvents);
363 // -------------------------------------------------------------------------
364 // ----- Finish --------------------------------------------------------
365 timer.Stop();
366 Double_t rtime = timer.RealTime();
367 Double_t ctime = timer.CpuTime();
368 cout << endl << endl;
369 cout << "Macro finished successfully." << endl; // marker of successful execution for CDASH
370 cout << "Input file is " + inputFileName << endl;
371 cout << "Output file is " + srcdstFileName << endl;
372 cout << "Real time " << rtime << " s, CPU time " << ctime << " s" << endl;
373 cout << endl;
374 // ------------------------------------------------------------------------
375 // delete fRunAna;
376}
377
378int main()
379{
380 run_reco_src();
381 return -1;
382}
void SetCurrentConfig(BmnCSCConfiguration::CSC_CONFIG config)
void SetHitMatching(Bool_t opt=kTRUE)
void SetTransferFunction(TString name)
void SetScale(Double_t factor)
Definition BmnFieldMap.h:55
virtual void Init()
void SetRunNumber(Int_t period_number, Int_t run_number)
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)
void SetRunNumber(Int_t r)
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.)
static Int_t GetNumROOTEvents(const char *filename, const char *treename="", int iVerbose=2)
static UniRun * GetRun(int period_number, int run_number)
get run from the database
Definition UniRun.cxx:177
static int ReadGeometryFile(int period_number, int run_number, char *geo_file_path, bool usePrevGeometryIfMissing=false)
Definition UniRun.cxx:1105
TString GetBeamParticle()
get beam particle of the current run
Definition UniRun.h:113
double * GetFieldVoltage()
get field voltage of the current run
Definition UniRun.h:125
TString GetTargetParticle()
get target particle of the current run
Definition UniRun.h:115
-clang-format
STL namespace.
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()