45 hfDigiCollectionTag_(fConfiguration.getParameter<edm::InputTag>(
"hfDigiCollectionTag")),
46 hcalCalibDigiCollectionTag_(fConfiguration.getParameter<edm::InputTag>(
"hcalCalibDigiCollectionTag")) {
61 Int_t neta,nphi,ndepth,nmax,nquad,npin;
63 std::cout<<std::endl<<
"HFLightCal beginJob: --> "<<std::endl;
68 printf(
"\nNo output textfile open\n\n");
69 std::cout<<
"Problem with output textFILE => exit"<<std::endl;
74 printf(
"\nNo input pre-file open\n\n");
75 std::cout<<
"Problem with input textFILE => exit"<<std::endl;
79 for (
int i=0;
i<1728;
i++) {
80 fscanf(
preFile,
"%d%d%d%d\r",&neta,&nphi,&ndepth,&nmax);
82 if (neta>=29 && neta<=41 && nphi<72 && nphi>0 && ndepth>0 && ndepth<=2)
83 itsmax[neta-29][(nphi-1)/2][ndepth-1] = nmax;
84 else if (neta<=-29 && neta>=-41 && nphi<72 && nphi>0 && ndepth>0 && ndepth<=2)
85 itsmax[13-neta-29][(nphi-1)/2][ndepth-1] = nmax;
87 std::cout<<
"Input pre-file: wrong channel record:"<<std::endl;
88 std::cout<<
"eta="<<neta<<
" phi="<<nphi<<
" depth="<<ndepth<<
" max="<<nmax<<std::endl;
91 for (
int i=0;
i<24;
i++) {
92 fscanf(
preFile,
"%d%d%d\r",&nquad,&npin,&nmax);
94 if (nquad>0 && nquad<=4 && npin<=3 && npin>0)
96 else if (nquad<0 && nquad>=-4 && npin<=3 && npin>0)
99 std::cout<<
"Input pre-file: wrong PIN record:"<<std::endl;
100 std::cout<<
"quad="<<nquad<<
" pin="<<npin<<
" max="<<nmax<<std::endl;
105 htmax =
new TH1F(
"htmax",
"Max TS",10,-0.5,9.5);
106 htmean =
new TH1F(
"htmean",
"Mean signal TS",100,0,10);
107 hsignalmean =
new TH1F(
"hsignalmean",
"Mean ADC 4maxTS",1201,-25,30000);
108 hsignalrms =
new TH1F(
"hsignalrms",
"RMS ADC 4maxTS",500,0,500);
109 hpedmean =
new TH1F(
"hpedmean",
"Mean ADC 4lowTS",200,-10,90);
110 hpedrms =
new TH1F(
"hpedrms",
"RMS ADC 4lowTS",200,0,100);
111 hspes =
new TH1F(
"hspes",
"SPE if measured",200,0,40);
112 hnpevar =
new TH1F(
"hnpevar",
"~N PE input",500,0,500);
113 hsignalmapP =
new TH2F(
"hsignalmapP",
"Mean(Response) - Mean(Pedestal) HFP;#eta;#phi",26,28.5,41.5,36,0,72);
114 hsignalRMSmapP =
new TH2F(
"hsignalRMSmapP",
"RMS Response HFP;#eta;#phi",26,28.5,41.5,36,0,72);
115 hnpemapP =
new TH2F(
"hnpemapP",
"~N PE input HFP;#eta;#phi",26,28.5,41.5,36,0,72);
117 hsignalmapM =
new TH2F(
"hsignalmapM",
"Mean(Response) - Mean(Pedestal) HFM;#eta;#phi",26,-41.5,-28.5,36,0,72);
118 hsignalRMSmapM =
new TH2F(
"hsignalRMSmapM",
"RMS Response HFM;#eta;#phi",26,-41.5,-28.5,36,0,72);
119 hnpemapM =
new TH2F(
"hnpemapM",
"~N PE input HFM;#eta;#phi",26,-41.5,-28.5,36,0,72);
122 for (
int i=0;
i<13;
i++)
for (
int j=0;
j<36;
j++)
for (
int k=0;
k<2;
k++) {
123 if (
i>10 &&
j%2==0)
continue;
124 sprintf(htit,
"ts_+%d_%d_%d",
i+29,
j*2+1,
k+1);
125 hts[
i][
j][
k] =
new TH1F(htit,htit,10,-0.5,9.5);
126 sprintf(htit,
"tsmean_+%d_%d_%d",
i+29,
j*2+1,
k+1);
127 htsm[
i][
j][
k] =
new TH1F(htit,htit,100,0,10);
128 sprintf(htit,
"sp_+%d_%d_%d",
i+29,
j*2+1,
k+1);
129 hsp[
i][
j][
k] =
new TH1F(htit,htit,1201,-25,30000);
130 sprintf(htit,
"spe_+%d_%d_%d",
i+29,
j*2+1,
k+1);
131 hspe[
i][
j][
k] =
new TH1F(htit,htit,200,-9.5,190.5);
132 sprintf(htit,
"ped_+%d_%d_%d",
i+29,
j*2+1,
k+1);
133 hped[
i][
j][
k] =
new TH1F(htit,htit,200,-9.5,190.5);
134 sprintf(htit,
"ts_-%d_%d_%d",
i+29,
j*2+1,
k+1);
135 hts[
i+13][
j][
k] =
new TH1F(htit,htit,10,-0.5,9.5);
136 sprintf(htit,
"tsmean_-%d_%d_%d",
i+29,
j*2+1,
k+1);
137 htsm[
i+13][
j][
k] =
new TH1F(htit,htit,100,0,10);
138 sprintf(htit,
"sp_-%d_%d_%d",
i+29,
j*2+1,
k+1);
139 hsp[
i+13][
j][
k] =
new TH1F(htit,htit,1201,-25,30000);
140 sprintf(htit,
"spe_-%d_%d_%d",
i+29,
j*2+1,
k+1);
141 hspe[
i+13][
j][
k] =
new TH1F(htit,htit,200,-9.5,190.5);
142 sprintf(htit,
"ped_-%d_%d_%d",
i+29,
j*2+1,
k+1);
143 hped[
i+13][
j][
k] =
new TH1F(htit,htit,200,-9.5,190.5);
146 for (
int i=0;
i<4;
i++)
for (
int j=0;
j<3;
j++) {
147 sprintf(htit,
"ts_PIN%d_+Q%d",
j+1,
i+1);
148 htspin[
i][
j] =
new TH1F(htit,htit,10,-0.5,9.5);
149 sprintf(htit,
"sp_PIN%d_+Q%d",
j+1,
i+1);
150 hsppin[
i][
j] =
new TH1F(htit,htit,1601,-25,40000);
151 sprintf(htit,
"spe_PIN%d_+Q%d",
j+1,
i+1);
152 hspepin[
i][
j] =
new TH1F(htit,htit,200,-9.5,190.5);
153 sprintf(htit,
"ped_PIN%d_+Q%d",
j+1,
i+1);
154 hpedpin[
i][
j] =
new TH1F(htit,htit,200,-9.5,190.5);
155 sprintf(htit,
"tsmean_PIN%d_+Q%d",
j+1,
i+1);
156 htsmpin[
i][
j] =
new TH1F(htit,htit,100,0,10);
157 sprintf(htit,
"ts_PIN%d_-Q%d",
j+1,
i+1);
158 htspin[
i+4][
j] =
new TH1F(htit,htit,10,-0.5,9.5);
159 sprintf(htit,
"sp_PIN%d_-Q%d",
j+1,
i+1);
160 hsppin[
i+4][
j] =
new TH1F(htit,htit,1601,-25,40000);
161 sprintf(htit,
"spe_PIN%d_-Q%d",
j+1,
i+1);
162 hspepin[
i+4][
j] =
new TH1F(htit,htit,200,-9.5,190.5);
163 sprintf(htit,
"ped_PIN%d_-Q%d",
j+1,
i+1);
164 hpedpin[
i+4][
j] =
new TH1F(htit,htit,200,-9.5,190.5);
165 sprintf(htit,
"tsmean_PIN%d_-Q%d",
j+1,
i+1);
166 htsmpin[
i+4][
j] =
new TH1F(htit,htit,100,0,10);
174 mean=hist->GetMean();
176 xmin=hist->GetXaxis()->GetXmin();
177 xmax=hist->GetXaxis()->GetXmax();
178 hist->SetAxisRange(mean-range*rms-100,mean+range*rms+100);
179 mean=hist->GetMean();
181 hist->SetAxisRange(mean-range*rms-100,mean+range*rms+100);
182 mean=hist->GetMean();
184 hist->SetAxisRange(xmin,xmax);
191 Double_t sum,xx,A0,C0,r0,sigma0,mean1,sigma1,A1,C1,
r1,mean2,sigma2,A2,C2,
r2,mean3,sigma3,A3,C3,r3;
193 const Double_t
k0=2.0, k1=1.6, k2=2.0;
197 A0 = 2*
Nev/(2+2*par[0]+par[0]*par[0]+
pow(par[0],3)/3+
pow(par[0],4)/12+
198 pow(par[0],5)/60+
pow(par[0],6)/360);
199 r0 = ((xx-par[1])/sigma0);
200 C0 = 1/(sigma0* TMath::Exp(-k0*k0/2)/k0 +
201 sigma0*
sqrt(2*3.14159)*0.5*(1+TMath::Erf(k0/1.41421)));
203 if(r0 < k0) sum = C0*A0*TMath::Exp(-0.5*r0*r0);
204 else sum = C0*A0*TMath::Exp(0.5*k0*k0-k0*r0);
206 mean1 = par[1]+par[3];
211 C1 = 1/(sigma1* TMath::Exp(-k1*k1/2)/k1 +
212 sigma1*
sqrt(2*3.14159)*0.5*(1+TMath::Erf(k1/1.41421)));
213 r1 = ((xx-mean1)/sigma1);
214 if(r1 < k1) sum += C1*A1*TMath::Exp(-0.5*r1*r1);
215 else sum += C1*A1*TMath::Exp(0.5*k1*k1-k1*r1);
217 mean2 = 2*par[3]+par[1];
218 sigma2 =
sqrt(2*sigma1*sigma1 -
pow(par[2],2));
220 A2 = A0*par[0]*par[0]/2;
221 C2 = 1/(sigma2* TMath::Exp(-k2*k2/2)/k2 +
222 sigma2*
sqrt(2*3.14159)*0.5*(1+TMath::Erf(k2/1.41421)));
223 r2 = ((xx-mean2)/sigma2);
224 if(r2 < k2) sum += C2*A2*TMath::Exp(-0.5*r2*r2);
225 else sum += C2*A2*TMath::Exp(0.5*k2*k2-k2*r2);
227 mean3 = 3*par[3]+par[1];
228 sigma3 =
sqrt(3*sigma1*sigma1 - 2*
pow(par[2],2));
229 A3 = A0*par[0]*par[0]*par[0]/6;
230 C3 = 1/(sigma3*
sqrt(2*3.14159));
231 r3 = ((xx-mean3)/sigma3);
232 sum += C3*A3*TMath::Exp(-0.5*r3*r3);
239 Double_t
mean,
rms,meanped,rmsped,npevar;
240 Double_t par[5],dspe=0,dnpe;
242 std::cout<<std::endl<<
"HFLightCal endJob --> ";
245 for (
int i=0;
i<26;
i++)
for (
int j=0;
j<36;
j++)
for (
int k=0;
k<2;
k++) {
246 if (
i>10 &&
i<13 &&
j%2==0)
continue;
247 if (
i>23 &&
j%2==0)
continue;
248 meanped=rmsped=mean=rms=0;
249 if (
hsp[
i][
j][
k]->Integral()>0) {
252 if (
hspe[
i][
j][k]->Integral()>
hsp[
i][
j][k]->Integral()*0.9 || mean<100) {
266 fprintf(
tFile,
" MeanInput=<%.2f> [linADCcount] RMS=<%.2f>\n",mean,rms);
267 fprintf(
tFile,
"#eta/phi/depth sum4maxTS RMS ~N_PE sum4lowTS RMS maxTS SPE +/- Err Comment\n");
268 TF1* fPed =
new TF1(
"fPed",
"gaus",0,120);
270 TF1 *fTot =
new TF1(
"fTot",
FitFun ,0,200,5);
272 for (
int i=0;
i<26;
i++)
for (
int j=0;
j<36;
j++)
for (
int k=0;
k<2;
k++) {
273 if (
i>10 &&
i<13 &&
j%2==0)
continue;
274 if (
i>23 &&
j%2==0)
continue;
278 if (
hspe[
i][
j][k]->Integral()>
hsp[
i][
j][k]->Integral()*0.9 || mean<100) {
280 if (
hspe[
i][
j][k]->Integral(1,(
int) (meanped+3*rmsped+12))/
Nev>0.1) {
282 if (mean+rms*3-meanped-rmsped*3>2 && rmsped>0) {
285 par[0] =
hped[
i][
j][
k]->GetMaximum();
286 fPed->SetParameters(par);
287 hped[
i][
j][
k]->Fit(fPed,
"BQ0");
288 fPed->GetParameters(&par[0]);
289 hped[
i][
j][
k]->Fit(fPed,
"B0Q",
"",par[1]-par[2]*3,par[1]+par[2]*3);
290 fPed->GetParameters(par);
291 hped[
i][
j][
k]->Fit(fPed,
"BLIQ",
"",par[1]-par[2]*3,par[1]+par[2]*3);
292 fPed->GetParameters(&par[0]);
297 fTot->SetParameters(par);
298 fTot->SetParLimits(0,0,2);
300 fTot->SetParLimits(1,par[1]-1,par[1]+1);
301 fTot->FixParameter(2,par[2]);
302 fTot->SetParLimits(3,1.2,100);
305 hspe[
i][
j][
k]->Fit(fTot,
"BLEQ",
"");
306 fTot->GetParameters(par);
307 hspe[
i][
j][
k]->Fit(fTot,
"BLEQ",
"",-10,par[1]+par[3]*5);
308 fTot->GetParameters(par);
309 dspe=fTot->GetParError(3);
310 dnpe=fTot->GetParError(0);
311 if (par[3]<1.21 || dnpe>par[0]) par[3]=-1;
312 else if (par[0]>1.96 || par[3]>49) par[3]=0;
322 if (par[3]>0) npevar=par[0];
324 if (
hspe[
i][
j][k]->Integral()>
hsp[
i][
j][k]->Integral()*0.98) {
331 if (rms*rms-rmsped*rmsped>1 && mean>meanped) {
332 npevar=(mean-meanped)*(mean-meanped)/(rms*rms-rmsped*rmsped);
335 intspe=int(
hspe[
i][
j][k]->Integral());
336 hspe[
i][
j][
k]->SetAxisRange(meanped+rmsped*4,300);
337 npevar=
hspe[
i][
j][
k]->Integral()/intspe;
338 if (npevar>0.01) npevar=-1;
340 hspe[
i][
j][
k]->SetAxisRange(-20,300);
344 if (npevar>5.0
e-5)
hnpevar->Fill(npevar);
349 if (npevar>0)
hnpemapP->Fill(
i+28.6+k/2.0,
j*2+1,npevar);
350 fprintf(
tFile,
"%3d%4d%5d %11.2f%8.2f",
i+29,
j*2+1,k+1,mean,rms);
353 fprintf(
tFile,
"%3d%4d%5d %11.2f%8.2f",13-
i-29,
j*2+1,k+1,mean,rms);
356 if (npevar>0)
hnpemapM->Fill(13-
i-28.6-k/2.0,
j*2+1,npevar);
358 if (npevar>0) fprintf(
tFile,
" %9.4f",npevar);
359 else fprintf(
tFile,
" 0 ");
360 fprintf(
tFile,
" %8.2f%8.2f",meanped,rmsped);
361 tsmax=
hts[
i][
j][
k]->GetMaximumBin()-1;
362 fprintf(
tFile,
" %4d",tsmax);
363 if (par[3]>0 && par[3]<99) fprintf(
tFile,
"%8.2f%7.2f",par[3],dspe);
364 else if (npevar>0) fprintf(
tFile,
"%8.2f 0 ",(mean-meanped)/npevar);
365 else fprintf(
tFile,
" 0 0 ");
369 if (
hsp[
i][
j][k]->GetEntries()<=0) fprintf(
tFile,
"NoSignal\n");
370 else if (
hsp[
i][
j][k]->GetEntries()<=10) fprintf(
tFile,
"Nev<10\n");
372 if (
hsp[
i][
j][k]->Integral()<=10 || mean>12000) fprintf(
tFile,
"SignalOffRange\n");
374 if (
hsp[
i][
j][k]->Integral()<100) fprintf(
tFile,
"Nev<100/");
375 if (npevar>0 && par[3]>0 && (npevar*
Nev<10 || npevar<0.001))
376 fprintf(
tFile,
"LowSignal/");
377 else if (npevar==0 && fabs(mean-meanped)<3) fprintf(
tFile,
"LowSignal/");
378 if (par[3]<0) fprintf(
tFile,
"BadFit/");
379 else if (par[3]==0) fprintf(
tFile,
"NoSPEFit/");
380 else if (par[3]>0 && npevar>1) fprintf(
tFile,
"NPE>1/");
381 if (npevar<0) fprintf(
tFile,
"Problem/");
382 if (mean<2) fprintf(
tFile,
"LowMean/");
383 if (rms<0.5) fprintf(
tFile,
"LowRMS/");
384 if (meanped<-1) fprintf(
tFile,
"LowPed/");
385 else if (meanped>25) fprintf(
tFile,
"HighPed/");
386 if (rmsped<0.5 && rmsped>0) fprintf(
tFile,
"NarrowPed/");
387 else if (rmsped>10) fprintf(
tFile,
"WidePed/");
388 if (
hped[
i][
j][k]->GetBinContent(201)>10) fprintf(
tFile,
"PedOffRange");
389 fprintf(
tFile,
"-\n");
394 for (
int i=0;
i<8;
i++)
for (
int j=0;
j<3;
j++) {
397 if (
hspepin[
i][j]->Integral()>
hsppin[
i][j]->Integral()*0.9 || mean<100) {
400 if (
i<4) fprintf(
tFile,
" PIN%d +Q%d %12.2f %6.2f",j+1,
i+1,mean,rms);
401 else fprintf(
tFile,
" PIN%d -Q%d %12.2f %6.2f",j+1,
i-3,mean,rms);
402 fprintf(
tFile,
" %15.2f %6.2f",meanped,rmsped);
403 tsmax=
htspin[
i][
j]->GetMaximumBin()-1;
404 fprintf(
tFile,
" %4d\n",tsmax);
410 std::cout<<std::endl<<
" --endJob-- done"<<std::endl;
418 int runNer = eventId.
run ();
419 int eventNumber = eventId.
event ();
422 if (
verbose)
std::cout <<
"========================================="<<std::endl
423 <<
"run/event: "<<runNer<<
'/'<<eventNumber<<std::endl;
426 Double_t maxADC,signal,ped=0,meant;
427 Int_t maxisample=0,i1=3,i2=6;
432 if (
verbose)
std::cout<<
"Analysis-> total CAL digis= "<<calib->size()<<std::endl;
488 if (
verbose)
std::cout<<
"Analysis-> total HF digis= "<<hf_digi->size()<<std::endl;
490 for (
unsigned ihit = 0; ihit < hf_digi->size (); ++ihit) {
493 int ieta = detId.
ieta();
494 int iphi = detId.
iphi();
495 int depth = detId.
depth();
497 <<ieta<<
'/'<<iphi<<
'/'<< depth << std::endl;
499 if (ieta>0) ieta = ieta-29;
500 else ieta = 13-ieta-29;
502 for (
int ii=0;
ii<10;
ii++) buf[
ii]=0;
504 for (
int isample = 0; isample < frame.
size(); ++isample) {
505 int adc = frame[isample].adc();
506 int capid = frame[isample].capid ();
507 double linear_ADC = frame[isample].nominal_fC();
508 double nominal_fC = detId.
subdet () ==
HcalForward ? 2.6 * linear_ADC : linear_ADC;
511 <<
", capid=" << capid
513 <<
", linearized ADC=" << linear_ADC
514 <<
", nominal fC=" << nominal_fC <<std::endl;
516 hts[ieta][(iphi-1)/2][depth-1]->
Fill(isample,linear_ADC);
517 buf[isample]=linear_ADC;
529 if (
ii<2) signal -= (buf[
ii+4]+buf[
ii+8])/2.0;
530 else if (
ii<4) signal -= buf[
ii+4];
531 else if (
ii<6) signal -= (buf[
ii+4]+buf[
ii-4])/2.0;
532 else if (
ii<8) signal -= buf[
ii-4];
533 else signal -= (buf[
ii-4]+buf[
ii-8])/2.0;
540 if (
abs(maxisample-
itsmax[ieta][(iphi-1)/2][depth-1]+1)>1) maxisample=
itsmax[ieta][(iphi-1)/2][depth-1]-1;
541 if (
verbose)
std::cout<<eventNumber<<
"/"<<ihit<<
": maxTS="<<maxisample<<endl;
544 htmax->Fill(maxisample);
547 if (i1<0) {i1=0;i2=3;}
548 else if (i2>9) {i1=6;i2=9;}
549 else if (i2<9 && maxisample<=
itsmax[ieta][(iphi-1)/2][depth-1]-1) {
550 if (buf[i1]<buf[i2+1]) {i1=i1+1;i2=i2+1;}
552 signal=buf[i1]+buf[i1+1]+buf[i1+2]+buf[i1+3];
553 hsp[ieta][(iphi-1)/2][depth-1]->
Fill(signal);
554 hspe[ieta][(iphi-1)/2][depth-1]->
Fill(signal);
565 if (i1<2) ped=buf[8]+buf[9]+buf[6]+buf[7];
566 else if (i1==2) ped=buf[6]+buf[9]+buf[7]+buf[0];
567 else if (i1==3) ped=buf[0]+buf[1]+buf[2]+buf[7];
568 else if (i1>=4) ped=buf[0]+buf[1]+buf[2]+buf[3];
570 hped[ieta][(iphi-1)/2][depth-1]->
Fill(ped);
574 meant=(buf[i1]-ped)*i1+(buf[i1+1]-ped)*(i1+1)+(buf[i1+2]-ped)*(i1+2)+(buf[i1+3]-ped)*(i1+3);
575 meant /= (buf[i1]-ped)+(buf[i1+1]-ped)+(buf[i1+2]-ped)+(buf[i1+3]-ped);
577 htsm[ieta][(iphi-1)/2][depth-1]->
Fill(meant);
int adc(sample_type sample)
get the ADC sample (12 bits)
edm::InputTag hcalCalibDigiCollectionTag_
EventNumber_t event() const
T getUntrackedParameter(std::string const &, T const &) const
virtual void endJob(void)
HFLightCal(const edm::ParameterSet &fConfiguration)
HcalSubdetector subdet() const
get the subdetector
edm::InputTag hfDigiCollectionTag_
int depth() const
get the tower depth
MVATrainerComputer * calib
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
int ieta() const
get the cell ieta
virtual void analyze(const edm::Event &fEvent, const edm::EventSetup &fSetup)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
int iphi() const
get the cell iphi
void HistSpecs(TH1F *hist, Double_t &mean, Double_t &rms, Double_t range=4)
int size() const
total number of samples in the digi
Double_t FitFun(Double_t *x, Double_t *par)
const HcalDetId & id() const
Power< A, B >::type pow(const A &a, const B &b)