3 #include <calobase/RawCluster.h>
4 #include <calobase/RawClusterContainer.h>
5 #include <calobase/RawClusterUtility.h>
6 #include <calobase/RawTower.h>
7 #include <calobase/RawTowerContainer.h>
8 #include <calobase/RawTowerDefs.h>
9 #include <calobase/RawTowerGeomContainer.h>
10 #include <calobase/TowerInfoContainer.h>
23 #include <TGraphErrors.h>
27 #include <TLorentzVector.h>
33 #include <CLHEP/Vector/ThreeVector.h>
46 , m_Filename(filename)
47 , m_cent_nclus_cut(350)
52 { row.fill(
nullptr); });
58 std::cout <<
"LiteCaloEval::Init(PHCompositeNode *topNode) Initializing" << std::endl;
64 pairInvMassTotal =
new TH1F(
"pairInvMassTotal",
"Pair Mass Histo", 130, 0.0, 1.3);
65 mass_eta =
new TH2F(
"mass_eta",
"2d Pair Mass Histo", 70, 0.0, 0.7, 400, -1.5, 1.5);
66 mass_eta_phi =
new TH3F(
"mass_eta_phi",
"3d Pair Mass Histo", 70, 0.0, 0.7, 150, -1.5, 1.5, 256, -3.142, 3.142);
67 h_totalClusters =
new TH1F(
"h_totalClusters",
"Histogram of total number of clusters", 600, 0, 600);
68 pt1_ptpi0_alpha =
new TH3F(
"pt1_ptpi0_alpha",
"Photon1 pT, pi0 pT, alpha", 40, 0., 4., 40, 0., 4., 10, 0., 1.);
69 fitp1_eta_phi2d =
new TH2F(
"fitp1_eta_phi2d",
"fit p1 eta phi", 16, 0, 16, 16, 0, 16);
85 for (
int i = 0;
i < 96;
i++)
90 eta_hist.at(
i) =
new TH1F(b.c_str(),
"eta and all phi's", 130, 0.0, 1.3);
93 if (topNode !=
nullptr)
96 _eventTree =
new TTree(
"_eventTree",
"An event level info Tree");
119 std::cout << std::endl;
120 std::cout <<
"Beginning of the event " <<
m_ievent << std::endl;
121 std::cout <<
"====================================" << std::endl;
135 RawClusterContainer *recal_clusters = findNode::getClass<RawClusterContainer>(topNode, clusnodename);
139 std::cout <<
PHWHERE <<
"EMCal cluster node is missing, can't collect EMCal clusters" << std::endl;
144 RawTowerContainer *_towers = findNode::getClass<RawTowerContainer>(topNode, towernode);
147 std::cout <<
PHWHERE <<
" ERROR: Can't find " << towernode << std::endl;
152 RawTowerGeomContainer *towergeom = findNode::getClass<RawTowerGeomContainer>(topNode, towergeomnode);
155 std::cout <<
PHWHERE <<
": Could not find node " << towergeomnode << std::endl;
168 TowerInfoContainer *_towerinfos = findNode::getClass<TowerInfoContainer>(topNode, towernode);
171 std::cout <<
PHWHERE <<
" ERROR: Can't find " << towernode << std::endl;
176 std::cout <<
"using these nodes for cluster/tower: " << clusnodename <<
" " << towernode << std::endl;
183 GlobalVertexMap *vertexmap = findNode::getClass<GlobalVertexMap>(topNode,
"GlobalVertexMap");
186 if (!vertexmap->
empty())
198 CLHEP::Hep3Vector
vertex(vx, vy, vz);
211 for (t_rclusiter = t_rbegin_end.first; t_rclusiter != t_rbegin_end.second; ++t_rclusiter)
213 RawCluster *t_recalcluster = t_rclusiter->second;
215 float cluse = t_recalcluster->
get_ecore();
223 if (cluse > 0.6 && t_recalcluster->
get_chi2() < 4)
225 savCs[iCs++] = t_recalcluster;
238 for (
int jCs = 0; jCs < iCs; jCs++)
247 std::vector<int> toweretas;
248 std::vector<int> towerphis;
249 std::vector<float> towerenergies;
262 for (toweriter = towers.first; toweriter != towers.second; ++toweriter)
278 double towerenergy = toweriter->second;
281 toweretas.push_back(towerieta);
282 towerphis.push_back(toweriphi);
283 towerenergies.push_back(towerenergy);
293 int maxTowerIndex = max_element(towerenergies.begin(), towerenergies.end()) - towerenergies.begin();
300 float tt_clus_energy = E_vec_cluster.mag();
301 float tt_clus_eta = E_vec_cluster.pseudoRapidity();
302 float tt_clus_pt = E_vec_cluster.perp();
303 float tt_clus_phi = E_vec_cluster.getPhi();
326 if (tt_clus_pt > 0.9 && iCs > 400000)
330 for (
int kCs = 0; kCs < iCs; kCs++)
339 float tt2_clus_energy = E_vec_cluster2.mag();
340 if (tt2_clus_energy > 0.6)
343 alphaCut = std::abs(tt_clus_energy - tt2_clus_energy) / (tt_clus_energy + tt_clus_energy);
346 float tt2_clus_eta = E_vec_cluster2.pseudoRapidity();
347 float tt2_clus_pt = E_vec_cluster2.perp();
348 float tt2_clus_phi = E_vec_cluster2.getPhi();
350 TLorentzVector pho1, pho2, pi0lv;
352 pho1.SetPtEtaPhiE(tt_clus_pt, tt_clus_eta, tt_clus_phi, tt_clus_energy);
353 pho2.SetPtEtaPhiE(tt2_clus_pt, tt2_clus_eta, tt2_clus_phi, tt2_clus_energy);
355 if (pho1.DeltaR(pho2) > 0.8)
362 float pairInvMass = pi0lv.M();
367 if (fabs(pi0lv.Pt()) > 1.0)
370 mass_eta->Fill(pairInvMass, tt_clus_eta);
397 if (topNode ==
nullptr &&
f_temp)
428 std::array<std::array<float, 260>, 96> myaggcorr{};
429 std::for_each(myaggcorr.begin(), myaggcorr.end(), [](
auto &row)
432 std::cout <<
"running w/ corr file? : " << incorrFile << std::endl;
434 if (!incorrFile.empty())
436 TFile *infileNt =
new TFile(incorrFile.c_str());
437 std::cout <<
"loaded incorrFile " << infileNt << std::endl;
444 TNtuple *innt_corrVals = (TNtuple *) infileNt->Get(
"nt_corrVals");
446 innt_corrVals->SetBranchAddress(
"tower_eta", &myieta);
447 innt_corrVals->SetBranchAddress(
"tower_phi", &myiphi);
448 innt_corrVals->SetBranchAddress(
"corr_val", &mycorr);
449 innt_corrVals->SetBranchAddress(
"agg_cv", &myaggcv);
451 int ntCorrs = innt_corrVals->GetEntries();
453 for (
int ij = 0; ij < ntCorrs; ij++)
455 innt_corrVals->GetEntry(ij);
456 int ci = (int) myieta;
457 int cj = (int) myiphi;
458 myaggcorr.at(ci).at(cj) = myaggcv;
459 if (ij > ntCorrs - 2 || ij == ntCorrs / 2)
461 std::cout <<
"loaded corrs eta,phi,aggcv " << myieta
462 <<
" " << myiphi <<
" " << myaggcv << std::endl;
470 std::cout <<
"in loop" << std::endl;
475 TFile *
f =
new TFile(filename.c_str());
476 t1 = (TTree *) f->Get(
"_eventTree");
481 t1->SetBranchAddress(
"_nClusters", &
_nClusters);
492 TLorentzVector *savClusLV[10000];
495 int nEntries = (int) t1->GetEntries();
498 if (nevts < 0 || nEntries < nevts)
504 int discarded_clusters = 0;
506 for (
int i = 0;
i < nevts2;
i++)
511 if ((
i % 10 == 0 &&
i < 200) || (
i % 100 == 0 &&
i < 1000) || (
i % 1000 == 0 &&
i < 37003) ||
i % 10000 == 0)
513 std::cout <<
"evt no " <<
i << std::endl;
521 if (nClusters > 1000)
523 discarded_clusters += 1;
527 float pt1cut = 0, pt2cut = 0;
529 for (
int j = 0;
j < nClusters;
j++)
556 savClusLV[
j] =
new TLorentzVector();
557 savClusLV[
j]->SetPtEtaPhiE(pt, eta, phi, E);
560 TLorentzVector *pho1, *pho2;
562 for (
int jCs = 0; jCs < iCs; jCs++)
564 pho1 = savClusLV[jCs];
583 float modCutFactor = 1.0;
590 pt1cut = 1.3 * modCutFactor;
591 pt2cut = 0.7 * modCutFactor;
598 pt1cut = 1.3 * modCutFactor + 1.4 * (iCs - 29) / 200.0 * modCutFactor;
599 pt2cut = 0.7 * modCutFactor + 1.4 * (iCs - 29) / 200.0 * modCutFactor;
602 float pi0ptcut = 1.22 * (pt1cut + pt2cut);
605 float alphacutval = 0.6;
607 float deltaRconecut = 1.1;
617 if (fabs(pho1->Pt()) < pt1cut)
623 for (
int kCs = 0; kCs < iCs; kCs++)
630 pho2 = savClusLV[kCs];
632 if (fabs(pho2->Pt()) < pt2cut)
637 alphaCut = fabs((pho1->E() - pho2->E()) / (pho1->E() + pho2->E()));
644 TLorentzVector pi0lv;
646 if (pho1->DeltaR(*pho2) > deltaRconecut)
651 pi0lv = *pho1 + *pho2;
652 if (fabs(pi0lv.Pt()) > pi0ptcut)
654 float pairInvMass = pi0lv.M();
668 std::cout <<
"total number of events: " << nEntries << std::endl;
669 std::cout <<
"total number of events discarded: " << discarded_clusters << std::endl;
677 std::array<std::array<float, 260>, 96> myaggcorr{};
678 std::for_each(myaggcorr.begin(), myaggcorr.end(), [](
auto &row)
681 std::cout <<
"running w/ corr file? : " << incorrFile << std::endl;
683 if (!incorrFile.empty())
685 TFile *infileNt =
new TFile(incorrFile.c_str());
686 std::cout <<
"loaded incorrFile " << infileNt << std::endl;
693 TNtuple *innt_corrVals = (TNtuple *) infileNt->Get(
"nt_corrVals");
695 innt_corrVals->SetBranchAddress(
"tower_eta", &myieta);
696 innt_corrVals->SetBranchAddress(
"tower_phi", &myiphi);
697 innt_corrVals->SetBranchAddress(
"corr_val", &mycorr);
698 innt_corrVals->SetBranchAddress(
"agg_cv", &myaggcv);
700 int ntCorrs = innt_corrVals->GetEntries();
702 for (
int ij = 0; ij < ntCorrs; ij++)
704 innt_corrVals->GetEntry(ij);
705 int ci = (int) myieta;
706 int cj = (int) myiphi;
707 myaggcorr.at(ci).at(cj) = myaggcv;
708 if (ij > ntCorrs - 2)
710 std::cout <<
"loaded corrs eta,phi,aggcv " << myieta
711 <<
" " << myiphi <<
" " << myaggcv << std::endl;
719 std::cout <<
"in loop" << std::endl;
724 TFile *
f =
new TFile(filename.c_str());
725 t1 = (TTree *) f->Get(
"_eventTree");
730 t1->SetBranchAddress(
"_nClusters", &
_nClusters);
741 std::array<TLorentzVector *, 10000> savClusLV{};
744 int nEntries = (int) t1->GetEntries();
747 if (nevts < 0 || nEntries < nevts)
752 for (
int i = 0;
i < nevts2;
i++)
757 if ((
i % 10 == 0 &&
i < 200) || (
i % 100 == 0 &&
i < 1000) || (
i % 1000 == 0 &&
i < 37003) ||
i % 10000 == 0)
759 std::cout <<
"evt no " <<
i << std::endl;
770 for (
int j = 0;
j < nClusters;
j++)
783 savClusLV.at(j) =
new TLorentzVector();
784 savClusLV.at(j)->SetPtEtaPhiE(pt, eta, phi, E);
787 TLorentzVector *pho1, *pho2;
789 for (
int jCs = 0; jCs < iCs; jCs++)
791 pho1 = savClusLV.at(jCs);
793 if (fabs(pho1->Pt()) < 1.0)
799 for (
int kCs = 0; kCs < iCs; kCs++)
806 pho2 = savClusLV.at(kCs);
808 if (fabs(pho2->Pt()) < 0.6)
813 TLorentzVector pi0lv;
814 if (pho1->DeltaR(*pho2) > 0.45)
818 pi0lv = *pho1 + *pho2;
819 float pairInvMass = pi0lv.M();
820 if (pi0lv.Pt() < 1.0)
833 alphaCut = fabs((pho1->E() - pho2->E()) / (pho1->E() + pho2->E()));
861 std::cout <<
" Inside Fit_Histos_Eta_Phi." << std::endl;
864 std::array<std::array<float, 256>, 96> myaggcorr{};
865 std::for_each(myaggcorr.begin(), myaggcorr.end(), [](
auto &row)
868 if (!incorrFile.empty())
870 TFile *infileNt =
new TFile(incorrFile.c_str());
877 TNtuple *innt_corrVals = (TNtuple *) infileNt->Get(
"nt_corrVals");
879 innt_corrVals->SetBranchAddress(
"tower_eta", &myieta);
880 innt_corrVals->SetBranchAddress(
"tower_phi", &myiphi);
881 innt_corrVals->SetBranchAddress(
"corr_val", &mycorr);
882 innt_corrVals->SetBranchAddress(
"agg_cv", &myaggcv);
884 int ntCorrs = innt_corrVals->GetEntries();
886 for (
int ij = 0; ij < ntCorrs; ij++)
888 innt_corrVals->GetEntry(ij);
889 int ci = (int) myieta;
890 int cj = (int) myiphi;
891 myaggcorr.at(ci).at(cj) = myaggcv;
892 if (ij > ntCorrs - 2)
894 std::cout <<
"loaded corrs eta,phi,aggcv " << myieta
895 <<
" " << myiphi <<
" " << myaggcv << std::endl;
912 fitp1_eta_phi2d =
new TH2F(
"fitp1_eta_phi2d",
"fit p1 eta phi", 96, 0, 96, 256, 0, 256);
914 double cemc_par1_values[96][256] = {{0.0}};
917 double cemc_par1_errors[96][256] = {{0.0}};
922 TNtuple *nt_corrVals =
new TNtuple(
"nt_corrVals",
"Ntuple of the corrections",
"tower_eta:tower_phi:corr_val:agg_cv");
924 for (
int ieta = 0; ieta < 96; ieta++)
926 for (
int iphi = 0; iphi < 256; iphi++)
940 for (
int kfi = 1; kfi < 20; kfi++)
950 f1[kj] =
new TF1(
"f1",
"gaus", 0.06, 0.20);
951 f2[kj] =
new TF1(
"f2",
"pol2", 0.01, 0.4);
953 cemc_hist_eta_phi.at(ieta).at(iphi)->Fit(f1[kj],
"",
"", pkloc - 0.04, pkloc + 0.04);
954 float fpkloc2 = f1[kj]->GetParameter(1);
956 TGraphErrors *grtemp =
new TGraphErrors();
959 std::cout <<
" getting " << bkgNm <<
" mean was " << fpkloc2
960 <<
" " << pkloc << std::endl;
962 grtemp->SetName(bkgNm.c_str());
964 for (
int gj = 1; gj <
cemc_hist_eta_phi.at(ieta).at(iphi)->GetNbinsX() + 1; gj++)
968 if ((binc > 0.06 * fpkloc2 / 0.145 && binc < 0.09 * fpkloc2 / 0.145) || (binc > 0.22 * fpkloc2 / 0.145 && binc < 0.35 * fpkloc2 / 0.145))
970 grtemp->SetPoint(ingr, binc, cntc);
971 grtemp->SetPointError(ingr++, 0.001, sqrt(cntc));
977 total[kj] =
new TF1(
"total",
"gaus(0)+pol2(3)", 0.06, 0.25);
981 f1[kj]->GetParameters(&par[0]);
982 f2[kj]->GetParameters(&par[3]);
984 total[kj]->SetParameters(par);
985 total[kj]->SetParLimits(2, 0.01, 0.027);
995 cemc_par1_values[ieta][iphi] = fit_fn[kj]->GetParameter(1);
1002 cemc_par1_errors[ieta][iphi] = fit_fn[kj]->GetParError(1);
1008 std::cout <<
"Warning::Fit Failed for eta bin : " << ieta << iphi << std::endl;
1009 cemc_par1_values[ieta][iphi] = -999.0;
1010 cemc_par1_errors[ieta][iphi] = -999.0;
1013 nt_corrVals->Fill(ieta, iphi, 0.135 / cemc_par1_values[ieta][iphi], 0.135 / cemc_par1_values[ieta][iphi] * myaggcorr.at(ieta).at(iphi));
1019 fitp1_eta_phi2d->SetBinContent(ieta + 1, iphi + 1, cemc_par1_values[ieta][iphi]);
1020 fitp1_eta_phi2d->SetBinError(ieta + 1, iphi + 1, cemc_par1_errors[ieta][iphi]);
1046 std::cout <<
" finished fit_histos_eta_phi. " << std::endl;
1052 std::cout <<
" Inside Fit_Histos_Eta_Phi." << std::endl;
1054 std::array<std::array<float, 256>, 96> myaggcorr{};
1055 std::for_each(myaggcorr.begin(), myaggcorr.end(), [](
auto &row)
1058 if (!incorrFile.empty())
1060 TFile *infileNt =
new TFile(incorrFile.c_str());
1067 TNtuple *innt_corrVals = (TNtuple *) infileNt->Get(
"nt_corrVals");
1069 innt_corrVals->SetBranchAddress(
"tower_eta", &myieta);
1070 innt_corrVals->SetBranchAddress(
"tower_phi", &myiphi);
1071 innt_corrVals->SetBranchAddress(
"corr_val", &mycorr);
1072 innt_corrVals->SetBranchAddress(
"agg_cv", &myaggcv);
1074 int ntCorrs = innt_corrVals->GetEntries();
1076 for (
int ij = 0; ij < ntCorrs; ij++)
1078 innt_corrVals->GetEntry(ij);
1079 int ci = (int) myieta;
1080 int cj = (int) myiphi;
1081 myaggcorr.at(ci).at(cj) = myaggcv;
1082 if (ij > ntCorrs - 2)
1084 std::cout <<
"loaded corrs eta,phi,aggcv " << myieta
1085 <<
" " << myiphi <<
" " << myaggcv << std::endl;
1102 fitp1_eta_phi2d =
new TH2F(
"fitp1_eta_phi2d",
"fit p1 eta phi", 96, 0, 96, 256, 0, 256);
1104 double cemc_par1_values[96][256] = {{0.0}};
1107 double cemc_par1_errors[96][256] = {{0.0}};
1112 TNtuple *nt_corrVals =
new TNtuple(
"nt_corrVals",
"Ntuple of the corrections",
"tower_eta:tower_phi:corr_val:agg_cv");
1114 for (
int ieta = 0; ieta < 96; ieta++)
1116 for (
int iphi = 0; iphi < 256; iphi++)
1118 if (ieta > 15 || iphi > 15)
1134 float bsavloc = 0.0;
1135 for (
int kfi = 1; kfi < 20; kfi++)
1138 if (locbv > bsavloc)
1145 f1[kj] =
new TF1(
"f1",
"gaus", 0.06, 0.20);
1146 f2[kj] =
new TF1(
"f2",
"pol2", 0.01, 0.4);
1148 cemc_hist_eta_phi.at(ieta).at(iphi)->Fit(f1[kj],
"",
"", pkloc - 0.04, pkloc + 0.04);
1149 float fpkloc2 = f1[kj]->GetParameter(1);
1151 TGraphErrors *grtemp =
new TGraphErrors();
1154 std::cout <<
" getting " << bkgNm <<
" mean was " << fpkloc2
1155 <<
" " << pkloc << std::endl;
1157 grtemp->SetName(bkgNm.c_str());
1159 for (
int gj = 1; gj <
cemc_hist_eta_phi.at(ieta).at(iphi)->GetNbinsX() + 1; gj++)
1163 if ((binc > 0.06 * fpkloc2 / 0.145 && binc < 0.09 * fpkloc2 / 0.145) || (binc > 0.22 * fpkloc2 / 0.145 && binc < 0.35 * fpkloc2 / 0.145))
1165 grtemp->SetPoint(ingr, binc, cntc);
1166 grtemp->SetPointError(ingr++, 0.001, sqrt(cntc));
1170 grtemp->Fit(f2[kj]);
1172 total[kj] =
new TF1(
"total",
"gaus(0)+pol2(3)", 0.06, 0.25);
1176 f1[kj]->GetParameters(&par[0]);
1177 f2[kj]->GetParameters(&par[3]);
1179 total[kj]->SetParameters(par);
1180 total[kj]->SetParLimits(2, 0.01, 0.027);
1190 cemc_par1_values[ieta][iphi] = fit_fn[kj]->GetParameter(1);
1197 cemc_par1_errors[ieta][iphi] = fit_fn[kj]->GetParError(1);
1203 std::cout <<
"Warning::Fit Failed for eta bin : " << ieta << iphi << std::endl;
1206 for (
int ipatt_eta = 0; ipatt_eta < 6; ipatt_eta++)
1208 for (
int ipatt_phi = 0; ipatt_phi < 16; ipatt_phi++)
1212 nt_corrVals->Fill(ieta + ipatt_eta * 16, iphi + ipatt_phi * 16, 0.135 / cemc_par1_values[ieta][iphi], 0.135 / cemc_par1_values[ieta][iphi] * myaggcorr.at(ieta).at(iphi));
1222 fitp1_eta_phi2d->SetBinContent(ieta + 1, iphi + 1, cemc_par1_values[ieta][iphi]);
1223 fitp1_eta_phi2d->SetBinError(ieta + 1, iphi + 1, cemc_par1_errors[ieta][iphi]);
1247 std::cout <<
" finished fit_histos_eta_phi. " << std::endl;
1253 std::cout <<
" Inside Fit_Histos_Eta_Phi." << std::endl;
1256 std::array<std::array<float, 256>, 96> myaggcorr{};
1257 std::for_each(myaggcorr.begin(), myaggcorr.end(), [](
auto &row)
1260 if (!incorrFile.empty())
1262 TFile *infileNt =
new TFile(incorrFile.c_str());
1269 TNtuple *innt_corrVals = (TNtuple *) infileNt->Get(
"nt_corrVals");
1271 innt_corrVals->SetBranchAddress(
"tower_eta", &myieta);
1272 innt_corrVals->SetBranchAddress(
"tower_phi", &myiphi);
1273 innt_corrVals->SetBranchAddress(
"corr_val", &mycorr);
1274 innt_corrVals->SetBranchAddress(
"agg_cv", &myaggcv);
1276 int ntCorrs = innt_corrVals->GetEntries();
1278 for (
int ij = 0; ij < ntCorrs; ij++)
1280 innt_corrVals->GetEntry(ij);
1281 int ci = (int) myieta;
1282 int cj = (int) myiphi;
1283 myaggcorr.at(ci).at(cj) = myaggcv;
1284 if (ij > ntCorrs - 2)
1286 std::cout <<
"loaded corrs eta,phi,aggcv " << myieta
1287 <<
" " << myiphi <<
" " << myaggcv << std::endl;
1303 TF1 *cemc_eta_phi_result =
nullptr;
1304 fitp1_eta_phi2d =
new TH2F(
"fitp1_eta_phi2d",
"fit p1 eta phi", 96, 0, 96, 256, 0, 256);
1305 double cemc_par1_values[96][256] = {{0.0}};
1308 double cemc_par1_errors[96][256] = {{0.0}};
1313 TNtuple *nt_corrVals =
new TNtuple(
"nt_corrVals",
"Ntuple of the corrections",
"tower_eta:tower_phi:corr_val:agg_cv");
1315 for (
int ithirds = 0; ithirds < 3; ithirds++)
1317 for (
int ieta = 0 + ithirds * 32; ieta < (ithirds * 32 + 16); ieta++)
1319 for (
int iphi = 0; iphi < 16; iphi++)
1322 float bsavloc = 0.0;
1323 for (
int kfi = 1; kfi < 25; kfi++)
1326 if (locbv > bsavloc)
1333 f1[kj] =
new TF1(
"f1",
"gaus", pkloc - 0.03, pkloc + 0.03);
1334 f2[kj] =
new TF1(
"f2",
"pol2", 0.01, 0.4);
1336 cemc_hist_eta_phi.at(ieta).at(iphi)->Fit(f1[kj],
"",
"", pkloc - 0.04, pkloc + 0.04);
1337 float fpkloc2 = f1[kj]->GetParameter(1);
1339 TGraphErrors *grtemp =
new TGraphErrors();
1342 std::cout <<
" getting " << bkgNm <<
" mean was " << fpkloc2
1343 <<
" " << pkloc << std::endl;
1345 grtemp->SetName(bkgNm.c_str());
1347 for (
int gj = 1; gj <
cemc_hist_eta_phi.at(ieta).at(iphi)->GetNbinsX() + 1; gj++)
1351 if ((binc > 0.06 * fpkloc2 / 0.145 && binc < 0.09 * fpkloc2 / 0.145) || (binc > 0.22 * fpkloc2 / 0.145 && binc < 0.35 * fpkloc2 / 0.145))
1353 grtemp->SetPoint(ingr, binc, cntc);
1354 grtemp->SetPointError(ingr++, 0.001, sqrt(cntc));
1358 grtemp->Fit(f2[kj]);
1360 total[kj] =
new TF1(
"total",
"gaus(0)+pol2(3)", 0.06, 0.3 * fpkloc2 / 0.145);
1364 f1[kj]->GetParameters(&par[0]);
1365 f2[kj]->GetParameters(&par[3]);
1367 total[kj]->SetParameters(par);
1368 total[kj]->SetParLimits(2, 0.01, 0.027);
1370 cemc_eta_phi_result =
cemc_hist_eta_phi.at(ieta).at(iphi)->GetFunction(
"total");
1375 if (cemc_eta_phi_result)
1378 cemc_par1_values[ieta][iphi] = cemc_eta_phi_result->GetParameter(1);
1385 cemc_par1_errors[ieta][iphi] = cemc_eta_phi_result->GetParError(1);
1391 std::cout <<
"Warning::Fit Failed for eta bin : " << ieta << iphi << std::endl;
1394 for (
int ipatt_eta = 0; ipatt_eta < 2; ipatt_eta++)
1396 for (
int ipatt_phi = 0; ipatt_phi < 16; ipatt_phi++)
1400 nt_corrVals->Fill(ieta + ipatt_eta * 16, iphi + ipatt_phi * 16, 0.135 / cemc_par1_values[ieta][iphi], 0.135 / cemc_par1_values[ieta][iphi] * myaggcorr.at(ieta).at(iphi));
1410 fitp1_eta_phi2d->SetBinContent(ieta + 1, iphi + 1, cemc_par1_values[ieta][iphi]);
1411 fitp1_eta_phi2d->SetBinError(ieta + 1, iphi + 1, cemc_par1_errors[ieta][iphi]);
1415 std::cout <<
" finished fit_histos_eta_phi. " << std::endl;
1422 std::array<std::array<float, 260>, 96> myaggcorr{};
1423 std::for_each(myaggcorr.begin(), myaggcorr.end(), [](
auto &row)
1426 if (!incorrFile.empty())
1428 TFile *infileNt =
new TFile(incorrFile.c_str());
1435 TNtuple *innt_corrVals = (TNtuple *) infileNt->Get(
"nt_corrVals");
1437 innt_corrVals->SetBranchAddress(
"tower_eta", &myieta);
1438 innt_corrVals->SetBranchAddress(
"tower_phi", &myiphi);
1439 innt_corrVals->SetBranchAddress(
"corr_val", &mycorr);
1440 innt_corrVals->SetBranchAddress(
"agg_cv", &myaggcv);
1442 int ntCorrs = innt_corrVals->GetEntries();
1444 for (
int ij = 0; ij < ntCorrs; ij++)
1446 innt_corrVals->GetEntry(ij);
1447 int ci = (int) myieta;
1448 int cj = (int) myiphi;
1449 myaggcorr.at(ci).at(cj) = myaggcv;
1450 if (ij > ntCorrs - 2)
1452 std::cout <<
"loaded corrs eta,phi,aggcv " << myieta
1453 <<
" " << myiphi <<
" " << myaggcv << std::endl;
1470 double eta_value[96];
1471 double eta_par1_value[96] = {0.0};
1472 double eta_par1_error[96] = {0.0};
1473 double eta_par2_value[96] = {0.0};
1474 double eta_par2_error[96] = {0.0};
1478 TNtuple *nt_corrVals =
new TNtuple(
"nt_corrVals",
"Ntuple of the corrections",
"tower_eta:tower_phi:corr_val:agg_cv");
1480 float avgmean = 0.170;
1482 int okHist[96] = {0};
1484 for (
int i = 0;
i < 96;
i++)
1490 else if (
eta_hist.at(
i)->GetEntries() == 0)
1499 float bsavloc = 0.0;
1501 for (
int kfi = 1; kfi < 30; kfi++)
1503 float locbv =
eta_hist.at(
i)->GetBinContent(kfi);
1504 if (locbv > bsavloc)
1506 pkloc =
eta_hist.at(
i)->GetBinCenter(kfi);
1511 f1[kj] =
new TF1(
"f1",
"gaus", 0.06, 0.20);
1512 f2[kj] =
new TF1(
"f2",
"pol2", 0.005, 0.5);
1514 if (pkloc < 0.110 || pkloc > 0.2)
1519 eta_hist.at(
i)->Fit(f1[kj],
"",
"", pkloc - 0.04, pkloc + 0.04);
1520 float fpkloc2 = f1[kj]->GetParameter(1);
1522 if (fpkloc2 < 0.110 || fpkloc2 > 0.2)
1527 TGraphErrors *grtemp =
new TGraphErrors();
1530 std::cout <<
" getting " << bkgNm <<
" mean was "
1531 << fpkloc2 <<
" " << pkloc << std::endl;
1532 grtemp->SetName(bkgNm.c_str());
1534 int firstnonzbin = -1;
1535 for (
int gj = 1; gj <
eta_hist.at(
i)->GetNbinsX() + 1; gj++)
1537 float binc =
eta_hist.at(
i)->GetBinCenter(gj);
1538 float cntc =
eta_hist.at(
i)->GetBinContent(gj);
1540 ((binc > 0.03 * fpkloc2 / 0.145 && binc < 0.09 * fpkloc2 / 0.145) || (binc > 0.265 * fpkloc2 / 0.145 && binc < 0.31 * fpkloc2 / 0.145)) && (cntc > 0 || firstnonzbin > 0))
1542 grtemp->SetPoint(ingr, binc, cntc);
1543 grtemp->SetPointError(ingr++, 0.001, sqrt(cntc));
1545 if (cntc && firstnonzbin < 0)
1551 grtemp->Fit(f2[kj]);
1553 total[kj] =
new TF1(
"total",
"gaus(0)+pol2(3)", 0.03 * fpkloc2 / 0.145, 0.31 * fpkloc2 / 0.145);
1557 f1[kj]->GetParameters(&par[0]);
1558 f2[kj]->GetParameters(&par[3]);
1560 total[kj]->SetParameters(par);
1561 total[kj]->SetParLimits(2, 0.015, 0.037);
1563 total[kj]->SetParLimits(0, 5.0,
eta_hist.at(
i)->Integral(0, 40));
1564 total[kj]->SetParLimits(1, 0.08, 0.22);
1570 fit_fn[kj] =
eta_hist.at(
i)->GetFunction(
"total");
1577 eta_par1_value[
i] = fit_fn[kj]->GetParameter(1);
1578 if (!(eta_par1_value[
i] > 0))
1580 eta_par1_value[
i] = 0.5;
1582 eta_par1_error[
i] = fit_fn[kj]->GetParError(1);
1583 eta_par2_value[
i] = fit_fn[kj]->GetParameter(2);
1584 eta_par2_error[
i] = fit_fn[kj]->GetParError(2);
1588 std::cout <<
"WarninG :: Fit Failed for eta bin : " <<
i << std::endl;
1591 avgmean += eta_par1_value[
i];
1599 for (
int iijk = 0; iijk < 96; iijk++)
1601 if (okHist[iijk] == 0)
1606 float locavg = 0.01;
1607 if (kj2 < 6 && iijk < 88)
1609 locavg = (eta_par1_value[iijk + 3] + eta_par1_value[iijk + 4] + eta_par1_value[iijk + 5] + eta_par1_value[iijk + 6] + eta_par1_value[iijk + 7]) / 5.0;
1610 if (fabs(locavg - avgmean) > 0.2 * avgmean)
1617 locavg = (eta_par1_value[iijk - 3] + eta_par1_value[iijk - 4] + eta_par1_value[iijk - 5] + eta_par1_value[iijk - 6] + eta_par1_value[iijk - 7]) / 5.0;
1618 if (fabs(locavg - avgmean) > 0.2 * avgmean)
1625 locavg = (eta_par1_value[iijk - 3] + eta_par1_value[iijk - 2] + eta_par1_value[iijk - 1] + eta_par1_value[iijk + 1] + eta_par1_value[iijk + 2] + eta_par1_value[iijk + 3]) / 6.0;
1626 if (fabs(locavg - avgmean) > 0.2 * avgmean)
1632 float thisfitp1 = 0;
1635 thisfitp1 = fit_fn[kj2]->GetParameter(1);
1636 if (fabs(thisfitp1 - locavg) > 0.12 * locavg)
1638 std::cout <<
"redoing fit for eta" << iijk <<
" " << fit_fn[kj2] << std::endl;
1639 fit_fn[kj2]->SetParameter(1, locavg);
1640 fit_fn[kj2]->FixParameter(1, locavg);
1641 eta_hist.at(iijk)->Fit(fit_fn[kj2]);
1642 fit_fn[kj2]->SetParLimits(1, locavg - 0.011, locavg + 0.011);
1643 eta_hist.at(iijk)->Fit(fit_fn[kj2]);
1656 eta_value[iijk] = iijk;
1657 eta_par1_value[iijk] = fit_fn[kj2]->GetParameter(1);
1658 if (!(eta_par1_value[iijk] > 0))
1660 eta_par1_value[iijk] = 0.5;
1662 eta_par1_error[iijk] = fit_fn[kj2]->GetParError(1);
1663 eta_par2_value[iijk] = fit_fn[kj2]->GetParameter(2);
1664 eta_par2_error[iijk] = fit_fn[kj2]->GetParError(2);
1668 std::cout <<
"WarninG :: Fit Failed for eta bin : " << iijk << std::endl;
1671 for (
int jj = 0; jj < 256; jj++)
1673 nt_corrVals->Fill(iijk, jj,
_setMassVal / eta_par1_value[iijk],
_setMassVal / eta_par1_value[iijk] * myaggcorr.at(iijk).at(jj));
1682 TGraphErrors *g1 =
new TGraphErrors(96, eta_value, eta_par1_value,
nullptr, eta_par1_error);
1683 g1->SetTitle(
"pi0 mean eta; eta; p1");
1684 g1->SetMarkerStyle(20);
1685 g1->SetMarkerColor(2);
1686 g1->SetName(
"eta_p1");
1688 TGraphErrors *g2 =
new TGraphErrors(96, eta_value, eta_par2_value,
nullptr, eta_par2_error);
1689 g2->SetTitle(
"pi0 sigma eta; eta; p2");
1690 g2->SetName(
"eta_p2");
1695 std::cout <<
" finished fit_histos_eta_slice" << std::endl;
1702 gSystem->Exec(ts.c_str());
1704 cal_output =
new TFile(outfile.c_str(),
"UPDATE");
1707 for (
int i = 0;
i < 96;
i++)
1711 TH1F *heta_temp = (TH1F *)
cal_output->Get(b.c_str());
1714 std::cout <<
"got " << b << std::endl;
1717 for (
int j = 0;
j < 256;
j++)
1720 TH1F *h_eta_phi_temp = (TH1F *)
cal_output->Get(hist_name.c_str());
1724 std::cout <<
"finished Loading histos" << std::endl;
1730 for (
int ithirds = 0; ithirds < 3; ithirds++)
1732 for (
int ieta = 0 + ithirds * 32; ieta < (ithirds * 32 + 16); ieta++)
1734 for (
int iphi = 0; iphi < 16; iphi++)
1736 for (
int ipatt_eta = 0; ipatt_eta < 2; ipatt_eta++)
1738 for (
int ipatt_phi = 0; ipatt_phi < 16; ipatt_phi++)
1740 if ((ipatt_eta > 0) || (ipatt_phi > 0))
1754 std::cout <<
" Inside Add_96()." << std::endl;
1755 for (
int ieta = 0; ieta < 16; ieta++)
1757 for (
int iphi = 0; iphi < 16; iphi++)
1759 for (
int ipatt_eta = 0; ipatt_eta < 6; ipatt_eta++)
1761 for (
int ipatt_phi = 0; ipatt_phi < 16; ipatt_phi++)
1763 if ((ipatt_eta > 0) || (ipatt_phi > 0))
1771 std::cout <<
" Finished Add_96(). " << std::endl;