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.3 by jengbou, Tue Sep 8 07:15:38 2009 UTC vs.
Revision 1.13 by jengbou, Fri Dec 4 08:37:40 2009 UTC

# Line 12 | Line 12 | Implementation:
12   */
13   //
14   // Original Author:  "Geng-yuan Jeng/UC Riverside"
15 + //                   "Yanyan Gao/Fermilab ygao@fnal.gov"
16   //         Created:  Thu Aug 20 11:55:40 CDT 2009
17   // $Id$
18   //
# Line 24 | Line 25 | Implementation:
25   #include <vector>
26   #include <iostream>
27   #include <sstream>
28 + #include <algorithm>
29  
30   // user include files
31   #include "FWCore/Framework/interface/Frameworkfwd.h"
# Line 50 | Line 52 | Implementation:
52   #include <SimDataFormats/Track/interface/SimTrackContainer.h>
53  
54   //root
55 < #include "TROOT.h"
56 < #include "TF1.h"
57 < #include "TString.h"
58 < #include "TStyle.h"
59 <
55 > #include <TROOT.h>
56 > #include <TF1.h>
57 > #include <TString.h>
58 > #include <TStyle.h>
59 > #include <TPaveStats.h>
60 > #include <TPad.h>
61  
62   using namespace std;
63  
64 < PVStudy::PVStudy(const edm::ParameterSet& iConfig):
62 <  nTrkMin_(10),nTrkMax_(100)
64 > PVStudy::PVStudy(const edm::ParameterSet& iConfig)
65   {
66 <  simG4_           = iConfig.getParameter<edm::InputTag>( "simG4" );
67 <  tracksLabel_     = iConfig.getUntrackedParameter<edm::InputTag>("tracks");
68 <  vtxSample_       = iConfig.getUntrackedParameter<edm::InputTag>("vtxSample");
69 <  verbose_         = iConfig.getUntrackedParameter<bool>("verbose", false);
70 <  realData_        = iConfig.getUntrackedParameter<bool>("realData",false);
71 <  analyze_         = iConfig.getUntrackedParameter<bool>("analyzeOnTheFly",false);
72 <  outputfilename_  = iConfig.getUntrackedParameter<string>("OutputFileName");
66 >  //=======================================================================
67 >  // Get configuration for TrackTupleMaker
68 >  //=======================================================================
69 >  simG4_                     = iConfig.getParameter<edm::InputTag>( "simG4" );
70 >  trackCollectionTag_        = iConfig.getUntrackedParameter<edm::InputTag>("trackCollection");  
71 >  splitTrackCollection1Tag_  = iConfig.getUntrackedParameter<edm::InputTag>("splitTrackCollection1");
72 >  splitTrackCollection2Tag_  = iConfig.getUntrackedParameter<edm::InputTag>("splitTrackCollection2");
73 >  vertexCollectionTag_       = iConfig.getUntrackedParameter<edm::InputTag>("vertexCollection");
74 >  splitVertexCollection1Tag_ = iConfig.getUntrackedParameter<edm::InputTag>("splitVertexCollection1");
75 >  splitVertexCollection2Tag_ = iConfig.getUntrackedParameter<edm::InputTag>("splitVertexCollection2");  
76 >  pixelVertexCollectionTag_  = iConfig.getParameter<edm::InputTag>("pixelVertexCollectionTag");  
77 >  verbose_                   = iConfig.getUntrackedParameter<bool>("verbose",false);
78 >  realData_                  = iConfig.getUntrackedParameter<bool>("realData",false);
79 >  analyze_                   = iConfig.getUntrackedParameter<bool>("analyzeOnTheFly",false);
80 >  saventuple_                = iConfig.getUntrackedParameter<bool>("saventuple",false);  
81 >  outputfilename_            = iConfig.getUntrackedParameter<string>("OutputFileName");
82 >  ntrkdiffcut_               = iConfig.getUntrackedParameter<double>("ntrkdiffcut");
83 >  zsigncut_                  = iConfig.getUntrackedParameter<int>("zsigncut");
84 >  nTrkMin_                   = iConfig.getUntrackedParameter<int>("nTrkMin");
85 >  nTrkMax_                   = iConfig.getUntrackedParameter<int>("nTrkMax");
86 >  histoFileName_             = iConfig.getUntrackedParameter<std::string> ("histoFileName");
87  
88    //now do what ever initialization is needed
89    pvinfo.clear();
90  
91 <  file_ = TFile::Open(outputfilename_.c_str(),"RECREATE");
92 <  ftree_ = new TTree("mytree","mytree");
93 <  ftree_->AutoSave();
94 <  ftree_->Branch("residual",&fres,"fres[3]/D");
95 <  ftree_->Branch("error",&ferror,"ferror[3]/D");
96 <  ftree_->Branch("nTrk",&fntrk,"fntrk/I");
97 <  
98 <  edm::Service<TFileService> fs;
99 < //   TFileDirectory subDir = fs->mkdir( "Summary" );
100 < //   TFileDirectory subSubDir = subDir.mkdir( "mySubSubDirectory" );
101 <
102 <  h_nTrk           = fs->make<TH1F>("nTrk","Num of total tracks",300,0,300);
103 <  h_nTrkPV         = fs->make<TH1F>("nTrkPV","Num of Tracks from PV",300,0,300);
104 <  h_trkPt          = fs->make<TH1D>("trkPt","Pt of all tracks",100,0,100);
105 <  h_trkPtPV        = fs->make<TH1D>("trkPtPV","Pt dist of tracks from PV",100,0,100);
91 >  
92 >  // Specify the data mode vector
93 >  if(realData_) datamode.push_back(0);
94 >  else {
95 >    datamode.push_back(0);
96 >    datamode.push_back(1);
97 >    datamode.push_back(2);
98 >    datamode.push_back(3);
99 >  }
100 >
101 >  // Create ntuple files if needed
102 >  if(saventuple_) {
103 >    file_ = TFile::Open(outputfilename_.c_str(),"RECREATE");
104 >    ftree_ = new TTree("mytree","mytree");
105 >    ftree_->AutoSave();
106 >    ftree_->Branch("residual",&fres_,"fres_[3]/D");
107 >    ftree_->Branch("error",&ferror_,"ferror_[3]/D");
108 >    ftree_->Branch("nTrkPV",&fntrk_,"fntrk_/I");
109 >
110 >    // pvtxtree_ analyzing the pvtxs ootb
111 >    pvtxtree_ = new TTree("pvtxtree","pvtxtree");
112 >    //pvtx using all tracks
113 >    pvtxtree_->Branch("nrecPV",&nrecPV_,"nrecPV/I");
114 >    pvtxtree_->Branch("nTrkPV",&nTrkPV_,"nTrkPV[nrecPV]/I");
115 >    pvtxtree_->Branch("sumptsq",&sumptsq_,"sumptsq[nrecPV]/D");    
116 >    pvtxtree_->Branch("isValid",&isValid_,"isValid/I");
117 >    pvtxtree_->Branch("isFake",&isFake_,"isFake/I");
118 >    pvtxtree_->Branch("recx",&recx_,"recx[nrecPV]/D");
119 >    pvtxtree_->Branch("recy",&recy_,"recy[nrecPV]/D");
120 >    pvtxtree_->Branch("recz",&recz_,"recz[nrecPV]/D");
121 >    pvtxtree_->Branch("recx_err",&recx_err_,"recx_err[nrecPV]/D");
122 >    pvtxtree_->Branch("recy_err",&recy_err_,"recy_err[nrecPV]/D");
123 >    pvtxtree_->Branch("recz_err",&recz_err_,"recz_err[nrecPV]/D");
124 >
125 >    pvtxtree_->Branch("min_zsep",&min_zsep_,"min_zsep/D");
126 >    pvtxtree_->Branch("min_ntrksep",&min_ntrksep_,"min_ntrksep/D");
127 >    pvtxtree_->Branch("min_sumpt2sep",&min_sumpt2sep_,"min_sumpt2sep/D");
128 >
129 >    //pvtx using splittracks1
130 >    pvtxtree_->Branch("nrecPV1_spl",&nrecPV1_spl_,"nrecPV1_spl/I");
131 >    pvtxtree_->Branch("nTrkPV1_spl",&nTrkPV1_spl_,"nTrkPV1_spl[nrecPV1_spl]/I");  
132 >    pvtxtree_->Branch("sumptsq1_spl",&sumptsq1_spl_,"sumptsq1_spl[nrecPV1_spl]/D");  
133 >    pvtxtree_->Branch("isValid1_spl",&isValid1_spl_,"isValid1_spl/I");
134 >    pvtxtree_->Branch("isFake1_spl",&isFake1_spl_,"isFake1_spl/I");
135 >    pvtxtree_->Branch("recx1_spl",&recx1_spl_,"recx1_spl[nrecPV1_spl]/D");
136 >    pvtxtree_->Branch("recy1_spl",&recy1_spl_,"recy1_spl[nrecPV1_spl]/D");
137 >    pvtxtree_->Branch("recz1_spl",&recz1_spl_,"recz1_spl[nrecPV1_spl]/D");
138 >    pvtxtree_->Branch("recx1_err_spl",&recx1_err_spl_,"recx1_err_spl[nrecPV1_spl]/D");
139 >    pvtxtree_->Branch("recy1_err_spl",&recy1_err_spl_,"recy1_err_spl[nrecPV1_spl]/D");
140 >    pvtxtree_->Branch("recz1_err_spl",&recz1_err_spl_,"recz1_err_spl[nrecPV1_spl]/D");  
141 >  
142 >    //pvtx using splittracks2
143 >    pvtxtree_->Branch("nrecPV2_spl",&nrecPV2_spl_,"nrecPV2_spl/I");
144 >    pvtxtree_->Branch("nTrkPV2_spl",&nTrkPV2_spl_,"nTrkPV2_spl[nrecPV2_spl]/I");    
145 >    pvtxtree_->Branch("sumptsq2_spl",&sumptsq2_spl_,"sumptsq2_spl[nrecPV2_spl]/D");  
146 >    pvtxtree_->Branch("isValid2_spl",&isValid2_spl_,"isValid2_spl/I");
147 >    pvtxtree_->Branch("isFake2_spl",&isFake2_spl_,"isFake2_spl/I");
148 >    pvtxtree_->Branch("recx2_spl",&recx2_spl_,"recx2_spl[nrecPV2_spl]/D");
149 >    pvtxtree_->Branch("recy2_spl",&recy2_spl_,"recy2_spl[nrecPV2_spl]/D");
150 >    pvtxtree_->Branch("recz2_spl",&recz2_spl_,"recz2_spl[nrecPV2_spl]/D");
151 >    pvtxtree_->Branch("recx2_err_spl",&recx2_err_spl_,"recx2_err_spl[nrecPV2_spl]/D");
152 >    pvtxtree_->Branch("recy2_err_spl",&recy2_err_spl_,"recy2_err_spl[nrecPV2_spl]/D");
153 >    pvtxtree_->Branch("recz2_err_spl",&recz2_err_spl_,"recz2_err_spl[nrecPV2_spl]/D");  
154 >    
155 >    //pixeVertices
156 >    pvtxtree_->Branch("nrecPV_pxlpvtx",&nrecPV_pxlpvtx_,"nrecPV_pxlpvtx/I");
157 >    pvtxtree_->Branch("nTrkPV_pxlpvtx",&nTrkPV_pxlpvtx_,"nTrkPV_pxlpvtx[nrecPV_pxlpvtx]/I");    
158 >    pvtxtree_->Branch("sumptsq_pxlpvtx",&sumptsq_pxlpvtx_,"sumptsq_pxlpvtx[nrecPV_pxlpvtx]/D");  
159 >    pvtxtree_->Branch("isValid_pxlpvtx",&isValid_pxlpvtx_,"isValid_pxlpvtx/I");
160 >    pvtxtree_->Branch("isFake_pxlpvtx",&isFake_pxlpvtx_,"isFake_pxlpvtx/I");
161 >    pvtxtree_->Branch("recx_pxlpvtx",&recx_pxlpvtx_,"recx_pxlpvtx[nrecPV_pxlpvtx]/D");
162 >    pvtxtree_->Branch("recy_pxlpvtx",&recy_pxlpvtx_,"recy_pxlpvtx[nrecPV_pxlpvtx]/D");
163 >    pvtxtree_->Branch("recz_pxlpvtx",&recz_pxlpvtx_,"recz_pxlpvtx[nrecPV_pxlpvtx]/D");
164 >    pvtxtree_->Branch("recx_err_pxlpvtx",&recx_err_pxlpvtx_,"recx_err_pxlpvtx[nrecPV_pxlpvtx]/D");
165 >    pvtxtree_->Branch("recy_err_pxlpvtx",&recy_err_pxlpvtx_,"recy_err_pxlpvtx[nrecPV_pxlpvtx]/D");
166 >    pvtxtree_->Branch("recz_err_pxlpvtx",&recz_err_pxlpvtx_,"recz_err_pxlpvtx[nrecPV_pxlpvtx]/D");  
167 >
168 >    //Fill the variables in the twovtx pair (recvtx1, recvtx2)
169 >    pvtxtree_->Branch("nrecPV_twovtx",&nrecPV_twovtx_,"nrecPV_twovtx/I");
170 >    pvtxtree_->Branch("nTrkPV1_spl_twovtx",&nTrkPV1_spl_twovtx_,"nTrkPV1_spl_twovtx[nrecPV_twovtx]/I");
171 >    pvtxtree_->Branch("nTrkPV2_spl_twovtx",&nTrkPV2_spl_twovtx_,"nTrkPV2_spl_twovtx[nrecPV_twovtx]/I");
172 >    pvtxtree_->Branch("sumptsq1_spl_twovtx",&sumptsq1_spl_twovtx_,"sumptsq1_spl_twovtx[nrecPV_twovtx]/D");
173 >    pvtxtree_->Branch("sumptsq2_spl_twovtx",&sumptsq2_spl_twovtx_,"sumptsq2_spl_twovtx[nrecPV_twovtx]/D");
174 >    pvtxtree_->Branch("nTrkPV_twovtx",&nTrkPV_twovtx_,"nTrkPV_twovtx[nrecPV_twovtx]/I");
175 >    pvtxtree_->Branch("deltax_twovtx",&deltax_twovtx_,"deltax_twovtx[nrecPV_twovtx]/D");
176 >    pvtxtree_->Branch("deltay_twovtx",&deltay_twovtx_,"deltay_twovtx[nrecPV_twovtx]/D");
177 >    pvtxtree_->Branch("deltaz_twovtx",&deltaz_twovtx_,"deltaz_twovtx[nrecPV_twovtx]/D");
178 >    pvtxtree_->Branch("errx_twovtx",&errx_twovtx_,"errx_twovtx[nrecPV_twovtx]/D");
179 >    pvtxtree_->Branch("erry_twovtx",&erry_twovtx_,"erry_twovtx[nrecPV_twovtx]/D");
180 >    pvtxtree_->Branch("errz_twovtx",&errz_twovtx_,"errz_twovtx[nrecPV_twovtx]/D");
181 >    pvtxtree_->Branch("pullx_twovtx",&pullx_twovtx_,"pullx_twovtx[nrecPV_twovtx]/D");
182 >    pvtxtree_->Branch("pully_twovtx",&pully_twovtx_,"pully_twovtx[nrecPV_twovtx]/D");
183 >    pvtxtree_->Branch("pullz_twovtx",&pullz_twovtx_,"pullz_twovtx[nrecPV_twovtx]/D");
184 >    
185 >    // MC variables
186 >    if(!realData_) {  
187 >      pvtxtree_->Branch("nsimPV",&nsimPV_,"nsimPV/I");
188 >      pvtxtree_->Branch("nsimTrkPV",&nsimTrkPV_,"nsimTrkPV[nsimPV]/I");
189 >      pvtxtree_->Branch("simx",&simx_,"simx[nsimPV]/D");
190 >      pvtxtree_->Branch("simy",&simy_,"simy[nsimPV]/D");
191 >      pvtxtree_->Branch("simz",&simz_,"simz[nsimPV]/D");
192 >      pvtxtree_->Branch("simptsq",&simptsq_,"simptsq[nsimPV]/D");
193 >
194 >      // For pvtxs with all the tracks
195 >      pvtxtree_->Branch("nrecPV_mct",&nrecPV_mct_,"nrecPV_mct/I");
196 >      pvtxtree_->Branch("deltax_mct",&deltax_mct_,"deltax_mct[nrecPV_mct]/D");
197 >      pvtxtree_->Branch("deltay_mct",&deltay_mct_,"deltay_mct[nrecPV_mct]/D");
198 >      pvtxtree_->Branch("deltaz_mct",&deltaz_mct_,"deltaz_mct[nrecPV_mct]/D");
199 >      pvtxtree_->Branch("pullx_mct",&pullx_mct_,"pullx_mct[nrecPV_mct]/D");
200 >      pvtxtree_->Branch("pully_mct",&pully_mct_,"pully_mct[nrecPV_mct]/D");
201 >      pvtxtree_->Branch("pullz_mct",&pullz_mct_,"pullz_mct[nrecPV_mct]/D");
202 >      // For pvtxs with splittracks1
203 >      pvtxtree_->Branch("nrecPV_spl1_mct",&nrecPV_spl1_mct_,"nrecPV_spl1_mct/I");
204 >      pvtxtree_->Branch("deltax_spl1_mct",&deltax_spl1_mct_,"deltax_spl1_mct[nrecPV_spl1_mct]/D");
205 >      pvtxtree_->Branch("deltay_spl1_mct",&deltay_spl1_mct_,"deltay_spl1_mct[nrecPV_spl1_mct]/D");
206 >      pvtxtree_->Branch("deltaz_spl1_mct",&deltaz_spl1_mct_,"deltaz_spl1_mct[nrecPV_spl1_mct]/D");
207 >      pvtxtree_->Branch("pullx_spl1_mct",&pullx_spl1_mct_,"pullx_spl1_mct[nrecPV_spl1_mct]/D");
208 >      pvtxtree_->Branch("pully_spl1_mct",&pully_spl1_mct_,"pully_spl1_mct[nrecPV_spl1_mct]/D");
209 >      pvtxtree_->Branch("pullz_spl1_mct",&pullz_spl1_mct_,"pullz_spl1_mct[nrecPV_spl1_mct]/D");
210 >      // For pvtxs with splittracks1
211 >      pvtxtree_->Branch("nrecPV_spl2_mct",&nrecPV_spl2_mct_,"nrecPV_spl2_mct/I");
212 >      pvtxtree_->Branch("deltax_spl2_mct",&deltax_spl2_mct_,"deltax_spl2_mct[nrecPV_spl2_mct]/D");
213 >      pvtxtree_->Branch("deltay_spl2_mct",&deltay_spl2_mct_,"deltay_spl2_mct[nrecPV_spl2_mct]/D");
214 >      pvtxtree_->Branch("deltaz_spl2_mct",&deltaz_spl2_mct_,"deltaz_spl2_mct[nrecPV_spl2_mct]/D");
215 >      pvtxtree_->Branch("pullx_spl2_mct",&pullx_spl2_mct_,"pullx_spl2_mct[nrecPV_spl2_mct]/D");
216 >      pvtxtree_->Branch("pully_spl2_mct",&pully_spl2_mct_,"pully_spl2_mct[nrecPV_spl2_mct]/D");
217 >      pvtxtree_->Branch("pullz_spl2_mct",&pullz_spl2_mct_,"pullz_spl2_mct[nrecPV_spl2_mct]/D");
218 >    }
219 >  }
220 >
221 >  setRootStyle();
222 >
223 >  // Create a root file for histograms
224 >  theFile = new TFile(histoFileName_.c_str(), "RECREATE");
225 >  // make diretories
226 >  theFile->mkdir("Summary");
227 >  theFile->cd();
228 >  theFile->mkdir("Others");
229 >  theFile->cd();
230 >
231 >  // Book Histograms:
232 >  h_pvtrk   = new PVHistograms();
233 >  h_pixvtx  = new PVHistograms();
234 >  h_misc    = new PVHistograms();
235 >  h_summary = new PVHistograms();
236 >  h_others  = new PVHistograms();
237 >
238 >  for(int i=0;i<3;i++) {  
239 >    if(i == 0) h_pvtrk->Init("pvTrk");
240 >    else {
241 >      stringstream ss;
242 >      ss << i;
243 >      h_pvtrk->Init("pvTrk",ss.str(),"spl");
244 >    }
245 >  }
246 >  h_pixvtx->Init("pixVtx");
247 >  h_misc->Init("misc");
248  
249 +  // Book MC only plots
250    if (!realData_) {
251 <    h_deltax       = fs->make<TH1D>("deltax","x-distance (Rec - Sim)",800,-0.04,0.04);
252 <    h_deltay       = fs->make<TH1D>("deltay","y-distance (Rec - Sim)",800,-0.04,0.04);
253 <    h_deltaz       = fs->make<TH1D>("deltaz","z-distance (Rec - Sim)",800,-0.04,0.04);
254 <    h_pullx        = fs->make<TH1D>("pullx","x-pull (Rec - Sim)",1000,-25.,25.);
255 <    h_pully        = fs->make<TH1D>("pully","y-pull (Rec - Sim)",1000,-25.,25.);
256 <    h_pullz        = fs->make<TH1D>("pullz","z-pull (Rec - Sim)",1000,-25.,25.);
257 <
258 <    // Summary of analysis:
259 <    if (analyze_) {
260 <      h_resx_nTrk    = fs->make<TH2D>("resx_ntrk","x-resolution (Rec - Sim) vs number of tracks",150,0,150,400,0.,200);
261 <      h_resx_nTrk->SetMarkerStyle(21);
262 <      h_resx_nTrk->SetMarkerColor(4);
263 <      h_resx_nTrk->GetXaxis()->SetTitle("Num of tracks");
264 <      h_resx_nTrk->GetYaxis()->SetTitle("#mum");
265 <      h_resy_nTrk    = fs->make<TH2D>("resy_ntrk","y-resolution (Rec - Sim) vs number of tracks",150,0,150,400,0.,200);
266 <      h_resy_nTrk->SetMarkerStyle(21);
267 <      h_resy_nTrk->SetMarkerColor(4);
109 <      h_resy_nTrk->GetXaxis()->SetTitle("Num of tracks");
110 <      h_resy_nTrk->GetYaxis()->SetTitle("#mum");
111 <      h_resz_nTrk    = fs->make<TH2D>("resz_ntrk","z-resolution (Rec - Sim) vs number of tracks",150,0,150,400,0.,200);
112 <      h_resz_nTrk->SetMarkerStyle(21);
113 <      h_resz_nTrk->SetMarkerColor(4);
114 <      h_resz_nTrk->GetXaxis()->SetTitle("Num of tracks");
115 <      h_resz_nTrk->GetYaxis()->SetTitle("#mum");
116 <      h_pullx_nTrk   = fs->make<TH2D>("pullx_ntrk","x-pull (Rec - Sim) vs number of tracks",150,0,150,100,0.,2.);
117 <      h_pullx_nTrk->SetMarkerStyle(21);
118 <      h_pullx_nTrk->SetMarkerColor(4);
119 <      h_pullx_nTrk->SetBit(TH1::kCanRebin);
120 <      h_pullx_nTrk->GetXaxis()->SetTitle("Num of tracks");
121 <      h_pully_nTrk   = fs->make<TH2D>("pully_ntrk","y-pull (Rec - Sim) vs number of tracks",150,0,150,100,0.,2.);
122 <      h_pully_nTrk->SetMarkerStyle(21);
123 <      h_pully_nTrk->SetMarkerColor(4);
124 <      h_pully_nTrk->SetBit(TH1::kCanRebin);
125 <      h_pully_nTrk->GetXaxis()->SetTitle("Num of tracks");
126 <      h_pullz_nTrk   = fs->make<TH2D>("pullz_ntrk","z-pull (Rec - Sim) vs number of tracks",150,0,150,100,0.,2.);
127 <      h_pullz_nTrk->SetMarkerStyle(21);
128 <      h_pullz_nTrk->SetMarkerColor(4);
129 <      h_pullz_nTrk->SetBit(TH1::kCanRebin);
130 <      h_pullz_nTrk->GetXaxis()->SetTitle("Num of tracks");
251 >    h_gen = new PVHistograms();
252 >    h_gen->Init("generator");
253 >  }
254 >
255 >  //Book histograms sensitive to data/mc
256 >  for (vector<int>::const_iterator it= datamode.begin(); it != datamode.end() ; ++it) {
257 >    string suffix;
258 >    if(verbose_)  cout<<"datamode = "<< *it<<endl;
259 >    switch(*it) {
260 >    case 0: suffix = "";
261 >      break;
262 >    case 1: suffix = "_spl1_mct";
263 >      break;
264 >    case 2: suffix = "_spl2_mct";      
265 >      break;
266 >    case 3: suffix = "_mct";
267 >      break;
268      }
269 +    h_summary->Init("summary",suffix);
270 +    
271 +    // Book residual, error and pull histograms for each nTrk bin
272      for (int ntrk=nTrkMin_;ntrk<=nTrkMax_;++ntrk) {
273        stringstream ss;
274        ss << ntrk;
275 <      string suffix = ss.str();
136 <      h["resx_"+suffix]  = fs->make<TH1D> (TString("deltax_"+suffix),"x-distance (Rec - Sim)",100,-0.02,0.02);
137 <      h["resx_"+suffix]->GetXaxis()->SetTitle("cm");
138 <      h["resy_"+suffix]  = fs->make<TH1D> (TString("deltay_"+suffix),"y-distance (Rec - Sim)",100,-0.02,0.02);
139 <      h["resy_"+suffix]->GetXaxis()->SetTitle("cm");
140 <      h["resz_"+suffix]  = fs->make<TH1D> (TString("deltaz_"+suffix),"z-distance (Rec - Sim)",100,-0.02,0.02);
141 <      h["resz_"+suffix]->GetXaxis()->SetTitle("cm");
142 <      h["pullx_"+suffix] = fs->make<TH1D> (TString("pullx_"+suffix),"x-pull (Rec - Sim)",100,-10.,10.);
143 <      h["pully_"+suffix] = fs->make<TH1D> (TString("pully_"+suffix),"y-pull (Rec - Sim)",100,-10.,10.);
144 <      h["pullz_"+suffix] = fs->make<TH1D> (TString("pullz_"+suffix),"z-pull (Rec - Sim)",100,-10.,10.);
145 <      suffix.clear();
275 >      h_others->Init("others",suffix,ss.str());
276      }
147  }
148 }
277  
278 +    // Book residual and pull histograms only when analyzeOntheFly is enabled
279 +    if(analyze_) {
280 +      h_ana = new PVHistograms();
281 +      h_ana->InitA("analysis",suffix,"nTrk",nTrkMin_,nTrkMax_);
282 +    }
283 +    suffix.clear();
284 +  } // End of Book histograms sensitive to data/mc    
285 +
286 + }
287  
288   PVStudy::~PVStudy()
289   {
290 <
291 <  // do anything here that needs to be done at desctruction time
292 <  // (e.g. close files, deallocate resources etc.)
290 >  theFile->cd();
291 >  theFile->cd("Summary");
292 >  h_pvtrk->Save();
293 >  h_pixvtx->Save();
294 >  h_gen->Save();
295 >  h_misc->Save();
296 >  h_summary->Save();
297 >  if (analyze_)
298 >    h_ana->Save();
299 >  theFile->cd();
300 >  theFile->cd("Others");
301 >  h_others->Save();
302  
303 +  theFile->Close();
304   }
305  
306 <
306 > void PVStudy::setRootStyle() {
307 >  //
308 >  gROOT->SetStyle("Plain");
309 >  gStyle->SetFillColor(1);
310 >  gStyle->SetOptDate();
311 >  //   gStyle->SetOptStat(1111110);
312 >  //   gStyle->SetOptFit(0111);
313 >  //   gStyle->SetPadTickX(1);
314 >  //   gStyle->SetPadTickY(1);
315 >  gStyle->SetMarkerSize(0.5);
316 >  gStyle->SetMarkerStyle(8);
317 >  gStyle->SetGridStyle(3);
318 >  //gStyle->SetPadGridX(1);
319 >  //gStyle->SetPadGridY(1);
320 >  gStyle->SetPaperSize(TStyle::kA4);
321 >  gStyle->SetStatW(0.25);             // width of statistics box; default is 0.19
322 >  //   gStyle->SetStatH(0.10);             // height of statistics box; default is 0.1
323 >  gStyle->SetStatFormat("6.4g");      // leave default format for now
324 >  gStyle->SetTitleSize(0.055, "");    // size for pad title; default is 0.02
325 >  gStyle->SetLabelSize(0.03, "XYZ");  // size for axis labels; default is 0.04
326 >  gStyle->SetStatFontSize(0.08);      // size for stat. box
327 >  gStyle->SetTitleFont(32, "XYZ");    // times-bold-italic font (p. 153) for axes
328 >  gStyle->SetTitleFont(32, "");       // same for pad title
329 >  gStyle->SetLabelFont(32, "XYZ");    // same for axis labels
330 >  gStyle->SetStatFont(32);            // same for stat. box
331 >  gStyle->SetLabelOffset(0.006, "Y"); // default is 0.005
332 >  //
333 >  return;
334 > }
335   //
336   // member functions
337   //
# Line 172 | Line 347 | std::vector<PVStudy::simPrimaryVertex> P
347        cout << "number of vertices " << evt->vertices_size() << endl;
348      }
349  
350 <    int idx=0;
350 >    int idx=0; int npv=0;
351      for(HepMC::GenEvent::vertex_const_iterator vitr= evt->vertices_begin();
352 <        vitr != evt->vertices_end(); ++vitr )
353 <      { // loop for vertex ...
354 <        HepMC::FourVector pos = (*vitr)->position();
355 <        //HepLorentzVector pos = (*vitr)->position();
356 <        if (pos.t()>0) { continue;} // ?
357 <        
358 <        bool hasMotherVertex=false;
359 <        //      if(verbose_) cout << "mothers" << endl;
360 <        for ( HepMC::GenVertex::particle_iterator mother  = (*vitr)->particles_begin(HepMC::parents);
361 <              mother != (*vitr)->particles_end(HepMC::parents); ++mother ) {
362 <          HepMC::GenVertex * mv=(*mother)->production_vertex();
363 <          if (mv) {hasMotherVertex=true;}
364 <          //      if(verbose_) {
365 <          //        cout << "\t";
191 <          //        (*mother)->print();
192 <          //      }
193 <        }
194 <
195 <        if(hasMotherVertex) {continue;}
196 <
197 <        // could be a new vertex, check  all primaries found so far to avoid multiple entries
198 <        const double mm2cm=0.1;
199 <        simPrimaryVertex sv(pos.x()*mm2cm,pos.y()*mm2cm,pos.z()*mm2cm); // sim unit mm, rec unit cm
200 <        simPrimaryVertex *vp=NULL;  // will become non-NULL if a vertex is found and then point to it
201 <        for(vector<simPrimaryVertex>::iterator v0=simpv.begin();
202 <            v0!=simpv.end(); v0++){
203 <          if( (fabs(sv.x-v0->x)<1e-5) && (fabs(sv.y-v0->y)<1e-5) && (fabs(sv.z-v0->z)<1e-5)){
204 <            vp=&(*v0);
205 <            break;
352 >        vitr != evt->vertices_end(); ++vitr ) { // loop for vertex ...
353 >      HepMC::FourVector pos = (*vitr)->position();
354 >      //HepLorentzVector pos = (*vitr)->position();
355 >
356 >      // t component of PV:
357 >      for ( HepMC::GenVertex::particle_iterator mother  = (*vitr)->particles_begin(HepMC::parents);
358 >            mother != (*vitr)->particles_end(HepMC::parents); ++mother ) {
359 >        //        std::cout << "Status = " << (*mother)->status() << std::endl;
360 >        HepMC::GenVertex * mv=(*mother)->production_vertex();
361 >        if( ((*mother)->status() == 3) && (!mv)) {
362 >          //        std::cout << "npv= " << npv << std::endl;
363 >          if (npv == 0) {
364 >            h_gen->Fill1d("genPart_cT", pos.t()); // mm
365 >            h_gen->Fill1d("genPart_T", pos.t()/299.792458); // ns
366            }
367 +          npv++;
368 +        }
369 +      }
370 +      //       if (pos.t()>0) { continue;} // for 22X when t of PV was not smeared
371 +        
372 +      bool hasMotherVertex=false;
373 +      if(verbose_) cout << "mothers of vertex[" << ++idx << "]: " << endl;
374 +      for ( HepMC::GenVertex::particle_iterator mother  = (*vitr)->particles_begin(HepMC::parents);
375 +            mother != (*vitr)->particles_end(HepMC::parents); ++mother ) {
376 +        HepMC::GenVertex * mv=(*mother)->production_vertex();
377 +        //        std::cout << "Status = " << (*mother)->status() << std::endl;
378 +        if (mv) {
379 +          hasMotherVertex=true;
380 +          if(!verbose_) break; //if verbose_, print all particles of gen vertices
381          }
382 +        if(verbose_) {
383 +          cout << "\t";
384 +          (*mother)->print();
385 +        }
386 +      }
387  
388 <        if(!vp){
389 <          // this is a new vertex
390 <          if(verbose_) cout << "this is a new vertex " << sv.x << " " << sv.y << " " << sv.z << endl;
391 <          simpv.push_back(sv);
392 <          vp=&simpv.back();
393 <        }else{
394 <          if(verbose_) cout << "this is not a new vertex " << sv.x << " " << sv.y << " " << sv.z << endl;
395 <        }
396 <        vp->genVertex.push_back((*vitr)->barcode());
397 <        // collect final state descendants
398 <        for ( HepMC::GenVertex::particle_iterator
399 <                daughter  = (*vitr)->particles_begin(HepMC::descendants);
400 <              daughter != (*vitr)->particles_end(HepMC::descendants);
401 <              ++daughter ) {
402 <          if (isFinalstateParticle(*daughter)){
403 <            if ( find(vp->finalstateParticles.begin(), vp->finalstateParticles.end(),(*daughter)->barcode())
404 <                 == vp->finalstateParticles.end()){
405 <              vp->finalstateParticles.push_back((*daughter)->barcode());
406 <              HepMC::FourVector m=(*daughter)->momentum();
407 <              // the next four lines used to be "vp->ptot+=m;" in the days of CLHEP::HepLorentzVector
408 <              // but adding FourVectors seems not to be foreseen
409 <              vp->ptot.setPx(vp->ptot.px()+m.px());
410 <              vp->ptot.setPy(vp->ptot.py()+m.py());
411 <              vp->ptot.setPz(vp->ptot.pz()+m.pz());
412 <              vp->ptot.setE(vp->ptot.e()+m.e());
413 <              vp->ptsq+=(m.perp())*(m.perp());
414 <              if ( (m.perp()>0.8) && (fabs(m.pseudoRapidity())<2.5) && isCharged( *daughter ) ){
415 <                vp->nGenTrk++;
416 <              }
388 >      if(hasMotherVertex) continue;
389 >
390 >      // could be a new vertex, check  all primaries found so far to avoid multiple entries
391 >      const double mm2cm=0.1;
392 >      simPrimaryVertex sv(pos.x()*mm2cm,pos.y()*mm2cm,pos.z()*mm2cm); // sim unit mm, rec unit cm
393 >      simPrimaryVertex *vp=NULL;  // will become non-NULL if a vertex is found and then point to it
394 >      for(vector<simPrimaryVertex>::iterator v0=simpv.begin();
395 >          v0!=simpv.end(); v0++){
396 >        if( (fabs(sv.x-v0->x)<1e-5) && (fabs(sv.y-v0->y)<1e-5) && (fabs(sv.z-v0->z)<1e-5)){
397 >          vp=&(*v0);
398 >          break;
399 >        }
400 >      }
401 >
402 >      if(!vp){
403 >        // this is a new vertex
404 >        if(verbose_) cout << "this is a new vertex " << sv.x << " " << sv.y << " " << sv.z << endl;
405 >        simpv.push_back(sv);
406 >        vp=&simpv.back();
407 >      }else{
408 >        if(verbose_) cout << "this is not a new vertex " << sv.x << " " << sv.y << " " << sv.z << endl;
409 >      }
410 >      vp->genVertex.push_back((*vitr)->barcode());
411 >      // collect final state descendants
412 >      for ( HepMC::GenVertex::particle_iterator daughter  = (*vitr)->particles_begin(HepMC::descendants);
413 >            daughter != (*vitr)->particles_end(HepMC::descendants);
414 >            ++daughter ) {
415 >        if (isFinalstateParticle(*daughter)){
416 >          if ( find(vp->finalstateParticles.begin(), vp->finalstateParticles.end(),(*daughter)->barcode())
417 >               == vp->finalstateParticles.end()){
418 >            vp->finalstateParticles.push_back((*daughter)->barcode());
419 >            HepMC::FourVector m=(*daughter)->momentum();
420 >            // the next four lines used to be "vp->ptot+=m;" in the days of CLHEP::HepLorentzVector
421 >            // but adding FourVectors seems not to be foreseen
422 >            vp->ptot.setPx(vp->ptot.px()+m.px());
423 >            vp->ptot.setPy(vp->ptot.py()+m.py());
424 >            vp->ptot.setPz(vp->ptot.pz()+m.pz());
425 >            vp->ptot.setE(vp->ptot.e()+m.e());
426 >            vp->ptsq+=(m.perp())*(m.perp());
427 >            if ( (m.perp()>0.8) && (fabs(m.pseudoRapidity())<2.5) && isCharged( *daughter ) ){
428 >              vp->nGenTrk++;
429              }
430            }
431          }
432 <        idx++;
433 <      }
432 >      }//loop MC vertices daughters
433 >    }//loop MC vertices
434    }
435    return simpv;
436   }
# Line 272 | Line 463 | std::vector<PVStudy::simPrimaryVertex> P
463                ptsq+=(*daughter)->momentum().perp()*(*daughter)->momentum().perp();
464              }
465            }
466 <          primary =  ( gv->position().t()==0);
466 >          //primary =  ( gv->position().t()==0 );
467 >          primary = true;
468 >          h_gen->Fill1d("genPart_cT", gv->position().t()); // mm
469 >          h_gen->Fill1d("genPart_T", gv->position().t()/299.792458); // ns
470 >
471            //resonance= ( gp->mother() && isResonance(gp->mother()));  // in CLHEP/HepMC days
472            // no more mother pointer in the improved HepMC GenParticle
473            resonance= ( isResonance(*(gp->production_vertex()->particles_in_const_begin())));
# Line 319 | Line 514 | void
514   PVStudy::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
515   {
516    using namespace edm;
517 <  using reco::TrackCollection;
517 >  using namespace reco;
518 >  
519 >  if (verbose_)
520 >    cout<<"PVStudy::analyze():"<<endl;
521 >  //=======================================================
522 >  // Initialize Root-tuple variables if needed
523 >  //=======================================================
524 >  //if(saventuple_)
525 >  SetVarToZero();
526 >  
527 >  //=======================================================
528 >  // Track accessors
529 >  //=======================================================
530 >  //trackCollection
531 >  static const reco::TrackCollection s_empty_trackColl;
532 >  const reco::TrackCollection *trackColl = &s_empty_trackColl;
533 >  edm::Handle<reco::TrackCollection> trackCollectionHandle;
534 >  iEvent.getByLabel(trackCollectionTag_, trackCollectionHandle);
535 >  if( iEvent.getByLabel(trackCollectionTag_, trackCollectionHandle)) {
536 >    trackColl = trackCollectionHandle.product();
537 >  } else {
538 >    cout << "trackCollection cannot be found -> using empty collection of same type." <<endl;
539 >  }
540  
541 <  ftree_->SetBranchAddress("residual",&fres);
542 <  ftree_->SetBranchAddress("error",&ferror);
543 <  ftree_->SetBranchAddress("nTrk",&fntrk);
541 >  //splitTrackCollection1
542 >  static const reco::TrackCollection s_empty_splitTrackColl1;
543 >  const reco::TrackCollection *splitTrackColl1 = &s_empty_splitTrackColl1;
544 >  edm::Handle<reco::TrackCollection> splitTrackCollection1Handle;
545 >  iEvent.getByLabel(splitTrackCollection1Tag_, splitTrackCollection1Handle);
546 >  if( iEvent.getByLabel(splitTrackCollection1Tag_, splitTrackCollection1Handle)) {
547 >    splitTrackColl1 = splitTrackCollection1Handle.product();
548 >  } else {
549 >    cout << "splitTrackCollection1 cannot be found -> using empty collection of same type." <<endl;
550 >  }
551  
552 <  Handle<TrackCollection> tracks;
553 <  iEvent.getByLabel(tracksLabel_,tracks);
552 >  //splitTrackCollection2
553 >  static const reco::TrackCollection s_empty_splitTrackColl2;
554 >  const reco::TrackCollection *splitTrackColl2 = &s_empty_splitTrackColl2;
555 >  edm::Handle<reco::TrackCollection> splitTrackCollection2Handle;
556 >  iEvent.getByLabel(splitTrackCollection2Tag_, splitTrackCollection2Handle);
557 >  if( iEvent.getByLabel(splitTrackCollection2Tag_, splitTrackCollection2Handle)) {
558 >    splitTrackColl2 = splitTrackCollection2Handle.product();
559 >  } else {
560 >    cout << "splitTrackCollection2 cannot be found -> using empty collection of same type." <<endl;
561 >  }
562  
331  Handle<reco::VertexCollection> recVtxs;
332  iEvent.getByLabel(vtxSample_, recVtxs);
563  
564 +  //=======================================================
565 +  // Fill trackparameters of the input tracks to pvtx fitter
566 +  //=======================================================
567 +  if(verbose_)
568 +    cout<<"Start filling track parameters of the input tracks to pvtx fitter."<<endl;
569 +  //fillTrackHisto(const reco::TrackCollection *trackColl, int datatype)
570 +  // datatype: unsplittracks (0); splittracks1 (1);  splittracks2 (2);
571 +  fillTrackHisto(trackColl, 0);
572 +  fillTrackHisto(splitTrackColl1, 1);
573 +  fillTrackHisto(splitTrackColl2, 2);
574 +  if(verbose_)
575 +    cout<<"End filling track parameters of the input tracks to pvtx fitter."<<endl;
576 +
577 +  //=======================================================
578 +  // PVTX accessors
579 +  //=======================================================
580 +  //vertexCollection
581 +  static const reco::VertexCollection s_empty_vertexColl;
582 +  const reco::VertexCollection *vertexColl = &s_empty_vertexColl;
583 +  edm::Handle<reco::VertexCollection> vertexCollectionHandle;
584 +  iEvent.getByLabel(vertexCollectionTag_, vertexCollectionHandle);
585 +  if( iEvent.getByLabel(vertexCollectionTag_, vertexCollectionHandle)) {
586 +    vertexColl = vertexCollectionHandle.product();
587 +  } else {
588 +    cout << "vertexCollection cannot be found -> using empty collection of same type." <<endl;
589 +  }
590 +
591 +  //splitVertexCollection1
592 +  static const reco::VertexCollection s_empty_splitVertexColl1;
593 +  const reco::VertexCollection *splitVertexColl1 = &s_empty_splitVertexColl1;
594 +  edm::Handle<reco::VertexCollection> splitVertexCollection1Handle;
595 +  iEvent.getByLabel(splitVertexCollection1Tag_, splitVertexCollection1Handle);
596 +  if( iEvent.getByLabel(splitVertexCollection1Tag_, splitVertexCollection1Handle)) {
597 +    splitVertexColl1 = splitVertexCollection1Handle.product();
598 +  } else {
599 +    cout << "splitVertexCollection1 cannot be found -> using empty collection of same type." <<endl;
600 +  }
601 +
602 +  //splitVertexCollection2
603 +  static const reco::VertexCollection s_empty_splitVertexColl2;
604 +  const reco::VertexCollection *splitVertexColl2 = &s_empty_splitVertexColl2;
605 +  edm::Handle<reco::VertexCollection> splitVertexCollection2Handle;
606 +  iEvent.getByLabel(splitVertexCollection2Tag_, splitVertexCollection2Handle);
607 +  if( iEvent.getByLabel(splitVertexCollection2Tag_, splitVertexCollection2Handle)) {
608 +    splitVertexColl2 = splitVertexCollection2Handle.product();
609 +  } else {
610 +    cout << "splitVertexCollection2 cannot be found -> using empty collection of same type." <<endl;
611 +  }
612 +  
613 +  if(verbose_) cout<<"End accessing the track and vertex collections"<<endl;
614 +  
615 +  //=======================================================
616 +  // MC simvtx accessor
617 +  //=======================================================
618    if (!realData_) {
619 <    Handle<SimVertexContainer> simVtxs;
619 >    edm::Handle<SimVertexContainer> simVtxs;
620      iEvent.getByLabel( simG4_, simVtxs);
621      
622 <    Handle<SimTrackContainer> simTrks;
622 >    edm::Handle<SimTrackContainer> simTrks;
623      iEvent.getByLabel( simG4_, simTrks);
624    }
625  
626 <  if(verbose_) printRecVtxs(recVtxs);
627 <
626 >  //=======================================================
627 >  // GET PDT
628 >  //=======================================================
629    try{
630      iSetup.getData(pdt);
631    }catch(const Exception&){
632      cout << "Some problem occurred with the particle data table. This may not work !." <<endl;
633    }
634 +  
635 +  //=======================================================
636 +  // GET pixelVertices
637 +  //=======================================================
638 +  static const reco::VertexCollection s_empty_pixelVertexColl;
639 +  const reco::VertexCollection *pixelVertexColl = &s_empty_pixelVertexColl;
640 +  edm::Handle<reco::VertexCollection>  pixelVertexCollectionHandle;
641 +  iEvent.getByLabel(pixelVertexCollectionTag_, pixelVertexCollectionHandle);
642 +  if( iEvent.getByLabel(pixelVertexCollectionTag_, pixelVertexCollectionHandle)) {
643 +    pixelVertexColl = pixelVertexCollectionHandle.product();
644 +  } else {
645 +    cout << "pixelVertexCollection cannot be found. -> using empty collection of same type." <<endl;
646 +  }
647  
648 +  //=======================================================
649 +  // Fill pixelVertices related histograms
650 +  //=======================================================
651 +  nrecPV_pxlpvtx_ = int (pixelVertexColl->size());
652 +  if(pixelVertexColl->size()>0 && pixelVertexColl->begin()->isValid() && !(pixelVertexColl->begin()->isFake())) {
653 +    //fillTrackHistoInPV(const reco::VertexCollection *vertexColl, int datatype, bool fillHisto, bool fillNtuple) {
654 +    fillTrackHistoInPV(pixelVertexColl, 4, false, true);
655 +    h_pixvtx->Fill1d("dzErr_pxlpvtx", pixelVertexColl->begin()->zError());    
656 +    // Get the dZ error of the tracks in the leading pixelVertexColl
657 +    for(reco::Vertex::trackRef_iterator t = (pixelVertexColl->begin())->tracks_begin();
658 +        t!= (pixelVertexColl->begin())->tracks_end(); t++) {
659 +      
660 +      if ( (**t).charge() < -1 || (**t).charge() > 1 ) {
661 +        //        h_pvtrk->Fill1d("trkPtPV", 0.);
662 +      }
663 +      else
664 +        h_pixvtx->Fill1d("trkdzErr_pxlpvtx", (**t).dzError());
665 +    }
666 +    // Fill the track->dz() in the PV difference from first pixelpvtx
667 +    for(reco::Vertex::trackRef_iterator t = (vertexColl->begin())->tracks_begin();
668 +        t!= (vertexColl->begin())->tracks_end(); t++) {
669 +      // illegal charge
670 +      if ( (**t).charge() < -1 || (**t).charge() > 1 ) {
671 +        //        h_pvtrk->Fill1d("trkPtPV", 0.);
672 +      }
673 +      else {
674 +        if(pixelVertexColl->size()>0) {
675 +          h_pixvtx->Fill1d("trkdz_pxlpvtxdz", (**t).dz() -  pixelVertexColl->begin()->z());
676 +          h_pixvtx->Fill1d("trkdz_pxlpvtxdz_pxlpvtxdzerr", fabs((**t).dz() -  pixelVertexColl->begin()->z())/pixelVertexColl->begin()->zError());
677 +          h_pixvtx->Fill1d("trkdz_pxlpvtxdz_trkdzerr", fabs((**t).dz() -  pixelVertexColl->begin()->z())/(**t).dzError());
678 +          h_pixvtx->Fill1d("trkdzErr_pvtx", (**t).dzError());
679 +        }
680 +      }
681 +    }
682 +  }
683 +
684 +  //=======================================================
685 +  // Fill number of reconstructed vertices
686 +  //=======================================================
687 +
688 +  if(verbose_)  {
689 +    cout<<"PVStudy::analyze() Printing vertexCollection: "<<endl;
690 +    printRecVtxs(vertexCollectionHandle);
691 +    cout<<"PVStudy::analyze() Printing splitVertexCollection1: "<<endl;
692 +    printRecVtxs(splitVertexCollection1Handle);
693 +    cout<<"PVStudy::analyze() Printing splitVertexCollection2: "<<endl;
694 +    printRecVtxs(splitVertexCollection2Handle);
695 +    cout<<"Start filling pvtx parameters."<<endl;
696 +  }
697 +  
698 +  nrecPV_ = int (vertexColl->size());
699 +  nrecPV1_spl_ = int (splitVertexColl1->size());
700 +  nrecPV2_spl_ = int (splitVertexColl2->size());
701 +
702 +  h_pvtrk->Fill1d("nrecPV", nrecPV_);
703 +  h_pvtrk->Fill1d("nrecPV1_spl", nrecPV1_spl_);
704 +  h_pvtrk->Fill1d("nrecPV2_spl", nrecPV2_spl_);
705 +  h_misc->Fill1d("nrecPVDiff", double(nrecPV1_spl_)-double(nrecPV2_spl_));
706 +  
707 +  //=================================================================
708 +  // Fill track parameter ntuple/hist for tracks used in recoVertices
709 +  //=================================================================
710 +
711 +  //fillTrackHistoInPV(const reco::VertexCollection *vertexColl, int datatype, bool fillHisto, bool fillNtuple) {
712 +  if(vertexColl->size() > 0 && vertexColl->begin()->isValid() && !(vertexColl->begin()->isFake()))
713 +    fillTrackHistoInPV(vertexColl, 0, true, true);
714 +  
715 +  if(splitVertexColl1->size() > 0 && splitVertexColl1->begin()->isValid() && !(splitVertexColl1->begin()->isFake()))
716 +    fillTrackHistoInPV(splitVertexColl1, 1, false, true);
717 +
718 +  if(splitVertexColl1->size() > 0 && splitVertexColl2->begin()->isValid() && !(splitVertexColl2->begin()->isFake()))
719 +    fillTrackHistoInPV(splitVertexColl2, 2, false, true);
720 +
721 +
722 +  //=======================================================
723 +  // Compare offlinePrimaryVertices with pixelVertices
724 +  //=======================================================
725 +  if( (pixelVertexColl->size()>0 && pixelVertexColl->begin()->isValid() && !(pixelVertexColl->begin()->isFake()))
726 +      && (vertexColl->size()>0 && vertexColl->begin()->isValid() && !(vertexColl->begin()->isFake())) ) {    
727 +    h_pixvtx->Fill1d("nrecPV_minus_nrecPxlPV", double (nrecPV_ - nrecPV_pxlpvtx_));
728 +    // difference in reconstructed position of the leading pvtx
729 +    //cout<<"recx_[0] = "<< recx_[0] << "recx_pxlpvtx_[0] = "<< recx_pxlpvtx_[0]<<endl;  
730 +    //cout<<"recy_[0] = "<< recy_[0] << "recy_pxlpvtx_[0] = "<< recy_pxlpvtx_[0]<<endl;
731 +    h_pixvtx->Fill1d("recxPV_minus_recxPxlPV", recx_[0] - recx_pxlpvtx_[0]);
732 +    h_pixvtx->Fill1d("recyPV_minus_recyPxlPV", recy_[0] - recy_pxlpvtx_[0]);
733 +    h_pixvtx->Fill1d("reczPV_minus_reczPxlPV", recz_[0] - recz_pxlpvtx_[0]);
734 +  }
735 +  
736 +
737 +
738 +  //==========================================================
739 +  // Fill secondary/primary min separations for multi-vertices
740 +  //==========================================================
741 +  
742 +  if(vertexColl->size()>1 && vertexColl->begin()->isValid() && !(vertexColl->begin()->isFake()) ) {  
743 +
744 +    double min_xsep = 9999.0;
745 +    double min_ysep = 9999.0;
746 +    double min_zsep = 9999.0;    
747 +    double min_xsep_sign = 9999.0;
748 +    double min_ysep_sign = 9999.0;
749 +    double min_zsep_sign = 9999.0;
750 +    double min_ntrksep = 9999.0;
751 +    double min_sumpt2sep = 9999999.0;
752 +    
753 +    if(verbose_) cout<<"leading pvtx z = "<< vertexColl->begin()->z() <<endl;
754 +
755 +    // Looping through the secondary vertices to find the mininum separation to the primary
756 +    for(reco::VertexCollection::const_iterator v=vertexColl->begin() + 1 ;
757 +        v!=vertexColl->end(); ++v) {  
758 +      if(v->isValid() && ! v->isFake()) {
759 +        // xsep
760 +        if(fabs(v->x()- vertexColl->begin()->x())<min_xsep)
761 +          min_xsep = fabs(v->x()- vertexColl->begin()->x());
762 +        // ysep
763 +        if(fabs(v->y()- vertexColl->begin()->y())<min_ysep)
764 +          min_ysep = fabs(v->y()- vertexColl->begin()->y());
765 +        // zsep
766 +        if(fabs(v->z()- vertexColl->begin()->z())<min_zsep)
767 +          min_zsep = fabs(v->z()- vertexColl->begin()->z());
768 +        // xsep_sign
769 +        double xsep_sign = fabs(v->x()- vertexColl->begin()->x())/max(v->xError(), vertexColl->begin()->xError());
770 +        if(xsep_sign < min_xsep_sign)
771 +          min_xsep_sign = xsep_sign;
772 +        // ysep_sign
773 +        double ysep_sign = fabs(v->y()- vertexColl->begin()->y())/max(v->yError(), vertexColl->begin()->yError());
774 +        if(ysep_sign < min_ysep_sign)
775 +          min_ysep_sign = ysep_sign;
776 +        // zsep_sign
777 +        double zsep_sign = fabs(v->z()- vertexColl->begin()->z())/max(v->zError(), vertexColl->begin()->zError());
778 +        if(zsep_sign < min_zsep_sign)
779 +          min_zsep_sign = zsep_sign;
780 +        // ntrksep
781 +        if( (double(vertexColl->begin()->tracksSize()) - double(v->tracksSize())) < min_ntrksep)
782 +          min_ntrksep = double(vertexColl->begin()->tracksSize()) - double(v->tracksSize());
783 +        // sumpt2sep
784 +        if(fabs(sumPtSquared(*v) - sumPtSquared(*(vertexColl->begin()))) < min_sumpt2sep)
785 +          min_sumpt2sep = fabs(sumPtSquared(*v) - sumPtSquared(*(vertexColl->begin())));
786 +      }
787 +    }
788 +    h_misc->Fill1d("min_xsep", min_xsep);
789 +    h_misc->Fill1d("min_ysep", min_ysep);
790 +    h_misc->Fill1d("min_zsep", min_zsep);
791 +    h_misc->Fill1d("min_xsep_sign", min_xsep_sign);
792 +    h_misc->Fill1d("min_ysep_sign", min_ysep_sign);
793 +    h_misc->Fill1d("min_zsep_sign", min_zsep_sign);
794 +    h_misc->Fill1d("min_ntrksep", min_ntrksep);
795 +    h_misc->Fill1d("min_sumpt2sep", min_sumpt2sep);
796 +
797 +    min_zsep_ = min_zsep;
798 +    min_ntrksep_ = min_ntrksep;
799 +    min_sumpt2sep_ = min_sumpt2sep;
800 +
801 +
802 +  } // End of  if(vertexColl->size()>1) {
803 +  
804 +  if(verbose_)
805 +    cout<<"End filling pvtx parameters."<<endl;
806 +  
807 +  //=======================================================
808 +  //           PrimaryVertex Matching
809 +  // 1. In z  |z1-z2|< zsigncut * max(sigmaz1, sigmaz2)
810 +  // 2. |(nTrkPV1 - nTrkPV2)/(nTrkPV1+nTrkPV2)|<ntrkdiffcut_
811 +  // Assume the first match is the primary vertex,
812 +  // since vertexColl are sorted in decreasing order of sum(pT)
813 +  //=======================================================
814 +
815 +  if(verbose_)   cout<<"PVStudy::analyze(): matching pvtxs "<<endl;
816 +  reco::VertexCollection s_empty_matchedVertexColl1;
817 +  reco::VertexCollection *matchedVertexColl1 = &s_empty_matchedVertexColl1;
818 +  matchedVertexColl1->reserve(splitVertexColl1->size());
819 +  reco::VertexCollection s_empty_matchedVertexColl2;
820 +  reco::VertexCollection *matchedVertexColl2 = &s_empty_matchedVertexColl2;
821 +  matchedVertexColl2->reserve(splitVertexColl2->size());
822 +  
823 +  bool stopmatching = false;
824 +  for (size_t ivtx = 0; ivtx<splitVertexCollection1Handle->size() && !stopmatching; ++ivtx) {
825 +    reco::VertexRef recvtx1(splitVertexCollection1Handle, ivtx);
826 +    if( !(recvtx1->isValid()) || recvtx1->isFake()) break;
827 +    for (size_t jvtx = ivtx; jvtx < splitVertexCollection2Handle->size(); ++jvtx) {    
828 +      //------------------------------------------------------------------------
829 +      //== If only considering matching the first vertex of the splitVertexColl
830 +      //------------------------------------------------------------------------
831 +      if (ivtx!=0 || jvtx!=0) { stopmatching = true; break; }
832 +      reco::VertexRef recvtx2(splitVertexCollection2Handle, jvtx);
833 +      if( !(recvtx2->isValid()) || recvtx2->isFake()) break;
834 +      if(verbose_) {
835 +        cout<<"Matching splitVertexColl1: #  "<< ivtx<< " and splitVertexColl1: # "<<jvtx<<endl;
836 +        cout<<"recvtx1->z() = " << recvtx1->z() << "+/- "<< recvtx1->zError() << "." << endl;
837 +        cout<<"recvtx2->z() = " << recvtx2->z() << "+/- "<< recvtx2->zError() << "." << endl;
838 +      }
839 +      if(matchVertex(recvtx1, recvtx2, zsigncut_)) {
840 +        if(verbose_) {
841 +          cout<<"The two splitted vertices match in Z. "<<endl;
842 +        }
843 +        int nTrkPV1 = recvtx1->tracksSize();
844 +        int nTrkPV2 = recvtx2->tracksSize();    
845 +        double ntrkreldiff = double(nTrkPV1-nTrkPV2)/double(nTrkPV1+nTrkPV2);
846 +        h_misc->Fill1d("nTrkPVDiff", nTrkPV1-nTrkPV2);
847 +        h_misc->Fill1d("nTrkPVRelDiff", ntrkreldiff);
848 +        if(fabs(ntrkreldiff)<ntrkdiffcut_) {    
849 +          if(verbose_) {
850 +            cout<<"(nTrkPV1-nTrkPV2)/(nTrkPV1+nTrkPV2) = " << ntrkreldiff<<endl;
851 +          }
852 +          matchedVertexColl1->push_back(*recvtx1);
853 +          matchedVertexColl2->push_back(*recvtx2);
854 +          stopmatching = true; // stop the matching when the first match is found!
855 +          break;
856 +        }
857 +        else
858 +          cout<<"WARNING: (nTrkPV1-nTrkPV2)/(nTrkPV1+nTrkPV2) = " << ntrkreldiff<<", exceeding cut "<<ntrkdiffcut_<<endl;
859 +      }
860 +      else {
861 +        cout<<"WARNING: The two reconstructed vertices do not match in z: "<<endl;
862 +        cout<<"recvtx1->z() = " << recvtx1->z() << "+/- "<< recvtx1->zError() << "." << endl;
863 +        cout<<"recvtx2->z() = " << recvtx2->z() << "+/- "<< recvtx2->zError() << "." << endl;  
864 +      }
865 +    }
866 +  }
867 +  if(verbose_)     cout<<"PVStudy::analyze(): End matching pvtxs"<<endl;
868 +  
869 +  //=======================================================
870 +  //  Analyze matchedVertexColls
871 +  //=======================================================
872 +  if(verbose_) {
873 +    cout<<"Begin analyzing the matchedVertexColl with size = "<< matchedVertexColl1->size()<< endl;
874 +  }    
875 +  
876 +  // Compare the reconstructed vertex position and calculate resolution/pulls
877 +  if(matchedVertexColl1->size() != 0 && matchedVertexColl2->size() != 0) {  
878 +    //fillPvtxHisto(const reco::VertexCollection *vertexColl, int datatype, bool fillHisto, bool fillNtuple)
879 +    fillTrackHistoInPV(matchedVertexColl1, 1, true, false);
880 +    fillTrackHistoInPV(matchedVertexColl2, 2, true, false);
881 +
882 +    reco::VertexCollection::const_iterator v1;
883 +    reco::VertexCollection::const_iterator v2;
884 +    nrecPV_twovtx_ = 0;
885 +    for(v1 = matchedVertexColl1->begin(), v2 = matchedVertexColl2->begin();
886 +        v1!=matchedVertexColl1->end(), v2 != matchedVertexColl2->end();
887 +        ++v1, ++v2) {
888 +      fres_[0] = (v1->x()-v2->x())/sqrt(2.0);
889 +      fres_[1] = (v1->y()-v2->y())/sqrt(2.0);
890 +      fres_[2] = (v1->z()-v2->z())/sqrt(2.0);
891 +      ferror_[0] = sqrt(pow(v1->xError(),2)+pow(v2->xError(),2))/sqrt(2);
892 +      ferror_[1] = sqrt(pow(v1->yError(),2)+pow(v2->yError(),2))/sqrt(2);
893 +      ferror_[2] = sqrt(pow(v1->zError(),2)+pow(v2->zError(),2))/sqrt(2);
894 +      fntrk_ =  (v1->tracksSize()+v2->tracksSize())/2;
895 +      
896 +      h_summary->Fill1d("deltax", fres_[0] );
897 +      h_summary->Fill1d("deltay", fres_[1] );
898 +      h_summary->Fill1d("deltaz", fres_[2] );
899 +      h_summary->Fill1d("pullx", fres_[0]/ferror_[0]);
900 +      h_summary->Fill1d("pully", fres_[1]/ferror_[1]);
901 +      h_summary->Fill1d("pullz", fres_[2]/ferror_[2]);
902 +      h_summary->Fill1d("errPVx", ferror_[0] );
903 +      h_summary->Fill1d("errPVy", ferror_[1] );
904 +      h_summary->Fill1d("errPVz", ferror_[2] );
905 +      pvinfo.push_back(PVStudy::PVInfo(res(fres_[0], fres_[1], fres_[2]),
906 +                                       error(ferror_[0], ferror_[1], ferror_[2]),
907 +                                       fntrk_));
908 +      // Fill histo according to its track multiplicity, set datamode = 0 for pvtx using all tracks
909 +      fillHisto(res(fres_[0], fres_[1], fres_[2]),
910 +                error(ferror_[0], ferror_[1], ferror_[2]),
911 +                fntrk_,0);  
912 +      // Fill the ntuple variables
913 +      nTrkPV1_spl_twovtx_[nrecPV_twovtx_] = v1->tracksSize();
914 +      nTrkPV2_spl_twovtx_[nrecPV_twovtx_] = v2->tracksSize();
915 +      sumptsq1_spl_twovtx_[nrecPV_twovtx_] = sumPtSquared(*v1);
916 +      sumptsq2_spl_twovtx_[nrecPV_twovtx_] = sumPtSquared(*v2);
917 +      nTrkPV_twovtx_[nrecPV_twovtx_] = fntrk_;
918 +      deltax_twovtx_[nrecPV_twovtx_] = fres_[0];
919 +      deltay_twovtx_[nrecPV_twovtx_] = fres_[1];
920 +      deltaz_twovtx_[nrecPV_twovtx_] = fres_[2];
921 +      errx_twovtx_[nrecPV_twovtx_] = ferror_[0];
922 +      erry_twovtx_[nrecPV_twovtx_] = ferror_[1];
923 +      errz_twovtx_[nrecPV_twovtx_] = ferror_[2];
924 +      pullx_twovtx_[nrecPV_twovtx_] = fres_[0]/ferror_[0];
925 +      pully_twovtx_[nrecPV_twovtx_] = fres_[1]/ferror_[1];
926 +      pullz_twovtx_[nrecPV_twovtx_] = fres_[2]/ferror_[2];    
927 +      nrecPV_twovtx_++;
928 +    } // End of analyzing res/pull
929 +  } // End of  if(matchedVertexColl1->size() == 1 && matchedVertexColl2->size() == 1 ) {
930 +  else
931 +    cout<<"WARNING: Cannot find matching pvtxs"<<endl;
932 +  
933 +  if(verbose_)     cout<<"End analyzing the matchedVertexColl"<<endl;
934 +
935 +  //=======================================================
936 +  // Fill simulated vertices
937 +  //=======================================================
938    if (!realData_) {
939      bool MC=false;
940      Handle<HepMCProduct> evtMC;
# Line 362 | Line 950 | PVStudy::analyze(const edm::Event& iEven
950        }
951        MC=true;
952      }
953 <
953 >    
954      if(MC){
955        // make a list of primary vertices:
956        std::vector<simPrimaryVertex> simpv;
957        simpv=getSimPVs(evtMC,"");
958        //     simpv=getSimPVs(evtMC, simVtxs, simTrks);
959 <    
960 <      int nsimtrk=0;
961 <      int nrectrk=0;
959 >      h_gen->Fill1d("nsimPV", simpv.size());
960 >      nsimPV_ = simpv.size();
961 >
962 >      int isimpv = 0;
963        for(std::vector<simPrimaryVertex>::iterator vsim=simpv.begin();
964 <          vsim!=simpv.end(); vsim++){
965 <        nsimtrk+=vsim->nGenTrk;
966 <        // look for a matching reconstructed vertex
967 <        vsim->recVtx=NULL;
968 <        for(reco::VertexCollection::const_iterator vrec=recVtxs->begin();
969 <            vrec!=recVtxs->end(); ++vrec){
970 <          nrectrk=vrec->tracksSize();
971 <          if(verbose_){
972 <            cout << "sim primary vertex x = " << vsim->x << "; y = " << vsim->y << "; z = " << vsim->z <<  endl;
973 <            cout << "Is matched? " << (matchVertex(*vsim,*vrec)?"Yes":"No") << endl;
974 <          }
975 <          if ( matchVertex(*vsim,*vrec) ){
976 <            // if the matching critera are fulfilled, accept the rec-vertex that is closest in z
977 <            if(    ((vsim->recVtx) && (fabs(vsim->recVtx->position().z()-vsim->z)>fabs(vrec->z()-vsim->z)))
978 <                   || (!vsim->recVtx) )
979 <              {
980 <                vsim->recVtx=&(*vrec);
981 <              }
982 <          }
394 <        }
395 <        if (vsim->recVtx){
396 <          if(verbose_) {
397 <            cout <<"primary matched " << vsim->x << " " << vsim->y << " " << vsim->z <<  endl;
398 <          }
399 <          fres[0] = vsim->recVtx->x()-vsim->x;
400 <          fres[1] = vsim->recVtx->y()-vsim->y;
401 <          fres[2] = vsim->recVtx->z()-vsim->z;
402 <          ferror[0] = vsim->recVtx->xError();
403 <          ferror[1] = vsim->recVtx->yError();
404 <          ferror[2] = vsim->recVtx->zError();
405 <          fntrk = nrectrk;
406 <          ftree_->Fill();
407 <
408 <          h_deltax->Fill( vsim->recVtx->x()-vsim->x );
409 <          h_deltay->Fill( vsim->recVtx->y()-vsim->y );
410 <          h_deltaz->Fill( vsim->recVtx->z()-vsim->z );
411 <          h_pullx->Fill( (vsim->recVtx->x()-vsim->x )/vsim->recVtx->xError() );
412 <          h_pully->Fill( (vsim->recVtx->y()-vsim->y )/vsim->recVtx->yError() );
413 <          h_pullz->Fill( (vsim->recVtx->z()-vsim->z )/vsim->recVtx->zError() );
414 <          pvinfo.push_back(PVStudy::PVInfo(res(vsim->recVtx->x()-vsim->x,
415 <                                               vsim->recVtx->y()-vsim->y,
416 <                                               vsim->recVtx->z()-vsim->z),
417 <                                           error(vsim->recVtx->xError(),
418 <                                                 vsim->recVtx->yError(),
419 <                                                 vsim->recVtx->zError()),
420 <                                           nrectrk));
421 <          // Fill histo according to its track multiplicity
422 <          fillHisto(res(vsim->recVtx->x()-vsim->x,
423 <                        vsim->recVtx->y()-vsim->y,
424 <                        vsim->recVtx->z()-vsim->z),
425 <                    pull((vsim->recVtx->x()-vsim->x )/vsim->recVtx->xError(),
426 <                         (vsim->recVtx->y()-vsim->y )/vsim->recVtx->yError(),
427 <                         (vsim->recVtx->z()-vsim->z )/vsim->recVtx->zError()),
428 <                    nrectrk);
429 <        }
430 <        else{  // no rec vertex found for this simvertex
431 <          if(verbose_) {
432 <            cout <<"primary not found " << vsim->x << " " << vsim->y << " " << vsim->z << " nGenTrk=" << vsim->nGenTrk << endl;
433 <          }
434 <        }
435 <      }
436 <    }
437 <  }// With MC
438 <  
439 <  // Loop RecVtxs and find matched SimVtxs
440 <  for(reco::VertexCollection::const_iterator v=recVtxs->begin();
441 <      v!=recVtxs->end(); ++v){
442 <    try {
443 <      for(reco::Vertex::trackRef_iterator t = v->tracks_begin();
444 <          t!=v->tracks_end(); t++) {
445 <        // illegal charge
446 <        if ( (**t).charge() < -1 || (**t).charge() > 1 ) {
447 <          //      h_trkPtPV->Fill(0.);
448 <        }
449 <        else {
450 <          h_trkPtPV->Fill((**t).pt());
451 <        }
452 <      }
453 <    }
454 <    catch (...) {
455 <      // exception thrown when trying to use linked track
456 <      //          h_trkPtPV->Fill(0.);
457 <    }
458 <    
459 <    h_nTrkPV->Fill(v->tracksSize());
460 <    
461 <  }
462 <  
463 <  h_nTrk->Fill(tracks->size());
464 <  
465 <  for(TrackCollection::const_iterator itTrack = tracks->begin();
466 <      itTrack != tracks->end();                      
467 <      ++itTrack) {
468 <    int charge = 0;
469 <    charge = itTrack->charge();
470 <    h_trkPt->Fill(itTrack->pt());
964 >          vsim!=simpv.end(); vsim++, isimpv++){
965 >        nsimTrkPV_[isimpv]  =vsim->nGenTrk;
966 >        simx_[isimpv] = vsim->x;
967 >        simy_[isimpv] = vsim->y;
968 >        simz_[isimpv] = vsim->y;
969 >        simptsq_[isimpv] = vsim->ptsq;
970 >        
971 >        //fillMCHisto((std::vector<simPrimaryVertex>::iterator vsim, int isimpv, const reco::VertexCollection *vtxColl, int datatype) {
972 >        fillMCHisto(vsim, isimpv, splitVertexColl1, 1);
973 >        fillMCHisto(vsim, isimpv, splitVertexColl2, 2);
974 >        fillMCHisto(vsim, isimpv, vertexColl, 3);
975 >      }
976 >    } // End of  for(std::vector<simPrimaryVertex>::iterator vsim=simpv.begin()
977 >  } // End of   if (!realData_) {
978 >
979 >  // Finally fill the ftree_
980 >  if(saventuple_) {
981 >    ftree_->Fill();
982 >    pvtxtree_->Fill();
983    }
472  
984   }
985  
475
986   // ------------ method called once each job just before starting event loop  ------------
987   void
988   PVStudy::beginJob()
# Line 482 | Line 992 | PVStudy::beginJob()
992   // ------------ method called once each job just after ending the event loop  ------------
993   void
994   PVStudy::endJob() {
995 <  double sqt2 = sqrt(2.);
996 <  if (!realData_) {
997 <    if (verbose_) cout << "Analyzing PV info" << endl;
998 <    for (int ntrk=nTrkMin_;ntrk<=nTrkMax_;++ntrk) {
999 <      if (verbose_) cout << "Fill point of ntrk = " << ntrk << endl;
1000 <      PVStudy::PVAnaInfo ipv = GetPVAnaInfo(ntrk);
1001 <      if (analyze_) {
1002 < //      if ( ipv.res_.x() > 0 ) h_resx_nTrk->Fill(ntrk,ipv.res_.x()/sqt2, 1.);
1003 < //      if ( ipv.res_.y() > 0 ) h_resy_nTrk->Fill(ntrk,ipv.res_.y()/sqt2, 1.);
1004 < //      if ( ipv.res_.z() > 0 ) h_resz_nTrk->Fill(ntrk,ipv.res_.z()/sqt2, 1.);
1005 <        if ( ipv.res_.x() > 0 ) h_resx_nTrk->Fill(ntrk,ipv.res_.x(), 1.);
1006 <        if ( ipv.res_.y() > 0 ) h_resy_nTrk->Fill(ntrk,ipv.res_.y(), 1.);
1007 <        if ( ipv.res_.z() > 0 ) h_resz_nTrk->Fill(ntrk,ipv.res_.z(), 1.);
1008 <        if ( ipv.pull_.x() > 0 ) h_pullx_nTrk->Fill(ntrk,ipv.pull_.x(), 1.);
499 <        if ( ipv.pull_.y() > 0 ) h_pully_nTrk->Fill(ntrk,ipv.pull_.y(), 1.);
500 <        if ( ipv.pull_.z() > 0 ) h_pullz_nTrk->Fill(ntrk,ipv.pull_.z(), 1.);
501 <      }
995 >  if (verbose_) cout << "Analyzing PV info" << endl;
996 >  // Looping through the datamodes available
997 >  for (vector<int>::const_iterator it= datamode.begin(); it != datamode.end() ; ++it) {  
998 >    string suffix;
999 >    if(verbose_)  cout<<"datamode = "<< *it<<endl;
1000 >    switch(*it) {
1001 >    case 0: suffix = "";
1002 >      break;
1003 >    case 1: suffix = "_spl1_mct";
1004 >      break;
1005 >    case 2: suffix = "_spl2_mct";      
1006 >      break;
1007 >    case 3: suffix = "_mct";
1008 >      break;
1009      }
1010 +    if(analyze_) {
1011 +      for (int ntrk=nTrkMin_;ntrk<=nTrkMax_;++ntrk) {
1012 +        cout << "ntrk = " << ntrk << endl;
1013 +        PVStudy::PVAnaInfo ipv = GetPVAnaInfo(ntrk,*it);
1014 +        if ( ipv.res_.x() > 0 ) h_ana->Fill2d("resx"+suffix+"_nTrk", ntrk,ipv.res_.x(), 1.);
1015 +        if ( ipv.res_.y() > 0 ) h_ana->Fill2d("resy"+suffix+"_nTrk", ntrk,ipv.res_.y(), 1.);
1016 +        if ( ipv.res_.z() > 0 ) h_ana->Fill2d("resz"+suffix+"_nTrk", ntrk,ipv.res_.z(), 1.);
1017 +        if ( ipv.pull_.x() > 0 ) h_ana->Fill2d("pullx"+suffix+"_nTrk", ntrk,ipv.pull_.x(), 1.);
1018 +        if ( ipv.pull_.y() > 0 ) h_ana->Fill2d("pully"+suffix+"_nTrk", ntrk,ipv.pull_.y(), 1.);
1019 +        if ( ipv.pull_.z() > 0 ) h_ana->Fill2d("pullz"+suffix+"_nTrk", ntrk,ipv.pull_.z(), 1.);
1020 +      }
1021 +    }
1022 +    suffix.clear();
1023 +  }
1024 +  if(saventuple_) {
1025 +    file_->cd();
1026 +    ftree_->Write();
1027 +    pvtxtree_->Write();
1028 +    file_->Close();
1029    }
504  file_->cd();
505  ftree_->Write();
506  file_->Close();
1030   }
1031  
1032 +
1033 +
1034 + // Match a recovertex with a simvertex
1035 + // ? Should the cut be parameter dependent?
1036 + // cut can be within n sigma of the vertex.zerror()
1037   bool PVStudy::matchVertex(const PVStudy::simPrimaryVertex & vsim,
1038                            const reco::Vertex & vrec)
1039   {
1040    return (fabs(vsim.z-vrec.z())<0.0500); // =500um
1041   }
1042  
1043 + // Match two reconstructed vertices
1044 + bool PVStudy::matchVertex( const reco::VertexRef & vrec1,
1045 +                           const reco::VertexRef & vrec2,
1046 +                           int zsigncut)
1047 + {
1048 +  double cut = zsigncut*max(vrec1->zError(), vrec2->zError());
1049 +  if(verbose_)
1050 +    cout<<"The matching criteria in z is "<<cut<<endl;
1051 +  return (fabs(vrec1->z()-vrec2->z())<cut);
1052 + }
1053 +
1054 +
1055   bool PVStudy::isResonance(const HepMC::GenParticle * p){
1056    double ctau=(pdt->particle( abs(p->pdg_id()) ))->lifetime();
1057    if(verbose_) cout << "isResonance   " << p->pdg_id() << " " << ctau << endl;
# Line 583 | Line 1123 | void PVStudy::printSimTrks(const Handle<
1123    }
1124   }
1125  
1126 < void PVStudy::fillHisto(res r, pull p, int ntk){
1126 > void PVStudy::fillHisto(res r, error er, int ntk, int datamode){
1127    stringstream ss;
1128    ss << ntk;
1129    string suffix = ss.str();
1130 +  if(datamode == 0 )  suffix = "_" + suffix;
1131 +  if(datamode == 1 )  suffix = "_spl1_mct_" + suffix;
1132 +  if(datamode == 2 )  suffix = "_spl2_mct_" + suffix;
1133 +  if(datamode == 3 )  suffix = "_mct_" + suffix;
1134 +  
1135    if (ntk < nTrkMin_ || ntk > nTrkMax_ ) return;
1136    // Fill histograms of res and pull of ntk
1137 <  h["resx_"+suffix]->Fill(r.x());
1138 <  h["resy_"+suffix]->Fill(r.y());
1139 <  h["resz_"+suffix]->Fill(r.z());
1140 <  h["pullx_"+suffix]->Fill(p.x());
1141 <  h["pully_"+suffix]->Fill(p.y());
1142 <  h["pullz_"+suffix]->Fill(p.z());
1137 >  h_others->Fill1d("deltax"+suffix, r.x());
1138 >  h_others->Fill1d("deltay"+suffix, r.y());
1139 >  h_others->Fill1d("deltaz"+suffix, r.z());
1140 >  h_others->Fill1d("pullx"+suffix, r.x()/er.x());
1141 >  h_others->Fill1d("pully"+suffix, r.y()/er.y());
1142 >  h_others->Fill1d("pullz"+suffix, r.z()/er.z());  
1143 >  h_others->Fill1d("errPVx"+suffix, er.x());
1144 >  h_others->Fill1d("errPVy"+suffix, er.y());
1145 >  h_others->Fill1d("errPVz"+suffix, er.z());
1146   }
1147  
1148 < PVStudy::PVAnaInfo PVStudy::GetPVAnaInfo(int ntk) {
1148 > PVStudy::PVAnaInfo PVStudy::GetPVAnaInfo(int ntk, int datamode) {
1149    map<int,double> data;
1150    data.clear();
1151 <  double fpar[2];
1151 >  double fpar[2] = {-999,-999};
1152    double cm2um = 10000;
1153    stringstream ss;
1154    ss << ntk;
1155 <  string suffix = ss.str();
1156 <
1155 >  string suffix = ss.str();
1156 >  if(datamode == 0 )  suffix = "_" + suffix;
1157 >  if(datamode == 1 )  suffix = "_spl1_mct_" + suffix;
1158 >  if(datamode == 2 )  suffix = "_spl2_mct_" + suffix;
1159 >  if(datamode == 3 )  suffix = "_mct_" + suffix;
1160 >  
1161    if(analyze_) {
1162      for ( int i = 0; i < 6; ++i) {
611      cout << "Here" << endl;
1163        switch (i) {
1164        case 0:
1165 <        fit(h["resx_"+suffix], fpar);
1165 >        if (!h_others->ReadHisto1D("deltax"+suffix)) break;
1166 >        fit(h_others->ReadHisto1D("deltax"+suffix), fpar);
1167          data[i] = fpar[0]*cm2um;
1168          break;
1169        case 1:
1170 <        fit(h["resy_"+suffix], fpar);
1170 >        if (!h_others->ReadHisto1D("deltay"+suffix)) break;
1171 >        fit(h_others->ReadHisto1D("deltay"+suffix), fpar);
1172          data[i] = fpar[0]*cm2um;
1173          break;
1174        case 2:
1175 <        fit(h["resz_"+suffix], fpar);
1175 >        if (!h_others->ReadHisto1D("deltaz"+suffix)) break;
1176 >        fit(h_others->ReadHisto1D("deltaz"+suffix), fpar);
1177          data[i] = fpar[0]*cm2um;
1178          break;
1179        case 3:
1180 <        fit(h["pullx_"+suffix], fpar);
1180 >        if (!h_others->ReadHisto1D("pullx"+suffix)) break;
1181 >        fit(h_others->ReadHisto1D("pullx"+suffix), fpar);
1182          data[i] = fpar[0];
1183          break;
1184        case 4:
1185 <        fit(h["pully_"+suffix], fpar);
1185 >        if (!h_others->ReadHisto1D("pully"+suffix)) break;
1186 >        fit(h_others->ReadHisto1D("pully"+suffix), fpar);
1187          data[i] = fpar[0];
1188          break;
1189        case 5:
1190 <        fit(h["pullz_"+suffix], fpar);
1190 >        if (!h_others->ReadHisto1D("pullz"+suffix)) break;
1191 >        fit(h_others->ReadHisto1D("pullz"+suffix), fpar);
1192          data[i] = fpar[0];
1193          break;
1194        }
# Line 650 | Line 1207 | PVStudy::PVAnaInfo PVStudy::GetPVAnaInfo
1207                              ntk);
1208   }
1209  
1210 < void PVStudy::fit(TH1 *&hdist, double data[]){
1210 > void PVStudy::fit(TH1 *hdist, double fitPars[]){
1211    TAxis *axis0 = hdist->GetXaxis();
1212    int nbin = axis0->GetLast();
1213    double nOF = hdist->GetBinContent(nbin+1);
1214    double nUF = hdist->GetBinContent(0);
1215 +  //   double fitRange = axis0->GetBinUpEdge(nbin);
1216 +  double fitRange = axis0->GetXmax();
1217 +  double sigMax[2] = {0.,0.};
1218 +
1219    if ( verbose_ ){
1220      cout << "Last bin = " << nbin;
1221      cout << "; hdist: Overflow Entries = " << nOF;
1222      cout << "; Underflow Entries = " << nUF;
1223 <    cout << "; hdist->GetEntries() = " << hdist->GetEntries() << endl;
1223 >    cout << "; hdist->GetEntries() = " << hdist->GetEntries();
1224 >    cout << "; fitting range = " << -fitRange << " to " << fitRange << endl;
1225    }
1226 <  if (hdist->GetEntries() - nOF - nUF >= 5) { // FIXME: for reasonable Gaussian fit
1227 <    hdist->Fit("gaus","Q");
1228 <    TF1 *fgaus = hdist->GetFunction("gaus");
1226 >  if (hdist->GetEntries() - nOF - nUF >= 10) { // FIXME: for reasonable Gaussian fit
1227 >    for (int bi = 0; bi < nbin; bi++) {
1228 >      if ( (axis0->GetBinLowEdge(bi) < 0) && (hdist->GetBinContent(bi) > 0) ) {
1229 >        sigMax[0] = axis0->GetBinLowEdge(bi);
1230 >        if ( abs(sigMax[0]) > abs(sigMax[1]) ) sigMax[1] = abs(sigMax[0]);
1231 >      }
1232 >      if ( (axis0->GetBinLowEdge(bi) >= 0) && (hdist->GetBinContent(bi) > 0) ) {
1233 >        sigMax[0] = axis0->GetBinUpEdge(bi);
1234 >        if ( abs(sigMax[0]) > abs(sigMax[1]) ) sigMax[1] = abs(sigMax[0]);
1235 >      }
1236 >    }
1237 >    if (verbose_) cout << "Fit sigMax = " << sqrt(2.)*sigMax[1] << endl;
1238 >
1239 >    TF1 *fgaus = new TF1("fgaus","gaus",-fitRange, fitRange);
1240 >    fgaus->SetParameter(1, 0.);
1241 >    fgaus->SetParLimits(1, -fitRange/40., fitRange/40.);
1242 >    fgaus->SetParLimits(2, 0., sqrt(2.)*sigMax[1]);
1243 >    fgaus->SetLineColor(4);
1244 >    hdist->Fit(fgaus,"Q");
1245 >    gPad->Update();
1246 >    TPaveStats *s = (TPaveStats*) hdist->GetListOfFunctions()->FindObject("stats");
1247 >    s->SetOptStat(1111111);
1248 >    s->SetOptFit(0111);
1249 >    gPad->Update();
1250      if (verbose_) cout << "got function" << endl;
1251 <    data[0] = ((fgaus->GetParameter(2))?fgaus->GetParameter(2):-999);
1251 >    fitPars[0] = ((fgaus->GetParameter(2))?fgaus->GetParameter(2):-999);
1252 >  }
1253 >  else
1254 >    fitPars[0] = -999;
1255 > }
1256 >
1257 > void PVStudy::fillTrackHisto(const reco::TrackCollection *trackColl, int datatype) {
1258 >  string suffix;
1259 >  suffix = ""; // for unsplit tracks
1260 >  if(datatype == 1) suffix = "1_spl"; // for splittracks 1
1261 >  if(datatype == 2) suffix = "2_spl"; // for splittracks 2
1262 >  
1263 >  h_pvtrk->Fill1d("nTrk"+suffix, trackColl->size());
1264 >  for(reco::TrackCollection::const_iterator itTrack = trackColl->begin();
1265 >      itTrack != trackColl->end();                      
1266 >      ++itTrack) {
1267 >    h_pvtrk->Fill1d("trkPt"+suffix, itTrack->pt());
1268 >    h_pvtrk->Fill1d("trkDxy"+suffix, itTrack->dxy());
1269 >    h_pvtrk->Fill1d("trkDz"+suffix, itTrack->dz());
1270 >    h_pvtrk->Fill1d("trkEta"+suffix, itTrack->eta());
1271 >    h_pvtrk->Fill1d("trkPhi"+suffix, itTrack->phi());
1272 >  }
1273 > }
1274 >
1275 > void PVStudy::fillTrackHistoInPV(const reco::VertexCollection *vertexColl, int datatype, bool fillHisto, bool fillNtuple) {
1276 >  string suffix;
1277 >  suffix = ""; // for unsplit tracks
1278 >  if(datatype == 1) suffix = "1_spl"; // for splittracks 1
1279 >  if(datatype == 2) suffix = "2_spl"; // for splittracks 2
1280 >  int ivtx = 0;
1281 >  for(reco::VertexCollection::const_iterator v=vertexColl->begin();
1282 >      v!=vertexColl->end(); ++v, ++ivtx) {  
1283 >    if(fillNtuple) {
1284 >      if(datatype == 0) {
1285 >        nTrkPV_[ivtx] = v->tracksSize();        
1286 >        sumptsq_[ivtx] = sumPtSquared(*v);
1287 >        isValid_[ivtx] = v->isValid();
1288 >        isFake_[ivtx] = v->isFake();    
1289 >        recx_[ivtx] = v->x();
1290 >        recy_[ivtx] = v->y();
1291 >        recz_[ivtx] = v->z();
1292 >        recx_err_[ivtx] = v->xError();
1293 >        recy_err_[ivtx] = v->yError();
1294 >        recz_err_[ivtx] = v->zError();
1295 >      }
1296 >      if(datatype == 1) {
1297 >        nTrkPV1_spl_[ivtx] = v->tracksSize();  
1298 >        sumptsq1_spl_[ivtx] = sumPtSquared(*v);        
1299 >        isValid1_spl_[ivtx] = v->isValid();
1300 >        isFake1_spl_[ivtx] = v->isFake();      
1301 >        recx1_spl_[ivtx] = v->x();
1302 >        recy1_spl_[ivtx] = v->y();
1303 >        recz1_spl_[ivtx] = v->z();
1304 >        recx1_err_spl_[ivtx] = v->xError();
1305 >        recy1_err_spl_[ivtx] = v->yError();
1306 >        recz1_err_spl_[ivtx] = v->zError();
1307 >
1308 >      }
1309 >      if(datatype == 2) {
1310 >        nTrkPV2_spl_[ivtx] = v->tracksSize();  
1311 >        sumptsq2_spl_[ivtx] = sumPtSquared(*v);        
1312 >        isValid2_spl_[ivtx] = v->isValid();
1313 >        isFake2_spl_[ivtx] = v->isFake();
1314 >        recx2_spl_[ivtx] = v->x();
1315 >        recy2_spl_[ivtx] = v->y();
1316 >        recz2_spl_[ivtx] = v->z();
1317 >        recx2_err_spl_[ivtx] = v->xError();
1318 >        recy2_err_spl_[ivtx] = v->yError();
1319 >        recz2_err_spl_[ivtx] = v->zError();
1320 >      }
1321 >      if(datatype == 4) { // for pixelVertices
1322 >        nTrkPV_pxlpvtx_[ivtx] = v->tracksSize();        
1323 >        sumptsq_pxlpvtx_[ivtx] = sumPtSquared(*v);      
1324 >        isValid_pxlpvtx_[ivtx] = v->isValid();
1325 >        isFake_pxlpvtx_[ivtx] = v->isFake();
1326 >        recx_pxlpvtx_[ivtx] = v->x();
1327 >        recy_pxlpvtx_[ivtx] = v->y();
1328 >        recz_pxlpvtx_[ivtx] = v->z();
1329 >        recx_err_pxlpvtx_[ivtx] = v->xError();
1330 >        recy_err_pxlpvtx_[ivtx] = v->yError();
1331 >        recz_err_pxlpvtx_[ivtx] = v->zError();
1332 >      }
1333 >    }
1334 >  }
1335 >  // For histogram only fill the leading pvtx parameters
1336 >  if(fillHisto) {
1337 >    h_pvtrk->Fill1d("nTrkPV"+suffix, vertexColl->begin()->tracksSize());
1338 >    try {
1339 >      for(reco::Vertex::trackRef_iterator t = vertexColl->begin()->tracks_begin();
1340 >          t!=vertexColl->begin()->tracks_end(); t++) {
1341 >        // illegal charge
1342 >        if ( (**t).charge() < -1 || (**t).charge() > 1 ) {
1343 >          //      h_pvtrk->Fill1d("trkPtPV", 0.);
1344 >        }
1345 >        else {
1346 >          h_pvtrk->Fill1d("trkPtPV"+suffix, (**t).pt());
1347 >          h_pvtrk->Fill1d("trkDxyPV"+suffix, (**t).dxy());
1348 >          h_pvtrk->Fill1d("trkDzPV"+suffix, (**t).dz());
1349 >          h_pvtrk->Fill1d("trkEtaPV"+suffix, (**t).eta());
1350 >          h_pvtrk->Fill1d("trkPhiPV"+suffix, (**t).phi());
1351 >        }
1352 >      }
1353 >    }
1354 >    catch (...) {
1355 >      // exception thrown when trying to use linked track
1356 >      //          h_pvtrk->Fill1d("trkPtPV", 0.);
1357 >    }
1358 >  }
1359 >  
1360 > }
1361 >
1362 > void PVStudy::fillMCHisto(std::vector<simPrimaryVertex>::iterator vsim, int isimpv, const reco::VertexCollection *vtxColl, int datatype)
1363 > {
1364 >  std::string suffix;
1365 >  // Set the vertexColl and histogram suffix according to datamode
1366 >  if (datatype == 1) {
1367 >    suffix = "_spl1_mct";
1368 >    nrecPV_spl1_mct_ = 0;  
1369 >  }
1370 >  if (datatype == 2) {
1371 >    suffix = "_spl2_mct";
1372 >    nrecPV_spl2_mct_ = 0;    
1373 >  }
1374 >  if (datatype == 3) {
1375 >    suffix = "_mct";
1376 >    nrecPV_mct_ = 0;  
1377 >  }
1378 >  
1379 >  //========================================================
1380 >  //  look for a matching reconstructed vertex in vertexColl
1381 >  //========================================================        
1382 >
1383 >  for(reco::VertexCollection::const_iterator vrec=vtxColl->begin();
1384 >      vrec!=vtxColl->end(); ++vrec){
1385 >    int nrectrk = vrec->tracksSize();
1386 >    vsim->recVtx=NULL;  
1387 >  
1388 >    if(verbose_){
1389 >      cout << "sim primary vertex x = " << vsim->x << "; y = " << vsim->y << "; z = " << vsim->z <<  endl;
1390 >      cout << "Is matched? " << (matchVertex(*vsim,*vrec)?"Yes":"No") << endl;
1391 >    }
1392 >    if ( matchVertex(*vsim,*vrec) && vrec->isValid() && !vrec->isFake() ) {
1393 >      vsim->recVtx=&(*vrec);
1394 >      
1395 >      // if the matching critera are fulfilled, accept the rec-vertex that is closest in z
1396 >      //if(    ((vsim->recVtx) && (fabs(vsim->recVtx->position().z()-vsim->z)>fabs(vrec->z()-vsim->z)))
1397 >      //|| (!vsim->recVtx) )
1398 >      //vsim->recVtx=&(*vrec);
1399 >      //}
1400 >      if(verbose_)
1401 >        cout <<"primary matched in vertexColl" << vsim->x << " " << vsim->y << " " << vsim->z <<  endl;
1402 >      
1403 >      double fres_mct[3];
1404 >      double ferror_mct[3];
1405 >      
1406 >      fres_mct[0] = vsim->recVtx->x()-vsim->x;
1407 >      fres_mct[1] = vsim->recVtx->y()-vsim->y;
1408 >      fres_mct[2] = vsim->recVtx->z()-vsim->z;
1409 >      ferror_mct[0] = vsim->recVtx->xError();
1410 >      ferror_mct[1] = vsim->recVtx->yError();
1411 >      ferror_mct[2] = vsim->recVtx->zError();
1412 >      
1413 >      h_summary->Fill1d("deltax"+suffix, fres_mct[0] );
1414 >      h_summary->Fill1d("deltay"+suffix, fres_mct[1] );
1415 >      h_summary->Fill1d("deltaz"+suffix, fres_mct[2] );
1416 >      h_summary->Fill1d("pullx"+suffix, fres_mct[0]/ferror_mct[0] );
1417 >      h_summary->Fill1d("pully"+suffix, fres_mct[1]/ferror_mct[1] );
1418 >      h_summary->Fill1d("pullz"+suffix, fres_mct[2]/ferror_mct[2] );
1419 >      h_summary->Fill1d("errPVx"+suffix, ferror_mct[0] );
1420 >      h_summary->Fill1d("errPVy"+suffix, ferror_mct[1] );
1421 >      h_summary->Fill1d("errPVz"+suffix, ferror_mct[2] );
1422 >      pvinfo.push_back(PVStudy::PVInfo(res(fres_mct[0], fres_mct[1], fres_mct[2]),
1423 >                                       error(ferror_mct[0], ferror_mct[1], ferror_mct[2]),
1424 >                                       nrectrk));
1425 >      // Fill histo according to its track multiplicity
1426 >      fillHisto(res(fres_mct[0], fres_mct[1], fres_mct[2]),
1427 >                error(ferror_mct[0], ferror_mct[1], ferror_mct[2]),
1428 >                nrectrk, datatype);
1429 >      
1430 >      if(saventuple_) {
1431 >        //Fill the values for variables in ftree_  
1432 >        if(datatype == 1) {
1433 >          nTrkPV_spl1_mct_[nrecPV_spl1_mct_] =   nrectrk;
1434 >          deltax_spl1_mct_[nrecPV_spl1_mct_] =  fres_mct[0];
1435 >          deltay_spl1_mct_[nrecPV_spl1_mct_] =  fres_mct[0];
1436 >          deltaz_spl1_mct_[nrecPV_spl1_mct_] =  fres_mct[0];
1437 >          pullx_spl1_mct_[nrecPV_spl1_mct_] = fres_mct[0]/ferror_mct[0];  
1438 >          pully_spl1_mct_[nrecPV_spl1_mct_] = fres_mct[1]/ferror_mct[1];
1439 >          pullz_spl1_mct_[nrecPV_spl1_mct_] =  fres_mct[2]/ferror_mct[2];
1440 >          nrecPV_spl1_mct_++;
1441 >        }
1442 >        
1443 >        if(datatype == 2) {
1444 >          nTrkPV_spl2_mct_[nrecPV_spl2_mct_] = nrectrk;
1445 >          deltax_spl2_mct_[nrecPV_spl2_mct_] =  fres_mct[0];
1446 >          deltay_spl2_mct_[nrecPV_spl2_mct_] =  fres_mct[0];
1447 >          deltaz_spl2_mct_[nrecPV_spl2_mct_] =  fres_mct[0];
1448 >          pullx_spl2_mct_[nrecPV_spl2_mct_] = fres_mct[0]/ferror_mct[0];  
1449 >          pully_spl2_mct_[nrecPV_spl2_mct_] = fres_mct[1]/ferror_mct[1];
1450 >          pullz_spl2_mct_[nrecPV_spl2_mct_] =  fres_mct[2]/ferror_mct[2];
1451 >          nrecPV_spl2_mct_++;
1452 >        }
1453 >        if(datatype == 3) {    
1454 >          nTrkPV_mct_[nrecPV_mct_] = nrectrk;
1455 >          deltax_mct_[nrecPV_mct_] =  fres_mct[0];
1456 >          deltay_mct_[nrecPV_mct_] =  fres_mct[0];
1457 >          deltaz_mct_[nrecPV_mct_] =  fres_mct[0];
1458 >          pullx_mct_[nrecPV_mct_] = fres_mct[0]/ferror_mct[0];  
1459 >          pully_mct_[nrecPV_mct_] = fres_mct[1]/ferror_mct[1];
1460 >          pullz_mct_[nrecPV_mct_] =  fres_mct[2]/ferror_mct[2];          
1461 >          nrecPV_mct_++;
1462 >        }
1463 >      } // End of  if(saventuple_) {
1464 >    } //  if ( matchVertex(*vsim,*vrec) ) {
1465 >    else {  // no rec vertex found for this simvertex
1466 >      if(verbose_)
1467 >        cout <<"primary not found " << vsim->x << " " << vsim->y << " " << vsim->z << " nGenTrk=" << vsim->nGenTrk << endl;
1468 >    }
1469 >  }
1470 > }
1471 >
1472 >
1473 > void PVStudy::SetVarToZero() {
1474 >  //Greg's variables
1475 >  fntrk_ = 0;
1476 >  //pvtx position (x,y,z) residual and error
1477 >  for(int i = 0; i<3;i++)    {
1478 >    fres_[i] = 0;
1479 >    ferror_[i] = 0;
1480 >  }
1481 >  
1482 >  //Yanyan's variables
1483 >  // Number of reconstructed vertices  
1484 >  nrecPV_ = 0;
1485 >  nrecPV1_spl_ = 0;
1486 >  nrecPV2_spl_ = 0;
1487 >  nrecPV_twovtx_ = 0;
1488 >  nsimPV_ = 0;
1489 >
1490 >  nrecPV_mct_ = 0;
1491 >  nrecPV_spl1_mct_ = 0;
1492 >  nrecPV_spl2_mct_ = 0;
1493 >
1494 >  // Mininum separation between the secondary pvtxes and leading pvtx
1495 >  min_zsep_ = 9999.0;
1496 >  min_ntrksep_ = 9999.0;
1497 >  min_sumpt2sep_ = -9999.0;
1498 >  
1499 >
1500 >  for (int i = 0; i < nMaxPVs_; i++) {
1501 >    // recoVertices with all tracks
1502 >    nTrkPV_[i] = 0; // Number of tracks in the pvtx    
1503 >    sumptsq_[i] = 0;
1504 >    isValid_[i] = -1;
1505 >    isFake_[i] = -1;
1506 >    recx_[i] = 0;
1507 >    recy_[i] = 0;
1508 >    recz_[i] = 0;
1509 >    recx_err_[i] = 0;
1510 >    recy_err_[i] = 0;
1511 >    recz_err_[i] = 0;
1512 >    
1513 >    // recoVertices with splitTrack1
1514 >    nTrkPV1_spl_[i] = 0; // Number of tracks in the pvtx    
1515 >    sumptsq1_spl_[i] = 0;
1516 >    isValid1_spl_[i] = -1;
1517 >    isFake1_spl_[i] = -1;
1518 >    recx1_spl_[i] = 0;
1519 >    recy1_spl_[i] = 0;
1520 >    recz1_spl_[i] = 0;
1521 >    recx1_err_spl_[i] = 0;
1522 >    recy1_err_spl_[i] = 0;
1523 >    recz1_err_spl_[i] = 0;
1524 >  
1525 >    // recoVertices with splitTrack2
1526 >    nTrkPV2_spl_[i] = 0; // Number of tracks in the pvtx  
1527 >    sumptsq2_spl_[i] = 0;
1528 >    isValid2_spl_[i] = -1;
1529 >    isFake2_spl_[i] = -1;
1530 >    recx2_spl_[i] = 0;
1531 >    recy2_spl_[i] = 0;
1532 >    recz2_spl_[i] = 0;
1533 >    recx2_err_spl_[i] = 0;
1534 >    recy2_err_spl_[i] = 0;
1535 >    recz2_err_spl_[i] = 0;
1536 >    
1537 >    //pixelVertices
1538 >    nTrkPV_pxlpvtx_[i] = 0; // Number of tracks in the pvtx  
1539 >    sumptsq_pxlpvtx_[i] = 0;
1540 >    isValid_pxlpvtx_[i] = -1;
1541 >    isFake_pxlpvtx_[i] = -1;
1542 >    recx_pxlpvtx_[i] = 0;
1543 >    recy_pxlpvtx_[i] = 0;
1544 >    recz_pxlpvtx_[i] = 0;
1545 >    recx_err_pxlpvtx_[i] = 0;
1546 >    recy_err_pxlpvtx_[i] = 0;
1547 >    recz_err_pxlpvtx_[i] = 0;
1548 >
1549 >    // matched two-vertices
1550 >    nTrkPV1_spl_twovtx_[i] = 0;
1551 >    nTrkPV2_spl_twovtx_[i] = 0;
1552 >    nTrkPV_twovtx_[i] = 0;  
1553 >    sumptsq1_spl_twovtx_[i] = 0; // Sum of pT squred in the pvtx
1554 >    sumptsq2_spl_twovtx_[i] = 0; // Sum of pT squred in the pvtx
1555 >    deltax_twovtx_[i] = 0;
1556 >    deltay_twovtx_[i] = 0;
1557 >    deltaz_twovtx_[i] = 0;
1558 >    errx_twovtx_[i] = 0;
1559 >    erry_twovtx_[i] = 0;
1560 >    errz_twovtx_[i] = 0;
1561 >    pullx_twovtx_[i] = 0;
1562 >    pully_twovtx_[i] = 0;
1563 >    pullz_twovtx_[i] = 0;
1564 >    
1565 >    //simpv
1566 >    nsimTrkPV_[i] = 0;
1567 >    simx_[i] = 0;
1568 >    simy_[i] = 0;
1569 >    simz_[i] = 0;
1570 >    simptsq_[i] = 0;
1571 >    
1572 >    // residual and pulls with mc truth required
1573 >    deltax_mct_[i] = 0;
1574 >    deltay_mct_[i] = 0;
1575 >    deltaz_mct_[i] = 0;
1576 >    pullx_mct_[i] = 0;
1577 >    pully_mct_[i] = 0;
1578 >    pullz_mct_[i] = 0;
1579 >        
1580 >    deltax_spl1_mct_[i] = 0;
1581 >    deltay_spl1_mct_[i] = 0;
1582 >    deltaz_spl1_mct_[i] = 0;
1583 >    pullx_spl1_mct_[i] = 0;
1584 >    pully_spl1_mct_[i] = 0;
1585 >    pullz_spl1_mct_[i] = 0;
1586 >    
1587 >    deltax_spl2_mct_[i] = 0;
1588 >    deltay_spl2_mct_[i] = 0;
1589 >    deltaz_spl2_mct_[i] = 0;
1590 >    pullx_spl2_mct_[i] = 0;
1591 >    pully_spl2_mct_[i] = 0;
1592 >    pullz_spl2_mct_[i] = 0;
1593 >  }
1594 >  
1595 > }
1596 >
1597 > double PVStudy::sumPtSquared(const reco::Vertex & v)  {
1598 >  double sum = 0.;
1599 >  double pT;
1600 >  for (reco::Vertex::trackRef_iterator it = v.tracks_begin(); it != v.tracks_end(); it++) {
1601 >    pT = (**it).pt();
1602 >    sum += pT*pT;
1603    }
1604 +  return sum;
1605   }
1606  
672 //define this as a plug-in
673 DEFINE_FWK_MODULE(PVStudy);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines