18ElectronCalibration::ElectronCalibration( TString infile, TString constfile,
int mcFlag,
int type,
int fits,
int docabins,
double upperdoca,
double lowerdoca,
int entabins,
double upperenta,
double lowerenta,
int costhbins ) :
20 m_constfilename(constfile),
25 m_upperdoca(upperdoca),
26 m_lowerdoca(lowerdoca),
28 m_upperenta(upperenta),
29 m_lowerenta(lowerenta),
30 m_costhbins(costhbins)
39 TFile* infile =
new TFile(m_filename);
40 TTree*
electron = (TTree*)infile->Get(
"track");
42 std::cout <<
"ElectronCalibration: getting run gains for file " << m_filename << std::endl;
59 electron->SetBranchAddress(
"run", &run);
60 electron->SetBranchAddress(
"dedxsat", &dedx);
61 electron->SetBranchAddress(
"costh", &costh);
64 electron->SetBranchAddress(
"numGoodHits", &b3nhit);
65 else if( m_type == 1 )
66 electron->SetBranchAddress(
"numGoodLayerHits", &b2nhit);
74 TTree* satTree =
new TTree(
"electron",
"dE/dx means and errors");
82 satTree->Branch(
"run",&fitrun,
"run/I");
83 satTree->Branch(
"dedx",&fitmean,
"dedx/D");
84 satTree->Branch(
"dedxerr",&fitmeanerr,
"dedxerr/D");
85 satTree->Branch(
"width",&fitwidth,
"width/D");
86 satTree->Branch(
"widtherr",&fitwidtherr,
"widtherr/D");
89 TH1F* hdedx_run =
new TH1F(
"dedx_run",
"dedx_run",200,0,2);
92 std::map<int, double> m_rungains;
96 int nentries =
electron->GetEntries();
97 for(
unsigned int index = 0; index < nentries; ++index ){
102 nhit = std::floor(b3nhit);
103 else if( m_type == 1 )
107 if( nhit < 0 || nhit > 100 || dedx <= 0 || costh != costh )
110 if( lastrun == -1 ) lastrun = run;
112 if( run == lastrun && index < (nentries-1) ) hdedx_run->Fill(dedx);
114 if( hdedx_run->Integral() < 50 ){
122 hdedx_run->Fit(
"gaus",
"ql");
123 fitmean = hdedx_run->GetFunction(
"gaus")->GetParameter(1);
124 fitmeanerr = hdedx_run->GetFunction(
"gaus")->GetParError(1);
125 fitwidth = hdedx_run->GetFunction(
"gaus")->GetParameter(2);
126 fitwidtherr = hdedx_run->GetFunction(
"gaus")->GetParError(2);
129 m_rungains[fitrun] = fitmean;
132 hdedx_run->Fill(dedx);
174 std::cout <<
"ElectronCalibration: plotting run gains for file " << m_filename << std::endl;
176 TFile* infile =
new TFile(filename);
177 TTree* intree = (TTree*)infile->Get(
"electron");
179 intree->Project(
"rungains",
"dedx:run");
180 TH1F* rungains = (TH1F*)infile->Get(
"rungains");
181 intree->Project(
"runsigma",
"dedx:width");
182 TH1F* runsigma = (TH1F*)infile->Get(
"runsigma");
184 TCanvas* can =
new TCanvas(
"electrons",
"",1200,600);
187 rungains->SetTitle(
";Run number;dE/dx");
191 runsigma->SetTitle(
";Run number;dE/dx #sigma");
193 can->SaveAs(
"plots/rungains.eps");
203 std::cout <<
"ElectronCalibration: reading in file " << m_filename << std::endl;
205 TFile* infile =
new TFile(m_filename);
206 TTree* track = (TTree*)infile->Get(
"track");
212 int kMaxEntries = 100;
213 double doca[kMaxEntries];
214 double enta[kMaxEntries];
215 double dedxhit[kMaxEntries];
224 track->SetBranchAddress(
"doca", doca);
225 track->SetBranchAddress(
"enta", enta);
226 track->SetBranchAddress(
"dedxhit", dedxhit);
229 track->SetBranchAddress(
"numGoodHits", &b3nhit);
230 else if( m_type == 1 )
231 track->SetBranchAddress(
"numGoodLayerHits", &b2nhit);
233 double docastep = (m_upperdoca-m_lowerdoca)/m_docabins;
234 double entastep[m_entabins];
241 TH1F* totalenta =
new TH1F(
"totalenta",
"",314,0,0.785);
242 for(
unsigned int index = 0; index < track->GetEntries(); ++index ){
243 track->GetEvent(index);
246 nhits = std::floor(b3nhit);
247 else if( m_type == 1 )
249 for(
int hit = 0; hit <
nhits; ++hit ){
252 if( enta[hit] >
PI/4.0 ) enta[hit] -=
PI/2.0;
253 else if( enta[hit] < -1.0*
PI/4.0 ) enta[hit] +=
PI/2.0;
254 totalenta->Fill(std::abs(enta[hit]));
257 entastep[0] = -0.785;
258 entastep[39] = 0.785;
259 int bin = 20;
int binmin = 1;
260 double total = totalenta->Integral()*2.0/(m_entabins+1);
261 for(
int i = 2; i <= 314; ++i ){
262 if( totalenta->Integral(binmin,i) >= total ){
263 entastep[
bin] = 0.0025*i;
268 for(
int i = 0; i < m_entabins; ++i ){
269 if( i > 0 && i < 20 ) entastep[i] = -1.0*entastep[39-i];
276 TTree* outTree =
new TTree(
"electrons",
"2D means and errors");
283 outTree->Branch(
"doca",&satdoca,
"doca/D");
284 outTree->Branch(
"enta",&satenta,
"enta/D");
285 outTree->Branch(
"dedx",&satdedx,
"dedx/D");
286 outTree->Branch(
"error",&saterror,
"error/D");
288 TH2F* twod =
new TH2F(
"twod",
"",m_docabins,m_lowerdoca,m_upperdoca,m_entabins,m_lowerenta,m_upperenta);
296 std::vector<double> docaent[m_docabins][m_entabins];
297 int docaenthits[m_docabins][m_entabins];
298 for(
int i = 0; i < m_docabins; ++i ){
299 for(
int j = 0; j < m_docabins; ++j ){
300 docaent[i][j].clear();
301 docaenthits[i][j] = 0;
305 for(
unsigned int index = 0; index < track->GetEntries(); ++index ){
306 track->GetEvent(index);
309 nhits = std::floor(b3nhit);
310 else if( m_type == 1 )
312 for(
int hit = 0; hit <
nhits; ++hit ){
315 if( enta[hit] >
PI/4.0 ) enta[hit] -=
PI/2.0;
316 else if( enta[hit] < -1.0*
PI/4.0 ) enta[hit] +=
PI/2.0;
318 if( doca[hit] > m_upperdoca || doca[hit] < m_lowerdoca )
continue;
319 if( enta[hit] > m_upperenta || enta[hit] < m_lowerenta )
continue;
321 int docaBin = (int)((doca[hit]-m_lowerdoca)/(m_upperdoca-m_lowerdoca) * m_docabins);
322 int entaBin = (int)((enta[hit]-m_lowerenta)/(m_upperenta-m_lowerenta) * m_entabins);
324 docaent[docaBin][entaBin].push_back(dedxhit[hit]);
325 docaenthits[docaBin][entaBin]++;
331 for(
int i = 0; i < m_docabins; ++i ){
332 for(
int j = 0; j < m_entabins; ++j ){
335 satdoca = m_lowerdoca+0.5*docastep+i*docastep;
336 satenta = m_lowerenta+0.5*entastep[j]+j*entastep[j];
339 ecor.
calculateMeans(tmean,satdedx,saterror,docaent[i][j],docaenthits[i][j]);
340 twod->SetBinContent(i,j,satdedx);
342 std::cout << i <<
"\t" << j <<
"\t" << satdedx <<
"\t" << saterror << std::endl;
357 TH1F* hdoca_enta[m_docabins][m_entabins];
360 for(
int i = 0; i < m_docabins; ++i ){
361 for(
int j = 0; j < m_entabins; ++j ){
363 sprintf(histname,
"doca_%d_enta_%d",i,j);
365 hdoca_enta[i][j] =
new TH1F(histname,histname,200,0,200);
370 for(
unsigned int index = 0; index < track->GetEntries(); ++index ){
371 track->GetEvent(index);
374 nhits = std::floor(b3nhit);
375 else if( m_type == 1 )
377 for(
int hit = 0; hit <
nhits; ++hit ){
380 if( enta[hit] >
PI/4.0 ) enta[hit] -=
PI/2.0;
381 else if( enta[hit] < -1.0*
PI/4.0 ) enta[hit] +=
PI/2.0;
383 if( doca[hit] > m_upperdoca || doca[hit] < m_lowerdoca )
continue;
384 if( enta[hit] > m_upperenta || enta[hit] < m_lowerenta )
continue;
386 int docaBin = (int)((doca[hit]-m_lowerdoca)/(m_upperdoca-m_lowerdoca) * m_docabins);
387 int entaBin = (int)((enta[hit]-m_lowerenta)/(m_upperenta-m_lowerenta) * m_entabins);
389 hdoca_enta[docaBin][entaBin]->Fill(dedxhit[hit]);
400 for(
int i = 0; i < m_docabins; ++i ){
401 for(
int j = 0; j < m_entabins; ++j ){
404 satdoca = m_lowerdoca+0.5*docastep+i*docastep;
405 satenta = m_lowerenta+0.5*entastep[j]+j*entastep[j];
408 fs = hdoca_enta[i][j]->Fit(
"landau",
"ql");
409 double mean = hdoca_enta[i][j]->GetFunction(
"landau")->GetParameter(1);
410 double width = hdoca_enta[i][j]->GetFunction(
"landau")->GetParameter(2);
412 fs = hdoca_enta[i][j]->Fit(
"landau",
"ql");
415 satdedx = hdoca_enta[i][j]->GetFunction(
"landau")->GetParameter(1);
416 saterror = hdoca_enta[i][j]->GetFunction(
"landau")->GetParError(1);
418 if( fs == 0 ) twod->SetBinContent(i,j,satdedx);
424 if( fs1 != 0 ) std::cout <<
"\t\t" <<
"MEAN FITS FAILED: " << fs1 << std::endl;
428 TCanvas* ctmp =
new TCanvas(
"tmp",
"tmp",900,900);
430 std::stringstream psname; psname <<
"plots/twoDFits.ps[";
431 ctmp->Print(psname.str().c_str());
432 psname.str(
""); psname <<
"plots/twoDFits.ps";
433 for(
int i = 0 ; i < m_docabins; ++i ){
434 for(
int j = 0; j < m_entabins; ++j ){
436 hdoca_enta[i][j]->Draw();
438 ctmp->Print(psname.str().c_str());
441 psname.str(
""); psname <<
"plots/twoDFits.ps]";
442 ctmp->Print(psname.str().c_str());
445 for(
int i = 0; i < m_docabins; ++i ){
446 for(
int j = 0; j < m_entabins; ++j ){
447 delete hdoca_enta[i][j];
463 TFile* infile =
new TFile(m_filename);
464 TTree*
electron = (TTree*)infile->Get(
"track");
466 std::cout <<
"ElectronCalibration: electron saturation correction " << m_filename << std::endl;
483 electron->SetBranchAddress(
"run", &run);
484 electron->SetBranchAddress(
"dedx", &dedxpub);
485 electron->SetBranchAddress(
"dedxsat", &dedx);
486 electron->SetBranchAddress(
"costh", &costh);
489 electron->SetBranchAddress(
"numGoodHits", &b3nhit);
490 else if( m_type == 1 )
491 electron->SetBranchAddress(
"numGoodLayerHits", &b2nhit);
499 TTree* satTree =
new TTree(
"electron",
"saturation correction");
507 satTree->Branch(
"costh",&costhbin,
"costh/D");
508 satTree->Branch(
"dedx",&fitmean,
"dedx/D");
509 satTree->Branch(
"dedxerr",&fitmeanerr,
"dedxerr/D");
510 satTree->Branch(
"width",&fitwidth,
"width/D");
511 satTree->Branch(
"widtherr",&fitwidtherr,
"widtherr/D");
514 TH1F* hdedx_costh[m_costhbins];
515 for(
int i = 0; i < m_costhbins; ++i ){
516 hdedx_costh[i] =
new TH1F(TString::Format(
"dedx_costh%i",i),
";dE/dx;cos(#theta)",200,0,2);
520 for(
unsigned int index = 0; index <
electron->GetEntries(); ++index ){
525 nhit = std::floor(b3nhit);
526 else if( m_type == 1 )
530 if( nhit < 0 || nhit > 100 || dedx <= 0 || costh != costh )
533 int bin = floor((costh+1.0)/2*m_costhbins);
534 hdedx_costh[
bin]->Fill(dedxpub);
538 for(
unsigned int i = 0; i < m_costhbins; ++i ){
539 costhbin = (2.0*i+1)/m_costhbins-1;
540 hdedx_costh[i]->Fit(
"gaus",
"ql");
541 fitmean = hdedx_costh[i]->GetFunction(
"gaus")->GetParameter(1);
542 fitmeanerr = hdedx_costh[i]->GetFunction(
"gaus")->GetParError(1);
543 fitwidth = hdedx_costh[i]->GetFunction(
"gaus")->GetParameter(2);
544 fitwidtherr = hdedx_costh[i]->GetFunction(
"gaus")->GetParError(2);
549 satTree->Project(
"satmean",
"dedx:costh");
550 TH1F* satmean = (TH1F*)outfile->Get(
"satmean");
551 satmean->SetStats(0);
552 satTree->Project(
"satsigma",
"width:costh");
553 TH1F* satsigma = (TH1F*)outfile->Get(
"satsigma");
554 satsigma->SetStats(0);
556 TCanvas* can =
new TCanvas(
"electrons",
"",1200,600);
559 satmean->SetTitle(
";cos(#theta);dE/dx");
563 satsigma->SetTitle(
";cos(#theta);dE/dx sigma");
565 can->SaveAs(
"plots/satmean.eps");
567 for(
int i = 0; i < m_costhbins; ++i ){
568 delete hdedx_costh[i];
*******INTEGER m_nBinMax INTEGER m_NdiMax !No of bins in histogram for cell exploration division $ !Last vertex $ !Last active cell $ !Last cell in buffer $ !No of sampling when dividing cell $ !No of function total $ !Flag for random ceel for $ !Flag for type of for WtMax $ !Flag which decides whether vertices are included in the sampling $ entire domain is hyp !Maximum effective eevents per bin
void fitRunGains(TFile *outfile)
void TwoDCorrection(TFile *outfile)
void plotRunGains(TString filename)
void SaturationCorrection(TFile *oufile)
void calculateMeans(double &mean, double &truncatedMean, double &truncatedMeanErr, double dedx[], int size) const
sprintf(cut,"kal_costheta0_em>-0.93&&kal_costheta0_em<0.93&&kal_pxy0_em>=0.05+%d*0.1&&kal_pxy0_em<0.15+%d*0.1&&NGch>=2", j, j)