BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
run_reco_gem_r7.C
Go to the documentation of this file.
1
2// --------------------------------------------------------------------------
3//
4// Macro for reconstruction of simulated events with standard settings
5//
6// HitProducers in MVD, RICH, TRD, TOF, ECAL
7// Digitizer and HitFinder in STS
8// FAST MC for ECAL
9// STS track finding and fitting (L1 / KF)
10// TRD track finding and fitting (L1 / KF)
11// RICH ring finding (ideal) and fitting
12// Global track finding (ideal), rich assignment
13// Primary vertex finding (ideal)
14// Matching of reconstructed and MC tracks in STS, RICH and TRD
15//
16// V. Friese 24/02/2006
17// Version 24/04/2007 (V. Friese)
18//
19// --------------------------------------------------------------------------
20#include <TGDMLParse.h>
21// CBM includes
22/*#include "CbmKF.h"
23#include "BmnFieldConst.h"
24#include "BmnFieldMap.h"
25#include "BmnFileSource.h"
26#include "BmnNewFieldMap.h"
27#include "CbmKFParticle.h"
28#include "CbmKFSecondaryVertexFinder.h"
29#include "CbmKFTrack.h"
30#include "CbmMCTrack.h"
31#include "CbmStsDigiPar.h"
32#include "CbmStsHit.h"
33#include "CbmStsKFTrackFitter.h"
34#include "CbmStsPoint.h"
35#include "CbmStsStation.h"
36#include "CbmStsTrack.h"
37#include "CbmTrackMatch.h"
38#include "CbmVertex.h"
39#include "FairParAsciiFileIo.h"
40#include "FairParRootFileIo.h"
41#include "FairRunAna.h"
42#include "FairRuntimeDb.h"
43#include "FairTrackParam.h"
44#include "TKey.h"
45#include "UniRun.h"
46
47// ROOT includes
48#include "BmnEventHeader.h"
49#include "CbmBmnStsDigitize.h"
50#include "CbmFindPrimaryVertex.h"
51#include "CbmL1.h"
52#include "CbmL1StsTrackFinder.h"
53#include "CbmPVFinderKF.h"
54#include "CbmPrimaryVertexFinder.h"
55#include "CbmStsClusterFinder.h"
56#include "CbmStsFindHits.h"
57#include "CbmStsFindTracks.h"
58#include "CbmStsTrackFinder.h"
59#include "StsTrackExtrapToDCH.h"
60#include "TStopwatch.h"
61
62#include <Riostream.h>
63#include <TBranch.h>
64#include <TClonesArray.h>
65#include <TDatabasePDG.h>
66#include <TError.h>
67#include <TFile.h>
68#include <TGeoCone.h>
69#include <TGeoManager.h>
70#include <TGeoVolume.h>
71#include <TH1.h>
72#include <TH2.h>
73#include <TMatrixD.h>
74#include <TROOT.h>
75#include <TRandom.h>
76#include <TSystem.h>
77#include <TTree.h>
78#include <TVector3.h>
79#include <TVectorD.h>
80#include <map>
81#include <set>
82#include <vector>
83*/
84
85// GEMS_v16_AZ_3mm.root
86// GEMS_RunSummer2016.root
87// bmn_run991_stripdigitthr15.root GEMS_RunWinter2016_old.root SIGEMS_v1.root
88void run_reco_gem_r7(TString inFile = "",
89 TString outFile = "",
90 TString geoFile = "SIGEMS_r7.root",
91 Int_t nEvents = 0,
92 Int_t rnum = 0,
93 Double_t Mscale = 1.366666667)
94{
95 Mscale = 1250 / 900.0;
96 // cout<<inFile<<endl;
97 // exit(0);
98 // ========================================================================
99 // Adjust this part according to your requirements
100 /*
101 TFile file(inFile);
102 TTree * tree = (TTree *)file.Get("BMN_DIGIT");
103 Int_t runID;
104 TClonesArray *bevhtca;
105 tree->SetBranchAddress("EventHeader", &bevhtca);
106 tree->GetEntry(0);
107 // cout<<" RUUUNNNN: "<<((BmnEventHeader*)bevhtca->At(0))->GetRunId()<<endl;
108 // exit(0);
109 //(TClonesArray *) FairRootManager::Instance()->GetObject("StsTrack");
110 runID = ((BmnEventHeader *)bevhtca->At(0))->GetRunId();
111 file.Close();
112
113 ifstream listOfFieldRuns("listOfFieldRuns.txt");
114
115 string line;
116 while (getline(listOfFieldRuns, line)) {
117 std::istringstream rfs(line);
118 int run_n;
119 double field, scale;
120 if (!(rfs >> run_n >> field >> scale)) {
121 break;
122 } // error
123
124 if (runID == run_n) {
125 Mscale = scale;
126 // cout<<run_n<<" "<<field<<" "<<scale<<endl;
127 break;
128 }
129 }
130
131 listOfFieldRuns.close();
132 if (Mscale < 0.5) exit(0);
133 */
134 // Verbosity level (0=quiet, 1=event level, 2=track level, 3=debug)
135 Int_t iVerbose = 0;
137 // Int_t iVerbose = 3;
138 // Input file (MC events)
139 // TString inFile = "data/AuAu_urqmd_3.3p1_4.0_gev__10000_ev__centr__seed_1_fscale88.mc.root";
140 // TString inFile = "mc.root";
141 // inFile = "bmn_run814_stripdigitthr15_noswap.root";
142 // Parameter file
143 // TString parFile = "data/AuAu_urqmd_3.3p1_4.0_gev__10000_ev__mbias__seed_0_params.root";
144 // TString dir = ""; // Output directory
145 // TString inFile = dir + mcFile; // MC transport file
146 // TString scriptFile = TString(gSystem->Getenv("MCFILE"));
147 // if (scriptFile != "") inFile = dir + scriptFile;
148 TString parFile = inFile;
149
150 // Output file
151 // outFile = "814.root";
152 // TString recoFile = TString(gSystem->Getenv("RECOFILE"));
153 // if (recoFile != "") outFile = dir + recoFile;
154
155 // Digitisation files.
156 // Add TObjectString containing the different file names to
157 // a TList which is passed as input to the FairParAsciiFileIo.
158 // The FairParAsciiFileIo will take care to create on the fly
159 // a concatenated input parameter file which is then used during
160 // the reconstruction.
161 TList* parFileList = new TList();
162
163 TString paramDir = gSystem->Getenv("VMCWORKDIR");
164 paramDir += "/parameters";
165
166 // TObjString stsDigiFile = paramDir + "/sts/sts_v12b_12344444_std.digi.par";
167 // TObjString stsDigiFile = paramDir + "/sts_v17a_gem.digi.par";
168 // TObjString stsDigiFile = paramDir + "/sts_v15a90_gem.digi.par";
169 // TObjString stsDigiFile = paramDir + "/sts_1st_30.digi.par";
170 // TObjString stsDigiFile = paramDir + "/sts_var.digi.par";
171 TString stsMatBudgetFile = ""; // paramDir + "/sts/sts_matbudget_v12b_12344444.root";
172 // TString stsMatBudgetFile = paramDir + "/sts_matbudget_var_fr.root";
173
174 // TString parFile="sts_v16s_gem.digi.par";//"GEMS_RunWinter2016.root";
175
176 TObjString stsDigiFile = "sts_v1_BMN_SI_GEM.digi.par"; // sts_v17BMN_gem.digi.par //18 for SI
177 // TObjString stsDigiFile2 = "/home/pokat/bmnM/bmnR/AZ_data/sts/GEMS_v16_AZ_3mm.root";
178 parFileList->Add(&stsDigiFile);
179 // parFileList->Add(&stsDigiFile2);
180
181 // In general, the following parts need not be touched
182 // ========================================================================
183
184 // ---- Debug option -------------------------------------------------
185 gDebug = 0;
186 // ------------------------------------------------------------------------
187
188 // ----- Timer --------------------------------------------------------
189 TStopwatch timer;
190 timer.Start();
191 // ------------------------------------------------------------------------
192
193 // ---- Load libraries -------------------------------------------------
194 // gROOT->LoadMacro("$VMCWORKDIR/macro/run/bmnloadlibs.C");
195 // bmnloadlibs();
196 // ------------------------------------------------------------------------
197
198 // ----- Reconstruction run -------------------------------------------
199 FairRunAna* run = new FairRunAna();
200 run->SetSource(new BmnFileSource(inFile));
201 run->SetOutputFile(outFile);
202 // -----------------------------------------------------------------------
203
204 // ----- Field map -------------------------------------------
205 // Int_t run_period=1, run_number=065;
206 // UniRun* pCurrentRun = UniRun::GetRun(run_period, run_number);
207 // if (pCurrentRun == 0) {
208 // exit(-2);
209 // }
210 // Double_t fieldScale = 0.01;
211 // double map_current = 0.01;//900.0;
212 // int* current_current = pCurrentRun->GetFieldCurrent();
213 // if (current_current == NULL) {
214 // fieldScale = 0.01;
215
216 // } else
217 // fieldScale = (*current_current) / map_current;
218 // cout<<" SCALE: "<<fieldScale<<endl;
219 // fieldScale=TMath::Max(fieldScale,0.01);
220 // FairRootManager::Instance()->InitSource();
221
222 // BmnEventHeader* bevh= (BmnEventHeader*)(
223 // ((TClonesArray*)FairRootManager::Instance()->GetObject("EventHeader"))->At(0) );
224 // Int_t runn=bevh->GetEventId();
225
226 BmnNewFieldMap* magField = new BmnNewFieldMap("field_sp41v4_ascii_Extrap.dat");
227 // Mscale=1.777777778;
228 // gROOT->LoadMacro("/run/media/pokat/SSD250/reco/tango_avg_field.C");
229 // Double_t Mscale=tango_avg_field(6,((BmnEventHeader*)bevhtca->At(0))->GetRunId());
230 // if(TMath::Abs(Mscale-1.3333)>0.2) exit(0);//Mscale=1.333333333;
231
232 magField->SetScale(Mscale); // 0.666666667);//2.0);//1.777777778);//2.0);//fieldScale);1.333333333
233 // BmnFieldConst* magField = new BmnFieldConst();
234 // magField->SetFieldRegion(-3000., 3000., -3000., 3000., -3000., 3000);
235 // magField->SetField(0, 0.000001 , 0.);
236
237 magField->Init();
238
239 run->SetField(magField);
240
241 cout << "FIELD SCALE: " << magField->GetScale() << endl;
242 // exit(0);
243 // ------------------------------------------------------------------------
244 // exit(0);
245 // =========================================================================
246 // === Detector Response Simulation (Digitiser) ===
247 // === (where available) ===
248 // =========================================================================
249
250 // ----- STS digitizer -------------------------------------------------
251 /*Double_t threshold = 4;
252 Double_t noiseWidth = 0.01;
253 Int_t nofBits = 12;
254 //Double_t electronsPerAdc = 10;
255 Double_t electronsPerAdc = 20; //AZ
256 Double_t StripDeadTime = 0.1;
257 Double_t minStep = 0.00004; //AZ
258 CbmBmnStsDigitize* stsDigitize = new CbmBmnStsDigitize("STS Digitiser", iVerbose);
259 stsDigitize->SetRealisticResponse();
260 stsDigitize->SetFrontThreshold (threshold);
261 stsDigitize->SetBackThreshold (threshold);
262 stsDigitize->SetFrontNoiseWidth(noiseWidth);
263 stsDigitize->SetBackNoiseWidth (noiseWidth);
264 stsDigitize->SetFrontNofBits (nofBits);
265 stsDigitize->SetBackNofBits (nofBits);
266 stsDigitize->SetFrontNofElPerAdc(electronsPerAdc);
267 stsDigitize->SetBackNofElPerAdc(electronsPerAdc);
268 stsDigitize->SetStripDeadTime (StripDeadTime);
269 stsDigitize->SetStep (minStep); //AZ
270 */
271 CbmBmnStsDigitize* stsDigitize = new CbmBmnStsDigitize("STS Digitiser", iVerbose);
272 stsDigitize->SetGeoFile(geoFile); // GP
273 run->AddTask(stsDigitize);
274 // -------------------------------------------------------------------------
275
276 // =========================================================================
277 // === STS local reconstruction ===
278 // =========================================================================
279 // ----- STS Cluster Finder --------------------------------------------
280 FairTask* stsClusterFinder = new CbmStsClusterFinder("STS Cluster Finder", iVerbose);
281 run->AddTask(stsClusterFinder);
282 // -------------------------------------------------------------------------
283
284 // ----- CSC Cluster Finder -------------------------------------------- //
285 // this task working, but isn't doing anything ! FOR NOW (16.07.18)
286 // FairTask *CSCClusterFinder = new CSCClusterFinder();
287 // run->AddTask(CSCClusterFinder);
288 // -------------------------------------------------------------------------
289
290 // ----- STS hit finder ------------------------------------------------
291 FairTask* stsFindHits = new CbmStsFindHits("STS Hit Finder", iVerbose);
292 run->AddTask(stsFindHits);
293 // -------------------------------------------------------------------------
294
295 // ----- STS hit matching -----------------------------------------------
296 // FairTask* stsMatchHits = new CbmStsMatchHits("STS Hit Matcher", iVerbose);
297 // run->AddTask(stsMatchHits);
298 // -------------------------------------------------------------------------
299
300 // --- STS track finding ------------------------------------------------
301 CbmKF* kalman = new CbmKF();
302 run->AddTask(kalman);
303
304 CbmL1* l1 = new CbmL1();
305 l1->SetMaterialBudgetFileName(stsMatBudgetFile);
306 run->AddTask(l1);
307
308 CbmStsTrackFinder* stsTrackFinder = new CbmL1StsTrackFinder();
309 FairTask* stsFindTracks = new CbmStsFindTracks(iVerbose, stsTrackFinder);
310 run->AddTask(stsFindTracks);
311
312 // --- STS track fitting -----------------------------------------------
313 // CbmStsTrackFitter* stsTrackFitter = new CbmStsKFTrackFitter();
314 // FairTask* stsFitTracks = new CbmStsFitTracks(stsTrackFitter, iVerbose);
315 // run->AddTask(stsFitTracks);
316 // -------------------------------------------------------------------------
317
318 // ----- Primary vertex finding ---------------------------------------
319
320 CbmPrimaryVertexFinder* pvFinder = new CbmPVFinderKF();
321 CbmFindPrimaryVertex* findVertex = new CbmFindPrimaryVertex(pvFinder); //
322 run->AddTask(findVertex);
323
324 // ------------------------------------------------------------------------
325
326 // StsTrackExtrapToDCH* extrapDCH= new StsTrackExtrapToDCH();
327 // extrapDCH.fEff=1;
328 // run->AddTask(extrapDCH);
329
330 /*
331 // --- STS track matching ----------------------------------------------
332 FairTask* stsMatchTracks = new CbmStsMatchTracks(iVerbose);
333 run->AddTask(stsMatchTracks);
334 // -------------------------------------------------------------------------
335
336
337 // --- STS track fitting -----------------------------------------------
338 /// CbmStsTrackFitter* stsTrackFitter = new CbmStsKFTrackFitter();
339 /// FairTask* stsFitTracks = new CbmStsFitTracks(stsTrackFitter, iVerbose);
340 /// run->AddTask(stsFitTracks);
341 // -------------------------------------------------------------------------
342
343 // === End of STS local reconstruction ===
344 // =========================================================================
345
346
347
348 // =========================================================================
349 // === Global tracking ===
350 // =========================================================================
351
352 /// CbmLitFindGlobalTracks* finder = new CbmLitFindGlobalTracks();
353 // Tracking method to be used
354 // "branch" - branching tracking
355 // "nn" - nearest neighbor tracking
356 // "weight" - weighting tracking
357 /// finder->SetTrackingType("branch");
358
359 // Hit-to-track merger method to be used
360 // "nearest_hit" - assigns nearest hit to the track
361 /// finder->SetMergerType("nearest_hit");
362
363 /// run->AddTask(finder);
364
365 // ----- Primary vertex finding ---------------------------------------
366 CbmPrimaryVertexFinder* pvFinder = new CbmPVFinderKF();
367 CbmFindPrimaryVertex* findVertex = new CbmFindPrimaryVertex(pvFinder); //
368 run->AddTask(findVertex);
369 // ------------------------------------------------------------------------
370
371 // === End of global tracking ===
372 // =========================================================================
373
374 // ----------- TRD track Pid Like ----------------------
375 // Since in the newest version of this method depends on the global
376 // track the task has to move after the global tracking
377 // FU 08.02.12 Switch the task off since the input file needed for the new geometry has to be generated first.
378 // CbmTrdSetTracksPidLike* trdSetTracksPidLikeTask =
379 // new CbmTrdSetTracksPidLike("Likelihood", "Likelihood");
380 // run->AddTask(trdSetTracksPidLikeTask);
381 // ----------------------------------------------------
382 */
383 // ----- Parameter database --------------------------------------------
384 // TString stsDigi = gSystem->Getenv("VMCWORKDIR");
385 // stsDigi += "/parameters/sts/";
386 // stsDigi += stsDigiFile;
387 FairRuntimeDb* rtdb = run->GetRuntimeDb();
388 FairParRootFileIo* parIo1 = new FairParRootFileIo();
389 FairParAsciiFileIo* parIo2 = new FairParAsciiFileIo();
390 parIo1->open(parFile.Data());
391 parIo2->open(parFileList, "in");
392 gSystem->Unlink(parIo2->getFilename()); // drop concatenated all_<pid>.par
393 rtdb->setFirstInput(parIo1);
394 rtdb->setSecondInput(parIo2);
395 rtdb->setOutput(parIo1);
396 rtdb->saveOutput();
397
398 // ------------------------------------------------------------------------
399
400 // ----- Intialise and run --------------------------------------------
401 run->Init();
402 cout << "Starting run" << endl;
403 run->Run(0, nEvents);
404 // ------------------------------------------------------------------------
405
406 // ----- Finish -------------------------------------------------------
407 timer.Stop();
408 Double_t rtime = timer.RealTime();
409 Double_t ctime = timer.CpuTime();
410 cout << endl << endl;
411 cout << "Macro finished succesfully." << endl;
412 cout << "Output file is " << outFile << endl;
413 cout << "Parameter file is " << parFile << endl;
414 cout << "Real time " << rtime << " s, CPU time " << ctime << " s" << endl;
415 cout << endl;
416 // ------------------------------------------------------------------------
417
418 // delete run;
419
420 cout << " Test passed" << endl;
421 cout << " All ok " << endl;
422 exit(0);
423}
int Int_t
Int_t gDebug
double Double_t
constexpr Int_t kFatal
Int_t gErrorIgnoreLevel
R__EXTERN TSystem * gSystem
void SetScale(Double_t factor)
Set a global field scaling factor.
Definition BmnFieldMap.h:55
virtual void Init()
Double_t GetScale() const
Accessor to global scaling factor.
Definition BmnFieldMap.h:90
BmnFileSource.h.
Field Map does not have any symmetries w.r.t coordinate axises.
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.
void Add(TObject *obj) override
Double_t RealTime()
void Start(Bool_t reset=kTRUE)
Double_t CpuTime()
void Stop()
const char * Data() const
void run_reco_gem_r7(TString inFile="", TString outFile="", TString geoFile="SIGEMS_r7.root", Int_t nEvents=0, Int_t rnum=0, Double_t Mscale=1.366666667)