CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
KineExample Class Reference

#include <RecoVertex/KineExample/src/KineExample.cc>

Inheritance diagram for KineExample:
edm::EDAnalyzer edm::EDConsumerBase

Public Member Functions

virtual void analyze (const edm::Event &, const edm::EventSetup &)
 
virtual void beginRun (edm::Run const &, edm::EventSetup const &)
 
virtual void endJob ()
 
 KineExample (const edm::ParameterSet &)
 
 ~KineExample ()
 
- Public Member Functions inherited from edm::EDAnalyzer
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzer ()
 
ModuleDescription const & moduleDescription () const
 
std::string workerType () const
 
virtual ~EDAnalyzer ()
 
- Public Member Functions inherited from edm::EDConsumerBase
 EDConsumerBase ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesDependentUpon (const std::string &iProcessName, std::vector< const char * > &oModuleLabels) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Private Member Functions

TrackingVertex getSimVertex (const edm::Event &iEvent) const
 
void printout (const RefCountedKinematicVertex &myVertex) const
 
void printout (const RefCountedKinematicParticle &myParticle) const
 
void printout (const RefCountedKinematicTree &myTree) const
 

Private Attributes

TrackAssociatorByChi2associatorForParamAtPca
 
edm::ParameterSet kvfPSet
 
std::string outputFile_
 
edm::ParameterSet theConfig
 
edm::EDGetTokenT
< reco::TrackCollection
token_tracks
 
edm::EDGetTokenT
< TrackingVertexCollection
token_VertexTruth
 

Additional Inherited Members

- Public Types inherited from edm::EDAnalyzer
typedef EDAnalyzer ModuleType
 
- Static Public Member Functions inherited from edm::EDAnalyzer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
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 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)
 

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 40 of file KineExample.h.

Constructor & Destructor Documentation

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

Definition at line 35 of file KineExample.cc.

References edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), kvfPSet, outputFile_, AlCaHLTBitMon_QueryRunRegistry::string, token_tracks, and token_VertexTruth.

36  : theConfig(iConfig)
37 {
38  token_tracks = consumes<TrackCollection>(iConfig.getParameter<string>("TrackLabel"));
39  outputFile_ = iConfig.getUntrackedParameter<std::string>("outputFile");
40  kvfPSet = iConfig.getParameter<edm::ParameterSet>("KVFParameters");
41 // rootFile_ = TFile::Open(outputFile_.c_str(),"RECREATE");
42  edm::LogInfo("RecoVertex/KineExample")
43  << "Initializing KVF TEST analyser - Output file: " << outputFile_ <<"\n";
44 // token_TrackTruth = consumes<TrackingParticleCollection>(edm::InputTag("trackingtruth", "TrackTruth"));
45  token_VertexTruth = consumes<TrackingVertexCollection>(edm::InputTag("trackingtruth", "VertexTruth"));
46 }
T getParameter(std::string const &) const
edm::EDGetTokenT< reco::TrackCollection > token_tracks
Definition: KineExample.h:65
T getUntrackedParameter(std::string const &, T const &) const
edm::ParameterSet kvfPSet
Definition: KineExample.h:59
edm::ParameterSet theConfig
Definition: KineExample.h:58
edm::EDGetTokenT< TrackingVertexCollection > token_VertexTruth
Definition: KineExample.h:67
std::string outputFile_
Definition: KineExample.h:64
KineExample::~KineExample ( )

Definition at line 49 of file KineExample.cc.

49  {
50 // delete rootFile_;
51 }

Member Function Documentation

void KineExample::analyze ( const edm::Event iEvent,
const edm::EventSetup iSetup 
)
virtual

Implements edm::EDAnalyzer.

Definition at line 71 of file KineExample.cc.

References gather_cfg::cout, cppFunctionSkipper::exception, KinematicConstrainedVertexFitter::fit(), KinematicParticleFitter::fit(), KinematicParticleVertexFitter::fit(), edm::EventSetup::get(), edm::Event::getByToken(), edm::EventBase::id(), edm::HandleBase::isValid(), TransientVertex::isValid(), jpsi, KinematicParticleFactoryFromTransientTrack::particle(), TransientVertex::position(), printout(), token_tracks, and KalmanVertexFitter::vertex().

72 {
73  try {
74 
75  cout << "Reconstructing event number: " << iEvent.id() << "\n";
76 
77  // get RECO tracks from the event
78  // `tks` can be used as a ptr to a reco::TrackCollection
80  iEvent.getByToken(token_tracks, tks);
81  if (!tks.isValid()) {
82  cout
83  << "Couln't find track collection: " << iEvent.id()
84  << "\n";
85  } else {
86 
87  edm::LogInfo("RecoVertex/KineExample")
88  << "Found: " << (*tks).size() << " reconstructed tracks" << "\n";
89  cout << "got " << (*tks).size() << " tracks " << endl;
90 
91  // Transform Track to TransientTrack
92  //get the builder:
94  iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder",theB);
95  //do the conversion:
96  vector<TransientTrack> t_tks = (*theB).build(tks);
97 
98  cout << "Found: " << t_tks.size() << " reconstructed tracks" << "\n";
99 
100  // Do a KindFit, if >= 4 tracks.
101  if (t_tks.size() > 3) {
102 
103  // For a first test, suppose that the first four tracks are the 2 muons,
104  // then the 2 kaons. Since this will not be true, the result of the fit
105  // will not be meaningfull, but at least you will get the idea of how to
106  // do such a fit.
107 
108  //First, to get started, a simple vertex fit:
109 
110  vector<TransientTrack> ttv;
111  ttv.push_back(t_tks[0]); ttv.push_back(t_tks[1]); ttv.push_back(t_tks[2]);ttv.push_back(t_tks[3]);
112  KalmanVertexFitter kvf(false);
113  TransientVertex tv = kvf.vertex(ttv);
114  if (!tv.isValid()) cout << "KVF failed\n";
115  else std::cout << "KVF fit Position: " << Vertex::Point(tv.position()) << "\n";
116 
117 
118  TransientTrack ttMuPlus = t_tks[0];
119  TransientTrack ttMuMinus = t_tks[1];
120  TransientTrack ttKPlus = t_tks[2];
121  TransientTrack ttKMinus = t_tks[3];
122 
123  //the final state muons and kaons from the Bs->J/PsiPhi->mumuKK decay
124  //Creating a KinematicParticleFactory
126 
127  //The mass of a muon and the insignificant mass sigma to avoid singularities in the covariance matrix.
128  ParticleMass muon_mass = 0.1056583;
129  ParticleMass kaon_mass = 0.493677;
130  float muon_sigma = 0.0000001;
131  float kaon_sigma = 0.000016;
132 
133  //initial chi2 and ndf before kinematic fits. The chi2 of the reconstruction is not considered
134  float chi = 0.;
135  float ndf = 0.;
136 
137  //making particles
138  vector<RefCountedKinematicParticle> muonParticles;
139  vector<RefCountedKinematicParticle> phiParticles;
140  vector<RefCountedKinematicParticle> allParticles;
141  muonParticles.push_back(pFactory.particle (ttMuPlus,muon_mass,chi,ndf,muon_sigma));
142  muonParticles.push_back(pFactory.particle (ttMuMinus,muon_mass,chi,ndf,muon_sigma));
143  allParticles.push_back(pFactory.particle (ttMuPlus,muon_mass,chi,ndf,muon_sigma));
144  allParticles.push_back(pFactory.particle (ttMuMinus,muon_mass,chi,ndf,muon_sigma));
145 
146  phiParticles.push_back(pFactory.particle (ttKPlus,kaon_mass,chi,ndf,kaon_sigma));
147  phiParticles.push_back(pFactory.particle (ttKMinus,kaon_mass,chi,ndf,kaon_sigma));
148  allParticles.push_back(pFactory.particle (ttKPlus,kaon_mass,chi,ndf,kaon_sigma));
149  allParticles.push_back(pFactory.particle (ttKMinus,kaon_mass,chi,ndf,kaon_sigma));
150 
151  /* Example of a simple vertex fit, without other constraints
152  * The reconstructed decay tree is a result of the kinematic fit
153  * The KinematicParticleVertexFitter fits the final state particles to their vertex and
154  * reconstructs the decayed state
155  */
157  cout <<"Simple vertex fit with KinematicParticleVertexFitter:\n";
158  RefCountedKinematicTree vertexFitTree = fitter.fit(allParticles);
159 
160  printout(vertexFitTree);
161 
163 
164  //creating the constraint for the J/Psi mass
165  ParticleMass jpsi = 3.09687;
166 
167  //creating the two track mass constraint
169 
170  //creating the fitter
172 
173  //obtaining the resulting tree
174  RefCountedKinematicTree myTree = kcvFitter.fit(allParticles, j_psi_c);
175 
176  cout << "\nGlobal fit done:\n";
177  printout(myTree);
178 
179  //creating the vertex fitter
181 
182  //reconstructing a J/Psi decay
183  RefCountedKinematicTree jpTree = kpvFitter.fit(muonParticles);
184 
185  //creating the particle fitter
186  KinematicParticleFitter csFitter;
187 
188  // creating the constraint
189  float jp_m_sigma = 0.00004;
190  KinematicConstraint * jpsi_c2 = new MassKinematicConstraint(jpsi,jp_m_sigma);
191 
192  //the constrained fit:
193  jpTree = csFitter.fit(jpsi_c2,jpTree);
194 
195  //getting the J/Psi KinematicParticle and putting it together with the kaons.
196  //The J/Psi KinematicParticle has a pointer to the tree it belongs to
197  jpTree->movePointerToTheTop();
198  RefCountedKinematicParticle jpsi_part = jpTree->currentParticle();
199  phiParticles.push_back(jpsi_part);
200 
201  //making a vertex fit and thus reconstructing the Bs parameters
202  // the resulting tree includes all the final state tracks, the J/Psi meson,
203  // its decay vertex, the Bs meson and its decay vertex.
204  RefCountedKinematicTree bsTree = kpvFitter.fit(phiParticles);
205  cout << "Sequential fit done:\n";
206  printout(bsTree);
207 
208 
209 
210 // // For the analysis: compare to your SimVertex
211 // TrackingVertex sv = getSimVertex(iEvent);
212 // edm::Handle<TrackingParticleCollection> TPCollectionH ;
213 // iEvent.getByToken(token_TrackTruth, TPCollectionH);
214 // const TrackingParticleCollection tPC = *(TPCollectionH.product());
215 // reco::RecoToSimCollection recSimColl=associatorForParamAtPca->associateRecoToSim(tks,
216 // TPCollectionH,
217 // &iEvent);
218 //
219 // tree->fill(tv, &sv, &recSimColl);
220 // }
221 
222  }
223  }
224 
225  }
226  catch (std::exception & err) {
227  cout << "Exception during event number: " << iEvent.id()
228  << "\n" << err.what() << "\n";
229  }
230 
231 }
edm::EDGetTokenT< reco::TrackCollection > token_tracks
Definition: KineExample.h:65
RefCountedKinematicTree fit(const std::vector< RefCountedKinematicParticle > &part)
void printout(const RefCountedKinematicVertex &myVertex) const
Definition: KineExample.cc:233
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:446
double ParticleMass
Definition: ParticleMass.h:5
std::pair< double, double > Point
Definition: CaloEllipse.h:18
std::vector< RefCountedKinematicTree > fit(KinematicConstraint *cs, const std::vector< RefCountedKinematicTree > &trees) const
GlobalPoint position() const
bool isValid() const
Definition: HandleBase.h:76
RefCountedKinematicTree fit(const std::vector< RefCountedKinematicParticle > &particles) const
const T & get() const
Definition: EventSetup.h:55
#define jpsi
edm::EventID id() const
Definition: EventBase.h:56
RefCountedKinematicParticle particle(const reco::TransientTrack &initialTrack, const ParticleMass &massGuess, float chiSquared, float degreesOfFr, float &m_sigma) const
tuple cout
Definition: gather_cfg.py:121
bool isValid() const
void KineExample::beginRun ( edm::Run const &  run,
edm::EventSetup const &  setup 
)
virtual

Reimplemented from edm::EDAnalyzer.

Definition at line 53 of file KineExample.cc.

References associatorForParamAtPca, edm::EventSetup::get(), and edm::ESHandle< class >::product().

53  {
54  edm::ESHandle<TrackAssociatorBase> theAssociatorForParamAtPca;
55  setup.get<TrackAssociatorRecord>().get("TrackAssociatorByChi2",theAssociatorForParamAtPca);
56  associatorForParamAtPca = (TrackAssociatorByChi2 *) theAssociatorForParamAtPca.product();
57 
58 // tree = new SimpleVertexTree("VertexFitter", associatorForParamAtPca);
59 }
TrackAssociatorByChi2 * associatorForParamAtPca
Definition: KineExample.h:60
T const * product() const
Definition: ESHandle.h:86
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
void KineExample::endJob ( void  )
virtual

Reimplemented from edm::EDAnalyzer.

Definition at line 62 of file KineExample.cc.

62  {
63 // delete tree;
64 }
TrackingVertex KineExample::getSimVertex ( const edm::Event iEvent) const
private

Definition at line 289 of file KineExample.cc.

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

290 {
291  // get the simulated vertices
293  iEvent.getByToken(token_VertexTruth,TVCollectionH);
294  const TrackingVertexCollection tPC = *(TVCollectionH.product());
295 
296 // Handle<edm::SimVertexContainer> simVtcs;
297 // iEvent.getByLabel("g4SimHits", simVtcs);
298 // std::cout << "SimVertex " << simVtcs->size() << std::endl;
299 // for(edm::SimVertexContainer::const_iterator v=simVtcs->begin();
300 // v!=simVtcs->end(); ++v){
301 // std::cout << "simvtx "
302 // << v->position().x() << " "
303 // << v->position().y() << " "
304 // << v->position().z() << " "
305 // << v->parentIndex() << " "
306 // << v->noParent() << " "
307 // << std::endl;
308 // }
309  return *(tPC.begin());
310 }
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:446
edm::EDGetTokenT< TrackingVertexCollection > token_VertexTruth
Definition: KineExample.h:67
T const * product() const
Definition: Handle.h:81
std::vector< TrackingVertex > TrackingVertexCollection
void KineExample::printout ( const RefCountedKinematicVertex myVertex) const
private

Definition at line 233 of file KineExample.cc.

References gather_cfg::cout.

Referenced by analyze(), and printout().

234 {
235  if (myVertex->vertexIsValid()) {
236  cout << "Decay vertex: " << myVertex->position() <<myVertex->chiSquared()<< " "<<myVertex->degreesOfFreedom()<<endl;
237  } else cout << "Decay vertex Not valid\n";
238 }
tuple cout
Definition: gather_cfg.py:121
void KineExample::printout ( const RefCountedKinematicParticle myParticle) const
private

Definition at line 240 of file KineExample.cc.

References gather_cfg::cout.

241 {
242  cout << "Particle: \n";
243 //accessing the reconstructed Bs meson parameters:
244 //SK: uncomment if needed AlgebraicVector7 bs_par = myParticle->currentState().kinematicParameters().vector();
245 
246 //and their joint covariance matrix:
247 //SK:uncomment if needed AlgebraicSymMatrix77 bs_er = myParticle->currentState().kinematicParametersError().matrix();
248  cout << "Momentum at vertex: " << myParticle->currentState().globalMomentum ()<<endl;
249  cout << "Parameters at vertex: " << myParticle->currentState().kinematicParameters().vector()<<endl;
250 }
tuple cout
Definition: gather_cfg.py:121
void KineExample::printout ( const RefCountedKinematicTree myTree) const
private

Definition at line 252 of file KineExample.cc.

References gather_cfg::cout, i, and printout().

253 {
254  if (!myTree->isValid()) {
255  cout <<"Tree is invalid. Fit failed.\n";
256  return;
257  }
258 
259 //accessing the tree components, move pointer to top
260  myTree->movePointerToTheTop();
261 
262 //We are now at the top of the decay tree getting the B_s reconstructed KinematicPartlcle
263  RefCountedKinematicParticle b_s = myTree->currentParticle();
264  printout(b_s);
265 
266 // The B_s decay vertex
267  RefCountedKinematicVertex b_dec_vertex = myTree->currentDecayVertex();
268  printout(b_dec_vertex);
269 
270  // Get all the children of Bs:
271  //In this way, the pointer is not moved
272  vector< RefCountedKinematicParticle > bs_children = myTree->finalStateParticles();
273 
274  for (unsigned int i=0;i< bs_children.size();++i) {
275  printout(bs_children[i]);
276  }
277 
278 //Now navigating down the tree , pointer is moved:
279  bool child = myTree->movePointerToTheFirstChild();
280 
281  if(child) while (myTree->movePointerToTheNextChild()) {
282  RefCountedKinematicParticle aChild = myTree->currentParticle();
283  printout(aChild);
284  }
285 }
int i
Definition: DBlmapReader.cc:9
void printout(const RefCountedKinematicVertex &myVertex) const
Definition: KineExample.cc:233
tuple cout
Definition: gather_cfg.py:121

Member Data Documentation

TrackAssociatorByChi2* KineExample::associatorForParamAtPca
private

Definition at line 60 of file KineExample.h.

Referenced by beginRun().

edm::ParameterSet KineExample::kvfPSet
private

Definition at line 59 of file KineExample.h.

Referenced by KineExample().

std::string KineExample::outputFile_
private

Definition at line 64 of file KineExample.h.

Referenced by KineExample().

edm::ParameterSet KineExample::theConfig
private

Definition at line 58 of file KineExample.h.

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

Definition at line 65 of file KineExample.h.

Referenced by analyze(), and KineExample().

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

Definition at line 67 of file KineExample.h.

Referenced by getSimVertex(), and KineExample().