27 #include "boost/io/ios_state.hpp"
34 #include <CLHEP/Vector/LorentzVector.h>
49 #include "TVirtualFitter.h"
51 #include "TGraphErrors.h"
52 #include "TBenchmark.h"
55 using CLHEP::HepLorentzVector;
66 m_HadDMCoeff (nullptr),
73 m_NormalizationType(
"Lin"),
74 m_NormalizationTypeNumber(0)
77 m_minimPars.emplace_back(
"PreSamplerB", 1.0, 0.5, 0.99, 20.0 );
78 m_minimPars.emplace_back(
"EMB1", 1.0, 0.5, 0.99, 20.0 );
79 m_minimPars.emplace_back(
"EMB2", 1.0, 0.5, 0.99, 20.0 );
80 m_minimPars.emplace_back(
"EMB3", 1.0, 0.5, 0.99, 20.0 );
81 m_minimPars.emplace_back(
"PreSamplerE", 1.0, 0.5, 0.99, 20.0 );
82 m_minimPars.emplace_back(
"EME1", 1.0, 0.5, 0.99, 20.0 );
83 m_minimPars.emplace_back(
"EME2", 1.0, 0.5, 0.99, 2000.0 );
84 m_minimPars.emplace_back(
"EME3", 1.0, 0.5, 0.99, 2000.0 );
85 m_minimPars.emplace_back(
"HEC0", 1.0, 0.5, 0.99, 2000.0 );
86 m_minimPars.emplace_back(
"HEC1", 1.0, 0.5, 0.99, 2000.0 );
87 m_minimPars.emplace_back(
"HEC2", 1.0, 0.5, 0.99, 20.0 );
88 m_minimPars.emplace_back(
"HEC3", 1.0, 0.5, 0.99, 20.0 );
89 m_minimPars.emplace_back(
"TileBar0", 1.0, 0.5, 0.99, 20.0 );
90 m_minimPars.emplace_back(
"TileBar1", 1.0, 0.5, 0.99, 20.0 );
91 m_minimPars.emplace_back(
"TileBar2", 1.0, 0.5, 0.99, 20.0 );
92 m_minimPars.emplace_back(
"TileGap1", 1.0, 0.5, 0.99, 20.0 );
93 m_minimPars.emplace_back(
"TileGap2", 1.0, 0.5, 0.99, 20.0 );
94 m_minimPars.emplace_back(
"TileGap3", 1.0, 0.5, 0.99, 20.0 );
95 m_minimPars.emplace_back(
"TileExt0", 1.0, 0.5, 0.99, 20.0 );
96 m_minimPars.emplace_back(
"TileExt1", 1.0, 0.5, 0.99, 20.0 );
97 m_minimPars.emplace_back(
"TileExt2", 1.0, 0.5, 0.99, 20.0 );
98 m_minimPars.emplace_back(
"FCAL0", 1.0, 0.01, 0.99, 3.0 );
99 m_minimPars.emplace_back(
"FCAL1", 1.0, 0.01, 0.99, 3.0 );
100 m_minimPars.emplace_back(
"FCAL2", 1.0, 0.5, 0.99, 20.0 );
101 m_minimPars.emplace_back(
"MINIFCAL0", 1.0, 0.5, 0.99, 20.0 );
102 m_minimPars.emplace_back(
"MINIFCAL1", 1.0, 0.5, 0.99, 20.0 );
103 m_minimPars.emplace_back(
"MINIFCAL2", 1.0, 0.5, 0.99, 20.0 );
104 m_minimPars.emplace_back(
"MINIFCAL3", 1.0, 0.5, 0.99, 20.0 );
105 m_minimPars.emplace_back(
"CONST", 0.0, 10., 0.0, 5000. );
126 std::cout << std::endl;
127 std::cout << std::endl;
128 std::cout <<
"--- CaloHadDMCoeffMinim::process() --- " << std::endl;
130 if(
m_isTestbeam) std::cout <<
"Processing TESTBEAM data" << std::endl;
133 std::cout <<
"Using weighting proportional to E_calib" << std::endl;
136 std::cout <<
"Using weighting proportional to log(E_calib)" << std::endl;
139 std::cout <<
"Using weighting proportional to 1/N_Clus_E_calib>0" << std::endl;
142 std::cout <<
"Using constant weighting" << std::endl;
170 std::cout <<
"CaloHadDMCoeffMinim::process -> Error! No entries in DeadMaterialTree." << std::endl;
176 std::cout <<
"CaloHadDMCoeffFit::process -> Error! Different numbers of areas for DM definition" << std::endl;
184 std::cout <<
"CaloHadDMCoeffMinim::process() -> Info. Preparing for '" << dmArea->
getTitle() <<
" index:" <<
m_area_index
185 <<
" npars:" << dmArea->
getNpars() <<
", for minimization:" <<
m_validNames.size() << std::endl;
187 std::cout <<
"CaloHadDMCoeffMinim::process() -> FATAL! Number of parameters for dead material area is different from number of mininuit pars." << std::endl;
196 std::cout <<
"CaloHadDMCoeffMinim::process() -> Info. Step 2 - making cluster set..." << std::endl;
204 if(i_ev%20000==0) std::cout <<
" i_ev: " << i_ev <<
" (" << nGoodEvents <<
") '" << ((TChain *)
m_data->
fChain)->GetFile()->GetName() <<
"'" << std::endl;
206 double EnergyResolution;
216 bool GoodClusterFound(
false);
218 HepLorentzVector hlv_pion(1,0,0,1);
221 HepLorentzVector hlv_cls(1,0,0,1);
223 double r = hlv_pion.angle(hlv_cls.vect());
228 GoodClusterFound =
true;
233 if(!GoodClusterFound)
continue;
242 std::vector<float> vars;
247 auto ev = std::make_unique<MinimSample>();
251 if(
ev->edmtrue<0)
ev->edmtrue=0.0;
259 double clus_weight = 1.0;
263 ev->weight = clus_weight;
266 ev->sigma2 = EnergyResolution*EnergyResolution;
279 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;
280 for(
int i_data=0; i_data<dmArea->
getLength(); i_data++) {
282 mb.Start(
"minuitperf");
292 std::vector<int > indexes;
294 std::cout <<
"==============================================================================" << std::endl;
295 std::cout <<
"run " << i_data
339 for(
unsigned int i_par=0; i_par<
m_minimPars.size(); i_par++){
347 TVirtualFitter::SetDefaultFitter(
"Minuit");
348 TVirtualFitter * minuit = TVirtualFitter::Fitter(
nullptr,
m_minimPars.size());
349 for(
unsigned int i_par=0; i_par<
m_minimPars.size(); i_par++){
351 minuit->SetParameter(i_par,
par->name.c_str(),
par->initVal,
par->initErr,
par->lowerLim,
par->upperLim);
352 if(
par->fixIt ) minuit->FixParameter(i_par);
359 minuit->ExecuteCommand(
"SET PRINT",arglist,2);
364 minuit->ExecuteCommand(
"MIGRAD",arglist,2);
367 std::cout <<
"Minuit results:" << std::endl;
368 for(
unsigned int i_par=0; i_par<
m_minimPars.size(); i_par++){
369 m_minimPars[i_par].value = minuit->GetParameter(i_par);
370 m_minimPars[i_par].error = minuit->GetParError(i_par);
371 std::cout <<
" i_par:" << i_par <<
" '" <<
m_minimPars[i_par].name <<
"' val:" << minuit->GetParameter(i_par) <<
" err:" << minuit->GetParError(i_par) << std::endl;
377 mb.Stop(
"minuitperf");
378 std::cout <<
"CPU: " <<
mb.GetCpuTime(
"minuitperf") << std::endl;
385 std::cout <<
"CaloHadDMCoeffMinim::process() -> Info. Making output coefficients set " << std::endl;
387 for (std::pair<
const int, std::vector<MinimPar > >&
p :
m_minimResults) {
393 boost::io::ios_base_all_saver coutsave (std::cout);
394 std::cout << std::fixed << std::setprecision(3) << iBin <<
" ";
395 for(
unsigned int i_par = 0; i_par<
m_minimPars.size(); i_par++){
400 std::cout << std::endl;
403 std::vector<int > indexes;
408 if( (fabs(
eta)>2.9 && fabs(
eta)<3.15)) {
413 if( fabs(
eta) > 3.25) {
424 return newHadDMCoeff;
434 std::cout <<
"CaloHadDMCoeffMinim::make_report() -> Info. Making report..." << std::endl;
435 gStyle->SetCanvasColor(10);
436 gStyle->SetCanvasBorderMode(0);
437 gStyle->SetPadColor(10);
438 gStyle->SetPadBorderMode(0);
439 gStyle->SetPalette(1);
440 gStyle->SetTitleBorderSize(1);
441 gStyle->SetTitleFillColor(10);
442 int cc_xx = 768, cc_yy = 1024;
445 gROOT->SetBatch(kTRUE);
447 std::string sfname = sreport;
448 TCanvas *ctmp =
new TCanvas(
"ctmp",
"ctmp", cc_xx, cc_yy);
450 ctmp->Print(sfname.c_str());
455 TLatex *tex =
new TLatex(); tex->SetNDC();
464 for(
int i_frac=0; i_frac<dimFrac->
getNbins(); i_frac++){
465 for(
int i_ener=0; i_ener<dimEner->
getNbins(); i_ener++){
466 for(
int i_lambda=0; i_lambda<dimLambda->
getNbins(); i_lambda++){
467 for(
int i_side=0; i_side<dimSide->
getNbins(); i_side++){
468 for(
int i_phi=0; i_phi<dimPhi->
getNbins(); i_phi++){
469 sprintf(cname,
"c1_dmfcal_minuit_weights_frac%d_ener%d_lambda%d_phi%d_side%d",i_frac, i_ener, i_lambda, i_phi, i_side);
470 TCanvas *c1_weights =
new TCanvas(cname, cname, cc_xx, cc_yy);
472 TPad *pad1=
nullptr, *pad2=
nullptr;
474 pad1 =
new TPad(
"p1ps",
"p1ps",0.0, y_edge, 1.0, 1.0); pad1->Draw();
475 pad2 =
new TPad(
"p2ps",
"p2ps",0.0, 0.0, 1.0, y_edge); pad2->Draw();
477 pad1->cd(); gPad->SetGrid(); gPad->SetLeftMargin(0.07); gPad->SetTopMargin(0.05); gPad->SetRightMargin(0.05); gPad->SetBottomMargin(0.08);
478 sprintf(
str,
"frac:%d ener:%d lambda:%d phi:%d side:%d",i_frac, i_ener, i_lambda, i_phi, i_side);
479 tex->SetTextColor(1); tex->SetTextSize(0.20); tex->DrawLatex(0.1,0.4,
str);
483 pad2->cd(i_canvas+1);
486 for(
int i_eta=0; i_eta<dimEta->
getNbins(); i_eta++){
487 std::vector<int > v_indx;
499 gr->SetPoint(i_eta, xx,
w);
502 sprintf(
str,
"Sample size %d",
int(smpsize));
506 for(
unsigned int i_par=0; i_par<
m_minimPars.size(); i_par++){
507 std::vector<float> vx;
508 std::vector<float> vy;
509 std::vector<float> vye;
510 for(
int i_eta=0; i_eta<dimEta->
getNbins(); i_eta++){
511 std::vector<int > v_indx;
521 vx.push_back(dimEta->
getXmin() + dimEta->
getDx()*i_eta);
527 TGraphErrors *
gr =
new TGraphErrors(dimEta->
getNbins());
528 for(
unsigned int i_p=0; i_p<vx.size(); i_p++){
529 gr->SetPoint(i_p, vx[i_p], vy[i_p]);
530 gr->SetPointError(i_p, 0.0, vye[i_p]);
532 pad2->cd(i_canvas+1);
541 c1_weights->Print(sfname.c_str());
550 ctmp->Print(sfname.c_str());
565 double sum_edm_rec = 0.0;
566 double sum_edm_true = 0.0;
568 double edm_rec = 0.0;
569 double edm_true =
event->edmtrue;
571 edm_rec += (
par[i_smp] - 1.0) * (
double)(
event->clsm_smp_energy_unw[i_smp]);
577 edm_rec = edm_rec/
GeV;
578 edm_true = edm_true/
GeV;
580 sum_edm_rec += edm_rec/(
event->sigma2 );
581 sum_edm_true += edm_true/(
event->sigma2 );
582 hi2 += (
event->weight*(edm_rec - edm_true)*(edm_rec - edm_true)/(
event->sigma2 ) );
587 std::cout <<
"nsel == 0 ! PANIC!" << std::endl;
593 <<
") sum_edm_rec:" << sum_edm_rec/
float(nsel)
594 <<
" sum_edm_true:" << sum_edm_true/
float(nsel)
598 for(
unsigned int i_par=0; i_par<
m_minimPars.size(); i_par++){
599 if( !
m_minimPars[i_par].fixIt ) std::cout <<
"( " << i_par <<
" " <<
m_minimPars[i_par].name <<
" " <<
par[i_par] <<
")";
601 std::cout << std::endl;