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 
33 
34 //generator level
36 #include "HepMC/GenEvent.h"
37 #include "HepMC/GenVertex.h"
38 #include "HepMC/GenParticle.h"
39 
40 // vertex stuff
44 
45 // simulated vertices,..., add <use name=SimDataFormats/Vertex> and <../Track>
51 //#include "DataFormats/Math/interface/LorentzVector.h"
57 
58 //Track et al
65 
66 // Root
67 #include <TH1.h>
68 #include <TFile.h>
69 
71 
72 
73 
74 
75 // class declaration
77 
79 
81 struct SimPart{
83  int type; // 0 = primary
84  double zdcap; // z@dca' (closest approach to the beam
85  double ddcap;
86  double zvtx; // z of the vertex
87  double xvtx; // x of the vertex
88  double yvtx; // y of the vertex
89  int pdg; // particle pdg id
90  int rec;
91 };
92 
93 // auxiliary class holding simulated primary vertices
95 public:
96 
97  simPrimaryVertex(double x1,double y1,double z1):x(x1),y(y1),z(z1),ptsq(0),nGenTrk(0){
98  ptot.setPx(0);
99  ptot.setPy(0);
100  ptot.setPz(0);
101  ptot.setE(0);
102  cluster=-1;
103  nclutrk=0;
104  p4=LorentzVector(0,0,0,0) ;
105  // event=0;
106  };
107  double x,y,z;
108  HepMC::FourVector ptot;
110  double ptsq;
111  int nGenTrk;
113  int cluster;
114  //int event;
116  double nclutrk;
117  std::vector<int> finalstateParticles;
118  std::vector<int> simTrackIndex;
119  std::vector<int> matchedRecTrackIndex;
120  std::vector<int> genVertex;
121  std::vector<reco::Track> reconstructedTracks;
123 };
124 
125 
126 // auxiliary class holding simulated events
127 class SimEvent {
128 public:
129 
131  //event=-1;
132  nrecTrack=0;
133  z=-99;
134  zfit=-99;
135  sumpt2rec=0.;
136  sumpt2=0;
137  sumpt=0;
138  Tc=-1;
139  dzmax=0;
140  dztrim=0;
141  chisq=0;
142  };
143  double x,y,z;
144  double xfit,yfit,zfit;
146  //int event;
148  std::vector<const TrackingParticle*> tp;
149  std::vector<reco::TransientTrack> tk;
150  std::vector<reco::TransientTrack> tkprim;
151  std::vector<reco::TransientTrack> tkprimsel;
152  double sumpt2rec;
153  double sumpt2,sumpt;
155  // rec vertex matching
156  double zmatch;
157  int nmatch;
158  std::map<double, int> ntInRecVz; // number of tracks in recvtx at z
159 };
160 
161 
162 
163 public:
166 
167  virtual void analyze(const edm::Event&, const edm::EventSetup&);
168  //virtual void beginJob(edm::EventSetup const&);
169  virtual void beginJob();
170  virtual void endJob();
171 
172 private:
173  void printPVTrks(const edm::Handle<reco::TrackCollection> &recTrks,
174  const edm::Handle<reco::VertexCollection> &recVtxs,
175  std::vector<SimPart>& tsim,
176  std::vector<SimEvent>& simEvt,
177  const bool selectedOnly=true);
178 
179  int* supf(std::vector<SimPart>& simtrks, const reco::TrackCollection & trks);
180  static bool match(const ParameterVector &a, const ParameterVector &b);
181  std::vector<SimPart> getSimTrkParameters( edm::Handle<edm::SimTrackContainer> & simTrks,
183  double simUnit=1.0);
184  void getTc(const std::vector<reco::TransientTrack>&,double &, double &, double &, double &, double&);
185  void add(std::map<std::string, TH1*>& h, TH1* hist){ h[hist->GetName()]=hist; hist->StatOverflows(kTRUE);}
186 
187  void Fill(std::map<std::string, TH1*>& h, std::string s, double x){
188  // cout << "Fill1 " << s << endl;
189  if(h.count(s)==0){
190  std::cout << "Trying to fill non-exiting Histogram named " << s << std::endl;
191  return;
192  }
193  h[s]->Fill(x);
194  }
195 
196  void Fill(std::map<std::string, TH1*>& h, std::string s, double x, double y){
197  // cout << "Fill2 " << s << endl;
198  if(h.count(s)==0){
199  std::cout << "Trying to fill non-exiting Histogram named " << s << std::endl;
200  return;
201  }
202  h[s]->Fill(x,y);
203  }
204 
205  void Fill(std::map<std::string, TH1*>& h, std::string s, double x, bool signal){
206  if(h.count(s)==0){
207  std::cout << "Trying to fill non-exiting Histogram named " << s << std::endl;
208  return;
209  }
210 
211  h[s]->Fill(x);
212  if(signal){
213  if(h.count(s+"Signal")==0){
214  std::cout << "Trying to fill non-exiting Histogram named " << s+"Signal" << std::endl;
215  return;
216  }
217  h[s+"Signal"]->Fill(x);
218  }else{
219  if(h.count(s+"PU")==0){
220  std::cout << "Trying to fill non-exiting Histogram named " << s+"PU" << std::endl;
221  return;
222  }
223  h[s+"PU"]->Fill(x);
224  }
225  }
226 
227  void Fill(std::map<std::string, TH1*>& h, std::string s, bool yesno, bool signal){
228  if (yesno){
229  Fill(h, s,1.,signal);
230  }else{
231  Fill(h, s,0.,signal);
232  }
233  }
234 
235  void Cumulate(TH1* h){
236 
237  if((h->GetEntries()==0) || (h->Integral()<=0) ){
238  std::cout << "DEBUG : Cumulate called with empty histogram " << h->GetTitle() << std::endl;
239  return;
240  }
241  std::cout << "DEBUG : cumulating " << h->GetTitle() << std::endl;
242  try{
243  h->ComputeIntegral();
244  Double_t * integral=h->GetIntegral();
245  h->SetContent(integral);
246  }catch(...){
247  std::cout << "DEBUG : an error occurred cumulating " << h->GetTitle() << std::endl;
248  }
249  std::cout << "DEBUG : cumulating " << h->GetTitle() << "done " << std::endl;
250  }
251 
252  std::map<std::string, TH1*> bookVertexHistograms();
253 
254  bool matchVertex(const simPrimaryVertex &vsim,
255  const reco::Vertex &vrec);
256  bool isResonance(const HepMC::GenParticle * p);
258  bool isCharged(const HepMC::GenParticle * p);
259  void fillTrackHistos(std::map<std::string, TH1*> & h, const std::string & ttype, const reco::Track & t, const reco::Vertex *v = NULL);
260  void dumpHitInfo(const reco::Track & t);
261  void printRecTrks( const edm::Handle<reco::TrackCollection> & recTrks);
262  void printRecVtxs(const edm::Handle<reco::VertexCollection> recVtxs, std::string title="Reconstructed Vertices");
265  std::vector<simPrimaryVertex> getSimPVs(const edm::Handle<edm::HepMCProduct> evtMC);
266  std::vector<simPrimaryVertex> getSimPVs(const edm::Handle<edm::HepMCProduct> evt,
269  std::vector<PrimaryVertexAnalyzer4PU::simPrimaryVertex> getSimPVs(const edm::Handle<TrackingVertexCollection>);
270 
272  std::vector< edm::RefToBase<reco::Track> > getTruthMatchedVertexTracks(
273  const reco::Vertex&
274  );
275 
276  std::vector<PrimaryVertexAnalyzer4PU::SimEvent> getSimEvents(
280  );
281 
282  void matchRecTracksToVertex(simPrimaryVertex & pv,
283  const std::vector<SimPart > & tsim,
284  const edm::Handle<reco::TrackCollection> & recTrks);
285 
286  void analyzeVertexCollection(std::map<std::string, TH1*> & h,
288  const edm::Handle<reco::TrackCollection> recTrks,
289  std::vector<simPrimaryVertex> & simpv,
290  const std::string message="");
291 
292  void analyzeVertexCollectionTP(std::map<std::string, TH1*> & h,
294  const edm::Handle<reco::TrackCollection> recTrks,
295  std::vector<SimEvent> & simEvt,
296  const std::string message="");
297 
298  void printEventSummary(std::map<std::string, TH1*> & h,
300  const edm::Handle<reco::TrackCollection> recTrks,
301  std::vector<SimEvent> & simEvt,
302  const std::string message);
303 
304  void history(const edm::Handle<edm::View<reco::Track> > & tracks,const size_t trackindex=10000);
305  std::string particleString(int) const;
309  ) const;
311  HepMC::GenVertex::particles_in_const_iterator,
312  HepMC::GenVertex::particles_in_const_iterator,
313  HepMC::GenVertex::particles_out_const_iterator,
314  HepMC::GenVertex::particles_out_const_iterator
315  ) const;
316 
317 
318  // ----------member data ---------------------------
320  std::string outputFile_; // output file
321  std::vector<std::string> vtxSample_; // make this a a vector to keep cfg compatibility with PrimaryVertexAnalyzer
322  double fBfield_;
323  TFile* rootFile_;
324  bool verbose_;
326  bool printXBS_;
328  double simUnit_;
329  double zmatch_;
332  // local counters
335  int ndump_;
338 
339  // from the event setup
340  int run_;
342  int event_;
345 
346  bool DEBUG_;
347 
348 
349  std::map<std::string, TH1*> hBS;
350  std::map<std::string, TH1*> hnoBS;
351  std::map<std::string, TH1*> hDA;
352  std::map<std::string, TH1*> hPIX;
353  std::map<std::string, TH1*> hMVF;
354  std::map<std::string, TH1*> hsimPV;
355 
358  std::map<double, TrackingParticleRef> z2tp_;
359 
362  double wxy2_;
366 };
367 
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
Definition: DDAxes.h:10
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_
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="")