3 #include <calobase/RawTower.h>
4 #include <calobase/RawTowerContainer.h>
5 #include <calobase/RawTowerGeom.h>
6 #include <calobase/RawTowerGeomContainer.h>
7 #include <calobase/TowerInfo.h>
8 #include <calobase/TowerInfoContainer.h>
23 #include <TGraphErrors.h>
50 return par[0] *
LCE_grff->Eval(x[0] * par[1],
nullptr,
"S");
80 , _inputnodename(
"TOWERINFO")
88 std::cout <<
"in init run " << std::endl;
92 std::cout <<
Name() <<
": No Calo Type set" << std::endl;
107 hcalin_energy_eta =
new TH2F(
"hcalin_energy_eta",
"hcalin energy eta", 1000, 0, 100, 240, -1.1, 1.1);
108 hcalin_e_eta_phi =
new TH3F(
"hcalin_e_eta_phi",
"hcalin e eta phi", 50, 0, 14, 24, -1.1, 1.1, 64, -3.14159, 3.14159);
111 for (
int i = 0;
i < 24;
i++)
113 for (
int j = 0;
j < 64;
j++)
117 hcal_in_eta_phi[
i][
j] =
new TH1F(hist_name.c_str(),
"Hcal_in_energy", 40000, 0, 4);
121 for (
int i = 0;
i < 25;
i++)
128 hcalin_eta[
i] =
new TH1F(hist_name.c_str(),
"hcalin eta's", 40000, 0, 4.);
132 hcalin_eta[
i] =
new TH1F(hist_name.c_str(),
"hcalin eta's", 2000000, 0, 4.);
138 hcalout_energy_eta =
new TH2F(
"hcalout_energy_eta",
"hcalout energy eta", 100, 0, 10, 240, -1.1, 1.1);
139 hcalout_e_eta_phi =
new TH3F(
"hcalout_e_eta_phi",
"hcalout e eta phi", 48, 0, 10, 24, -1.1, 1.1, 64, -3.14159, 3.14159);
142 for (
int i = 0;
i < 24;
i++)
144 for (
int j = 0;
j < 64;
j++)
148 hcal_out_eta_phi[
i][
j] =
new TH1F(hist_name.c_str(),
"Hcal_out energy", 20000, 0, 10);
153 for (
int i = 0;
i < 25;
i++)
158 hcalout_eta[
i] =
new TH1F(hist_name.c_str(),
"hcalout eta's", 20000, 0, 10);
162 hcalout_eta[
i] =
new TH1F(hist_name.c_str(),
"hcalout eta's", 1000000, 0, 10);
170 for (
int i = 0;
i < 96;
i++)
172 for (
int j = 0;
j < 256;
j++)
176 cemc_hist_eta_phi[
i][
j] =
new TH1F(hist_name.c_str(),
"Hist_ieta_phi_leaf(e)", 5000, 0, 10);
181 for (
int i = 0;
i < 97;
i++)
183 gStyle->SetOptFit(1);
188 eta_hist[
i] =
new TH1F(b.c_str(),
"eta and all phi's", 5000, 0, 10);
192 eta_hist[
i] =
new TH1F(b.c_str(),
"eta and all phi's", 1000000, 0, 10);
197 energy_eta_hist =
new TH2F(
"energy_eta_hist",
"energy eta and all phi", 512, 0, 10, 960, -1.15, 1.15);
200 e_eta_phi =
new TH3F(
"e_eta_phi",
"e v eta v phi", 50, 0, 10, 192, -1.1335, 1.13350, 256, -3.14159, 3.14159);
219 std::cout <<
"LiteCaloEval::process_event(PHCompositeNode *topNode) Processing Event " <<
_ievent << std::endl;
246 towers = findNode::getClass<RawTowerContainer>(topNode, towernode);
249 std::cout <<
PHWHERE <<
" ERROR: Can't find " << towernode << std::endl;
255 towergeom = findNode::getClass<RawTowerGeomContainer>(topNode, towergeomnode);
258 std::cout <<
PHWHERE <<
" ERROR: Can't find " << towergeomnode << std::endl;
263 rtiter = begin_end.first;
268 std::cout <<
"mode is set " << std::endl;
283 towerinfos = findNode::getClass<TowerInfoContainer>(topNode, towernode.c_str());
287 std::cout <<
PHWHERE <<
" ERROR: Can't find " << towernode << std::endl;
293 unsigned int nchannels = -1;
297 nchannels = towerinfos->
size();
301 nchannels = towers->
size();
322 std::cout <<
"ERROR: Recheck iteration process with rtiter variable" << std::endl;
326 unsigned int ieta = 99999;
327 unsigned int iphi = 99999;
343 tower = rtiter->second;
355 std::cout <<
PHWHERE <<
" ERROR: Can't find tower geometry for this tower hit: ";
366 if (ieta > 95 || iphi > 256)
369 std::cout <<
"ieta or iphi not set correctly/ was less than 0 " << std::endl;
396 int ppkket = pket % 3;
398 e *= 0.88 + llet * 0.04 - 0.01 + 0.01 * ppkket;
425 e *= 0.945 + llet * 0.02;
452 e *= 0.945 + llet * 0.02;
486 std::cout <<
" writing lite calo file" << std::endl;
798 std::cout <<
"need infile to run LiteCaloEval::Get_Histos" << std::endl;
808 gSystem->Exec(ts.Data());
809 f_temp =
new TFile(outfile,
"UPDATE");
814 f_temp =
new TFile(infile);
830 for (
int i = 0;
i < max_ieta+1;
i++)
834 TString
b =
"eta_" +
a;
846 TH1F *heta_temp = (TH1F *)
f_temp->Get(b.Data());
848 if (!heta_temp &&
i == 0)
850 std::cout <<
" warning hist " << b.Data() <<
" not found" << std::endl;
865 if (! (
i < max_ieta) )
869 for (
int j = 0;
j < max_iphi;
j++)
885 std::cout <<
"getting " << hist_name_p << std::endl;
889 TH1F *heta_tempp = (TH1F *)
f_temp->Get(hist_name_p.c_str());
891 if (!heta_tempp &&
i == 0)
893 std::cout <<
" warning hist " << hist_name_p.c_str() <<
" not found" << std::endl;
915 bool onlyEta =
false;
927 float par_value[96] = {0};
928 float par_err[96] = {0};
929 float eta_value[96] = {0};
930 float eta_err[96] = {0};
939 TF1 *
f1 =
new TF1(
"myexpo",
LCE_fitf, 0.1, 10, 2);
940 f1->SetParameters(1.0, 1.0);
943 if (modeFitShifts % 10 == 1)
952 int addSmooth = modeFitShifts % 100 / 10;
955 nsmooth += addSmooth;
959 bool flag_fit_rings =
false;
963 if (modeFitShifts % 1000 / 100 == 1)
965 flag_fit_rings =
true;
981 TH2F *corrPat =
new TH2F(
"corrPat",
"", max_ieta, 0, max_ieta, max_iphi, 0, max_iphi);
983 if (flag_fit_rings ==
true)
987 corrPat->SetMinimum(0.95);
988 corrPat->SetMaximum(1.03);
992 corrPat->SetMinimum(0.92);
993 corrPat->SetMaximum(1.05);
1000 corrPat->SetMinimum(0.87);
1001 corrPat->SetMaximum(1.09);
1005 corrPat->SetMinimum(0.9450);
1006 corrPat->SetMaximum(1.0764);
1011 int maxbin = max_ieta;
1020 TH1F *hnewf =
nullptr;
1023 for (
int i = minbin;
i < maxbin;
i++)
1030 TString myClnm =
"newhc_eta";
1031 myClnm = myClnm +
i;
1033 TString myClnm2 =
"gnewhc_eta";
1034 myClnm2 = myClnm2 +
i;
1044 TH1F *cleanEtaRef =
nullptr;
1045 TString cleanEta =
"cleanEtaRef_";
1050 if (flag_fit_rings ==
true)
1053 cleanEtaRef = (TH1F *)
eta_hist[iik]->Clone(cleanEta.Data());
1069 cleanEtaRef->Rebin(5);
1075 hnewf = (TH1F *) ref_lce->
eta_hist[iik]->Clone(myClnm.Data());
1082 if (flag_fit_rings ==
true)
1086 cleanEtaRef = (TH1F *)
hcalout_eta[iik]->Clone(cleanEta.Data());
1090 for (
int b = 14;
b <= 19;
b++)
1096 cleanEtaRef->Rebin(10);
1097 cleanEtaRef->Rebin(2);
1103 hnewf = (TH1F *) ref_lce->
hcalout_eta[iik]->Clone(myClnm.Data());
1111 if (flag_fit_rings ==
true)
1114 cleanEtaRef = (TH1F *)
hcalin_eta[iik]->Clone(cleanEta.Data());
1117 cleanEtaRef->Rebin(10);
1118 cleanEtaRef->Rebin(10);
1122 hnewf = (TH1F *) ref_lce->
hcalin_eta[iik]->Clone(myClnm.Data());
1128 if (flag_fit_rings ==
true)
1130 cleanEtaRef->Smooth(nsmooth);
1131 LCE_grff =
new TGraph(cleanEtaRef);
1136 hnewf->Smooth(nsmooth);
1153 std::cout <<
"fitting " << i << std::endl;
1156 f2f = (TF1 *)
eta_hist[i]->GetFunction(
"myexpo");
1173 f2f = (TF1 *)
hcalout_eta[i]->GetFunction(
"myexpo");
1189 f2f = (TF1 *)
hcalin_eta[i]->GetFunction(
"myexpo");
1194 TGraph *grT =
new TGraph(1000);
1195 grT->SetName(myClnm2.Data());
1197 for (
int jjk = 0; jjk < 1000; jjk++)
1200 grT->SetPoint(jjk, xjj, f2f->Eval(xjj));
1208 a1f = f2f->GetParameter(1);
1209 b1f = f2f->GetParError(1);
1219 if (onlyEta ==
true)
1228 for (
int j = 0;
j < max_iphi;
j++)
1261 TString myClnmp =
"newhc_eta";
1262 myClnmp = myClnmp + 1000 * (i + 2) +
j;
1264 TString myClnm2p =
"gnewhc_eta";
1265 myClnm2p = myClnm2p + 1000 * (i + 2) +
j;
1269 std::cout <<
" making fitting " << myClnmp.Data() << std::endl;
1273 TH1F *hnewfp =
nullptr;
1279 if (flag_fit_rings ==
true)
1298 if (flag_fit_rings ==
true)
1317 if (flag_fit_rings ==
true)
1331 std::cout <<
"got neweff phi eta ... fitting w/ fit min,max: " <<
fitmin
1332 <<
" " <<
fitmax << std::endl;
1340 if (flag_fit_rings ==
false)
1342 hnewfp->Smooth(nsmooth);
1346 if (flag_fit_rings ==
true)
1349 LCE_grff =
new TGraph(cleanEtaRef);
1353 TF1 *f2f2 =
nullptr;
1359 if (flag_fit_rings == 1)
1361 scaleP0 /= cleanEtaRef->Integral(cleanEtaRef->FindBin(
fitmin), cleanEtaRef->FindBin(
fitmax));
1365 scaleP0 /= hnewfp->Integral(hnewfp->FindBin(
fitmin), hnewfp->FindBin(
fitmax));
1368 f1->SetParameters(scaleP0, 1.0);
1382 if (flag_fit_rings ==
true)
1392 if (flag_fit_rings == 1)
1394 scaleP0 /= cleanEtaRef->Integral(cleanEtaRef->FindBin(
fitmin), cleanEtaRef->FindBin(
fitmax));
1398 scaleP0 /= hnewfp->Integral(hnewfp->FindBin(
fitmin), hnewfp->FindBin(
fitmax));
1402 f1->SetParameters(scaleP0, 1.0);
1416 if (flag_fit_rings ==
true)
1426 if (flag_fit_rings == 1)
1428 scaleP0 /= cleanEtaRef->Integral(cleanEtaRef->FindBin(
fitmin), cleanEtaRef->FindBin(
fitmax));
1433 scaleP0 /= hnewfp->Integral(hnewfp->FindBin(
fitmin), hnewfp->FindBin(
fitmax));
1436 f1->SetParameters(scaleP0, 1.0);
1449 if (flag_fit_rings ==
true)
1456 TGraph *local_grT =
new TGraph(1000);
1457 local_grT->SetName(myClnm2p.Data());
1459 for (
int jjk = 0; jjk < 1000; jjk++)
1463 local_grT->SetPoint(jjk, xjj, f2f2->Eval(xjj));
1468 float a1fp = f2f2->GetParameter(1);
1469 float b1fp = f2f2->GetParError(1);
1475 corrPat->SetBinContent(i + 1,
j + 1, 1 / a1fp);
1476 corrPat->SetBinError(i + 1,
j + 1, 1 / b1fp);
1483 TGraphErrors g1(max_ieta, eta_value, par_value, eta_err, par_err);
1484 g1.SetTitle(
"fitted shifts; eta; p1");
1485 g1.SetMarkerStyle(20);
1487 g1.SetName(
"Fit1_etaout");
1494 std::cout <<
"TowerSlope module: writing emcal correction tree into output file"
1496 TTree *
t1 =
new TTree(
"emc_corr_tree",
"a tree of simple emcal calib corrections");
1499 t1->Branch(
"corr", &corr,
"corr/F");
1500 t1->Branch(
"towid", &towid,
"towid/I");
1502 for (
int mjl = 0; mjl < max_ieta; mjl++)
1504 for (
int mjk = 0; mjk < max_iphi; mjk++)
1506 towid = mjl * 1000 + mjk;
1507 corr = corrPat->GetBinContent(mjl + 1, mjk + 1);
1525 std::string hcal_corr_file_name =
"HCAL_CORR_TXTFILE";
1528 hcal_corr_file_name +=
f_temp->GetName();
1529 hcal_corr_file_name +=
".txt";
1532 std::cout <<
"TowerSlope module: writing hcal corrections into output file "
1533 << hcal_corr_file_name
1536 std::ofstream out_hcal_corrF(hcal_corr_file_name.c_str());
1538 for (
int mjl = 0; mjl < max_ieta; mjl++)
1540 for (
int mjk = 0; mjk < max_iphi; mjk++)
1542 float corr = corrPat->GetBinContent(mjl + 1, mjk + 1);
1552 out_hcal_corrF << mjl <<
" "
1554 << corr << std::endl;
1558 out_hcal_corrF.close();