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; |
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; |
94 |
double obmax=0.; |
double obmax=0.; |
95 |
double obt; |
double obt; |
96 |
double s4rate; |
double s4rate; |
|
int nbin=0; |
|
97 |
//------to open headerfile, s4file, Trigfile and vardumpfile---------------------------/ |
//------to open headerfile, s4file, Trigfile and vardumpfile---------------------------/ |
98 |
TFile *file =new TFile(base.Data()) ; |
TFile *file =new TFile(base.Data()) ; |
99 |
if (!file){ |
if (!file){ |
103 |
|
|
104 |
TTree *VarDumpTr = (TTree*)file->Get("VarDump"); |
TTree *VarDumpTr = (TTree*)file->Get("VarDump"); |
105 |
TTree *PhysicsTr = (TTree*)file->Get("Physics"); |
TTree *PhysicsTr = (TTree*)file->Get("Physics"); |
106 |
|
|
107 |
TBranch *S4Br = PhysicsTr->GetBranch("S4"); |
TBranch *S4Br = PhysicsTr->GetBranch("S4"); |
108 |
TBranch *TriggerBr = PhysicsTr->GetBranch("Trigger"); |
TBranch *TriggerBr = PhysicsTr->GetBranch("Trigger"); |
109 |
TBranch *headBr = PhysicsTr->GetBranch("Header"); |
TBranch *headBr = PhysicsTr->GetBranch("Header"); |
110 |
TBranch *VarDumpBr = VarDumpTr->GetBranch("VarDump"); |
TBranch *VarDumpBr = VarDumpTr->GetBranch("VarDump"); |
111 |
TBranch *headVarDumpBr = VarDumpTr->GetBranch("Header"); |
TBranch *headVarDumpBr = VarDumpTr->GetBranch("Header"); |
112 |
|
|
113 |
pamela::S4::S4Event *s4e = 0; |
pamela::S4::S4Event *s4e = 0; |
114 |
pamela::EventHeader *eh = 0; |
pamela::EventHeader *eh = 0; |
115 |
pamela::PscuHeader *ph = 0; |
pamela::PscuHeader *ph = 0; |
122 |
PhysicsTr->SetBranchAddress("Trigger", &trige); |
PhysicsTr->SetBranchAddress("Trigger", &trige); |
123 |
VarDumpTr->SetBranchAddress("VarDump", &vde); |
VarDumpTr->SetBranchAddress("VarDump", &vde); |
124 |
|
|
125 |
nevents = headBr->GetEntries(); |
nevents = S4Br->GetEntries(); |
|
const Int_t sizetot = nevents; |
|
126 |
|
|
127 |
//----------- If nevents < = 0 ---------------------------------/ |
//----------- If nevents < = 0 ---------------------------------/ |
128 |
if (nevents<=0) { |
if (nevents<=0) { |
129 |
printf("nevents = %i \n", nevents); |
printf("nevents = %i \n", nevents); |
130 |
printf(" \n"); |
printf(" \n"); |
131 |
|
|
132 |
TCanvas *canvas4 = new TCanvas("No entries", "No entries ", 400, 200); |
TCanvas *canvas4 = new TCanvas("No entries", "No entries ", 400, 200); |
133 |
canvas4->SetFillColor(10); |
canvas4->SetFillColor(10); |
134 |
canvas4->cd(); |
canvas4->cd(); |
143 |
noentries.str(""); |
noentries.str(""); |
144 |
noentries<< "No entries for this files"; |
noentries<< "No entries for this files"; |
145 |
l->DrawLatex(0.05, 0.5, noentries.str().c_str()); |
l->DrawLatex(0.05, 0.5, noentries.str().c_str()); |
146 |
|
|
147 |
if (outDir == "./") { |
if (outDir == "./") { |
148 |
oss.str(""); |
oss.str(""); |
149 |
oss << filename.Data() << "_S4_QL." << format.Data(); |
oss << filename.Data() << "_S4_QL." << format.Data(); |
151 |
oss.str(""); |
oss.str(""); |
152 |
oss << outDir.Data() << filename.Data() << "_S4_QL." << format.Data(); |
oss << outDir.Data() << filename.Data() << "_S4_QL." << format.Data(); |
153 |
} |
} |
154 |
|
|
155 |
canvas4->Update(); |
canvas4->Update(); |
156 |
canvas4->SaveAs(oss.str().c_str()); |
canvas4->SaveAs(oss.str().c_str()); |
157 |
|
|
158 |
return; |
return; |
159 |
} |
} |
160 |
|
const Int_t ev = nevents; |
161 |
for (Int_t i = 0; i < nevents; i++){ |
TString trcss[ev]; |
162 |
headBr->GetEntry(i); |
//-------to set trigger configuration---------------------------------// |
163 |
S4Br->GetEntry(i); |
for (Int_t ll = 0; ll < nevents; ll++){ |
164 |
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); |
|
165 |
trigconf = trige->trigconf; |
trigconf = trige->trigconf; |
166 |
trc = 0; |
trc = 0; |
167 |
if ( trigconf & (1<<0) ) trc = "TOF1"; |
if ( trigconf & (1<<0) ) trc = "TOF1"; |
176 |
if ( trigconf & (1<<3) ) { |
if ( trigconf & (1<<3) ) { |
177 |
if (trc==0) trc= "TOF4"; |
if (trc==0) trc= "TOF4"; |
178 |
else trc = Form("%s-TOF4",trc); |
else trc = Form("%s-TOF4",trc); |
179 |
} |
} |
180 |
if ( trigconf & (1<<4) ) { |
if ( trigconf & (1<<4) ) { |
181 |
if (trc==0) trc= "TOF5"; |
if (trc==0) trc= "TOF5"; |
182 |
else trc = Form("%s-TOF5",trc); |
else trc = Form("%s-TOF5",trc); |
183 |
} |
} |
184 |
if ( trigconf & (1<<5) ) { |
if ( trigconf & (1<<5) ) { |
185 |
if (trc==0) trc= "TOF6"; |
if (trc==0) trc= "TOF6"; |
186 |
else trc = Form("%s-TOF6",trc); |
else trc = Form("%s-TOF6",trc); |
187 |
} |
} |
188 |
if ( trigconf & (1<<6) ) { |
if ( trigconf & (1<<6) ) { |
189 |
if (trc==0) trc= "TOF7"; |
if (trc==0) trc= "TOF7"; |
190 |
else trc = Form("%s-TOF7",trc); |
else trc = Form("%s-TOF7",trc); |
193 |
if (trc==0) trc= "S4"; |
if (trc==0) trc= "S4"; |
194 |
else trc = Form("%s-S4",trc); |
else trc = Form("%s-S4",trc); |
195 |
} |
} |
196 |
if ( trigconf & (1<<8) ) { |
if ( trigconf & (1<<8) ) { |
197 |
if (trc==0) trc= "CALO"; |
if (trc==0) trc= "CALO"; |
198 |
else trc = Form("%s-CALO",trc); |
else trc = Form("%s-CALO",trc); |
199 |
} |
} |
200 |
if ( trigconf & (1<<9) ) { |
if ( trigconf & (1<<9) ) { |
201 |
if (trc==0) trc= "CALIB_ON"; |
if (trc==0) trc= "CALIB_ON"; |
202 |
else trc = Form("%s-CALIB_ON",trc); |
else trc = Form("%s-CALIB_ON",trc); |
203 |
} |
} |
204 |
trcs = ""; |
trcs = ""; |
205 |
trcs = trc; |
trcs = trc; |
206 |
if (i==0){ |
if (ll==0){ |
207 |
trcss[0]=trcs; |
trcss[0]=trcs; |
208 |
j=j+1; |
j=j+1; |
209 |
} |
} |
210 |
if (trcs!=trcss[j-1] && i>0){ |
if (trcs!=trcss[j-1] && ll>0){ |
211 |
trcss[j]=trcs; |
trcss[j]=trcs; |
212 |
j=j+1; |
j=j+1; |
213 |
} |
} |
214 |
|
//cout<<i<<"\n"; |
215 |
|
//cout<<nevents<<"\n\n"; |
216 |
} |
} |
217 |
|
//--------------------------// |
218 |
for(Int_t k=0; k<31; k++){ |
for(Int_t k=0; k<31; k++){ |
219 |
for(Int_t p=0; p<j ; p++){ |
for(Int_t p=0; p<j ; p++){ |
220 |
if(trgconf[k]==trcss[p]){ |
if(trgconf[k]==trcss[p]){ |
226 |
if(trcsstot[k]!= "") |
if(trcsstot[k]!= "") |
227 |
trcsstot2=trcsstot2+"/"+ trcsstot[k]; |
trcsstot2=trcsstot2+"/"+ trcsstot[k]; |
228 |
} |
} |
229 |
|
|
230 |
//---------to search S4 threshold and convert it into char (hexadecimal value)--------// |
//---------to search S4 threshold and convert it into char (hexadecimal value)--------// |
231 |
vardumpentries = VarDumpBr->GetEntries(); |
vardumpentries = VarDumpBr->GetEntries(); |
232 |
if(vardumpentries==0){ |
if(vardumpentries==0){ |
251 |
} |
} |
252 |
sprintf(S4_TRH, "%d" , S4_TRHmip); |
sprintf(S4_TRH, "%d" , S4_TRHmip); |
253 |
} |
} |
254 |
} |
} |
255 |
|
|
256 |
//********************** First Histogram ************************************// |
//********************** First Histogram ************************************// |
257 |
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); |
258 |
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); |
259 |
|
|
260 |
//********************** Second Histogram ************************************// |
//********************** Second Histogram ************************************// |
261 |
headBr->GetEntry(0); |
headBr->GetEntry(0); |
262 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
263 |
firstime = ph->GetOrbitalTime(); |
firstime = ph->GetOrbitalTime(); |
264 |
headBr->GetEntry(nevents-1); |
|
265 |
|
headBr->GetEntry(nevents); |
266 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
267 |
lastime = ph->GetOrbitalTime(); |
lastime = ph->GetOrbitalTime(); |
268 |
|
headBr->GetEntry(nevents-100); |
269 |
|
ph = eh->GetPscuHeader(); |
270 |
|
if(lastime-ph->GetOrbitalTime()> 100000) nevents=nevents-100; |
271 |
|
int iii=0,MaxR=0; |
272 |
|
while(iii < nevents){ |
273 |
|
headBr->GetEntry(iii); |
274 |
|
ph = eh->GetPscuHeader(); |
275 |
|
if((ph->GetOrbitalTime()) <= firstime) firstime=ph->GetOrbitalTime(); |
276 |
|
if((ph->GetOrbitalTime()) >= lastime) lastime=ph->GetOrbitalTime(); |
277 |
|
TriggerBr->GetEntry(iii); |
278 |
|
if(trige->s4calcount[0]>MaxR)MaxR=trige->s4calcount[0]; |
279 |
|
iii++; |
280 |
|
} |
281 |
|
MaxR=10+2*(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)/3); |
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+": smoothed S4 rate", filename+": smoothed S4 rate", 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]; |
rate->Fill(ph->GetOrbitalTime(),trige->s4calcount[0]); |
|
rate->Fill(obt, s4rate); |
|
315 |
h1->Fill(s4e->S4_DATA); |
h1->Fill(s4e->S4_DATA); |
316 |
Allev->Fill(obt,s4e->S4_DATA); |
Allev->Fill(ph->GetOrbitalTime(),s4e->S4_DATA); |
317 |
Alltime->Fill(obt); |
Alltime->Fill(ph->GetOrbitalTime()); |
318 |
if((i==n) && (s4rate >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)){ |
|
rateline->Fill(obt,s4rate); |
|
|
n=n+5; |
|
|
} |
|
|
if ((trige->patterntrig[0] == 0) && (trige->patterntrig[2] == 0) && (trige->patterntrig[3] == 0) && (trige->patterntrig[4] == 0) && (trige->patterntrig[5] == 0)){ |
|
319 |
h2->Fill(s4e->S4_DATA); |
h2->Fill(s4e->S4_DATA); |
320 |
S4ev->Fill(obt,s4e->S4_DATA); |
S4ev->Fill(ph->GetOrbitalTime(),s4e->S4_DATA); |
321 |
S4time->Fill(obt); |
S4time->Fill(ph->GetOrbitalTime()); |
322 |
p=p+1; |
p=p+1; |
323 |
} |
} |
324 |
} |
} |
325 |
|
Int_t kk=0; |
326 |
|
Double_t Aobt=0; |
327 |
|
while (kk < nevents){ |
328 |
|
obt=0; |
329 |
|
s4rate=0; |
330 |
|
Aobt=0; |
331 |
|
for(Int_t jj=kk; jj< (kk+100); jj++){ |
332 |
|
TriggerBr->GetEntry(jj); |
333 |
|
headBr->GetEntry(jj); |
334 |
|
obt = obt+(ph->GetOrbitalTime()); |
335 |
|
s4rate= s4rate+(trige->s4calcount[0]); |
336 |
|
Aobt=Aobt+((ph->GetOrbitalTime())-obmin)*(trige->s4calcount[0]); |
337 |
|
} |
338 |
|
rateline->Fill((Aobt/s4rate)+obmin,(s4rate/100)); |
339 |
|
kk=kk+100; |
340 |
|
} |
341 |
|
|
342 |
//****************************** Canvases *******************************// |
//****************************** Canvases *******************************// |
343 |
//------------------- First Canvas --------------------------------// |
//------------------- First Canvas --------------------------------// |
477 |
Allev->GetXaxis()->CenterTitle(); |
Allev->GetXaxis()->CenterTitle(); |
478 |
Allev->GetYaxis()->SetTitle("Mean signal ( ADC )"); |
Allev->GetYaxis()->SetTitle("Mean signal ( ADC )"); |
479 |
Allev->GetYaxis()->CenterTitle(); |
Allev->GetYaxis()->CenterTitle(); |
480 |
Allev->SetMinimum(20); |
//Allev->SetMinimum(20); |
481 |
Allev->Divide(Alltime); |
Allev->Divide(Alltime); |
482 |
Allev->Draw("p"); |
Allev->Draw("p"); |
483 |
pad3->Draw(); |
pad3->Draw(); |