Belle II Software  release-08-01-10
B2BIIFixMdstModule.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 // $Id: B2BIIFixMdst.h 11331 2011-07-25 11:58:12Z hitoshi $
10 //
11 // $Log$
12 // Revision 1.16 2005/03/10 14:16:14 hitoshi
13 // check table sizes
14 //
15 // Revision 1.15 2004/04/25 16:33:47 hitoshi
16 // modified to be able to handle output from low p finder (by kakuno). modified
17 // Benergy to fetch data from DB (by Shibata).
18 //
19 // Revision 1.14 2003/06/24 07:55:15 katayama
20 // Remived unused parameters
21 //
22 // Revision 1.13 2003/06/12 13:25:24 hitoshi
23 // scale_error implemented last year (by Higuchi; valid up to exp19) is incorporated
24 //
25 // Revision 1.12 2003/03/19 05:02:32 hitoshi
26 // minor change (by Miyabayashi).
27 //
28 // Revision 1.11 2002/09/06 03:47:21 hitoshi
29 // Endcap_MX_layer=11 is now the default (by muon group).
30 //
31 // Revision 1.9 2002/04/26 01:25:07 katayama
32 // New correction from Perers san
33 //
34 // Revision 1.8 2002/04/24 00:58:36 hitoshi
35 // new scale factors for e15 mdst reprocessed with 20020405.
36 //
37 // Revision 1.7 2002/04/19 07:24:38 katayama
38 // Added pi0/vertex, calibdedx
39 //
40 // Revision 1.6 2002/04/05 01:19:32 katayama
41 // templates for ecl_primary_vertex
42 //
43 // Revision 1.5 2002/03/31 06:54:39 katayama
44 // fix_pi0
45 //
46 // Revision 1.4 2002/03/30 01:06:05 katayama
47 // HadronB & L4passed events only
48 //
49 // Revision 1.3 2002/03/19 04:25:47 katayama
50 // Add parameters for scale_momenta, set nominal b energy
51 //
52 // Revision 1.2 2002/03/13 02:55:19 katayama
53 // First version
54 //
55 //
56 
57 #pragma once
58 
59 #define HEP_SHORT_NAMES
60 
61 /* Basf2 headers. */
62 #include <framework/core/Module.h>
63 #include <framework/dataobjects/EventExtraInfo.h>
64 #include <framework/datastore/StoreObjPtr.h>
65 #include <framework/logging/Logger.h>
66 
67 /* Belle headers. */
68 #include <belle_legacy/belle.h>
69 #include <belle_legacy/tables/run_info.h>
70 
71 /* CLHEP headers. */
72 #include <CLHEP/Matrix/SymMatrix.h>
73 #include <CLHEP/Geometry/Point3D.h>
74 
75 /* C++ headers. */
76 #include <string>
77 
79 
80 namespace Belle {
81 
82  class Mdst_vee2;
83 
84 }
85 
86 namespace Belle2 {
92  class MuidProb;
93 
102 
103  static const int m_muid_version = 100;
105  public:
110 
114  virtual void initialize() override;
115 
119  virtual void beginRun() override;
120 
124  virtual void event() override;
125 
129  virtual void terminate() override;
130 
134  static double get_Benergy()
135  {
136  return s_benergy_value;
137  };
138 
142  static double get_pi0resol(double p, double theta, const char* side,
143  bool mcdata, int exp, int option)
144  {
145  return pi0resol(p, theta, side, mcdata, exp, option);
146  };
147 
148  public: // BASF Parameters
149 
168  int m_benergy;
171  static double s_benergy_value;
183  int m_5Srun;
198  int m_expno;
200 
203 
204  protected:
205 
206  private:
207 
208  int m_old_expno = 0;
209  int m_mapped_expno = 0;
211  MuidProb* m_muonprob{nullptr};
212  MuidProb* m_pionprob{nullptr};
213  MuidProb* m_kaonprob{nullptr};
217 
218  bool good_event();
220  int get_reprocess_version();
222  void scale_momenta(float scale_data = 1.0, float scale_mc = 1.0, int mode = 0);
224  void scale_momenta_set(const int, const int, const int,
225  double&);
226  void scale_momenta_set_v1(const int, const int, const int, double&);
227  void scale_momenta_set_v2(const int, const int, const int, double&);
229  double vee_mass_nofit(const Belle::Mdst_vee2& vee2, float scale = 1.0);
231  // Author: J.Tanaka (+T.Higuchi/2002,2003)
232  void scale_error(const int message_level = 0);
233  // void scale_error(void);
234 
235  void smear_trk();
237  // Author: H.Kakuno
238  int add_extra_trk_vee2();
239  int remove_extra_trk_vee2();
241  // Author: Miyabayashi
246  void make_pi0(int, double, double);
247  void correct_ecl(int, int);
249  int set_primary_vertex(HepPoint3D& v, CLHEP::HepSymMatrix& ve);
251  void make_pi0_primary_vertex(int, double, double, const HepPoint3D&,
252  const CLHEP::HepSymMatrix&);
254  const CLHEP::HepSymMatrix&);
256  static double pi0resol(double, double, const char*, bool, int, int);
257 
258  // Author: T. Matsumoto
259  // based on dcpvrare_ml:0127, interface is modified by M. Nakao
260  //
262  double Benergy(int expnum = 0, int runnum = 0);
263 
264  // Author: Kakuno
266  void fix_pi0_brecon(void);
267  // Author: Mike Peters
269  void shift_tof(const int mode);
271  void shift_tof_set(const int expno, const int runno,
272  const int mode, const int im,
273  const double pmom, const double sgn,
274  double& shift);
275  // Author: Leo Piilonen
276  void Muid_init(void);
277  void Muid_term(void);
278  void Muid_event(void);
279  void Muid_begin_run(const int, const int, const int);
280  void Muid_end_run(void);
282  };
283 
285  class MuidProb {
286 
287  public:
288 
292  MuidProb(const char*, int&);
294  ~MuidProb() {};
296  double prob(int, int, int, int, double) const;
298  double probRange(int, int, int, int) const;
300  double probRchisq(int, int, int, double) const;
302  double probECL(double, double) const;
304  void readDB(const char*, int&);
306 
307  private:
308 
309  // Array sizes as stored in input file
310 
311  static const int kRange = 16;
312  static const int kRchisq = 50;
313  static const int kEEcl = 100;
314  static const int kPTrk = 50;
316  // Overflow value of reduced chi-squared, ECL energy, CDC momentum
317 
318  static const double kRchisqMax;
319  static const double kEEclMax;
320  static const double kPTrkMax;
322  // Probability density arrays for range, reduced chi**2, and ECL energy
323  // (last one sliced by tracdk momentum in 100 MeV/c bins).
324  // One extra bin in chi-squared and ECL-energy distributions for overflows.
325  // For reduced chi-squared and ECL-energy, three extra arrays are stored for
326  // spline interpolation to eliminate binning artifacts.
327 
328  double fRange[2][4][15][kRange];
329  double fRchisq[2][4][kRchisq + 1];
330  double fRchisqN[2][4][15];
331  double fRchisqD1[2][4][kRchisq + 1] = {{{0.0}}};
332  double fRchisqD2[2][4][kRchisq + 1] = {{{0.0}}};
333  double fRchisqD3[2][4][kRchisq + 1] = {{{0.0}}};
334  double fEEcl[kPTrk][kEEcl + 1];
335  double fEEclD1[kPTrk][kEEcl + 1] = {{0.0}};
336  double fEEclD2[kPTrk][kEEcl + 1] = {{0.0}};
337  double fEEclD3[kPTrk][kEEcl + 1] = {{0.0}};
339  };
340 
342 }
Declaration of class B2BIIFixMdst.
void Muid_end_run(void)
Called when the current run ends.
int m_expno
parameter ExpNo: Experiment number for muid (default=0) 0 ==> use experiment number stored in data fi...
std::string m_scale_error_dataset_name
Set scale_error_dataset name.
int m_benergy_db
Apply Benergy from DB or file.
void Muid_init(void)
Initialize the Muid module.
float m_scale_momenta_scale_mc
Set parameter scale_mc for scale_momenta.
bool m_saveResultExtraInfo
Whether to save result as EventExtraInfo.
int m_calib_dedx
Do dedx calibration.
int m_smear_trk
Do extra-smearing for MC tracks.
int m_scale_momenta
Apply scale_momenta.
void Muid_begin_run(const int, const int, const int)
Called for each new run.
int m_correct_ecl_option
Apply correct_ecl_option.
MuidProb * m_kaonprob
Pointer to kaons' prob-density object.
int m_use_ecl
parameter UseECL: Use (1) or don't use (0) ECL in muid (default=0)
int m_l4passed_only
Select level4-passed event only.
int m_correct_ecl
Apply correct_ecl.
double m_make_pi0_lower_limit
Set make_pi0 lower mass limit.
int m_make_pi0
Apply make_pi0 (after correct_ecl)
int m_shift_tof_mode
Do tof_correction.
int m_correct_ecl_primary_vertex
Apply correct_ecl_primary_vertex.
void Muid_event(void)
Called for each event.
static double get_Benergy()
Get Benergy.
int m_reprocess_version_specified
Specify reprocess version.
float m_scale_momenta_scale_data
Set parameter scale_data for scale_momenta.
int m_correct_ecl_version
Apply correct_ecl_version.
MuidProb * m_pionprob
Pointer to pions' prob-density object.
int m_scale_error
Apply scale_error.
int m_scale_momenta_mode
Set parameter mode for scale_momenta.
int m_check_version_consistency
Check consistency between environment variable and mdst version.
int m_table_size
Check table sizes.
void Muid_term(void)
Terminate the Muid module.
int m_limit_mdst_ecl_trk
Limit of mdst_ecl_trk table size.
int m_add_or_remove_extra_trk_vee2
(1) to add to Mdst_charged etc, (-1) to remove (move to Mdst_*_extra), (0) do nothing
int m_make_pi0_primary_vertex
Apply make_pi0_primary_vertex (after correct_ecl)
int m_correct_ecl_5s
For run indep.
int m_mapped_expno
Mapped value of m_old_exp_no.
int m_reprocess_version
Reprocess version (=0:old; =1:new)
int m_limit_mdst_klm_cluster_hit
Limit of mdst_klm_cluster_hit table size.
int m_hadron_b_only
Select Hadron B event only.
MuidProb * m_muonprob
Pointer to muons' prob-density object.
int m_old_expno
Most recently used experiment # in muid.
static double get_pi0resol(double p, double theta, const char *side, bool mcdata, int exp, int option)
Get pi0 resolution.
static const int m_muid_version
Version number of muid part.
int m_good_event
Select good event only.
int m_hadron_a_only
Select Hadron A event only.
int m_benergy_mcdb
Apply Benergy from DB or default value in MC.
double m_make_pi0_upper_limit
Set make_pi0 upper mass limit.
StoreObjPtr< EventExtraInfo > m_eventExtraInfo
Event ExtraInfo.
int m_5Srun
5S,2S,1S run or not
int m_eklm_max_layer
parameter Endcap_MX_layer: Max layer # of KLM endcap (default=11) 0 ==> use same value as was used by...
int m_make_pi0_option
Set make_pi0 option.
Base class for Modules.
Definition: Module.h:72
Class computes probability density for Muid calculation.
~MuidProb()
Destructor.
double fRchisq[2][4][kRchisq+1]
Reduced chi-squared pdf.
double fRchisqD2[2][4][kRchisq+1]
Second derivatives of Reduced chi-squared pdf.
static const int kRange
Array size of range.
double fRange[2][4][15][kRange]
Range pdf.
double probRange(int, int, int, int) const
Compute probability density for range.
double probECL(double, double) const
Compute probability density for ECL energy deposit.
double fRchisqD1[2][4][kRchisq+1]
First derivatives of Reduced chi-squared pdf.
double prob(int, int, int, int, double) const
Compute probability density.
double probRchisq(int, int, int, double) const
Compute probability density for reduced chi-squared.
MuidProb(const char *, int &)
Constructor.
static const int kRchisq
Array size of reduced chi-squared.
static const double kEEclMax
Overflow value of ECL energy.
double fEEclD1[kPTrk][kEEcl+1]
First derivatives of ECL energy pdf.
double fEEclD2[kPTrk][kEEcl+1]
Second derivatives of ECL energy pdf.
static const double kPTrkMax
Overflow value of CDC momentum.
double fEEclD3[kPTrk][kEEcl+1]
Third derivatives of ECL energy pdf.
double fRchisqN[2][4][15]
Non-overflow normalization.
static const int kEEcl
Array size of ECL energy.
double fRchisqD3[2][4][kRchisq+1]
Third derivatives of Reduced chi-squared pdf.
static const int kPTrk
Array size of CDC momentum.
static const double kRchisqMax
Overflow value of reduced chi-squared.
void readDB(const char *, int &)
Read in probability density functions from database.
double fEEcl[kPTrk][kEEcl+1]
ECL energy pdf.
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:96
void fix_pi0_brecon(void)
Fix relation gamma<->pi0 in brecon table.
void scale_momenta_set_v2(const int, const int, const int, double &)
Return scale factors set_v2.
void make_pi0(int, double, double)
Create Mdst_pi0 from Mdst_gamma and Mdst_ecl to let people get mass-constraint fitted momentum of pi0...
void shift_tof(const int mode)
Shift tof times to account for residuals.
virtual void initialize() override
Initialize the module.
void make_pi0_primary_vertex(int, double, double, const HepPoint3D &, const CLHEP::HepSymMatrix &)
Fill Mdst_pi0 based on the fit result.
virtual void event() override
Called for each event.
void smear_trk()
Apply track smearing (on MC)
double Benergy(int expnum=0, int runnum=0)
Return Beam energy.
virtual void terminate() override
Terminates the module.
int remove_extra_trk_vee2()
Remove extra tracks from Mdst_trk and Mdst_vee2.
void correct_ecl_primary_vertex(const HepPoint3D &, const CLHEP::HepSymMatrix &)
Correct ecl using primary vertex.
void correct_ecl(int, int)
Correct photon's momenta and error matrix.
virtual void beginRun() override
Called when a new run is started.
void scale_momenta_set_v1(const int, const int, const int, double &)
Return scale factors set_v1.
int add_extra_trk_vee2()
Add Mdst_trk_extra and Mdst_vee_extra to Mdst_trk and Mdst_vee2, respectively.
void shift_tof_set(const int expno, const int runno, const int mode, const int im, const double pmom, const double sgn, double &shift)
Return time shifts for different exp.
int set_primary_vertex(HepPoint3D &v, CLHEP::HepSymMatrix &ve)
Set primary vertex assuming all tracks are pions.
static double s_benergy_value
Beam energy.
void scale_momenta(float scale_data=1.0, float scale_mc=1.0, int mode=0)
Scale momenta of Mdst_trk.
bool good_event()
Check if event correspondes to the period when Belle detector not in good condition.
void scale_error(const int message_level=0)
Apply scale error.
void scale_momenta_set(const int, const int, const int, double &)
Return scale factors for 2001 summer confs.
int get_reprocess_version()
Get reprocess version of input mdst.
double vee_mass_nofit(const Belle::Mdst_vee2 &vee2, float scale=1.0)
Calculates V0 mass with non-constraint fit results.
static double pi0resol(double, double, const char *, bool, int, int)
Treat pi0 mass width as a func.
Abstract base class for different kinds of events.