Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-07 04:38:06

0001 #include "FWCore/Framework/interface/ConsumesCollector.h"
0002 #include "FWCore/Framework/interface/Event.h"
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0005 #include "RecoVertex/PrimaryVertexProducer/interface/VertexTimeAlgorithmLegacy4D.h"
0006 
0007 #ifdef PVTX_DEBUG
0008 #define LOG edm::LogPrint("VertexTimeAlgorithmLegacy4D")
0009 #else
0010 #define LOG LogDebug("VertexTimeAlgorithmLegacy4D")
0011 #endif
0012 
0013 VertexTimeAlgorithmLegacy4D::VertexTimeAlgorithmLegacy4D(edm::ParameterSet const& iConfig, edm::ConsumesCollector& iCC)
0014     : VertexTimeAlgorithmBase(iConfig, iCC) {}
0015 
0016 void VertexTimeAlgorithmLegacy4D::fillPSetDescription(edm::ParameterSetDescription& iDesc) {
0017   VertexTimeAlgorithmBase::fillPSetDescription(iDesc);
0018 }
0019 
0020 void VertexTimeAlgorithmLegacy4D::setEvent(edm::Event& iEvent, edm::EventSetup const&) {}
0021 
0022 bool VertexTimeAlgorithmLegacy4D::vertexTime(float& vtxTime, float& vtxTimeError, const TransientVertex& vtx) const {
0023   const auto num_track = vtx.originalTracks().size();
0024   if (num_track == 0) {
0025     return false;
0026   }
0027 
0028   double sumwt = 0.;
0029   double sumw = 0.;
0030 
0031   for (const auto& trk : vtx.originalTracks()) {
0032     const double time = trk.timeExt();
0033     const double err = trk.dtErrorExt();
0034     if ((time == 0) && (err >= TransientTrackBuilder::defaultInvalidTrackTimeReso))
0035       continue;  // tracks with no time information, as implemented in TransientTrackBuilder.cc l.17
0036     const double inverr = err > 0. ? 1.0 / err : 0.;
0037     const double w = inverr * inverr;
0038     sumwt += w * time;
0039     sumw += w;
0040   }
0041 
0042   if (sumw > 0) {
0043     vtxTime = sumwt / sumw;
0044     vtxTimeError = 1 / sqrt(sumw);
0045     return true;
0046   }
0047 
0048   vtxTime = 0;
0049   vtxTimeError = 1.;
0050   return false;
0051 }