ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/Jeng/PVStudy/plugins/PVStudy.cc
(Generate patch)

Comparing UserCode/Jeng/PVStudy/plugins/PVStudy.cc (file contents):
Revision 1.11 by yygao, Wed Nov 11 19:28:50 2009 UTC vs.
Revision 1.20 by yygao, Thu Feb 18 10:59:48 2010 UTC

# Line 25 | Line 25 | Implementation:
25   #include <vector>
26   #include <iostream>
27   #include <sstream>
28 #include <algorithm>
28  
29   // user include files
30   #include "FWCore/Framework/interface/Frameworkfwd.h"
# Line 50 | Line 49 | Implementation:
49   #include <SimDataFormats/Vertex/interface/SimVertexContainer.h>
50   #include <SimDataFormats/Track/interface/SimTrack.h>
51   #include <SimDataFormats/Track/interface/SimTrackContainer.h>
52 + // BeamSpot
53 + #include "DataFormats/BeamSpot/interface/BeamSpot.h"
54  
55   //root
56   #include <TROOT.h>
# Line 60 | Line 61 | Implementation:
61   #include <TPad.h>
62  
63   using namespace std;
64 + typedef math::XYZTLorentzVectorF LorentzVector;
65 + typedef math::XYZPoint Point;
66  
67   PVStudy::PVStudy(const edm::ParameterSet& iConfig)
68   {
69    //=======================================================================
70    // Get configuration for TrackTupleMaker
71    //=======================================================================
72 <  simG4_           = iConfig.getParameter<edm::InputTag>( "simG4" );
73 <  trackCollectionTag_     = iConfig.getUntrackedParameter<edm::InputTag>("trackCollection");  
74 <  splitTrackCollection1Tag_     = iConfig.getUntrackedParameter<edm::InputTag>("splitTrackCollection1");
75 <  splitTrackCollection2Tag_     = iConfig.getUntrackedParameter<edm::InputTag>("splitTrackCollection2");
72 >  simG4_                     = iConfig.getParameter<edm::InputTag>( "simG4" );
73 >  trackCollectionTag_        = iConfig.getUntrackedParameter<edm::InputTag>("trackCollection");  
74 >  splitTrackCollection1Tag_  = iConfig.getUntrackedParameter<edm::InputTag>("splitTrackCollection1");
75 >  splitTrackCollection2Tag_  = iConfig.getUntrackedParameter<edm::InputTag>("splitTrackCollection2");
76    vertexCollectionTag_       = iConfig.getUntrackedParameter<edm::InputTag>("vertexCollection");
77 <  splitVertexCollection1Tag_       = iConfig.getUntrackedParameter<edm::InputTag>("splitVertexCollection1");
78 <  splitVertexCollection2Tag_       = iConfig.getUntrackedParameter<edm::InputTag>("splitVertexCollection2");  
79 <  pixelVertexCollectionTag_      = iConfig.getParameter<edm::InputTag>("pixelVertexCollectionTag");  
80 <  verbose_         = iConfig.getUntrackedParameter<bool>("verbose",false);
81 <  realData_        = iConfig.getUntrackedParameter<bool>("realData",false);
82 <  analyze_         = iConfig.getUntrackedParameter<bool>("analyzeOnTheFly",false);
83 <  saventuple_         = iConfig.getUntrackedParameter<bool>("saventuple",false);  
84 <  outputfilename_  = iConfig.getUntrackedParameter<string>("OutputFileName");
85 <  ntrkdiffcut_         = iConfig.getUntrackedParameter<double>("ntrkdiffcut");
86 <  zsigncut_         = iConfig.getUntrackedParameter<int>("zsigncut");
87 <  nTrkMin_ =  iConfig.getUntrackedParameter<int>("nTrkMin");
88 <  nTrkMax_ =  iConfig.getUntrackedParameter<int>("nTrkMax");
89 <
77 >  splitVertexCollection1Tag_ = iConfig.getUntrackedParameter<edm::InputTag>("splitVertexCollection1");
78 >  splitVertexCollection2Tag_ = iConfig.getUntrackedParameter<edm::InputTag>("splitVertexCollection2");
79 >  verbose_                   = iConfig.getUntrackedParameter<bool>("verbose",false);
80 >  realData_                  = iConfig.getUntrackedParameter<bool>("realData",false);
81 >  analyze_                   = iConfig.getUntrackedParameter<bool>("analyzeOnTheFly",false);
82 >  saventuple_                = iConfig.getUntrackedParameter<bool>("saventuple",false);  
83 >  outputfilename_            = iConfig.getUntrackedParameter<string>("OutputFileName");  
84 >  histoFileName_             = iConfig.getUntrackedParameter<std::string> ("histoFileName");
85 >  ntrkdiffcut_               = iConfig.getUntrackedParameter<double>("ntrkdiffcut");
86 >  nTrkMin_                   = iConfig.getUntrackedParameter<int>("nTrkMin");
87 >  nTrkMax_                   = iConfig.getUntrackedParameter<int>("nTrkMax");
88 >  zsigncut_                  = iConfig.getUntrackedParameter<int>("zsigncut");
89 >  bsSrc = iConfig.getParameter< edm::InputTag >("beamSpot");
90 >  
91    //now do what ever initialization is needed
92    pvinfo.clear();
93  
90  
94    // Specify the data mode vector
95    if(realData_) datamode.push_back(0);
96    else {
# Line 96 | Line 99 | PVStudy::PVStudy(const edm::ParameterSet
99      datamode.push_back(2);
100      datamode.push_back(3);
101    }
102 <
100 <  // Create ntuple files if needed
102 > // Create ntuple files if needed
103    if(saventuple_) {
104      file_ = TFile::Open(outputfilename_.c_str(),"RECREATE");
105      ftree_ = new TTree("mytree","mytree");
# Line 108 | Line 110 | PVStudy::PVStudy(const edm::ParameterSet
110  
111      // pvtxtree_ analyzing the pvtxs ootb
112      pvtxtree_ = new TTree("pvtxtree","pvtxtree");
111    //pvtx using all tracks
112    pvtxtree_->Branch("nrecPV",&nrecPV_,"nrecPV/I");
113    pvtxtree_->Branch("nTrkPV",&nTrkPV_,"nTrkPV[nrecPV]/I");
114    pvtxtree_->Branch("sumptsq",&sumptsq_,"sumptsq[nrecPV]/D");    
115    pvtxtree_->Branch("isValid",&isValid_,"isValid/I");
116    pvtxtree_->Branch("isFake",&isFake_,"isFake/I");
117    pvtxtree_->Branch("recx",&recx_,"recx[nrecPV]/D");
118    pvtxtree_->Branch("recy",&recy_,"recy[nrecPV]/D");
119    pvtxtree_->Branch("recz",&recz_,"recz[nrecPV]/D");
120    pvtxtree_->Branch("recx_err",&recx_err_,"recx_err[nrecPV]/D");
121    pvtxtree_->Branch("recy_err",&recy_err_,"recy_err[nrecPV]/D");
122    pvtxtree_->Branch("recz_err",&recz_err_,"recz_err[nrecPV]/D");
113  
114 +    // Event information for the data
115 +    pvtxtree_->Branch("glob_runno",&glob_runno_,"glob_runno/I");
116 +    pvtxtree_->Branch("glob_evtno",&glob_evtno_,"glob_evtno/I");
117 +    pvtxtree_->Branch("glob_ls",&glob_ls_,"glob_ls/I");
118 +    pvtxtree_->Branch("glob_bx",&glob_bx_,"glob_bx/I");  
119 +    
120 +
121 +    pvtxtree_->Branch("nrecPV",&nrecPV_,"nrecPV/I");
122 +    pvtxtree_->Branch("nrecPV1_spl",&nrecPV1_spl_,"nrecPV1_spl/I");
123 +    pvtxtree_->Branch("nrecPV2_spl",&nrecPV2_spl_,"nrecPV2_spl/I");
124 +    // Event level information
125      pvtxtree_->Branch("min_zsep",&min_zsep_,"min_zsep/D");
126      pvtxtree_->Branch("min_ntrksep",&min_ntrksep_,"min_ntrksep/D");
127      pvtxtree_->Branch("min_sumpt2sep",&min_sumpt2sep_,"min_sumpt2sep/D");
128  
129 <    //pvtx using splittracks1
130 <    pvtxtree_->Branch("nrecPV1_spl",&nrecPV1_spl_,"nrecPV1_spl/I");
131 <    pvtxtree_->Branch("nTrkPV1_spl",&nTrkPV1_spl_,"nTrkPV1_spl[nrecPV1_spl]/I");  
132 <    pvtxtree_->Branch("sumptsq1_spl",&sumptsq1_spl_,"sumptsq1_spl[nrecPV1_spl]/D");  
132 <    pvtxtree_->Branch("isValid1_spl",&isValid1_spl_,"isValid1_spl/I");
133 <    pvtxtree_->Branch("isFake1_spl",&isFake1_spl_,"isFake1_spl/I");
134 <    pvtxtree_->Branch("recx1_spl",&recx1_spl_,"recx1_spl[nrecPV1_spl]/D");
135 <    pvtxtree_->Branch("recy1_spl",&recy1_spl_,"recy1_spl[nrecPV1_spl]/D");
136 <    pvtxtree_->Branch("recz1_spl",&recz1_spl_,"recz1_spl[nrecPV1_spl]/D");
137 <    pvtxtree_->Branch("recx1_err_spl",&recx1_err_spl_,"recx1_err_spl[nrecPV1_spl]/D");
138 <    pvtxtree_->Branch("recy1_err_spl",&recy1_err_spl_,"recy1_err_spl[nrecPV1_spl]/D");
139 <    pvtxtree_->Branch("recz1_err_spl",&recz1_err_spl_,"recz1_err_spl[nrecPV1_spl]/D");  
140 <  
141 <    //pvtx using splittracks2
142 <    pvtxtree_->Branch("nrecPV2_spl",&nrecPV2_spl_,"nrecPV2_spl/I");
143 <    pvtxtree_->Branch("nTrkPV2_spl",&nTrkPV2_spl_,"nTrkPV2_spl[nrecPV2_spl]/I");    
144 <    pvtxtree_->Branch("sumptsq2_spl",&sumptsq2_spl_,"sumptsq2_spl[nrecPV2_spl]/D");  
145 <    pvtxtree_->Branch("isValid2_spl",&isValid2_spl_,"isValid2_spl/I");
146 <    pvtxtree_->Branch("isFake2_spl",&isFake2_spl_,"isFake2_spl/I");
147 <    pvtxtree_->Branch("recx2_spl",&recx2_spl_,"recx2_spl[nrecPV2_spl]/D");
148 <    pvtxtree_->Branch("recy2_spl",&recy2_spl_,"recy2_spl[nrecPV2_spl]/D");
149 <    pvtxtree_->Branch("recz2_spl",&recz2_spl_,"recz2_spl[nrecPV2_spl]/D");
150 <    pvtxtree_->Branch("recx2_err_spl",&recx2_err_spl_,"recx2_err_spl[nrecPV2_spl]/D");
151 <    pvtxtree_->Branch("recy2_err_spl",&recy2_err_spl_,"recy2_err_spl[nrecPV2_spl]/D");
152 <    pvtxtree_->Branch("recz2_err_spl",&recz2_err_spl_,"recz2_err_spl[nrecPV2_spl]/D");  
153 <    
154 <    //pixeVertices
155 <    pvtxtree_->Branch("nrecPV_pxlpvtx",&nrecPV_pxlpvtx_,"nrecPV_pxlpvtx/I");
156 <    pvtxtree_->Branch("nTrkPV_pxlpvtx",&nTrkPV_pxlpvtx_,"nTrkPV_pxlpvtx[nrecPV_pxlpvtx]/I");    
157 <    pvtxtree_->Branch("sumptsq_pxlpvtx",&sumptsq_pxlpvtx_,"sumptsq_pxlpvtx[nrecPV_pxlpvtx]/D");  
158 <    pvtxtree_->Branch("isValid_pxlpvtx",&isValid_pxlpvtx_,"isValid_pxlpvtx/I");
159 <    pvtxtree_->Branch("isFake_pxlpvtx",&isFake_pxlpvtx_,"isFake_pxlpvtx/I");
160 <    pvtxtree_->Branch("recx_pxlpvtx",&recx_pxlpvtx_,"recx_pxlpvtx[nrecPV_pxlpvtx]/D");
161 <    pvtxtree_->Branch("recy_pxlpvtx",&recy_pxlpvtx_,"recy_pxlpvtx[nrecPV_pxlpvtx]/D");
162 <    pvtxtree_->Branch("recz_pxlpvtx",&recz_pxlpvtx_,"recz_pxlpvtx[nrecPV_pxlpvtx]/D");
163 <    pvtxtree_->Branch("recx_err_pxlpvtx",&recx_err_pxlpvtx_,"recx_err_pxlpvtx[nrecPV_pxlpvtx]/D");
164 <    pvtxtree_->Branch("recy_err_pxlpvtx",&recy_err_pxlpvtx_,"recy_err_pxlpvtx[nrecPV_pxlpvtx]/D");
165 <    pvtxtree_->Branch("recz_err_pxlpvtx",&recz_err_pxlpvtx_,"recz_err_pxlpvtx[nrecPV_pxlpvtx]/D");  
129 >    //Fill the variables in the twovtx pair (recvtx1, recvtx2)  
130 >    // Information related to the analyzing the two-vertex method
131 >
132 >
133  
167    //Fill the variables in the twovtx pair (recvtx1, recvtx2)
134      pvtxtree_->Branch("nrecPV_twovtx",&nrecPV_twovtx_,"nrecPV_twovtx/I");
169    pvtxtree_->Branch("nTrkPV1_spl_twovtx",&nTrkPV1_spl_twovtx_,"nTrkPV1_spl_twovtx[nrecPV_twovtx]/I");
170    pvtxtree_->Branch("nTrkPV2_spl_twovtx",&nTrkPV2_spl_twovtx_,"nTrkPV2_spl_twovtx[nrecPV_twovtx]/I");
171    pvtxtree_->Branch("sumptsq1_spl_twovtx",&sumptsq1_spl_twovtx_,"sumptsq1_spl_twovtx[nrecPV_twovtx]/D");
172    pvtxtree_->Branch("sumptsq2_spl_twovtx",&sumptsq2_spl_twovtx_,"sumptsq2_spl_twovtx[nrecPV_twovtx]/D");
135      pvtxtree_->Branch("nTrkPV_twovtx",&nTrkPV_twovtx_,"nTrkPV_twovtx[nrecPV_twovtx]/I");
136      pvtxtree_->Branch("deltax_twovtx",&deltax_twovtx_,"deltax_twovtx[nrecPV_twovtx]/D");
137      pvtxtree_->Branch("deltay_twovtx",&deltay_twovtx_,"deltay_twovtx[nrecPV_twovtx]/D");
# Line 180 | Line 142 | PVStudy::PVStudy(const edm::ParameterSet
142      pvtxtree_->Branch("pullx_twovtx",&pullx_twovtx_,"pullx_twovtx[nrecPV_twovtx]/D");
143      pvtxtree_->Branch("pully_twovtx",&pully_twovtx_,"pully_twovtx[nrecPV_twovtx]/D");
144      pvtxtree_->Branch("pullz_twovtx",&pullz_twovtx_,"pullz_twovtx[nrecPV_twovtx]/D");
145 +
146 +    // Information for the splitVertexColl1
147 +    pvtxtree_->Branch("nTrkPV1_spl_twovtx",&nTrkPV1_spl_twovtx_,"nTrkPV1_spl_twovtx[nrecPV_twovtx]/I");
148 +    pvtxtree_->Branch("ndofPV1_spl_twovtx",&ndofPV1_spl_twovtx_,"ndofPV1_spl_twovtx[nrecPV_twovtx]/D");
149 +    pvtxtree_->Branch("normchi2PV1_spl_twovtx",&normchi2PV1_spl_twovtx_,"normchi2PV1_spl_twovtx[nrecPV_twovtx]/D");
150 +    pvtxtree_->Branch("avgPtPV1_spl_twovtx",&avgPtPV1_spl_twovtx_,"avgPtPV1_spl_twovtx[nrecPV_twovtx]/D");
151 +    pvtxtree_->Branch("errx1_spl_twovtx",&errx1_spl_twovtx_,"errx1_spl_twovtx[nrecPV_twovtx]/D");
152 +    pvtxtree_->Branch("erry1_spl_twovtx",&erry1_spl_twovtx_,"erry1_spl_twovtx[nrecPV_twovtx]/D");
153 +    pvtxtree_->Branch("errz1_spl_twovtx",&errz1_spl_twovtx_,"errz1_spl_twovtx[nrecPV_twovtx]/D");
154 +  
155 +    
156 +    // Information for the splitVertexColl2
157 +    pvtxtree_->Branch("nTrkPV2_spl_twovtx",&nTrkPV2_spl_twovtx_,"nTrkPV2_spl_twovtx[nrecPV_twovtx]/I");
158 +    pvtxtree_->Branch("ndofPV2_spl_twovtx",&ndofPV2_spl_twovtx_,"ndofPV2_spl_twovtx[nrecPV_twovtx]/D");
159 +    pvtxtree_->Branch("normchi2PV2_spl_twovtx",&normchi2PV2_spl_twovtx_,"normchi2PV2_spl_twovtx[nrecPV_twovtx]/D");
160 +    pvtxtree_->Branch("avgPtPV2_spl_twovtx",&avgPtPV2_spl_twovtx_,"avgPtPV2_spl_twovtx[nrecPV_twovtx]/D");
161 +    pvtxtree_->Branch("errx2_spl_twovtx",&errx2_spl_twovtx_,"errx2_spl_twovtx[nrecPV_twovtx]/D");
162 +    pvtxtree_->Branch("erry2_spl_twovtx",&erry2_spl_twovtx_,"erry2_spl_twovtx[nrecPV_twovtx]/D");
163 +    pvtxtree_->Branch("errz2_spl_twovtx",&errz2_spl_twovtx_,"errz2_spl_twovtx[nrecPV_twovtx]/D");
164 +  
165      
166      // MC variables
167      if(!realData_) {  
# Line 197 | Line 179 | PVStudy::PVStudy(const edm::ParameterSet
179        pvtxtree_->Branch("deltaz_mct",&deltaz_mct_,"deltaz_mct[nrecPV_mct]/D");
180        pvtxtree_->Branch("pullx_mct",&pullx_mct_,"pullx_mct[nrecPV_mct]/D");
181        pvtxtree_->Branch("pully_mct",&pully_mct_,"pully_mct[nrecPV_mct]/D");
182 <      pvtxtree_->Branch("pullz_mct",&pullz_mct_,"pullz_mct[nrecPV_mct]/D");
182 >      pvtxtree_->Branch("pullz_mct",&pullz_mct_,"pullz_mct[nrecPV_mct]/D");    
183 >      pvtxtree_->Branch("errx_mct",&errx_mct_,"errx_mct[nrecPV_mct]/D");
184 >      pvtxtree_->Branch("erry_mct",&erry_mct_,"erry_mct[nrecPV_mct]/D");
185 >      pvtxtree_->Branch("errz_mct",&errz_mct_,"errz_mct[nrecPV_mct]/D");
186 >      pvtxtree_->Branch("nTrkPV_mct",&nTrkPV_mct_,"nTrkPV_mct[nrecPV_mct]/I");
187 >      pvtxtree_->Branch("ndofPV_mct",&ndofPV_mct_,"ndofPV_mct[nrecPV_mct]/D");
188 >      pvtxtree_->Branch("normchi2PV_mct",&normchi2PV_mct_,"normchi2PV_mct[nrecPV_mct]/D");
189 >      pvtxtree_->Branch("avgPtPV_mct",&avgPtPV_mct_,"avgPtPV_mct[nrecPV_mct]/D");
190 >
191        // For pvtxs with splittracks1
192        pvtxtree_->Branch("nrecPV_spl1_mct",&nrecPV_spl1_mct_,"nrecPV_spl1_mct/I");
193        pvtxtree_->Branch("deltax_spl1_mct",&deltax_spl1_mct_,"deltax_spl1_mct[nrecPV_spl1_mct]/D");
# Line 206 | Line 196 | PVStudy::PVStudy(const edm::ParameterSet
196        pvtxtree_->Branch("pullx_spl1_mct",&pullx_spl1_mct_,"pullx_spl1_mct[nrecPV_spl1_mct]/D");
197        pvtxtree_->Branch("pully_spl1_mct",&pully_spl1_mct_,"pully_spl1_mct[nrecPV_spl1_mct]/D");
198        pvtxtree_->Branch("pullz_spl1_mct",&pullz_spl1_mct_,"pullz_spl1_mct[nrecPV_spl1_mct]/D");
199 +      pvtxtree_->Branch("errx_spl1_mct",&errx_spl1_mct_,"errx_spl1_mct[nrecPV_spl1_mct]/D");
200 +      pvtxtree_->Branch("erry_spl1_mct",&erry_spl1_mct_,"erry_spl1_mct[nrecPV_spl1_mct]/D");
201 +      pvtxtree_->Branch("errz_spl1_mct",&errz_spl1_mct_,"errz_spl1_mct[nrecPV_spl1_mct]/D");
202 +      pvtxtree_->Branch("nTrkPV_spl1_mct",&nTrkPV_spl1_mct_,"nTrkPV_spl1_mct[nrecPV_spl1_mct]/I");
203 +      pvtxtree_->Branch("ndofPV_spl1_mct",&ndofPV_spl1_mct_,"ndofPV_spl1_mct[nrecPV_spl1_mct]/D");
204 +      pvtxtree_->Branch("normchi2PV_spl1_mct",&normchi2PV_spl1_mct_,"normchi2PV_spl1_mct[nrecPV_spl1_mct]/D");
205 +      pvtxtree_->Branch("avgPtPV_spl1_mct",&avgPtPV_spl1_mct_,"avgPtPV_spl1_mct[nrecPV_spl1_mct]/D");
206 +        
207        // For pvtxs with splittracks1
208        pvtxtree_->Branch("nrecPV_spl2_mct",&nrecPV_spl2_mct_,"nrecPV_spl2_mct/I");
209        pvtxtree_->Branch("deltax_spl2_mct",&deltax_spl2_mct_,"deltax_spl2_mct[nrecPV_spl2_mct]/D");
# Line 213 | Line 211 | PVStudy::PVStudy(const edm::ParameterSet
211        pvtxtree_->Branch("deltaz_spl2_mct",&deltaz_spl2_mct_,"deltaz_spl2_mct[nrecPV_spl2_mct]/D");
212        pvtxtree_->Branch("pullx_spl2_mct",&pullx_spl2_mct_,"pullx_spl2_mct[nrecPV_spl2_mct]/D");
213        pvtxtree_->Branch("pully_spl2_mct",&pully_spl2_mct_,"pully_spl2_mct[nrecPV_spl2_mct]/D");
214 <      pvtxtree_->Branch("pullz_spl2_mct",&pullz_spl2_mct_,"pullz_spl2_mct[nrecPV_spl2_mct]/D");
214 >      pvtxtree_->Branch("pullz_spl2_mct",&pullz_spl2_mct_,"pullz_spl2_mct[nrecPV_spl2_mct]/D");  
215 >      pvtxtree_->Branch("errx_spl2_mct",&errx_spl2_mct_,"errx_spl2_mct[nrecPV_spl2_mct]/D");
216 >      pvtxtree_->Branch("erry_spl2_mct",&erry_spl2_mct_,"erry_spl2_mct[nrecPV_spl2_mct]/D");
217 >      pvtxtree_->Branch("errz_spl2_mct",&errz_spl2_mct_,"errz_spl2_mct[nrecPV_spl2_mct]/D");  
218 >      pvtxtree_->Branch("nTrkPV_spl2_mct",&nTrkPV_spl2_mct_,"nTrkPV_spl2_mct[nrecPV_spl2_mct]/I");
219 >      pvtxtree_->Branch("ndofPV_spl2_mct",&ndofPV_spl2_mct_,"ndofPV_spl2_mct[nrecPV_spl2_mct]/D");
220 >      pvtxtree_->Branch("normchi2PV_spl2_mct",&normchi2PV_spl2_mct_,"normchi2PV_spl2_mct[nrecPV_spl2_mct]/D");
221 >      pvtxtree_->Branch("avgPtPV_spl2_mct",&avgPtPV_spl2_mct_,"avgPtPV_spl2_mct[nrecPV_spl2_mct]/D");
222 >
223      }
224    }
219
220  edm::Service<TFileService> fs;
221  TFileDirectory subDir = fs->mkdir( "Summary" );
222  TFileDirectory subDir1 = fs->mkdir( "Others" );
223  //   TFileDirectory subSubDir = subDir.mkdir( "mySubSubDirectory" );
224
225  setRootStyle();
225    
226 <  //Book histograms for track and pvtx parameters for each splitted pvtx
228 <  //i=0 : x (as in unsplit track collection)
229 <  //i=1 : x1_spl_
230 <  //i=2 : x2_spl_
226 >  setRootStyle();
227  
228 <  
229 <  for(int i=0;i<3;i++)
230 <    {  
231 <      string suffix;
232 <      if(i == 0) suffix = "";
233 <      else {
234 <        stringstream ss;
235 <        ss << i;
236 <        suffix =ss.str()+"_spl";  
237 <      }
238 <      h["nTrk"+suffix]   = subDir.make<TH1D>(TString("nTrk"+suffix), TString("Num of rec tracks"+suffix),300,0,300);
239 <      h["trkPt"+suffix]  = subDir.make<TH1D>(TString("trkPt"+suffix), TString("Pt of rec tracks "+suffix),100,0,100);
240 <      h["trkEta"+suffix] = subDir.make<TH1D>(TString("trkEta"+suffix), TString("#eta of rec tracks "+suffix),100,-3,3);
241 <      h["trkPhi"+suffix] = subDir.make<TH1D>(TString("trkPhi"+suffix), TString("#Phi of rec tracks "+suffix),100,-3.2,3.2);
242 <      h["trkDxy"+suffix] = subDir.make<TH1D>(TString("trkDxy"+suffix), TString("Dxy of rec tracks "+suffix),100,-0.5,0.5);  
243 <      h["trkDz"+suffix] = subDir.make<TH1D>(TString("trkDz"+suffix), TString("Dz of rec tracks "+suffix),100,-50,50);  
244 <      
245 <      h["nTrkPV"+suffix]   = subDir.make<TH1D>(TString("nTrkPV"+suffix), TString("Num of rec tracks in PV"+suffix),300,0,300);
246 <      h["trkPtPV"+suffix]  = subDir.make<TH1D>(TString("trkPtPV"+suffix), TString("Pt of rec tracks in "+suffix),100,0,100);
247 <      h["trkEtaPV"+suffix] = subDir.make<TH1D>(TString("trkEtaPV"+suffix), TString("#eta of rec tracks in PV"+suffix),100,-3,3);
248 <      h["trkPhiPV"+suffix] = subDir.make<TH1D>(TString("trkPhiPV"+suffix), TString("#Phi of rec tracks in PV"+suffix),100,-3.2,3.2);
249 <      h["trkDxyPV"+suffix] = subDir.make<TH1D>(TString("trkDxyPV"+suffix), TString("Dxy of rec tracks in PV"+suffix),100,-5,5);  
250 <      h["trkDzPV"+suffix] = subDir.make<TH1D>(TString("trkDzPV"+suffix), TString("Dz of rec tracks "+suffix),100,-50,50);
251 <      h["nrecPV"+suffix]   = subDir.make<TH1D>(TString("nrecPV"+suffix), TString("Num of rec pvtx"+suffix),50,0,50);    
252 <      suffix.clear();
228 >  //========================================
229 >  // Booking histograms
230 >  //========================================
231 >  
232 >  // Create a root file for histograms
233 >  theFile = new TFile(histoFileName_.c_str(), "RECREATE");
234 >  // make diretories
235 >  theFile->mkdir("Summary");
236 >  theFile->cd();
237 >  theFile->mkdir("Others");
238 >  theFile->cd();
239 >  if (analyze_) {
240 >    theFile->mkdir("Results");
241 >    theFile->cd();
242 >  }
243 >
244 >  // Book Histograms:
245 >  h_pvtrk   = new PVHistograms();
246 >  h_misc    = new PVHistograms();
247 >  h_summary = new PVHistograms();
248 >  h_others  = new PVHistograms();
249 >
250 >  for(int i=0;i<3;i++) {  
251 >    if(i == 0) h_pvtrk->Init("pvTrk");
252 >    else {
253 >      stringstream ss;
254 >      ss << i;
255 >      h_pvtrk->Init("pvTrk", ss.str(),"spl");
256      }
257 <  h["nrecPVDiff"]     = subDir.make<TH1D>("nrecPVDiff","nrecPV1-nRecPV2",21,-10.5,10.5);
258 <  h["nTrkPVDiff"]     = subDir.make<TH1D>("nTrkPVDiff","nTrkPV1-nTrkPV2",41,-20.5,20.5);
259 <  h["nTrkPVRelDiff"]  = subDir.make<TH1D>("nTrkPVRelDiff","(nTrkPV1-nTrkPV2)/(nTrkPV1+nTrkPV2)",100,-1,1);
260 <
261 <  // Histograms on comparing the multi-vertices
262 <  // Difference in reconstructed vtx position
263 <  h["min_xsep"]   = subDir.make<TH1D>("min_xsep", "min x diff of primary and secondary pvtx",300,0,0.1);
264 <  h["min_xsep_sign"]   = subDir.make<TH1D>("min_xsep_sign", "min x diff in signf of primary and secondary pvtx",300,0,5);
265 <  h["min_ysep"]   = subDir.make<TH1D>("min_ysep", "min y diff of primary and secondary pvtx",300,0,0.1);
267 <  h["min_ysep_sign"]   = subDir.make<TH1D>("min_ysep_sign", "min y diff in signf of primary and secondary pvtx",300,0,5);
268 <  h["min_zsep"]   = subDir.make<TH1D>("min_zsep", "min z diff of primary and secondary pvtx",300,0,5);
269 <  h["min_zsep_sign"]   = subDir.make<TH1D>("min_zsep_sign", "min z diff in signf of primary and secondary pvtx",300,0,200);
270 <  // Difference in reconstructed vtx position
271 <  h["min_ntrksep"]   = subDir.make<TH1D>("min_ntrksep", "min nTrk diff of primary and secondary pvtx",201,-50.5,150.5);
272 <  h["min_sumpt2sep"]   = subDir.make<TH1D>("min_sumpt2sep", "min sumpt2 diff of primary and secondary pvtx",300,0,10000);
257 >  }
258 >  h_misc->Init("misc");
259 >
260 >  // Book MC only plots
261 >  if (!realData_) {
262 >    h_gen = new PVHistograms();
263 >    h_gen->Init("generator");
264 >  }
265 >  if (analyze_) h_ana = new PVHistograms();
266  
267    //Book histograms sensitive to data/mc
268    for (vector<int>::const_iterator it= datamode.begin(); it != datamode.end() ; ++it) {
269      string suffix;
270 <    if(verbose_)  cout<<"datamode = "<< *it<<endl;
270 >    edm::LogInfo("Debug")<<"datamode = "<< *it<<endl;
271      switch(*it) {
272      case 0: suffix = "";
273        break;
# Line 285 | Line 278 | PVStudy::PVStudy(const edm::ParameterSet
278      case 3: suffix = "_mct";
279        break;
280      }
281 <    h["deltax"+suffix] = subDir.make<TH1D>(TString("deltax"+suffix), TString("x-residual pvtx"+suffix),800,-0.04,0.04);
289 <    h["deltay"+suffix] = subDir.make<TH1D>(TString("deltay"+suffix), TString("y-residual pvtx"+suffix),800,-0.04,0.04);
290 <    h["deltaz"+suffix] = subDir.make<TH1D>(TString("deltaz"+suffix), TString("z-residual pvtx"+suffix),800,-0.04,0.04);
291 <    h["pullx"+suffix]  = subDir.make<TH1D>(TString("pullx"+suffix), TString("x-pull pvtx"+suffix),800,-10,10);
292 <    h["pully"+suffix]  = subDir.make<TH1D>(TString("pully"+suffix), TString("y-pull pvtx"+suffix),800,-10,10);
293 <    h["pullz"+suffix]  = subDir.make<TH1D>(TString("pullz"+suffix), TString("z-pull pvtx"+suffix),800,-10,10);
294 <    h["errPVx"+suffix] = subDir.make<TH1D>(TString("errPVx"+suffix), TString("X"+suffix+" vertex error"),100,0.,0.02);
295 <    h["errPVy"+suffix] = subDir.make<TH1D>(TString("errPVy"+suffix), TString("Y"+suffix+" vertex error"),100,0.,0.02);
296 <    h["errPVz"+suffix] = subDir.make<TH1D>(TString("errPVz"+suffix), TString("Z"+suffix+" vertex error"),100,0.,0.02);
281 >    h_summary->Init("summary",suffix);
282      
283      // Book residual, error and pull histograms for each nTrk bin
284      for (int ntrk=nTrkMin_;ntrk<=nTrkMax_;++ntrk) {
285        stringstream ss;
286        ss << ntrk;
287 <      string suffix2 = suffix+"_"+ss.str();
288 <      h["deltax"+suffix2]  = subDir1.make<TH1D>(TString("deltax"+suffix2), TString("x-residual of pvtx"+suffix),100,-0.02,0.02);
289 <      h["deltax"+suffix2]->GetXaxis()->SetTitle("cm");
305 <      h["deltay"+suffix2]  = subDir1.make<TH1D>(TString("deltay"+suffix2), TString("y-residual of pvtx"+suffix),100,-0.02,0.02);
306 <      h["deltay"+suffix2]->GetXaxis()->SetTitle("cm");
307 <      h["deltaz"+suffix2]  = subDir1.make<TH1D>(TString("deltaz"+suffix2), TString("z-residual of pvtx"+suffix),100,-0.02,0.02);
308 <      h["deltaz"+suffix2]->GetXaxis()->SetTitle("cm");
309 <      h["pullx"+suffix2] = subDir1.make<TH1D>(TString("pullx"+suffix2), TString("x-pull of pvtx"+suffix),100,-10.,10.);
310 <      h["pully"+suffix2] = subDir1.make<TH1D>(TString("pully"+suffix2), TString("y-pull of pvtx"+suffix),100,-10.,10.);
311 <      h["pullz"+suffix2] = subDir1.make<TH1D>(TString("pullz"+suffix2), TString("z-pull of pvtx"+suffix),100,-10.,10.);
312 <      h["errPVx"+suffix2] = subDir1.make<TH1D>(TString("errPVx"+suffix2), TString("X"+suffix+" vertex error"),100,0.,0.02);
313 <      h["errPVy"+suffix2] = subDir1.make<TH1D>(TString("errPVy"+suffix2), TString("Y"+suffix+" vertex error"),100,0.,0.02);
314 <      h["errPVz"+suffix2] = subDir1.make<TH1D>(TString("errPVz"+suffix2), TString("Z"+suffix+" vertex error"),100,0.,0.02);
315 <      suffix2.clear();
316 <    } // End of   for (int ntrk=nTrkMin_;ntrk<=nTrkMax_;++ntrk) {
317 <    
287 >      h_others->Init("others",suffix,ss.str());
288 >    }
289 >
290      // Book residual and pull histograms only when analyzeOntheFly is enabled
291 <    if(analyze_) {
320 <      h2["resx"+suffix+"_nTrk"]= subDir.make<TH2D>(TString("resx"+suffix+"_nTrk"), TString("x-resolution vs number of tracks in pvtx"+suffix),150,0,150,400,0.,200);
321 <      h2["resx"+suffix+"_nTrk"]->SetMarkerStyle(21);
322 <      h2["resx"+suffix+"_nTrk"]->SetMarkerColor(4);
323 <      h2["resx"+suffix+"_nTrk"]->GetXaxis()->SetTitle("Num of tracks");
324 <      h2["resx"+suffix+"_nTrk"]->GetYaxis()->SetTitle("#mum");
325 <      h2["resy"+suffix+"_nTrk"]= subDir.make<TH2D>(TString("resy"+suffix+"_nTrk"), TString("y-resolution vs number of tracks in pvtx"+suffix),150,0,150,400,0.,200);
326 <      h2["resy"+suffix+"_nTrk"]->SetMarkerStyle(21);
327 <      h2["resy"+suffix+"_nTrk"]->SetMarkerColor(4);
328 <      h2["resy"+suffix+"_nTrk"]->GetXaxis()->SetTitle("Num of tracks");
329 <      h2["resy"+suffix+"_nTrk"]->GetYaxis()->SetTitle("#mum");
330 <      h2["resz"+suffix+"_nTrk"]= subDir.make<TH2D>(TString("resz"+suffix+"_nTrk"), TString("z-resolution vs number of tracks in pvtx"+suffix),150,0,150,400,0.,200);
331 <      h2["resz"+suffix+"_nTrk"]->SetMarkerStyle(21);
332 <      h2["resz"+suffix+"_nTrk"]->SetMarkerColor(4);
333 <      h2["resz"+suffix+"_nTrk"]->GetXaxis()->SetTitle("Num of tracks");
334 <      h2["resz"+suffix+"_nTrk"]->GetYaxis()->SetTitle("#mum");
335 <      h2["pullx"+suffix+"_nTrk"]= subDir.make<TH2D>(TString("pullx"+suffix+"_nTrk"), TString("x-pull vs number of tracks"+suffix),150,0,150,100,0.,2.);
336 <      h2["pullx"+suffix+"_nTrk"]->SetMarkerStyle(21);
337 <      h2["pullx"+suffix+"_nTrk"]->SetMarkerColor(4);
338 <      h2["pullx"+suffix+"_nTrk"]->SetBit(TH1::kCanRebin);
339 <      h2["pullx"+suffix+"_nTrk"]->GetXaxis()->SetTitle("Num of tracks");
340 <      h2["pully"+suffix+"_nTrk"]= subDir.make<TH2D>(TString("pully"+suffix+"_nTrk"), TString("y-pull vs number of tracks"+suffix),150,0,150,100,0.,2.);
341 <      h2["pully"+suffix+"_nTrk"]->SetMarkerStyle(21);
342 <      h2["pully"+suffix+"_nTrk"]->SetMarkerColor(4);
343 <      h2["pully"+suffix+"_nTrk"]->SetBit(TH1::kCanRebin);
344 <      h2["pully"+suffix+"_nTrk"]->GetXaxis()->SetTitle("Num of tracks");
345 <      h2["pullz"+suffix+"_nTrk"]= subDir.make<TH2D>(TString("pullz"+suffix+"_nTrk"), TString("x-pull vs number of tracks"+suffix),150,0,150,100,0.,2.);
346 <      h2["pullz"+suffix+"_nTrk"]->SetMarkerStyle(21);
347 <      h2["pullz"+suffix+"_nTrk"]->SetMarkerColor(4);
348 <      h2["pullz"+suffix+"_nTrk"]->SetBit(TH1::kCanRebin);
349 <      h2["pullz"+suffix+"_nTrk"]->GetXaxis()->SetTitle("Num of tracks");
350 <    } // End of   if(analyze_) {
291 >    if(analyze_) h_ana->InitA("analysis",suffix,"nTrk",nTrkMin_,nTrkMax_);
292      suffix.clear();
293    } // End of Book histograms sensitive to data/mc    
294    
354  // Book histograms about pixelVertices
355  h["trkdz_pxlpvtxdz"]   = subDir.make<TH1D>("trkdz_pxlpvtxdz", "(Track dz - pixelpvtx dz) in cm",300,-0.5,0.5);
356  h["trkdz_pxlpvtxdz_pxlpvtxdzerr"]   = subDir.make<TH1D>("trkdz_pxlpvtxdz_pxlpvtxdzerr", "|Track dz - pixelpvtx dz| / pxlpvtxdzErr",300,0,100);  
357  h["trkdz_pxlpvtxdz_trkdzerr"]   = subDir.make<TH1D>("trkdz_pxlpvtxdz_trkdzerr", "|Track dz - pixelpvtx dz| / trkdzErr",300,0,50);
358  h["trkdzErr_pxlpvtx"]   = subDir.make<TH1D>("trkdzErr_pxlpvtxdz", "Track dzErr of leading pixelpvtx ",300,0,0.5);
359  h["trkdzErr_pvtx"]   = subDir.make<TH1D>("trkdzErr_pvtx", "Track dzErr of the leading pvtx ",300,0,0.5);
360  h["dzErr_pxlpvtx"]   = subDir.make<TH1D>("dzErr_pxlpvtx", "zError of the leading pvtx ",300,0,0.5);
361  // Compare offlinePrimaryVertices with pixelVertices
362  h["nrecPV_minus_nrecPxlPV"] =  subDir.make<TH1D>("nrecPV_minus_nrecPxlPV", "nrecPV_minus_nrecPxlPV",21,-10.5,10.5);
363  h["recxPV_minus_recxPxlPV"] =  subDir.make<TH1D>("recxPV_minus_recxPxlPV", "recxPV_minus_recxPxlPV",300,-0.02,0.02);
364  h["recyPV_minus_recyPxlPV"] =  subDir.make<TH1D>("recyPV_minus_recyPxlPV", "recyPV_minus_recyPxlPV",300,-0.02,0.02);
365  h["reczPV_minus_reczPxlPV"] =  subDir.make<TH1D>("reczPV_minus_reczPxlPV", "reczPV_minus_reczPxlPV",300,-0.1,0.1);
295  
367  // Book MC only plots
368  if (!realData_) {  
369    h["genPart_T"]      = subDir.make<TH1D>("genPart_T","t component of gen particles",300,-0.5,0.5);
370    h["genPart_T"]->GetXaxis()->SetTitle("t (nanosecond)");
371    h["genPart_cT"]     = subDir.make<TH1D>("genPart_cT","ct component of gen particles",300,-150.,150.);
372    h["genPart_cT"]->GetXaxis()->SetTitle("ct (mm)");    
373    h["nsimPV"]         = subDir.make<TH1D>("nsimPV","Num of sim PV",51,-0.5,50.5);  
374  }
296   }
297  
298   PVStudy::~PVStudy()
# Line 379 | Line 300 | PVStudy::~PVStudy()
300  
301    // do anything here that needs to be done at desctruction time
302    // (e.g. close files, deallocate resources etc.)
303 +  theFile->cd();
304 +  theFile->cd("Summary");
305 +  h_pvtrk->Save();
306 +  h_misc->Save();
307 +  h_summary->Save();
308 +  if (!realData_)
309 +    h_gen->Save();
310 +  if (analyze_) {
311 +    theFile->cd();
312 +    theFile->cd("Results");
313 +    h_ana->Save();
314 +  }
315 +  theFile->cd();
316 +  theFile->cd("Others");
317 +  h_others->Save();
318  
319 +  theFile->Close();
320   }
321  
322   void PVStudy::setRootStyle() {
# Line 403 | Line 340 | void PVStudy::setRootStyle() {
340    gStyle->SetTitleSize(0.055, "");    // size for pad title; default is 0.02
341    gStyle->SetLabelSize(0.03, "XYZ");  // size for axis labels; default is 0.04
342    gStyle->SetStatFontSize(0.08);      // size for stat. box
343 <  gStyle->SetTitleFont(32, "XYZ");    // times-bold-italic font (p. 153) for axes
344 <  gStyle->SetTitleFont(32, "");       // same for pad title
345 <  gStyle->SetLabelFont(32, "XYZ");    // same for axis labels
346 <  gStyle->SetStatFont(32);            // same for stat. box
343 >  gStyle->SetTitleFont(42, "XYZ");    // times-bold-italic font (p. 153) for axes
344 >  gStyle->SetTitleFont(42, "");       // same for pad title
345 >  gStyle->SetLabelFont(42, "XYZ");    // same for axis labels
346 >  gStyle->SetStatFont(42);            // same for stat. box
347    gStyle->SetLabelOffset(0.006, "Y"); // default is 0.005
348    //
349    return;
# Line 416 | Line 353 | void PVStudy::setRootStyle() {
353   //
354   std::vector<PVStudy::simPrimaryVertex> PVStudy::getSimPVs(const Handle<HepMCProduct> evtMC, std::string suffix="")
355   {
356 <  std::vector<PVStudy::simPrimaryVertex> simpv;
356 > std::vector<PVStudy::simPrimaryVertex> simpv;
357    const HepMC::GenEvent* evt=evtMC->GetEvent();
358    if (evt) {
359 <    if(verbose_) {
360 <      cout << "process id " << evt->signal_process_id()<<endl;
361 <      cout << "signal process vertex " << ( evt->signal_process_vertex() ?
362 <                                            evt->signal_process_vertex()->barcode() : 0 )   <<endl;
426 <      cout << "number of vertices " << evt->vertices_size() << endl;
427 <    }
359 >    edm::LogInfo("SimPVs") << "[getSimPVs] process id " << evt->signal_process_id()<<endl;
360 >    edm::LogInfo("SimPVs") << "[getSimPVs] signal process vertex " << ( evt->signal_process_vertex() ?
361 >                                                                        evt->signal_process_vertex()->barcode() : 0 ) <<endl;
362 >    edm::LogInfo("SimPVs") << "[getSimPVs] number of vertices " << evt->vertices_size() << endl;
363  
364      int idx=0; int npv=0;
365      for(HepMC::GenEvent::vertex_const_iterator vitr= evt->vertices_begin();
# Line 435 | Line 370 | std::vector<PVStudy::simPrimaryVertex> P
370        // t component of PV:
371        for ( HepMC::GenVertex::particle_iterator mother  = (*vitr)->particles_begin(HepMC::parents);
372              mother != (*vitr)->particles_end(HepMC::parents); ++mother ) {
373 <        //        std::cout << "Status = " << (*mother)->status() << std::endl;
373 >        //        edm::LogInfo("SimPVs") << "Status = " << (*mother)->status() << endl;
374          HepMC::GenVertex * mv=(*mother)->production_vertex();
375          if( ((*mother)->status() == 3) && (!mv)) {
376 <          //        std::cout << "npv= " << npv << std::endl;
376 >          //        edm::LogInfo("SimPVs") << "npv= " << npv << endl;
377            if (npv == 0) {
378 <            h["genPart_cT"]->Fill(pos.t()); // mm
379 <            h["genPart_T"]->Fill(pos.t()/299.792458); // ns
378 >            h_gen->Fill1d("genPart_cT", pos.t()); // mm
379 >            h_gen->Fill1d("genPart_T", pos.t()/299.792458); // ns
380            }
381            npv++;
382          }
# Line 449 | Line 384 | std::vector<PVStudy::simPrimaryVertex> P
384        //       if (pos.t()>0) { continue;} // for 22X when t of PV was not smeared
385          
386        bool hasMotherVertex=false;
387 <      if(verbose_) cout << "mothers of vertex[" << ++idx << "]: " << endl;
387 >      if (verbose_) cout << "[getSimPVs] mothers of vertex[" << ++idx << "]: " << endl;
388        for ( HepMC::GenVertex::particle_iterator mother  = (*vitr)->particles_begin(HepMC::parents);
389              mother != (*vitr)->particles_end(HepMC::parents); ++mother ) {
390          HepMC::GenVertex * mv=(*mother)->production_vertex();
391 <        //        std::cout << "Status = " << (*mother)->status() << std::endl;
391 >        // if (verbose_) cout << "Status = " << (*mother)->status() << endl;
392          if (mv) {
393            hasMotherVertex=true;
394            if(!verbose_) break; //if verbose_, print all particles of gen vertices
# Line 480 | Line 415 | std::vector<PVStudy::simPrimaryVertex> P
415  
416        if(!vp){
417          // this is a new vertex
418 <        if(verbose_) cout << "this is a new vertex " << sv.x << " " << sv.y << " " << sv.z << endl;
418 >        edm::LogInfo("SimPVs") << "[getSimPVs] this is a new vertex " << sv.x << " " << sv.y << " " << sv.z << endl;
419          simpv.push_back(sv);
420          vp=&simpv.back();
421        }else{
422 <        if(verbose_) cout << "this is not a new vertex " << sv.x << " " << sv.y << " " << sv.z << endl;
422 >        edm::LogInfo("SimPVs") << "[getSimPVs] this is not a new vertex " << sv.x << " " << sv.y << " " << sv.z << endl;
423        }
424        vp->genVertex.push_back((*vitr)->barcode());
425        // collect final state descendants
# Line 508 | Line 443 | std::vector<PVStudy::simPrimaryVertex> P
443              }
444            }
445          }
446 <      }
447 <    }
446 >      }//loop MC vertices daughters
447 >    }//loop MC vertices
448    }
449    return simpv;
450   }
# Line 542 | Line 477 | std::vector<PVStudy::simPrimaryVertex> P
477                ptsq+=(*daughter)->momentum().perp()*(*daughter)->momentum().perp();
478              }
479            }
480 <          primary =  ( gv->position().t()==0);
480 >          //primary =  ( gv->position().t()==0 );
481 >          primary = true;
482 >          h_gen->Fill1d("genPart_cT", gv->position().t()); // mm
483 >          h_gen->Fill1d("genPart_T", gv->position().t()/299.792458); // ns
484 >
485            //resonance= ( gp->mother() && isResonance(gp->mother()));  // in CLHEP/HepMC days
486            // no more mother pointer in the improved HepMC GenParticle
487            resonance= ( isResonance(*(gp->production_vertex()->particles_in_const_begin())));
# Line 591 | Line 530 | PVStudy::analyze(const edm::Event& iEven
530    using namespace edm;
531    using namespace reco;
532    
533 <  if (verbose_)
534 <    cout<<"PVStudy::analyze():"<<endl;
535 <  //=======================================================
533 >  //========================================================================
534 >  // Step 0: Prepare root variables and get information from the Event
535 >  //========================================================================
536 >  
537 >  edm::LogInfo("Debug")<<"[PVStudy]"<<endl;
538    // Initialize Root-tuple variables if needed
598  //=======================================================
599  //if(saventuple_)
539    SetVarToZero();
540    
541 <  //=======================================================
603 <  // Track accessors
604 <  //=======================================================
605 <  //trackCollection
541 >  // ====== TrackCollection
542    static const reco::TrackCollection s_empty_trackColl;
543    const reco::TrackCollection *trackColl = &s_empty_trackColl;
544    edm::Handle<reco::TrackCollection> trackCollectionHandle;
# Line 610 | Line 546 | PVStudy::analyze(const edm::Event& iEven
546    if( iEvent.getByLabel(trackCollectionTag_, trackCollectionHandle)) {
547      trackColl = trackCollectionHandle.product();
548    } else {
549 <    cout << "trackCollection cannot be found -> using empty collection of same type." <<endl;
549 >    edm::LogInfo("Debug") << "[PVStudy] trackCollection cannot be found -> using empty collection of same type." <<endl;
550    }
551 <
616 <  //splitTrackCollection1
551 >  // ====== splitTrackCollection1
552    static const reco::TrackCollection s_empty_splitTrackColl1;
553    const reco::TrackCollection *splitTrackColl1 = &s_empty_splitTrackColl1;
554    edm::Handle<reco::TrackCollection> splitTrackCollection1Handle;
# Line 621 | Line 556 | PVStudy::analyze(const edm::Event& iEven
556    if( iEvent.getByLabel(splitTrackCollection1Tag_, splitTrackCollection1Handle)) {
557      splitTrackColl1 = splitTrackCollection1Handle.product();
558    } else {
559 <    cout << "splitTrackCollection1 cannot be found -> using empty collection of same type." <<endl;
559 >    edm::LogInfo("Debug") << "[PVStudy] splitTrackCollection1 cannot be found -> using empty collection of same type." <<endl;
560    }
561 <
627 <  //splitTrackCollection2
561 >  // ====== splitTrackCollection2
562    static const reco::TrackCollection s_empty_splitTrackColl2;
563    const reco::TrackCollection *splitTrackColl2 = &s_empty_splitTrackColl2;
564    edm::Handle<reco::TrackCollection> splitTrackCollection2Handle;
# Line 632 | Line 566 | PVStudy::analyze(const edm::Event& iEven
566    if( iEvent.getByLabel(splitTrackCollection2Tag_, splitTrackCollection2Handle)) {
567      splitTrackColl2 = splitTrackCollection2Handle.product();
568    } else {
569 <    cout << "splitTrackCollection2 cannot be found -> using empty collection of same type." <<endl;
569 >   edm::LogInfo("Debug") << "[PVStudy] splitTrackCollection2 cannot be found -> using empty collection of same type." <<endl;
570    }
571 <
572 <
639 < //=======================================================
640 <  // Fill trackparameters of the input tracks to pvtx fitter
641 <  //=======================================================
642 <  if(verbose_)
643 <    cout<<"Start filling track parameters of the input tracks to pvtx fitter."<<endl;
644 <  //fillTrackHisto(const reco::TrackCollection *trackColl, int datatype)
645 <  // datatype: unsplittracks (0); splittracks1 (1);  splittracks2 (2);
646 <  fillTrackHisto(trackColl, 0);
647 <  fillTrackHisto(splitTrackColl1, 1);
648 <  fillTrackHisto(splitTrackColl2, 2);
649 <  if(verbose_)
650 <    cout<<"End filling track parameters of the input tracks to pvtx fitter."<<endl;
651 <
652 <  //=======================================================
653 <  // PVTX accessors
654 <  //=======================================================
655 <  //vertexCollection
571 >  
572 >  // ======= PrimaryVertexCollection
573    static const reco::VertexCollection s_empty_vertexColl;
574    const reco::VertexCollection *vertexColl = &s_empty_vertexColl;
575    edm::Handle<reco::VertexCollection> vertexCollectionHandle;
# Line 660 | Line 577 | PVStudy::analyze(const edm::Event& iEven
577    if( iEvent.getByLabel(vertexCollectionTag_, vertexCollectionHandle)) {
578      vertexColl = vertexCollectionHandle.product();
579    } else {
580 <    cout << "vertexCollection cannot be found -> using empty collection of same type." <<endl;
580 >   edm::LogInfo("Debug") << "[PVStudy] vertexCollection cannot be found -> using empty collection of same type." <<endl;
581    }
582 <
666 <  //splitVertexCollection1
582 >  // ====== splitVertexCollection1
583    static const reco::VertexCollection s_empty_splitVertexColl1;
584    const reco::VertexCollection *splitVertexColl1 = &s_empty_splitVertexColl1;
585    edm::Handle<reco::VertexCollection> splitVertexCollection1Handle;
# Line 671 | Line 587 | PVStudy::analyze(const edm::Event& iEven
587    if( iEvent.getByLabel(splitVertexCollection1Tag_, splitVertexCollection1Handle)) {
588      splitVertexColl1 = splitVertexCollection1Handle.product();
589    } else {
590 <    cout << "splitVertexCollection1 cannot be found -> using empty collection of same type." <<endl;
591 <  }
592 <
677 <  //splitVertexCollection2
590 >    edm::LogInfo("Debug") << "[PVStudy] splitVertexCollection1 cannot be found -> using empty collection of same type." <<endl;
591 >  }
592 >  // ====== splitVertexCollection2
593    static const reco::VertexCollection s_empty_splitVertexColl2;
594    const reco::VertexCollection *splitVertexColl2 = &s_empty_splitVertexColl2;
595    edm::Handle<reco::VertexCollection> splitVertexCollection2Handle;
# Line 682 | Line 597 | PVStudy::analyze(const edm::Event& iEven
597    if( iEvent.getByLabel(splitVertexCollection2Tag_, splitVertexCollection2Handle)) {
598      splitVertexColl2 = splitVertexCollection2Handle.product();
599    } else {
600 <    cout << "splitVertexCollection2 cannot be found -> using empty collection of same type." <<endl;
600 >    edm::LogInfo("Debug") << "[PVStudy] splitVertexCollection2 cannot be found -> using empty collection of same type." <<endl;
601    }
602 +
603    
604 <  if(verbose_) cout<<"End accessing the track and vertex collections"<<endl;
604 >  // ======== BeamSpot accessors
605 >  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
606 >  iEvent.getByLabel(bsSrc,recoBeamSpotHandle);
607 >  reco::BeamSpot bs = *recoBeamSpotHandle;    
608 >  const Point beamSpot = recoBeamSpotHandle.isValid() ? Point(recoBeamSpotHandle->x0(), recoBeamSpotHandle->y0(), recoBeamSpotHandle->z0()) : Point(0, 0, 0);
609    
610 <  //=======================================================
611 <  // MC simvtx accessor
612 <  //=======================================================
610 >  edm::LogInfo("Debug")<<"[PVStudy] End accessing the track, beamSpot, primary vertex collections"<<endl;
611 >  
612 >  // ========== MC simvtx accessor
613    if (!realData_) {
614      edm::Handle<SimVertexContainer> simVtxs;
615      iEvent.getByLabel( simG4_, simVtxs);
# Line 698 | Line 618 | PVStudy::analyze(const edm::Event& iEven
618      iEvent.getByLabel( simG4_, simTrks);
619    }
620  
621 <  //=======================================================
702 <  // GET PDT
703 <  //=======================================================
621 >  // ========== GET PDT
622    try{
623      iSetup.getData(pdt);
624    }catch(const Exception&){
625 <    cout << "Some problem occurred with the particle data table. This may not work !." <<endl;
625 >    edm::LogInfo("Debug") << "[PVStudy] Some problem occurred with the particle data table. This may not work !." <<endl;
626    }
627    
628 <  //=======================================================
629 <  // GET pixelVertices
630 <  //=======================================================
631 <  static const reco::VertexCollection s_empty_pixelVertexColl;
632 <  const reco::VertexCollection *pixelVertexColl = &s_empty_pixelVertexColl;
633 <  edm::Handle<reco::VertexCollection>  pixelVertexCollectionHandle;
634 <  iEvent.getByLabel(pixelVertexCollectionTag_, pixelVertexCollectionHandle);
635 <  if( iEvent.getByLabel(pixelVertexCollectionTag_, pixelVertexCollectionHandle)) {
636 <    pixelVertexColl = pixelVertexCollectionHandle.product();
637 <  } else {
638 <    cout << "pixelVertexCollection cannot be found. -> using empty collection of same type." <<endl;
628 >  // ======= Get MC information if needed
629 >  bool MC=false;  
630 >  Handle<HepMCProduct> evtMC;
631 >  if (!realData_) {
632 >    iEvent.getByLabel("generator",evtMC);
633 >    if (!evtMC.isValid()) {
634 >      MC=false;
635 >      edm::LogInfo("Debug") << "[PVStudy] no HepMCProduct found"<< endl;
636 >    } else {
637 >      edm::LogInfo("Debug") << "[PVStudy] generator HepMCProduct found"<< endl;
638 >      MC=true;
639 >    }
640    }
641  
642 <  //=======================================================
643 <  // Fill pixelVertices related histograms
644 <  //=======================================================
645 <  nrecPV_pxlpvtx_ = int (pixelVertexColl->size());
646 <  if(pixelVertexColl->size()>0 && pixelVertexColl->begin()->isValid() && !(pixelVertexColl->begin()->isFake())) {
647 <    //fillTrackHistoInPV(const reco::VertexCollection *vertexColl, int datatype, bool fillHisto, bool fillNtuple) {
648 <    fillTrackHistoInPV(pixelVertexColl, 4, false, true);
649 <    h["dzErr_pxlpvtx"]->Fill( pixelVertexColl->begin()->zError());    
650 <    // Get the dZ error of the tracks in the leading pixelVertexColl
651 <    for(reco::Vertex::trackRef_iterator t = (pixelVertexColl->begin())->tracks_begin();
652 <        t!= (pixelVertexColl->begin())->tracks_end(); t++) {
653 <      
735 <      if ( (**t).charge() < -1 || (**t).charge() > 1 ) {
736 <        //        h["trkPtPV"]->Fill(0.);
737 <      }
738 <      else
739 <        h["trkdzErr_pxlpvtx"]->Fill((**t).dzError());
740 <    }
741 <    // Fill the track->dz() in the PV difference from first pixelpvtx
742 <    for(reco::Vertex::trackRef_iterator t = (vertexColl->begin())->tracks_begin();
743 <        t!= (vertexColl->begin())->tracks_end(); t++) {
744 <      // illegal charge
745 <      if ( (**t).charge() < -1 || (**t).charge() > 1 ) {
746 <        //        h["trkPtPV"]->Fill(0.);
747 <      }
748 <      else {
749 <        if(pixelVertexColl->size()>0) {
750 <          h["trkdz_pxlpvtxdz"]->Fill((**t).dz() -  pixelVertexColl->begin()->z());
751 <          h["trkdz_pxlpvtxdz_pxlpvtxdzerr"]->Fill(fabs((**t).dz() -  pixelVertexColl->begin()->z())/pixelVertexColl->begin()->zError());
752 <          h["trkdz_pxlpvtxdz_trkdzerr"]->Fill(fabs((**t).dz() -  pixelVertexColl->begin()->z())/(**t).dzError());
753 <          h["trkdzErr_pvtx"]->Fill((**t).dzError());
754 <        }
755 <      }
756 <    }
642 >  //========================================================================
643 >  // Step 1:  Apply event cleaning for data and MC
644 >  //          WARNING: event selection cut are hard coded!!
645 >  //========================================================================
646 >  // =====Loop over the trackColl to get the fraction of HighPurity tracks
647 >  int nTracks = 0;
648 >  int nHighPurityTracks=0;
649 >  double fHighPurity=0;
650 >
651 >  for (unsigned int i=0; i<trackCollectionHandle->size(); i++, nTracks++) {
652 >    TrackRef tkref(trackCollectionHandle,i);
653 >    if(tkref->quality(reco::TrackBase::highPurity)) ++nHighPurityTracks;
654    }
655 <
656 <  //=======================================================
657 <  // Fill number of reconstructed vertices
658 <  //=======================================================
655 >  if(nTracks>0)
656 >    fHighPurity =  double(nHighPurityTracks)/double(nTracks);
657 >  if(verbose_)
658 >    cout<<"fraction of HighPurity track is "<<fHighPurity<<endl;  
659 >    
660 >  if( (fHighPurity<0.2 && nTracks>10) || vertexColl->begin()->isFake()) return;
661  
662 <  if(verbose_)  {
663 <    cout<<"PVStudy::analyze() Printing vertexCollection: "<<endl;
662 >  glob_runno_ = iEvent.id().run();
663 >  glob_evtno_ = iEvent.id().event();
664 >  glob_ls_   = iEvent.luminosityBlock();
665 >  glob_bx_  = iEvent.bunchCrossing();  
666 >  return;
667 >  
668 >  
669 >  //========================================================================
670 >  // Step 2: Fill histograms for the splitting consistency checks
671 >  //========================================================================
672 >  
673 >  // === Fill trackparameters of the input tracks to pvtx fitter
674 >  edm::LogInfo("Debug")<<"[PVStudy] Start filling track parameters of the input tracks to pvtx fitter."<<endl;
675 >  //fillTrackHisto(const reco::TrackCollection *trackColl, int datatype, const Point & bs)
676 >  // datatype: unsplittracks (0); splittracks1 (1);  splittracks2 (2);
677 >  fillTrackHisto(trackColl, 0, beamSpot);
678 >  fillTrackHisto(splitTrackColl1, 1, beamSpot);
679 >  fillTrackHisto(splitTrackColl2, 2, beamSpot);
680 >  edm::LogInfo("Debug")<<"[PVStudy] End filling track parameters of the input tracks to pvtx fitter."<<endl;
681 >  
682 >  
683 >  // ==== Fill number of reconstructed vertices
684 >  edm::LogInfo("Debug")<<"[PVStudy] Printing vertexCollection: "<<endl;
685 >  edm::LogInfo("Debug")<<"[PVStudy] Printing splitVertexCollection1: "<<endl;
686 >  edm::LogInfo("Debug")<<"[PVStudy] Printing splitVertexCollection2: "<<endl;
687 >  edm::LogInfo("Debug")<<"[PVStudy] Start filling pvtx parameters."<<endl;
688 >  if (verbose_) {
689      printRecVtxs(vertexCollectionHandle);
766    cout<<"PVStudy::analyze() Printing splitVertexCollection1: "<<endl;
690      printRecVtxs(splitVertexCollection1Handle);
768    cout<<"PVStudy::analyze() Printing splitVertexCollection2: "<<endl;
691      printRecVtxs(splitVertexCollection2Handle);
770    cout<<"Start filling pvtx parameters."<<endl;
692    }
693 <  
693 >
694    nrecPV_ = int (vertexColl->size());
695    nrecPV1_spl_ = int (splitVertexColl1->size());
696    nrecPV2_spl_ = int (splitVertexColl2->size());
697  
698 <  h["nrecPV"]->Fill(nrecPV_);
699 <  h["nrecPV1_spl"]->Fill(nrecPV1_spl_);
700 <  h["nrecPV2_spl"]->Fill(nrecPV2_spl_);
701 <  h["nrecPVDiff"]->Fill(double(nrecPV1_spl_)-double(nrecPV2_spl_));
781 <  
782 <  //=================================================================
783 <  // Fill track parameter ntuple/hist for tracks used in recoVertices
784 <  //=================================================================
785 <
786 <  //fillTrackHistoInPV(const reco::VertexCollection *vertexColl, int datatype, bool fillHisto, bool fillNtuple) {
787 <  if(vertexColl->size() > 0 && vertexColl->begin()->isValid() && !(vertexColl->begin()->isFake()))
788 <    fillTrackHistoInPV(vertexColl, 0, true, true);
698 >  h_pvtrk->Fill1d("nrecPV", nrecPV_);
699 >  h_pvtrk->Fill1d("nrecPV1_spl", nrecPV1_spl_);
700 >  h_pvtrk->Fill1d("nrecPV2_spl", nrecPV2_spl_);
701 >  h_misc->Fill1d("nrecPVDiff", double(nrecPV1_spl_)-double(nrecPV2_spl_));
702    
790  if(splitVertexColl1->size() > 0 && splitVertexColl1->begin()->isValid() && !(splitVertexColl1->begin()->isFake()))
791    fillTrackHistoInPV(splitVertexColl1, 1, false, true);
792
793  if(splitVertexColl1->size() > 0 && splitVertexColl2->begin()->isValid() && !(splitVertexColl2->begin()->isFake()))
794    fillTrackHistoInPV(splitVertexColl2, 2, false, true);
795
796
797  //=======================================================
798  // Compare offlinePrimaryVertices with pixelVertices
799  //=======================================================
800  if( (pixelVertexColl->size()>0 && pixelVertexColl->begin()->isValid() && !(pixelVertexColl->begin()->isFake()))
801      && (vertexColl->size()>0 && vertexColl->begin()->isValid() && !(vertexColl->begin()->isFake())) ) {    
802    h["nrecPV_minus_nrecPxlPV"]->Fill( double (nrecPV_ - nrecPV_pxlpvtx_));
803    // difference in reconstructed position of the leading pvtx
804    //cout<<"recx_[0] = "<< recx_[0] << "recx_pxlpvtx_[0] = "<< recx_pxlpvtx_[0]<<endl;  
805    //cout<<"recy_[0] = "<< recy_[0] << "recy_pxlpvtx_[0] = "<< recy_pxlpvtx_[0]<<endl;
806    h["recxPV_minus_recxPxlPV"]->Fill (recx_[0] - recx_pxlpvtx_[0]);
807    h["recyPV_minus_recyPxlPV"]->Fill (recy_[0] - recy_pxlpvtx_[0]);
808    h["reczPV_minus_reczPxlPV"]->Fill (recz_[0] - recz_pxlpvtx_[0]);
809  }
703    
704 <
705 <
706 <  //==========================================================
707 <  // Fill secondary/primary min separations for multi-vertices
815 <  //==========================================================
704 >  // ======= Fill track parameter ntuple/hist for tracks used in recoVertices
705 >  //fillTrackHistoInPV(const reco::VertexCollection *vertexColl, int datatype, const Point & bs) {
706 >  if(vertexColl->size() > 0 && vertexColl->begin()->isValid() && !(vertexColl->begin()->isFake()))
707 >    fillTrackHistoInPV(vertexColl, 0, beamSpot);
708    
709 +  // ======= Fill secondary/primary min separations for multi-vertices
710    if(vertexColl->size()>1 && vertexColl->begin()->isValid() && !(vertexColl->begin()->isFake()) ) {  
818
711      double min_xsep = 9999.0;
712      double min_ysep = 9999.0;
713      double min_zsep = 9999.0;    
# Line 825 | Line 717 | PVStudy::analyze(const edm::Event& iEven
717      double min_ntrksep = 9999.0;
718      double min_sumpt2sep = 9999999.0;
719      
720 <    if(verbose_) cout<<"leading pvtx z = "<< vertexColl->begin()->z() <<endl;
720 >    edm::LogInfo("Debug")<<"[PVStudy] leading pvtx z = "<< vertexColl->begin()->z() <<endl;
721  
722      // Looping through the secondary vertices to find the mininum separation to the primary
723      for(reco::VertexCollection::const_iterator v=vertexColl->begin() + 1 ;
# Line 860 | Line 752 | PVStudy::analyze(const edm::Event& iEven
752            min_sumpt2sep = fabs(sumPtSquared(*v) - sumPtSquared(*(vertexColl->begin())));
753        }
754      }
755 <    h["min_xsep"]->Fill(min_xsep);
756 <    h["min_ysep"]->Fill(min_ysep);
757 <    h["min_zsep"]->Fill(min_zsep);
758 <    h["min_xsep_sign"]->Fill(min_xsep_sign);
759 <    h["min_ysep_sign"]->Fill(min_ysep_sign);
760 <    h["min_zsep_sign"]->Fill(min_zsep_sign);
761 <    h["min_ntrksep"]->Fill(min_ntrksep);
762 <    h["min_sumpt2sep"]->Fill(min_sumpt2sep);
755 >    h_misc->Fill1d("min_xsep", min_xsep);
756 >    h_misc->Fill1d("min_ysep", min_ysep);
757 >    h_misc->Fill1d("min_zsep", min_zsep);
758 >    h_misc->Fill1d("min_xsep_sign", min_xsep_sign);
759 >    h_misc->Fill1d("min_ysep_sign", min_ysep_sign);
760 >    h_misc->Fill1d("min_zsep_sign", min_zsep_sign);
761 >    h_misc->Fill1d("min_ntrksep", min_ntrksep);
762 >    h_misc->Fill1d("min_sumpt2sep", min_sumpt2sep);
763  
764      min_zsep_ = min_zsep;
765      min_ntrksep_ = min_ntrksep;
766      min_sumpt2sep_ = min_sumpt2sep;
875
876
767    } // End of  if(vertexColl->size()>1) {
768    
769 <  if(verbose_)
880 <    cout<<"End filling pvtx parameters."<<endl;
881 <  
882 <  //=======================================================
883 <  //           PrimaryVertex Matching
884 <  // 1. In z  |z1-z2|< zsigncut * max(sigmaz1, sigmaz2)
885 <  // 2. |(nTrkPV1 - nTrkPV2)/(nTrkPV1+nTrkPV2)|<ntrkdiffcut_
886 <  // Assume the first match is the primary vertex,
887 <  // since vertexColl are sorted in decreasing order of sum(pT)
888 <  //=======================================================
769 >  edm::LogInfo("Debug")<<"[PVStudy] End filling pvtx parameters."<<endl;
770  
771 <  if(verbose_)   cout<<"PVStudy::analyze(): matching pvtxs "<<endl;
771 >  //========================================================================
772 >  // Step 3:  PrimaryVertex Matching
773 >  //   1. In z  |z1-z2|< zsigncut * max(sigmaz1, sigmaz2)
774 >  //   2. |(nTrkPV1 - nTrkPV2)/(nTrkPV1+nTrkPV2)|<ntrkdiffcut_
775 >  //   3. The first match is the primary vertex, which has largest sum(pT^2)
776 >  //========================================================================
777 >  
778 >  edm::LogInfo("Debug")<<"[PVStudy] matching pvtxs "<<endl;
779    reco::VertexCollection s_empty_matchedVertexColl1;
780    reco::VertexCollection *matchedVertexColl1 = &s_empty_matchedVertexColl1;
781    matchedVertexColl1->reserve(splitVertexColl1->size());
# Line 906 | Line 794 | PVStudy::analyze(const edm::Event& iEven
794        if (ivtx!=0 || jvtx!=0) { stopmatching = true; break; }
795        reco::VertexRef recvtx2(splitVertexCollection2Handle, jvtx);
796        if( !(recvtx2->isValid()) || recvtx2->isFake()) break;
797 <      if(verbose_) {
798 <        cout<<"Matching splitVertexColl1: #  "<< ivtx<< " and splitVertexColl1: # "<<jvtx<<endl;
799 <        cout<<"recvtx1->z() = " << recvtx1->z() << "+/- "<< recvtx1->zError() << "." << endl;
800 <        cout<<"recvtx2->z() = " << recvtx2->z() << "+/- "<< recvtx2->zError() << "." << endl;
801 <      }
797 >      edm::LogInfo("Debug")<<"[PVStudy] Matching splitVertexColl1: #  "<< ivtx<< " and splitVertexColl1: # "<<jvtx<<endl;
798 >      edm::LogInfo("Debug")<<"[PVStudy] recvtx1->z() = " << recvtx1->z() << "+/- "<< recvtx1->zError() << "." << endl;
799 >      edm::LogInfo("Debug")<<"[PVStudy] recvtx2->z() = " << recvtx2->z() << "+/- "<< recvtx2->zError() << "." << endl;
800 >      
801 >      double twovtxsig = (recvtx1->z()-recvtx2->z())/max(recvtx1->zError(), recvtx2->zError());
802 >      h_misc->Fill1d("twovtxzsign", twovtxsig);
803        if(matchVertex(recvtx1, recvtx2, zsigncut_)) {
804 <        if(verbose_) {
805 <          cout<<"The two splitted vertices match in Z. "<<endl;
917 <        }
804 >        edm::LogInfo("Debug")<<"[PVStudy] The two splitted vertices match in Z. "<<endl;
805 >
806          int nTrkPV1 = recvtx1->tracksSize();
807          int nTrkPV2 = recvtx2->tracksSize();    
808          double ntrkreldiff = double(nTrkPV1-nTrkPV2)/double(nTrkPV1+nTrkPV2);
809 <        h["nTrkPVDiff"]->Fill(nTrkPV1-nTrkPV2);
810 <        h["nTrkPVRelDiff"]->Fill(ntrkreldiff);
809 >        h_misc->Fill1d("nTrkPVDiff", nTrkPV1-nTrkPV2);
810 >        h_misc->Fill1d("nTrkPVRelDiff", ntrkreldiff);
811          if(fabs(ntrkreldiff)<ntrkdiffcut_) {    
812 <          if(verbose_) {
813 <            cout<<"(nTrkPV1-nTrkPV2)/(nTrkPV1+nTrkPV2) = " << ntrkreldiff<<endl;
926 <          }
812 >          edm::LogInfo("Debug")<<"[PVStudy] (nTrkPV1-nTrkPV2)/(nTrkPV1+nTrkPV2) = " << ntrkreldiff<<endl;
813 >
814            matchedVertexColl1->push_back(*recvtx1);
815            matchedVertexColl2->push_back(*recvtx2);
816            stopmatching = true; // stop the matching when the first match is found!
817            break;
818          }
819          else
820 <          cout<<"WARNING: (nTrkPV1-nTrkPV2)/(nTrkPV1+nTrkPV2) = " << ntrkreldiff<<", exceeding cut "<<ntrkdiffcut_<<endl;
820 >          edm::LogInfo("Debug")<<"WARNING: (nTrkPV1-nTrkPV2)/(nTrkPV1+nTrkPV2) = " << ntrkreldiff<<", exceeding cut "<<ntrkdiffcut_<<endl;
821        }
822        else {
823 <        cout<<"WARNING: The two reconstructed vertices do not match in z: "<<endl;
824 <        cout<<"recvtx1->z() = " << recvtx1->z() << "+/- "<< recvtx1->zError() << "." << endl;
825 <        cout<<"recvtx2->z() = " << recvtx2->z() << "+/- "<< recvtx2->zError() << "." << endl;  
823 >        edm::LogInfo("Debug")<<"WARNING: The two reconstructed vertices do not match in z: "<<endl;
824 >        edm::LogInfo("Debug")<<"recvtx1->z() = " << recvtx1->z() << "+/- "<< recvtx1->zError() << "." << endl;
825 >        edm::LogInfo("Debug")<<"recvtx2->z() = " << recvtx2->z() << "+/- "<< recvtx2->zError() << "." << endl;  
826        }
827      }
828    }
829 <  if(verbose_)     cout<<"PVStudy::analyze(): End matching pvtxs"<<endl;
830 <  
831 <  //=======================================================
832 <  //  Analyze matchedVertexColls
833 <  //=======================================================
834 <  if(verbose_) {
835 <    cout<<"Begin analyzing the matchedVertexColl with size = "<< matchedVertexColl1->size()<< endl;
836 <  }    
829 >  edm::LogInfo("Debug")<<"[PVStudy] End matching pvtxs"<<endl;
830 >
831 >  //========================================================================
832 >  // Step 4: Analyze matchedVertexColls
833 >  //========================================================================
834 >  edm::LogInfo("Debug")<<"[PVStudy] Begin analyzing the matchedVertexColl with size = "<< matchedVertexColl1->size()<< endl;
835 >  
836 >  // ==== If it is MC, analyze the res/pull of the unsplit vertexColl first
837 >  if(MC){
838 >    // make a list of primary vertices:
839 >    std::vector<simPrimaryVertex> simpv;
840 >    simpv=getSimPVs(evtMC,"");
841 >    //     simpv=getSimPVs(evtMC, simVtxs, simTrks);
842 >    h_gen->Fill1d("nsimPV", simpv.size());
843 >    nsimPV_ = simpv.size();
844 >    int isimpv = 0;
845 >    for(std::vector<simPrimaryVertex>::iterator vsim=simpv.begin();
846 >        vsim!=simpv.end(); vsim++, isimpv++){
847 >      nsimTrkPV_[isimpv]  =vsim->nGenTrk;
848 >      simx_[isimpv] = vsim->x;
849 >      simy_[isimpv] = vsim->y;
850 >      simz_[isimpv] = vsim->y;
851 >      simptsq_[isimpv] = vsim->ptsq;
852 >      //fillMCHisto((std::vector<simPrimaryVertex>::iterator vsim, int isimpv, const reco::VertexCollection *vtxColl, int datatype) {
853 >      fillMCHisto(vsim, isimpv, vertexColl, 3);
854 >    }
855 >  }
856    
857    // Compare the reconstructed vertex position and calculate resolution/pulls
858    if(matchedVertexColl1->size() != 0 && matchedVertexColl2->size() != 0) {  
859 <    //fillPvtxHisto(const reco::VertexCollection *vertexColl, int datatype, bool fillHisto, bool fillNtuple)
860 <    fillTrackHistoInPV(matchedVertexColl1, 1, true, false);
861 <    fillTrackHistoInPV(matchedVertexColl2, 2, true, false);
859 >    // ==== Analyze the splitted vtx using MC method
860 >    if(MC){
861 >      // make a list of primary vertices:
862 >      std::vector<simPrimaryVertex> simpv;
863 >      simpv=getSimPVs(evtMC,"");
864 >      //     simpv=getSimPVs(evtMC, simVtxs, simTrks);
865 >      int isimpv = 0;
866 >      for(std::vector<simPrimaryVertex>::iterator vsim=simpv.begin();
867 >          vsim!=simpv.end(); vsim++, isimpv++){
868 >        //fillMCHisto((std::vector<simPrimaryVertex>::iterator vsim, int isimpv, const reco::VertexCollection *vtxColl, int datatype) {
869 >        fillMCHisto(vsim, isimpv, matchedVertexColl1, 1);
870 >        fillMCHisto(vsim, isimpv, matchedVertexColl2, 2);
871 >      }
872 >    }
873 >
874 >    // ==== Analyze res/pull two-vertex method
875 >    //fillPvtxHisto(const reco::VertexCollection *vertexColl, int datatype)
876 >    fillTrackHistoInPV(matchedVertexColl1, 1, beamSpot);
877 >    fillTrackHistoInPV(matchedVertexColl2, 2, beamSpot);
878  
879      reco::VertexCollection::const_iterator v1;
880      reco::VertexCollection::const_iterator v2;
881 +
882      nrecPV_twovtx_ = 0;
883      for(v1 = matchedVertexColl1->begin(), v2 = matchedVertexColl2->begin();
884          v1!=matchedVertexColl1->end(), v2 != matchedVertexColl2->end();
885 <        ++v1, ++v2) {
885 >        ++v1, ++v2) {
886 >      h_misc->Fill1d("ndofPVDiff", v1->ndof() - v2->ndof());
887 >      h_misc->Fill1d("ndofPVRelDiff", (v1->ndof()-v2->ndof())/(v1->ndof()+v2->ndof()));
888        fres_[0] = (v1->x()-v2->x())/sqrt(2.0);
889        fres_[1] = (v1->y()-v2->y())/sqrt(2.0);
890        fres_[2] = (v1->z()-v2->z())/sqrt(2.0);
# Line 968 | Line 893 | PVStudy::analyze(const edm::Event& iEven
893        ferror_[2] = sqrt(pow(v1->zError(),2)+pow(v2->zError(),2))/sqrt(2);
894        fntrk_ =  (v1->tracksSize()+v2->tracksSize())/2;
895        
896 <      h["deltax"]->Fill( fres_[0] );
897 <      h["deltay"]->Fill( fres_[1] );
898 <      h["deltaz"]->Fill( fres_[2] );
899 <      h["pullx"]->Fill( fres_[0]/ferror_[0]);
900 <      h["pully"]->Fill( fres_[1]/ferror_[1]);
901 <      h["pullz"]->Fill( fres_[2]/ferror_[2]);
902 <      h["errPVx"]->Fill( ferror_[0] );
903 <      h["errPVy"]->Fill( ferror_[1] );
904 <      h["errPVz"]->Fill( ferror_[2] );
896 >      h_summary->Fill1d("deltax", fres_[0] );
897 >      h_summary->Fill1d("deltay", fres_[1] );
898 >      h_summary->Fill1d("deltaz", fres_[2] );
899 >      h_summary->Fill1d("pullx", fres_[0]/ferror_[0]);
900 >      h_summary->Fill1d("pully", fres_[1]/ferror_[1]);
901 >      h_summary->Fill1d("pullz", fres_[2]/ferror_[2]);
902 >      h_summary->Fill1d("errPVx", ferror_[0] );
903 >      h_summary->Fill1d("errPVy", ferror_[1] );
904 >      h_summary->Fill1d("errPVz", ferror_[2] );
905        pvinfo.push_back(PVStudy::PVInfo(res(fres_[0], fres_[1], fres_[2]),
906                                         error(ferror_[0], ferror_[1], ferror_[2]),
907                                         fntrk_));
# Line 984 | Line 909 | PVStudy::analyze(const edm::Event& iEven
909        fillHisto(res(fres_[0], fres_[1], fres_[2]),
910                  error(ferror_[0], ferror_[1], ferror_[2]),
911                  fntrk_,0);  
912 +
913        // Fill the ntuple variables
988      nTrkPV1_spl_twovtx_[nrecPV_twovtx_] = v1->tracksSize();
989      nTrkPV2_spl_twovtx_[nrecPV_twovtx_] = v2->tracksSize();
990      sumptsq1_spl_twovtx_[nrecPV_twovtx_] = sumPtSquared(*v1);
991      sumptsq2_spl_twovtx_[nrecPV_twovtx_] = sumPtSquared(*v2);
914        nTrkPV_twovtx_[nrecPV_twovtx_] = fntrk_;
915        deltax_twovtx_[nrecPV_twovtx_] = fres_[0];
916        deltay_twovtx_[nrecPV_twovtx_] = fres_[1];
# Line 999 | Line 921 | PVStudy::analyze(const edm::Event& iEven
921        pullx_twovtx_[nrecPV_twovtx_] = fres_[0]/ferror_[0];
922        pully_twovtx_[nrecPV_twovtx_] = fres_[1]/ferror_[1];
923        pullz_twovtx_[nrecPV_twovtx_] = fres_[2]/ferror_[2];    
924 +
925 +
926 +      //SplittedVertex
927 +      
928 +      nTrkPV1_spl_twovtx_[nrecPV_twovtx_] = v1->tracksSize();
929 +      ndofPV1_spl_twovtx_[nrecPV_twovtx_] = v1->ndof();
930 +      normchi2PV1_spl_twovtx_[nrecPV_twovtx_] = v1->normalizedChi2();
931 +      avgPtPV1_spl_twovtx_[nrecPV_twovtx_] = avgPtRecVtx(*v1);
932 +      errx1_spl_twovtx_[nrecPV_twovtx_] = v1->xError();
933 +      erry1_spl_twovtx_[nrecPV_twovtx_] = v1->yError();
934 +      errz1_spl_twovtx_[nrecPV_twovtx_] = v1->zError();
935 +  
936 +      nTrkPV2_spl_twovtx_[nrecPV_twovtx_] = v2->tracksSize();
937 +      ndofPV2_spl_twovtx_[nrecPV_twovtx_] = v2->ndof();
938 +      normchi2PV2_spl_twovtx_[nrecPV_twovtx_] = v2->normalizedChi2();
939 +      avgPtPV2_spl_twovtx_[nrecPV_twovtx_] = avgPtRecVtx(*v2);
940 +      errx2_spl_twovtx_[nrecPV_twovtx_] = v2->xError();
941 +      erry2_spl_twovtx_[nrecPV_twovtx_] = v2->yError();
942 +      errz2_spl_twovtx_[nrecPV_twovtx_] = v2->zError();
943 +  
944        nrecPV_twovtx_++;
945 +
946 +
947 +      
948 +      // Print some information of the two tracks events
949 +      if(verbose_ && fntrk_ < 4) {
950 +        cout<<"Printing matchedVertexColl1 for low ntrack bins"<<endl;
951 +        printRecVtx(*v1);
952 +        cout<<"Printing matchedVertexColl1 for low ntrack bins"<<endl;
953 +        printRecVtx(*v2);
954 +      }
955      } // End of analyzing res/pull
956    } // End of  if(matchedVertexColl1->size() == 1 && matchedVertexColl2->size() == 1 ) {
957    else
958 <    cout<<"WARNING: Cannot find matching pvtxs"<<endl;
958 >    edm::LogInfo("Debug")<<"[PVStudy] WARNING: Cannot find matching pvtxs"<<endl;
959    
960 <  if(verbose_)     cout<<"End analyzing the matchedVertexColl"<<endl;
960 >  edm::LogInfo("Debug")<<"[PVStudy] End analyzing the matchedVertexColl"<<endl;
961  
962 <  //=======================================================
963 <  // Fill simulated vertices
964 <  //=======================================================
965 <  if (!realData_) {
1014 <    bool MC=false;
1015 <    Handle<HepMCProduct> evtMC;
1016 <    iEvent.getByLabel("generator",evtMC);
1017 <    if (!evtMC.isValid()) {
1018 <      MC=false;
1019 <      if(verbose_){
1020 <        cout << "no HepMCProduct found"<< endl;
1021 <      }
1022 <    } else {
1023 <      if(verbose_){
1024 <        cout << "generator HepMCProduct found"<< endl;
1025 <      }
1026 <      MC=true;
1027 <    }
1028 <    
1029 <    if(MC){
1030 <      // make a list of primary vertices:
1031 <      std::vector<simPrimaryVertex> simpv;
1032 <      simpv=getSimPVs(evtMC,"");
1033 <      //     simpv=getSimPVs(evtMC, simVtxs, simTrks);
1034 <      h["nsimPV"]->Fill(simpv.size());
1035 <      nsimPV_ = simpv.size();
1036 <
1037 <      int isimpv = 0;
1038 <      for(std::vector<simPrimaryVertex>::iterator vsim=simpv.begin();
1039 <          vsim!=simpv.end(); vsim++, isimpv++){
1040 <        nsimTrkPV_[isimpv]  =vsim->nGenTrk;
1041 <        simx_[isimpv] = vsim->x;
1042 <        simy_[isimpv] = vsim->y;
1043 <        simz_[isimpv] = vsim->y;
1044 <        simptsq_[isimpv] = vsim->ptsq;
1045 <        
1046 <        //fillMCHisto((std::vector<simPrimaryVertex>::iterator vsim, int isimpv, const reco::VertexCollection *vtxColl, int datatype) {
1047 <        fillMCHisto(vsim, isimpv, splitVertexColl1, 1);
1048 <        fillMCHisto(vsim, isimpv, splitVertexColl2, 2);
1049 <        fillMCHisto(vsim, isimpv, vertexColl, 3);
1050 <      }
1051 <    } // End of  for(std::vector<simPrimaryVertex>::iterator vsim=simpv.begin()
1052 <  } // End of   if (!realData_) {
1053 <
1054 <  // Finally fill the ftree_
962 >
963 >  //========================================================================
964 >  // Step 5: Fill ntuple if saventuple_ is on
965 >  //========================================================================
966    if(saventuple_) {
967      ftree_->Fill();
968      pvtxtree_->Fill();
969    }
970 +  
971   }
972  
973 +
974 +  
975   // ------------ method called once each job just before starting event loop  ------------
976   void
977   PVStudy::beginJob()
# Line 1067 | Line 981 | PVStudy::beginJob()
981   // ------------ method called once each job just after ending the event loop  ------------
982   void
983   PVStudy::endJob() {
984 <  if (verbose_) cout << "Analyzing PV info" << endl;
984 >  edm::LogInfo("Analysis") << "[endJob] Analyzing PV info" << endl;
985    // Looping through the datamodes available
986    for (vector<int>::const_iterator it= datamode.begin(); it != datamode.end() ; ++it) {  
987      string suffix;
988 <    if(verbose_)  cout<<"datamode = "<< *it<<endl;
988 >    edm::LogInfo("Analysis")<<"[endJob] datamode = "<< *it<<endl;
989      switch(*it) {
990      case 0: suffix = "";
991        break;
# Line 1082 | Line 996 | PVStudy::endJob() {
996      case 3: suffix = "_mct";
997        break;
998      }
999 +    suffix += "_nTrk";
1000      if(analyze_) {
1001        for (int ntrk=nTrkMin_;ntrk<=nTrkMax_;++ntrk) {
1002 +        edm::LogInfo("Analysis") << "[endJob] ntrk = " << ntrk << endl;
1003          PVStudy::PVAnaInfo ipv = GetPVAnaInfo(ntrk,*it);
1004 <        if ( ipv.res_.x() > 0 ) h2["resx"+suffix+"_nTrk"]->Fill(ntrk,ipv.res_.x(), 1.);
1005 <        if ( ipv.res_.y() > 0 ) h2["resy"+suffix+"_nTrk"]->Fill(ntrk,ipv.res_.y(), 1.);
1006 <        if ( ipv.res_.z() > 0 ) h2["resz"+suffix+"_nTrk"]->Fill(ntrk,ipv.res_.z(), 1.);
1007 <        if ( ipv.pull_.x() > 0 ) h2["pullx"+suffix+"_nTrk"]->Fill(ntrk,ipv.pull_.x(), 1.);
1008 <        if ( ipv.pull_.y() > 0 ) h2["pully"+suffix+"_nTrk"]->Fill(ntrk,ipv.pull_.y(), 1.);
1009 <        if ( ipv.pull_.z() > 0 ) h2["pullz"+suffix+"_nTrk"]->Fill(ntrk,ipv.pull_.z(), 1.);
1004 >        if ( ipv.res_.x() > 0 ) h_ana->Fill2d("resx"+suffix, ntrk,ipv.res_.x());
1005 >        if ( ipv.res_.y() > 0 ) h_ana->Fill2d("resy"+suffix, ntrk,ipv.res_.y());
1006 >        if ( ipv.res_.z() > 0 ) h_ana->Fill2d("resz"+suffix, ntrk,ipv.res_.z());
1007 >        if ( ipv.pull_.x() > 0 ) h_ana->Fill2d("pullx"+suffix, ntrk,ipv.pull_.x());
1008 >        if ( ipv.pull_.y() > 0 ) h_ana->Fill2d("pully"+suffix, ntrk,ipv.pull_.y());
1009 >        if ( ipv.pull_.z() > 0 ) h_ana->Fill2d("pullz"+suffix, ntrk,ipv.pull_.z());
1010        }
1011 <    }
1011 >    }
1012      suffix.clear();
1013    }
1014    if(saventuple_) {
# Line 1101 | Line 1017 | PVStudy::endJob() {
1017      pvtxtree_->Write();
1018      file_->Close();
1019    }
1020 < }
1105 <
1020 >  
1021  
1022 + }
1023  
1024   // Match a recovertex with a simvertex
1025   // ? Should the cut be parameter dependent?
# Line 1111 | Line 1027 | PVStudy::endJob() {
1027   bool PVStudy::matchVertex(const PVStudy::simPrimaryVertex & vsim,
1028                            const reco::Vertex & vrec)
1029   {
1030 <  return (fabs(vsim.z-vrec.z())<0.0500); // =500um
1030 >  if(vrec.isFake() || !vrec.isValid()) return false;
1031 >  else
1032 >    return true;
1033 >    //return (fabs(vsim.z-vrec.z())<0.0500); // =500um // remove this hard cut
1034   }
1035  
1036   // Match two reconstructed vertices
# Line 1120 | Line 1039 | bool PVStudy::matchVertex( const reco::V
1039                             int zsigncut)
1040   {
1041    double cut = zsigncut*max(vrec1->zError(), vrec2->zError());
1042 <  if(verbose_)
1124 <    cout<<"The matching criteria in z is "<<cut<<endl;
1042 >  edm::LogInfo("Debug")<<"[matchVertex] The matching criteria in z is "<<cut<<endl;
1043    return (fabs(vrec1->z()-vrec2->z())<cut);
1044   }
1045  
1046  
1047   bool PVStudy::isResonance(const HepMC::GenParticle * p){
1048    double ctau=(pdt->particle( abs(p->pdg_id()) ))->lifetime();
1049 <  if(verbose_) cout << "isResonance   " << p->pdg_id() << " " << ctau << endl;
1049 >  edm::LogInfo("Debug") << "[isResonance] isResonance   " << p->pdg_id() << " " << ctau << endl;
1050    return  ctau >0 && ctau <1e-6;
1051   }
1052  
# Line 1179 | Line 1097 | void PVStudy::printRecVtxs(const Handle<
1097    }
1098   }
1099  
1100 + void PVStudy::printRecVtx(const reco::Vertex & v){
1101 +
1102 +  cout << "#trk " << std::setw(3) << v.tracksSize()
1103 +         << " chi2 " << std::setw(4) << v.chi2()
1104 +         << " ndof " << std::setw(3) << v.ndof() << endl
1105 +         << " x "  << std::setw(8) <<std::fixed << std::setprecision(4) << v.x()
1106 +         << " dx " << std::setw(8) << v.xError()<< endl
1107 +         << " y "  << std::setw(8) << v.y()
1108 +         << " dy " << std::setw(8) << v.yError()<< endl
1109 +         << " z "  << std::setw(8) << v.z()
1110 +         << " dz " << std::setw(8) << v.zError()
1111 +         << endl;
1112 + }
1113 +
1114   void PVStudy::printSimTrks(const Handle<SimTrackContainer> simTrks){
1115    cout <<  " simTrks   type, (momentum), vertIndex, genpartIndex"  << endl;
1116    int i=1;
# Line 1200 | Line 1132 | void PVStudy::printSimTrks(const Handle<
1132   void PVStudy::fillHisto(res r, error er, int ntk, int datamode){
1133    stringstream ss;
1134    ss << ntk;
1135 <  string suffix = ss.str();
1136 <  if(datamode == 0 )  suffix = "_" + suffix;
1137 <  if(datamode == 1 )  suffix = "_spl1_mct_" + suffix;
1138 <  if(datamode == 2 )  suffix = "_spl2_mct_" + suffix;
1139 <  if(datamode == 3 )  suffix = "_mct_" + suffix;
1135 >  string suffix;
1136 >  if(datamode == 0 )  suffix = "_" + ss.str();
1137 >  if(datamode == 1 )  suffix = "_spl1_mct_" + ss.str();
1138 >  if(datamode == 2 )  suffix = "_spl2_mct_" + ss.str();
1139 >  if(datamode == 3 )  suffix = "_mct_" + ss.str();
1140    
1141    if (ntk < nTrkMin_ || ntk > nTrkMax_ ) return;
1142    // Fill histograms of res and pull of ntk
1143 <  h["deltax"+suffix]->Fill(r.x());
1144 <  h["deltay"+suffix]->Fill(r.y());
1145 <  h["deltaz"+suffix]->Fill(r.z());
1146 <  h["pullx"+suffix]->Fill(r.x()/er.x());
1147 <  h["pully"+suffix]->Fill(r.y()/er.y());
1148 <  h["pullz"+suffix]->Fill(r.z()/er.z());  
1149 <  h["errPVx"+suffix]->Fill(er.x());
1150 <  h["errPVy"+suffix]->Fill(er.y());
1151 <  h["errPVz"+suffix]->Fill(er.z());
1143 >  h_others->Fill1d("deltax"+suffix, r.x());
1144 >  h_others->Fill1d("deltay"+suffix, r.y());
1145 >  h_others->Fill1d("deltaz"+suffix, r.z());
1146 >  h_others->Fill1d("pullx"+suffix, r.x()/er.x());
1147 >  h_others->Fill1d("pully"+suffix, r.y()/er.y());
1148 >  h_others->Fill1d("pullz"+suffix, r.z()/er.z());  
1149 >  h_others->Fill1d("errPVx"+suffix, er.x());
1150 >  h_others->Fill1d("errPVy"+suffix, er.y());
1151 >  h_others->Fill1d("errPVz"+suffix, er.z());
1152   }
1153  
1154 +
1155   PVStudy::PVAnaInfo PVStudy::GetPVAnaInfo(int ntk, int datamode) {
1156    map<int,double> data;
1157    data.clear();
# Line 1236 | Line 1169 | PVStudy::PVAnaInfo PVStudy::GetPVAnaInfo
1169      for ( int i = 0; i < 6; ++i) {
1170        switch (i) {
1171        case 0:
1172 <        fit(h["deltax"+suffix], fpar);
1172 >        if (!h_others->ReadHisto1D("deltax"+suffix)) break;
1173 >        fit(h_others->ReadHisto1D("deltax"+suffix), fpar);
1174          data[i] = fpar[0]*cm2um;
1175          break;
1176        case 1:
1177 <        fit(h["deltay"+suffix], fpar);
1177 >        if (!h_others->ReadHisto1D("deltay"+suffix)) break;
1178 >        fit(h_others->ReadHisto1D("deltay"+suffix), fpar);
1179          data[i] = fpar[0]*cm2um;
1180          break;
1181        case 2:
1182 <        fit(h["deltaz"+suffix], fpar);
1182 >        if (!h_others->ReadHisto1D("deltaz"+suffix)) break;
1183 >        fit(h_others->ReadHisto1D("deltaz"+suffix), fpar);
1184          data[i] = fpar[0]*cm2um;
1185          break;
1186        case 3:
1187 <        fit(h["pullx"+suffix], fpar);
1187 >        if (!h_others->ReadHisto1D("pullx"+suffix)) break;
1188 >        fit(h_others->ReadHisto1D("pullx"+suffix), fpar);
1189          data[i] = fpar[0];
1190          break;
1191        case 4:
1192 <        fit(h["pully"+suffix], fpar);
1192 >        if (!h_others->ReadHisto1D("pully"+suffix)) break;
1193 >        fit(h_others->ReadHisto1D("pully"+suffix), fpar);
1194          data[i] = fpar[0];
1195          break;
1196        case 5:
1197 <        fit(h["pullz"+suffix], fpar);
1197 >        if (!h_others->ReadHisto1D("pullz"+suffix)) break;
1198 >        fit(h_others->ReadHisto1D("pullz"+suffix), fpar);
1199          data[i] = fpar[0];
1200          break;
1201        }
1202 <      if (verbose_ && data[i] > 0) cout << "data[" << i << "] = " << data[i] << (i<3?" micro m":" ") << endl;
1202 >      if (data[i] > 0) edm::LogInfo("Analysis") << "[Analysis] data[" << i << "] = " << data[i] << (i<3?" micro m":" ") << endl;
1203      }
1204    }
1205    else
# Line 1275 | Line 1214 | PVStudy::PVAnaInfo PVStudy::GetPVAnaInfo
1214                              ntk);
1215   }
1216  
1217 < void PVStudy::fit(TH1 *&hdist, double fitPars[]){
1217 >
1218 > void PVStudy::fit(TH1 *hdist, double fitPars[]){
1219    TAxis *axis0 = hdist->GetXaxis();
1220    int nbin = axis0->GetLast();
1221    double nOF = hdist->GetBinContent(nbin+1);
1222    double nUF = hdist->GetBinContent(0);
1223    //   double fitRange = axis0->GetBinUpEdge(nbin);
1224 <  double fitRange = axis0->GetXmax();
1224 >  // double fitRange = axis0->GetXmax();
1225 >  double fitRange = 2*hdist->GetRMS();
1226    double sigMax[2] = {0.,0.};
1227  
1228 <  if ( verbose_ ){
1229 <    cout << "Last bin = " << nbin;
1230 <    cout << "; hdist: Overflow Entries = " << nOF;
1231 <    cout << "; Underflow Entries = " << nUF;
1232 <    cout << "; hdist->GetEntries() = " << hdist->GetEntries();
1233 <    cout << "; fitting range = " << -fitRange << " to " << fitRange << endl;
1293 <  }
1228 >  edm::LogInfo("Analysis") << "[Fit] Last bin = " << nbin
1229 >                           << "; hdist: Overflow Entries = " << nOF
1230 >                           << "; Underflow Entries = " << nUF
1231 >                           << "; hdist->GetEntries() = " << hdist->GetEntries()
1232 >                           << "; fitting range = " << -fitRange << " to " << fitRange << endl;
1233 >
1234    if (hdist->GetEntries() - nOF - nUF >= 10) { // FIXME: for reasonable Gaussian fit
1235      for (int bi = 0; bi < nbin; bi++) {
1236        if ( (axis0->GetBinLowEdge(bi) < 0) && (hdist->GetBinContent(bi) > 0) ) {
# Line 1302 | Line 1242 | void PVStudy::fit(TH1 *&hdist, double fi
1242          if ( abs(sigMax[0]) > abs(sigMax[1]) ) sigMax[1] = abs(sigMax[0]);
1243        }
1244      }
1245 <    if (verbose_) cout << "Fit sigMax = " << sqrt(2.)*sigMax[1] << endl;
1245 >    //edm::LogInfo("Analysis") << "[Fit] Fit sigMax = " << sqrt(2.)*sigMax[1] << endl;
1246  
1247      TF1 *fgaus = new TF1("fgaus","gaus",-fitRange, fitRange);
1248      fgaus->SetParameter(1, 0.);
1249 <    fgaus->SetParLimits(1, -fitRange/40., fitRange/40.);
1249 >    fgaus->SetParLimits(1, -fitRange/10., fitRange/10.);
1250      fgaus->SetParLimits(2, 0., sqrt(2.)*sigMax[1]);
1251      fgaus->SetLineColor(4);
1252 <    hdist->Fit(fgaus,"Q");
1252 >    hdist->Fit(fgaus,"QLRM");
1253      gPad->Update();
1254      TPaveStats *s = (TPaveStats*) hdist->GetListOfFunctions()->FindObject("stats");
1255      s->SetOptStat(1111111);
1256      s->SetOptFit(0111);
1257      gPad->Update();
1258 <    if (verbose_) cout << "got function" << endl;
1258 >    //edm::LogInfo("Analysis") << "[Fit] got function" << endl;
1259      fitPars[0] = ((fgaus->GetParameter(2))?fgaus->GetParameter(2):-999);
1260    }
1261    else
1262      fitPars[0] = -999;
1263   }
1264  
1265 < void PVStudy::fillTrackHisto(const reco::TrackCollection *trackColl, int datatype) {
1265 >
1266 > void PVStudy::fillTrackHisto(const reco::TrackCollection *trackColl, int datatype, const Point & bs) {
1267    string suffix;
1268    suffix = ""; // for unsplit tracks
1269    if(datatype == 1) suffix = "1_spl"; // for splittracks 1
1270    if(datatype == 2) suffix = "2_spl"; // for splittracks 2
1271    
1272 <  h["nTrk"+suffix]->Fill(trackColl->size());
1272 >  h_pvtrk->Fill1d("nTrk"+suffix, trackColl->size());
1273    for(reco::TrackCollection::const_iterator itTrack = trackColl->begin();
1274        itTrack != trackColl->end();                      
1275        ++itTrack) {
1276 <    h["trkPt"+suffix]->Fill(itTrack->pt());
1277 <    h["trkDxy"+suffix]->Fill(itTrack->dxy());
1278 <    h["trkDz"+suffix]->Fill(itTrack->dz());
1279 <    h["trkEta"+suffix]->Fill(itTrack->eta());
1280 <    h["trkPhi"+suffix]->Fill(itTrack->phi());
1276 >    h_pvtrk->Fill1d("trkPt"+suffix, itTrack->pt());
1277 >    h_pvtrk->Fill1d("trkDxy"+suffix, itTrack->dxy());
1278 >    h_pvtrk->Fill1d("trkDxyCorr"+suffix, itTrack->dxy(bs));
1279 >    h_pvtrk->Fill1d("trkDz"+suffix, itTrack->dz());
1280 >    h_pvtrk->Fill1d("trkEta"+suffix, itTrack->eta());
1281 >    h_pvtrk->Fill1d("trkPhi"+suffix, itTrack->phi());
1282    }
1283   }
1284  
1285 < void PVStudy::fillTrackHistoInPV(const reco::VertexCollection *vertexColl, int datatype, bool fillHisto, bool fillNtuple) {
1285 > void PVStudy::fillTrackHistoInPV(const reco::VertexCollection *vertexColl, int datatype, const Point & bs) {
1286    string suffix;
1287    suffix = ""; // for unsplit tracks
1288    if(datatype == 1) suffix = "1_spl"; // for splittracks 1
# Line 1348 | Line 1290 | void PVStudy::fillTrackHistoInPV(const r
1290    int ivtx = 0;
1291    for(reco::VertexCollection::const_iterator v=vertexColl->begin();
1292        v!=vertexColl->end(); ++v, ++ivtx) {  
1293 <    if(fillNtuple) {
1294 <      if(datatype == 0) {
1295 <        nTrkPV_[ivtx] = v->tracksSize();        
1296 <        sumptsq_[ivtx] = sumPtSquared(*v);
1297 <        isValid_[ivtx] = v->isValid();
1298 <        isFake_[ivtx] = v->isFake();    
1299 <        recx_[ivtx] = v->x();
1300 <        recy_[ivtx] = v->y();
1301 <        recz_[ivtx] = v->z();
1302 <        recx_err_[ivtx] = v->xError();
1303 <        recy_err_[ivtx] = v->yError();
1304 <        recz_err_[ivtx] = v->zError();
1305 <
1306 <        
1307 <      }
1308 <      if(datatype == 1) {
1309 <        nTrkPV1_spl_[ivtx] = v->tracksSize();  
1310 <        sumptsq1_spl_[ivtx] = sumPtSquared(*v);        
1311 <        isValid1_spl_[ivtx] = v->isValid();
1312 <        isFake1_spl_[ivtx] = v->isFake();      
1313 <        recx1_spl_[ivtx] = v->x();
1372 <        recy1_spl_[ivtx] = v->y();
1373 <        recz1_spl_[ivtx] = v->z();
1374 <        recx1_err_spl_[ivtx] = v->xError();
1375 <        recy1_err_spl_[ivtx] = v->yError();
1376 <        recz1_err_spl_[ivtx] = v->zError();
1377 <
1378 <      }
1379 <      if(datatype == 2) {
1380 <        nTrkPV2_spl_[ivtx] = v->tracksSize();  
1381 <        sumptsq2_spl_[ivtx] = sumPtSquared(*v);        
1382 <        isValid2_spl_[ivtx] = v->isValid();
1383 <        isFake2_spl_[ivtx] = v->isFake();
1384 <        recx2_spl_[ivtx] = v->x();
1385 <        recy2_spl_[ivtx] = v->y();
1386 <        recz2_spl_[ivtx] = v->z();
1387 <        recx2_err_spl_[ivtx] = v->xError();
1388 <        recy2_err_spl_[ivtx] = v->yError();
1389 <        recz2_err_spl_[ivtx] = v->zError();
1390 <      }
1391 <      if(datatype == 4) { // for pixelVertices
1392 <        nTrkPV_pxlpvtx_[ivtx] = v->tracksSize();        
1393 <        sumptsq_pxlpvtx_[ivtx] = sumPtSquared(*v);      
1394 <        isValid_pxlpvtx_[ivtx] = v->isValid();
1395 <        isFake_pxlpvtx_[ivtx] = v->isFake();
1396 <        recx_pxlpvtx_[ivtx] = v->x();
1397 <        recy_pxlpvtx_[ivtx] = v->y();
1398 <        recz_pxlpvtx_[ivtx] = v->z();
1399 <        recx_err_pxlpvtx_[ivtx] = v->xError();
1400 <        recy_err_pxlpvtx_[ivtx] = v->yError();
1401 <        recz_err_pxlpvtx_[ivtx] = v->zError();
1402 <      }
1403 <    }
1404 <  }
1405 <  // For histogram only fill the leading pvtx parameters
1406 <  if(fillHisto) {
1407 <    h["nTrkPV"+suffix]->Fill(vertexColl->begin()->tracksSize());
1408 <    try {
1409 <      for(reco::Vertex::trackRef_iterator t = vertexColl->begin()->tracks_begin();
1410 <          t!=vertexColl->begin()->tracks_end(); t++) {
1411 <        // illegal charge
1412 <        if ( (**t).charge() < -1 || (**t).charge() > 1 ) {
1413 <          //      h["trkPtPV"]->Fill(0.);
1414 <        }
1415 <        else {
1416 <          h["trkPtPV"+suffix]->Fill((**t).pt());
1417 <          h["trkDxyPV"+suffix]->Fill((**t).dxy());
1418 <          h["trkDzPV"+suffix]->Fill((**t).dz());
1419 <          h["trkEtaPV"+suffix]->Fill((**t).eta());
1420 <          h["trkPhiPV"+suffix]->Fill((**t).phi());
1293 >    if(!v->isFake()) {
1294 >      h_pvtrk->Fill1d("nTrkPV"+suffix, vertexColl->begin()->tracksSize());
1295 >      h_pvtrk->Fill1d("ndofPV"+suffix, vertexColl->begin()->ndof());
1296 >      int nHWTrkPV_ = 0;
1297 >      try {
1298 >        for(reco::Vertex::trackRef_iterator t = vertexColl->begin()->tracks_begin();
1299 >            t!=vertexColl->begin()->tracks_end(); t++) {
1300 >          // illegal charge
1301 >          if ( (**t).charge() < -1 || (**t).charge() > 1 ) {
1302 >            //    h_pvtrk->Fill1d("trkPtPV", 0.);
1303 >          }
1304 >          else {
1305 >            h_pvtrk->Fill1d("trkPtPV"+suffix, (**t).pt());
1306 >            h_pvtrk->Fill1d("trkDxyPV"+suffix, (**t).dxy());  
1307 >            h_pvtrk->Fill1d("trkDxyCorrPV"+suffix, (**t).dxy(bs));
1308 >            h_pvtrk->Fill1d("trkDzPV"+suffix, (**t).dz());
1309 >            h_pvtrk->Fill1d("trkEtaPV"+suffix, (**t).eta());
1310 >            h_pvtrk->Fill1d("trkPhiPV"+suffix, (**t).phi());
1311 >            if(vertexColl->begin()->trackWeight(*t) > 0.5)
1312 >              nHWTrkPV_++;
1313 >          }
1314          }
1315        }
1316 <    }
1317 <    catch (...) {
1318 <      // exception thrown when trying to use linked track
1319 <      //          h["trkPtPV"]->Fill(0.);
1316 >      catch (...) {
1317 >        // exception thrown when trying to use linked track
1318 >        //        h_pvtrk->Fill1d("trkPtPV", 0.);
1319 >      }
1320 >      h_pvtrk->Fill1d("nHWTrkPV"+suffix, nHWTrkPV_);
1321      }
1322    }
1429  
1323   }
1324  
1325   void PVStudy::fillMCHisto(std::vector<simPrimaryVertex>::iterator vsim, int isimpv, const reco::VertexCollection *vtxColl, int datatype)
# Line 1452 | Line 1345 | void PVStudy::fillMCHisto(std::vector<si
1345  
1346    for(reco::VertexCollection::const_iterator vrec=vtxColl->begin();
1347        vrec!=vtxColl->end(); ++vrec){
1455    int nrectrk = vrec->tracksSize();
1348      vsim->recVtx=NULL;  
1349 <  
1350 <    if(verbose_){
1351 <      cout << "sim primary vertex x = " << vsim->x << "; y = " << vsim->y << "; z = " << vsim->z <<  endl;
1352 <      cout << "Is matched? " << (matchVertex(*vsim,*vrec)?"Yes":"No") << endl;
1461 <    }
1462 <    if ( matchVertex(*vsim,*vrec) ) {
1349 >    edm::LogInfo("Debug") << "[fillMCHisto] sim primary vertex x = " << vsim->x << "; y = " << vsim->y << "; z = " << vsim->z <<  endl;
1350 >    edm::LogInfo("Debug") << "[fillMCHisto] Is matched? " << (matchVertex(*vsim,*vrec)?"Yes":"No") << endl;
1351 >
1352 >    if ( matchVertex(*vsim,*vrec)  ) {
1353        vsim->recVtx=&(*vrec);
1354        
1355        // if the matching critera are fulfilled, accept the rec-vertex that is closest in z
# Line 1467 | Line 1357 | void PVStudy::fillMCHisto(std::vector<si
1357        //|| (!vsim->recVtx) )
1358        //vsim->recVtx=&(*vrec);
1359        //}
1360 <      if(verbose_)
1471 <        cout <<"primary matched in vertexColl" << vsim->x << " " << vsim->y << " " << vsim->z <<  endl;
1360 >      edm::LogInfo("Debug") <<"[fillMCHisto] primary matched in vertexColl" << vsim->x << " " << vsim->y << " " << vsim->z <<  endl;
1361        
1362        double fres_mct[3];
1363        double ferror_mct[3];
1364 <      
1364 >      int nrectrk =  int(vsim->recVtx->tracksSize());
1365 >      double ndofPV = vsim->recVtx->ndof();
1366 >      double normchi2PV =  vsim->recVtx->normalizedChi2();
1367 >      double avgPtPV = avgPtRecVtx(*(vsim->recVtx));
1368 >
1369        fres_mct[0] = vsim->recVtx->x()-vsim->x;
1370        fres_mct[1] = vsim->recVtx->y()-vsim->y;
1371        fres_mct[2] = vsim->recVtx->z()-vsim->z;
# Line 1480 | Line 1373 | void PVStudy::fillMCHisto(std::vector<si
1373        ferror_mct[1] = vsim->recVtx->yError();
1374        ferror_mct[2] = vsim->recVtx->zError();
1375        
1376 <      h["deltax"+suffix]->Fill( fres_mct[0] );
1377 <      h["deltay"+suffix]->Fill( fres_mct[1] );
1378 <      h["deltaz"+suffix]->Fill( fres_mct[2] );
1379 <      h["pullx"+suffix]->Fill( fres_mct[0]/ferror_mct[0] );
1380 <      h["pully"+suffix]->Fill( fres_mct[1]/ferror_mct[1] );
1381 <      h["pullz"+suffix]->Fill( fres_mct[2]/ferror_mct[2] );
1382 <      h["errPVx"+suffix]->Fill( ferror_mct[0] );
1383 <      h["errPVy"+suffix]->Fill( ferror_mct[1] );
1384 <      h["errPVz"+suffix]->Fill( ferror_mct[2] );
1376 >      h_summary->Fill1d("deltax"+suffix, fres_mct[0] );
1377 >      h_summary->Fill1d("deltay"+suffix, fres_mct[1] );
1378 >      h_summary->Fill1d("deltaz"+suffix, fres_mct[2] );
1379 >      h_summary->Fill1d("pullx"+suffix, fres_mct[0]/ferror_mct[0] );
1380 >      h_summary->Fill1d("pully"+suffix, fres_mct[1]/ferror_mct[1] );
1381 >      h_summary->Fill1d("pullz"+suffix, fres_mct[2]/ferror_mct[2] );
1382 >      h_summary->Fill1d("errPVx"+suffix, ferror_mct[0] );
1383 >      h_summary->Fill1d("errPVy"+suffix, ferror_mct[1] );
1384 >      h_summary->Fill1d("errPVz"+suffix, ferror_mct[2] );
1385        pvinfo.push_back(PVStudy::PVInfo(res(fres_mct[0], fres_mct[1], fres_mct[2]),
1386                                         error(ferror_mct[0], ferror_mct[1], ferror_mct[2]),
1387                                         nrectrk));
# Line 1498 | Line 1391 | void PVStudy::fillMCHisto(std::vector<si
1391                  nrectrk, datatype);
1392        
1393        if(saventuple_) {
1394 <        //Fill the values for variables in ftree_  
1394 >        //Fill the values for variables in pvtxtree_  
1395          if(datatype == 1) {
1396            nTrkPV_spl1_mct_[nrecPV_spl1_mct_] =   nrectrk;
1397 +          ndofPV_spl1_mct_[nrecPV_spl1_mct_] =  ndofPV;
1398 +          normchi2PV_spl1_mct_[nrecPV_spl1_mct_] =  normchi2PV;
1399 +          avgPtPV_spl1_mct_[nrecPV_spl1_mct_] = avgPtPV;
1400            deltax_spl1_mct_[nrecPV_spl1_mct_] =  fres_mct[0];
1401 <          deltay_spl1_mct_[nrecPV_spl1_mct_] =  fres_mct[0];
1402 <          deltaz_spl1_mct_[nrecPV_spl1_mct_] =  fres_mct[0];
1401 >          deltay_spl1_mct_[nrecPV_spl1_mct_] =  fres_mct[1];
1402 >          deltaz_spl1_mct_[nrecPV_spl1_mct_] =  fres_mct[2];
1403            pullx_spl1_mct_[nrecPV_spl1_mct_] = fres_mct[0]/ferror_mct[0];  
1404            pully_spl1_mct_[nrecPV_spl1_mct_] = fres_mct[1]/ferror_mct[1];
1405            pullz_spl1_mct_[nrecPV_spl1_mct_] =  fres_mct[2]/ferror_mct[2];
1406 +          errx_spl1_mct_[nrecPV_spl1_mct_] =  ferror_mct[0];
1407 +          erry_spl1_mct_[nrecPV_spl1_mct_] =  ferror_mct[1];
1408 +          errz_spl1_mct_[nrecPV_spl1_mct_] =  ferror_mct[2];
1409            nrecPV_spl1_mct_++;
1410          }
1512        
1411          if(datatype == 2) {
1412 <          nTrkPV_spl2_mct_[nrecPV_spl2_mct_] = nrectrk;
1412 >          nTrkPV_spl2_mct_[nrecPV_spl2_mct_] = nrectrk;  
1413 >          ndofPV_spl2_mct_[nrecPV_spl2_mct_] =  ndofPV;
1414 >          normchi2PV_spl2_mct_[nrecPV_spl2_mct_] =  normchi2PV;
1415 >          avgPtPV_spl2_mct_[nrecPV_spl2_mct_] = avgPtPV;
1416            deltax_spl2_mct_[nrecPV_spl2_mct_] =  fres_mct[0];
1417 <          deltay_spl2_mct_[nrecPV_spl2_mct_] =  fres_mct[0];
1418 <          deltaz_spl2_mct_[nrecPV_spl2_mct_] =  fres_mct[0];
1417 >          deltay_spl2_mct_[nrecPV_spl2_mct_] =  fres_mct[1];
1418 >          deltaz_spl2_mct_[nrecPV_spl2_mct_] =  fres_mct[2];
1419            pullx_spl2_mct_[nrecPV_spl2_mct_] = fres_mct[0]/ferror_mct[0];  
1420            pully_spl2_mct_[nrecPV_spl2_mct_] = fres_mct[1]/ferror_mct[1];
1421 <          pullz_spl2_mct_[nrecPV_spl2_mct_] =  fres_mct[2]/ferror_mct[2];
1421 >          pullz_spl2_mct_[nrecPV_spl2_mct_] =  fres_mct[2]/ferror_mct[2];        
1422 >          errx_spl2_mct_[nrecPV_spl2_mct_] =  ferror_mct[0];
1423 >          erry_spl2_mct_[nrecPV_spl2_mct_] =  ferror_mct[1];
1424 >          errz_spl2_mct_[nrecPV_spl2_mct_] =  ferror_mct[2];
1425            nrecPV_spl2_mct_++;
1426          }
1427          if(datatype == 3) {    
1428 <          nTrkPV_mct_[nrecPV_mct_] = nrectrk;
1428 >          nTrkPV_mct_[nrecPV_mct_] = nrectrk;
1429 >          ndofPV_mct_[nrecPV_mct_] =  ndofPV;
1430 >          normchi2PV_mct_[nrecPV_mct_] =  normchi2PV;
1431 >          avgPtPV_mct_[nrecPV_mct_] = avgPtPV;
1432            deltax_mct_[nrecPV_mct_] =  fres_mct[0];
1433            deltay_mct_[nrecPV_mct_] =  fres_mct[0];
1434            deltaz_mct_[nrecPV_mct_] =  fres_mct[0];
1435            pullx_mct_[nrecPV_mct_] = fres_mct[0]/ferror_mct[0];  
1436            pully_mct_[nrecPV_mct_] = fres_mct[1]/ferror_mct[1];
1437 <          pullz_mct_[nrecPV_mct_] =  fres_mct[2]/ferror_mct[2];          
1437 >          pullz_mct_[nrecPV_mct_] =  fres_mct[2]/ferror_mct[2];
1438 >          errx_mct_[nrecPV_mct_] =  ferror_mct[0];
1439 >          erry_mct_[nrecPV_mct_] =  ferror_mct[1];
1440 >          errz_mct_[nrecPV_mct_] =  ferror_mct[2];        
1441            nrecPV_mct_++;
1442          }
1443        } // End of  if(saventuple_) {
1444      } //  if ( matchVertex(*vsim,*vrec) ) {
1445      else {  // no rec vertex found for this simvertex
1446 <      if(verbose_)
1537 <        cout <<"primary not found " << vsim->x << " " << vsim->y << " " << vsim->z << " nGenTrk=" << vsim->nGenTrk << endl;
1446 >      edm::LogInfo("Debug") <<"[fillMCHisto] primary not found " << vsim->x << " " << vsim->y << " " << vsim->z << " nGenTrk=" << vsim->nGenTrk << endl;
1447      }
1448    }
1449   }
1450  
1542
1451   void PVStudy::SetVarToZero() {
1544  //Greg's variables
1452    fntrk_ = 0;
1453    //pvtx position (x,y,z) residual and error
1454    for(int i = 0; i<3;i++)    {
1455 <      fres_[i] = 0;
1456 <      ferror_[i] = 0;
1455 >    fres_[i] = 0;
1456 >    ferror_[i] = 0;
1457    }
1458    
1459 <  //Yanyan's variables
1460 <  // Number of reconstructed vertices  
1459 >  // Event level information
1460 >  glob_runno_ = 0;
1461 >  glob_evtno_ = 0;
1462 >  glob_ls_ = 0;
1463 >  glob_bx_ = 0;
1464    nrecPV_ = 0;
1465    nrecPV1_spl_ = 0;
1466    nrecPV2_spl_ = 0;
# Line 1566 | Line 1476 | void PVStudy::SetVarToZero() {
1476    min_ntrksep_ = 9999.0;
1477    min_sumpt2sep_ = -9999.0;
1478    
1479 <
1479 >  // Variables filled per Vertex
1480    for (int i = 0; i < nMaxPVs_; i++) {
1571    // recoVertices with all tracks
1572    nTrkPV_[i] = 0; // Number of tracks in the pvtx    
1573    sumptsq_[i] = 0;
1574    isValid_[i] = -1;
1575    isFake_[i] = -1;
1576    recx_[i] = 0;
1577    recy_[i] = 0;
1578    recz_[i] = 0;
1579    recx_err_[i] = 0;
1580    recy_err_[i] = 0;
1581    recz_err_[i] = 0;
1582    
1583    // recoVertices with splitTrack1
1584    nTrkPV1_spl_[i] = 0; // Number of tracks in the pvtx    
1585    sumptsq1_spl_[i] = 0;
1586    isValid1_spl_[i] = -1;
1587    isFake1_spl_[i] = -1;
1588    recx1_spl_[i] = 0;
1589    recy1_spl_[i] = 0;
1590    recz1_spl_[i] = 0;
1591    recx1_err_spl_[i] = 0;
1592    recy1_err_spl_[i] = 0;
1593    recz1_err_spl_[i] = 0;
1594  
1595    // recoVertices with splitTrack2
1596    nTrkPV2_spl_[i] = 0; // Number of tracks in the pvtx  
1597    sumptsq2_spl_[i] = 0;
1598    isValid2_spl_[i] = -1;
1599    isFake2_spl_[i] = -1;
1600    recx2_spl_[i] = 0;
1601    recy2_spl_[i] = 0;
1602    recz2_spl_[i] = 0;
1603    recx2_err_spl_[i] = 0;
1604    recy2_err_spl_[i] = 0;
1605    recz2_err_spl_[i] = 0;
1606    
1607    //pixelVertices
1608    nTrkPV_pxlpvtx_[i] = 0; // Number of tracks in the pvtx  
1609    sumptsq_pxlpvtx_[i] = 0;
1610    isValid_pxlpvtx_[i] = -1;
1611    isFake_pxlpvtx_[i] = -1;
1612    recx_pxlpvtx_[i] = 0;
1613    recy_pxlpvtx_[i] = 0;
1614    recz_pxlpvtx_[i] = 0;
1615    recx_err_pxlpvtx_[i] = 0;
1616    recy_err_pxlpvtx_[i] = 0;
1617    recz_err_pxlpvtx_[i] = 0;
1618
1481      // matched two-vertices
1482      nTrkPV1_spl_twovtx_[i] = 0;
1483 +    ndofPV1_spl_twovtx_[i] = 0;
1484 +    normchi2PV1_spl_twovtx_[i] = 0;
1485 +    avgPtPV1_spl_twovtx_[i] = 0;
1486 +    errx1_spl_twovtx_[i] = 0;
1487 +    erry1_spl_twovtx_[i] = 0;
1488 +    errz1_spl_twovtx_[i] = 0;
1489 +
1490      nTrkPV2_spl_twovtx_[i] = 0;
1491 <    nTrkPV_twovtx_[i] = 0;  
1492 <    sumptsq1_spl_twovtx_[i] = 0; // Sum of pT squred in the pvtx
1493 <    sumptsq2_spl_twovtx_[i] = 0; // Sum of pT squred in the pvtx
1491 >    ndofPV2_spl_twovtx_[i] = 0;
1492 >    normchi2PV2_spl_twovtx_[i] = 0;
1493 >    avgPtPV2_spl_twovtx_[i] = 0;
1494 >    errx2_spl_twovtx_[i] = 0;
1495 >    erry2_spl_twovtx_[i] = 0;
1496 >    errz2_spl_twovtx_[i] = 0;
1497 >    
1498      deltax_twovtx_[i] = 0;
1499      deltay_twovtx_[i] = 0;
1500      deltaz_twovtx_[i] = 0;
# Line 1646 | Line 1519 | void PVStudy::SetVarToZero() {
1519      pullx_mct_[i] = 0;
1520      pully_mct_[i] = 0;
1521      pullz_mct_[i] = 0;
1522 <        
1522 >    nTrkPV_mct_[i] = 0;
1523 >    ndofPV_mct_[i] = 0;
1524 >    normchi2PV_mct_[i] = 0;
1525 >    avgPtPV_mct_[i] = 0;
1526 >    errx_mct_[i] = 0;
1527 >    erry_mct_[i] = 0;
1528 >    errz_mct_[i] = 0;
1529 >    
1530      deltax_spl1_mct_[i] = 0;
1531      deltay_spl1_mct_[i] = 0;
1532      deltaz_spl1_mct_[i] = 0;
1533      pullx_spl1_mct_[i] = 0;
1534      pully_spl1_mct_[i] = 0;
1535      pullz_spl1_mct_[i] = 0;
1536 <    
1536 >    nTrkPV_spl1_mct_[i] = 0;
1537 >    ndofPV_spl1_mct_[i] = 0;
1538 >    normchi2PV_spl1_mct_[i] = 0;
1539 >    avgPtPV_spl1_mct_[i] = 0;
1540 >    errx_spl1_mct_[i] = 0;
1541 >    erry_spl1_mct_[i] = 0;
1542 >    errz_spl1_mct_[i] = 0;
1543 >
1544      deltax_spl2_mct_[i] = 0;
1545      deltay_spl2_mct_[i] = 0;
1546      deltaz_spl2_mct_[i] = 0;
1547      pullx_spl2_mct_[i] = 0;
1548      pully_spl2_mct_[i] = 0;
1549      pullz_spl2_mct_[i] = 0;
1550 +    nTrkPV_spl2_mct_[i] = 0;
1551 +    ndofPV_spl2_mct_[i] = 0;
1552 +    normchi2PV_spl2_mct_[i] = 0;
1553 +    avgPtPV_spl2_mct_[i] = 0;
1554 +    errx_spl2_mct_[i] = 0;
1555 +    erry_spl2_mct_[i] = 0;
1556 +    errz_spl2_mct_[i] = 0;
1557 +
1558    }
1664  
1559   }
1560  
1561   double PVStudy::sumPtSquared(const reco::Vertex & v)  {
1562 <  double sum = 0.;
1563 <  double pT;
1564 <  for (reco::Vertex::trackRef_iterator it = v.tracks_begin(); it != v.tracks_end(); it++) {
1565 <    pT = (**it).pt();
1566 <    sum += pT*pT;
1562 >  if(v.isFake() || (!v.isValid()) || v.tracksSize() == 0) return 0.0;
1563 >  else {
1564 >    double sum = 0.;
1565 >    double pT;
1566 >    for (reco::Vertex::trackRef_iterator it = v.tracks_begin(); it != v.tracks_end(); it++) {
1567 >      pT = (**it).pt();
1568 >      sum += pT*pT;
1569 >    }
1570 >    return sum;
1571    }
1674  return sum;
1572   }
1573  
1574 +
1575 +
1576 + double PVStudy::avgPtRecVtx(const reco::Vertex & v)  {
1577 +
1578 +  if(v.isFake() || !v.isValid() || v.tracksSize()==0 ) return 0;
1579 +  else {
1580 +    double sumpT = 0.;
1581 +    for (reco::Vertex::trackRef_iterator it = v.tracks_begin(); it != v.tracks_end(); it++) {
1582 +      sumpT +=  (**it).pt();
1583 +  }
1584 +    return sumpT/double(v.tracksSize());
1585 +  }
1586 + }
1587 +
1588 +
1589 +

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines