CMS 3D CMS Logo

VertexTimeAlgorithmFromTracksPID.cc
Go to the documentation of this file.
7 #include "vdt/vdtMath.h"
8 
10 
11 #ifdef PVTX_DEBUG
12 #define LOG edm::LogPrint("VertexTimeAlgorithmFromTracksPID")
13 #else
14 #define LOG LogDebug("VertexTimeAlgorithmFromTracksPID")
15 #endif
16 
19  : VertexTimeAlgorithmBase(iConfig, iCC),
20  trackMTDTimeToken_(iCC.consumes(iConfig.getParameter<edm::InputTag>("trackMTDTimeVMapTag"))),
21  trackMTDTimeErrorToken_(iCC.consumes(iConfig.getParameter<edm::InputTag>("trackMTDTimeErrorVMapTag"))),
22  trackMTDTimeQualityToken_(iCC.consumes(iConfig.getParameter<edm::InputTag>("trackMTDTimeQualityVMapTag"))),
23  trackMTDTofPiToken_(iCC.consumes(iConfig.getParameter<edm::InputTag>("trackMTDTofPiVMapTag"))),
24  trackMTDTofKToken_(iCC.consumes(iConfig.getParameter<edm::InputTag>("trackMTDTofKVMapTag"))),
25  trackMTDTofPToken_(iCC.consumes(iConfig.getParameter<edm::InputTag>("trackMTDTofPVMapTag"))),
26  trackMTDSigmaTofPiToken_(iCC.consumes(iConfig.getParameter<edm::InputTag>("trackMTDSigmaTofPiVMapTag"))),
27  trackMTDSigmaTofKToken_(iCC.consumes(iConfig.getParameter<edm::InputTag>("trackMTDSigmaTofKVMapTag"))),
28  trackMTDSigmaTofPToken_(iCC.consumes(iConfig.getParameter<edm::InputTag>("trackMTDSigmaTofPVMapTag"))),
29  minTrackVtxWeight_(iConfig.getParameter<double>("minTrackVtxWeight")),
30  minTrackTimeQuality_(iConfig.getParameter<double>("minTrackTimeQuality")),
31  probPion_(iConfig.getParameter<double>("probPion")),
32  probKaon_(iConfig.getParameter<double>("probKaon")),
33  probProton_(iConfig.getParameter<double>("probProton")),
34  Tstart_(iConfig.getParameter<double>("Tstart")),
35  coolingFactor_(iConfig.getParameter<double>("coolingFactor")) {}
36 
39 
40  iDesc.add<edm::InputTag>("trackMTDTimeVMapTag", edm::InputTag("trackExtenderWithMTD:generalTracktmtd"))
41  ->setComment("Input ValueMap for track time at MTD");
42  iDesc.add<edm::InputTag>("trackMTDTimeErrorVMapTag", edm::InputTag("trackExtenderWithMTD:generalTracksigmatmtd"))
43  ->setComment("Input ValueMap for track time uncertainty at MTD");
44  iDesc.add<edm::InputTag>("trackMTDTimeQualityVMapTag", edm::InputTag("mtdTrackQualityMVA:mtdQualMVA"))
45  ->setComment("Input ValueMap for track MVA quality value");
46  iDesc.add<edm::InputTag>("trackMTDTofPiVMapTag", edm::InputTag("trackExtenderWithMTD:generalTrackTofPi"))
47  ->setComment("Input ValueMap for track tof as pion");
48  iDesc.add<edm::InputTag>("trackMTDTofKVMapTag", edm::InputTag("trackExtenderWithMTD:generalTrackTofK"))
49  ->setComment("Input ValueMap for track tof as kaon");
50  iDesc.add<edm::InputTag>("trackMTDTofPVMapTag", edm::InputTag("trackExtenderWithMTD:generalTrackTofP"))
51  ->setComment("Input ValueMap for track tof as proton");
52  iDesc.add<edm::InputTag>("trackMTDSigmaTofPiVMapTag", edm::InputTag("trackExtenderWithMTD:generalTrackSigmaTofPi"))
53  ->setComment("Input ValueMap for track tof uncertainty as pion");
54  iDesc.add<edm::InputTag>("trackMTDSigmaTofKVMapTag", edm::InputTag("trackExtenderWithMTD:generalTrackSigmaTofK"))
55  ->setComment("Input ValueMap for track tof uncertainty as kaon");
56  iDesc.add<edm::InputTag>("trackMTDSigmaTofPVMapTag", edm::InputTag("trackExtenderWithMTD:generalTrackSigmaTofP"))
57  ->setComment("Input ValueMap for track tof uncertainty as proton");
58 
59  iDesc.add<double>("minTrackVtxWeight", 0.5)->setComment("Minimum track weight");
60  iDesc.add<double>("minTrackTimeQuality", 0.8)->setComment("Minimum MVA Quality selection on tracks");
61 
62  iDesc.add<double>("probPion", 0.7)->setComment("A priori probability pions");
63  iDesc.add<double>("probKaon", 0.2)->setComment("A priori probability kaons");
64  iDesc.add<double>("probProton", 0.1)->setComment("A priori probability protons");
65 
66  iDesc.add<double>("Tstart", 256.)->setComment("DA initial temperature T");
67  iDesc.add<double>("coolingFactor", 0.5)->setComment("DA cooling factor");
68 }
69 
71  // additional collections required for vertex-time calculation
81 }
82 
84  float& vtxTimeError,
85  const TransientVertex& vtx) const {
86  if (vtx.originalTracks().empty()) {
87  return false;
88  }
89 
90  auto const vtxTime_init = vtxTime;
91  auto const vtxTimeError_init = vtxTimeError;
92  const int max_iterations = 100;
93 
94  double tsum = 0;
95  double wsum = 0;
96  double w2sum = 0;
97 
98  double const a[3] = {probPion_, probKaon_, probProton_};
99 
100  std::vector<TrackInfo> v_trackInfo;
101  v_trackInfo.reserve(vtx.originalTracks().size());
102 
103  // initial guess
104  for (const auto& trk : vtx.originalTracks()) {
105  auto const trkWeight = vtx.trackWeight(trk);
106  if (trkWeight > minTrackVtxWeight_) {
107  auto const trkTimeQuality = trackMTDTimeQualities_[trk.trackBaseRef()];
108 
109  if (trkTimeQuality >= minTrackTimeQuality_) {
110  auto const trkTime = trackMTDTimes_[trk.trackBaseRef()];
111  auto const trkTimeError = trackMTDTimeErrors_[trk.trackBaseRef()];
112 
113  v_trackInfo.emplace_back();
114  auto& trkInfo = v_trackInfo.back();
115 
116  trkInfo.trkWeight = trkWeight;
117  trkInfo.trkTimeErrorHyp[0] =
118  std::sqrt(trkTimeError * trkTimeError +
119  trackMTDSigmaTofPi_[trk.trackBaseRef()] * trackMTDSigmaTofPi_[trk.trackBaseRef()]);
120  trkInfo.trkTimeErrorHyp[1] =
121  std::sqrt(trkTimeError * trkTimeError +
122  trackMTDSigmaTofK_[trk.trackBaseRef()] * trackMTDSigmaTofK_[trk.trackBaseRef()]);
123  trkInfo.trkTimeErrorHyp[2] =
124  std::sqrt(trkTimeError * trkTimeError +
125  trackMTDSigmaTofP_[trk.trackBaseRef()] * trackMTDSigmaTofP_[trk.trackBaseRef()]);
126 
127  trkInfo.trkTimeHyp[0] = trkTime - trackMTDTofPi_[trk.trackBaseRef()];
128  trkInfo.trkTimeHyp[1] = trkTime - trackMTDTofK_[trk.trackBaseRef()];
129  trkInfo.trkTimeHyp[2] = trkTime - trackMTDTofP_[trk.trackBaseRef()];
130 
131  double const wgt[3] = {trkWeight / (trkInfo.trkTimeErrorHyp[0] * trkInfo.trkTimeErrorHyp[0]),
132  trkWeight / (trkInfo.trkTimeErrorHyp[1] * trkInfo.trkTimeErrorHyp[1]),
133  trkWeight / (trkInfo.trkTimeErrorHyp[2] * trkInfo.trkTimeErrorHyp[2])};
134 
135  for (uint j = 0; j < 3; ++j) {
136  wsum += wgt[j] * a[j];
137  tsum += wgt[j] * a[j] * trkInfo.trkTimeHyp[j];
138  }
139 
140  LOG << "vertexTimeFromTracks: track"
141  << " pt=" << trk.track().pt() << " eta=" << trk.track().eta() << " phi=" << trk.track().phi()
142  << " vtxWeight=" << trkWeight << " time=" << trkTime << " timeError=" << trkTimeError
143  << " timeQuality=" << trkTimeQuality << " timeHyp[pion]=" << trkInfo.trkTimeHyp[0] << " +/- "
144  << trkInfo.trkTimeErrorHyp[0] << " timeHyp[kaon]=" << trkInfo.trkTimeHyp[1] << " +/- "
145  << trkInfo.trkTimeErrorHyp[1] << " timeHyp[proton]=" << trkInfo.trkTimeHyp[2] << " +/- "
146  << trkInfo.trkTimeErrorHyp[2];
147  }
148  }
149  }
150  if (wsum > 0) {
151  auto t0 = tsum / wsum;
152  auto beta = 1. / Tstart_;
153  int nit = 0;
154  while ((nit++) < max_iterations) {
155  tsum = 0;
156  wsum = 0;
157  w2sum = 0;
158 
159  for (auto const& trkInfo : v_trackInfo) {
160  double dt[3] = {trkInfo.trkTimeErrorHyp[0], trkInfo.trkTimeErrorHyp[1], trkInfo.trkTimeErrorHyp[2]};
161  double e[3] = {0, 0, 0};
162  const double cut_off = 4.5;
163  double Z = vdt::fast_exp(
164  -beta * cut_off); // outlier rejection term Z_0 = exp(-beta * cut_off) = exp(-beta * 0.5 * 3 * 3)
165 
166  for (unsigned int j = 0; j < 3; j++) {
167  auto const tpull = (trkInfo.trkTimeHyp[j] - t0) / dt[j];
168  e[j] = vdt::fast_exp(-0.5 * beta * tpull * tpull);
169  Z += a[j] * e[j];
170  }
171 
172  double wsum_trk = 0, wsum_sigma_trk = 0;
173  for (uint j = 0; j < 3; j++) {
174  double wt = a[j] * e[j] / Z;
175  double w = wt * trkInfo.trkWeight / (dt[j] * dt[j]);
176  wsum_trk += w;
177  wsum_sigma_trk += w * dt[j];
178  tsum += w * trkInfo.trkTimeHyp[j];
179  }
180 
181  wsum += wsum_trk;
182  w2sum += wsum_sigma_trk * wsum_sigma_trk;
183  }
184 
185  if (wsum < 1e-10) {
186  LOG << "vertexTimeFromTracks: failed while iterating";
187  return false;
188  }
189 
190  vtxTime = tsum / wsum;
191 
192  LOG << "vertexTimeFromTracks: iteration=" << nit << ", T= " << 1 / beta << ", t=" << vtxTime
193  << ", t-t0=" << vtxTime - t0;
194 
195  if ((std::abs(vtxTime - t0) < 1e-4 / std::sqrt(beta)) and beta >= 1.) {
196  vtxTimeError = std::sqrt(w2sum) / wsum;
197 
198  LOG << "vertexTimeFromTracks: tfit = " << vtxTime << " +/- " << vtxTimeError << " trec = " << vtx.time()
199  << ", iteration=" << nit;
200 
201  return true;
202  }
203 
204  if ((std::abs(vtxTime - t0) < 1e-3) and beta < 1.) {
205  beta = std::min(1., beta / coolingFactor_);
206  }
207 
208  t0 = vtxTime;
209  }
210 
211  LOG << "vertexTimeFromTracks: failed to converge";
212  } else {
213  LOG << "vertexTimeFromTracks: has no track timing info";
214  }
215 
216  vtxTime = vtxTime_init;
217  vtxTimeError = vtxTimeError_init;
218 
219  return false;
220 }
edm::EDGetTokenT< edm::ValueMap< float > > const trackMTDTofKToken_
void setComment(std::string const &value)
float dt
Definition: AMPTWrapper.h:136
edm::EDGetTokenT< edm::ValueMap< float > > const trackMTDTofPToken_
T w() const
edm::EDGetTokenT< edm::ValueMap< float > > const trackMTDTimeQualityToken_
void setEvent(edm::Event &iEvent, edm::EventSetup const &iSetup) override
static void fillPSetDescription(edm::ParameterSetDescription &iDesc)
edm::EDGetTokenT< edm::ValueMap< float > > const trackMTDTimeToken_
int iEvent
Definition: GenABIO.cc:224
edm::EDGetTokenT< edm::ValueMap< float > > const trackMTDSigmaTofPiToken_
T sqrt(T t)
Definition: SSEVec.h:23
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ParameterDescriptionBase * add(U const &iLabel, T const &value)
static void fillPSetDescription(edm::ParameterSetDescription &iDesc)
edm::EDGetTokenT< edm::ValueMap< float > > const trackMTDTofPiToken_
edm::EDGetTokenT< edm::ValueMap< float > > const trackMTDSigmaTofKToken_
edm::EDGetTokenT< edm::ValueMap< float > > const trackMTDSigmaTofPToken_
HLT enums.
double a
Definition: hdecay.h:121
VertexTimeAlgorithmFromTracksPID(const edm::ParameterSet &conf, edm::ConsumesCollector &iC)
bool vertexTime(float &vtxTime, float &vtxTimeError, TransientVertex const &vtx) const override
edm::EDGetTokenT< edm::ValueMap< float > > const trackMTDTimeErrorToken_