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::one::EDAnalyzer<> edm::one::EDAnalyzerBase edm::EDConsumerBase

Public Member Functions

void analyze (const edm::Event &, const edm::EventSetup &) override
 
void beginJob () override
 
void endJob () override
 
 KVFTest (const edm::ParameterSet &)
 
 ~KVFTest () override
 
- Public Member Functions inherited from edm::one::EDAnalyzer<>
 EDAnalyzer ()=default
 
 EDAnalyzer (const EDAnalyzer &)=delete
 
SerialTaskQueueglobalLuminosityBlocksQueue () final
 
SerialTaskQueueglobalRunsQueue () final
 
const EDAnalyzeroperator= (const EDAnalyzer &)=delete
 
bool wantsGlobalLuminosityBlocks () const final
 
bool wantsGlobalRuns () const final
 
bool wantsInputProcessBlocks () const final
 
bool wantsProcessBlocks () const final
 
- Public Member Functions inherited from edm::one::EDAnalyzerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzerBase ()
 
ModuleDescription const & moduleDescription () const
 
bool wantsStreamLuminosityBlocks () const
 
bool wantsStreamRuns () const
 
 ~EDAnalyzerBase () override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ESProxyIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
std::vector< ESProxyIndex > const & esGetTokenIndicesVector (edm::Transition iTrans) const
 
std::vector< ESRecordIndex > const & esGetTokenRecordIndicesVector (edm::Transition iTrans) const
 
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 & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::array< std::vector< ModuleDescription const *> *, NumBranchTypes > &modulesAll, std::vector< ModuleProcessName > &modulesInPreviousProcesses, 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 selectInputProcessBlocks (ProductRegistry const &productRegistry, ProcessBlockHelperBase const &processBlockHelperBase)
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProxyIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Member Functions

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

Private Attributes

const edm::ESGetToken< MagneticField, IdealMagneticFieldRecordestoken_MF
 
const edm::ESGetToken< TransientTrackBuilder, TransientTrackRecordestoken_TTB
 
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::one::EDAnalyzerBase
typedef EDAnalyzerBase ModuleType
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::one::EDAnalyzerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
template<BranchType B = InEvent>
EDConsumerBaseAdaptor< Bconsumes (edm::InputTag tag) noexcept
 
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 ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<Transition Tr = Transition::Event>
constexpr auto esConsumes ()
 
template<Transition Tr = Transition::Event>
auto esConsumes (ESInputTag tag)
 
template<Transition Tr = Transition::Event>
ESGetTokenGeneric esConsumes (eventsetup::EventSetupRecordKey const &iRecord, eventsetup::DataKey const &iKey)
 Used with EventSetupRecord::doGet. More...
 
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)
 
void resetItemsToGetFrom (BranchType iType)
 

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 38 of file KVFTest.h.

Constructor & Destructor Documentation

◆ KVFTest()

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

Definition at line 19 of file KVFTest.cc.

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

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 }
std::string outputFile_
Definition: KVFTest.h:59
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > estoken_MF
Definition: KVFTest.h:51
edm::EDGetTokenT< reco::TrackCollection > token_tracks
Definition: KVFTest.h:60
edm::ParameterSet theConfig
Definition: KVFTest.h:54
edm::EDGetTokenT< reco::TrackToTrackingParticleAssociator > token_associatorForParamAtPca
Definition: KVFTest.h:63
T getUntrackedParameter(std::string const &, T const &) const
edm::EDGetTokenT< TrackingParticleCollection > token_TrackTruth
Definition: KVFTest.h:61
const edm::ESGetToken< TransientTrackBuilder, TransientTrackRecord > estoken_TTB
Definition: KVFTest.h:52
TFile * rootFile_
Definition: KVFTest.h:57
Log< level::Info, false > LogInfo
edm::EDGetTokenT< TrackingVertexCollection > token_VertexTruth
Definition: KVFTest.h:62
edm::ParameterSet kvfPSet
Definition: KVFTest.h:55

◆ ~KVFTest()

KVFTest::~KVFTest ( )
override

Definition at line 35 of file KVFTest.cc.

References rootFile_.

35 { delete rootFile_; }
TFile * rootFile_
Definition: KVFTest.h:57

Member Function Documentation

◆ analyze()

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

Implements edm::one::EDAnalyzerBase.

Definition at line 45 of file KVFTest.cc.

References reco::TrackToTrackingParticleAssociator::associateRecoToSim(), estoken_MF, estoken_TTB, edm::EventSetup::getData(), getSimVertex(), iEvent, edm::HandleBase::isValid(), TransientVertex::position(), edm::Handle< T >::product(), pfDeepBoostedJetPreprocessParams_cfi::sv, token_associatorForParamAtPca, token_tracks, token_TrackTruth, and KalmanVertexFitter::vertex().

45  {
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 }
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > estoken_MF
Definition: KVFTest.h:51
reco::RecoToSimCollection associateRecoToSim(const edm::Handle< edm::View< reco::Track >> &tCH, const edm::Handle< TrackingParticleCollection > &tPCH) const
GlobalPoint position() const
edm::EDGetTokenT< reco::TrackCollection > token_tracks
Definition: KVFTest.h:60
T const * product() const
Definition: Handle.h:70
edm::EDGetTokenT< reco::TrackToTrackingParticleAssociator > token_associatorForParamAtPca
Definition: KVFTest.h:63
edm::EDGetTokenT< TrackingParticleCollection > token_TrackTruth
Definition: KVFTest.h:61
int iEvent
Definition: GenABIO.cc:224
const edm::ESGetToken< TransientTrackBuilder, TransientTrackRecord > estoken_TTB
Definition: KVFTest.h:52
math::XYZPoint Point
bool getData(T &iHolder) const
Definition: EventSetup.h:122
Log< level::Warning, true > LogPrint
Log< level::Info, false > LogInfo
bool isValid() const
Definition: HandleBase.h:70
TrackingVertex getSimVertex(const edm::Event &iEvent) const
Definition: KVFTest.cc:101
std::vector< TrackingParticle > TrackingParticleCollection
Definition: tree.py:1

◆ beginJob()

void KVFTest::beginJob ( void  )
overridevirtual

Reimplemented from edm::one::EDAnalyzerBase.

Definition at line 37 of file KVFTest.cc.

37 {}

◆ endJob()

void KVFTest::endJob ( void  )
overridevirtual

Reimplemented from edm::one::EDAnalyzerBase.

Definition at line 39 of file KVFTest.cc.

39 {}

◆ getSimVertex()

TrackingVertex KVFTest::getSimVertex ( const edm::Event iEvent) const
private

Definition at line 101 of file KVFTest.cc.

References iEvent, edm::Handle< T >::product(), and token_VertexTruth.

Referenced by analyze().

101  {
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 }
T const * product() const
Definition: Handle.h:70
int iEvent
Definition: GenABIO.cc:224
edm::EDGetTokenT< TrackingVertexCollection > token_VertexTruth
Definition: KVFTest.h:62
std::vector< TrackingVertex > TrackingVertexCollection

Member Data Documentation

◆ estoken_MF

const edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> KVFTest::estoken_MF
private

Definition at line 51 of file KVFTest.h.

Referenced by analyze().

◆ estoken_TTB

const edm::ESGetToken<TransientTrackBuilder, TransientTrackRecord> KVFTest::estoken_TTB
private

Definition at line 52 of file KVFTest.h.

Referenced by analyze().

◆ kvfPSet

edm::ParameterSet KVFTest::kvfPSet
private

Definition at line 55 of file KVFTest.h.

Referenced by KVFTest().

◆ outputFile_

std::string KVFTest::outputFile_
private

Definition at line 59 of file KVFTest.h.

Referenced by KVFTest().

◆ rootFile_

TFile* KVFTest::rootFile_
private

Definition at line 57 of file KVFTest.h.

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

◆ theConfig

edm::ParameterSet KVFTest::theConfig
private

Definition at line 54 of file KVFTest.h.

◆ token_associatorForParamAtPca

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

Definition at line 63 of file KVFTest.h.

Referenced by analyze(), and KVFTest().

◆ token_tracks

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

Definition at line 60 of file KVFTest.h.

Referenced by analyze(), and KVFTest().

◆ token_TrackTruth

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

Definition at line 61 of file KVFTest.h.

Referenced by analyze(), and KVFTest().

◆ token_VertexTruth

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

Definition at line 62 of file KVFTest.h.

Referenced by getSimVertex(), and KVFTest().

◆ tree

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