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