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.6 by jengbou, Wed Sep 9 23:05:38 2009 UTC vs.
Revision 1.7 by yygao, Thu Oct 8 14:57:46 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 59 | Line 60 | Implementation:
60  
61   using namespace std;
62  
63 < PVStudy::PVStudy(const edm::ParameterSet& iConfig):
63 <  nTrkMin_(10),nTrkMax_(100)
63 > PVStudy::PVStudy(const edm::ParameterSet& iConfig)
64   {
65 +  //=======================================================================
66 +  // Get configuration for TrackTupleMaker
67 +  //=======================================================================
68    simG4_           = iConfig.getParameter<edm::InputTag>( "simG4" );
69 <  tracksLabel_     = iConfig.getUntrackedParameter<edm::InputTag>("tracks");
70 <  vtxSample_       = iConfig.getUntrackedParameter<edm::InputTag>("vtxSample");
71 <  verbose_         = iConfig.getUntrackedParameter<bool>("verbose", false);
69 >  trackCollectionTag_     = iConfig.getUntrackedParameter<edm::InputTag>("trackCollection");  
70 >  splitTrackCollection1Tag_     = iConfig.getUntrackedParameter<edm::InputTag>("splitTrackCollection1");
71 >  splitTrackCollection2Tag_     = iConfig.getUntrackedParameter<edm::InputTag>("splitTrackCollection2");
72 >  vertexCollectionTag_       = iConfig.getUntrackedParameter<edm::InputTag>("vertexCollection");
73 >  splitVertexCollection1Tag_       = iConfig.getUntrackedParameter<edm::InputTag>("splitVertexCollection1");
74 >  splitVertexCollection2Tag_       = iConfig.getUntrackedParameter<edm::InputTag>("splitVertexCollection2");
75 >  verbose_         = iConfig.getUntrackedParameter<bool>("verbose",false);
76    realData_        = iConfig.getUntrackedParameter<bool>("realData",false);
77    analyze_         = iConfig.getUntrackedParameter<bool>("analyzeOnTheFly",false);
78 <  outputfilename_  = iConfig.getUntrackedParameter<string>("OutputFileName");
78 >  saventuple_         = iConfig.getUntrackedParameter<bool>("saventuple",false);  
79 >  outputfilename_  = iConfig.getUntrackedParameter<string>("OutputFileName");
80 >  ntrkdiffcut_         = iConfig.getUntrackedParameter<double>("ntrkdiffcut");
81 >  nTrkMin_ =  iConfig.getUntrackedParameter<int>("nTrkMin");
82 >  nTrkMax_ =  iConfig.getUntrackedParameter<int>("nTrkMax");
83  
84    //now do what ever initialization is needed
85    pvinfo.clear();
86  
87 <  file_ = TFile::Open(outputfilename_.c_str(),"RECREATE");
88 <  ftree_ = new TTree("mytree","mytree");
89 <  ftree_->AutoSave();
90 <  ftree_->Branch("residual",&fres,"fres[3]/D");
91 <  ftree_->Branch("error",&ferror,"ferror[3]/D");
92 <  ftree_->Branch("nTrk",&fntrk,"fntrk/I");
87 >
88 >  // Specify the data mode vector
89 >  if(realData_) datamode.push_back(0);
90 >  else {
91 >    datamode.push_back(0);
92 >    datamode.push_back(1);
93 >    datamode.push_back(2);
94 >    datamode.push_back(3);
95 >  }
96 >
97 >  // Create ntuple files if needed
98 >  if(saventuple_) {
99 >    file_ = TFile::Open(outputfilename_.c_str(),"RECREATE");
100 >    ftree_ = new TTree("mytree","mytree");
101 >    ftree_->AutoSave();
102 >    ftree_->Branch("residual",&fres_,"fres_[3]/D");
103 >    ftree_->Branch("error",&ferror_,"ferror_[3]/D");
104 >    ftree_->Branch("nTrkPV",&fntrk_,"fntrk_/I");
105 >    ftree_->Branch("nrecPV",&nrecPV_,"nrecPV_/I");
106 >    ftree_->Branch("nrecPV1_spl",&nrecPV1_spl_,"nrecPV1_spl_/I");
107 >    ftree_->Branch("nrecPV2_spl",&nrecPV2_spl_,"nrecPV2_spl_/I");
108    
109 +    // If it is MC, get the resA, resB
110 +    if(!realData_) {
111 +      ftree_->Branch("residual_spl1_mct",&fres_spl1_mct_,"fres_spl1_mct_[3]/D");
112 +      ftree_->Branch("error_spl1_mct",&ferror_spl1_mct_,"ferror_spl1_mct_[3]/D");
113 +      ftree_->Branch("nTrkPV_spl1_mct",&fntrk_spl1_mct_,"fntrk_spl1_mct_/I");
114 +      ftree_->Branch("residual_spl2_mct",&fres_spl2_mct_,"fres_spl2_mct_[3]/D");
115 +      ftree_->Branch("error_spl2_mct",&ferror_spl2_mct_,"ferror_spl2_mct_[3]/D");
116 +      ftree_->Branch("nTrkPV_spl2_mct",&fntrk_spl2_mct_,"fntrk_spl2_mct_/I");
117 +      ftree_->Branch("residual_mct",&fres_mct_,"fres_mct_[3]/D");
118 +      ftree_->Branch("error_mct",&ferror_mct_,"ferror_mct_[3]/D");
119 +      ftree_->Branch("nTrkPV_mct",&fntrk_mct_,"fntrk_mct_/I");
120 +    }
121 +  }
122 +
123    edm::Service<TFileService> fs;
124    TFileDirectory subDir = fs->mkdir( "Summary" );
125    TFileDirectory subDir1 = fs->mkdir( "Others" );
126    //   TFileDirectory subSubDir = subDir.mkdir( "mySubSubDirectory" );
127  
128    setRootStyle();
129 <
130 <  h["nTrk"]           = subDir.make<TH1F>("nTrk","Num of total rec tracks",300,0,300);
131 <  h["nTrkPV"]         = subDir.make<TH1F>("nTrkPV","Num of rec tracks of PVs",300,0,300);
132 <  h["trkPt"]          = subDir.make<TH1D>("trkPt","Pt of all rec tracks",100,0,100);
133 <  h["trkPtPV"]        = subDir.make<TH1D>("trkPtPV","Pt dist of rec tracks from PV",100,0,100);
134 <  h["genPart_T"]      = subDir.make<TH1D>("genPart_T","t component of gen particles",300,-0.5,0.5);
135 <  h["genPart_T"]->GetXaxis()->SetTitle("t (nanosecond)");
136 <  h["genPart_cT"]     = subDir.make<TH1D>("genPart_cT","ct component of gen particles",300,-150.,150.);
137 <  h["genPart_cT"]->GetXaxis()->SetTitle("ct (mm)");
138 <
139 <  if (!realData_) {
140 <    h["deltax"]       = subDir.make<TH1D>("deltax","x-distance (Rec - Sim)",800,-0.04,0.04);
141 <    h["deltay"]       = subDir.make<TH1D>("deltay","y-distance (Rec - Sim)",800,-0.04,0.04);
142 <    h["deltaz"]       = subDir.make<TH1D>("deltaz","z-distance (Rec - Sim)",800,-0.04,0.04);
143 <    h["pullx"]        = subDir.make<TH1D>("pullx","x-pull (Rec - Sim)",1000,-25.,25.);
144 <    h["pully"]        = subDir.make<TH1D>("pully","y-pull (Rec - Sim)",1000,-25.,25.);
145 <    h["pullz"]        = subDir.make<TH1D>("pullz","z-pull (Rec - Sim)",1000,-25.,25.);
146 <    h["errPVx"]       = subDir.make<TH1D>("errPVx","X vertex error",100,0.,0.02);
147 <    h["errPVy"]       = subDir.make<TH1D>("errPVy","Y vertex error",100,0.,0.02);
148 <    h["errPVz"]       = subDir.make<TH1D>("errPVz","Z vertex error",100,0.,0.02);
149 <
150 <    // Summary of analysis:
151 <    if (analyze_) {
152 <      h2["resx_nTrk"]= subDir.make<TH2D>("resx_ntrk","x-resolution (Rec - Sim) vs number of tracks",150,0,150,400,0.,200);
153 <      h2["resx_nTrk"]->SetMarkerStyle(21);
154 <      h2["resx_nTrk"]->SetMarkerColor(4);
155 <      h2["resx_nTrk"]->GetXaxis()->SetTitle("Num of tracks");
156 <      h2["resx_nTrk"]->GetYaxis()->SetTitle("#mum");
157 <      h2["resy_nTrk"]= subDir.make<TH2D>("resy_ntrk","y-resolution (Rec - Sim) vs number of tracks",150,0,150,400,0.,200);
158 <      h2["resy_nTrk"]->SetMarkerStyle(21);
159 <      h2["resy_nTrk"]->SetMarkerColor(4);
160 <      h2["resy_nTrk"]->GetXaxis()->SetTitle("Num of tracks");
161 <      h2["resy_nTrk"]->GetYaxis()->SetTitle("#mum");
162 <      h2["resz_nTrk"]= subDir.make<TH2D>("resz_ntrk","z-resolution (Rec - Sim) vs number of tracks",150,0,150,400,0.,200);
163 <      h2["resz_nTrk"]->SetMarkerStyle(21);
164 <      h2["resz_nTrk"]->SetMarkerColor(4);
165 <      h2["resz_nTrk"]->GetXaxis()->SetTitle("Num of tracks");
166 <      h2["resz_nTrk"]->GetYaxis()->SetTitle("#mum");
167 <      h2["pullx_nTrk"]= subDir.make<TH2D>("pullx_ntrk","x-pull (Rec - Sim) vs number of tracks",150,0,150,100,0.,2.);
168 <      h2["pullx_nTrk"]->SetMarkerStyle(21);
169 <      h2["pullx_nTrk"]->SetMarkerColor(4);
170 <      h2["pullx_nTrk"]->SetBit(TH1::kCanRebin);
171 <      h2["pullx_nTrk"]->GetXaxis()->SetTitle("Num of tracks");
172 <      h2["pully_nTrk"]= subDir.make<TH2D>("pully_ntrk","y-pull (Rec - Sim) vs number of tracks",150,0,150,100,0.,2.);
173 <      h2["pully_nTrk"]->SetMarkerStyle(21);
174 <      h2["pully_nTrk"]->SetMarkerColor(4);
175 <      h2["pully_nTrk"]->SetBit(TH1::kCanRebin);
176 <      h2["pully_nTrk"]->GetXaxis()->SetTitle("Num of tracks");
137 <      h2["pullz_nTrk"]= subDir.make<TH2D>("pullz_ntrk","z-pull (Rec - Sim) vs number of tracks",150,0,150,100,0.,2.);
138 <      h2["pullz_nTrk"]->SetMarkerStyle(21);
139 <      h2["pullz_nTrk"]->SetMarkerColor(4);
140 <      h2["pullz_nTrk"]->SetBit(TH1::kCanRebin);
141 <      h2["pullz_nTrk"]->GetXaxis()->SetTitle("Num of tracks");
129 >  
130 >  //Book histograms for track and pvtx parameters for each splitted pvtx
131 >  //i=0 : x (as in unsplit track collection)
132 >  //i=1 : x1_spl_
133 >  //i=2 : x2_spl_
134 >  
135 >  for(int i=0;i<3;i++)
136 >    {  
137 >      string suffix;
138 >      if(i == 0) suffix = "";
139 >      else {
140 >        stringstream ss;
141 >        ss << i;
142 >        suffix =ss.str()+"_spl";  
143 >      }
144 >      h["nTrk"+suffix]   = subDir.make<TH1D>(TString("nTrk"+suffix), TString("Num of rec tracks"+suffix),300,0,300);
145 >      h["trkPt"+suffix]  = subDir.make<TH1D>(TString("trkPt"+suffix), TString("Pt of rec tracks "+suffix),100,0,100);
146 >      h["trkEta"+suffix] = subDir.make<TH1D>(TString("trkEta"+suffix), TString("#Eta of rec tracks "+suffix),100,-3,3);
147 >      h["trkPhi"+suffix] = subDir.make<TH1D>(TString("trkPhi"+suffix), TString("#Phi of rec tracks "+suffix),100,-3.2,3.2);
148 >      h["trkDxy"+suffix] = subDir.make<TH1D>(TString("trkDxy"+suffix), TString("Dxy of rec tracks "+suffix),100,-5,5);  
149 >      h["trkDz"+suffix] = subDir.make<TH1D>(TString("trkDz"+suffix), TString("Dz of rec tracks "+suffix),100,-50,50);  
150 >      
151 >      h["nTrkPV"+suffix]   = subDir.make<TH1D>(TString("nTrkPV"+suffix), TString("Num of rec tracks in PV"+suffix),300,0,300);
152 >      h["trkPtPV"+suffix]  = subDir.make<TH1D>(TString("trkPtPV"+suffix), TString("Pt of rec tracks in "+suffix),100,0,100);
153 >      h["trkEtaPV"+suffix] = subDir.make<TH1D>(TString("trkEtaPV"+suffix), TString("#Eta of rec tracks in PV"+suffix),100,-3,3);
154 >      h["trkPhiPV"+suffix] = subDir.make<TH1D>(TString("trkPhiPV"+suffix), TString("#Phi of rec tracks in PV"+suffix),100,-3.2,3.2);
155 >      h["trkDxyPV"+suffix] = subDir.make<TH1D>(TString("trkDxyPV"+suffix), TString("Dxy of rec tracks in PV"+suffix),100,-5,5);  
156 >      h["trkDzPV"+suffix] = subDir.make<TH1D>(TString("trkDzPV"+suffix), TString("Dz of rec tracks "+suffix),100,-50,50);
157 >      h["nrecPV"+suffix]   = subDir.make<TH1D>(TString("nrecPV"+suffix), TString("Num of rec pvtx"+suffix),50,0,50);    
158 >      suffix.clear();
159 >    }
160 >  h["nrecPVDiff"]     = subDir.make<TH1D>("nrecPVDiff","nrecPV1-nRecPV2",21,-10.5,10.5);
161 >  h["nTrkPVDiff"]     = subDir.make<TH1D>("nTrkPVDiff","nTrkPV1-nTrkPV2",41,-20.5,20.5);
162 >  h["nTrkPVRelDiff"]  = subDir.make<TH1D>("nTrkPVRelDiff","(nTrkPV1-nTrkPV2)/(nTrkPV1+nTrkPV2)",100,-1,1);
163 >  
164 >  //Book histograms sensitive to data/mc
165 >  for (vector<int>::const_iterator it= datamode.begin(); it != datamode.end() ; ++it) {
166 >    string suffix;
167 >    if(verbose_)  cout<<"datamode = "<< *it<<endl;
168 >    switch(*it) {
169 >    case 0: suffix = "";
170 >      break;
171 >    case 1: suffix = "_spl1_mct";
172 >      break;
173 >    case 2: suffix = "_spl2_mct";      
174 >      break;
175 >    case 3: suffix = "_mct";
176 >      break;
177      }
178 +    h["deltax"+suffix] = subDir.make<TH1D>(TString("deltax"+suffix), TString("x-residual pvtx"+suffix),800,-0.04,0.04);
179 +    h["deltay"+suffix] = subDir.make<TH1D>(TString("deltay"+suffix), TString("y-residual pvtx"+suffix),800,-0.04,0.04);
180 +    h["deltaz"+suffix] = subDir.make<TH1D>(TString("deltaz"+suffix), TString("z-residual pvtx"+suffix),800,-0.04,0.04);
181 +    h["pullx"+suffix]  = subDir.make<TH1D>(TString("pullx"+suffix), TString("x-pull pvtx"+suffix),800,-10,10);
182 +    h["pully"+suffix]  = subDir.make<TH1D>(TString("pully"+suffix), TString("y-pull pvtx"+suffix),800,-10,10);
183 +    h["pullz"+suffix]  = subDir.make<TH1D>(TString("pullz"+suffix), TString("z-pull pvtx"+suffix),800,-10,10);
184 +    h["errPVx"+suffix] = subDir.make<TH1D>(TString("errPVx"+suffix), TString("X"+suffix+" vertex error"),100,0.,0.02);
185 +    h["errPVy"+suffix] = subDir.make<TH1D>(TString("errPVy"+suffix), TString("Y"+suffix+" vertex error"),100,0.,0.02);
186 +    h["errPVz"+suffix] = subDir.make<TH1D>(TString("errPVz"+suffix), TString("Z"+suffix+" vertex error"),100,0.,0.02);
187 +    
188 +    // Book residual, error and pull histograms for each nTrk bin
189      for (int ntrk=nTrkMin_;ntrk<=nTrkMax_;++ntrk) {
190        stringstream ss;
191        ss << ntrk;
192 <      string suffix = ss.str();
193 <      h["resx_"+suffix]  = fs->make<TH1D>(TString("deltax_"+suffix),"x-distance (Rec - Sim)",100,-0.02,0.02);
194 <      h["resx_"+suffix]->GetXaxis()->SetTitle("cm");
195 <      h["resy_"+suffix]  = fs->make<TH1D>(TString("deltay_"+suffix),"y-distance (Rec - Sim)",100,-0.02,0.02);
196 <      h["resy_"+suffix]->GetXaxis()->SetTitle("cm");
197 <      h["resz_"+suffix]  = fs->make<TH1D>(TString("deltaz_"+suffix),"z-distance (Rec - Sim)",100,-0.02,0.02);
198 <      h["resz_"+suffix]->GetXaxis()->SetTitle("cm");
199 <      h["pullx_"+suffix] = fs->make<TH1D>(TString("pullx_"+suffix),"x-pull (Rec - Sim)",100,-10.,10.);
200 <      h["pully_"+suffix] = fs->make<TH1D>(TString("pully_"+suffix),"y-pull (Rec - Sim)",100,-10.,10.);
201 <      h["pullz_"+suffix] = fs->make<TH1D>(TString("pullz_"+suffix),"z-pull (Rec - Sim)",100,-10.,10.);
202 <      h["errPVx_"+suffix]  = subDir1.make<TH1D>(TString("errPVx_"+suffix),"X vertex error",100,0.,0.02);
203 <      h["errPVy_"+suffix]  = subDir1.make<TH1D>(TString("errPVy_"+suffix),"Y vertex error",100,0.,0.02);
204 <      h["errPVz_"+suffix]  = subDir1.make<TH1D>(TString("errPVz_"+suffix),"Z vertex error",100,0.,0.02);
205 <      suffix.clear();
206 <    }
192 >      string suffix2 = suffix+"_"+ss.str();
193 >      h["deltax"+suffix2]  = subDir1.make<TH1D>(TString("deltax"+suffix2), TString("x-residual of pvtx"+suffix),100,-0.02,0.02);
194 >      h["deltax"+suffix2]->GetXaxis()->SetTitle("cm");
195 >      h["deltay"+suffix2]  = subDir1.make<TH1D>(TString("deltay"+suffix2), TString("y-residual of pvtx"+suffix),100,-0.02,0.02);
196 >      h["deltay"+suffix2]->GetXaxis()->SetTitle("cm");
197 >      h["deltaz"+suffix2]  = subDir1.make<TH1D>(TString("deltaz"+suffix2), TString("z-residual of pvtx"+suffix),100,-0.02,0.02);
198 >      h["deltaz"+suffix2]->GetXaxis()->SetTitle("cm");
199 >      h["pullx"+suffix2] = subDir1.make<TH1D>(TString("pullx"+suffix2), TString("x-pull of pvtx"+suffix),100,-10.,10.);
200 >      h["pully"+suffix2] = subDir1.make<TH1D>(TString("pully"+suffix2), TString("y-pull of pvtx"+suffix),100,-10.,10.);
201 >      h["pullz"+suffix2] = subDir1.make<TH1D>(TString("pullz"+suffix2), TString("z-pull of pvtx"+suffix),100,-10.,10.);
202 >      h["errPVx"+suffix2] = subDir1.make<TH1D>(TString("errPVx"+suffix2), TString("X"+suffix+" vertex error"),100,0.,0.02);
203 >      h["errPVy"+suffix2] = subDir1.make<TH1D>(TString("errPVy"+suffix2), TString("Y"+suffix+" vertex error"),100,0.,0.02);
204 >      h["errPVz"+suffix2] = subDir1.make<TH1D>(TString("errPVz"+suffix2), TString("Z"+suffix+" vertex error"),100,0.,0.02);
205 >      suffix2.clear();
206 >    } // End of   for (int ntrk=nTrkMin_;ntrk<=nTrkMax_;++ntrk) {
207 >    
208 >    // Book residual and pull histograms only when analyzeOntheFly is enabled
209 >    if(analyze_) {
210 >      h2["resx"+suffix+"_nTrk"]= subDir.make<TH2D>(TString("resx"+suffix+"_nTrk"), TString("x-resolution vs number of tracks in pvtx"+suffix),150,0,150,400,0.,200);
211 >      h2["resx"+suffix+"_nTrk"]->SetMarkerStyle(21);
212 >      h2["resx"+suffix+"_nTrk"]->SetMarkerColor(4);
213 >      h2["resx"+suffix+"_nTrk"]->GetXaxis()->SetTitle("Num of tracks");
214 >      h2["resx"+suffix+"_nTrk"]->GetYaxis()->SetTitle("#mum");
215 >      h2["resy"+suffix+"_nTrk"]= subDir.make<TH2D>(TString("resy"+suffix+"_nTrk"), TString("y-resolution vs number of tracks in pvtx"+suffix),150,0,150,400,0.,200);
216 >      h2["resy"+suffix+"_nTrk"]->SetMarkerStyle(21);
217 >      h2["resy"+suffix+"_nTrk"]->SetMarkerColor(4);
218 >      h2["resy"+suffix+"_nTrk"]->GetXaxis()->SetTitle("Num of tracks");
219 >      h2["resy"+suffix+"_nTrk"]->GetYaxis()->SetTitle("#mum");
220 >      h2["resz"+suffix+"_nTrk"]= subDir.make<TH2D>(TString("resz"+suffix+"_nTrk"), TString("z-resolution vs number of tracks in pvtx"+suffix),150,0,150,400,0.,200);
221 >      h2["resz"+suffix+"_nTrk"]->SetMarkerStyle(21);
222 >      h2["resz"+suffix+"_nTrk"]->SetMarkerColor(4);
223 >      h2["resz"+suffix+"_nTrk"]->GetXaxis()->SetTitle("Num of tracks");
224 >      h2["resz"+suffix+"_nTrk"]->GetYaxis()->SetTitle("#mum");
225 >      h2["pullx"+suffix+"_nTrk"]= subDir.make<TH2D>(TString("pullx"+suffix+"_nTrk"), TString("x-pull vs number of tracks"+suffix),150,0,150,100,0.,2.);
226 >      h2["pullx"+suffix+"_nTrk"]->SetMarkerStyle(21);
227 >      h2["pullx"+suffix+"_nTrk"]->SetMarkerColor(4);
228 >      h2["pullx"+suffix+"_nTrk"]->SetBit(TH1::kCanRebin);
229 >      h2["pullx"+suffix+"_nTrk"]->GetXaxis()->SetTitle("Num of tracks");
230 >      h2["pully"+suffix+"_nTrk"]= subDir.make<TH2D>(TString("pully"+suffix+"_nTrk"), TString("y-pull vs number of tracks"+suffix),150,0,150,100,0.,2.);
231 >      h2["pully"+suffix+"_nTrk"]->SetMarkerStyle(21);
232 >      h2["pully"+suffix+"_nTrk"]->SetMarkerColor(4);
233 >      h2["pully"+suffix+"_nTrk"]->SetBit(TH1::kCanRebin);
234 >      h2["pully"+suffix+"_nTrk"]->GetXaxis()->SetTitle("Num of tracks");
235 >      h2["pullz"+suffix+"_nTrk"]= subDir.make<TH2D>(TString("pullz"+suffix+"_nTrk"), TString("x-pull vs number of tracks"+suffix),150,0,150,100,0.,2.);
236 >      h2["pullz"+suffix+"_nTrk"]->SetMarkerStyle(21);
237 >      h2["pullz"+suffix+"_nTrk"]->SetMarkerColor(4);
238 >      h2["pullz"+suffix+"_nTrk"]->SetBit(TH1::kCanRebin);
239 >      h2["pullz"+suffix+"_nTrk"]->GetXaxis()->SetTitle("Num of tracks");
240 >    } // End of   if(analyze_) {
241 >    suffix.clear();
242 >  } // End of Book histograms sensitive to data/mc  
243 >  // Book MC only plots
244 >  if (!realData_) {  
245 >    h["genPart_T"]      = subDir.make<TH1D>("genPart_T","t component of gen particles",300,-0.5,0.5);
246 >    h["genPart_T"]->GetXaxis()->SetTitle("t (nanosecond)");
247 >    h["genPart_cT"]     = subDir.make<TH1D>("genPart_cT","ct component of gen particles",300,-150.,150.);
248 >    h["genPart_cT"]->GetXaxis()->SetTitle("ct (mm)");    
249 >    h["nsimPV"]         = subDir.make<TH1D>("nsimPV","Num of sim PV",51,-0.5,50.5);  
250    }
251   }
252  
164
253   PVStudy::~PVStudy()
254   {
255  
# Line 377 | Line 465 | void
465   PVStudy::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
466   {
467    using namespace edm;
468 <  using reco::TrackCollection;
469 <
470 <  ftree_->SetBranchAddress("residual",&fres);
471 <  ftree_->SetBranchAddress("error",&ferror);
472 <  ftree_->SetBranchAddress("nTrk",&fntrk);
473 <
474 <  Handle<TrackCollection> tracks;
475 <  iEvent.getByLabel(tracksLabel_,tracks);
476 <
477 <  Handle<reco::VertexCollection> recVtxs;
478 <  iEvent.getByLabel(vtxSample_, recVtxs);
468 >  using namespace reco;
469 >  
470 >  if (verbose_)
471 >    cout<<"PVStudy::analyze():"<<endl;
472 >  //=======================================================
473 >  // Initialize Root-tuple variables if needed
474 >  //=======================================================
475 >  if(saventuple_)
476 >    SetVarToZero();
477 >  
478 >  //=======================================================
479 >  // Track accessors
480 >  //=======================================================
481 >  //trackCollection
482 >  static const reco::TrackCollection s_empty_trackColl;
483 >  const reco::TrackCollection *trackColl = &s_empty_trackColl;
484 >  edm::Handle<reco::TrackCollection> trackCollectionHandle;
485 >  iEvent.getByLabel(trackCollectionTag_, trackCollectionHandle);
486 >  if( iEvent.getByLabel(trackCollectionTag_, trackCollectionHandle)) {
487 >    trackColl = trackCollectionHandle.product();
488 >  } else {
489 >    cout << "trackCollection cannot be found -> using empty collection of same type." <<endl;
490 >  }
491 >  //splitTrackCollection1
492 >  static const reco::TrackCollection s_empty_splitTrackColl1;
493 >  const reco::TrackCollection *splitTrackColl1 = &s_empty_splitTrackColl1;
494 >  edm::Handle<reco::TrackCollection> splitTrackCollection1Handle;
495 >  iEvent.getByLabel(splitTrackCollection1Tag_, splitTrackCollection1Handle);
496 >  if( iEvent.getByLabel(splitTrackCollection1Tag_, splitTrackCollection1Handle)) {
497 >    splitTrackColl1 = splitTrackCollection1Handle.product();
498 >  } else {
499 >    cout << "splitTrackCollection1 cannot be found -> using empty collection of same type." <<endl;
500 >  }
501 >  //splitTrackCollection2
502 >  static const reco::TrackCollection s_empty_splitTrackColl2;
503 >  const reco::TrackCollection *splitTrackColl2 = &s_empty_splitTrackColl2;
504 >  edm::Handle<reco::TrackCollection> splitTrackCollection2Handle;
505 >  iEvent.getByLabel(splitTrackCollection2Tag_, splitTrackCollection2Handle);
506 >  if( iEvent.getByLabel(splitTrackCollection2Tag_, splitTrackCollection2Handle)) {
507 >    splitTrackColl2 = splitTrackCollection2Handle.product();
508 >  } else {
509 >    cout << "splitTrackCollection2 cannot be found -> using empty collection of same type." <<endl;
510 >  }
511 >  
512 >  //=======================================================
513 >  // PVTX accessors
514 >  //=======================================================
515 >  //vertexCollection
516 >  static const reco::VertexCollection s_empty_vertexColl;
517 >  const reco::VertexCollection *vertexColl = &s_empty_vertexColl;
518 >  edm::Handle<reco::VertexCollection> vertexCollectionHandle;
519 >  iEvent.getByLabel(vertexCollectionTag_, vertexCollectionHandle);
520 >  if( iEvent.getByLabel(vertexCollectionTag_, vertexCollectionHandle)) {
521 >    vertexColl = vertexCollectionHandle.product();
522 >  } else {
523 >    cout << "vertexCollection cannot be found -> using empty collection of same type." <<endl;
524 >  }
525 >  //splitVertexCollection1
526 >  static const reco::VertexCollection s_empty_splitVertexColl1;
527 >  const reco::VertexCollection *splitVertexColl1 = &s_empty_splitVertexColl1;
528 >  edm::Handle<reco::VertexCollection> splitVertexCollection1Handle;
529 >  iEvent.getByLabel(splitVertexCollection1Tag_, splitVertexCollection1Handle);
530 >  if( iEvent.getByLabel(splitVertexCollection1Tag_, splitVertexCollection1Handle)) {
531 >    splitVertexColl1 = splitVertexCollection1Handle.product();
532 >  } else {
533 >    cout << "splitVertexCollection1 cannot be found -> using empty collection of same type." <<endl;
534 >  }
535 >  //splitVertexCollection2
536 >  static const reco::VertexCollection s_empty_splitVertexColl2;
537 >  const reco::VertexCollection *splitVertexColl2 = &s_empty_splitVertexColl2;
538 >  edm::Handle<reco::VertexCollection> splitVertexCollection2Handle;
539 >  iEvent.getByLabel(splitVertexCollection2Tag_, splitVertexCollection2Handle);
540 >  if( iEvent.getByLabel(splitVertexCollection2Tag_, splitVertexCollection2Handle)) {
541 >    splitVertexColl2 = splitVertexCollection2Handle.product();
542 >  } else {
543 >    cout << "splitVertexCollection2 cannot be found -> using empty collection of same type." <<endl;
544 >  }
545  
546 +  if(verbose_) cout<<"Done accessing the track and vertex collections"<<endl;
547 +  
548 +  //=======================================================
549 +  // MC simvtx accessor
550 +  //=======================================================
551    if (!realData_) {
552 <    Handle<SimVertexContainer> simVtxs;
552 >    edm::Handle<SimVertexContainer> simVtxs;
553      iEvent.getByLabel( simG4_, simVtxs);
554      
555 <    Handle<SimTrackContainer> simTrks;
555 >    edm::Handle<SimTrackContainer> simTrks;
556      iEvent.getByLabel( simG4_, simTrks);
557    }
558  
559 <  if(verbose_) printRecVtxs(recVtxs);
560 <
559 >  //=======================================================
560 >  // GET PDT
561 >  //=======================================================
562    try{
563      iSetup.getData(pdt);
564    }catch(const Exception&){
565      cout << "Some problem occurred with the particle data table. This may not work !." <<endl;
566    }
567  
568 +  //=======================================================
569 +  // Fill trackparameters of the input tracks to pvtx fitter
570 +  //=======================================================
571 +
572 +  // GeneralTracks  
573 +  h["nTrk"]->Fill(trackColl->size());
574 +  for(TrackCollection::const_iterator itTrack = trackColl->begin();
575 +      itTrack != trackColl->end();                      
576 +      ++itTrack) {
577 +    h["trkPt"]->Fill(itTrack->pt());
578 +    h["trkDxy"]->Fill(itTrack->dxy());
579 +    h["trkDz"]->Fill(itTrack->dz());
580 +    h["trkEta"]->Fill(itTrack->eta());
581 +    h["trkPhi"]->Fill(itTrack->phi());
582 +  }
583 +  
584 +  //SplittedTracks1
585 +  h["nTrk1_spl"]->Fill(splitTrackColl1->size());
586 +  for(TrackCollection::const_iterator itTrack = splitTrackColl1->begin();
587 +      itTrack != splitTrackColl1->end();                      
588 +      ++itTrack) {
589 +    h["trkPt1_spl"]->Fill(itTrack->pt());
590 +    h["trkDxy1_spl"]->Fill(itTrack->dxy());
591 +    h["trkDz1_spl"]->Fill(itTrack->dz());
592 +    h["trkEta1_spl"]->Fill(itTrack->eta());
593 +    h["trkPhi1_spl"]->Fill(itTrack->phi());
594 +  }
595 +  //SplittedTracks2  
596 +  h["nTrk2_spl"]->Fill(splitTrackColl2->size());
597 +  for(TrackCollection::const_iterator itTrack = splitTrackColl2->begin();
598 +      itTrack != splitTrackColl2->end();                      
599 +      ++itTrack) {
600 +    h["trkPt2_spl"]->Fill(itTrack->pt());
601 +    h["trkDxy2_spl"]->Fill(itTrack->dxy());
602 +    h["trkDz2_spl"]->Fill(itTrack->dz());
603 +    h["trkEta2_spl"]->Fill(itTrack->eta());
604 +    h["trkPhi2_spl"]->Fill(itTrack->phi());
605 +  }
606 +  
607 +  if(verbose_)
608 +    cout<<"Done filling track parameters of the input tracks to pvtx fitter."<<endl;
609 +
610 +  //=======================================================
611 +  // Fill reconstructed vertices
612 +  //=======================================================
613 +  if(verbose_)  {
614 +    cout<<"PVStudy::analyze() Printing vertexCollection: "<<endl;
615 +    printRecVtxs(vertexCollectionHandle);
616 +    cout<<"PVStudy::analyze() Printing splitVertexCollection1: "<<endl;
617 +    printRecVtxs(splitVertexCollection1Handle);
618 +    cout<<"PVStudy::analyze() Printing splitVertexCollection2: "<<endl;
619 +    printRecVtxs(splitVertexCollection2Handle);
620 +  }
621 +  
622 +  h["nrecPV"]->Fill(vertexColl->size());
623 +  h["nrecPV1_spl"]->Fill(splitVertexColl1->size());
624 +  h["nrecPV2_spl"]->Fill(splitVertexColl2->size());
625 +  h["nrecPVDiff"]->Fill(double(splitVertexColl1->size())-double(splitVertexColl2->size()));
626 +  //Fill the tree variables
627 +  nrecPV_ = vertexColl->size();
628 +  nrecPV1_spl_ = splitVertexColl1->size();
629 +  nrecPV2_spl_ = splitVertexColl2->size();
630 +  
631 +  // Fill the track paramters for the vertexColl
632 +  for(reco::VertexCollection::const_iterator v=vertexColl->begin();
633 +      v!=vertexColl->end(); ++v){  
634 +    try {
635 +      for(reco::Vertex::trackRef_iterator t = v->tracks_begin();
636 +          t!=v->tracks_end(); t++) {
637 +        // illegal charge
638 +        if ( (**t).charge() < -1 || (**t).charge() > 1 ) {
639 +          //      h["trkPtPV"]->Fill(0.);
640 +        }
641 +        else {
642 +          h["trkPtPV"]->Fill((**t).pt());
643 +          h["trkDxyPV"]->Fill((**t).dxy());
644 +          h["trkDzPV"]->Fill((**t).dz());
645 +          h["trkEtaPV"]->Fill((**t).eta());
646 +          h["trkPhiPV"]->Fill((**t).phi());
647 +        }
648 +      }
649 +    }
650 +    catch (...) {
651 +      // exception thrown when trying to use linked track
652 +      //          h["trkPtPV"]->Fill(0.);
653 +    }
654 +  }
655 +  
656 +  
657 +  // == ignore multi-vertices (for now)
658 +  //take single pvt collection and compare
659 +  if(splitVertexColl1->size() == 1 && splitVertexColl2->size() == 1 ) {
660 +    const reco::Vertex recvtx1 = *(splitVertexColl1->begin());
661 +    const reco::Vertex recvtx2 = *(splitVertexColl2->begin());
662 +    if (matchVertex(recvtx1, recvtx2))  {
663 +      int nTrkPV1 = recvtx1.tracksSize();
664 +      int nTrkPV2 = recvtx2.tracksSize();    
665 +      h["nTrkPV1_spl"]->Fill(nTrkPV1);
666 +      h["nTrkPV2_spl"]->Fill(nTrkPV2);
667 +      double ntrkreldiff = double(nTrkPV1-nTrkPV2)/double(nTrkPV1+nTrkPV2);
668 +      h["nTrkPVDiff"]->Fill(nTrkPV1-nTrkPV2);
669 +      h["nTrkPVRelDiff"]->Fill(ntrkreldiff);
670 +      
671 +      // Fill the track paramters for the splitVertexColl1
672 +      try {
673 +        for(reco::Vertex::trackRef_iterator t = recvtx1.tracks_begin();
674 +            t!=recvtx1.tracks_end(); t++) {
675 +          // illegal charge
676 +          if ( (**t).charge() < -1 || (**t).charge() > 1 ) {
677 +            //    h["trkPtPV"]->Fill(0.);
678 +          }
679 +          else {
680 +            h["trkPtPV1_spl"]->Fill((**t).pt());
681 +            h["trkDxyPV1_spl"]->Fill((**t).dxy());
682 +            h["trkDzPV1_spl"]->Fill((**t).dz());
683 +            h["trkEtaPV1_spl"]->Fill((**t).eta());
684 +            h["trkPhiPV1_spl"]->Fill((**t).phi());
685 +          }
686 +        }
687 +      }
688 +      catch (...) {
689 +        // exception thrown when trying to use linked track
690 +        //        h["trkPtPV"]->Fill(0.);
691 +      }
692 +      
693 +      // Fill the track paramters for the splitVertexColl2
694 +      try {
695 +        for(reco::Vertex::trackRef_iterator t = recvtx2.tracks_begin();
696 +            t!=recvtx2.tracks_end(); t++) {
697 +          // illegal charge
698 +          if ( (**t).charge() < -1 || (**t).charge() > 1 ) {
699 +            //    h["trkPtPV"]->Fill(0.);
700 +          }
701 +          else {
702 +            h["trkPtPV2_spl"]->Fill((**t).pt());
703 +            h["trkDxyPV2_spl"]->Fill((**t).dxy());
704 +            h["trkDzPV2_spl"]->Fill((**t).dz());
705 +            h["trkEtaPV2_spl"]->Fill((**t).eta());
706 +            h["trkPhiPV2_spl"]->Fill((**t).phi());
707 +          }
708 +        }
709 +      }
710 +      catch (...) {
711 +        // exception thrown when trying to use linked track
712 +        //        h["trkPtPV"]->Fill(0.);
713 +      }
714 +      
715 +      if(verbose_)
716 +        cout<<"Done filling track parameters in reconstruced vertices."<<endl;
717 +
718 +      if(fabs(ntrkreldiff)<ntrkdiffcut_) {
719 +        fres_[0] = (recvtx1.x()-recvtx2.x())/sqrt(2.0);
720 +        fres_[1] = (recvtx1.y()-recvtx2.y())/sqrt(2.0);
721 +        fres_[2] = (recvtx1.z()-recvtx2.z())/sqrt(2.0);      
722 +        ferror_[0] = sqrt(pow(recvtx1.xError(),2)+pow(recvtx2.xError(),2))/sqrt(2);
723 +        ferror_[1] = sqrt(pow(recvtx1.yError(),2)+pow(recvtx2.yError(),2))/sqrt(2);
724 +        ferror_[2] = sqrt(pow(recvtx1.zError(),2)+pow(recvtx2.zError(),2))/sqrt(2);
725 +        fntrk_ =  (nTrkPV1+nTrkPV2)/2;
726 +        
727 +        h["deltax"]->Fill( fres_[0] );
728 +        h["deltay"]->Fill( fres_[1] );
729 +        h["deltaz"]->Fill( fres_[2] );
730 +        h["pullx"]->Fill( fres_[0]/ferror_[0]);
731 +        h["pully"]->Fill( fres_[1]/ferror_[1]);
732 +        h["pullz"]->Fill( fres_[2]/ferror_[2]);
733 +        h["errPVx"]->Fill( ferror_[0] );
734 +        h["errPVy"]->Fill( ferror_[1] );
735 +        h["errPVz"]->Fill( ferror_[2] );
736 +        pvinfo.push_back(PVStudy::PVInfo(res(fres_[0], fres_[1], fres_[2]),
737 +                                         error(ferror_[0], ferror_[1], ferror_[2]),
738 +                                         fntrk_));
739 +        // Fill histo according to its track multiplicity, set datamode = 0
740 +        fillHisto(res(fres_[0], fres_[1], fres_[2]),
741 +                  error(ferror_[0], ferror_[1], ferror_[2]),
742 +                  fntrk_,0);  
743 +
744 +        ftree_->Fill();  
745 +      } // End of  if(fabs(ntrkreldiff)<ntrkdiffcut_) {
746 +    } // End of  if (matchVertex(recvtx1, recvtx2))  {
747 +    else   {
748 +      cout<<"WARNING: The two reconstructed vertices do not match in z: "<<endl;
749 +      cout<<"recvtx1.z() = " << recvtx1.z() <<"; recvtx2.z() = " <<  recvtx2.z() <<endl;
750 +    }
751 +  } // End of fill histograms for two-vertices Method
752 +
753 +  if(verbose_)
754 +    cout<<"Done filling res/pull with two-vertices method"<<endl;
755 +
756 +  //=======================================================
757 +  // Fill simulated vertices
758 +  //=======================================================
759    if (!realData_) {
760      bool MC=false;
761      Handle<HepMCProduct> evtMC;
# Line 420 | Line 771 | PVStudy::analyze(const edm::Event& iEven
771        }
772        MC=true;
773      }
774 <
774 >    
775      if(MC){
776        // make a list of primary vertices:
777        std::vector<simPrimaryVertex> simpv;
778        simpv=getSimPVs(evtMC,"");
779        //     simpv=getSimPVs(evtMC, simVtxs, simTrks);
780 <    
780 >      h["nsimPV"]->Fill(simpv.size());
781        int nsimtrk=0;
782        int nrectrk=0;
783 +      
784        for(std::vector<simPrimaryVertex>::iterator vsim=simpv.begin();
785            vsim!=simpv.end(); vsim++){
786          nsimtrk+=vsim->nGenTrk;
787 <        // look for a matching reconstructed vertex
788 <        vsim->recVtx=NULL;
789 <        for(reco::VertexCollection::const_iterator vrec=recVtxs->begin();
790 <            vrec!=recVtxs->end(); ++vrec){
791 <          nrectrk=vrec->tracksSize();
792 <          if(verbose_){
793 <            cout << "sim primary vertex x = " << vsim->x << "; y = " << vsim->y << "; z = " << vsim->z <<  endl;
794 <            cout << "Is matched? " << (matchVertex(*vsim,*vrec)?"Yes":"No") << endl;
795 <          }
796 <          if ( matchVertex(*vsim,*vrec) ){
797 <            // if the matching critera are fulfilled, accept the rec-vertex that is closest in z
798 <            if(    ((vsim->recVtx) && (fabs(vsim->recVtx->position().z()-vsim->z)>fabs(vrec->z()-vsim->z)))
799 <                   || (!vsim->recVtx) )
800 <              {
787 >        // Loop over the datamodes, for MC, fill only 1, 2, 3
788 >        for (int i=1;i<=3;i++) {
789 >          static const reco::VertexCollection s_empty_vtxColl;
790 >          const reco::VertexCollection *vtxColl = &s_empty_vtxColl;
791 >          std::string suffix;
792 >          // Set the vertexColl and histogram suffix according to datamode
793 >          if (i == 1) {
794 >            vtxColl = splitVertexColl1;
795 >            suffix = "_spl1_mct";
796 >          }
797 >          if (i == 2) {
798 >            vtxColl =  splitVertexColl2;
799 >            suffix = "_spl2_mct";
800 >          }
801 >          if (i == 3) {
802 >            vtxColl =  vertexColl;
803 >            suffix = "_mct";
804 >          }
805 >          //========================================================
806 >          //  look for a matching reconstructed vertex in vertexColl
807 >          //========================================================    
808 >          vsim->recVtx=NULL;
809 >          for(reco::VertexCollection::const_iterator vrec=vtxColl->begin();
810 >              vrec!=vtxColl->end(); ++vrec){
811 >            nrectrk=vrec->tracksSize();
812 >            if(verbose_){
813 >              cout << "sim primary vertex x = " << vsim->x << "; y = " << vsim->y << "; z = " << vsim->z <<  endl;
814 >              cout << "Is matched? " << (matchVertex(*vsim,*vrec)?"Yes":"No") << endl;
815 >            }
816 >            if ( matchVertex(*vsim,*vrec) ){
817 >              // if the matching critera are fulfilled, accept the rec-vertex that is closest in z
818 >              if(    ((vsim->recVtx) && (fabs(vsim->recVtx->position().z()-vsim->z)>fabs(vrec->z()-vsim->z)))
819 >                     || (!vsim->recVtx) )
820                  vsim->recVtx=&(*vrec);
821 +            }// End of finding the matched reco_vertex
822 +            
823 +            if (vsim->recVtx){
824 +              if(verbose_) {
825 +                cout <<"primary matched in vertexColl" << vsim->x << " " << vsim->y << " " << vsim->z <<  endl;
826 +              }
827 +              double fres_mct[3];
828 +              double ferror_mct[3];
829 +              int fntrk_mct;
830 +              
831 +              fres_mct[0] = vsim->recVtx->x()-vsim->x;
832 +              fres_mct[1] = vsim->recVtx->y()-vsim->y;
833 +              fres_mct[2] = vsim->recVtx->z()-vsim->z;
834 +              ferror_mct[0] = vsim->recVtx->xError();
835 +              ferror_mct[1] = vsim->recVtx->yError();
836 +              ferror_mct[2] = vsim->recVtx->zError();
837 +              fntrk_mct = nrectrk;
838 +              
839 +              //Fill the values for variables in ftree_
840 +              if(i == 1) {
841 +                for(int j = 0;j<3;j++)
842 +                  fres_spl1_mct_[j] = fres_mct[j];
843 +                fntrk_spl1_mct_ =  fntrk_mct;
844                }
845 +              if(i == 2) {
846 +                for(int j = 0;j<3;j++)
847 +                  fres_spl2_mct_[j] = fres_mct[j];
848 +                fntrk_spl2_mct_ =  fntrk_mct;
849 +              }
850 +              if(i == 3) {
851 +                for(int j=0;j<3;j++)
852 +                  fres_mct_[j] = fres_mct[j];
853 +                fntrk_mct_ =  fntrk_mct;
854 +              }
855 +              
856 +              h["deltax"+suffix]->Fill( fres_mct[0] );
857 +              h["deltay"+suffix]->Fill( fres_mct[1] );
858 +              h["deltaz"+suffix]->Fill( fres_mct[2] );
859 +              h["pullx"+suffix]->Fill( fres_mct[0]/ferror_mct[0] );
860 +              h["pully"+suffix]->Fill( fres_mct[1]/ferror_mct[1] );
861 +              h["pullz"+suffix]->Fill( fres_mct[2]/ferror_mct[2] );
862 +              h["errPVx"+suffix]->Fill( ferror_mct[0] );
863 +              h["errPVy"+suffix]->Fill( ferror_mct[1] );
864 +              h["errPVz"+suffix]->Fill( ferror_mct[2] );
865 +              pvinfo.push_back(PVStudy::PVInfo(res(fres_mct[0], fres_mct[1], fres_mct[2]),
866 +                                               error(ferror_mct[0], ferror_mct[1], ferror_mct[2]),
867 +                                               fntrk_mct));
868 +              // Fill histo according to its track multiplicity
869 +              fillHisto(res(fres_mct[0], fres_mct[1], fres_mct[2]),
870 +                        error(ferror_mct[0], ferror_mct[1], ferror_mct[2]),
871 +                        fntrk_mct, i);
872 +              ftree_->Fill();
873 +              suffix.clear();
874 +            }
875 +            else {  // no rec vertex found for this simvertex
876 +              if(verbose_)
877 +                cout <<"primary not found " << vsim->x << " " << vsim->y << " " << vsim->z << " nGenTrk=" << vsim->nGenTrk << endl;
878 +            }
879            }
880 <        }
881 <        if (vsim->recVtx){
882 <          if(verbose_) {
883 <            cout <<"primary matched " << vsim->x << " " << vsim->y << " " << vsim->z <<  endl;
456 <          }
457 <          fres[0] = vsim->recVtx->x()-vsim->x;
458 <          fres[1] = vsim->recVtx->y()-vsim->y;
459 <          fres[2] = vsim->recVtx->z()-vsim->z;
460 <          ferror[0] = vsim->recVtx->xError();
461 <          ferror[1] = vsim->recVtx->yError();
462 <          ferror[2] = vsim->recVtx->zError();
463 <          fntrk = nrectrk;
464 <
465 <          h["deltax"]->Fill( fres[0] );
466 <          h["deltay"]->Fill( fres[1] );
467 <          h["deltaz"]->Fill( fres[2] );
468 <          h["pullx"]->Fill( fres[0]/ferror[0] );
469 <          h["pully"]->Fill( fres[1]/ferror[1] );
470 <          h["pullz"]->Fill( fres[2]/ferror[2] );
471 <          h["errPVx"]->Fill( ferror[0] );
472 <          h["errPVy"]->Fill( ferror[1] );
473 <          h["errPVz"]->Fill( ferror[2] );
474 <          pvinfo.push_back(PVStudy::PVInfo(res(fres[0], fres[1], fres[2]),
475 <                                           error(ferror[0], ferror[1], ferror[2]),
476 <                                           nrectrk));
477 <          // Fill histo according to its track multiplicity
478 <          fillHisto(res(fres[0], fres[1], fres[2]),
479 <                    error(ferror[0], ferror[1], ferror[2]),
480 <                    nrectrk);
481 <
482 <          ftree_->Fill();
483 <        }
484 <        else{  // no rec vertex found for this simvertex
485 <          if(verbose_) {
486 <            cout <<"primary not found " << vsim->x << " " << vsim->y << " " << vsim->z << " nGenTrk=" << vsim->nGenTrk << endl;
487 <          }
488 <        }
489 <      }
490 <    }
491 <  }// With MC
492 <  
493 <  // Loop RecVtxs and find matched SimVtxs
494 <  for(reco::VertexCollection::const_iterator v=recVtxs->begin();
495 <      v!=recVtxs->end(); ++v){
496 <    try {
497 <      for(reco::Vertex::trackRef_iterator t = v->tracks_begin();
498 <          t!=v->tracks_end(); t++) {
499 <        // illegal charge
500 <        if ( (**t).charge() < -1 || (**t).charge() > 1 ) {
501 <          //      h["trkPtPV"]->Fill(0.);
502 <        }
503 <        else {
504 <          h["trkPtPV"]->Fill((**t).pt());
505 <        }
506 <      }
507 <    }
508 <    catch (...) {
509 <      // exception thrown when trying to use linked track
510 <      //          h["trkPtPV"]->Fill(0.);
511 <    }
512 <    
513 <    h["nTrkPV"]->Fill(v->tracksSize());
514 <    
515 <  }
516 <  
517 <  h["nTrk"]->Fill(tracks->size());
518 <  
519 <  for(TrackCollection::const_iterator itTrack = tracks->begin();
520 <      itTrack != tracks->end();                      
521 <      ++itTrack) {
522 <    int charge = 0;
523 <    charge = itTrack->charge();
524 <    h["trkPt"]->Fill(itTrack->pt());
525 <  }
526 <  
880 >        } // === End of Looping through vertexColl
881 >      }
882 >    } // End of  for(std::vector<simPrimaryVertex>::iterator vsim=simpv.begin()
883 >  } // End of Filling MC variables
884   }
885  
529
886   // ------------ method called once each job just before starting event loop  ------------
887   void
888   PVStudy::beginJob()
# Line 536 | Line 892 | PVStudy::beginJob()
892   // ------------ method called once each job just after ending the event loop  ------------
893   void
894   PVStudy::endJob() {
895 <  double sqt2 = sqrt(2.);
896 <  if (!realData_) {
897 <    if (verbose_) cout << "Analyzing PV info" << endl;
895 >  if (verbose_) cout << "Analyzing PV info" << endl;
896 >  // Looping through the datamodes available
897 >  for (vector<int>::const_iterator it= datamode.begin(); it != datamode.end() ; ++it) {  
898 >    string suffix;
899 >    if(verbose_)  cout<<"datamode = "<< *it<<endl;
900 >    switch(*it) {
901 >    case 0: suffix = "";
902 >      break;
903 >    case 1: suffix = "_spl1_mct";
904 >      break;
905 >    case 2: suffix = "_spl2_mct";      
906 >      break;
907 >    case 3: suffix = "_mct";
908 >      break;
909 >    }
910      for (int ntrk=nTrkMin_;ntrk<=nTrkMax_;++ntrk) {
911        if (verbose_) cout << "Fill point of ntrk = " << ntrk << endl;
912 <      PVStudy::PVAnaInfo ipv = GetPVAnaInfo(ntrk);
912 >      PVStudy::PVAnaInfo ipv = GetPVAnaInfo(ntrk,*it);
913        if (analyze_) {
914 < //      if ( ipv.res_.x() > 0 ) h2["resx_nTrk"]->Fill(ntrk,ipv.res_.x()/sqt2, 1.);
915 < //      if ( ipv.res_.y() > 0 ) h2["resy_nTrk"]->Fill(ntrk,ipv.res_.y()/sqt2, 1.);
916 < //      if ( ipv.res_.z() > 0 ) h2["resz_nTrk"]->Fill(ntrk,ipv.res_.z()/sqt2, 1.);
917 <        if ( ipv.res_.x() > 0 ) h2["resx_nTrk"]->Fill(ntrk,ipv.res_.x(), 1.);
918 <        if ( ipv.res_.y() > 0 ) h2["resy_nTrk"]->Fill(ntrk,ipv.res_.y(), 1.);
919 <        if ( ipv.res_.z() > 0 ) h2["resz_nTrk"]->Fill(ntrk,ipv.res_.z(), 1.);
552 <        if ( ipv.pull_.x() > 0 ) h2["pullx_nTrk"]->Fill(ntrk,ipv.pull_.x(), 1.);
553 <        if ( ipv.pull_.y() > 0 ) h2["pully_nTrk"]->Fill(ntrk,ipv.pull_.y(), 1.);
554 <        if ( ipv.pull_.z() > 0 ) h2["pullz_nTrk"]->Fill(ntrk,ipv.pull_.z(), 1.);
914 >        if ( ipv.res_.x() > 0 ) h2["resx"+suffix+"_nTrk"]->Fill(ntrk,ipv.res_.x(), 1.);
915 >        if ( ipv.res_.y() > 0 ) h2["resy"+suffix+"_nTrk"]->Fill(ntrk,ipv.res_.y(), 1.);
916 >        if ( ipv.res_.z() > 0 ) h2["resz"+suffix+"_nTrk"]->Fill(ntrk,ipv.res_.z(), 1.);
917 >        if ( ipv.pull_.x() > 0 ) h2["pullx"+suffix+"_nTrk"]->Fill(ntrk,ipv.pull_.x(), 1.);
918 >        if ( ipv.pull_.y() > 0 ) h2["pully"+suffix+"_nTrk"]->Fill(ntrk,ipv.pull_.y(), 1.);
919 >        if ( ipv.pull_.z() > 0 ) h2["pullz"+suffix+"_nTrk"]->Fill(ntrk,ipv.pull_.z(), 1.);
920        }
921 <    }
921 >    } // End of  for (int ntrk=nTrkMin_;ntrk<=nTrkMax_;++ntrk) {
922 >    suffix.clear();
923    }
924    file_->cd();
925    ftree_->Write();
926    file_->Close();
927   }
928  
929 +
930 +
931 + // Match a recovertex with a simvertex
932 + // ? Should the cut be parameter dependent?
933 + // cut can be within n sigma of the vertex.zerror()
934   bool PVStudy::matchVertex(const PVStudy::simPrimaryVertex & vsim,
935                            const reco::Vertex & vrec)
936   {
937    return (fabs(vsim.z-vrec.z())<0.0500); // =500um
938   }
939  
940 + // Match two reconstructed vertices
941 + bool PVStudy::matchVertex( const reco::Vertex & vrec1,
942 +                           const reco::Vertex & vrec2)
943 + {
944 +  return (fabs(vrec1.z()-vrec2.z())<0.0500); // =500um
945 + }
946 +
947 +
948   bool PVStudy::isResonance(const HepMC::GenParticle * p){
949    double ctau=(pdt->particle( abs(p->pdg_id()) ))->lifetime();
950    if(verbose_) cout << "isResonance   " << p->pdg_id() << " " << ctau << endl;
# Line 637 | Line 1016 | void PVStudy::printSimTrks(const Handle<
1016    }
1017   }
1018  
1019 < void PVStudy::fillHisto(res r, error er, int ntk){
1019 > void PVStudy::fillHisto(res r, error er, int ntk, int datamode){
1020    stringstream ss;
1021    ss << ntk;
1022    string suffix = ss.str();
1023 +  if(datamode == 0 )  suffix = "_" + suffix;
1024 +  if(datamode == 1 )  suffix = "_spl1_mct_" + suffix;
1025 +  if(datamode == 2 )  suffix = "_spl2_mct_" + suffix;
1026 +  if(datamode == 3 )  suffix = "_mct_" + suffix;
1027 +  
1028    if (ntk < nTrkMin_ || ntk > nTrkMax_ ) return;
1029    // Fill histograms of res and pull of ntk
1030 <  h["resx_"+suffix]->Fill(r.x());
1031 <  h["resy_"+suffix]->Fill(r.y());
1032 <  h["resz_"+suffix]->Fill(r.z());
1033 <  h["pullx_"+suffix]->Fill(r.x()/er.x());
1034 <  h["pully_"+suffix]->Fill(r.y()/er.y());
1035 <  h["pullz_"+suffix]->Fill(r.z()/er.z());
1036 <  h["errPVx_"+suffix]->Fill(er.x());
1037 <  h["errPVy_"+suffix]->Fill(er.y());
1038 <  h["errPVz_"+suffix]->Fill(er.z());
1030 >  h["deltax"+suffix]->Fill(r.x());
1031 >  h["deltay"+suffix]->Fill(r.y());
1032 >  h["deltaz"+suffix]->Fill(r.z());
1033 >  h["pullx"+suffix]->Fill(r.x()/er.x());
1034 >  h["pully"+suffix]->Fill(r.y()/er.y());
1035 >  h["pullz"+suffix]->Fill(r.z()/er.z());  
1036 >  h["errPVx"+suffix]->Fill(er.x());
1037 >  h["errPVy"+suffix]->Fill(er.y());
1038 >  h["errPVz"+suffix]->Fill(er.z());
1039   }
1040  
1041 < PVStudy::PVAnaInfo PVStudy::GetPVAnaInfo(int ntk) {
1041 > PVStudy::PVAnaInfo PVStudy::GetPVAnaInfo(int ntk, int datamode) {
1042    map<int,double> data;
1043    data.clear();
1044    double fpar[2] = {-999,-999};
1045    double cm2um = 10000;
1046    stringstream ss;
1047    ss << ntk;
1048 <  string suffix = ss.str();
1049 <
1048 >  string suffix = ss.str();
1049 >  if(datamode == 0 )  suffix = "_" + suffix;
1050 >  if(datamode == 1 )  suffix = "_spl1_mct_" + suffix;
1051 >  if(datamode == 2 )  suffix = "_spl2_mct_" + suffix;
1052 >  if(datamode == 3 )  suffix = "_mct_" + suffix;
1053 >  
1054    if(analyze_) {
1055      for ( int i = 0; i < 6; ++i) {
1056        switch (i) {
1057        case 0:
1058 <        fit(h["resx_"+suffix], fpar);
1058 >        fit(h["deltax"+suffix], fpar);
1059          data[i] = fpar[0]*cm2um;
1060          break;
1061        case 1:
1062 <        fit(h["resy_"+suffix], fpar);
1062 >        fit(h["deltay"+suffix], fpar);
1063          data[i] = fpar[0]*cm2um;
1064          break;
1065        case 2:
1066 <        fit(h["resz_"+suffix], fpar);
1066 >        fit(h["deltaz"+suffix], fpar);
1067          data[i] = fpar[0]*cm2um;
1068          break;
1069        case 3:
1070 <        fit(h["pullx_"+suffix], fpar);
1070 >        fit(h["pullx"+suffix], fpar);
1071          data[i] = fpar[0];
1072          break;
1073        case 4:
1074 <        fit(h["pully_"+suffix], fpar);
1074 >        fit(h["pully"+suffix], fpar);
1075          data[i] = fpar[0];
1076          break;
1077        case 5:
1078 <        fit(h["pullz_"+suffix], fpar);
1078 >        fit(h["pullz"+suffix], fpar);
1079          data[i] = fpar[0];
1080          break;
1081        }
# Line 753 | Line 1141 | void PVStudy::fit(TH1 *&hdist, double fi
1141      fitPars[0] = -999;
1142   }
1143  
1144 < //define this as a plug-in
1145 < DEFINE_FWK_MODULE(PVStudy);
1144 > void PVStudy::SetVarToZero() {
1145 >  
1146 >  // number of reconstructed vertices
1147 >  nrecPV_ = 0;
1148 >  nrecPV1_spl_ = 0;
1149 >  nrecPV2_spl_ = 0;
1150 >  // number of tracks in the vertex
1151 >  fntrk_ = 0;
1152 >  fntrk_spl1_mct_ = 0;
1153 >  fntrk_spl2_mct_ = 0;
1154 >  fntrk_mct_ = 0;
1155 >  //pvtx position (x,y,z) residual and error
1156 >  for(int i = 0; i<3;i++)
1157 >    {
1158 >      fres_[i] = 0;
1159 >      ferror_[i] = 0;
1160 >      fres_spl1_mct_[i] = 0;
1161 >      ferror_spl1_mct_[i] = 0;
1162 >      fres_spl2_mct_[i] = 0;
1163 >      ferror_spl2_mct_[i] = 0;
1164 >      fres_mct_[i] = 0;
1165 >      ferror_mct_[i] = 0;
1166 >    }
1167 > }
1168 >
1169 >

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines