14 #include <Event/EventTypes.h>
15 #include <Event/packetConstants.h>
16 #include <Event/packet.h>
17 #include <Event/packet_hbd_fpgashort.h>
27 polarity_positive =
true;
38 cout <<
"Reading " <<
NCH <<
" Channels." << endl;
41 for(
int ich=0; ich<
NCH; ich++)
44 name =
"gch"; name += ich;
45 gpulse[ich]->SetName(name);
46 gpulse[ich]->SetMarkerStyle(20);
47 gpulse[ich]->SetMarkerSize(0.4);
51 h_PulsePeaks[ich] =
new TH1F(name, name, (
int)4*max, 0., max);
52 h_PulsePeaks[ich]->SetStats(kFALSE);
57 double int_max = max*24./6. ;
58 h_PulseInt[ich] =
new TH1F(name, name, (
int)int_max, 0., int_max );
61 name =
"Signal_Height_vs_Int_";
63 h2_Pulse_H_Int[ich] =
new TH2F(name, name, (
int) max, 0., max, (
int)int_max, 0., int_max);
74 name =
"Fit_analyze_";
76 h2_fit_shape[ich] =
new TH2F(name,name,48,0,24,2100,0,2100);
80 name =
"TResolution_";
82 h_tres[ich] =
new TH1F(name, name, 24, 0, 24);
85 name =
"Ped_Resolution_";
87 h_ped_res[ich] =
new TH1F(name, name, 500,2000,2200);
101 h_info =
new TH1F(name, name, 10, 0, 10);
108 name =
"Saturation_rates_vs_ch";
109 h_saturation_rates =
new TH1F(name, name, NCH, 0, NCH);
111 cout <<
"Reading below HBD channels: " << endl;
112 for(
int ich=0; ich<
NCH; ich++) cout << channel_index[ich] <<
", ";
117 rate->SetNameTitle(
"Rate",
"Trigger Rate");
127 if(
verbosity) cout <<
"hcal::evLoop" << endl;
129 cout <<
"Reading file " << prdfName << endl;
133 cout <<
"Couldn't open input file " << prdfName << endl;
138 double time_begin = 0.;
139 double time_end = 0.;
140 while(GetNextEvent())
144 if(nevts>0&&
nevents==nevts)
break;
147 time_end = (
double) evt->getTime();
149 time_begin = time_end;
152 cout <<
"Total number of events processed " <<
nevents << endl;
153 h_info->SetBinContent(2,
nevents);
155 cout <<
"Saturation summary " << endl;
156 for(
int ich=0; ich<
NCH; ich++)
158 cout <<
"Channel " << ich <<
" => " << 100*saturation_map[ich]/
nevents <<
" % " <<endl;
159 h_saturation_rates->Fill( h_saturation_rates->FindBin(ich), 100*saturation_map[ich]/
nevents );
169 if(
verbosity) cout <<
"hcal::Clear()" << endl;
170 for (
int ich=0; ich<
NCH; ich++)
188 if(evt->getEvtType()==9)
190 cout <<
"Event " <<
nevents << endl;
191 cout <<
"Start Time " << evt->getTime() << endl;
192 cout <<
"Start Date " << evt->getDate() << endl;
194 h_info->SetBinContent(1, evt->getRunNumber() );
196 h_info->SetBinContent(3, evt->getTime() );
198 else if(evt->getEvtType()==12)
201 h_info->SetBinContent(4, evt->getTime() );
209 for(
int ich=0; ich<
NCH; ich++)
211 int hbd_channel = channel_index[ich];
212 for (
int isamp=0; isamp<
NSAMPLES; isamp++)
216 Short_t val = spacket->
iValue(hbd_channel,isamp);
217 gpulse[ich]->SetPoint(isamp,(Double_t)isamp,(Double_t)val);
220 if(!polarity_positive && TMath::MinElement(24,
gpulse[ich]->
GetY())==0)
223 saturation_map[ich]++;
224 if(
verbosity) cout <<
"Saturated channel " << ich << endl;
235 if(
nevents>1) cout <<
"Event: " <<
nevents <<
" Packet not found " << endl;
246 if(polarity_positive) peakval = 0.;
247 else peakval = 99999.;
250 for(
int iSample=0; iSample<
NSAMPLES; iSample++)
253 if(!polarity_positive &&
gpulse[ich]->
GetY()[iSample]<peakval){
255 peakval =
gpulse[ich]->GetY()[iSample];
257 }
else if(polarity_positive &&
gpulse[ich]->
GetY()[iSample]>peakval)
259 peakval =
gpulse[ich]->GetY()[iSample];
265 if(polarity_positive) peakval -=
pedestal;
266 else peakval = pedestal - peakval;
267 if(peakval<0.) peakval = 0.;
270 par[1] = peakPos - risetime;
271 if(par[1]<0.) par[1] = 0.;
276 fits[ich]->SetParameters(par);
277 fits[ich]->SetParLimits(0,peakval*0.98,peakval*1.02);
278 fits[ich]->SetParLimits(1,0,24);
279 fits[ich]->SetParLimits(2, 2, 4.);
280 fits[ich]->SetParLimits(3,1.,2.);
281 fits[ich]->SetParLimits(4, pedestal-30, pedestal+30);
282 fits[ich]->SetParLimits(5, 1, -1);
283 gpulse[ich]->Fit( fits[ich],
"MQR",
"goff", 0., (
double) NSAMPLES);
293 double min = fits[ich]->GetMinimum();
294 double minx = fits[ich]->GetMinimumX();
298 double max = fits[ich]->GetMaximum();
299 double maxx = fits[ich]->GetMaximumX();
301 if(polarity_positive) ped_val = fits[ich]->GetParameter(4)+maxx*fits[ich]->GetParameter(5);
302 else ped_val = fits[ich]->GetParameter(4)+minx*fits[ich]->GetParameter(5);
304 double peakvalue = 0;
305 if(polarity_positive) peakvalue = max - ped_val;
306 else peakvalue = ped_val -
min;
308 double integral = 24*ped_val - fits[ich]->Integral(0,24);
309 if(
verbosity) cout <<
"Channel " << ich <<
" " << h_PulsePeaks[ich]->GetName() <<
" PED: " << ped_val <<
" Signal " << peakvalue <<
" Integrated signal: " << integral << endl;
313 h_PulsePeaks[ich]->Fill( peakvalue );
314 h_PulseInt[ich]->Fill( integral );
315 h2_Pulse_H_Int[ich]->Fill( peakvalue, integral );
316 h_tres[ich]->Fill( (polarity_positive)?maxx:minx );
317 h_ped_res[ich]->Fill( ped_val );
340 if(
gpulse[0]->GetN()==0)
return;
344 for(
int ich=0; ich<
NCH; ich++)
347 fits[ich]->SetParameter(1,4.0);
348 for(
float x=0;
x<48;
x=
x+0.5)
350 h2_fit_shape[ich]->Fill(
x, fits[ich]->Eval(
x) );
358 int ny_c = ceil(
NCH/4 );
359 c =
new TCanvas(
"sphenix",
"sphenix display", 300*nx_c, 200*ny_c );
360 c->Divide(nx_c,ny_c);
362 for(
int ich=0; ich<
NCH; ich++)
366 gpulse[ich]->SetMaximum( plot_max );
367 gpulse[ich]->SetMinimum( plot_min );
372 cout <<
"Kill the process or 'killall root.exe' to stop the canvas" << endl;
375 for(
int ich=0; ich<
NCH; ich++)
c->cd(ich+1)->Modified();
385 double pedestal = par[4] + x[0]*par[5];
388 double signal = par[0]*pow((x[0]-par[1]),par[2])*exp(-(x[0]-par[1])*par[3]);
389 return pedestal +
signal ;
395 double pedestal = par[4] + x[0]*par[5];
397 double signal = par[0]*pow((x[0]-par[1]),par[2])*exp(-(x[0]-par[1])*par[3]);
405 fout = TFile::Open( filename,
"RECREATE" );
406 for(
int ich=0; ich<
NCH; ich++)
408 h_PulsePeaks[ich]->Write();
409 h_tres[ich]->Write();
410 h_ped_res[ich]->Write();
411 h2_fit_shape[ich]->Write();
414 h_PulseInt[ich]->Write();
415 h2_Pulse_H_Int[ich]->Write();
417 h_saturation_rates->Write();