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