26 #include "boost/io/ios_state.hpp"
31 #include <CLHEP/Vector/LorentzVector.h>
46 #include "TVirtualFitter.h"
48 #include "TGraphErrors.h"
49 #include "TBenchmark.h"
52 using CLHEP::HepLorentzVector;
63 m_HadDMCoeff (nullptr),
70 m_NormalizationType(
"Lin"),
71 m_NormalizationTypeNumber(0)
74 m_minimPars.emplace_back(
"PreSamplerB", 1.0, 0.5, 0.99, 20.0 );
75 m_minimPars.emplace_back(
"EMB1", 1.0, 0.5, 0.99, 20.0 );
76 m_minimPars.emplace_back(
"EMB2", 1.0, 0.5, 0.99, 20.0 );
77 m_minimPars.emplace_back(
"EMB3", 1.0, 0.5, 0.99, 20.0 );
78 m_minimPars.emplace_back(
"PreSamplerE", 1.0, 0.5, 0.99, 20.0 );
79 m_minimPars.emplace_back(
"EME1", 1.0, 0.5, 0.99, 20.0 );
80 m_minimPars.emplace_back(
"EME2", 1.0, 0.5, 0.99, 2000.0 );
81 m_minimPars.emplace_back(
"EME3", 1.0, 0.5, 0.99, 2000.0 );
82 m_minimPars.emplace_back(
"HEC0", 1.0, 0.5, 0.99, 2000.0 );
83 m_minimPars.emplace_back(
"HEC1", 1.0, 0.5, 0.99, 2000.0 );
84 m_minimPars.emplace_back(
"HEC2", 1.0, 0.5, 0.99, 20.0 );
85 m_minimPars.emplace_back(
"HEC3", 1.0, 0.5, 0.99, 20.0 );
86 m_minimPars.emplace_back(
"TileBar0", 1.0, 0.5, 0.99, 20.0 );
87 m_minimPars.emplace_back(
"TileBar1", 1.0, 0.5, 0.99, 20.0 );
88 m_minimPars.emplace_back(
"TileBar2", 1.0, 0.5, 0.99, 20.0 );
89 m_minimPars.emplace_back(
"TileGap1", 1.0, 0.5, 0.99, 20.0 );
90 m_minimPars.emplace_back(
"TileGap2", 1.0, 0.5, 0.99, 20.0 );
91 m_minimPars.emplace_back(
"TileGap3", 1.0, 0.5, 0.99, 20.0 );
92 m_minimPars.emplace_back(
"TileExt0", 1.0, 0.5, 0.99, 20.0 );
93 m_minimPars.emplace_back(
"TileExt1", 1.0, 0.5, 0.99, 20.0 );
94 m_minimPars.emplace_back(
"TileExt2", 1.0, 0.5, 0.99, 20.0 );
95 m_minimPars.emplace_back(
"FCAL0", 1.0, 0.01, 0.99, 3.0 );
96 m_minimPars.emplace_back(
"FCAL1", 1.0, 0.01, 0.99, 3.0 );
97 m_minimPars.emplace_back(
"FCAL2", 1.0, 0.5, 0.99, 20.0 );
98 m_minimPars.emplace_back(
"MINIFCAL0", 1.0, 0.5, 0.99, 20.0 );
99 m_minimPars.emplace_back(
"MINIFCAL1", 1.0, 0.5, 0.99, 20.0 );
100 m_minimPars.emplace_back(
"MINIFCAL2", 1.0, 0.5, 0.99, 20.0 );
101 m_minimPars.emplace_back(
"MINIFCAL3", 1.0, 0.5, 0.99, 20.0 );
102 m_minimPars.emplace_back(
"CONST", 0.0, 10., 0.0, 5000. );
123 std::cout << std::endl;
124 std::cout << std::endl;
125 std::cout <<
"--- CaloHadDMCoeffMinim::process() --- " << std::endl;
127 if(
m_isTestbeam) std::cout <<
"Processing TESTBEAM data" << std::endl;
130 std::cout <<
"Using weighting proportional to E_calib" << std::endl;
133 std::cout <<
"Using weighting proportional to log(E_calib)" << std::endl;
136 std::cout <<
"Using weighting proportional to 1/N_Clus_E_calib>0" << std::endl;
139 std::cout <<
"Using constant weighting" << std::endl;
167 std::cout <<
"CaloHadDMCoeffMinim::process -> Error! No entries in DeadMaterialTree." << std::endl;
173 std::cout <<
"CaloHadDMCoeffFit::process -> Error! Different numbers of areas for DM definition" << std::endl;
181 std::cout <<
"CaloHadDMCoeffMinim::process() -> Info. Preparing for '" << dmArea->
getTitle() <<
" index:" <<
m_area_index
182 <<
" npars:" << dmArea->
getNpars() <<
", for minimization:" <<
m_validNames.size() << std::endl;
184 std::cout <<
"CaloHadDMCoeffMinim::process() -> FATAL! Number of parameters for dead material area is different from number of mininuit pars." << std::endl;
193 std::cout <<
"CaloHadDMCoeffMinim::process() -> Info. Step 2 - making cluster set..." << std::endl;
201 if(i_ev%20000==0) std::cout <<
" i_ev: " << i_ev <<
" (" << nGoodEvents <<
") '" << ((TChain *)
m_data->
fChain)->GetFile()->GetName() <<
"'" << std::endl;
203 double EnergyResolution;
213 bool GoodClusterFound(
false);
215 HepLorentzVector hlv_pion(1,0,0,1);
218 HepLorentzVector hlv_cls(1,0,0,1);
220 double r = hlv_pion.angle(hlv_cls.vect());
225 GoodClusterFound =
true;
230 if(!GoodClusterFound)
continue;
239 std::vector<float> vars;
244 auto ev = std::make_unique<MinimSample>();
248 if(
ev->edmtrue<0)
ev->edmtrue=0.0;
256 double clus_weight = 1.0;
260 ev->weight = clus_weight;
263 ev->sigma2 = EnergyResolution*EnergyResolution;
276 std::cout <<
"CaloHadDMCoeffMinim::process() -> Info. Starting minimization, m_minimSample.size(): " <<
m_minimSample.size() <<
"( " <<
float(
m_minimSample.size())*(26.0/1
e+06) <<
" Mb)"<< std::endl;
277 for(
int i_data=0; i_data<dmArea->
getLength(); i_data++) {
279 mb.Start(
"minuitperf");
289 std::vector<int > indexes;
291 std::cout <<
"==============================================================================" << std::endl;
292 std::cout <<
"run " << i_data
336 for(
unsigned int i_par=0; i_par<
m_minimPars.size(); i_par++){
344 TVirtualFitter::SetDefaultFitter(
"Minuit");
345 TVirtualFitter * minuit = TVirtualFitter::Fitter(
nullptr,
m_minimPars.size());
346 for(
unsigned int i_par=0; i_par<
m_minimPars.size(); i_par++){
348 minuit->SetParameter(i_par,
par->name.c_str(),
par->initVal,
par->initErr,
par->lowerLim,
par->upperLim);
349 if(
par->fixIt ) minuit->FixParameter(i_par);
356 minuit->ExecuteCommand(
"SET PRINT",arglist,2);
361 minuit->ExecuteCommand(
"MIGRAD",arglist,2);
364 std::cout <<
"Minuit results:" << std::endl;
365 for(
unsigned int i_par=0; i_par<
m_minimPars.size(); i_par++){
366 m_minimPars[i_par].value = minuit->GetParameter(i_par);
367 m_minimPars[i_par].error = minuit->GetParError(i_par);
368 std::cout <<
" i_par:" << i_par <<
" '" <<
m_minimPars[i_par].name <<
"' val:" << minuit->GetParameter(i_par) <<
" err:" << minuit->GetParError(i_par) << std::endl;
374 mb.Stop(
"minuitperf");
375 std::cout <<
"CPU: " <<
mb.GetCpuTime(
"minuitperf") << std::endl;
382 std::cout <<
"CaloHadDMCoeffMinim::process() -> Info. Making output coefficients set " << std::endl;
384 for (std::pair<
const int, std::vector<MinimPar > >&
p :
m_minimResults) {
390 boost::io::ios_base_all_saver coutsave (std::cout);
391 std::cout << std::fixed << std::setprecision(3) << iBin <<
" ";
392 for(
unsigned int i_par = 0; i_par<
m_minimPars.size(); i_par++){
397 std::cout << std::endl;
400 std::vector<int > indexes;
405 if( (fabs(
eta)>2.9 && fabs(
eta)<3.15)) {
410 if( fabs(
eta) > 3.25) {
421 return newHadDMCoeff;
431 std::cout <<
"CaloHadDMCoeffMinim::make_report() -> Info. Making report..." << std::endl;
432 gStyle->SetCanvasColor(10);
433 gStyle->SetCanvasBorderMode(0);
434 gStyle->SetPadColor(10);
435 gStyle->SetPadBorderMode(0);
436 gStyle->SetPalette(1);
437 gStyle->SetTitleBorderSize(1);
438 gStyle->SetTitleFillColor(10);
439 int cc_xx = 768, cc_yy = 1024;
440 gROOT->SetBatch(kTRUE);
442 std::string sfname = sreport;
443 TCanvas *ctmp =
new TCanvas(
"ctmp",
"ctmp", cc_xx, cc_yy);
445 ctmp->Print(sfname.c_str());
450 TLatex *tex =
new TLatex(); tex->SetNDC();
459 for(
int i_frac=0; i_frac<dimFrac->
getNbins(); i_frac++){
460 for(
int i_ener=0; i_ener<dimEner->
getNbins(); i_ener++){
461 for(
int i_lambda=0; i_lambda<dimLambda->
getNbins(); i_lambda++){
462 for(
int i_side=0; i_side<dimSide->
getNbins(); i_side++){
463 for(
int i_phi=0; i_phi<dimPhi->
getNbins(); i_phi++){
464 const std::string cname =
std::format(
"c1_dmfcal_minuit_weights_frac{}_ener{}_lambda{}_phi{}_side{}",
465 i_frac, i_ener, i_lambda, i_phi, i_side);
466 TCanvas *c1_weights =
new TCanvas(cname.c_str(), cname.c_str(), cc_xx, cc_yy);
468 TPad *pad1=
nullptr, *pad2=
nullptr;
470 pad1 =
new TPad(
"p1ps",
"p1ps",0.0, y_edge, 1.0, 1.0); pad1->Draw();
471 pad2 =
new TPad(
"p2ps",
"p2ps",0.0, 0.0, 1.0, y_edge); pad2->Draw();
473 pad1->cd(); gPad->SetGrid(); gPad->SetLeftMargin(0.07); gPad->SetTopMargin(0.05); gPad->SetRightMargin(0.05); gPad->SetBottomMargin(0.08);
474 std::string
str =
std::format(
"frac:{} ener:{} lambda:{} phi:{} side:{}",
475 i_frac, i_ener, i_lambda, i_phi, i_side);
476 tex->SetTextColor(1); tex->SetTextSize(0.20); tex->DrawLatex(0.1,0.4,
str.c_str());
480 pad2->cd(i_canvas+1);
483 for(
int i_eta=0; i_eta<dimEta->
getNbins(); i_eta++){
484 std::vector<int > v_indx;
496 gr->SetPoint(i_eta, xx,
w);
499 gr->SetTitle(
str.c_str());
502 for(
unsigned int i_par=0; i_par<
m_minimPars.size(); i_par++){
503 std::vector<float> vx;
504 std::vector<float> vy;
505 std::vector<float> vye;
506 for(
int i_eta=0; i_eta<dimEta->
getNbins(); i_eta++){
507 std::vector<int > v_indx;
517 vx.push_back(dimEta->
getXmin() + dimEta->
getDx()*i_eta);
523 TGraphErrors *
gr =
new TGraphErrors(dimEta->
getNbins());
524 for(
unsigned int i_p=0; i_p<vx.size(); i_p++){
525 gr->SetPoint(i_p, vx[i_p], vy[i_p]);
526 gr->SetPointError(i_p, 0.0, vye[i_p]);
528 pad2->cd(i_canvas+1);
537 c1_weights->Print(sfname.c_str());
546 ctmp->Print(sfname.c_str());
561 double sum_edm_rec = 0.0;
562 double sum_edm_true = 0.0;
564 double edm_rec = 0.0;
565 double edm_true =
event->edmtrue;
567 edm_rec += (
par[i_smp] - 1.0) * (
double)(
event->clsm_smp_energy_unw[i_smp]);
573 edm_rec = edm_rec/
GeV;
574 edm_true = edm_true/
GeV;
576 sum_edm_rec += edm_rec/(
event->sigma2 );
577 sum_edm_true += edm_true/(
event->sigma2 );
578 hi2 += (
event->weight*(edm_rec - edm_true)*(edm_rec - edm_true)/(
event->sigma2 ) );
583 std::cout <<
"nsel == 0 ! PANIC!" << std::endl;
589 <<
") sum_edm_rec:" << sum_edm_rec/
float(nsel)
590 <<
" sum_edm_true:" << sum_edm_true/
float(nsel)
594 for(
unsigned int i_par=0; i_par<
m_minimPars.size(); i_par++){
595 if( !
m_minimPars[i_par].fixIt ) std::cout <<
"( " << i_par <<
" " <<
m_minimPars[i_par].name <<
" " <<
par[i_par] <<
")";
597 std::cout << std::endl;