00001 #include "RecoVertex/KinematicFit/plugins/KineExample.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/KalmanVertexFit/interface/KalmanVertexFitter.h"
00018 #include "SimTracker/Records/interface/TrackAssociatorRecord.h"
00019
00020 #include "RecoVertex/KinematicFitPrimitives/interface/ParticleMass.h"
00021 #include "RecoVertex/KinematicFitPrimitives/interface/MultiTrackKinematicConstraint.h"
00022 #include <RecoVertex/KinematicFitPrimitives/interface/KinematicParticleFactoryFromTransientTrack.h>
00023
00024 #include "RecoVertex/KinematicFit/interface/KinematicConstrainedVertexFitter.h"
00025 #include "RecoVertex/KinematicFit/interface/TwoTrackMassKinematicConstraint.h"
00026 #include "RecoVertex/KinematicFit/interface/KinematicParticleVertexFitter.h"
00027 #include "RecoVertex/KinematicFit/interface/KinematicParticleFitter.h"
00028 #include "RecoVertex/KinematicFit/interface/MassKinematicConstraint.h"
00029
00030 #include <iostream>
00031
00032 using namespace reco;
00033 using namespace edm;
00034 using namespace std;
00035
00036 KineExample::KineExample(const edm::ParameterSet& iConfig)
00037 : theConfig(iConfig)
00038 {
00039 trackLabel_ = iConfig.getParameter<std::string>("TrackLabel");
00040 outputFile_ = iConfig.getUntrackedParameter<std::string>("outputFile");
00041 kvfPSet = iConfig.getParameter<edm::ParameterSet>("KVFParameters");
00042
00043 edm::LogInfo("RecoVertex/KineExample")
00044 << "Initializing KVF TEST analyser - Output file: " << outputFile_ <<"\n";
00045 }
00046
00047
00048 KineExample::~KineExample() {
00049
00050 }
00051
00052 void KineExample::beginJob(edm::EventSetup const& setup){
00053 edm::ESHandle<TrackAssociatorBase> theAssociatorForParamAtPca;
00054 setup.get<TrackAssociatorRecord>().get("TrackAssociatorByChi2",theAssociatorForParamAtPca);
00055 associatorForParamAtPca = (TrackAssociatorByChi2 *) theAssociatorForParamAtPca.product();
00056
00057
00058 }
00059
00060
00061 void KineExample::endJob() {
00062
00063 }
00064
00065
00066
00067
00068
00069 void
00070 KineExample::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00071 {
00072
00073 edm::LogInfo("RecoVertex/KineExample")
00074 << "Reconstructing event number: " << iEvent.id() << "\n";
00075
00076
00077
00078 edm::Handle<reco::TrackCollection> tks;
00079 iEvent.getByLabel(trackLabel_, tks);
00080 if (!tks.isValid()) {
00081 cout
00082 << "Exception during event number: " << iEvent.id()
00083 << "\n";
00084 } else {
00085
00086 edm::LogInfo("RecoVertex/KineExample")
00087 << "Found: " << (*tks).size() << " reconstructed tracks" << "\n";
00088 cout << "got " << (*tks).size() << " tracks " << endl;
00089
00090
00091
00092
00093 edm::ESHandle<TransientTrackBuilder> theB;
00094 iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder",theB);
00095
00096 vector<TransientTrack> t_tks = (*theB).build(tks);
00097
00098 edm::LogInfo("RecoVertex/KineExample")
00099 << "Found: " << t_tks.size() << " reconstructed tracks" << "\n";
00100
00101
00102 if (t_tks.size() > 3) {
00103
00104
00105
00106
00107
00108
00109
00110
00111 vector<TransientTrack> ttv;
00112 ttv.push_back(t_tks[0]); ttv.push_back(t_tks[1]); ttv.push_back(t_tks[2]);ttv.push_back(t_tks[3]);
00113 KalmanVertexFitter kvf(false);
00114 TransientVertex tv = kvf.vertex(ttv);
00115
00116 std::cout << "Position: " << Vertex::Point(tv.position()) << "\n";
00117
00118
00119 TransientTrack ttMuPlus = t_tks[0];
00120 TransientTrack ttMuMinus = t_tks[1];
00121 TransientTrack ttKPlus = t_tks[2];
00122 TransientTrack ttKMinus = t_tks[3];
00123
00124
00125
00126 KinematicParticleFactoryFromTransientTrack pFactory;
00127
00128
00129 ParticleMass muon_mass = 0.1056583;
00130 ParticleMass kaon_mass = 0.493677;
00131 float muon_sigma = 0.0000000001;
00132 float kaon_sigma = 0.000016;
00133
00134
00135 float chi = 0.;
00136 float ndf = 0.;
00137
00138
00139 vector<RefCountedKinematicParticle> muonParticles;
00140 vector<RefCountedKinematicParticle> phiParticles;
00141 vector<RefCountedKinematicParticle> allParticles;
00142 muonParticles.push_back(pFactory.particle (ttMuPlus,muon_mass,chi,ndf,muon_sigma));
00143 muonParticles.push_back(pFactory.particle (ttMuMinus,muon_mass,chi,ndf,muon_sigma));
00144 allParticles.push_back(pFactory.particle (ttMuPlus,muon_mass,chi,ndf,muon_sigma));
00145 allParticles.push_back(pFactory.particle (ttMuMinus,muon_mass,chi,ndf,muon_sigma));
00146
00147 phiParticles.push_back(pFactory.particle (ttKPlus,kaon_mass,chi,ndf,kaon_sigma));
00148 phiParticles.push_back(pFactory.particle (ttKMinus,kaon_mass,chi,ndf,kaon_sigma));
00149 allParticles.push_back(pFactory.particle (ttKPlus,kaon_mass,chi,ndf,kaon_sigma));
00150 allParticles.push_back(pFactory.particle (ttKMinus,kaon_mass,chi,ndf,kaon_sigma));
00151
00152
00153
00154
00155
00156
00157 KinematicParticleVertexFitter fitter;
00158 RefCountedKinematicTree vertexFitTree = fitter.fit(allParticles);
00159
00160 printout(vertexFitTree);
00161
00163
00164
00165 ParticleMass jpsi = 3.09687;
00166
00167
00168 MultiTrackKinematicConstraint * j_psi_c = new TwoTrackMassKinematicConstraint(jpsi);
00169
00170
00171 KinematicConstrainedVertexFitter kcvFitter;
00172
00173
00174 RefCountedKinematicTree myTree = kcvFitter.fit(allParticles, j_psi_c);
00175
00176 cout << "Global fit done:\n";
00177 printout(myTree);
00178
00179
00180 KinematicParticleVertexFitter kpvFitter;
00181
00182
00183 RefCountedKinematicTree jpTree = kpvFitter.fit(muonParticles);
00184
00185
00186 KinematicParticleFitter csFitter;
00187
00188
00189 float jp_m_sigma = 0.00004;
00190 KinematicConstraint * jpsi_c2 = new MassKinematicConstraint(jpsi,jp_m_sigma);
00191
00192
00193 jpTree = csFitter.fit(jpsi_c2,jpTree);
00194
00195
00196
00197 jpTree->movePointerToTheTop();
00198 RefCountedKinematicParticle jpsi_part = jpTree->currentParticle();
00199 phiParticles.push_back(jpsi_part);
00200
00201
00202
00203
00204 RefCountedKinematicTree bsTree = kpvFitter.fit(phiParticles);
00205 cout << "Sequential fit done:\n";
00206 printout(bsTree);
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222 }
00223 }
00224 }
00225
00226 void KineExample::printout(const RefCountedKinematicVertex& myVertex) const
00227 {
00228 cout << "Decay vertex: " << myVertex->position() <<endl;
00229 }
00230
00231 void KineExample::printout(const RefCountedKinematicParticle& myParticle) const
00232 {
00233 cout << "Particle: \n";
00234
00235 AlgebraicVector7 bs_par = myParticle->currentState().kinematicParameters().vector();
00236
00237
00238 AlgebraicSymMatrix77 bs_er = myParticle->currentState().kinematicParametersError().matrix();
00239 cout << "Momentum at vertex: " << myParticle->currentState().globalMomentum ()<<endl;
00240 cout << "Parameters at vertex: " << myParticle->currentState().kinematicParameters().vector()<<endl;
00241 }
00242
00243 void KineExample::printout(const RefCountedKinematicTree& myTree) const
00244 {
00245
00246
00247 myTree->movePointerToTheTop();
00248
00249
00250 RefCountedKinematicParticle b_s = myTree->currentParticle();
00251 printout(b_s);
00252
00253
00254 RefCountedKinematicVertex b_dec_vertex = myTree->currentDecayVertex();
00255 printout(b_dec_vertex);
00256
00257
00258
00259 vector< RefCountedKinematicParticle > bs_children = myTree->finalStateParticles();
00260
00261 for (unsigned int i=0;i< bs_children.size();++i) {
00262 printout(bs_children[i]);
00263 }
00264
00265
00266 bool child = myTree->movePointerToTheFirstChild();
00267
00268 if(child) while (myTree->movePointerToTheNextChild()) {
00269 RefCountedKinematicParticle aChild = myTree->currentParticle();
00270 printout(aChild);
00271 }
00272 }
00273
00274
00275
00276 TrackingVertex KineExample::getSimVertex(const edm::Event& iEvent) const
00277 {
00278
00279 edm::Handle<TrackingVertexCollection> TVCollectionH ;
00280 iEvent.getByLabel("trackingtruth","VertexTruth",TVCollectionH);
00281 const TrackingVertexCollection tPC = *(TVCollectionH.product());
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296 return *(tPC.begin());
00297 }
00298 DEFINE_ANOTHER_FWK_MODULE(KineExample);