CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
KVFTest Class Reference

#include <RecoVertex/KVFTest/src/KVFTest.cc>

Inheritance diagram for KVFTest:
edm::EDAnalyzer edm::EDConsumerBase

Public Member Functions

virtual void analyze (const edm::Event &, const edm::EventSetup &)
 
virtual void beginJob ()
 
virtual void endJob ()
 
 KVFTest (const edm::ParameterSet &)
 
 ~KVFTest ()
 
- Public Member Functions inherited from edm::EDAnalyzer
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzer ()
 
ModuleDescription const & moduleDescription () const
 
std::string workerType () const
 
virtual ~EDAnalyzer ()
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Member Functions

TrackingVertex getSimVertex (const edm::Event &iEvent) const
 

Private Attributes

edm::ParameterSet kvfPSet
 
std::string outputFile_
 
TFile * rootFile_
 
edm::ParameterSet theConfig
 
edm::EDGetTokenT< reco::TrackToTrackingParticleAssociatortoken_associatorForParamAtPca
 
edm::EDGetTokenT< reco::TrackCollectiontoken_tracks
 
edm::EDGetTokenT< TrackingParticleCollectiontoken_TrackTruth
 
edm::EDGetTokenT< TrackingVertexCollectiontoken_VertexTruth
 
std::unique_ptr< SimpleVertexTreetree
 

Additional Inherited Members

- Public Types inherited from edm::EDAnalyzer
typedef EDAnalyzer ModuleType
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::EDAnalyzer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

This is a very simple test analyzer mean to test the KalmanVertexFitter

Description: steers tracker primary vertex reconstruction and storage

Implementation: <Notes on="" implementation>="">

Definition at line 37 of file KVFTest.h.

Constructor & Destructor Documentation

KVFTest::KVFTest ( const edm::ParameterSet iConfig)
explicit

Definition at line 25 of file KVFTest.cc.

References edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), kvfPSet, outputFile_, rootFile_, AlCaHLTBitMon_QueryRunRegistry::string, token_associatorForParamAtPca, token_tracks, token_TrackTruth, and token_VertexTruth.

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 }
T getParameter(std::string const &) const
std::string outputFile_
Definition: KVFTest.h:56
T getUntrackedParameter(std::string const &, T const &) const
edm::EDGetTokenT< reco::TrackCollection > token_tracks
Definition: KVFTest.h:57
edm::ParameterSet theConfig
Definition: KVFTest.h:51
edm::EDGetTokenT< reco::TrackToTrackingParticleAssociator > token_associatorForParamAtPca
Definition: KVFTest.h:60
edm::EDGetTokenT< TrackingParticleCollection > token_TrackTruth
Definition: KVFTest.h:58
TFile * rootFile_
Definition: KVFTest.h:54
edm::EDGetTokenT< TrackingVertexCollection > token_VertexTruth
Definition: KVFTest.h:59
edm::ParameterSet kvfPSet
Definition: KVFTest.h:52
KVFTest::~KVFTest ( )

Definition at line 42 of file KVFTest.cc.

References rootFile_.

42  {
43  delete rootFile_;
44 }
TFile * rootFile_
Definition: KVFTest.h:54

Member Function Documentation

void KVFTest::analyze ( const edm::Event iEvent,
const edm::EventSetup iSetup 
)
virtual

Definition at line 58 of file KVFTest.cc.

References reco::TrackToTrackingParticleAssociator::associateRecoToSim(), gather_cfg::cout, edm::EventSetup::get(), edm::Event::getByToken(), getSimVertex(), edm::EventBase::id(), edm::HandleBase::isValid(), TransientVertex::position(), edm::Handle< T >::product(), edm::ESHandle< T >::product(), token_associatorForParamAtPca, token_tracks, token_TrackTruth, and KalmanVertexFitter::vertex().

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 }
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:457
edm::EDGetTokenT< reco::TrackCollection > token_tracks
Definition: KVFTest.h:57
std::pair< double, double > Point
Definition: CaloEllipse.h:18
edm::EDGetTokenT< reco::TrackToTrackingParticleAssociator > token_associatorForParamAtPca
Definition: KVFTest.h:60
edm::EDGetTokenT< TrackingParticleCollection > token_TrackTruth
Definition: KVFTest.h:58
GlobalPoint position() const
bool isValid() const
Definition: HandleBase.h:74
T const * product() const
Definition: Handle.h:81
reco::RecoToSimCollection associateRecoToSim(const edm::Handle< edm::View< reco::Track > > &tCH, const edm::Handle< TrackingParticleCollection > &tPCH) const
compare reco to sim the handle of reco::Track and TrackingParticle collections
const T & get() const
Definition: EventSetup.h:56
edm::EventID id() const
Definition: EventBase.h:58
Definition: tree.py:1
T const * product() const
Definition: ESHandle.h:86
void KVFTest::beginJob ( void  )
virtual

Reimplemented from edm::EDAnalyzer.

Definition at line 46 of file KVFTest.cc.

46  {
47 }
void KVFTest::endJob ( void  )
virtual

Reimplemented from edm::EDAnalyzer.

Definition at line 50 of file KVFTest.cc.

50  {
51 }
TrackingVertex KVFTest::getSimVertex ( const edm::Event iEvent) const
private

Definition at line 126 of file KVFTest.cc.

References DEFINE_FWK_MODULE, edm::Event::getByToken(), edm::Handle< T >::product(), and token_VertexTruth.

Referenced by analyze().

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 }
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
T const * product() const
Definition: Handle.h:81
edm::EDGetTokenT< TrackingVertexCollection > token_VertexTruth
Definition: KVFTest.h:59
std::vector< TrackingVertex > TrackingVertexCollection

Member Data Documentation

edm::ParameterSet KVFTest::kvfPSet
private

Definition at line 52 of file KVFTest.h.

Referenced by KVFTest().

std::string KVFTest::outputFile_
private

Definition at line 56 of file KVFTest.h.

Referenced by KVFTest().

TFile* KVFTest::rootFile_
private

Definition at line 54 of file KVFTest.h.

Referenced by KVFTest(), and ~KVFTest().

edm::ParameterSet KVFTest::theConfig
private

Definition at line 51 of file KVFTest.h.

edm::EDGetTokenT<reco::TrackToTrackingParticleAssociator> KVFTest::token_associatorForParamAtPca
private

Definition at line 60 of file KVFTest.h.

Referenced by analyze(), and KVFTest().

edm::EDGetTokenT<reco::TrackCollection> KVFTest::token_tracks
private

Definition at line 57 of file KVFTest.h.

Referenced by analyze(), and KVFTest().

edm::EDGetTokenT<TrackingParticleCollection> KVFTest::token_TrackTruth
private

Definition at line 58 of file KVFTest.h.

Referenced by analyze(), and KVFTest().

edm::EDGetTokenT<TrackingVertexCollection> KVFTest::token_VertexTruth
private

Definition at line 59 of file KVFTest.h.

Referenced by getSimVertex(), and KVFTest().

std::unique_ptr<SimpleVertexTree> KVFTest::tree
private