00001 #include "RecoVertex/KalmanVertexFit/plugins/KVFTest.h"
00002
00003 #include "DataFormats/VertexReco/interface/Vertex.h"
00004 #include "DataFormats/VertexReco/interface/VertexFwd.h"
00005 #include "DataFormats/TrackReco/interface/Track.h"
00006 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00007 #include "DataFormats/Common/interface/EDProduct.h"
00008 #include "DataFormats/Common/interface/Handle.h"
00009 #include "FWCore/Framework/interface/MakerMacros.h"
00010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00011 #include "FWCore/Framework/interface/ESHandle.h"
00012
00013 #include "TrackingTools/TransientTrack/interface/TransientTrackBuilder.h"
00014 #include "TrackingTools/Records/interface/TransientTrackRecord.h"
00015 #include "TrackingTools/TransientTrack/interface/TransientTrack.h"
00016 #include "RecoVertex/VertexPrimitives/interface/TransientVertex.h"
00017 #include "RecoVertex/VertexPrimitives/interface/ConvertError.h"
00018 #include "RecoVertex/KalmanVertexFit/interface/KalmanVertexFitter.h"
00019 #include "SimTracker/Records/interface/TrackAssociatorRecord.h"
00020
00021 #include <iostream>
00022
00023 using namespace reco;
00024 using namespace edm;
00025 using namespace std;
00026
00027 KVFTest::KVFTest(const edm::ParameterSet& iConfig)
00028 : theConfig(iConfig)
00029 {
00030 trackLabel_ = iConfig.getParameter<std::string>("TrackLabel");
00031 outputFile_ = iConfig.getUntrackedParameter<std::string>("outputFile");
00032 kvfPSet = iConfig.getParameter<edm::ParameterSet>("KVFParameters");
00033 rootFile_ = TFile::Open(outputFile_.c_str(),"RECREATE");
00034 edm::LogInfo("RecoVertex/KVFTest")
00035 << "Initializing KVF TEST analyser - Output file: " << outputFile_ <<"\n";
00036 }
00037
00038
00039 KVFTest::~KVFTest() {
00040 delete rootFile_;
00041 }
00042
00043 void KVFTest::beginJob(edm::EventSetup const& setup){
00044 edm::ESHandle<TrackAssociatorBase> theAssociatorForParamAtPca;
00045 setup.get<TrackAssociatorRecord>().get("TrackAssociatorByChi2",theAssociatorForParamAtPca);
00046 associatorForParamAtPca = (TrackAssociatorByChi2 *) theAssociatorForParamAtPca.product();
00047
00048 tree = new SimpleVertexTree("VertexFitter", associatorForParamAtPca);
00049 }
00050
00051
00052 void KVFTest::endJob() {
00053 delete tree;
00054 }
00055
00056
00057
00058
00059
00060 void
00061 KVFTest::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00062 {
00063 edm::LogInfo("RecoVertex/KVFTest")
00064 << "Reconstructing event number: " << iEvent.id() << "\n";
00065
00066
00067
00068 edm::Handle<edm::View<reco::Track> > tks;
00069 iEvent.getByLabel(trackLabel_, tks);
00070 if (!tks.isValid()) {
00071 edm::LogInfo("RecoVertex/KVFTest")
00072 << "Exception during event number: " << iEvent.id()
00073 << "\n";
00074 } else {
00075 edm::LogInfo("RecoVertex/KVFTest")
00076 << "Found: " << (*tks).size() << " reconstructed tracks" << "\n";
00077 cout << "got " << (*tks).size() << " tracks " << endl;
00078
00079
00080
00081
00082 edm::ESHandle<TransientTrackBuilder> theB;
00083 iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder",theB);
00084
00085 vector<TransientTrack> t_tks = (*theB).build(tks);
00086
00087 edm::LogInfo("RecoVertex/KVFTest")
00088 << "Found: " << t_tks.size() << " reconstructed tracks" << "\n";
00089
00090
00091 if (t_tks.size() > 1) {
00092
00093 KalmanVertexFitter kvf(true);
00094 TransientVertex tv = kvf.vertex(t_tks);
00095
00096 std::cout << "Position: " << Vertex::Point(tv.position()) << "\n";
00097
00098
00099 TrackingVertex sv = getSimVertex(iEvent);
00100 edm::Handle<TrackingParticleCollection> TPCollectionH ;
00101 iEvent.getByLabel("trackingtruth","TrackTruth",TPCollectionH);
00102 if (!TPCollectionH.isValid()) {
00103 edm::LogInfo("RecoVertex/KVFTest")
00104 << "Exception during event number: " << iEvent.id()
00105 << "\n";
00106 } else {
00107 const TrackingParticleCollection tPC = *(TPCollectionH.product());
00108 reco::RecoToSimCollection recSimColl=associatorForParamAtPca->associateRecoToSim(tks,
00109 TPCollectionH,
00110 &iEvent);
00111 tree->fill(tv, &sv, &recSimColl);
00112 }
00113 }
00114 }
00115 }
00116
00117
00118
00119 TrackingVertex KVFTest::getSimVertex(const edm::Event& iEvent) const
00120 {
00121
00122 edm::Handle<TrackingVertexCollection> TVCollectionH ;
00123 iEvent.getByLabel("trackingtruth","VertexTruth",TVCollectionH);
00124 const TrackingVertexCollection tPC = *(TVCollectionH.product());
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139 return *(tPC.begin());
00140 }