CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
KVFTest.cc
Go to the documentation of this file.
2 
10 
18 
19 #include <iostream>
20 
21 using namespace reco;
22 using namespace edm;
23 using namespace std;
24 
26  : theConfig(iConfig)
27 {
28  token_tracks = consumes<TrackCollection>(iConfig.getParameter<string>("TrackLabel"));
29  outputFile_ = iConfig.getUntrackedParameter<std::string>("outputFile");
30  kvfPSet = iConfig.getParameter<edm::ParameterSet>("KVFParameters");
31  rootFile_ = TFile::Open(outputFile_.c_str(),"RECREATE");
32  edm::LogInfo("RecoVertex/KVFTest")
33  << "Initializing KVF TEST analyser - Output file: " << outputFile_ <<"\n";
34 
35  token_TrackTruth = consumes<TrackingParticleCollection>(edm::InputTag("trackingtruth", "TrackTruth"));
36  token_VertexTruth = consumes<TrackingVertexCollection>(edm::InputTag("trackingtruth", "VertexTruth"));
37  token_associatorForParamAtPca = consumes<reco::TrackToTrackingParticleAssociator>(edm::InputTag("trackAssociatorByChi2"));
38 
39 }
40 
41 
43  delete rootFile_;
44 }
45 
47 }
48 
49 
51 }
52 
53 //
54 // member functions
55 //
56 
57 void
59 {
61  iEvent.getByToken(token_associatorForParamAtPca,associatorForParamAtPca);
62 
63  if(not tree) {
65  iSetup.get<IdealMagneticFieldRecord>().get(magField);
66  tree.reset( new SimpleVertexTree("VertexFitter", magField.product()) );
67  }
68 
69 
70 
71  edm::LogInfo("RecoVertex/KVFTest")
72  << "Reconstructing event number: " << iEvent.id() << "\n";
73 
74  // get RECO tracks from the event
75  // `tks` can be used as a ptr to a reco::TrackCollection
77  iEvent.getByToken(token_tracks, tks);
78  if (!tks.isValid()) {
79  edm::LogInfo("RecoVertex/KVFTest")
80  << "Exception during event number: " << iEvent.id()
81  << "\n";
82  } else {
83  edm::LogInfo("RecoVertex/KVFTest")
84  << "Found: " << (*tks).size() << " reconstructed tracks" << "\n";
85  std::cout << "got " << (*tks).size() << " tracks " << std::endl;
86 
87  // Transform Track to TransientTrack
88 
89  //get the builder:
91  iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder",theB);
92  //do the conversion:
93  std::vector<TransientTrack> t_tks = (*theB).build(tks);
94 
95  edm::LogInfo("RecoVertex/KVFTest")
96  << "Found: " << t_tks.size() << " reconstructed tracks" << "\n";
97 
98  // Call the KalmanVertexFitter if more than 1 track
99  if (t_tks.size() > 1) {
100  // KalmanVertexFitter kvf(kvfPSet);
101  KalmanVertexFitter kvf(true);
102  TransientVertex tv = kvf.vertex(t_tks);
103 
104  std::cout << "Position: " << Vertex::Point(tv.position()) << "\n";
105 
106  // For the analysis: compare to your SimVertex
107  TrackingVertex sv = getSimVertex(iEvent);
109  iEvent.getByToken(token_TrackTruth, TPCollectionH);
110  if (!TPCollectionH.isValid()) {
111  edm::LogInfo("RecoVertex/KVFTest")
112  << "Exception during event number: " << iEvent.id()
113  << "\n";
114  } else {
115  const TrackingParticleCollection tPC = *(TPCollectionH.product());
116  reco::RecoToSimCollection recSimColl=associatorForParamAtPca->associateRecoToSim(tks,
117  TPCollectionH);
118  tree->fill(tv, &sv, &recSimColl);
119  }
120  }
121  }
122 }
123 
124 //Returns the first vertex in the list.
125 
127 {
128  // get the simulated vertices
130  iEvent.getByToken(token_VertexTruth,TVCollectionH);
131  const TrackingVertexCollection tPC = *(TVCollectionH.product());
132 
133 // Handle<edm::SimVertexContainer> simVtcs;
134 // iEvent.getByLabel("g4SimHits", simVtcs);
135 // std::cout << "SimVertex " << simVtcs->size() << std::endl;
136 // for(edm::SimVertexContainer::const_iterator v=simVtcs->begin();
137 // v!=simVtcs->end(); ++v){
138 // std::cout << "simvtx "
139 // << v->position().x() << " "
140 // << v->position().y() << " "
141 // << v->position().z() << " "
142 // << v->parentIndex() << " "
143 // << v->noParent() << " "
144 // << std::endl;
145 // }
146  return *(tPC.begin());
147 }
T getParameter(std::string const &) const
std::string outputFile_
Definition: KVFTest.h:56
T getUntrackedParameter(std::string const &, T const &) const
std::vector< TrackingParticle > TrackingParticleCollection
TrackingVertex getSimVertex(const edm::Event &iEvent) const
Definition: KVFTest.cc:126
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual CachingVertex< 5 > vertex(const std::vector< reco::TransientTrack > &tracks) const
edm::EDGetTokenT< reco::TrackCollection > token_tracks
Definition: KVFTest.h:57
std::pair< double, double > Point
Definition: CaloEllipse.h:18
virtual void analyze(const edm::Event &, const edm::EventSetup &)
Definition: KVFTest.cc:58
virtual void endJob()
Definition: KVFTest.cc:50
edm::EDGetTokenT< reco::TrackToTrackingParticleAssociator > token_associatorForParamAtPca
Definition: KVFTest.h:60
edm::EDGetTokenT< TrackingParticleCollection > token_TrackTruth
Definition: KVFTest.h:58
int iEvent
Definition: GenABIO.cc:230
GlobalPoint position() const
TFile * rootFile_
Definition: KVFTest.h:54
bool isValid() const
Definition: HandleBase.h:75
std::unique_ptr< SimpleVertexTree > tree
Definition: KVFTest.h:53
virtual void beginJob()
Definition: KVFTest.cc:46
T const * product() const
Definition: Handle.h:81
edm::EDGetTokenT< TrackingVertexCollection > token_VertexTruth
Definition: KVFTest.h:59
std::vector< TrackingVertex > TrackingVertexCollection
const T & get() const
Definition: EventSetup.h:56
T const * product() const
Definition: ESHandle.h:86
KVFTest(const edm::ParameterSet &)
Definition: KVFTest.cc:25
edm::EventID id() const
Definition: EventBase.h:59
edm::ParameterSet kvfPSet
Definition: KVFTest.h:52
tuple cout
Definition: gather_cfg.py:145
~KVFTest()
Definition: KVFTest.cc:42