9 #include <reconstruction/modules/KlId/KlongValidation/KlongValidationModule.h>
10 #include <mdst/dataobjects/KlId.h>
12 #include <framework/datastore/StoreArray.h>
13 #include <framework/logging/Logger.h>
14 #include <framework/gearbox/Const.h>
17 #include <reconstruction/modules/KlId/KLMExpert/KlId.h>
18 #include <tracking/dataobjects/TrackClusterSeparation.h>
30 KlongValidationModule::KlongValidationModule():
Module()
32 setDescription(
"Module used by the validation server to generate root files for the K0L validation. It calculates fake rates and efficiencies.");
34 "Name of the output root file (must end with .root)",
37 "If cut < 0, then only the neutral KLMClusters will be used. Otherwise, only the KLMClusters that satisfies the selection will be used.",
54 m_Phi_Pass =
new TH1F(
"Phi Passed",
"Passed #Phi;#Phi [rad];Count", 32, -3.2, 3.2);
55 m_Phi_all =
new TH1F(
"Phi All",
"All #Phi;#Phi [rad];Count", 32, -3.2, 3.2);
56 m_effPhi =
new TH1F(
"Phi Efficiency",
"Efficiency #Phi;#Phi [rad];Efficiency", 32, -3.2, 3.2);
58 m_Theta_Pass =
new TH1F(
"Theta Passed",
"Passed #Theta;#Theta [rad];Count", 32, 0, 3.2);
59 m_Theta_all =
new TH1F(
"Theta All",
"All #Theta;#Theta [rad];Count", 32, 0, 3.2);
60 m_effTheta =
new TH1F(
"Theta Efficiency",
"Efficiency #Theta;#Theta [rad];Efficiency", 32, 0, 3.2);
62 m_Mom_Pass =
new TH1F(
"Momentum Efficiency",
"Efficiency Momentum;Momentum [GeV];Efficiency", 25, 0, 5);
63 m_Mom_all =
new TH1F(
"Momentum Efficiency normalise",
"Efficiency Momentum;Momentum [GeV];Count", 25, 0, 5);
64 m_Mom_all_plot =
new TH1F(
"Momentum Efficiency all, obtained from clusters",
"Efficiency Momentum;Momentum [GeV];Count", 25, 0,
66 m_effMom =
new TH1F(
"Momentum Efficiency obtained from cluster",
"Efficiency Momentum;Momentum [GeV];Efficiency", 25, 0, 5);
68 m_fakePhi_Pass =
new TH1F(
"Phi Fake Passsed",
"Fake Passed #Phi;#Phi [rad];Count", 32, -3.2, 3.2);
69 m_fakePhi =
new TH1F(
"Phi Fake Rate",
"Fake Rate #Phi;#Phi [rad];Fake Rate", 32, -3.2, 3.2);
71 m_fakeTheta_Pass =
new TH1F(
"Theta Fake Passed",
"Fake Passed #Theta;#Theta [rad];Count", 32, 0, 3.2);
72 m_fakeTheta =
new TH1F(
"Theta Fake Rate",
"Fake Rate #Theta;#Theta [rad];Fake Rate", 32, 0, 3.2);
74 m_fakeMom_Pass =
new TH1F(
"Momentum Fake Passed",
"Momentum Fake Passed;Momentum [GeV];Count", 25, 0, 5);
75 m_fakeMom =
new TH1F(
"Momentum Fake Rate",
"Momentum Fake Rate;Momentum [GeV];Fake Rate", 25, 0, 5);
77 m_time =
new TH1F(
"KLM Cluster Time",
"Cluster Timing;Cluster time [ns];Count", 200, -30, 70);
78 m_trackSep =
new TH1F(
"KLM trackSeperation Distance",
"KLM trackSeperation Distance;Distance [mm];Count", 100, 0, 4000);
79 m_nLayer =
new TH1F(
"KLM N-Layer",
"N-layer;N-layer;count", 20, 0, 20);
81 m_bkgPhi =
new TH1F(
"Phi Beam BKG",
"BeamBKG #Phi;#Phi [rad];Background count", 32, -3.2, 3.2);
82 m_bkgTheta =
new TH1F(
"Theta Beam BKG",
"BeamBKG #Theta;#Theta [rad];Background count", 32, 0, 3.2);
83 m_bkgMom =
new TH1F(
"Momentum Beam BKG",
"BeamBKG #Momentum;#Momentum [GeV];Background count", 25, 0, 5);
85 m_innermostLayer =
new TH1F(
"Innermost layer",
"Innermost layer;Innermost layer; Count", 20, 0, 20);
86 m_trackFlag =
new TH1F(
"Track flag",
"TrackFlag;Flag; Count", 2, 0, 1);
87 m_ECLFlag =
new TH1F(
"ECL flag",
"ECLFlag;Flag; Count", 2, 0, 1);
113 auto klidObj = cluster.getRelatedTo<
KlId>();
124 if (!cluster.getAssociatedTrackFlag()) {
132 if (mcpart ==
nullptr) {
137 while (!(mcpart -> getMother() ==
nullptr)) {
142 mcpart = mcpart -> getMother();
148 double time = cluster.getTime();
149 double nLayer = cluster.getLayers();
150 double trackSep = 1.0e20;
152 for (
auto trackSeperation : trackSeperations) {
154 if (dist < trackSep) {
166 m_phi = cluster.getMomentum().Phi();
167 m_theta = cluster.getMomentum().Theta();
168 m_momentum = std::abs(cluster.getMomentumMag());
216 m_trackFlag->Fill(cluster.getAssociatedTrackFlag());
217 m_ECLFlag->Fill(cluster.getAssociatedEclClusterFlag());
245 std::vector<double> efficiency(
m_xbins.size());
246 std::vector<double> purity(
m_xbins.size());
247 std::vector<double> backrej(
m_xbins.size());
250 for (
unsigned int i = 0; i <
m_xbins.size() - 1; ++i) {
253 if ((NtruePositive + NfalsePositive) <= 0) {
256 purity[i] = NtruePositive / (NtruePositive + NfalsePositive);
259 backrej[i] = 1 - NfalsePositive / NallFakes;
263 if (NallKlong <= 0) {
264 B2WARNING(
"No Klongs found in ROC calculation.");
266 efficiency[i] = NtruePositive / NallKlong;
270 m_ROC =
new TGraph(
m_xbins.size(), efficiency.data(), purity.data());
273 m_ROC->SetMarkerStyle(3);
275 m_ROC->SetLineColorAlpha(kBlue, 0.0);
276 m_backRej->SetLineColorAlpha(kBlue, 0.0);
277 m_ROC->GetXaxis()->SetTitle(
"Efficiency");
278 m_backRej->GetXaxis()->SetTitle(
"Efficiency");
279 m_ROC->GetYaxis()->SetTitle(
"Purity");
280 m_backRej->GetYaxis()->SetTitle(
"Background rejection");
281 m_ROC-> SetTitle(
"Klong Purity vs Efficiency");
282 m_backRej-> SetTitle(
"Klong background rejection vs Efficiency");
283 m_ROC-> GetListOfFunctions() -> Add(
new TNamed(
"Description",
284 "Purity vs Efficiency each point represents a cut on the klong ID."));
285 m_ROC -> GetListOfFunctions() -> Add(
new TNamed(
"Check",
"Should be as high as possible"));
286 m_backRej -> GetListOfFunctions() -> Add(
new TNamed(
"Check",
"Should be as high as possible"));
287 m_ROC -> GetListOfFunctions() -> Add(
new TNamed(
"Contact",
"fnc@lnf.infn.it"));
288 m_backRej -> GetListOfFunctions() -> Add(
new TNamed(
"Contact",
"fnc@lnf.infn.it"));
291 std::vector<std::tuple<TH1F*, std::string, std::string, bool>> histograms;
292 std::string defaultCheck{
"Nightly result should not differ significantly from the reference"};
293 histograms.push_back(make_tuple(
m_klidAll,
"KlId distribution", defaultCheck,
true));
294 histograms.push_back(make_tuple(
m_Mom_all_plot,
"All Momenta generated", defaultCheck,
false));
295 histograms.push_back(make_tuple(
m_effPhi,
"KlId efficiency in Phi", defaultCheck,
false));
296 histograms.push_back(make_tuple(
m_effTheta,
"KlId efficiency in Theta",
297 defaultCheck +
"; efficiency must be 0 below 0.3 rad and above 2.7 rad",
true));
298 histograms.push_back(make_tuple(
m_effMom,
"KlId efficiency in Momentum", defaultCheck,
true));
299 histograms.push_back(make_tuple(
m_fakePhi,
"KlId fake rate in Phi", defaultCheck,
false));
300 histograms.push_back(make_tuple(
m_fakeTheta,
"KlId fake rate in Theta",
301 defaultCheck +
"; fake rate must be 0 below 0.3 rad and above 2.7 rad",
true));
302 histograms.push_back(make_tuple(
m_fakeMom,
"KlId fake rate in Momentum", defaultCheck,
true));
303 histograms.push_back(make_tuple(
m_time,
"KLMClusters time", defaultCheck +
"; no secondary peaks",
true));
304 histograms.push_back(make_tuple(
m_trackSep,
"Distance of KLMCluster to closest Track", defaultCheck,
true));
305 histograms.push_back(make_tuple(
m_nLayer,
"KLMClusters nLayer", defaultCheck,
false));
306 histograms.push_back(make_tuple(
m_innermostLayer,
"KLMClusters innermostLayer", defaultCheck,
false));
307 histograms.push_back(make_tuple(
m_bkgPhi,
"Beam bkg in Phi", defaultCheck,
false));
308 histograms.push_back(make_tuple(
m_bkgTheta,
"Beam bkg in Theta",
309 defaultCheck +
"; background must be 0 below 0.3 rad and above 2.7 rad",
false));
310 histograms.push_back(make_tuple(
m_bkgMom,
"Beam bkg in Momentum", defaultCheck,
false));
311 histograms.push_back(make_tuple(
m_trackFlag,
"Track flag", defaultCheck,
false));
312 histograms.push_back(make_tuple(
m_ECLFlag,
"ECLCluster flag", defaultCheck,
false));
314 for (
auto hist : histograms) {
315 std::get<0>(hist) -> SetTitle(std::get<1>(hist).c_str());
316 std::get<0>(hist) -> GetListOfFunctions() -> Add(
new TNamed(
"Description", std::get<1>(hist)));
317 std::get<0>(hist) -> GetListOfFunctions() -> Add(
new TNamed(
"Check", std::get<2>(hist).c_str()));
318 std::get<0>(hist) -> GetListOfFunctions() -> Add(
new TNamed(
"Contact",
"fnc@lnf.infn.it"));
319 if (std::get<3>(hist))
320 std::get<0>(hist) -> GetListOfFunctions() -> Add(
new TNamed(
"MetaOptions",
"shifter,pvalue-warn=0.99,pvalue-error=0.02"));
322 std::get<0>(hist) -> GetListOfFunctions() -> Add(
new TNamed(
"MetaOptions",
"pvalue-warn=0.99,pvalue-error=0.1"));
323 std::get<0>(hist) -> Write();
int getPDGCode() const
PDG code.
static const ParticleType Klong
K^0_L particle.
Klong identifcation (KlId) datastore object to store results from KlId calculations.
TH1F * m_Mom_Pass
momentum efficiency
TH1F * m_effTheta
efficiency in angle to z
TH1F * m_nLayer
layer count plot
bool m_passed
did cluster pass selection of algorythm?
TH1F * m_trackSep
track separation distance plot
TH1F * m_Mom_all_plot
momentum efficiency
TH1F * m_Theta_Pass
efficiency in angle to z
TH1F * m_fakeMom_Pass
fake momentum plot
TFile * m_f
root tree etc.
TH1F * m_klidAll
used for roc
StoreArray< KLMCluster > m_klmClusters
storearrays
virtual void initialize() override
initialize
TGraph * m_backRej
background rejection
TH1F * m_fakePhi_Pass
fake phi, angle in x-y
virtual void event() override
process event
const std::vector< double > m_xbins
bins used for the ROC plots
virtual void endRun() override
end run
virtual void terminate() override
terminate
TH1F * m_fakeTheta_Pass
fake theta, angle to z
TH1F * m_klidFake
used for roc
TH1F * m_Phi_Pass
efficiency in x-y plane
double m_theta
angle in z-plane
double m_momentum
momentum
TH1F * m_Phi_all
efficiency in x-y plane
TH1F * m_trackFlag
track flag
virtual void beginRun() override
beginn run
TH1F * m_klidTrue
used for roc
std::string m_outputName
output file name
TH1F * m_time
cluster timing plot
float m_KlIdCut
of > 0 use Klid else use trackflag as reconstruction criterion
TH1F * m_ECLFlag
ECL flag.
virtual ~KlongValidationModule()
Destructor
bool m_isBeamBKG
is beam bkg
StoreArray< MCParticle > m_mcParticles
storearrays
TH1F * m_innermostLayer
innermostlayer
bool m_faked
cluster wrongly reconstructed as K0L?
bool m_reconstructedAsKl
cluster reconstructed as K0L?
TH1F * m_fakeTheta
fake theta, angle to z
TH1F * m_effMom
momentum efficiency
TH1F * m_effPhi
efficiency in x-y plane
TH1F * m_Mom_all
momentum efficiency
TH1F * m_fakeMom
fake momentum plot
TH1F * m_fakePhi
fake phi, angle in x-y
TH1F * m_Theta_all
efficiency in angle to z
A Class to store the Monte Carlo particle information.
void setDescription(const std::string &description)
Sets the description of the module.
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
Store one Track-KLMCluster separation as a ROOT object.
double getDistance() const
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Helper functions for all klid modules to improve readability of the code.
bool isKLMClusterSignal(const Belle2::KLMCluster &cluster, float mcWeigthCut=0.66)
checks if a cluster is signal under the mcWeightcondition (mcWeight = energy deposition)
Abstract base class for different kinds of events.