Belle II Software  light-2303-iriomote
B2BIIConvertMdstModule.h
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 
9 #pragma once
10 
11 #include <framework/core/Module.h>
12 
13 #define BELLE_TARGET_H "belle-x86_64-unknown-linux-gnu-g++.h"
14 #include "belle_legacy/panther/panther.h"
15 #include "belle_legacy/panther/panther_group.h"
16 
17 // Belle objects (Panther tables)
18 #include "belle_legacy/tables/belletdf.h"
19 #include "belle_legacy/tables/mdst.h"
20 
21 #include "belle_legacy/helix/Helix.h"
22 
23 // Belle2 objects
24 #include <mdst/dataobjects/V0.h>
25 #include <mdst/dataobjects/ECLCluster.h>
26 #include <mdst/dataobjects/KLMCluster.h>
27 #include <analysis/dataobjects/Particle.h>
28 #include <analysis/dataobjects/ParticleList.h>
29 #include <mdst/dataobjects/MCParticle.h>
30 #include <mdst/dataobjects/MCParticleGraph.h>
31 #include <mdst/dataobjects/Track.h>
32 #include <mdst/dataobjects/PIDLikelihood.h>
33 #include <framework/dataobjects/EventExtraInfo.h>
34 #include <b2bii/dataobjects/BelleTrkExtra.h>
35 
36 // Replace BeamParameters
37 #include <mdst/dbobjects/BeamSpot.h>
38 #include <mdst/dbobjects/CollisionBoostVector.h>
39 #include <mdst/dbobjects/CollisionInvariantMass.h>
40 
41 #include <framework/datastore/StoreArray.h>
42 #include <framework/database/DBObjPtr.h>
43 #include <framework/gearbox/Const.h>
44 
45 #include "CLHEP/Vector/ThreeVector.h"
46 #include "CLHEP/Vector/LorentzVector.h"
47 #include "CLHEP/Matrix/SymMatrix.h"
48 #include "CLHEP/Geometry/Point3D.h"
49 
50 typedef HepGeom::Point3D<double> HepPoint3D;
51 
52 #include <string>
53 #include <map>
54 
55 //enable ACC conversion (needs externals >= v00-06-01)
56 #define HAVE_KID_ACC
57 
58 //enable EID conversion (needs externals > v00-07-01)
59 #define HAVE_EID
60 
61 // enable findKs (needs externals > v00-07-01)
62 #define HAVE_FINDKS
63 
64 // enable nisKsFinder (needs externals > v00-07-01)
65 #define HAVE_NISKSFINDER
66 
67 // enable goodLambda (needs externals >= v01-08-00)
68 #define HAVE_GOODLAMBDA
69 
70 namespace Belle2 {
94  class B2BIIConvertMdstModule : public Module {
95 
100 
103 
106 
107  };
108 
109  // Public functions
110  public:
111 
115  virtual ~B2BIIConvertMdstModule() override;
116 
118  virtual void initialize() override;
119 
121  virtual void beginRun() override;
122  virtual void event() override;
123  virtual void endRun() override;
124  virtual void terminate() override;
126  // Data members
127  private:
128 
132  void initializeDataStore();
133 
135  // true = real data
136  // false = mc
138 
141 
143  // true = use 6x6 (position, momentum) covariance matrix
144  // false = use 5x5 (helix parameters) covariance matrix
146 
149 
152 
155  bool m_nisEnable;
168 
171 
172  //-----------------------------------------------------------------------------
173  // CONVERT TABLES
174  //-----------------------------------------------------------------------------
175 
179  void convertRecTrgTable();
180 
184  void convertEvtclsTable();
185 
189  void convertGenHepEvtTable();
190 
194  void convertMdstECLTable();
195 
199  void convertMdstKLMTable();
200 
205 
209  void convertMdstGammaTable();
210 
214  void copyNbarFromGamma();
215 
219  void convertMdstKLongTable();
220 
224  void convertMdstPi0Table();
225 
230  void convertMdstVee2Table();
231 
233  void convertBeamEnergy();
234 
236  void convertIPProfile(bool beginRun = false);
237 
238  //-----------------------------------------------------------------------------
239  // CONVERT OBJECTS
240  //-----------------------------------------------------------------------------
241 
245  void convertGenHepevtObject(const Belle::Gen_hepevt& genHepevt, MCParticleGraph::GraphParticle* mcParticle);
246 
251  void convertMdstECLObject(const Belle::Mdst_ecl& ecl, const Belle::Mdst_ecl_aux& eclAux, ECLCluster* eclCluster);
252 
257  void convertMdstKLMObject(const Belle::Mdst_klm_cluster& klm, KLMCluster* klmCluster);
258 
263  void convertMdstChargedObject(const Belle::Mdst_charged& belleTrack, Track* track);
264 
268  TrackFitResult createTrackFitResult(const CLHEP::HepLorentzVector& momentum,
269  const HepPoint3D& position,
270  const CLHEP::HepSymMatrix& error,
271  const short int charge,
272  const Const::ParticleType& pType,
273  const float pValue,
274  const uint64_t hitPatternCDCInitializer,
275  const uint32_t hitPatternVXDInitializer,
276  const uint16_t ndf);
277 
281  int getHelixParameters(const Belle::Mdst_trk_fit& trk_fit,
282  const double mass,
283  const HepPoint3D& newPivot,
284  std::vector<float>& helixParams,
285  CLHEP::HepSymMatrix& error5x5,
286  CLHEP::HepLorentzVector& momentum,
287  HepPoint3D& position,
288  CLHEP::HepSymMatrix& error7x7,
289  const double dPhi = 0.0);
290 
294  void convertHelix(Belle::Helix& helix, std::vector<float>& helixParams, CLHEP::HepSymMatrix& error5x5);
295 
299  void convertHelix(const Belle::Mdst_trk_fit& trk_fit, const HepPoint3D& newPivot, std::vector<float>& helixParams,
300  std::vector<float>& helixError);
301 
305  void belleVeeDaughterToCartesian(const Belle::Mdst_vee2& vee, const int charge, const Const::ParticleType& pType,
306  CLHEP::HepLorentzVector& momentum, HepPoint3D& position, CLHEP::HepSymMatrix& error);
307 
311  void belleVeeDaughterHelix(const Belle::Mdst_vee2& vee, const int charge, std::vector<float>& helixParam,
312  std::vector<float>& helixError);
313 
315  void convertPIDData(const Belle::Mdst_charged& belleTrack, const Track* track);
316 
318  const static int c_nHyp = 5;
321 
323  void setLikelihoods(PIDLikelihood* pid, Const::EDetector det, double likelihoods[c_nHyp], bool discard_allzero = false);
324 
325 #ifdef HAVE_KID_ACC
327  static double acc_pid(const Belle::Mdst_charged& chg, int idp);
329  double cdc_pid(const Belle::Mdst_charged& chg, int idp);
330 #endif
331 
333  double atcPID(const PIDLikelihood* pid, int sigHyp, int bkgHyp);
334 
335  //-----------------------------------------------------------------------------
336  // RELATIONS
337  //-----------------------------------------------------------------------------
338 
343 
348 
349  //-----------------------------------------------------------------------------
350  // MISC
351  //-----------------------------------------------------------------------------
352 
356  int recoverMoreThan24bitIDHEP(int id);
357 
361  void testMCRelation(const Belle::Gen_hepevt& belleMC, const MCParticle* mcP, const std::string& objectName);
362 
365 
367  std::map<int, int> genHepevtToMCParticle;
369  std::map<int, int> mdstEclToECLCluster;
371  std::map<int, int> mdstGammaToParticle;
373  std::map<int, int> mdstKlmToKLMCluster;
375  std::map<int, int> mdstKlongToParticle;
376 
379 
382 
385 
388 
391 
394 
397 
400 
403 
406 
428  const int ERRMCONV[7] = {3, 4, 5, -1, 0, 1, 2};
429 
431  const double BFIELD = 1.5;
432 
434  const double KAPPA2OMEGA = 1.5 * TMath::C() * 1E-11;
435 
436  };
437 
439 } // end namespace Belle2
Module converts Belle MDST objects (Panther records) to Belle II MDST objects.
void belleVeeDaughterHelix(const Belle::Mdst_vee2 &vee, const int charge, std::vector< float > &helixParam, std::vector< float > &helixError)
obtains the helix parameters of the vee daughters
double atcPID(const PIDLikelihood *pid, int sigHyp, int bkgHyp)
calculates atc_pid(3,1,5,sigHyp,bkgHyp).prob() from converted PIDLikelihood
void convertMdstGammaTable()
Reads all entries of Mdst_Gamma Panther table, creates a particle list 'gamma:mdst' and adds them to ...
std::map< int, int > mdstKlmToKLMCluster
map of Mdst_klm Panther IDs and corresponding KLMCluster StoreArray indices
void copyNbarFromGamma()
Copies Particles in 'gamma:mdst' with energy > 0.5 GeV to be anti-n0:mdst.
void convertMdstChargedTable()
Reads and converts all entries of Mdst_charged (Mdst_trk and Mdst_trk_fit) Panther table to Track (Tr...
void setTracksToECLClustersRelations()
Sets Track -> ECLCluster relations.
OptionalDBObjPtr< CollisionBoostVector > m_collisionBoostVectorDB
CollisionBoostVector for boost vector.
StoreObjPtr< EventExtraInfo > m_evtInfo
Event Extra Info.
const int ERRMCONV[7]
CONVERSION OF TRACK ERROR MATRIX ELEMENTS.
StoreArray< KLMCluster > m_klmClusters
KLM clusters.
void belleVeeDaughterToCartesian(const Belle::Mdst_vee2 &vee, const int charge, const Const::ParticleType &pType, CLHEP::HepLorentzVector &momentum, HepPoint3D &position, CLHEP::HepSymMatrix &error)
Fills 4-momentum, position and 7x7 error matrix from Belle Vee daughter.
@ c_GeneratorLevel
Match to generator-level particles.
virtual void initialize() override
Initialize the module.
void setLikelihoods(PIDLikelihood *pid, Const::EDetector det, double likelihoods[c_nHyp], bool discard_allzero=false)
Add given Belle likelihoods (not log-likelihoods, in Belle hypothesis order) for given detector to pi...
StoreArray< V0 > m_v0s
V0-particles.
virtual void event() override
Called for each event.
void convertGenHepEvtTable()
Reads and converts all entries of Gen_hepevt Panther table to MCParticle dataobjects and adds them to...
double cdc_pid(const Belle::Mdst_charged &chg, int idp)
Returns CDC likelihood for given hypothesis idp.
void convertRecTrgTable()
Reads and converts m_final from rectrg_summary3.
void setKLMClustersRelations()
Sets KLMCluster -> Track and ECLCluster relations.
bool m_convertEvtcls
Flag to switch on conversion of Evtcls table.
const double KAPPA2OMEGA
Conversion factor for Kappa -> Omega helix parameters.
virtual void endRun() override
Called when the current run is finished.
bool m_nisEnable
Flag to switch on conversion of nisKsFinder info.
StoreArray< TrackFitResult > m_trackFitResults
Track fir results.
BeamSpot m_beamSpot
Interaction Point of the beam.
StoreArray< Particle > m_particles
Particles.
virtual void terminate() override
Terminates the module.
OptionalDBObjPtr< CollisionInvariantMass > m_collisionInvMDB
CollisionInvariantMass for Invariant Mass of Beam.
void convertHelix(Belle::Helix &helix, std::vector< float > &helixParams, CLHEP::HepSymMatrix &error5x5)
Converts Belle's Helix parameters and it's covariance matrix to Belle II's version.
void convertMdstPi0Table()
Reads all entries of Mdst_Pi0 Panther table, creates a particle list 'pi0:mdst' and adds them to Stor...
std::map< int, int > genHepevtToMCParticle
map of Gen_hepevt Panther IDs and corresponding MCParticle StoreArray indices
void testMCRelation(const Belle::Gen_hepevt &belleMC, const MCParticle *mcP, const std::string &objectName)
Checks if the reconstructed object (Track, ECLCluster, ...) was matched to the same MCParticle.
bool m_convertNbar
Flag to create anti-n0:mdst list from gamma:mdst.
void convertIPProfile(bool beginRun=false)
Stores the IPProfiles in BeamSpot (currently in DataStore)
void convertMdstECLObject(const Belle::Mdst_ecl &ecl, const Belle::Mdst_ecl_aux &eclAux, ECLCluster *eclCluster)
Converts Mdst_ecl(_aux) record to ECLCluster object.
CollisionInvariantMass m_collisionInvM
CollisionInvariantMass for the invariant mass of the beam.
bool m_convertBeamParameters
Convert beam parameters or use information stored in Belle II database.
static double acc_pid(const Belle::Mdst_charged &chg, int idp)
Returns ACC likelihood for given hypothesis idp.
virtual void beginRun() override
Module functions to be called from event process.
StoreArray< Track > m_tracks
Tracks.
void convertBeamEnergy()
Stores beam parameters (energy, angles) in CollisionInvariantMass and CollisionBoostVector (currently...
void convertPIDData(const Belle::Mdst_charged &belleTrack, const Track *track)
Get PID information for belleTrack and add it to PIDLikelihood (with relation from track).
void convertMdstKLMObject(const Belle::Mdst_klm_cluster &klm, KLMCluster *klmCluster)
Converts Mdst_klm_cluster record to KLMCluster object.
Belle2::MCParticleGraph m_particleGraph
MCParticle Graph to build Belle2 MC Particles.
void convertMdstKLongTable()
Reads all entries of Mdst_Klong Panther table, creates a particle list 'K_L0:mdst' and adds them to S...
OptionalDBObjPtr< BeamSpot > m_beamSpotDB
BeamSpot for IP.
bool m_realData
flag that tells whether given data sample is for real data or MC
StoreArray< ECLCluster > m_eclClusters
ECL clusters.
void convertGenHepevtObject(const Belle::Gen_hepevt &genHepevt, MCParticleGraph::GraphParticle *mcParticle)
Converts Gen_hepevt record to MCParticleGraph object.
void initializeDataStore()
Initializes Belle II DataStore.
void convertMdstECLTable()
Reads and converts all entries of Mdst_ecl(_aux) Panther table to ECLCluster dataobjects and adds the...
CollisionBoostVector m_collisionBoostVector
CollisionBoostVector for bosst vector of the beam.
std::string m_mcMatchingModeString
MC matching mode.
int m_lastIPProfileBin
variable to tell us which IPProfile bin was active last time we looked
void convertMdstKLMTable()
Reads and converts all entries of Mdst_klm_cluster Panther table to KLMCluster dataobjects and adds t...
bool m_convertRecTrg
Flag to switch on conversion of rectrg_summary3.
std::map< int, int > mdstGammaToParticle
map of gamma Panther IDs and corresponding Particle StoreArray indices
static const Const::ChargedStable c_belleHyp_to_chargedStable[c_nHyp]
maps Belle hypotheses to Const::ChargedStable (from http://belle.kek.jp/secured/wiki/doku....
std::map< int, int > mdstKlongToParticle
map of Klong Panther IDs and corresponding Particle StoreArray indices
double m_matchType2E9oE25Threshold
E9/E25 threshold value clusters with a value above this threshold are classified as neutral even if t...
void convertMdstChargedObject(const Belle::Mdst_charged &belleTrack, Track *track)
Converts Mdst_charged (Mdst_trk(_fit)) record to Track (TrackFitResult) object.
StoreArray< MCParticle > m_mcParticles
MC particles.
void convertMdstVee2Table()
Reads and converts all entries of Mdst_vee2 Panther table to V0 dataobjects and adds them to StoreArr...
StoreArray< PIDLikelihood > m_pidLikelihoods
output PIDLikelihood array.
std::map< int, int > mdstEclToECLCluster
map of Mdst_ecl Panther IDs and corresponding ECLCluster StoreArray indices
TrackFitResult createTrackFitResult(const CLHEP::HepLorentzVector &momentum, const HepPoint3D &position, const CLHEP::HepSymMatrix &error, const short int charge, const Const::ParticleType &pType, const float pValue, const uint64_t hitPatternCDCInitializer, const uint32_t hitPatternVXDInitializer, const uint16_t ndf)
Creates TrackFitResult and fills it.
virtual ~B2BIIConvertMdstModule() override
Destructor.
const double BFIELD
B filed in TESLA.
MCMatchingMode m_mcMatchingMode
C matching mode.
StoreArray< BelleTrkExtra > m_belleTrkExtra
Belle CDC extra information.
bool m_use6x6CovarianceMatrix4Tracks
flag that tells which form of covariance matrix should be used in the conversion of charged tracks
int recoverMoreThan24bitIDHEP(int id)
Helper function to recover falsely set idhep info in GenHepEvt list.
bool m_convertTrkExtra
Flag to switch on conversion of first(last)_{x,y,z} of mdst_trk_fit.
int getHelixParameters(const Belle::Mdst_trk_fit &trk_fit, const double mass, const HepPoint3D &newPivot, std::vector< float > &helixParams, CLHEP::HepSymMatrix &error5x5, CLHEP::HepLorentzVector &momentum, HepPoint3D &position, CLHEP::HepSymMatrix &error7x7, const double dPhi=0.0)
Fills Helix parameters (converted to Belle II version), 5x5 error matrix, 4-momentum,...
static const int c_nHyp
Number of Belle track hypotheses (see c_belleHyp_to_chargedStable).
void convertEvtclsTable()
Reads and converts all entries of evtcls Panther table.
This class contains the beam spot position and size modeled as a gaussian distribution in space.
Definition: BeamSpot.h:22
This class contains the measured average boost vector vec(beta) = (beta_x, beta_y,...
This class contains the measured average center-of-mass energy, which is equal to the invariant mass ...
Provides a type-safe way to pass members of the chargedStableSet set.
Definition: Const.h:580
The ParticleType class for identifying different particle types.
Definition: Const.h:399
EDetector
Enum for identifying the detector components (detector and subdetector).
Definition: Const.h:42
ECL cluster data.
Definition: ECLCluster.h:27
KLM cluster data.
Definition: KLMCluster.h:28
Class to represent Particle data in graph.
Class to build, validate and sort a particle decay chain.
A Class to store the Monte Carlo particle information.
Definition: MCParticle.h:32
Base class for Modules.
Definition: Module.h:72
Optional DBObjPtr: This class behaves the same as the DBObjPtr except that it will not raise errors w...
Definition: DBObjPtr.h:48
Class to collect log likelihoods from TOP, ARICH, dEdx, ECL and KLM aimed for output to mdst includes...
Definition: PIDLikelihood.h:26
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:95
Values of the result of a track fit with a given particle hypothesis.
Class that bundles various TrackFitResults.
Definition: Track.h:25
Abstract base class for different kinds of events.
Definition: ClusterUtils.h:23