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.9 by yygao, Thu Oct 29 02:05:54 2009 UTC vs.
Revision 1.19 by yygao, Sat Jan 30 18:27:09 2010 UTC

# Line 25 | Line 25 | Implementation:
25   #include <vector>
26   #include <iostream>
27   #include <sstream>
28 #include <algorithm>
28  
29   // user include files
30   #include "FWCore/Framework/interface/Frameworkfwd.h"
# Line 50 | Line 49 | Implementation:
49   #include <SimDataFormats/Vertex/interface/SimVertexContainer.h>
50   #include <SimDataFormats/Track/interface/SimTrack.h>
51   #include <SimDataFormats/Track/interface/SimTrackContainer.h>
52 + // BeamSpot
53 + #include "DataFormats/BeamSpot/interface/BeamSpot.h"
54  
55   //root
56   #include <TROOT.h>
# Line 60 | Line 61 | Implementation:
61   #include <TPad.h>
62  
63   using namespace std;
64 + typedef math::XYZTLorentzVectorF LorentzVector;
65 + typedef math::XYZPoint Point;
66  
67   PVStudy::PVStudy(const edm::ParameterSet& iConfig)
68   {
69    //=======================================================================
70    // Get configuration for TrackTupleMaker
71    //=======================================================================
72 <  simG4_           = iConfig.getParameter<edm::InputTag>( "simG4" );
73 <  trackCollectionTag_     = iConfig.getUntrackedParameter<edm::InputTag>("trackCollection");  
74 <  splitTrackCollection1Tag_     = iConfig.getUntrackedParameter<edm::InputTag>("splitTrackCollection1");
75 <  splitTrackCollection2Tag_     = iConfig.getUntrackedParameter<edm::InputTag>("splitTrackCollection2");
72 >  simG4_                     = iConfig.getParameter<edm::InputTag>( "simG4" );
73 >  trackCollectionTag_        = iConfig.getUntrackedParameter<edm::InputTag>("trackCollection");  
74 >  splitTrackCollection1Tag_  = iConfig.getUntrackedParameter<edm::InputTag>("splitTrackCollection1");
75 >  splitTrackCollection2Tag_  = iConfig.getUntrackedParameter<edm::InputTag>("splitTrackCollection2");
76    vertexCollectionTag_       = iConfig.getUntrackedParameter<edm::InputTag>("vertexCollection");
77 <  splitVertexCollection1Tag_       = iConfig.getUntrackedParameter<edm::InputTag>("splitVertexCollection1");
78 <  splitVertexCollection2Tag_       = iConfig.getUntrackedParameter<edm::InputTag>("splitVertexCollection2");
79 <  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 <  ntrkdiffcut_         = iConfig.getUntrackedParameter<double>("ntrkdiffcut");
85 <  zsigncut_         = iConfig.getUntrackedParameter<int>("zsigncut");
86 <  nTrkMin_ =  iConfig.getUntrackedParameter<int>("nTrkMin");
87 <  nTrkMax_ =  iConfig.getUntrackedParameter<int>("nTrkMax");
88 <
77 >  splitVertexCollection1Tag_ = iConfig.getUntrackedParameter<edm::InputTag>("splitVertexCollection1");
78 >  splitVertexCollection2Tag_ = iConfig.getUntrackedParameter<edm::InputTag>("splitVertexCollection2");
79 >  verbose_                   = iConfig.getUntrackedParameter<bool>("verbose",false);
80 >  realData_                  = iConfig.getUntrackedParameter<bool>("realData",false);
81 >  analyze_                   = iConfig.getUntrackedParameter<bool>("analyzeOnTheFly",false);
82 >  saventuple_                = iConfig.getUntrackedParameter<bool>("saventuple",false);  
83 >  outputfilename_            = iConfig.getUntrackedParameter<string>("OutputFileName");  
84 >  histoFileName_             = iConfig.getUntrackedParameter<std::string> ("histoFileName");
85 >  ntrkdiffcut_               = iConfig.getUntrackedParameter<double>("ntrkdiffcut");
86 >  nTrkMin_                   = iConfig.getUntrackedParameter<int>("nTrkMin");
87 >  nTrkMax_                   = iConfig.getUntrackedParameter<int>("nTrkMax");
88 >  zsigncut_                  = iConfig.getUntrackedParameter<int>("zsigncut");
89 >  bsSrc = iConfig.getParameter< edm::InputTag >("beamSpot");
90 >  
91    //now do what ever initialization is needed
92    pvinfo.clear();
93  
89  
94    // Specify the data mode vector
95    if(realData_) datamode.push_back(0);
96    else {
# Line 95 | Line 99 | PVStudy::PVStudy(const edm::ParameterSet
99      datamode.push_back(2);
100      datamode.push_back(3);
101    }
102 <
99 <  // Create ntuple files if needed
102 > // Create ntuple files if needed
103    if(saventuple_) {
104      file_ = TFile::Open(outputfilename_.c_str(),"RECREATE");
105      ftree_ = new TTree("mytree","mytree");
# Line 107 | Line 110 | PVStudy::PVStudy(const edm::ParameterSet
110  
111      // pvtxtree_ analyzing the pvtxs ootb
112      pvtxtree_ = new TTree("pvtxtree","pvtxtree");
113 <    //pvtx using all tracks
113 >
114 >    // Event information for the data
115 >    pvtxtree_->Branch("glob_runno",&glob_runno_,"glob_runno/I");
116 >    pvtxtree_->Branch("glob_evtno",&glob_evtno_,"glob_evtno/I");
117 >    pvtxtree_->Branch("glob_ls",&glob_ls_,"glob_ls/I");
118 >    pvtxtree_->Branch("glob_bx",&glob_bx_,"glob_bx/I");  
119 >    
120 >
121      pvtxtree_->Branch("nrecPV",&nrecPV_,"nrecPV/I");
112    pvtxtree_->Branch("nTrkPV",&nTrkPV_,"nTrkPV[nrecPV]/I");
113    pvtxtree_->Branch("recx",&recx_,"recx[nrecPV]/D");
114    pvtxtree_->Branch("recy",&recy_,"recy[nrecPV]/D");
115    pvtxtree_->Branch("recz",&recz_,"recz[nrecPV]/D");
116    pvtxtree_->Branch("recx_err",&recx_err_,"recx_err[nrecPV]/D");
117    pvtxtree_->Branch("recy_err",&recy_err_,"recy_err[nrecPV]/D");
118    pvtxtree_->Branch("recz_err",&recz_err_,"recz_err[nrecPV]/D");
119    //pvtx using splittracks1
122      pvtxtree_->Branch("nrecPV1_spl",&nrecPV1_spl_,"nrecPV1_spl/I");
121    pvtxtree_->Branch("nTrkPV1_spl",&nTrkPV1_spl_,"nTrkPV1_spl[nrecPV1_spl]/I");
122    pvtxtree_->Branch("recx1_spl",&recx1_spl_,"recx1_spl[nrecPV1_spl]/D");
123    pvtxtree_->Branch("recy1_spl",&recy1_spl_,"recy1_spl[nrecPV1_spl]/D");
124    pvtxtree_->Branch("recz1_spl",&recz1_spl_,"recz1_spl[nrecPV1_spl]/D");
125    pvtxtree_->Branch("recx1_err_spl",&recx1_err_spl_,"recx1_err_spl[nrecPV1_spl]/D");
126    pvtxtree_->Branch("recy1_err_spl",&recy1_err_spl_,"recy1_err_spl[nrecPV1_spl]/D");
127    pvtxtree_->Branch("recz1_err_spl",&recz1_err_spl_,"recz1_err_spl[nrecPV1_spl]/D");
128    //pvtx using splittracks2
123      pvtxtree_->Branch("nrecPV2_spl",&nrecPV2_spl_,"nrecPV2_spl/I");
124 <    pvtxtree_->Branch("nTrkPV2_spl",&nTrkPV2_spl_,"nTrkPV2_spl[nrecPV2_spl]/I");
125 <    pvtxtree_->Branch("recx2_spl",&recx2_spl_,"recx2_spl[nrecPV2_spl]/D");
126 <    pvtxtree_->Branch("recy2_spl",&recy2_spl_,"recy2_spl[nrecPV2_spl]/D");
127 <    pvtxtree_->Branch("recz2_spl",&recz2_spl_,"recz2_spl[nrecPV2_spl]/D");
128 <    pvtxtree_->Branch("recx2_err_spl",&recx2_err_spl_,"recx2_err_spl[nrecPV2_spl]/D");
129 <    pvtxtree_->Branch("recy2_err_spl",&recy2_err_spl_,"recy2_err_spl[nrecPV2_spl]/D");
130 <    pvtxtree_->Branch("recz2_err_spl",&recz2_err_spl_,"recz2_err_spl[nrecPV2_spl]/D");
131 <    //Fill the variables in the twovtx pair (recvtx1, recvtx2)
124 >    // Event level information
125 >    pvtxtree_->Branch("min_zsep",&min_zsep_,"min_zsep/D");
126 >    pvtxtree_->Branch("min_ntrksep",&min_ntrksep_,"min_ntrksep/D");
127 >    pvtxtree_->Branch("min_sumpt2sep",&min_sumpt2sep_,"min_sumpt2sep/D");
128 >
129 >    //Fill the variables in the twovtx pair (recvtx1, recvtx2)  
130 >    // Information related to the analyzing the two-vertex method
131 >
132 >
133 >
134      pvtxtree_->Branch("nrecPV_twovtx",&nrecPV_twovtx_,"nrecPV_twovtx/I");
139    pvtxtree_->Branch("nTrkPV1_spl_twovtx",&nTrkPV1_spl_twovtx_,"nTrkPV1_spl_twovtx[nrecPV_twovtx]/I");
140    pvtxtree_->Branch("nTrkPV2_spl_twovtx",&nTrkPV2_spl_twovtx_,"nTrkPV2_spl_twovtx[nrecPV_twovtx]/I");
141    pvtxtree_->Branch("sumptsq1_spl_twovtx",&sumptsq1_spl_twovtx_,"sumptsq1_spl_twovtx[nrecPV_twovtx]/D");
142    pvtxtree_->Branch("sumptsq2_spl_twovtx",&sumptsq2_spl_twovtx_,"sumptsq2_spl_twovtx[nrecPV_twovtx]/D");
135      pvtxtree_->Branch("nTrkPV_twovtx",&nTrkPV_twovtx_,"nTrkPV_twovtx[nrecPV_twovtx]/I");
136      pvtxtree_->Branch("deltax_twovtx",&deltax_twovtx_,"deltax_twovtx[nrecPV_twovtx]/D");
137      pvtxtree_->Branch("deltay_twovtx",&deltay_twovtx_,"deltay_twovtx[nrecPV_twovtx]/D");
# Line 150 | Line 142 | PVStudy::PVStudy(const edm::ParameterSet
142      pvtxtree_->Branch("pullx_twovtx",&pullx_twovtx_,"pullx_twovtx[nrecPV_twovtx]/D");
143      pvtxtree_->Branch("pully_twovtx",&pully_twovtx_,"pully_twovtx[nrecPV_twovtx]/D");
144      pvtxtree_->Branch("pullz_twovtx",&pullz_twovtx_,"pullz_twovtx[nrecPV_twovtx]/D");
145 +
146 +    // Information for the splitVertexColl1
147 +    pvtxtree_->Branch("nTrkPV1_spl_twovtx",&nTrkPV1_spl_twovtx_,"nTrkPV1_spl_twovtx[nrecPV_twovtx]/I");
148 +    pvtxtree_->Branch("ndofPV1_spl_twovtx",&ndofPV1_spl_twovtx_,"ndofPV1_spl_twovtx[nrecPV_twovtx]/D");
149 +    pvtxtree_->Branch("normchi2PV1_spl_twovtx",&normchi2PV1_spl_twovtx_,"normchi2PV1_spl_twovtx[nrecPV_twovtx]/D");
150 +    pvtxtree_->Branch("avgPtPV1_spl_twovtx",&avgPtPV1_spl_twovtx_,"avgPtPV1_spl_twovtx[nrecPV_twovtx]/D");
151 +    pvtxtree_->Branch("errx1_spl_twovtx",&errx1_spl_twovtx_,"errx1_spl_twovtx[nrecPV_twovtx]/D");
152 +    pvtxtree_->Branch("erry1_spl_twovtx",&erry1_spl_twovtx_,"erry1_spl_twovtx[nrecPV_twovtx]/D");
153 +    pvtxtree_->Branch("errz1_spl_twovtx",&errz1_spl_twovtx_,"errz1_spl_twovtx[nrecPV_twovtx]/D");
154 +  
155 +    
156 +    // Information for the splitVertexColl2
157 +    pvtxtree_->Branch("nTrkPV2_spl_twovtx",&nTrkPV2_spl_twovtx_,"nTrkPV2_spl_twovtx[nrecPV_twovtx]/I");
158 +    pvtxtree_->Branch("ndofPV2_spl_twovtx",&ndofPV2_spl_twovtx_,"ndofPV2_spl_twovtx[nrecPV_twovtx]/D");
159 +    pvtxtree_->Branch("normchi2PV2_spl_twovtx",&normchi2PV2_spl_twovtx_,"normchi2PV2_spl_twovtx[nrecPV_twovtx]/D");
160 +    pvtxtree_->Branch("avgPtPV2_spl_twovtx",&avgPtPV2_spl_twovtx_,"avgPtPV2_spl_twovtx[nrecPV_twovtx]/D");
161 +    pvtxtree_->Branch("errx2_spl_twovtx",&errx2_spl_twovtx_,"errx2_spl_twovtx[nrecPV_twovtx]/D");
162 +    pvtxtree_->Branch("erry2_spl_twovtx",&erry2_spl_twovtx_,"erry2_spl_twovtx[nrecPV_twovtx]/D");
163 +    pvtxtree_->Branch("errz2_spl_twovtx",&errz2_spl_twovtx_,"errz2_spl_twovtx[nrecPV_twovtx]/D");
164 +  
165      
166      // MC variables
167      if(!realData_) {  
# Line 167 | Line 179 | PVStudy::PVStudy(const edm::ParameterSet
179        pvtxtree_->Branch("deltaz_mct",&deltaz_mct_,"deltaz_mct[nrecPV_mct]/D");
180        pvtxtree_->Branch("pullx_mct",&pullx_mct_,"pullx_mct[nrecPV_mct]/D");
181        pvtxtree_->Branch("pully_mct",&pully_mct_,"pully_mct[nrecPV_mct]/D");
182 <      pvtxtree_->Branch("pullz_mct",&pullz_mct_,"pullz_mct[nrecPV_mct]/D");
182 >      pvtxtree_->Branch("pullz_mct",&pullz_mct_,"pullz_mct[nrecPV_mct]/D");    
183 >      pvtxtree_->Branch("errx_mct",&errx_mct_,"errx_mct[nrecPV_mct]/D");
184 >      pvtxtree_->Branch("erry_mct",&erry_mct_,"erry_mct[nrecPV_mct]/D");
185 >      pvtxtree_->Branch("errz_mct",&errz_mct_,"errz_mct[nrecPV_mct]/D");
186 >      pvtxtree_->Branch("nTrkPV_mct",&nTrkPV_mct_,"nTrkPV_mct[nrecPV_mct]/I");
187 >      pvtxtree_->Branch("ndofPV_mct",&ndofPV_mct_,"ndofPV_mct[nrecPV_mct]/D");
188 >      pvtxtree_->Branch("normchi2PV_mct",&normchi2PV_mct_,"normchi2PV_mct[nrecPV_mct]/D");
189 >      pvtxtree_->Branch("avgPtPV_mct",&avgPtPV_mct_,"avgPtPV_mct[nrecPV_mct]/D");
190 >
191        // For pvtxs with splittracks1
192        pvtxtree_->Branch("nrecPV_spl1_mct",&nrecPV_spl1_mct_,"nrecPV_spl1_mct/I");
193        pvtxtree_->Branch("deltax_spl1_mct",&deltax_spl1_mct_,"deltax_spl1_mct[nrecPV_spl1_mct]/D");
# Line 176 | Line 196 | PVStudy::PVStudy(const edm::ParameterSet
196        pvtxtree_->Branch("pullx_spl1_mct",&pullx_spl1_mct_,"pullx_spl1_mct[nrecPV_spl1_mct]/D");
197        pvtxtree_->Branch("pully_spl1_mct",&pully_spl1_mct_,"pully_spl1_mct[nrecPV_spl1_mct]/D");
198        pvtxtree_->Branch("pullz_spl1_mct",&pullz_spl1_mct_,"pullz_spl1_mct[nrecPV_spl1_mct]/D");
199 +      pvtxtree_->Branch("errx_spl1_mct",&errx_spl1_mct_,"errx_spl1_mct[nrecPV_spl1_mct]/D");
200 +      pvtxtree_->Branch("erry_spl1_mct",&erry_spl1_mct_,"erry_spl1_mct[nrecPV_spl1_mct]/D");
201 +      pvtxtree_->Branch("errz_spl1_mct",&errz_spl1_mct_,"errz_spl1_mct[nrecPV_spl1_mct]/D");
202 +      pvtxtree_->Branch("nTrkPV_spl1_mct",&nTrkPV_spl1_mct_,"nTrkPV_spl1_mct[nrecPV_spl1_mct]/I");
203 +      pvtxtree_->Branch("ndofPV_spl1_mct",&ndofPV_spl1_mct_,"ndofPV_spl1_mct[nrecPV_spl1_mct]/D");
204 +      pvtxtree_->Branch("normchi2PV_spl1_mct",&normchi2PV_spl1_mct_,"normchi2PV_spl1_mct[nrecPV_spl1_mct]/D");
205 +      pvtxtree_->Branch("avgPtPV_spl1_mct",&avgPtPV_spl1_mct_,"avgPtPV_spl1_mct[nrecPV_spl1_mct]/D");
206 +        
207        // For pvtxs with splittracks1
208        pvtxtree_->Branch("nrecPV_spl2_mct",&nrecPV_spl2_mct_,"nrecPV_spl2_mct/I");
209        pvtxtree_->Branch("deltax_spl2_mct",&deltax_spl2_mct_,"deltax_spl2_mct[nrecPV_spl2_mct]/D");
# Line 183 | Line 211 | PVStudy::PVStudy(const edm::ParameterSet
211        pvtxtree_->Branch("deltaz_spl2_mct",&deltaz_spl2_mct_,"deltaz_spl2_mct[nrecPV_spl2_mct]/D");
212        pvtxtree_->Branch("pullx_spl2_mct",&pullx_spl2_mct_,"pullx_spl2_mct[nrecPV_spl2_mct]/D");
213        pvtxtree_->Branch("pully_spl2_mct",&pully_spl2_mct_,"pully_spl2_mct[nrecPV_spl2_mct]/D");
214 <      pvtxtree_->Branch("pullz_spl2_mct",&pullz_spl2_mct_,"pullz_spl2_mct[nrecPV_spl2_mct]/D");
214 >      pvtxtree_->Branch("pullz_spl2_mct",&pullz_spl2_mct_,"pullz_spl2_mct[nrecPV_spl2_mct]/D");  
215 >      pvtxtree_->Branch("errx_spl2_mct",&errx_spl2_mct_,"errx_spl2_mct[nrecPV_spl2_mct]/D");
216 >      pvtxtree_->Branch("erry_spl2_mct",&erry_spl2_mct_,"erry_spl2_mct[nrecPV_spl2_mct]/D");
217 >      pvtxtree_->Branch("errz_spl2_mct",&errz_spl2_mct_,"errz_spl2_mct[nrecPV_spl2_mct]/D");  
218 >      pvtxtree_->Branch("nTrkPV_spl2_mct",&nTrkPV_spl2_mct_,"nTrkPV_spl2_mct[nrecPV_spl2_mct]/I");
219 >      pvtxtree_->Branch("ndofPV_spl2_mct",&ndofPV_spl2_mct_,"ndofPV_spl2_mct[nrecPV_spl2_mct]/D");
220 >      pvtxtree_->Branch("normchi2PV_spl2_mct",&normchi2PV_spl2_mct_,"normchi2PV_spl2_mct[nrecPV_spl2_mct]/D");
221 >      pvtxtree_->Branch("avgPtPV_spl2_mct",&avgPtPV_spl2_mct_,"avgPtPV_spl2_mct[nrecPV_spl2_mct]/D");
222 >
223      }
224    }
225 <
190 <  edm::Service<TFileService> fs;
191 <  TFileDirectory subDir = fs->mkdir( "Summary" );
192 <  TFileDirectory subDir1 = fs->mkdir( "Others" );
193 <  //   TFileDirectory subSubDir = subDir.mkdir( "mySubSubDirectory" );
194 <
225 >  
226    setRootStyle();
227 +
228 +  //========================================
229 +  // Booking histograms
230 +  //========================================
231    
232 <  //Book histograms for track and pvtx parameters for each splitted pvtx
233 <  //i=0 : x (as in unsplit track collection)
234 <  //i=1 : x1_spl_
235 <  //i=2 : x2_spl_
236 <  
237 <  for(int i=0;i<3;i++)
238 <    {  
239 <      string suffix;
240 <      if(i == 0) suffix = "";
241 <      else {
242 <        stringstream ss;
243 <        ss << i;
244 <        suffix =ss.str()+"_spl";  
245 <      }
246 <      h["nTrk"+suffix]   = subDir.make<TH1D>(TString("nTrk"+suffix), TString("Num of rec tracks"+suffix),300,0,300);
247 <      h["trkPt"+suffix]  = subDir.make<TH1D>(TString("trkPt"+suffix), TString("Pt of rec tracks "+suffix),100,0,100);
248 <      h["trkEta"+suffix] = subDir.make<TH1D>(TString("trkEta"+suffix), TString("#eta of rec tracks "+suffix),100,-3,3);
249 <      h["trkPhi"+suffix] = subDir.make<TH1D>(TString("trkPhi"+suffix), TString("#Phi of rec tracks "+suffix),100,-3.2,3.2);
250 <      h["trkDxy"+suffix] = subDir.make<TH1D>(TString("trkDxy"+suffix), TString("Dxy of rec tracks "+suffix),100,-5,5);  
251 <      h["trkDz"+suffix] = subDir.make<TH1D>(TString("trkDz"+suffix), TString("Dz of rec tracks "+suffix),100,-50,50);  
252 <      
253 <      h["nTrkPV"+suffix]   = subDir.make<TH1D>(TString("nTrkPV"+suffix), TString("Num of rec tracks in PV"+suffix),300,0,300);
254 <      h["trkPtPV"+suffix]  = subDir.make<TH1D>(TString("trkPtPV"+suffix), TString("Pt of rec tracks in "+suffix),100,0,100);
255 <      h["trkEtaPV"+suffix] = subDir.make<TH1D>(TString("trkEtaPV"+suffix), TString("#eta of rec tracks in PV"+suffix),100,-3,3);
221 <      h["trkPhiPV"+suffix] = subDir.make<TH1D>(TString("trkPhiPV"+suffix), TString("#Phi of rec tracks in PV"+suffix),100,-3.2,3.2);
222 <      h["trkDxyPV"+suffix] = subDir.make<TH1D>(TString("trkDxyPV"+suffix), TString("Dxy of rec tracks in PV"+suffix),100,-5,5);  
223 <      h["trkDzPV"+suffix] = subDir.make<TH1D>(TString("trkDzPV"+suffix), TString("Dz of rec tracks "+suffix),100,-50,50);
224 <      h["nrecPV"+suffix]   = subDir.make<TH1D>(TString("nrecPV"+suffix), TString("Num of rec pvtx"+suffix),50,0,50);    
225 <      suffix.clear();
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 <  
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 242 | 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);
246 <    h["deltay"+suffix] = subDir.make<TH1D>(TString("deltay"+suffix), TString("y-residual pvtx"+suffix),800,-0.04,0.04);
247 <    h["deltaz"+suffix] = subDir.make<TH1D>(TString("deltaz"+suffix), TString("z-residual pvtx"+suffix),800,-0.04,0.04);
248 <    h["pullx"+suffix]  = subDir.make<TH1D>(TString("pullx"+suffix), TString("x-pull pvtx"+suffix),800,-10,10);
249 <    h["pully"+suffix]  = subDir.make<TH1D>(TString("pully"+suffix), TString("y-pull pvtx"+suffix),800,-10,10);
250 <    h["pullz"+suffix]  = subDir.make<TH1D>(TString("pullz"+suffix), TString("z-pull pvtx"+suffix),800,-10,10);
251 <    h["errPVx"+suffix] = subDir.make<TH1D>(TString("errPVx"+suffix), TString("X"+suffix+" vertex error"),100,0.,0.02);
252 <    h["errPVy"+suffix] = subDir.make<TH1D>(TString("errPVy"+suffix), TString("Y"+suffix+" vertex error"),100,0.,0.02);
253 <    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");
262 <      h["deltay"+suffix2]  = subDir1.make<TH1D>(TString("deltay"+suffix2), TString("y-residual of pvtx"+suffix),100,-0.02,0.02);
263 <      h["deltay"+suffix2]->GetXaxis()->SetTitle("cm");
264 <      h["deltaz"+suffix2]  = subDir1.make<TH1D>(TString("deltaz"+suffix2), TString("z-residual of pvtx"+suffix),100,-0.02,0.02);
265 <      h["deltaz"+suffix2]->GetXaxis()->SetTitle("cm");
266 <      h["pullx"+suffix2] = subDir1.make<TH1D>(TString("pullx"+suffix2), TString("x-pull of pvtx"+suffix),100,-10.,10.);
267 <      h["pully"+suffix2] = subDir1.make<TH1D>(TString("pully"+suffix2), TString("y-pull of pvtx"+suffix),100,-10.,10.);
268 <      h["pullz"+suffix2] = subDir1.make<TH1D>(TString("pullz"+suffix2), TString("z-pull of pvtx"+suffix),100,-10.,10.);
269 <      h["errPVx"+suffix2] = subDir1.make<TH1D>(TString("errPVx"+suffix2), TString("X"+suffix+" vertex error"),100,0.,0.02);
270 <      h["errPVy"+suffix2] = subDir1.make<TH1D>(TString("errPVy"+suffix2), TString("Y"+suffix+" vertex error"),100,0.,0.02);
271 <      h["errPVz"+suffix2] = subDir1.make<TH1D>(TString("errPVz"+suffix2), TString("Z"+suffix+" vertex error"),100,0.,0.02);
272 <      suffix2.clear();
273 <    } // End of   for (int ntrk=nTrkMin_;ntrk<=nTrkMax_;++ntrk) {
274 <    
287 >      h_others->Init("others",suffix,ss.str());
288 >    }
289 >
290      // Book residual and pull histograms only when analyzeOntheFly is enabled
291 <    if(analyze_) {
277 <      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);
278 <      h2["resx"+suffix+"_nTrk"]->SetMarkerStyle(21);
279 <      h2["resx"+suffix+"_nTrk"]->SetMarkerColor(4);
280 <      h2["resx"+suffix+"_nTrk"]->GetXaxis()->SetTitle("Num of tracks");
281 <      h2["resx"+suffix+"_nTrk"]->GetYaxis()->SetTitle("#mum");
282 <      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);
283 <      h2["resy"+suffix+"_nTrk"]->SetMarkerStyle(21);
284 <      h2["resy"+suffix+"_nTrk"]->SetMarkerColor(4);
285 <      h2["resy"+suffix+"_nTrk"]->GetXaxis()->SetTitle("Num of tracks");
286 <      h2["resy"+suffix+"_nTrk"]->GetYaxis()->SetTitle("#mum");
287 <      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);
288 <      h2["resz"+suffix+"_nTrk"]->SetMarkerStyle(21);
289 <      h2["resz"+suffix+"_nTrk"]->SetMarkerColor(4);
290 <      h2["resz"+suffix+"_nTrk"]->GetXaxis()->SetTitle("Num of tracks");
291 <      h2["resz"+suffix+"_nTrk"]->GetYaxis()->SetTitle("#mum");
292 <      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.);
293 <      h2["pullx"+suffix+"_nTrk"]->SetMarkerStyle(21);
294 <      h2["pullx"+suffix+"_nTrk"]->SetMarkerColor(4);
295 <      h2["pullx"+suffix+"_nTrk"]->SetBit(TH1::kCanRebin);
296 <      h2["pullx"+suffix+"_nTrk"]->GetXaxis()->SetTitle("Num of tracks");
297 <      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.);
298 <      h2["pully"+suffix+"_nTrk"]->SetMarkerStyle(21);
299 <      h2["pully"+suffix+"_nTrk"]->SetMarkerColor(4);
300 <      h2["pully"+suffix+"_nTrk"]->SetBit(TH1::kCanRebin);
301 <      h2["pully"+suffix+"_nTrk"]->GetXaxis()->SetTitle("Num of tracks");
302 <      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.);
303 <      h2["pullz"+suffix+"_nTrk"]->SetMarkerStyle(21);
304 <      h2["pullz"+suffix+"_nTrk"]->SetMarkerColor(4);
305 <      h2["pullz"+suffix+"_nTrk"]->SetBit(TH1::kCanRebin);
306 <      h2["pullz"+suffix+"_nTrk"]->GetXaxis()->SetTitle("Num of tracks");
307 <    } // 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 <  // Book MC only plots
295 <  if (!realData_) {  
312 <    h["genPart_T"]      = subDir.make<TH1D>("genPart_T","t component of gen particles",300,-0.5,0.5);
313 <    h["genPart_T"]->GetXaxis()->SetTitle("t (nanosecond)");
314 <    h["genPart_cT"]     = subDir.make<TH1D>("genPart_cT","ct component of gen particles",300,-150.,150.);
315 <    h["genPart_cT"]->GetXaxis()->SetTitle("ct (mm)");    
316 <    h["nsimPV"]         = subDir.make<TH1D>("nsimPV","Num of sim PV",51,-0.5,50.5);  
317 <  }
293 >  } // End of Book histograms sensitive to data/mc    
294 >  
295 >
296   }
297  
298   PVStudy::~PVStudy()
# Line 322 | 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 346 | 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 359 | 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;
369 <      cout << "number of vertices " << evt->vertices_size() << endl;
370 <    }
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 378 | 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 392 | 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 423 | 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 451 | 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 485 | 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 534 | 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
541  //=======================================================
542  //if(saventuple_)
539    SetVarToZero();
540    
541 <  //=======================================================
546 <  // Track accessors
547 <  //=======================================================
548 <  //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 553 | 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 <  //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 563 | 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 <  //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 573 | 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 <  //=======================================================
580 <  // PVTX accessors
581 <  //=======================================================
582 <  //vertexCollection
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 587 | 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 <  //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 597 | 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;
590 >    edm::LogInfo("Debug") << "[PVStudy] splitVertexCollection1 cannot be found -> using empty collection of same type." <<endl;
591    }
592 <  //splitVertexCollection2
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 607 | 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  
613  if(verbose_) cout<<"End accessing the track and vertex collections"<<endl;
603    
604 <  //=======================================================
605 <  // MC simvtx accessor
606 <  //=======================================================
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 >  edm::LogInfo("Debug")<<"[PVStudy] End accessing the track, beamSpot, primary vertex collections"<<endl;
611 >  
612 >  // ========== MC simvtx accessor
613    if (!realData_) {
614      edm::Handle<SimVertexContainer> simVtxs;
615      iEvent.getByLabel( simG4_, simVtxs);
# Line 623 | Line 618 | PVStudy::analyze(const edm::Event& iEven
618      iEvent.getByLabel( simG4_, simTrks);
619    }
620  
621 <  //=======================================================
627 <  // GET PDT
628 <  //=======================================================
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 >  // ======= Get MC information if needed
629 >  bool MC=false;  
630 >  Handle<HepMCProduct> evtMC;
631 >  if (!realData_) {
632 >    iEvent.getByLabel("generator",evtMC);
633 >    if (!evtMC.isValid()) {
634 >      MC=false;
635 >      edm::LogInfo("Debug") << "[PVStudy] no HepMCProduct found"<< endl;
636 >    } else {
637 >      edm::LogInfo("Debug") << "[PVStudy] generator HepMCProduct found"<< endl;
638 >      MC=true;
639 >    }
640    }
641  
642 <  //=======================================================
643 <  // Fill trackparameters of the input tracks to pvtx fitter
644 <  //=======================================================
642 >  //========================================================================
643 >  // Step 1:  Apply event cleaning for data and MC
644 >  //          WARNING: event selection cut are hard coded!!
645 >  //========================================================================
646 >  // =====Loop over the trackColl to get the fraction of HighPurity tracks
647 >  int nTracks = 0;
648 >  int nHighPurityTracks=0;
649 >  double fHighPurity=0;
650 >
651 >  for (unsigned int i=0; i<trackCollectionHandle->size(); i++, nTracks++) {
652 >    TrackRef tkref(trackCollectionHandle,i);
653 >    if(tkref->quality(reco::TrackBase::highPurity)) ++nHighPurityTracks;
654 >  }
655 >  if(nTracks>0)
656 >    fHighPurity =  double(nHighPurityTracks)/double(nTracks);
657    if(verbose_)
658 <    cout<<"Start filling track parameters of the input tracks to pvtx fitter."<<endl;
659 <  //fillTrackHisto(const reco::TrackCollection *trackColl, int datatype)
658 >    cout<<"fraction of HighPurity track is "<<fHighPurity<<endl;  
659 >    
660 >  if( (fHighPurity<0.2 && nTracks>10) || vertexColl->begin()->isFake()) {
661 >    glob_runno_ = iEvent.id().run();
662 >    glob_evtno_ = iEvent.id().event();
663 >    glob_ls_   = iEvent.luminosityBlock();
664 >    glob_bx_  = iEvent.bunchCrossing();  
665 >    return;
666 >  }
667 >
668 >  //========================================================================
669 >  // Step 2: Fill histograms for the splitting consistency checks
670 >  //========================================================================
671 >  
672 >  // === Fill trackparameters of the input tracks to pvtx fitter
673 >  edm::LogInfo("Debug")<<"[PVStudy] Start filling track parameters of the input tracks to pvtx fitter."<<endl;
674 >  //fillTrackHisto(const reco::TrackCollection *trackColl, int datatype, const Point & bs)
675    // datatype: unsplittracks (0); splittracks1 (1);  splittracks2 (2);
676 <  fillTrackHisto(trackColl, 0);
677 <  fillTrackHisto(splitTrackColl1, 1);
678 <  fillTrackHisto(splitTrackColl2, 2);
679 <  if(verbose_)
680 <    cout<<"End filling track parameters of the input tracks to pvtx fitter."<<endl;
681 <
682 <  //=======================================================
683 <  // Fill reconstructed vertices ootb
684 <  //=======================================================
685 <  if(verbose_)  {
686 <    cout<<"PVStudy::analyze() Printing vertexCollection: "<<endl;
676 >  fillTrackHisto(trackColl, 0, beamSpot);
677 >  fillTrackHisto(splitTrackColl1, 1, beamSpot);
678 >  fillTrackHisto(splitTrackColl2, 2, beamSpot);
679 >  edm::LogInfo("Debug")<<"[PVStudy] End filling track parameters of the input tracks to pvtx fitter."<<endl;
680 >  
681 >  
682 >  // ==== Fill number of reconstructed vertices
683 >  edm::LogInfo("Debug")<<"[PVStudy] Printing vertexCollection: "<<endl;
684 >  edm::LogInfo("Debug")<<"[PVStudy] Printing splitVertexCollection1: "<<endl;
685 >  edm::LogInfo("Debug")<<"[PVStudy] Printing splitVertexCollection2: "<<endl;
686 >  edm::LogInfo("Debug")<<"[PVStudy] Start filling pvtx parameters."<<endl;
687 >  if (verbose_) {
688      printRecVtxs(vertexCollectionHandle);
654    cout<<"PVStudy::analyze() Printing splitVertexCollection1: "<<endl;
689      printRecVtxs(splitVertexCollection1Handle);
656    cout<<"PVStudy::analyze() Printing splitVertexCollection2: "<<endl;
690      printRecVtxs(splitVertexCollection2Handle);
658    cout<<"Start filling pvtx parameters."<<endl;
691    }
692 <    
692 >
693    nrecPV_ = int (vertexColl->size());
694    nrecPV1_spl_ = int (splitVertexColl1->size());
695    nrecPV2_spl_ = int (splitVertexColl2->size());
696  
697 <  h["nrecPV"]->Fill(nrecPV_);
698 <  h["nrecPV1_spl"]->Fill(nrecPV1_spl_);
699 <  h["nrecPV2_spl"]->Fill(nrecPV2_spl_);
700 <  h["nrecPVDiff"]->Fill(double(nrecPV1_spl_)-double(nrecPV2_spl_));
697 >  h_pvtrk->Fill1d("nrecPV", nrecPV_);
698 >  h_pvtrk->Fill1d("nrecPV1_spl", nrecPV1_spl_);
699 >  h_pvtrk->Fill1d("nrecPV2_spl", nrecPV2_spl_);
700 >  h_misc->Fill1d("nrecPVDiff", double(nrecPV1_spl_)-double(nrecPV2_spl_));
701 >  
702 >  
703 >  // ======= Fill track parameter ntuple/hist for tracks used in recoVertices
704 >  //fillTrackHistoInPV(const reco::VertexCollection *vertexColl, int datatype, const Point & bs) {
705 >  if(vertexColl->size() > 0 && vertexColl->begin()->isValid() && !(vertexColl->begin()->isFake()))
706 >    fillTrackHistoInPV(vertexColl, 0, beamSpot);
707 >  
708 >  // ======= Fill secondary/primary min separations for multi-vertices
709 >  if(vertexColl->size()>1 && vertexColl->begin()->isValid() && !(vertexColl->begin()->isFake()) ) {  
710 >    double min_xsep = 9999.0;
711 >    double min_ysep = 9999.0;
712 >    double min_zsep = 9999.0;    
713 >    double min_xsep_sign = 9999.0;
714 >    double min_ysep_sign = 9999.0;
715 >    double min_zsep_sign = 9999.0;
716 >    double min_ntrksep = 9999.0;
717 >    double min_sumpt2sep = 9999999.0;
718      
719 <  //fillTrackHistoInPV(const reco::VertexCollection *vertexColl, int datatype, bool fillHisto, bool fillNtuple) {
720 <  fillTrackHistoInPV(vertexColl, 0, true, true);
721 <  fillTrackHistoInPV(splitVertexColl1, 1, false, true);
722 <  fillTrackHistoInPV(splitVertexColl2, 2, false, true);
723 <  if(verbose_)
724 <    cout<<"End filling pvtx parameters."<<endl;
719 >    edm::LogInfo("Debug")<<"[PVStudy] leading pvtx z = "<< vertexColl->begin()->z() <<endl;
720 >
721 >    // Looping through the secondary vertices to find the mininum separation to the primary
722 >    for(reco::VertexCollection::const_iterator v=vertexColl->begin() + 1 ;
723 >        v!=vertexColl->end(); ++v) {  
724 >      if(v->isValid() && ! v->isFake()) {
725 >        // xsep
726 >        if(fabs(v->x()- vertexColl->begin()->x())<min_xsep)
727 >          min_xsep = fabs(v->x()- vertexColl->begin()->x());
728 >        // ysep
729 >        if(fabs(v->y()- vertexColl->begin()->y())<min_ysep)
730 >          min_ysep = fabs(v->y()- vertexColl->begin()->y());
731 >        // zsep
732 >        if(fabs(v->z()- vertexColl->begin()->z())<min_zsep)
733 >          min_zsep = fabs(v->z()- vertexColl->begin()->z());
734 >        // xsep_sign
735 >        double xsep_sign = fabs(v->x()- vertexColl->begin()->x())/max(v->xError(), vertexColl->begin()->xError());
736 >        if(xsep_sign < min_xsep_sign)
737 >          min_xsep_sign = xsep_sign;
738 >        // ysep_sign
739 >        double ysep_sign = fabs(v->y()- vertexColl->begin()->y())/max(v->yError(), vertexColl->begin()->yError());
740 >        if(ysep_sign < min_ysep_sign)
741 >          min_ysep_sign = ysep_sign;
742 >        // zsep_sign
743 >        double zsep_sign = fabs(v->z()- vertexColl->begin()->z())/max(v->zError(), vertexColl->begin()->zError());
744 >        if(zsep_sign < min_zsep_sign)
745 >          min_zsep_sign = zsep_sign;
746 >        // ntrksep
747 >        if( (double(vertexColl->begin()->tracksSize()) - double(v->tracksSize())) < min_ntrksep)
748 >          min_ntrksep = double(vertexColl->begin()->tracksSize()) - double(v->tracksSize());
749 >        // sumpt2sep
750 >        if(fabs(sumPtSquared(*v) - sumPtSquared(*(vertexColl->begin()))) < min_sumpt2sep)
751 >          min_sumpt2sep = fabs(sumPtSquared(*v) - sumPtSquared(*(vertexColl->begin())));
752 >      }
753 >    }
754 >    h_misc->Fill1d("min_xsep", min_xsep);
755 >    h_misc->Fill1d("min_ysep", min_ysep);
756 >    h_misc->Fill1d("min_zsep", min_zsep);
757 >    h_misc->Fill1d("min_xsep_sign", min_xsep_sign);
758 >    h_misc->Fill1d("min_ysep_sign", min_ysep_sign);
759 >    h_misc->Fill1d("min_zsep_sign", min_zsep_sign);
760 >    h_misc->Fill1d("min_ntrksep", min_ntrksep);
761 >    h_misc->Fill1d("min_sumpt2sep", min_sumpt2sep);
762 >
763 >    min_zsep_ = min_zsep;
764 >    min_ntrksep_ = min_ntrksep;
765 >    min_sumpt2sep_ = min_sumpt2sep;
766 >  } // End of  if(vertexColl->size()>1) {
767    
768 <  //=======================================================
678 <  //           PrimaryVertex Matching
679 <  // 1. In z  |z1-z2|< zsigncut * max(sigmaz1, sigmaz2)
680 <  // 2. |(nTrkPV1 - nTrkPV2)/(nTrkPV1+nTrkPV2)|<ntrkdiffcut_
681 <  // Assume the first match is the primary vertex,
682 <  // since vertexColl are sorted in decreasing order of sum(pT)
683 <  //=======================================================
768 >  edm::LogInfo("Debug")<<"[PVStudy] End filling pvtx parameters."<<endl;
769  
770 <  if(verbose_)   cout<<"PVStudy::analyze(): matching pvtxs "<<endl;
770 >  //========================================================================
771 >  // Step 3:  PrimaryVertex Matching
772 >  //   1. In z  |z1-z2|< zsigncut * max(sigmaz1, sigmaz2)
773 >  //   2. |(nTrkPV1 - nTrkPV2)/(nTrkPV1+nTrkPV2)|<ntrkdiffcut_
774 >  //   3. The first match is the primary vertex, which has largest sum(pT^2)
775 >  //========================================================================
776 >  
777 >  edm::LogInfo("Debug")<<"[PVStudy] matching pvtxs "<<endl;
778    reco::VertexCollection s_empty_matchedVertexColl1;
779    reco::VertexCollection *matchedVertexColl1 = &s_empty_matchedVertexColl1;
780    matchedVertexColl1->reserve(splitVertexColl1->size());
# Line 690 | Line 782 | PVStudy::analyze(const edm::Event& iEven
782    reco::VertexCollection *matchedVertexColl2 = &s_empty_matchedVertexColl2;
783    matchedVertexColl2->reserve(splitVertexColl2->size());
784    
785 <  for (size_t ivtx = 0; ivtx<splitVertexCollection1Handle->size(); ++ivtx) {
785 >  bool stopmatching = false;
786 >  for (size_t ivtx = 0; ivtx<splitVertexCollection1Handle->size() && !stopmatching; ++ivtx) {
787      reco::VertexRef recvtx1(splitVertexCollection1Handle, ivtx);
788 <    for (size_t jvtx = ivtx; jvtx < splitVertexCollection2Handle->size(); ++jvtx) {
788 >    if( !(recvtx1->isValid()) || recvtx1->isFake()) break;
789 >    for (size_t jvtx = ivtx; jvtx < splitVertexCollection2Handle->size(); ++jvtx) {    
790 >      //------------------------------------------------------------------------
791 >      //== If only considering matching the first vertex of the splitVertexColl
792 >      //------------------------------------------------------------------------
793 >      if (ivtx!=0 || jvtx!=0) { stopmatching = true; break; }
794        reco::VertexRef recvtx2(splitVertexCollection2Handle, jvtx);
795 +      if( !(recvtx2->isValid()) || recvtx2->isFake()) break;
796 +      edm::LogInfo("Debug")<<"[PVStudy] Matching splitVertexColl1: #  "<< ivtx<< " and splitVertexColl1: # "<<jvtx<<endl;
797 +      edm::LogInfo("Debug")<<"[PVStudy] recvtx1->z() = " << recvtx1->z() << "+/- "<< recvtx1->zError() << "." << endl;
798 +      edm::LogInfo("Debug")<<"[PVStudy] recvtx2->z() = " << recvtx2->z() << "+/- "<< recvtx2->zError() << "." << endl;
799 +      
800 +      double twovtxsig = (recvtx1->z()-recvtx2->z())/max(recvtx1->zError(), recvtx2->zError());
801 +      h_misc->Fill1d("twovtxzsign", twovtxsig);
802        if(matchVertex(recvtx1, recvtx2, zsigncut_)) {
803 <        if(verbose_) {
804 <          cout<<"The two splitted vertices match in Z: "<<endl;
700 <          cout<<"recvtx1->z() = " << recvtx1->z() << "+/- "<< recvtx1->zError() << "." << endl;
701 <          cout<<"recvtx2->z() = " << recvtx2->z() << "+/- "<< recvtx2->zError() << "." << endl;
702 <        }
803 >        edm::LogInfo("Debug")<<"[PVStudy] The two splitted vertices match in Z. "<<endl;
804 >
805          int nTrkPV1 = recvtx1->tracksSize();
806          int nTrkPV2 = recvtx2->tracksSize();    
807          double ntrkreldiff = double(nTrkPV1-nTrkPV2)/double(nTrkPV1+nTrkPV2);
808 <        h["nTrkPVDiff"]->Fill(nTrkPV1-nTrkPV2);
809 <        h["nTrkPVRelDiff"]->Fill(ntrkreldiff);
808 >        h_misc->Fill1d("nTrkPVDiff", nTrkPV1-nTrkPV2);
809 >        h_misc->Fill1d("nTrkPVRelDiff", ntrkreldiff);
810          if(fabs(ntrkreldiff)<ntrkdiffcut_) {    
811 <          if(verbose_) {
812 <            cout<<"(nTrkPV1-nTrkPV2)/(nTrkPV1+nTrkPV2) = " << ntrkreldiff<<endl;
711 <          }
811 >          edm::LogInfo("Debug")<<"[PVStudy] (nTrkPV1-nTrkPV2)/(nTrkPV1+nTrkPV2) = " << ntrkreldiff<<endl;
812 >
813            matchedVertexColl1->push_back(*recvtx1);
814            matchedVertexColl2->push_back(*recvtx2);
815 <          continue;
815 >          stopmatching = true; // stop the matching when the first match is found!
816 >          break;
817          }
818          else
819 <          cout<<"WARNING: (nTrkPV1-nTrkPV2)/(nTrkPV1+nTrkPV2) = " << ntrkreldiff<<", exceeding cut "<<ntrkdiffcut_<<endl;
819 >          edm::LogInfo("Debug")<<"WARNING: (nTrkPV1-nTrkPV2)/(nTrkPV1+nTrkPV2) = " << ntrkreldiff<<", exceeding cut "<<ntrkdiffcut_<<endl;
820        }
821        else {
822 <        cout<<"WARNING: The two reconstructed vertices do not match in z: "<<endl;
823 <        cout<<"recvtx1->z() = " << recvtx1->z() << "+/- "<< recvtx1->zError() << "." << endl;
824 <        cout<<"recvtx2->z() = " << recvtx2->z() << "+/- "<< recvtx2->zError() << "." << endl;  
822 >        edm::LogInfo("Debug")<<"WARNING: The two reconstructed vertices do not match in z: "<<endl;
823 >        edm::LogInfo("Debug")<<"recvtx1->z() = " << recvtx1->z() << "+/- "<< recvtx1->zError() << "." << endl;
824 >        edm::LogInfo("Debug")<<"recvtx2->z() = " << recvtx2->z() << "+/- "<< recvtx2->zError() << "." << endl;  
825        }
826      }
827    }
828 <  if(verbose_)     cout<<"PVStudy::analyze(): End matching pvtxs"<<endl;
727 <  
728 <  //=======================================================
729 <  //  Analyze matchedVertexColls
730 <  //=======================================================
731 <  if(verbose_) {
732 <    cout<<"Begin analyzing the matchedVertexColl with size = "<< matchedVertexColl1->size()<< endl;
733 <  }    
828 >  edm::LogInfo("Debug")<<"[PVStudy] End matching pvtxs"<<endl;
829  
830 +  //========================================================================
831 +  // Step 4: Analyze matchedVertexColls
832 +  //========================================================================
833 +  edm::LogInfo("Debug")<<"[PVStudy] Begin analyzing the matchedVertexColl with size = "<< matchedVertexColl1->size()<< endl;
834 +  
835 +  // ==== If it is MC, analyze the res/pull of the unsplit vertexColl first
836 +  if(MC){
837 +    // make a list of primary vertices:
838 +    std::vector<simPrimaryVertex> simpv;
839 +    simpv=getSimPVs(evtMC,"");
840 +    //     simpv=getSimPVs(evtMC, simVtxs, simTrks);
841 +    h_gen->Fill1d("nsimPV", simpv.size());
842 +    nsimPV_ = simpv.size();
843 +    int isimpv = 0;
844 +    for(std::vector<simPrimaryVertex>::iterator vsim=simpv.begin();
845 +        vsim!=simpv.end(); vsim++, isimpv++){
846 +      nsimTrkPV_[isimpv]  =vsim->nGenTrk;
847 +      simx_[isimpv] = vsim->x;
848 +      simy_[isimpv] = vsim->y;
849 +      simz_[isimpv] = vsim->y;
850 +      simptsq_[isimpv] = vsim->ptsq;
851 +      //fillMCHisto((std::vector<simPrimaryVertex>::iterator vsim, int isimpv, const reco::VertexCollection *vtxColl, int datatype) {
852 +      fillMCHisto(vsim, isimpv, vertexColl, 3);
853 +    }
854 +  }
855    
856    // Compare the reconstructed vertex position and calculate resolution/pulls
857    if(matchedVertexColl1->size() != 0 && matchedVertexColl2->size() != 0) {  
858 <    //fillPvtxHisto(const reco::VertexCollection *vertexColl, int datatype, bool fillHisto, bool fillNtuple)
859 <    fillTrackHistoInPV(matchedVertexColl1, 1, true, false);
860 <    fillTrackHistoInPV(matchedVertexColl2, 2, true, false);
858 >    // ==== Analyze the splitted vtx using MC method
859 >    if(MC){
860 >      // make a list of primary vertices:
861 >      std::vector<simPrimaryVertex> simpv;
862 >      simpv=getSimPVs(evtMC,"");
863 >      //     simpv=getSimPVs(evtMC, simVtxs, simTrks);
864 >      int isimpv = 0;
865 >      for(std::vector<simPrimaryVertex>::iterator vsim=simpv.begin();
866 >          vsim!=simpv.end(); vsim++, isimpv++){
867 >        //fillMCHisto((std::vector<simPrimaryVertex>::iterator vsim, int isimpv, const reco::VertexCollection *vtxColl, int datatype) {
868 >        fillMCHisto(vsim, isimpv, matchedVertexColl1, 1);
869 >        fillMCHisto(vsim, isimpv, matchedVertexColl2, 2);
870 >      }
871 >    }
872 >
873 >    // ==== Analyze res/pull two-vertex method
874 >    //fillPvtxHisto(const reco::VertexCollection *vertexColl, int datatype)
875 >    fillTrackHistoInPV(matchedVertexColl1, 1, beamSpot);
876 >    fillTrackHistoInPV(matchedVertexColl2, 2, beamSpot);
877  
878      reco::VertexCollection::const_iterator v1;
879      reco::VertexCollection::const_iterator v2;
880 +
881      nrecPV_twovtx_ = 0;
882      for(v1 = matchedVertexColl1->begin(), v2 = matchedVertexColl2->begin();
883          v1!=matchedVertexColl1->end(), v2 != matchedVertexColl2->end();
884 <        ++v1, ++v2) {
884 >        ++v1, ++v2) {
885 >      h_misc->Fill1d("ndofPVDiff", v1->ndof() - v2->ndof());
886 >      h_misc->Fill1d("ndofPVRelDiff", (v1->ndof()-v2->ndof())/(v1->ndof()+v2->ndof()));
887        fres_[0] = (v1->x()-v2->x())/sqrt(2.0);
888        fres_[1] = (v1->y()-v2->y())/sqrt(2.0);
889        fres_[2] = (v1->z()-v2->z())/sqrt(2.0);
# Line 753 | Line 892 | PVStudy::analyze(const edm::Event& iEven
892        ferror_[2] = sqrt(pow(v1->zError(),2)+pow(v2->zError(),2))/sqrt(2);
893        fntrk_ =  (v1->tracksSize()+v2->tracksSize())/2;
894        
895 <      h["deltax"]->Fill( fres_[0] );
896 <      h["deltay"]->Fill( fres_[1] );
897 <      h["deltaz"]->Fill( fres_[2] );
898 <      h["pullx"]->Fill( fres_[0]/ferror_[0]);
899 <      h["pully"]->Fill( fres_[1]/ferror_[1]);
900 <      h["pullz"]->Fill( fres_[2]/ferror_[2]);
901 <      h["errPVx"]->Fill( ferror_[0] );
902 <      h["errPVy"]->Fill( ferror_[1] );
903 <      h["errPVz"]->Fill( ferror_[2] );
895 >      h_summary->Fill1d("deltax", fres_[0] );
896 >      h_summary->Fill1d("deltay", fres_[1] );
897 >      h_summary->Fill1d("deltaz", fres_[2] );
898 >      h_summary->Fill1d("pullx", fres_[0]/ferror_[0]);
899 >      h_summary->Fill1d("pully", fres_[1]/ferror_[1]);
900 >      h_summary->Fill1d("pullz", fres_[2]/ferror_[2]);
901 >      h_summary->Fill1d("errPVx", ferror_[0] );
902 >      h_summary->Fill1d("errPVy", ferror_[1] );
903 >      h_summary->Fill1d("errPVz", ferror_[2] );
904        pvinfo.push_back(PVStudy::PVInfo(res(fres_[0], fres_[1], fres_[2]),
905                                         error(ferror_[0], ferror_[1], ferror_[2]),
906                                         fntrk_));
# Line 769 | Line 908 | PVStudy::analyze(const edm::Event& iEven
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
773      nTrkPV1_spl_twovtx_[nrecPV_twovtx_] = v1->tracksSize();
774      nTrkPV2_spl_twovtx_[nrecPV_twovtx_] = v2->tracksSize();
775      sumptsq1_spl_twovtx_[nrecPV_twovtx_] = sumPtSquared(*v1);
776      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 784 | 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 +      
927 +      nTrkPV1_spl_twovtx_[nrecPV_twovtx_] = v1->tracksSize();
928 +      ndofPV1_spl_twovtx_[nrecPV_twovtx_] = v1->ndof();
929 +      normchi2PV1_spl_twovtx_[nrecPV_twovtx_] = v1->normalizedChi2();
930 +      avgPtPV1_spl_twovtx_[nrecPV_twovtx_] = avgPtRecVtx(*v1);
931 +      errx1_spl_twovtx_[nrecPV_twovtx_] = v1->xError();
932 +      erry1_spl_twovtx_[nrecPV_twovtx_] = v1->yError();
933 +      errz1_spl_twovtx_[nrecPV_twovtx_] = v1->zError();
934 +  
935 +      nTrkPV2_spl_twovtx_[nrecPV_twovtx_] = v2->tracksSize();
936 +      ndofPV2_spl_twovtx_[nrecPV_twovtx_] = v2->ndof();
937 +      normchi2PV2_spl_twovtx_[nrecPV_twovtx_] = v2->normalizedChi2();
938 +      avgPtPV2_spl_twovtx_[nrecPV_twovtx_] = avgPtRecVtx(*v2);
939 +      errx2_spl_twovtx_[nrecPV_twovtx_] = v2->xError();
940 +      erry2_spl_twovtx_[nrecPV_twovtx_] = v2->yError();
941 +      errz2_spl_twovtx_[nrecPV_twovtx_] = v2->zError();
942 +  
943        nrecPV_twovtx_++;
944 +
945 +
946 +      
947 +      // Print some information of the two tracks events
948 +      if(verbose_ && fntrk_ < 4) {
949 +        cout<<"Printing matchedVertexColl1 for low ntrack bins"<<endl;
950 +        printRecVtx(*v1);
951 +        cout<<"Printing matchedVertexColl1 for low ntrack bins"<<endl;
952 +        printRecVtx(*v2);
953 +      }
954      } // End of analyzing res/pull
955    } // End of  if(matchedVertexColl1->size() == 1 && matchedVertexColl2->size() == 1 ) {
956    else
957 <    cout<<"WARNING: Cannot find matching pvtxs"<<endl;
957 >    edm::LogInfo("Debug")<<"[PVStudy] WARNING: Cannot find matching pvtxs"<<endl;
958    
959 <  if(verbose_)     cout<<"End analyzing the matchedVertexColl"<<endl;
959 >  edm::LogInfo("Debug")<<"[PVStudy] End analyzing the matchedVertexColl"<<endl;
960  
961 <  //=======================================================
962 <  // Fill simulated vertices
963 <  //=======================================================
964 <  if (!realData_) {
799 <    bool MC=false;
800 <    Handle<HepMCProduct> evtMC;
801 <    iEvent.getByLabel("generator",evtMC);
802 <    if (!evtMC.isValid()) {
803 <      MC=false;
804 <      if(verbose_){
805 <        cout << "no HepMCProduct found"<< endl;
806 <      }
807 <    } else {
808 <      if(verbose_){
809 <        cout << "generator HepMCProduct found"<< endl;
810 <      }
811 <      MC=true;
812 <    }
813 <    
814 <    if(MC){
815 <      // make a list of primary vertices:
816 <      std::vector<simPrimaryVertex> simpv;
817 <      simpv=getSimPVs(evtMC,"");
818 <      //     simpv=getSimPVs(evtMC, simVtxs, simTrks);
819 <      h["nsimPV"]->Fill(simpv.size());
820 <      nsimPV_ = simpv.size();
821 <
822 <      int isimpv = 0;
823 <      for(std::vector<simPrimaryVertex>::iterator vsim=simpv.begin();
824 <          vsim!=simpv.end(); vsim++, isimpv++){
825 <        nsimTrkPV_[isimpv]  =vsim->nGenTrk;
826 <        simx_[isimpv] = vsim->x;
827 <        simy_[isimpv] = vsim->y;
828 <        simz_[isimpv] = vsim->y;
829 <        simptsq_[isimpv] = vsim->ptsq;
830 <        
831 <        //fillMCHisto((std::vector<simPrimaryVertex>::iterator vsim, int isimpv, const reco::VertexCollection *vtxColl, int datatype) {
832 <        fillMCHisto(vsim, isimpv, splitVertexColl1, 1);
833 <        fillMCHisto(vsim, isimpv, splitVertexColl2, 2);
834 <        fillMCHisto(vsim, isimpv, vertexColl, 3);
835 <      }
836 <    } // End of  for(std::vector<simPrimaryVertex>::iterator vsim=simpv.begin()
837 <  } // End of   if (!realData_) {
838 <
839 <  // Finally fill the ftree_
961 >
962 >  //========================================================================
963 >  // Step 5: Fill ntuple if saventuple_ is on
964 >  //========================================================================
965    if(saventuple_) {
966      ftree_->Fill();
967      pvtxtree_->Fill();
968    }
969 +  
970   }
971  
972 +
973 +  
974   // ------------ method called once each job just before starting event loop  ------------
975   void
976   PVStudy::beginJob()
# Line 852 | Line 980 | PVStudy::beginJob()
980   // ------------ method called once each job just after ending the event loop  ------------
981   void
982   PVStudy::endJob() {
983 <  if (verbose_) cout << "Analyzing PV info" << endl;
983 >  edm::LogInfo("Analysis") << "[endJob] Analyzing PV info" << endl;
984    // Looping through the datamodes available
985    for (vector<int>::const_iterator it= datamode.begin(); it != datamode.end() ; ++it) {  
986      string suffix;
987 <    if(verbose_)  cout<<"datamode = "<< *it<<endl;
987 >    edm::LogInfo("Analysis")<<"[endJob] datamode = "<< *it<<endl;
988      switch(*it) {
989      case 0: suffix = "";
990        break;
# Line 867 | Line 995 | PVStudy::endJob() {
995      case 3: suffix = "_mct";
996        break;
997      }
998 +    suffix += "_nTrk";
999      if(analyze_) {
1000        for (int ntrk=nTrkMin_;ntrk<=nTrkMax_;++ntrk) {
1001 +        edm::LogInfo("Analysis") << "[endJob] ntrk = " << ntrk << endl;
1002          PVStudy::PVAnaInfo ipv = GetPVAnaInfo(ntrk,*it);
1003 <        if ( ipv.res_.x() > 0 ) h2["resx"+suffix+"_nTrk"]->Fill(ntrk,ipv.res_.x(), 1.);
1004 <        if ( ipv.res_.y() > 0 ) h2["resy"+suffix+"_nTrk"]->Fill(ntrk,ipv.res_.y(), 1.);
1005 <        if ( ipv.res_.z() > 0 ) h2["resz"+suffix+"_nTrk"]->Fill(ntrk,ipv.res_.z(), 1.);
1006 <        if ( ipv.pull_.x() > 0 ) h2["pullx"+suffix+"_nTrk"]->Fill(ntrk,ipv.pull_.x(), 1.);
1007 <        if ( ipv.pull_.y() > 0 ) h2["pully"+suffix+"_nTrk"]->Fill(ntrk,ipv.pull_.y(), 1.);
1008 <        if ( ipv.pull_.z() > 0 ) h2["pullz"+suffix+"_nTrk"]->Fill(ntrk,ipv.pull_.z(), 1.);
1003 >        if ( ipv.res_.x() > 0 ) h_ana->Fill2d("resx"+suffix, ntrk,ipv.res_.x());
1004 >        if ( ipv.res_.y() > 0 ) h_ana->Fill2d("resy"+suffix, ntrk,ipv.res_.y());
1005 >        if ( ipv.res_.z() > 0 ) h_ana->Fill2d("resz"+suffix, ntrk,ipv.res_.z());
1006 >        if ( ipv.pull_.x() > 0 ) h_ana->Fill2d("pullx"+suffix, ntrk,ipv.pull_.x());
1007 >        if ( ipv.pull_.y() > 0 ) h_ana->Fill2d("pully"+suffix, ntrk,ipv.pull_.y());
1008 >        if ( ipv.pull_.z() > 0 ) h_ana->Fill2d("pullz"+suffix, ntrk,ipv.pull_.z());
1009        }
1010 <    }
1010 >    }
1011      suffix.clear();
1012    }
1013    if(saventuple_) {
# Line 886 | Line 1016 | PVStudy::endJob() {
1016      pvtxtree_->Write();
1017      file_->Close();
1018    }
1019 < }
890 <
1019 >  
1020  
1021 + }
1022  
1023   // Match a recovertex with a simvertex
1024   // ? Should the cut be parameter dependent?
# Line 896 | Line 1026 | PVStudy::endJob() {
1026   bool PVStudy::matchVertex(const PVStudy::simPrimaryVertex & vsim,
1027                            const reco::Vertex & vrec)
1028   {
1029 <  return (fabs(vsim.z-vrec.z())<0.0500); // =500um
1029 >  if(vrec.isFake() || !vrec.isValid()) return false;
1030 >  else
1031 >    return true;
1032 >    //return (fabs(vsim.z-vrec.z())<0.0500); // =500um // remove this hard cut
1033   }
1034  
1035   // Match two reconstructed vertices
# Line 905 | Line 1038 | bool PVStudy::matchVertex( const reco::V
1038                             int zsigncut)
1039   {
1040    double cut = zsigncut*max(vrec1->zError(), vrec2->zError());
1041 <  if(verbose_)
909 <    cout<<"The matching criteria in z is "<<cut<<endl;
1041 >  edm::LogInfo("Debug")<<"[matchVertex] The matching criteria in z is "<<cut<<endl;
1042    return (fabs(vrec1->z()-vrec2->z())<cut);
1043   }
1044  
1045  
1046   bool PVStudy::isResonance(const HepMC::GenParticle * p){
1047    double ctau=(pdt->particle( abs(p->pdg_id()) ))->lifetime();
1048 <  if(verbose_) cout << "isResonance   " << p->pdg_id() << " " << ctau << endl;
1048 >  edm::LogInfo("Debug") << "[isResonance] isResonance   " << p->pdg_id() << " " << ctau << endl;
1049    return  ctau >0 && ctau <1e-6;
1050   }
1051  
# Line 964 | Line 1096 | void PVStudy::printRecVtxs(const Handle<
1096    }
1097   }
1098  
1099 + void PVStudy::printRecVtx(const reco::Vertex & v){
1100 +
1101 +  cout << "#trk " << std::setw(3) << v.tracksSize()
1102 +         << " chi2 " << std::setw(4) << v.chi2()
1103 +         << " ndof " << std::setw(3) << v.ndof() << endl
1104 +         << " x "  << std::setw(8) <<std::fixed << std::setprecision(4) << v.x()
1105 +         << " dx " << std::setw(8) << v.xError()<< endl
1106 +         << " y "  << std::setw(8) << v.y()
1107 +         << " dy " << std::setw(8) << v.yError()<< endl
1108 +         << " z "  << std::setw(8) << v.z()
1109 +         << " dz " << std::setw(8) << v.zError()
1110 +         << endl;
1111 + }
1112 +
1113   void PVStudy::printSimTrks(const Handle<SimTrackContainer> simTrks){
1114    cout <<  " simTrks   type, (momentum), vertIndex, genpartIndex"  << endl;
1115    int i=1;
# Line 985 | Line 1131 | void PVStudy::printSimTrks(const Handle<
1131   void PVStudy::fillHisto(res r, error er, int ntk, int datamode){
1132    stringstream ss;
1133    ss << ntk;
1134 <  string suffix = ss.str();
1135 <  if(datamode == 0 )  suffix = "_" + suffix;
1136 <  if(datamode == 1 )  suffix = "_spl1_mct_" + suffix;
1137 <  if(datamode == 2 )  suffix = "_spl2_mct_" + suffix;
1138 <  if(datamode == 3 )  suffix = "_mct_" + suffix;
1134 >  string suffix;
1135 >  if(datamode == 0 )  suffix = "_" + ss.str();
1136 >  if(datamode == 1 )  suffix = "_spl1_mct_" + ss.str();
1137 >  if(datamode == 2 )  suffix = "_spl2_mct_" + ss.str();
1138 >  if(datamode == 3 )  suffix = "_mct_" + ss.str();
1139    
1140    if (ntk < nTrkMin_ || ntk > nTrkMax_ ) return;
1141    // Fill histograms of res and pull of ntk
1142 <  h["deltax"+suffix]->Fill(r.x());
1143 <  h["deltay"+suffix]->Fill(r.y());
1144 <  h["deltaz"+suffix]->Fill(r.z());
1145 <  h["pullx"+suffix]->Fill(r.x()/er.x());
1146 <  h["pully"+suffix]->Fill(r.y()/er.y());
1147 <  h["pullz"+suffix]->Fill(r.z()/er.z());  
1148 <  h["errPVx"+suffix]->Fill(er.x());
1149 <  h["errPVy"+suffix]->Fill(er.y());
1150 <  h["errPVz"+suffix]->Fill(er.z());
1142 >  h_others->Fill1d("deltax"+suffix, r.x());
1143 >  h_others->Fill1d("deltay"+suffix, r.y());
1144 >  h_others->Fill1d("deltaz"+suffix, r.z());
1145 >  h_others->Fill1d("pullx"+suffix, r.x()/er.x());
1146 >  h_others->Fill1d("pully"+suffix, r.y()/er.y());
1147 >  h_others->Fill1d("pullz"+suffix, r.z()/er.z());  
1148 >  h_others->Fill1d("errPVx"+suffix, er.x());
1149 >  h_others->Fill1d("errPVy"+suffix, er.y());
1150 >  h_others->Fill1d("errPVz"+suffix, er.z());
1151   }
1152  
1153 +
1154   PVStudy::PVAnaInfo PVStudy::GetPVAnaInfo(int ntk, int datamode) {
1155    map<int,double> data;
1156    data.clear();
# Line 1021 | Line 1168 | PVStudy::PVAnaInfo PVStudy::GetPVAnaInfo
1168      for ( int i = 0; i < 6; ++i) {
1169        switch (i) {
1170        case 0:
1171 <        fit(h["deltax"+suffix], fpar);
1171 >        if (!h_others->ReadHisto1D("deltax"+suffix)) break;
1172 >        fit(h_others->ReadHisto1D("deltax"+suffix), fpar);
1173          data[i] = fpar[0]*cm2um;
1174          break;
1175        case 1:
1176 <        fit(h["deltay"+suffix], fpar);
1176 >        if (!h_others->ReadHisto1D("deltay"+suffix)) break;
1177 >        fit(h_others->ReadHisto1D("deltay"+suffix), fpar);
1178          data[i] = fpar[0]*cm2um;
1179          break;
1180        case 2:
1181 <        fit(h["deltaz"+suffix], fpar);
1181 >        if (!h_others->ReadHisto1D("deltaz"+suffix)) break;
1182 >        fit(h_others->ReadHisto1D("deltaz"+suffix), fpar);
1183          data[i] = fpar[0]*cm2um;
1184          break;
1185        case 3:
1186 <        fit(h["pullx"+suffix], fpar);
1186 >        if (!h_others->ReadHisto1D("pullx"+suffix)) break;
1187 >        fit(h_others->ReadHisto1D("pullx"+suffix), fpar);
1188          data[i] = fpar[0];
1189          break;
1190        case 4:
1191 <        fit(h["pully"+suffix], fpar);
1191 >        if (!h_others->ReadHisto1D("pully"+suffix)) break;
1192 >        fit(h_others->ReadHisto1D("pully"+suffix), fpar);
1193          data[i] = fpar[0];
1194          break;
1195        case 5:
1196 <        fit(h["pullz"+suffix], fpar);
1196 >        if (!h_others->ReadHisto1D("pullz"+suffix)) break;
1197 >        fit(h_others->ReadHisto1D("pullz"+suffix), fpar);
1198          data[i] = fpar[0];
1199          break;
1200        }
1201 <      if (verbose_ && data[i] > 0) cout << "data[" << i << "] = " << data[i] << (i<3?" micro m":" ") << endl;
1201 >      if (data[i] > 0) edm::LogInfo("Analysis") << "[Analysis] data[" << i << "] = " << data[i] << (i<3?" micro m":" ") << endl;
1202      }
1203    }
1204    else
# Line 1060 | Line 1213 | PVStudy::PVAnaInfo PVStudy::GetPVAnaInfo
1213                              ntk);
1214   }
1215  
1216 < void PVStudy::fit(TH1 *&hdist, double fitPars[]){
1216 >
1217 > void PVStudy::fit(TH1 *hdist, double fitPars[]){
1218    TAxis *axis0 = hdist->GetXaxis();
1219    int nbin = axis0->GetLast();
1220    double nOF = hdist->GetBinContent(nbin+1);
1221    double nUF = hdist->GetBinContent(0);
1222    //   double fitRange = axis0->GetBinUpEdge(nbin);
1223 <  double fitRange = axis0->GetXmax();
1223 >  // double fitRange = axis0->GetXmax();
1224 >  double fitRange = 2*hdist->GetRMS();
1225    double sigMax[2] = {0.,0.};
1226  
1227 <  if ( verbose_ ){
1228 <    cout << "Last bin = " << nbin;
1229 <    cout << "; hdist: Overflow Entries = " << nOF;
1230 <    cout << "; Underflow Entries = " << nUF;
1231 <    cout << "; hdist->GetEntries() = " << hdist->GetEntries();
1232 <    cout << "; fitting range = " << -fitRange << " to " << fitRange << endl;
1078 <  }
1227 >  edm::LogInfo("Analysis") << "[Fit] Last bin = " << nbin
1228 >                           << "; hdist: Overflow Entries = " << nOF
1229 >                           << "; Underflow Entries = " << nUF
1230 >                           << "; hdist->GetEntries() = " << hdist->GetEntries()
1231 >                           << "; fitting range = " << -fitRange << " to " << fitRange << endl;
1232 >
1233    if (hdist->GetEntries() - nOF - nUF >= 10) { // FIXME: for reasonable Gaussian fit
1234      for (int bi = 0; bi < nbin; bi++) {
1235        if ( (axis0->GetBinLowEdge(bi) < 0) && (hdist->GetBinContent(bi) > 0) ) {
# Line 1087 | Line 1241 | void PVStudy::fit(TH1 *&hdist, double fi
1241          if ( abs(sigMax[0]) > abs(sigMax[1]) ) sigMax[1] = abs(sigMax[0]);
1242        }
1243      }
1244 <    if (verbose_) cout << "Fit sigMax = " << sqrt(2.)*sigMax[1] << endl;
1244 >    //edm::LogInfo("Analysis") << "[Fit] Fit sigMax = " << sqrt(2.)*sigMax[1] << endl;
1245  
1246      TF1 *fgaus = new TF1("fgaus","gaus",-fitRange, fitRange);
1247      fgaus->SetParameter(1, 0.);
1248 <    fgaus->SetParLimits(1, -fitRange/40., fitRange/40.);
1248 >    fgaus->SetParLimits(1, -fitRange/10., fitRange/10.);
1249      fgaus->SetParLimits(2, 0., sqrt(2.)*sigMax[1]);
1250      fgaus->SetLineColor(4);
1251 <    hdist->Fit(fgaus,"Q");
1251 >    hdist->Fit(fgaus,"QLRM");
1252      gPad->Update();
1253      TPaveStats *s = (TPaveStats*) hdist->GetListOfFunctions()->FindObject("stats");
1254      s->SetOptStat(1111111);
1255      s->SetOptFit(0111);
1256      gPad->Update();
1257 <    if (verbose_) cout << "got function" << endl;
1257 >    //edm::LogInfo("Analysis") << "[Fit] got function" << endl;
1258      fitPars[0] = ((fgaus->GetParameter(2))?fgaus->GetParameter(2):-999);
1259    }
1260    else
1261      fitPars[0] = -999;
1262   }
1263  
1264 < void PVStudy::fillTrackHisto(const reco::TrackCollection *trackColl, int datatype) {
1264 >
1265 > void PVStudy::fillTrackHisto(const reco::TrackCollection *trackColl, int datatype, const Point & bs) {
1266    string suffix;
1267    suffix = ""; // for unsplit tracks
1268    if(datatype == 1) suffix = "1_spl"; // for splittracks 1
1269    if(datatype == 2) suffix = "2_spl"; // for splittracks 2
1270    
1271 <  h["nTrk"+suffix]->Fill(trackColl->size());
1271 >  h_pvtrk->Fill1d("nTrk"+suffix, trackColl->size());
1272    for(reco::TrackCollection::const_iterator itTrack = trackColl->begin();
1273        itTrack != trackColl->end();                      
1274        ++itTrack) {
1275 <    h["trkPt"+suffix]->Fill(itTrack->pt());
1276 <    h["trkDxy"+suffix]->Fill(itTrack->dxy());
1277 <    h["trkDz"+suffix]->Fill(itTrack->dz());
1278 <    h["trkEta"+suffix]->Fill(itTrack->eta());
1279 <    h["trkPhi"+suffix]->Fill(itTrack->phi());
1275 >    h_pvtrk->Fill1d("trkPt"+suffix, itTrack->pt());
1276 >    h_pvtrk->Fill1d("trkDxy"+suffix, itTrack->dxy());
1277 >    h_pvtrk->Fill1d("trkDxyCorr"+suffix, itTrack->dxy(bs));
1278 >    h_pvtrk->Fill1d("trkDz"+suffix, itTrack->dz());
1279 >    h_pvtrk->Fill1d("trkEta"+suffix, itTrack->eta());
1280 >    h_pvtrk->Fill1d("trkPhi"+suffix, itTrack->phi());
1281    }
1282   }
1283  
1284 < void PVStudy::fillTrackHistoInPV(const reco::VertexCollection *vertexColl, int datatype, bool fillHisto, bool fillNtuple) {
1284 > void PVStudy::fillTrackHistoInPV(const reco::VertexCollection *vertexColl, int datatype, const Point & bs) {
1285    string suffix;
1286    suffix = ""; // for unsplit tracks
1287    if(datatype == 1) suffix = "1_spl"; // for splittracks 1
# Line 1133 | Line 1289 | void PVStudy::fillTrackHistoInPV(const r
1289    int ivtx = 0;
1290    for(reco::VertexCollection::const_iterator v=vertexColl->begin();
1291        v!=vertexColl->end(); ++v, ++ivtx) {  
1292 <    if(fillNtuple) {
1293 <      if(datatype == 0) {
1294 <        nTrkPV_[ivtx] = v->tracksSize();
1295 <        recx_[ivtx] = v->x();
1140 <        recy_[ivtx] = v->y();
1141 <        recz_[ivtx] = v->z();
1142 <        recx_err_[ivtx] = v->xError();
1143 <        recy_err_[ivtx] = v->yError();
1144 <        recz_err_[ivtx] = v->zError();
1145 <      }
1146 <      if(datatype == 1) {
1147 <        nTrkPV1_spl_[ivtx] = v->tracksSize();  
1148 <        recx1_spl_[ivtx] = v->x();
1149 <        recy1_spl_[ivtx] = v->y();
1150 <        recz1_spl_[ivtx] = v->z();
1151 <        recx1_err_spl_[ivtx] = v->xError();
1152 <        recy1_err_spl_[ivtx] = v->yError();
1153 <        recz1_err_spl_[ivtx] = v->zError();
1154 <      }
1155 <      if(datatype == 2) {
1156 <        nTrkPV2_spl_[ivtx] = v->tracksSize();  
1157 <        recx2_spl_[ivtx] = v->x();
1158 <        recy2_spl_[ivtx] = v->y();
1159 <        recz2_spl_[ivtx] = v->z();
1160 <        recx2_err_spl_[ivtx] = v->xError();
1161 <        recy2_err_spl_[ivtx] = v->yError();
1162 <        recz2_err_spl_[ivtx] = v->zError();
1163 <      }
1164 <    }
1165 <
1166 <    if(fillHisto) {
1167 <      h["nTrkPV"+suffix]->Fill(v->tracksSize());
1292 >    if(!v->isFake()) {
1293 >      h_pvtrk->Fill1d("nTrkPV"+suffix, vertexColl->begin()->tracksSize());
1294 >      h_pvtrk->Fill1d("ndofPV"+suffix, vertexColl->begin()->ndof());
1295 >      int nHWTrkPV_ = 0;
1296        try {
1297 <        for(reco::Vertex::trackRef_iterator t = v->tracks_begin();
1298 <            t!=v->tracks_end(); t++) {
1297 >        for(reco::Vertex::trackRef_iterator t = vertexColl->begin()->tracks_begin();
1298 >            t!=vertexColl->begin()->tracks_end(); t++) {
1299            // illegal charge
1300            if ( (**t).charge() < -1 || (**t).charge() > 1 ) {
1301 <            //    h["trkPtPV"]->Fill(0.);
1301 >            //    h_pvtrk->Fill1d("trkPtPV", 0.);
1302            }
1303            else {
1304 <            h["trkPtPV"+suffix]->Fill((**t).pt());
1305 <            h["trkDxyPV"+suffix]->Fill((**t).dxy());
1306 <            h["trkDzPV"+suffix]->Fill((**t).dz());
1307 <            h["trkEtaPV"+suffix]->Fill((**t).eta());
1308 <            h["trkPhiPV"+suffix]->Fill((**t).phi());
1304 >            h_pvtrk->Fill1d("trkPtPV"+suffix, (**t).pt());
1305 >            h_pvtrk->Fill1d("trkDxyPV"+suffix, (**t).dxy());  
1306 >            h_pvtrk->Fill1d("trkDxyCorrPV"+suffix, (**t).dxy(bs));
1307 >            h_pvtrk->Fill1d("trkDzPV"+suffix, (**t).dz());
1308 >            h_pvtrk->Fill1d("trkEtaPV"+suffix, (**t).eta());
1309 >            h_pvtrk->Fill1d("trkPhiPV"+suffix, (**t).phi());
1310 >            if(vertexColl->begin()->trackWeight(*t) > 0.5)
1311 >              nHWTrkPV_++;
1312            }
1313          }
1314        }
1315        catch (...) {
1316          // exception thrown when trying to use linked track
1317 <        //        h["trkPtPV"]->Fill(0.);
1317 >        //        h_pvtrk->Fill1d("trkPtPV", 0.);
1318        }
1319 +      h_pvtrk->Fill1d("nHWTrkPV"+suffix, nHWTrkPV_);
1320      }
1321    }
1322   }
# Line 1212 | Line 1344 | void PVStudy::fillMCHisto(std::vector<si
1344  
1345    for(reco::VertexCollection::const_iterator vrec=vtxColl->begin();
1346        vrec!=vtxColl->end(); ++vrec){
1215    int nrectrk = vrec->tracksSize();
1347      vsim->recVtx=NULL;  
1348 <  
1349 <    if(verbose_){
1350 <      cout << "sim primary vertex x = " << vsim->x << "; y = " << vsim->y << "; z = " << vsim->z <<  endl;
1351 <      cout << "Is matched? " << (matchVertex(*vsim,*vrec)?"Yes":"No") << endl;
1221 <    }
1222 <    if ( matchVertex(*vsim,*vrec) ) {
1348 >    edm::LogInfo("Debug") << "[fillMCHisto] sim primary vertex x = " << vsim->x << "; y = " << vsim->y << "; z = " << vsim->z <<  endl;
1349 >    edm::LogInfo("Debug") << "[fillMCHisto] Is matched? " << (matchVertex(*vsim,*vrec)?"Yes":"No") << endl;
1350 >
1351 >    if ( matchVertex(*vsim,*vrec)  ) {
1352        vsim->recVtx=&(*vrec);
1353        
1354        // if the matching critera are fulfilled, accept the rec-vertex that is closest in z
# Line 1227 | Line 1356 | void PVStudy::fillMCHisto(std::vector<si
1356        //|| (!vsim->recVtx) )
1357        //vsim->recVtx=&(*vrec);
1358        //}
1359 <      if(verbose_)
1231 <        cout <<"primary matched in vertexColl" << vsim->x << " " << vsim->y << " " << vsim->z <<  endl;
1359 >      edm::LogInfo("Debug") <<"[fillMCHisto] primary matched in vertexColl" << vsim->x << " " << vsim->y << " " << vsim->z <<  endl;
1360        
1361        double fres_mct[3];
1362        double ferror_mct[3];
1363 <      
1363 >      int nrectrk =  int(vsim->recVtx->tracksSize());
1364 >      double ndofPV = vsim->recVtx->ndof();
1365 >      double normchi2PV =  vsim->recVtx->normalizedChi2();
1366 >      double avgPtPV = avgPtRecVtx(*(vsim->recVtx));
1367 >
1368        fres_mct[0] = vsim->recVtx->x()-vsim->x;
1369        fres_mct[1] = vsim->recVtx->y()-vsim->y;
1370        fres_mct[2] = vsim->recVtx->z()-vsim->z;
# Line 1240 | Line 1372 | void PVStudy::fillMCHisto(std::vector<si
1372        ferror_mct[1] = vsim->recVtx->yError();
1373        ferror_mct[2] = vsim->recVtx->zError();
1374        
1375 <      h["deltax"+suffix]->Fill( fres_mct[0] );
1376 <      h["deltay"+suffix]->Fill( fres_mct[1] );
1377 <      h["deltaz"+suffix]->Fill( fres_mct[2] );
1378 <      h["pullx"+suffix]->Fill( fres_mct[0]/ferror_mct[0] );
1379 <      h["pully"+suffix]->Fill( fres_mct[1]/ferror_mct[1] );
1380 <      h["pullz"+suffix]->Fill( fres_mct[2]/ferror_mct[2] );
1381 <      h["errPVx"+suffix]->Fill( ferror_mct[0] );
1382 <      h["errPVy"+suffix]->Fill( ferror_mct[1] );
1383 <      h["errPVz"+suffix]->Fill( ferror_mct[2] );
1375 >      h_summary->Fill1d("deltax"+suffix, fres_mct[0] );
1376 >      h_summary->Fill1d("deltay"+suffix, fres_mct[1] );
1377 >      h_summary->Fill1d("deltaz"+suffix, fres_mct[2] );
1378 >      h_summary->Fill1d("pullx"+suffix, fres_mct[0]/ferror_mct[0] );
1379 >      h_summary->Fill1d("pully"+suffix, fres_mct[1]/ferror_mct[1] );
1380 >      h_summary->Fill1d("pullz"+suffix, fres_mct[2]/ferror_mct[2] );
1381 >      h_summary->Fill1d("errPVx"+suffix, ferror_mct[0] );
1382 >      h_summary->Fill1d("errPVy"+suffix, ferror_mct[1] );
1383 >      h_summary->Fill1d("errPVz"+suffix, ferror_mct[2] );
1384        pvinfo.push_back(PVStudy::PVInfo(res(fres_mct[0], fres_mct[1], fres_mct[2]),
1385                                         error(ferror_mct[0], ferror_mct[1], ferror_mct[2]),
1386                                         nrectrk));
# Line 1258 | Line 1390 | void PVStudy::fillMCHisto(std::vector<si
1390                  nrectrk, datatype);
1391        
1392        if(saventuple_) {
1393 <        //Fill the values for variables in ftree_  
1393 >        //Fill the values for variables in pvtxtree_  
1394          if(datatype == 1) {
1395            nTrkPV_spl1_mct_[nrecPV_spl1_mct_] =   nrectrk;
1396 +          ndofPV_spl1_mct_[nrecPV_spl1_mct_] =  ndofPV;
1397 +          normchi2PV_spl1_mct_[nrecPV_spl1_mct_] =  normchi2PV;
1398 +          avgPtPV_spl1_mct_[nrecPV_spl1_mct_] = avgPtPV;
1399            deltax_spl1_mct_[nrecPV_spl1_mct_] =  fres_mct[0];
1400 <          deltay_spl1_mct_[nrecPV_spl1_mct_] =  fres_mct[0];
1401 <          deltaz_spl1_mct_[nrecPV_spl1_mct_] =  fres_mct[0];
1400 >          deltay_spl1_mct_[nrecPV_spl1_mct_] =  fres_mct[1];
1401 >          deltaz_spl1_mct_[nrecPV_spl1_mct_] =  fres_mct[2];
1402            pullx_spl1_mct_[nrecPV_spl1_mct_] = fres_mct[0]/ferror_mct[0];  
1403            pully_spl1_mct_[nrecPV_spl1_mct_] = fres_mct[1]/ferror_mct[1];
1404            pullz_spl1_mct_[nrecPV_spl1_mct_] =  fres_mct[2]/ferror_mct[2];
1405 +          errx_spl1_mct_[nrecPV_spl1_mct_] =  ferror_mct[0];
1406 +          erry_spl1_mct_[nrecPV_spl1_mct_] =  ferror_mct[1];
1407 +          errz_spl1_mct_[nrecPV_spl1_mct_] =  ferror_mct[2];
1408            nrecPV_spl1_mct_++;
1409          }
1272        
1410          if(datatype == 2) {
1411 <          nTrkPV_spl2_mct_[nrecPV_spl2_mct_] = nrectrk;
1411 >          nTrkPV_spl2_mct_[nrecPV_spl2_mct_] = nrectrk;  
1412 >          ndofPV_spl2_mct_[nrecPV_spl2_mct_] =  ndofPV;
1413 >          normchi2PV_spl2_mct_[nrecPV_spl2_mct_] =  normchi2PV;
1414 >          avgPtPV_spl2_mct_[nrecPV_spl2_mct_] = avgPtPV;
1415            deltax_spl2_mct_[nrecPV_spl2_mct_] =  fres_mct[0];
1416 <          deltay_spl2_mct_[nrecPV_spl2_mct_] =  fres_mct[0];
1417 <          deltaz_spl2_mct_[nrecPV_spl2_mct_] =  fres_mct[0];
1416 >          deltay_spl2_mct_[nrecPV_spl2_mct_] =  fres_mct[1];
1417 >          deltaz_spl2_mct_[nrecPV_spl2_mct_] =  fres_mct[2];
1418            pullx_spl2_mct_[nrecPV_spl2_mct_] = fres_mct[0]/ferror_mct[0];  
1419            pully_spl2_mct_[nrecPV_spl2_mct_] = fres_mct[1]/ferror_mct[1];
1420 <          pullz_spl2_mct_[nrecPV_spl2_mct_] =  fres_mct[2]/ferror_mct[2];
1420 >          pullz_spl2_mct_[nrecPV_spl2_mct_] =  fres_mct[2]/ferror_mct[2];        
1421 >          errx_spl2_mct_[nrecPV_spl2_mct_] =  ferror_mct[0];
1422 >          erry_spl2_mct_[nrecPV_spl2_mct_] =  ferror_mct[1];
1423 >          errz_spl2_mct_[nrecPV_spl2_mct_] =  ferror_mct[2];
1424            nrecPV_spl2_mct_++;
1425          }
1426          if(datatype == 3) {    
1427 <          nTrkPV_mct_[nrecPV_mct_] = nrectrk;
1427 >          nTrkPV_mct_[nrecPV_mct_] = nrectrk;
1428 >          ndofPV_mct_[nrecPV_mct_] =  ndofPV;
1429 >          normchi2PV_mct_[nrecPV_mct_] =  normchi2PV;
1430 >          avgPtPV_mct_[nrecPV_mct_] = avgPtPV;
1431            deltax_mct_[nrecPV_mct_] =  fres_mct[0];
1432            deltay_mct_[nrecPV_mct_] =  fres_mct[0];
1433            deltaz_mct_[nrecPV_mct_] =  fres_mct[0];
1434            pullx_mct_[nrecPV_mct_] = fres_mct[0]/ferror_mct[0];  
1435            pully_mct_[nrecPV_mct_] = fres_mct[1]/ferror_mct[1];
1436 <          pullz_mct_[nrecPV_mct_] =  fres_mct[2]/ferror_mct[2];          
1436 >          pullz_mct_[nrecPV_mct_] =  fres_mct[2]/ferror_mct[2];
1437 >          errx_mct_[nrecPV_mct_] =  ferror_mct[0];
1438 >          erry_mct_[nrecPV_mct_] =  ferror_mct[1];
1439 >          errz_mct_[nrecPV_mct_] =  ferror_mct[2];        
1440            nrecPV_mct_++;
1441          }
1442        } // End of  if(saventuple_) {
1443      } //  if ( matchVertex(*vsim,*vrec) ) {
1444      else {  // no rec vertex found for this simvertex
1445 <      if(verbose_)
1297 <        cout <<"primary not found " << vsim->x << " " << vsim->y << " " << vsim->z << " nGenTrk=" << vsim->nGenTrk << endl;
1445 >      edm::LogInfo("Debug") <<"[fillMCHisto] primary not found " << vsim->x << " " << vsim->y << " " << vsim->z << " nGenTrk=" << vsim->nGenTrk << endl;
1446      }
1447    }
1448   }
1449  
1302
1450   void PVStudy::SetVarToZero() {
1304  //Greg's variables
1451    fntrk_ = 0;
1452    //pvtx position (x,y,z) residual and error
1453    for(int i = 0; i<3;i++)    {
1454 <      fres_[i] = 0;
1455 <      ferror_[i] = 0;
1454 >    fres_[i] = 0;
1455 >    ferror_[i] = 0;
1456    }
1457    
1458 <  //Yanyan's variables
1459 <  // Number of reconstructed vertices  // for GeneralTracks
1458 >  // Event level information
1459 >  glob_runno_ = 0;
1460 >  glob_evtno_ = 0;
1461 >  glob_ls_ = 0;
1462 >  glob_bx_ = 0;
1463    nrecPV_ = 0;
1464    nrecPV1_spl_ = 0;
1465    nrecPV2_spl_ = 0;
1466    nrecPV_twovtx_ = 0;
1467    nsimPV_ = 0;
1468 +
1469    nrecPV_mct_ = 0;
1470    nrecPV_spl1_mct_ = 0;
1471    nrecPV_spl2_mct_ = 0;
1472  
1473 +  // Mininum separation between the secondary pvtxes and leading pvtx
1474 +  min_zsep_ = 9999.0;
1475 +  min_ntrksep_ = 9999.0;
1476 +  min_sumpt2sep_ = -9999.0;
1477 +  
1478 +  // Variables filled per Vertex
1479    for (int i = 0; i < nMaxPVs_; i++) {
1480 <    nTrkPV_[i] = 0; // Number of tracks in the pvtx
1325 <    recx_[i] = 0;
1326 <    recy_[i] = 0;
1327 <    recz_[i] = 0;
1328 <    recx_err_[i] = 0;
1329 <    recy_err_[i] = 0;
1330 <    recz_err_[i] = 0;
1331 <
1332 <    nTrkPV1_spl_[i] = 0; // Number of tracks in the pvtx
1333 <    recx1_spl_[i] = 0;
1334 <    recy1_spl_[i] = 0;
1335 <    recz1_spl_[i] = 0;
1336 <    recx1_err_spl_[i] = 0;
1337 <    recy1_err_spl_[i] = 0;
1338 <    recz1_err_spl_[i] = 0;
1339 <
1340 <    nTrkPV2_spl_[i] = 0; // Number of tracks in the pvtx
1341 <  
1342 <    recx2_spl_[i] = 0;
1343 <    recy2_spl_[i] = 0;
1344 <    recz2_spl_[i] = 0;
1345 <    recx2_err_spl_[i] = 0;
1346 <    recy2_err_spl_[i] = 0;
1347 <    recz2_err_spl_[i] = 0;
1348 <    
1480 >    // matched two-vertices
1481      nTrkPV1_spl_twovtx_[i] = 0;
1482 +    ndofPV1_spl_twovtx_[i] = 0;
1483 +    normchi2PV1_spl_twovtx_[i] = 0;
1484 +    avgPtPV1_spl_twovtx_[i] = 0;
1485 +    errx1_spl_twovtx_[i] = 0;
1486 +    erry1_spl_twovtx_[i] = 0;
1487 +    errz1_spl_twovtx_[i] = 0;
1488 +
1489      nTrkPV2_spl_twovtx_[i] = 0;
1490 <    nTrkPV_twovtx_[i] = 0;  
1491 <    sumptsq1_spl_twovtx_[i] = 0; // Sum of pT squred in the pvtx
1492 <    sumptsq2_spl_twovtx_[i] = 0; // Sum of pT squred in the pvtx
1490 >    ndofPV2_spl_twovtx_[i] = 0;
1491 >    normchi2PV2_spl_twovtx_[i] = 0;
1492 >    avgPtPV2_spl_twovtx_[i] = 0;
1493 >    errx2_spl_twovtx_[i] = 0;
1494 >    erry2_spl_twovtx_[i] = 0;
1495 >    errz2_spl_twovtx_[i] = 0;
1496 >    
1497      deltax_twovtx_[i] = 0;
1498      deltay_twovtx_[i] = 0;
1499      deltaz_twovtx_[i] = 0;
# Line 1361 | Line 1504 | void PVStudy::SetVarToZero() {
1504      pully_twovtx_[i] = 0;
1505      pullz_twovtx_[i] = 0;
1506      
1507 +    //simpv
1508      nsimTrkPV_[i] = 0;
1509      simx_[i] = 0;
1510      simy_[i] = 0;
1511      simz_[i] = 0;
1512      simptsq_[i] = 0;
1513      
1514 +    // residual and pulls with mc truth required
1515      deltax_mct_[i] = 0;
1516      deltay_mct_[i] = 0;
1517      deltaz_mct_[i] = 0;
1518      pullx_mct_[i] = 0;
1519      pully_mct_[i] = 0;
1520      pullz_mct_[i] = 0;
1521 <        
1521 >    nTrkPV_mct_[i] = 0;
1522 >    ndofPV_mct_[i] = 0;
1523 >    normchi2PV_mct_[i] = 0;
1524 >    avgPtPV_mct_[i] = 0;
1525 >    errx_mct_[i] = 0;
1526 >    erry_mct_[i] = 0;
1527 >    errz_mct_[i] = 0;
1528 >    
1529      deltax_spl1_mct_[i] = 0;
1530      deltay_spl1_mct_[i] = 0;
1531      deltaz_spl1_mct_[i] = 0;
1532      pullx_spl1_mct_[i] = 0;
1533      pully_spl1_mct_[i] = 0;
1534      pullz_spl1_mct_[i] = 0;
1535 <    
1535 >    nTrkPV_spl1_mct_[i] = 0;
1536 >    ndofPV_spl1_mct_[i] = 0;
1537 >    normchi2PV_spl1_mct_[i] = 0;
1538 >    avgPtPV_spl1_mct_[i] = 0;
1539 >    errx_spl1_mct_[i] = 0;
1540 >    erry_spl1_mct_[i] = 0;
1541 >    errz_spl1_mct_[i] = 0;
1542 >
1543      deltax_spl2_mct_[i] = 0;
1544      deltay_spl2_mct_[i] = 0;
1545      deltaz_spl2_mct_[i] = 0;
1546      pullx_spl2_mct_[i] = 0;
1547      pully_spl2_mct_[i] = 0;
1548      pullz_spl2_mct_[i] = 0;
1549 +    nTrkPV_spl2_mct_[i] = 0;
1550 +    ndofPV_spl2_mct_[i] = 0;
1551 +    normchi2PV_spl2_mct_[i] = 0;
1552 +    avgPtPV_spl2_mct_[i] = 0;
1553 +    errx_spl2_mct_[i] = 0;
1554 +    erry_spl2_mct_[i] = 0;
1555 +    errz_spl2_mct_[i] = 0;
1556 +
1557    }
1391  
1558   }
1559  
1560   double PVStudy::sumPtSquared(const reco::Vertex & v)  {
1561 <  double sum = 0.;
1562 <  double pT;
1563 <  for (reco::Vertex::trackRef_iterator it = v.tracks_begin(); it != v.tracks_end(); it++) {
1564 <    pT = (**it).pt();
1565 <    sum += pT*pT;
1561 >  if(v.isFake() || (!v.isValid()) || v.tracksSize() == 0) return 0.0;
1562 >  else {
1563 >    double sum = 0.;
1564 >    double pT;
1565 >    for (reco::Vertex::trackRef_iterator it = v.tracks_begin(); it != v.tracks_end(); it++) {
1566 >      pT = (**it).pt();
1567 >      sum += pT*pT;
1568 >    }
1569 >    return sum;
1570 >  }
1571 > }
1572 >
1573 >
1574 >
1575 > double PVStudy::avgPtRecVtx(const reco::Vertex & v)  {
1576 >
1577 >  if(v.isFake() || !v.isValid() || v.tracksSize()==0 ) return 0;
1578 >  else {
1579 >    double sumpT = 0.;
1580 >    for (reco::Vertex::trackRef_iterator it = v.tracks_begin(); it != v.tracks_end(); it++) {
1581 >      sumpT +=  (**it).pt();
1582 >  }
1583 >    return sumpT/double(v.tracksSize());
1584    }
1401  return sum;
1585   }
1586 +
1587 +
1588 +

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines