BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
DrawSpill.C
Go to the documentation of this file.
1
2#define PAD_WIDTH 3840
3#define PAD_HEIGHT 1280
4
5/**
6 * DrawSpill
7 * Draw the MSC data
8 * @param fileName
9 * @param digiPath directory of the DIGI files (not used now)
10 * @param drawBusy draw the time ranges of the busy signal
11 */
12void DrawSpill(TString fileName = "bmn_run7820_meta.root", TString digiPath = ".", bool drawBusy = true)
13{
14 if (fileName == "") {
15 cout << "File not specified!" << endl;
16 return;
17 }
18 FairLogger::GetLogger()->SetLogToScreen(true);
19 FairLogger::GetLogger()->SetLogScreenLevel("info"); // for info write "INFO"
20 // const vector<string> evt_tr_names{"BT", "MBT", "CCT1", "CCT2"};
21 const vector<string> evt_tr_names{
22 // "BT", "MBT", "CCT1", "CCT2", "RC_Trig_Cand", "DAQ_RO_Trig", "pBT", "BC1L", "NiT", "BT&nBUSY"};
23 // "BT", "MBT", "CCT1", "CCT2", "nFD", "RC_Trig_Cand", "DAQ_RO_Trig"};
24
25 // "BC0", "BC1", "pBT", "BT", "BT1", "NIT", "MBT", "CCT1", "CCT2", "CCT3", "CCT4",
26 // "FHCal", "BD_BA", "nFD",
27 // "Busy", "L0_Trig", "L1_Trig", "L1_Trig_v2", "L2_Trig", "L2_Trig_v2"};
28 // "pBT", "BT", "BT1", "NIT", "CCT2", "CCT3", "CCT4", "FHCal", "BD_BA", "L1_Trig", "L2_Trig_v2",
29 // "BC1",
30 "BT'", "MBT", "nFD", "CCT1", "L0_Trig", "L1_Trig", "L1_Trig_v2", "L2_Trig", "L2_Trig_v2", "Busy"};
31 gStyle->SetOptStat("e");
32
33 TFile* file = new TFile(fileName, "READ");
34 if (file->IsOpen() == false) {
35 LOG(error) << "Cannot open file " << fileName << " !" << endl;
36 return;
37 }
38 DigiRunHeader* rh = static_cast<DigiRunHeader*>(file->Get("DigiRunHeader"));
39 // BmnMetadataRaw* metadata = static_cast<BmnMetadataRaw*>(file->Get("RawRunMetadata"));
40
41 if (rh == nullptr) {
42 LOG(error) << "No run header!" << endl;
43 return;
44 }
45 printf("Run Header content:\n");
46 UInt_t PeriodId = rh->GetPeriodId();
47 UInt_t RunId = rh->GetRunId();
48 uint64_t msc_delta = PeriodId > 8 ? 16 : 200;
49 uint64_t trc_delta = 8;
50 uint64_t trc_slices_shift = 4;
51 printf("\tPeriod: %u Run: %u\n", PeriodId, RunId);
52 TTimeStamp RunStartTime = rh->GetRunStartTime();
53 TTimeStamp RunEndTime = rh->GetRunEndTime();
54 printf("\tSTART : %s\n", RunStartTime.AsString());
55 printf("\tFINISH : %s\n", RunEndTime.AsString());
56 auto& tcc = rh->GetTrigConfig().TrigChannelConfig();
57 NameChMap& fTrigBitsMap = rh->GetTrcBitMap();
58 // map<SysPoint, BmnSpillInfo>& fSpillMap = metadata->SpillMap();
59 // NameChMap& fTrigBitsMap = metadata->TrcMap();
60 // Name2SerCh& fScalersMap = metadata->ScalersMap();
61 // gStyle->SetTitleSize(22);
62 TTree* tree = static_cast<TTree*>(file->Get("spill"));
63 BmnSpillHeader* sh = nullptr;
64 TClonesArray* msc = nullptr;
65 TClonesArray* t0raw = nullptr;
66 tree->SetBranchAddress("BmnSpillHeader.", &sh);
67 tree->SetBranchAddress("MSC", &msc);
68 tree->SetBranchAddress("T0Raw", &t0raw);
69 /** canvas for trig counters per spill*/
70 vector<unique_ptr<TH1D>> evt_tr_hist;
71 size_t trigCount = evt_tr_names.size();
72 size_t padCount = trigCount + 1;
73 TString name = "Evt_triggers";
74 auto can{make_unique<TCanvas>(name, name, PAD_WIDTH * 1, PAD_HEIGHT * padCount)};
75 can->Divide(1, padCount);
76 // Double_t left_time(0), right_time(8e9);
77 // Double_t left_time(0e9), right_time(12e9);
78 // Double_t left_time(1e9), right_time(8e9);
79 // Double_t left_time(1.595e9), right_time(1.596e9);
80 Double_t left_time(1.5956e9), right_time(1.5963e9);
81 // Double_t left_time(5.0158838e9), right_time(5.0158855e9);
82 // Double_t left_time(5.0158846e9), right_time(5.0158855e9);
83 // Double_t left_time(5.0158852e9), right_time(5.0158855e9);
84 // Double_t left_time(5.0161e9), right_time(5.01635e9);
85 // Double_t left_time(5.01619245e9), right_time(5.01619275e9);
86 UInt_t nbins = TMath::Min(500.0, (right_time - left_time) / msc_delta);
87 UInt_t half_bin = (right_time - left_time) / (2 * nbins) - 1;
88 printf("NBins = %u\n", nbins);
89 UInt_t nbins_trc = TMath::Min(500.0, (right_time - left_time) / trc_delta);
90
91 for (Int_t i = 0; i < trigCount; i++) {
92 name = TString("scaler_") + TString(evt_tr_names[i]);
93 evt_tr_hist.push_back(make_unique<TH1D>(name, name, nbins, left_time, right_time));
94 unique_ptr<TH1D>& h = evt_tr_hist.back();
95 h->SetLineWidth(3);
96 h->GetXaxis()->SetLabelSize(0.08);
97 h->GetYaxis()->SetLabelSize(0.09);
98 h->GetXaxis()->SetTitleOffset(50);
99 h->GetXaxis()->SetLabelOffset(0.028);
100 h->GetYaxis()->SetLabelOffset(0.015);
101 }
102 // TRC bit state time line
103 name = "TRC_bit_state";
104 UInt_t n_trc_bits = 16;
105 // unique_ptr<TH2I> h_TRC_time_bits =
106 // make_unique<TH1I>(name, name, nbins_trc, left_time, right_time, n_trc_bits, 0, n_trc_bits);
107 // for (auto &[tr_name: i_bit]: fTrigBitsMap) {
108 // h_TRC_time_bits->GetYaxis()->SetBinLabel(i_bit, tr_name.data());
109 // }
110 // Load events dataframe
111 // TString file_names(Form("%s/*%u_ev*_p*.root", digiPath.Data(), RunId));
112 // cout <<" digi names " << file_names << endl;
113 // ROOT::RDataFrame df{"bmndata", file_names};
114
115 int64_t NSpills = tree->GetEntriesFast();
116 for (int64_t iSpill : {/*(int64_t)0,*/ NSpills - 2, NSpills - 1}) {
117 // for (int64_t iSpill = 0; iSpill < NSpills; iSpill++) {
118 tree->GetEntry(iSpill);
119 SysPoint left_tp = sh->GetStartTime() + ((uint64_t)left_time) * 1ns;
120 SysPoint right_tp = sh->GetStartTime() + ((uint64_t)right_time) * 1ns;
121 printf("Spill:\n\tstart %s\n\tstop %s\n", BmnFunctionSet::TimePoint2String(sh->GetStartTime()).c_str(),
123
124 if (msc->GetEntries()) {
125 BmnMSCMatrix<uint8_t>* msc_matrix = static_cast<BmnMSCMatrix<uint8_t>*>(msc->At(0));
126 for (Int_t i = 0; i < trigCount; i++) {
127 evt_tr_hist[i]->Reset();
128 string sc_name = evt_tr_names[i];
129 // auto it = rh->ScalersName2IndexMap().find(sc_name);
130 // if (it == rh->ScalersName2IndexMap().end())
131 // continue;
132 // uint16_t i_sc = it->second;
133
134 // auto& tline = msc_matrix->ScalerTimeLine(sc_name);
135 // auto itLower = tline.lower_bound(left_tp);
136 // auto itUpper = tline.upper_bound(right_tp);
137 auto [itLower, itUpper] = msc_matrix->GetScalerRange(sc_name, left_tp, right_tp);
138 // auto itLower = tline.lower_bound(sh->GetStartTime() + (uint64_t)left_time * 1ns);
139 // auto itUpper = tline.upper_bound(sh->GetStopTime() + (uint64_t)right_time * 1ns);
140 for (auto itTimes = itLower; itTimes != itUpper; itTimes++) {
141 SysPoint time = itTimes->first;
142 uint8_t cnt = itTimes->second;
143 int64_t nans = (time.time_since_epoch() - sh->GetStartTime().time_since_epoch()).count();
144 if (cnt)
145 evt_tr_hist[i]->Fill(nans, cnt);
146 }
147 // for (size_t i_rec = 0; i_rec < msc_matrix->GetNRecords(); i_rec++) {
148 // // uint8_t cnt = msc_matrix->Counts(i_rec, i_sc);
149 // uint8_t cnt = msc_matrix->GetCount(i_rec, i_sc);
150 // int64_t nans =
151 // (msc_matrix->Time(i_rec).time_since_epoch() -
152 // sh->GetStartTime().time_since_epoch()).count();
153 // // printf("MSC %7zu %7u %9ld\n", i_rec,
154 // cnt, nans);
155 // // printf("MSC %u\n", msc_matrix->GetCount(i_rec, i_sc));
156 // if (cnt)
157 // evt_tr_hist[i]->Fill(nans, cnt);
158 // }
159 }
160 for (Int_t i = 0; i < trigCount; i++) {
161 TVirtualPad* pad = can->cd(i + 1);
162 gStyle->SetTitleFontSize(0.1);
163 gStyle->SetTitleX(.5);
164 gStyle->SetTitleY(1.01);
165 evt_tr_hist[i]->Draw("hist");
166 if (drawBusy) {
167 auto [itLower, itUpper] = msc_matrix->GetBusyRanges(left_tp, right_tp);
168 for (auto itRangeEntry = itLower; itRangeEntry != itUpper; itRangeEntry++) {
169 const SysPoint& timeBegin = itRangeEntry->first;
170 const SysPoint& timeEnd = itRangeEntry->second;
171 int64_t nansBegin =
172 (timeBegin.time_since_epoch() - sh->GetStartTime().time_since_epoch()).count();
173 int64_t nansEnd = (timeEnd.time_since_epoch() - sh->GetStartTime().time_since_epoch()).count();
174 int32_t binLow = evt_tr_hist[i]->FindBin(nansBegin);
175 double low = evt_tr_hist[i]->GetBinLowEdge(binLow);
176 int32_t binHi = evt_tr_hist[i]->FindBin(nansEnd);
177 double hi = evt_tr_hist[i]->GetBinLowEdge(binHi);
178 TBox* box = new TBox(
179 // nans/* - half_bin*/, 0,
180 low, 0,
181 // nans_end/* - half_bin*/,
182 hi, evt_tr_hist[i]->GetMaximum());
183 box->SetFillColor(kRed);
184 box->SetFillStyle(3001);
185 box->Draw("same");
186 }
187 }
188 }
189 // // TH1D* div = (TH1D*)evt_tr_hist[8]->Clone("L1/BC1");
190 // // div->Divide(evt_tr_hist[7].get());
191 // // div->SetTitle("nFD/CCT1");
192 // // can->cd(padCount);
193 // // div->Draw("hist");
194 // auto df_spill = df.Filter(
195 // [&](BmnEventHeader& eh) {
196 // return ((eh.GetEventTimeTP() >= left_tp) && (eh.GetEventTimeTP() <= right_tp));
197 // },
198 // {"BmnEventHeader."});
199 //
200 // auto df_sp_digi =
201 // df_spill
202 // .Define("trctime",
203 // [&](BmnEventHeader& eh) {
204 // // vector<pair<uint64_t, uint8_t>> bit_time_line;
205 // // printf("Ev %u\n", eh.GetEventId());
206 // vector<uint64_t> time_line;
207 // uint64_t nans_ev_slice =
208 // std::chrono::duration_cast<std::chrono::nanoseconds>(
209 // eh.GetEventTimeTP() - sh->GetStartTime())
210 // .count();
211 // nans_ev_slice -= trc_delta * trc_slices_shift;
212 // // printf("%u %zu\n", eh.GetEventId(),
213 // // eh.GetInputSignalsVector().size());
214 // for (uint32_t& bit_slice : eh.GetInputSignalsVector()) {
215 // nans_ev_slice += trc_delta;
216 // for (uint8_t i_bit = 0; i_bit < n_trc_bits; i_bit++) {
217 // if (bit_slice & BIT(i_bit)) {
218 // // bit_time_line.push_back(make_pair(nans_ev_slice, i_bit));
219 // // printf("%lu %u\n",
220 // nans_ev_slice,
221 // // i_bit);
222 // time_line.push_back(nans_ev_slice);
223 // }
224 // }
225 // }
226 // return time_line;
227 // },
228 // {"BmnEventHeader."})
229 // .Define("trcbit",
230 // [&](BmnEventHeader& eh) {
231 // vector<uint8_t> trig_line;
232 // uint64_t nans_ev_slice =
233 // std::chrono::duration_cast<std::chrono::nanoseconds>(
234 // eh.GetEventTimeTP() - sh->GetStartTime())
235 // .count();
236 // nans_ev_slice -= trc_delta * trc_slices_shift;
237 // for (uint32_t& bit_slice : eh.GetInputSignalsVector()) {
238 // nans_ev_slice += trc_delta;
239 // for (uint8_t i_bit = 0; i_bit < n_trc_bits; i_bit++) {
240 // if (bit_slice & BIT(i_bit))
241 // trig_line.push_back(i_bit);
242 // }
243 // }
244 // return trig_line;
245 // },
246 // {"BmnEventHeader."});
247 // auto res = df_sp_digi.Histo2D(
248 // {name, name, (int32_t)nbins_trc, left_time, right_time, (int32_t)n_trc_bits, 0,
249 // (double)n_trc_bits}, "trctime", "trcbit");
250 // // "trctb.first", "trctb.second");
251 // res->GetXaxis()->SetLabelSize(0.08);
252 // res->GetYaxis()->SetLabelSize(0.09);
253 // res->SetLineWidth(4);
254 // for (auto& map_el : fTrigBitsMap)
255 // res->GetYaxis()->SetBinLabel(map_el.second + 1, map_el.first.data());
256 // TVirtualPad* pad = can->cd(padCount);
257 // double xmin = left_time; // pad->GetUxmin();
258 // double xmax = right_time; // pad->GetUxmax();
259 // double step = (right_time - left_time) / nbins_trc;
260 // // res->GetXaxis()->SetNdivisions(nbins_trc);
261 // gStyle->SetGridWidth(4);
262 // pad->SetGrid(0, 1);
263 // res->Draw("col");
264 // res->Draw("same Y+");
265 //
266 // for (double x = xmin; x <= xmax; x += step) {
267 // TLine* lx = new TLine(x, 0, x, n_trc_bits);
268 // lx->SetLineStyle(7);
269 // lx->SetLineWidth(4);
270 // lx->SetLineColor(kGray + 2);
271 // lx->Draw("same");
272 // }
273 // // TAxis *left = res->GetYaxis();
274 // // TAxis *right = (TAxis*)left->Clone();
275 // // right->SetLabelOffset(1.0);
276 // // right->Draw("HIST SAME Y+");
277 // // TVirtualPad* pad2 = can->cd(padCount);
278 // // pad2->SetFillColor(0);
279 // // pad2->SetFillStyle(4000);
280 // // pad2->SetFrameFillStyle(0);
281 // // res->Draw("same Y+");
282 // // pad->Update();
283
284 can->SaveAs(Form("scalers_%u_s%ld.png", RunId, iSpill));
285 // delete div;
286 // break;
287 }
288 }
289}
#define PAD_WIDTH
Definition DrawSpill.C:2
#define PAD_HEIGHT
Definition DrawSpill.C:3
TCanvas * can(nullptr)
int i
Definition P4_F32vec4.h:22
int Int_t
unsigned int UInt_t
double Double_t
kRed
char * Form(const char *fmt,...)
R__EXTERN TStyle * gStyle
std::chrono::time_point< SysClock > SysPoint
std::unordered_map< std::string, uint16_t > NameChMap
Definition BmnAliases.h:7
static std::string TimePoint2String(SysPoint p)
Storage for all MSC counters of the spill.
auto GetBusyRanges(const SysPoint &timeBegin=SysPoint::min(), const SysPoint &timeEnd=SysPoint::max())
Returns the [begin,end) iterators for range of time point pairs representing begin and end of a busy ...
auto GetScalerRange(const string &scaler_name, const SysPoint &timeBegin=SysPoint::min(), const SysPoint &timeEnd=SysPoint::max())
const SysPoint GetStopTime()
Get the stop TS.
const SysPoint GetStartTime()
Get the start TS.
unordered_map< string, BmnTrigChannelConfig > & TrigChannelConfig()
NameChMap & GetTrcBitMap()
TRC bit map.
uint64_t GetPeriodId()
Get the period ID for this run.
uint64_t GetRunId()
Get the run ID.
TTimeStamp GetRunEndTime()
TTimeStamp GetRunStartTime()
BmnTrigConfig & GetTrigConfig()
Get DAQ trigger config.
virtual void SetFillColor(Color_t fcolor)
virtual void SetFillStyle(Style_t fstyle)
void Draw(Option_t *option="") override
T * Get(const char *namecycle)
virtual Bool_t IsOpen() const
Int_t GetEntries() const override
TObject * At(Int_t idx) const override
const char * AsString(const Option_t *option="") const
virtual Int_t GetEntry(Long64_t entry, Int_t getall=0)
virtual Long64_t GetEntriesFast() const
Int_t SetBranchAddress(const char *bname, T **add, TBranch **ptr=nullptr)
void DrawSpill(TString fileName="bmn_run7820_meta.root", TString digiPath=".", bool drawBusy=true)
DrawSpill Draw the MSC data.
Definition DrawSpill.C:12
Double_t Min(Double_t a, Double_t b)