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.10 by yygao, Sun Nov 8 02:56:57 2009 UTC vs.
Revision 1.23 by yygao, Mon May 31 14:19:45 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 39 | Line 38 | Implementation:
38   #include "DataFormats/TrackReco/interface/Track.h"
39   #include "DataFormats/TrackReco/interface/TrackFwd.h"
40   #include "FWCore/ServiceRegistry/interface/Service.h"
41 < #include "PhysicsTools/UtilAlgos/interface/TFileService.h"
41 > #include "CommonTools/UtilAlgos/interface/TFileService.h"
42   #include "UserCode/PVStudy/interface/PVStudy.h"
43   //
44   #include "DataFormats/VertexReco/interface/Vertex.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 >  useHWTrk_                  = iConfig.getUntrackedParameter<bool>("useHWTrk",false);
90 >  avgTrkPtInPVMin_                  = iConfig.getUntrackedParameter<double>("avgTrkPtInPVMin");
91 >  avgTrkPtInPVMax_                  = iConfig.getUntrackedParameter<double>("avgTrkPtInPVMax");
92 >  bsSrc = iConfig.getParameter< edm::InputTag >("beamSpot");
93 >  
94    //now do what ever initialization is needed
95    pvinfo.clear();
96  
90  
97    // Specify the data mode vector
98    if(realData_) datamode.push_back(0);
99    else {
# Line 96 | Line 102 | PVStudy::PVStudy(const edm::ParameterSet
102      datamode.push_back(2);
103      datamode.push_back(3);
104    }
105 <
100 <  // Create ntuple files if needed
105 > // Create ntuple files if needed
106    if(saventuple_) {
107      file_ = TFile::Open(outputfilename_.c_str(),"RECREATE");
108      ftree_ = new TTree("mytree","mytree");
# Line 108 | Line 113 | PVStudy::PVStudy(const edm::ParameterSet
113  
114      // pvtxtree_ analyzing the pvtxs ootb
115      pvtxtree_ = new TTree("pvtxtree","pvtxtree");
116 <    //pvtx using all tracks
117 <    pvtxtree_->Branch("nrecPV",&nrecPV_,"nrecPV/I");
118 <    pvtxtree_->Branch("nTrkPV",&nTrkPV_,"nTrkPV[nrecPV]/I");
119 <    pvtxtree_->Branch("sumptsq",&sumptsq_,"sumptsq[nrecPV]/D");    
120 <    pvtxtree_->Branch("isValid",&isValid_,"isValid/I");
121 <    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");
116 >
117 >    // Event information for the data
118 >    pvtxtree_->Branch("glob_runno",&glob_runno_,"glob_runno/I");
119 >    pvtxtree_->Branch("glob_evtno",&glob_evtno_,"glob_evtno/I");
120 >    pvtxtree_->Branch("glob_ls",&glob_ls_,"glob_ls/I");
121 >    pvtxtree_->Branch("glob_bx",&glob_bx_,"glob_bx/I");  
122      
123 +
124 +    pvtxtree_->Branch("nrecPV",&nrecPV_,"nrecPV/I");
125 +    pvtxtree_->Branch("nrecPV1_spl",&nrecPV1_spl_,"nrecPV1_spl/I");
126 +    pvtxtree_->Branch("nrecPV2_spl",&nrecPV2_spl_,"nrecPV2_spl/I");
127 +    // Event level information
128      pvtxtree_->Branch("min_zsep",&min_zsep_,"min_zsep/D");
129      pvtxtree_->Branch("min_ntrksep",&min_ntrksep_,"min_ntrksep/D");
130      pvtxtree_->Branch("min_sumpt2sep",&min_sumpt2sep_,"min_sumpt2sep/D");
131  
132 <    //pvtx using splittracks1
133 <    pvtxtree_->Branch("nrecPV1_spl",&nrecPV1_spl_,"nrecPV1_spl/I");
134 <    pvtxtree_->Branch("nTrkPV1_spl",&nTrkPV1_spl_,"nTrkPV1_spl[nrecPV1_spl]/I");  
131 <    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 <    //Fill the variables in the twovtx pair (recvtx1, recvtx2)
132 >    //Fill the variables in the twovtx pair (recvtx1, recvtx2)  
133 >    // Information related to the analyzing the two-vertex method
134 >
135      pvtxtree_->Branch("nrecPV_twovtx",&nrecPV_twovtx_,"nrecPV_twovtx/I");
156    pvtxtree_->Branch("nTrkPV1_spl_twovtx",&nTrkPV1_spl_twovtx_,"nTrkPV1_spl_twovtx[nrecPV_twovtx]/I");
157    pvtxtree_->Branch("nTrkPV2_spl_twovtx",&nTrkPV2_spl_twovtx_,"nTrkPV2_spl_twovtx[nrecPV_twovtx]/I");
158    pvtxtree_->Branch("sumptsq1_spl_twovtx",&sumptsq1_spl_twovtx_,"sumptsq1_spl_twovtx[nrecPV_twovtx]/D");
159    pvtxtree_->Branch("sumptsq2_spl_twovtx",&sumptsq2_spl_twovtx_,"sumptsq2_spl_twovtx[nrecPV_twovtx]/D");
136      pvtxtree_->Branch("nTrkPV_twovtx",&nTrkPV_twovtx_,"nTrkPV_twovtx[nrecPV_twovtx]/I");
137      pvtxtree_->Branch("deltax_twovtx",&deltax_twovtx_,"deltax_twovtx[nrecPV_twovtx]/D");
138      pvtxtree_->Branch("deltay_twovtx",&deltay_twovtx_,"deltay_twovtx[nrecPV_twovtx]/D");
# Line 167 | Line 143 | PVStudy::PVStudy(const edm::ParameterSet
143      pvtxtree_->Branch("pullx_twovtx",&pullx_twovtx_,"pullx_twovtx[nrecPV_twovtx]/D");
144      pvtxtree_->Branch("pully_twovtx",&pully_twovtx_,"pully_twovtx[nrecPV_twovtx]/D");
145      pvtxtree_->Branch("pullz_twovtx",&pullz_twovtx_,"pullz_twovtx[nrecPV_twovtx]/D");
146 +
147 +    // Information for the splitVertexColl1
148 +    pvtxtree_->Branch("nTrkPV1_spl_twovtx",&nTrkPV1_spl_twovtx_,"nTrkPV1_spl_twovtx[nrecPV_twovtx]/I");
149 +    pvtxtree_->Branch("ndofPV1_spl_twovtx",&ndofPV1_spl_twovtx_,"ndofPV1_spl_twovtx[nrecPV_twovtx]/D");
150 +    pvtxtree_->Branch("normchi2PV1_spl_twovtx",&normchi2PV1_spl_twovtx_,"normchi2PV1_spl_twovtx[nrecPV_twovtx]/D");
151 +    pvtxtree_->Branch("avgPtPV1_spl_twovtx",&avgPtPV1_spl_twovtx_,"avgPtPV1_spl_twovtx[nrecPV_twovtx]/D");
152 +    pvtxtree_->Branch("errx1_spl_twovtx",&errx1_spl_twovtx_,"errx1_spl_twovtx[nrecPV_twovtx]/D");
153 +    pvtxtree_->Branch("erry1_spl_twovtx",&erry1_spl_twovtx_,"erry1_spl_twovtx[nrecPV_twovtx]/D");
154 +    pvtxtree_->Branch("errz1_spl_twovtx",&errz1_spl_twovtx_,"errz1_spl_twovtx[nrecPV_twovtx]/D");
155 +  
156 +    
157 +    // Information for the splitVertexColl2
158 +    pvtxtree_->Branch("nTrkPV2_spl_twovtx",&nTrkPV2_spl_twovtx_,"nTrkPV2_spl_twovtx[nrecPV_twovtx]/I");
159 +    pvtxtree_->Branch("ndofPV2_spl_twovtx",&ndofPV2_spl_twovtx_,"ndofPV2_spl_twovtx[nrecPV_twovtx]/D");
160 +    pvtxtree_->Branch("normchi2PV2_spl_twovtx",&normchi2PV2_spl_twovtx_,"normchi2PV2_spl_twovtx[nrecPV_twovtx]/D");
161 +    pvtxtree_->Branch("avgPtPV2_spl_twovtx",&avgPtPV2_spl_twovtx_,"avgPtPV2_spl_twovtx[nrecPV_twovtx]/D");
162 +    pvtxtree_->Branch("errx2_spl_twovtx",&errx2_spl_twovtx_,"errx2_spl_twovtx[nrecPV_twovtx]/D");
163 +    pvtxtree_->Branch("erry2_spl_twovtx",&erry2_spl_twovtx_,"erry2_spl_twovtx[nrecPV_twovtx]/D");
164 +    pvtxtree_->Branch("errz2_spl_twovtx",&errz2_spl_twovtx_,"errz2_spl_twovtx[nrecPV_twovtx]/D");
165 +  
166      
167      // MC variables
168      if(!realData_) {  
# Line 184 | Line 180 | PVStudy::PVStudy(const edm::ParameterSet
180        pvtxtree_->Branch("deltaz_mct",&deltaz_mct_,"deltaz_mct[nrecPV_mct]/D");
181        pvtxtree_->Branch("pullx_mct",&pullx_mct_,"pullx_mct[nrecPV_mct]/D");
182        pvtxtree_->Branch("pully_mct",&pully_mct_,"pully_mct[nrecPV_mct]/D");
183 <      pvtxtree_->Branch("pullz_mct",&pullz_mct_,"pullz_mct[nrecPV_mct]/D");
183 >      pvtxtree_->Branch("pullz_mct",&pullz_mct_,"pullz_mct[nrecPV_mct]/D");    
184 >      pvtxtree_->Branch("errx_mct",&errx_mct_,"errx_mct[nrecPV_mct]/D");
185 >      pvtxtree_->Branch("erry_mct",&erry_mct_,"erry_mct[nrecPV_mct]/D");
186 >      pvtxtree_->Branch("errz_mct",&errz_mct_,"errz_mct[nrecPV_mct]/D");
187 >      pvtxtree_->Branch("nTrkPV_mct",&nTrkPV_mct_,"nTrkPV_mct[nrecPV_mct]/I");
188 >      pvtxtree_->Branch("ndofPV_mct",&ndofPV_mct_,"ndofPV_mct[nrecPV_mct]/D");
189 >      pvtxtree_->Branch("normchi2PV_mct",&normchi2PV_mct_,"normchi2PV_mct[nrecPV_mct]/D");
190 >      pvtxtree_->Branch("avgPtPV_mct",&avgPtPV_mct_,"avgPtPV_mct[nrecPV_mct]/D");
191 >
192        // For pvtxs with splittracks1
193        pvtxtree_->Branch("nrecPV_spl1_mct",&nrecPV_spl1_mct_,"nrecPV_spl1_mct/I");
194        pvtxtree_->Branch("deltax_spl1_mct",&deltax_spl1_mct_,"deltax_spl1_mct[nrecPV_spl1_mct]/D");
# Line 193 | Line 197 | PVStudy::PVStudy(const edm::ParameterSet
197        pvtxtree_->Branch("pullx_spl1_mct",&pullx_spl1_mct_,"pullx_spl1_mct[nrecPV_spl1_mct]/D");
198        pvtxtree_->Branch("pully_spl1_mct",&pully_spl1_mct_,"pully_spl1_mct[nrecPV_spl1_mct]/D");
199        pvtxtree_->Branch("pullz_spl1_mct",&pullz_spl1_mct_,"pullz_spl1_mct[nrecPV_spl1_mct]/D");
200 +      pvtxtree_->Branch("errx_spl1_mct",&errx_spl1_mct_,"errx_spl1_mct[nrecPV_spl1_mct]/D");
201 +      pvtxtree_->Branch("erry_spl1_mct",&erry_spl1_mct_,"erry_spl1_mct[nrecPV_spl1_mct]/D");
202 +      pvtxtree_->Branch("errz_spl1_mct",&errz_spl1_mct_,"errz_spl1_mct[nrecPV_spl1_mct]/D");
203 +      pvtxtree_->Branch("nTrkPV_spl1_mct",&nTrkPV_spl1_mct_,"nTrkPV_spl1_mct[nrecPV_spl1_mct]/I");
204 +      pvtxtree_->Branch("ndofPV_spl1_mct",&ndofPV_spl1_mct_,"ndofPV_spl1_mct[nrecPV_spl1_mct]/D");
205 +      pvtxtree_->Branch("normchi2PV_spl1_mct",&normchi2PV_spl1_mct_,"normchi2PV_spl1_mct[nrecPV_spl1_mct]/D");
206 +      pvtxtree_->Branch("avgPtPV_spl1_mct",&avgPtPV_spl1_mct_,"avgPtPV_spl1_mct[nrecPV_spl1_mct]/D");
207 +        
208        // For pvtxs with splittracks1
209        pvtxtree_->Branch("nrecPV_spl2_mct",&nrecPV_spl2_mct_,"nrecPV_spl2_mct/I");
210        pvtxtree_->Branch("deltax_spl2_mct",&deltax_spl2_mct_,"deltax_spl2_mct[nrecPV_spl2_mct]/D");
# Line 200 | Line 212 | PVStudy::PVStudy(const edm::ParameterSet
212        pvtxtree_->Branch("deltaz_spl2_mct",&deltaz_spl2_mct_,"deltaz_spl2_mct[nrecPV_spl2_mct]/D");
213        pvtxtree_->Branch("pullx_spl2_mct",&pullx_spl2_mct_,"pullx_spl2_mct[nrecPV_spl2_mct]/D");
214        pvtxtree_->Branch("pully_spl2_mct",&pully_spl2_mct_,"pully_spl2_mct[nrecPV_spl2_mct]/D");
215 <      pvtxtree_->Branch("pullz_spl2_mct",&pullz_spl2_mct_,"pullz_spl2_mct[nrecPV_spl2_mct]/D");
215 >      pvtxtree_->Branch("pullz_spl2_mct",&pullz_spl2_mct_,"pullz_spl2_mct[nrecPV_spl2_mct]/D");  
216 >      pvtxtree_->Branch("errx_spl2_mct",&errx_spl2_mct_,"errx_spl2_mct[nrecPV_spl2_mct]/D");
217 >      pvtxtree_->Branch("erry_spl2_mct",&erry_spl2_mct_,"erry_spl2_mct[nrecPV_spl2_mct]/D");
218 >      pvtxtree_->Branch("errz_spl2_mct",&errz_spl2_mct_,"errz_spl2_mct[nrecPV_spl2_mct]/D");  
219 >      pvtxtree_->Branch("nTrkPV_spl2_mct",&nTrkPV_spl2_mct_,"nTrkPV_spl2_mct[nrecPV_spl2_mct]/I");
220 >      pvtxtree_->Branch("ndofPV_spl2_mct",&ndofPV_spl2_mct_,"ndofPV_spl2_mct[nrecPV_spl2_mct]/D");
221 >      pvtxtree_->Branch("normchi2PV_spl2_mct",&normchi2PV_spl2_mct_,"normchi2PV_spl2_mct[nrecPV_spl2_mct]/D");
222 >      pvtxtree_->Branch("avgPtPV_spl2_mct",&avgPtPV_spl2_mct_,"avgPtPV_spl2_mct[nrecPV_spl2_mct]/D");
223      }
224    }
206
207  edm::Service<TFileService> fs;
208  TFileDirectory subDir = fs->mkdir( "Summary" );
209  TFileDirectory subDir1 = fs->mkdir( "Others" );
210  //   TFileDirectory subSubDir = subDir.mkdir( "mySubSubDirectory" );
211
212  setRootStyle();
225    
226 <  //Book histograms for track and pvtx parameters for each splitted pvtx
215 <  //i=0 : x (as in unsplit track collection)
216 <  //i=1 : x1_spl_
217 <  //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);
254 <  h["min_ysep_sign"]   = subDir.make<TH1D>("min_ysep_sign", "min y diff in signf of primary and secondary pvtx",300,0,5);
255 <  h["min_zsep"]   = subDir.make<TH1D>("min_zsep", "min z diff of primary and secondary pvtx",300,0,5);
256 <  h["min_zsep_sign"]   = subDir.make<TH1D>("min_zsep_sign", "min z diff in signf of primary and secondary pvtx",300,0,200);
257 <  // Difference in reconstructed vtx position
258 <  h["min_ntrksep"]   = subDir.make<TH1D>("min_ntrksep", "min nTrk diff of primary and secondary pvtx",201,-50.5,150.5);
259 <  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 272 | 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);
276 <    h["deltay"+suffix] = subDir.make<TH1D>(TString("deltay"+suffix), TString("y-residual pvtx"+suffix),800,-0.04,0.04);
277 <    h["deltaz"+suffix] = subDir.make<TH1D>(TString("deltaz"+suffix), TString("z-residual pvtx"+suffix),800,-0.04,0.04);
278 <    h["pullx"+suffix]  = subDir.make<TH1D>(TString("pullx"+suffix), TString("x-pull pvtx"+suffix),800,-10,10);
279 <    h["pully"+suffix]  = subDir.make<TH1D>(TString("pully"+suffix), TString("y-pull pvtx"+suffix),800,-10,10);
280 <    h["pullz"+suffix]  = subDir.make<TH1D>(TString("pullz"+suffix), TString("z-pull pvtx"+suffix),800,-10,10);
281 <    h["errPVx"+suffix] = subDir.make<TH1D>(TString("errPVx"+suffix), TString("X"+suffix+" vertex error"),100,0.,0.02);
282 <    h["errPVy"+suffix] = subDir.make<TH1D>(TString("errPVy"+suffix), TString("Y"+suffix+" vertex error"),100,0.,0.02);
283 <    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");
292 <      h["deltay"+suffix2]  = subDir1.make<TH1D>(TString("deltay"+suffix2), TString("y-residual of pvtx"+suffix),100,-0.02,0.02);
293 <      h["deltay"+suffix2]->GetXaxis()->SetTitle("cm");
294 <      h["deltaz"+suffix2]  = subDir1.make<TH1D>(TString("deltaz"+suffix2), TString("z-residual of pvtx"+suffix),100,-0.02,0.02);
295 <      h["deltaz"+suffix2]->GetXaxis()->SetTitle("cm");
296 <      h["pullx"+suffix2] = subDir1.make<TH1D>(TString("pullx"+suffix2), TString("x-pull of pvtx"+suffix),100,-10.,10.);
297 <      h["pully"+suffix2] = subDir1.make<TH1D>(TString("pully"+suffix2), TString("y-pull of pvtx"+suffix),100,-10.,10.);
298 <      h["pullz"+suffix2] = subDir1.make<TH1D>(TString("pullz"+suffix2), TString("z-pull of pvtx"+suffix),100,-10.,10.);
299 <      h["errPVx"+suffix2] = subDir1.make<TH1D>(TString("errPVx"+suffix2), TString("X"+suffix+" vertex error"),100,0.,0.02);
300 <      h["errPVy"+suffix2] = subDir1.make<TH1D>(TString("errPVy"+suffix2), TString("Y"+suffix+" vertex error"),100,0.,0.02);
301 <      h["errPVz"+suffix2] = subDir1.make<TH1D>(TString("errPVz"+suffix2), TString("Z"+suffix+" vertex error"),100,0.,0.02);
302 <      suffix2.clear();
303 <    } // End of   for (int ntrk=nTrkMin_;ntrk<=nTrkMax_;++ntrk) {
304 <    
287 >      h_others->Init("others",suffix,ss.str());
288 >    }
289 >
290      // Book residual and pull histograms only when analyzeOntheFly is enabled
291 <    if(analyze_) {
307 <      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);
308 <      h2["resx"+suffix+"_nTrk"]->SetMarkerStyle(21);
309 <      h2["resx"+suffix+"_nTrk"]->SetMarkerColor(4);
310 <      h2["resx"+suffix+"_nTrk"]->GetXaxis()->SetTitle("Num of tracks");
311 <      h2["resx"+suffix+"_nTrk"]->GetYaxis()->SetTitle("#mum");
312 <      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);
313 <      h2["resy"+suffix+"_nTrk"]->SetMarkerStyle(21);
314 <      h2["resy"+suffix+"_nTrk"]->SetMarkerColor(4);
315 <      h2["resy"+suffix+"_nTrk"]->GetXaxis()->SetTitle("Num of tracks");
316 <      h2["resy"+suffix+"_nTrk"]->GetYaxis()->SetTitle("#mum");
317 <      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);
318 <      h2["resz"+suffix+"_nTrk"]->SetMarkerStyle(21);
319 <      h2["resz"+suffix+"_nTrk"]->SetMarkerColor(4);
320 <      h2["resz"+suffix+"_nTrk"]->GetXaxis()->SetTitle("Num of tracks");
321 <      h2["resz"+suffix+"_nTrk"]->GetYaxis()->SetTitle("#mum");
322 <      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.);
323 <      h2["pullx"+suffix+"_nTrk"]->SetMarkerStyle(21);
324 <      h2["pullx"+suffix+"_nTrk"]->SetMarkerColor(4);
325 <      h2["pullx"+suffix+"_nTrk"]->SetBit(TH1::kCanRebin);
326 <      h2["pullx"+suffix+"_nTrk"]->GetXaxis()->SetTitle("Num of tracks");
327 <      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.);
328 <      h2["pully"+suffix+"_nTrk"]->SetMarkerStyle(21);
329 <      h2["pully"+suffix+"_nTrk"]->SetMarkerColor(4);
330 <      h2["pully"+suffix+"_nTrk"]->SetBit(TH1::kCanRebin);
331 <      h2["pully"+suffix+"_nTrk"]->GetXaxis()->SetTitle("Num of tracks");
332 <      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.);
333 <      h2["pullz"+suffix+"_nTrk"]->SetMarkerStyle(21);
334 <      h2["pullz"+suffix+"_nTrk"]->SetMarkerColor(4);
335 <      h2["pullz"+suffix+"_nTrk"]->SetBit(TH1::kCanRebin);
336 <      h2["pullz"+suffix+"_nTrk"]->GetXaxis()->SetTitle("Num of tracks");
337 <    } // 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    
295 <  // Book histograms about pixelVertices
342 <  h["trkdz_pxlpvtxdz"]   = subDir.make<TH1D>("trkdz_pxlpvtxdz", "(Track dz - pixelpvtx dz) in cm",300,-0.5,0.5);
343 <  h["trkdz_pxlpvtxdz_pxlpvtxdzerr"]   = subDir.make<TH1D>("trkdz_pxlpvtxdz_pxlpvtxdzerr", "|Track dz - pixelpvtx dz| / pxlpvtxdzErr",300,0,100);
344 <  h["trkdz_pxlpvtxdz_trkdzerr"]   = subDir.make<TH1D>("trkdz_pxlpvtxdz_trkdzerr", "|Track dz - pixelpvtx dz| / trkdzErr",300,0,50);
345 <  h["trkdzErr_pxlpvtx"]   = subDir.make<TH1D>("trkdzErr_pxlpvtxdz", "Track dzErr of leading pixelpvtx ",300,0,0.5);
346 <  h["trkdzErr_pvtx"]   = subDir.make<TH1D>("trkdzErr_pvtx", "Track dzErr of the leading pvtx ",300,0,0.5);
347 <  h["dzErr_pxlpvtx"]   = subDir.make<TH1D>("dzErr_pxlpvtx", "zError of the leading pvtx ",300,0,0.5);
348 <
349 <  // Book MC only plots
350 <  if (!realData_) {  
351 <    h["genPart_T"]      = subDir.make<TH1D>("genPart_T","t component of gen particles",300,-0.5,0.5);
352 <    h["genPart_T"]->GetXaxis()->SetTitle("t (nanosecond)");
353 <    h["genPart_cT"]     = subDir.make<TH1D>("genPart_cT","ct component of gen particles",300,-150.,150.);
354 <    h["genPart_cT"]->GetXaxis()->SetTitle("ct (mm)");    
355 <    h["nsimPV"]         = subDir.make<TH1D>("nsimPV","Num of sim PV",51,-0.5,50.5);  
356 <  }
295 >
296   }
297  
298   PVStudy::~PVStudy()
# Line 361 | 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 385 | 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 398 | 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;
408 <      cout << "number of vertices " << evt->vertices_size() << endl;
409 <    }
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 417 | 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 431 | 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 462 | 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 490 | 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 524 | 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 573 | 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
580  //=======================================================
581  //if(saventuple_)
539    SetVarToZero();
540    
541 <  //=======================================================
585 <  // Track accessors
586 <  //=======================================================
587 <  //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 592 | 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 <
598 <  //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 603 | 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 <
609 <  //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 614 | 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 <
621 < //=======================================================
622 <  // Fill trackparameters of the input tracks to pvtx fitter
623 <  //=======================================================
624 <  if(verbose_)
625 <    cout<<"Start filling track parameters of the input tracks to pvtx fitter."<<endl;
626 <  //fillTrackHisto(const reco::TrackCollection *trackColl, int datatype)
627 <  // datatype: unsplittracks (0); splittracks1 (1);  splittracks2 (2);
628 <  fillTrackHisto(trackColl, 0);
629 <  fillTrackHisto(splitTrackColl1, 1);
630 <  fillTrackHisto(splitTrackColl2, 2);
631 <  if(verbose_)
632 <    cout<<"End filling track parameters of the input tracks to pvtx fitter."<<endl;
633 <
634 <  //=======================================================
635 <  // PVTX accessors
636 <  //=======================================================
637 <  //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 642 | 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 <
648 <  //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 653 | 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 <
659 <  //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 664 | 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 +  // ======== 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 <  if(verbose_) cout<<"End accessing the track and vertex collections"<<endl;
610 >  edm::LogInfo("Debug")<<"[PVStudy] End accessing the track, beamSpot, primary vertex collections"<<endl;
611    
612 <  //=======================================================
673 <  // MC simvtx accessor
674 <  //=======================================================
612 >  // ========== MC simvtx accessor
613    if (!realData_) {
614      edm::Handle<SimVertexContainer> simVtxs;
615      iEvent.getByLabel( simG4_, simVtxs);
# Line 680 | Line 618 | PVStudy::analyze(const edm::Event& iEven
618      iEvent.getByLabel( simG4_, simTrks);
619    }
620  
621 <  //=======================================================
684 <  // GET PDT
685 <  //=======================================================
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;
703 <  }
704 <
705 <  //=======================================================
706 <  // Fill pixelVertices related histograms
707 <  //=======================================================
708 <  if(pixelVertexColl->size()>0 && pixelVertexColl->begin()->isValid() && !(pixelVertexColl->begin()->isFake())) {
709 <    h["dzErr_pxlpvtx"]->Fill( pixelVertexColl->begin()->zError());    
710 <    // Get the dZ error of the tracks in the leading pixelVertexColl
711 <    for(reco::Vertex::trackRef_iterator t = (pixelVertexColl->begin())->tracks_begin();
712 <        t!= (pixelVertexColl->begin())->tracks_end(); t++) {
713 <      
714 <      if ( (**t).charge() < -1 || (**t).charge() > 1 ) {
715 <        //        h["trkPtPV"]->Fill(0.);
716 <      }
717 <      else
718 <        h["trkdzErr_pxlpvtx"]->Fill((**t).dzError());
719 <    }
720 <    // Fill the track->dz() in the PV difference from first pixelpvtx
721 <    for(reco::Vertex::trackRef_iterator t = (vertexColl->begin())->tracks_begin();
722 <        t!= (vertexColl->begin())->tracks_end(); t++) {
723 <      // illegal charge
724 <      if ( (**t).charge() < -1 || (**t).charge() > 1 ) {
725 <        //        h["trkPtPV"]->Fill(0.);
726 <      }
727 <      else {
728 <        if(pixelVertexColl->size()>0) {
729 <          h["trkdz_pxlpvtxdz"]->Fill((**t).dz() -  pixelVertexColl->begin()->z());
730 <          h["trkdz_pxlpvtxdz_pxlpvtxdzerr"]->Fill(fabs((**t).dz() -  pixelVertexColl->begin()->z())/pixelVertexColl->begin()->zError());
731 <          h["trkdz_pxlpvtxdz_trkdzerr"]->Fill(fabs((**t).dz() -  pixelVertexColl->begin()->z())/(**t).dzError());
732 <          h["trkdzErr_pvtx"]->Fill((**t).dzError());
733 <        }
734 <      }
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    }
737  
738
739  //=======================================================
740  // Fill number of reconstructed vertices ootb
741  //=======================================================
641  
642 <  if(verbose_)  {
643 <    cout<<"PVStudy::analyze() Printing vertexCollection: "<<endl;
642 >  //========================================================================
643 >  // Step 1:  Apply event cleaning for data and MC
644 >  //          WARNING: event selection cut are hard coded!!
645 >  //========================================================================
646 >
647 >  glob_runno_ = iEvent.id().run();
648 >  glob_evtno_ = iEvent.id().event();
649 >  glob_ls_   = iEvent.luminosityBlock();
650 >  glob_bx_  = iEvent.bunchCrossing();  
651 >  
652 >  //========================================================================
653 >  // Step 2: Fill histograms for the splitting consistency checks
654 >  //========================================================================
655 >  
656 >  // === Fill trackparameters of the input tracks to pvtx fitter
657 >  edm::LogInfo("Debug")<<"[PVStudy] Start filling track parameters of the input tracks to pvtx fitter."<<endl;
658 >  //fillTrackHisto(const reco::TrackCollection *trackColl, int datatype, const Point & bs)
659 >  // datatype: unsplittracks (0); splittracks1 (1);  splittracks2 (2);
660 >  fillTrackHisto(trackColl, 0, beamSpot);
661 >  fillTrackHisto(splitTrackColl1, 1, beamSpot);
662 >  fillTrackHisto(splitTrackColl2, 2, beamSpot);
663 >  edm::LogInfo("Debug")<<"[PVStudy] End filling track parameters of the input tracks to pvtx fitter."<<endl;
664 >  
665 >  
666 >  // ==== Fill number of reconstructed vertices
667 >  edm::LogInfo("Debug")<<"[PVStudy] Printing vertexCollection: "<<endl;
668 >  edm::LogInfo("Debug")<<"[PVStudy] Printing splitVertexCollection1: "<<endl;
669 >  edm::LogInfo("Debug")<<"[PVStudy] Printing splitVertexCollection2: "<<endl;
670 >  edm::LogInfo("Debug")<<"[PVStudy] Start filling pvtx parameters."<<endl;
671 >  if (verbose_) {
672      printRecVtxs(vertexCollectionHandle);
746    cout<<"PVStudy::analyze() Printing splitVertexCollection1: "<<endl;
673      printRecVtxs(splitVertexCollection1Handle);
748    cout<<"PVStudy::analyze() Printing splitVertexCollection2: "<<endl;
674      printRecVtxs(splitVertexCollection2Handle);
750    cout<<"Start filling pvtx parameters."<<endl;
675    }
676 <  
676 >
677    nrecPV_ = int (vertexColl->size());
678    nrecPV1_spl_ = int (splitVertexColl1->size());
679    nrecPV2_spl_ = int (splitVertexColl2->size());
680  
681 <  h["nrecPV"]->Fill(nrecPV_);
682 <  h["nrecPV1_spl"]->Fill(nrecPV1_spl_);
683 <  h["nrecPV2_spl"]->Fill(nrecPV2_spl_);
684 <  h["nrecPVDiff"]->Fill(double(nrecPV1_spl_)-double(nrecPV2_spl_));
761 <
762 <  //=================================================================
763 <  // Fill track parameter ntuple/hist for tracks used in recoVertices
764 <  //=================================================================
765 <
766 <  //fillTrackHistoInPV(const reco::VertexCollection *vertexColl, int datatype, bool fillHisto, bool fillNtuple) {
767 <  if(vertexColl->size() > 0 && vertexColl->begin()->isValid() && !(vertexColl->begin()->isFake()))
768 <    fillTrackHistoInPV(vertexColl, 0, true, true);
681 >  h_pvtrk->Fill1d("nrecPV", nrecPV_);
682 >  h_pvtrk->Fill1d("nrecPV1_spl", nrecPV1_spl_);
683 >  h_pvtrk->Fill1d("nrecPV2_spl", nrecPV2_spl_);
684 >  h_misc->Fill1d("nrecPVDiff", double(nrecPV1_spl_)-double(nrecPV2_spl_));
685    
770  if(splitVertexColl1->size() > 0 && splitVertexColl1->begin()->isValid() && !(splitVertexColl1->begin()->isFake()))
771    fillTrackHistoInPV(splitVertexColl1, 1, false, true);
772
773  if(splitVertexColl1->size() > 0 && splitVertexColl2->begin()->isValid() && !(splitVertexColl2->begin()->isFake()))
774    fillTrackHistoInPV(splitVertexColl2, 2, false, true);
775
776  //==========================================================
777  // Fill secondary/primary min separations for multi-vertices
778  //==========================================================
686    
687 +  // ======= Fill track parameter ntuple/hist for tracks used in recoVertices
688 +  //fillTrackHistoInPV(const reco::VertexCollection *vertexColl, int datatype, const Point & bs) {
689 +  if(vertexColl->size() > 0 && vertexColl->begin()->isValid() && !(vertexColl->begin()->isFake()))
690 +    fillTrackHistoInPV(vertexColl, 0, beamSpot);
691 +  
692 +  // ======= Fill secondary/primary min separations for multi-vertices
693    if(vertexColl->size()>1 && vertexColl->begin()->isValid() && !(vertexColl->begin()->isFake()) ) {  
781
694      double min_xsep = 9999.0;
695      double min_ysep = 9999.0;
696      double min_zsep = 9999.0;    
# Line 788 | Line 700 | PVStudy::analyze(const edm::Event& iEven
700      double min_ntrksep = 9999.0;
701      double min_sumpt2sep = 9999999.0;
702      
703 <    if(verbose_) cout<<"leading pvtx z = "<< vertexColl->begin()->z() <<endl;
703 >    edm::LogInfo("Debug")<<"[PVStudy] leading pvtx z = "<< vertexColl->begin()->z() <<endl;
704  
705      // Looping through the secondary vertices to find the mininum separation to the primary
706      for(reco::VertexCollection::const_iterator v=vertexColl->begin() + 1 ;
707          v!=vertexColl->end(); ++v) {  
708        if(v->isValid() && ! v->isFake()) {
797        // xsep
709          if(fabs(v->x()- vertexColl->begin()->x())<min_xsep)
710            min_xsep = fabs(v->x()- vertexColl->begin()->x());
800        // ysep
711          if(fabs(v->y()- vertexColl->begin()->y())<min_ysep)
712            min_ysep = fabs(v->y()- vertexColl->begin()->y());
803        // zsep
713          if(fabs(v->z()- vertexColl->begin()->z())<min_zsep)
714            min_zsep = fabs(v->z()- vertexColl->begin()->z());
806        // xsep_sign
715          double xsep_sign = fabs(v->x()- vertexColl->begin()->x())/max(v->xError(), vertexColl->begin()->xError());
716          if(xsep_sign < min_xsep_sign)
717            min_xsep_sign = xsep_sign;
810        // ysep_sign
718          double ysep_sign = fabs(v->y()- vertexColl->begin()->y())/max(v->yError(), vertexColl->begin()->yError());
719          if(ysep_sign < min_ysep_sign)
720            min_ysep_sign = ysep_sign;
814        // zsep_sign
721          double zsep_sign = fabs(v->z()- vertexColl->begin()->z())/max(v->zError(), vertexColl->begin()->zError());
722          if(zsep_sign < min_zsep_sign)
723            min_zsep_sign = zsep_sign;
818        // ntrksep
724          if( (double(vertexColl->begin()->tracksSize()) - double(v->tracksSize())) < min_ntrksep)
725            min_ntrksep = double(vertexColl->begin()->tracksSize()) - double(v->tracksSize());
821        // sumpt2sep
726          if(fabs(sumPtSquared(*v) - sumPtSquared(*(vertexColl->begin()))) < min_sumpt2sep)
727            min_sumpt2sep = fabs(sumPtSquared(*v) - sumPtSquared(*(vertexColl->begin())));
728        }
729      }
730 <    h["min_xsep"]->Fill(min_xsep);
731 <    h["min_ysep"]->Fill(min_ysep);
732 <    h["min_zsep"]->Fill(min_zsep);
733 <    h["min_xsep_sign"]->Fill(min_xsep_sign);
734 <    h["min_ysep_sign"]->Fill(min_ysep_sign);
735 <    h["min_zsep_sign"]->Fill(min_zsep_sign);
736 <    h["min_ntrksep"]->Fill(min_ntrksep);
737 <    h["min_sumpt2sep"]->Fill(min_sumpt2sep);
730 >    h_misc->Fill1d("min_xsep", min_xsep);
731 >    h_misc->Fill1d("min_ysep", min_ysep);
732 >    h_misc->Fill1d("min_zsep", min_zsep);
733 >    h_misc->Fill1d("min_xsep_sign", min_xsep_sign);
734 >    h_misc->Fill1d("min_ysep_sign", min_ysep_sign);
735 >    h_misc->Fill1d("min_zsep_sign", min_zsep_sign);
736 >    h_misc->Fill1d("min_ntrksep", min_ntrksep);
737 >    h_misc->Fill1d("min_sumpt2sep", min_sumpt2sep);
738  
739      min_zsep_ = min_zsep;
740      min_ntrksep_ = min_ntrksep;
741      min_sumpt2sep_ = min_sumpt2sep;
838
839
742    } // End of  if(vertexColl->size()>1) {
743    
744 <  if(verbose_)
843 <    cout<<"End filling pvtx parameters."<<endl;
844 <  
845 <  //=======================================================
846 <  //           PrimaryVertex Matching
847 <  // 1. In z  |z1-z2|< zsigncut * max(sigmaz1, sigmaz2)
848 <  // 2. |(nTrkPV1 - nTrkPV2)/(nTrkPV1+nTrkPV2)|<ntrkdiffcut_
849 <  // Assume the first match is the primary vertex,
850 <  // since vertexColl are sorted in decreasing order of sum(pT)
851 <  //=======================================================
744 >  edm::LogInfo("Debug")<<"[PVStudy] End filling pvtx parameters."<<endl;
745  
746 <  if(verbose_)   cout<<"PVStudy::analyze(): matching pvtxs "<<endl;
746 >  //========================================================================
747 >  // Step 3:  PrimaryVertex Matching
748 >  //   1. In z  |z1-z2|< zsigncut * max(sigmaz1, sigmaz2)
749 >  //   2. |(nTrkPV1 - nTrkPV2)/(nTrkPV1+nTrkPV2)|<ntrkdiffcut_
750 >  //   3. The first match is the primary vertex, which has largest sum(pT^2)
751 >  //========================================================================
752 >  
753 >  edm::LogInfo("Debug")<<"[PVStudy] matching pvtxs "<<endl;
754    reco::VertexCollection s_empty_matchedVertexColl1;
755    reco::VertexCollection *matchedVertexColl1 = &s_empty_matchedVertexColl1;
756    matchedVertexColl1->reserve(splitVertexColl1->size());
# Line 869 | Line 769 | PVStudy::analyze(const edm::Event& iEven
769        if (ivtx!=0 || jvtx!=0) { stopmatching = true; break; }
770        reco::VertexRef recvtx2(splitVertexCollection2Handle, jvtx);
771        if( !(recvtx2->isValid()) || recvtx2->isFake()) break;
772 <      if(verbose_) {
773 <        cout<<"Matching splitVertexColl1: #  "<< ivtx<< " and splitVertexColl1: # "<<jvtx<<endl;
774 <        cout<<"recvtx1->z() = " << recvtx1->z() << "+/- "<< recvtx1->zError() << "." << endl;
775 <        cout<<"recvtx2->z() = " << recvtx2->z() << "+/- "<< recvtx2->zError() << "." << endl;
776 <      }
772 >      edm::LogInfo("Debug")<<"[PVStudy] Matching splitVertexColl1: #  "<< ivtx<< " and splitVertexColl1: # "<<jvtx<<endl;
773 >      edm::LogInfo("Debug")<<"[PVStudy] recvtx1->z() = " << recvtx1->z() << "+/- "<< recvtx1->zError() << "." << endl;
774 >      edm::LogInfo("Debug")<<"[PVStudy] recvtx2->z() = " << recvtx2->z() << "+/- "<< recvtx2->zError() << "." << endl;
775 >      
776 >      double twovtxsig = (recvtx1->z()-recvtx2->z())/max(recvtx1->zError(), recvtx2->zError());
777 >      h_misc->Fill1d("twovtxzsign", twovtxsig);
778        if(matchVertex(recvtx1, recvtx2, zsigncut_)) {
779 <        if(verbose_) {
780 <          cout<<"The two splitted vertices match in Z. "<<endl;
779 >        edm::LogInfo("Debug")<<"[PVStudy] The two splitted vertices match in Z. "<<endl;
780 >
781 >        int nTrkPV1, nTrkPV2;
782 >        if(useHWTrk_) {
783 >          nTrkPV1 = nHWTrkRecVtx(*recvtx1);
784 >          nTrkPV2 = nHWTrkRecVtx(*recvtx2);
785 >        }
786 >        else {
787 >          nTrkPV1 = recvtx1->tracksSize();
788 >          nTrkPV2 = recvtx2->tracksSize();
789          }
881        int nTrkPV1 = recvtx1->tracksSize();
882        int nTrkPV2 = recvtx2->tracksSize();    
790          double ntrkreldiff = double(nTrkPV1-nTrkPV2)/double(nTrkPV1+nTrkPV2);
791 <        h["nTrkPVDiff"]->Fill(nTrkPV1-nTrkPV2);
792 <        h["nTrkPVRelDiff"]->Fill(ntrkreldiff);
791 >        h_misc->Fill1d("nTrkPVDiff", nTrkPV1-nTrkPV2);
792 >        h_misc->Fill1d("nTrkPVRelDiff", ntrkreldiff);
793          if(fabs(ntrkreldiff)<ntrkdiffcut_) {    
794 <          if(verbose_) {
795 <            cout<<"(nTrkPV1-nTrkPV2)/(nTrkPV1+nTrkPV2) = " << ntrkreldiff<<endl;
889 <          }
794 >          edm::LogInfo("Debug")<<"[PVStudy] (nTrkPV1-nTrkPV2)/(nTrkPV1+nTrkPV2) = " << ntrkreldiff<<endl;
795 >
796            matchedVertexColl1->push_back(*recvtx1);
797            matchedVertexColl2->push_back(*recvtx2);
798            stopmatching = true; // stop the matching when the first match is found!
799            break;
800          }
801          else
802 <          cout<<"WARNING: (nTrkPV1-nTrkPV2)/(nTrkPV1+nTrkPV2) = " << ntrkreldiff<<", exceeding cut "<<ntrkdiffcut_<<endl;
802 >          edm::LogInfo("Debug")<<"WARNING: (nTrkPV1-nTrkPV2)/(nTrkPV1+nTrkPV2) = " << ntrkreldiff<<", exceeding cut "<<ntrkdiffcut_<<endl;
803        }
804        else {
805 <        cout<<"WARNING: The two reconstructed vertices do not match in z: "<<endl;
806 <        cout<<"recvtx1->z() = " << recvtx1->z() << "+/- "<< recvtx1->zError() << "." << endl;
807 <        cout<<"recvtx2->z() = " << recvtx2->z() << "+/- "<< recvtx2->zError() << "." << endl;  
805 >        edm::LogInfo("Debug")<<"WARNING: The two reconstructed vertices do not match in z: "<<endl;
806 >        edm::LogInfo("Debug")<<"recvtx1->z() = " << recvtx1->z() << "+/- "<< recvtx1->zError() << "." << endl;
807 >        edm::LogInfo("Debug")<<"recvtx2->z() = " << recvtx2->z() << "+/- "<< recvtx2->zError() << "." << endl;  
808        }
809      }
810    }
811 <  if(verbose_)     cout<<"PVStudy::analyze(): End matching pvtxs"<<endl;
812 <  
813 <  //=======================================================
814 <  //  Analyze matchedVertexColls
815 <  //=======================================================
816 <  if(verbose_) {
817 <    cout<<"Begin analyzing the matchedVertexColl with size = "<< matchedVertexColl1->size()<< endl;
818 <  }    
811 >  edm::LogInfo("Debug")<<"[PVStudy] End matching pvtxs"<<endl;
812 >
813 >  //========================================================================
814 >  // Step 4: Analyze matchedVertexColls
815 >  //========================================================================
816 >  edm::LogInfo("Debug")<<"[PVStudy] Begin analyzing the matchedVertexColl with size = "<< matchedVertexColl1->size()<< endl;
817 >  
818 >  // ==== If it is MC, analyze the res/pull of the unsplit vertexColl first
819 >  if(MC){
820 >    // make a list of primary vertices:
821 >    std::vector<simPrimaryVertex> simpv;
822 >    simpv=getSimPVs(evtMC,"");
823 >    //     simpv=getSimPVs(evtMC, simVtxs, simTrks);
824 >    h_gen->Fill1d("nsimPV", simpv.size());
825 >    nsimPV_ = simpv.size();
826 >    int isimpv = 0;
827 >    for(std::vector<simPrimaryVertex>::iterator vsim=simpv.begin();
828 >        vsim!=simpv.end(); vsim++, isimpv++){
829 >      nsimTrkPV_[isimpv]  =vsim->nGenTrk;
830 >      simx_[isimpv] = vsim->x;
831 >      simy_[isimpv] = vsim->y;
832 >      simz_[isimpv] = vsim->y;
833 >      simptsq_[isimpv] = vsim->ptsq;
834 >      fillMCHisto(vsim, isimpv, vertexColl, 3, avgTrkPtInPVMin_, avgTrkPtInPVMax_);
835 >    }
836 >  }
837    
838    // Compare the reconstructed vertex position and calculate resolution/pulls
839    if(matchedVertexColl1->size() != 0 && matchedVertexColl2->size() != 0) {  
840 <    //fillPvtxHisto(const reco::VertexCollection *vertexColl, int datatype, bool fillHisto, bool fillNtuple)
841 <    fillTrackHistoInPV(matchedVertexColl1, 1, true, false);
842 <    fillTrackHistoInPV(matchedVertexColl2, 2, true, false);
840 >    // ==== Analyze the splitted vtx using MC method
841 >    if(MC){
842 >      // make a list of primary vertices:
843 >      std::vector<simPrimaryVertex> simpv;
844 >      simpv=getSimPVs(evtMC,"");
845 >      //     simpv=getSimPVs(evtMC, simVtxs, simTrks);
846 >      int isimpv = 0;
847 >      for(std::vector<simPrimaryVertex>::iterator vsim=simpv.begin();
848 >          vsim!=simpv.end(); vsim++, isimpv++){
849 >        fillMCHisto(vsim, isimpv, matchedVertexColl1, 1, avgTrkPtInPVMin_, avgTrkPtInPVMax_);
850 >        fillMCHisto(vsim, isimpv, matchedVertexColl2, 2, avgTrkPtInPVMin_, avgTrkPtInPVMax_);
851 >      }
852 >    }
853 >
854 >    // ==== Analyze res/pull two-vertex method
855 >    //fillPvtxHisto(const reco::VertexCollection *vertexColl, int datatype)
856 >    fillTrackHistoInPV(matchedVertexColl1, 1, beamSpot);
857 >    fillTrackHistoInPV(matchedVertexColl2, 2, beamSpot);
858  
859      reco::VertexCollection::const_iterator v1;
860      reco::VertexCollection::const_iterator v2;
861 +
862      nrecPV_twovtx_ = 0;
863      for(v1 = matchedVertexColl1->begin(), v2 = matchedVertexColl2->begin();
864          v1!=matchedVertexColl1->end(), v2 != matchedVertexColl2->end();
865          ++v1, ++v2) {
866 +      
867 +      // ==================================================================
868 +      // With the option to fill the histograms at a given average pT range
869 +      // ==================================================================
870 +      if (avgPtRecVtx(*v1) < avgTrkPtInPVMin_ || avgPtRecVtx(*v1) > avgTrkPtInPVMax_ ) continue;
871 +      if (avgPtRecVtx(*v2) < avgTrkPtInPVMin_ || avgPtRecVtx(*v2) > avgTrkPtInPVMax_ ) continue;
872 +
873 +      h_misc->Fill1d("ndofPVDiff", v1->ndof() - v2->ndof());
874 +      h_misc->Fill1d("ndofPVRelDiff", (v1->ndof()-v2->ndof())/(v1->ndof()+v2->ndof()));
875        fres_[0] = (v1->x()-v2->x())/sqrt(2.0);
876        fres_[1] = (v1->y()-v2->y())/sqrt(2.0);
877        fres_[2] = (v1->z()-v2->z())/sqrt(2.0);
878        ferror_[0] = sqrt(pow(v1->xError(),2)+pow(v2->xError(),2))/sqrt(2);
879        ferror_[1] = sqrt(pow(v1->yError(),2)+pow(v2->yError(),2))/sqrt(2);
880        ferror_[2] = sqrt(pow(v1->zError(),2)+pow(v2->zError(),2))/sqrt(2);
932      fntrk_ =  (v1->tracksSize()+v2->tracksSize())/2;
881        
882 <      h["deltax"]->Fill( fres_[0] );
883 <      h["deltay"]->Fill( fres_[1] );
884 <      h["deltaz"]->Fill( fres_[2] );
885 <      h["pullx"]->Fill( fres_[0]/ferror_[0]);
886 <      h["pully"]->Fill( fres_[1]/ferror_[1]);
887 <      h["pullz"]->Fill( fres_[2]/ferror_[2]);
888 <      h["errPVx"]->Fill( ferror_[0] );
889 <      h["errPVy"]->Fill( ferror_[1] );
890 <      h["errPVz"]->Fill( ferror_[2] );
882 >      int nTrkPV1, nTrkPV2;
883 >      if(useHWTrk_) {
884 >        nTrkPV1 = nHWTrkRecVtx(*v1);
885 >        nTrkPV2 = nHWTrkRecVtx(*v2);
886 >      }
887 >      else {
888 >        nTrkPV1 = v1->tracksSize();
889 >        nTrkPV2 = v2->tracksSize();
890 >      }
891 >      
892 >      fntrk_ = (nTrkPV1 + nTrkPV2)/2;
893 >      
894 >      h_summary->Fill1d("deltax", fres_[0] );
895 >      h_summary->Fill1d("deltay", fres_[1] );
896 >      h_summary->Fill1d("deltaz", fres_[2] );
897 >      h_summary->Fill1d("pullx", fres_[0]/ferror_[0]);
898 >      h_summary->Fill1d("pully", fres_[1]/ferror_[1]);
899 >      h_summary->Fill1d("pullz", fres_[2]/ferror_[2]);
900 >      h_summary->Fill1d("errPVx", ferror_[0] );
901 >      h_summary->Fill1d("errPVy", ferror_[1] );
902 >      h_summary->Fill1d("errPVz", ferror_[2] );
903        pvinfo.push_back(PVStudy::PVInfo(res(fres_[0], fres_[1], fres_[2]),
904                                         error(ferror_[0], ferror_[1], ferror_[2]),
905                                         fntrk_));
906        // Fill histo according to its track multiplicity, set datamode = 0 for pvtx using all tracks
907 +
908        fillHisto(res(fres_[0], fres_[1], fres_[2]),
909                  error(ferror_[0], ferror_[1], ferror_[2]),
910                  fntrk_,0);  
911 +
912        // Fill the ntuple variables
951      nTrkPV1_spl_twovtx_[nrecPV_twovtx_] = v1->tracksSize();
952      nTrkPV2_spl_twovtx_[nrecPV_twovtx_] = v2->tracksSize();
953      sumptsq1_spl_twovtx_[nrecPV_twovtx_] = sumPtSquared(*v1);
954      sumptsq2_spl_twovtx_[nrecPV_twovtx_] = sumPtSquared(*v2);
913        nTrkPV_twovtx_[nrecPV_twovtx_] = fntrk_;
914        deltax_twovtx_[nrecPV_twovtx_] = fres_[0];
915        deltay_twovtx_[nrecPV_twovtx_] = fres_[1];
# Line 962 | Line 920 | PVStudy::analyze(const edm::Event& iEven
920        pullx_twovtx_[nrecPV_twovtx_] = fres_[0]/ferror_[0];
921        pully_twovtx_[nrecPV_twovtx_] = fres_[1]/ferror_[1];
922        pullz_twovtx_[nrecPV_twovtx_] = fres_[2]/ferror_[2];    
923 +
924 +
925 +      //SplittedVertex
926 +      nTrkPV1_spl_twovtx_[nrecPV_twovtx_] = nTrkPV1;
927 +      ndofPV1_spl_twovtx_[nrecPV_twovtx_] = v1->ndof();
928 +      normchi2PV1_spl_twovtx_[nrecPV_twovtx_] = v1->normalizedChi2();
929 +      avgPtPV1_spl_twovtx_[nrecPV_twovtx_] = avgPtRecVtx(*v1);
930 +      errx1_spl_twovtx_[nrecPV_twovtx_] = v1->xError();
931 +      erry1_spl_twovtx_[nrecPV_twovtx_] = v1->yError();
932 +      errz1_spl_twovtx_[nrecPV_twovtx_] = v1->zError();
933 +      
934 +      nTrkPV2_spl_twovtx_[nrecPV_twovtx_] = nTrkPV2;
935 +      ndofPV2_spl_twovtx_[nrecPV_twovtx_] = v2->ndof();
936 +      normchi2PV2_spl_twovtx_[nrecPV_twovtx_] = v2->normalizedChi2();
937 +      avgPtPV2_spl_twovtx_[nrecPV_twovtx_] = avgPtRecVtx(*v2);
938 +      errx2_spl_twovtx_[nrecPV_twovtx_] = v2->xError();
939 +      erry2_spl_twovtx_[nrecPV_twovtx_] = v2->yError();
940 +      errz2_spl_twovtx_[nrecPV_twovtx_] = v2->zError();
941 +  
942        nrecPV_twovtx_++;
943 +      
944 +      // Print some information of the two tracks events
945 +      if(verbose_ && fntrk_ < 4) {
946 +        cout<<"Printing matchedVertexColl1 for low ntrack bins"<<endl;
947 +        printRecVtx(*v1);
948 +        cout<<"Printing matchedVertexColl1 for low ntrack bins"<<endl;
949 +        printRecVtx(*v2);
950 +      }
951      } // End of analyzing res/pull
952    } // End of  if(matchedVertexColl1->size() == 1 && matchedVertexColl2->size() == 1 ) {
953    else
954 <    cout<<"WARNING: Cannot find matching pvtxs"<<endl;
954 >    edm::LogInfo("Debug")<<"[PVStudy] WARNING: Cannot find matching pvtxs"<<endl;
955    
956 <  if(verbose_)     cout<<"End analyzing the matchedVertexColl"<<endl;
972 <
973 <  //=======================================================
974 <  // Fill simulated vertices
975 <  //=======================================================
976 <  if (!realData_) {
977 <    bool MC=false;
978 <    Handle<HepMCProduct> evtMC;
979 <    iEvent.getByLabel("generator",evtMC);
980 <    if (!evtMC.isValid()) {
981 <      MC=false;
982 <      if(verbose_){
983 <        cout << "no HepMCProduct found"<< endl;
984 <      }
985 <    } else {
986 <      if(verbose_){
987 <        cout << "generator HepMCProduct found"<< endl;
988 <      }
989 <      MC=true;
990 <    }
991 <    
992 <    if(MC){
993 <      // make a list of primary vertices:
994 <      std::vector<simPrimaryVertex> simpv;
995 <      simpv=getSimPVs(evtMC,"");
996 <      //     simpv=getSimPVs(evtMC, simVtxs, simTrks);
997 <      h["nsimPV"]->Fill(simpv.size());
998 <      nsimPV_ = simpv.size();
956 >  edm::LogInfo("Debug")<<"[PVStudy] End analyzing the matchedVertexColl"<<endl;
957  
958 <      int isimpv = 0;
959 <      for(std::vector<simPrimaryVertex>::iterator vsim=simpv.begin();
960 <          vsim!=simpv.end(); vsim++, isimpv++){
961 <        nsimTrkPV_[isimpv]  =vsim->nGenTrk;
1004 <        simx_[isimpv] = vsim->x;
1005 <        simy_[isimpv] = vsim->y;
1006 <        simz_[isimpv] = vsim->y;
1007 <        simptsq_[isimpv] = vsim->ptsq;
1008 <        
1009 <        //fillMCHisto((std::vector<simPrimaryVertex>::iterator vsim, int isimpv, const reco::VertexCollection *vtxColl, int datatype) {
1010 <        fillMCHisto(vsim, isimpv, splitVertexColl1, 1);
1011 <        fillMCHisto(vsim, isimpv, splitVertexColl2, 2);
1012 <        fillMCHisto(vsim, isimpv, vertexColl, 3);
1013 <      }
1014 <    } // End of  for(std::vector<simPrimaryVertex>::iterator vsim=simpv.begin()
1015 <  } // End of   if (!realData_) {
1016 <
1017 <  // Finally fill the ftree_
958 >
959 >  //========================================================================
960 >  // Step 5: Fill ntuple if saventuple_ is on
961 >  //========================================================================
962    if(saventuple_) {
963      ftree_->Fill();
964      pvtxtree_->Fill();
965    }
966 +  
967   }
968  
969 +
970 +  
971   // ------------ method called once each job just before starting event loop  ------------
972   void
973   PVStudy::beginJob()
# Line 1030 | Line 977 | PVStudy::beginJob()
977   // ------------ method called once each job just after ending the event loop  ------------
978   void
979   PVStudy::endJob() {
980 <  if (verbose_) cout << "Analyzing PV info" << endl;
980 >  edm::LogInfo("Analysis") << "[endJob] Analyzing PV info" << endl;
981    // Looping through the datamodes available
982    for (vector<int>::const_iterator it= datamode.begin(); it != datamode.end() ; ++it) {  
983      string suffix;
984 <    if(verbose_)  cout<<"datamode = "<< *it<<endl;
984 >    edm::LogInfo("Analysis")<<"[endJob] datamode = "<< *it<<endl;
985      switch(*it) {
986      case 0: suffix = "";
987        break;
# Line 1045 | Line 992 | PVStudy::endJob() {
992      case 3: suffix = "_mct";
993        break;
994      }
995 +    suffix += "_nTrk";
996      if(analyze_) {
997        for (int ntrk=nTrkMin_;ntrk<=nTrkMax_;++ntrk) {
998 +        edm::LogInfo("Analysis") << "[endJob] ntrk = " << ntrk << endl;
999          PVStudy::PVAnaInfo ipv = GetPVAnaInfo(ntrk,*it);
1000 <        if ( ipv.res_.x() > 0 ) h2["resx"+suffix+"_nTrk"]->Fill(ntrk,ipv.res_.x(), 1.);
1001 <        if ( ipv.res_.y() > 0 ) h2["resy"+suffix+"_nTrk"]->Fill(ntrk,ipv.res_.y(), 1.);
1002 <        if ( ipv.res_.z() > 0 ) h2["resz"+suffix+"_nTrk"]->Fill(ntrk,ipv.res_.z(), 1.);
1003 <        if ( ipv.pull_.x() > 0 ) h2["pullx"+suffix+"_nTrk"]->Fill(ntrk,ipv.pull_.x(), 1.);
1004 <        if ( ipv.pull_.y() > 0 ) h2["pully"+suffix+"_nTrk"]->Fill(ntrk,ipv.pull_.y(), 1.);
1005 <        if ( ipv.pull_.z() > 0 ) h2["pullz"+suffix+"_nTrk"]->Fill(ntrk,ipv.pull_.z(), 1.);
1000 >        if ( ipv.res_.x() > 0 ) h_ana->Fill2d("resx"+suffix, ntrk,ipv.res_.x());
1001 >        if ( ipv.res_.y() > 0 ) h_ana->Fill2d("resy"+suffix, ntrk,ipv.res_.y());
1002 >        if ( ipv.res_.z() > 0 ) h_ana->Fill2d("resz"+suffix, ntrk,ipv.res_.z());
1003 >        if ( ipv.pull_.x() > 0 ) h_ana->Fill2d("pullx"+suffix, ntrk,ipv.pull_.x());
1004 >        if ( ipv.pull_.y() > 0 ) h_ana->Fill2d("pully"+suffix, ntrk,ipv.pull_.y());
1005 >        if ( ipv.pull_.z() > 0 ) h_ana->Fill2d("pullz"+suffix, ntrk,ipv.pull_.z());
1006        }
1007 <    }
1007 >    }
1008      suffix.clear();
1009    }
1010    if(saventuple_) {
# Line 1064 | Line 1013 | PVStudy::endJob() {
1013      pvtxtree_->Write();
1014      file_->Close();
1015    }
1016 < }
1068 <
1016 >  
1017  
1018 + }
1019  
1020   // Match a recovertex with a simvertex
1021   // ? Should the cut be parameter dependent?
# Line 1074 | Line 1023 | PVStudy::endJob() {
1023   bool PVStudy::matchVertex(const PVStudy::simPrimaryVertex & vsim,
1024                            const reco::Vertex & vrec)
1025   {
1026 <  return (fabs(vsim.z-vrec.z())<0.0500); // =500um
1026 >  if(vrec.isFake() || !vrec.isValid()) return false;
1027 >  else
1028 >    return true;
1029 >    //return (fabs(vsim.z-vrec.z())<0.0500); // =500um // remove this hard cut
1030   }
1031  
1032   // Match two reconstructed vertices
# Line 1083 | Line 1035 | bool PVStudy::matchVertex( const reco::V
1035                             int zsigncut)
1036   {
1037    double cut = zsigncut*max(vrec1->zError(), vrec2->zError());
1038 <  if(verbose_)
1087 <    cout<<"The matching criteria in z is "<<cut<<endl;
1038 >  edm::LogInfo("Debug")<<"[matchVertex] The matching criteria in z is "<<cut<<endl;
1039    return (fabs(vrec1->z()-vrec2->z())<cut);
1040   }
1041  
1042  
1043   bool PVStudy::isResonance(const HepMC::GenParticle * p){
1044    double ctau=(pdt->particle( abs(p->pdg_id()) ))->lifetime();
1045 <  if(verbose_) cout << "isResonance   " << p->pdg_id() << " " << ctau << endl;
1045 >  edm::LogInfo("Debug") << "[isResonance] isResonance   " << p->pdg_id() << " " << ctau << endl;
1046    return  ctau >0 && ctau <1e-6;
1047   }
1048  
# Line 1142 | Line 1093 | void PVStudy::printRecVtxs(const Handle<
1093    }
1094   }
1095  
1096 + void PVStudy::printRecVtx(const reco::Vertex & v){
1097 +
1098 +  cout << "#trk " << std::setw(3) << v.tracksSize()
1099 +         << " chi2 " << std::setw(4) << v.chi2()
1100 +         << " ndof " << std::setw(3) << v.ndof() << endl
1101 +         << " x "  << std::setw(8) <<std::fixed << std::setprecision(4) << v.x()
1102 +         << " dx " << std::setw(8) << v.xError()<< endl
1103 +         << " y "  << std::setw(8) << v.y()
1104 +         << " dy " << std::setw(8) << v.yError()<< endl
1105 +         << " z "  << std::setw(8) << v.z()
1106 +         << " dz " << std::setw(8) << v.zError()
1107 +         << endl;
1108 + }
1109 +
1110   void PVStudy::printSimTrks(const Handle<SimTrackContainer> simTrks){
1111    cout <<  " simTrks   type, (momentum), vertIndex, genpartIndex"  << endl;
1112    int i=1;
# Line 1160 | Line 1125 | void PVStudy::printSimTrks(const Handle<
1125    }
1126   }
1127  
1128 < void PVStudy::fillHisto(res r, error er, int ntk, int datamode){
1128 > void PVStudy::fillHisto(res r, error er, int ntk, int datamode) {
1129    stringstream ss;
1130    ss << ntk;
1131 <  string suffix = ss.str();
1132 <  if(datamode == 0 )  suffix = "_" + suffix;
1133 <  if(datamode == 1 )  suffix = "_spl1_mct_" + suffix;
1134 <  if(datamode == 2 )  suffix = "_spl2_mct_" + suffix;
1135 <  if(datamode == 3 )  suffix = "_mct_" + suffix;
1131 >  string suffix;
1132 >  if(datamode == 0 )  suffix = "_" + ss.str();
1133 >  if(datamode == 1 )  suffix = "_spl1_mct_" + ss.str();
1134 >  if(datamode == 2 )  suffix = "_spl2_mct_" + ss.str();
1135 >  if(datamode == 3 )  suffix = "_mct_" + ss.str();
1136    
1137    if (ntk < nTrkMin_ || ntk > nTrkMax_ ) return;
1138    // Fill histograms of res and pull of ntk
1139 <  h["deltax"+suffix]->Fill(r.x());
1140 <  h["deltay"+suffix]->Fill(r.y());
1141 <  h["deltaz"+suffix]->Fill(r.z());
1142 <  h["pullx"+suffix]->Fill(r.x()/er.x());
1143 <  h["pully"+suffix]->Fill(r.y()/er.y());
1144 <  h["pullz"+suffix]->Fill(r.z()/er.z());  
1145 <  h["errPVx"+suffix]->Fill(er.x());
1146 <  h["errPVy"+suffix]->Fill(er.y());
1147 <  h["errPVz"+suffix]->Fill(er.z());
1139 >  h_others->Fill1d("deltax"+suffix, r.x());
1140 >  h_others->Fill1d("deltay"+suffix, r.y());
1141 >  h_others->Fill1d("deltaz"+suffix, r.z());
1142 >  h_others->Fill1d("pullx"+suffix, r.x()/er.x());
1143 >  h_others->Fill1d("pully"+suffix, r.y()/er.y());
1144 >  h_others->Fill1d("pullz"+suffix, r.z()/er.z());  
1145 >  h_others->Fill1d("errPVx"+suffix, er.x());
1146 >  h_others->Fill1d("errPVy"+suffix, er.y());
1147 >  h_others->Fill1d("errPVz"+suffix, er.z());
1148   }
1149  
1150 +
1151   PVStudy::PVAnaInfo PVStudy::GetPVAnaInfo(int ntk, int datamode) {
1152    map<int,double> data;
1153    data.clear();
# Line 1199 | Line 1165 | PVStudy::PVAnaInfo PVStudy::GetPVAnaInfo
1165      for ( int i = 0; i < 6; ++i) {
1166        switch (i) {
1167        case 0:
1168 <        fit(h["deltax"+suffix], fpar);
1168 >        if (!h_others->ReadHisto1D("deltax"+suffix)) break;
1169 >        fit(h_others->ReadHisto1D("deltax"+suffix), fpar);
1170          data[i] = fpar[0]*cm2um;
1171          break;
1172        case 1:
1173 <        fit(h["deltay"+suffix], fpar);
1173 >        if (!h_others->ReadHisto1D("deltay"+suffix)) break;
1174 >        fit(h_others->ReadHisto1D("deltay"+suffix), fpar);
1175          data[i] = fpar[0]*cm2um;
1176          break;
1177        case 2:
1178 <        fit(h["deltaz"+suffix], fpar);
1178 >        if (!h_others->ReadHisto1D("deltaz"+suffix)) break;
1179 >        fit(h_others->ReadHisto1D("deltaz"+suffix), fpar);
1180          data[i] = fpar[0]*cm2um;
1181          break;
1182        case 3:
1183 <        fit(h["pullx"+suffix], fpar);
1183 >        if (!h_others->ReadHisto1D("pullx"+suffix)) break;
1184 >        fit(h_others->ReadHisto1D("pullx"+suffix), fpar);
1185          data[i] = fpar[0];
1186          break;
1187        case 4:
1188 <        fit(h["pully"+suffix], fpar);
1188 >        if (!h_others->ReadHisto1D("pully"+suffix)) break;
1189 >        fit(h_others->ReadHisto1D("pully"+suffix), fpar);
1190          data[i] = fpar[0];
1191          break;
1192        case 5:
1193 <        fit(h["pullz"+suffix], fpar);
1193 >        if (!h_others->ReadHisto1D("pullz"+suffix)) break;
1194 >        fit(h_others->ReadHisto1D("pullz"+suffix), fpar);
1195          data[i] = fpar[0];
1196          break;
1197        }
1198 <      if (verbose_ && data[i] > 0) cout << "data[" << i << "] = " << data[i] << (i<3?" micro m":" ") << endl;
1198 >      if (data[i] > 0) edm::LogInfo("Analysis") << "[Analysis] data[" << i << "] = " << data[i] << (i<3?" micro m":" ") << endl;
1199      }
1200    }
1201    else
# Line 1238 | Line 1210 | PVStudy::PVAnaInfo PVStudy::GetPVAnaInfo
1210                              ntk);
1211   }
1212  
1213 < void PVStudy::fit(TH1 *&hdist, double fitPars[]){
1213 >
1214 > void PVStudy::fit(TH1 *hdist, double fitPars[]){
1215    TAxis *axis0 = hdist->GetXaxis();
1216    int nbin = axis0->GetLast();
1217    double nOF = hdist->GetBinContent(nbin+1);
1218    double nUF = hdist->GetBinContent(0);
1219    //   double fitRange = axis0->GetBinUpEdge(nbin);
1220 <  double fitRange = axis0->GetXmax();
1220 >  // double fitRange = axis0->GetXmax();
1221 >  double fitRange = 2*hdist->GetRMS();
1222    double sigMax[2] = {0.,0.};
1223  
1224 <  if ( verbose_ ){
1225 <    cout << "Last bin = " << nbin;
1226 <    cout << "; hdist: Overflow Entries = " << nOF;
1227 <    cout << "; Underflow Entries = " << nUF;
1228 <    cout << "; hdist->GetEntries() = " << hdist->GetEntries();
1229 <    cout << "; fitting range = " << -fitRange << " to " << fitRange << endl;
1256 <  }
1224 >  edm::LogInfo("Analysis") << "[Fit] Last bin = " << nbin
1225 >                           << "; hdist: Overflow Entries = " << nOF
1226 >                           << "; Underflow Entries = " << nUF
1227 >                           << "; hdist->GetEntries() = " << hdist->GetEntries()
1228 >                           << "; fitting range = " << -fitRange << " to " << fitRange << endl;
1229 >
1230    if (hdist->GetEntries() - nOF - nUF >= 10) { // FIXME: for reasonable Gaussian fit
1231      for (int bi = 0; bi < nbin; bi++) {
1232        if ( (axis0->GetBinLowEdge(bi) < 0) && (hdist->GetBinContent(bi) > 0) ) {
# Line 1265 | Line 1238 | void PVStudy::fit(TH1 *&hdist, double fi
1238          if ( abs(sigMax[0]) > abs(sigMax[1]) ) sigMax[1] = abs(sigMax[0]);
1239        }
1240      }
1241 <    if (verbose_) cout << "Fit sigMax = " << sqrt(2.)*sigMax[1] << endl;
1241 >    //edm::LogInfo("Analysis") << "[Fit] Fit sigMax = " << sqrt(2.)*sigMax[1] << endl;
1242  
1243      TF1 *fgaus = new TF1("fgaus","gaus",-fitRange, fitRange);
1244      fgaus->SetParameter(1, 0.);
1245 <    fgaus->SetParLimits(1, -fitRange/40., fitRange/40.);
1245 >    fgaus->SetParLimits(1, -fitRange/10., fitRange/10.);
1246      fgaus->SetParLimits(2, 0., sqrt(2.)*sigMax[1]);
1247      fgaus->SetLineColor(4);
1248 <    hdist->Fit(fgaus,"Q");
1248 >    hdist->Fit(fgaus,"QLRM");
1249      gPad->Update();
1250      TPaveStats *s = (TPaveStats*) hdist->GetListOfFunctions()->FindObject("stats");
1251      s->SetOptStat(1111111);
1252      s->SetOptFit(0111);
1253      gPad->Update();
1254 <    if (verbose_) cout << "got function" << endl;
1254 >    //edm::LogInfo("Analysis") << "[Fit] got function" << endl;
1255      fitPars[0] = ((fgaus->GetParameter(2))?fgaus->GetParameter(2):-999);
1256    }
1257    else
1258      fitPars[0] = -999;
1259   }
1260  
1261 < void PVStudy::fillTrackHisto(const reco::TrackCollection *trackColl, int datatype) {
1261 >
1262 > void PVStudy::fillTrackHisto(const reco::TrackCollection *trackColl, int datatype, const Point & bs) {
1263    string suffix;
1264    suffix = ""; // for unsplit tracks
1265    if(datatype == 1) suffix = "1_spl"; // for splittracks 1
1266    if(datatype == 2) suffix = "2_spl"; // for splittracks 2
1267    
1268 <  h["nTrk"+suffix]->Fill(trackColl->size());
1268 >  h_pvtrk->Fill1d("nTrk"+suffix, trackColl->size());
1269    for(reco::TrackCollection::const_iterator itTrack = trackColl->begin();
1270        itTrack != trackColl->end();                      
1271        ++itTrack) {
1272 <    h["trkPt"+suffix]->Fill(itTrack->pt());
1273 <    h["trkDxy"+suffix]->Fill(itTrack->dxy());
1274 <    h["trkDz"+suffix]->Fill(itTrack->dz());
1275 <    h["trkEta"+suffix]->Fill(itTrack->eta());
1276 <    h["trkPhi"+suffix]->Fill(itTrack->phi());
1272 >    h_pvtrk->Fill1d("trkPt"+suffix, itTrack->pt());
1273 >    h_pvtrk->Fill1d("trkDxy"+suffix, itTrack->dxy());
1274 >    h_pvtrk->Fill1d("trkDxyCorr"+suffix, itTrack->dxy(bs));
1275 >    h_pvtrk->Fill1d("trkDz"+suffix, itTrack->dz());
1276 >    h_pvtrk->Fill1d("trkEta"+suffix, itTrack->eta());
1277 >    h_pvtrk->Fill1d("trkPhi"+suffix, itTrack->phi());
1278    }
1279   }
1280  
1281 < void PVStudy::fillTrackHistoInPV(const reco::VertexCollection *vertexColl, int datatype, bool fillHisto, bool fillNtuple) {
1281 > void PVStudy::fillTrackHistoInPV(const reco::VertexCollection *vertexColl, int datatype, const Point & bs) {
1282    string suffix;
1283    suffix = ""; // for unsplit tracks
1284    if(datatype == 1) suffix = "1_spl"; // for splittracks 1
# Line 1311 | Line 1286 | void PVStudy::fillTrackHistoInPV(const r
1286    int ivtx = 0;
1287    for(reco::VertexCollection::const_iterator v=vertexColl->begin();
1288        v!=vertexColl->end(); ++v, ++ivtx) {  
1289 <    if(fillNtuple) {
1290 <      if(datatype == 0) {
1291 <        nTrkPV_[ivtx] = v->tracksSize();        
1292 <        sumptsq_[ivtx] = sumPtSquared(*v);
1293 <        isValid_[ivtx] = v->isValid();
1294 <        isFake_[ivtx] = v->isFake();    
1295 <        recx_[ivtx] = v->x();
1296 <        recy_[ivtx] = v->y();
1297 <        recz_[ivtx] = v->z();
1298 <        recx_err_[ivtx] = v->xError();
1299 <        recy_err_[ivtx] = v->yError();
1300 <        recz_err_[ivtx] = v->zError();
1301 <
1302 <        
1303 <      }
1304 <      if(datatype == 1) {
1305 <        nTrkPV1_spl_[ivtx] = v->tracksSize();  
1306 <        sumptsq1_spl_[ivtx] = sumPtSquared(*v);        
1307 <        isValid1_spl_[ivtx] = v->isValid();
1333 <        isFake1_spl_[ivtx] = v->isFake();      
1334 <        recx1_spl_[ivtx] = v->x();
1335 <        recy1_spl_[ivtx] = v->y();
1336 <        recz1_spl_[ivtx] = v->z();
1337 <        recx1_err_spl_[ivtx] = v->xError();
1338 <        recy1_err_spl_[ivtx] = v->yError();
1339 <        recz1_err_spl_[ivtx] = v->zError();
1340 <
1341 <      }
1342 <      if(datatype == 2) {
1343 <        nTrkPV2_spl_[ivtx] = v->tracksSize();  
1344 <        sumptsq2_spl_[ivtx] = sumPtSquared(*v);        
1345 <        isValid2_spl_[ivtx] = v->isValid();
1346 <        isFake2_spl_[ivtx] = v->isFake();
1347 <        recx2_spl_[ivtx] = v->x();
1348 <        recy2_spl_[ivtx] = v->y();
1349 <        recz2_spl_[ivtx] = v->z();
1350 <        recx2_err_spl_[ivtx] = v->xError();
1351 <        recy2_err_spl_[ivtx] = v->yError();
1352 <        recz2_err_spl_[ivtx] = v->zError();
1353 <      }
1354 <    }
1355 <  }
1356 <  // For histogram only fill the leading pvtx parameters
1357 <  if(fillHisto) {
1358 <    h["nTrkPV"+suffix]->Fill(vertexColl->begin()->tracksSize());
1359 <    try {
1360 <      for(reco::Vertex::trackRef_iterator t = vertexColl->begin()->tracks_begin();
1361 <          t!=vertexColl->begin()->tracks_end(); t++) {
1362 <        // illegal charge
1363 <        if ( (**t).charge() < -1 || (**t).charge() > 1 ) {
1364 <          //      h["trkPtPV"]->Fill(0.);
1365 <        }
1366 <        else {
1367 <          h["trkPtPV"+suffix]->Fill((**t).pt());
1368 <          h["trkDxyPV"+suffix]->Fill((**t).dxy());
1369 <          h["trkDzPV"+suffix]->Fill((**t).dz());
1370 <          h["trkEtaPV"+suffix]->Fill((**t).eta());
1371 <          h["trkPhiPV"+suffix]->Fill((**t).phi());
1289 >    if(!v->isFake()) {
1290 >      h_pvtrk->Fill1d("nTrkPV"+suffix, vertexColl->begin()->tracksSize());
1291 >      h_pvtrk->Fill1d("ndofPV"+suffix, vertexColl->begin()->ndof());  
1292 >      h_pvtrk->Fill1d("nHWTrkPV"+suffix, nHWTrkRecVtx(*v));
1293 >      try {
1294 >        for(reco::Vertex::trackRef_iterator t = vertexColl->begin()->tracks_begin();
1295 >            t!=vertexColl->begin()->tracks_end(); t++) {
1296 >          // illegal charge
1297 >          if ( (**t).charge() < -1 || (**t).charge() > 1 ) {
1298 >            //    h_pvtrk->Fill1d("trkPtPV", 0.);
1299 >          }
1300 >          else {
1301 >            h_pvtrk->Fill1d("trkPtPV"+suffix, (**t).pt());
1302 >            h_pvtrk->Fill1d("trkDxyPV"+suffix, (**t).dxy());  
1303 >            h_pvtrk->Fill1d("trkDxyCorrPV"+suffix, (**t).dxy(bs));
1304 >            h_pvtrk->Fill1d("trkDzPV"+suffix, (**t).dz());
1305 >            h_pvtrk->Fill1d("trkEtaPV"+suffix, (**t).eta());
1306 >            h_pvtrk->Fill1d("trkPhiPV"+suffix, (**t).phi());
1307 >          }
1308          }
1309        }
1310 <    }
1311 <    catch (...) {
1312 <      // exception thrown when trying to use linked track
1313 <      //          h["trkPtPV"]->Fill(0.);
1310 >      catch (...) {
1311 >        // exception thrown when trying to use linked track
1312 >        //        h_pvtrk->Fill1d("trkPtPV", 0.);
1313 >      }
1314      }
1315    }
1380  
1316   }
1317  
1318 < void PVStudy::fillMCHisto(std::vector<simPrimaryVertex>::iterator vsim, int isimpv, const reco::VertexCollection *vtxColl, int datatype)
1318 > void PVStudy::fillMCHisto(std::vector<simPrimaryVertex>::iterator vsim, int isimpv, const reco::VertexCollection *vtxColl,
1319 >                          int datatype, double avgTrkPtInPVMin_, double avgTrkPtInPVMax_)
1320   {
1321    std::string suffix;
1322    // Set the vertexColl and histogram suffix according to datamode
# Line 1396 | Line 1332 | void PVStudy::fillMCHisto(std::vector<si
1332      suffix = "_mct";
1333      nrecPV_mct_ = 0;  
1334    }
1335 <  
1335 >
1336    //========================================================
1337 <  //  look for a matching reconstructed vertex in vertexColl
1338 <  //========================================================        
1339 <
1337 >  //  For each simulated vertex, look for a match in the vertexColl
1338 >  //  If more than 1 recVtx is found, use the one with closest in Z
1339 >  //========================================================  
1340 >    
1341 >  // === look for a matching reconstructed vertex in vertexColl
1342    for(reco::VertexCollection::const_iterator vrec=vtxColl->begin();
1343        vrec!=vtxColl->end(); ++vrec){
1406    int nrectrk = vrec->tracksSize();
1344      vsim->recVtx=NULL;  
1345 <  
1346 <    if(verbose_){
1347 <      cout << "sim primary vertex x = " << vsim->x << "; y = " << vsim->y << "; z = " << vsim->z <<  endl;
1348 <      cout << "Is matched? " << (matchVertex(*vsim,*vrec)?"Yes":"No") << endl;
1412 <    }
1413 <    if ( matchVertex(*vsim,*vrec) ) {
1345 >    edm::LogInfo("Debug") << "[fillMCHisto] sim primary vertex x = " << vsim->x << "; y = " << vsim->y << "; z = " << vsim->z <<  endl;
1346 >    edm::LogInfo("Debug") << "[fillMCHisto] Is matched? " << (matchVertex(*vsim,*vrec)?"Yes":"No") << endl;
1347 >    
1348 >    if ( matchVertex(*vsim,*vrec)  ) {
1349        vsim->recVtx=&(*vrec);
1350 <      
1416 <      // if the matching critera are fulfilled, accept the rec-vertex that is closest in z
1350 >      //if the matching critera are fulfilled, accept the rec-vertex that is closest in z
1351        //if(    ((vsim->recVtx) && (fabs(vsim->recVtx->position().z()-vsim->z)>fabs(vrec->z()-vsim->z)))
1352        //|| (!vsim->recVtx) )
1353        //vsim->recVtx=&(*vrec);
1420      //}
1421      if(verbose_)
1422        cout <<"primary matched in vertexColl" << vsim->x << " " << vsim->y << " " << vsim->z <<  endl;
1423      
1424      double fres_mct[3];
1425      double ferror_mct[3];
1426      
1427      fres_mct[0] = vsim->recVtx->x()-vsim->x;
1428      fres_mct[1] = vsim->recVtx->y()-vsim->y;
1429      fres_mct[2] = vsim->recVtx->z()-vsim->z;
1430      ferror_mct[0] = vsim->recVtx->xError();
1431      ferror_mct[1] = vsim->recVtx->yError();
1432      ferror_mct[2] = vsim->recVtx->zError();
1433      
1434      h["deltax"+suffix]->Fill( fres_mct[0] );
1435      h["deltay"+suffix]->Fill( fres_mct[1] );
1436      h["deltaz"+suffix]->Fill( fres_mct[2] );
1437      h["pullx"+suffix]->Fill( fres_mct[0]/ferror_mct[0] );
1438      h["pully"+suffix]->Fill( fres_mct[1]/ferror_mct[1] );
1439      h["pullz"+suffix]->Fill( fres_mct[2]/ferror_mct[2] );
1440      h["errPVx"+suffix]->Fill( ferror_mct[0] );
1441      h["errPVy"+suffix]->Fill( ferror_mct[1] );
1442      h["errPVz"+suffix]->Fill( ferror_mct[2] );
1443      pvinfo.push_back(PVStudy::PVInfo(res(fres_mct[0], fres_mct[1], fres_mct[2]),
1444                                       error(ferror_mct[0], ferror_mct[1], ferror_mct[2]),
1445                                       nrectrk));
1446      // Fill histo according to its track multiplicity
1447      fillHisto(res(fres_mct[0], fres_mct[1], fres_mct[2]),
1448                error(ferror_mct[0], ferror_mct[1], ferror_mct[2]),
1449                nrectrk, datatype);
1450      
1451      if(saventuple_) {
1452        //Fill the values for variables in ftree_  
1453        if(datatype == 1) {
1454          nTrkPV_spl1_mct_[nrecPV_spl1_mct_] =   nrectrk;
1455          deltax_spl1_mct_[nrecPV_spl1_mct_] =  fres_mct[0];
1456          deltay_spl1_mct_[nrecPV_spl1_mct_] =  fres_mct[0];
1457          deltaz_spl1_mct_[nrecPV_spl1_mct_] =  fres_mct[0];
1458          pullx_spl1_mct_[nrecPV_spl1_mct_] = fres_mct[0]/ferror_mct[0];  
1459          pully_spl1_mct_[nrecPV_spl1_mct_] = fres_mct[1]/ferror_mct[1];
1460          pullz_spl1_mct_[nrecPV_spl1_mct_] =  fres_mct[2]/ferror_mct[2];
1461          nrecPV_spl1_mct_++;
1462        }
1463        
1464        if(datatype == 2) {
1465          nTrkPV_spl2_mct_[nrecPV_spl2_mct_] = nrectrk;
1466          deltax_spl2_mct_[nrecPV_spl2_mct_] =  fres_mct[0];
1467          deltay_spl2_mct_[nrecPV_spl2_mct_] =  fres_mct[0];
1468          deltaz_spl2_mct_[nrecPV_spl2_mct_] =  fres_mct[0];
1469          pullx_spl2_mct_[nrecPV_spl2_mct_] = fres_mct[0]/ferror_mct[0];  
1470          pully_spl2_mct_[nrecPV_spl2_mct_] = fres_mct[1]/ferror_mct[1];
1471          pullz_spl2_mct_[nrecPV_spl2_mct_] =  fres_mct[2]/ferror_mct[2];
1472          nrecPV_spl2_mct_++;
1473        }
1474        if(datatype == 3) {    
1475          nTrkPV_mct_[nrecPV_mct_] = nrectrk;
1476          deltax_mct_[nrecPV_mct_] =  fres_mct[0];
1477          deltay_mct_[nrecPV_mct_] =  fres_mct[0];
1478          deltaz_mct_[nrecPV_mct_] =  fres_mct[0];
1479          pullx_mct_[nrecPV_mct_] = fres_mct[0]/ferror_mct[0];  
1480          pully_mct_[nrecPV_mct_] = fres_mct[1]/ferror_mct[1];
1481          pullz_mct_[nrecPV_mct_] =  fres_mct[2]/ferror_mct[2];          
1482          nrecPV_mct_++;
1483        }
1484      } // End of  if(saventuple_) {
1485    } //  if ( matchVertex(*vsim,*vrec) ) {
1486    else {  // no rec vertex found for this simvertex
1487      if(verbose_)
1488        cout <<"primary not found " << vsim->x << " " << vsim->y << " " << vsim->z << " nGenTrk=" << vsim->nGenTrk << endl;
1354      }
1355    }
1356 < }
1356 >  
1357 >  // === If match found fill the residual and pulls
1358 >  if(vsim->recVtx) {
1359 >    edm::LogInfo("Debug") <<"[fillMCHisto] primary matched in vertexColl" << vsim->x << " " << vsim->y << " " << vsim->z <<  endl;
1360 >    double avgPtPV = avgPtRecVtx(*(vsim->recVtx));
1361 >    if(avgPtPV>avgTrkPtInPVMax_ || avgPtPV<avgTrkPtInPVMin_) return;
1362 >
1363 >    // if study the resolution/pull for all tracks in the PVtx
1364 >    int nrectrk;
1365 >    if(useHWTrk_)
1366 >      nrectrk=nHWTrkRecVtx(*(vsim->recVtx));
1367 >    else
1368 >      nrectrk =  int(vsim->recVtx->tracksSize());
1369 >
1370 >    double fres_mct[3];
1371 >    double ferror_mct[3];
1372 >    
1373 >    double ndofPV = vsim->recVtx->ndof();
1374 >    double normchi2PV =  vsim->recVtx->normalizedChi2();
1375  
1376 +    fres_mct[0] = vsim->recVtx->x()-vsim->x;
1377 +    fres_mct[1] = vsim->recVtx->y()-vsim->y;
1378 +    fres_mct[2] = vsim->recVtx->z()-vsim->z;
1379 +    ferror_mct[0] = vsim->recVtx->xError();
1380 +    ferror_mct[1] = vsim->recVtx->yError();
1381 +    ferror_mct[2] = vsim->recVtx->zError();
1382 +    
1383 +    h_summary->Fill1d("deltax"+suffix, fres_mct[0] );
1384 +    h_summary->Fill1d("deltay"+suffix, fres_mct[1] );
1385 +    h_summary->Fill1d("deltaz"+suffix, fres_mct[2] );
1386 +    h_summary->Fill1d("pullx"+suffix, fres_mct[0]/ferror_mct[0] );
1387 +    h_summary->Fill1d("pully"+suffix, fres_mct[1]/ferror_mct[1] );
1388 +    h_summary->Fill1d("pullz"+suffix, fres_mct[2]/ferror_mct[2] );
1389 +    h_summary->Fill1d("errPVx"+suffix, ferror_mct[0] );
1390 +    h_summary->Fill1d("errPVy"+suffix, ferror_mct[1] );
1391 +    h_summary->Fill1d("errPVz"+suffix, ferror_mct[2] );
1392 +    pvinfo.push_back(PVStudy::PVInfo(res(fres_mct[0], fres_mct[1], fres_mct[2]),
1393 +                                     error(ferror_mct[0], ferror_mct[1], ferror_mct[2]),
1394 +                                     nrectrk));
1395 +    // Fill histo according to its track multiplicity
1396 +    fillHisto(res(fres_mct[0], fres_mct[1], fres_mct[2]),
1397 +              error(ferror_mct[0], ferror_mct[1], ferror_mct[2]),
1398 +              nrectrk, datatype);
1399 +    
1400 +    if(saventuple_) {
1401 +      //Fill the values for variables in pvtxtree_  
1402 +      if(datatype == 1) {
1403 +        nTrkPV_spl1_mct_[nrecPV_spl1_mct_] =   nrectrk;
1404 +        ndofPV_spl1_mct_[nrecPV_spl1_mct_] =  ndofPV;
1405 +        normchi2PV_spl1_mct_[nrecPV_spl1_mct_] =  normchi2PV;
1406 +        avgPtPV_spl1_mct_[nrecPV_spl1_mct_] = avgPtPV;
1407 +        deltax_spl1_mct_[nrecPV_spl1_mct_] =  fres_mct[0];
1408 +        deltay_spl1_mct_[nrecPV_spl1_mct_] =  fres_mct[1];
1409 +        deltaz_spl1_mct_[nrecPV_spl1_mct_] =  fres_mct[2];
1410 +        pullx_spl1_mct_[nrecPV_spl1_mct_] = fres_mct[0]/ferror_mct[0];  
1411 +        pully_spl1_mct_[nrecPV_spl1_mct_] = fres_mct[1]/ferror_mct[1];
1412 +        pullz_spl1_mct_[nrecPV_spl1_mct_] =  fres_mct[2]/ferror_mct[2];
1413 +        errx_spl1_mct_[nrecPV_spl1_mct_] =  ferror_mct[0];
1414 +        erry_spl1_mct_[nrecPV_spl1_mct_] =  ferror_mct[1];
1415 +        errz_spl1_mct_[nrecPV_spl1_mct_] =  ferror_mct[2];
1416 +        nrecPV_spl1_mct_++;
1417 +      }
1418 +      if(datatype == 2) {
1419 +        nTrkPV_spl2_mct_[nrecPV_spl2_mct_] = nrectrk;      
1420 +        ndofPV_spl2_mct_[nrecPV_spl2_mct_] =  ndofPV;
1421 +        normchi2PV_spl2_mct_[nrecPV_spl2_mct_] =  normchi2PV;
1422 +        avgPtPV_spl2_mct_[nrecPV_spl2_mct_] = avgPtPV;
1423 +        deltax_spl2_mct_[nrecPV_spl2_mct_] =  fres_mct[0];
1424 +        deltay_spl2_mct_[nrecPV_spl2_mct_] =  fres_mct[1];
1425 +        deltaz_spl2_mct_[nrecPV_spl2_mct_] =  fres_mct[2];
1426 +        pullx_spl2_mct_[nrecPV_spl2_mct_] = fres_mct[0]/ferror_mct[0];  
1427 +        pully_spl2_mct_[nrecPV_spl2_mct_] = fres_mct[1]/ferror_mct[1];
1428 +        pullz_spl2_mct_[nrecPV_spl2_mct_] =  fres_mct[2]/ferror_mct[2];          
1429 +        errx_spl2_mct_[nrecPV_spl2_mct_] =  ferror_mct[0];
1430 +        erry_spl2_mct_[nrecPV_spl2_mct_] =  ferror_mct[1];
1431 +        errz_spl2_mct_[nrecPV_spl2_mct_] =  ferror_mct[2];
1432 +        nrecPV_spl2_mct_++;
1433 +      }
1434 +      if(datatype == 3) {      
1435 +        nTrkPV_mct_[nrecPV_mct_] = nrectrk;
1436 +        ndofPV_mct_[nrecPV_mct_] =  ndofPV;
1437 +        normchi2PV_mct_[nrecPV_mct_] =  normchi2PV;
1438 +        avgPtPV_mct_[nrecPV_mct_] = avgPtPV;
1439 +        deltax_mct_[nrecPV_mct_] =  fres_mct[0];
1440 +        deltay_mct_[nrecPV_mct_] =  fres_mct[0];
1441 +        deltaz_mct_[nrecPV_mct_] =  fres_mct[0];
1442 +        pullx_mct_[nrecPV_mct_] = fres_mct[0]/ferror_mct[0];  
1443 +        pully_mct_[nrecPV_mct_] = fres_mct[1]/ferror_mct[1];
1444 +        pullz_mct_[nrecPV_mct_] =  fres_mct[2]/ferror_mct[2];
1445 +        errx_mct_[nrecPV_mct_] =  ferror_mct[0];
1446 +        erry_mct_[nrecPV_mct_] =  ferror_mct[1];
1447 +        errz_mct_[nrecPV_mct_] =  ferror_mct[2];          
1448 +        nrecPV_mct_++;
1449 +      }
1450 +    } // End of  if(saventuple_) {
1451 +  } //  if ( matchVertex(*vsim,*vrec) ) {
1452 +  else {  // no rec vertex found for this simvertex
1453 +    edm::LogInfo("Debug") <<"[fillMCHisto] primary not found " << vsim->x << " " << vsim->y << " " << vsim->z << " nGenTrk=" << vsim->nGenTrk << endl;
1454 +  }
1455 + }
1456  
1457 +                                                                                                                  
1458   void PVStudy::SetVarToZero() {
1495  //Greg's variables
1459    fntrk_ = 0;
1460    //pvtx position (x,y,z) residual and error
1461    for(int i = 0; i<3;i++)    {
1462 <      fres_[i] = 0;
1463 <      ferror_[i] = 0;
1462 >    fres_[i] = 0;
1463 >    ferror_[i] = 0;
1464    }
1465    
1466 <  //Yanyan's variables
1467 <  // Number of reconstructed vertices  
1466 >  // Event level information
1467 >  glob_runno_ = 0;
1468 >  glob_evtno_ = 0;
1469 >  glob_ls_ = 0;
1470 >  glob_bx_ = 0;
1471    nrecPV_ = 0;
1472    nrecPV1_spl_ = 0;
1473    nrecPV2_spl_ = 0;
# Line 1517 | Line 1483 | void PVStudy::SetVarToZero() {
1483    min_ntrksep_ = 9999.0;
1484    min_sumpt2sep_ = -9999.0;
1485    
1486 <
1486 >  // Variables filled per Vertex
1487    for (int i = 0; i < nMaxPVs_; i++) {
1522    // recoVertices with all tracks
1523    nTrkPV_[i] = 0; // Number of tracks in the pvtx    
1524    sumptsq_[i] = 0;
1525    isValid_[i] = -1;
1526    isFake_[i] = -1;
1527    recx_[i] = 0;
1528    recy_[i] = 0;
1529    recz_[i] = 0;
1530    recx_err_[i] = 0;
1531    recy_err_[i] = 0;
1532    recz_err_[i] = 0;
1533    
1534    
1535
1536    // recoVertices with splitTrack1
1537    nTrkPV1_spl_[i] = 0; // Number of tracks in the pvtx    
1538    sumptsq1_spl_[i] = 0;
1539    isValid1_spl_[i] = -1;
1540    isFake1_spl_[i] = -1;
1541    recx1_spl_[i] = 0;
1542    recy1_spl_[i] = 0;
1543    recz1_spl_[i] = 0;
1544    recx1_err_spl_[i] = 0;
1545    recy1_err_spl_[i] = 0;
1546    recz1_err_spl_[i] = 0;
1547  
1548    
1549    // recoVertices with splitTrack2
1550    nTrkPV2_spl_[i] = 0; // Number of tracks in the pvtx  
1551    sumptsq2_spl_[i] = 0;
1552    isValid2_spl_[i] = -1;
1553    isFake2_spl_[i] = -1;
1554    recx2_spl_[i] = 0;
1555    recy2_spl_[i] = 0;
1556    recz2_spl_[i] = 0;
1557    recx2_err_spl_[i] = 0;
1558    recy2_err_spl_[i] = 0;
1559    recz2_err_spl_[i] = 0;
1560    
1488      // matched two-vertices
1489      nTrkPV1_spl_twovtx_[i] = 0;
1490 +    ndofPV1_spl_twovtx_[i] = 0;
1491 +    normchi2PV1_spl_twovtx_[i] = 0;
1492 +    avgPtPV1_spl_twovtx_[i] = 0;
1493 +    errx1_spl_twovtx_[i] = 0;
1494 +    erry1_spl_twovtx_[i] = 0;
1495 +    errz1_spl_twovtx_[i] = 0;
1496 +
1497      nTrkPV2_spl_twovtx_[i] = 0;
1498 <    nTrkPV_twovtx_[i] = 0;  
1499 <    sumptsq1_spl_twovtx_[i] = 0; // Sum of pT squred in the pvtx
1500 <    sumptsq2_spl_twovtx_[i] = 0; // Sum of pT squred in the pvtx
1498 >    ndofPV2_spl_twovtx_[i] = 0;
1499 >    normchi2PV2_spl_twovtx_[i] = 0;
1500 >    avgPtPV2_spl_twovtx_[i] = 0;
1501 >    errx2_spl_twovtx_[i] = 0;
1502 >    erry2_spl_twovtx_[i] = 0;
1503 >    errz2_spl_twovtx_[i] = 0;
1504 >    
1505      deltax_twovtx_[i] = 0;
1506      deltay_twovtx_[i] = 0;
1507      deltaz_twovtx_[i] = 0;
# Line 1588 | Line 1526 | void PVStudy::SetVarToZero() {
1526      pullx_mct_[i] = 0;
1527      pully_mct_[i] = 0;
1528      pullz_mct_[i] = 0;
1529 <        
1529 >    nTrkPV_mct_[i] = 0;
1530 >    ndofPV_mct_[i] = 0;
1531 >    normchi2PV_mct_[i] = 0;
1532 >    avgPtPV_mct_[i] = 0;
1533 >    errx_mct_[i] = 0;
1534 >    erry_mct_[i] = 0;
1535 >    errz_mct_[i] = 0;
1536 >    
1537      deltax_spl1_mct_[i] = 0;
1538      deltay_spl1_mct_[i] = 0;
1539      deltaz_spl1_mct_[i] = 0;
1540      pullx_spl1_mct_[i] = 0;
1541      pully_spl1_mct_[i] = 0;
1542      pullz_spl1_mct_[i] = 0;
1543 <    
1543 >    nTrkPV_spl1_mct_[i] = 0;
1544 >    ndofPV_spl1_mct_[i] = 0;
1545 >    normchi2PV_spl1_mct_[i] = 0;
1546 >    avgPtPV_spl1_mct_[i] = 0;
1547 >    errx_spl1_mct_[i] = 0;
1548 >    erry_spl1_mct_[i] = 0;
1549 >    errz_spl1_mct_[i] = 0;
1550 >
1551      deltax_spl2_mct_[i] = 0;
1552      deltay_spl2_mct_[i] = 0;
1553      deltaz_spl2_mct_[i] = 0;
1554      pullx_spl2_mct_[i] = 0;
1555      pully_spl2_mct_[i] = 0;
1556      pullz_spl2_mct_[i] = 0;
1557 +    nTrkPV_spl2_mct_[i] = 0;
1558 +    ndofPV_spl2_mct_[i] = 0;
1559 +    normchi2PV_spl2_mct_[i] = 0;
1560 +    avgPtPV_spl2_mct_[i] = 0;
1561 +    errx_spl2_mct_[i] = 0;
1562 +    erry_spl2_mct_[i] = 0;
1563 +    errz_spl2_mct_[i] = 0;
1564 +
1565    }
1606  
1566   }
1567  
1568   double PVStudy::sumPtSquared(const reco::Vertex & v)  {
1569 <  double sum = 0.;
1570 <  double pT;
1571 <  for (reco::Vertex::trackRef_iterator it = v.tracks_begin(); it != v.tracks_end(); it++) {
1572 <    pT = (**it).pt();
1573 <    sum += pT*pT;
1569 >  if(v.isFake() || (!v.isValid()) || v.tracksSize() == 0) return 0.0;
1570 >  else {
1571 >    double sum = 0.;
1572 >    double pT;
1573 >    for (reco::Vertex::trackRef_iterator it = v.tracks_begin(); it != v.tracks_end(); it++) {
1574 >      pT = (**it).pt();
1575 >      sum += pT*pT;
1576 >    }
1577 >    return sum;
1578    }
1616  return sum;
1579   }
1580  
1581 +
1582 +
1583 + double PVStudy::avgPtRecVtx(const reco::Vertex & v)  {
1584 +
1585 +  if(v.isFake() || !v.isValid() || v.tracksSize()==0 ) return 0;
1586 +  else {
1587 +    int nHWTrk = 0;
1588 +    double sumpT = 0.;
1589 +    for (reco::Vertex::trackRef_iterator it = v.tracks_begin(); it != v.tracks_end(); it++) {
1590 +      if(v.trackWeight(*it) > 0.5 ) {
1591 +        sumpT +=  (**it).pt();
1592 +        nHWTrk++;
1593 +      }
1594 +  }
1595 +    if(nHWTrk > 0)
1596 +      return sumpT/double(nHWTrk);
1597 +    else
1598 +      return 0;
1599 +  }
1600 + }
1601 +
1602 + int PVStudy::nHWTrkRecVtx(const reco::Vertex & v)  {
1603 +  int nHWTrkPV = 0;
1604 +  for (reco::Vertex::trackRef_iterator it = v.tracks_begin(); it != v.tracks_end(); it++) {
1605 +    if(v.trackWeight(*it) > 0.5)
1606 +      nHWTrkPV++;
1607 +  }
1608 +  return nHWTrkPV;
1609 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines