10#include <ecl/modules/eclLocalMaximumFinder/ECLLocalMaximumFinderModule.h>
13#include <ecl/dataobjects/ECLCalDigit.h>
14#include <ecl/dataobjects/ECLConnectedRegion.h>
15#include <ecl/dataobjects/ECLDigit.h>
16#include <ecl/dataobjects/ECLElementNumbers.h>
17#include <ecl/dataobjects/ECLHit.h>
18#include <ecl/dataobjects/ECLLocalMaximum.h>
19#include <ecl/geometry/ECLGeometryPar.h>
20#include <ecl/geometry/ECLNeighbours.h>
27#include <framework/gearbox/Const.h>
28#include <framework/logging/Logger.h>
29#include <mdst/dataobjects/MCParticle.h>
62 "Run in training mode (i.e. fill file with MVA input variables and determine MC truth of LM.).", 0);
63 addParam(
"outfileName",
m_outfileName,
"Output file name for training file.", std::string(
"ECLLocalMaximumFinderOutput.root"));
64 addParam(
"method",
m_method,
"Method to determine the LM (cut, none, fastbdt).", std::string(
"none"));
66 addParam(
"cutOffset",
m_cutOffset,
"Cut method specific: Offset. (BaBar: 2.5, high eff: 1.40)", 2.5);
67 addParam(
"cutSlope",
m_cutSlope,
"Cut method specific: Slope. (BaBar: 0.5, high eff: 3.0)", 0.5);
79 B2DEBUG(200,
"ECLLocalMaximumFinderModule::initialize()");
89 B2WARNING(
"ECLLocalMaximumFinderModule::initialize: Matching fraction must be above 1e-6, input: " <<
m_truthFraction <<
90 " will be reset to 1e-6.");
95 B2WARNING(
"ECLLocalMaximumFinderModule::initialize: Matching fraction must be below 1.0, input: " <<
m_truthFraction <<
96 " will be reset to 1.0.");
113 const int cBufferLength = 500;
114 char tmpBuffer[cBufferLength];
115 int tmpBufferLength = sprintf(tmpBuffer,
"%s",
m_outfileName.c_str());
117 if (tmpBufferLength >= cBufferLength) {
118 B2FATAL(
"ECLLocalMaximumFinderModule::initialize(): Output training filename length too long!");
121 m_outfile =
new TFile(tmpBuffer,
"RECREATE");
122 m_tree =
new TTree(
"locmax",
"locmax");
168 B2WARNING(
"ECLLocalMaximumFinderModule::beginRun: Energy threshold " <<
m_energyCut <<
" GeV is too small, resetting to " <<
179 B2DEBUG(200,
"ECLLocalMaximumFinderModule::event()");
188 std::vector< double > vNeighourEnergies;
193 const int crId = aCR.getCRId();
202 std::fill_n(vNeighourEnergies.begin(), vNeighourEnergies.size(),
209 int neighbourCount = 0;
210 for (
auto& neighbourId :
m_neighbourMap->getNeighbours(aECLCalDigit.getCellId())) {
211 if (neighbourId == aECLCalDigit.getCellId())
continue;
215 double energyNeighbour = 0.0;
218 vNeighourEnergies[neighbourCount] = energyNeighbour;
221 vNeighourEnergies[neighbourCount] = 0.0;
225 if (energyNeighbour > aECLCalDigit.getEnergy()) {
234 for (
unsigned int npos = 0; npos < vNeighourEnergies.size(); ++npos) {
235 if (vNeighourEnergies[npos] >= 0) {
241 m_time = aECLCalDigit.getTime();
247 m_energy =
static_cast < float >(aECLCalDigit.getEnergy());
248 m_cellId =
static_cast < float >(aECLCalDigit.getCellId());
251 m_CRId =
static_cast < float >(crId);
252 m_LMId =
static_cast < float >(iLM);
263 auto relatedParticlePairs = aECLCalDigit.getRelationsWith<
MCParticle>();
265 for (
unsigned int irel = 0; irel < relatedParticlePairs.size(); irel++) {
266 const auto particle = relatedParticlePairs.object(irel);
267 const double weight = relatedParticlePairs.weight(irel);
270 int motherindex = -1;
276 B2DEBUG(175,
" -> digt energy: " << aECLCalDigit.getEnergy());
309 ", aECLCalDigit.getEnergy(): " << aECLCalDigit.getEnergy());
311 B2DEBUG(200,
"(m_maxNeighbourEnergy - m_cutRatioCorrection) / (aECLCalDigit.getEnergy() - m_cutRatioCorrection)" <<
333 int highestEnergyCellId = -1;
334 double highestEnergy = 0.0;
338 if (aECLCalDigit.getEnergy() > highestEnergy) {
339 highestEnergyCellId = aECLCalDigit.getCellId();
340 highestEnergy = aECLCalDigit.getEnergy();
350 uint16_t nLMPerRegion[3] = {};
352 const int iCellId = aLM.getCellId();
369 B2DEBUG(200,
"ECLLocalMaximumFinderModule::endRun()");
375 B2DEBUG(200,
"ECLLocalMaximumFinderModule::terminate()");
395 B2DEBUG(175,
"ECLLocalMaximumFinderModule::makeLocalMaximum(): local maximum cellid: " << cellId);
398 aLocalMaximum->setLMId(lmId);
401 aLocalMaximum->setCellId(cellId);
416 for (
unsigned int i = 0; i < 10; ++i) {
417 for (
unsigned int j = 0; j < 5; ++j) {
450 int index = particle.getArrayIndex();
461 pi0index =
m_mcParticles[index]->getMother()->getArrayIndex();
475 pi0arrayindex = pi0index;
482 const double theta = vertex.Theta();
484 if (theta > 0.555015 and theta < 2.26369) {
485 double radius = vertex.Perp();
487 }
else if (theta <= 0.555015) {
489 }
else if (theta >= 2.26369) {
499 for (
int i = 0; i < 5; i++) {
517 for (
unsigned int i = 0; i < 10; ++i) {
518 for (
unsigned int j = 0; j < 5; ++j) {
547 }
else if (abs(motherpdg) ==
Const::muon.getPDGCode()) {
static const ParticleType neutron
neutron particle
static const ParticleType pi0
neutral pion particle
static const ChargedStable muon
muon particle
static const ChargedStable pion
charged pion particle
static const ParticleType Klong
K^0_L particle.
static const ChargedStable proton
proton particle
static const ChargedStable kaon
charged kaon particle
static const ParticleType photon
photon particle
static const ChargedStable electron
electron particle
Class to store calibrated ECLDigits: ECLCalDigits.
Class to store connected regions (CRs)
TTree * m_tree
tree that contain information for MVA training
double m_cutRatioCorrection
correction for nominator and denominator of the ratio.
double m_signalEnergy[10][5]
total energy per MC matching type of this digit
void getEnteringMother(const MCParticle &particle, int &pdg, int &arrayindex, int &pi0arrayindex)
Get enterging mother of this particle.
StoreArray< ECLConnectedRegion > m_eclConnectedRegions
Store array: ECLConnectedRegion.
float m_timeFitFailed
failed fit
float m_energyRatioNeighbour[c_nMaxNeighbours]
energy ratio of neighbour 0..9 to center
double m_cutOffset
cut offset
double m_totalSignalEnergy
total energy of this digit
float m_phiId
local maximum center theta Id
double m_energyCut
energy cut for seed
virtual void initialize() override
Initialize.
virtual const char * eclHitArrayName() const
Name to be used for default or PureCsI option: ECLHits.
StoreArray< ECLLocalMaximum > m_eclLocalMaximums
Store array: ECLLocalMaximum.
float m_cellId
local maximum center cell Id
virtual void event() override
Event.
virtual const char * eclLocalMaximumArrayName() const
Name to be used for default option: ECLLocalMaximums.
int getIdPosition(const int type, const int id)
Get Id position in the vector.
float m_energy
Variables to monitor the MVA training.
virtual void endRun() override
End run.
std::string m_method
Method to find the local maximum.
virtual void terminate() override
Terminate (close ROOT files here if you have opened any).
ECL::ECLGeometryPar * m_geom
Geometry.
std::string m_outfileName
file name prefix of the training output file
StoreArray< ECLDigit > m_eclDigits
Store array: ECLDigit.
ECL::ECLNeighbours * m_neighbourMap
Neighbour maps.
void makeLocalMaximum(const ECLConnectedRegion &aCR, const int cellId, const int lmId)
Make local maximum for a given connected region.
void resetClassifierVariables()
Reset Classifier Variables.
float m_thetaId
local maximum center theta Id
virtual const char * mcParticleArrayName() const
MCParticles.
float m_maxNeighbourEnergy
highest energy of all neighbours
ECLLocalMaximumFinderModule()
Constructor.
bool isEnteringECL(const B2Vector3D &vec)
Check if particle is produced outside of the ECL.
TFile * m_outfile
Output training files and trees.
float m_timeResolution
time resolution
virtual void beginRun() override
Begin.
void addToSignalEnergy(int motherpdg, int motherindex, int pi0index, double weight)
Add energy to vector.
DBObjPtr< ECLClusteringParameters > m_eclClusteringParameters
ECLClusteringParameters payload: includes value for energyCut.
bool m_useParametersFromDatabase
get energyCut from payload
virtual const char * eclDigitArrayName() const
Name to be used for default or PureCsI option: ECLDigits.
float m_targetpi0index
target array index
StoreArray< ECLHit > m_eclHits
Store array: ECLHit.
virtual const char * eclConnectedRegionArrayName() const
Name to be used for default option: ECLConnectedRegions.
float m_target
MC truth variables.
static const unsigned c_nMaxNeighbours
Variables (possibly) used for MVA classification.
StoreArray< MCParticle > m_mcParticles
Store array: MCParticle.
virtual const char * eclCalDigitArrayName() const
Name to be used for default or PureCsI option: ECLCalDigits.
float m_targetindex
target array index
float m_maxEnergyRatio
Highest energetic neighbour energy divided by LM energy.
int m_signalId[10][5]
total energy per MC matching type of this digit
const double c_minEnergyCut
Minimum LM energy.
std::vector< int > m_StoreArrPosition
vector (ECLElementNumbers::c_NCrystals + 1 entries) with cell id to store array positions
StoreObjPtr< EventLevelClusteringInfo > m_eventLevelClusteringInfo
EventLevelClusteringInfo.
void resetTrainingVariables()
Reset Debug Variables.
void getMax(int &maxtype, int &maxpos)
Get the highest energy deposition particle type.
StoreArray< ECLCalDigit > m_eclCalDigits
Store array: ECLCalDigit.
double m_cutSlope
cut slope.
int m_isTrainingMode
training mode for MVA methods (i.e.
double m_truthFraction
MC truth fraction.
float m_nNeighbours10
Variables (possibly) used for cut classification.
virtual ~ECLLocalMaximumFinderModule()
Destructor.
Class to store local maxima (LM)
static ECLGeometryPar * Instance()
Static method to get a reference to the ECLGeometryPar instance.
Class to get the neighbours for a given cell id.
A Class to store the Monte Carlo particle information.
void setDescription(const std::string &description)
Sets the description of the module.
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
void addRelationTo(const RelationsInterface< BASE > *object, float weight=1.0, const std::string &namedRelation="") const
Add a relation from this object to another object (with caching).
RelationVector< TO > getRelationsTo(const std::string &name="", const std::string &namedRelation="") const
Get the relations that point from this object to another store array.
static const double MeV
[megaelectronvolt]
static const double cm
Standard units with the value = 1.
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.
B2Vector3< double > B2Vector3D
typedef for common usage with double
bool isForward(int cellId)
Check whether the crystal is in forward ECL.
bool isBarrel(int cellId)
Check whether the crystal is in barrel ECL.
const int c_NCrystals
Number of crystals.
bool isBackward(int cellId)
Check whether the crystal is in backward ECL.
Abstract base class for different kinds of events.