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 // user include files
26 
27 // generator level
28 #include "HepMC/SimpleVector.h"
31 
32 // math
35 
36 // reco track
39 
40 // reco vertex
42 
43 // simulated track
47 
48 // simulated vertex
50 
51 // pile-up
53 
54 // tracking
56 
57 // vertexing
59 
60 // ROOT
61 #include <TH1.h>
62 
63 // ROOT forward declarations
64 class TFile;
65 
66 // class declaration
68 
70 
72 struct SimPart{
74  int type; // 0 = primary
75  double zdcap; // z@dca' (closest approach to the beam
76  double ddcap;
77  double zvtx; // z of the vertex
78  double xvtx; // x of the vertex
79  double yvtx; // y of the vertex
80  int pdg; // particle pdg id
81  int rec;
82 };
83 
84 // auxiliary class holding simulated primary vertices
86 public:
87 
88  simPrimaryVertex(double x1,double y1,double z1):x(x1),y(y1),z(z1),ptsq(0),nGenTrk(0){
89  ptot.setPx(0);
90  ptot.setPy(0);
91  ptot.setPz(0);
92  ptot.setE(0);
93  cluster=-1;
94  nclutrk=0;
95  p4=LorentzVector(0,0,0,0) ;
96  // event=0;
97  };
98  double x,y,z;
99  HepMC::FourVector ptot;
101  double ptsq;
102  int nGenTrk;
104  int cluster;
106  double nclutrk;
107  std::vector<int> finalstateParticles;
108  std::vector<int> simTrackIndex;
109  std::vector<int> matchedRecTrackIndex;
110  std::vector<int> genVertex;
111  std::vector<reco::Track> reconstructedTracks;
113 };
114 
115 
116 // auxiliary class holding simulated events
117 class SimEvent {
118 public:
119 
121  nrecTrack=0;
122  z=-99;
123  zfit=-99;
124  sumpt2rec=0.;
125  sumpt2=0;
126  sumpt=0;
127  Tc=-1;
128  dzmax=0;
129  dztrim=0;
130  chisq=0;
131  };
132  double x,y,z;
133  double xfit,yfit,zfit;
136  std::vector<const TrackingParticle*> tp;
137  std::vector<reco::TransientTrack> tk;
138  std::vector<reco::TransientTrack> tkprim;
139  std::vector<reco::TransientTrack> tkprimsel;
140  double sumpt2rec;
141  double sumpt2,sumpt;
143  // rec vertex matching
144  double zmatch;
145  int nmatch;
146  std::map<double, int> ntInRecVz; // number of tracks in recvtx at z
147 };
148 
149 
150 
151 public:
154 
155  virtual void analyze(const edm::Event&, const edm::EventSetup&);
156  virtual void beginJob();
157  virtual void endJob();
158 
159 private:
160  void printPVTrks(const edm::Handle<reco::TrackCollection> &recTrks,
161  const edm::Handle<reco::VertexCollection> &recVtxs,
162  std::vector<SimPart>& tsim,
163  std::vector<SimEvent>& simEvt,
164  const bool selectedOnly=true);
165 
166  std::vector<int> supf(std::vector<SimPart>& simtrks, const reco::TrackCollection & trks);
167  static bool match(const ParameterVector &a, const ParameterVector &b);
168  std::vector<SimPart> getSimTrkParameters( edm::Handle<edm::SimTrackContainer> & simTrks,
170  double simUnit=1.0);
171  void getTc(const std::vector<reco::TransientTrack>&,double &, double &, double &, double &, double&);
172  void add(std::map<std::string, TH1*>& h, TH1* hist){ h[hist->GetName()]=hist; hist->StatOverflows(kTRUE);}
173 
174  void Fill(std::map<std::string, TH1*>& h, std::string s, double x){
175  if(h.count(s)==0){
176  std::cout << "Trying to fill non-exiting Histogram named " << s << std::endl;
177  return;
178  }
179  h[s]->Fill(x);
180  }
181 
182  void Fill(std::map<std::string, TH1*>& h, std::string s, double x, double y){
183  if(h.count(s)==0){
184  std::cout << "Trying to fill non-exiting Histogram named " << s << std::endl;
185  return;
186  }
187  h[s]->Fill(x,y);
188  }
189 
190  void Fill(std::map<std::string, TH1*>& h, std::string s, double x, bool signal){
191  if(h.count(s)==0){
192  std::cout << "Trying to fill non-exiting Histogram named " << s << std::endl;
193  return;
194  }
195 
196  h[s]->Fill(x);
197  if(signal){
198  if(h.count(s+"Signal")==0){
199  std::cout << "Trying to fill non-exiting Histogram named " << s+"Signal" << std::endl;
200  return;
201  }
202  h[s+"Signal"]->Fill(x);
203  }else{
204  if(h.count(s+"PU")==0){
205  std::cout << "Trying to fill non-exiting Histogram named " << s+"PU" << std::endl;
206  return;
207  }
208  h[s+"PU"]->Fill(x);
209  }
210  }
211 
212  void Fill(std::map<std::string, TH1*>& h, std::string s, bool yesno, bool signal){
213  if (yesno){
214  Fill(h, s,1.,signal);
215  }else{
216  Fill(h, s,0.,signal);
217  }
218  }
219 
220  void Cumulate(TH1* h){
221 
222  if((h->GetEntries()==0) || (h->Integral()<=0) ){
223  std::cout << "DEBUG : Cumulate called with empty histogram " << h->GetTitle() << std::endl;
224  return;
225  }
226  std::cout << "DEBUG : cumulating " << h->GetTitle() << std::endl;
227  try{
228  h->ComputeIntegral();
229  Double_t * integral=h->GetIntegral();
230  h->SetContent(integral);
231  }catch(...){
232  std::cout << "DEBUG : an error occurred cumulating " << h->GetTitle() << std::endl;
233  }
234  std::cout << "DEBUG : cumulating " << h->GetTitle() << "done " << std::endl;
235  }
236 
237  std::map<std::string, TH1*> bookVertexHistograms();
238 
239  bool matchVertex(const simPrimaryVertex &vsim,
240  const reco::Vertex &vrec);
241  bool isResonance(const HepMC::GenParticle * p);
243  bool isCharged(const HepMC::GenParticle * p);
244  void fillTrackHistos(std::map<std::string, TH1*> & h, const std::string & ttype, const reco::Track & t, const reco::Vertex *v = NULL);
245  void dumpHitInfo(const reco::Track & t);
246  void printRecTrks( const edm::Handle<reco::TrackCollection> & recTrks);
247  void printRecVtxs(const edm::Handle<reco::VertexCollection> recVtxs, std::string title="Reconstructed Vertices");
250  std::vector<simPrimaryVertex> getSimPVs(const edm::Handle<edm::HepMCProduct> evtMC);
251  std::vector<simPrimaryVertex> getSimPVs(const edm::Handle<edm::HepMCProduct> evt,
254  std::vector<PrimaryVertexAnalyzer4PU::simPrimaryVertex> getSimPVs(const edm::Handle<TrackingVertexCollection>);
255  double getTrueSeparation(float, const std::vector<float> &);
256  double getTrueSeparation(SimEvent, std::vector<SimEvent> &);
257  std::vector<int>* vertex_match(float, const edm::Handle<reco::VertexCollection>);
258 
260  std::vector< edm::RefToBase<reco::Track> > getTruthMatchedVertexTracks(
261  const reco::Vertex&
262  );
263 
264  std::vector<PrimaryVertexAnalyzer4PU::SimEvent> getSimEvents(
268  );
269 
270  void matchRecTracksToVertex(simPrimaryVertex & pv,
271  const std::vector<SimPart > & tsim,
272  const edm::Handle<reco::TrackCollection> & recTrks);
273 
274  void analyzeVertexCollection(std::map<std::string, TH1*> & h,
276  const edm::Handle<reco::TrackCollection> recTrks,
277  std::vector<simPrimaryVertex> & simpv,
278  const std::vector<float> & pui_z,
279  const std::string message="");
280 
281  void analyzeVertexCollectionTP(std::map<std::string, TH1*> & h,
283  const edm::Handle<reco::TrackCollection> recTrks,
284  std::vector<SimEvent> & simEvt,
286  const std::string message="");
287 
288  void printEventSummary(std::map<std::string, TH1*> & h,
290  const edm::Handle<reco::TrackCollection> recTrks,
291  std::vector<SimEvent> & simEvt,
292  const std::string message);
293 
294  void history(const edm::Handle<edm::View<reco::Track> > & tracks,const size_t trackindex=10000);
295  std::string particleString(int) const;
299  ) const;
301  HepMC::GenVertex::particles_in_const_iterator,
302  HepMC::GenVertex::particles_in_const_iterator,
303  HepMC::GenVertex::particles_out_const_iterator,
304  HepMC::GenVertex::particles_out_const_iterator
305  ) const;
306 
307 
308  // ----------member data ---------------------------
309  bool verbose_;
311  bool printXBS_;
314  bool DEBUG_;
315 
316  // local counters
319  int ndump_;
320 
321  // from the event setup
327 
328  double fBfield_;
329  double simUnit_;
330  double zmatch_;
331  double wxy2_;
332 
337 
341 
342  TFile* rootFile_;
344 
346  std::string outputFile_; // output file
347  std::vector<std::string> vtxSample_; // make this a a vector to keep cfg compatibility with PrimaryVertexAnalyzer
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 
356  std::map<double, TrackingParticleRef> z2tp_;
357 
369 };
edm::EDGetTokenT< reco::TrackCollection > recoTrackCollectionToken_
TrackFilterForPVFinding theTrackFilter
edm::EDGetTokenT< reco::BeamSpot > recoBeamSpotToken_
edm::EDGetTokenT< edm::SimTrackContainer > edmSimTrackContainerToken_
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< int > supf(std::vector< SimPart > &simtrks, const reco::TrackCollection &trks)
edm::EDGetTokenT< reco::VertexCollection > recoVertexCollectionToken_
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:13
unsigned long long EventNumber_t
static bool match(const ParameterVector &a, const ParameterVector &b)
edm::ESHandle< TransientTrackBuilder > theB_
edm::EDGetTokenT< TrackingParticleCollection > trackingParticleCollectionToken_
#define NULL
Definition: scimark2.h:8
math::Vector< dimension >::type ParameterVector
parameter vector
Definition: TrackBase.h:73
edm::EDGetTokenT< TrackingVertexCollection > trackingVertexCollectionToken_
edm::EDGetTokenT< edm::HepMCProduct > edmHepMCProductToken_
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::vector< float > &pui_z, const std::string message="")
void printRecVtxs(const edm::Handle< reco::VertexCollection > recVtxs, std::string title="Reconstructed Vertices")
unsigned int LuminosityBlockNumber_t
edm::EDGetTokenT< reco::TrackToTrackingParticleAssociator > recoTrackToTrackingParticleAssociatorToken_
std::map< std::string, TH1 * > hnoBS
edm::LuminosityBlockNumber_t luminosityBlock_
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:29
double getTrueSeparation(float, const std::vector< float > &)
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 &)
const reco::TrackToTrackingParticleAssociator * associatorByHits_
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)
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
std::vector< int > * vertex_match(float, const edm::Handle< reco::VertexCollection >)
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)
edm::EDGetTokenT< edm::View< reco::Track > > edmView_recoTrack_Token_
edm::EDGetTokenT< edm::SimVertexContainer > edmSimVertexContainerToken_
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)
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)
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:12
reco::RecoToSimCollection r2s_
double b
Definition: hdecay.h:120
std::string vertexString(const TrackingParticleRefVector &, const 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
void analyzeVertexCollectionTP(std::map< std::string, TH1 * > &h, const edm::Handle< reco::VertexCollection > recVtxs, const edm::Handle< reco::TrackCollection > recTrks, std::vector< SimEvent > &simEvt, reco::RecoToSimCollection rsC, const std::string message="")
edm::EDGetTokenT< reco::VertexCollection > recoVertexCollection_DA_Token_
edm::EDGetTokenT< reco::VertexCollection > recoVertexCollection_BS_Token_
edm::EDGetTokenT< std::vector< PileupSummaryInfo > > vecPileupSummaryInfoToken_
tuple cout
Definition: gather_cfg.py:121
unsigned int RunNumber_t
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_