Belle II Software  release-08-01-10
MillepedeCollectorModule Class Reference

Calibration data collector for Millepede Algorithm. More...

#include <MillepedeCollectorModule.h>

Inheritance diagram for MillepedeCollectorModule:
Collaboration diagram for MillepedeCollectorModule:

Public Types

enum  EModulePropFlags {
  c_Input = 1 ,
  c_Output = 2 ,
  c_ParallelProcessingCertified = 4 ,
  c_HistogramManager = 8 ,
  c_InternalSerializer = 16 ,
  c_TerminateInAllProcesses = 32 ,
  c_DontCollectStatistics = 64
}
 Each module can be tagged with property flags, which indicate certain features of the module. More...
 
typedef ModuleCondition::EAfterConditionPath EAfterConditionPath
 Forward the EAfterConditionPath definition from the ModuleCondition.
 

Public Member Functions

 MillepedeCollectorModule ()
 Constructor: Sets the description, the properties and the parameters of the module.
 
virtual void prepare () override
 Prepration.
 
virtual void collect () override
 Data collection.
 
virtual void closeRun () override
 Only for closing mille binaries after each run.
 
virtual void finish () override
 Register mille binaries in file catalog.
 
std::string getUniqueMilleName ()
 Make a name for mille binary (encodes module name + starting exp, run and event + process id)
 
std::vector< genfit::Track * > getParticlesTracks (std::vector< Particle * > particles, bool addVertexPoint=true)
 Get all useable tracks for particles. More...
 
bool fitRecoTrack (RecoTrack &recoTrack, Particle *particle=nullptr)
 Fit given RecoTrack with GBL. More...
 
TMatrixD getGlobalToLocalTransform (const genfit::MeasuredStateOnPlane &msop)
 Compute the transformation matrix d(q/p,u',v',u,v)/d(x,y,z,px,py,pz) from state at first track point (vertex) More...
 
TMatrixD getLocalToGlobalTransform (const genfit::MeasuredStateOnPlane &msop)
 Compute the transformation matrix d(x,y,z,px,py,pz)/d(q/p,u',v',u,v) from state at first track point (vertex) More...
 
std::pair< TMatrixD, TMatrixD > getTwoBodyToLocalTransform (Particle &mother, double motherMass)
 Compute the transformation matrices d(q/p,u'v',u,v)/d(vx,vy,vz,px,py,pz,theta,phi,M) = dq/d(v,z) for both particles in pair. More...
 
void storeTrajectory (gbl::GblTrajectory &trajectory)
 Write down a GBL trajectory (to TTree or binary file)
 
std::tuple< B2Vector3D, TMatrixDSym > getPrimaryVertexAndCov () const
 Get the primary vertex position estimation and its size from BeamSpot. More...
 
void initialize () final
 Set up a default RunRange object in datastore and call prepare()
 
void event () final
 Check current experiment and run and update if needed, fill into RunRange and collect()
 
void beginRun () final
 Reset the m_runCollectOnRun flag, if necessary, to begin collection again. More...
 
void endRun () final
 Write the current collector objects to a file and clear their memory.
 
void terminate () final
 Write the final objects to the file.
 
void defineHisto () final
 Runs due to HistoManager, allows us to discover the correct file.
 
template<class T >
void registerObject (std::string name, T *obj)
 Register object with a name, takes ownership, do not access the pointer beyond prepare()
 
template<class T >
T * getObjectPtr (std::string name)
 Calls the CalibObjManager to get the requested stored collector data.
 
virtual std::vector< std::string > getFileNames (bool outputFiles)
 Return a list of output filenames for this modules. More...
 
const std::string & getName () const
 Returns the name of the module. More...
 
const std::string & getType () const
 Returns the type of the module (i.e. More...
 
const std::string & getPackage () const
 Returns the package this module is in.
 
const std::string & getDescription () const
 Returns the description of the module.
 
void setName (const std::string &name)
 Set the name of the module. More...
 
void setPropertyFlags (unsigned int propertyFlags)
 Sets the flags for the module properties. More...
 
LogConfiggetLogConfig ()
 Returns the log system configuration.
 
void setLogConfig (const LogConfig &logConfig)
 Set the log system configuration.
 
void setLogLevel (int logLevel)
 Configure the log level.
 
void setDebugLevel (int debugLevel)
 Configure the debug messaging level.
 
void setAbortLevel (int abortLevel)
 Configure the abort log level.
 
void setLogInfo (int logLevel, unsigned int logInfo)
 Configure the printed log information for the given level. More...
 
void if_value (const std::string &expression, const std::shared_ptr< Path > &path, EAfterConditionPath afterConditionPath=EAfterConditionPath::c_End)
 Add a condition to the module. More...
 
void if_false (const std::shared_ptr< Path > &path, EAfterConditionPath afterConditionPath=EAfterConditionPath::c_End)
 A simplified version to add a condition to the module. More...
 
void if_true (const std::shared_ptr< Path > &path, EAfterConditionPath afterConditionPath=EAfterConditionPath::c_End)
 A simplified version to set the condition of the module. More...
 
bool hasCondition () const
 Returns true if at least one condition was set for the module.
 
const ModuleConditiongetCondition () const
 Return a pointer to the first condition (or nullptr, if none was set)
 
const std::vector< ModuleCondition > & getAllConditions () const
 Return all set conditions for this module.
 
bool evalCondition () const
 If at least one condition was set, it is evaluated and true returned if at least one condition returns true. More...
 
std::shared_ptr< PathgetConditionPath () const
 Returns the path of the last true condition (if there is at least one, else reaturn a null pointer). More...
 
Module::EAfterConditionPath getAfterConditionPath () const
 What to do after the conditional path is finished. More...
 
std::vector< std::shared_ptr< Path > > getAllConditionPaths () const
 Return all condition paths currently set (no matter if the condition is true or not).
 
bool hasProperties (unsigned int propertyFlags) const
 Returns true if all specified property flags are available in this module. More...
 
bool hasUnsetForcedParams () const
 Returns true and prints error message if the module has unset parameters which the user has to set in the steering file.
 
const ModuleParamListgetParamList () const
 Return module param list.
 
template<typename T >
ModuleParam< T > & getParam (const std::string &name) const
 Returns a reference to a parameter. More...
 
bool hasReturnValue () const
 Return true if this module has a valid return value set.
 
int getReturnValue () const
 Return the return value set by this module. More...
 
std::shared_ptr< PathElementclone () const override
 Create an independent copy of this module. More...
 
std::shared_ptr< boost::python::list > getParamInfoListPython () const
 Returns a python list of all parameters. More...
 

Static Public Member Functions

static void exposePythonAPI ()
 Exposes methods of the Module class to Python.
 

Protected Member Functions

virtual void startRun ()
 Replacement for beginRun(). Do anything you would normally do in beginRun here.
 
virtual void inDefineHisto ()
 Replacement for defineHisto(). Do anything you would normally do in defineHisto here.
 
virtual void def_initialize ()
 Wrappers to make the methods without "def_" prefix callable from Python. More...
 
virtual void def_beginRun ()
 Wrapper method for the virtual function beginRun() that has the implementation to be used in a call from Python.
 
virtual void def_event ()
 Wrapper method for the virtual function event() that has the implementation to be used in a call from Python.
 
virtual void def_endRun ()
 This method can receive that the current run ends as a call from the Python side. More...
 
virtual void def_terminate ()
 Wrapper method for the virtual function terminate() that has the implementation to be used in a call from Python.
 
void setDescription (const std::string &description)
 Sets the description of the module. More...
 
void setType (const std::string &type)
 Set the module type. More...
 
template<typename T >
void addParam (const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
 Adds a new parameter to the module. More...
 
template<typename T >
void addParam (const std::string &name, T &paramVariable, const std::string &description)
 Adds a new enforced parameter to the module. More...
 
void setReturnValue (int value)
 Sets the return value for this module as integer. More...
 
void setReturnValue (bool value)
 Sets the return value for this module as bool. More...
 
void setParamList (const ModuleParamList &params)
 Replace existing parameter list.
 

Protected Attributes

TDirectory * m_dir
 The top TDirectory that collector objects for this collector will be stored beneath.
 
CalibObjManager m_manager
 Controls the creation, collection and access to calibration objects.
 
RunRangem_runRange
 Overall list of runs processed.
 
Calibration::ExpRun m_expRun
 Current ExpRun for object retrieval (becomes -1,-1 for granularity=all)
 
StoreObjPtr< EventMetaDatam_emd
 Current EventMetaData.
 

Private Member Functions

void updateMassWidthIfSet (std::string listName, double &mass, double &width)
 Update mass and width of the particle (mother in list) with user custom-defined values.
 
bool getPreScaleChoice ()
 I'm a little worried about floating point precision when comparing to 0.0 and 1.0 as special values. More...
 
std::list< ModulePtrgetModules () const override
 no submodules, return empty list
 
std::string getPathString () const override
 return the module name.
 
void setParamPython (const std::string &name, const boost::python::object &pyObj)
 Implements a method for setting boost::python objects. More...
 
void setParamPythonDict (const boost::python::dict &dictionary)
 Implements a method for reading the parameter values from a boost::python dictionary. More...
 

Private Attributes

std::vector< std::string > m_tracks
 Names of arrays with single RecoTracks fitted by GBL.
 
std::vector< std::string > m_particles
 Names of particle list with single particles.
 
std::vector< std::string > m_vertices
 Name of particle list with mothers of daughters to be used with vertex constraint in calibration.
 
std::vector< std::string > m_primaryVertices
 Name of particle list with mothers of daughters to be used with vertex + IP profile (+ optional calibration) constraint in calibration.
 
std::vector< std::string > m_twoBodyDecays
 Name of particle list with mothers of daughters to be used with vertex + mass constraint in calibration.
 
std::vector< std::string > m_primaryTwoBodyDecays
 Name of particle list with mothers of daughters to be used with vertex + IP profile (+ optional calibration) + IP kinematics (+ optional calibration) constraint in calibration.
 
std::vector< std::string > m_primaryMassTwoBodyDecays
 Name of particle list with mothers of daughters to be used with vertex + IP profile + mass constraint in calibration.
 
std::vector< std::string > m_primaryMassVertexTwoBodyDecays
 Name of particle list with mothers of daughters to be used with vertex + IP profile + mass constraint in calibration.
 
double m_stableParticleWidth
 Width (in GeV/c/c) to use for invariant mass constraint for 'stable' particles (like K short). More...
 
bool m_doublePrecision
 Use double (instead of single/float) precision for binary files.
 
bool m_calibrateVertex
 Add derivatives for beam spot vertex calibration for primary vertices.
 
bool m_calibrateKinematics = true
 Add derivatives for beam spot kinematics calibration for primary vertices.
 
double m_minPValue
 Minimum p.value for output.
 
bool m_useGblTree
 Whether to use TTree to accumulate GBL data instead of binary files.
 
bool m_absFilePaths
 Use absolute path to locate binary files in MilleData.
 
std::vector< std::string > m_components {}
 Whether to use VXD alignment hierarchy.
 
int m_externalIterations
 Number of external iterations of GBL fitter.
 
std::string m_internalIterations
 String defining internal GBL iterations for outlier down-weighting.
 
int m_recalcJacobians
 Up to which external iteration propagation Jacobians should be re-calculated.
 
bool m_fitTrackT0
 Add local parameter for track T0 fit in GBL (local derivative)
 
bool m_updateCDCWeights
 Update L/R weights from previous DAF fit result?
 
double m_minCDCHitWeight
 Minimum CDC hit weight.
 
double m_minUsedCDCHitFraction
 Minimum CDC used hit fraction.
 
int m_hierarchyType
 Type of alignment hierarchy (for VXD only for now): 0 = None, 1 = Flat (only constraints, no new global parameters/derivatives), 2 = Half-Shells + sensors (no ladders), 3 = Full.
 
bool m_enablePXDHierarchy
 enable PXD hierarchy
 
bool m_enableSVDHierarchy
 enable SVD hierarchy
 
bool m_enableWireByWireAlignment
 Enable global derivatives for wire-by-wire alignment.
 
bool m_enableWireSagging
 Enable global derivatives for wire sagging.
 
std::vector< std::tuple< int, int, int > > m_eventNumbers {}
 List of event meta data entries at which payloads can change for timedep calibration.
 
std::vector< std::tuple< std::vector< int >, std::vector< std::tuple< int, int, int > > > > m_timedepConfig
 Config for time dependence: list( tuple( list( param1, param2, ... More...
 
std::map< std::string, std::tuple< double, double > > m_customMassConfig
 Map of list_name -> (mass, width) for custom mass and width setting.
 
std::vector< gbl::GblDatam_currentGblData {}
 Current vector of GBL data from trajectory to be stored in a tree.
 
StoreObjPtr< EventT0m_eventT0
 Optional input for EventT0.
 
StoreObjPtr< EventMetaDatam_evtMetaData
 Required object pointer to EventMetaData.
 
std::string m_granularity
 Granularity of data collection = run|all(= no granularity, exp,run=-1,-1)
 
int m_maxEventsPerRun
 Maximum number of events to be collected at the start of each run (-1 = no maximum)
 
float m_preScale
 Prescale module parameter, this fraction of events will have collect() run on them [0.0 -> 1.0].
 
bool m_runCollectOnRun = true
 Whether or not we will run the collect() at all this run, basically skips the event() function if false.
 
std::map< Calibration::ExpRun, int > m_expRunEvents
 How many events processed for each ExpRun so far, stops counting up once max is hit Only used/incremented if m_maxEventsPerRun > -1.
 
int * m_eventsCollectedInRun
 Will point at correct value in m_expRunEvents.
 
std::string m_name
 The name of the module, saved as a string (user-modifiable)
 
std::string m_type
 The type of the module, saved as a string.
 
std::string m_package
 Package this module is found in (may be empty).
 
std::string m_description
 The description of the module.
 
unsigned int m_propertyFlags
 The properties of the module as bitwise or (with |) of EModulePropFlags.
 
LogConfig m_logConfig
 The log system configuration of the module.
 
ModuleParamList m_moduleParamList
 List storing and managing all parameter of the module.
 
bool m_hasReturnValue
 True, if the return value is set.
 
int m_returnValue
 The return value.
 
std::vector< ModuleConditionm_conditions
 Module condition, only non-null if set.
 

Detailed Description

Calibration data collector for Millepede Algorithm.

Collects data from GBL-fitted tracks and produces binary files for Millepede

Definition at line 34 of file MillepedeCollectorModule.h.

Member Enumeration Documentation

◆ EModulePropFlags

enum EModulePropFlags
inherited

Each module can be tagged with property flags, which indicate certain features of the module.

Enumerator
c_Input 

This module is an input module (reads data).

c_Output 

This module is an output module (writes data).

c_ParallelProcessingCertified 

This module can be run in parallel processing mode safely (All I/O must be done through the data store, in particular, the module must not write any files.)

c_HistogramManager 

This module is used to manage histograms accumulated by other modules.

c_InternalSerializer 

This module is an internal serializer/deserializer for parallel processing.

c_TerminateInAllProcesses 

When using parallel processing, call this module's terminate() function in all processes().

This will also ensure that there is exactly one process (single-core if no parallel modules found) or at least one input, one main and one output process.

c_DontCollectStatistics 

No statistics is collected for this module.

Definition at line 77 of file Module.h.

Member Function Documentation

◆ beginRun()

void beginRun ( void  )
finalvirtualinherited

Reset the m_runCollectOnRun flag, if necessary, to begin collection again.

It seems that the beginRun() function is called in each basf2 subprocess when the run changes in each process. This is nice because it allows us to write the new (exp,run) object creation in the beginRun function as though the other processes don't exist.

Reimplemented from HistoModule.

Definition at line 77 of file CalibrationCollectorModule.cc.

78 {
83  // Current (Exp,Run)
84  ExpRun expRun = make_pair(m_emd->getExperiment(), m_emd->getRun());
85  m_runRange->add(expRun.first, expRun.second);
86 
87  // Do we care about the number of events collected in each (input data) ExpRun?
88  // If so, we want to create values for the events collected map
89  if (m_maxEventsPerRun > -1) {
90  // Do we have a count for this ExpRun yet? If not create one
91  auto i_eventsInExpRun = m_expRunEvents.find(expRun);
92  if (i_eventsInExpRun == m_expRunEvents.end()) {
93  m_expRunEvents[expRun] = 0;
94  }
95 
96  // Set our pointer to the correct location for this ExpRun
98  // Want to reset our flag to start collection if necessary
100  B2INFO("New run has had less events than the maximum collected so far ("
102  << " < "
104  << "). Turning on collection.");
105  m_runCollectOnRun = true;
106  } else {
107  B2INFO("New run has had more events than the maximum collected so far ("
109  << " >= "
111  << "). Turning off collection.");
112  m_runCollectOnRun = false;
113  }
114  }
115  // Granularity=all removes data spliting by runs by setting
116  // always the same exp, run for calibration data objects
117  if (m_granularity == "all") {
118  m_expRun = { -1, -1};
119  } else {
120  m_expRun = expRun;
121  }
123  // Run the user's startRun() implementation if there is one
124  startRun();
125 }
bool m_runCollectOnRun
Whether or not we will run the collect() at all this run, basically skips the event() function if fal...
virtual void startRun()
Replacement for beginRun(). Do anything you would normally do in beginRun here.
Calibration::ExpRun m_expRun
Current ExpRun for object retrieval (becomes -1,-1 for granularity=all)
CalibObjManager m_manager
Controls the creation, collection and access to calibration objects.
std::string m_granularity
Granularity of data collection = run|all(= no granularity, exp,run=-1,-1)
RunRange * m_runRange
Overall list of runs processed.
int * m_eventsCollectedInRun
Will point at correct value in m_expRunEvents.
StoreObjPtr< EventMetaData > m_emd
Current EventMetaData.
int m_maxEventsPerRun
Maximum number of events to be collected at the start of each run (-1 = no maximum)
std::map< Calibration::ExpRun, int > m_expRunEvents
How many events processed for each ExpRun so far, stops counting up once max is hit Only used/increme...
void add(int exp, int run)
Add an experiment and run number to the set.
Definition: RunRange.h:58
void createExpRunDirectories(Calibration::ExpRun &expRun) const
For each templated object, we create a new TDirectory for this exprun.
Struct containing exp number and run number.
Definition: Splitter.h:51

◆ clone()

std::shared_ptr< PathElement > clone ( ) const
overridevirtualinherited

Create an independent copy of this module.

Note that parameters are shared, so changing them on a cloned module will also affect the original module.

Implements PathElement.

Definition at line 179 of file Module.cc.

◆ def_endRun()

virtual void def_endRun ( )
inlineprotectedvirtualinherited

This method can receive that the current run ends as a call from the Python side.

For regular C++-Modules that forwards the call to the regular endRun() method.

Reimplemented in PyModule.

Definition at line 439 of file Module.h.

◆ def_initialize()

virtual void def_initialize ( )
inlineprotectedvirtualinherited

Wrappers to make the methods without "def_" prefix callable from Python.

Overridden in PyModule. Wrapper method for the virtual function initialize() that has the implementation to be used in a call from Python.

Reimplemented in PyModule.

Definition at line 420 of file Module.h.

◆ evalCondition()

bool evalCondition ( ) const
inherited

If at least one condition was set, it is evaluated and true returned if at least one condition returns true.

If no condition or result value was defined, the method returns false. Otherwise, the condition is evaluated and true returned, if at least one condition returns true. To speed up the evaluation, the condition strings were already parsed in the method if_value().

Returns
True if at least one condition and return value exists and at least one condition expression was evaluated to true.

Definition at line 96 of file Module.cc.

◆ fitRecoTrack()

bool fitRecoTrack ( RecoTrack recoTrack,
Particle particle = nullptr 
)

Fit given RecoTrack with GBL.

Parameters
recoTrackA RecoTrack object to be fitted
particlePointer to reconstructed daughter particle updated by vertex fit OR nullptr for single track
Returns
true for success, false when some problems occured (or track too much down-weighted by previous DAF fit)

Definition at line 1036 of file MillepedeCollectorModule.cc.

1037 {
1038  try {
1039  // For already fitted tracks, try to get fitted (DAF) weights for CDC
1040  if (m_updateCDCWeights && recoTrack.getNumberOfCDCHits() && recoTrack.getTrackFitStatus()
1041  && recoTrack.getTrackFitStatus()->isFitted()) {
1042  double sumCDCWeights = recoTrack.getNumberOfCDCHits(); // start with full weights
1043  // Do the hits synchronisation
1044  auto relatedRecoHitInformation =
1046 
1047  for (RecoHitInformation& recoHitInformation : relatedRecoHitInformation) {
1048 
1049  if (recoHitInformation.getFlag() == RecoHitInformation::c_pruned) {
1050  B2FATAL("Found pruned point in RecoTrack. Pruned tracks cannot be used in MillepedeCollector.");
1051  }
1052 
1053  if (recoHitInformation.getTrackingDetector() != RecoHitInformation::c_CDC) continue;
1054 
1055  const genfit::TrackPoint* trackPoint = recoTrack.getCreatedTrackPoint(&recoHitInformation);
1056  if (trackPoint) {
1057  if (not trackPoint->hasFitterInfo(recoTrack.getCardinalRepresentation()))
1058  continue;
1059  auto kalmanFitterInfo = dynamic_cast<genfit::KalmanFitterInfo*>(trackPoint->getFitterInfo());
1060  if (not kalmanFitterInfo) {
1061  continue;
1062  } else {
1063  std::vector<double> weights = kalmanFitterInfo->getWeights();
1064  if (weights.size() == 2) {
1065  if (weights.at(0) > weights.at(1))
1066  recoHitInformation.setRightLeftInformation(RecoHitInformation::c_left);
1067  else if (weights.at(0) < weights.at(1))
1068  recoHitInformation.setRightLeftInformation(RecoHitInformation::c_right);
1069 
1070  double weightLR = weights.at(0) + weights.at(1);
1071  if (weightLR < m_minCDCHitWeight) recoHitInformation.setUseInFit(false);
1072  sumCDCWeights += weightLR - 1.; // reduce weight sum if weightLR<1
1073  }
1074  }
1075  }
1076  }
1077 
1078  double usedCDCHitFraction = sumCDCWeights / double(recoTrack.getNumberOfCDCHits());
1079  getObjectPtr<TH1F>("cdc_hit_fraction")->Fill(usedCDCHitFraction);
1080  if (usedCDCHitFraction < m_minUsedCDCHitFraction)
1081  return false;
1082  }
1083  } catch (...) {
1084  B2ERROR("Error in checking DAF weights from previous fit to resolve hit ambiguity. Why? Failed fit points in DAF? Skip track to be sure.");
1085  return false;
1086  }
1087 
1088  std::shared_ptr<genfit::GblFitter> gbl(new genfit::GblFitter());
1090  gbl->setTrackSegmentController(new GblMultipleScatteringController);
1091 
1092  MeasurementAdder factory("", "", "", "", "");
1093 
1094  // We need the store arrays
1100 
1101  // Create the genfit::MeasurementFactory
1102  genfit::MeasurementFactory<genfit::AbsMeasurement> genfitMeasurementFactory;
1103 
1104  // Add producer for alignable RecoHits to factory
1105  if (pxdHits.isOptional()) {
1108  genfitMeasurementFactory.addProducer(Const::PXD, PXDProducer);
1109  }
1110 
1111  if (svdHits.isOptional()) {
1114  genfitMeasurementFactory.addProducer(Const::SVD, SVDProducer);
1115  }
1116 
1117  if (cdcHits.isOptional()) {
1120  genfitMeasurementFactory.addProducer(Const::CDC, CDCProducer);
1121  }
1122 
1123  if (bklmHits.isOptional()) {
1126  genfitMeasurementFactory.addProducer(Const::BKLM, BKLMProducer);
1127  }
1128 
1129  if (eklmHits.isOptional()) {
1132  genfitMeasurementFactory.addProducer(Const::EKLM, EKLMProducer);
1133  }
1134 
1135 
1136  // Create the measurement creators
1137  std::vector<std::shared_ptr<PXDBaseMeasurementCreator>> pxdMeasurementCreators = { std::shared_ptr<PXDBaseMeasurementCreator>(new PXDCoordinateMeasurementCreator(genfitMeasurementFactory)) };
1138  std::vector<std::shared_ptr<SVDBaseMeasurementCreator>> svdMeasurementCreators = { std::shared_ptr<SVDBaseMeasurementCreator>(new SVDCoordinateMeasurementCreator(genfitMeasurementFactory)) };
1139  // TODO: Create a new MeasurementCreator based on SVDBaseMeasurementCreator (or on SVDCoordinateMeasurementCreator), which does the combination on the fly.
1140 
1141  std::vector<std::shared_ptr<CDCBaseMeasurementCreator>> cdcMeasurementCreators = { std::shared_ptr<CDCBaseMeasurementCreator>(new CDCCoordinateMeasurementCreator(genfitMeasurementFactory)) };
1142  std::vector<std::shared_ptr<BKLMBaseMeasurementCreator>> bklmMeasurementCreators = { std::shared_ptr<BKLMBaseMeasurementCreator>(new BKLMCoordinateMeasurementCreator(genfitMeasurementFactory)) };
1143  std::vector<std::shared_ptr<EKLMBaseMeasurementCreator>> eklmMeasurementCreators = { std::shared_ptr<EKLMBaseMeasurementCreator>(new EKLMCoordinateMeasurementCreator(genfitMeasurementFactory)) };
1144 
1145  // TODO: Or put it in here and leave the svdMeasurementCreators empty.
1146  std::vector<std::shared_ptr<BaseMeasurementCreator>> additionalMeasurementCreators = {};
1147  factory.resetMeasurementCreators(pxdMeasurementCreators, svdMeasurementCreators, cdcMeasurementCreators, bklmMeasurementCreators,
1148  eklmMeasurementCreators, additionalMeasurementCreators);
1149  factory.addMeasurements(recoTrack);
1150 
1151  auto& gfTrack = RecoTrackGenfitAccess::getGenfitTrack(recoTrack);
1152 
1153  int currentPdgCode = TrackFitter::createCorrectPDGCodeForChargedStable(Const::muon, recoTrack);
1154  if (particle)
1155  currentPdgCode = particle->getPDGCode();
1156 
1157  genfit::AbsTrackRep* trackRep = RecoTrackGenfitAccess::createOrReturnRKTrackRep(recoTrack, currentPdgCode);
1158  gfTrack.setCardinalRep(gfTrack.getIdForRep(trackRep));
1159 
1160  if (particle) {
1161  B2Vector3D vertexPos = particle->getVertex();
1162  B2Vector3D vertexMom = particle->getMomentum();
1163  gfTrack.setStateSeed(vertexPos, vertexMom);
1164 
1165  genfit::StateOnPlane vertexSOP(gfTrack.getCardinalRep());
1166  B2Vector3D vertexRPhiDir(vertexPos[0], vertexPos[1], 0);
1167  B2Vector3D vertexZDir(0, 0, vertexPos[2]);
1168  //FIXME: This causes problem to current GBL version in genfit -> needs update of GBL to re-enable
1169  // genfit::SharedPlanePtr vertexPlane(new genfit::DetPlane(vertexPos, vertexRPhiDir, vertexZDir));
1170  //This works instead fine:
1171  genfit::SharedPlanePtr vertexPlane(new genfit::DetPlane(vertexPos, vertexMom));
1172 
1173  vertexSOP.setPlane(vertexPlane);
1174  vertexSOP.setPosMom(vertexPos, vertexMom);
1175  TMatrixDSym vertexCov(5);
1176  vertexCov.UnitMatrix();
1177  // By using negative covariance no measurement is added to GBL. But this first point
1178  // is then used as additional point in trajectory at the assumed point of its fitted vertex
1179  vertexCov *= -1.;
1180  genfit::MeasuredStateOnPlane mop(vertexSOP, vertexCov);
1181  genfit::FullMeasurement* vertex = new genfit::FullMeasurement(mop, Const::IR);
1182  gfTrack.insertMeasurement(vertex, 0);
1183  }
1184 
1185  try {
1186  for (unsigned int i = 0; i < gfTrack.getNumPoints() - 1; ++i) {
1187  //if (gfTrack.getPointWithMeasurement(i)->getNumRawMeasurements() != 1)
1188  // continue;
1189  genfit::PlanarMeasurement* planarMeas1 = dynamic_cast<genfit::PlanarMeasurement*>(gfTrack.getPointWithMeasurement(
1190  i)->getRawMeasurement(0));
1191  genfit::PlanarMeasurement* planarMeas2 = dynamic_cast<genfit::PlanarMeasurement*>(gfTrack.getPointWithMeasurement(
1192  i + 1)->getRawMeasurement(0));
1193 
1194  if (planarMeas1 != NULL && planarMeas2 != NULL &&
1195  planarMeas1->getDetId() == planarMeas2->getDetId() &&
1196  planarMeas1->getPlaneId() != -1 && // -1 is default plane id
1197  planarMeas1->getPlaneId() == planarMeas2->getPlaneId()) {
1198  Belle2::AlignableSVDRecoHit* hit1 = dynamic_cast<Belle2::AlignableSVDRecoHit*>(planarMeas1);
1199  Belle2::AlignableSVDRecoHit* hit2 = dynamic_cast<Belle2::AlignableSVDRecoHit*>(planarMeas2);
1200  if (hit1 && hit2) {
1201  Belle2::AlignableSVDRecoHit* hitU(NULL);
1202  Belle2::AlignableSVDRecoHit* hitV(NULL);
1203  // We have to decide U/V now (else AlignableSVDRecoHit2D could throw FATAL)
1204  if (hit1->isU() && !hit2->isU()) {
1205  hitU = hit1;
1206  hitV = hit2;
1207  } else if (!hit1->isU() && hit2->isU()) {
1208  hitU = hit2;
1209  hitV = hit1;
1210  } else {
1211  continue;
1212  }
1214  // insert measurement before point i (increases number of currect point to i+1)
1215  gfTrack.insertMeasurement(hit, i);
1216  // now delete current point (at its original place, we have the new 2D recohit)
1217  gfTrack.deletePoint(i + 1);
1218  gfTrack.deletePoint(i + 1);
1219  }
1220  }
1221  }
1222  } catch (std::exception& e) {
1223  B2ERROR(e.what());
1224  B2ERROR("SVD Cluster combination failed. This is symptomatic of pruned tracks. MillepedeCollector cannot process pruned tracks.");
1225  return false;
1226  }
1227 
1228  try {
1229  gbl->processTrackWithRep(&gfTrack, gfTrack.getCardinalRep(), true);
1230  } catch (genfit::Exception& e) {
1231  B2ERROR(e.what());
1232  return false;
1233  } catch (...) {
1234  B2ERROR("GBL fit failed.");
1235  return false;
1236  }
1237 
1238  return true;
1239 }
This class is used to transfer CDC information to the track fit and Millepede.
This class is used to transfer PXD information to the track fit.
This class is used to transfer SVD information to the track fit.
This class is used to transfer SVD information to the track fit.
static const ChargedStable muon
muon particle
Definition: Const.h:651
TrackSegmentController for use with GblFitter in Belle2.
Algorithm class to translate the added detector hits (e.g.
bool m_updateCDCWeights
Update L/R weights from previous DAF fit result?
double m_minCDCHitWeight
Minimum CDC hit weight.
int m_recalcJacobians
Up to which external iteration propagation Jacobians should be re-calculated.
double m_minUsedCDCHitFraction
Minimum CDC used hit fraction.
std::string m_internalIterations
String defining internal GBL iterations for outlier down-weighting.
int m_externalIterations
Number of external iterations of GBL fitter.
This class stores additional information to every CDC/SVD/PXD hit stored in a RecoTrack.
CDCHit UsedCDCHit
Define, use of CDC hits as CDC hits (for symmetry).
EKLMAlignmentHit UsedEKLMHit
Define, use of EKLMHit2d as EKLM hits.
KLMHit2d UsedBKLMHit
Define, use of KLMHit2d as BKLM hits.
PXDCluster UsedPXDHit
Define, use of clusters or true hits for PXD.
SVDCluster UsedSVDHit
Define, use of clusters or true hits for SVD.
static genfit::Track & getGenfitTrack(RecoTrack &recoTrack)
Give access to the RecoTrack's genfit::Track.
Definition: RecoTrack.cc:404
static genfit::AbsTrackRep * createOrReturnRKTrackRep(RecoTrack &recoTrack, int PDGcode)
Checks if a TrackRap for the PDG id of the RecoTrack (and its charge conjugate) does already exit and...
Definition: RecoTrack.cc:409
const genfit::FitStatus * getTrackFitStatus(const genfit::AbsTrackRep *representation=nullptr) const
Return the track fit status for the given representation or for the cardinal one. You are not allowed...
Definition: RecoTrack.h:621
unsigned int getNumberOfCDCHits() const
Return the number of cdc hits.
Definition: RecoTrack.h:427
const genfit::TrackPoint * getCreatedTrackPoint(const RecoHitInformation *recoHitInformation) const
Get a pointer to the TrackPoint that was created from this hit.
Definition: RecoTrack.cc:230
genfit::AbsTrackRep * getCardinalRepresentation() const
Get a pointer to the cardinal track representation. You are not allowed to modify or delete it!
Definition: RecoTrack.h:631
const std::string & getStoreArrayNameOfRecoHitInformation() const
Name of the store array of the reco hit informations.
Definition: RecoTrack.h:747
RelationVector< TO > getRelationsTo(const std::string &name="", const std::string &namedRelation="") const
Get the relations that point from this object to another store array.
bool isU() const
Is the coordinate u or v?
Definition: SVDRecoHit.h:91
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
static int createCorrectPDGCodeForChargedStable(const Const::ChargedStable &particleType, const RecoTrack &recoTrack)
Helper function to multiply the PDG code of a charged stable with the charge of the reco track (if ne...
Definition: TrackFitter.cc:24
Abstract base class for a track representation.
Definition: AbsTrackRep.h:66
Detector plane.
Definition: DetPlane.h:59
Exception class for error handling in GENFIT (provides storage for diagnostic information)
Definition: Exception.h:48
bool isFitted() const
Has the track been fitted?
Definition: FitStatus.h:94
Measurement class implementing a measurement of all track parameters.
Generic GBL implementation.
Definition: GblFitter.h:53
Collects information needed and produced by a AbsKalmanFitter implementations and is specific to one ...
#StateOnPlane with additional covariance matrix.
void addProducer(int detID, AbsMeasurementProducer< measurement_T > *hitProd)
Register a producer module to the factory.
Template class for a measurement producer module.
Measurement class implementing a planar hit geometry (1 or 2D).
A state with arbitrary dimension defined in a DetPlane.
Definition: StateOnPlane.h:47
Object containing AbsMeasurement and AbsFitterInfo objects.
Definition: TrackPoint.h:46
AbsFitterInfo * getFitterInfo(const AbsTrackRep *rep=nullptr) const
Get fitterInfo for rep. Per default, use cardinal rep.
Definition: TrackPoint.cc:170
CoordinateMeasurementCreator< RecoHitInformation::UsedSVDHit, Const::SVD > SVDCoordinateMeasurementCreator
Hit to reco hit measurement creator for the SVD.
CoordinateMeasurementCreator< RecoHitInformation::UsedPXDHit, Const::PXD > PXDCoordinateMeasurementCreator
Hit to reco hit measurement creator for the PXD.
CoordinateMeasurementCreator< RecoHitInformation::UsedBKLMHit, Const::BKLM > BKLMCoordinateMeasurementCreator
Hit to reco hit measurement creator for the BKLM.
CoordinateMeasurementCreator< RecoHitInformation::UsedCDCHit, Const::CDC > CDCCoordinateMeasurementCreator
Needed for templating.
CoordinateMeasurementCreator< RecoHitInformation::UsedEKLMHit, Const::EKLM > EKLMCoordinateMeasurementCreator
Hit to reco hit measurement creator for the EKLM.
Namespace for the general broken lines package.
std::shared_ptr< genfit::DetPlane > SharedPlanePtr
Shared Pointer to a DetPlane.

◆ getAfterConditionPath()

Module::EAfterConditionPath getAfterConditionPath ( ) const
inherited

What to do after the conditional path is finished.

(defaults to c_End if no condition is set)

Definition at line 133 of file Module.cc.

◆ getConditionPath()

std::shared_ptr< Path > getConditionPath ( ) const
inherited

Returns the path of the last true condition (if there is at least one, else reaturn a null pointer).


Definition at line 113 of file Module.cc.

◆ getFileNames()

virtual std::vector<std::string> getFileNames ( bool  outputFiles)
inlinevirtualinherited

Return a list of output filenames for this modules.

This will be called when basf2 is run with "--dry-run" if the module has set either the c_Input or c_Output properties.

If the parameter outputFiles is false (for modules with c_Input) the list of input filenames should be returned (if any). If outputFiles is true (for modules with c_Output) the list of output files should be returned (if any).

If a module has sat both properties this member is called twice, once for each property.

The module should return the actual list of requested input or produced output filenames (including handling of input/output overrides) so that the grid system can handle input/output files correctly.

This function should return the same value when called multiple times. This is especially important when taking the input/output overrides from Environment as they get consumed when obtained so the finalized list of output files should be stored for subsequent calls.

Reimplemented in RootOutputModule, StorageRootOutputModule, and RootInputModule.

Definition at line 134 of file Module.h.

◆ getGlobalToLocalTransform()

TMatrixD getGlobalToLocalTransform ( const genfit::MeasuredStateOnPlane msop)

Compute the transformation matrix d(q/p,u',v',u,v)/d(x,y,z,px,py,pz) from state at first track point (vertex)

Parameters
msopMeasuredStateOnPlane - linearization point (track state @ plane) at which the transformation should be computed

Definition at line 1435 of file MillepedeCollectorModule.cc.

◆ getLocalToGlobalTransform()

TMatrixD getLocalToGlobalTransform ( const genfit::MeasuredStateOnPlane msop)

Compute the transformation matrix d(x,y,z,px,py,pz)/d(q/p,u',v',u,v) from state at first track point (vertex)

Parameters
msopMeasuredStateOnPlane - linearization point (track state @ plane) at which the transformation should be computed

Definition at line 1507 of file MillepedeCollectorModule.cc.

◆ getName()

const std::string& getName ( ) const
inlineinherited

Returns the name of the module.

This can be changed via e.g. set_name() in the steering file to give more useful names if there is more than one module of the same type.

For identifying the type of a module, using getType() (or type() in Python) is recommended.

Definition at line 187 of file Module.h.

◆ getParamInfoListPython()

std::shared_ptr< boost::python::list > getParamInfoListPython ( ) const
inherited

Returns a python list of all parameters.

Each item in the list consists of the name of the parameter, a string describing its type, a python list of all default values and the description of the parameter.

Returns
A python list containing the parameters of this parameter list.

Definition at line 279 of file Module.cc.

◆ getParticlesTracks()

std::vector< genfit::Track * > getParticlesTracks ( std::vector< Particle * >  particles,
bool  addVertexPoint = true 
)

Get all useable tracks for particles.

Parameters
particlesvector of Belle2::Particles to be changed in vector of genfit::Tracks
addVertexPointflag for adding the vertex point

Definition at line 1241 of file MillepedeCollectorModule.cc.

◆ getPreScaleChoice()

bool getPreScaleChoice ( )
inlineprivateinherited

I'm a little worried about floating point precision when comparing to 0.0 and 1.0 as special values.

But since a user will have set them (or left them as default) as exactly equal to 0.0 or 1.0 rather than calculating them in almost every case, I think we can assume that the equalities hold.

Definition at line 122 of file CalibrationCollectorModule.h.

123  {
124  if (m_preScale == 1.) {
125  return true;
126  } else if (m_preScale == 0.) {
127  return false;
128  } else {
129  const double randomNumber = gRandom->Uniform();
130  return randomNumber < m_preScale;
131  }
132  }
float m_preScale
Prescale module parameter, this fraction of events will have collect() run on them [0....

◆ getPrimaryVertexAndCov()

tuple< B2Vector3D, TMatrixDSym > getPrimaryVertexAndCov ( ) const

Get the primary vertex position estimation and its size from BeamSpot.

Returns
tuple<B2Vector3D, TMatrixDSym> tuple with position and size as covariance matrix

Definition at line 1569 of file MillepedeCollectorModule.cc.

◆ getReturnValue()

int getReturnValue ( ) const
inlineinherited

Return the return value set by this module.

This value is only meaningful if hasReturnValue() is true

Definition at line 381 of file Module.h.

◆ getTwoBodyToLocalTransform()

std::pair< TMatrixD, TMatrixD > getTwoBodyToLocalTransform ( Particle mother,
double  motherMass 
)

Compute the transformation matrices d(q/p,u'v',u,v)/d(vx,vy,vz,px,py,pz,theta,phi,M) = dq/d(v,z) for both particles in pair.

Only for decays of type V0(*)->f+f- (same mass for f)

Parameters
motherThe mother Belle2::Particle with two daughters, its 4-momenta should already be updated by a previous vertex fit done by modularAnalysis.
motherMassThis function expect the assumed invariant mass of the pair. This is to allow to set artifical values (e.g. for e+e- -> mu+mu-)
Returns
a pair of 5x9 matrices {dq+/d(v,z), dq-/d(v,z)}. One for each particle in list (in list order). NOTE: The signs DO NOT refer to charges of the particles! If you want to know: (+) particle is that one which goes along the mother momentum in CM system

The transformation is from local measurement system at 1st (GBL) point of each track in pair (virtual measurement (see fitRecoTrack(..., particle) and addVertexPoint parameter of getParticlesTracks(...)) to the common parameters which staticaly and kinematicaly describe the two-body decay:

  • Position of the common vertex (vy,vy,vz)
  • Total momentum of the pair (particles are back-to-back in their CM) (px,py,pz) and the invariant mass (M) of the decay
  • 2 angles describing the orientation of the decay particles in the system of the mother (CM)

Reference: Widl, Edmund ; Frühwirth R; "Representation and Estimation of Trajectories from Two-body Decays", CMS-NOTE-2007-032, http://cds.cern.ch/record/1073690

Definition at line 1289 of file MillepedeCollectorModule.cc.

◆ getType()

const std::string & getType ( ) const
inherited

Returns the type of the module (i.e.

class name minus 'Module')

Definition at line 41 of file Module.cc.

◆ hasProperties()

bool hasProperties ( unsigned int  propertyFlags) const
inherited

Returns true if all specified property flags are available in this module.

Parameters
propertyFlagsOred EModulePropFlags which should be compared with the module flags.

Definition at line 160 of file Module.cc.

◆ if_false()

void if_false ( const std::shared_ptr< Path > &  path,
EAfterConditionPath  afterConditionPath = EAfterConditionPath::c_End 
)
inherited

A simplified version to add a condition to the module.

Please note that successive calls of this function will add more than one condition to the module. If more than one condition results in true, only the last of them will be used.

Please be careful: Avoid creating cyclic paths, e.g. by linking a condition to a path which is processed before the path where this module is located in.

It is equivalent to the if_value() method, using the expression "<1". This method is meant to be used together with the setReturnValue(bool value) method.

Parameters
pathShared pointer to the Path which will be executed if the return value is false.
afterConditionPathWhat to do after executing 'path'.

Definition at line 85 of file Module.cc.

◆ if_true()

void if_true ( const std::shared_ptr< Path > &  path,
EAfterConditionPath  afterConditionPath = EAfterConditionPath::c_End 
)
inherited

A simplified version to set the condition of the module.

Please note that successive calls of this function will add more than one condition to the module. If more than one condition results in true, only the last of them will be used.

Please be careful: Avoid creating cyclic paths, e.g. by linking a condition to a path which is processed before the path where this module is located in.

It is equivalent to the if_value() method, using the expression ">=1". This method is meant to be used together with the setReturnValue(bool value) method.

Parameters
pathShared pointer to the Path which will be executed if the return value is true.
afterConditionPathWhat to do after executing 'path'.

Definition at line 90 of file Module.cc.

◆ if_value()

void if_value ( const std::string &  expression,
const std::shared_ptr< Path > &  path,
EAfterConditionPath  afterConditionPath = EAfterConditionPath::c_End 
)
inherited

Add a condition to the module.

Please note that successive calls of this function will add more than one condition to the module. If more than one condition results in true, only the last of them will be used.

See https://confluence.desy.de/display/BI/Software+ModCondTut or ModuleCondition for a description of the syntax.

Please be careful: Avoid creating cyclic paths, e.g. by linking a condition to a path which is processed before the path where this module is located in.

Parameters
expressionThe expression of the condition.
pathShared pointer to the Path which will be executed if the condition is evaluated to true.
afterConditionPathWhat to do after executing 'path'.

Definition at line 79 of file Module.cc.

◆ setDescription()

void setDescription ( const std::string &  description)
protectedinherited

Sets the description of the module.

Parameters
descriptionA description of the module.

Definition at line 214 of file Module.cc.

◆ setLogInfo()

void setLogInfo ( int  logLevel,
unsigned int  logInfo 
)
inherited

Configure the printed log information for the given level.

Parameters
logLevelThe log level (one of LogConfig::ELogLevel)
logInfoWhat kind of info should be printed? ORed combination of LogConfig::ELogInfo flags.

Definition at line 73 of file Module.cc.

◆ setName()

void setName ( const std::string &  name)
inlineinherited

Set the name of the module.

Note
The module name is set when using the REG_MODULE macro, but the module can be renamed before calling process() using the set_name() function in your steering file.
Parameters
nameThe name of the module

Definition at line 214 of file Module.h.

◆ setParamPython()

void setParamPython ( const std::string &  name,
const boost::python::object &  pyObj 
)
privateinherited

Implements a method for setting boost::python objects.

The method supports the following types: list, dict, int, double, string, bool The conversion of the python object to the C++ type and the final storage of the parameter value is done in the ModuleParam class.

Parameters
nameThe unique name of the parameter.
pyObjThe object which should be converted and stored as the parameter value.

Definition at line 234 of file Module.cc.

◆ setParamPythonDict()

void setParamPythonDict ( const boost::python::dict &  dictionary)
privateinherited

Implements a method for reading the parameter values from a boost::python dictionary.

The key of the dictionary has to be the name of the parameter and the value has to be of one of the supported parameter types.

Parameters
dictionaryThe python dictionary from which the parameter values are read.

Definition at line 249 of file Module.cc.

◆ setPropertyFlags()

void setPropertyFlags ( unsigned int  propertyFlags)
inherited

Sets the flags for the module properties.

Parameters
propertyFlagsbitwise OR of EModulePropFlags

Definition at line 208 of file Module.cc.

◆ setReturnValue() [1/2]

void setReturnValue ( bool  value)
protectedinherited

Sets the return value for this module as bool.

The bool value is saved as an integer with the convention 1 meaning true and 0 meaning false. The value can be used in the steering file to divide the analysis chain into several paths.

Parameters
valueThe value of the return value.

Definition at line 227 of file Module.cc.

◆ setReturnValue() [2/2]

void setReturnValue ( int  value)
protectedinherited

Sets the return value for this module as integer.

The value can be used in the steering file to divide the analysis chain into several paths.

Parameters
valueThe value of the return value.

Definition at line 220 of file Module.cc.

◆ setType()

void setType ( const std::string &  type)
protectedinherited

Set the module type.

Only for use by internal modules (which don't use the normal REG_MODULE mechanism).

Definition at line 48 of file Module.cc.

Member Data Documentation

◆ m_stableParticleWidth

double m_stableParticleWidth
private

Width (in GeV/c/c) to use for invariant mass constraint for 'stable' particles (like K short).

Temporary until proper solution is found

Definition at line 136 of file MillepedeCollectorModule.h.

◆ m_timedepConfig

std::vector< std::tuple< std::vector< int >, std::vector< std::tuple< int, int, int > > > > m_timedepConfig
private

Config for time dependence: list( tuple( list( param1, param2, ...

), list( (ev, run, exp), ... )), ...

Definition at line 181 of file MillepedeCollectorModule.h.


The documentation for this class was generated from the following files: