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;
105  //int event;
107  double nclutrk;
108  std::vector<int> finalstateParticles;
109  std::vector<int> simTrackIndex;
110  std::vector<int> matchedRecTrackIndex;
111  std::vector<int> genVertex;
112  std::vector<reco::Track> reconstructedTracks;
114 };
115 
116 
117 // auxiliary class holding simulated events
118 class SimEvent {
119 public:
120 
122  //event=-1;
123  nrecTrack=0;
124  z=-99;
125  zfit=-99;
126  sumpt2rec=0.;
127  sumpt2=0;
128  sumpt=0;
129  Tc=-1;
130  dzmax=0;
131  dztrim=0;
132  chisq=0;
133  };
134  double x,y,z;
135  double xfit,yfit,zfit;
137  //int event;
139  std::vector<const TrackingParticle*> tp;
140  std::vector<reco::TransientTrack> tk;
141  std::vector<reco::TransientTrack> tkprim;
142  std::vector<reco::TransientTrack> tkprimsel;
143  double sumpt2rec;
144  double sumpt2,sumpt;
146  // rec vertex matching
147  double zmatch;
148  int nmatch;
149  std::map<double, int> ntInRecVz; // number of tracks in recvtx at z
150 };
151 
152 
153 
154 public:
157 
158  virtual void analyze(const edm::Event&, const edm::EventSetup&);
159  //virtual void beginJob(edm::EventSetup const&);
160  virtual void beginJob();
161  virtual void endJob();
162 
163 private:
164  void printPVTrks(const edm::Handle<reco::TrackCollection> &recTrks,
165  const edm::Handle<reco::VertexCollection> &recVtxs,
166  std::vector<SimPart>& tsim,
167  std::vector<SimEvent>& simEvt,
168  const bool selectedOnly=true);
169 
170  std::vector<int> supf(std::vector<SimPart>& simtrks, const reco::TrackCollection & trks);
171  static bool match(const ParameterVector &a, const ParameterVector &b);
172  std::vector<SimPart> getSimTrkParameters( edm::Handle<edm::SimTrackContainer> & simTrks,
174  double simUnit=1.0);
175  void getTc(const std::vector<reco::TransientTrack>&,double &, double &, double &, double &, double&);
176  void add(std::map<std::string, TH1*>& h, TH1* hist){ h[hist->GetName()]=hist; hist->StatOverflows(kTRUE);}
177 
178  void Fill(std::map<std::string, TH1*>& h, std::string s, double x){
179  // cout << "Fill1 " << s << endl;
180  if(h.count(s)==0){
181  std::cout << "Trying to fill non-exiting Histogram named " << s << std::endl;
182  return;
183  }
184  h[s]->Fill(x);
185  }
186 
187  void Fill(std::map<std::string, TH1*>& h, std::string s, double x, double y){
188  // cout << "Fill2 " << 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,y);
194  }
195 
196  void Fill(std::map<std::string, TH1*>& h, std::string s, double x, bool signal){
197  if(h.count(s)==0){
198  std::cout << "Trying to fill non-exiting Histogram named " << s << std::endl;
199  return;
200  }
201 
202  h[s]->Fill(x);
203  if(signal){
204  if(h.count(s+"Signal")==0){
205  std::cout << "Trying to fill non-exiting Histogram named " << s+"Signal" << std::endl;
206  return;
207  }
208  h[s+"Signal"]->Fill(x);
209  }else{
210  if(h.count(s+"PU")==0){
211  std::cout << "Trying to fill non-exiting Histogram named " << s+"PU" << std::endl;
212  return;
213  }
214  h[s+"PU"]->Fill(x);
215  }
216  }
217 
218  void Fill(std::map<std::string, TH1*>& h, std::string s, bool yesno, bool signal){
219  if (yesno){
220  Fill(h, s,1.,signal);
221  }else{
222  Fill(h, s,0.,signal);
223  }
224  }
225 
226  void Cumulate(TH1* h){
227 
228  if((h->GetEntries()==0) || (h->Integral()<=0) ){
229  std::cout << "DEBUG : Cumulate called with empty histogram " << h->GetTitle() << std::endl;
230  return;
231  }
232  std::cout << "DEBUG : cumulating " << h->GetTitle() << std::endl;
233  try{
234  h->ComputeIntegral();
235  Double_t * integral=h->GetIntegral();
236  h->SetContent(integral);
237  }catch(...){
238  std::cout << "DEBUG : an error occurred cumulating " << h->GetTitle() << std::endl;
239  }
240  std::cout << "DEBUG : cumulating " << h->GetTitle() << "done " << std::endl;
241  }
242 
243  std::map<std::string, TH1*> bookVertexHistograms();
244 
245  bool matchVertex(const simPrimaryVertex &vsim,
246  const reco::Vertex &vrec);
247  bool isResonance(const HepMC::GenParticle * p);
249  bool isCharged(const HepMC::GenParticle * p);
250  void fillTrackHistos(std::map<std::string, TH1*> & h, const std::string & ttype, const reco::Track & t, const reco::Vertex *v = NULL);
251  void dumpHitInfo(const reco::Track & t);
252  void printRecTrks( const edm::Handle<reco::TrackCollection> & recTrks);
253  void printRecVtxs(const edm::Handle<reco::VertexCollection> recVtxs, std::string title="Reconstructed Vertices");
256  std::vector<simPrimaryVertex> getSimPVs(const edm::Handle<edm::HepMCProduct> evtMC);
257  std::vector<simPrimaryVertex> getSimPVs(const edm::Handle<edm::HepMCProduct> evt,
260  std::vector<PrimaryVertexAnalyzer4PU::simPrimaryVertex> getSimPVs(const edm::Handle<TrackingVertexCollection>);
261  double getTrueSeparation(float, const std::vector<float> &);
262  double getTrueSeparation(SimEvent, std::vector<SimEvent> &);
263  std::vector<int>* vertex_match(float, const edm::Handle<reco::VertexCollection>);
264 
266  std::vector< edm::RefToBase<reco::Track> > getTruthMatchedVertexTracks(
267  const reco::Vertex&
268  );
269 
270  std::vector<PrimaryVertexAnalyzer4PU::SimEvent> getSimEvents(
274  );
275 
276  void matchRecTracksToVertex(simPrimaryVertex & pv,
277  const std::vector<SimPart > & tsim,
278  const edm::Handle<reco::TrackCollection> & recTrks);
279 
280  void analyzeVertexCollection(std::map<std::string, TH1*> & h,
282  const edm::Handle<reco::TrackCollection> recTrks,
283  std::vector<simPrimaryVertex> & simpv,
284  const std::vector<float> & pui_z,
285  const std::string message="");
286 
287  void analyzeVertexCollectionTP(std::map<std::string, TH1*> & h,
289  const edm::Handle<reco::TrackCollection> recTrks,
290  std::vector<SimEvent> & simEvt,
292  const std::string message="");
293 
294  void printEventSummary(std::map<std::string, TH1*> & h,
296  const edm::Handle<reco::TrackCollection> recTrks,
297  std::vector<SimEvent> & simEvt,
298  const std::string message);
299 
300  void history(const edm::Handle<edm::View<reco::Track> > & tracks,const size_t trackindex=10000);
301  std::string particleString(int) const;
305  ) const;
307  HepMC::GenVertex::particles_in_const_iterator,
308  HepMC::GenVertex::particles_in_const_iterator,
309  HepMC::GenVertex::particles_out_const_iterator,
310  HepMC::GenVertex::particles_out_const_iterator
311  ) const;
312 
313 
314  // ----------member data ---------------------------
315  bool verbose_;
317  bool printXBS_;
320  bool DEBUG_;
321 
322  // local counters
325  int ndump_;
326 
327  // from the event setup
328  int run_;
330  int event_;
333 
334  double fBfield_;
335  double simUnit_;
336  double zmatch_;
337  double wxy2_;
338 
343 
347 
348  TFile* rootFile_;
350 
352  std::string outputFile_; // output file
353  std::vector<std::string> vtxSample_; // make this a a vector to keep cfg compatibility with PrimaryVertexAnalyzer
354 
355  std::map<std::string, TH1*> hBS;
356  std::map<std::string, TH1*> hnoBS;
357  std::map<std::string, TH1*> hDA;
358  std::map<std::string, TH1*> hPIX;
359  std::map<std::string, TH1*> hMVF;
360  std::map<std::string, TH1*> hsimPV;
361 
362  std::map<double, TrackingParticleRef> z2tp_;
363 
374 };
375 
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:10
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:68
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")
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: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 &)
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)
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)
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
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_