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