32 #include <CLHEP/Vector/LorentzVector.h>
48 #include "TGraphErrors.h"
49 #include "TProfile2D.h"
52 using CLHEP::HepLorentzVector;
60 m_energyMin(200*
MeV), m_weightMax(5.0), m_NormalizationType(
"Lin"),
61 m_NormalizationTypeNumber(0)
81 std::cout << std::endl;
82 std::cout << std::endl;
83 std::cout <<
"--- CaloHadDMCoeffFit::process() --- " << std::endl;
85 if(
m_isTestbeam) std::cout <<
"Processing TESTBEAM data" << std::endl;
88 std::cout <<
"Using weighting proportional to E_calib" << std::endl;
91 std::cout <<
"Using weighting proportional to log(E_calib)" << std::endl;
94 std::cout <<
"Using weighting proportional to 1/N_Clus_E_calib>0" << std::endl;
97 std::cout <<
"Using constant weighting" << std::endl;
126 std::cout <<
"CaloHadDMCoeffFit::process -> Error! No entries in DeadMaterialTree." << std::endl;
132 std::cout <<
"CaloHadDMCoeffFit::process -> Error! Different numbers of areas for DM definition" << std::endl;
149 std::cout <<
"CaloHadDMCoeffFit::process() -> Info. Getting averages..." << std::endl;
151 if(i_ev%20000==0) std::cout <<
" i_ev: " << i_ev <<
" '" << ((TChain *)
m_data->
fChain)->GetFile()->GetName() <<
"'" << std::endl;
155 bool GoodClusterFound(
false);
157 HepLorentzVector hlv_pion(1,0,0,1);
160 HepLorentzVector hlv_cls(1,0,0,1);
162 double r = hlv_pion.angle(hlv_cls.vect());
167 GoodClusterFound =
true;
172 if(!GoodClusterFound)
continue;
179 double clus_weight = 1.0;
183 if(clus_weight <= 0)
continue;
185 std::vector<float> vars;
189 if(iBin < 0)
continue;
198 std::cout <<
"Panic! Zero cluster energy" << std::endl;
208 std::cout <<
"done" << std::endl;
209 std::vector<double > engDmOverClusLim;
218 std::cout <<
"CaloHadDMCoeffFit::process() -> Info. Creation of histograms..." << std::endl;
231 sprintf(
hname,
"hp_DmVsPrep_%d",i_size);
234 float x_lim_edm = 2.0*
m_engDm[i_size]->m_aver + 3.0*sqrt(
m_engDm[i_size]->m_rms);
235 float x_lim_eprep = 2.0*
m_engPrep[i_size]->m_aver + 3.0*sqrt(
m_engPrep[i_size]->m_rms);
236 if(x_lim_edm <= 0.0) x_lim_edm = 1.0;
237 if(x_lim_eprep <= 0.0) x_lim_eprep = 1.0;
240 sprintf(
hname,
"h2_DmVsPrep_%d",i_size);
244 sprintf(
hname,
"h1_engDmOverClus_%d",i_size);
252 TProfile2D *hp2=
nullptr;
253 if(refbin == i_size) {
254 std::cout <<
" creating histos:" <<
hname <<
" refbin:" << refbin << std::endl;
257 sprintf(
hname,
"m_hp2_DmWeight_%d",i_size);
259 }
else if (refbin >= 0) {
269 std::cout <<
"CaloHadDMCoeffFit::process() -> Info. Filling histograms..." << std::endl;
271 if(i_ev%20000==0) std::cout <<
" i_ev: " << i_ev <<
" '" << ((TChain *)
m_data->
fChain)->GetFile()->GetName() <<
"'" << std::endl;
275 bool GoodClusterFound(
false);
277 HepLorentzVector hlv_pion(1,0,0,1);
280 HepLorentzVector hlv_cls(1,0,0,1);
282 double r = hlv_pion.angle(hlv_cls.vect());
287 GoodClusterFound =
true;
292 if(!GoodClusterFound)
continue;
299 double clus_weight = 1.0;
303 if(clus_weight <= 0.0)
continue;
305 std::vector<float> vars;
309 if(iBin < 0)
continue;
330 std::cout <<
"CaloHadDMCoeffFit::process() -> Info. Fitting histograms..." << std::endl;
331 TF1 *fitFun =
new TF1(
"fitFun",
"[0]+[1]*pow(x,[2])",1.,200000.);
332 double start_pars[3] = {100.0, 1.0, 1.0};
333 double start_errs[3] = {1.0, 1.0, 0.01};
339 if(hp->GetEntries() <25)
continue;
340 for(
int ip=0;
ip<fitFun->GetNpar();
ip++) fitFun->SetParameter(
ip,start_pars[
ip]);
341 fitFun->SetParErrors(start_errs);
342 fitFun->FixParameter(2,1.0);
343 std::cout <<
"----------------------" << std::endl;
344 double fitlim1 = hp->GetBinLowEdge(1);
347 if(
area->getTitle()==
"ENG_CALIB_DEAD_TILEG3") {
354 hp->Fit(fitFun,
"0Q",
"",fitlim1,fitlim2);
355 TF1 *
f=hp->GetFunction(fitFun->GetName());
357 f->ResetBit(TF1::kNotDraw);
366 std::cout <<
"CaloHadDMCoeffFit::process() -> Info. Making new coefficients ... " << std::endl;
384 std::vector<int > indexes;
394 float p0 = fitFun->GetParameter(0);
395 float s0 = fitFun->GetParError(0);
396 float p1 = fitFun->GetParameter(1);
397 float s1 = fitFun->GetParError(1);
400 if(fitFun->GetNDF() >= 2 && fitFun->GetChisquare()/fitFun->GetNDF() < 100. &&
p1 !=0.0 &&
p1>0.2) {
403 m_FitData[i_size]->descr = std::string(
"OK");
407 std::cout <<
"i_size ok " << i_size <<
" " <<
m_FitData[i_size]->descr << std::endl;
410 m_FitData[i_size]->descr = std::string(
"failed");
411 if(fitFun->GetNDF() < 2 || fitFun->GetChisquare()/fitFun->GetNDF() > 100.)
m_FitData[i_size]->descr += std::string(
" NDFCHI");
412 if(
p1==0 ||
p1<0.2)
m_FitData[i_size]->descr += std::string(
" p1");
414 std::cout <<
"i_size failed " << i_size <<
" " <<
m_FitData[i_size]->descr << std::endl;
419 m_FitData[i_size]->descr =
"failed noFitFun";
420 std::cout <<
"i_size nofitfun " << i_size <<
" " <<
m_FitData[i_size]->descr << std::endl;
445 std::vector<int >
tmp = indexes;
449 pars[0] = (*had_pars)[0];
450 pars[1] = (*had_pars)[1];
451 pars[2] = (*had_pars)[2];
453 sprintf(
str,
"Afrom %d",iBin);
461 std::vector<int >
tmp = indexes;
465 pars[0] = (*had_pars)[0];
466 pars[1] = (*had_pars)[1];
467 pars[2] = (*had_pars)[2];
469 sprintf(
str,
"Afrom %d",iBin);
471 std::cout <<
"xxx A i_size:" << i_size <<
" iBin:" << iBin <<
" " <<
m_FitData[i_size]->descr << std::endl;
476 std::vector<int >
tmp = indexes;
484 pars[0] = (*had_pars)[0];
485 pars[1] = (*had_pars)[1];
486 pars[2] = (*had_pars)[2];
488 sprintf(
str,
"Bfrom %d",iBin);
514 if(fabs(
eta) > 1.44 && fabs(
eta) < 1.56) {
518 if(fabs(
eta) > 4.0) rcut = rcut*0.7;
590 float etaRegions[][2] = { {0.0, 0.1}, {1.4, 1.7}, {2.0, 2.1}, {3.3, 3.4}, {4.0, 4.1} };
591 std::cout <<
"CaloHadDMCoeffFit::make_report() -> Info. Making report..." << std::endl;
592 gStyle->SetCanvasColor(10);
593 gStyle->SetCanvasBorderMode(0);
594 gStyle->SetPadColor(10);
595 gStyle->SetPadBorderMode(0);
596 gStyle->SetPalette(1);
597 gStyle->SetTitleBorderSize(1);
598 gStyle->SetTitleFillColor(10);
599 int cc_xx = 768, cc_yy = 1024;
602 gROOT->SetBatch(kTRUE);
604 std::string sfname = sreport;
605 TCanvas *ctmp =
new TCanvas(
"ctmp",
"ctmp", cc_xx, cc_yy);
607 ctmp->Print(sfname.c_str());
610 TCanvas *c1ps =
new TCanvas(
"c1ps",
"c1ps", cc_xx, cc_yy);
623 std::vector<int > v_indx;
625 for(
int i_frac=0; i_frac<dimFrac->
getNbins(); i_frac++) {
626 for(
int i_ener=0; i_ener<dimEner->
getNbins(); i_ener++) {
627 for(
int i_lambda=0; i_lambda<dimLambda->
getNbins(); i_lambda++) {
628 for(
int i_side=0; i_side<dimSide->
getNbins(); i_side++) {
629 for(
int i_phi=0; i_phi<dimPhi->
getNbins(); i_phi++) {
635 for(
int k=0;
k<2;
k++){
637 TPad *pad1 =
new TPad(
"p1ps",
"p1ps",0.0, 0.95, 1.0, 1.0); pad1->Draw();
638 TPad *pad2 =
new TPad(
"p2ps",
"p2ps",0.0, 0.0, 1.0, 0.95); pad2->Draw();
643 sprintf(
str,
"%s em:%d ener:%d> %5.1f-%6.1f phi:%d s:%d",dmArea->
getTitle().c_str(),i_frac,i_ener, ener1, ener2, i_phi, i_side);
644 tex.SetTextSize(0.4);
645 tex.SetTextColor(kBlue);
646 tex.DrawTextNDC(0.05,0.1,
str);
662 for(
int i_eta=0; i_eta<dimEta->
getNbins(); i_eta++){
666 std::cout <<
"Panic! iBin == -1, i_frac:" << i_frac <<
" i_ener:" << i_ener <<
" i_lambda:" << i_lambda <<
" i_eta:" << i_eta << std::endl;
677 pad2->cd(1+i_eta); gPad->SetGrid();
678 hh->GetXaxis()->SetNdivisions(508);
679 hh->GetYaxis()->SetNdivisions(508);
680 hh->GetXaxis()->SetTitle(
"edmtrue");
681 hh->GetYaxis()->SetTitle(
"eprep");
683 gStyle->SetOptStat(111111);
686 gStyle->SetOptStat(1);
692 tex.SetTextSize(0.095);
693 tex.SetTextColor(kBlue);
695 tex.DrawTextNDC(0.2,0.8,
str);
696 sprintf(
str,
"%d",iBin);
697 tex.DrawTextNDC(0.5,0.28,
str);
700 tex.SetTextColor(kBlue);
701 float p0inv, s0inv, p1inv, s1inv;
702 m_FitData[iBin]->getInverted(p0inv, s0inv, p1inv, s1inv);
703 tex.SetTextColor(kBlue); tex.SetTextSize(0.07);
705 tex.DrawTextNDC(0.2,0.7,
str);
706 sprintf(
str,
"inv:%6.3f %6.3f",p0inv, p1inv);
707 tex.DrawTextNDC(0.2,0.7-0.1,
str);
708 sprintf(
str,
"err:%6.3f %6.3f",s0inv, s1inv);
709 tex.DrawTextNDC(0.2,0.7-0.2,
str);
711 tex.SetTextColor(kRed);
715 sprintf(
str,
"Oops!");
716 tex.SetTextColor(kMagenta); tex.SetTextSize(0.095);
717 tex.DrawTextNDC(0.2,0.7,
str);
720 c1ps->Print(sfname.c_str());
721 printf(
"page:%d dmArea->m_title:%s frac:%d ener:%d phi:%d side:%d\n",
722 npage++, dmArea->
getTitle().c_str(), i_frac, i_ener, i_phi, i_side);
732 for(
int i_side=0; i_side<dimSide->
getNbins(); i_side++){
734 for(
int i_phi=0; i_phi<dimPhi->
getNbins(); i_phi++){
736 for(
int i_par=0; i_par<2; i_par++){
738 TPad *pad1 =
new TPad(
"p1ps",
"p1ps",0.0, 0.95, 1.0, 1.0); pad1->Draw();
739 TPad *pad2 =
new TPad(
"p2ps",
"p2ps",0.0, 0.0, 1.0, 0.95); pad2->Draw();
742 sprintf(
str,
"Summary: %s par:%d frac:%d phi:%d side:%d",dmArea->
getTitle().c_str(),i_par,i_frac, i_phi, i_side);
743 tex.SetTextSize(0.5); tex.SetTextColor(kBlue);
744 tex.DrawTextNDC(0.05,0.1,
str);
760 for(
int i_eta=0; i_eta<dimEta->
getNbins(); i_eta++){
762 TGraphErrors *
gr =
new TGraphErrors(dimEner->
getNbins());
763 for(
int i_ener=0; i_ener<dimEner->
getNbins(); i_ener++) {
768 float p0inv, s0inv, p1inv, s1inv;
769 m_FitData[iBin]->getInverted(p0inv, s0inv, p1inv, s1inv);
779 gr->SetPointError(i_ener, 0.0, ye);
781 pad2->cd(1+i_eta); gPad->SetGrid();
785 tex.SetTextSize(0.095);
786 tex.SetTextColor(kBlue);
787 sprintf(
str,
"%4.2f-%4.2f phibin:%d",
eta1,
eta2,i_phi);
788 tex.DrawTextNDC(0.2,0.8,
str);
790 c1ps->Print(sfname.c_str());
791 printf(
"page:%d dmArea->m_title:%s frac:%d Energy summary\n",
792 npage++, dmArea->
getTitle().c_str(), i_frac);
813 for(
int i_frac=0; i_frac<dimFrac->
getNbins(); i_frac++){
814 for(
int i_side=0; i_side<dimSide->
getNbins(); i_side++){
815 for(
int i_phi=0; i_phi<dimPhi->
getNbins(); i_phi++){
816 for(
int i_eta=0; i_eta<dimEta->
getNbins(); i_eta++){
818 bool ShowThisEta =
false;
819 for(
int i=0;
i<
int(
sizeof(etaRegions)/
sizeof(
float)/2);
i++){
821 if(xeta>=etaRegions[
i][0] && xeta <= etaRegions[
i][1]) {
826 if(!ShowThisEta)
continue;
827 std::vector<int > v_indx;
837 bzero(xx,100*
sizeof(Double_t));
838 for(
int i_ener=0; i_ener<dimEner->
getNbins()+1; i_ener++){
839 xx[i_ener] = dimEner->
getXmin() + dimEner->
getDx()*i_ener;
842 bzero(
yy,100*
sizeof(Double_t));
843 for(
int i_lambda=0; i_lambda<dimLambda->
getNbins()+1; i_lambda++){
844 yy[i_lambda] = dimLambda->
getXmin() + dimLambda->
getDx()*i_lambda;
852 sprintf(
hname,
"%s dm:%d frac:%d eta:%d phi:%d indx:%d-%d<ecls>/<edm>",dmArea->
getTitle().c_str(),i_dms, i_frac, i_eta, i_phi, ibin_min, ibin_max);
854 sprintf(
hname,
"%s dm:%d frac:%d eta:%d phi:%d indx:%d-%d nev",dmArea->
getTitle().c_str(),i_dms, i_frac, i_eta, i_phi, ibin_min, ibin_max);
856 for(
int i=0;
i<n_prof;
i++){
857 hp2[
i]->GetXaxis()->SetTitle(
"log10(E_{cls}(MeV))");
858 hp2[
i]->GetYaxis()->SetTitle(
"log10(#lambda)");
859 hp2[
i]->GetZaxis()->SetTitle(
"<E_{cls}>/<E_{dm}>");
862 float hp_aver[n_prof];
863 bzero(hp_aver,n_prof*
sizeof(
float));
864 std::vector<std::pair<int, int> > v_occupancy;
865 for(
int i_ener=0; i_ener<dimEner->
getNbins(); i_ener++) {
866 for(
int i_lambda=0; i_lambda<dimLambda->
getNbins(); i_lambda++) {
871 std::cout <<
"Panic in pp3, Wrong iBin=-1" << std::endl;
875 hp2[0]->Fill(dimEner->
getXmin() + dimEner->
getDx()*(i_ener+0.5), dimLambda->
getXmin() + dimLambda->
getDx()*(i_lambda+0.5),
x);
878 hp2[1]->Fill(dimEner->
getXmin() + dimEner->
getDx()*(i_ener+0.5), dimLambda->
getXmin() + dimLambda->
getDx()*(i_lambda+0.5),
x );
880 std::pair<int, int> pp;
883 v_occupancy.push_back(pp);
886 TCanvas *cp2 =
new TCanvas(
"cp2",
"cp2",cc_xx,cc_yy);
888 TPad *pad1 =
new TPad(
"cp2_p1ps",
"cp2_p1ps",0.0, 0.95, 1.0, 1.0); pad1->Draw();
889 TPad *pad2 =
new TPad(
"cp2_p2ps",
"cp2_p2ps",0.0, 0.0, 1.0, 0.95); pad2->Draw();
892 sprintf(
str,
"Summary: %s frac:%d phi:%d side:%d",dmArea->
getTitle().c_str(),i_frac, i_phi, i_side);
893 tex.SetTextSize(0.5); tex.SetTextColor(kBlue);
894 tex.DrawTextNDC(0.05,0.1,
str);
898 gPad->SetRightMargin(0.2);
899 hp2[1]->Draw(
"colz");
908 for(
int i_ener=0; i_ener<dimEner->
getNbins(); i_ener++) {
911 sprintf(
str,
"%d",iBin);
913 tex.SetTextSize(0.03);
914 tex.SetTextAngle(90.);
919 std::sort(v_occupancy.begin(), v_occupancy.end());
921 for(
unsigned int i_spec=0; i_spec<v_occupancy.size(); i_spec++){
922 int iBin = v_occupancy[i_spec].second;
924 std::cout <<
"Panic in pp3, Wrong iBin=-1" << std::endl;
928 std::cout <<
"Undefined h1 for " << iBin << std::endl;
931 std::vector<int > indexes;
933 sprintf(
str,
"ibin:%d frac:%d ener:%d lambda:%d eta:%d phi:%d",iBin,
940 gStyle->SetOptStat(111111);
944 tex.SetTextSize(0.05);
945 tex.DrawTextNDC(0.2,0.7,
str);
946 if(i_spec >= 3)
break;
948 cp2->Print(sfname.c_str());
949 printf(
"page:%d dmArea->m_title:%s i_frac:%d eta:%d phi:%d side:%d\n",
950 npage, dmArea->
getTitle().c_str(), i_frac, i_eta, i_phi, i_side);
960 ctmp->Print(sfname.c_str());
1021 double xLimRight(0);
1024 for(
int i=1;
i<=pH->GetNbinsX();
i++){
1025 nevtot += pH->GetBinEntries(
i);
1032 double inv_nevtot = nevtot ? 1. / nevtot : 1;
1033 for(
int i=1;
i<=pH->GetNbinsX();
i++){
1034 nev_in += pH->GetBinEntries(
i);
1035 if(pH->GetBinEffectiveEntries(
i)<2.0){
1036 pH->SetBinEntries(
i,0.0);
1037 pH->SetBinContent(
i,0.0);
1043 if(nev_in*inv_nevtot > ev_ratio) {
1044 xLimRight=pH->GetBinCenter(
i) + pH->GetBinWidth(
i)/2.;
1049 if(xLimRight==0) xLimRight=pH->GetBinCenter(pH->GetNbinsX()) + pH->GetBinWidth(pH->GetNbinsX())/2.;
1061 double xLimRight=pH->GetBinCenter(pH->GetNbinsX()) + pH->GetBinWidth(pH->GetNbinsX())/2.;
1062 int nbinx = (
int)pH->GetNbinsX();
1064 double nevtot = pH->Integral();
1067 const double inv_nevtot = 1. / nevtot;
1068 for(
int i_bin = 0; i_bin <=nbinx; i_bin++){
1069 nev+= pH->GetBinContent(i_bin);
1071 if(
nev*inv_nevtot >= ev_ratio){
1072 xLimRight = pH->GetBinCenter(i_bin) + pH->GetBinWidth(i_bin)/2.;
1077 double new_aver = 0.0;
1079 for(
int i_bin = 1; i_bin <=nbinx; i_bin++){
1080 if(pH->GetBinCenter(i_bin) <= xLimRight) {
1081 new_aver += pH->GetBinContent(i_bin)*pH->GetBinCenter(i_bin);
1082 sum += pH->GetBinContent(i_bin);
1087 if(new_aver < 0.0) new_aver = 0.0;
1089 new_aver = pH->GetMean();
1099 std::vector<int > indexes;