11 #include <reconstruction/modules/KlId/KlongValidation/KlongValidationModule.h>
12 #include <mdst/dataobjects/KlId.h>
14 #include <framework/datastore/StoreArray.h>
15 #include <framework/logging/Logger.h>
18 #include <reconstruction/modules/KlId/KLMExpert/KlId.h>
19 #include <tracking/dataobjects/TrackClusterSeparation.h>
33 setDescription(
"Module used by the validation server to generate root files for the K0L validation. It calculates fake rates and efficiencies.");
35 "Name of the output root file (must end with .root)",
38 "If cut < 0, then only the neutral KLMClusters will be used. Otherwise, only the KLMClusters that satisfies the selection will be used.",
55 m_Phi_Pass =
new TH1F(
"Phi Passed",
"Passed #Phi;#Phi;Count", 32, -3.2, 3.2);
56 m_Phi_all =
new TH1F(
"Phi All",
"All #Phi;#Phi;Count", 32, -3.2, 3.2);
57 m_effPhi =
new TH1F(
"Phi Efficiency",
"Efficiency #Phi;#Phi;Efficiency", 32, -3.2, 3.2);
59 m_Theta_Pass =
new TH1F(
"Theta Passed",
"Passed #Theta;#Theta;Count", 32, 0, 3.2);
60 m_Theta_all =
new TH1F(
"Theta All",
"All #Theta;#Theta;Count", 32, 0, 3.2);
61 m_effTheta =
new TH1F(
"Theta Efficiency",
"Efficiency #Theta;#Theta;Efficiency", 32, 0, 3.2);
63 m_Mom_Pass =
new TH1F(
"Momentum Efficiency",
"Efficiency Momentum;Momentum;Efficiency", 25, 0, 5);
64 m_Mom_all =
new TH1F(
"Momentum Efficiency normalise",
"Efficiency Momentum;Momentum;Count", 25, 0, 5);
65 m_Mom_all_plot =
new TH1F(
"Momentum Efficiency all, obtained from clusters",
"Efficiency Momentum;Momentum;Count", 25, 0, 5);
66 m_effMom =
new TH1F(
"Momentum Efficiency obtained from cluster",
"Efficiency Momentum;Momentum;Efficiency", 25, 0, 5);
68 m_fakePhi_Pass =
new TH1F(
"Phi Fake Passsed",
"Fake Passed #Phi;#Phi;Count", 32, -3.2, 3.2);
69 m_fakePhi =
new TH1F(
"Phi Fake Rate",
"Fake Rate #Phi;#Phi;Fake Rate", 32, -3.2, 3.2);
71 m_fakeTheta_Pass =
new TH1F(
"Theta Fake Passed",
"Fake Passed #Theta;#Theta;Count", 32, 0, 3.2);
72 m_fakeTheta =
new TH1F(
"Theta Fake Rate",
"Fake Rate #Theta;#Theta;Fake Rate", 32, 0, 3.2);
74 m_fakeMom_Pass =
new TH1F(
"Momentum Fake Passed",
"Momentum Fake Passed;Momentum;Count", 25, 0, 5);
75 m_fakeMom =
new TH1F(
"Momentum Fake Rate",
"Momentum Fake Rate;Momentum;Fake Rate", 25, 0, 5);
77 m_time =
new TH1F(
"KLM Cluster Time",
"Cluster Timing;Cluster time;Count", 20, -5, 15);
78 m_trackSep =
new TH1F(
"KLM trackSeperation Distance",
"KLM trackSeperation Distance;Distance;Count", 100, 0, 4000);
79 m_energy =
new TH1F(
"KLM Energy",
"KLM Energy;Energy;count", 25, 0, 5);
80 m_nLayer =
new TH1F(
"KLM N-Layer",
"N-layer;N-layer;count", 20, 0, 20);
82 m_bkgPhi =
new TH1F(
"Phi Beam BKG",
"BeamBKG #Phi;#Phi;Background count", 32, -3.2, 3.2);
83 m_bkgTheta =
new TH1F(
"Theta Beam BKG",
"BeamBKG #Theta;#Theta;Background count", 32, 0, 3.2);
84 m_bkgMom =
new TH1F(
"Momentum Beam BKG",
"BeamBKG #Momentum;#Momentum;Background count", 25, 0, 5);
86 m_innermostLayer =
new TH1F(
"Innermost layer",
"Innermost layer;Innermost layer; Count", 20, 0, 20);
87 m_trackFlag =
new TH1F(
"Track flag",
"TrackFlag;Flag; Count", 2, 0, 1);
88 m_ECLFlag =
new TH1F(
"ECL flag",
"ECLFlag;Flag; Count", 2, 0, 1);
114 auto klidObj = cluster.getRelatedTo<
KlId>();
125 if (!cluster.getAssociatedTrackFlag()) {
133 if (mcpart ==
nullptr) {
138 while (!(mcpart -> getMother() ==
nullptr)) {
139 if (mcpart -> getPDG() == 130) {
143 mcpart = mcpart -> getMother();
149 double time = cluster.getTime();
150 double nLayer = cluster.getLayers();
151 double energy = cluster.getEnergy();
152 double trackSep = 1.0e20;
154 for (
auto trackSeperation : trackSeperations) {
156 if (dist < trackSep) {
168 m_phi = cluster.getMomentum().Phi();
169 m_theta = cluster.getMomentum().Theta();
170 m_momentum = std::abs(cluster.getMomentumMag());
220 m_trackFlag->Fill(cluster.getAssociatedTrackFlag());
221 m_ECLFlag->Fill(cluster.getAssociatedEclClusterFlag());
249 std::vector<double> efficiency(
m_xbins.size());
250 std::vector<double> purity(
m_xbins.size());
251 std::vector<double> backrej(
m_xbins.size());
254 for (
unsigned int i = 0; i <
m_xbins.size() - 1; ++i) {
257 if ((NtruePositive + NfalsePositive) <= 0) {
260 purity[i] = NtruePositive / (NtruePositive + NfalsePositive);
263 backrej[i] = 1 - NfalsePositive / NallFakes;
267 if (NallKlong <= 0) {
268 B2WARNING(
"No Klongs found in ROC calculation.");
270 efficiency[i] = NtruePositive / NallKlong;
274 m_ROC =
new TGraph(
m_xbins.size(), efficiency.data(), purity.data());
277 m_ROC->SetMarkerStyle(3);
279 m_ROC->SetLineColorAlpha(kBlue, 0.0);
280 m_backRej->SetLineColorAlpha(kBlue, 0.0);
281 m_ROC->GetXaxis()->SetTitle(
"Efficiency");
282 m_backRej->GetXaxis()->SetTitle(
"Efficiency");
283 m_ROC->GetYaxis()->SetTitle(
"Purity");
284 m_backRej->GetYaxis()->SetTitle(
"Background rejection");
285 m_ROC-> SetTitle(
"Klong Purity vs Efficiency");
286 m_backRej-> SetTitle(
"Klong background rejection vs Efficiency");
287 m_ROC-> GetListOfFunctions() -> Add(
new TNamed(
"Description",
288 "Purity vs Efficiency each point represents a cut on the klong ID."));
289 m_ROC -> GetListOfFunctions() -> Add(
new TNamed(
"Check",
"Should be as high as possible"));
290 m_backRej -> GetListOfFunctions() -> Add(
new TNamed(
"Check",
"Should be as high as possible"));
291 m_ROC -> GetListOfFunctions() -> Add(
new TNamed(
"Contact",
"fnc@lnf.infn.it"));
292 m_backRej -> GetListOfFunctions() -> Add(
new TNamed(
"Contact",
"fnc@lnf.infn.it"));
295 std::vector<std::tuple<TH1F*, std::string, bool>> histograms;
296 histograms.push_back(make_tuple(
m_klidAll,
"KlId distribution",
true));
297 histograms.push_back(make_tuple(
m_Mom_all_plot,
"All Momenta generated",
false));
298 histograms.push_back(make_tuple(
m_effPhi,
"KlId efficiency in Phi",
false));
299 histograms.push_back(make_tuple(
m_effTheta,
"KlId efficiency in Theta",
true));
300 histograms.push_back(make_tuple(
m_effMom,
"KlId efficiency in Momentum",
true));
301 histograms.push_back(make_tuple(
m_fakePhi,
"KlId fake rate in Phi",
false));
302 histograms.push_back(make_tuple(
m_fakeTheta,
"KlId fake rate in Theta",
true));
303 histograms.push_back(make_tuple(
m_fakeMom,
"KlId fake rate in Momentum",
true));
304 histograms.push_back(make_tuple(
m_time,
"KLMClusters time",
true));
305 histograms.push_back(make_tuple(
m_trackSep,
"Distance of KLMCluster to closest Track",
true));
306 histograms.push_back(make_tuple(
m_energy,
"KLMClusters energy",
false));
307 histograms.push_back(make_tuple(
m_nLayer,
"KLMClusters nLayer",
false));
308 histograms.push_back(make_tuple(
m_innermostLayer,
"KLMClusters innermostLayer",
false));
309 histograms.push_back(make_tuple(
m_bkgPhi,
"Beam bkg in Phi",
false));
310 histograms.push_back(make_tuple(
m_bkgTheta,
"Beam bkg in Theta",
false));
311 histograms.push_back(make_tuple(
m_bkgMom,
"Beam bkg in Momentum",
false));
312 histograms.push_back(make_tuple(
m_trackFlag,
"Track flag",
false));
313 histograms.push_back(make_tuple(
m_ECLFlag,
"ECLCluster flag",
false));
315 for (
auto hist : histograms) {
316 std::get<0>(hist) -> SetTitle(std::get<1>(hist).c_str());
317 std::get<0>(hist) -> GetListOfFunctions() -> Add(
new TNamed(
"Description", std::get<1>(hist)));
318 std::get<0>(hist) -> GetListOfFunctions() -> Add(
new TNamed(
"Check",
"Should not change"));
319 std::get<0>(hist) -> GetListOfFunctions() -> Add(
new TNamed(
"Contact",
"fnc@lnf.infn.it"));
320 if (std::get<2>(hist))
321 std::get<0>(hist) -> GetListOfFunctions() -> Add(
new TNamed(
"MetaOptions",
"shifter,pvalue-warn=0.99,pvalue-error=0.1"));
323 std::get<0>(hist) -> GetListOfFunctions() -> Add(
new TNamed(
"MetaOptions",
"pvalue-warn=0.99,pvalue-error=0.1"));
324 std::get<0>(hist) -> Write();