BmnRoot
Loading...
Searching...
No Matches
BmnHistScWall.cxx
Go to the documentation of this file.
1#include "BmnHistScWall.h"
2
3#include "TGaxis.h"
4
5BmnHistScWall::BmnHistScWall(TString title, TString path, Int_t PeriodID, BmnSetup stp)
6 : BmnHist(PeriodID, stp)
7{
8 fTitle = title;
9 fName = title + "_cl";
10 SetGeometry(Form("ScWall_geo_period%d.root", PeriodID));
11 TGaxis::SetMaxDigits(2);
13}
14
15void BmnHistScWall::SetGeometry(const std::string& path)
16{
17 LOG(debug) << "BmnHistScWall::SetGeometry " << path;
18 fGeoHandler = new BmnScWallGeo();
19 fGeoHandler->ReadGeometryFromFile(path, false);
20}
21
23{
24 TString name;
25 name = fTitle + "_h2d_Grid";
26 h2d_grid = new TH2F(name, "ScWall Grid", 18, -135, 135, 8, -60, 60);
27 // h2d_grid = new TH2F(name, "ScWall Grid", fUniqueXpos.size()-1, &fUniqueXpos[0], fUniqueYpos.size()-1,
28 // &fUniqueYpos[0]);
29 h2d_grid->GetXaxis()->SetTitle("X [cm]");
30 h2d_grid->GetXaxis()->SetTitleColor(kOrange + 10);
31 h2d_grid->GetYaxis()->SetTitle("Y [cm]");
32 h2d_grid->GetYaxis()->SetTitleColor(kOrange + 10);
33 h2d_grid->GetZaxis()->SetNoExponent(kFALSE);
34 // h2d_grid->SetBarOffset(-0.2);
35 h2d_grid->SetStats(0);
36
37 name = fTitle + "_h2d_GridCenter";
38 h2d_grid_center = new TH2F(name, "ScWall Grid center", 36, -135, 135, 16, -60, 60);
39 // h2d_grid_center = new TH2F(name, "ScWall Grid center", 10, -30, 45, 4, -15, 15);
40 h2d_grid_center->GetXaxis()->SetTitle("X [cm]");
41 h2d_grid_center->GetXaxis()->SetTitleColor(kOrange + 10);
42 h2d_grid_center->GetYaxis()->SetTitle("Y [cm]");
43 h2d_grid_center->GetYaxis()->SetTitleColor(kOrange + 10);
44 h2d_grid_center->GetZaxis()->SetNoExponent(kFALSE);
45 // h2d_grid_center->SetBarOffset(-0.4);
46 h2d_grid_center->SetMarkerSize(0.6);
47 h2d_grid_center->SetStats(0);
48
49 name = fTitle + "_h2d_profile";
50 h2d_profile = new TH2F(name, "ScWall Profile", 175, 0, 175, 200, 0, 100);
51 h2d_profile->GetXaxis()->SetTitle("Cell id");
52 h2d_profile->GetXaxis()->SetTitleColor(kOrange + 10);
53 h2d_profile->GetYaxis()->SetTitle("dE/dx [Z^2]");
54 h2d_profile->GetYaxis()->SetTitleColor(kOrange + 10);
55 h2d_profile->SetStats(0);
56 name = fTitle + "CanvasAmplitudes";
57
58 // text histos
59 name = fTitle + "_h2d_cell_id";
60 h2d_cell_id = new TH2F(name, "h2d_cell_id", 18, -135, 135, 8, -60, 60);
61 h2d_cell_id->GetXaxis()->SetTitle("X [cm]");
62 h2d_cell_id->GetXaxis()->SetTitleColor(kOrange + 10);
63 h2d_cell_id->GetYaxis()->SetTitle("Y [cm]");
64 h2d_cell_id->GetYaxis()->SetTitleColor(kOrange + 10);
65 h2d_cell_id->GetZaxis()->SetNoExponent(kFALSE);
66 h2d_cell_id->SetMarkerSize(0.8);
67 h2d_cell_id->SetMarkerColor(kBlack);
68 // h2d_cell_id->SetBarOffset(0.2);
69
70 name = fTitle + "_h2d_cell_id_center";
71 h2d_cell_id_center = new TH2F(name, "h2d_cell_id_center", 10, -45, 30, 4, -15, 15);
72 h2d_cell_id_center->GetXaxis()->SetTitle("X [cm]");
73 h2d_cell_id_center->GetXaxis()->SetTitleColor(kOrange + 10);
74 h2d_cell_id_center->GetYaxis()->SetTitle("Y [cm]");
75 h2d_cell_id_center->GetYaxis()->SetTitleColor(kOrange + 10);
76 h2d_cell_id_center->GetZaxis()->SetNoExponent(kFALSE);
77 h2d_cell_id_center->SetMarkerSize(0.6);
78 h2d_cell_id_center->SetMarkerColor(kBlack);
79 // h2d_cell_id_center->SetBarOffset(-0.2);
80
81 name = fTitle + "CanvasAmplitudes";
82 canAmps = new TCanvas(name, name, PAD_WIDTH * ScWall_ROWS, PAD_HEIGHT * ScWall_COLS);
83 canAmps->Divide(ScWall_ROWS, ScWall_COLS);
84 canAmpsPads.resize(ScWall_ROWS * ScWall_COLS);
85 NamesAmps.resize(ScWall_ROWS * ScWall_COLS);
86 PadInfo* p1 = new PadInfo();
87 p1->aux = {h2d_grid_center, h2d_grid, h2d_cell_id, h2d_cell_id_center};
88 p1->auxOpt = {"colz logz", "colz", "text", "text"};
89
90 canAmpsPads[0] = p1;
91 PadInfo* p2 = new PadInfo();
92 p2->current = h2d_profile;
93 p2->opt = "colz logy logz";
94 canAmpsPads[1] = p2;
95
96 name = fTitle + "_hCellAmpl";
97 hCellAmpl = new TH1F(name, name, 400, 0, 35000);
98 hCellAmpl->SetStats(0);
99 hCellAmpl->GetYaxis()->SetTitle("Counts");
100 hCellAmpl->GetXaxis()->SetTitle("fAmpl");
101
102 name = fTitle + "_hCellE";
103 hCellE = new TH1F(name, name, 400, 0, 3000);
104 hCellE->SetStats(0);
105 hCellE->GetYaxis()->SetTitle("Counts");
106 hCellE->GetXaxis()->SetTitle("dE/dx");
107
108 name = fTitle + "_wfmCell";
109 wfmCell = new TH1F(name, name, 100, 0, 100);
110 wfmCell->SetMarkerStyle(31);
111 wfmCell->SetMarkerSize(0.5);
112 wfmCell->SetStats(0);
113
114 name = fTitle + "CanvasSelection";
115 canSelect = new TCanvas(name, name, PAD_WIDTH * 1, PAD_HEIGHT * 3);
116 canSelect->Divide(1, 3);
117 canSelectPads.resize(1 * 3);
118 NamesSelect.resize(1 * 3);
119 PadInfo* ps1 = new PadInfo();
120 ps1->current = hCellAmpl;
121 ps1->opt = "hist";
122 canSelectPads.at(0) = ps1;
123 NamesSelect.at(0) = ps1->current->GetName();
124 PadInfo* ps2 = new PadInfo();
125 ps2->current = hCellE;
126 ps2->opt = "hist";
127 canSelectPads.at(1) = ps2;
128 NamesSelect.at(1) = ps2->current->GetName();
129 PadInfo* ps3 = new PadInfo();
130 ps3->current = wfmCell;
131 ps3->opt = "hist lp";
132 canSelectPads.at(2) = ps3;
133 NamesSelect.at(2) = ps3->current->GetName();
134
135 name = fTitle + "_hModEn_scwall_nt";
136 hModEn_scwall_nt = new TH1F(name, "ScWall amp in cells", 200, 0, 200);
137 hModEn_scwall_nt->GetXaxis()->SetTitle("Cell id");
138 hModEn_scwall_nt->GetXaxis()->SetTitleColor(kOrange + 10);
139 hModEn_scwall_nt->GetYaxis()->SetTitle("dE/dx [Z^2]");
140 hModEn_scwall_nt->GetYaxis()->SetTitleColor(kOrange + 10);
141 hModEn_scwall_nt->SetOption("hist");
142 hModEn_scwall_nt->SetStats(0);
143
144 name = fTitle + "CanvasModEn";
145 canModEn = new TCanvas(name, name, 1, 1);
146 canModEn->Divide(1, 1);
147 canModEnPads.resize(1);
148 NamesModEn.resize(1);
149 PadInfo* pm = new PadInfo();
150 pm->current = hModEn_scwall_nt;
151 canModEnPads.at(0) = pm;
152 NamesModEn.at(0) = pm->current->GetName();
153}
154
155void BmnHistScWall::Register(THttpServer* serv)
156{
157 fServer = serv;
158 fServer->Register("/", this);
159 TString path = "/" + fTitle + "/";
160 fServer->Register(path, canAmps);
161 fServer->Register(path, canModEn);
162 fServer->Register(path, canSelect);
163 TString cmd = "/" + fName + "/->Reset()";
164 fServer->SetItemField(path.Data(), "_monitoring", "2000");
165 fServer->SetItemField(path.Data(), "_layout", "grid3x3");
166 TString cmdTitle = path + "Reset";
167 fServer->RegisterCommand(cmdTitle.Data(), cmd.Data(), "button;");
168 fServer->Restrict(cmdTitle, "visible=shift");
169 fServer->Restrict(cmdTitle, "allow=shift");
170 cmd = "/" + fName + "/->SetRefRun(%arg1%)";
171 cmdTitle = path + "SetRefRun";
172 fServer->RegisterCommand(cmdTitle.Data(), cmd.Data(), "button;");
173 cmdTitle = path + "ChangeSelection";
174 fServer->RegisterCommand(cmdTitle, TString("/") + fName.Data() + "/->SetSelection(%arg1%,%arg2%)", "button;");
175 fServer->Restrict(cmdTitle, "visible=shift");
176 fServer->Restrict(cmdTitle, "allow=shift");
177 fServer->Restrict(cmdTitle.Data(), "deny=guest");
178}
179
180void BmnHistScWall::SetDir(TFile* outFile = NULL, TTree* recoTree = NULL)
181{
182 frecoTree = recoTree;
183 fDir = NULL;
184 if (outFile != NULL)
185 fDir = outFile->mkdir(fTitle + "_hists");
186 h2d_grid->SetDirectory(fDir);
187 h2d_grid_center->SetDirectory(fDir);
188 h2d_profile->SetDirectory(fDir);
189 hCellE->SetDirectory(fDir);
190 hCellAmpl->SetDirectory(fDir);
191 wfmCell->SetDirectory(fDir);
192 h2d_cell_id->SetDirectory(fDir);
193 h2d_cell_id_center->SetDirectory(fDir);
194 hModEn_scwall_nt->SetDirectory(fDir);
195}
196
197void BmnHistScWall::SetSelection(Int_t Cell, Int_t Trigger)
198{
199 fSelectedCell = Cell;
200 fSelectedTrigger = Trigger;
201 TString command = "(1)";
202 TString digiInTree = "ScWallDigi";
203 if (fSelectedCell >= 0)
204 command = Form(" && %s.GetCellId() == %d", digiInTree.Data(), fSelectedCell);
205 TString triggerCondition = "";
206 if (fSelectedTrigger >= 0)
207 triggerCondition = Form(" && %s trigger bit == %d (bitBT=2, bitBC1=3, bitMBT=6, bitNiT=4, bitCCT1=5, "
208 "bitCCT2=8, bitCCT3=12, bitFHCAL=9)",
209 digiInTree.Data(), fSelectedTrigger);
210 TString titleSignal = Form("#splitline{Signal %s}{%s}", command.Data(), triggerCondition.Data());
211 TString titleAmpl = Form("#splitline{Ampl %s}{%s}", command.Data(), triggerCondition.Data());
212 TString titleWfm = Form("#splitline{Wfm %s}{%s}", command.Data(), triggerCondition.Data());
213 hCellE->SetTitle(titleSignal);
214 hCellAmpl->SetTitle(titleAmpl);
215 wfmCell->SetTitle(titleWfm);
216 hCellE->Reset();
217 hCellAmpl->Reset();
218 wfmCell->Reset();
219 if (frecoTree != NULL) {
220 TString direction = Form("%s.fAmpl>>%s", digiInTree.Data(), hCellE->GetName());
221 frecoTree->Draw(direction.Data(), command.Data(), "goff");
222 wfmCell->SetTitle(titleWfm);
223 }
224}
225
227{
228 BmnHist::DrawRef(canAmps, &canAmpsPads);
229 BmnHist::DrawRef(canModEn, &canModEnPads);
230 BmnHist::DrawRef(canSelect, &canSelectPads);
231 return;
232}
233
235{
236 BmnEventHeader* head = fDigiArrays->header;
237 TClonesArray* digits = fDigiArrays->scwall;
238 if (!digits)
239 return;
240
241 h2d_grid->Scale(fEventCounter);
242 h2d_grid_center->Scale(fEventCounter);
243 hModEn_scwall_nt->Scale(fEventCounter);
244
245 // Loop over digis
246 for (Int_t iDig = 0; iDig < digits->GetEntriesFast(); iDig++) {
247 BmnScWallDigi* digi = (BmnScWallDigi*)digits->At(iDig);
248 double signal = digi->GetSignal();
249 UInt_t cell_id = digi->GetCellId();
250 if (cell_id > kTOTAL_CELLS)
251 continue;
252 const auto& positionMap = fGeoHandler->GetPositionMap();
253 auto it = positionMap.find(digi->GetAddress());
254 if (it == positionMap.end())
255 continue;
256 float x_pos = it->second.first.X();
257 float y_pos = it->second.first.Y();
258
259 UInt_t TrigPattern = head->GetInputSignalsAR();
260 // auto bitBT = (TrigPattern >> 2) & 1; // BT
261 // auto bitBC1 = (TrigPattern >> 3) & 1; // BC1
262 // auto bitMBT = (TrigPattern >> 6) & 1; // MBT
263 // auto bitNiT = (TrigPattern >> 4) & 1; // NiT
264 // auto bitCCT1 = (TrigPattern >> 5) & 1; // CCT1
265 // auto bitCCT2 = (TrigPattern >> 8) & 1; // CCT2
266 // auto bitCCT3 = (TrigPattern >> 12) & 1; // CCT3
267 // auto bitFHCAL = (TrigPattern >> 9) & 1; // FHCAL
268
269 bool isSelected = ((Int_t)digi->GetCellId() == fSelectedCell);
270 if (isSelected) {
271 if ((TrigPattern >> fSelectedTrigger) & 1) {
272 hCellAmpl->Fill(digi->fAmpl);
273 hCellE->Fill(signal);
274 auto Wfm = digi->GetWfm();
275 std::vector<float> points(Wfm.size());
276 std::iota(std::begin(points), std::end(points), 0); // Fill with 0, 1, ..., wfm.back().
277 wfmCell->Reset();
278 wfmCell->GetXaxis()->SetRangeUser(0, Wfm.size());
279 for (UInt_t wfm_iter = 0; wfm_iter < Wfm.size(); wfm_iter++)
280 wfmCell->Fill(wfm_iter, Wfm.at(wfm_iter));
281 }
282 }
283
284 h2d_profile->Fill(digi->GetCellId(), signal);
285 hModEn_scwall_nt->Fill(cell_id, signal);
286 if (cell_id <= 40) // inner block of the wall
287 {
288 h2d_grid_center->Fill(x_pos, y_pos, signal);
289 int bin_x = h2d_cell_id_center->GetXaxis()->FindBin(x_pos);
290 int bin_y = h2d_cell_id_center->GetYaxis()->FindBin(y_pos);
291 int BC = h2d_cell_id_center->GetBinContent(bin_x, bin_y);
292 if (BC == 0)
293 h2d_cell_id_center->Fill(x_pos, y_pos, cell_id);
294 } else // outer block of the wall
295 {
296 h2d_grid->Fill(x_pos, y_pos, signal);
297 int bin_x = h2d_cell_id->GetXaxis()->FindBin(x_pos);
298 int bin_y = h2d_cell_id->GetYaxis()->FindBin(y_pos);
299 int BC = h2d_cell_id->GetBinContent(bin_x, bin_y);
300 if (BC == 0)
301 h2d_cell_id->Fill(x_pos, y_pos, cell_id);
302 }
303 }
304 fEventCounter++;
305 h2d_grid->Scale(1. / fEventCounter);
306 h2d_grid_center->Scale(1. / fEventCounter);
307 hModEn_scwall_nt->Scale(1. / fEventCounter);
308}
309
311{
312 TString FileName = Form("bmn_run%04d_hist.root", id);
313 printf("SetRefRun: %s\n", FileName.Data());
314 if (refRunName != FileName) {
315 refRunName = FileName;
316 refID = id;
317 BmnHist::LoadRefRun(refID, refPath + FileName, fTitle, canAmpsPads, NamesAmps);
318 BmnHist::LoadRefRun(refID, refPath + FileName, fTitle, canModEnPads, NamesModEn);
319 DrawBoth();
320 }
321 return kBMNSUCCESS;
322}
323
325{
326 for (auto pad : canAmpsPads) {
327 if (pad->ref)
328 delete pad->ref;
329 pad->ref = NULL;
330 }
331 for (auto pad : canModEnPads) {
332 if (pad->ref)
333 delete pad->ref;
334 pad->ref = NULL;
335 }
336 refID = 0;
337}
338
340{
341 printf("BmnHistScWall : Reset histos\n");
342 fEventCounter = 1;
343 h2d_grid->Reset();
344 h2d_grid_center->Reset();
345 h2d_profile->Reset();
346 h2d_cell_id->Reset();
347 h2d_cell_id_center->Reset();
348 wfmCell->Reset();
349 hCellE->Reset();
350 hCellAmpl->Reset();
351 hModEn_scwall_nt->Reset();
352}
353
355{
356 if (fGeoHandler)
357 delete fGeoHandler;
358 delete canAmps;
359 delete canModEn;
360 delete canSelect;
361 if (fDir != NULL)
362 return;
363 delete h2d_grid;
364 delete h2d_grid_center;
365 delete h2d_profile;
366 delete h2d_cell_id;
367 delete h2d_cell_id_center;
368 delete wfmCell;
369 delete hCellE;
370 delete hCellAmpl;
371 delete hModEn_scwall_nt;
372}
#define PAD_WIDTH
Definition BmnAdcQA.cxx:3
#define PAD_HEIGHT
Definition BmnAdcQA.cxx:4
BmnStatus
Definition BmnEnums.h:24
@ kBMNSUCCESS
Definition BmnEnums.h:25
BmnSetup
Definition BmnEnums.h:89
double GetSignal() const
uint32_t GetAddress() const
std::vector< float > GetWfm() const
Waveform.
UInt_t GetInputSignalsAR()
BmnStatus ReadGeometryFromFile(const std::string &path, bool getGlobalPosition=true)
const auto & GetPositionMap() const
virtual ~BmnHistScWall()
BmnStatus SetRefRun(Int_t id)
void SetGeometry(const std::string &path)
void FillFromDigi(DigiArrays *fDigiArrays)
void SetDir(TFile *outFile, TTree *recoTree)
void SetSelection(Int_t Cell, Int_t Trigger)
BmnHistScWall(TString title="ScWall", TString path="", Int_t periodID=8, BmnSetup setup=kBMNSETUP)
void Register(THttpServer *serv)
TTree * frecoTree
Definition BmnHist.h:88
Int_t refID
Definition BmnHist.h:92
TString refPath
Definition BmnHist.h:90
TDirectory * fDir
Definition BmnHist.h:89
static void DrawRef(unique_ptr< TCanvas > &canGemStrip, vector< PadInfo * > *canGemStripPads)
Definition BmnHist.cxx:15
TString refRunName
Definition BmnHist.h:91
static BmnStatus LoadRefRun(Int_t refID, TString FullName, TString fTitle, vector< PadInfo * > canPads, vector< TString > Names)
Definition BmnHist.cxx:100
THttpServer * fServer
Definition BmnHist.h:87
Class for experimental data at digi level.
uint32_t GetCellId() const
BmnEventHeader * header
Definition DigiArrays.h:146
TClonesArray * scwall
Definition DigiArrays.h:133
Storage for pad content and it's options.
Definition PadInfo.h:20
string opt
Definition PadInfo.h:88
vector< TH1 * > aux
Definition PadInfo.h:80
vector< TString > auxOpt
Definition PadInfo.h:81
TH1 * current
Definition PadInfo.h:78
#define ScWall_COLS
#define ScWall_ROWS