9#include <analysis/modules/CurlTagger/CurlTaggerModule.h>
11#include <framework/datastore/StoreObjPtr.h>
13#include <analysis/dataobjects/ParticleList.h>
15#include <analysis/variables/TrackVariables.h>
16#include <analysis/variables/Variables.h>
17#include <analysis/variables/MCTruthVariables.h>
23#include <analysis/modules/CurlTagger/Bundle.h>
24#include <analysis/modules/CurlTagger/SelectorCut.h>
25#include <analysis/modules/CurlTagger/SelectorMVA.h>
42 R
"DOC(Curl Tagger is a tool designed to identify and tag extra tracks caused by low pt particles curling around the detector. For further documentation please see 'tagCurlTracks' in modularAnalysis.)DOC");
46 addParam(
"belle",
m_BelleFlag,
"flag to distinuguish Belle (true) from Belle II (false) data",
false);
47 addParam(
"ptCut",
m_PtCut,
"Preselection pt cut. Only consider tracks below threshold as candidates for curlers.", 0.5);
49 "the name of the selector to use when deciding if two reconstructed particles are the same true particle, available : 'cut', 'mva'",
52 "additionally bundles the particles using their genParticleIndex and tags them with extraInfo(isTruthCurl) and extraInfo(truthBundleSize).",
54 addParam(
"train",
m_TrainFlag,
"flag for training the MVA or other methods if needed",
false);
57 "minimum allowed selector response for a match. If usePayloadCut is true the value will be overwritten with the cut stored in the payload.",
60 "EXPERT: the name of the output root file created when running in training mode.",
61 std::string(
"CurlTagger_Training.root"));
68 if (Variable::particlePt(p) >
m_PtCut) {
return false;}
69 if (!(Variable::trackNCDCHits(p) > 0 || Variable::trackNVXDHits(p) > 0)) {
return false;}
70 if (p -> getCharge() == 0) {
return false;}
81 B2WARNING(
"Curl Tagger 'cut' selector is only calibrated for Belle");
87 B2ERROR(
"Curl Track Tagger - Selector type does not exists.");
109 B2ERROR(
"ParticleList " << iList <<
" not found");
112 unsigned int particleListSize = particleList -> getListSize();
113 if (particleListSize == 0) {
119 std::vector<CurlTagger::Bundle> bundles;
120 std::vector<CurlTagger::Bundle> truthBundles;
122 for (
unsigned int i = 0; i < particleListSize; i++) {
124 Particle* iPart = particleList -> getParticle(i);
125 iPart -> addExtraInfo(
"isCurl", 0);
126 iPart -> addExtraInfo(
"bundleSize", 0);
128 iPart -> addExtraInfo(
"isTruthCurl", 0);
129 iPart -> addExtraInfo(
"truthBundleSize", 0);
133 bool addedParticleToBundle =
false;
134 std::vector<float> bundlesResponse;
137 unsigned int bundleSize = bundle.size();
138 float averageResponse = 0;
140 for (
unsigned int b = 0; b < bundleSize; b++) {
141 Particle* bPart = bundle.getParticle(b);
142 averageResponse +=
m_Selector -> getResponse(iPart, bPart);
145 averageResponse /= bundleSize;
146 bundlesResponse.push_back(averageResponse);
149 if (bundlesResponse.size() > 0) {
150 auto maxElement = std::max_element(bundlesResponse.begin(), bundlesResponse.end());
152 int maxPosition = std::distance(std::begin(bundlesResponse), maxElement);
153 bundles[maxPosition].addParticle(iPart);
154 addedParticleToBundle =
true;
158 if (!addedParticleToBundle) {
161 bundles.push_back(tempBundle);
165 bool addedParticleToTruthBundle =
false;
166 for (
auto& truthBundle : truthBundles) {
167 Particle* bPart = truthBundle.getParticle(0);
168 if (Variable::genParticleIndex(iPart) == Variable::genParticleIndex(bPart)) {
169 truthBundle.addParticle(iPart);
170 addedParticleToTruthBundle =
true;
174 if (!addedParticleToTruthBundle) {
177 truthBundles.push_back(truthTempBundle);
182 bundle.tagCurlInfo();
184 bundle.tagSizeInfo();
189 truthBundle.tagCurlInfo();
190 truthBundle.tagSizeInfo();
194 for (
unsigned int i = 0; i < particleListSize; i++) {
195 Particle* iPart = particleList -> getParticle(i);
198 for (
unsigned int j = 0; j < particleListSize; j++) {
199 Particle* jPart = particleList -> getParticle(j);
200 if (i == j) {
continue;}
std::vector< std::string > m_ParticleLists
input particle lists
bool passesPreSelection(Particle *particle)
preselects particles that may be curl tracks
virtual void initialize() override
initialise
virtual void event() override
event code - all curl track selection done here
virtual void endRun() override
end run - unused
bool m_payloadCutFlag
flag for overriding the m_responseCut with a value retrieved from the payload
virtual void terminate() override
termination
virtual ~CurlTaggerModule() override
destructor
bool m_TrainFlag
switch between training and classifying
virtual void beginRun() override
begin run - unused
std::string m_SelectorType
name of selector function to use
bool m_McStatsFlag
if true also does some truth based matching and tags the particles with truthCurl info
CurlTaggerModule()
Constructor: Sets the description, the properties and the parameters of the module.
double m_PtCut
preselection pt cut
bool m_BelleFlag
flags if data/mc comes from belle or belle II
std::string m_TrainFileName
expert: output file name of ntuple produced in training mode
CurlTagger::Selector * m_Selector
contains the selector used
double m_ResponseCut
min classifier response to consider a match
class to contain particles identified to come from the same actual/mc particle
void addParticle(Particle *particle)
adds Particle to Bundle
Simple cut based selector for curl tracks taken from Belle note 1079.
MVA based selector for tagging curl tracks in Belle and Belle II.
virtual void finalize()
finalise selector if needed
virtual void initialize()
initialise selector if needed
virtual void collectTrainingInfo(Particle *, Particle *)
collect information for training for mva or other selectors
virtual float getOptimalResponseCut()
returns optimal cut to use with selector
void setDescription(const std::string &description)
Sets the description of the module.
Class to store reconstructed particles.
Type-safe access to single objects in the data store.
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.
Abstract base class for different kinds of events.