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