CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PrimaryVertexAnalyzer4PU.cc
Go to the documentation of this file.
2 
10 
11 //generator level + CLHEP
12 #include "HepMC/GenEvent.h"
13 #include "HepMC/GenVertex.h"
14 #include "HepMC/GenParticle.h"
15 
16 // reco track and vertex
19 
20 // simulated track
22 
23 // simulated vertex
25 
26 // crossing frame
30 
31 // TrackingParticle
34 
35 // tracking tools
37 
38 // clustering
41 
42 // associator
44 
45 // fit
48 
50 
51 // ROOT
52 #include <TH2.h>
53 #include <TFile.h>
54 #include <TProfile.h>
55 
56 #include <cmath>
57 #include <gsl/gsl_math.h>
58 #include <gsl/gsl_eigen.h>
59 
60 using namespace edm;
61 using namespace reco;
62 using namespace std;
63 //
64 // constants, enums and typedefs
65 //
67 //
68 // static data member definitions
69 //
70 
71 //
72 // constructors and destructor
73 //
75  : verbose_( iConfig.getUntrackedParameter<bool>( "verbose", false ) )
76  , doMatching_( iConfig.getUntrackedParameter<bool>( "matching", false ) )
77  , printXBS_( iConfig.getUntrackedParameter<bool>( "XBS", false ) )
78  , dumpThisEvent_( false )
79  , dumpPUcandidates_( iConfig.getUntrackedParameter<bool>( "dumpPUcandidates", false ) )
80  , DEBUG_( false )
81  , eventcounter_( 0 )
82  , dumpcounter_( 0 )
83  , ndump_( 10 )
84  , run_( 0 )
85  , luminosityBlock_( 0 )
86  , event_( 0 )
87  , bunchCrossing_( 0 )
88  , orbitNumber_( 0 )
89  , fBfield_( 0. )
90  , simUnit_( 1.0 ) // starting with CMSSW_1_2_x ??
91  , zmatch_( iConfig.getUntrackedParameter<double>( "zmatch", 0.0500 ) )
92  , wxy2_( 0. )
93  , theTrackFilter( iConfig.getParameter<edm::ParameterSet>( "TkFilterParameters" ) )
94  , recoTrackProducer_( iConfig.getUntrackedParameter<std::string>("recoTrackProducer") )
95  , outputFile_( iConfig.getUntrackedParameter<std::string>( "outputFile" ) )
96  , vecPileupSummaryInfoToken_( consumes< std::vector<PileupSummaryInfo> >( edm::InputTag( std::string( "addPileupInfo" ) ) ) )
97  , recoVertexCollectionToken_( consumes<reco::VertexCollection>( edm::InputTag( std::string( "offlinePrimaryVertices" ) ) ) )
98  , recoVertexCollection_BS_Token_( consumes<reco::VertexCollection>( edm::InputTag( std::string( "offlinePrimaryVerticesWithBS" ) ) ) )
99  , recoVertexCollection_DA_Token_( consumes<reco::VertexCollection>( edm::InputTag( std::string( "offlinePrimaryVerticesDA" ) ) ) )
100  , recoTrackCollectionToken_( consumes<reco::TrackCollection>( edm::InputTag( iConfig.getUntrackedParameter<std::string>( "recoTrackProducer" ) ) ) )
101  , recoBeamSpotToken_( consumes<reco::BeamSpot>( iConfig.getParameter<edm::InputTag>( "beamSpot" ) ) )
102  , edmView_recoTrack_Token_( consumes< edm::View<reco::Track> >( edm::InputTag( iConfig.getUntrackedParameter<std::string>( "recoTrackProducer" ) ) ) )
103  , edmSimVertexContainerToken_( consumes<edm::SimVertexContainer>( iConfig.getParameter<edm::InputTag>( "simG4" ) ) )
104  , edmSimTrackContainerToken_( consumes<edm::SimTrackContainer>( iConfig.getParameter<edm::InputTag>( "simG4" ) ) )
105  , trackingParticleCollectionToken_( consumes<TrackingParticleCollection>( edm::InputTag( std::string( "mix" )
106  , std::string( "MergedTrackTruth" )
107  )
108  )
109  )
110  , trackingVertexCollectionToken_( consumes<TrackingVertexCollection>( edm::InputTag( std::string( "mix" )
111  , std::string( "MergedTrackTruth" )
112  )
113  )
114  )
115  , edmHepMCProductToken_( consumes<edm::HepMCProduct>( edm::InputTag( std::string( "generator" ) ) ) ) // starting with 3_1_0 pre something
116  , recoTrackToTrackingParticleAssociatorToken_(consumes<reco::TrackToTrackingParticleAssociator>(edm::InputTag("trackAssociatorByHits")))
117 
118 {
119  //now do what ever initialization is needed
120  // open output file to store histograms}
121  rootFile_ = TFile::Open(outputFile_.c_str(),"RECREATE");
122  if ( (edm::getReleaseVersion()).find("CMSSW_1_1_",0)!=std::string::npos){
123  simUnit_=0.1; // for use in CMSSW_1_1_1 tutorial
124  }
125  cout << "PrimaryVertexAnalyzer4PU: zmatch=" << zmatch_ << endl;
126  //DEBUG_=true;
127 }
128 
129 
131 {
132  // do anything here that needs to be done at desctruction time
133  // (e.g. close files, deallocate resources etc.)
134  delete rootFile_;
135 }
136 
137 
138 //
139 // member functions
140 //
141 
143  std::map<std::string, TH1*> h;
144 
145  // release validation histograms used in DoCompare.C
146  h["nbtksinvtx"] = new TH1F("nbtksinvtx","reconstructed tracks in vertex",40,-0.5,39.5);
147  h["nbtksinvtxPU"] = new TH1F("nbtksinvtxPU","reconstructed tracks in vertex",40,-0.5,39.5);
148  h["nbtksinvtxTag"]= new TH1F("nbtksinvtxTag","reconstructed tracks in vertex",40,-0.5,39.5);
149  h["resx"] = new TH1F("resx","residual x",100,-0.04,0.04);
150  h["resy"] = new TH1F("resy","residual y",100,-0.04,0.04);
151  h["resz"] = new TH1F("resz","residual z",100,-0.1,0.1);
152  h["resz10"] = new TH1F("resz10","residual z",100,-1.0,1.);
153  h["pullx"] = new TH1F("pullx","pull x",100,-25.,25.);
154  h["pully"] = new TH1F("pully","pull y",100,-25.,25.);
155  h["pullz"] = new TH1F("pullz","pull z",100,-25.,25.);
156  h["vtxchi2"] = new TH1F("vtxchi2","chi squared",100,0.,100.);
157  h["vtxndf"] = new TH1F("vtxndf","degrees of freedom",500,0.,100.);
158  h["vtxndfc"] = new TH1F("vtxndfc","expected 2nd highest ndof",500,0.,100.);
159 
160  h["vtxndfvsntk"] = new TH2F("vtxndfvsntk","ndof vs #tracks",20,0.,100, 20, 0., 200.);
161  h["vtxndfoverntk"]= new TH1F("vtxndfoverntk","ndof / #tracks",40,0.,2.);
162  h["vtxndf2overntk"]= new TH1F("vtxndf2overntk","(ndof+2) / #tracks",40,0.,2.);
163  h["tklinks"] = new TH1F("tklinks","Usable track links",2,-0.5,1.5);
164  h["nans"] = new TH1F("nans","Illegal values for x,y,z,xx,xy,xz,yy,yz,zz",9,0.5,9.5);
165 
166  // raw
167  add(h, new TH1F("szRecVtx","size of recvtx collection",20, -0.5, 19.5));
168  add(h, new TH1F("isFake","fake vertex",2, -0.5, 1.5));
169  add(h, new TH1F("isFake1","fake vertex or ndof<0",2, -0.5, 1.5));
170  add(h, new TH1F("bunchCrossing","bunchCrossing",4000, 0., 4000.));
171  add(h, new TH2F("bunchCrossingLogNtk","bunchCrossingLogNtk",4000, 0., 4000.,5,0., 5.));
172  add(h, new TH1F("highpurityTrackFraction","fraction of high purity tracks",20, 0., 1.));
173  add(h, new TH2F("trkchi2vsndof","vertices chi2 vs ndof",50, 0., 100., 50, 0., 200.));
174  add(h, new TH1F("trkchi2overndof","vertices chi2 / ndof",50, 0., 5.));
175  // two track vertices
176  add(h,new TH2F("2trkchi2vsndof","two-track vertices chi2 vs ndof",40, 0., 10., 20, 0., 20.));
177  add(h,new TH1F("2trkmassSS","two-track vertices mass (same sign)",100, 0., 2.));
178  add(h,new TH1F("2trkmassOS","two-track vertices mass (opposite sign)",100, 0., 2.));
179  add(h,new TH1F("2trkdphi","two-track vertices delta-phi",360, 0, 2*M_PI));
180  add(h,new TH1F("2trkseta","two-track vertices sum-eta",50, -2., 2.));
181  add(h,new TH1F("2trkdphicurl","two-track vertices delta-phi (sum eta<0.1)",360, 0, 2*M_PI));
182  add(h,new TH1F("2trksetacurl","two-track vertices sum-eta (delta-phi<0.1)",50, -2., 2.));
183  add(h,new TH1F("2trkdetaOS","two-track vertices delta-eta (same sign)",50, -0.5, 0.5));
184  add(h,new TH1F("2trkdetaSS","two-track vertices delta-eta (opposite sign)",50, -0.5, 0.5));
185  // two track PU vertices
186  add(h,new TH1F("2trkmassSSPU","two-track vertices mass (same sign)",100, 0., 2.));
187  add(h,new TH1F("2trkmassOSPU","two-track vertices mass (opposite sign)",100, 0., 2.));
188  add(h,new TH1F("2trkdphiPU","two-track vertices delta-phi",360, 0, 2*M_PI));
189  add(h,new TH1F("2trksetaPU","two-track vertices sum-eta",50, -2., 2.));
190  add(h,new TH1F("2trkdphicurlPU","two-track vertices delta-phi (sum eta<0.1)",360, 0, 2*M_PI));
191  add(h,new TH1F("2trksetacurlPU","two-track vertices sum-eta (delta-phi<0.1)",50, -2., 2.));
192  add(h,new TH1F("2trkdetaOSPU","two-track vertices delta-eta (same sign)",50, -0.5, 0.5));
193  add(h,new TH1F("2trkdetaSSPU","two-track vertices delta-eta (opposite sign)",50, -0.5, 0.5));
194  // three track vertices
195  add(h,new TH2F("2trkchi2vsndof","two-track vertices chi2 vs ndof",40, 0., 10., 20, 0., 20.));
196  add(h,new TH2F("3trkchi2vsndof","three-track vertices chi2 vs ndof",40, 0., 10., 20, 0., 20.));
197  add(h,new TH2F("4trkchi2vsndof","four-track vertices chi2 vs ndof",40, 0., 10., 20, 0., 20.));
198  add(h,new TH2F("5trkchi2vsndof","five-track vertices chi2 vs ndof",40, 0., 10., 20, 0., 20.));
199  // same for fakes
200  add(h,new TH2F("fake2trkchi2vsndof","fake two-track vertices chi2 vs ndof",40, 0., 10., 20, 0., 20.));
201  add(h,new TH2F("fake3trkchi2vsndof","fake three-track vertices chi2 vs ndof",40, 0., 10., 20, 0., 20.));
202  add(h,new TH2F("fake4trkchi2vsndof","fake four-track vertices chi2 vs ndof",40, 0., 10., 20, 0., 20.));
203  add(h,new TH2F("fake5trkchi2vsndof","fake five-track vertices chi2 vs ndof",40, 0., 10., 20, 0., 20.));
204  h["resxr"] = new TH1F("resxr","relative residual x",100,-0.04,0.04);
205  h["resyr"] = new TH1F("resyr","relative residual y",100,-0.04,0.04);
206  h["reszr"] = new TH1F("reszr","relative residual z",100,-0.1,0.1);
207  h["pullxr"] = new TH1F("pullxr","relative pull x",100,-25.,25.);
208  h["pullyr"] = new TH1F("pullyr","relative pull y",100,-25.,25.);
209  h["pullzr"] = new TH1F("pullzr","relative pull z",100,-25.,25.);
210  h["vtxprob"] = new TH1F("vtxprob","chisquared probability",100,0.,1.);
211  h["eff"] = new TH1F("eff","efficiency",2, -0.5, 1.5);
212  h["efftag"] = new TH1F("efftag","efficiency tagged vertex",2, -0.5, 1.5);
213  h["zdistancetag"] = new TH1F("zdistancetag","z-distance between tagged and generated",100, -0.1, 0.1);
214  h["abszdistancetag"] = new TH1F("abszdistancetag","z-distance between tagged and generated",1000, 0., 1.0);
215  h["abszdistancetagcum"] = new TH1F("abszdistancetagcum","z-distance between tagged and generated",1000, 0., 1.0);
216  h["puritytag"] = new TH1F("puritytag","purity of primary vertex tags",2, -0.5, 1.5);
217  h["effvsptsq"] = new TProfile("effvsptsq","efficiency vs ptsq",20, 0., 10000., 0, 1.);
218  h["effvsnsimtrk"] = new TProfile("effvsnsimtrk","efficiency vs # simtracks",50, 0., 50., 0, 1.);
219  h["effvsnrectrk"] = new TProfile("effvsnrectrk","efficiency vs # rectracks",50, 0., 50., 0, 1.);
220  h["effvsnseltrk"] = new TProfile("effvsnseltrk","efficiency vs # selected tracks",50, 0., 50., 0, 1.);
221  h["effvsz"] = new TProfile("effvsz","efficiency vs z",20, -20., 20., 0, 1.);
222  h["effvsz2"] = new TProfile("effvsz2","efficiency vs z (2mm)",20, -20., 20., 0, 1.);
223  h["effvsr"] = new TProfile("effvsr","efficiency vs r",20, 0., 1., 0, 1.);
224  h["xresvsntrk"] = new TProfile("xresvsntrk","xresolution vs # vertex tracks",40, 0., 200., 0, 0.01);
225  h["yresvsntrk"] = new TProfile("yresvsntrk","yresolution vs # vertex tracks",40, 0., 200., 0, 0.01);
226  h["zresvsntrk"] = new TProfile("zresvsntrk","zresolution vs # vertex tracks",40, 0., 200., 0, 0.01);
227  h["cpuvsntrk"] = new TProfile("cpuvsntrk","cpu time vs # of fitted tracks",40, 0., 200., 0, 200.);
228  h["cpucluvsntrk"] = new TProfile("cpucluvsntrk","clustering cpu time # of tracks",40, 0., 200., 0, 10.);
229  h["cpufit"] = new TH1F("cpufit","cpu time for fitting",100, 0., 200.);
230  h["cpuclu"] = new TH1F("cpuclu","cpu time for clustering",100, 0., 200.);
231  h["nbtksinvtx2"] = new TH1F("nbtksinvtx2","reconstructed tracks in vertex",40,0.,200.);
232  h["nbtksinvtxPU2"] = new TH1F("nbtksinvtxPU2","reconstructed tracks in vertex",40,0.,200.);
233  h["nbtksinvtxTag2"] = new TH1F("nbtksinvtxTag2","reconstructed tracks in vertex",40,0.,200.);
234 
235  h["xrec"] = new TH1F("xrec","reconstructed x",100,-0.1,0.1);
236  h["yrec"] = new TH1F("yrec","reconstructed y",100,-0.1,0.1);
237  h["zrec"] = new TH1F("zrec","reconstructed z",100,-20.,20.);
238  h["err1"] = new TH1F("err1","error 1",100,0.,0.1);
239  h["err2"] = new TH1F("err2","error 2",100,0.,0.1);
240  h["errx"] = new TH1F("errx","error x",100,0.,0.1);
241  h["erry"] = new TH1F("erry","error y",100,0.,0.1);
242  h["errz"] = new TH1F("errz","error z",100,0.,2.0);
243  h["errz1"] = new TH1F("errz1","error z",100,0.,0.2);
244 
245  h["zrecNt100"] = new TH1F("zrecNt100","reconstructed z for high multiplicity events",80,-40.,40.);
246  add(h, new TH2F("zrecvsnt","reconstructed z vs number of tracks",100,-50., 50., 20, 0., 200.));
247  add(h, new TH2F("xyrec","reconstructed xy",100, -4., 4., 100, -4., 4.));
248  h["xrecBeam"] = new TH1F("xrecBeam","reconstructed x - beam x",100,-0.1,0.1);
249  h["yrecBeam"] = new TH1F("yrecBeam","reconstructed y - beam y",100,-0.1,0.1);
250  h["zrecBeam"] = new TH1F("zrecBeam","reconstructed z - beam z",100,-20.,20.);
251  h["xrecBeamvsz"] = new TH2F("xrecBeamvsz","reconstructed x - beam x vs z", 20, -20., 20.,100,-0.1,0.1);
252  h["yrecBeamvsz"] = new TH2F("yrecBeamvsz","reconstructed y - beam y vs z", 20, -20., 20.,100,-0.1,0.1);
253  h["xrecBeamvszprof"] = new TProfile("xrecBeamvszprof","reconstructed x - beam x vs z-z0", 20, -20., 20.,-0.1,0.1);
254  h["yrecBeamvszprof"] = new TProfile("yrecBeamvszprof","reconstructed y - beam y vs z-z0", 20, -20., 20.,-0.1,0.1);
255  add(h, new TH2F("xrecBeamvsdxXBS","reconstructed x - beam x vs resolution",10,0., 0.02, 100, -0.1,0.1)); // just a test
256  add(h, new TH2F("yrecBeamvsdyXBS","reconstructed z - beam z vs resolution",10,0., 0.02, 100, -0.1,0.1));
257  add(h, new TH2F("xrecBeamvsdx","reconstructed x - beam x vs resolution",10,0., 0.02, 100, -0.1,0.1));
258  add(h, new TH2F("yrecBeamvsdy","reconstructed z - beam z vs resolution",10,0., 0.02, 100, -0.1,0.1));
259  add(h, new TH2F("xrecBeamvsdxR2","reconstructed x - beam x vs resolution",20,0., 0.04, 100, -0.1,0.1));
260  add(h, new TH2F("yrecBeamvsdyR2","reconstructed z - beam z vs resolution",20,0., 0.04, 100, -0.1,0.1));
261  h["xrecBeamvsdxprof"] = new TProfile("xrecBeamvsdxprof","reconstructed x - beam x vs resolution",10, 0., 0.04,-0.1,0.1 );
262  h["yrecBeamvsdyprof"] = new TProfile("yrecBeamvsdyprof","reconstructed y - beam y vs resolution",10, 0., 0.04,-0.1,0.1 );
263  add(h, new TProfile("xrecBeam2vsdx2prof","reconstructed x - beam x vs resolution",10,0., 0.002, 0., 0.01));
264  add(h, new TProfile("yrecBeam2vsdy2prof","reconstructed y - beam y vs resolution",10,0., 0.002, 0., 0.01));
265  add(h,new TH2F("xrecBeamvsdx2","reconstructed x - beam x vs resolution",10,0., 0.002, 100, -0.01, 0.01));
266  add(h,new TH2F("yrecBeamvsdy2","reconstructed y - beam y vs resolution",10,0., 0.002, 100, -0.01, 0.01));
267  h["xrecb"] = new TH1F("xrecb","reconstructed x - beam x",100,-0.01,0.01);
268  h["yrecb"] = new TH1F("yrecb","reconstructed y - beam y",100,-0.01,0.01);
269  h["zrecb"] = new TH1F("zrecb","reconstructed z - beam z",100,-20.,20.);
270  h["xrec1"] = new TH1F("xrec1","reconstructed x",100,-4,4);
271  h["yrec1"] = new TH1F("yrec1","reconstructed y",100,-4,4); // should match the sim histos
272  h["zrec1"] = new TH1F("zrec1","reconstructed z",100,-80.,80.);
273  h["xrec2"] = new TH1F("xrec2","reconstructed x",100,-1,1);
274  h["yrec2"] = new TH1F("yrec2","reconstructed y",100,-1,1);
275  h["zrec2"] = new TH1F("zrec2","reconstructed z",100,-40.,40.);
276  h["xrec3"] = new TH1F("xrec3","reconstructed x",100,-0.1,0.1);
277  h["yrec3"] = new TH1F("yrec3","reconstructed y",100,-0.1,0.1);
278  h["zrec3"] = new TH1F("zrec3","reconstructed z",100,-20.,20.);
279  add(h, new TH1F("xrecBeamPull","normalized residuals reconstructed x - beam x",100,-20,20));
280  add(h, new TH1F("yrecBeamPull","normalized residuals reconstructed y - beam y",100,-20,20));
281  add(h, new TH1F("zdiffrec","z-distance between vertices",200,-20., 20.));
282  add(h, new TH1F("zdiffrec2","z-distance between ndof>2 vertices",200,-20., 20.));
283  add(h, new TH1F("zdiffrec4","z-distance between ndof>4 vertices",200,-20., 20.));
284  add(h, new TH1F("zdiffrec8","z-distance between ndof>8 vertices",200,-20., 20.));
285  add(h, new TH2F("zvszrec2","z positions of multiple vertices",200,-20., 20., 200,-20., 20.));
286  add(h, new TH2F("pzvspz2","prob(z) of multiple vertices",100, 0.,1.,100,0., 1.));
287  add(h, new TH2F("zvszrec4","z positions of multiple vertices",100,-20., 20., 100,-20., 20.));
288  add(h, new TH2F("pzvspz4","prob(z) of multiple vertices",100, 0.,1.,100,0., 1.));
289  add(h, new TH2F("zdiffvsz","z-distance vs z",100,-10.,10.,30,-15.,15.));
290  add(h, new TH2F("zdiffvsz4","z-distance vs z (ndof>4)",100,-10.,10.,30,-15.,15.));
291  add(h, new TProfile("eff0vsntrec","efficiency vs # reconstructed tracks",50, 0., 50., 0, 1.));
292  add(h, new TProfile("eff0vsntsel","efficiency vs # selected tracks",50, 0., 50., 0, 1.));
293  add(h, new TProfile("eff0ndof0vsntsel","efficiency (ndof>0) vs # selected tracks",50, 0., 50., 0, 1.));
294  add(h, new TProfile("eff0ndof8vsntsel","efficiency (ndof>8) vs # selected tracks",50, 0., 50., 0, 1.));
295  add(h, new TProfile("eff0ndof2vsntsel","efficiency (ndof>2) vs # selected tracks",50, 0., 50., 0, 1.));
296  add(h, new TProfile("eff0ndof4vsntsel","efficiency (ndof>4) vs # selected tracks",50, 0., 50., 0, 1.));
297  add(h, new TH1F("xbeamPUcand","x - beam of PU candidates (ndof>4)",100,-1., 1.));
298  add(h, new TH1F("ybeamPUcand","y - beam of PU candidates (ndof>4)",100,-1., 1.));
299  add(h, new TH1F("xbeamPullPUcand","x - beam pull of PU candidates (ndof>4)",100,-20., 20.));
300  add(h, new TH1F("ybeamPullPUcand","y - beam pull of PU candidates (ndof>4)",100,-20., 20.));
301  add(h, new TH1F("ndofOverNtk","ndof / ntk of ndidates (ndof>4)",100,0., 2.));
302  add(h, new TH1F("ndofOverNtkPUcand","ndof / ntk of ndidates (ndof>4)",100,0., 2.));
303  add(h, new TH1F("zPUcand","z positions of PU candidates (all)",100,-20., 20.));
304  add(h, new TH1F("zPUcand2","z positions of PU candidates (ndof>2)",100,-20., 20.));
305  add(h, new TH1F("zPUcand4","z positions of PU candidates (ndof>4)",100,-20., 20.));
306  add(h, new TH1F("ndofPUcand","ndof of PU candidates (all)",50,0., 100.));
307  add(h, new TH1F("ndofPUcand2","ndof of PU candidates (ndof>2)",50,0., 100.));
308  add(h, new TH1F("ndofPUcand4","ndof of PU candidates (ndof>4)",50,0., 100.));
309  add(h, new TH1F("ndofnr2","second highest ndof",500,0., 100.));
310  add(h, new TH1F("ndofnr2d1cm","second highest ndof (dz>1cm)",500,0., 100.));
311  add(h, new TH1F("ndofnr2d2cm","second highest ndof (dz>2cm)",500,0., 100.));
312 
313  h["nrecvtx"] = new TH1F("nrecvtx","# of reconstructed vertices", 50, -0.5, 49.5);
314  h["nrecvtx8"] = new TH1F("nrecvtx8","# of reconstructed vertices with ndof>8", 50, -0.5, 49.5);
315  h["nrecvtx2"] = new TH1F("nrecvtx2","# of reconstructed vertices with ndof>2", 50, -0.5, 49.5);
316  h["nrecvtx4"] = new TH1F("nrecvtx4","# of reconstructed vertices with ndof>4", 50, -0.5, 49.5);
317  h["nrectrk"] = new TH1F("nrectrk","# of reconstructed tracks", 100, -0.5, 99.5);
318  add(h, new TH1F("nsimtrk","# of simulated tracks", 100, -0.5, 99.5));
319  add(h, new TH1F("nsimtrkSignal","# of simulated tracks (Signal)", 100, -0.5, 99.5));
320  add(h, new TH1F("nsimtrkPU","# of simulated tracks (PU)", 100, -0.5, 99.5));
321  h["nsimtrk"]->StatOverflows(kTRUE);
322  h["nsimtrkPU"]->StatOverflows(kTRUE);
323  h["nsimtrkSignal"]->StatOverflows(kTRUE);
324  h["xrectag"] = new TH1F("xrectag","reconstructed x, signal vtx",100,-0.05,0.05);
325  h["yrectag"] = new TH1F("yrectag","reconstructed y, signal vtx",100,-0.05,0.05);
326  h["zrectag"] = new TH1F("zrectag","reconstructed z, signal vtx",100,-20.,20.);
327  h["nrectrk0vtx"] = new TH1F("nrectrk0vtx","# rec tracks no vertex ",100,-0.5, 99.5);
328  h["nseltrk0vtx"] = new TH1F("nseltrk0vtx","# rec tracks no vertex ",100,-0.5, 99.5);
329  h["nrecsimtrk"] = new TH1F("nrecsimtrk","# rec tracks matched to sim tracks in vertex",100,-0.5, 99.5);
330  h["nrecnosimtrk"] = new TH1F("nrecsimtrk","# rec tracks not matched to sim tracks in vertex",100,-0.5, 99.5);
331  h["trackAssEffvsPt"] = new TProfile("trackAssEffvsPt","track association efficiency vs pt",20, 0., 100., 0, 1.);
332 
333  // cluster stuff
334  h["nseltrk"] = new TH1F("nseltrk","# of reconstructed tracks selected for PV", 100, -0.5, 99.5);
335  h["nclutrkall"] = new TH1F("nclutrkall","# of reconstructed tracks in clusters", 100, -0.5, 99.5);
336  h["nclutrkvtx"] = new TH1F("nclutrkvtx","# of reconstructed tracks in clusters of reconstructed vertices", 100, -0.5, 99.5);
337  h["nclu"] = new TH1F("nclu","# of clusters", 100, -0.5, 99.5);
338  h["nclu0vtx"] = new TH1F("nclu0vtx","# of clusters in events with no PV", 100, -0.5, 99.5);
339  h["zlost1"] = new TH1F("zlost1","z of lost vertices (bad z)", 100, -20., 20.);
340  h["zlost2"] = new TH1F("zlost2","z of lost vertices (no matching cluster)", 100, -20., 20.);
341  h["zlost3"] = new TH1F("zlost3","z of lost vertices (vertex too far from beam)", 100, -20., 20.);
342  h["zlost4"] = new TH1F("zlost4","z of lost vertices (invalid vertex)", 100, -20., 20.);
343  h["selstat"] = new TH1F("selstat","selstat", 5, -2.5, 2.5);
344 
345  // properties of fake vertices (MC only)_
346  add(h, new TH1F("fakeVtxZNdofgt05","z of fake vertices with ndof>0.5", 100, -20., 20.));
347  add(h, new TH1F("fakeVtxZNdofgt2","z of fake vertices with ndof>2", 100, -20., 20.));
348  add(h, new TH1F("fakeVtxZ","z of fake vertices", 100, -20., 20.));
349  add(h, new TH1F("fakeVtxNdof","ndof of fake vertices", 500,0., 100.));
350  add(h,new TH1F("fakeVtxNtrk","number of tracks in fake vertex",20,-0.5, 19.5));
351  add(h,new TH1F("matchedVtxNdof","ndof of matched vertices", 500,0., 100.));
352 
353  // histograms of track quality (Data and MC)
354  string types[] = {"all","sel","bachelor","sellost","wgt05","wlt05","M","tagged","untagged","ndof4","PUcand","PUfake"};
355  for(int t=0; t<12; t++){
356  add(h, new TH1F(("rapidity_"+types[t]).c_str(),"rapidity ",100,-3., 3.));
357  h["z0_"+types[t]] = new TH1F(("z0_"+types[t]).c_str(),"z0 ",80,-40., 40.);
358  h["phi_"+types[t]] = new TH1F(("phi_"+types[t]).c_str(),"phi ",80,-3.14159, 3.14159);
359  h["eta_"+types[t]] = new TH1F(("eta_"+types[t]).c_str(),"eta ",80,-4., 4.);
360  h["pt_"+types[t]] = new TH1F(("pt_"+types[t]).c_str(),"pt ",100,0., 20.);
361  h["found_"+types[t]] = new TH1F(("found_"+types[t]).c_str(),"found hits",20, 0., 20.);
362  h["lost_"+types[t]] = new TH1F(("lost_"+types[t]).c_str(),"lost hits",20, 0., 20.);
363  h["nchi2_"+types[t]] = new TH1F(("nchi2_"+types[t]).c_str(),"normalized track chi2",100, 0., 20.);
364  h["rstart_"+types[t]] = new TH1F(("rstart_"+types[t]).c_str(),"start radius",100, 0., 20.);
365  h["tfom_"+types[t]] = new TH1F(("tfom_"+types[t]).c_str(),"track figure of merit",100, 0., 100.);
366  h["expectedInner_"+types[t]] = new TH1F(("expectedInner_"+types[t]).c_str(),"expected inner hits ",10, 0., 10.);
367  h["expectedOuter_"+types[t]] = new TH1F(("expectedOuter_"+types[t]).c_str(),"expected outer hits ",10, 0., 10.);
368  h["logtresxy_"+types[t]] = new TH1F(("logtresxy_"+types[t]).c_str(),"log10(track r-phi resolution/um)",100, 0., 5.);
369  h["logtresz_"+types[t]] = new TH1F(("logtresz_"+types[t]).c_str(),"log10(track z resolution/um)",100, 0., 5.);
370  h["tpullxy_"+types[t]] = new TH1F(("tpullxy_"+types[t]).c_str(),"track r-phi pull",100, -10., 10.);
371  add(h, new TH2F( ("lvseta_"+types[t]).c_str(),"cluster length vs eta",60,-3., 3., 20, 0., 20));
372  add(h, new TH2F( ("lvstanlambda_"+types[t]).c_str(),"cluster length vs tan lambda",60,-6., 6., 20, 0., 20));
373  add(h, new TH1F( ("restrkz_"+types[t]).c_str(),"z-residuals (track vs vertex)", 200, -5., 5.));
374  add(h, new TH2F( ("restrkzvsphi_"+types[t]).c_str(),"z-residuals (track - vertex)", 12,-3.14159,3.14159,100, -5., 5.));
375  add(h, new TH2F( ("restrkzvseta_"+types[t]).c_str(),"z-residuals (track - vertex)", 12,-3.,3.,200, -5., 5.));
376  add(h, new TH2F( ("pulltrkzvsphi_"+types[t]).c_str(),"normalized z-residuals (track - vertex)", 12,-3.14159,3.14159,100, -5., 5.));
377  add(h, new TH2F( ("pulltrkzvseta_"+types[t]).c_str(),"normalized z-residuals (track - vertex)", 12,-3.,3.,100, -5., 5.));
378  add(h, new TH1F( ("pulltrkz_"+types[t]).c_str(),"normalized z-residuals (track vs vertex)", 100, -5., 5.));
379  add(h, new TH1F( ("sigmatrkz0_"+types[t]).c_str(),"z-resolution (excluding beam)", 100, 0., 5.));
380  add(h, new TH1F( ("sigmatrkz_"+types[t]).c_str(),"z-resolution (including beam)", 100,0., 5.));
381  add(h, new TH1F( ("nbarrelhits_"+types[t]).c_str(),"number of pixel barrel hits", 10, 0., 10.));
382  add(h, new TH1F( ("nbarrelLayers_"+types[t]).c_str(),"number of pixel barrel layers", 10, 0., 10.));
383  add(h, new TH1F( ("nPxLayers_"+types[t]).c_str(),"number of pixel layers (barrel+endcap)", 10, 0., 10.));
384  add(h, new TH1F( ("nSiLayers_"+types[t]).c_str(),"number of Tracker layers ", 20, 0., 20.));
385  add(h, new TH1F( ("trackAlgo_"+types[t]).c_str(),"track algorithm ", 30, 0., 30.));
386  add(h, new TH1F( ("trackQuality_"+types[t]).c_str(),"track quality ", 7, -1., 6.));
387  }
388  add(h, new TH1F("trackWt","track weight in vertex",100,0., 1.));
389 
390  h["nrectrk"]->StatOverflows(kTRUE);
391  h["nrectrk"]->StatOverflows(kTRUE);
392  h["nrectrk0vtx"]->StatOverflows(kTRUE);
393  h["nseltrk0vtx"]->StatOverflows(kTRUE);
394  h["nrecsimtrk"]->StatOverflows(kTRUE);
395  h["nrecnosimtrk"]->StatOverflows(kTRUE);
396  h["nseltrk"]->StatOverflows(kTRUE);
397  h["nbtksinvtx"]->StatOverflows(kTRUE);
398  h["nbtksinvtxPU"]->StatOverflows(kTRUE);
399  h["nbtksinvtxTag"]->StatOverflows(kTRUE);
400  h["nbtksinvtx2"]->StatOverflows(kTRUE);
401  h["nbtksinvtxPU2"]->StatOverflows(kTRUE);
402  h["nbtksinvtxTag2"]->StatOverflows(kTRUE);
403 
404  // pile-up and track assignment related histograms (MC)
405  h["npu0"] =new TH1F("npu0","Number of simulated vertices",40,0.,40.);
406  h["npu1"] =new TH1F("npu1","Number of simulated vertices with >0 track",40,0.,40.);
407  h["npu2"] =new TH1F("npu2","Number of simulated vertices with >1 track",40,0.,40.);
408  h["nrecv"] =new TH1F("nrecv","# of reconstructed vertices", 40, 0, 40);
409  add(h,new TH2F("nrecvsnpu","#rec vertices vs number of sim vertices with >0 tracks", 40, 0., 40, 40, 0, 40));
410  add(h,new TH2F("nrecvsnpu2","#rec vertices vs number of sim vertices with >1 tracks", 40, 0., 40, 40, 0, 40));
411  add(h,new TH1F("sumpt","sumpt of simulated tracks",100,0.,100.));
412  add(h,new TH1F("sumptSignal","sumpt of simulated tracks in Signal events",100,0.,200.));
413  add(h,new TH1F("sumptPU","sumpt of simulated tracks in PU events",100,0.,200.));
414  add(h,new TH1F("sumpt2rec","sumpt2 of reconstructed and matched tracks",100,0.,100.));
415  add(h,new TH1F("sumpt2","sumpt2 of simulated tracks",100,0.,100.));
416  add(h,new TH1F("sumpt2Signal","sumpt2 of simulated tracks in Signal events",100,0.,200.));
417  add(h,new TH1F("sumpt2PU","sumpt2 of simulated tracks in PU events",100,0.,200.));
418  add(h,new TH1F("sumpt2rec","sumpt2 of reconstructed and matched tracks",100,0.,100.));
419  add(h,new TH1F("sumpt2recSignal","sumpt2 of reconstructed and matched tracks in Signal events",100,0.,200.));
420  add(h,new TH1F("sumpt2recPU","sumpt2 of reconstructed and matched tracks in PU events",100,0.,200.));
421  add(h,new TH1F("nRecTrkInSimVtx","number of reco tracks matched to sim-vertex", 101, 0., 100));
422  add(h,new TH1F("nRecTrkInSimVtxSignal","number of reco tracks matched to signal sim-vertex", 101, 0., 100));
423  add(h,new TH1F("nRecTrkInSimVtxPU","number of reco tracks matched to PU-vertex", 101, 0., 100));
424  add(h,new TH1F("nPrimRecTrkInSimVtx","number of reco primary tracks matched to sim-vertex", 101, 0., 100));
425  add(h,new TH1F("nPrimRecTrkInSimVtxSignal","number of reco primary tracks matched to signal sim-vertex", 101, 0., 100));
426  add(h,new TH1F("nPrimRecTrkInSimVtxPU","number of reco primary tracks matched to PU-vertex", 101, 0., 100));
427  // obsolete, scheduled for removal
428  add(h,new TH1F("recPurity","track purity of reconstructed vertices", 101, 0., 1.01));
429  add(h,new TH1F("recPuritySignal","track purity of reconstructed Signal vertices", 101, 0., 1.01));
430  add(h,new TH1F("recPurityPU","track purity of reconstructed PU vertices", 101, 0., 1.01));
431  // end of obsolete
432  add(h,new TH1F("recmatchPurity","track purity of all vertices", 101, 0., 1.01));
433  add(h,new TH1F("recmatchPurityTag","track purity of tagged vertices", 101, 0., 1.01));
434  add(h,new TH1F("recmatchPurityTagSignal","track purity of tagged Signal vertices", 101, 0., 1.01));
435  add(h,new TH1F("recmatchPurityTagPU","track purity of tagged PU vertices", 101, 0., 1.01));
436  add(h,new TH1F("recmatchPuritynoTag","track purity of untagged vertices", 101, 0., 1.01));
437  add(h,new TH1F("recmatchPuritynoTagSignal","track purity of untagged Signal vertices", 101, 0., 1.01));
438  add(h,new TH1F("recmatchPuritynoTagPU","track purity of untagged PU vertices", 101, 0., 1.01));
439  add(h,new TH1F("recmatchvtxs","number of sim vertices contributing to recvtx", 10, 0., 10.));
440  add(h,new TH1F("recmatchvtxsTag","number of sim vertices contributing to recvtx", 10, 0., 10.));
441  add(h,new TH1F("recmatchvtxsnoTag","number of sim vertices contributing to recvtx", 10, 0., 10.));
442 
443  add(h,new TH1F("trkAssignmentEfficiency", "track to vertex assignment efficiency", 101, 0., 1.01) );
444  add(h,new TH1F("trkAssignmentEfficiencySignal", "track to signal vertex assignment efficiency", 101, 0., 1.01) );
445  add(h,new TH1F("trkAssignmentEfficiencyPU", "track to PU vertex assignment efficiency", 101, 0., 1.01) );
446  add(h,new TH1F("primtrkAssignmentEfficiency", "track to vertex assignment efficiency", 101, 0., 1.01) );
447  add(h,new TH1F("primtrkAssignmentEfficiencySignal", "track to signal vertex assignment efficiency", 101, 0., 1.01) );
448  add(h,new TH1F("primtrkAssignmentEfficiencyPU", "track to PU vertex assignment efficiency", 101, 0., 1.01) );
449  add(h,new TH1F("vtxMultiplicity", "number of rec vertices containg tracks from one true vertex", 10, 0., 10.) );
450  add(h,new TH1F("vtxMultiplicitySignal", "number of rec vertices containg tracks from the Signal Vertex", 10, 0., 10.) );
451  add(h,new TH1F("vtxMultiplicityPU", "number of rec vertices containg tracks from a PU Vertex", 10, 0., 10.) );
452 
453  add(h,new TProfile("vtxFindingEfficiencyVsNtrk","finding efficiency vs number of associated rec tracks",100, 0., 100., 0., 1.) );
454  add(h,new TProfile("vtxFindingEfficiencyVsNtrkSignal","Signal vertex finding efficiency vs number of associated rec tracks",100, 0., 100., 0., 1.) );
455  add(h,new TProfile("vtxFindingEfficiencyVsNtrkPU","PU vertex finding efficiency vs number of associated rec tracks",100, 0., 100., 0., 1.) );
456 
457  add(h,new TH1F("TagVtxTrkPurity","TagVtxTrkPurity",100,0.,1.01));
458  add(h,new TH1F("TagVtxTrkEfficiency","TagVtxTrkEfficiency",100,0.,1.01));
459 
460  add(h,new TH1F("matchVtxFraction","fraction of sim vertex tracks found in a recvertex",101,0,1.01));
461  add(h,new TH1F("matchVtxFractionSignal","fraction of sim vertex tracks found in a recvertex",101,0,1.01));
462  add(h,new TH1F("matchVtxFractionPU","fraction of sim vertex tracks found in a recvertex",101,0,1.01));
463  add(h,new TH1F("matchVtxFractionCum","fraction of sim vertex tracks found in a recvertex",101,0,1.01));
464  add(h,new TH1F("matchVtxFractionCumSignal","fraction of sim vertexs track found in a recvertex",101,0,1.01));
465  add(h,new TH1F("matchVtxFractionCumPU","fraction of sim vertex tracks found in a recvertex",101,0,1.01));
466  add(h,new TH1F("matchVtxEfficiency","efficiency for finding matching rec vertex",2,-0.5,1.5));
467  add(h,new TH1F("matchVtxEfficiencySignal","efficiency for finding matching rec vertex",2,-0.5,1.5));
468  add(h,new TH1F("matchVtxEfficiencyPU","efficiency for finding matching rec vertex",2,-0.5,1.5));
469  add(h,new TH1F("matchVtxEfficiency2","efficiency for finding matching rec vertex (nt>1)",2,-0.5,1.5));
470  add(h,new TH1F("matchVtxEfficiency2Signal","efficiency for finding matching rec vertex (nt>1)",2,-0.5,1.5));
471  add(h,new TH1F("matchVtxEfficiency2PU","efficiency for finding matching rec vertex (nt>1)",2,-0.5,1.5));
472  add(h,new TH1F("matchVtxEfficiency5","efficiency for finding matching rec vertex (purity>0.5)",2,-0.5,1.5));
473  add(h,new TH1F("matchVtxEfficiency5Signal","efficiency for finding matching rec vertex (purity>0.5)",2,-0.5,1.5));
474  add(h,new TH1F("matchVtxEfficiency5PU","efficiency for finding matching rec vertex (purity>0.5)",2,-0.5,1.5));
475 
476  add(h,new TH1F("matchVtxEfficiencyZ","efficiency for finding matching rec vertex within 1 mm",2,-0.5,1.5));
477  add(h,new TH1F("matchVtxEfficiencyZSignal","efficiency for finding matching rec vertex within 1 mm",2,-0.5,1.5));
478  add(h,new TH1F("matchVtxEfficiencyZPU","efficiency for finding matching rec vertex within 1 mm",2,-0.5,1.5));
479 
480  add(h,new TH1F("matchVtxEfficiencyZ1","efficiency for finding matching rec vertex within 1 mm (nt>0)",2,-0.5,1.5));
481  add(h,new TH1F("matchVtxEfficiencyZ1Signal","efficiency for finding matching rec vertex within 1 mm (nt>0)",2,-0.5,1.5));
482  add(h,new TH1F("matchVtxEfficiencyZ1PU","efficiency for finding matching rec vertex within 1 mm (nt>0)",2,-0.5,1.5));
483 
484  add(h,new TH1F("matchVtxEfficiencyZ2","efficiency for finding matching rec vertex within 1 mm (nt>1)",2,-0.5,1.5));
485  add(h,new TH1F("matchVtxEfficiencyZ2Signal","efficiency for finding matching rec vertex within 1 mm (nt>1)",2,-0.5,1.5));
486  add(h,new TH1F("matchVtxEfficiencyZ2PU","efficiency for finding matching rec vertex within 1 mm (nt>1)",2,-0.5,1.5));
487 
488  add(h,new TH1F("matchVtxZ","z distance to matched recvtx",100, -0.1, 0.1));
489  add(h,new TH1F("matchVtxZPU","z distance to matched recvtx",100, -0.1, 0.1));
490  add(h,new TH1F("matchVtxZSignal","z distance to matched recvtx",100, -0.1, 0.1));
491 
492  add(h,new TH1F("matchVtxZCum","z distance to matched recvtx",1001,0, 1.01));
493  add(h,new TH1F("matchVtxZCumSignal","z distance to matched recvtx",1001,0, 1.01));
494  add(h,new TH1F("matchVtxZCumPU","z distance to matched recvtx",1001,0, 1.01));
495 
496  add(h,new TH1F("unmatchedVtx","number of unmatched rec vertices (fakes)",10,0.,10.));
497  add(h,new TH1F("unmatchedVtxFrac","fraction of unmatched rec vertices (fakes)",1000,0.,1.0));
498  add(h,new TH1F("unmatchedVtxZ","z of unmached rec vertices (fakes)",100,-20., 20.));
499  add(h,new TH1F("unmatchedVtxNdof","ndof of unmatched rec vertices (fakes)", 500,0., 100.));
500  add(h,new TH2F("correctlyassigned","pt and eta of correctly assigned tracks", 60, -3., 3., 100, 0, 10.));
501  add(h,new TH2F("misassigned","pt and eta of mis assigned tracks", 60, -3., 3., 100, 0, 10.));
502 
503  //efficiency plots based on mc-true information
504  add(h,new TProfile("effvszsep","efficiency vs true z-separation",500, 0., 10., 0, 1.));
505  add(h,new TProfile("effwodvszsep","efficiency w/o double-counting vs true z-separation",500, 0., 10., 0, 1.));
506  add(h,new TProfile("mergedvszsep","merge rate vs true z-separation",500, 0., 10., 0, 1.));
507  add(h,new TProfile("splitvszsep","split rate vs true z-separation",500, 0., 10., 0, 1.));
508  add(h,new TProfile("tveffvszsep","efficiency vs true z-separation",500, 0., 10., 0, 1.));
509  add(h,new TProfile("tveffwodvszsep","efficiency w/o double-counting vs true z-separation",500, 0., 10., 0, 1.));
510  add(h,new TProfile("tvmergedvszsep","merge rate vs true z-separation",500, 0., 10., 0, 1.));
511 
512  add(h,new TH1F("ptcat","pt of correctly assigned tracks", 100, 0, 10.));
513  add(h,new TH1F("etacat","eta of correctly assigned tracks", 60, -3., 3.));
514  add(h,new TH1F("phicat","phi of correctly assigned tracks", 100, -3.14159, 3.14159));
515  add(h,new TH1F("dzcat","dz of correctly assigned tracks", 100, 0., 1.));
516 
517  add(h,new TH1F("ptmis","pt of mis-assigned tracks", 100, 0, 10.));
518  add(h,new TH1F("etamis","eta of mis-assigned tracks", 60, -3., 3.));
519  add(h,new TH1F("phimis","phi of mis-assigned tracks",100, -3.14159, 3.14159));
520  add(h,new TH1F("dzmis","dz of mis-assigned tracks", 100, 0., 1.));
521 
522 
523  add(h,new TH1F("Tc","Tc computed with Truth matched Reco Tracks",100,0.,20.));
524  add(h,new TH1F("TcSignal","Tc of signal vertices computed with Truth matched Reco Tracks",100,0.,20.));
525  add(h,new TH1F("TcPU","Tc of PU vertices computed with Truth matched Reco Tracks",100,0.,20.));
526 
527  add(h,new TH1F("logTc","log Tc computed with Truth matched Reco Tracks",100,-2.,8.));
528  add(h,new TH1F("logTcSignal","log Tc of signal vertices computed with Truth matched Reco Tracks",100,-2.,8.));
529  add(h,new TH1F("logTcPU","log Tc of PU vertices computed with Truth matched Reco Tracks",100,-2.,8.));
530 
531  add(h,new TH1F("xTc","Tc of merged clusters",100,0.,20.));
532  add(h,new TH1F("xTcSignal","Tc of signal vertices merged with PU",100,0.,20.));
533  add(h,new TH1F("xTcPU","Tc of merged PU vertices",100,0.,20.));
534 
535  add(h,new TH1F("logxTc","log Tc merged vertices",100,-2.,8.));
536  add(h,new TH1F("logxTcSignal","log Tc of signal vertices merged with PU",100,-2.,8.));
537  add(h,new TH1F("logxTcPU","log Tc of merged PU vertices ",100,-2.,8.));
538 
539  add(h,new TH1F("logChisq","Chisq/ntrk computed with Truth matched Reco Tracks",100,-2.,8.));
540  add(h,new TH1F("logChisqSignal","Chisq/ntrk of signal vertices computed with Truth matched Reco Tracks",100,-2.,8.));
541  add(h,new TH1F("logChisqPU","Chisq/ntrk of PU vertices computed with Truth matched Reco Tracks",100,-2.,8.));
542 
543  add(h,new TH1F("logxChisq","Chisq/ntrk of merged clusters",100,-2.,8.));
544  add(h,new TH1F("logxChisqSignal","Chisq/ntrk of signal vertices merged with PU",100,-2.,8.));
545  add(h,new TH1F("logxChisqPU","Chisq/ntrk of merged PU vertices",100,-2.,8.));
546 
547  add(h,new TH1F("Chisq","Chisq/ntrk computed with Truth matched Reco Tracks",100,0.,20.));
548  add(h,new TH1F("ChisqSignal","Chisq/ntrk of signal vertices computed with Truth matched Reco Tracks",100,0.,20.));
549  add(h,new TH1F("ChisqPU","Chisq/ntrk of PU vertices computed with Truth matched Reco Tracks",100,0.,20.));
550 
551  add(h,new TH1F("xChisq","Chisq/ntrk of merged clusters",100,0.,20.));
552  add(h,new TH1F("xChisqSignal","Chisq/ntrk of signal vertices merged with PU",100,0.,20.));
553  add(h,new TH1F("xChisqPU","Chisq/ntrk of merged PU vertices",100,0.,20.));
554 
555  add(h,new TH1F("dzmax","dzmax computed with Truth matched Reco Tracks",100,0.,2.));
556  add(h,new TH1F("dzmaxSignal","dzmax of signal vertices computed with Truth matched Reco Tracks",100,0.,2.));
557  add(h,new TH1F("dzmaxPU","dzmax of PU vertices computed with Truth matched Reco Tracks",100,0.,2.));
558 
559  add(h,new TH1F("xdzmax","dzmax of merged clusters",100,0.,2.));
560  add(h,new TH1F("xdzmaxSignal","dzmax of signal vertices merged with PU",100,0.,2.));
561  add(h,new TH1F("xdzmaxPU","dzmax of merged PU vertices",100,0.,2.));
562 
563  add(h,new TH1F("dztrim","dzmax computed with Truth matched Reco Tracks",100,0.,2.));
564  add(h,new TH1F("dztrimSignal","dzmax of signal vertices computed with Truth matched Reco Tracks",100,0.,2.));
565  add(h,new TH1F("dztrimPU","dzmax of PU vertices computed with Truth matched Reco Tracks",100,0.,2.));
566 
567  add(h,new TH1F("xdztrim","dzmax of merged clusters",100,0.,2.));
568  add(h,new TH1F("xdztrimSignal","dzmax of signal vertices merged with PU",100,0.,2.));
569  add(h,new TH1F("xdztrimPU","dzmax of merged PU vertices",100,0.,2.));
570 
571  add(h,new TH1F("m4m2","m4m2 computed with Truth matched Reco Tracks",100,0.,100.));
572  add(h,new TH1F("m4m2Signal","m4m2 of signal vertices computed with Truth matched Reco Tracks",100,0.,100.));
573  add(h,new TH1F("m4m2PU","m4m2 of PU vertices computed with Truth matched Reco Tracks",100,0.,100.));
574 
575  add(h,new TH1F("xm4m2","m4m2 of merged clusters",100,0.,100.));
576  add(h,new TH1F("xm4m2Signal","m4m2 of signal vertices merged with PU",100,0.,100.));
577  add(h,new TH1F("xm4m2PU","m4m2 of merged PU vertices",100,0.,100.));
578 
579  return h;
580 }
581 
582 
583 //
584 // member functions
585 //
587  std::cout << " PrimaryVertexAnalyzer4PU::beginJob conversion from sim units to rec units is " << simUnit_ << std::endl;
588 
589  rootFile_->cd();
590 
591  TDirectory *noBS = rootFile_->mkdir("noBS");
592  noBS->cd();
594  for(std::map<std::string,TH1*>::const_iterator hist=hnoBS.begin(); hist!=hnoBS.end(); hist++){
595  hist->second->SetDirectory(noBS);
596  }
597 
598  TDirectory *withBS = rootFile_->mkdir("BS");
599  withBS->cd();
601  for(std::map<std::string,TH1*>::const_iterator hist=hBS.begin(); hist!=hBS.end(); hist++){
602  hist->second->SetDirectory(withBS);
603  }
604 
605  TDirectory *DA = rootFile_->mkdir("DA");
606  DA->cd();
608  for(std::map<std::string,TH1*>::const_iterator hist=hDA.begin(); hist!=hDA.end(); hist++){
609  hist->second->SetDirectory(DA);
610  }
611 
612  rootFile_->cd();
613  hsimPV["rapidity"] = new TH1F("rapidity","rapidity ",100,-10., 10.);
614  hsimPV["chRapidity"] = new TH1F("chRapidity","charged rapidity ",100,-10., 10.);
615  hsimPV["recRapidity"] = new TH1F("recRapidity","reconstructed rapidity ",100,-10., 10.);
616  hsimPV["pt"] = new TH1F("pt","pt ",100,0., 20.);
617 
618  hsimPV["xsim"] = new TH1F("xsim","simulated x",100,-0.01,0.01); // 0.01cm = 100 um
619  hsimPV["ysim"] = new TH1F("ysim","simulated y",100,-0.01,0.01);
620  hsimPV["zsim"] = new TH1F("zsim","simulated z",100,-20.,20.);
621 
622  hsimPV["xsim1"] = new TH1F("xsim1","simulated x",100,-4.,4.);
623  hsimPV["ysim1"] = new TH1F("ysim1","simulated y",100,-4.,4.);
624  hsimPV["zsim1"] = new TH1F("zsim1","simulated z",100,-40.,40.);
625 
626  add(hsimPV, new TH1F("xsim2PU","simulated x (Pile-up)",100,-1.,1.));
627  add(hsimPV, new TH1F("ysim2PU","simulated y (Pile-up)",100,-1.,1.));
628  add(hsimPV, new TH1F("zsim2PU","simulated z (Pile-up)",100,-20.,20.));
629  add(hsimPV, new TH1F("xsim2Signal","simulated x (Signal)",100,-1.,1.));
630  add(hsimPV, new TH1F("ysim2Signal","simulated y (Signal)",100,-1.,1.));
631  add(hsimPV, new TH1F("zsim2Signal","simulated z (Signal)",100,-20.,20.));
632 
633  hsimPV["xsim2"] = new TH1F("xsim2","simulated x",100,-1,1); // 0.01cm = 100 um
634  hsimPV["ysim2"] = new TH1F("ysim2","simulated y",100,-1,1);
635  hsimPV["zsim2"] = new TH1F("zsim2","simulated z",100,-20.,20.);
636  hsimPV["xsim3"] = new TH1F("xsim3","simulated x",100,-0.1,0.1); // 0.01cm = 100 um
637  hsimPV["ysim3"] = new TH1F("ysim3","simulated y",100,-0.1,0.1);
638  hsimPV["zsim3"] = new TH1F("zsim3","simulated z",100,-20.,20.);
639  hsimPV["xsimb"] = new TH1F("xsimb","simulated x",100,-0.01,0.01); // 0.01cm = 100 um
640  hsimPV["ysimb"] = new TH1F("ysimb","simulated y",100,-0.01,0.01);
641  hsimPV["zsimb"] = new TH1F("zsimb","simulated z",100,-20.,20.);
642  hsimPV["xsimb1"] = new TH1F("xsimb1","simulated x",100,-0.1,0.1); // 0.01cm = 100 um
643  hsimPV["ysimb1"] = new TH1F("ysimb1","simulated y",100,-0.1,0.1);
644  hsimPV["zsimb1"] = new TH1F("zsimb1","simulated z",100,-20.,20.);
645  add(hsimPV, new TH1F("xbeam","beamspot x",100,-1.,1.));
646  add(hsimPV, new TH1F("ybeam","beamspot y",100,-1.,1.));
647  add(hsimPV, new TH1F("zbeam","beamspot z",100,-1.,1.));
648  add(hsimPV, new TH1F("wxbeam","beamspot sigma x",100,-1.,1.));
649  add(hsimPV, new TH1F("wybeam","beamspot sigma y",100,-1.,1.));
650  add(hsimPV, new TH1F("wzbeam","beamspot sigma z",100,-1.,1.));
651  hsimPV["xsim2"]->StatOverflows(kTRUE);
652  hsimPV["ysim2"]->StatOverflows(kTRUE);
653  hsimPV["zsim2"]->StatOverflows(kTRUE);
654  hsimPV["xsimb"]->StatOverflows(kTRUE);
655  hsimPV["ysimb"]->StatOverflows(kTRUE);
656  hsimPV["zsimb"]->StatOverflows(kTRUE);
657  hsimPV["nsimvtx"] = new TH1F("nsimvtx","# of simulated vertices", 50, -0.5, 49.5);
658  hsimPV["nbsimtksinvtx"]= new TH1F("nbsimtksinvtx","simulated tracks in vertex",100,-0.5,99.5);
659  hsimPV["nbsimtksinvtx"]->StatOverflows(kTRUE);
660 }
661 
663  std::cout << "this is void PrimaryVertexAnalyzer4PU::endJob() " << std::endl;
664  //cumulate some histos
665  double sumDA=0,sumBS=0,sumnoBS=0;
666  for(int i=101; i>0; i--){
667  sumDA+=hDA["matchVtxFractionSignal"]->GetBinContent(i)/hDA["matchVtxFractionSignal"]->Integral();
668  hDA["matchVtxFractionCumSignal"]->SetBinContent(i,sumDA);
669  sumBS+=hBS["matchVtxFractionSignal"]->GetBinContent(i)/hBS["matchVtxFractionSignal"]->Integral();
670  hBS["matchVtxFractionCumSignal"]->SetBinContent(i,sumBS);
671  sumnoBS+=hnoBS["matchVtxFractionSignal"]->GetBinContent(i)/hnoBS["matchVtxFractionSignal"]->Integral();
672  hnoBS["matchVtxFractionCumSignal"]->SetBinContent(i,sumnoBS);
673  }
674  sumDA=0,sumBS=0,sumnoBS=0;
675  for(int i=1; i<1001; i++){
676  sumDA+=hDA["abszdistancetag"]->GetBinContent(i);
677  hDA["abszdistancetagcum"]->SetBinContent(i,sumDA/float(hDA["abszdistancetag"]->GetEntries()));
678  sumBS+=hBS["abszdistancetag"]->GetBinContent(i);
679  hBS["abszdistancetagcum"]->SetBinContent(i,sumBS/float(hBS["abszdistancetag"]->GetEntries()));
680  sumnoBS+=hnoBS["abszdistancetag"]->GetBinContent(i);
681  hnoBS["abszdistancetagcum"]->SetBinContent(i,sumnoBS/float(hnoBS["abszdistancetag"]->GetEntries()));
682  }
683 
684  Cumulate(hBS["matchVtxZCum"]); Cumulate(hBS["matchVtxZCumSignal"]); Cumulate(hBS["matchVtxZCumPU"]);
685  Cumulate(hnoBS["matchVtxZCum"]); Cumulate(hnoBS["matchVtxZCumSignal"]); Cumulate(hnoBS["matchVtxZCumPU"]);
686  Cumulate(hDA["matchVtxZCum"]); Cumulate(hDA["matchVtxZCumSignal"]); Cumulate(hDA["matchVtxZCumPU"]);
687 
688  // make a reference for ndofnr2
689  double p;
690  for(int i=1; i<501; i++){
691  if(hDA["vtxndf"]->GetEntries()>0){
692  p= hDA["vtxndf"]->Integral(i,501)/hDA["vtxndf"]->GetEntries(); hDA["vtxndfc"]->SetBinContent(i,p*hDA["vtxndf"]->GetBinContent(i));
693  }
694  if(hBS["vtxndf"]->GetEntries()>0){
695  p= hBS["vtxndf"]->Integral(i,501)/hBS["vtxndf"]->GetEntries(); hBS["vtxndfc"]->SetBinContent(i,p*hBS["vtxndf"]->GetBinContent(i));
696  }
697  if(hnoBS["vtxndf"]->GetEntries()>0){
698  p=hnoBS["vtxndf"]->Integral(i,501)/hnoBS["vtxndf"]->GetEntries(); hnoBS["vtxndfc"]->SetBinContent(i,p*hnoBS["vtxndf"]->GetBinContent(i));
699  }
700  }
701 
702  rootFile_->cd();
703  for(std::map<std::string,TH1*>::const_iterator hist=hsimPV.begin(); hist!=hsimPV.end(); hist++){
704  std::cout << "writing " << hist->first << std::endl;
705  hist->second->Write();
706  }
707  rootFile_->Write();
708  std::cout << "PrimaryVertexAnalyzer4PU::endJob: done" << std::endl;
709 }
710 
711 
712 // helper functions
713 std::vector<PrimaryVertexAnalyzer4PU::SimPart> PrimaryVertexAnalyzer4PU::getSimTrkParameters(
716  double simUnit)
717 {
718  std::vector<SimPart > tsim;
719  if(simVtcs->begin()==simVtcs->end()){
720  if(verbose_){
721  cout << " PrimaryVertexAnalyzer4PU::getSimTrkParameters no simvtcs" << endl;
722  }
723  return tsim;
724  }
725  if(verbose_){
726  cout << " PrimaryVertexAnalyzer4PU::getSimTrkParameters simVtcs n=" << simVtcs->size() << endl;
727  cout << " PrimaryVertexAnalyzer4PU::getSimTrkParameters 1st position" << setw(8) << setprecision(4) << simVtcs->begin()->position() << endl;
728  }
729  double t0=simVtcs->begin()->position().e();
730 
731  for(edm::SimTrackContainer::const_iterator t=simTrks->begin();
732  t!=simTrks->end(); ++t){
733  if (t->noVertex()){
734  std::cout << "simtrk has no vertex" << std::endl;
735  }else{
736  // get the vertex position
737  math::XYZTLorentzVectorD v((*simVtcs)[t->vertIndex()].position().x(),
738  (*simVtcs)[t->vertIndex()].position().y(),
739  (*simVtcs)[t->vertIndex()].position().z(),
740  (*simVtcs)[t->vertIndex()].position().e());
741  int pdgCode=t->type();
742 
743  if( pdgCode==-99 ){
744  // such entries cause crashes, no idea what they are
745  std::cout << "funny particle skipped , code=" << pdgCode << std::endl;
746  }else{
747  double Q=0;
748  if ((pdgCode==11)||(pdgCode==13)||(pdgCode==15)||(pdgCode==-211)||(pdgCode==-2212)||(pdgCode==-321)||(pdgCode==-3222)){Q=-1;}
749  else if((pdgCode==-11)||(pdgCode==-13)||(pdgCode==-15)||(pdgCode==211)||(pdgCode==2212)||(pdgCode==321)||(pdgCode==3222)){Q=1;}
750  else {
751  }
752  math::XYZTLorentzVectorD p(t->momentum().x(),t->momentum().y(),t->momentum().z(),t->momentum().e());
753  if ( (Q != 0) && (p.pt()>0.1) && (fabs(t->momentum().eta())<3.0)
754  && fabs(v.z()*simUnit<20) && (sqrt(v.x()*v.x()+v.y()*v.y())<10.)){
755  double x0=v.x()*simUnit;
756  double y0=v.y()*simUnit;
757  double z0=v.z()*simUnit;
758  double kappa=-Q*0.002998*fBfield_/p.pt();
759  double D0=x0*sin(p.phi())-y0*cos(p.phi())-0.5*kappa*(x0*x0+y0*y0);
760  double q=sqrt(1.-2.*kappa*D0);
761  double s0=(x0*cos(p.phi())+y0*sin(p.phi()))/q;
762  double s1;
763  if (fabs(kappa*s0)>0.001){
764  s1=asin(kappa*s0)/kappa;
765  }else{
766  double ks02=(kappa*s0)*(kappa*s0);
767  s1=s0*(1.+ks02/6.+3./40.*ks02*ks02+5./112.*pow(ks02,3));
768  }
769  SimPart sp;//ParameterVector par;
770  sp.par[reco::TrackBase::i_qoverp] = Q/p.P();
771  sp.par[reco::TrackBase::i_lambda] = M_PI/2.-p.theta();
772  sp.par[reco::TrackBase::i_phi] = p.phi()-asin(kappa*s0);
773  sp.par[reco::TrackBase::i_dxy] = -2.*D0/(1.+q);
774  sp.par[reco::TrackBase::i_dsz] = z0*sin(p.theta())-s1*cos(p.theta());
775 
776  sp.pdg=pdgCode;
777  if (v.t()-t0<1e-15){
778  sp.type=0; // primary
779  }else{
780  sp.type=1; //secondary
781  }
782 
783  // now get zpca (get perigee wrt beam)
784  double x1=x0-0.033; double y1=y0-0.; // FIXME how do we get the simulated beam position?
785  D0=x1*sin(p.phi())-y1*cos(p.phi())-0.5*kappa*(x1*x1+y1*y1);
786  q=sqrt(1.-2.*kappa*D0);
787  s0=(x1*cos(p.phi())+y1*sin(p.phi()))/q;
788  if (fabs(kappa*s0)>0.001){
789  s1=asin(kappa*s0)/kappa;
790  }else{
791  double ks02=(kappa*s0)*(kappa*s0);
792  s1=s0*(1.+ks02/6.+3./40.*ks02*ks02+5./112.*pow(ks02,3));
793  }
794  sp.ddcap=-2.*D0/(1.+q);
795  sp.zdcap=z0-s1/tan(p.theta());
796  sp.zvtx=z0;
797  sp.xvtx=x0;
798  sp.yvtx=y0;
799 
800  tsim.push_back(sp);
801  }
802  }
803  }// has vertex
804  }//for loop
805  return tsim;
806 }
807 
808 namespace {
809  struct Array2D {
810  Array2D(size_t iN, size_t iM):
811  m_step(iM),m_array(new double[iN*iM]) {}
812 
813  double& operator()(size_t iN, size_t iM) {
814  return m_array[iN*m_step+iM];
815  }
816 
817  double operator()(size_t iN, size_t iM) const {
818  return m_array[iN*m_step+iM];
819  }
820 
821  size_t m_step;
822  std::unique_ptr<double[]> m_array;
823  };
824 }
825 
826 std::vector<int> PrimaryVertexAnalyzer4PU::supf(std::vector<SimPart>& simtrks, const reco::TrackCollection & trks){
827  const unsigned int nsim=simtrks.size();
828  const unsigned int nrec=trks.size();
829  std::vector<int> rectosim(nrec); // pointer to associated simtrk
830  Array2D pij(nrec,nsim);
831  double mu=100.; // initial chi^2 cut-off (5 dofs !)
832  int nmatch=0;
833  int i=0;
834  for(reco::TrackCollection::const_iterator t=trks.begin(); t!=trks.end(); ++t){
835  rectosim[i]=-1;
836  ParameterVector par = t->parameters();
837  reco::TrackBase::CovarianceMatrix S = t->covariance();
838  S.Invert();
839  for(unsigned int j=0; j<nsim; j++){
840  simtrks[j].rec=-1;
841  SimPart s=simtrks[j];
842  double c=0;
843  for(unsigned int k=0; k<5; k++){
844  for(unsigned int l=0; l<5; l++){
845  c+=(par(k)-s.par[k])*(par(l)-s.par[l])*S(k,l);
846  }
847  }
848  pij(i,j)=exp(-0.5*c);
849  }
850  i++;
851  }
852 
853  for(unsigned int k=0; k<nrec; k++){
854  int imatch=-1; int jmatch=-1;
855  double pmatch=0;
856  for(unsigned int j=0; j<nsim; j++){
857  if ((simtrks[j].rec)<0){
858  double psum=exp(-0.5*mu); //cutoff
859  for(unsigned int i=0; i<nrec; i++){
860  if (rectosim[i]<0){ psum+=pij(i,j);}
861  }
862  for(unsigned int i=0; i<nrec; i++){
863  if ((rectosim[i]<0)&&(pij(i,j)/psum>pmatch)){
864  pmatch=pij(i,j)/psum;
865  imatch=i; jmatch=j;
866  }
867  }
868  }
869  }// sim loop
870  if((jmatch>=0)||(imatch>=0)){
871  if (pmatch>0.01){
872  rectosim[imatch]=jmatch;
873  simtrks[jmatch].rec=imatch;
874  nmatch++;
875  }else if (match(simtrks[jmatch].par, trks.at(imatch).parameters())){
876  // accept it anyway if it matches crudely and relax the cut-off
877  rectosim[imatch]=jmatch;
878  simtrks[jmatch].rec=imatch;
879  nmatch++;
880  mu=mu*2;
881  }
882  }
883  }
884 
885  std::cout << "unmatched sim " << std::endl;
886  for(unsigned int j=0; j<nsim; j++){
887  if(simtrks[j].rec<0){
888  double pt= 1./simtrks[j].par[0]/tan(simtrks[j].par[1]);
889  if((fabs(pt))>1.){
890  std::cout << setw(3) << j << setw(8) << simtrks[j].pdg
891  << setw(8) << setprecision(4) << " (" << simtrks[j].xvtx << "," << simtrks[j].yvtx << "," << simtrks[j].zvtx << ")"
892  << " pt= " << pt
893  << " phi=" << simtrks[j].par[2]
894  << " eta= " << -log(tan(0.5*(M_PI/2-simtrks[j].par[1])))
895  << std::endl;
896  }
897  }
898  }
899  return rectosim;
900 }
901 
903  const ParameterVector &b){
904  double dqoverp =a(0)-b(0);
905  double dlambda =a(1)-b(1);
906  double dphi =a(2)-b(2);
907  double dsz =a(4)-b(4);
908  if (dphi>M_PI){ dphi-=M_2_PI; }else if(dphi<-M_PI){dphi+=M_2_PI;}
909  return ( (fabs(dqoverp)<0.2) && (fabs(dlambda)<0.02) && (fabs(dphi)<0.04) && (fabs(dsz)<1.0) );
910 }
911 
913  const reco::Vertex &vrec){
914  return (fabs(vsim.z*simUnit_-vrec.z())<zmatch_);
915 }
916 
918  double ctau=(pdt_->particle( abs(p->pdg_id()) ))->lifetime();
919  return ctau >0 && ctau <1e-6;
920 }
921 
923  return ( !p->end_vertex() && p->status()==1 );
924 }
925 
926 
928  const ParticleData * part = pdt_->particle( p->pdg_id() );
929  if (part){
930  return part->charge()!=0;
931  }else{
932  // the new/improved particle table doesn't know anti-particles
933  return pdt_->particle( -p->pdg_id() )!=0;
934  }
935 }
936 
937 void PrimaryVertexAnalyzer4PU::fillTrackHistos(std::map<std::string, TH1*> & h, const std::string & ttype, const reco::Track & t, const reco::Vertex * v){
938  Fill(h,"rapidity_"+ttype,t.eta());
939  Fill(h,"z0_"+ttype,t.vz());
940  Fill(h,"phi_"+ttype,t.phi());
941  Fill(h,"eta_"+ttype,t.eta());
942  Fill(h,"pt_"+ttype,t.pt());
943  Fill(h,"found_"+ttype,t.found());
944  Fill(h,"lost_"+ttype,t.lost());
945  Fill(h,"nchi2_"+ttype,t.normalizedChi2());
946  Fill(h,"rstart_"+ttype,(t.innerPosition()).Rho());
947 
948  double d0Error=t.d0Error();
949  double d0=t.dxy(vertexBeamSpot_.position());
950  if (d0Error>0){
951  Fill(h,"logtresxy_"+ttype,log(d0Error/0.0001)/log(10.));
952  Fill(h,"tpullxy_"+ttype,d0/d0Error);
953  }
954  double dzError=t.dzError();
955  if(dzError>0){
956  Fill(h,"logtresz_"+ttype,log(dzError/0.0001)/log(10.));
957  }
958 
959  Fill(h,"sigmatrkz_"+ttype,sqrt(pow(t.dzError(),2)+wxy2_/pow(tan(t.theta()),2)));
960  Fill(h,"sigmatrkz0_"+ttype,t.dzError());
961 
962  // track vs vertex
963  if((! (v==NULL)) && (v->ndof()>10.)) {
964  // emulate clusterizer input
965  TransientTrack tt = theB_->build(&t); tt.setBeamSpot(vertexBeamSpot_); // need the setBeamSpot !
966  double z=(tt.stateAtBeamLine().trackStateAtPCA()).position().z();
967  double tantheta=tan((tt.stateAtBeamLine().trackStateAtPCA()).momentum().theta());
968  double dz2= pow(tt.track().dzError(),2)+wxy2_/pow(tantheta,2);
969 
970  Fill(h,"restrkz_"+ttype,z-v->position().z());
971  Fill(h,"restrkzvsphi_"+ttype,t.phi(), z-v->position().z());
972  Fill(h,"restrkzvseta_"+ttype,t.eta(), z-v->position().z());
973  Fill(h,"pulltrkzvsphi_"+ttype,t.phi(), (z-v->position().z())/sqrt(dz2));
974  Fill(h,"pulltrkzvseta_"+ttype,t.eta(), (z-v->position().z())/sqrt(dz2));
975 
976  Fill(h,"pulltrkz_"+ttype,(z-v->position().z())/sqrt(dz2));
977  }
978 
979  // collect some info on hits and clusters
980  Fill(h, "nbarrelLayers_" + ttype, t.hitPattern().pixelBarrelLayersWithMeasurement());
981  Fill(h, "nPxLayers_" + ttype, t.hitPattern().pixelLayersWithMeasurement());
982  Fill(h, "nSiLayers_" + ttype ,t.hitPattern().trackerLayersWithMeasurement());
983  Fill(h, "expectedInner_" + ttype, t.hitPattern().numberOfHits(HitPattern::MISSING_INNER_HITS));
984  Fill(h, "expectedOuter_" + ttype, t.hitPattern().numberOfHits(HitPattern::MISSING_OUTER_HITS));
985  Fill(h, "trackAlgo_" + ttype, t.algo());
986  Fill(h, "trackQuality_" + ttype, t.qualityMask());
987 
988  int longesthit=0, nbarrel=0;
990  if ((**hit).isValid() && (**hit).geographicalId().det() == DetId::Tracker ){
991  bool barrel = DetId((**hit).geographicalId()).subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel);
992  if (barrel){
993  const SiPixelRecHit *pixhit = dynamic_cast<const SiPixelRecHit*>( &(**hit));
994  edm::Ref<edmNew::DetSetVector<SiPixelCluster>, SiPixelCluster> const& clust = (*pixhit).cluster();
995  if (clust.isNonnull()) {
996  nbarrel++;
997  if (clust->sizeY()-longesthit>0) longesthit=clust->sizeY();
998  if (clust->sizeY()>20.){
999  Fill(h,"lvseta_"+ttype,t.eta(), 19.9);
1000  Fill(h,"lvstanlambda_"+ttype,tan(t.lambda()), 19.9);
1001  }else{
1002  Fill(h,"lvseta_"+ttype,t.eta(), float(clust->sizeY()));
1003  Fill(h,"lvstanlambda_"+ttype,tan(t.lambda()), float(clust->sizeY()));
1004  }
1005  }
1006  }
1007  }
1008  }
1009  Fill(h,"nbarrelhits_"+ttype,float(nbarrel));
1010  //-------------------------------------------------------------------
1011 }
1012 
1014  // collect some info on hits and clusters
1015  int longesthit=0, nbarrel=0;
1016  cout << Form("%5.2f %5.2f : ",t.pt(),t.eta());
1018  if ((**hit).isValid() && (**hit).geographicalId().det() == DetId::Tracker ){
1019  bool barrel = DetId((**hit).geographicalId()).subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel);
1020  if (barrel){
1021  nbarrel++;
1022  const SiPixelRecHit *pixhit = dynamic_cast<const SiPixelRecHit*>( &(**hit));
1023  edm::Ref<edmNew::DetSetVector<SiPixelCluster>, SiPixelCluster> const& clust = (*pixhit).cluster();
1024  if (clust.isNonnull()) {
1025  cout << Form("%4d",clust->sizeY());
1026  if (clust->sizeY()-longesthit>0) longesthit=clust->sizeY();
1027  }
1028  }
1029  }
1030  }
1031 }
1032 
1034  int ivtx=0;
1035  std::cout << std::endl << title << std::endl;
1036  for(reco::VertexCollection::const_iterator v=recVtxs->begin();
1037  v!=recVtxs->end(); ++v){
1038  string vtype=" recvtx ";
1039  if( v->isFake()){
1040  vtype=" fake ";
1041  }else if (v->ndof()==-5){
1042  vtype=" cluster "; // pos=selector[iclu],cputime[iclu],clusterz[iclu]
1043  }else if(v->ndof()==-3){
1044  vtype=" event ";
1045  }
1046  std::cout << "vtx "<< std::setw(3) << std::setfill(' ')<<ivtx++
1047  << vtype
1048  << " #trk " << std::fixed << std::setprecision(4) << std::setw(3) << v->tracksSize()
1049  << " chi2 " << std::fixed << std::setw(4) << std::setprecision(1) << v->chi2()
1050  << " ndof " << std::fixed << std::setw(5) << std::setprecision(2) << v->ndof()
1051  << " x " << std::setw(8) <<std::fixed << std::setprecision(4) << v->x()
1052  << " dx " << std::setw(8) << v->xError()
1053  << " y " << std::setw(8) << v->y()
1054  << " dy " << std::setw(8) << v->yError()
1055  << " z " << std::setw(8) << v->z()
1056  << " dz " << std::setw(8) << v->zError()
1057  << std::endl;
1058  }
1059 }
1060 
1062  int i=0;
1063  for(SimVertexContainer::const_iterator vsim=simVtxs->begin();
1064  vsim!=simVtxs->end(); ++vsim){
1065  if ( vsim->position().x()*vsim->position().x()+vsim->position().y()*vsim->position().y() < 1.){
1066  std::cout << i++ << ")" << std::scientific
1067  << " evtid=" << vsim->eventId().event() << "," << vsim->eventId().bunchCrossing()
1068  << " sim x=" << vsim->position().x()*simUnit_
1069  << " sim y=" << vsim->position().y()*simUnit_
1070  << " sim z=" << vsim->position().z()*simUnit_
1071  << " sim t=" << vsim->position().t()
1072  << " parent=" << vsim->parentIndex()
1073  << std::endl;
1074  }
1075  }
1076 }
1077 
1078 
1080  std::cout << " simTrks type, (momentum), vertIndex, genpartIndex" << std::endl;
1081  int i=1;
1082  for(SimTrackContainer::const_iterator t=simTrks->begin();
1083  t!=simTrks->end(); ++t){
1084  std::cout << i++ << ")"
1085  << t->eventId().event() << "," << t->eventId().bunchCrossing()
1086  << (*t)
1087  << " index="
1088  << (*t).genpartIndex();
1089  std::cout << std::endl;
1090  }
1091 }
1092 
1094 
1095  cout << "printRecTrks" << endl;
1096  int i =1;
1097  for(reco::TrackCollection::const_iterator t=recTrks->begin(); t!=recTrks->end(); ++t){
1098  cout << endl;
1099  cout << "Track "<<i << " " ; i++;
1100  if( t->quality(reco::TrackBase::loose)){ cout << "loose ";};
1101  if( t->quality(reco::TrackBase::tight)){ cout << "tight ";};
1102  if( t->quality(reco::TrackBase::highPurity)){ cout << "highPurity ";};
1103  if( t->quality(reco::TrackBase::confirmed)){ cout << "confirmed ";};
1104  if( t->quality(reco::TrackBase::goodIterative)){ cout << "goodIterative ";};
1105  cout << endl;
1106 
1107  TransientTrack tk = theB_->build(&(*t)); tk.setBeamSpot(vertexBeamSpot_);
1108  double ipsig=0;
1109  if (tk.stateAtBeamLine().isValid()){
1111  }else{
1112  ipsig=-1;
1113  }
1114 
1115  cout << Form("pt=%8.3f phi=%6.3f eta=%6.3f z=%8.4f dz=%6.4f, ipsig=%6.1f",t->pt(), t->phi(), t->eta(), t->vz(), t->dzError(),ipsig) << endl;
1116 
1117 
1118  cout << Form(" found=%6d lost=%6d chi2/ndof=%10.3f ",t->found(), t->lost(),t->normalizedChi2())<<endl;
1119  const reco::HitPattern &p = t->hitPattern();
1120 
1121  cout << "subdet layers valid lost" << endl;
1122  cout << Form(" barrel %2d %2d %2d",
1123  p.pixelBarrelLayersWithMeasurement(),
1124  p.numberOfValidPixelBarrelHits(),
1125  p.numberOfLostPixelBarrelHits(HitPattern::TRACK_HITS))
1126  << endl;
1127 
1128  cout << Form(" fwd %2d %2d %2d",
1129  p.pixelEndcapLayersWithMeasurement(),
1130  p.numberOfValidPixelEndcapHits(),
1131  p.numberOfLostPixelEndcapHits(HitPattern::TRACK_HITS))
1132  << endl;
1133  cout << Form(" pixel %2d %2d %2d",
1134  p.pixelLayersWithMeasurement(),
1135  p.numberOfValidPixelHits(),
1136  p.numberOfLostPixelHits(HitPattern::TRACK_HITS))
1137  << endl;
1138  cout << Form(" tracker %2d %2d %2d",
1139  p.trackerLayersWithMeasurement(),
1140  p.numberOfValidTrackerHits(),
1141  p.numberOfLostTrackerHits(HitPattern::TRACK_HITS))
1142  << endl;
1143  cout << endl;
1144 
1145  for(trackingRecHit_iterator hit=t->recHitsBegin(); hit!=t->recHitsEnd(); hit++){
1146  if ((**hit).isValid() && (**hit).geographicalId().det() == DetId::Tracker ){
1147  bool barrel = DetId((**hit).geographicalId()).subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel);
1148  bool endcap = DetId((**hit).geographicalId()).subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap);
1149  if (barrel){
1150  const SiPixelRecHit *pixhit = dynamic_cast<const SiPixelRecHit*>( &(**hit));
1151  edm::Ref<edmNew::DetSetVector<SiPixelCluster>, SiPixelCluster> const& clust = (*pixhit).cluster();
1152  if (clust.isNonnull()) {
1153  cout << Form(" barrel cluster size=%2d charge=%6.1f wx=%2d wy=%2d, expected=%3.1f",clust->size(),clust->charge(),clust->sizeX(),clust->sizeY(),1.+2./fabs(tan(t->theta()))) << endl;
1154  }
1155  }else if(endcap){
1156  const SiPixelRecHit *pixhit = dynamic_cast<const SiPixelRecHit*>( &(**hit));
1157  edm::Ref<edmNew::DetSetVector<SiPixelCluster>, SiPixelCluster> const& clust = (*pixhit).cluster();
1158  if (clust.isNonnull()) {
1159  cout << Form(" endcap cluster size=%2d charge=%6.1f wx=%2d wy=%2d",clust->size(),clust->charge(),clust->sizeX(),clust->sizeY()) << endl;
1160  }
1161  }
1162  }
1163  }
1164 
1165  cout << "hitpattern" << endl;
1166  for(int i = 0; i < p.numberOfHits(HitPattern::TRACK_HITS); i++){
1167  p.printHitPattern(HitPattern::TRACK_HITS, i, std::cout);
1168  }
1169 
1170  cout << "expected inner " << p.numberOfHits(HitPattern::MISSING_INNER_HITS) << endl;
1171  for(int i = 0; i < p.numberOfHits(HitPattern::MISSING_INNER_HITS); i++){
1172  p.printHitPattern(HitPattern::MISSING_INNER_HITS, i, std::cout);
1173  }
1174 
1175  cout << "expected outer " << p.numberOfHits(HitPattern::MISSING_OUTER_HITS) << endl;
1176  for(int i = 0; i < p.numberOfHits(HitPattern::MISSING_OUTER_HITS); i++){
1177  p.printHitPattern(HitPattern::MISSING_OUTER_HITS, i, std::cout);
1178  }
1179  }
1180 }
1181 
1182 namespace {
1183  bool recTrackLessZ(const reco::TransientTrack & tk1,
1184  const reco::TransientTrack & tk2)
1185  {
1187  }
1188 }
1189 
1190 
1192  const Handle<reco::VertexCollection> &recVtxs,
1193  std::vector<SimPart>& tsim,
1194  std::vector<SimEvent>& simEvt,
1195  bool selectedOnly){
1196  // make a printout of the tracks selected for PV reconstructions, show matching MC tracks, too
1197  vector<TransientTrack> selTrks;
1198  for(reco::TrackCollection::const_iterator t=recTrks->begin();
1199  t!=recTrks->end(); ++t){
1200  TransientTrack tt = theB_->build(&(*t)); tt.setBeamSpot(vertexBeamSpot_);
1201  if( (!selectedOnly) || (selectedOnly && theTrackFilter(tt))){ selTrks.push_back(tt); }
1202  }
1203  if (selTrks.size()==0) return;
1204  stable_sort(selTrks.begin(), selTrks.end(), recTrackLessZ);
1205 
1206  // select tracks like for PV reconstruction and match them to sim tracks
1207  reco::TrackCollection selRecTrks;
1208 
1209  for(unsigned int i=0; i<selTrks.size(); i++){ selRecTrks.push_back(selTrks[i].track());}
1210  std::vector<int> rectosim=supf(tsim, selRecTrks);
1211 
1212  // now dump in a format similar to the clusterizer
1213  cout << "printPVTrks" << endl;
1214  cout << "---- z +/- dz 1bet-m ip +/-dip pt phi eta";
1215  if((tsim.size()>0)||(simEvt.size()>0)) {cout << " type pdg zvtx zdca dca zvtx zdca dsz";}
1216  cout << endl;
1217 
1218  cout.precision(4);
1219  int isel=0;
1220  for(unsigned int i=0; i<selTrks.size(); i++){
1221  if (selectedOnly || (theTrackFilter(selTrks[i]))) {
1222  cout << setw (3)<< isel;
1223  isel++;
1224  }else{
1225  cout << " ";
1226  }
1227 
1228  // is this track in the tracklist of a recvtx ?
1229  int vmatch=-1;
1230  int iv=0;
1231  for(reco::VertexCollection::const_iterator v=recVtxs->begin();
1232  v!=recVtxs->end(); ++v){
1233  if ( (v->ndof()<-1) || (v->chi2()<=0) ) continue; // skip clusters
1234  for(trackit_t tv=v->tracks_begin(); tv!=v->tracks_end(); tv++){
1235  const reco::Track & RTv=*(tv->get());
1236  if(selTrks[i].track().vz()==RTv.vz()) {vmatch=iv;}
1237  }
1238  iv++;
1239  }
1240 
1241  double tz=(selTrks[i].stateAtBeamLine().trackStateAtPCA()).position().z();
1242  double tantheta=tan((selTrks[i].stateAtBeamLine().trackStateAtPCA()).momentum().theta());
1243  double tdz0= selTrks[i].track().dzError();
1244  double tdz2= pow(selTrks[i].track().dzError(),2)+ (pow(vertexBeamSpot_.BeamWidthX(),2)+pow(vertexBeamSpot_.BeamWidthY(),2))/pow(tantheta,2);
1245 
1246  if(vmatch>-1){
1247  cout << "["<<setw(2)<<vmatch<<"]";
1248  }else{
1249  int status=0;
1250  if(status==0){
1251  cout <<" ";
1252  }else{
1253  if(status&0x1){cout << "i";}else{cout << ".";};
1254  if(status&0x2){cout << "c";}else{cout << ".";};
1255  if(status&0x4){cout << "h";}else{cout << ".";};
1256  if(status&0x8){cout << "q";}else{cout << ".";};
1257  }
1258  }
1259  cout << setw (8) << fixed << setprecision(4)<< tz << " +/-" << setw (6)<< sqrt(tdz2);
1260 
1261  // track quality and hit information, see DataFormats/TrackReco/interface/HitPattern.h
1262  if(selTrks[i].track().quality(reco::TrackBase::highPurity)){ cout << " *";}else{cout <<" ";}
1263  if(selTrks[i].track().hitPattern().hasValidHitInFirstPixelBarrel()){ cout << "+"; } else { cout << "-"; }
1264  cout << setw(1) << selTrks[i].track().hitPattern().pixelBarrelLayersWithMeasurement();
1265  cout << setw(1) << selTrks[i].track().hitPattern().pixelEndcapLayersWithMeasurement();
1266  cout << setw(1) << hex << selTrks[i].track().hitPattern().trackerLayersWithMeasurement()
1267  - selTrks[i].track().hitPattern().pixelLayersWithMeasurement() << dec;
1268  cout << "-" << setw(1) << hex << selTrks[i].track().hitPattern().numberOfHits(HitPattern::MISSING_OUTER_HITS) << dec;
1269 
1270 
1271  Measurement1D IP=selTrks[i].stateAtBeamLine().transverseImpactParameter();
1272  cout << setw (8) << IP.value() << "+/-" << setw (6) << IP.error();
1273  if(selTrks[i].track().ptError()<1){
1274  cout << " " << setw(8) << setprecision(2) << selTrks[i].track().pt()*selTrks[i].track().charge();
1275  }else{
1276  cout << " " << setw(7) << setprecision(1) << selTrks[i].track().pt()*selTrks[i].track().charge() << "*";
1277  }
1278  cout << " " << setw(5) << setprecision(2) << selTrks[i].track().phi()
1279  << " " << setw(5) << setprecision(2) << selTrks[i].track().eta() ;
1280 
1281  // print MC info, if available
1282  if(simEvt.size()>0){
1283  reco::Track t=selTrks[i].track();
1284  try{
1285  TrackingParticleRef tpr = z2tp_[t.vz()];
1286  const TrackingVertex *parentVertex= tpr->parentVertex().get();
1287  double vz=parentVertex->position().z();
1288  cout << " " << tpr->eventId().event();
1289  cout << " " << setw(5) << tpr->pdgId();
1290  cout << " " << setw(8) << setprecision(4) << vz;
1291  }catch (...){
1292  cout << " not matched";
1293  }
1294  }else{
1295  if(rectosim[i]>0){
1296  if(tsim[rectosim[i]].type==0){ cout << " prim " ;}else{cout << " sec ";}
1297  cout << " " << setw(5) << tsim[rectosim[i]].pdg;
1298  cout << " " << setw(8) << setprecision(4) << tsim[rectosim[i]].zvtx;
1299  cout << " " << setw(8) << setprecision(4) << tsim[rectosim[i]].zdcap;
1300  cout << " " << setw(8) << setprecision(4) << tsim[rectosim[i]].ddcap;
1301  double zvtxpull=(tz-tsim[rectosim[i]].zvtx)/sqrt(tdz2);
1302  cout << setw(6) << setprecision(1) << zvtxpull;
1303  double zdcapull=(tz-tsim[rectosim[i]].zdcap)/tdz0;
1304  cout << setw(6) << setprecision(1) << zdcapull;
1305  double dszpull=(selTrks[i].track().dsz()-tsim[rectosim[i]].par[4])/selTrks[i].track().dszError();
1306  cout << setw(6) << setprecision(1) << dszpull;
1307  }
1308  }
1309  cout << endl;
1310  }
1311 }
1312 
1313 
1315  const std::vector<SimPart > & tsim,
1316  const edm::Handle<reco::TrackCollection> & recTrks)
1317 {
1318  // find all recTracks that belong to this simulated vertex (not just the ones that are used in
1319  // matching recVertex)
1320  std::cout << "dump rec tracks: " << std::endl;
1321  int irec=0;
1322  for(reco::TrackCollection::const_iterator t=recTrks->begin();
1323  t!=recTrks->end(); ++t){
1324  reco::TrackBase::ParameterVector p = t->parameters();
1325  std::cout << irec++ << ") " << p << std::endl;
1326  }
1327 
1328  std::cout << "match sim tracks: " << std::endl;
1329  pv.matchedRecTrackIndex.clear();
1330  pv.nMatchedTracks=0;
1331  int isim=0;
1332  for(std::vector<SimPart>::const_iterator s=tsim.begin();
1333  s!=tsim.end(); ++s){
1334  std::cout << isim++ << " " << s->par;// << std::endl;
1335  int imatch=-1;
1336  int irec=0;
1337  for(reco::TrackCollection::const_iterator t=recTrks->begin();
1338  t!=recTrks->end(); ++t){
1339  reco::TrackBase::ParameterVector p = t->parameters();
1340  if (match(s->par,p)){ imatch=irec; }
1341  irec++;
1342  }
1343  pv.matchedRecTrackIndex.push_back(imatch);
1344  if(imatch>-1){
1345  pv.nMatchedTracks++;
1346  std::cout << " matched to rec trk" << imatch << std::endl;
1347  }else{
1348  std::cout << " not matched" << std::endl;
1349  }
1350  }
1351 }
1352 /********************************************************************************************************/
1353 
1354 void PrimaryVertexAnalyzer4PU::getTc(const std::vector<reco::TransientTrack>& tracks,
1355  double & Tc, double & chsq, double & dzmax, double & dztrim, double & m4m2){
1356  if (tracks.size()<2){ Tc=-1; chsq=-1; dzmax=-1; dztrim=-1; m4m2=-1; return;}
1357 
1358  double sumw=0, sumwz=0, sumww=0,sumwwz=0,sumwwzz=0;
1359  double zmin=1e10, zmin1=1e10, zmax1=-1e10, zmax=-1e10;
1360  double m4=0,m3=0,m2=0,m1=0,m0=0;
1361  for(vector<reco::TransientTrack>::const_iterator it=tracks.begin(); it!=tracks.end(); it++){
1362  double tantheta=tan(((*it).stateAtBeamLine().trackStateAtPCA()).momentum().theta());
1363  reco::BeamSpot beamspot=(it->stateAtBeamLine()).beamSpot();
1364  double z=((*it).stateAtBeamLine().trackStateAtPCA()).position().z();
1365  double dz2= pow((*it).track().dzError(),2)+pow(beamspot.BeamWidthX()/tantheta,2);
1366  double w=1./dz2; // take p=1
1367  sumw += w;
1368  sumwz += w*z;
1369  sumwwz += w*w*z;;
1370  sumwwzz += w*w*z*z;
1371  sumww += w*w;
1372  m0 += w;
1373  m1 += w*z;
1374  m2 += w*z*z;
1375  m3 += w*z*z*z;
1376  m4 += w*z*z*z*z;
1377  if(dz2<pow(0.1,2)){
1378  if(z<zmin1){zmin1=z;} if(z<zmin){zmin1=zmin; zmin=z;}
1379  if(z>zmax1){zmax1=z;} if(z>zmax){zmax1=zmax; zmax=z;}
1380  }
1381  }
1382  double z=sumwz/sumw;
1383  double a=sumwwzz-2*z*sumwwz+z*z*sumww;
1384  double b=sumw;
1385  if(tracks.size()>1){
1386  chsq=(m2-m0*z*z)/(tracks.size()-1);
1387  Tc=2.*a/b;
1388  m4m2=sqrt((m4-4*m3*z+6*m2*z*z-3*m1*z*z*z+m0*z*z*z*z)/(m2-2*m1*z+z*z*m0));
1389  }else{
1390  chsq=0;
1391  Tc=0;
1392  m4m2=0;
1393  }
1394  dzmax=zmax-zmin;
1395  dztrim=zmax1-zmin1;// truncated
1396 }
1397 /********************************************************************************************************/
1398 
1400 
1401 /********************************************************************************************************/
1402 // for a reco track select the matching tracking particle, always use this function to make sure we
1403 // are consistent
1404 // to get the TrackingParticle form the TrackingParticleRef, use ->get();
1405 {
1406  double f=0;
1407  try{
1408  std::vector<std::pair<TrackingParticleRef, double> > tp = r2s_[track];
1409  for (std::vector<std::pair<TrackingParticleRef, double> >::const_iterator it = tp.begin();
1410  it != tp.end(); ++it) {
1411 
1412  if (it->second>f){
1413  tpr=it->first;
1414  f=it->second;
1415  }
1416  }
1417  } catch (Exception event) {
1418  // silly way of testing whether track is in r2s_
1419  }
1420 
1421  // sanity check on track parameters?
1422 
1423  return (f>0.5);
1424 }
1425 /********************************************************************************************************/
1426 
1427 std::vector< edm::RefToBase<reco::Track> > PrimaryVertexAnalyzer4PU::getTruthMatchedVertexTracks(
1428  const reco::Vertex& v
1429  )
1430 // for vertex v get a list of tracks for which truth matching is available
1431 /********************************************************************************************************/
1432 {
1433  std::vector< edm::RefToBase<reco::Track> > b;
1434  TrackingParticleRef tpr;
1435 
1436  for(trackit_t tv=v.tracks_begin(); tv!=v.tracks_end(); tv++){
1437  edm::RefToBase<reco::Track> track=*tv;
1438  if (truthMatchedTrack(track, tpr)){
1439  b.push_back(*tv);
1440  }
1441  }
1442 
1443 
1444  return b;
1445 }
1446 /********************************************************************************************************/
1447 
1448 std::vector<PrimaryVertexAnalyzer4PU::SimEvent> PrimaryVertexAnalyzer4PU::getSimEvents
1452  edm::Handle<View<Track> > trackCollectionH
1453  ){
1454 
1455  const TrackingParticleCollection* simTracks = TPCollectionH.product();
1456  const View<Track> tC = *(trackCollectionH.product());
1457 
1458 
1459  vector<SimEvent> simEvt;
1460  map<EncodedEventId, unsigned int> eventIdToEventMap;
1461  map<EncodedEventId, unsigned int>::iterator id;
1462  bool dumpTP=false;
1463  for(TrackingParticleCollection::const_iterator it=simTracks->begin(); it!=simTracks->end(); it++){
1464 
1465  if( fabs(it->parentVertex().get()->position().z())>100.) continue; // skip funny entries @ -13900
1466 
1467  unsigned int event=0; //note, this is no longer the same as eventId().event()
1468  id=eventIdToEventMap.find(it->eventId());
1469  if (id==eventIdToEventMap.end()){
1470 
1471  // new event here
1472  SimEvent e;
1473  e.eventId=it->eventId();
1474  event=simEvt.size();
1475  const TrackingVertex *parentVertex= it->parentVertex().get();
1476  if(DEBUG_){
1477  cout << "getSimEvents: ";
1478  cout << it->eventId().bunchCrossing() << "," << it->eventId().event()
1479  << " z="<< it->vz() << " "
1480  << parentVertex->eventId().bunchCrossing() << "," <<parentVertex->eventId().event()
1481  << " z=" << parentVertex->position().z() << endl;
1482  }
1483  if (it->eventId()==parentVertex->eventId()){
1484  e.x=parentVertex->position().x();
1485  e.y=parentVertex->position().y();
1486  e.z=parentVertex->position().z();
1487  if(e.z<-100){
1488  dumpTP=true;
1489  }
1490  }else{
1491  e.x=0; e.y=0; e.z=-88.;
1492  }
1493  simEvt.push_back(e);
1494  eventIdToEventMap[e.eventId]=event;
1495  }else{
1496  event=id->second;
1497  }
1498 
1499 
1500  simEvt[event].tp.push_back(&(*it));
1501  if( (abs(it->eta())<2.5) && (it->charge()!=0) ){
1502  simEvt[event].sumpt2+=pow(it->pt(),2); // should keep track of decays ?
1503  simEvt[event].sumpt+=it->pt();
1504  }
1505  }
1506 
1507  if(dumpTP){
1508  for(TrackingParticleCollection::const_iterator it=simTracks->begin(); it!=simTracks->end(); it++){
1509  std::cout << *it << std::endl;
1510  }
1511  }
1512 
1513 
1514  for(View<Track>::size_type i=0; i<tC.size(); ++i) {
1515  RefToBase<Track> track(trackCollectionH, i);
1516  TrackingParticleRef tpr;
1517  if( truthMatchedTrack(track,tpr)){
1518 
1519  if( eventIdToEventMap.find(tpr->eventId())==eventIdToEventMap.end() ){ cout << "Bug in getSimEvents" << endl; break; }
1520 
1521  z2tp_[track.get()->vz()]=tpr;
1522 
1523  unsigned int event=eventIdToEventMap[tpr->eventId()];
1524  double ipsig=0,ipdist=0;
1525  const TrackingVertex *parentVertex= tpr->parentVertex().get();
1526  double vx=parentVertex->position().x(); // problems with tpr->vz()
1527  double vy=parentVertex->position().y();
1528  double vz=parentVertex->position().z();
1529  double d=sqrt(pow(simEvt[event].x-vx,2)+pow(simEvt[event].y-vy,2)+pow(simEvt[event].z-vz,2))*1.e4;
1530  ipdist=d;
1531  double dxy=track->dxy(vertexBeamSpot_.position());
1532  ipsig=dxy/track->dxyError();
1533 
1534 
1535  TransientTrack t = theB_->build(tC[i]);
1536  t.setBeamSpot(vertexBeamSpot_);
1537  if (theTrackFilter(t)){
1538  simEvt[event].tk.push_back(t);
1539  if(ipdist<5){simEvt[event].tkprim.push_back(t);}
1540  if(ipsig<5){simEvt[event].tkprimsel.push_back(t);}
1541  }
1542 
1543  }
1544  }
1545 
1546  AdaptiveVertexFitter theFitter;
1547  cout << "SimEvents " << simEvt.size() << endl;
1548  for(unsigned int i=0; i<simEvt.size(); i++){
1549 
1550  if(simEvt[i].tkprim.size()>0){
1551 
1552  getTc(simEvt[i].tkprimsel, simEvt[i].Tc, simEvt[i].chisq, simEvt[i].dzmax, simEvt[i].dztrim, simEvt[i].m4m2);
1553  TransientVertex v = theFitter.vertex(simEvt[i].tkprim, vertexBeamSpot_);
1554  if (v.isValid()){
1555  simEvt[i].xfit=v.position().x();
1556  simEvt[i].yfit=v.position().y();
1557  simEvt[i].zfit=v.position().z();
1558  // if (simEvt[i].z<-80.){simEvt[i].z=v.position().z();} // for now
1559  }
1560  }
1561 
1562  if(DEBUG_){
1563  cout << i <<" ) nTP=" << simEvt[i].tp.size()
1564  << " z=" << simEvt[i].z
1565  << " recTrks=" << simEvt[i].tk.size()
1566  << " recTrksPrim=" << simEvt[i].tkprim.size()
1567  << " zfit=" << simEvt[i].zfit
1568  << endl;
1569  }
1570  }
1571 
1572  return simEvt;
1573 }
1574 
1575 
1576 std::vector<PrimaryVertexAnalyzer4PU::simPrimaryVertex> PrimaryVertexAnalyzer4PU::getSimPVs(
1577  const Handle<HepMCProduct> evtMC)
1578 {
1579  if(DEBUG_){std::cout << "getSimPVs HepMC " << std::endl;}
1580 
1581  std::vector<PrimaryVertexAnalyzer4PU::simPrimaryVertex> simpv;
1582  const HepMC::GenEvent* evt=evtMC->GetEvent();
1583  if (evt) {
1584  for(HepMC::GenEvent::vertex_const_iterator vitr= evt->vertices_begin();
1585  vitr != evt->vertices_end(); ++vitr )
1586  { // loop for vertex ...
1587 
1588  HepMC::FourVector pos = (*vitr)->position();
1589  if (fabs(pos.z())>1000) continue; // skip funny junk vertices
1590 
1591  bool hasMotherVertex=false;
1592  for ( HepMC::GenVertex::particle_iterator
1593  mother = (*vitr)->particles_begin(HepMC::parents);
1594  mother != (*vitr)->particles_end(HepMC::parents);
1595  ++mother ) {
1596  HepMC::GenVertex * mv=(*mother)->production_vertex();
1597  if (mv) {hasMotherVertex=true;}
1598  }
1599  if(hasMotherVertex) {continue;}
1600 
1601  // could be a new vertex, check all primaries found so far to avoid multiple entries
1602  const double mm=0.1;
1603  simPrimaryVertex sv(pos.x()*mm,pos.y()*mm,pos.z()*mm);
1604  simPrimaryVertex *vp=NULL; // will become non-NULL if a vertex is found and then point to it
1605  for(std::vector<simPrimaryVertex>::iterator v0=simpv.begin();
1606  v0!=simpv.end(); v0++){
1607  if( (fabs(sv.x-v0->x)<1e-5) && (fabs(sv.y-v0->y)<1e-5) && (fabs(sv.z-v0->z)<1e-5)){
1608  vp=&(*v0);
1609  break;
1610  }
1611  }
1612  if(!vp){
1613  // this is a new vertex
1614  simpv.push_back(sv);
1615  vp=&simpv.back();
1616  }
1617 
1618  // store the gen vertex barcode with this simpv
1619  vp->genVertex.push_back((*vitr)->barcode());
1620 
1621  // collect final state descendants and sum up momenta etc
1622  for ( HepMC::GenVertex::particle_iterator
1623  daughter = (*vitr)->particles_begin(HepMC::descendants);
1624  daughter != (*vitr)->particles_end(HepMC::descendants);
1625  ++daughter ) {
1627  if ( find(vp->finalstateParticles.begin(), vp->finalstateParticles.end(),(*daughter)->barcode())
1628  == vp->finalstateParticles.end()){
1629  vp->finalstateParticles.push_back((*daughter)->barcode());
1630  HepMC::FourVector m=(*daughter)->momentum();
1631  vp->ptot.setPx(vp->ptot.px()+m.px());
1632  vp->ptot.setPy(vp->ptot.py()+m.py());
1633  vp->ptot.setPz(vp->ptot.pz()+m.pz());
1634  vp->ptot.setE(vp->ptot.e()+m.e());
1635  vp->ptsq+=(m.perp())*(m.perp());
1636  // count relevant particles
1637  if ( (m.perp()>0.2) && (fabs(m.pseudoRapidity())<2.5) && isCharged( *daughter ) ){
1638  vp->nGenTrk++;
1639  }
1640 
1641  hsimPV["rapidity"]->Fill(m.pseudoRapidity());
1642  if( (m.perp()>0.8) && isCharged( *daughter ) ){
1643  hsimPV["chRapidity"]->Fill(m.pseudoRapidity());
1644  }
1645  hsimPV["pt"]->Fill(m.perp());
1646  }//new final state particle for this vertex
1647  }//daughter is a final state particle
1648  }
1649  }
1650  }
1651  if(verbose_){
1652  cout << "------- PrimaryVertexAnalyzer4PU simPVs -------" << endl;
1653  for(std::vector<simPrimaryVertex>::iterator v0=simpv.begin();
1654  v0!=simpv.end(); v0++){
1655  cout << "z=" << v0->z
1656  << " px=" << v0->ptot.px()
1657  << " py=" << v0->ptot.py()
1658  << " pz=" << v0->ptot.pz()
1659  << " pt2="<< v0->ptsq
1660  << endl;
1661  }
1662  cout << "-----------------------------------------------" << endl;
1663  }
1664  return simpv;
1665 }
1666 
1667 
1668 double
1669 PrimaryVertexAnalyzer4PU::getTrueSeparation(float in_z, const vector<float> & simpv)
1670 {
1671 
1672  double sepL_min = 50.;
1673 
1674  //loop over all sim vertices
1675  for(unsigned sv_idx=0; sv_idx<simpv.size(); ++sv_idx){
1676 
1677  float comp_z = simpv[sv_idx];
1678  double dist_z = fabs(comp_z - in_z);
1679 
1680  if ( dist_z==0. ) continue;
1681  if ( dist_z<sepL_min ) sepL_min = dist_z;
1682  }
1683  return sepL_min;
1684 }
1685 
1686 
1687 double
1689 {
1690 
1691  EncodedEventId in_ev = inEv.eventId;
1692  double in_z = inEv.z;
1693 
1694  int lastEvent = -1;
1695 
1696  double sepL_min = 50.;
1697 
1698  //loop over all sim vertices
1699  for(unsigned se_idx=0; se_idx<simEv.size(); ++se_idx){
1700 
1701  SimEvent compEv = simEv[se_idx];
1702  EncodedEventId comp_ev = compEv.eventId;
1703 
1704  if ( comp_ev.event()==lastEvent ) continue;
1705  lastEvent = comp_ev.event();
1706 
1707  float comp_z = compEv.z;
1708 
1709  if ( ( fabs(comp_z)>24. ) || ( comp_ev.bunchCrossing()!=0 ) || ( in_ev.event()==comp_ev.event() ) ) continue;
1710 
1711  double dist_z = fabs(comp_z - in_z);
1712 
1713  if ( dist_z<sepL_min ) sepL_min = dist_z;
1714 
1715  }
1716 
1717  return sepL_min;
1718 
1719 }
1720 
1721 vector<int>*
1723 {
1724 
1725  double zmatch_ = 3.;
1726 
1727  vector<int>* matchs = new vector<int>();
1728 
1729  for(unsigned vtx_idx=0; vtx_idx<vCH->size(); ++vtx_idx){
1730 
1731  VertexRef comp_vtxref(vCH, vtx_idx);
1732 
1733  double comp_z = comp_vtxref->z();
1734  double comp_z_err = comp_vtxref->zError();
1735 
1736  double z_dist = comp_z - in_z;
1737  double z_rel = z_dist / comp_z_err;
1738 
1739  if ( fabs(z_rel)<zmatch_ ) {
1740  matchs->push_back(vtx_idx);
1741  }
1742 
1743  }
1744 
1745  return matchs;
1746 }
1747 
1748 
1749 /* get sim pv from TrackingParticles/TrackingVertex */
1750 std::vector<PrimaryVertexAnalyzer4PU::simPrimaryVertex> PrimaryVertexAnalyzer4PU::getSimPVs(
1752  )
1753 {
1754  std::vector<PrimaryVertexAnalyzer4PU::simPrimaryVertex> simpv;
1755 
1756  if(DEBUG_){std::cout << "getSimPVs TrackingVertexCollection " << std::endl;}
1757 
1758  for (TrackingVertexCollection::const_iterator v = tVC -> begin(); v != tVC -> end(); ++v) {
1759 
1760  if(DEBUG_){
1761  std::cout << (v->eventId()).event() << v -> position() << v->g4Vertices().size() <<" " <<v->genVertices().size() << " t=" <<v->position().t()*1.e12 <<" ==0:" <<(v->position().t()>0) << std::endl;
1762  for( TrackingVertex::g4v_iterator gv=v->g4Vertices_begin(); gv!=v->g4Vertices_end(); gv++){
1763  std::cout << *gv << std::endl;
1764  }
1765  std::cout << "----------" << std::endl;
1766  }
1767 
1768  if ((unsigned int) v->eventId().event()<simpv.size()) continue;
1769  if (fabs(v->position().z())>1000) continue; // skip funny junk vertices
1770 
1771  // could be a new vertex, check all primaries found so far to avoid multiple entries
1772  const double mm=1.0; // for tracking vertices
1773  simPrimaryVertex sv(v->position().x()*mm,v->position().y()*mm,v->position().z()*mm);
1774 
1775  sv.eventId=v->eventId();
1776 
1777  for (TrackingParticleRefVector::iterator iTrack = v->daughterTracks_begin(); iTrack != v->daughterTracks_end(); ++iTrack){
1778  sv.eventId=(**iTrack).eventId();
1779  }
1780  simPrimaryVertex *vp=NULL; // will become non-NULL if a vertex is found and then point to it
1781  for(std::vector<simPrimaryVertex>::iterator v0=simpv.begin();
1782  v0!=simpv.end(); v0++){
1783  if( (sv.eventId==v0->eventId) && (fabs(sv.x-v0->x)<1e-5) && (fabs(sv.y-v0->y)<1e-5) && (fabs(sv.z-v0->z)<1e-5)){
1784  vp=&(*v0);
1785  break;
1786  }
1787  }
1788  if(!vp){
1789  // this is a new vertex
1790  if(DEBUG_){std::cout << "this is a new vertex " << sv.eventId.event() << " " << sv.x << " " << sv.y << " " << sv.z <<std::endl;}
1791  simpv.push_back(sv);
1792  vp=&simpv.back();
1793  }else{
1794  if(DEBUG_){std::cout << "this is not a new vertex" << sv.x << " " << sv.y << " " << sv.z <<std::endl;}
1795  }
1796 
1797  // Loop over daughter track(s)
1798  if(DEBUG_){
1799  for (TrackingVertex::tp_iterator iTP = v -> daughterTracks_begin(); iTP != v -> daughterTracks_end(); ++iTP) {
1800  std::cout << " Daughter momentum: " << (*(*iTP)).momentum();
1801  std::cout << " Daughter type " << (*(*iTP)).pdgId();
1802  std::cout << std::endl;
1803  }
1804  }
1805  }
1806  if(DEBUG_){
1807  cout << "------- PrimaryVertexAnalyzer4PU simPVs from TrackingVertices -------" << endl;
1808  for(std::vector<simPrimaryVertex>::iterator v0=simpv.begin();
1809  v0!=simpv.end(); v0++){
1810  cout << "z=" << v0->z << " event=" << v0->eventId.event() << endl;
1811  }
1812  cout << "-----------------------------------------------" << endl;
1813  }
1814  return simpv;
1815 }
1816 
1817 
1818 // ------------ method called to produce the data ------------
1819 void
1821 {
1822  std::vector<simPrimaryVertex> simpv; // a list of primary MC vertices
1823  std::vector<float> pui_z;
1824  std::vector<SimPart> tsim;
1825 
1826  eventcounter_++;
1827  run_ = iEvent.id().run();
1828  luminosityBlock_ = iEvent.luminosityBlock();
1829  event_ = iEvent.id().event();
1830  bunchCrossing_ = iEvent.bunchCrossing();
1831  orbitNumber_ = iEvent.orbitNumber();
1832 
1833  if(verbose_){
1834  std::cout << endl
1835  << "PrimaryVertexAnalyzer4PU::analyze event counter=" << eventcounter_
1836  << " Run=" << run_ << " LumiBlock " << luminosityBlock_ << " event " << event_
1837  << " bx=" << bunchCrossing_ << " orbit=" << orbitNumber_
1838  << std::endl;
1839  }
1840 
1841  try{
1842  iSetup.getData(pdt_);
1843  }catch(const Exception&){
1844  std::cout << "Some problem occurred with the particle data table. This may not work !" <<std::endl;
1845  }
1846 
1847  try{
1848 
1849  //get the pileup information
1851  iEvent.getByToken( vecPileupSummaryInfoToken_, puinfoH );
1852  PileupSummaryInfo puinfo;
1853 
1854  for (unsigned int puinfo_ite=0;puinfo_ite<(*puinfoH).size();++puinfo_ite){
1855  if ((*puinfoH)[puinfo_ite].getBunchCrossing()==0){
1856  puinfo=(*puinfoH)[puinfo_ite];
1857  break;
1858  }
1859  }
1860 
1861  pui_z = puinfo.getPU_zpositions();
1862 
1863  } catch( edm::Exception const & ex ) {
1864  if ( !ex.alreadyPrinted() ) {
1865  std::cout << ex.what() << " Maybe data?" << std::endl;
1866  }
1867  }
1868 
1870  bool bnoBS = iEvent.getByToken( recoVertexCollectionToken_, recVtxs );
1871 
1873  bool bBS = iEvent.getByToken( recoVertexCollection_BS_Token_, recVtxsBS );
1874 
1876  bool bDA = iEvent.getByToken( recoVertexCollection_DA_Token_, recVtxsDA );
1877 
1879  iEvent.getByToken( recoTrackCollectionToken_, recTrks );
1880 
1881  int nhighpurity=0, ntot=0;
1882  for(reco::TrackCollection::const_iterator t=recTrks->begin(); t!=recTrks->end(); ++t){
1883  ntot++;
1884  if(t->quality(reco::TrackBase::highPurity)) nhighpurity++;
1885  }
1886  if(ntot>10) hnoBS["highpurityTrackFraction"]->Fill(float(nhighpurity)/float(ntot));
1887  if((recoTrackProducer_=="generalTracks")&&(nhighpurity<0.25*ntot)){
1888  if(verbose_){ cout << "rejected, " << nhighpurity << " highpurity out of " << ntot << " total tracks "<< endl<< endl;}
1889  return;
1890  }
1891 
1895  Fill(hsimPV, "xbeam",vertexBeamSpot_.x0()); Fill(hsimPV, "wxbeam",vertexBeamSpot_.BeamWidthX());
1896  Fill(hsimPV, "ybeam",vertexBeamSpot_.y0()); Fill(hsimPV, "wybeam",vertexBeamSpot_.BeamWidthY());
1897  Fill(hsimPV, "zbeam",vertexBeamSpot_.z0());// Fill("wzbeam",vertexBeamSpot_.BeamWidthZ());
1898  }else{
1899  cout << " beamspot not found, using dummy " << endl;
1900  vertexBeamSpot_=reco::BeamSpot();// dummy
1901  }
1902 
1903  if(bnoBS){
1904  if((recVtxs->begin()->isValid())&&(recVtxs->begin()->ndof()>1)&&(recVtxs->begin()->ndof()>(0.0*recVtxs->begin()->tracksSize()))){ // was 5 and 0.2
1905  Fill(hnoBS,"xrecBeamvsdxXBS",recVtxs->begin()->xError(),recVtxs->begin()->x()-vertexBeamSpot_.x0());
1906  Fill(hnoBS,"yrecBeamvsdyXBS",recVtxs->begin()->yError(),recVtxs->begin()->y()-vertexBeamSpot_.y0());
1907 
1908  if(printXBS_) {
1909  cout << Form("XBS %10d %5d %14llu %4d %lu %5.2f %8f %8f %8f %8f %8f %8f",
1911  (unsigned long)(recVtxs->begin()->tracksSize()), recVtxs->begin()->ndof(),
1912  recVtxs->begin()->x(), recVtxs->begin()->xError(),
1913  recVtxs->begin()->y(), recVtxs->begin()->yError(),
1914  recVtxs->begin()->z(), recVtxs->begin()->zError()
1915  ) << endl;
1916  }
1917 
1918  }
1919  }
1920 
1921  // for the associator
1922  Handle<View<Track> > trackCollectionH;
1923  iEvent.getByToken( edmView_recoTrack_Token_, trackCollectionH );
1924 
1925  Handle<HepMCProduct> evtMC;
1926 
1928  iEvent.getByToken( edmSimVertexContainerToken_, simVtxs );
1929 
1930  Handle<SimTrackContainer> simTrks;
1931  iEvent.getByToken( edmSimTrackContainerToken_, simTrks );
1932 
1935  bool gotTP = iEvent.getByToken( trackingParticleCollectionToken_, TPCollectionH );
1936  bool gotTV = iEvent.getByToken( trackingVertexCollectionToken_, TVCollectionH );
1937 
1938  iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder",theB_);
1939  fBfield_=((*theB_).field()->inTesla(GlobalPoint(0.,0.,0.))).z();
1940 
1941  vector<SimEvent> simEvt;
1942  if (gotTP && gotTV ){
1943 
1945  iEvent.getByToken(recoTrackToTrackingParticleAssociatorToken_,theHitsAssociator);
1946  associatorByHits_ = theHitsAssociator.product();
1947  r2s_ = associatorByHits_->associateRecoToSim (trackCollectionH,TPCollectionH);
1948  simEvt=getSimEvents(TPCollectionH, TVCollectionH, trackCollectionH);
1949 
1950  if (simEvt.size()==0){
1951  cout << " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
1952  cout << " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
1953  cout << " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
1954  cout << " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
1955  cout << " !!!!!!!!!!!!!!!!!!!!!! got TrackingParticles but no simEvt !!!!!!!!!!!!!!!!!" << endl;
1956  cout << " dumping Tracking particles " << endl;
1957  const TrackingParticleCollection* simTracks = TPCollectionH.product();
1958  for(TrackingParticleCollection::const_iterator it=simTracks->begin(); it!=simTracks->end(); it++){
1959  cout << *it << endl;
1960  }
1961  cout << " dumping Tracking Vertices " << endl;
1962  const TrackingVertexCollection* tpVtxs = TVCollectionH.product();
1963  for(TrackingVertexCollection::const_iterator iv=tpVtxs->begin(); iv!=tpVtxs->end(); iv++){
1964  cout << *iv << endl;
1965  }
1966  if( iEvent.getByToken( edmHepMCProductToken_, evtMC ) ){
1967  cout << "dumping simTracks" << endl;
1968  for(SimTrackContainer::const_iterator t=simTrks->begin(); t!=simTrks->end(); ++t){
1969  cout << *t << endl;
1970  }
1971  cout << "dumping simVertexes" << endl;
1972  for(SimVertexContainer::const_iterator vv=simVtxs->begin();
1973  vv!=simVtxs->end();
1974  ++vv){
1975  cout << *vv << endl;
1976  }
1977  }else{
1978  cout << "no hepMC" << endl;
1979  }
1980  cout << " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
1981 
1982  const HepMC::GenEvent* evt=evtMC->GetEvent();
1983  if(evt){
1984  std::cout << "process id " <<evt->signal_process_id()<<std::endl;
1985  std::cout <<"signal process vertex "<< ( evt->signal_process_vertex() ?
1986  evt->signal_process_vertex()->barcode() : 0 ) <<std::endl;
1987  std::cout <<"number of vertices " << evt->vertices_size() << std::endl;
1988  evt->print();
1989  }else{
1990  cout << "no event in HepMC" << endl;
1991  }
1992  cout << " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
1993 
1994  }
1995  }
1996 
1997  if(gotTV){
1998 
1999  if(verbose_){
2000  cout << "Found Tracking Vertices " << endl;
2001  }
2002  simpv=getSimPVs(TVCollectionH);
2003 
2004 
2005  }else if( iEvent.getByToken( edmHepMCProductToken_, evtMC ) ) {
2006 
2007  simpv=getSimPVs(evtMC);
2008 
2009  if(verbose_){
2010  cout << "Using HepMCProduct " << endl;
2011  std::cout << "simtrks " << simTrks->size() << std::endl;
2012  }
2013  tsim = PrimaryVertexAnalyzer4PU::getSimTrkParameters(simTrks, simVtxs, simUnit_);
2014 
2015  }else{
2016  // if(verbose_({cout << "No MC info at all" << endl;}
2017  }
2018 
2019  // get the beam spot from the appropriate dummy vertex, if available
2020  for(reco::VertexCollection::const_iterator v=recVtxs->begin();
2021  v!=recVtxs->end(); ++v){
2022  if ((v->ndof()==-3) && (v->chi2()==0) ){
2023  myBeamSpot=math::XYZPoint(v->x(), v->y(), v->z());
2024  }
2025  }
2026 
2027  hsimPV["nsimvtx"]->Fill(simpv.size());
2028  for(std::vector<simPrimaryVertex>::iterator vsim=simpv.begin();
2029  vsim!=simpv.end(); vsim++){
2030  if(doMatching_){
2031  matchRecTracksToVertex(*vsim, tsim, recTrks); // hepmc, based on track parameters
2032  }
2033 
2034  hsimPV["nbsimtksinvtx"]->Fill(vsim->nGenTrk);
2035  hsimPV["xsim"]->Fill(vsim->x*simUnit_);
2036  hsimPV["ysim"]->Fill(vsim->y*simUnit_);
2037  hsimPV["zsim"]->Fill(vsim->z*simUnit_);
2038  hsimPV["xsim1"]->Fill(vsim->x*simUnit_);
2039  hsimPV["ysim1"]->Fill(vsim->y*simUnit_);
2040  hsimPV["zsim1"]->Fill(vsim->z*simUnit_);
2041  Fill(hsimPV,"xsim2",vsim->x*simUnit_,vsim==simpv.begin());
2042  Fill(hsimPV,"ysim2",vsim->y*simUnit_,vsim==simpv.begin());
2043  Fill(hsimPV,"zsim2",vsim->z*simUnit_,vsim==simpv.begin());
2044  hsimPV["xsim2"]->Fill(vsim->x*simUnit_);
2045  hsimPV["ysim2"]->Fill(vsim->y*simUnit_);
2046  hsimPV["zsim2"]->Fill(vsim->z*simUnit_);
2047  hsimPV["xsim3"]->Fill(vsim->x*simUnit_);
2048  hsimPV["ysim3"]->Fill(vsim->y*simUnit_);
2049  hsimPV["zsim3"]->Fill(vsim->z*simUnit_);
2050  hsimPV["xsimb"]->Fill(vsim->x*simUnit_-vertexBeamSpot_.x0());
2051  hsimPV["ysimb"]->Fill(vsim->y*simUnit_-vertexBeamSpot_.y0());
2052  hsimPV["zsimb"]->Fill(vsim->z*simUnit_-vertexBeamSpot_.z0());
2053  hsimPV["xsimb1"]->Fill(vsim->x*simUnit_-vertexBeamSpot_.x0());
2054  hsimPV["ysimb1"]->Fill(vsim->y*simUnit_-vertexBeamSpot_.y0());
2055  hsimPV["zsimb1"]->Fill(vsim->z*simUnit_-vertexBeamSpot_.z0());
2056  }
2057 
2058  if(bnoBS){
2059  analyzeVertexCollection(hnoBS, recVtxs, recTrks, simpv, pui_z, "noBS");
2060  analyzeVertexCollectionTP(hnoBS, recVtxs, recTrks, simEvt, r2s_,"noBS");
2061  }
2062  if(bBS){
2063  analyzeVertexCollection(hBS, recVtxsBS, recTrks, simpv, pui_z, "BS");
2064  analyzeVertexCollectionTP(hBS, recVtxsBS, recTrks, simEvt, r2s_,"BS");
2065  }
2066  if(bDA){
2067  analyzeVertexCollection(hDA, recVtxsDA, recTrks, simpv, pui_z, "DA");
2068  analyzeVertexCollectionTP(hDA, recVtxsDA, recTrks, simEvt, r2s_,"DA");
2069  }
2070 
2071  if((dumpThisEvent_&& (dumpcounter_<100)) ||(verbose_ && (eventcounter_<ndump_))){
2072  cout << endl << "Event dump" << endl
2073  << "event counter=" << eventcounter_
2074  << " Run=" << run_ << " LumiBlock " << luminosityBlock_ << " event " << event_
2075  << " bx=" << bunchCrossing_ << " orbit=" << orbitNumber_
2076  << std::endl;
2077  dumpcounter_++;
2078 
2079  if (bnoBS) {printRecVtxs(recVtxs,"Offline without Beamspot");}
2080  if (bnoBS && (!bDA)){ printPVTrks(recTrks, recVtxs, tsim, simEvt, false);}
2081  if (bBS) printRecVtxs(recVtxsBS,"Offline with Beamspot");
2082  if (bDA) {
2083  printRecVtxs(recVtxsDA,"Offline DA");
2084  printPVTrks(recTrks, recVtxsDA, tsim, simEvt, false);
2085  }
2086  if (dumpcounter_<2){cout << "beamspot " << vertexBeamSpot_ << endl;}
2087  }
2088 
2089  if(verbose_){
2090  std::cout << std::endl;
2091  }
2092 }
2093 
2094 namespace {
2095 bool lt(const std::pair<double,unsigned int>& a,const std::pair<double,unsigned int>& b ){
2096  return a.first<b.first;
2097 }
2098 }
2099 
2100 /***************************************************************************************/
2101 void PrimaryVertexAnalyzer4PU::printEventSummary(std::map<std::string, TH1*> & h,
2103  const edm::Handle<reco::TrackCollection> recTrks,
2104  vector<SimEvent> & simEvt,
2105  const string message){
2106  // make a readable summary of the vertex finding if the TrackingParticles are availabe
2107  if (simEvt.size()==0){return;}
2108 
2109 
2110  // sort vertices in z ... for nicer printout
2111 
2112  vector< pair<double,unsigned int> > zrecv;
2113  for(unsigned int idx=0; idx<recVtxs->size(); idx++){
2114  if ( (recVtxs->at(idx).ndof()<0) || (recVtxs->at(idx).chi2()<=0) ) continue; // skip clusters
2115  zrecv.push_back( make_pair(recVtxs->at(idx).z(),idx) );
2116  }
2117  stable_sort(zrecv.begin(),zrecv.end(),lt);
2118 
2119  // same for simulated vertices
2120  vector< pair<double,unsigned int> > zsimv;
2121  for(unsigned int idx=0; idx<simEvt.size(); idx++){
2122  zsimv.push_back(make_pair(simEvt[idx].z, idx));
2123  }
2124  stable_sort(zsimv.begin(), zsimv.end(),lt);
2125 
2126  cout << "---------------------------" << endl;
2127  cout << "event counter = " << eventcounter_ << " " << message << endl;
2128  cout << "---------------------------" << endl;
2129  cout << " z[cm] rec --> ";
2130  cout.precision(4);
2131  for(vector< pair<double,unsigned int> >::iterator itrec=zrecv.begin(); itrec!=zrecv.end(); itrec++){
2132  cout << setw(7) << fixed << itrec->first;
2133  if (itrec->second==0){cout << "*" ;}else{cout << " " ;}
2134  }
2135  cout << endl;
2136  cout << " ";
2137  for(vector< pair<double,unsigned int> >::iterator itrec=zrecv.begin(); itrec!=zrecv.end(); itrec++){
2138  cout << setw(7) << fixed << recVtxs->at(itrec->second).tracksSize();
2139  if (itrec->second==0){cout << "*" ;}else{cout << " " ;}
2140  }
2141  cout << " rec tracks" << endl;
2142  cout << " ";
2143  map<unsigned int, int> truthMatchedVertexTracks;
2144  for(vector< pair<double,unsigned int> >::iterator itrec=zrecv.begin(); itrec!=zrecv.end(); itrec++){
2145  truthMatchedVertexTracks[itrec->second]=getTruthMatchedVertexTracks(recVtxs->at(itrec->second)).size();
2146  cout << setw(7) << fixed << truthMatchedVertexTracks[itrec->second];
2147  if (itrec->second==0){cout << "*" ;}else{cout << " " ;}
2148  }
2149  cout << " truth matched " << endl;
2150 
2151  cout << "sim ------- trk prim ----" << endl;
2152 
2153  map<unsigned int, unsigned int> rvmatch; // reco vertex matched to sim vertex (sim to rec)
2154  map<unsigned int, double > nmatch; // highest number of truth-matched tracks of ev found in a recvtx
2155  map<unsigned int, double > purity; // highest purity of a rec vtx (i.e. highest number of tracks from the same simvtx)
2156  map<unsigned int, double > wpurity; // same for the sum of weights
2157 
2158  for(vector< pair<double,unsigned int> >::iterator itrec=zrecv.begin(); itrec!=zrecv.end(); itrec++){
2159  purity[itrec->second]=0.;
2160  wpurity[itrec->second]=0.;
2161  }
2162 
2163  for(vector< pair<double,unsigned int> >::iterator itsim=zsimv.begin(); itsim!=zsimv.end(); itsim++){
2164  SimEvent* ev =&(simEvt[itsim->second]);
2165 
2166  cout.precision(4);
2167  if (itsim->second==0){
2168  cout << setw(8) << fixed << ev->z << ")*" << setw(5) << ev->tk.size() << setw(5) << ev->tkprim.size() << " | ";
2169  }else{
2170  cout << setw(8) << fixed << ev->z << ") " << setw(5) << ev->tk.size() << setw(5) << ev->tkprim.size() << " | ";
2171  }
2172 
2173  nmatch[itsim->second]=0; // highest number of truth-matched tracks of ev found in a recvtx
2174  double matchpurity=0,matchwpurity=0;
2175 
2176  for(vector< pair<double,unsigned int> >::iterator itrec=zrecv.begin(); itrec!=zrecv.end(); itrec++){
2177  const reco::Vertex *v = &(recVtxs->at(itrec->second));
2178 
2179  // count tracks found in both, sim and rec
2180  double n=0,wt=0;
2181  for(vector<TransientTrack>::iterator te=ev->tk.begin(); te!=ev->tk.end(); te++){
2182  const reco::Track& RTe=te->track();
2183  for(trackit_t tv=v->tracks_begin(); tv!=v->tracks_end(); tv++){
2184  const reco::Track & RTv=*(tv->get());
2185  if(RTe.vz()==RTv.vz()) {n++; wt+=v->trackWeight(*tv);}
2186  }
2187  }
2188  cout << setw(7) << int(n)<< " ";
2189 
2190  if (n > nmatch[itsim->second]){
2191  nmatch[itsim->second]=n;
2192  rvmatch[itsim->second]=itrec->second;
2193  matchpurity=n/truthMatchedVertexTracks[itrec->second];
2194  matchwpurity=wt/truthMatchedVertexTracks[itrec->second];
2195  }
2196 
2197  if(n > purity[itrec->second]){
2198  purity[itrec->second]=n;
2199  }
2200 
2201  if(wt > wpurity[itrec->second]){
2202  wpurity[itrec->second]=wt;
2203  }
2204 
2205  }// end of reco vertex loop
2206 
2207  cout << " | ";
2208  if (nmatch[itsim->second]>0 ){
2209  if(matchpurity>0.5){
2210  cout << "found ";
2211  }else{
2212  cout << "merged ";
2213  }
2214  cout << " max eff. = " << setw(8) << nmatch[itsim->second]/ev->tk.size() << " p=" << matchpurity << " w=" << matchwpurity << endl;
2215  }else{
2216  if(ev->tk.size()==0){
2217  cout << " invisible" << endl;
2218  }else if (ev->tk.size()==1){
2219  cout << "single track " << endl;
2220  }else{
2221  cout << "lost " << endl;
2222  }
2223  }
2224  }
2225  cout << "---------------------------" << endl;
2226 
2227  // the purity of the reconstructed vertex
2228  cout << " purity ";
2229  for(vector< pair<double,unsigned int> >::iterator itrec=zrecv.begin(); itrec!=zrecv.end(); itrec++){
2230  cout << setw(7) << fixed << purity[itrec->second]/truthMatchedVertexTracks[itrec->second];
2231  if (itrec->second==0){cout << "*" ;}else{cout << " " ;}
2232  }
2233  cout << endl;
2234 
2235  cout << "---------------------------" << endl;
2236 
2237  // list problematic tracks
2238  for(vector< pair<double,unsigned int> >::iterator itsim=zsimv.begin(); itsim!=zsimv.end(); itsim++){
2239  SimEvent* ev =&(simEvt[itsim->second]);
2240 
2241  for(vector<TransientTrack>::iterator te=ev->tk.begin(); te!=ev->tk.end(); te++){
2242  const reco::Track& RTe=te->track();
2243 
2244  int ivassign=-1; // will become the index of the vertex to which a track was assigned
2245 
2246  for(vector< pair<double,unsigned int> >::iterator itrec=zrecv.begin(); itrec!=zrecv.end(); itrec++){
2247  const reco::Vertex *v = &(recVtxs->at(itrec->second));
2248 
2249  for(trackit_t tv=v->tracks_begin(); tv!=v->tracks_end(); tv++){
2250  const reco::Track & RTv=*(tv->get());
2251  if(RTe.vz()==RTv.vz()) {ivassign=itrec->second;}
2252  }
2253  }
2254  double tantheta=tan((te->stateAtBeamLine().trackStateAtPCA()).momentum().theta());
2255  reco::BeamSpot beamspot=(te->stateAtBeamLine()).beamSpot();
2256  double dz2= pow(RTe.dzError(),2)+pow(beamspot.BeamWidthX()/tantheta,2);
2257 
2258  if(ivassign==(int)rvmatch[itsim->second]){
2259  Fill(h,"correctlyassigned",RTe.eta(),RTe.pt());
2260  Fill(h,"ptcat",RTe.pt());
2261  Fill(h,"etacat",RTe.eta());
2262  Fill(h,"phicat",RTe.phi());
2263  Fill(h,"dzcat",sqrt(dz2));
2264  }else{
2265  Fill(h,"misassigned",RTe.eta(),RTe.pt());
2266  Fill(h,"ptmis",RTe.pt());
2267  Fill(h,"etamis",RTe.eta());
2268  Fill(h,"phimis",RTe.phi());
2269  Fill(h,"dzmis",sqrt(dz2));
2270  cout << "vertex " << setw(8) << fixed << ev->z;
2271 
2272  if (ivassign<0){
2273  cout << " track lost ";
2274  // for some clusterizers there shouldn't be any lost tracks,
2275  // are there differences in the track selection?
2276  }else{
2277  cout << " track misassigned " << setw(8) << fixed << recVtxs->at(ivassign).z();
2278  }
2279 
2280  cout << " track z=" << setw(8) << fixed << RTe.vz() << "+/-" << RTe.dzError() << " pt=" << setw(8) << fixed<< RTe.pt() << " eta=" << setw(8) << fixed << RTe.eta()<< " sel=" <<theTrackFilter(*te);
2281 
2282  //
2283  //cout << " ztrack=" << te->track().vz();
2284  TrackingParticleRef tpr = z2tp_[te->track().vz()];
2285  double zparent=tpr->parentVertex().get()->position().z();
2286  if(zparent==ev->z) {
2287  cout << " prim";
2288  }else{
2289  cout << " sec ";
2290  }
2291  cout << " id=" << tpr->pdgId();
2292  cout << endl;
2293 
2294  //
2295  }
2296  }// next simvertex-track
2297 
2298  }//next simvertex
2299 
2300  cout << "---------------------------" << endl;
2301 
2302 }
2303 /***************************************************************************************/
2304 
2305 void PrimaryVertexAnalyzer4PU::analyzeVertexCollectionTP(std::map<std::string, TH1*> & h,
2307  const edm::Handle<reco::TrackCollection> recTrks,
2308  vector<SimEvent> & simEvt,
2310  const string message){
2311  if(simEvt.size()==0)return;
2312 
2313  printEventSummary(h, recVtxs,recTrks,simEvt,message);
2314 
2315  //const int iSignal=0;
2316  EncodedEventId iSignal=simEvt[0].eventId;
2317  Fill(h,"npu0",simEvt.size());
2318 
2319  for(vector<SimEvent>::iterator ev=simEvt.begin(); ev!=simEvt.end(); ev++){
2320  Fill(h,"Tc", ev->Tc, ev==simEvt.begin());
2321  Fill(h,"Chisq", ev->chisq, ev==simEvt.begin());
2322  if(ev->chisq>0)Fill(h,"logChisq", log(ev->chisq), ev==simEvt.begin());
2323  Fill(h,"dzmax", ev->dzmax, ev==simEvt.begin());
2324  Fill(h,"dztrim",ev->dztrim,ev==simEvt.begin());
2325  Fill(h,"m4m2", ev->m4m2, ev==simEvt.begin());
2326  if(ev->Tc>0){ Fill(h,"logTc",log(ev->Tc)/log(10.),ev==simEvt.begin());}
2327 
2328  for(vector<SimEvent>::iterator ev2=ev+1; ev2!=simEvt.end(); ev2++){
2329  vector<TransientTrack> xt;
2330  if((ev->tkprimsel.size()>0)&&(ev2->tkprimsel.size()>0)&&(ev->tkprimsel.size()+ev2->tkprimsel.size())>1){
2331  xt.insert (xt.end() ,ev->tkprimsel.begin(),ev->tkprimsel.end());
2332  xt.insert (xt.end() ,ev2->tkprimsel.begin(),ev2->tkprimsel.end());
2333  double xTc,xChsq,xDzmax,xDztrim,xm4m2;
2334  getTc(xt, xTc, xChsq, xDzmax, xDztrim,xm4m2);
2335  if(xTc>0){
2336  Fill(h,"xTc",xTc,ev==simEvt.begin());
2337  Fill(h,"logxTc", log(xTc)/log(10),ev==simEvt.begin());
2338  Fill(h,"xChisq", xChsq,ev==simEvt.begin());
2339  if(xChsq>0){Fill(h,"logxChisq", log(xChsq),ev==simEvt.begin());};
2340  Fill(h,"xdzmax", xDzmax,ev==simEvt.begin());
2341  Fill(h,"xdztrim", xDztrim,ev==simEvt.begin());
2342  Fill(h,"xm4m2", xm4m2,ev==simEvt.begin());
2343 
2344  }
2345  }
2346  }
2347  }
2348 
2349  // --------------------------------------- count actual rec vtxs ----------------------
2350  int nrecvtxs=0;//, nrecvtxs1=0, nrecvtxs2=0;
2351  for(reco::VertexCollection::const_iterator v=recVtxs->begin();
2352  v!=recVtxs->end(); ++v){
2353  if ( (v->isFake()) || (v->ndof()<0) || (v->chi2()<=0) ) continue; // skip clusters
2354  nrecvtxs++;
2355  }
2356 
2357  // --------------------------------------- fill the track assignment matrix ----------------------
2358  for(vector<SimEvent>::iterator ev=simEvt.begin(); ev!=simEvt.end(); ev++){
2359  ev->ntInRecVz.clear(); // just in case
2360  ev->zmatch=-99.;
2361  ev->nmatch=0;
2362  for(reco::VertexCollection::const_iterator v=recVtxs->begin();
2363  v!=recVtxs->end(); ++v){
2364  double n=0, wt=0;
2365  for(vector<TransientTrack>::iterator te=ev->tk.begin(); te!=ev->tk.end(); te++){
2366  const reco::Track& RTe=te->track();
2367  for(trackit_t tv=v->tracks_begin(); tv!=v->tracks_end(); tv++){
2368  const reco::Track & RTv=*(tv->get());
2369  if(RTe.vz()==RTv.vz()) {n++; wt+=v->trackWeight(*tv);}
2370  }
2371  }
2372  ev->ntInRecVz[v->z()]=n;
2373  if (n > ev->nmatch){ ev->nmatch=n; ev->zmatch=v->z(); ev->zmatch=v->z(); }
2374  }
2375  }
2376 
2377  // call a vertex a fake if for every sim vertex there is another recvertex containing more tracks
2378  // from that sim vertex than the current recvertex
2379  double nfake=0;
2380  for(reco::VertexCollection::const_iterator v=recVtxs->begin();
2381  v!=recVtxs->end(); ++v){
2382  bool matched=false;
2383  for(vector<SimEvent>::iterator ev=simEvt.begin(); ev!=simEvt.end(); ev++){
2384  if ((ev->nmatch>0)&&(ev->zmatch==v->z())){
2385  matched=true;
2386  }
2387  }
2388  if(!matched && !v->isFake()) {
2389  nfake++;
2390  cout << " fake rec vertex at z=" << v->z() << endl;
2391  // some histograms of fake vertex properties here
2392  Fill(h,"unmatchedVtxZ",v->z());
2393  Fill(h,"unmatchedVtxNdof",v->ndof());
2394  }
2395  }
2396  if(nrecvtxs>0){
2397  Fill(h,"unmatchedVtx",nfake);
2398  Fill(h,"unmatchedVtxFrac",nfake/nrecvtxs);
2399  }
2400 
2401  // --------------------------------------- match rec to sim ---------------------------------------
2402  for(reco::VertexCollection::const_iterator v=recVtxs->begin();
2403  v!=recVtxs->end(); ++v){
2404 
2405  if ( (v->ndof()<0) || (v->chi2()<=0) ) continue; // skip clusters
2406  double nmatch=-1; // highest number of tracks in recvtx v found in any event
2407  EncodedEventId evmatch;
2408  bool matchFound=false;
2409  double nmatchvtx=0; // number of simvtcs contributing to recvtx v
2410 
2411  for(vector<SimEvent>::iterator ev=simEvt.begin(); ev!=simEvt.end(); ev++){
2412 
2413  double n=0; // number of tracks that are in both, the recvtx v and the event ev
2414  for(vector<TransientTrack>::iterator te=ev->tk.begin(); te!=ev->tk.end(); te++){
2415 
2416  const reco::Track& RTe=te->track();
2417  for(trackit_t tv=v->tracks_begin(); tv!=v->tracks_end(); tv++){
2418  const reco::Track & RTv=*(tv->get());
2419  if(RTe.vz()==RTv.vz()){ n++;}
2420  }
2421  }
2422 
2423  // find the best match in terms of the highest number of tracks
2424  // from a simvertex in this rec vertex
2425  if (n > nmatch){
2426  nmatch=n;
2427  evmatch=ev->eventId;
2428  matchFound=true;
2429  }
2430  if(n>0){
2431  nmatchvtx++;
2432  }
2433  }
2434 
2435  double nmatchany=getTruthMatchedVertexTracks(*v).size();
2436  if (matchFound && (nmatchany>0)){
2437  // highest number of tracks in recvtx matched to (the same) sim vertex
2438  // purity := -----------------------------------------------------------------
2439  // number of truth matched tracks in this recvtx
2440  double purity =nmatch/nmatchany;
2441  Fill(h,"recmatchPurity",purity);
2442  if(v==recVtxs->begin()){
2443  Fill(h,"recmatchPurityTag",purity, (bool)(evmatch==iSignal));
2444  }else{
2445  Fill(h,"recmatchPuritynoTag",purity,(bool)(evmatch==iSignal));
2446  }
2447  }
2448  Fill(h,"recmatchvtxs",nmatchvtx);
2449  if(v==recVtxs->begin()){
2450  Fill(h,"recmatchvtxsTag",nmatchvtx);
2451  }else{
2452  Fill(h,"recmatchvtxsnoTag",nmatchvtx);
2453  }
2454 
2455  } // recvtx loop
2456  Fill(h,"nrecv",nrecvtxs);
2457 
2458 
2459  // --------------------------------------- match sim to rec ---------------------------------------
2460  int npu1=0, npu2=0;
2461 
2462  vector<int> used_indizesV;
2463  int lastEvent = 999;
2464 
2465  for(vector<SimEvent>::iterator ev=simEvt.begin(); ev!=simEvt.end(); ev++){
2466 
2467  if(ev->tk.size()>0) npu1++;
2468  if(ev->tk.size()>1) npu2++;
2469 
2470  double sep = getTrueSeparation(*ev, simEvt);
2471 
2472  bool isSignal= ev->eventId==iSignal;
2473 
2474  Fill(h,"nRecTrkInSimVtx",(double) ev->tk.size(),isSignal);
2475  Fill(h,"nPrimRecTrkInSimVtx",(double) ev->tkprim.size(),isSignal);
2476  Fill(h,"sumpt2rec",sqrt(ev->sumpt2rec),isSignal);
2477  Fill(h,"sumpt2",sqrt(ev->sumpt2),isSignal);
2478  Fill(h,"sumpt",sqrt(ev->sumpt),isSignal);
2479 
2480  double nRecVWithTrk=0; // vertices with tracks from this simvertex
2481  double nmatch=0, ntmatch=0, zmatch=-99;
2482 
2483  for(reco::VertexCollection::const_iterator v=recVtxs->begin();
2484  v!=recVtxs->end(); ++v){
2485  if ( (v->ndof()<-1) || (v->chi2()<=0) ) continue; // skip clusters
2486  // count tracks found in both, sim and rec
2487  double n=0, wt=0;
2488  for(vector<TransientTrack>::iterator te=ev->tk.begin(); te!=ev->tk.end(); te++){
2489  const reco::Track& RTe=te->track();
2490  for(trackit_t tv=v->tracks_begin(); tv!=v->tracks_end(); tv++){
2491  const reco::Track & RTv=*(tv->get());
2492  if(RTe.vz()==RTv.vz()) {n++; wt+=v->trackWeight(*tv);}
2493  }
2494  }
2495 
2496  if(n>0){ nRecVWithTrk++; }
2497  if (n > nmatch){
2498  nmatch=n; ntmatch=v->tracksSize(); zmatch=v->position().z();
2499  }
2500 
2501  }// end of reco vertex loop
2502 
2503  // nmatch is the highest number of tracks from this sim vertex found in a single reco-vertex
2504  if(ev->tk.size()>0){ Fill(h,"trkAssignmentEfficiency", nmatch/ev->tk.size(), isSignal); };
2505  if(ev->tkprim.size()>0){ Fill(h,"primtrkAssignmentEfficiency", nmatch/ev->tkprim.size(), isSignal); };
2506 
2507  // matched efficiency = efficiency for finding a reco vertex with > 50% of the simvertexs reconstructed tracks
2508 
2509  double ntsim=ev->tk.size(); // may be better to use the number of primary tracks here ?
2510  double matchpurity=nmatch/ntmatch;
2511 
2512  if(ntsim>0){
2513 
2514  Fill(h,"matchVtxFraction",nmatch/ntsim,isSignal);
2515  if(nmatch/ntsim>=0.5){
2516  Fill(h,"matchVtxEfficiency",1.,isSignal);
2517  if(ntsim>1){Fill(h,"matchVtxEfficiency2",1.,isSignal);}
2518  if(matchpurity>0.5){Fill(h,"matchVtxEfficiency5",1.,isSignal);}
2519  }else{
2520  Fill(h,"matchVtxEfficiency",0.,isSignal);
2521  if(ntsim>1){Fill(h,"matchVtxEfficiency2",0.,isSignal);}
2522  Fill(h,"matchVtxEfficiency5",0.,isSignal); // no (matchpurity>5) here !!
2523  if(isSignal){
2524  cout << "Signal vertex not matched " << message << " event=" << eventcounter_ << " nmatch=" << nmatch << " ntsim=" << ntsim << endl;
2525  }
2526  }
2527  } // ntsim >0
2528 
2529  if(zmatch>-99){
2530  Fill(h,"matchVtxZ",zmatch-ev->z);
2531  Fill(h,"matchVtxZ",zmatch-ev->z,isSignal);
2532  Fill(h,"matchVtxZCum",fabs(zmatch-ev->z));
2533  Fill(h,"matchVtxZCum",fabs(zmatch-ev->z),isSignal);
2534 
2535  }else{
2536  Fill(h,"matchVtxZCum",1.0);
2537  Fill(h,"matchVtxZCum",1.0,isSignal);
2538 
2539  }
2540  if(fabs(zmatch-ev->z)<zmatch_){
2541  Fill(h,"matchVtxEfficiencyZ",1.,isSignal);
2542  }else{
2543  Fill(h,"matchVtxEfficiencyZ",0.,isSignal);
2544  }
2545 
2546  if(ntsim>0) Fill(h, "matchVtxEfficiencyZ1", fabs(zmatch-ev->z)<zmatch_ , isSignal);
2547  if(ntsim>1) Fill(h, "matchVtxEfficiencyZ2", fabs(zmatch-ev->z)<zmatch_ , isSignal);
2548 
2549 
2550  Fill(h,"vtxMultiplicity",nRecVWithTrk,isSignal);
2551 
2552  // efficiency vs number of tracks, use your favorite definition of efficiency here
2553  if(fabs(zmatch-ev->z)<zmatch_){ // zmatch
2554  Fill(h,"vtxFindingEfficiencyVsNtrk",(double) ev->tk.size(),1.);
2555  if(isSignal){
2556  Fill(h,"vtxFindingEfficiencyVsNtrkSignal",ev->tk.size(),1.);
2557  }else{
2558  Fill(h,"vtxFindingEfficiencyVsNtrkPU",(double) ev->tk.size(),1.);
2559  }
2560 
2561  }else{
2562  Fill(h,"vtxFindingEfficiencyVsNtrk",(double) ev->tk.size(),0.);
2563  if(isSignal){
2564  Fill(h,"vtxFindingEfficiencyVsNtrkSignal",(double) ev->tk.size(),1.);
2565  }else{
2566  Fill(h,"vtxFindingEfficiencyVsNtrkPU",(double) ev->tk.size(),1.);
2567  }
2568  }
2569 
2570  //part of the separation efficiency profiles
2571 
2572  if ( ev->eventId.event()==lastEvent ) continue;
2573  lastEvent = ev->eventId.event();
2574 
2575  if ( ( fabs(ev->z)>24. ) || ( ev->eventId.bunchCrossing()!=0 ) ) continue;
2576 
2577  int max_match = 0;
2578  int best_match = 999;
2579 
2580  for ( unsigned rv_idx=0; rv_idx<recVtxs->size(); rv_idx++ ) {
2581 
2582  VertexRef vtx_ref(recVtxs, rv_idx);
2583 
2584  int match = 0;
2585 
2586  for ( vector<TrackBaseRef>::const_iterator rv_trk_ite=vtx_ref->tracks_begin(); rv_trk_ite!=vtx_ref->tracks_end(); rv_trk_ite++ ) {
2587 
2588  vector<pair<TrackingParticleRef, double> > tp;
2589  if ( rsC.find(*rv_trk_ite)!=rsC.end() ) tp = rsC[*rv_trk_ite];
2590 
2591  for ( unsigned matched_tp_idx=0; matched_tp_idx<tp.size(); matched_tp_idx++ ) {
2592 
2593  TrackingParticle trackpart = *(tp[matched_tp_idx].first);
2594  EncodedEventId tp_ev = trackpart.eventId();
2595 
2596  if ( ( tp_ev.bunchCrossing()==ev->eventId.bunchCrossing() ) && ( tp_ev.event()==ev->eventId.event() ) ) {
2597  match++;
2598  break;
2599  }
2600 
2601  }
2602 
2603  }
2604 
2605 
2606  if ( match > max_match ) {
2607 
2608  max_match = match;
2609  best_match = rv_idx;
2610 
2611  }
2612 
2613  }
2614 
2615  double eff = 0.;
2616  double effwod = 0.;
2617  double dsimed = 0.;
2618 
2619  bool dsflag = false;
2620 
2621  for (unsigned i=0;i<used_indizesV.size(); i++) {
2622  if ( used_indizesV.at(i)==best_match ) {
2623  dsflag = true;
2624  break;
2625  }
2626  }
2627 
2628  if ( best_match!=999 ) eff = 1.;
2629  if ( dsflag ) dsimed = 1.;
2630  if ( ( best_match!=999 ) && ( !dsflag ) ) effwod = 1.;
2631 
2632  if ( best_match!=999 ) {
2633  used_indizesV.push_back(best_match);
2634  }
2635 
2636  Fill(h,"tveffvszsep", sep, eff);
2637  Fill(h,"tveffwodvszsep", sep, effwod);
2638  Fill(h,"tvmergedvszsep", sep, dsimed);
2639 
2640 
2641  }
2642 
2643  Fill(h,"npu1",npu1);
2644  Fill(h,"npu2",npu2);
2645 
2646  Fill(h,"nrecvsnpu",npu1,float(nrecvtxs));
2647  Fill(h,"nrecvsnpu2",npu2,float(nrecvtxs));
2648 
2649  // --------------------------------------- sim-signal vs rec-tag ---------------------------------------
2650  SimEvent* ev=&(simEvt[0]);
2651  const reco::Vertex* v=&(*recVtxs->begin());
2652 
2653  double n=0;
2654  for(vector<TransientTrack>::iterator te=ev->tk.begin(); te!=ev->tk.end(); te++){
2655  const reco::Track& RTe=te->track();
2656  for(trackit_t tv=v->tracks_begin(); tv!=v->tracks_end(); tv++){
2657  const reco::Track & RTv=*(tv->get());
2658  if(RTe.vz()==RTv.vz()) {n++;}
2659  }
2660  }
2661 
2662  cout << "Number of tracks in reco tagvtx " << v->tracksSize() << endl;
2663  cout << "Number of selected tracks in sim event vtx " << ev->tk.size() << " (prim=" << ev->tkprim.size() << ")"<<endl;
2664  cout << "Number of tracks in both " << n << endl;
2665  double ntruthmatched=getTruthMatchedVertexTracks(*v).size();
2666  if (ntruthmatched>0){
2667  cout << "TrackPurity = "<< n/ntruthmatched <<endl;
2668  Fill(h,"TagVtxTrkPurity",n/ntruthmatched);
2669  }
2670  if (ev->tk.size()>0){
2671  cout << "TrackEfficiency = "<< n/ev->tk.size() <<endl;
2672  Fill(h,"TagVtxTrkEfficiency",n/ev->tk.size());
2673  }
2674 }
2675 
2676 /***************************************************************************************/
2677 
2678 void PrimaryVertexAnalyzer4PU::analyzeVertexCollection(std::map<std::string, TH1*> & h,
2679  const Handle<reco::VertexCollection> recVtxs,
2680  const Handle<reco::TrackCollection> recTrks,
2681  std::vector<simPrimaryVertex> & simpv,
2682  const std::vector<float> & pui_z,
2683  const std::string message)
2684 {
2685  int nrectrks=recTrks->size();
2686  int nrecvtxs=recVtxs->size();
2687  int nseltrks=-1;
2688  reco::TrackCollection selTrks; // selected tracks
2689  reco::TrackCollection lostTrks; // selected but lost tracks (part of dropped clusters)
2690 
2691  // extract dummy vertices representing clusters
2693  reco::Vertex allSelected;
2694  double cpufit=0;
2695  double cpuclu=0;
2696  for(reco::VertexCollection::const_iterator v=recVtxs->begin();
2697  v!=recVtxs->end(); ++v){
2698  if ( (fabs(v->ndof()+3.)<0.0001) && (v->chi2()<=0) ){
2699  // this dummy vertex is for the full event
2700  allSelected=(*v);
2701  nseltrks=(allSelected.tracksSize());
2702  nrecvtxs--;
2703  cpuclu=-v->chi2();
2704  continue;
2705  }else if( (fabs(v->ndof()+2.)<0.0001) && (v->chi2()==0) ){
2706  // this is a cluster, not a vertex
2707  clusters.push_back(*v);
2708  Fill(h,"cpuvsntrk",(double) v->tracksSize(),fabs(v->y()));
2709  cpufit+=fabs(v->y());
2710  Fill(h,"nclutrkall",(double) v->tracksSize());
2711  Fill(h,"selstat",v->x());
2712  nrecvtxs--;
2713  }
2714  }
2715  Fill(h,"cpuclu",cpuclu);
2716  Fill(h,"cpufit",cpufit);
2717  Fill(h,"cpucluvsntrk",nrectrks, cpuclu);
2718 
2719  if(simpv.size()>0){//this is mc
2720  double dsimrecx=0.;
2721  double dsimrecy=0.;//0.0011;
2722  double dsimrecz=0.;//0.0012;
2723 
2724  // vertex matching and efficiency bookkeeping
2725  int nsimtrk=0;
2726  for(std::vector<simPrimaryVertex>::iterator vsim=simpv.begin();
2727  vsim!=simpv.end(); vsim++){
2728 
2729  nsimtrk+=vsim->nGenTrk;
2730  // look for a matching reconstructed vertex
2731  vsim->recVtx=NULL;
2732  vsim->cluster=-1;
2733 
2734  for(reco::VertexCollection::const_iterator vrec=recVtxs->begin(); vrec!=recVtxs->end(); ++vrec){
2735 
2736  if( vrec->isFake() ) {
2737  continue; // skip fake vertices (=beamspot)
2738  cout << "fake vertex" << endl;
2739  }
2740 
2741  if( vrec->ndof()<0. )continue; // skip dummy clusters, if any
2742  // if ( matchVertex(*vsim,*vrec) ){
2743 
2744  // if the matching critera are fulfilled, accept the rec-vertex that is closest in z
2745  if( ((vsim->recVtx) && (fabs(vsim->recVtx->position().z()-vsim->z-dsimrecz)>fabs(vrec->z()-vsim->z-dsimrecz)))
2746  || (!vsim->recVtx) )
2747  {
2748  vsim->recVtx=&(*vrec);
2749 
2750  // find the corresponding cluster
2751  for(unsigned int iclu=0; iclu<clusters.size(); iclu++){
2752  if( fabs(clusters[iclu].position().z()-vrec->position().z()) < 0.001 ){
2753  vsim->cluster=iclu;
2754  vsim->nclutrk=clusters[iclu].position().y();
2755  }
2756  }
2757  }
2758 
2759  // the following only works in MC samples without pile-up
2760  if ((simpv.size()==1) && ( fabs(vsim->recVtx->position().z()-vsim->z-dsimrecz)>zmatch_ )){
2761 
2762  // now we have a recvertex without a matching simvertex, I would call this fake
2763  // however, the G4 info does not contain pile-up
2764  Fill(h,"fakeVtxZ",vrec->z());
2765  if (vrec->ndof()>=0.5) Fill(h,"fakeVtxZNdofgt05",vrec->z());
2766  if (vrec->ndof()>=2.0) Fill(h,"fakeVtxZNdofgt2",vrec->z());
2767  Fill(h,"fakeVtxNdof",vrec->ndof());
2768  Fill(h,"fakeVtxNtrk",vrec->tracksSize());
2769  if(vrec->tracksSize()==2){ Fill(h,"fake2trkchi2vsndof",vrec->ndof(),vrec->chi2()); }
2770  if(vrec->tracksSize()==3){ Fill(h,"fake3trkchi2vsndof",vrec->ndof(),vrec->chi2()); }
2771  if(vrec->tracksSize()==4){ Fill(h,"fake4trkchi2vsndof",vrec->ndof(),vrec->chi2()); }
2772  if(vrec->tracksSize()==5){ Fill(h,"fake5trkchi2vsndof",vrec->ndof(),vrec->chi2()); }
2773  }
2774  }
2775 
2776  Fill(h,"nsimtrk",float(nsimtrk));
2777  Fill(h,"nsimtrk",float(nsimtrk),vsim==simpv.begin());
2778  Fill(h,"nrecsimtrk",float(vsim->nMatchedTracks));
2779  Fill(h,"nrecnosimtrk",float(nsimtrk-vsim->nMatchedTracks));
2780 
2781  // histogram properties of matched vertices
2782  if (vsim->recVtx && ( fabs(vsim->recVtx->z()-vsim->z*simUnit_)<zmatch_ )){
2783 
2784  if(verbose_){std::cout <<"primary matched " << message << " " << setw(8) << setprecision(4) << vsim->x << " " << vsim->y << " " << vsim->z << std:: endl;}
2785  Fill(h,"matchedVtxNdof", vsim->recVtx->ndof());
2786  // residuals an pulls with respect to simulated vertex
2787  Fill(h,"resx", vsim->recVtx->x()-vsim->x*simUnit_ );
2788  Fill(h,"resy", vsim->recVtx->y()-vsim->y*simUnit_ );
2789  Fill(h,"resz", vsim->recVtx->z()-vsim->z*simUnit_ );
2790  Fill(h,"resz10", vsim->recVtx->z()-vsim->z*simUnit_ );
2791  Fill(h,"pullx", (vsim->recVtx->x()-vsim->x*simUnit_)/vsim->recVtx->xError() );
2792  Fill(h,"pully", (vsim->recVtx->y()-vsim->y*simUnit_)/vsim->recVtx->yError() );
2793  Fill(h,"pullz", (vsim->recVtx->z()-vsim->z*simUnit_)/vsim->recVtx->zError() );
2794  Fill(h,"resxr", vsim->recVtx->x()-vsim->x*simUnit_-dsimrecx);
2795  Fill(h,"resyr", vsim->recVtx->y()-vsim->y*simUnit_-dsimrecy );
2796  Fill(h,"reszr", vsim->recVtx->z()-vsim->z*simUnit_-dsimrecz);
2797  Fill(h,"pullxr", (vsim->recVtx->x()-vsim->x*simUnit_-dsimrecx)/vsim->recVtx->xError() );
2798  Fill(h,"pullyr", (vsim->recVtx->y()-vsim->y*simUnit_-dsimrecy)/vsim->recVtx->yError() );
2799  Fill(h,"pullzr", (vsim->recVtx->z()-vsim->z*simUnit_-dsimrecz)/vsim->recVtx->zError() );
2800 
2801  // efficiency with zmatch within 500 um (or whatever zmatch is)
2802  Fill(h,"eff", 1.);
2803  if(simpv.size()==1){
2804  if (vsim->recVtx==&(*recVtxs->begin())){
2805  Fill(h,"efftag", 1.);
2806  }else{
2807  Fill(h,"efftag", 0.);
2808  cout << "signal vertex not tagged " << message << " " << eventcounter_ << endl;
2809  // call XXClusterizerInZ.vertices(seltrks,3)
2810  }
2811  }
2812 
2813  Fill(h,"effvsptsq",vsim->ptsq,1.);
2814  Fill(h,"effvsnsimtrk",vsim->nGenTrk,1.);
2815  Fill(h,"effvsnrectrk",nrectrks,1.);
2816  Fill(h,"effvsnseltrk",nseltrks,1.);
2817  Fill(h,"effvsz",vsim->z*simUnit_,1.);
2818  Fill(h,"effvsz2",vsim->z*simUnit_,1.);
2819  Fill(h,"effvsr",sqrt(vsim->x*vsim->x+vsim->y*vsim->y)*simUnit_,1.);
2820 
2821  }else{ // no matching rec vertex found for this simvertex
2822 
2823  bool plapper=verbose_ && vsim->nGenTrk;
2824  if(plapper){
2825  // be quiet about invisble vertices
2826  std::cout << "primary not found " << message << " " << eventcounter_ << " x=" <<vsim->x*simUnit_ << " y=" << vsim->y*simUnit_ << " z=" << vsim->z*simUnit_ << " nGenTrk=" << vsim->nGenTrk << std::endl;
2827  }
2828  int mistype=0;
2829  if (vsim->recVtx){
2830  if(plapper){
2831  std::cout << "nearest recvertex at " << vsim->recVtx->z() << " dz=" << vsim->recVtx->z()-vsim->z*simUnit_ << std::endl;
2832  }
2833 
2834  if (fabs(vsim->recVtx->z()-vsim->z*simUnit_)<0.2 ){
2835  Fill(h,"effvsz2",vsim->z*simUnit_,1.);
2836  }
2837 
2838  if (fabs(vsim->recVtx->z()-vsim->z*simUnit_)<0.5 ){
2839  if(verbose_){std::cout << "type 1, lousy z vertex" << std::endl;}
2840  Fill(h,"zlost1", vsim->z*simUnit_,1.);
2841  mistype=1;
2842  }else{
2843  if(plapper){std::cout << "type 2a no vertex anywhere near" << std::endl;}
2844  mistype=2;
2845  }
2846  }else{// no recVtx at all
2847  mistype=2;
2848  if(plapper){std::cout << "type 2b, no vertex at all" << std::endl;}
2849  }
2850 
2851  if(mistype==2){
2852  int selstat=-3;
2853  // no matching vertex found, is there a cluster?
2854  for(unsigned int iclu=0; iclu<clusters.size(); iclu++){
2855  if( fabs(clusters[iclu].position().z()-vsim->z*simUnit_) < 0.1 ){
2856  selstat=int(clusters[iclu].position().x()+0.1);
2857  if(verbose_){std::cout << "matching cluster found with selstat=" << clusters[iclu].position().x() << std::endl;}
2858  }
2859  }
2860  if (selstat==0){
2861  if(plapper){std::cout << "vertex rejected (distance to beam)" << std::endl;}
2862  Fill(h,"zlost3", vsim->z*simUnit_,1.);
2863  }else if(selstat==-1){
2864  if(plapper) {std::cout << "vertex invalid" << std::endl;}
2865  Fill(h,"zlost4", vsim->z*simUnit_,1.);
2866  }else if(selstat==1){
2867  if(plapper){std::cout << "vertex accepted, this cannot be right!!!!!!!!!!" << std::endl;}
2868  }else if(selstat==-2){
2869  if(plapper){std::cout << "dont know what this means !!!!!!!!!!" << std::endl;}
2870  }else if(selstat==-3){
2871  if(plapper){std::cout << "no matching cluster found " << std::endl;}
2872  Fill(h,"zlost2", vsim->z*simUnit_,1.);
2873  }else{
2874  if(plapper){std::cout << "dont know what this means either !!!!!!!!!!" << selstat << std::endl;}
2875  }
2876  }//mistype==2
2877 
2878 
2879  Fill(h,"eff", 0.);
2880  if(simpv.size()==1){ Fill(h,"efftag", 0.); }
2881 
2882  Fill(h,"effvsptsq",vsim->ptsq,0.);
2883  Fill(h,"effvsnsimtrk",float(vsim->nGenTrk),0.);
2884  Fill(h,"effvsnrectrk",nrectrks,0.);
2885  Fill(h,"effvsnseltrk",nseltrks,0.);
2886  Fill(h,"effvsz",vsim->z*simUnit_,0.);
2887  Fill(h,"effvsr",sqrt(vsim->x*vsim->x+vsim->y*vsim->y)*simUnit_,0.);
2888 
2889  //part of the efficiency vs separation
2890 
2891  } // no recvertex for this simvertex
2892 
2893  }// end of sim/rec matching
2894 
2895  // purity of event vertex tags
2896  if (recVtxs->size()>0){
2897  Double_t dz=(*recVtxs->begin()).z() - (*simpv.begin()).z*simUnit_;
2898  Fill(h,"zdistancetag",dz);
2899  Fill(h,"abszdistancetag",fabs(dz));
2900  if( fabs(dz)<zmatch_){
2901  Fill(h,"puritytag",1.);
2902  }else{
2903  // bad tag: the true primary was more than 500 um (or zmatch) away from the tagged primary
2904  Fill(h,"puritytag",0.);
2905  }
2906  }
2907 
2908  }else{
2909  //if(verbose_) cout << "PrimaryVertexAnalyzer4PU::analyzeVertexCollection: simPV is empty!" << endl;
2910  }
2911 
2912 
2913  //******* the following code does not require MC and will/should work for data **********
2914 
2915  Fill(h,"bunchCrossing",bunchCrossing_);
2916  if(recTrks->size()>0) Fill(h,"bunchCrossingLogNtk",bunchCrossing_,log(recTrks->size())/log(10.));
2917 
2918  // ----------------- reconstructed tracks ------------------------
2919  // the list of selected tracks can only be correct if the selection parameterset and track collection
2920  // is the same that was used for the reconstruction
2921 
2922  int nt=0;
2923  for(reco::TrackCollection::const_iterator t=recTrks->begin();
2924  t!=recTrks->end(); ++t){
2925  if((recVtxs->size()>0) && (recVtxs->begin()->isValid())){
2926  fillTrackHistos(h,"all",*t,&(*recVtxs->begin()));
2927  }else{
2928  fillTrackHistos(h,"all",*t);
2929  }
2930  if(recTrks->size()>100) fillTrackHistos(h,"M",*t);
2931 
2932  TransientTrack tt = theB_->build(&(*t)); tt.setBeamSpot(vertexBeamSpot_);
2933  if (theTrackFilter(tt)){
2934  selTrks.push_back(*t);
2935  fillTrackHistos(h,"sel",*t);
2936  int foundinvtx=0;
2937  int nvtemp=-1;
2938  for(reco::VertexCollection::const_iterator v=recVtxs->begin();
2939  v!=recVtxs->end(); ++v){
2940  nvtemp++;
2941  if(( v->isFake()) || (v->ndof()<-2) ) break;
2942  for(trackit_t tv=v->tracks_begin(); tv!=v->tracks_end(); tv++ ){
2943  if( ((**tv).vz()==t->vz()&&((**tv).phi()==t->phi())) ) {
2944  foundinvtx++;
2945  }
2946  }
2947  }
2948  if(foundinvtx==0){
2949  fillTrackHistos(h,"sellost",*t);
2950  }else if(foundinvtx>1){
2951  cout << "hmmmm " << foundinvtx << endl;
2952  }
2953  }
2954  nt++;
2955  }
2956 
2957 
2958  if (nseltrks<0){
2959  nseltrks=selTrks.size();
2960  }else if( ! (nseltrks==(int)selTrks.size()) ){
2961  std::cout << "Warning: inconsistent track selection !" << std::endl;
2962  }
2963 
2964  // fill track histograms of vertex tracks
2965  int nrec=0, nrec0=0, nrec8=0, nrec2=0, nrec4=0;
2966  for(reco::VertexCollection::const_iterator v=recVtxs->begin();
2967  v!=recVtxs->end(); ++v){
2968 
2969  if (! (v->isFake()) && v->ndof()>0 && v->chi2()>0 ){
2970  nrec++;
2971  if (v->ndof()>0) nrec0++;
2972  if (v->ndof()>8) nrec8++;
2973  if (v->ndof()>2) nrec2++;
2974  if (v->ndof()>4) nrec4++;
2975  for(trackit_t t=v->tracks_begin(); t!=v->tracks_end(); t++){
2976  if(v==recVtxs->begin()){
2977  fillTrackHistos(h,"tagged",**t, &(*v));
2978  }else{
2979  fillTrackHistos(h,"untagged",**t, &(*v));
2980  }
2981 
2982  Float_t wt=v->trackWeight(*t);
2983  //dumpHitInfo(**t); cout << " w=" << wt << endl;
2984  Fill(h,"trackWt",wt);
2985  if(wt>0.5){
2986  fillTrackHistos(h,"wgt05",**t, &(*v));
2987  if(v->ndof()>4) fillTrackHistos(h,"ndof4",**t, &(*v));
2988  }else{
2989  fillTrackHistos(h,"wlt05",**t, &(*v));
2990  }
2991  }
2992  }
2993  }
2994 
2995 
2996  // bachelor tracks (only available through clusters right now)
2997  for(unsigned int iclu=0; iclu<clusters.size(); iclu++){
2998  if (clusters[iclu].tracksSize()==1){
2999  for(trackit_t t = clusters[iclu].tracks_begin();
3000  t!=clusters[iclu].tracks_end(); t++){
3001  fillTrackHistos(h,"bachelor",**t);
3002  }
3003  }
3004  }
3005 
3006 
3007  // ----------------- reconstructed vertices ------------------------
3008 
3009  // event
3010  Fill(h,"szRecVtx",recVtxs->size());
3011  Fill(h,"nclu",clusters.size());
3012  Fill(h,"nseltrk",nseltrks);
3013  Fill(h,"nrectrk",nrectrks);
3014  Fill(h,"nrecvtx",nrec);
3015  Fill(h,"nrecvtx2",nrec2);
3016  Fill(h,"nrecvtx4",nrec4);
3017  Fill(h,"nrecvtx8",nrec8);
3018 
3019  if(nrec>0){
3020  Fill(h,"eff0vsntrec",nrectrks,1.);
3021  Fill(h,"eff0vsntsel",nseltrks,1.);
3022  }else{
3023  Fill(h,"eff0vsntrec",nrectrks,0.);
3024  Fill(h,"eff0vsntsel",nseltrks,0.);
3025  if((nseltrks>1)&&(verbose_)){
3026  cout << Form("PrimaryVertexAnalyzer4PU: %s may have lost a vertex %10d %14llu %4d / %4d ",message.c_str(),run_, event_, nrectrks,nseltrks) << endl;
3027  dumpThisEvent_=true;
3028  }
3029  }
3030  if(nrec0>0) { Fill(h,"eff0ndof0vsntsel",nseltrks,1.);}else{ Fill(h,"eff0ndof0vsntsel",nseltrks,0.);}
3031  if(nrec2>0) { Fill(h,"eff0ndof2vsntsel",nseltrks,1.);}else{ Fill(h,"eff0ndof2vsntsel",nseltrks,0.);}
3032  if(nrec4>0) { Fill(h,"eff0ndof4vsntsel",nseltrks,1.);}else{ Fill(h,"eff0ndof4vsntsel",nseltrks,0.);}
3033  if(nrec8>0) { Fill(h,"eff0ndof8vsntsel",nseltrks,1.);}else{ Fill(h,"eff0ndof8vsntsel",nseltrks,0.);}
3034 
3035  if((nrec>1)&&(DEBUG_)) {
3036  cout << "multivertex event" << endl;
3037  dumpThisEvent_=true;
3038  }
3039 
3040  if((nrectrks>10)&&(nseltrks<3)){
3041  cout << "small fraction of selected tracks " << endl;
3042  dumpThisEvent_=true;
3043  }
3044 
3045  // properties of events without a vertex
3046  if((nrec==0)||(recVtxs->begin()->isFake())){
3047  Fill(h,"nrectrk0vtx",nrectrks);
3048  Fill(h,"nseltrk0vtx",nseltrks);
3049  Fill(h,"nclu0vtx",clusters.size());
3050  }
3051 
3052 
3053  // properties of (valid) vertices
3054  double ndof2=-10,ndof1=-10, zndof1=0, zndof2=0;
3055  for(reco::VertexCollection::const_iterator v=recVtxs->begin();
3056  v!=recVtxs->end(); ++v){
3057  if(v->isFake()){ Fill(h,"isFake",1.);}else{ Fill(h,"isFake",0.);}
3058  if(v->isFake()||((v->ndof()<0)&&(v->ndof()>-3))){ Fill(h,"isFake1",1.);}else{ Fill(h,"isFake1",0.);}
3059 
3060  if((v->isFake())||(v->ndof()<0)) continue;
3061  if(v->ndof()>ndof1){ ndof2=ndof1; zndof2=zndof1; ndof1=v->ndof(); zndof1=v->position().z();}
3062  else if(v->ndof()>ndof2){ ndof2=v->ndof(); zndof2=v->position().z();}
3063 
3064 
3065  // some special histogram for two track vertices
3066  if(v->tracksSize()==2){
3067  const TrackBaseRef& t1= *(v->tracks_begin());
3068  const TrackBaseRef& t2=*(v->tracks_begin()+1);
3069  bool os=(t1->charge()*t2->charge()<0);
3070  double dphi=t1->phi()-t2->phi(); if (dphi<0) dphi+=2*M_PI;
3071  double m12=sqrt(pow( sqrt(pow(0.139,2)+pow( t1->p(),2)) +sqrt(pow(0.139,2)+pow( t2->p(),2)) ,2)
3072  -pow(t1->px()+t2->px(),2)
3073  -pow(t1->py()+t2->py(),2)
3074  -pow(t1->pz()+t2->pz(),2)
3075  );
3076  if(os){
3077  Fill(h,"2trkdetaOS",t1->eta()-t2->eta());
3078  Fill(h,"2trkmassOS",m12);
3079  }else{
3080  Fill(h,"2trkdetaSS",t1->eta()-t2->eta());
3081  Fill(h,"2trkmassSS",m12);
3082  }
3083  Fill(h,"2trkdphi",dphi);
3084  Fill(h,"2trkseta",t1->eta()+t2->eta());
3085  if(fabs(dphi-M_PI)<0.1) Fill(h,"2trksetacurl",t1->eta()+t2->eta());
3086  if(fabs(t1->eta()+t2->eta())<0.1) Fill(h,"2trkdphicurl",dphi);
3087  // fill separately for extra vertices
3088  if(v!=recVtxs->begin()){
3089  if(os){
3090  Fill(h,"2trkdetaOSPU",t1->eta()-t2->eta());
3091  Fill(h,"2trkmassOSPU",m12);
3092  }else{
3093  Fill(h,"2trkdetaSSPU",t1->eta()-t2->eta());
3094  Fill(h,"2trkmassSSPU",m12);
3095  }
3096  Fill(h,"2trkdphiPU",dphi);
3097  Fill(h,"2trksetaPU",t1->eta()+t2->eta());
3098  if(fabs(dphi-M_PI)<0.1) Fill(h,"2trksetacurlPU",t1->eta()+t2->eta());
3099  if(fabs(t1->eta()+t2->eta())<0.1) Fill(h,"2trkdphicurlPU",dphi);
3100  }
3101  }
3102 
3103 
3104  Fill(h,"trkchi2vsndof",v->ndof(),v->chi2());
3105  if(v->ndof()>0){ Fill(h,"trkchi2overndof",v->chi2()/v->ndof()); }
3106  if(v->tracksSize()==2){ Fill(h,"2trkchi2vsndof",v->ndof(),v->chi2()); }
3107  if(v->tracksSize()==3){ Fill(h,"3trkchi2vsndof",v->ndof(),v->chi2()); }
3108  if(v->tracksSize()==4){ Fill(h,"4trkchi2vsndof",v->ndof(),v->chi2()); }
3109  if(v->tracksSize()==5){ Fill(h,"5trkchi2vsndof",v->ndof(),v->chi2()); }
3110 
3111  Fill(h,"nbtksinvtx",v->tracksSize());
3112  Fill(h,"nbtksinvtx2",v->tracksSize());
3113  Fill(h,"vtxchi2",v->chi2());
3114  Fill(h,"vtxndf",v->ndof());
3115  Fill(h,"vtxprob",ChiSquaredProbability(v->chi2() ,v->ndof()));
3116  Fill(h,"vtxndfvsntk",v->tracksSize(), v->ndof());
3117  Fill(h,"vtxndfoverntk",v->ndof()/v->tracksSize());
3118  Fill(h,"vtxndf2overntk",(v->ndof()+2)/v->tracksSize());
3119  Fill(h,"zrecvsnt",v->position().z(),float(nrectrks));
3120  if(nrectrks>100){
3121  Fill(h,"zrecNt100",v->position().z());
3122  }
3123 
3124  if(v->ndof()>2.0){ // enter only vertices that really contain tracks
3125  Fill(h,"xrec",v->position().x());
3126  Fill(h,"yrec",v->position().y());
3127  Fill(h,"zrec",v->position().z());
3128  Fill(h,"xrec1",v->position().x());
3129  Fill(h,"yrec1",v->position().y());
3130  Fill(h,"zrec1",v->position().z());
3131  Fill(h,"xrec2",v->position().x());
3132  Fill(h,"yrec2",v->position().y());
3133  Fill(h,"zrec2",v->position().z());
3134  Fill(h,"xrec3",v->position().x());
3135  Fill(h,"yrec3",v->position().y());
3136  Fill(h,"zrec3",v->position().z());
3137  Fill(h,"xrecb",v->position().x()-vertexBeamSpot_.x0());
3138  Fill(h,"yrecb",v->position().y()-vertexBeamSpot_.y0());
3139  Fill(h,"zrecb",v->position().z()-vertexBeamSpot_.z0());
3140  Fill(h,"xrecBeam",v->position().x()-vertexBeamSpot_.x0());
3141  Fill(h,"yrecBeam",v->position().y()-vertexBeamSpot_.y0());
3142  Fill(h,"zrecBeam",v->position().z()-vertexBeamSpot_.z0());
3143  Fill(h,"xrecBeamPull",(v->position().x()-vertexBeamSpot_.x0())/sqrt(pow(v->xError(),2)+pow(vertexBeamSpot_.BeamWidthX(),2)));
3144  Fill(h,"yrecBeamPull",(v->position().y()-vertexBeamSpot_.y0())/sqrt(pow(v->yError(),2)+pow(vertexBeamSpot_.BeamWidthY(),2)));
3145 
3146  Fill(h,"xrecBeamvsdx",v->xError(),v->position().x()-vertexBeamSpot_.x0());
3147  Fill(h,"yrecBeamvsdy",v->yError(),v->position().y()-vertexBeamSpot_.y0());
3148  Fill(h,"xrecBeamvsdxR2",v->position().x()-vertexBeamSpot_.x0(),v->xError());
3149  Fill(h,"yrecBeamvsdyR2",v->position().y()-vertexBeamSpot_.y0(),v->yError());
3150  Fill(h,"xrecBeam2vsdx2prof",pow(v->xError(),2),pow(v->position().x()-vertexBeamSpot_.x0(),2));
3151  Fill(h,"yrecBeam2vsdy2prof",pow(v->yError(),2),pow(v->position().y()-vertexBeamSpot_.y0(),2));
3152  Fill(h,"xrecBeamvsdx2",pow(v->xError(),2),pow(v->position().x()-vertexBeamSpot_.x0(),2));
3153  Fill(h,"yrecBeamvsdy2",pow(v->yError(),2),pow(v->position().y()-vertexBeamSpot_.y0(),2));
3154  Fill(h,"xrecBeamvsz",v->position().z(),v->position().x()-vertexBeamSpot_.x0());
3155  Fill(h,"yrecBeamvsz",v->position().z(),v->position().y()-vertexBeamSpot_.y0());
3156  Fill(h,"xrecBeamvszprof",v->position().z(),v->position().x()-vertexBeamSpot_.x0());
3157  Fill(h,"yrecBeamvszprof",v->position().z(),v->position().y()-vertexBeamSpot_.y0());
3158  Fill(h,"xrecBeamvsdxprof",v->xError(),v->position().x()-vertexBeamSpot_.x0());
3159  Fill(h,"yrecBeamvsdyprof",v->yError(),v->position().y()-vertexBeamSpot_.y0());
3160 
3161 
3162  Fill(h,"errx",v->xError());
3163  Fill(h,"erry",v->yError());
3164  Fill(h,"errz",v->zError());
3165  double vxx=v->covariance(0,0);
3166  double vyy=v->covariance(1,1);
3167  double vxy=v->covariance(1,0);
3168  double dv=0.25*(vxx+vyy)*(vxx+vyy-(vxx*vyy-vxy*vxy));
3169  if(dv>0){
3170  double l1=0.5*(vxx+vyy)+sqrt(dv);
3171  Fill(h,"err1",sqrt(l1));
3172  double l2=sqrt(0.5*(vxx+vyy)-sqrt(dv));
3173  if(l2>0) Fill(h,"err2",sqrt(l2));
3174  }
3175 
3176 
3177  // look at the tagged vertex separately
3178  if (v==recVtxs->begin()){
3179  Fill(h,"nbtksinvtxTag",v->tracksSize());
3180  Fill(h,"nbtksinvtxTag2",v->tracksSize());
3181  Fill(h,"xrectag",v->position().x());
3182  Fill(h,"yrectag",v->position().y());
3183  Fill(h,"zrectag",v->position().z());
3184  }else{
3185  Fill(h,"nbtksinvtxPU",v->tracksSize());
3186  Fill(h,"nbtksinvtxPU2",v->tracksSize());
3187  }
3188 
3189  // vertex resolution vs number of tracks
3190  Fill(h,"xresvsntrk",v->tracksSize(),v->xError());
3191  Fill(h,"yresvsntrk",v->tracksSize(),v->yError());
3192  Fill(h,"zresvsntrk",v->tracksSize(),v->zError());
3193 
3194  }
3195 
3196  // cluster properties (if available)
3197  for(unsigned int iclu=0; iclu<clusters.size(); iclu++){
3198  if( fabs(clusters[iclu].position().z()-v->position().z()) < 0.0001 ){
3199  Fill(h,"nclutrkvtx",clusters[iclu].tracksSize());
3200  }
3201  }
3202 
3203  // properties of (valid) neighbour vertices
3204  reco::VertexCollection::const_iterator v1=v; v1++;
3205  for(; v1!=recVtxs->end(); ++v1){
3206  if((v1->isFake())||(v1->ndof()<0)) continue;
3207  Fill(h,"zdiffrec",v->position().z()-v1->position().z());
3208 
3209  double z0=v->position().z()-vertexBeamSpot_.z0();
3210  double z1=v1->position().z()-vertexBeamSpot_.z0();
3211  Fill(h,"zPUcand",z0); Fill(h,"zPUcand",z1);
3212  Fill(h,"ndofPUcand",v->ndof()); Fill(h,"ndofPUcand",v1->ndof());
3213 
3214  Fill(h,"zdiffvsz",z1-z0,0.5*(z1+z0));
3215 
3216  if ((v->ndof()>2) && (v1->ndof()>2)){
3217  Fill(h,"zdiffrec2",v->position().z()-v1->position().z());
3218  Fill(h,"zPUcand2",z0);
3219  Fill(h,"zPUcand2",z1);
3220  Fill(h,"ndofPUcand2",v->ndof());
3221  Fill(h,"ndofPUcand2",v1->ndof());
3222  Fill(h,"zvszrec2",z0, z1);
3223  Fill(h,"pzvspz2",TMath::Freq(z0/2.16),TMath::Freq(z1/2.16) );
3224  }
3225 
3226  if ((v->ndof()>4) && (v1->ndof()>4)){
3227  Fill(h,"zdiffvsz4",z1-z0,0.5*(z1+z0));
3228  Fill(h,"zdiffrec4",v->position().z()-v1->position().z());
3229  Fill(h,"zvszrec4",z0, z1);
3230  Fill(h,"pzvspz4",TMath::Freq(z0/2.16),TMath::Freq(z1/2.16) );
3231  if(fabs(z0-z1)>1.0){
3232  Fill(h,"xbeamPUcand",v->position().x()-vertexBeamSpot_.x0());
3233  Fill(h,"ybeamPUcand",v->position().y()-vertexBeamSpot_.y0());
3234  Fill(h,"xbeamPullPUcand",(v->position().x()-vertexBeamSpot_.x0())/v->xError());
3235  Fill(h,"ybeamPullPUcand",(v->position().y()-vertexBeamSpot_.y0())/v->yError());
3236  Fill(h,"ndofOverNtkPUcand",v->ndof()/v->tracksSize());
3237  Fill(h,"ndofOverNtkPUcand",v1->ndof()/v1->tracksSize());
3238  Fill(h,"xbeamPUcand",v1->position().x()-vertexBeamSpot_.x0());
3239  Fill(h,"ybeamPUcand",v1->position().y()-vertexBeamSpot_.y0());
3240  Fill(h,"xbeamPullPUcand",(v1->position().x()-vertexBeamSpot_.x0())/v1->xError());
3241  Fill(h,"ybeamPullPUcand",(v1->position().y()-vertexBeamSpot_.y0())/v1->yError());
3242  Fill(h,"zPUcand4",z0);
3243  Fill(h,"zPUcand4",z1);
3244  Fill(h,"ndofPUcand4",v->ndof());
3245  Fill(h,"ndofPUcand4",v1->ndof());
3246  for(trackit_t t=v->tracks_begin(); t!=v->tracks_end(); t++){ if(v->trackWeight(*t)>0.5) fillTrackHistos(h,"PUcand",**t, &(*v)); }
3247  for(trackit_t t=v1->tracks_begin(); t!=v1->tracks_end(); t++){ if(v1->trackWeight(*t)>0.5) fillTrackHistos(h,"PUcand",**t, &(*v1)); }
3248  }
3249  }
3250 
3251  if ((v->ndof()>4) && (v1->ndof()>2) && (v1->ndof()<4)){
3252  for(trackit_t t=v1->tracks_begin(); t!=v1->tracks_end(); t++){ if(v1->trackWeight(*t)>0.5) fillTrackHistos(h,"PUfake",**t, &(*v1)); }
3253  }
3254 
3255  if ((v->ndof()>8) && (v1->ndof()>8)){
3256  Fill(h,"zdiffrec8",v->position().z()-v1->position().z());
3257  if(dumpPUcandidates_ && fabs(z0-z1)>1.0){
3258  cout << "PU candidate " << run_ << " " << event_ << " " << message << " zdiff=" <<z0-z1 << endl;
3259  dumpThisEvent_=true;
3260  }
3261  }
3262 
3263  }
3264 
3265  // test track links, use reconstructed vertices
3266  bool problem = false;
3267  Fill(h,"nans",1.,std::isnan(v->position().x())*1.);
3268  Fill(h,"nans",2.,std::isnan(v->position().y())*1.);
3269  Fill(h,"nans",3.,std::isnan(v->position().z())*1.);
3270 
3271  int index = 3;
3272  for (int i = 0; i != 3; i++) {
3273  for (int j = i; j != 3; j++) {
3274  index++;
3275  Fill(h,"nans",index*1., std::isnan(v->covariance(i, j))*1.);
3276  if (std::isnan(v->covariance(i, j))) problem = true;
3277  // in addition, diagonal element must be positive
3278  if (j == i && v->covariance(i, j) < 0) {
3279  Fill(h,"nans",index*1., 1.);
3280  problem = true;
3281  }
3282  }
3283  }
3284 
3285  try {
3286  for(trackit_t t = v->tracks_begin();
3287  t!=v->tracks_end(); t++) {
3288  // illegal charge
3289  if ( (**t).charge() < -1 || (**t).charge() > 1 ) {
3290  Fill(h,"tklinks",0.);
3291  }
3292  else {
3293  Fill(h,"tklinks",1.);
3294  }
3295  }
3296  } catch (...) {
3297  // exception thrown when trying to use linked track
3298  Fill(h,"tklinks",0.);
3299  }
3300 
3301  if (problem) {
3302  // analyze track parameter covariance definiteness
3303  double data[25];
3304  try {
3305  int itk = 0;
3306  for(trackit_t t = v->tracks_begin();
3307  t!=v->tracks_end(); t++) {
3308  std::cout << "Track " << itk++ << std::endl;
3309  int i2 = 0;
3310  for (int i = 0; i != 5; i++) {
3311  for (int j = 0; j != 5; j++) {
3312  data[i2] = (**t).covariance(i, j);
3313  std::cout << std:: scientific << data[i2] << " ";
3314  i2++;
3315  }
3316  std::cout << std::endl;
3317  }
3318  gsl_matrix_view m
3319  = gsl_matrix_view_array (data, 5, 5);
3320 
3321  gsl_vector *eval = gsl_vector_alloc (5);
3322  gsl_matrix *evec = gsl_matrix_alloc (5, 5);
3323 
3324  gsl_eigen_symmv_workspace * w =
3325  gsl_eigen_symmv_alloc (5);
3326 
3327  gsl_eigen_symmv (&m.matrix, eval, evec, w);
3328 
3329  gsl_eigen_symmv_free (w);
3330 
3331  gsl_eigen_symmv_sort (eval, evec,
3332  GSL_EIGEN_SORT_ABS_ASC);
3333 
3334  // print sorted eigenvalues
3335  {
3336  int i;
3337  for (i = 0; i < 5; i++) {
3338  double eval_i
3339  = gsl_vector_get (eval, i);
3340  //gsl_vector_view evec_i
3341  // = gsl_matrix_column (evec, i);
3342 
3343  printf ("eigenvalue = %g\n", eval_i);
3344  // printf ("eigenvector = \n");
3345  // gsl_vector_fprintf (stdout,
3346  // &evec_i.vector, "%g");
3347  }
3348  }
3349  }
3350  }
3351  catch (...) {
3352  // exception thrown when trying to use linked track
3353  break;
3354  }// catch()
3355  }// if (problem)
3356 
3357  } // vertex loop (v)
3358 
3359  // 2nd highest ndof
3360  if (ndof2>0){
3361  Fill(h,"ndofnr2",ndof2);
3362  if(fabs(zndof1-zndof2)>1) Fill(h,"ndofnr2d1cm",ndof2);
3363  if(fabs(zndof1-zndof2)>2) Fill(h,"ndofnr2d2cm",ndof2);
3364  }
3365 
3366  //part of the separation efficiency profiles
3367 
3368  if ( pui_z.size()>0 ) {
3369 
3370  vector<int> used_indizesV;
3371 
3372  for (unsigned spv_idx=0; spv_idx<pui_z.size(); spv_idx++) {
3373 
3374  float sv = pui_z[spv_idx];
3375 
3376  if ( fabs(sv)>24. ) continue;
3377 
3378  double eff = 0.;
3379  double effwod = 0.;
3380  double dreco = 0.;
3381  double dsimed = 0.;
3382 
3383  vector<int>* matchedV = vertex_match(sv, recVtxs);
3384  unsigned numMatchs = matchedV->size();
3385 
3386  bool dsflag = false;
3387 
3388  for (unsigned i=0;i<used_indizesV.size(); i++) {
3389  for (unsigned j=0;j<numMatchs; j++) {
3390  if ( used_indizesV.at(i)==matchedV->at(j) ) {
3391  dsflag = true;
3392  break;
3393  }
3394  }
3395  }
3396 
3397  if ( numMatchs>0 ) eff = 1.;
3398  if ( numMatchs>1 ) dreco = 1.;
3399  if ( dsflag ) dsimed = 1.;
3400  if ( ( numMatchs>0 ) && ( !dsflag ) ) effwod = 1.;
3401 
3402  for (unsigned i=0;i<numMatchs; i++) {
3403  used_indizesV.push_back(matchedV->at(i));
3404  }
3405 
3406  float sep = getTrueSeparation(sv, pui_z);
3407 
3408  Fill(h,"effvszsep", sep, eff);
3409  Fill(h,"effwodvszsep", sep, effwod);
3410  Fill(h,"mergedvszsep", sep, dsimed);
3411  Fill(h,"splitvszsep", sep, dreco);
3412 
3413  }
3414 
3415  } else {
3416  std::cout << "Strange PileUpSummaryInfo in the event" << std::endl;
3417  }
3418 }
RunNumber_t run() const
Definition: EventID.h:39
virtual char const * what() const
Definition: Exception.cc:141
edm::EDGetTokenT< reco::TrackCollection > recoTrackCollectionToken_
double p() const
momentum vector magnitude
Definition: TrackBase.h:663
type
Definition: HCALResponse.h:21
TrackFilterForPVFinding theTrackFilter
value_type const * get() const
Definition: RefToBase.h:212
EventNumber_t event() const
Definition: EventID.h:41
unsigned int size_type
Definition: View.h:85
double z0() const
z coordinate
Definition: BeamSpot.h:68
int i
Definition: DBlmapReader.cc:9
edm::EDGetTokenT< reco::BeamSpot > recoBeamSpotToken_
double d0Error() const
error on d0
Definition: TrackBase.h:850
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)
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:250
int event() const
get the contents of the subdetector field (should be protected?)
TPRegexp parents
Definition: eve_filter.cc:24
unsigned short lost() const
Number of lost (=invalid) hits on track.
Definition: Track.h:199
std::vector< PrimaryVertexAnalyzer4PU::SimEvent > getSimEvents(edm::Handle< TrackingParticleCollection >, edm::Handle< TrackingVertexCollection >, edm::Handle< edm::View< reco::Track > >)
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > > XYZTLorentzVectorD
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:14
void fillTrackHistos(std::map< std::string, TH1 * > &h, const std::string &ttype, const reco::Track &t, const reco::Vertex *v=NULL)
const double w
Definition: UKUtility.cc:23
std::vector< TrackingParticle > TrackingParticleCollection
trackRef_iterator tracks_end() const
last iterator over tracks
Definition: Vertex.cc:44
const_iterator end() const
last iterator over the map (read only)
void setBeamSpot(const reco::BeamSpot &beamSpot)
double normalizedChi2() const
chi-squared divided by n.d.o.f. (or chi-squared * 1e6 if n.d.o.f. is zero)
Definition: TrackBase.h:609
reco::TrackBase::ParameterVector ParameterVector
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:449
std::map< std::string, TH1 * > hsimPV
std::vector< SimVertex >::const_iterator g4v_iterator
edm::Handle< reco::BeamSpot > recoBeamSpotHandle_
std::vector< reco::TransientTrack > tk
double theta() const
polar angle
Definition: TrackBase.h:627
double dxyError() const
error on dxy
Definition: TrackBase.h:844
Divides< arg, void > D0
Definition: Factorize.h:143
std::vector< int > supf(std::vector< SimPart > &simtrks, const reco::TrackCollection &trks)
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
const_iterator find(const key_type &k) const
find element with specified reference key
edm::EDGetTokenT< reco::VertexCollection > recoVertexCollectionToken_
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:13
Geom::Theta< T > theta() const
T y() const
Definition: PV3DBase.h:63
int bunchCrossing() const
Definition: EventBase.h:66
double error() const
Definition: Measurement1D.h:30
const reco::GenParticle * mother(const reco::GenParticle &p, unsigned int imoth=0)
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:63
static bool match(const ParameterVector &a, const ParameterVector &b)
size_type size() const
edm::ESHandle< TransientTrackBuilder > theB_
edm::EDGetTokenT< TrackingParticleCollection > trackingParticleCollectionToken_
double phi() const
azimuthal angle of momentum vector
Definition: TrackBase.h:693
#define NULL
Definition: scimark2.h:8
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
bool ev
math::Vector< dimension >::type ParameterVector
parameter vector
Definition: TrackBase.h:73
double px() const
x coordinate of momentum vector
Definition: TrackBase.h:675
int pixelLayersWithMeasurement() const
Definition: HitPattern.cc:458
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
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")
int trackerLayersWithMeasurement() const
Definition: HitPattern.cc:477
const Point & position() const
position
Definition: Vertex.h:106
edm::EDGetTokenT< reco::TrackToTrackingParticleAssociator > recoTrackToTrackingParticleAssociatorToken_
bool alreadyPrinted() const
Definition: Exception.cc:251
TrajectoryStateClosestToBeamLine stateAtBeamLine() const
float float float z
void getData(T &iHolder) const
Definition: EventSetup.h:78
std::map< std::string, TH1 * > hnoBS
edm::LuminosityBlockNumber_t luminosityBlock_
const math::XYZPoint & innerPosition() const
position of the innermost hit
Definition: Track.h:55
TrackAlgorithm algo() const
Definition: TrackBase.h:423
void Fill(std::map< std::string, TH1 * > &h, std::string s, double x)
std::map< std::string, TH1 * > hDA
double getTrueSeparation(float, const std::vector< float > &)
bool isFinalstateParticle(const HepMC::GenParticle *p)
bool isCharged(const HepMC::GenParticle *p)
int iEvent
Definition: GenABIO.cc:230
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:699
const std::vector< float > & getPU_zpositions() const
bool truthMatchedTrack(edm::RefToBase< reco::Track >, TrackingParticleRef &)
bool isnan(float x)
Definition: math.h:13
const reco::TrackToTrackingParticleAssociator * associatorByHits_
float trackWeight(const TrackBaseRef &r) const
returns the weight with which a Track has contributed to the vertex-fit.
T sqrt(T t)
Definition: SSEVec.h:48
int bunchCrossing() const
get the detector field from this detid
GlobalPoint position() const
std::map< std::string, TH1 * > bookVertexHistograms()
double pt() const
track transverse momentum
Definition: TrackBase.h:669
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)
T z() const
Definition: PV3DBase.h:64
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
tuple IP
Definition: listHistos.py:76
const reco::GenParticle * daughter(const reco::GenParticle &p, unsigned int idau)
int qualityMask() const
Definition: TrackBase.h:904
virtual CachingVertex< 5 > vertex(const std::vector< reco::TransientTrack > &) const
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int j
Definition: DBlmapReader.cc:9
double z() const
y coordinate
Definition: Vertex.h:112
double lambda() const
Lambda angle.
Definition: TrackBase.h:633
std::vector< simPrimaryVertex > getSimPVs(const edm::Handle< edm::HepMCProduct > evtMC)
double f[11][100]
float ChiSquaredProbability(double chiSquared, double nrDOF)
double BeamWidthX() const
beam width X
Definition: BeamSpot.h:86
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)
const int mu
Definition: Constants.h:22
#define end
Definition: vmac.h:37
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:242
int orbitNumber() const
Definition: EventBase.h:67
trackingRecHit_iterator recHitsBegin() const
Iterator to first hit on the track.
Definition: Track.h:104
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)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
bool isValid() const
Definition: HandleBase.h:75
HepPDT::ParticleData ParticleData
#define M_PI
edm::EDGetTokenT< edm::View< reco::Track > > edmView_recoTrack_Token_
double ndof() const
Definition: Vertex.h:102
edm::EDGetTokenT< edm::SimVertexContainer > edmSimVertexContainerToken_
int nt
Definition: AMPTWrapper.h:32
double pz() const
z coordinate of momentum vector
Definition: TrackBase.h:687
std::map< std::string, TH1 * > hBS
std::vector< reco::TransientTrack > tkprim
double dzError() const
error on dz
Definition: TrackBase.h:862
reco::Vertex::trackRef_iterator trackit_t
std::string getReleaseVersion()
double vz() const
z coordinate of the reference point on track
Definition: TrackBase.h:717
Definition: DetId.h:18
GlobalPoint position() const
void matchRecTracksToVertex(simPrimaryVertex &pv, const std::vector< SimPart > &tsim, const edm::Handle< reco::TrackCollection > &recTrks)
double significance() const
Definition: Measurement1D.h:32
bool isResonance(const HepMC::GenParticle *p)
T const * product() const
Definition: Handle.h:81
const Track & track() const
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
Definition: TrackBase.h:384
reco::RecoToSimCollection associateRecoToSim(const edm::Handle< edm::View< reco::Track > > &tCH, const edm::Handle< TrackingParticleCollection > &tPCH) const
compare reco to sim the handle of reco::Track and TrackingParticle collections
tuple tracks
Definition: testEve_cfg.py:39
void printRecTrks(const edm::Handle< reco::TrackCollection > &recTrks)
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
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
part
Definition: HCALResponse.h:20
std::vector< TrackingVertex > TrackingVertexCollection
const T & get() const
Definition: EventSetup.h:55
std::vector< SimVertex > SimVertexContainer
reco::RecoToSimCollection r2s_
int pixelBarrelLayersWithMeasurement() const
Definition: HitPattern.cc:517
double BeamWidthY() const
beam width Y
Definition: BeamSpot.h:88
double b
Definition: hdecay.h:120
double value() const
Definition: Measurement1D.h:28
double S(const TLorentzVector &, const TLorentzVector &)
Definition: Particle.cc:99
EncodedEventId eventId() const
Signal source, crossing number.
PrimaryVertexAnalyzer4PU(const edm::ParameterSet &)
edm::EventID id() const
Definition: EventBase.h:60
const EncodedEventId & eventId() const
Pixel cluster – collection of neighboring pixels above threshold.
void printSimTrks(const edm::Handle< edm::SimTrackContainer > simVtrks)
#define begin
Definition: vmac.h:30
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
void add(std::map< std::string, TH1 * > &h, TH1 *hist)
double a
Definition: hdecay.h:121
< trclass="colgroup">< tdclass="colgroup"colspan=5 > DT local reconstruction</td ></tr >< tr >< td >< ahref="classDTRecHit1DPair.html"> DTRecHit1DPair</a ></td >< td >< ahref="DataFormats_DTRecHit.html"> edm::RangeMap & lt
static int position[264][3]
Definition: ReadPGInfo.cc:509
unsigned short found() const
Number of valid hits on track.
Definition: Track.h:194
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="")
void event_()
edm::EDGetTokenT< reco::VertexCollection > recoVertexCollection_DA_Token_
edm::EDGetTokenT< reco::VertexCollection > recoVertexCollection_BS_Token_
edm::EDGetTokenT< std::vector< PileupSummaryInfo > > vecPileupSummaryInfoToken_
std::vector< TrackBaseRef >::const_iterator trackRef_iterator
The iteratator for the vector&lt;TrackRef&gt;
Definition: Vertex.h:37
double y0() const
y coordinate
Definition: BeamSpot.h:66
Monte Carlo truth information used for tracking validation.
tuple cout
Definition: gather_cfg.py:121
int charge() const
track electric charge
Definition: TrackBase.h:615
const Point & position() const
position
Definition: BeamSpot.h:62
static const G4double kappa
volatile std::atomic< bool > shutdown_flag false
Definition: DDAxes.h:10
trackRef_iterator tracks_begin() const
first iterator over tracks
Definition: Vertex.cc:39
tuple status
Definition: ntuplemaker.py:245
void dumpHitInfo(const reco::Track &t)
double dxy() const
dxy parameter. (This is the transverse impact parameter w.r.t. to (0,0,0) ONLY if refPoint is close t...
Definition: TrackBase.h:639
T x() const
Definition: PV3DBase.h:62
virtual void analyze(const edm::Event &, const edm::EventSetup &)
bool isValid() const
std::vector< SimTrack > SimTrackContainer
std::vector< edm::RefToBase< reco::Track > > getTruthMatchedVertexTracks(const reco::Vertex &)
edm::ESHandle< ParticleDataTable > pdt_
std::map< double, TrackingParticleRef > z2tp_
tuple size
Write out results.
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
size_t tracksSize() const
number of tracks
Definition: Vertex.cc:34
double py() const
y coordinate of momentum vector
Definition: TrackBase.h:681
TrackingRecHitCollection::base::const_iterator trackingRecHit_iterator
iterator over a vector of reference to TrackingRecHit in the same collection
math::Error< dimension >::type CovarianceMatrix
5 parameter covariance matrix
Definition: TrackBase.h:76
int numberOfHits(HitCategory category) const
Definition: HitPattern.h:718
Our base class.
Definition: SiPixelRecHit.h:23
const LorentzVector & position() const
double x0() const
x coordinate
Definition: BeamSpot.h:64
trackingRecHit_iterator recHitsEnd() const
Iterator to last hit on the track.
Definition: Track.h:109