17 #include <TDirectory.h>
23 #include <JANA/JApplication.h>
24 #include <JANA/JFactory.h>
39 VERBOSEHISTOGRAMS = 0;
42 gPARMS->SetDefaultParameter(
"BCAL_ALGR:VERBOSE",
VERBOSE,
"Verbosity level");
43 gPARMS->SetDefaultParameter(
"BCAL_ALGR:VERBOSEHISTOGRAMS", VERBOSEHISTOGRAMS,
"Create more histograms (default 0 for monitoring)");
63 gStyle->SetTitleOffset(1,
"Y");
64 gStyle->SetTitleOffset(1.3,
"z");
65 gStyle->SetTitleSize(0.06,
"xyz");
66 gStyle->SetTitleSize(0.07,
"h");
67 gStyle->SetLabelSize(0.06,
"xy");
68 gStyle->SetLabelSize(0.04,
"z");
70 gStyle->SetTitleAlign(13);
71 gStyle->SetNdivisions(505,
"xy");
73 gStyle->SetOptStat(11);
77 TDirectory *
main = gDirectory;
78 TDirectory *bcalgainratio = main->mkdir(
"bcalgainratio");
81 char histname[255], modtitle[255], histtitle[255];
83 sprintf(histtitle,
"All channels;Z Position (cm);log of integral ratio US/DS");
84 logintratiovsZ_all =
new TH2I(
"logintratiovsZ_all",histtitle,500,-250.0,250.0,500,-3,3);
85 sprintf(histtitle,
"All channels;Z Position (cm);log of peak ratio US/DS");
86 logpeakratiovsZ_all =
new TH2I(
"logpeakratiovsZ_all",histtitle,500,-250.0,250.0,500,-3,3);
88 sprintf(histtitle,
"Atten. length from integ.;-2 / slope of [ln(A_{U}/A_{D}) vs position];BCAL cells");
89 hist_attenlength =
new TH1I(
"hist_attenlength",histtitle,100,200,900);
90 sprintf(histtitle,
"Gain ratio from integ.;G_{U}/G_{D} from [ln(A_{U}/A_{D}) vs position];BCAL cells");
91 hist_gainratio =
new TH1I(
"hist_gainratio",histtitle,100,0.3,1.7);
93 sprintf(histtitle,
"Atten. length from integ. (Uncertainty);fit uncertainty;BCAL cells");
94 hist_attenlength_err =
new TH1I(
"hist_attenlength_err",histtitle,100,0,0);
95 sprintf(histtitle,
"Gain ratio from integ. (Uncertainty);fit uncertainty;BCAL cells");
96 hist_gainratio_err =
new TH1I(
"hist_gainratio_err",histtitle,100,0,0);
98 sprintf(histtitle,
"Atten. length from integ. (Uncertainty);rel. fit uncertainty (%%);BCAL cells");
99 hist_attenlength_relerr =
new TH1I(
"hist_attenlength_relerr",histtitle,100,0,0);
100 sprintf(histtitle,
"Gain ratio from integ. (Uncertainty);rel. fit uncertainty (%%);BCAL cells");
101 hist_gainratio_relerr =
new TH1I(
"hist_gainratio_relerr",histtitle,100,0,0);
103 sprintf(histtitle,
"Atten. length from integ.;Module;Layer and Sector");
104 hist2D_intattenlength =
new TH2F(
"hist2D_intattenlength",histtitle,48,0.5,48.5,16,0.5,16.5);
105 sprintf(histtitle,
"Gain ratio from integ.;Module;Layer and Sector;G_{U}/G_{D}");
106 hist2D_intgainratio =
new TH2F(
"hist2D_intgainratio",histtitle,48,0.5,48.5,16,0.5,16.5);
108 if (VERBOSEHISTOGRAMS) {
109 sprintf(histtitle,
"Atten. length from peak;Module;Layer and Sector");
110 hist2D_peakattenlength =
new TH2F(
"hist2D_peakattenlength",histtitle,48,0.5,48.5,16,0.5,16.5);
111 sprintf(histtitle,
"Gain ratio from peak;Module;Layer and Sector;G_{U}/G_{D}");
112 hist2D_peakgainratio =
new TH2F(
"hist2D_peakgainratio",histtitle,48,0.5,48.5,16,0.5,16.5);
114 sprintf(histtitle,
"Average Z pos;Module;Layer and Sector;Z (cm)");
115 hist2D_aveZ =
new TH2F(
"hist2D_aveZ",histtitle,48,0.5,48.5,16,0.5,16.5);
118 EvsZ_all =
new TH2I(
"EvsZ_all",
"E vs Z;Z Position (cm);Energy",100,-250.0,250.0,200,0,0.2);
119 EvsZ_layer[0] =
new TH2I(
"EvsZ_layer1",
"E vs Z (layer 1);Z Position (cm);Energy",100,-250.0,250.0,200,0,0.2);
120 EvsZ_layer[1] =
new TH2I(
"EvsZ_layer2",
"E vs Z (layer 2);Z Position (cm);Energy",100,-250.0,250.0,200,0,0.2);
121 EvsZ_layer[2] =
new TH2I(
"EvsZ_layer3",
"E vs Z (layer 3);Z Position (cm);Energy",100,-250.0,250.0,200,0,0.2);
122 EvsZ_layer[3] =
new TH2I(
"EvsZ_layer4",
"E vs Z (layer 4);Z Position (cm);Energy",100,-250.0,250.0,200,0,0.2);
124 gStyle->SetOptFit(0);
125 gStyle->SetOptStat(0);
127 TDirectory *dirlogpeakratiovsZ = bcalgainratio->mkdir(
"logpeakratiovsZ");
128 TDirectory *dirlogintratiovsZ = bcalgainratio->mkdir(
"logintratiovsZ");
129 TDirectory *dirEvsZ = bcalgainratio->mkdir(
"EvsZ");
132 if (VERBOSEHISTOGRAMS) {
133 dirlogpeakratiovsZ->cd();
134 for (
int module=0; module<
nummodule; module++) {
136 for (
int sector=0; sector<
numsector; sector++) {
137 sprintf(histname,
"logpeakratiovsZ_%02i%i%i",module+1,
layer+1,sector+1);
138 sprintf(modtitle,
"Channel (M%i,L%i,S%i)",module+1,
layer+1,sector+1);
139 sprintf(histtitle,
"%s;Z Position (cm);log of pulse height ratio US/DS",modtitle);
140 logpeakratiovsZ[module][
layer][sector] =
new TH2I(histname,histtitle,220,-220.0,220.0,400,-4,4);
145 dirlogintratiovsZ->cd();
146 for (
int module=0; module<
nummodule; module++) {
148 for (
int sector=0; sector<
numsector; sector++) {
149 sprintf(histname,
"logintratiovsZ_%02i%i%i",module+1,
layer+1,sector+1);
150 sprintf(modtitle,
"Channel (M%i,L%i,S%i)",module+1,
layer+1,sector+1);
151 sprintf(histtitle,
"%s;Z Position (cm);log of integral ratio US/DS",modtitle);
152 logintratiovsZ[module][
layer][sector] =
new TH2I(histname,histtitle,220,-220.0,220.0,400,-4,4);
156 if (VERBOSEHISTOGRAMS) {
158 for (
int module=0; module<
nummodule; module++) {
160 for (
int sector=0; sector<
numsector; sector++) {
161 sprintf(histname,
"EvsZ_%02i%i%i",module+1,
layer+1,sector+1);
162 sprintf(modtitle,
"Channel (M%i,L%i,S%i)",module+1,
layer+1,sector+1);
163 sprintf(histtitle,
"%s;Z Position (cm);Energy",modtitle);
164 EvsZ[module][
layer][sector] =
new TH2I(histname,histtitle,100,-250.0,250.0,200,0,0.2);
197 bool locIsHDDMEvent = loop->GetJEvent().GetStatusBit(
kSTATUS_HDDM);
200 vector<const DBCALGeometry *> BCALGeomVec;
201 loop->Get(BCALGeomVec);
202 if(BCALGeomVec.size() == 0)
203 throw JException(
"Could not load DBCALGeometry object!");
204 auto locBCALGeom = BCALGeomVec[0];
207 vector<const DBCALPoint*> dbcalpoints;
208 loop->Get(dbcalpoints);
211 vector< vector<const DBCALDigiHit*> > digihits_vec;
212 for(
unsigned int i=0; i<dbcalpoints.size(); i++) {
214 vector<const DBCALDigiHit*> digihits;
215 point->Get(digihits);
217 digihits_vec.push_back(digihits);
220 char name[255], histtitle[255];
224 japp->RootFillLock(
this);
226 if (
VERBOSE>=4)
printf(
"BCAL_attenlength_gainratio::evnt() event %4lu points %3lu \n", eventnumber, dbcalpoints.size());
227 for(
unsigned int i=0; i<dbcalpoints.size(); i++) {
229 int module = point->
module();
231 int sector = point->
sector();
232 float pointE = point->
E();
233 float pointEus = point->
E_US();
234 float pointEds = point->
E_DS();
237 vector<const DBCALDigiHit*> &digihits = digihits_vec[i];
239 if (digihits.size()!=2) {
240 printf(
"Warning: BCAL_attenlength_gainratio: event %llu: wrong number of BCALDigiHit objects found %i\n",
241 (
long long unsigned int)eventnumber,(
int)digihits.size());
244 if (digihits[0]->end==digihits[1]->end) {
245 printf(
"Warning: BCAL_attenlength_gainratio: event %llu: two hits in same end of point\n",(
long long unsigned int)eventnumber);
248 int Vmid0 = (digihits[0]->pulse_peak+digihits[0]->pedestal)/2;
249 int Vmid1 = (digihits[1]->pulse_peak+digihits[1]->pedestal)/2;
250 if (
VERBOSE>=5)
printf(
"BCAL_attenlength_gainratio::evnt() peak %4i ped %3i peak %4i ped %3i\n",
251 digihits[0]->pulse_peak,digihits[0]->
pedestal,digihits[0]->pulse_peak,digihits[0]->
pedestal);
252 if (Vmid0 <= 105 || Vmid1 <= 105 || digihits[0]->pulse_time > 2880 || digihits[1]->pulse_time > 2880) {
253 if (!locIsHDDMEvent)
continue;
256 float peakUS, peakDS;
257 float integralUS, integralDS;
259 if (digihits[0]->end==0) {
260 integralUS = digihits[0]->pulse_integral - ((float)digihits[0]->nsamples_integral*(
float)digihits[0]->pedestal)/
261 (
float)digihits[0]->nsamples_pedestal;
262 integralDS = digihits[1]->pulse_integral - ((float)digihits[1]->nsamples_integral*(
float)digihits[1]->pedestal)/
263 (
float)digihits[1]->nsamples_pedestal;
264 peakUS = digihits[0]->pulse_peak - (float)digihits[0]->
pedestal/(
float)digihits[0]->nsamples_pedestal;
265 peakDS = digihits[1]->pulse_peak - (float)digihits[1]->
pedestal/(
float)digihits[1]->nsamples_pedestal;
267 integralDS = digihits[0]->pulse_integral - ((float)digihits[0]->nsamples_integral*(
float)digihits[0]->pedestal)/
268 (
float)digihits[0]->nsamples_pedestal;
269 integralUS = digihits[1]->pulse_integral - ((float)digihits[1]->nsamples_integral*(
float)digihits[1]->pedestal)/
270 (
float)digihits[1]->nsamples_pedestal;
271 peakDS = digihits[0]->pulse_peak - (float)digihits[0]->
pedestal/(
float)digihits[0]->nsamples_pedestal;
272 peakUS = digihits[1]->pulse_peak - (float)digihits[1]->
pedestal/(
float)digihits[1]->nsamples_pedestal;
277 float zpos = point->
z() - locBCALGeom->GetBCAL_center() + z_target_center;
278 float intratio = (float)integralUS/(
float)integralDS;
279 float logintratio = log(intratio);
280 float peakratio = (float)peakUS/(
float)peakDS;
281 float logpeakratio = log(peakratio);
282 float logEratio = log(pointEus/pointEds);
283 if (
VERBOSE>=5)
printf(
"%5llu %2i %i %i %8.1f %8.1f %8.3f %8.3f %8.3f\n",
284 (
long long unsigned int)eventnumber,module,layer,sector,integralUS,integralDS,intratio,logintratio,zpos);
287 logintratiovsZ[module-1][layer-1][sector-1]->Fill(zpos, logintratio);
288 logintratiovsZ_all->Fill(zpos, logintratio);
289 logpeakratiovsZ_all->Fill(zpos, logpeakratio);
291 sprintf(name,
"logintratiovsZ_layer%i",layer);
292 sprintf(histtitle,
"Layer %i;Z Position (cm);log of integral ratio US/DS",layer);
294 zpos, logintratio, histtitle, 500,-250.0,250.0,500,-3,3);
296 if (VERBOSEHISTOGRAMS) {
297 sprintf(name,
"logEratiovsZ_%02i%i%i",module,layer,sector);
298 sprintf(histtitle,
"Channel (M%i,L%i,S%i);Z Position (cm);log of E ratio ln(E_{US}/E_{DS}) ",module,layer,sector);
300 zpos, logEratio, histtitle, 250,-250.0,250.0,400,-4,4);
303 sprintf(name,
"logEratiovsZ_layer%i",layer);
304 sprintf(histtitle,
"Layer %i;Z Position (cm);log of E ratio ln(E_{US}/E_{DS}) ",layer);
306 zpos, logEratio, histtitle, 500,-250.0,250.0,500,-3,3);
309 if (VERBOSEHISTOGRAMS) {
310 logpeakratiovsZ[module-1][layer-1][sector-1]->Fill(zpos, logpeakratio);
313 if (VERBOSEHISTOGRAMS) EvsZ[module-1][layer-1][sector-1]->Fill(zpos, pointE);
314 EvsZ_all->Fill(zpos, pointE);
315 EvsZ_layer[layer-1]->Fill(zpos, pointE);
318 japp->RootFillUnLock(
this);
345 japp->RootFillLock(
this);
357 printf(
"BCAL_attenlength_gainratio::fini >> Fitting all histograms\n");
359 TF1 *intfit =
new TF1(
"intfit",
"pol1");
360 if (VERBOSEHISTOGRAMS) {
361 for (
int module=0; module<
nummodule; module++) {
363 for (
int sector=0; sector<
numsector; sector++) {
365 sprintf(name,
"logEratiovsZ_%02i%i%i",module+1,
layer+1,sector+1);
368 int layersect = (
layer)*4 + sector + 1;
369 int entries = hist->GetEntries();
371 hist->Fit(intfit,
"q");
372 float p0 = intfit->GetParameter(0);
373 float p1 = intfit->GetParameter(1);
377 float attenlength = -2./
p1;
378 float gainratio = exp(p0);
381 if (
VERBOSE>0)
printf(
"(%2i,%i,%i) %3i %8.3f %8.3f ", module,
layer,sector,entries,attenlength,gainratio);
384 sprintf(histtitle,
"Atten. length from E;Module;Layer and Sector");
386 module+1,layersect,attenlength, histtitle, 48,0.5,48.5,16,0.5,16.5);
387 sprintf(histtitle,
"Gain ratio from integ.;Module;Layer and Sector;G_{U}/G_{D}");
389 module+1,layersect,gainratio, histtitle, 48,0.5,48.5,16,0.5,16.5);
396 TF1 *peakfit =
new TF1(
"peakfit",
"pol1");
397 for (
int module=0; module<
nummodule; module++) {
399 for (
int sector=0; sector<
numsector; sector++) {
400 int layersect = (
layer)*4 + sector + 1;
401 int entries = logintratiovsZ[module][
layer][sector]->GetEntries();
403 logintratiovsZ[module][
layer][sector]->Fit(intfit,
"q");
404 float p0 = intfit->GetParameter(0);
405 float p1 = intfit->GetParameter(1);
406 float p0err = intfit->GetParError(0);
407 float p1err = intfit->GetParError(1);
409 float attenlength = -2./
p1;
410 float gainratio = exp(p0);
411 float attenlengtherr = 2/p1/p1*p1err;
412 float gainratioerr = exp(p0)*p0err;
413 if (
VERBOSE>0)
printf(
"(%2i,%i,%i) %3i %8.3f %8.3f ", module,
layer,sector,entries,attenlength,gainratio);
414 hist_attenlength->Fill(attenlength);
415 hist_gainratio->Fill(gainratio);
416 hist_attenlength_err->Fill(attenlengtherr);
417 hist_gainratio_err->Fill(gainratioerr);
418 hist_attenlength_relerr->Fill(attenlengtherr/attenlength*100);
419 hist_gainratio_relerr->Fill(gainratioerr/gainratio*100);
420 hist2D_intattenlength->SetBinContent(module+1,layersect,attenlength);
421 hist2D_intattenlength->SetBinError(module+1,layersect,attenlengtherr);
422 hist2D_intgainratio->SetBinContent(module+1,layersect,gainratio);
423 hist2D_intgainratio->SetBinError(module+1,layersect,gainratioerr);
425 if (VERBOSEHISTOGRAMS) {
426 logpeakratiovsZ[module][
layer][sector]->Fit(peakfit,
"q");
427 p0 = peakfit->GetParameter(0);
428 p1 = peakfit->GetParameter(1);
429 p0err = peakfit->GetParError(0);
430 p1err = peakfit->GetParError(1);
431 attenlength = -2./
p1;
433 attenlengtherr = 2/p1/p1*p1err;
434 gainratioerr = exp(p0)*p0err;
435 hist2D_peakattenlength->SetBinContent(module+1,layersect,attenlength);
436 hist2D_peakattenlength->SetBinError(module+1,layersect,attenlengtherr);
437 hist2D_peakgainratio->SetBinContent(module+1,layersect,gainratio);
438 hist2D_peakgainratio->SetBinError(module+1,layersect,gainratioerr);
439 float aveZ = EvsZ[module][
layer][sector]->GetMean(1);
440 float aveZerr = EvsZ[module][
layer][sector]->GetMeanError(1);
441 hist2D_aveZ->SetBinContent(module+1,layersect,aveZ);
442 hist2D_aveZ->SetBinError(module+1,layersect,aveZerr);
448 if (VERBOSEHISTOGRAMS) {
449 hist2D_peakattenlength->SetBinContent(0,0,1);
450 hist2D_peakgainratio->SetBinContent(0,0,1);
452 hist2D_intattenlength->SetBinContent(0,0,1);
453 hist2D_intgainratio->SetBinContent(0,0,1);
455 japp->RootFillUnLock(
this);
jerror_t init(void)
Called once at program start.
jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.
sprintf(text,"Post KinFit Cut")
static const int numsector
static const int numlayer
~JEventProcessor_BCAL_attenlength_gainratio()
JEventProcessor_BCAL_attenlength_gainratio()
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.
DGeometry * GetDGeometry(unsigned int run_number)
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
static TH1I * pedestal[nChan]
float E_DS() const
Return the attenuation corrected Energy of DS Hit.
static const int nummodule
float E_US() const
Return the attenuation corrected Energy of US Hit.
printf("string=%s", string)
bool GetTargetZ(double &z_target) const
z-location of center of target
jerror_t fini(void)
Called after last event of last event source has been processed.
int main(int argc, char *argv[])