BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
DrawSpillEvents.C
Go to the documentation of this file.
1
3
4// #if !defined(__CINT__) || defined(__MAKECINT__)
5// #include <memory>
6// #include <chrono>
7// #include <iostream>
8// #include <map>
9//// ROOT
10// #include <TString.h>
11// #include <TStyle.h>
12// #include <TFile.h>
13// #include <TTree.h>
14// #include <TTimeStamp.h>
15//// fairroot
16////#include <fairlogger/Logger.h>
17// #include <FairLogger.h>
18//// BmnRoot
19// #include "../../base/header/DigiRunHeader.h"
20// #include <BmnMetadataRaw.h>
21// #include <BmnSpillHeader.h>
22// #endif
23
24#define PAD_WIDTH 3840
25#define PAD_HEIGHT 640
26
27using namespace std;
28
29/**
30 * DrawSpillEvents
31 * Draw the MSC data
32 * @param fileName
33 */
34void DrawSpillEvents(TString fileName = "bmn_run9362_ev0_p0_digi.root")
35{
36 if (fileName == "") {
37 cout << "File not specified!" << endl;
38 return;
39 }
40 FairLogger::GetLogger()->SetLogToScreen(true);
41 FairLogger::GetLogger()->SetLogScreenLevel("info"); // for info write "INFO"
42 // const vector<string> evt_tr_names{"BT", "MBT", "CCT1", "CCT2"};
43 const vector<string> evt_tr_names{"BT", "MBT", "CCT1", "CCT2", "RC_Trig_Cand",
44 "DAQ_RO_Trig", "pBT", "BC1L", "NiT", "BT&nBUSY"};
45 // gStyle->SetOptStat("e");
46
47 TFile* file = new TFile(fileName, "READ");
48 if (file->IsOpen() == false) {
49 // printf("\nCannot open file %s !\n", fileName.Data());
50 LOG(error) << "Cannot open file " << fileName << " !" << endl;
51 return;
52 }
53 DigiRunHeader* rh = static_cast<DigiRunHeader*>(file->Get("DigiRunHeader"));
54 BmnMetadataRaw* metadata = static_cast<BmnMetadataRaw*>(file->Get("RawRunMetadata"));
55
56 if (rh == nullptr) {
57 LOG(error) << "No run header!" << endl;
58 return;
59 }
60 printf("Run Header content:\n");
61 UInt_t PeriodId = rh->GetPeriodId();
62 UInt_t RunId = rh->GetRunId();
63 printf("\tPeriod: %u Run: %u\n", PeriodId, RunId);
64 TTimeStamp RunStartTime = rh->GetRunStartTime();
65 TTimeStamp RunEndTime = rh->GetRunEndTime();
66 printf("\tSTART : %s\n", RunStartTime.AsString());
67 printf("\tFINISH : %s\n", RunEndTime.AsString());
68 auto& tcc = rh->GetTrigConfig().TrigChannelConfig();
69 map<SysPoint, BmnSpillInfo>& fSpillMap = rh->GetSpillMap();
70 // map<SysPoint, BmnSpillInfo>& fSpillMap = metadata->SpillMap();
71 NameChMap& fTrigBitsMap = metadata->TrcMap();
72 Name2SerCh& fScalersMap = metadata->ScalersMap();
73 // gStyle->SetTitleSize(22);
74 TTree* tree = static_cast<TTree*>(file->Get("spill"));
75 BmnSpillHeader* sh = nullptr;
76 TClonesArray* msc = nullptr;
77 TClonesArray* t0raw = nullptr;
78 tree->SetBranchAddress("BmnSpillHeader.", &sh);
79 tree->SetBranchAddress("MSC", &msc);
80 tree->SetBranchAddress("T0Raw", &t0raw);
81 /** canvas for trig counters per spill*/
82 vector<unique_ptr<TH1I>> evt_tr_hist;
83 size_t trigCount = 1; // evt_tr_names.size();
84 TString name = "Evt_triggers";
85 // auto can{make_unique<TCanvas>(name, name, PAD_WIDTH * 1, PAD_HEIGHT * trigCount)};
86 auto can{make_unique<TCanvas>(name, name, 1920, 1080)};
87 can->Divide(1, trigCount);
88 Double_t left_time(0), right_time(128);
89 const int32_t nbinsX = 128 + 1; // TMath::Min(500.0, (right_time - left_time) / msc_delta);
90 const int32_t nbinsY = 250;
91 int32_t station = 0;
92 int32_t module = 0;
93 int32_t layer = 1;
94 name = TString("SiBT0");
95 unique_ptr<TH2I> hist = make_unique<TH2I>(name, name, nbinsY, 0, 12e9, nbinsX + 1, 0, nbinsX);
96 hist->SetLineWidth(3);
97 hist->GetXaxis()->SetTitle("time");
98 hist->GetYaxis()->SetTitle("X");
99 hist->GetXaxis()->SetLabelSize(0.03);
100 hist->GetYaxis()->SetLabelSize(0.03);
101 // hist->GetXaxis()->SetTitleOffset(50);
102 hist->GetXaxis()->SetLabelOffset(0.028);
103 hist->GetYaxis()->SetLabelOffset(0.015);
104
105 if (fSpillMap.size() < 2) {
106 printf("No Spill in the map!");
107 return;
108 }
109 // auto itb = fSpillMap.begin();
110 // BmnSpillInfo& si = (++itb)->second;
111 TString file_names = "./bmn_run9362_ev*_p*_digi.root";
112 TChain chain("bmndata");
113 chain.Add(file_names);
114 BmnEventHeader* inEventHeader(nullptr);
115 TClonesArray* inSibt(nullptr);
116 map<SysPoint, int64_t> ts2event;
117 chain.SetBranchAddress("BmnEventHeader.", &inEventHeader);
118 chain.SetBranchAddress("SiBT", &inSibt);
119 // for (int64_t iEntry = 0; iEntry < chain.GetEntries(); iEntry++) {
120 // chain.GetEntry(iEntry);
121 // ts2event.insert(make_pair(inEventHeader->GetEventTimeTP(), iEntry));
122 // // printf("insert iev %u ientry %li\n", inEventHeader->GetEventId(), iEntry);
123 //
124 // }
125
126 ROOT::RDataFrame df{"bmndata", file_names};
127
128 uint32_t ispill(0);
129 for (auto& mapel : fSpillMap) {
130 hist->Reset();
131 BmnSpillInfo& si = mapel.second;
132
133 auto df_spill = df.Filter(
134 [&](BmnEventHeader& eh) {
135 return ((eh.GetEventTimeTP() >= si.start_ts) && (eh.GetEventTimeTP() <= si.stop_ts));
136 },
137 {"BmnEventHeader."});
138
139 auto df_sp_digi = df_spill
140 .Define("tss",
141 [&](BmnEventHeader& eh) {
142 return std::chrono::duration_cast<std::chrono::nanoseconds>(
143 eh.GetEventTimeTP() - si.start_ts)
144 .count();
145 },
146 {"BmnEventHeader."})
147 .Define("strip",
148 [&](TClonesArray& array) {
149 std::vector<int32_t> out;
150 for (int32_t iDig = 0; iDig < array.GetEntries(); iDig++) {
151 BmnSiBTDigit* dig = static_cast<BmnSiBTDigit*>(array.At(iDig));
152 if ((dig->GetStation() != station) || (dig->GetModule() != module)
153 || (dig->GetStripLayer() != layer))
154 continue;
155 out.push_back(dig->GetStripNumber());
156 }
157 return out;
158 },
159 {"SiBT"});
160 // auto res = df_sp_digi.Histo1D("tss");//,"strip0");
161 auto res = df_sp_digi.Histo2D({name, name, nbinsY, 0, 11e9, nbinsX + 1, 0, nbinsX}, "tss", "strip");
162 // auto res = df_sp_digi.Histo2D("digi", "digi", nbinsY, 0, 12e9, nbinsX + 1, 0, nbinsX);
163 can->cd(1);
164 res->Draw("colz");
165 can->SaveAs(Form("spill_strip_run%u_l%d_spill%d.png", RunId, layer, ispill));
166
167 // auto it_start = ts2event.lower_bound(si.start_ts);
168 // auto it_stop = ts2event.upper_bound(si.stop_ts);
169 // if (it_start == ts2event.end()) {
170 // LOG(error) << "Cant'f find events in the spill";
171 // return;
172 // }
173 // printf("Spill:\n\tstart ts: %s\n\tstop ts: %s\n",
174 // BmnFunctionSet::TimePoint2String(si.start_ts).data(),
175 // BmnFunctionSet::TimePoint2String(si.stop_ts).data());
176 // for (auto it_time = it_start; it_time != it_stop; it_time++) {
177 // SysPoint time = it_time->first;
178 // int64_t iEntry = it_time->second;
179 // chain.GetEntry(iEntry);
180 // SysPoint point = inEventHeader->GetEventTimeTP();
181 // uint32_t iev = inEventHeader->GetEventId();
182 // for (int32_t iDig = 0; iDig < inSibt->GetEntries(); iDig++) {
183 // BmnSiBTDigit* dig = static_cast<BmnSiBTDigit*>(inSibt->At(iDig));
184 // if ((dig->GetStation() != station) || (dig->GetModule() != module) || (dig->GetStripLayer() !=
185 // layer))
186 // continue;
187 // int64_t time_since_start = std::chrono::duration_cast<std::chrono::nanoseconds>(time -
188 // si.start_ts).count(); //.time_since_epoch();
189 // // printf("iev %7u strip %3d time_since_start %12lu time %s \n",
190 // // iev, dig->GetStripNumber(), time_since_start,
191 // BmnFunctionSet::TimePoint2String(time).data()); hist->Fill(time_since_start,
192 // dig->GetStripNumber());
193 // }
194 //
195 // }
196 // can->cd(1);
197 // hist->Draw("colz");
198 // can->SaveAs(Form("spill_strip_run%u_s%u.png", RunId, ispill));
199 ispill++;
200 }
201}
TCanvas * can(nullptr)
unsigned int UInt_t
double Double_t
char * Form(const char *fmt,...)
std::unordered_map< std::string, std::pair< uint32_t, uint16_t > > Name2SerCh
Definition BmnAliases.h:9
std::unordered_map< std::string, uint16_t > NameChMap
Definition BmnAliases.h:7
SysPoint GetEventTimeTP()
Class BmnMetadataRaw for the configuration and raw spill information.
Name2SerCh & ScalersMap()
NameChMap & TrcMap()
Int_t GetStripNumber()
Int_t GetStripLayer()
Int_t GetStation()
Int_t GetModule()
unordered_map< string, BmnTrigChannelConfig > & TrigChannelConfig()
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.
map< SysPoint, BmnSpillInfo > & GetSpillMap()
RInterface< RDFDetail::RFilter< F, Proxied >, DS_t > Filter(F f, const ColumnNames_t &columns={}, std::string_view name="")
Int_t SetBranchAddress(const char *bname, T **add, TBranch **ptr=nullptr)
virtual Int_t Add(const char *name, Long64_t nentries=TTree::kMaxEntries)
T * Get(const char *namecycle)
virtual Bool_t IsOpen() const
const char * AsString(const Option_t *option="") const
Int_t SetBranchAddress(const char *bname, T **add, TBranch **ptr=nullptr)
void DrawSpillEvents(TString fileName="bmn_run9362_ev0_p0_digi.root")
DrawSpillEvents Draw the MSC data.
Definition json.hpp:4446
SysPoint stop_ts
SysPoint start_ts