ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/Jeng/PVStudy/plugins/PVStudy.cc
Revision: 1.17
Committed: Tue Jan 26 12:06:49 2010 UTC (15 years, 3 months ago) by yygao
Content type: text/plain
Branch: MAIN
CVS Tags: CMSSW_3_3_6_patch3_Dec19thReReco
Changes since 1.16: +232 -113 lines
Log Message:
adapt for the collision

File Contents

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