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  minTrackVtxWeight_(iConfig.getParameter<double>("minTrackVtxWeight")),
27  minTrackTimeQuality_(iConfig.getParameter<double>("minTrackTimeQuality")),
28  probPion_(iConfig.getParameter<double>("probPion")),
29  probKaon_(iConfig.getParameter<double>("probKaon")),
30  probProton_(iConfig.getParameter<double>("probProton")),
31  Tstart_(iConfig.getParameter<double>("Tstart")),
32  coolingFactor_(iConfig.getParameter<double>("coolingFactor")) {}
33 
36 
37  iDesc.add<edm::InputTag>("trackMTDTimeVMapTag", edm::InputTag("trackExtenderWithMTD:generalTracktmtd"))
38  ->setComment("Input ValueMap for track time at MTD");
39  iDesc.add<edm::InputTag>("trackMTDTimeErrorVMapTag", edm::InputTag("trackExtenderWithMTD:generalTracksigmatmtd"))
40  ->setComment("Input ValueMap for track time uncertainty at MTD");
41  iDesc.add<edm::InputTag>("trackMTDTimeQualityVMapTag", edm::InputTag("mtdTrackQualityMVA:mtdQualMVA"))
42  ->setComment("Input ValueMap for track MVA quality value");
43  iDesc.add<edm::InputTag>("trackMTDTofPiVMapTag", edm::InputTag("trackExtenderWithMTD:generalTrackTofPi"))
44  ->setComment("Input ValueMap for track tof as pion");
45  iDesc.add<edm::InputTag>("trackMTDTofKVMapTag", edm::InputTag("trackExtenderWithMTD:generalTrackTofK"))
46  ->setComment("Input ValueMap for track tof as kaon");
47  iDesc.add<edm::InputTag>("trackMTDTofPVMapTag", edm::InputTag("trackExtenderWithMTD:generalTrackTofP"))
48  ->setComment("Input ValueMap for track tof as proton");
49 
50  iDesc.add<double>("minTrackVtxWeight", 0.5)->setComment("Minimum track weight");
51  iDesc.add<double>("minTrackTimeQuality", 0.8)->setComment("Minimum MVA Quality selection on tracks");
52 
53  iDesc.add<double>("probPion", 0.7)->setComment("A priori probability pions");
54  iDesc.add<double>("probKaon", 0.2)->setComment("A priori probability kaons");
55  iDesc.add<double>("probProton", 0.1)->setComment("A priori probability protons");
56 
57  iDesc.add<double>("Tstart", 256.)->setComment("DA initial temperature T");
58  iDesc.add<double>("coolingFactor", 0.5)->setComment("DA cooling factor");
59 }
60 
62  // additional collections required for vertex-time calculation
69 }
70 
72  float& vtxTimeError,
73  const TransientVertex& vtx) const {
74  if (vtx.originalTracks().empty()) {
75  return false;
76  }
77 
78  auto const vtxTime_init = vtxTime;
79  auto const vtxTimeError_init = vtxTimeError;
80  const int max_iterations = 100;
81 
82  double tsum = 0;
83  double wsum = 0;
84  double w2sum = 0;
85 
86  double const a[3] = {probPion_, probKaon_, probProton_};
87 
88  std::vector<TrackInfo> v_trackInfo;
89  v_trackInfo.reserve(vtx.originalTracks().size());
90 
91  // initial guess
92  for (const auto& trk : vtx.originalTracks()) {
93  auto const trkWeight = vtx.trackWeight(trk);
94  if (trkWeight > minTrackVtxWeight_) {
95  auto const trkTimeQuality = trackMTDTimeQualities_[trk.trackBaseRef()];
96 
97  if (trkTimeQuality >= minTrackTimeQuality_) {
98  auto const trkTime = trackMTDTimes_[trk.trackBaseRef()];
99  auto const trkTimeError = trackMTDTimeErrors_[trk.trackBaseRef()];
100 
101  v_trackInfo.emplace_back();
102  auto& trkInfo = v_trackInfo.back();
103 
104  trkInfo.trkWeight = trkWeight;
105  trkInfo.trkTimeError = trkTimeError;
106 
107  trkInfo.trkTimeHyp[0] = trkTime - trackMTDTofPi_[trk.trackBaseRef()];
108  trkInfo.trkTimeHyp[1] = trkTime - trackMTDTofK_[trk.trackBaseRef()];
109  trkInfo.trkTimeHyp[2] = trkTime - trackMTDTofP_[trk.trackBaseRef()];
110 
111  auto const wgt = trkWeight / (trkTimeError * trkTimeError);
112  wsum += wgt;
113 
114  for (uint j = 0; j < 3; ++j) {
115  tsum += wgt * trkInfo.trkTimeHyp[j] * a[j];
116  }
117  LOG << "vertexTimeFromTracks: track"
118  << " pt=" << trk.track().pt() << " eta=" << trk.track().eta() << " phi=" << trk.track().phi()
119  << " vtxWeight=" << trkWeight << " time=" << trkTime << " timeError=" << trkTimeError
120  << " timeQuality=" << trkTimeQuality << " timeHyp[pion]=" << trkInfo.trkTimeHyp[0]
121  << " timeHyp[kaon]=" << trkInfo.trkTimeHyp[1] << " timeHyp[proton]=" << trkInfo.trkTimeHyp[2];
122  }
123  }
124  }
125  if (wsum > 0) {
126  auto t0 = tsum / wsum;
127  auto beta = 1. / Tstart_;
128  int nit = 0;
129  while ((nit++) < max_iterations) {
130  tsum = 0;
131  wsum = 0;
132  w2sum = 0;
133 
134  for (auto const& trkInfo : v_trackInfo) {
135  double dt = trkInfo.trkTimeError;
136  double e[3] = {0, 0, 0};
137  const double cut_off = 4.5;
138  double Z = vdt::fast_exp(
139  -beta * cut_off); // outlier rejection term Z_0 = exp(-beta * cut_off) = exp(-beta * 0.5 * 3 * 3)
140  for (unsigned int j = 0; j < 3; j++) {
141  auto const tpull = (trkInfo.trkTimeHyp[j] - t0) / dt;
142  e[j] = vdt::fast_exp(-0.5 * beta * tpull * tpull);
143  Z += a[j] * e[j];
144  }
145 
146  double wsum_trk = 0;
147  for (uint j = 0; j < 3; j++) {
148  double wt = a[j] * e[j] / Z;
149  double w = wt * trkInfo.trkWeight / (dt * dt);
150  wsum_trk += w;
151  tsum += w * trkInfo.trkTimeHyp[j];
152  }
153 
154  wsum += wsum_trk;
155  w2sum += wsum_trk * wsum_trk * (dt * dt) / trkInfo.trkWeight;
156  }
157 
158  if (wsum < 1e-10) {
159  LOG << "vertexTimeFromTracks: failed while iterating";
160  return false;
161  }
162 
163  vtxTime = tsum / wsum;
164 
165  LOG << "vertexTimeFromTracks: iteration=" << nit << ", T= " << 1 / beta << ", t=" << vtxTime
166  << ", t-t0=" << vtxTime - t0;
167 
168  if ((std::abs(vtxTime - t0) < 1e-4 / std::sqrt(beta)) and beta >= 1.) {
169  vtxTimeError = std::sqrt(w2sum) / wsum;
170 
171  LOG << "vertexTimeFromTracks: tfit = " << vtxTime << " +/- " << vtxTimeError << " trec = " << vtx.time()
172  << ", iteration=" << nit;
173 
174  return true;
175  }
176 
177  if ((std::abs(vtxTime - t0) < 1e-3) and beta < 1.) {
178  beta = std::min(1., beta / coolingFactor_);
179  }
180 
181  t0 = vtxTime;
182  }
183 
184  LOG << "vertexTimeFromTracks: failed to converge";
185  } else {
186  LOG << "vertexTimeFromTracks: has no track timing info";
187  }
188 
189  vtxTime = vtxTime_init;
190  vtxTimeError = vtxTimeError_init;
191 
192  return false;
193 }
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
T sqrt(T t)
Definition: SSEVec.h:19
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_
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_