7 #include <calobase/RawCluster.h>
8 #include <calobase/RawClusterContainer.h>
9 #include <calobase/RawClusterUtility.h>
10 #include <calobase/RawTowerGeom.h>
11 #include <calobase/RawTowerGeomContainer.h>
12 #include <calobase/TowerInfo.h>
13 #include <calobase/TowerInfoContainer.h>
14 #include <calobase/TowerInfoDefs.h>
29 #include <TLorentzVector.h>
33 #include <CLHEP/Vector/ThreeVector.h>
43 , outfilename(filename)
65 for (
int i = 0;
i < 96;
i++)
67 h_mass_eta_lt[
i] =
new TH1F(Form(
"h_mass_eta_lt%d",
i),
"", 50, 0, 0.5);
70 h_cemc_etaphi =
new TH2F(
"h_cemc_etaphi",
"", 96, 0, 96, 256, 0, 256);
73 h_InvMass =
new TH1F(
"h_InvMass",
"Invariant Mass", 120, 0, 1.2);
74 h_InvMassMix =
new TH1F(
"h_InvMassMix",
"Invariant Mass", 120, 0, 1.2);
77 h_etaphi_clus =
new TH2F(
"h_etaphi_clus",
"", 140, -1.2, 1.2, 64, -1 * M_PI, M_PI);
78 h_clusE =
new TH1F(
"h_clusE",
"", 100, 0, 10);
82 h_pt1 =
new TH1F(
"h_pt1",
"", 100, 0, 5);
83 h_pt2 =
new TH1F(
"h_pt2",
"", 100, 0, 5);
85 h_nclusters =
new TH1F(
"h_nclusters",
"", 1000, 0, 1000);
108 float emcal_hit_threshold = 0.5;
112 float maxAlpha = 0.6;
113 float clus_chisq_cut = 4;
114 float nClus_ptCut = 0.5;
115 int max_nClusCount = 300;
119 GlobalVertexMap* vertexmap = findNode::getClass<GlobalVertexMap>(topNode,
"GlobalVertexMap");
123 std::cout <<
"pi0EtaByEta GlobalVertexMap node is missing" << std::endl;
127 if (vertexmap && !vertexmap->
empty())
132 vtx_z = vtx->
get_z();
136 std::vector<float> ht_eta;
137 std::vector<float> ht_phi;
141 TowerInfoContainer* towers = findNode::getClass<TowerInfoContainer>(topNode,
"TOWERINFO_CALIB_CEMC");
153 if (!isGood && offlineenergy > 0.2)
155 ht_eta.push_back(ieta);
156 ht_phi.push_back(iphi);
162 if (offlineenergy > emcal_hit_threshold)
169 RawClusterContainer* clusterContainer = findNode::getClass<RawClusterContainer>(topNode,
"CLUSTERINFO_CEMC2");
170 if (!clusterContainer)
172 std::cout <<
PHWHERE <<
"funkyCaloStuff::process_event - Fatal Error - CLUSTER_CEMC node is missing. " << std::endl;
179 RawTowerGeomContainer* m_geometry = findNode::getClass<RawTowerGeomContainer>(topNode, towergeomnodename);
182 std::cout <<
Name() <<
"::"
184 <<
": Could not find node " << towergeomnodename << std::endl;
185 throw std::runtime_error(
"failed to find TOWERGEOM node in RawClusterDeadHotMask::CreateNodeTree");
192 for (clusterIter = clusterEnd.first; clusterIter != clusterEnd.second; clusterIter++)
194 RawCluster* recoCluster = clusterIter->second;
196 CLHEP::Hep3Vector
vertex(0, 0, vtx_z);
199 float clus_pt = E_vec_cluster.perp();
200 float clus_chisq = recoCluster->
get_chi2();
202 if (clus_pt < nClus_ptCut)
206 if (clus_chisq > clus_chisq_cut)
216 if (nClusCount > max_nClusCount)
222 float pt1ClusCut = 1.3;
223 float pt2ClusCut = 0.7;
227 pt1ClusCut += 1.4 * (nClusCount - 29) / 200.0;
228 pt2ClusCut += 1.4 * (nClusCount - 29) / 200.0;
231 float pi0ptcut = 1.22 * (pt1ClusCut + pt2ClusCut);
233 std::vector<float> save_pt;
234 std::vector<float> save_eta;
235 std::vector<float> save_phi;
236 std::vector<float> save_e;
238 for (clusterIter = clusterEnd.first; clusterIter != clusterEnd.second; clusterIter++)
240 RawCluster* recoCluster = clusterIter->second;
242 CLHEP::Hep3Vector
vertex(0, 0, vtx_z);
245 float clusE = E_vec_cluster.mag();
246 float clus_eta = E_vec_cluster.pseudoRapidity();
247 float clus_phi = E_vec_cluster.phi();
248 float clus_pt = E_vec_cluster.perp();
249 float clus_chisq = recoCluster->
get_chi2();
252 if (clus_chisq > clus_chisq_cut)
260 bool hotClus =
false;
262 unsigned int lt_eta = -1;
263 for (toweriter = towerCR.first; toweriter != towerCR.second; ++toweriter)
276 for (
size_t i = 0;
i < ht_eta.size();
i++)
278 if (towerphi == ht_phi[
i] && towereta == ht_eta[
i])
292 TLorentzVector photon1;
293 photon1.SetPtEtaPhiE(clus_pt, clus_eta, clus_phi, clusE);
295 if (clus_pt < pt1ClusCut || clus_pt > ptClusMax)
300 for (clusterIter2 = clusterEnd.first; clusterIter2 != clusterEnd.second; clusterIter2++)
302 if (clusterIter == clusterIter2)
306 RawCluster* recoCluster2 = clusterIter2->second;
310 float clus2E = E_vec_cluster2.mag();
311 float clus2_eta = E_vec_cluster2.pseudoRapidity();
312 float clus2_phi = E_vec_cluster2.phi();
313 float clus2_pt = E_vec_cluster2.perp();
314 float clus2_chisq = recoCluster2->
get_chi2();
316 if (clus2_pt < pt2ClusCut || clus_pt > ptClusMax)
320 if (clus2_chisq > clus_chisq_cut)
328 bool hotClus2 =
false;
329 for (toweriter2 = towerCR2.first; toweriter2 != towerCR2.second; ++toweriter2)
334 for (
size_t i = 0;
i < ht_eta.size();
i++)
336 if (towerphi == ht_phi[
i] && towereta == ht_phi[
i])
347 TLorentzVector photon2;
348 photon2.SetPtEtaPhiE(clus2_pt, clus2_eta, clus2_phi, clus2E);
350 if (fabs(clusE - clus2E) / (clusE + clus2E) > maxAlpha)
355 if (photon1.DeltaR(photon2) > maxDr)
360 TLorentzVector pi0 = photon1 + photon2;
361 if (pi0.Pt() < pi0ptcut)
366 h_pt1->Fill(photon1.Pt());
367 h_pt2->Fill(photon2.Pt());
396 TF1*
fitFunc =
new TF1(
"fitFunc",
"[0]/[2]/2.5*exp(-0.5*((x-[1])/[2])^2) + [3] + [4]*x + [5]*x^2 + [6]*x^3", h->GetXaxis()->GetXmin(), h->GetXaxis()->GetXmax());
398 fitFunc->SetParameter(0, 5);
400 fitFunc->SetParameter(2, 0.01);
401 fitFunc->SetParameter(3, 0.0);
402 fitFunc->SetParameter(4, 0.0);
403 fitFunc->SetParameter(5, 0.0);
404 fitFunc->SetParameter(6, 100);
406 fitFunc->SetParLimits(0, 0,10);
407 fitFunc->SetParLimits(1, 0.113, 0.25);
408 fitFunc->SetParLimits(2, 0.01, 0.04);
409 fitFunc->SetParLimits(3,-2 ,1 );
410 fitFunc->SetParLimits(4,0 ,40 );
411 fitFunc->SetParLimits(5, -150,50 );
412 fitFunc->SetParLimits(6, 0,200 );
414 fitFunc->SetRange(0.05, 0.7);
417 h->Fit(
"fitFunc",
"QN");
424 TFile* fin =
new TFile(infile.c_str());
425 std::cout <<
"getting hists" << std::endl;
426 TH1F* h_peak_eta =
new TH1F(
"h_peak_eta",
"", 96, 0, 96);
427 TH1F* h_sigma_eta =
new TH1F(
"h_sigma_eta",
"", 96, 0, 96);
428 TH1F* h_p3_eta =
new TH1F(
"h_p3_eta",
"", 96, 0, 96);
429 TH1F* h_p4_eta =
new TH1F(
"h_p4_eta",
"", 96, 0, 96);
430 TH1F* h_p5_eta =
new TH1F(
"h_p5_eta",
"", 96, 0, 96);
431 TH1F* h_p6_eta =
new TH1F(
"h_p6_eta",
"", 96, 0, 96);
432 TH1F* h_p0_eta =
new TH1F(
"h_p0_eta",
"", 96, 0, 96);
435 std::cout <<
"pi0EtaByEta::fitEtaSlices null fin" << std::endl;
439 for (
int i = 0;
i < 96;
i++)
441 h_M_eta[
i] = (TH1F*) fin->Get(Form(
"h_mass_eta_lt%d",
i));
442 h_M_eta[
i]->Scale(1./h_M_eta[
i]->Integral(),
"width");
446 for (
int i = 0;
i < 96;
i++)
450 std::cout <<
"pi0EtaByEta::fitEtaSlices null hist" << std::endl;
454 fitFunOut[
i]->SetName(Form(
"f_pi0_eta%d",i));
455 float mass_val_out = fitFunOut[
i]->GetParameter(1);
456 float mass_err_out = fitFunOut[
i]->GetParError(1);
457 h_peak_eta->SetBinContent(i + 1, mass_val_out);
458 if (isnan(h_M_eta[i]->GetEntries())){
459 h_peak_eta->SetBinError(i + 1, 0);
462 h_peak_eta->SetBinError(i + 1, mass_err_out);
463 h_sigma_eta->SetBinContent(i+1,fitFunOut[i]->
GetParameter(2));
464 h_sigma_eta->SetBinError(i+1,fitFunOut[i]->GetParError(2));
465 h_p3_eta->SetBinContent(i+1,fitFunOut[i]->
GetParameter(3));
466 h_p3_eta->SetBinError(i+1,fitFunOut[i]->GetParError(3));
467 h_p4_eta->SetBinContent(i+1,fitFunOut[i]->
GetParameter(4));
468 h_p4_eta->SetBinError(i+1,fitFunOut[i]->GetParError(4));
469 h_p5_eta->SetBinContent(i+1,fitFunOut[i]->
GetParameter(5));
470 h_p5_eta->SetBinError(i+1,fitFunOut[i]->GetParError(5));
471 h_p6_eta->SetBinContent(i+1,fitFunOut[i]->
GetParameter(6));
472 h_p6_eta->SetBinError(i+1,fitFunOut[i]->GetParError(6));
473 h_p0_eta->SetBinContent(i+1,fitFunOut[i]->
GetParameter(0));
474 h_p0_eta->SetBinError(i+1,fitFunOut[i]->GetParError(0));
480 std::string m_fieldname =
"Femc_datadriven_qm1_correction";
482 for (
int i = 0;
i < 96;
i++)
484 for (
int j = 0;
j < 256;
j++)
489 cdbttree2->SetFloatValue(key, m_fieldname, val1 * correction);
494 cdbttree2->WriteCDBTTree();
498 TFile* fit_out =
new TFile(fitOutFile.c_str(),
"recreate");
500 for (
auto&
i : h_M_eta)
505 for (
auto&
i : fitFunOut)
516 h_sigma_eta->Write();
520 std::cout <<
"finish fitting suc" << std::endl;