Belle II Software  release-05-01-25
B2BIIFixMdstModule_tof.cc
1 //
2 // $Id: B2BIIFixMdst_tof.cc 10002 2007-02-26 06:56:17Z katayama $
3 //
4 // $Log$
5 //
6 // Revision 2.0 2015/03/11 tkeck
7 // Conversion to Belle II
8 //
9 // Revision 1.6 2002/06/22 01:14:24 katayama
10 // For exp. 9. (same as exp. 11 and 13)
11 //
12 // Revision 1.5 2002/06/20 23:41:50 katayama
13 // New tof for exp. 7
14 //
15 // Revision 1.4 2002/06/10 12:28:53 katayama
16 // Better exp. 15 from Mike san. Also work for exp. 11
17 //
18 // Revision 1.3 2002/05/28 23:46:08 katayama
19 // New correction for reprocessed exp. 13 from Peters/Jones san
20 //
21 // Revision 1.2 2002/05/04 23:54:35 hitoshi
22 // Updated correctios for exp15. Also added corrections for exp17.
23 //
24 // Revision 1.1 2002/04/26 01:25:07 katayama
25 // New correction from Perers san
26 //
27 //
28 //
29 
30 #include <b2bii/modules/B2BIIMdstInput/B2BIIFixMdstModule.h>
31 #include "belle_legacy/panther/panther.h"
32 
33 #include <cmath>
34 #include <cfloat>
35 
36 #include "TMath.h"
37 #include "TVector3.h"
38 
39 #include "CLHEP/Vector/ThreeVector.h"
40 
41 #include "belle_legacy/tables/mdst.h"
42 #include "belle_legacy/tables/belletdf.h"
43 
44 namespace Belle2 {
51 //===============================================================
52  void B2BIIFixMdstModule::shift_tof(const int mode)
53  {
54 //===============================================================
55 // Shifts tof times to account for residuals.
56 // Based on scale_momenta code
57 //======================================================
58 //Check existence of belle_event
59 
60  Belle::Belle_event_Manager& evtmgr = Belle::Belle_event_Manager::get_manager();
61  if (evtmgr.count() == 0) return; //do nothing if no Belle::Belle_Event
62 
63  Belle::Mdst_event_add_Manager& addmgr = Belle::Mdst_event_add_Manager::get_manager();
64  if (addmgr.count() == 0) return; //do nothing if no Belle::Mdst_Event_Add
65  if (addmgr[0].flag(4) != 0) return; //do nothing if already shifted
66 
67 //check mode
68  if (mode < 0 || mode > 2) {
69  B2ERROR("shift_tof: invalid mode specified;");
70  B2ERROR("mode must be 0, 1, 2");
71  return;
72  }
73 
74  int expmc = evtmgr[0].ExpMC();
75  int expno = evtmgr[0].ExpNo();
76  int runno = evtmgr[0].RunNo();
77 
78  if (expmc == 2) return; //for now, apply no shift to MC
79 
80  addmgr[0].flag(4, 1); //set flag
81 
82  // Loop over all charged tracks
83 
84  Belle::Mdst_charged_Manager& ChgMgr = Belle::Mdst_charged_Manager::get_manager();
85  for (std::vector<Belle::Mdst_charged>::iterator it = ChgMgr.begin();
86  it != ChgMgr.end(); ++it) {
87  Belle::Mdst_charged& Chg = *it;
88  if (Chg) {
89  // Get mdst_tof table for the track
90  Belle::Mdst_tof& Tof = Chg.tof();
91  if (Tof) {
92  // Get momentum and charge of track
93  TVector3 Mom(Chg.px(), Chg.py(), Chg.pz());
94  double pmom = Mom.Mag();
95  double sgn = Chg.charge();
96  // Loop over mass hypotheses
97  for (int im = 0; im < 5; im++) {
98  double shift = 0.;
99  shift_tof_set(expno, runno, mode, im, pmom, sgn, shift);
100  if (fabs(shift) < .005) continue;
101  double ot = Tof.tof_exp(im); //old t (expected)
102  double odt = ot - Tof.tof(); //old dt
103  double opid = Tof.pid(im); //old pid
104 // double ocl=Tof.cl(im); //old cl
105  int ndf = (int)(Tof.ndf(im) + .001); //ndf
106  if (opid > 0. && opid < 1.) {
107  double ct = ot + shift; //corr t
108  double cdt = ct - Tof.tof(); //corr dt
109  double err = fabs(odt) / sqrt(-2.*log(opid)); //est error
110  double cch = pow(cdt / err, 2); //corr chisq
111  double cpid = exp(-.5 * cch); //corr pid
112  double ccl = TMath::Prob(cch, ndf); //corr cl
113  Tof.tof_exp(im, ct);
114  Tof.pid(im, cpid);
115  Tof.cl(im, ccl);
116  }
117  }
118  }
119  }
120  }
121  }
122  void B2BIIFixMdstModule::shift_tof_set(const int expno, const int runno,
123  const int mode, const int im,
124  const double pmom, const double sgn,
125  double& shift)
126  {
127  static const double m[5] = {.000511, .10566, .13957, .49368, .93827};
128  shift = 0.;
129  double beta = pmom / sqrt(pmom * pmom + m[im] * m[im]);
130  switch (expno) {
131  case 7:
132  if (mode == 1) {
133  switch (im) {
134  case 2:
135  if (runno < 536) shift = 0.;
136  else if (runno < 1440) shift = .5054 - .5216 * std::min(beta, .955);
137  else shift = .8321 - .8648 * std::min(beta, .96);
138  break;
139  case 3:
140  if (runno < 536) shift = -.0414 * exp(-pow(beta - .538, 2) / .0569);
141  else if (runno < 1440) shift = -12.3 * exp(-pow(beta + .288, 2) / .1197);
142  else shift = 0.;
143  break;
144  case 4:
145  if (sgn > 0.) {
146  shift = -.876 * exp(-pow(beta + .1818, 2) / .1947);
147  } else {
148  if (runno < 1440)
149  shift = .01 - .1028 * exp(-pow(beta - .4454, 2) / .00272);
150  else shift = .01 - .064 * exp(-pow(beta - .4273, 2) / .00317);
151  }
152  break;
153  default:
154  break;
155  } // end switch(im)
156  } // end if(mode)
157  break;
158  case 9:
159  case 11:
160  case 13:
161  if (mode == 1) {
162  switch (im) {
163  case 2:
164  shift = 1.089 - 1.131 * std::min(beta, .955);
165  break;
166  case 4:
167  if (sgn > 0.) shift = -.876 * exp(-pow(beta + .1818, 2) / .1947);
168  else shift = .01 - .1028 * exp(-pow(beta - .4454, 2) / .00272);
169  break;
170  default:
171  break;
172  } // end switch(im)
173  } // end if(mode)
174  break;
175  case 15:
176  if (mode == 1) {
177  switch (im) {
178  case 2:
179 // if(sgn>0.) shift=-4.73+9.853*beta-5.139*beta*beta;
180 // The following stmt replaced the one above on 6/7/02 to remove the
181 // -16 ps value at beta=1. MWP
182  if (sgn > 0.) shift = -.0183 * exp(-pow(beta - .911, 2) / .00161);
183  break;
184  case 3:
185  shift = -6.6 * exp(-beta / .1);
186  break;
187  case 4:
188  if (sgn > 0.) shift = -.736 * exp(-pow(beta + .04158, 2) / .119);
189  else shift = .02 - .1475 * exp(-pow(beta - .4267, 2) / .00249);
190  break;
191  default:
192  break;
193  } // end switch(im)
194  } // end if(mode)
195  break;
196  case 17:
197  case 19: //same corrections for Exps 17 and 19
198  if (mode == 1) {
199  switch (im) {
200  case 4:
201  if (sgn > 0.) shift = -.3259 * exp(-pow(beta - .1042, 2) / .0817);
202  else shift = .02 - .1475 * exp(-pow(beta - .4267, 2) / .00249);
203  break;
204  default:
205  break;
206  } // end switch(im)
207  } // end if(mode)
208  default:
209  break;
210  } // end switch(expno)
211  }
213 } // namespace Belle
Belle2::B2BIIFixMdstModule::shift_tof
void shift_tof(const int mode)
Shift tof times to account for residuals.
Definition: B2BIIFixMdstModule_tof.cc:52
Belle2::B2BIIFixMdstModule::shift_tof_set
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.
Definition: B2BIIFixMdstModule_tof.cc:122
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19