28 |
* in a pad |
* in a pad |
29 |
* |
* |
30 |
* for a large namber of events is not possible to have vectors, so all graphs have been converted in histograms |
* for a large namber of events is not possible to have vectors, so all graphs have been converted in histograms |
31 |
|
* |
32 |
|
* Version 2.0 - September 2006 |
33 |
|
* Fixed bugs: changed the number of bin in the "rate" histograms and the size of the string vector trcss |
34 |
*******/ |
*******/ |
35 |
|
|
36 |
|
|
48 |
#include "TGraph.h" |
#include "TGraph.h" |
49 |
#include "TH1F.h" |
#include "TH1F.h" |
50 |
#include "TF1.h" |
#include "TF1.h" |
51 |
|
#include "TH2F.h" |
52 |
|
#include "TF2.h" |
53 |
#include "TGaxis.h" |
#include "TGaxis.h" |
54 |
#include "TString.h" |
#include "TString.h" |
55 |
#include "TPaveText.h" |
#include "TPaveText.h" |
64 |
using namespace std; |
using namespace std; |
65 |
|
|
66 |
void S4_QL(TString base, TString outDir, TString format, ULong_t DeltaT){ //DeltaT in minute |
void S4_QL(TString base, TString outDir, TString format, ULong_t DeltaT){ //DeltaT in minute |
67 |
|
|
68 |
//------ Variables initialization ---------/ |
//------ Variables initialization ---------/ |
69 |
Int_t tmpSize; |
Int_t tmpSize; |
70 |
ULong_t mintime, maxtime; |
ULong_t mintime, maxtime; |
75 |
TString filename = ((TObjString*)base.Tokenize('/')->Last())->GetString(); |
TString filename = ((TObjString*)base.Tokenize('/')->Last())->GetString(); |
76 |
filename = ((TObjString*)filename.Tokenize('.')->First())->GetString(); |
filename = ((TObjString*)filename.Tokenize('.')->First())->GetString(); |
77 |
char *trc; |
char *trc; |
78 |
TString trcs; |
TString trcs,ciao; |
79 |
TString str; |
TString str; |
80 |
TString trcsstot[31]; |
TString trcsstot[31]; |
81 |
TString trcsstot2; |
TString trcsstot2; |
82 |
TString trcss[100]=""; |
|
83 |
TString trgconf[31]={"TOF1","TOF2","TOF3","TOF4","TOF5","TOF6","TOF7","S4","CALO","CALO-S4","TOF1-S4","TOF2-S4","TOF3-S4","TOF4-S4","TOF5-S4","TOF6-S4","TOF7-S4","TOF1-CALO","TOF2-CALO","TOF3-CALO","TOF4-CALO","TOF5-CALO","TOF6-CALO","TOF7-CALO","TOF1-CALO-S4","TOF2-CALO-S4","TOF3-CALO-S4","TOF4-CALO-S4","TOF5-CALO-S4","TOF6-CALO-S4","TOF7-CALO-S4",}; |
TString trgconf[31]={"TOF1","TOF2","TOF3","TOF4","TOF5","TOF6","TOF7","S4","CALO","CALO-S4","TOF1-S4","TOF2-S4","TOF3-S4","TOF4-S4","TOF5-S4","TOF6-S4","TOF7-S4","TOF1-CALO","TOF2-CALO","TOF3-CALO","TOF4-CALO","TOF5-CALO","TOF6-CALO","TOF7-CALO","TOF1-CALO-S4","TOF2-CALO-S4","TOF3-CALO-S4","TOF4-CALO-S4","TOF5-CALO-S4","TOF6-CALO-S4","TOF7-CALO-S4",}; |
84 |
stringstream oss, oss1, oss2, oss3, s4soglia, buffer, conftrig, noentries; |
stringstream oss, oss1, oss2, oss3, s4soglia, buffer, conftrig, noentries; |
85 |
ULong_t lastime, firstime; |
ULong_t lastime, firstime,obmin,obmax,obt; |
86 |
Int_t vardumpentries = 0; |
Int_t vardumpentries = 0; |
87 |
|
Int_t channels = 4096; |
88 |
char S4_TRH[10]; |
char S4_TRH[10]; |
89 |
char S4_TRH2[10]; |
char S4_TRH2[10]; |
90 |
Int_t trigconf = 0; |
Int_t trigconf = 0; |
91 |
Long64_t nevents; |
Long64_t nevents; |
92 |
string title; |
string title; |
93 |
double obmin=0.; |
|
|
double obmax=0.; |
|
|
double obt; |
|
94 |
double s4rate; |
double s4rate; |
|
int nbin=0; |
|
95 |
//------to open headerfile, s4file, Trigfile and vardumpfile---------------------------/ |
//------to open headerfile, s4file, Trigfile and vardumpfile---------------------------/ |
96 |
TFile *file =new TFile(base.Data()) ; |
TFile *file =new TFile(base.Data()) ; |
97 |
if (!file){ |
if (!file){ |
101 |
|
|
102 |
TTree *VarDumpTr = (TTree*)file->Get("VarDump"); |
TTree *VarDumpTr = (TTree*)file->Get("VarDump"); |
103 |
TTree *PhysicsTr = (TTree*)file->Get("Physics"); |
TTree *PhysicsTr = (TTree*)file->Get("Physics"); |
104 |
|
|
105 |
TBranch *S4Br = PhysicsTr->GetBranch("S4"); |
TBranch *S4Br = PhysicsTr->GetBranch("S4"); |
106 |
TBranch *TriggerBr = PhysicsTr->GetBranch("Trigger"); |
TBranch *TriggerBr = PhysicsTr->GetBranch("Trigger"); |
107 |
TBranch *headBr = PhysicsTr->GetBranch("Header"); |
TBranch *headBr = PhysicsTr->GetBranch("Header"); |
108 |
TBranch *VarDumpBr = VarDumpTr->GetBranch("VarDump"); |
TBranch *VarDumpBr = VarDumpTr->GetBranch("VarDump"); |
109 |
TBranch *headVarDumpBr = VarDumpTr->GetBranch("Header"); |
TBranch *headVarDumpBr = VarDumpTr->GetBranch("Header"); |
110 |
|
|
111 |
pamela::S4::S4Event *s4e = 0; |
pamela::S4::S4Event *s4e = 0; |
112 |
pamela::EventHeader *eh = 0; |
pamela::EventHeader *eh = 0; |
113 |
pamela::PscuHeader *ph = 0; |
pamela::PscuHeader *ph = 0; |
120 |
PhysicsTr->SetBranchAddress("Trigger", &trige); |
PhysicsTr->SetBranchAddress("Trigger", &trige); |
121 |
VarDumpTr->SetBranchAddress("VarDump", &vde); |
VarDumpTr->SetBranchAddress("VarDump", &vde); |
122 |
|
|
123 |
nevents = headBr->GetEntries(); |
nevents = S4Br->GetEntries(); |
|
const Int_t sizetot = nevents; |
|
124 |
|
|
125 |
//----------- If nevents < = 0 ---------------------------------/ |
//----------- If nevents < = 0 ---------------------------------/ |
126 |
if (nevents<=0) { |
if (nevents<=0) { |
127 |
printf("nevents = %i \n", nevents); |
printf("nevents = %i \n", nevents); |
128 |
printf(" \n"); |
printf(" \n"); |
129 |
|
|
130 |
TCanvas *canvas4 = new TCanvas("No entries", "No entries ", 400, 200); |
TCanvas *canvas4 = new TCanvas("No entries", "No entries ", 400, 200); |
131 |
canvas4->SetFillColor(10); |
canvas4->SetFillColor(10); |
132 |
canvas4->cd(); |
canvas4->cd(); |
141 |
noentries.str(""); |
noentries.str(""); |
142 |
noentries<< "No entries for this files"; |
noentries<< "No entries for this files"; |
143 |
l->DrawLatex(0.05, 0.5, noentries.str().c_str()); |
l->DrawLatex(0.05, 0.5, noentries.str().c_str()); |
144 |
|
|
145 |
if (outDir == "./") { |
if (outDir == "./") { |
146 |
oss.str(""); |
oss.str(""); |
147 |
oss << filename.Data() << "_S4_QL." << format.Data(); |
oss << filename.Data() << "_S4_QL." << format.Data(); |
149 |
oss.str(""); |
oss.str(""); |
150 |
oss << outDir.Data() << filename.Data() << "_S4_QL." << format.Data(); |
oss << outDir.Data() << filename.Data() << "_S4_QL." << format.Data(); |
151 |
} |
} |
152 |
|
|
153 |
canvas4->Update(); |
canvas4->Update(); |
154 |
canvas4->SaveAs(oss.str().c_str()); |
canvas4->SaveAs(oss.str().c_str()); |
155 |
|
|
156 |
return; |
return; |
157 |
} |
} |
158 |
|
const Int_t ev = nevents; |
159 |
for (Int_t i = 0; i < nevents; i++){ |
TString trcss[ev]; |
160 |
headBr->GetEntry(i); |
//-------to set trigger configuration---------------------------------// |
161 |
S4Br->GetEntry(i); |
for (Int_t ll = 0; ll < nevents; ll++){ |
162 |
TriggerBr->GetEntry(i); |
TriggerBr->GetEntry(ll); |
|
if (s4e->unpackError == 1 || s4e->S4_DATA==0) continue; |
|
|
//-------to set max adc value------------------------------------------// |
|
|
if (i==0){ |
|
|
adcmax=s4e->S4_DATA; |
|
|
} |
|
|
//-------to set trigger configuration---------------------------------// |
|
|
if ((s4e->S4_DATA)> adcmax) adcmax=(s4e->S4_DATA); |
|
163 |
trigconf = trige->trigconf; |
trigconf = trige->trigconf; |
164 |
trc = 0; |
trc = 0; |
165 |
if ( trigconf & (1<<0) ) trc = "TOF1"; |
if ( trigconf & (1<<0) ) trc = "TOF1"; |
174 |
if ( trigconf & (1<<3) ) { |
if ( trigconf & (1<<3) ) { |
175 |
if (trc==0) trc= "TOF4"; |
if (trc==0) trc= "TOF4"; |
176 |
else trc = Form("%s-TOF4",trc); |
else trc = Form("%s-TOF4",trc); |
177 |
} |
} |
178 |
if ( trigconf & (1<<4) ) { |
if ( trigconf & (1<<4) ) { |
179 |
if (trc==0) trc= "TOF5"; |
if (trc==0) trc= "TOF5"; |
180 |
else trc = Form("%s-TOF5",trc); |
else trc = Form("%s-TOF5",trc); |
181 |
} |
} |
182 |
if ( trigconf & (1<<5) ) { |
if ( trigconf & (1<<5) ) { |
183 |
if (trc==0) trc= "TOF6"; |
if (trc==0) trc= "TOF6"; |
184 |
else trc = Form("%s-TOF6",trc); |
else trc = Form("%s-TOF6",trc); |
185 |
} |
} |
186 |
if ( trigconf & (1<<6) ) { |
if ( trigconf & (1<<6) ) { |
187 |
if (trc==0) trc= "TOF7"; |
if (trc==0) trc= "TOF7"; |
188 |
else trc = Form("%s-TOF7",trc); |
else trc = Form("%s-TOF7",trc); |
191 |
if (trc==0) trc= "S4"; |
if (trc==0) trc= "S4"; |
192 |
else trc = Form("%s-S4",trc); |
else trc = Form("%s-S4",trc); |
193 |
} |
} |
194 |
if ( trigconf & (1<<8) ) { |
if ( trigconf & (1<<8) ) { |
195 |
if (trc==0) trc= "CALO"; |
if (trc==0) trc= "CALO"; |
196 |
else trc = Form("%s-CALO",trc); |
else trc = Form("%s-CALO",trc); |
197 |
} |
} |
198 |
if ( trigconf & (1<<9) ) { |
if ( trigconf & (1<<9) ) { |
199 |
if (trc==0) trc= "CALIB_ON"; |
if (trc==0) trc= "CALIB_ON"; |
200 |
else trc = Form("%s-CALIB_ON",trc); |
else trc = Form("%s-CALIB_ON",trc); |
201 |
} |
} |
202 |
trcs = ""; |
trcs = ""; |
203 |
trcs = trc; |
trcs = trc; |
204 |
if (i==0){ |
if (ll==0){ |
205 |
trcss[0]=trcs; |
trcss[0]=trcs; |
206 |
j=j+1; |
j=j+1; |
207 |
} |
} |
208 |
if (trcs!=trcss[j-1] && i>0){ |
if (trcs!=trcss[j-1] && ll>0){ |
209 |
trcss[j]=trcs; |
trcss[j]=trcs; |
210 |
j=j+1; |
j=j+1; |
211 |
} |
} |
212 |
|
//cout<<i<<"\n"; |
213 |
|
//cout<<nevents<<"\n\n"; |
214 |
} |
} |
215 |
|
//--------------------------// |
216 |
for(Int_t k=0; k<31; k++){ |
for(Int_t k=0; k<31; k++){ |
217 |
for(Int_t p=0; p<j ; p++){ |
for(Int_t p=0; p<j ; p++){ |
218 |
if(trgconf[k]==trcss[p]){ |
if(trgconf[k]==trcss[p]){ |
224 |
if(trcsstot[k]!= "") |
if(trcsstot[k]!= "") |
225 |
trcsstot2=trcsstot2+"/"+ trcsstot[k]; |
trcsstot2=trcsstot2+"/"+ trcsstot[k]; |
226 |
} |
} |
227 |
|
|
228 |
//---------to search S4 threshold and convert it into char (hexadecimal value)--------// |
//---------to search S4 threshold and convert it into char (hexadecimal value)--------// |
229 |
vardumpentries = VarDumpBr->GetEntries(); |
vardumpentries = VarDumpBr->GetEntries(); |
230 |
if(vardumpentries==0){ |
if(vardumpentries==0){ |
249 |
} |
} |
250 |
sprintf(S4_TRH, "%d" , S4_TRHmip); |
sprintf(S4_TRH, "%d" , S4_TRHmip); |
251 |
} |
} |
252 |
} |
} |
253 |
|
|
254 |
//********************** First Histogram ************************************// |
//********************** First Histogram ************************************// |
255 |
TH1F *h1 = new TH1F("All events", "S4 distribution for file: "+filename, adcmax, 10, adcmax+(adcmax/10)); |
TH1F *h1 = new TH1F("All events", "S4 distribution for file: "+filename, channels, 1, channels); |
256 |
TH1F *h2 = new TH1F("S4 Triggered events", "S4 distribution for file: "+filename, adcmax, 10, adcmax+(adcmax/10)); |
TH1F *h2 = new TH1F("S4 Triggered events", "S4 distribution for file: "+filename, channels, 1, channels); |
257 |
|
|
258 |
//********************** Second Histogram ************************************// |
//********************** Second Histogram ************************************// |
259 |
headBr->GetEntry(0); |
headBr->GetEntry(0); |
260 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
261 |
firstime = ph->GetOrbitalTime(); |
firstime = ph->GetOrbitalTime(); |
262 |
|
|
263 |
for (Int_t i = 0; i < nevents; i++){ |
headBr->GetEntry(nevents); |
264 |
headBr->GetEntry(i); |
ph = eh->GetPscuHeader(); |
265 |
|
lastime = ph->GetOrbitalTime(); |
266 |
|
headBr->GetEntry(nevents-100); |
267 |
|
ph = eh->GetPscuHeader(); |
268 |
|
obt=ph->GetOrbitalTime(); |
269 |
|
if(lastime-obt> 100000)nevents=nevents-100; |
270 |
|
int iii=0,MaxR=0; |
271 |
|
while(iii < nevents){ |
272 |
|
headBr->GetEntry(iii); |
273 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
274 |
if((ph->GetOrbitalTime()) <= firstime) firstime=ph->GetOrbitalTime(); |
obt=ph->GetOrbitalTime(); |
275 |
if((ph->GetOrbitalTime()) >= lastime) lastime=ph->GetOrbitalTime(); |
if(obt<=firstime) firstime=ph->GetOrbitalTime(); |
276 |
|
if(obt>=lastime) lastime=ph->GetOrbitalTime(); |
277 |
|
TriggerBr->GetEntry(iii); |
278 |
|
if(trige->s4calcount[0]>MaxR)MaxR=trige->s4calcount[0]; |
279 |
|
iii++; |
280 |
} |
} |
281 |
|
MaxR=2*(1.05*MaxR/2); |
282 |
|
|
283 |
obmin=firstime; |
obmin=firstime; |
284 |
obmax=lastime; |
obmax=lastime; |
285 |
const ULong_t nint=(((lastime-firstime)/(DeltaT*60000))); |
const ULong_t nint=(((lastime-firstime)/(DeltaT*60000))); |
291 |
TH1F *S4time = new TH1F("Mean signal from S4-triggered events", filename+": Mean signal from S4 (only s4 triggered events)", size, obmin, obmax); |
TH1F *S4time = new TH1F("Mean signal from S4-triggered events", filename+": Mean signal from S4 (only s4 triggered events)", size, obmin, obmax); |
292 |
|
|
293 |
//********************** Third Histogram ************************************// |
//********************** Third Histogram ************************************// |
|
nbin=sizetot; |
|
294 |
title=""; |
title=""; |
295 |
title=filename+": S4 rate from Trigger Packet"; |
title=filename+": S4 rate from Trigger Packet"; |
296 |
|
|
297 |
const ULong_t nint3=(lastime-firstime); |
const ULong_t nint2=(lastime-firstime)/10000; |
298 |
const Int_t size3 = (Int_t)((nint3)/100); |
const Int_t size2 = (Int_t)((nint2+1)); // one bin every 10 second |
299 |
|
const ULong_t nint3=(lastime-firstime)/1000; |
300 |
TH1F *rate= new TH1F(title.c_str(), title.c_str(), nint3, obmin, obmax); |
const Int_t size3 = (Int_t)((nint3+1)); // one bin every 1 second |
301 |
TH1F *rateline= new TH1F(filename+". S4 rate from Trigger Packet: mean value over 100 events", filename+". S4 rate from Trigger Packet: mean value over 100 events", size3, obmin, obmax); |
const Int_t Rbin = MaxR/2; |
302 |
|
TH2I *rate= new TH2I(title.c_str(), title.c_str(), size2,obmin,obmax,Rbin,0,MaxR); |
303 |
|
TH2I *rateline= new TH2I(filename+". S4 rate from Trigger Packet: mean value over 100 events", filename+". S4 rate from Trigger Packet: mean value over 100 events",size3,obmin,obmax,Rbin,0,MaxR); |
304 |
|
|
305 |
//------------------------------------------------------------------------------------------------------------------ |
//------------------------------------------------------------------------------------------------------------------ |
306 |
//------- fill histograms ---------// |
//------- fill histograms ---------// |
310 |
headBr->GetEntry(i); |
headBr->GetEntry(i); |
311 |
S4Br->GetEntry(i); |
S4Br->GetEntry(i); |
312 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
|
obt = ph->GetOrbitalTime(); |
|
313 |
if (s4e->unpackError == 1 && (s4e->S4_DATA)==0) continue; |
if (s4e->unpackError == 1 && (s4e->S4_DATA)==0) continue; |
314 |
s4rate= trige->s4calcount[0]; |
obt=ph->GetOrbitalTime(); |
315 |
rate->Fill(obt, s4rate); |
rate->Fill(obt,trige->s4calcount[0]); |
316 |
h1->Fill(s4e->S4_DATA); |
h1->Fill(s4e->S4_DATA); |
317 |
Allev->Fill(obt,s4e->S4_DATA); |
Allev->Fill(obt,s4e->S4_DATA); |
318 |
Alltime->Fill(obt); |
Alltime->Fill(obt); |
319 |
if ((trige->patterntrig[0] == 0) && (trige->patterntrig[1] != 0) &&(trige->patterntrig[2] == 0) && (trige->patterntrig[3] == 0) && (trige->patterntrig[4] == 0) && (trige->patterntrig[5] == 0)){ |
if ((trige->patterntrig[0] == 0)&&(trige->patterntrig[1] != 0)&&(trige->patterntrig[2] == 0)&&(trige->patterntrig[3] == 0)&&(trige->patterntrig[4] == 0)&&(trige->patterntrig[5] == 0)){ |
320 |
h2->Fill(s4e->S4_DATA); |
h2->Fill(s4e->S4_DATA); |
321 |
S4ev->Fill(obt,s4e->S4_DATA); |
S4ev->Fill(obt,s4e->S4_DATA); |
322 |
S4time->Fill(obt); |
S4time->Fill(obt); |
324 |
} |
} |
325 |
} |
} |
326 |
Int_t kk=0; |
Int_t kk=0; |
327 |
|
ULong_t Aobt=0; |
328 |
while (kk < nevents){ |
while (kk < nevents){ |
329 |
obt=0; |
obt=0; |
330 |
s4rate=0; |
s4rate=0; |
331 |
|
Aobt=0; |
332 |
for(Int_t jj=kk; jj< (kk+100); jj++){ |
for(Int_t jj=kk; jj< (kk+100); jj++){ |
333 |
TriggerBr->GetEntry(jj); |
TriggerBr->GetEntry(jj); |
334 |
headBr->GetEntry(jj); |
headBr->GetEntry(jj); |
335 |
obt = obt+(ph->GetOrbitalTime()); |
obt=ph->GetOrbitalTime(); |
336 |
s4rate= s4rate+(trige->s4calcount[0]); |
s4rate= s4rate+(trige->s4calcount[0]); |
337 |
|
Aobt=Aobt-obmin+obt; |
338 |
|
//*(trige->s4calcount[0])/1000; |
339 |
} |
} |
340 |
rateline->Fill((obt/100),(s4rate/100)); |
Aobt=Aobt/100; |
341 |
|
Aobt=Aobt+obmin; |
342 |
|
rateline->Fill(Aobt,s4rate/100); |
343 |
|
//rateline->Fill(ph->GetOrbitalTime(),(s4rate/100)); |
344 |
kk=kk+100; |
kk=kk+100; |
345 |
} |
} |
346 |
|
|
482 |
Allev->GetXaxis()->CenterTitle(); |
Allev->GetXaxis()->CenterTitle(); |
483 |
Allev->GetYaxis()->SetTitle("Mean signal ( ADC )"); |
Allev->GetYaxis()->SetTitle("Mean signal ( ADC )"); |
484 |
Allev->GetYaxis()->CenterTitle(); |
Allev->GetYaxis()->CenterTitle(); |
485 |
Allev->SetMinimum(20); |
//Allev->SetMinimum(20); |
486 |
Allev->Divide(Alltime); |
Allev->Divide(Alltime); |
487 |
Allev->Draw("p"); |
Allev->Draw("p"); |
488 |
pad3->Draw(); |
pad3->Draw(); |
543 |
rate->GetXaxis()->CenterTitle(); |
rate->GetXaxis()->CenterTitle(); |
544 |
rate->GetYaxis()->SetTitle("S4 rate (Hz)"); |
rate->GetYaxis()->SetTitle("S4 rate (Hz)"); |
545 |
rate->GetYaxis()->CenterTitle(); |
rate->GetYaxis()->CenterTitle(); |
546 |
if(rate->GetMaximum() > 1000) gPad->SetLogy(); |
if(MaxR>500) gPad->SetLogy(); |
547 |
rate->Draw("9p"); |
rate->Draw("9p"); |
548 |
|
|
549 |
canvas3->cd(2); |
canvas3->cd(2); |
556 |
rateline->GetYaxis()->SetTitle("S4 rate (Hz)"); |
rateline->GetYaxis()->SetTitle("S4 rate (Hz)"); |
557 |
rateline->GetYaxis()->CenterTitle(); |
rateline->GetYaxis()->CenterTitle(); |
558 |
rateline->SetMaximum(rate->GetMaximum()); |
rateline->SetMaximum(rate->GetMaximum()); |
559 |
if(rateline->GetMaximum() > 1000) gPad->SetLogy(); |
if(MaxR>500) gPad->SetLogy(); |
560 |
rateline->Draw("9p"); |
rateline->Draw("9p"); |
561 |
|
|
562 |
|
|
640 |
S4_QL(argv[1], outDir, format, DeltaT); |
S4_QL(argv[1], outDir, format, DeltaT); |
641 |
|
|
642 |
} |
} |
|
|
|