CMS 3D CMS Logo

KVFTest.cc
Go to the documentation of this file.
2 
12 #include <iostream>
13 #include <memory>
14 
15 using namespace reco;
16 using namespace edm;
17 using namespace std;
18 
20  : estoken_MF(esConsumes()),
21  estoken_TTB(esConsumes(edm::ESInputTag("", "TransientTrackBuilder"))),
22  theConfig(iConfig) {
23  token_tracks = consumes<TrackCollection>(iConfig.getParameter<string>("TrackLabel"));
24  outputFile_ = iConfig.getUntrackedParameter<std::string>("outputFile");
25  kvfPSet = iConfig.getParameter<edm::ParameterSet>("KVFParameters");
26  rootFile_ = TFile::Open(outputFile_.c_str(), "RECREATE");
27  edm::LogInfo("RecoVertex/KVFTest") << "Initializing KVF TEST analyser - Output file: " << outputFile_ << "\n";
28 
29  token_TrackTruth = consumes<TrackingParticleCollection>(edm::InputTag("trackingtruth", "TrackTruth"));
30  token_VertexTruth = consumes<TrackingVertexCollection>(edm::InputTag("trackingtruth", "VertexTruth"));
32  consumes<reco::TrackToTrackingParticleAssociator>(edm::InputTag("trackAssociatorByChi2"));
33 }
34 
36 
38 
39 void KVFTest::endJob() {}
40 
41 //
42 // member functions
43 //
44 
45 void KVFTest::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
47  iEvent.getByToken(token_associatorForParamAtPca, associatorForParamAtPca);
48 
49  if (not tree) {
50  tree = std::make_unique<SimpleVertexTree>("VertexFitter", &iSetup.getData(estoken_MF));
51  }
52 
53  edm::LogInfo("RecoVertex/KVFTest") << "Reconstructing event number: " << iEvent.id() << "\n";
54 
55  // get RECO tracks from the event
56  // `tks` can be used as a ptr to a reco::TrackCollection
58  iEvent.getByToken(token_tracks, tks);
59  if (!tks.isValid()) {
60  edm::LogInfo("RecoVertex/KVFTest") << "Exception during event number: " << iEvent.id() << "\n";
61  } else {
62  edm::LogInfo("RecoVertex/KVFTest") << "Found: " << (*tks).size() << " reconstructed tracks"
63  << "\n";
64  edm::LogPrint("RecoVertex/KVFTest") << "got " << (*tks).size() << " tracks " << std::endl;
65 
66  // Transform Track to TransientTrack
67 
68  //get the builder:
69  const auto& theB = &iSetup.getData(estoken_TTB);
70  //do the conversion:
71  std::vector<TransientTrack> t_tks = theB->build(tks);
72 
73  edm::LogInfo("RecoVertex/KVFTest") << "Found: " << t_tks.size() << " reconstructed tracks"
74  << "\n";
75 
76  // Call the KalmanVertexFitter if more than 1 track
77  if (t_tks.size() > 1) {
78  // KalmanVertexFitter kvf(kvfPSet);
79  KalmanVertexFitter kvf(true);
80  TransientVertex tv = kvf.vertex(t_tks);
81 
82  edm::LogPrint("RecoVertex/KVFTest") << "Position: " << Vertex::Point(tv.position()) << "\n";
83 
84  // For the analysis: compare to your SimVertex
87  iEvent.getByToken(token_TrackTruth, TPCollectionH);
88  if (!TPCollectionH.isValid()) {
89  edm::LogInfo("RecoVertex/KVFTest") << "Exception during event number: " << iEvent.id() << "\n";
90  } else {
91  const TrackingParticleCollection tPC = *(TPCollectionH.product());
92  reco::RecoToSimCollection recSimColl = associatorForParamAtPca->associateRecoToSim(tks, TPCollectionH);
93  tree->fill(tv, &sv, &recSimColl);
94  }
95  }
96  }
97 }
98 
99 //Returns the first vertex in the list.
100 
102  // get the simulated vertices
104  iEvent.getByToken(token_VertexTruth, TVCollectionH);
105  const TrackingVertexCollection tPC = *(TVCollectionH.product());
106 
107  // Handle<edm::SimVertexContainer> simVtcs;
108  // iEvent.getByLabel("g4SimHits", simVtcs);
109  // std::cout << "SimVertex " << simVtcs->size() << std::endl;
110  // for(edm::SimVertexContainer::const_iterator v=simVtcs->begin();
111  // v!=simVtcs->end(); ++v){
112  // std::cout << "simvtx "
113  // << v->position().x() << " "
114  // << v->position().y() << " "
115  // << v->position().z() << " "
116  // << v->parentIndex() << " "
117  // << v->noParent() << " "
118  // << std::endl;
119  // }
120  return *(tPC.begin());
121 }
KalmanVertexFitter::vertex
CachingVertex< 5 > vertex(const std::vector< reco::TransientTrack > &tracks) const override
Definition: KalmanVertexFitter.h:49
Handle.h
edm::ESInputTag
Definition: ESInputTag.h:87
KVFTest::KVFTest
KVFTest(const edm::ParameterSet &)
Definition: KVFTest.cc:19
MessageLogger.h
KVFTest::rootFile_
TFile * rootFile_
Definition: KVFTest.h:57
edm::Handle::product
T const * product() const
Definition: Handle.h:70
KalmanVertexFitter.h
edm
HLT enums.
Definition: AlignableModifier.h:19
tree
Definition: tree.py:1
reco::TrackToTrackingParticleAssociator::associateRecoToSim
reco::RecoToSimCollection associateRecoToSim(const edm::Handle< edm::View< reco::Track >> &tCH, const edm::Handle< TrackingParticleCollection > &tPCH) const
Definition: TrackToTrackingParticleAssociator.h:64
edm::LogPrint
Log< level::Warning, true > LogPrint
Definition: MessageLogger.h:130
TransientVertex::position
GlobalPoint position() const
Definition: TransientVertex.h:169
TrackingVertexCollection
std::vector< TrackingVertex > TrackingVertexCollection
Definition: TrackingVertexContainer.h:8
KVFTest::~KVFTest
~KVFTest() override
Definition: KVFTest.cc:35
KVFTest::estoken_MF
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > estoken_MF
Definition: KVFTest.h:51
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:46
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
TransientTrack.h
edm::Handle< reco::TrackToTrackingParticleAssociator >
KVFTest::estoken_TTB
const edm::ESGetToken< TransientTrackBuilder, TransientTrackRecord > estoken_TTB
Definition: KVFTest.h:52
KVFTest::token_associatorForParamAtPca
edm::EDGetTokenT< reco::TrackToTrackingParticleAssociator > token_associatorForParamAtPca
Definition: KVFTest.h:63
MakerMacros.h
Point
math::XYZPoint Point
Definition: TrackerDpgAnalysis.cc:106
Track.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
KVFTest::token_tracks
edm::EDGetTokenT< reco::TrackCollection > token_tracks
Definition: KVFTest.h:60
pfDeepBoostedJetPreprocessParams_cfi.sv
sv
Definition: pfDeepBoostedJetPreprocessParams_cfi.py:352
KVFTest.h
KVFTest::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: KVFTest.cc:45
KVFTest::beginJob
void beginJob() override
Definition: KVFTest.cc:37
edm::ParameterSet
Definition: ParameterSet.h:47
KVFTest::endJob
void endJob() override
Definition: KVFTest.cc:39
edm::AssociationMap< edm::OneToManyWithQualityGeneric< edm::View< reco::Track >, TrackingParticleCollection, double > >
TrackingVertex
Definition: TrackingVertex.h:22
KVFTest
Definition: KVFTest.h:38
iEvent
int iEvent
Definition: GenABIO.cc:224
KVFTest::kvfPSet
edm::ParameterSet kvfPSet
Definition: KVFTest.h:55
TransientVertex
Definition: TransientVertex.h:18
edm::EventSetup
Definition: EventSetup.h:58
KVFTest::token_TrackTruth
edm::EDGetTokenT< TrackingParticleCollection > token_TrackTruth
Definition: KVFTest.h:61
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::EventSetup::getData
bool getData(T &iHolder) const
Definition: EventSetup.h:127
VertexFwd.h
TransientVertex.h
std
Definition: JetResolutionObject.h:76
Vertex.h
KVFTest::getSimVertex
TrackingVertex getSimVertex(const edm::Event &iEvent) const
Definition: KVFTest.cc:101
TrackingParticleCollection
std::vector< TrackingParticle > TrackingParticleCollection
Definition: TrackingParticleFwd.h:9
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
KVFTest::token_VertexTruth
edm::EDGetTokenT< TrackingVertexCollection > token_VertexTruth
Definition: KVFTest.h:62
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
DeDxTools::esConsumes
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
edm::Event
Definition: Event.h:73
KVFTest::outputFile_
std::string outputFile_
Definition: KVFTest.h:59
edm::InputTag
Definition: InputTag.h:15
KalmanVertexFitter
Definition: KalmanVertexFitter.h:22