BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
run_raw_bmn.C
Go to the documentation of this file.
1TString gRawRootFilePath = ""; // store intermediate RAW ROOT file path
2/// Converts and/or decodes BM@N raw data file to a file with detector digits
3///
4/// The macro drives BmnRawDataDecoder through up to two steps:
5/// 1. conversion of the binary .data file into an intermediate RAW ROOT file
6/// containing the electronics digits (ADC, TDC, ..., sync);
7/// 2. decoding of that RAW ROOT file into detector digits using the mapping
8/// and calibration files selected for the given period, run and setup.
9///
10/// \param file full path to the input raw file (.data for todo = 1 or 2;
11/// RAW ROOT file for todo = 0)
12/// \param outfile full path to the output file with detector digits;
13/// if empty, built as bmn_run<runId><_evXX_pXX><.compress>_digi.root
14/// \param nEvents number of events to process, 0 means all events
15/// \param period BM@N run period number, to pick up mapping and calibration files
16/// \param todo 0 - RAW_ROOT -> DIGI, 1 - RAW -> DIGI, 2 - RAW -> RAW_ROOT
17/// \param doHoldRawRoot if kFALSE, the intermediate RAW ROOT file is deleted after
18/// decoding (ignored when todo = 2)
19void run_raw_bmn(TString file = "",
20 TString outfile = "",
21 Long_t nEvents = 0,
22 UInt_t period = 8,
23 UInt_t todo = 1,
24 Bool_t doHoldRawRoot = kTRUE)
25{
26 gSystem->ExpandPathName(file);
27 gSystem->ExpandPathName(outfile);
28 bool doConvert = (todo == 1) || (todo == 2);
29 bool doDecode = (todo == 1) || (todo == 0);
30
31 Int_t iVerbose = 0; ///<- Verbosity level: 0 - summary info on progress; 1 - event level, 2 - event objects level,
32 ///< 3 - full debug output
33 FairLogger::GetLogger()->SetLogToScreen(true);
34 FairLogger::GetLogger()->SetLogScreenLevel("info"); // for info write "INFO"
35
36 TStopwatch timer;
37 TStopwatch timer_conv;
38 timer.Start();
39
40 BmnRawDataDecoder* rdd = new BmnRawDataDecoder(file, outfile, nEvents, period);
41 BmnStatus convert_status;
42 BmnStatus decode_status;
43 // rdd->SetRawRootDirPath("/dev/shm/temp_raw/");
44 // use kSRCSETUP for Short-Range Correlation program and kBMNSETUP otherwise
45 BmnSetup stp = kBMNSETUP; //(decoder->GetRunId() >= 2041 && decoder->GetRunId() <= 3588) ? kSRCSETUP : kBMNSETUP;
46 rdd->SetBmnSetup(stp);
47 rdd->SetVerbose(iVerbose);
48
49 std::map<DetectorId, bool> setup; // flags to determine BM@N setup
50 setup.insert(std::make_pair(kBC, 1)); // TRIGGERS
51 // setup.insert(std::make_pair(kMWPC, 0)); // MWPC
52 setup.insert(std::make_pair(kSILICON, 1)); // SILICON
53 setup.insert(std::make_pair(kGEM, 1)); // GEM
54 setup.insert(std::make_pair(kTOF1, 1)); // TOF-400
55 // setup.insert(std::make_pair(kTOF, 1)); // TOF-700
56 setup.insert(std::make_pair(kTOF701, 1)); // TOF-701
57 setup.insert(std::make_pair(kDCH, 1)); // DCH
58 // setup.insert(std::make_pair(kZDC, 0)); // ZDC
59 // setup.insert(std::make_pair(kECAL, 0)); // ECAL
60 setup.insert(std::make_pair(kCSC, 1)); // CSC
61 setup.insert(std::make_pair(kSCWALL, 1)); // SCWALL
62 setup.insert(std::make_pair(kFHCAL, 1)); // FHCAL
63 setup.insert(std::make_pair(kHODO, 1)); // HODO
64 setup.insert(std::make_pair(kNDET, 1)); // Neutron Calorimeter Prototype
65 setup.insert(std::make_pair(kHGND, 1)); // Neutron Calorimeter
66 setup.insert(std::make_pair(kSiBT, 1)); // SiBD
67 setup.insert(std::make_pair(kVSP, 1)); // VSP
68 rdd->SetDetectorSetup(setup);
69
70 // Set converter/decoder general parameters
71 rdd->SetDecoderConfigFileName(string(getenv("VMCWORKDIR")) + "/config/bmnconf.json");
72
73 if (doConvert) {
74 timer_conv.Start();
75 BmnStatus convert_status = rdd->ConvertRawToRoot(); // Convert raw data in .data format into adc-,tdc-, ...,
76 // sync-digits in .root format
77 if (convert_status == kBMNERROR)
78 return;
80 printf("Root File Name: %s\n", gRawRootFilePath.Data());
81 timer_conv.Stop();
82 }
83
84 if (doDecode) {
85 rdd->CreateDecoder();
86 BmnDecoder* decoder = rdd->GetDecoder();
87 TString PeriodSetupExt = Form("%d%s.txt", period, ((stp == kBMNSETUP) ? "" : "_SRC"));
88 decoder->SetTrigPlaceMapping(TString("Trig_PlaceMap_Run") + PeriodSetupExt);
89 decoder->SetTrigChannelMapping(TString("Trig_map_Run") + PeriodSetupExt);
90 decoder->SetSiliconMapping(TString("SILICON_map_run") + PeriodSetupExt);
91 decoder->SetSiBTMapping(TString("SiBT_map_period") + PeriodSetupExt);
92 decoder->SetGemMapping(TString("GEM_map_run") + PeriodSetupExt);
93 decoder->SetCSCMapping(TString("CSC_map_period")
94 + Form("%d%s%s.txt", period, ((stp == kBMNSETUP) ? "" : "_SRC"),
95 (decoder->GetRunId() < 7013 ? "_before_run_7013" : "")));
96 decoder->SetMSCMapping(TString("MSC_map_Run") + PeriodSetupExt);
97 // in case comment out the line decoder->SetTof400Mapping("...")
98 // the maps of TOF400 will be read from DB (only for JINR network)
99 decoder->SetTof400Mapping(TString("TOF400_PlaceMap_RUN") + PeriodSetupExt,
100 TString("TOF400_StripMap_RUN") + PeriodSetupExt);
101 decoder->SetTof701Mapping(TString("TOF701_PlaceMap_RUN") + PeriodSetupExt,
102 TString("TOF701_StripMap_RUN") + PeriodSetupExt);
103 // decoder->SetZDCMapping("ZDC_map_period_5.txt");
104 // decoder->SetZDCCalibration("zdc_muon_calibration.txt");
105 decoder->SetScWallMapping(Form("SCWALL_map_period%d.json", period));
106 decoder->SetFHCalMapping(TString("FHCAL_map_period") + PeriodSetupExt);
107 decoder->SetFHCalCalibration(TString("FHCAL_calibration_period") + PeriodSetupExt);
108 decoder->SetHodoMapping(Form("HODO_map_period%d.json", period));
109 decoder->SetNdetMapping(TString("NDET_map_period") + PeriodSetupExt);
110 if ((decoder->GetRunId() >= 7506 && decoder->GetRunId() <= 7534)
111 || (decoder->GetRunId() >= 8203 && decoder->GetRunId() <= 8258))
112 decoder->SetNdetCalibration(TString("NDET_calibration_period")
113 + Form("%d_run_7506_7534_or_8203_8258.txt", period));
114 else
115 decoder->SetNdetCalibration(TString("NDET_calibration_period") + PeriodSetupExt);
116 decoder->SetHgndMapping(Form("HGND_map_period%d.json", period));
117 decoder->SetHgndCalibration(Form("HGND_calibration_period%d.json", period));
118 // decoder->SetECALMapping(TString("ECAL_map_period_") + PeriodSetupExt);
119 // decoder->SetECALCalibration("");
120 // decoder->SetMwpcMapping(TString("MWPC_map_period") + ((period == 6 && decoder->GetRunId() < 1397) ? 5 :
121 // PeriodSetupExt));
122
123 decoder->SetApplyThreshold(kTRUE); // set kFALSE to check pedestals
124 decoder->SetUseCalibFile(kFALSE); // set kTRUE to save and load strip signal calibration data
125 decode_status = rdd->DecodeDataToDigi(); // Decode data into detector-digits using current mappings.
126 if (!doHoldRawRoot) {
127 printf("Removing %s\n", decoder->GetRootFileName().Data());
128 gSystem->Exec(TString::Format("rm -f %s", decoder->GetRootFileName().Data()));
129 }
130 printf("Output digi file: %s\n", decoder->GetDigiFileName().Data());
131 }
132 timer.Stop();
133
134 if ((doConvert && (convert_status == kBMNSUCCESS)) || (doDecode && (decode_status == kBMNSUCCESS)))
135 printf("\tMacro finished successfully!\n\n"); // marker of successfully execution for software testing systems
136 if (doConvert) {
137 Double_t rtime_conv = timer_conv.RealTime();
138 Double_t ctime_conv = timer_conv.CpuTime();
139 printf("Converter: Real time %f s, CPU time %f s\n", rtime_conv, ctime_conv);
140 }
141 Double_t rtime = timer.RealTime();
142 Double_t ctime = timer.CpuTime();
143 printf("All steps: Real time %f s, CPU time %f s\n", rtime, ctime);
144 delete rdd;
145}
bool Bool_t
int Int_t
long Long_t
unsigned int UInt_t
constexpr Bool_t kFALSE
double Double_t
constexpr Bool_t kTRUE
char * Form(const char *fmt,...)
R__EXTERN TSystem * gSystem
@ kBC
@ kSILICON
@ kNDET
@ kGEM
@ kVSP
@ kHGND
@ kTOF1
@ kFHCAL
@ kSCWALL
@ kCSC
@ kTOF701
@ kDCH
@ kSiBT
@ kHODO
BmnStatus
Define status code.
Definition BmnEnums.h:93
@ kBMNERROR
Error.
Definition BmnEnums.h:95
@ kBMNSUCCESS
Success.
Definition BmnEnums.h:94
BmnSetup
Define experimental setup.
Definition BmnEnums.h:165
@ kBMNSETUP
Definition BmnEnums.h:166
void SetApplyThreshold(bool b)
Definition BmnDecoder.h:128
void SetHgndMapping(TString map)
Definition BmnDecoder.h:217
void SetFHCalCalibration(TString cal)
Definition BmnDecoder.h:207
void SetHgndCalibration(TString cal)
Definition BmnDecoder.h:219
TString GetDigiFileName()
Definition BmnDecoder.h:274
void SetFHCalMapping(TString map)
Definition BmnDecoder.h:205
void SetMSCMapping(TString map)
Definition BmnDecoder.h:225
void SetTof701Mapping(TString PlaceMap, TString StripMap)
Definition BmnDecoder.h:184
void SetUseCalibFile(bool v)
Definition BmnDecoder.h:243
void SetNdetCalibration(TString cal)
Definition BmnDecoder.h:215
void SetTrigPlaceMapping(TString map)
Definition BmnDecoder.h:160
UInt_t GetRunId() const
Definition BmnDecoder.h:132
void SetGemMapping(TString map)
Definition BmnDecoder.h:174
void SetTrigChannelMapping(TString file)
Definition BmnDecoder.h:168
void SetScWallMapping(TString map)
Definition BmnDecoder.h:201
void SetCSCMapping(TString map)
Definition BmnDecoder.h:166
void SetSiliconMapping(TString map)
Definition BmnDecoder.h:162
void SetTof400Mapping(TString PlaceMap, TString StripMap)
Definition BmnDecoder.h:178
TString GetRootFileName()
Definition BmnDecoder.h:227
void SetHodoMapping(TString map)
Definition BmnDecoder.h:209
void SetNdetMapping(TString map)
Definition BmnDecoder.h:213
void SetSiBTMapping(TString map)
Definition BmnDecoder.h:164
void SetDetectorSetup(std::map< DetectorId, bool > setup)
BmnDecoder * GetDecoder() const
void SetVerbose(Int_t v)
void SetBmnSetup(BmnSetup v)
void SetDecoderConfigFileName(string FileName)
Double_t RealTime()
void Start(Bool_t reset=kTRUE)
Double_t CpuTime()
void Stop()
const char * Data() const
static TString Format(const char *fmt,...)
TString gRawRootFilePath
Definition run_raw_bmn.C:1
void run_raw_bmn(TString file="", TString outfile="", Long_t nEvents=0, UInt_t period=8, UInt_t todo=1, Bool_t doHoldRawRoot=kTRUE)
Converts and/or decodes BM@N raw data file to a file with detector digits.
Definition run_raw_bmn.C:19