BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
run_reco_bmn_p.C
Go to the documentation of this file.
1// Macro for reconstruction of simulated or experimental events for BM@N
2//
3// inputFileName - input file with data (MC or exp. data)
4// bmndstFileName - output file with reconstructed data
5// nStartEvent - number of first event to process (starts with zero), default: 0
6// nEvents - number of events to process, 0 - all events of given file will be processed, default: 1 000 events
7R__ADD_INCLUDE_PATH($VMCWORKDIR)
8#define CellAuto // Choose Tracking: L1 or CellAuto
9
10void run_reco_bmn(TString inputFileName = "$VMCWORKDIR/macro/run/evetest.root",
11 TString bmndstFileName = "$VMCWORKDIR/macro/run/bmndst.root",
12 Int_t nStartEvent = 0,
13 Int_t nEvents = 1000)
14{
15 gDebug = 0; // Debug option
16 // Verbosity level (0 = quiet (progress bar), 1 = event-level, 2 = track-level, 3 = full debug)
17 Int_t iVerbose = 0;
18
19 // ----- Timer ---------------------------------------------------------
20 TStopwatch timer;
21 timer.Start();
22
23 // ----- Reconstruction run --------------------------------------------
24 FairRunAna* fRunAna = new FairRunAna();
25 fRunAna->SetEventHeader(new DstEventHeader());
26
27 Bool_t isField =
28 (inputFileName.Contains("noField")) ? kFALSE : kTRUE; // flag for tracking (to use mag.field or not)
29 Bool_t isTarget = kTRUE; // kTRUE; // flag for tracking (run with target or not)
31 inputFileName); // flag for hit finder (to create digits or take them from data-file)
32
33 // Declare input source as simulation file or experimental data
34 FairSource* fFileSource;
35
36 // -1 means use of the BM@N-setup when processing MC-input
37 // DO NOT change it manually!
38 Int_t run_period = 7, run_number = -1;
39 Double_t fieldScale = 0.;
40 if (isExp) {
41 if (!BmnFunctionSet::CheckFileExist(inputFileName)) {
42 cout << "ERROR: digi file " + inputFileName + " does not exist!" << endl;
43 exit(-1);
44 }
45
46 // set source as raw root data file
47 fFileSource = new BmnFileSource(inputFileName, run_period, run_number);
48
49 // get geometry for run from the Geometry Database
50 GeoSetup gSetup;
51 string setupTag = gSetup.GetLastApprovedSetupTag(TString::Format("run%d", run_period).Data());
52 Int_t res_code = gSetup.LoadSetupToGeoManager(setupTag);
53 if (res_code != 0) {
54 cout << "ERROR: could not load geometry '" << setupTag << "' from the Geometry Database" << endl;
55 exit(-2);
56 }
57
58 // get gGeoManager from ROOT file (if required)
59 TFile* geoFile = new TFile(geoFileName, "READ");
60 if (!geoFile->IsOpen()) {
61 cout << "ERROR: could not open ROOT file with geometry: " + geoFileName << endl;
62 exit(-3);
63 }
64 TList* keyList = geoFile->GetListOfKeys();
65 TIter next(keyList);
66 TKey* key = (TKey*)next();
67 TString className(key->GetClassName());
68 if (className.BeginsWith("TGeoManager"))
69 key->ReadObj();
70 else {
71 cout << "ERROR: TGeoManager is not top element in geometry file " + geoFileName << endl;
72 exit(-4);
73 }
74
75 // set magnet field with factor corresponding to the given run
76 UniRun* pCurrentRun = UniRun::GetRun(run_period, run_number);
77 if (pCurrentRun == 0)
78 exit(-5);
79 Double_t* field_voltage = pCurrentRun->GetFieldVoltage();
80 if (field_voltage == NULL) {
81 cout << "ERROR: no field voltage was found for run " << run_period << ":" << run_number << endl;
82 exit(-6);
83 }
84 Double_t map_current = 55.87;
85 if (*field_voltage < 10) {
86 fieldScale = 0;
87 isField = kFALSE;
88 } else
89 fieldScale = (*field_voltage) / map_current;
90
91 BmnFieldMap* magField = new BmnNewFieldMap("field_sp41v4_ascii_Extrap.root");
92 magField->SetScale(fieldScale);
93 magField->Init();
94 fRunAna->SetField(magField);
95 isExp = kTRUE;
96 TString targ = "-";
97 if (pCurrentRun->GetTargetParticle() == "") {
98 isTarget = kFALSE;
99 } else {
100 targ = pCurrentRun->GetTargetParticle();
101 isTarget = kTRUE;
102 }
103 TString beam = pCurrentRun->GetBeamParticle();
104 if (beam == "")
105 beam = "-";
106 cout << "\n\n|||||||||||||||| EXPERIMENTAL RUN SUMMARY ||||||||||||||||" << endl;
107 cout << "||\t\t\t\t\t\t\t||" << endl;
108 cout << "||\t\tPeriod:\t\t" << run_period << "\t\t\t||" << endl;
109 cout << "||\t\tNumber:\t\t" << run_number << "\t\t\t||" << endl;
110 cout << "||\t\tBeam:\t\t" << beam << "\t\t\t||" << endl;
111 cout << "||\t\tTarget:\t\t" << targ << "\t\t\t||" << endl;
112 cout << "||\t\tField scale:\t" << setprecision(4) << fieldScale << "\t\t\t||" << endl;
113 cout << "||\t\t\t\t\t\t\t||" << endl;
114 cout << "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||\n\n" << endl;
115 } else { // for simulation files
116 if (!BmnFunctionSet::CheckFileExist(inputFileName))
117 return;
118 fFileSource = new FairFileSource(inputFileName);
119 }
120 fRunAna->SetSource(fFileSource);
121 fRunAna->SetSink(new FairRootFileSink(bmndstFileName));
122 fRunAna->SetGenerateRunInfo(false);
123
124 // if nEvents is equal 0 then all events of the given file starting with "nStartEvent" should be processed
125 if (nEvents == 0)
126 nEvents = MpdGetNumEvents::GetNumROOTEvents((char*)inputFileName.Data()) - nStartEvent;
127
128 // Digitisation files.
129 // Add TObjectString file names to a TList which is passed as input to the FairParAsciiFileIo.
130 // The FairParAsciiFileIo will create on fly a concatenated input parameter file, which is then used during the
131 // reconstruction.
132 TList* parFileNameList = new TList();
133#ifdef L1
134 TObjString stsDigiFile = "$VMCWORKDIR/parameters/sts_v1_BMN_SI_GEM.digi.par";
135 parFileNameList->Add(&stsDigiFile);
136#endif
137 TObjString tofDigiFile = "$VMCWORKDIR/parameters/tof_standard.geom.par";
138 parFileNameList->Add(&tofDigiFile);
139
140 // ====================================================================== //
141 // === Check Triggers === //
142 // ====================================================================== //
143 // BmnTriggersCheck* triggs = new BmnTriggersCheck(isExp, run_period, run_number);
144 // fRunAna->AddTask(triggs);
145 // ====================================================================== //
146 // === MWPC hit finder === //
147 // ====================================================================== //
148 BmnMwpcHitFinder* mwpcHM = new BmnMwpcHitFinder(isExp, run_period, run_number);
149 fRunAna->AddTask(mwpcHM);
150
151#ifdef L1
152 // ====================================================================== //
153 // === STS digitizer === //
154 // ====================================================================== //
155 CbmBmnStsDigitize* stsDigitize = new CbmBmnStsDigitize("STS Digitiser", iVerbose);
156 stsDigitize->SetGeoFile("$VMCWORKDIR/geometry/SIGEMS_r7.root");
157 fRunAna->AddTask(stsDigitize);
158
159 // ====================================================================== //
160 // === STS Cluster Finder === //
161 // ====================================================================== //
162 FairTask* stsClusterFinder = new CbmStsClusterFinder("STS Cluster Finder", iVerbose);
163 fRunAna->AddTask(stsClusterFinder);
164
165 // ====================================================================== //
166 // === STS hit finder === //
167 // ====================================================================== //
168 FairTask* stsFindHits = new CbmStsFindHits("STS Hit Finder", iVerbose);
169 fRunAna->AddTask(stsFindHits);
170
171 // ====================================================================== //
172 // === STS track finding === //
173 // ====================================================================== //
174 CbmKF* kalman = new CbmKF();
175 fRunAna->AddTask(kalman);
176
177 CbmL1* l1 = new CbmL1();
178 TString stsMatBudgetFile =
179 ""; // paramDir + "/sts/sts_matbudget_v12b_12344444.root"; // paramDir + "/sts_matbudget_var_fr.root";
180 l1->SetMaterialBudgetFileName(stsMatBudgetFile);
181 fRunAna->AddTask(l1);
182
183 CbmStsTrackFinder* stsTrackFinder = new CbmL1StsTrackFinder();
184 FairTask* stsFindTracks = new CbmStsFindTracks(iVerbose, stsTrackFinder);
185 fRunAna->AddTask(stsFindTracks);
186
187 // ====================================================================== //
188 // === Primary vertex finding === //
189 // ====================================================================== //
190 CbmPrimaryVertexFinder* pvFinder = new CbmPVFinderKF();
191 CbmFindPrimaryVertex* findVertex = new CbmFindPrimaryVertex(pvFinder);
192 fRunAna->AddTask(findVertex);
193#else
194 // ====================================================================== //
195 // === Silicon hit finder === //
196 // ====================================================================== //
197 BmnSiliconHitMaker* siliconHM = new BmnSiliconHitMaker(run_period, run_number, isExp);
198 if (!isExp)
199 siliconHM->SetCurrentConfig(BmnSiliconConfiguration::RunSpring2018); // set explicitly
200 fRunAna->AddTask(siliconHM);
201
202 // ====================================================================== //
203 // === GEM hit finder === //
204 // ====================================================================== //
205 BmnGemStripHitMaker* gemHM = new BmnGemStripHitMaker(run_period, run_number, isExp);
206 if (!isExp)
208 gemHM->SetHitMatching(kTRUE);
209 fRunAna->AddTask(gemHM);
210
211 // ====================================================================== //
212 // === CSC hit finder === //
213 // ====================================================================== //
214 BmnCSCHitMaker* cscHM = new BmnCSCHitMaker(run_period, run_number, isExp);
215 if (!isExp)
217 cscHM->SetHitMatching(kTRUE);
218 fRunAna->AddTask(cscHM);
219
220 // ====================================================================== //
221 // === Tracking (InnerTracker) === //
222 // ====================================================================== //
223 BmnCellAutoTracking* gemTF = new BmnCellAutoTracking(run_period, run_number, isField, isTarget);
224 fRunAna->AddTask(gemTF);
225
226 // ====================================================================== //
227 // === Primary vertex finding === //
228 // ====================================================================== //
229 BmnVertexFinder* gemVF = new BmnVertexFinder(run_period);
230 fRunAna->AddTask(gemVF);
231#endif
232
233 // ====================================================================== //
234 // === TOF1 hit finder === //
235 // ====================================================================== //
236 BmnTof1HitProducer* tof1HP = new BmnTof1HitProducer("TOF1", !isExp, iVerbose, kFALSE);
237 tof1HP->SetPeriodRun(run_period, run_number);
238 fRunAna->AddTask(tof1HP);
239
240 // ====================================================================== //
241 // === TOF2 hit finder === //
242 // ====================================================================== //
243 BmnTofHitProducer* tof2HP =
244 new BmnTofHitProducer("TOF", "TOF700_geometry_run7_panin.txt", !isExp, iVerbose, kFALSE);
245 tof2HP->SetTimeResolution(0.115);
246 tof2HP->SetMCTimeFile("TOF700_MC_argon_qgsm_time_run7.txt");
247 tof2HP->SetMainStripSelection(0); // 0 - minimal time, 1 - maximal amplitude
248 tof2HP->SetSelectXYCalibration(1); // 0 - Petukhov, 1 - Panin
249 tof2HP->SetTimeMin(-2.f); // minimal digit time
250 tof2HP->SetTimeMax(+15.f); // Maximal digit time
251 tof2HP->SetDiffTimeMaxSmall(1.3f); // Abs maximal difference for small chambers
252 tof2HP->SetDiffTimeMaxBig(3.5f); // Abs maximal difference for big chambers
253 fRunAna->AddTask(tof2HP);
254
255 // ====================================================================== //
256 // === Tracking (MWPC) === //
257 // ====================================================================== //
258 BmnMwpcTrackFinder* mwpcTF = new BmnMwpcTrackFinder(isExp, run_period, run_number);
259 fRunAna->AddTask(mwpcTF);
260
261 // ====================================================================== //
262 // === Tracking (DCH) === //
263 // ====================================================================== //
264
265 if (!isExp) {
267 fRunAna->AddTask(dchHP);
268 }
269
270 BmnDchTrackFinder* dchTF = new BmnDchTrackFinder(isExp);
271 dchTF->SetTransferFunction("transfer_func.txt");
272 fRunAna->AddTask(dchTF);
273
274 // Residual analysis
275 BmnResiduals* res = new BmnResiduals(run_period, run_number);
276 fRunAna->AddTask(res);
277
278 BmnGlobalTracking* glTF = new BmnGlobalTracking(isField, isExp, kTRUE);
279 fRunAna->AddTask(glTF);
280
281 // Fill DST Event Header (if iVerbose = 0, then print progress bar)
282 BmnFillDstTask* dst_task = new BmnFillDstTask(nEvents);
283 dst_task->SetRunNumber(run_period, run_number);
284 fRunAna->AddTask(dst_task);
285
286 // ----- Parameter database --------------------------------------------
287 FairRuntimeDb* rtdb = fRunAna->GetRuntimeDb();
288 FairParRootFileIo* parIo1 = new FairParRootFileIo();
289 FairParAsciiFileIo* parIo2 = new FairParAsciiFileIo();
290 parIo1->open(inputFileName.Data());
291 parIo2->open(parFileNameList, "in");
292 gSystem->Unlink(parIo2->getFilename()); // drop concatenated all_<pid>.par
293 rtdb->setFirstInput(parIo1);
294 rtdb->setSecondInput(parIo2);
295 rtdb->setOutput(parIo1);
296 rtdb->saveOutput();
297 // -------------------------------------------------------------------------
298 // ----- Initialize and run --------------------------------------------
299 fRunAna->GetMainTask()->SetVerbose(iVerbose);
300 fRunAna->Init();
301 cout << "Starting run" << endl;
302 fRunAna->Run(nStartEvent, nStartEvent + nEvents);
303 // -------------------------------------------------------------------------
304 // ----- Finish --------------------------------------------------------
305 timer.Stop();
306 Double_t rtime = timer.RealTime();
307 Double_t ctime = timer.CpuTime();
308 cout << endl << endl;
309 cout << "Macro finished successfully." << endl; // marker of successful execution for CDASH
310 cout << "Input file is " + inputFileName << endl;
311 cout << "Output file is " + bmndstFileName << endl;
312 cout << "Real time " << rtime << " s, CPU time " << ctime << " s" << endl;
313 cout << endl;
314 // ------------------------------------------------------------------------
315}
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)
R__EXTERN TSystem * gSystem
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 isSimulationFile(TString fileName="")
static int CheckFileExist(TString &fileName, int iVerbose=0, EAccessMode mode=kFileExists)
void SetCurrentConfig(BmnGemStripConfiguration::GEM_CONFIG config)
void SetHitMatching(Bool_t opt=kTRUE)
Field Map does not have any symmetries w.r.t coordinate axises.
void SetCurrentConfig(BmnSiliconConfiguration::SILICON_CONFIG config)
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.)
void SetGeoFile(TString geoFile)
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)
TList * GetListOfKeys() const override
virtual Bool_t IsOpen() const
void Add(TObject *obj) override
Double_t RealTime()
void Start(Bool_t reset=kTRUE)
Double_t CpuTime()
void Stop()
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
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_bmn(TString inputFileName="$VMCWORKDIR/macro/run/evetest.root", TString bmndstFileName="$VMCWORKDIR/macro/run/bmndst.root", Int_t nStartEvent=0, Int_t nEvents=1000)