BmnRoot
Loading...
Searching...
No Matches
ScintWall_scan.cpp
Go to the documentation of this file.
1#include <iostream>
2#include <fstream>
3#include <vector>
4#include <TFile.h>
5#include <TNtuple.h>
6#include <TGraph.h>
7#include <TF1.h>
8#include <TTree.h>
9#include <TCanvas.h>
10#include <TH1F.h>
11#include "TCutG.h"
12#include <algorithm>
13#include <fstream>
14#include <iostream>
15#include <map>
16#include <numeric>
17#include <stdio.h>
18//#include "utils.h"
19#include "TString.h"
20#include "TH1D.h"
21#include "TMultiGraph.h"
22#include "TStyle.h"
23#include "TH2.h"
24
25void drawgrid() //draw borders between cells
26{
27 double xs = 15; // grid step along X
28 double ys = 15; // grid step along Y
29 double xmin, ymin, xmax, ymax;
30 gPad->GetRangeAxis(xmin, ymin, xmax, ymax);
31 auto aline = new TLine();
32 aline->SetLineStyle(3);
33 for (double yg = ymin + ys; yg < ymax; yg = yg + ys)
34 aline->PaintLine(xmin, yg, xmax, yg);
35 for (double xg = xmin + xs; xg < xmax; xg = xg + xs)
36 aline->PaintLine(xg, ymin, xg, ymax);
37}
38void drawgrid_center() //same for the central cells
39{
40 double xs = 7.5; // grid step along X
41 double ys = 7.5; // grid step along Y
42 double xmin, ymin, xmax, ymax;
43 gPad->GetRangeAxis(xmin, ymin, xmax, ymax);
44 auto aline = new TLine();
45 aline->SetLineStyle(3);
46 for (double yg = ymin + ys; yg < ymax; yg = yg + ys)
47 aline->PaintLine(xmin, yg, xmax, yg);
48 for (double xg = xmin + xs; xg < xmax; xg = xg + xs)
49 aline->PaintLine(xg, ymin, xg, ymax);
50}
51
52void scan() //main program
53{
54 //list of cells in blocks
55 int A_block[15] = {42, 43, 44,
56 59, 60, 61, 62,
57 77, 78, 79, 80,
58 95, 96, 97, 98};
59 int B_block[15] = {45, 46, 47, 48, 49,
60 63, 64, 65, 66, 67,
61 81, 82, 83, 84, 85};
62 int C_block[15] = {50, 51, 52, 53, 54,
63 68, 69, 70, 71, 72,
64 86, 87, 88, 89, 90};
65 int D_block[15] = {55, 56, 57,
66 73, 74, 75, 76,
67 91, 92, 93, 94,
68 104, 105, 106, 107};
69 int I_block[15] = {108, 109, 110, 111,
70 121, 122, 123, 124,
71 139, 140, 141, 142,
72 158, 159, 160};
73 int J_block[15] = {125, 126, 127, 128, 129,
74 143, 144, 145, 146, 147,
75 161, 162, 163, 164, 165};
76 int K_block[15] = {130, 131, 132, 133, 134,
77 148, 149, 150, 151, 152,
78 166, 167, 168, 169, 170};
79 int L_block[15] = {117, 118, 119, 120,
80 135, 136, 137, 138,
81 153, 154, 155, 156,
82 171, 172, 173};
83 int E_block[13] = {99, 100, 101,
84 1, 2, 3, 4, 5,
85 11, 12, 13, 14, 15};
86 int F_block[12] = {6, 7, 8, 9, 10,
87 16, 17, 18, 19, 20,
88 102, 103};
89 int G_block[13] = {112, 113, 114,
90 21, 22, 23, 24, 25,
91 31, 32, 33, 34, 35};
92 int H_block[12] = {26, 27, 28, 29, 30,
93 36, 37, 38, 39, 40,
94 115, 116};
95
96 TH2F *cell_v_signal = new TH2F("cell_v_signal", "cell_v_signal", 200, 0, 200, 200, 0, 2000);
97 TH2F *ScintWall = new TH2F("ScintWall", "ScintWall", 18, -135, 135, 8, -60, 60);
98 TH2F *ScintWall_CellID = new TH2F("ScintWall_CellID", "ScintWall_CellID", 18, -135, 135, 8, -60, 60);
99 TH2F *ScintWall_center = new TH2F("ScintWall_center", "ScintWall_center", 10, -45, 30, 4, -15, 15);
100 TH2F *ScintWall_center_CellID = new TH2F("ScintWall_center_CellID", "ScintWall_center_CellID", 10, -45, 30, 4, -15, 15);
101 TH1F *cell_v_signal1D = new TH1F("cell_v_signal1D", "cell_v_signal1D", 200, 0, 200);
102 TH1F *cells[200];
103 for (int i = 0; i < 200; i++)
104 cells[i] = new TH1F(TString::Format("Cell_%d", i), TString::Format("Cell_%d", i), 500, -2.0, 200);
105
106 TFile *_file0 = TFile::Open("/lhep/users/vvolkov/BMN/src1.root"); //insert .root file path and name here
107 TTree *tree = (TTree *)_file0->Get("bmndata");
108
109 TClonesArray *BmnScWallDigiArray = nullptr; //leave nullptr!!!
110 tree->SetBranchAddress("ScWallDigi", &BmnScWallDigiArray);
111 BmnScWallRaw2Digit *tempScWallMapper = new BmnScWallRaw2Digit();
112 tempScWallMapper->ParseConfig("SCWALL_map_dry_run_2022.txt"); //path to the scwall map
113
114 int counter = 0;
115 auto ThatVectorX = tempScWallMapper->GetUniqueXpositions();
116 auto ThatVectorY = tempScWallMapper->GetUniqueYpositions();
117 delete tempScWallMapper;
118 int n_events = tree->GetEntries();
119 cout << n_events << endl;
120 for (int ev = 0; ev < tree->GetEntries(); ev++)
121 {
122 ScintWall_CellID->Reset(); //for cell id number in pdf
123 ScintWall_center_CellID->Reset(); //for cell id number in pdf
124 counter = 0;
125 tree->GetEntry(ev);
126 for (int i = 0; i < BmnScWallDigiArray->GetEntriesFast(); i++) //cells iterations
127 {
128 BmnScWallDigi *ThisDigi = (BmnScWallDigi *)BmnScWallDigiArray->At(i);
129 float realXpos = ThatVectorX.at(ThisDigi->GetX());
130 float realYpos = ThatVectorY.at(ThisDigi->GetY());
131 float signal = ThisDigi->GetSignal(); //get what you need here (ZL, Amplitude etc., see the conv.root (input file) for methods or ask Nikolay. You can use fSignal instead GetSignal() for example)
132 float cell_id = ThisDigi->GetCellId(); //same
133 if (cell_id > 200) // we don't have scwall out of this range, so skip
134 continue;
135 counter++; // for future
136 //cout << ev << " cell id " << cell_id << " X " << realXpos / 10 << " Y " << realYpos / 10 << " Signal " << signal << endl; //control output
137
138 if (cell_id <= 40) //central block of the wall
139 {
140 //cout << ev << "CC cell id " << cell_id << " X " << realXpos / 10 << " Y " << realYpos / 10 << endl;
141 ScintWall_center->Fill(realXpos / 10, realYpos / 10, signal / n_events);
142 ScintWall_center_CellID->Fill(realXpos / 10, realYpos / 10, cell_id);
143 cell_v_signal->Fill(cell_id, signal);
144 cell_v_signal1D->Fill(cell_id, signal / n_events);
145 cells[(int)cell_id]->Fill(signal);
146 }
147 else //noncentral
148 {
149 //cout << ev << " cell id " << cell_id << " X " << realXpos / 10 << " Y " << realYpos / 10 << endl;
150 ScintWall->Fill(realXpos / 10, realYpos / 10, signal / n_events); //Ox: signal normilized to 1 event, be careful, as the actual number of events is different for different cells,
151 //so if you need exact values, you should obtain number of events for EVERY cell and then divide signal on that value with respect to each cell
152 ScintWall_CellID->Fill(realXpos / 10, realYpos / 10, cell_id); //for the cell id numbers on the histogram
153 cell_v_signal->Fill(cell_id, signal); //TH2F
154 cell_v_signal1D->Fill(cell_id, signal / n_events); //TH1F
155 cells[(int)cell_id]->Fill(signal); //spectrum
156 //if ((int)cell_id == 77) // control output of the cell you need
157 //cout << ev << " | " << cell_id << " int " << (int)cell_id << " s " << signal << endl;
158 }
159 }
160 }
161
167
168 gStyle->SetOptStat(0);
169 gStyle->SetPaintTextFormat("4.0f"); //how many numbers in output and how many after dot
170
171 TCanvas *c2 = new TCanvas();
172 ScintWall->SetBarOffset(-0.2);
173 ScintWall->Draw("colzTEXT L");
174 ScintWall_CellID->SetMarkerSize(1.3);
175 ScintWall_CellID->SetMarkerColor(kRed);
176 ScintWall_CellID->SetBarOffset(0.2);
177 ScintWall_CellID->Draw("TEXT SAME");
178 ScintWall->GetXaxis()->SetTitle("X [cm]");
179 ScintWall->GetYaxis()->SetTitle("Y [cm]");
180 auto grid = new TExec("grid", "drawgrid()"); //add borders
181 grid->Draw();
182 c2->Print("h1.pdf(", "pdf");
183
184 TCanvas *c3 = new TCanvas();
185 ScintWall_center->SetBarOffset(-0.2);
186 ScintWall_center->Draw("colzTEXT");
187 ScintWall_center_CellID->SetMarkerSize(1.5);
188 ScintWall_center_CellID->SetMarkerColor(kRed);
189 ScintWall_center_CellID->SetBarOffset(0.2);
190 ScintWall_center_CellID->Draw("TEXT SAME");
191 ScintWall_center->GetXaxis()->SetTitle("X [cm]");
192 ScintWall_center->GetYaxis()->SetTitle("Y [cm]");
193 auto grid_center = new TExec("grid_center", "drawgrid_center()");
194 grid_center->Draw();
195 c3->Print("h1.pdf", "pdf");
196
197 //draw spectra
198 TCanvas *cA = new TCanvas();
199 cA->DivideSquare(15);
200 for (int i = 1; i <= 15; i++)
201 {
202 cA->cd(i);
203 cells[A_block[i - 1]]->Draw();
204 cells[A_block[i - 1]]->GetXaxis()->SetTitle("signal");
205 cells[A_block[i - 1]]->GetYaxis()->SetTitle("counts");
206 }
207 cA->cd(); // c1 is the TCanvas
208 TPad *pad5 = new TPad("all", "all", 0, 0, 1, 1);
209 pad5->SetFillStyle(4000); // transparent
210 pad5->Draw();
211 pad5->cd();
212 TLatex *lat = new TLatex();
213 lat->DrawLatexNDC(.005, .96, "A");
214 cA->Print("h1.pdf", "pdf");
215
216 TCanvas *cB = new TCanvas();
217 cB->DivideSquare(15);
218 for (int i = 1; i <= 15; i++)
219 {
220 cB->cd(i);
221 cells[B_block[i - 1]]->Draw();
222 }
223 cB->cd(); // c1 is the TCanvas
224
225 lat->DrawLatexNDC(.005, .96, "B");
226 cB->Print("h1.pdf", "pdf");
227
228 TCanvas *cC = new TCanvas();
229 cC->DivideSquare(15);
230 for (int i = 1; i <= 15; i++)
231 {
232 cC->cd(i);
233 cells[C_block[i - 1]]->Draw();
234 }
235 cC->cd(); // c1 is the TCanvas
236
237 lat->DrawLatexNDC(.005, .96, "C");
238 cC->Print("h1.pdf", "pdf");
239
240 TCanvas *cD = new TCanvas();
241 cD->DivideSquare(15);
242 for (int i = 1; i <= 15; i++)
243 {
244 cD->cd(i);
245 cells[D_block[i - 1]]->Draw();
246 }
247 cD->cd(); // c1 is the TCanvas
248 lat->DrawLatexNDC(.005, .96, "D");
249 cD->Print("h1.pdf", "pdf");
250
251 TCanvas *cI = new TCanvas();
252 cI->DivideSquare(15);
253 for (int i = 1; i <= 15; i++)
254 {
255 cI->cd(i);
256 cells[I_block[i - 1]]->Draw();
257 }
258 cI->cd(); // c1 is the TCanvas
259 lat->DrawLatexNDC(.005, .96, "I");
260 cI->Print("h1.pdf", "pdf");
261
262 TCanvas *cJ = new TCanvas();
263 cJ->DivideSquare(15);
264 for (int i = 1; i <= 15; i++)
265 {
266 cJ->cd(i);
267 cells[J_block[i - 1]]->Draw();
268 }
269 cJ->cd(); // c1 is the TCanvas
270 lat->DrawLatexNDC(.005, .96, "J");
271 cJ->Print("h1.pdf", "pdf");
272
273 TCanvas *cK = new TCanvas();
274 cK->DivideSquare(15);
275 for (int i = 1; i <= 15; i++)
276 {
277 cK->cd(i);
278 cells[K_block[i - 1]]->Draw();
279 }
280 cK->cd(); // c1 is the TCanvas
281 lat->DrawLatexNDC(.005, .96, "K");
282 cK->Print("h1.pdf", "pdf");
283
284 TCanvas *cL = new TCanvas();
285 cL->DivideSquare(15);
286 for (int i = 1; i <= 15; i++)
287 {
288 cL->cd(i);
289 cells[L_block[i - 1]]->Draw();
290 }
291 cL->cd(); // c1 is the TCanvas
292 lat->DrawLatexNDC(.005, .96, "L");
293 cL->Print("h1.pdf", "pdf");
294
295 TCanvas *cE = new TCanvas();
296 cE->DivideSquare(13);
297 for (int i = 1; i <= 13; i++)
298 {
299 cE->cd(i);
300 cells[E_block[i - 1]]->Draw();
301 }
302 cE->cd(); // c1 is the TCanvas
303 lat->DrawLatexNDC(.005, .96, "E");
304 cE->Print("h1.pdf", "pdf");
305
306 TCanvas *cG = new TCanvas();
307 cG->DivideSquare(13);
308 for (int i = 1; i <= 13; i++)
309 {
310 cG->cd(i);
311 cells[G_block[i - 1]]->Draw();
312 }
313 cG->cd(); // c1 is the TCanvas
314 lat->DrawLatexNDC(.005, .96, "G");
315 cG->Print("h1.pdf", "pdf");
316
317 TCanvas *cF = new TCanvas();
318 cF->DivideSquare(12);
319 for (int i = 1; i <= 12; i++)
320 {
321 cF->cd(i);
322 cells[F_block[i - 1]]->Draw();
323 }
324 cF->cd(); // c1 is the TCanvas
325 lat->DrawLatexNDC(.005, .96, "F");
326 cF->Print("h1.pdf", "pdf");
327
328 TCanvas *cH = new TCanvas();
329 cH->DivideSquare(12);
330 for (int i = 1; i <= 12; i++)
331 {
332 cH->cd(i);
333 cells[H_block[i - 1]]->Draw();
334 }
335 cH->cd(); // c1 is the TCanvas
336 lat->DrawLatexNDC(.005, .96, "H");
337 cH->Print("h1.pdf", "pdf");
338
339 //draw TH2F
340 TCanvas *c4 = new TCanvas();
341 cell_v_signal->Draw("colz");
342 cell_v_signal->GetXaxis()->SetTitle("cell id");
343 cell_v_signal->GetYaxis()->SetTitle("signal");
344 c4->Print("h1.pdf", "pdf");
345
346 //draw TH1F
347 TCanvas *c5 = new TCanvas();
348 cell_v_signal1D->Draw("hist");
349 cell_v_signal1D->GetXaxis()->SetTitle("cell id");
350 cell_v_signal1D->GetYaxis()->SetTitle("signal/n_{events}");
351 //cell_v_signal1D->GetXaxis()->SetTitleSize(0.05);
352 //cell_v_signal1D->GetYaxis()->SetTitleSize(0.05);
353 c5->Print("h1.pdf)", "pdf");
354
355 //make pdf with map, if the map not needed, comment this line
356 gSystem->Exec("pdfunite h1.pdf map.pdf result.pdf");
357}
int i
Definition P4_F32vec4.h:22
double GetSignal() const
Class for experimental data at digi level.
uint32_t GetCellId() const
void ParseConfig(TString mappingFile)
void scan()
void drawgrid()
void drawgrid_center()