7 #include "vdt/vdtMath.h" 12 #define LOG edm::LogPrint("VertexTimeAlgorithmFromTracksPID") 14 #define LOG LogDebug("VertexTimeAlgorithmFromTracksPID") 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")) {}
41 ->setComment(
"Input ValueMap for track time at MTD");
43 ->setComment(
"Input ValueMap for track time uncertainty at MTD");
45 ->setComment(
"Input ValueMap for track MVA quality value");
47 ->setComment(
"Input ValueMap for track tof as pion");
49 ->setComment(
"Input ValueMap for track tof as kaon");
51 ->setComment(
"Input ValueMap for track tof as proton");
53 ->setComment(
"Input ValueMap for track tof uncertainty as pion");
55 ->setComment(
"Input ValueMap for track tof uncertainty as kaon");
57 ->setComment(
"Input ValueMap for track tof uncertainty as proton");
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");
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");
66 iDesc.
add<
double>(
"Tstart", 256.)->
setComment(
"DA initial temperature T");
67 iDesc.
add<
double>(
"coolingFactor", 0.5)->
setComment(
"DA cooling factor");
86 if (
vtx.originalTracks().empty()) {
90 auto const vtxTime_init = vtxTime;
91 auto const vtxTimeError_init = vtxTimeError;
92 const int max_iterations = 100;
100 std::vector<TrackInfo> v_trackInfo;
101 v_trackInfo.reserve(
vtx.originalTracks().size());
104 for (
const auto& trk :
vtx.originalTracks()) {
105 auto const trkWeight =
vtx.trackWeight(trk);
113 v_trackInfo.emplace_back();
114 auto& trkInfo = v_trackInfo.back();
116 trkInfo.trkWeight = trkWeight;
117 trkInfo.trkTimeErrorHyp[0] =
120 trkInfo.trkTimeErrorHyp[1] =
123 trkInfo.trkTimeErrorHyp[2] =
127 trkInfo.trkTimeHyp[0] = trkTime -
trackMTDTofPi_[trk.trackBaseRef()];
128 trkInfo.trkTimeHyp[1] = trkTime -
trackMTDTofK_[trk.trackBaseRef()];
129 trkInfo.trkTimeHyp[2] = trkTime -
trackMTDTofP_[trk.trackBaseRef()];
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])};
136 wsum += wgt[
j] *
a[
j];
137 tsum += wgt[
j] *
a[
j] * trkInfo.trkTimeHyp[
j];
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];
151 auto t0 = tsum / wsum;
154 while ((nit++) < max_iterations) {
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(
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);
172 double wsum_trk = 0, wsum_sigma_trk = 0;
174 double wt =
a[
j] *
e[
j] /
Z;
175 double w = wt * trkInfo.trkWeight / (
dt[
j] *
dt[
j]);
177 wsum_sigma_trk +=
w *
dt[
j];
178 tsum +=
w * trkInfo.trkTimeHyp[
j];
182 w2sum += wsum_sigma_trk * wsum_sigma_trk;
186 LOG <<
"vertexTimeFromTracks: failed while iterating";
190 vtxTime = tsum / wsum;
192 LOG <<
"vertexTimeFromTracks: iteration=" << nit <<
", T= " << 1 /
beta <<
", t=" << vtxTime
193 <<
", t-t0=" << vtxTime -
t0;
198 LOG <<
"vertexTimeFromTracks: tfit = " << vtxTime <<
" +/- " << vtxTimeError <<
" trec = " <<
vtx.time()
199 <<
", iteration=" << nit;
211 LOG <<
"vertexTimeFromTracks: failed to converge";
213 LOG <<
"vertexTimeFromTracks: has no track timing info";
216 vtxTime = vtxTime_init;
217 vtxTimeError = vtxTimeError_init;
edm::EDGetTokenT< edm::ValueMap< float > > const trackMTDTofKToken_
edm::ValueMap< float > trackMTDTimes_
void setComment(std::string const &value)
edm::EDGetTokenT< edm::ValueMap< float > > const trackMTDTofPToken_
edm::EDGetTokenT< edm::ValueMap< float > > const trackMTDTimeQualityToken_
void setEvent(edm::Event &iEvent, edm::EventSetup const &iSetup) override
double const minTrackTimeQuality_
static void fillPSetDescription(edm::ParameterSetDescription &iDesc)
edm::EDGetTokenT< edm::ValueMap< float > > const trackMTDTimeToken_
edm::ValueMap< float > trackMTDSigmaTofPi_
edm::ValueMap< float > trackMTDTofPi_
edm::EDGetTokenT< edm::ValueMap< float > > const trackMTDSigmaTofPiToken_
edm::ValueMap< float > trackMTDTimeErrors_
Abs< T >::type abs(const T &t)
edm::ValueMap< float > trackMTDTofP_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
static void fillPSetDescription(edm::ParameterSetDescription &iDesc)
edm::EDGetTokenT< edm::ValueMap< float > > const trackMTDTofPiToken_
edm::ValueMap< float > trackMTDTimeQualities_
double const coolingFactor_
edm::EDGetTokenT< edm::ValueMap< float > > const trackMTDSigmaTofKToken_
double const minTrackVtxWeight_
edm::EDGetTokenT< edm::ValueMap< float > > const trackMTDSigmaTofPToken_
edm::ValueMap< float > trackMTDTofK_
edm::ValueMap< float > trackMTDSigmaTofK_
VertexTimeAlgorithmFromTracksPID(const edm::ParameterSet &conf, edm::ConsumesCollector &iC)
bool vertexTime(float &vtxTime, float &vtxTimeError, TransientVertex const &vtx) const override
edm::ValueMap< float > trackMTDSigmaTofP_
edm::EDGetTokenT< edm::ValueMap< float > > const trackMTDTimeErrorToken_