Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
// UserScript.C
//
// Helper macro to build additional histograms
void UserScript()
{
//
const UInt_t NTRIGS = 6;
const TString trig_names[NTRIGS]={"h1X","h1Y","h1Xh1y","h2X","h2Y","hTrig"};
TH1F* hScalTrig[NTRIGS];
Double_t trig_scal[NTRIGS];
Double_t trig_ave[NTRIGS]={0,0,0,0,0,0};
TH1F* hAveTrig;
hAveTrig=new TH1F("AveTrig","Ave Trig Rates ",NTRIGS,0,NTRIGS);
//
const UInt_t NBCMS = 3;
const TString bcm_names[NBCMS] = {"BCM1", "BCM2","Unser"};
TH1F* hScalBCM[NBCMS];
TH1F* hCurBCM[NBCMS];
TH1F* hAveCurBCM;
hAveCurBCM=new TH1F("AveCurBCM","Ave Current ",NBCMS,0,NBCMS);
TH1F* hAveRateBCM;
hAveRateBCM=new TH1F("AveRateBCM","Ave BCM Rate ",NBCMS,0,NBCMS);
Double_t bcm_scal[NBCMS];
Double_t bcm_cur[NBCMS];
Double_t bcm_ave_cur[NBCMS]={0.,0.,0.};
Double_t bcm_ave_rate[NBCMS]={0.,0.,0.};
Double_t bcm_offset[NBCMS]={250000,250000,393000};
Double_t bcm_slope[NBCMS]={4500*1.15,4500,4000};
//
const UInt_t NPLANES = 4;
const TString plane_names[NPLANES] = {"1x", "1y", "2x", "2y"};
const UInt_t nbars[NPLANES] = {16, 10, 16, 10};
const UInt_t nbars_low[NPLANES] = {1, 1, 1, 1};
TH1F* hScalHodNegEv[NPLANES][16];
TH1F* hScalHodPosEv[NPLANES][16];
TH1F* hScalHodNeg[NPLANES];
TH1F* hScalHodPos[NPLANES];
Double_t hod_scalneg[NPLANES][16];
Double_t hod_scalpos[NPLANES][16];
Double_t hod_scalneg_rate[NPLANES][16];
Double_t hod_scalpos_rate[NPLANES][16];
Double_t good_bcm=0;
Double_t good_bcm_limit=265000.;
//
TTree *T=(TTree*)gDirectory->Get("TSHS");
Int_t totev=T->GetEntries();
// totev=400;
//
TString i2dbarname;TString h2dttitle;TString h2dtname;TString list_name;
for(UInt_t ip = 0; ip < NTRIGS; ip++) {
h2dttitle= trig_names[ip]+"; Event Number ; Rate ";
h2dtname="uhScalTrig"+trig_names[ip];
hScalTrig[ip]= new TH1F(h2dtname,h2dttitle,totev,0,totev);
list_name ="HS"+trig_names[ip]+"r";
T->SetBranchAddress(list_name,&trig_scal[ip]);
}
//
for(UInt_t ip = 0; ip < NBCMS; ip++) {
h2dttitle= bcm_names[ip]+"; Event Number ; Rate ";
h2dtname="uhScal"+bcm_names[ip];
hScalBCM[ip]= new TH1F(h2dtname,h2dttitle,totev,0,totev);
h2dttitle= bcm_names[ip]+"; Event Number ; Current ";
h2dtname="uhCur"+bcm_names[ip];
hCurBCM[ip]= new TH1F(h2dtname,h2dttitle,totev,0,totev);
list_name ="HS"+bcm_names[ip]+"r";
T->SetBranchAddress(list_name,&bcm_scal[ip]);
}
//
for(UInt_t ip = 0; ip < NPLANES; ip++) {
h2dttitle= "Beam On,Neg"+plane_names[ip]+"; Scintillator Bar ; Ave Rate ";
h2dtname="uhScalHodNeg"+plane_names[ip];
hScalHodNeg[ip]= new TH1F(h2dtname,h2dttitle,nbars[ip],0.5,nbars[ip]+.5);
h2dttitle= "Beam on,Pos"+plane_names[ip]+"; Scintillator Bar ; Ave Rate ";
h2dtname="uhScalHodPos"+plane_names[ip];
hScalHodPos[ip]= new TH1F(h2dtname,h2dttitle,nbars[ip],0.5,nbars[ip]+.5);
for(UInt_t ibar = nbars_low[ip]-1; ibar < nbars[ip]; ibar++) {
i2dbarname = Form("%02d",ibar+1);
h2dttitle= "Neg Hod"+plane_names[ip]+i2dbarname+"; Event Number ; Rate ";
h2dtname="uhScalEvHodNeg"+plane_names[ip]+"Pad"+i2dbarname;
hScalHodNegEv[ip][ibar]= new TH1F(h2dtname,h2dttitle,totev,0,totev);
h2dttitle= "Pos Hod"+plane_names[ip]+i2dbarname+"; Event Number ; Rate ";
h2dtname="uhScalEvHodPos"+plane_names[ip]+"Pad"+i2dbarname;
hScalHodPosEv[ip][ibar]= new TH1F(h2dtname,h2dttitle,totev,0,totev);
hod_scalneg_rate[ip][ibar]=0;
hod_scalpos_rate[ip][ibar]=0;
}
}
//
//
for(UInt_t ip = 0; ip < NPLANES; ip++) {
for(UInt_t ibar = nbars_low[ip]-1; ibar < nbars[ip]; ibar++) {
i2dbarname = Form("%d",ibar+1);
list_name ="HShhod"+plane_names[ip]+i2dbarname+"Mr";
T->SetBranchAddress(list_name,&hod_scalneg[ip][ibar]);
list_name ="HShhod"+plane_names[ip]+i2dbarname+"Pr";
T->SetBranchAddress(list_name,&hod_scalpos[ip][ibar]);
}
}
// Loop over the events, filling the histograms
// cout << " looping over data " << endl;
for(UInt_t iev = 0; iev < totev; iev++) {
// cout << " iev = " << iev << endl;
// cout << " get entry = " << iev << endl;
T->GetEntry(iev);
//
for(UInt_t ip = 0; ip < NTRIGS; ip++) {
hScalTrig[ip]->SetBinContent(iev,trig_scal[ip]);
if (bcm_scal[0] > good_bcm_limit) trig_ave[ip]+=trig_scal[ip];
}
//
for(UInt_t ip = 0; ip < NBCMS; ip++) {
hScalBCM[ip]->SetBinContent(iev,bcm_scal[ip]);
bcm_cur[ip]=(bcm_scal[ip]-bcm_offset[ip])/bcm_slope[ip];
hCurBCM[ip]->SetBinContent(iev,bcm_cur[ip]);
if (bcm_scal[0] > good_bcm_limit) bcm_ave_cur[ip]+=bcm_cur[ip];
if (bcm_scal[0] > good_bcm_limit) bcm_ave_rate[ip]+=bcm_scal[ip];
}
if (bcm_scal[0] > good_bcm_limit) good_bcm++;
//
for(UInt_t ip = 0; ip < NPLANES; ip++) {
for(UInt_t ibar = nbars_low[ip]-1; ibar < nbars[ip]; ibar++) {
hScalHodNegEv[ip][ibar]->SetBinContent(iev,hod_scalneg[ip][ibar]);
hScalHodPosEv[ip][ibar]->SetBinContent(iev,hod_scalpos[ip][ibar]);
if (bcm_scal[0] > good_bcm_limit) {
hod_scalneg_rate[ip][ibar]+=hod_scalneg[ip][ibar];
hod_scalpos_rate[ip][ibar]+=hod_scalpos[ip][ibar];
}
// cout << ip+1 << " " << ibar+1 << " " << hod_scalneg[ip][ibar]<< " " << hod_scalpos[ip][ibar] << endl;
}
}
// cout << " finish event = " << iev << endl;
}
cout << " Done " << endl;
// calculate average when beam-on
if (good_bcm >0) {
cout << " tot ev = " << totev << " Good BCm events = " << good_bcm << endl;
for(UInt_t ip = 0; ip < NBCMS; ip++) {
hAveCurBCM->SetBinContent(ip,bcm_ave_cur[ip]/good_bcm);
hAveRateBCM->SetBinContent(ip,bcm_ave_rate[ip]/good_bcm);
}
for(UInt_t ip = 0; ip < NTRIGS; ip++) {
hAveTrig->SetBinContent(ip,trig_ave[ip]/good_bcm);
}
for(UInt_t ip = 0; ip < NPLANES; ip++) {
for(UInt_t ibar = nbars_low[ip]-1; ibar < nbars[ip]; ibar++) {
hScalHodNeg[ip]->SetBinContent(ibar+1,hod_scalneg_rate[ip][ibar]/good_bcm);
hScalHodPos[ip]->SetBinContent(ibar+1,hod_scalpos_rate[ip][ibar]/good_bcm);
}
}
}
//
return;
}
void plot_hms_scalers(TString histname,TString histname2) {
const UInt_t NTRIGS = 6;
const TString trig_names[NTRIGS]={"h1X","h1Y","h1Xh1y","h2X","h2Y","hTrig"};
const UInt_t NPLANES = 4;
const TString plane_names[NPLANES] = {"1x", "1y", "2x", "2y"};
const TString bar_names[16] = {"Pad01", "Pad02", "Pad03", "Pad04","Pad05", "Pad06", "Pad07", "Pad08","Pad09","Pad10","Pad11", "Pad12", "Pad13", "Pad14","Pad15", "Pad16"};
const UInt_t nbars[NPLANES] = {16, 10, 16, 10};
const UInt_t nbars_low[NPLANES] = {1, 1, 1, 1};
TH1F* h;
TH1F* hh;
TH1F* htrig;
TH1F* hhtrig;
TText* htext;
TText* hhtext;
Double_t aveh=0,avehh=0;
h = (TH1F*) gDirectory->Get(histname);
hh = (TH1F*) gDirectory->Get(histname2);
if(!h) {
UserScript();
h = (TH1F*) gDirectory->Get(histname);
if(!h) {
cout << "User histogram " << histname << " not found" << endl;
exit(1);
}
if (histname2!="none") {
hh = (TH1F*) gDirectory->Get(histname2);
if(!hh) {
cout << "User histogram " << histname2 << " not found" << endl;
exit(1);
}
}
}
if (histname.Contains("Trig")) {
htrig = (TH1F*) gDirectory->Get("AveTrig");
}
if (histname2.Contains("Trig")) {
hhtrig = (TH1F*) gDirectory->Get("AveTrig");
}
for (Int_t ip=0;ip<NTRIGS;ip++) {
if (histname.Contains(trig_names[ip])) aveh=htrig->GetBinContent(ip);
if (histname2.Contains(trig_names[ip])) avehh=hhtrig->GetBinContent(ip);
}
// cout << histname.Contains("adcpeak") << endl;
Double_t maxf=0,max1=0,max2=0;
h->SetStats(0);
h->GetXaxis()->SetTitleOffset(.6);
h->GetXaxis()->SetTitleSize(0.08);
h->GetYaxis()->SetTitleOffset(.6);
h->GetYaxis()->SetTitleSize(0.08);
h->SetMinimum(0);
max1=h->GetBinContent(h->GetMaximumBin());
if (histname.Contains("uhScalHod")) {
TH1F* h1hod;
TH1F* h2hod;
TString h1title;
TString h2title;
UInt_t ipl_f1=0;
UInt_t ipl_f2=0;
for(UInt_t ipl = 0; ipl < NPLANES; ipl++) {
if (histname.Contains(plane_names[ipl]))ipl_f1 = ipl;
if (histname2.Contains(plane_names[ipl])) ipl_f2=ipl;
}
if (histname.Contains("Neg")) h1title="uhScalHodNeg"+plane_names[ipl_f1];
if (histname.Contains("Pos")) h1title="uhScalHodPos"+plane_names[ipl_f1];
if (histname2.Contains("Neg")) h2title="uhScalHodNeg"+plane_names[ipl_f2];
if (histname2.Contains("Pos")) h2title="uhScalHodPos"+plane_names[ipl_f2];
h1hod = (TH1F*) gDirectory->Get(h1title);
h2hod = (TH1F*) gDirectory->Get(h2title);
for(UInt_t ibar = nbars_low[ipl_f1]-1; ibar < nbars[ipl_f1]; ibar++) {
if (h1hod) aveh+=h1hod->GetBinContent(ibar+1);
}
for(UInt_t ibar = nbars_low[ipl_f2]-1; ibar < nbars[ipl_f2]; ibar++) {
if (h2hod) avehh+=h2hod->GetBinContent(ibar+1);
}
}
if (histname.Contains("EvHod")) {
TH1F* h1hod;
TH1F* h2hod;
TString h1title;
TString h2title;
TString i2barname;
for(UInt_t ipl = 0; ipl < NPLANES; ipl++) {
for(UInt_t ibar = nbars_low[ipl]-1; ibar < nbars[ipl]; ibar++) {
if (histname.Contains(plane_names[ipl]) && histname.Contains(bar_names[ibar])) {
if (histname.Contains("Neg")) h1title="uhScalHodNeg"+plane_names[ipl];
if (histname.Contains("Pos")) h1title="uhScalHodPos"+plane_names[ipl];
h1hod = (TH1F*) gDirectory->Get(h1title);
if (h1hod) aveh=h1hod->GetBinContent(ibar+1);
}
if (histname2.Contains(plane_names[ipl]) && histname2.Contains(bar_names[ibar])) {
if (histname2.Contains("Neg")) h2title="uhScalHodNeg"+plane_names[ipl];
if (histname2.Contains("Pos")) h2title="uhScalHodPos"+plane_names[ipl];
h2hod = (TH1F*) gDirectory->Get(h2title);
if (h2hod) avehh=h2hod->GetBinContent(ibar+1);
}
}
}
}
if (histname.Contains("BCM") || histname.Contains("Unser")) {
TH1F* hbcm;
if (histname.Contains("Cur") ) hbcm = (TH1F*) gDirectory->Get("AveCurBCM");
if (histname.Contains("Scal") ) hbcm = (TH1F*) gDirectory->Get("AveRateBCM");
if (histname.Contains("BCM1")) aveh=hbcm->GetBinContent(0);
if (histname.Contains("BCM2")) aveh=hbcm->GetBinContent(1);
if (histname.Contains("Unser")) aveh=hbcm->GetBinContent(2);
if (histname2!="none") {
if (histname2.Contains("BCM1")) avehh=hbcm->GetBinContent(0);
if (histname2.Contains("BCM2")) avehh=hbcm->GetBinContent(1);
if (histname2.Contains("Unser")) avehh=hbcm->GetBinContent(2);
}
}
if (hh) max2=hh->GetBinContent(hh->GetMaximumBin());
maxf=max1*1.2;
if (hh && max2>max1) maxf=max2*1.2;
if (h && !histname.Contains("uhScalHod")) htext = new TText(2,maxf*.95,Form("%s Ave = %7.2f",h->GetTitle(),aveh));
if (hh && !histname.Contains("uhScalHod")) hhtext = new TText(2,maxf*.90,Form("%s Ave = %7.2f",hh->GetTitle(),avehh));
if (h && histname.Contains("uhScalHod")) htext = new TText(2,maxf*.95,Form("%s Integral = %7.2f",h->GetTitle(),aveh));
if (hh && histname.Contains("uhScalHod")) hhtext = new TText(2,maxf*.90,Form("%s Integral = %7.2f",hh->GetTitle(),avehh));
h->SetMaximum(maxf);
h->Draw("p");
h->SetMarkerStyle(7);
h->SetMarkerColor(1);
htext->Draw();
if (hh) {
hh->Draw("p same");
hh->SetMarkerColor(2);
hh->SetMarkerStyle(7);
hhtext->Draw();
hhtext->SetTextColor(2);
}
}