12 #include <analysis/modules/TreeFitter/TreeFitterModule.h>
13 #include <analysis/VertexFitting/TreeFitter/FitManager.h>
15 #include <framework/datastore/StoreArray.h>
16 #include <framework/particledb/EvtGenDatabasePDG.h>
18 #include <analysis/utility/ParticleCopy.h>
20 #include <analysis/VertexFitting/TreeFitter/ConstraintConfiguration.h>
21 #include <analysis/VertexFitting/TreeFitter/FitParameterDimensionException.h>
29 setDescription(
"Tree Fitter module. Performs simultaneous fit of all vertices in a decay chain. Can also be used to just fit a single vertex.");
30 setPropertyFlags(c_ParallelProcessingCertified);
32 addParam(
"particleList", m_particleList,
33 "Type::[string]. Input mother of the decay tree to fit. For example 'B0:myB0particleList'.");
34 addParam(
"confidenceLevel", m_confidenceLevel,
35 "Type::[double]. Confidence level to accept fitted decay tree. Candidates with < confidenceLevel will be removed from the particle list! Typical Values: -1: keep all particle candidates, 0: remove all that fail the fit, 0.001: standard cut, 0.1: (too) tight cut. Optimise using a figure of merit (for example S/(sqrt{S+B}) ) for your analysis.",
37 addParam(
"convergencePrecision", m_precision,
38 "Type::[double]. Fractional upper limit for chi2 fluctuations to accept result. Larger value = less signal rejection but also less background rejection. Optimized for FOM on different topologies - don't touch unless you REALLY want this.",
40 addParam(
"massConstraintList", m_massConstraintList,
41 "Type::[int]. List of particles to mass constrain with int = pdg code. Note that the variables 'M': fit result for the particle and 'InvM': calculated from the daughter momenta, will look different (especially if you don't update the daughters!).", {});
42 addParam(
"massConstraintListParticlename", m_massConstraintListParticlename,
43 "Type::[string]. List of particles to mass constrain with string = particle name.", {});
46 addParam(
"geoConstraintList", m_geoConstraintListPDG,
47 "Type::[int], if 'autoSetGeoConstraintAndMergeVertices==False' you can manually set the particles that will be geometrically constrained here.", {});
48 addParam(
"sharedVertexList", m_fixedToMotherVertexListPDG,
49 "Type::[int], if 'autoSetGeoConstraintAndMergeVertices==False' you can manually set the particles that share the vertex with their mother here.", {});
50 addParam(
"autoSetGeoConstraintAndMergeVertices", m_automatic_vertex_constraining,
51 "Type::bool, shall vertices of strong resonance be merged with their mothers? Can the particles vertex be constraint geometrically?",
54 addParam(
"customOriginVertex", m_customOriginVertex,
55 "Type::[double]. List of vertex coordinates to be used in the custom origin constraint.", {0.001, 0, 0.0116});
56 addParam(
"customOriginCovariance", m_customOriginCovariance,
57 "Type::[double]. List vertex covariance elements used in the custom origin constraint (as a vector). Default is meant for B0 decays and is taken from 100k generated B0 to mumu events.",
64 addParam(
"customOriginConstraint", m_customOrigin,
65 "Type::[bool]. Use a custom vertex as the production point of the highest hierarchy particle (register this as the mother of the list you specify). Like the beam constraint but you can specify the position its covariance yourself. ",
67 addParam(
"ipConstraint", m_ipConstraint,
68 "Type::[bool]. Use the IP as the origin of the tree. This registers an internal IP particle as the mother of the list you give. Or in other words forces the PRODUCTION vertex of your particle to be the IP and its covariance as specified in the database.",
70 addParam(
"originDimension", m_originDimension,
71 "Type int, default 3. If origin or ip constraint used, specify the dimension of the constraint 3->x,y,z; 2->x,y. This also changes the dimension of the geometric constraints! So you might want to turn them off for some particles. (That means turn auto off and manually on for the ones you want to constrain)",
73 addParam(
"updateAllDaughters", m_updateDaughters,
74 "Type::[bool]. Update all daughters (vertex position and momenta) in the tree. If not set only the 4-momenta for the head of the tree will be updated. We also update the vertex position of the daughters regardless of what you put here, because otherwise the default when the particle list is created is {0,0,0}.",
77 addParam(
"expertMassConstraintType", m_massConstraintType,
78 "Type::[int]. False(0): use particles parameters in mass constraint; True: use sum of daughter parameters for mass constraint. WAARNING not even guaranteed that it works.",
80 addParam(
"expertRemoveConstraintList", m_removeConstraintList,
81 "Type::[string]. List of constraints that you do not want to be used in the fit. WARNING don't use if you don't know exactly what it does.", {});
82 addParam(
"expertUseReferencing", m_useReferencing,
83 "Type::[bool]. Use the Extended Kalman Filter. This implementation linearises around the previous state vector which gives smoother convergence.",
85 addParam(
"inflationFactorCovZ", m_inflationFactorCovZ,
86 "Inflate the covariance of the beamspot by this number so that the 3d beam constraint becomes weaker in Z.And: thisnumber->infinity : dim(beamspot constr) 3d->2d.",
99 TParticlePDG* particletemp = TDatabasePDG::Instance()->GetParticle((containedParticle).c_str());
116 std::vector<unsigned int> toRemove;
117 const unsigned int n =
m_plist->getListSize();
120 for (
unsigned i = 0; i < n; i++) {
128 const bool ok =
fitTree(particle);
129 if (!ok) { particle->setPValue(-1); }
135 toRemove.push_back(particle->getArrayIndex());
139 m_plist->removeParticles(toRemove);
149 B2WARNING(
"Not a single candidate survived the fit. Candidates before fit: " <<
m_nCandidatesBeforeFit <<
" after: " <<
171 std::unique_ptr<TreeFitter::FitManager> TreeFitter(
180 bool rc = TreeFitter->fit();
186 B2INFO(
"\033[1;35m================================================================================\033[0m");
187 B2INFO(
"\033[40;97m ,., \033[0m");
188 B2INFO(
"\033[40;97m ;%&M%;_ ,.., \033[0m");
189 B2INFO(
"\033[40;97m \"_ \"__\" % M % M %; , ..., , \033[0m");
190 B2INFO(
"\033[40;97m , ..., __.\" --\" , ., _ - \" % &W % WM %; \033[0m");
191 B2INFO(
"\033[40;97m ; % M&$M % \"___ \"_._ %M%\"_.\"\" _ \"\"\"\"\"\" \033[0m");
192 B2INFO(
"\033[40;97m \"\"\"\"\" \"\" , \\_. \"_. .\" \033[0m");
193 B2INFO(
"\033[40;97m , ., _\"__ \\__./ .\" \033[0m");
194 B2INFO(
"\033[40;97m ___ __ | y , .., \033[97;40mThank you for using TreeFitter. \033[0m");
195 B2INFO(
"\033[40;97m /)'\\ ''''| u \\ %W%W%%; \033[0m");
196 B2INFO(
"\033[40;97m ___)/ \"---\\_ \\ |____\" \033[97;40mPlease cite both: \033[0m");
197 B2INFO(
"\033[40;97m ;&&%%; (|__.|)./ ,.., \033[97;40m10.1016/j.nima.2020.164269 \033[0m");
198 B2INFO(
"\033[40;97m ,.., ___\\ |/ &&\" \033[97;40m 10.1016/j.nima.2005.06.078 \033[0m");
199 B2INFO(
"\033[40;97m &&%%& (| Uo / '\" \033[97;40mEmail: \033[0m");
200 B2INFO(
"\033[40;97m '''' \\ 7 \\ \033[97;40mfrancesco.tenchini@desy.de \033[0m");
201 B2INFO(
"\033[40;97m ._______________.-'____\"\"-.____. \033[97;40mjo-frederik.krohn@desy.de \033[0m");
202 B2INFO(
"\033[40;97m \\ / \033[0m");
203 B2INFO(
"\033[40;97m \\ \033[0m\033[32;40mTREEFITTER\033[0m\033[40;97m / \033[0m");
204 B2INFO(
"\033[40;97m \\_______________________/ \033[0m");
205 B2INFO(
"\033[40;97m (_) (_) \033[0m");
206 B2INFO(
"\033[40;97m \033[0m");
207 B2INFO(
"\033[1;35m============= TREEFIT STATISTICS ===============================================\033[0m");
211 " candidates were removed during the fit.\033[0m");
213 "% of candidates survived the fit.\033[0m");
215 "% of candidates did not.\033[0m");
216 B2INFO(
"\033[1;39mYou choose to drop all candidates with pValue < " <<
m_confidenceLevel <<
".\033[0m");
217 B2INFO(
"\033[1;35m================================================================================\033[0m");
Class to store reconstructed particles.
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
Accessor to arrays stored in the data store.
Module to fit an entire decay tree.
void plotFancyASCII()
plot ascii art and statistics
std::vector< double > m_customOriginVertex
vertex coordinates of the custom origin
virtual void initialize() override
initialize
virtual void event() override
performed for each event
bool m_updateDaughters
flag if you want to update all particle momenta in the decay tree.
std::vector< std::string > m_massConstraintListParticlename
vector carrying the names of the particles to be mass constraint
unsigned int m_nCandidatesAfter
after the fit
std::vector< int > m_massConstraintList
vector carrying the PDG codes of the particles to be mass constraint
std::vector< int > m_fixedToMotherVertexListPDG
list of pdg codes of particles where we use the same vertex for production and decay which is the ver...
virtual void terminate() override
stuff at the end
bool m_automatic_vertex_constraining
should the vertex be joined with the mother and should it be geometrically constrained?...
virtual void beginRun() override
performed at the start of run
bool m_ipConstraint
Use x-y-z beamspot constraint.
int m_originDimension
dimension to use for beam/origin constraint
int m_inflationFactorCovZ
inflate beamspot covariance of z by this number
std::vector< std::string > m_removeConstraintList
list of constraints not to be applied in tree fit WARNING only use if you know what you are doing
int m_massConstraintType
type of the mass constraint false: use normal one.
std::vector< int > m_geoConstraintListPDG
list of pdg codes of particles to use a geo constraint for
std::vector< double > m_customOriginCovariance
covariance of the custom origin
std::string m_particleList
name of the particle list fed to the fitter
double m_confidenceLevel
minimum confidence level to accept fit calculated as f(chiSquared, NDF) -2: accept all 0: only accept...
bool m_customOrigin
use a custom vertex as the production vertex of the highest hierarchy particle
bool m_useReferencing
linearise around a previous state of the Kalman Filter
bool fitTree(Particle *head)
this fits all particle candidates contained in the m_particleList
double m_precision
convergence precision for the newton method When the delta chiSquared between 2 iterations divided by...
StoreObjPtr< ParticleList > m_plist
input particle list
unsigned int m_nCandidatesBeforeFit
before the fit
exception template, runtime_error implements what()
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
void copyDaughters(Particle *mother)
Function copies all (grand-)^n-daughter particles of the argument mother Particle.
Abstract base class for different kinds of events.