CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PrimaryVertexAnalyzer4PU.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: MyPrimaryVertexAnalyzer4PU
4 // Class: MyPrimaryVertexAnalyzer4PU
5 //
13 //
14 // Original Author: Wolfram Erdmann
15 
16 
17 // system include files
18 #include <memory>
19 #include <string>
20 #include <vector>
21 
22 
23 // user include files
28 
32 
33 //generator level
35 #include "HepMC/GenEvent.h"
36 #include "HepMC/GenVertex.h"
37 #include "HepMC/GenParticle.h"
38 
39 // vertex stuff
43 
44 // simulated vertices,..., add <use name=SimDataFormats/Vertex> and <../Track>
50 //#include "DataFormats/Math/interface/LorentzVector.h"
56 
57 //Track et al
64 
65 // Root
66 #include <TH1.h>
67 #include <TFile.h>
68 
70 
71 
72 
73 
74 // class declaration
76 
78 
80 struct SimPart{
82  int type; // 0 = primary
83  double zdcap; // z@dca' (closest approach to the beam
84  double ddcap;
85  double zvtx; // z of the vertex
86  double xvtx; // x of the vertex
87  double yvtx; // y of the vertex
88  int pdg; // particle pdg id
89  int rec;
90 };
91 
92 // auxiliary class holding simulated primary vertices
94 public:
95 
96  simPrimaryVertex(double x1,double y1,double z1):x(x1),y(y1),z(z1),ptsq(0),nGenTrk(0){
97  ptot.setPx(0);
98  ptot.setPy(0);
99  ptot.setPz(0);
100  ptot.setE(0);
101  cluster=-1;
102  nclutrk=0;
103  p4=LorentzVector(0,0,0,0) ;
104  // event=0;
105  };
106  double x,y,z;
107  HepMC::FourVector ptot;
109  double ptsq;
110  int nGenTrk;
112  int cluster;
113  //int event;
115  double nclutrk;
116  std::vector<int> finalstateParticles;
117  std::vector<int> simTrackIndex;
118  std::vector<int> matchedRecTrackIndex;
119  std::vector<int> genVertex;
120  std::vector<reco::Track> reconstructedTracks;
122 };
123 
124 
125 // auxiliary class holding simulated events
126 class SimEvent {
127 public:
128 
130  //event=-1;
131  nrecTrack=0;
132  z=-99;
133  zfit=-99;
134  sumpt2rec=0.;
135  sumpt2=0;
136  sumpt=0;
137  Tc=-1;
138  dzmax=0;
139  dztrim=0;
140  chisq=0;
141  };
142  double x,y,z;
143  double xfit,yfit,zfit;
145  //int event;
147  std::vector<const TrackingParticle*> tp;
148  std::vector<reco::TransientTrack> tk;
149  std::vector<reco::TransientTrack> tkprim;
150  std::vector<reco::TransientTrack> tkprimsel;
151  double sumpt2rec;
152  double sumpt2,sumpt;
154  // rec vertex matching
155  double zmatch;
156  int nmatch;
157  std::map<double, int> ntInRecVz; // number of tracks in recvtx at z
158 };
159 
160 
161 
162 public:
165 
166  virtual void analyze(const edm::Event&, const edm::EventSetup&);
167  //virtual void beginJob(edm::EventSetup const&);
168  virtual void beginJob();
169  virtual void endJob();
170 
171 private:
172  void printPVTrks(const edm::Handle<reco::TrackCollection> &recTrks,
173  const edm::Handle<reco::VertexCollection> &recVtxs,
174  std::vector<SimPart>& tsim,
175  std::vector<SimEvent>& simEvt,
176  const bool selectedOnly=true);
177 
178  int* supf(std::vector<SimPart>& simtrks, const reco::TrackCollection & trks);
179  static bool match(const ParameterVector &a, const ParameterVector &b);
180  std::vector<SimPart> getSimTrkParameters( edm::Handle<edm::SimTrackContainer> & simTrks,
182  double simUnit=1.0);
183  void getTc(const std::vector<reco::TransientTrack>&,double &, double &, double &, double &, double&);
184  void add(std::map<std::string, TH1*>& h, TH1* hist){ h[hist->GetName()]=hist; hist->StatOverflows(kTRUE);}
185 
186  void Fill(std::map<std::string, TH1*>& h, std::string s, double x){
187  // cout << "Fill1 " << s << endl;
188  if(h.count(s)==0){
189  std::cout << "Trying to fill non-exiting Histogram named " << s << std::endl;
190  return;
191  }
192  h[s]->Fill(x);
193  }
194 
195  void Fill(std::map<std::string, TH1*>& h, std::string s, double x, double y){
196  // cout << "Fill2 " << s << endl;
197  if(h.count(s)==0){
198  std::cout << "Trying to fill non-exiting Histogram named " << s << std::endl;
199  return;
200  }
201  h[s]->Fill(x,y);
202  }
203 
204  void Fill(std::map<std::string, TH1*>& h, std::string s, double x, bool signal){
205  if(h.count(s)==0){
206  std::cout << "Trying to fill non-exiting Histogram named " << s << std::endl;
207  return;
208  }
209 
210  h[s]->Fill(x);
211  if(signal){
212  if(h.count(s+"Signal")==0){
213  std::cout << "Trying to fill non-exiting Histogram named " << s+"Signal" << std::endl;
214  return;
215  }
216  h[s+"Signal"]->Fill(x);
217  }else{
218  if(h.count(s+"PU")==0){
219  std::cout << "Trying to fill non-exiting Histogram named " << s+"PU" << std::endl;
220  return;
221  }
222  h[s+"PU"]->Fill(x);
223  }
224  }
225 
226  void Fill(std::map<std::string, TH1*>& h, std::string s, bool yesno, bool signal){
227  if (yesno){
228  Fill(h, s,1.,signal);
229  }else{
230  Fill(h, s,0.,signal);
231  }
232  }
233 
234  void Cumulate(TH1* h){
235 
236  if((h->GetEntries()==0) || (h->Integral()<=0) ){
237  std::cout << "DEBUG : Cumulate called with empty histogram " << h->GetTitle() << std::endl;
238  return;
239  }
240  std::cout << "DEBUG : cumulating " << h->GetTitle() << std::endl;
241  try{
242  h->ComputeIntegral();
243  Double_t * integral=h->GetIntegral();
244  h->SetContent(integral);
245  }catch(...){
246  std::cout << "DEBUG : an error occurred cumulating " << h->GetTitle() << std::endl;
247  }
248  std::cout << "DEBUG : cumulating " << h->GetTitle() << "done " << std::endl;
249  }
250 
251  std::map<std::string, TH1*> bookVertexHistograms();
252 
253  bool matchVertex(const simPrimaryVertex &vsim,
254  const reco::Vertex &vrec);
255  bool isResonance(const HepMC::GenParticle * p);
257  bool isCharged(const HepMC::GenParticle * p);
258  void fillTrackHistos(std::map<std::string, TH1*> & h, const std::string & ttype, const reco::Track & t, const reco::Vertex *v = NULL);
259  void dumpHitInfo(const reco::Track & t);
260  void printRecTrks( const edm::Handle<reco::TrackCollection> & recTrks);
261  void printRecVtxs(const edm::Handle<reco::VertexCollection> recVtxs, std::string title="Reconstructed Vertices");
264  std::vector<simPrimaryVertex> getSimPVs(const edm::Handle<edm::HepMCProduct> evtMC);
265  std::vector<simPrimaryVertex> getSimPVs(const edm::Handle<edm::HepMCProduct> evt,
268  std::vector<PrimaryVertexAnalyzer4PU::simPrimaryVertex> getSimPVs(const edm::Handle<TrackingVertexCollection>);
269 
271  std::vector< edm::RefToBase<reco::Track> > getTruthMatchedVertexTracks(
272  const reco::Vertex&
273  );
274 
275  std::vector<PrimaryVertexAnalyzer4PU::SimEvent> getSimEvents(
279  );
280 
281  void matchRecTracksToVertex(simPrimaryVertex & pv,
282  const std::vector<SimPart > & tsim,
283  const edm::Handle<reco::TrackCollection> & recTrks);
284 
285  void analyzeVertexCollection(std::map<std::string, TH1*> & h,
287  const edm::Handle<reco::TrackCollection> recTrks,
288  std::vector<simPrimaryVertex> & simpv,
289  const std::string message="");
290 
291  void analyzeVertexCollectionTP(std::map<std::string, TH1*> & h,
293  const edm::Handle<reco::TrackCollection> recTrks,
294  std::vector<SimEvent> & simEvt,
295  const std::string message="");
296 
297  void printEventSummary(std::map<std::string, TH1*> & h,
299  const edm::Handle<reco::TrackCollection> recTrks,
300  std::vector<SimEvent> & simEvt,
301  const std::string message);
302 
303  void history(const edm::Handle<edm::View<reco::Track> > & tracks,const size_t trackindex=10000);
304  std::string particleString(int) const;
305  std::string vertexString(
308  ) const;
309  std::string vertexString(
310  HepMC::GenVertex::particles_in_const_iterator,
311  HepMC::GenVertex::particles_in_const_iterator,
312  HepMC::GenVertex::particles_out_const_iterator,
313  HepMC::GenVertex::particles_out_const_iterator
314  ) const;
315 
316 
317  // ----------member data ---------------------------
318  std::string recoTrackProducer_;
319  std::string outputFile_; // output file
320  std::vector<std::string> vtxSample_; // make this a a vector to keep cfg compatibility with PrimaryVertexAnalyzer
321  double fBfield_;
322  TFile* rootFile_;
323  bool verbose_;
325  bool printXBS_;
327  double simUnit_;
328  double zmatch_;
331  // local counters
334  int ndump_;
337 
338  // from the event setup
339  int run_;
341  int event_;
344 
345  bool DEBUG_;
346 
347 
348  std::map<std::string, TH1*> hBS;
349  std::map<std::string, TH1*> hnoBS;
350  std::map<std::string, TH1*> hDA;
351  std::map<std::string, TH1*> hPIX;
352  std::map<std::string, TH1*> hMVF;
353  std::map<std::string, TH1*> hsimPV;
354 
357  std::map<double, TrackingParticleRef> z2tp_;
358 
361  double wxy2_;
364 };
365 
TrackFilterForPVFinding theTrackFilter
bool matchVertex(const simPrimaryVertex &vsim, const reco::Vertex &vrec)
std::vector< SimPart > getSimTrkParameters(edm::Handle< edm::SimTrackContainer > &simTrks, edm::Handle< edm::SimVertexContainer > &simVtcs, double simUnit=1.0)
std::vector< PrimaryVertexAnalyzer4PU::SimEvent > getSimEvents(edm::Handle< TrackingParticleCollection >, edm::Handle< TrackingVertexCollection >, edm::Handle< edm::View< reco::Track > >)
void fillTrackHistos(std::map< std::string, TH1 * > &h, const std::string &ttype, const reco::Track &t, const reco::Vertex *v=NULL)
std::vector< std::string > vtxSample_
reco::TrackBase::ParameterVector ParameterVector
std::map< std::string, TH1 * > hsimPV
std::vector< const TrackingParticle * > tp
edm::Handle< reco::BeamSpot > recoBeamSpotHandle_
std::vector< reco::TransientTrack > tk
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:10
static bool match(const ParameterVector &a, const ParameterVector &b)
edm::ESHandle< TransientTrackBuilder > theB_
#define NULL
Definition: scimark2.h:8
math::Vector< dimension >::type ParameterVector
parameter vector
Definition: TrackBase.h:70
void printRecVtxs(const edm::Handle< reco::VertexCollection > recVtxs, std::string title="Reconstructed Vertices")
std::map< std::string, TH1 * > hnoBS
void Fill(std::map< std::string, TH1 * > &h, std::string s, double x)
std::map< std::string, TH1 * > hDA
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:30
void analyzeVertexCollectionTP(std::map< std::string, TH1 * > &h, const edm::Handle< reco::VertexCollection > recVtxs, const edm::Handle< reco::TrackCollection > recTrks, std::vector< SimEvent > &simEvt, const std::string message="")
bool isFinalstateParticle(const HepMC::GenParticle *p)
std::string particleString(int) const
std::map< std::string, TH1 * > hMVF
bool isCharged(const HepMC::GenParticle *p)
bool truthMatchedTrack(edm::RefToBase< reco::Track >, TrackingParticleRef &)
std::map< std::string, TH1 * > bookVertexHistograms()
std::map< std::string, TH1 * > hPIX
void printPVTrks(const edm::Handle< reco::TrackCollection > &recTrks, const edm::Handle< reco::VertexCollection > &recVtxs, std::vector< SimPart > &tsim, std::vector< SimEvent > &simEvt, const bool selectedOnly=true)
std::vector< simPrimaryVertex > getSimPVs(const edm::Handle< edm::HepMCProduct > evtMC)
void printSimVtxs(const edm::Handle< edm::SimVertexContainer > simVtxs)
void Fill(std::map< std::string, TH1 * > &h, std::string s, bool yesno, bool signal)
void printEventSummary(std::map< std::string, TH1 * > &h, const edm::Handle< reco::VertexCollection > recVtxs, const edm::Handle< reco::TrackCollection > recTrks, std::vector< SimEvent > &simEvt, const std::string message)
void history(const edm::Handle< edm::View< reco::Track > > &tracks, const size_t trackindex=10000)
Integral< F, X >::type integral(const F &f)
Definition: Integral.h:69
std::map< std::string, TH1 * > hBS
std::vector< reco::TransientTrack > tkprim
void Fill(std::map< std::string, TH1 * > &h, std::string s, double x, bool signal)
TrackAssociatorBase * associatorByHits_
simPrimaryVertex(double x1, double y1, double z1)
void matchRecTracksToVertex(simPrimaryVertex &pv, const std::vector< SimPart > &tsim, const edm::Handle< reco::TrackCollection > &recTrks)
bool isResonance(const HepMC::GenParticle *p)
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
tuple tracks
Definition: testEve_cfg.py:39
void printRecTrks(const edm::Handle< reco::TrackCollection > &recTrks)
math::XYZTLorentzVector LorentzVector
void getTc(const std::vector< reco::TransientTrack > &, double &, double &, double &, double &, double &)
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:13
reco::RecoToSimCollection r2s_
double b
Definition: hdecay.h:120
int * supf(std::vector< SimPart > &simtrks, const reco::TrackCollection &trks)
std::string vertexString(TrackingParticleRefVector, TrackingParticleRefVector) const
PrimaryVertexAnalyzer4PU(const edm::ParameterSet &)
void printSimTrks(const edm::Handle< edm::SimTrackContainer > simVtrks)
void add(std::map< std::string, TH1 * > &h, TH1 *hist)
void Fill(std::map< std::string, TH1 * > &h, std::string s, double x, double y)
double a
Definition: hdecay.h:121
tuple cout
Definition: gather_cfg.py:121
x
Definition: VDTMath.h:216
void dumpHitInfo(const reco::Track &t)
virtual void analyze(const edm::Event &, const edm::EventSetup &)
std::vector< edm::RefToBase< reco::Track > > getTruthMatchedVertexTracks(const reco::Vertex &)
edm::ESHandle< ParticleDataTable > pdt_
std::vector< reco::TransientTrack > tkprimsel
std::map< double, TrackingParticleRef > z2tp_
mathSSE::Vec4< T > v
void analyzeVertexCollection(std::map< std::string, TH1 * > &h, const edm::Handle< reco::VertexCollection > recVtxs, const edm::Handle< reco::TrackCollection > recTrks, std::vector< simPrimaryVertex > &simpv, const std::string message="")