File indexing completed on 2024-04-06 12:29:07
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #include <memory>
0016 #include <iostream>
0017
0018
0019 #include "DataFormats/Common/interface/Handle.h"
0020 #include "DataFormats/GsfTrackReco/interface/GsfTrack.h"
0021 #include "DataFormats/GsfTrackReco/interface/GsfTrackFwd.h"
0022 #include "DataFormats/VertexReco/interface/Vertex.h"
0023 #include "DataFormats/VertexReco/interface/VertexFwd.h"
0024 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0025 #include "FWCore/Framework/interface/ESHandle.h"
0026 #include "FWCore/Framework/interface/Event.h"
0027 #include "FWCore/Framework/interface/EventSetup.h"
0028 #include "FWCore/Framework/interface/Frameworkfwd.h"
0029 #include "FWCore/PluginManager/interface/ModuleDef.h"
0030 #include "FWCore/Framework/interface/MakerMacros.h"
0031 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0032 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0033 #include "MagneticField/Engine/interface/MagneticField.h"
0034 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
0035 #include "RecoVertex/GaussianSumVertexFit/interface/GsfVertexFitter.h"
0036 #include "RecoVertex/KalmanVertexFit/interface/KalmanVertexFitter.h"
0037 #include "RecoVertex/KalmanVertexFit/interface/SimpleVertexTree.h"
0038 #include "RecoVertex/VertexPrimitives/interface/TransientVertex.h"
0039 #include "SimDataFormats/TrackingAnalysis/interface/TrackingVertexContainer.h"
0040 #include "SimDataFormats/Vertex/interface/SimVertex.h"
0041 #include "TrackingTools/Records/interface/TransientTrackRecord.h"
0042 #include "TrackingTools/TransientTrack/interface/TransientTrack.h"
0043 #include "TrackingTools/TransientTrack/interface/TransientTrackBuilder.h"
0044
0045 #include <TFile.h>
0046
0047
0048
0049
0050
0051 class GsfTest : public edm::one::EDAnalyzer<> {
0052 public:
0053 explicit GsfTest(const edm::ParameterSet&);
0054 ~GsfTest();
0055
0056 virtual void analyze(const edm::Event&, const edm::EventSetup&);
0057
0058 private:
0059 TrackingVertex getSimVertex(const edm::Event& iEvent) const;
0060
0061 const edm::ESGetToken<TransientTrackBuilder, TransientTrackRecord> estoken_ttk;
0062 const edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> estoken_mf;
0063
0064 edm::ParameterSet gsfPSet;
0065
0066 std::unique_ptr<SimpleVertexTree> tree;
0067 TFile* rootFile_;
0068
0069 std::string outputFile_;
0070 edm::EDGetTokenT<reco::TrackCollection> token_tracks;
0071
0072 edm::EDGetTokenT<TrackingVertexCollection> token_VertexTruth;
0073 };
0074
0075 using namespace reco;
0076 using namespace edm;
0077 using namespace std;
0078
0079 GsfTest::GsfTest(const edm::ParameterSet& iConfig)
0080 : estoken_ttk(esConsumes(edm::ESInputTag("", "TransientTrackBuilder"))), estoken_mf(esConsumes()) {
0081 token_tracks = consumes<TrackCollection>(iConfig.getParameter<string>("TrackLabel"));
0082 outputFile_ = iConfig.getUntrackedParameter<std::string>("outputFile");
0083 gsfPSet = iConfig.getParameter<edm::ParameterSet>("GsfParameters");
0084 rootFile_ = TFile::Open(outputFile_.c_str(), "RECREATE");
0085 edm::LogInfo("RecoVertex/GsfTest") << "Initializing KVF TEST analyser - Output file: " << outputFile_ << "\n";
0086
0087 token_VertexTruth = consumes<TrackingVertexCollection>(edm::InputTag("trackingtruth", "VertexTruth"));
0088 }
0089
0090 GsfTest::~GsfTest() { delete rootFile_; }
0091
0092
0093
0094
0095
0096 void GsfTest::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0097 if (not tree) {
0098 const MagneticField* magField = &iSetup.getData(estoken_mf);
0099 tree.reset(new SimpleVertexTree("VertexFitter", magField));
0100 }
0101
0102 try {
0103 edm::LogInfo("RecoVertex/GsfTest") << "Reconstructing event number: " << iEvent.id() << "\n";
0104
0105
0106
0107 edm::Handle<edm::View<reco::Track> > tks;
0108 iEvent.getByToken(token_tracks, tks);
0109
0110 edm::LogInfo("RecoVertex/GsfTest") << "Found: " << (*tks).size() << " reconstructed tracks"
0111 << "\n";
0112
0113
0114
0115
0116 edm::ESHandle<TransientTrackBuilder> theB = iSetup.getHandle(estoken_ttk);
0117
0118 vector<TransientTrack> t_tks = (*theB).build(tks);
0119
0120 edm::LogInfo("RecoVertex/GsfTest") << "Found: " << t_tks.size() << " reconstructed tracks"
0121 << "\n";
0122
0123
0124 if (t_tks.size() > 1) {
0125
0126
0127
0128
0129
0130 KalmanVertexFitter kvf;
0131 TransientVertex tv2 = kvf.vertex(t_tks);
0132 edm::LogPrint("GsfTest") << "KVF Position: " << Vertex::Point(tv2.position()) << tv2.normalisedChiSquared()
0133 << " " << tv2.degreesOfFreedom() << "\n";
0134
0135 GsfVertexFitter gsf(gsfPSet);
0136 TransientVertex tv = gsf.vertex(t_tks);
0137 edm::LogPrint("GsfTest") << "Position: " << Vertex::Point(tv.position()) << "\n";
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147 }
0148
0149 }
0150
0151 catch (cms::Exception& err) {
0152 edm::LogError("GsfTest") << "Exception during event number: " << iEvent.id() << "\n" << err.what() << "\n";
0153 }
0154 }
0155
0156
0157
0158 TrackingVertex GsfTest::getSimVertex(const edm::Event& iEvent) const {
0159
0160 edm::Handle<TrackingVertexCollection> TVCollectionH;
0161 iEvent.getByToken(token_VertexTruth, TVCollectionH);
0162 const TrackingVertexCollection tPC = *(TVCollectionH.product());
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177 return *(tPC.begin());
0178 }
0179
0180 DEFINE_FWK_MODULE(GsfTest);