CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MuonTrackValidator.cc
Go to the documentation of this file.
3 
6 
21 
22 #include "TMath.h"
23 #include <TF1.h>
24 
25 using namespace std;
26 using namespace edm;
27 
28 
30 
31 
32  int j=0;
33  for (unsigned int ww=0;ww<associators.size();ww++){
34  for (unsigned int www=0;www<label.size();www++){
35 
36  ibooker.cd();
37  InputTag algo = label[www];
38  string dirName=dirName_;
39  if (algo.process()!="")
40  dirName+=algo.process()+"_";
41  if(algo.label()!="")
42  dirName+=algo.label();
43  if(algo.instance()!="")
44  dirName+=("_"+algo.instance());
45  if (dirName.find("Tracks")<dirName.length()){
46  dirName.replace(dirName.find("Tracks"),6,"Trks");
47  }
48  if (dirName.find("UpdatedAtVtx")<dirName.length()){
49  dirName.replace(dirName.find("UpdatedAtVtx"),12,"UpdAtVtx");
50  }
51  string assoc= associators[ww];
52  if (assoc.find("tpToTkmuTrackAssociation")<assoc.length()){
53  dirName+="_TkAsso";
54  }
55  std::replace(dirName.begin(), dirName.end(), ':', '_');
56  ibooker.setCurrentFolder(dirName.c_str());
57 
58  setUpVectors();
59 
60  ibooker.goUp();
61  string subDirName = dirName + "/simulation";
62  ibooker.setCurrentFolder(subDirName.c_str());
63  h_ptSIM.push_back( ibooker.book1D("ptSIM", "generated p_{t}", 5500, 0, 110 ) );
64  h_etaSIM.push_back( ibooker.book1D("etaSIM", "generated pseudorapidity", 500, -2.5, 2.5 ) );
65  h_tracksSIM.push_back( ibooker.book1D("tracksSIM","number of simulated tracks",200,-0.5,99.5) );
66  h_vertposSIM.push_back( ibooker.book1D("vertposSIM","Transverse position of sim vertices",100,0.,120.) );
67 
68  ibooker.cd();
69  ibooker.setCurrentFolder(dirName.c_str());
70  h_tracks.push_back( ibooker.book1D("tracks","number of reconstructed tracks",200,-0.5,19.5) );
71  h_fakes.push_back( ibooker.book1D("fakes","number of fake reco tracks",20,-0.5,19.5) );
72  h_charge.push_back( ibooker.book1D("charge","charge",3,-1.5,1.5) );
73  h_hits.push_back( ibooker.book1D("hits", "number of hits per track", nintHit,minHit,maxHit ) );
74  h_losthits.push_back( ibooker.book1D("losthits", "number of lost hits per track", nintHit,minHit,maxHit) );
75  h_nchi2.push_back( ibooker.book1D("chi2", "normalized #chi^{2}", 200, 0, 20 ) );
76  h_nchi2_prob.push_back( ibooker.book1D("chi2_prob", "normalized #chi^{2} probability",100,0,1));
77 
79  h_recoeta.push_back( ibooker.book1D("num_reco_eta","N of reco track vs eta",nint,min,max) );
80  h_assoceta.push_back( ibooker.book1D("num_assoc(simToReco)_eta","N of associated tracks (simToReco) vs eta",nint,min,max) );
81  h_assoc2eta.push_back( ibooker.book1D("num_assoc(recoToSim)_eta","N of associated (recoToSim) tracks vs eta",nint,min,max) );
82  h_simuleta.push_back( ibooker.book1D("num_simul_eta","N of simulated tracks vs eta",nint,min,max) );
83  h_recopT.push_back( ibooker.book1D("num_reco_pT","N of reco track vs pT",nintpT,minpT,maxpT) );
84  h_assocpT.push_back( ibooker.book1D("num_assoc(simToReco)_pT","N of associated tracks (simToReco) vs pT",nintpT,minpT,maxpT) );
85  h_assoc2pT.push_back( ibooker.book1D("num_assoc(recoToSim)_pT","N of associated (recoToSim) tracks vs pT",nintpT,minpT,maxpT) );
86  h_simulpT.push_back( ibooker.book1D("num_simul_pT","N of simulated tracks vs pT",nintpT,minpT,maxpT) );
87  //
88  h_recohit.push_back( ibooker.book1D("num_reco_hit","N of reco track vs hit",nintHit,minHit,maxHit) );
89  h_assochit.push_back( ibooker.book1D("num_assoc(simToReco)_hit","N of associated tracks (simToReco) vs hit",nintHit,minHit,maxHit) );
90  h_assoc2hit.push_back( ibooker.book1D("num_assoc(recoToSim)_hit","N of associated (recoToSim) tracks vs hit",nintHit,minHit,maxHit) );
91  h_simulhit.push_back( ibooker.book1D("num_simul_hit","N of simulated tracks vs hit",nintHit,minHit,maxHit) );
92  //
93  h_recophi.push_back( ibooker.book1D("num_reco_phi","N of reco track vs phi",nintPhi,minPhi,maxPhi) );
94  h_assocphi.push_back( ibooker.book1D("num_assoc(simToReco)_phi","N of associated tracks (simToReco) vs phi",nintPhi,minPhi,maxPhi) );
95  h_assoc2phi.push_back( ibooker.book1D("num_assoc(recoToSim)_phi","N of associated (recoToSim) tracks vs phi",nintPhi,minPhi,maxPhi) );
96  h_simulphi.push_back( ibooker.book1D("num_simul_phi","N of simulated tracks vs phi",nintPhi,minPhi,maxPhi) );
97 
98  h_recodxy.push_back( ibooker.book1D("num_reco_dxy","N of reco track vs dxy",nintDxy,minDxy,maxDxy) );
99  h_assocdxy.push_back( ibooker.book1D("num_assoc(simToReco)_dxy","N of associated tracks (simToReco) vs dxy",nintDxy,minDxy,maxDxy) );
100  h_assoc2dxy.push_back( ibooker.book1D("num_assoc(recoToSim)_dxy","N of associated (recoToSim) tracks vs dxy",nintDxy,minDxy,maxDxy) );
101  h_simuldxy.push_back( ibooker.book1D("num_simul_dxy","N of simulated tracks vs dxy",nintDxy,minDxy,maxDxy) );
102 
103  h_recodz.push_back( ibooker.book1D("num_reco_dz","N of reco track vs dz",nintDz,minDz,maxDz) );
104  h_assocdz.push_back( ibooker.book1D("num_assoc(simToReco)_dz","N of associated tracks (simToReco) vs dz",nintDz,minDz,maxDz) );
105  h_assoc2dz.push_back( ibooker.book1D("num_assoc(recoToSim)_dz","N of associated (recoToSim) tracks vs dz",nintDz,minDz,maxDz) );
106  h_simuldz.push_back( ibooker.book1D("num_simul_dz","N of simulated tracks vs dz",nintDz,minDz,maxDz) );
107 
108  h_assocvertpos.push_back( ibooker.book1D("num_assoc(simToReco)_vertpos","N of associated tracks (simToReco) vs transverse vert position",nintVertpos,minVertpos,maxVertpos) );
109  h_simulvertpos.push_back( ibooker.book1D("num_simul_vertpos","N of simulated tracks vs transverse vert position",nintVertpos,minVertpos,maxVertpos) );
110 
111  h_assoczpos.push_back( ibooker.book1D("num_assoc(simToReco)_zpos","N of associated tracks (simToReco) vs z vert position",nintZpos,minZpos,maxZpos) );
112  h_simulzpos.push_back( ibooker.book1D("num_simul_zpos","N of simulated tracks vs z vert position",nintZpos,minZpos,maxZpos) );
113 
114 
116 
117  h_eta.push_back( ibooker.book1D("eta", "pseudorapidity residue", 1000, -0.1, 0.1 ) );
118  h_pt.push_back( ibooker.book1D("pullPt", "pull of p_{t}", 100, -10, 10 ) );
119  h_pullTheta.push_back( ibooker.book1D("pullTheta","pull of #theta parameter",250,-25,25) );
120  h_pullPhi.push_back( ibooker.book1D("pullPhi","pull of #phi parameter",250,-25,25) );
121  h_pullDxy.push_back( ibooker.book1D("pullDxy","pull of dxy parameter",250,-25,25) );
122  h_pullDz.push_back( ibooker.book1D("pullDz","pull of dz parameter",250,-25,25) );
123  h_pullQoverp.push_back( ibooker.book1D("pullQoverp","pull of qoverp parameter",250,-25,25) );
124 
125  if (associators[ww]=="TrackAssociatorByChi2"){
126  h_assochi2.push_back( ibooker.book1D("assocChi2","track association #chi^{2}",1000000,0,100000) );
127  h_assochi2_prob.push_back(ibooker.book1D("assocChi2_prob","probability of association #chi^{2}",100,0,1));
128  } else if (associators[ww]=="TrackAssociatorByHits"){
129  h_assocFraction.push_back( ibooker.book1D("assocFraction","fraction of shared hits",200,0,2) );
130  h_assocSharedHit.push_back(ibooker.book1D("assocSharedHit","number of shared hits",20,0,20));
131  }
132 
133  chi2_vs_nhits.push_back( ibooker.book2D("chi2_vs_nhits","#chi^{2} vs nhits",25,0,25,100,0,10) );
134  h_chi2meanhitsh.push_back( ibooker.bookProfile("chi2mean_vs_nhits","mean #chi^{2} vs nhits",25,0,25,100,0,10) );
135 
136  etares_vs_eta.push_back( ibooker.book2D("etares_vs_eta","etaresidue vs eta",nint,min,max,200,-0.1,0.1) );
137  nrec_vs_nsim.push_back( ibooker.book2D("nrec_vs_nsim","nrec vs nsim",20,-0.5,19.5,20,-0.5,19.5) );
138 
139  chi2_vs_eta.push_back( ibooker.book2D("chi2_vs_eta","chi2_vs_eta",nint,min,max, 200, 0, 20 ));
140  h_chi2meanh.push_back( ibooker.bookProfile("chi2mean","mean #chi^{2} vs #eta",nint,min,max, 200, 0, 20) );
141  chi2_vs_phi.push_back( ibooker.book2D("chi2_vs_phi","#chi^{2} vs #phi",nintPhi,minPhi,maxPhi, 200, 0, 20 ) );
142  h_chi2mean_vs_phi.push_back( ibooker.bookProfile("chi2mean_vs_phi","mean of #chi^{2} vs #phi",nintPhi,minPhi,maxPhi, 200, 0, 20) );
143 
144  nhits_vs_eta.push_back( ibooker.book2D("nhits_vs_eta","nhits vs eta",nint,min,max,nintHit,minHit,maxHit) );
145  nDThits_vs_eta.push_back( ibooker.book2D("nDThits_vs_eta","# DT hits vs eta",nint,min,max,nintHit,minHit,maxHit) );
146  nCSChits_vs_eta.push_back( ibooker.book2D("nCSChits_vs_eta","# CSC hits vs eta",nint,min,max,nintHit,minHit,maxHit) );
147  nRPChits_vs_eta.push_back( ibooker.book2D("nRPChits_vs_eta","# RPC hits vs eta",nint,min,max,nintHit,minHit,maxHit) );
148 
149  h_DThits_eta.push_back( ibooker.bookProfile("DThits_eta","mean # DT hits vs eta",nint,min,max,nintHit,minHit,maxHit) );
150  h_CSChits_eta.push_back( ibooker.bookProfile("CSChits_eta","mean # CSC hits vs eta",nint,min,max,nintHit,minHit,maxHit) );
151  h_RPChits_eta.push_back( ibooker.bookProfile("RPChits_eta","mean # RPC hits vs eta",nint,min,max,nintHit,minHit,maxHit) );
152  h_hits_eta.push_back( ibooker.bookProfile("hits_eta","mean #hits vs eta",nint,min,max,nintHit,minHit,maxHit) );
153  nhits_vs_phi.push_back( ibooker.book2D("nhits_vs_phi","#hits vs #phi",nintPhi,minPhi,maxPhi,nintHit,minHit,maxHit) );
154  h_hits_phi.push_back( ibooker.bookProfile("hits_phi","mean #hits vs #phi",nintPhi,minPhi,maxPhi, nintHit,minHit,maxHit) );
155 
156  nlosthits_vs_eta.push_back( ibooker.book2D("nlosthits_vs_eta","nlosthits vs eta",nint,min,max,nintHit,minHit,maxHit) );
157  h_losthits_eta.push_back( ibooker.bookProfile("losthits_eta","losthits_eta",nint,min,max,nintHit,minHit,maxHit) );
158 
159  ptres_vs_eta.push_back(ibooker.book2D("ptres_vs_eta","ptres_vs_eta",nint,min,max, ptRes_nbin, ptRes_rangeMin, ptRes_rangeMax));
160  ptres_vs_phi.push_back( ibooker.book2D("ptres_vs_phi","p_{t} res vs #phi",nintPhi,minPhi,maxPhi, ptRes_nbin, ptRes_rangeMin, ptRes_rangeMax));
161  ptres_vs_pt.push_back(ibooker.book2D("ptres_vs_pt","ptres_vs_pt",nintpT,minpT,maxpT, ptRes_nbin, ptRes_rangeMin, ptRes_rangeMax));
162 
163  cotThetares_vs_eta.push_back(ibooker.book2D("cotThetares_vs_eta","cotThetares_vs_eta",nint,min,max,cotThetaRes_nbin, cotThetaRes_rangeMin, cotThetaRes_rangeMax));
164  cotThetares_vs_pt.push_back(ibooker.book2D("cotThetares_vs_pt","cotThetares_vs_pt",nintpT,minpT,maxpT, cotThetaRes_nbin, cotThetaRes_rangeMin, cotThetaRes_rangeMax));
165 
166  phires_vs_eta.push_back(ibooker.book2D("phires_vs_eta","phires_vs_eta",nint,min,max, phiRes_nbin, phiRes_rangeMin, phiRes_rangeMax));
167  phires_vs_pt.push_back(ibooker.book2D("phires_vs_pt","phires_vs_pt",nintpT,minpT,maxpT, phiRes_nbin, phiRes_rangeMin, phiRes_rangeMax));
168  phires_vs_phi.push_back(ibooker.book2D("phires_vs_phi","#phi res vs #phi",nintPhi,minPhi,maxPhi,phiRes_nbin, phiRes_rangeMin, phiRes_rangeMax));
169 
170  dxyres_vs_eta.push_back(ibooker.book2D("dxyres_vs_eta","dxyres_vs_eta",nint,min,max,dxyRes_nbin, dxyRes_rangeMin, dxyRes_rangeMax));
171  dxyres_vs_pt.push_back( ibooker.book2D("dxyres_vs_pt","dxyres_vs_pt",nintpT,minpT,maxpT,dxyRes_nbin, dxyRes_rangeMin, dxyRes_rangeMax));
172 
173  dzres_vs_eta.push_back(ibooker.book2D("dzres_vs_eta","dzres_vs_eta",nint,min,max,dzRes_nbin, dzRes_rangeMin, dzRes_rangeMax));
174  dzres_vs_pt.push_back(ibooker.book2D("dzres_vs_pt","dzres_vs_pt",nintpT,minpT,maxpT,dzRes_nbin, dzRes_rangeMin, dzRes_rangeMax));
175 
176  ptmean_vs_eta_phi.push_back(ibooker.bookProfile2D("ptmean_vs_eta_phi","mean p_{t} vs #eta and #phi",nintPhi,minPhi,maxPhi,nint,min,max,1000,0,1000));
177  phimean_vs_eta_phi.push_back(ibooker.bookProfile2D("phimean_vs_eta_phi","mean #phi vs #eta and #phi",nintPhi,minPhi,maxPhi,nint,min,max,nintPhi,minPhi,maxPhi));
178 
179  //pulls of track params vs eta: to be used with fitslicesytool
180  dxypull_vs_eta.push_back(ibooker.book2D("dxypull_vs_eta","dxypull_vs_eta",nint,min,max,100,-10,10));
181  ptpull_vs_eta.push_back(ibooker.book2D("ptpull_vs_eta","ptpull_vs_eta",nint,min,max,100,-10,10));
182  dzpull_vs_eta.push_back(ibooker.book2D("dzpull_vs_eta","dzpull_vs_eta",nint,min,max,100,-10,10));
183  phipull_vs_eta.push_back(ibooker.book2D("phipull_vs_eta","phipull_vs_eta",nint,min,max,100,-10,10));
184  thetapull_vs_eta.push_back(ibooker.book2D("thetapull_vs_eta","thetapull_vs_eta",nint,min,max,100,-10,10));
185 
186  //pulls of track params vs phi
187  ptpull_vs_phi.push_back(ibooker.book2D("ptpull_vs_phi","p_{t} pull vs #phi",nintPhi,minPhi,maxPhi,100,-10,10));
188  phipull_vs_phi.push_back(ibooker.book2D("phipull_vs_phi","#phi pull vs #phi",nintPhi,minPhi,maxPhi,100,-10,10));
189  thetapull_vs_phi.push_back(ibooker.book2D("thetapull_vs_phi","#theta pull vs #phi",nintPhi,minPhi,maxPhi,100,-10,10));
190 
191  nrecHit_vs_nsimHit_sim2rec.push_back( ibooker.book2D("nrecHit_vs_nsimHit_sim2rec","nrecHit vs nsimHit (Sim2RecAssoc)",nintHit,minHit,maxHit, nintHit,minHit,maxHit ));
192  nrecHit_vs_nsimHit_rec2sim.push_back( ibooker.book2D("nrecHit_vs_nsimHit_rec2sim","nrecHit vs nsimHit (Rec2simAssoc)",nintHit,minHit,maxHit, nintHit,minHit,maxHit ));
193 
194  if (MABH) {
195 h_PurityVsQuality.push_back( ibooker.book2D("PurityVsQuality","Purity vs Quality (MABH)",20,0.01,1.01,20,0.01,1.01) );
196 h_assoceta_Quality05.push_back( ibooker.book1D("num_assoc(simToReco)_eta_Q05","N of associated tracks (simToReco) vs eta (Quality>0.5)",nint,min,max) );
197 h_assoceta_Quality075.push_back( ibooker.book1D("num_assoc(simToReco)_eta_Q075","N of associated tracks (simToReco) vs eta (Quality>0.75)",nint,min,max) );
198 h_assocpT_Quality05.push_back( ibooker.book1D("num_assoc(simToReco)_pT_Q05","N of associated tracks (simToReco) vs pT (Quality>0.5)",nintpT,minpT,maxpT) );
199 h_assocpT_Quality075.push_back( ibooker.book1D("num_assoc(simToReco)_pT_Q075","N of associated tracks (simToReco) vs pT (Quality>0.75)",nintpT,minpT,maxpT) );
200 h_assocphi_Quality05.push_back( ibooker.book1D("num_assoc(simToReco)_phi_Q05","N of associated tracks (simToReco) vs phi (Quality>0.5)",nintPhi,minPhi,maxPhi) );
201 h_assocphi_Quality075.push_back( ibooker.book1D("num_assoc(simToReco)_phi_Q075","N of associated tracks (simToReco) vs phi (Quality>0.75)",nintPhi,minPhi,maxPhi) );
202  }
203 
204  if(useLogPt){
205 BinLogX(dzres_vs_pt[j]->getTH2F());
206 BinLogX(dxyres_vs_pt[j]->getTH2F());
207 BinLogX(phires_vs_pt[j]->getTH2F());
208 BinLogX(cotThetares_vs_pt[j]->getTH2F());
209 BinLogX(ptres_vs_pt[j]->getTH2F());
210 BinLogX(h_recopT[j]->getTH1F());
211 BinLogX(h_assocpT[j]->getTH1F());
212 BinLogX(h_assoc2pT[j]->getTH1F());
213 BinLogX(h_simulpT[j]->getTH1F());
214 if (MABH) {
215 BinLogX(h_assocpT_Quality05[j]->getTH1F());
216 BinLogX(h_assocpT_Quality075[j]->getTH1F());
217 }
218  j++;
219  }
220 
221  }
222  }
223  if (UseAssociators) {
225  for (unsigned int w=0;w<associators.size();w++) {
226  setup.get<TrackAssociatorRecord>().get(associators[w],theAssociator);
227  associator.push_back( theAssociator.product() );
228  }
229  }
230 }
231 
233  using namespace reco;
234 
235  edm::LogInfo("MuonTrackValidator") << "\n====================================================" << "\n"
236 << "Analyzing new event" << "\n"
237 << "====================================================\n" << "\n";
238  edm::ESHandle<ParametersDefinerForTP> parametersDefinerTP;
239  setup.get<TrackAssociatorRecord>().get(parametersDefiner,parametersDefinerTP);
240 
241  edm::Handle<TrackingParticleCollection> TPCollectionHeff ;
242  event.getByToken(tp_effic_Token,TPCollectionHeff);
243  const TrackingParticleCollection tPCeff = *(TPCollectionHeff.product());
244 
245  edm::Handle<TrackingParticleCollection> TPCollectionHfake ;
246  event.getByToken(tp_fake_Token,TPCollectionHfake);
247  const TrackingParticleCollection tPCfake = *(TPCollectionHfake.product());
248 
249  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
250  event.getByToken(bsSrc_Token,recoBeamSpotHandle);
251  reco::BeamSpot bs = *recoBeamSpotHandle;
252 
253  int w=0;
254  for (unsigned int ww=0;ww<associators.size();ww++){
255  for (unsigned int www=0;www<label.size();www++){
256  //
257  //get collections from the event
258  //
259  edm::Handle<edm::View<Track> > trackCollection;
260 
261  reco::RecoToSimCollection recSimColl;
262  reco::SimToRecoCollection simRecColl;
263  unsigned int trackCollectionSize = 0;
264 
265  if(!event.getByToken(track_Collection_Token[www], trackCollection)&&ignoremissingtkcollection_) {
266 
267 recSimColl.post_insert();
268 simRecColl.post_insert();
269 
270  }
271 
272  else {
273 
274 trackCollectionSize = trackCollection->size();
275 //associate tracks
276 if(UseAssociators){
277 edm::LogVerbatim("MuonTrackValidator") << "Analyzing "
278 << label[www].process()<<":"
279 << label[www].label()<<":"
280 << label[www].instance()<<" with "
281 << associators[ww].c_str() <<"\n";
282 
283 LogTrace("MuonTrackValidator") << "Calling associateRecoToSim method" << "\n";
284 recSimColl=associator[ww]->associateRecoToSim(trackCollection,
285 TPCollectionHfake,
286 &event,&setup);
287 LogTrace("MuonTrackValidator") << "Calling associateSimToReco method" << "\n";
288 simRecColl=associator[ww]->associateSimToReco(trackCollection,
289 TPCollectionHeff,
290 &event,&setup);
291 }
292 else{
293 edm::LogVerbatim("MuonTrackValidator") << "Analyzing "
294 << label[www].process()<<":"
295 << label[www].label()<<":"
296 << label[www].instance()<<" with "
297 << associatormap.process()<<":"
298 << associatormap.label()<<":"
299 << associatormap.instance()<<"\n";
300 
301 Handle<reco::SimToRecoCollection > simtorecoCollectionH;
302 event.getByToken(simToRecoCollection_Token,simtorecoCollectionH);
303 simRecColl= *(simtorecoCollectionH.product());
304 
305 Handle<reco::RecoToSimCollection > recotosimCollectionH;
306 event.getByToken(recoToSimCollection_Token,recotosimCollectionH);
307 recSimColl= *(recotosimCollectionH.product());
308 }
309 
310  }
311 
312 
313  //
314  //fill simulation histograms
315  //compute number of tracks per eta interval
316  //
317  edm::LogVerbatim("MuonTrackValidator") << "\n# of TrackingParticles: " << tPCeff.size() << "\n";
318  int ats = 0;
319  int st=0;
320  for (TrackingParticleCollection::size_type i=0; i<tPCeff.size(); i++){
321 bool TP_is_matched = false;
322 double quality = 0.;
323 bool Quality05 = false;
324 bool Quality075 = false;
325 
326 TrackingParticleRef tpr(TPCollectionHeff, i);
327 TrackingParticle* tp=const_cast<TrackingParticle*>(tpr.get());
328 TrackingParticle::Vector momentumTP;
329 TrackingParticle::Point vertexTP;
330 double dxySim = 0;
331 double dzSim = 0;
332 
333 //If the TrackingParticle is collison like, get the momentum and vertex at production state
334 if(parametersDefiner=="LhcParametersDefinerForTP")
335 {
336 if(! tpSelector(*tp)) continue;
337 momentumTP = tp->momentum();
338 vertexTP = tp->vertex();
339 //Calcualte the impact parameters w.r.t. PCA
340 TrackingParticle::Vector momentum = parametersDefinerTP->momentum(event,setup,tpr);
341 TrackingParticle::Point vertex = parametersDefinerTP->vertex(event,setup,tpr);
342 dxySim = (-vertex.x()*sin(momentum.phi())+vertex.y()*cos(momentum.phi()));
343 dzSim = vertex.z() - (vertex.x()*momentum.x()+vertex.y()*momentum.y())/sqrt(momentum.perp2()) * momentum.z()/sqrt(momentum.perp2());
344 }
345 //If the TrackingParticle is comics, get the momentum and vertex at PCA
346 if(parametersDefiner=="CosmicParametersDefinerForTP")
347 {
348 if(! cosmictpSelector(tpr,&bs,event,setup)) continue;
349 momentumTP = parametersDefinerTP->momentum(event,setup,tpr);
350 vertexTP = parametersDefinerTP->vertex(event,setup,tpr);
351 dxySim = (-vertexTP.x()*sin(momentumTP.phi())+vertexTP.y()*cos(momentumTP.phi()));
352 dzSim = vertexTP.z() - (vertexTP.x()*momentumTP.x()+vertexTP.y()*momentumTP.y())/sqrt(momentumTP.perp2()) * momentumTP.z()/sqrt(momentumTP.perp2());
353 }
354 edm::LogVerbatim("MuonTrackValidator") <<"--------------------Selected TrackingParticle #"<<tpr.key();
355 st++;
356 
357 h_ptSIM[w]->Fill(sqrt(momentumTP.perp2()));
358 h_etaSIM[w]->Fill(momentumTP.eta());
359 h_vertposSIM[w]->Fill(sqrt(vertexTP.perp2()));
360 
361 std::vector<std::pair<RefToBase<Track>, double> > rt;
362 if(simRecColl.find(tpr) != simRecColl.end()){
363 rt = (std::vector<std::pair<RefToBase<Track>, double> >) simRecColl[tpr];
364 if (rt.size()!=0) {
365 RefToBase<Track> assoc_recoTrack = rt.begin()->first;
366 edm::LogVerbatim("MuonTrackValidator")<<"-----------------------------associated Track #"<<assoc_recoTrack.key();
367 TP_is_matched = true;
368 ats++;
369 quality = rt.begin()->second;
370 edm::LogVerbatim("MuonTrackValidator") << "TrackingParticle #" <<tpr.key()
371 << " with pt=" << sqrt(momentumTP.perp2())
372 << " associated with quality:" << quality <<"\n";
373 if (MABH) {
374 if (quality > 0.75) {
375 Quality075 = true;
376 Quality05 = true;
377 }
378 else if (quality > 0.5) {
379 Quality05 = true;
380 }
381 }
382 }
383 }else{
384 edm::LogVerbatim("MuonTrackValidator")
385 << "TrackingParticle #" << tpr.key()
386 << " with pt,eta,phi: "
387 << sqrt(momentumTP.perp2()) << " , "
388 << momentumTP.eta() << " , "
389 << momentumTP.phi() << " , "
390 << " NOT associated to any reco::Track" << "\n";
391 }
392 
393 for (unsigned int f=0; f<etaintervals[w].size()-1; f++){
394 if (getEta(momentumTP.eta())>etaintervals[w][f]&&
395 getEta(momentumTP.eta())<etaintervals[w][f+1]) {
396 totSIMeta[w][f]++;
397 if (TP_is_matched) {
398 totASSeta[w][f]++;
399 
400 if (MABH) {
401 if (Quality075) {
402 totASSeta_Quality075[w][f]++;
403 totASSeta_Quality05[w][f]++;
404 }
405 else if (Quality05) {
406 totASSeta_Quality05[w][f]++;
407 }
408 }
409 }
410 }
411 } // END for (unsigned int f=0; f<etaintervals[w].size()-1; f++){
412 
413 for (unsigned int f=0; f<phiintervals[w].size()-1; f++){
414 if (momentumTP.phi() > phiintervals[w][f]&&
415 momentumTP.phi() <phiintervals[w][f+1]) {
416 totSIM_phi[w][f]++;
417 if (TP_is_matched) {
418 totASS_phi[w][f]++;
419 
420 if (MABH) {
421 if (Quality075) {
422 totASS_phi_Quality075[w][f]++;
423 totASS_phi_Quality05[w][f]++;
424 }
425 else if (Quality05) {
426 totASS_phi_Quality05[w][f]++;
427 }
428 }
429 }
430 }
431 } // END for (unsigned int f=0; f<phiintervals[w].size()-1; f++){
432 
433 
434 for (unsigned int f=0; f<pTintervals[w].size()-1; f++){
435  if (getPt(sqrt(momentumTP.perp2()))>pTintervals[w][f]&&
436  getPt(sqrt(momentumTP.perp2()))<pTintervals[w][f+1]) {
437  totSIMpT[w][f]++;
438 if (TP_is_matched) {
439 totASSpT[w][f]++;
440 
441 if (MABH) {
442 if (Quality075) {
443 totASSpT_Quality075[w][f]++;
444 totASSpT_Quality05[w][f]++;
445 }
446 else if (Quality05) {
447 totASSpT_Quality05[w][f]++;
448 }
449 }
450 }
451 }
452 } // END for (unsigned int f=0; f<pTintervals[w].size()-1; f++){
453 
454  for (unsigned int f=0; f<dxyintervals[w].size()-1; f++){
455 if (dxySim>dxyintervals[w][f]&&
456 dxySim<dxyintervals[w][f+1]) {
457 totSIM_dxy[w][f]++;
458 if (TP_is_matched) {
459 totASS_dxy[w][f]++;
460 }
461 }
462 } // END for (unsigned int f=0; f<dxyintervals[w].size()-1; f++){
463 
464 for (unsigned int f=0; f<dzintervals[w].size()-1; f++){
465 if (dzSim>dzintervals[w][f]&&
466 dzSim<dzintervals[w][f+1]) {
467 totSIM_dz[w][f]++;
468 if (TP_is_matched) {
469  totASS_dz[w][f]++;
470  }
471  }
472  } // END for (unsigned int f=0; f<dzintervals[w].size()-1; f++){
473 
474 for (unsigned int f=0; f<vertposintervals[w].size()-1; f++){
475 if (sqrt(vertexTP.perp2())>vertposintervals[w][f]&&
476 sqrt(vertexTP.perp2())<vertposintervals[w][f+1]) {
477 totSIM_vertpos[w][f]++;
478 if (TP_is_matched) {
479 totASS_vertpos[w][f]++;
480 }
481 }
482 } // END for (unsigned int f=0; f<vertposintervals[w].size()-1; f++){
483 
484 for (unsigned int f=0; f<zposintervals[w].size()-1; f++){
485 if (vertexTP.z()>zposintervals[w][f]&&
486 vertexTP.z()<zposintervals[w][f+1]) {
487 totSIM_zpos[w][f]++;
488 if (TP_is_matched) {
489  totASS_zpos[w][f]++;
490  }
491  }
492  } // END for (unsigned int f=0; f<zposintervals[w].size()-1; f++){
493 
494 int nSimHits = 0;
495 if (usetracker && usemuon) {
496 nSimHits= tpr.get()->numberOfHits();
497 }
498 else if (!usetracker && usemuon) {
499 nSimHits= tpr.get()->numberOfHits() - tpr.get()->numberOfTrackerHits();
500 }
501 else if (usetracker && !usemuon) {
502 nSimHits=tpr.get()->numberOfTrackerHits();
503 }
504 
505 
506  int tmp = std::min(nSimHits,int(maxHit-1));
507 edm::LogVerbatim("MuonTrackValidator") << "\t N simhits = "<< nSimHits<<"\n";
508 
509 totSIM_hit[w][tmp]++;
510 if (TP_is_matched) totASS_hit[w][tmp]++;
511 
512 if (TP_is_matched)
513 {
514 RefToBase<Track> assoctrack = rt.begin()->first;
515 nrecHit_vs_nsimHit_sim2rec[w]->Fill( assoctrack->numberOfValidHits(),nSimHits);
516 }
517  } // End for (TrackingParticleCollection::size_type i=0; i<tPCeff.size(); i++){
518  if (st!=0) h_tracksSIM[w]->Fill(st);
519 
520 
521  //
522  //fill reconstructed track histograms
523  //
524  edm::LogVerbatim("MuonTrackValidator") << "\n# of reco::Tracks with "
525 << label[www].process()<<":"
526 << label[www].label()<<":"
527 << label[www].instance()
528 << ": " << trackCollectionSize << "\n";
529  int at=0;
530  int rT=0;
531  for(edm::View<Track>::size_type i=0; i<trackCollectionSize; ++i){
532  bool Track_is_matched = false;
533 RefToBase<Track> track(trackCollection, i);
534 rT++;
535 
536 std::vector<std::pair<TrackingParticleRef, double> > tp;
538 
539 // new logic (bidirectional)
540 if (BiDirectional_RecoToSim_association) {
541 edm::LogVerbatim("MuonTrackValidator")<<"----------------------------------------Track #"<< track.key();
542 
543 if(recSimColl.find(track) != recSimColl.end()) {
544 tp = recSimColl[track];
545 if (tp.size() != 0) {
546 tpr = tp.begin()->first;
547 // RtS and StR must associate the same pair !
548 if(simRecColl.find(tpr) != simRecColl.end()) {
549 std::vector<std::pair<RefToBase<Track>, double> > track_checkback = simRecColl[tpr];
550 RefToBase<Track> assoc_track_checkback;
551 assoc_track_checkback = track_checkback.begin()->first;
552 
553 if ( assoc_track_checkback.key() == track.key() ) {
554 edm::LogVerbatim("MuonTrackValidator")<<"------------------associated TrackingParticle #"<<tpr.key();
555 Track_is_matched = true;
556 at++;
557 double Purity = tp.begin()->second;
558 double Quality = track_checkback.begin()->second;
559 edm::LogVerbatim("MuonTrackValidator") << "reco::Track #" << track.key() << " with pt=" << track->pt()
560 << " associated with quality:" << Purity <<"\n";
561 if (MABH) h_PurityVsQuality[w]->Fill(Quality,Purity);
562 }
563 }
564 }
565 }
566 
567 if (!Track_is_matched) edm::LogVerbatim("MuonTrackValidator")
568 << "reco::Track #" << track.key() << " with pt=" << track->pt() << " NOT associated to any TrackingParticle" << "\n";
569 }
570 // old logic (bugged)
571 else {
572 if(recSimColl.find(track) != recSimColl.end()){
573 tp = recSimColl[track];
574 if (tp.size()!=0) {
575 Track_is_matched = true;
576 tpr = tp.begin()->first;
577 at++;
578 edm::LogVerbatim("MuonTrackValidator") << "reco::Track #" << track.key() << " with pt=" << track->pt()
579 << " associated with quality:" << tp.begin()->second <<"\n";
580 }
581 } else {
582 edm::LogVerbatim("MuonTrackValidator") << "reco::Track #" << track.key() << " with pt=" << track->pt()
583 << " NOT associated to any TrackingParticle" << "\n";
584 }
585 }
586 
587 //Compute fake rate vs eta
588 for (unsigned int f=0; f<etaintervals[w].size()-1; f++){
589 if (getEta(track->momentum().eta())>etaintervals[w][f]&&
590 getEta(track->momentum().eta())<etaintervals[w][f+1]) {
591 totRECeta[w][f]++;
592 if (Track_is_matched) {
593 totASS2eta[w][f]++;
594 }
595 }
596 } // End for (unsigned int f=0; f<etaintervals[w].size()-1; f++){
597 
598 for (unsigned int f=0; f<phiintervals[w].size()-1; f++){
599 if (track->momentum().phi()>phiintervals[w][f]&&
600 track->momentum().phi()<phiintervals[w][f+1]) {
601 totREC_phi[w][f]++;
602 if (Track_is_matched) {
603 totASS2_phi[w][f]++;
604 }
605 }
606 } // End for (unsigned int f=0; f<phiintervals[w].size()-1; f++){
607 
608 
609 for (unsigned int f=0; f<pTintervals[w].size()-1; f++){
610 if (getPt(sqrt(track->momentum().perp2()))>pTintervals[w][f]&&
611 getPt(sqrt(track->momentum().perp2()))<pTintervals[w][f+1]) {
612 totRECpT[w][f]++;
613 if (Track_is_matched) {
614 totASS2pT[w][f]++;
615 }
616 }
617 } // End for (unsigned int f=0; f<pTintervals[w].size()-1; f++){
618 
619 for (unsigned int f=0; f<dxyintervals[w].size()-1; f++){
620 if (track->dxy(bs.position())>dxyintervals[w][f]&&
621 track->dxy(bs.position())<dxyintervals[w][f+1]) {
622 totREC_dxy[w][f]++;
623 if (Track_is_matched) {
624 totASS2_dxy[w][f]++;
625 }
626 }
627 } // End for (unsigned int f=0; f<dxyintervals[w].size()-1; f++){
628 
629 for (unsigned int f=0; f<dzintervals[w].size()-1; f++){
630 if (track->dz(bs.position())>dzintervals[w][f]&&
631 track->dz(bs.position())<dzintervals[w][f+1]) {
632 totREC_dz[w][f]++;
633 if (Track_is_matched) {
634 totASS2_dz[w][f]++;
635 }
636 }
637 } // End for (unsigned int f=0; f<dzintervals[w].size()-1; f++){
638 
639 int tmp = std::min((int)track->found(),int(maxHit-1));
640  totREC_hit[w][tmp]++;
641 if (Track_is_matched) totASS2_hit[w][tmp]++;
642 
643 edm::LogVerbatim("MuonTrackValidator") << "\t N valid rechits = "<< (int)track->found() <<"\n";
644 
645 //Fill other histos
646  try{
647 if (!Track_is_matched) continue;
648 
649 if (associators[ww]=="TrackAssociatorByChi2"){
650 //association chi2
651 double assocChi2 = -tp.begin()->second;//in association map is stored -chi2
652 h_assochi2[www]->Fill(assocChi2);
653 h_assochi2_prob[www]->Fill(TMath::Prob((assocChi2)*5,5));
654 }
655 else if (associators[ww]=="TrackAssociatorByHits"){
656 double fraction = tp.begin()->second;
657 h_assocFraction[www]->Fill(fraction);
658 h_assocSharedHit[www]->Fill(fraction*track->numberOfValidHits());
659 }
660 
661 //nchi2 and hits global distributions
662 h_nchi2[w]->Fill(track->normalizedChi2());
663 h_nchi2_prob[w]->Fill(TMath::Prob(track->chi2(),(int)track->ndof()));
664 h_hits[w]->Fill(track->numberOfValidHits());
665 h_losthits[w]->Fill(track->numberOfLostHits());
666 chi2_vs_nhits[w]->Fill(track->numberOfValidHits(),track->normalizedChi2());
667 h_charge[w]->Fill( track->charge() );
668 
669 //Get tracking particle parameters at point of closest approach to the beamline
670 TrackingParticle::Vector momentumTP = parametersDefinerTP->momentum(event,setup,tpr) ;
671 TrackingParticle::Point vertexTP = parametersDefinerTP->vertex(event,setup,tpr);
672 double ptSim = sqrt(momentumTP.perp2());
673 double qoverpSim = tpr->charge()/sqrt(momentumTP.x()*momentumTP.x()+momentumTP.y()*momentumTP.y()+momentumTP.z()*momentumTP.z());
674 double thetaSim = momentumTP.theta();
675 double lambdaSim = M_PI/2-momentumTP.theta();
676 double phiSim = momentumTP.phi();
677 double dxySim = (-vertexTP.x()*sin(momentumTP.phi())+vertexTP.y()*cos(momentumTP.phi()));
678 double dzSim = vertexTP.z() - (vertexTP.x()*momentumTP.x()+vertexTP.y()*momentumTP.y())/sqrt(momentumTP.perp2()) * momentumTP.z()/sqrt(momentumTP.perp2());
679 
680 // removed unused variable, left this in case it has side effects
681 track->parameters();
682 
683 double qoverpRec(0);
684 double qoverpErrorRec(0);
685 double ptRec(0);
686 double ptErrorRec(0);
687 double lambdaRec(0);
688 double lambdaErrorRec(0);
689 double phiRec(0);
690 double phiErrorRec(0);
691 
692 
693 //loop to decide whether to take gsfTrack (utilisation of mode-function) or common track
694 const GsfTrack* gsfTrack(0);
695 if(useGsf){
696 gsfTrack = dynamic_cast<const GsfTrack*>(&(*track));
697 if (gsfTrack==0) edm::LogInfo("MuonTrackValidator") << "Trying to access mode for a non-GsfTrack";
698 }
699 
700 if (gsfTrack) {
701 // get values from mode
702 getRecoMomentum(*gsfTrack, ptRec, ptErrorRec, qoverpRec, qoverpErrorRec,
703 lambdaRec,lambdaErrorRec, phiRec, phiErrorRec);
704 }
705 
706 else {
707 // get values from track (without mode)
708 getRecoMomentum(*track, ptRec, ptErrorRec, qoverpRec, qoverpErrorRec,
709 lambdaRec,lambdaErrorRec, phiRec, phiErrorRec);
710 }
711 
712 double thetaRec = track->theta();
713 double ptError = ptErrorRec;
714 double ptres = ptRec - ptSim;
715 double etares = track->eta()-momentumTP.Eta();
716 double dxyRec = track->dxy(bs.position());
717 double dzRec = track->dz(bs.position());
718 // eta residue; pt, k, theta, phi, dxy, dz pulls
719 double qoverpPull=(qoverpRec-qoverpSim)/qoverpErrorRec;
720 double thetaPull=(lambdaRec-lambdaSim)/lambdaErrorRec;
721 double phiDiff = phiRec - phiSim;
722 if (abs(phiDiff) > M_PI) {
723 if (phiDiff >0.) phiDiff = phiDiff - 2.*M_PI;
724  else phiDiff = phiDiff + 2.*M_PI;
725 }
726 double phiPull=phiDiff/phiErrorRec;
727 double dxyPull=(dxyRec-dxySim)/track->dxyError();
728 double dzPull=(dzRec-dzSim)/track->dzError();
729 
730 double contrib_Qoverp = ((qoverpRec-qoverpSim)/qoverpErrorRec)*
731 ((qoverpRec-qoverpSim)/qoverpErrorRec)/5;
732 double contrib_dxy = ((dxyRec-dxySim)/track->dxyError())*((dxyRec-dxySim)/track->dxyError())/5;
733 double contrib_dz = ((dzRec-dzSim)/track->dzError())*((dzRec-dzSim)/track->dzError())/5;
734 double contrib_theta = ((lambdaRec-lambdaSim)/lambdaErrorRec)*
735 ((lambdaRec-lambdaSim)/lambdaErrorRec)/5;
736 double contrib_phi = (phiDiff/phiErrorRec)*(phiDiff/phiErrorRec)/5;
737 
738 LogTrace("MuonTrackValidator") << "assocChi2=" << tp.begin()->second << "\n"
739 << "" << "\n"
740 << "ptREC=" << ptRec << "\n"
741 << "etaREC=" << track->eta() << "\n"
742 << "qoverpREC=" << qoverpRec << "\n"
743 << "dxyREC=" << dxyRec << "\n"
744 << "dzREC=" << dzRec << "\n"
745 << "thetaREC=" << track->theta() << "\n"
746 << "phiREC=" << phiRec << "\n"
747 << "" << "\n"
748 << "qoverpError()=" << qoverpErrorRec << "\n"
749 << "dxyError()=" << track->dxyError() << "\n"
750 << "dzError()=" << track->dzError() << "\n"
751 << "thetaError()=" << lambdaErrorRec << "\n"
752 << "phiError()=" << phiErrorRec << "\n"
753 << "" << "\n"
754 << "ptSIM=" << ptSim << "\n"
755 << "etaSIM=" << momentumTP.Eta() << "\n"
756 << "qoverpSIM=" << qoverpSim << "\n"
757 << "dxySIM=" << dxySim << "\n"
758 << "dzSIM=" << dzSim << "\n"
759 << "thetaSIM=" << M_PI/2-lambdaSim << "\n"
760 << "phiSIM=" << phiSim << "\n"
761 << "" << "\n"
762 << "contrib_Qoverp=" << contrib_Qoverp << "\n"
763 << "contrib_dxy=" << contrib_dxy << "\n"
764 << "contrib_dz=" << contrib_dz << "\n"
765 << "contrib_theta=" << contrib_theta << "\n"
766 << "contrib_phi=" << contrib_phi << "\n"
767 << "" << "\n"
768 <<"chi2PULL="<<contrib_Qoverp+contrib_dxy+contrib_dz+contrib_theta+contrib_phi<<"\n";
769 
770 h_pullQoverp[w]->Fill(qoverpPull);
771 h_pullTheta[w]->Fill(thetaPull);
772 h_pullPhi[w]->Fill(phiPull);
773 h_pullDxy[w]->Fill(dxyPull);
774 h_pullDz[w]->Fill(dzPull);
775 
776 
777 h_pt[w]->Fill(ptres/ptError);
778 h_eta[w]->Fill(etares);
779 etares_vs_eta[w]->Fill(getEta(track->eta()),etares);
780 
781 
782 //chi2 and #hit vs eta: fill 2D histos
783 chi2_vs_eta[w]->Fill(getEta(track->eta()),track->normalizedChi2());
784 nhits_vs_eta[w]->Fill(getEta(track->eta()),track->numberOfValidHits());
785 nDThits_vs_eta[w]->Fill(getEta(track->eta()),track->hitPattern().numberOfValidMuonDTHits());
786 nCSChits_vs_eta[w]->Fill(getEta(track->eta()),track->hitPattern().numberOfValidMuonCSCHits());
787 nRPChits_vs_eta[w]->Fill(getEta(track->eta()),track->hitPattern().numberOfValidMuonRPCHits());
788 
789 nlosthits_vs_eta[w]->Fill(getEta(track->eta()),track->numberOfLostHits());
790 
791 //resolution of track params: fill 2D histos
792 dxyres_vs_eta[w]->Fill(getEta(track->eta()),dxyRec-dxySim);
793 ptres_vs_eta[w]->Fill(getEta(track->eta()),(ptRec-ptSim)/ptRec);
794 dzres_vs_eta[w]->Fill(getEta(track->eta()),dzRec-dzSim);
795 phires_vs_eta[w]->Fill(getEta(track->eta()),phiDiff);
796 cotThetares_vs_eta[w]->Fill(getEta(track->eta()), cos(thetaRec)/sin(thetaRec) - cos(thetaSim)/sin(thetaSim));
797 
798 //same as before but vs pT
799 dxyres_vs_pt[w]->Fill(getPt(ptRec),dxyRec-dxySim);
800 ptres_vs_pt[w]->Fill(getPt(ptRec),(ptRec-ptSim)/ptRec);
801 dzres_vs_pt[w]->Fill(getPt(ptRec),dzRec-dzSim);
802 phires_vs_pt[w]->Fill(getPt(ptRec),phiDiff);
803  cotThetares_vs_pt[w]->Fill(getPt(ptRec), cos(thetaRec)/sin(thetaRec) - cos(thetaSim)/sin(thetaSim));
804 
805 //pulls of track params vs eta: fill 2D histos
806 dxypull_vs_eta[w]->Fill(getEta(track->eta()),dxyPull);
807 ptpull_vs_eta[w]->Fill(getEta(track->eta()),ptres/ptError);
808 dzpull_vs_eta[w]->Fill(getEta(track->eta()),dzPull);
809 phipull_vs_eta[w]->Fill(getEta(track->eta()),phiPull);
810 thetapull_vs_eta[w]->Fill(getEta(track->eta()),thetaPull);
811 
812 //plots vs phi
813 nhits_vs_phi[w]->Fill(phiRec,track->numberOfValidHits());
814 chi2_vs_phi[w]->Fill(phiRec,track->normalizedChi2());
815 ptmean_vs_eta_phi[w]->Fill(phiRec,getEta(track->eta()),ptRec);
816 phimean_vs_eta_phi[w]->Fill(phiRec,getEta(track->eta()),phiRec);
817 ptres_vs_phi[w]->Fill(phiRec,(ptRec-ptSim)/ptRec);
818 phires_vs_phi[w]->Fill(phiRec,phiDiff);
819 ptpull_vs_phi[w]->Fill(phiRec,ptres/ptError);
820 phipull_vs_phi[w]->Fill(phiRec,phiPull);
821 thetapull_vs_phi[w]->Fill(phiRec,thetaPull);
822 
823 int nSimHits = 0;
824 if (usetracker && usemuon) {
825 nSimHits= tpr.get()->numberOfHits();
826 }
827 else if (!usetracker && usemuon) {
828 nSimHits= tpr.get()->numberOfHits() - tpr.get()->numberOfTrackerHits();
829 }
830 else if (usetracker && !usemuon) {
831 nSimHits=tpr.get()->numberOfTrackerHits();
832 }
833 
834 nrecHit_vs_nsimHit_rec2sim[w]->Fill(track->numberOfValidHits(), nSimHits);
835 
836 } // End of try{
837 catch (cms::Exception e){
838 LogTrace("MuonTrackValidator") << "exception found: " << e.what() << "\n";
839 }
840  } // End of for(View<Track>::size_type i=0; i<trackCollectionSize; ++i){
841  if (at!=0) h_tracks[w]->Fill(at);
842  h_fakes[w]->Fill(rT-at);
843  edm::LogVerbatim("MuonTrackValidator") << "Total Simulated: " << st << "\n"
844 << "Total Associated (simToReco): " << ats << "\n"
845 << "Total Reconstructed: " << rT << "\n"
846 << "Total Associated (recoToSim): " << at << "\n"
847 << "Total Fakes: " << rT-at << "\n";
848  nrec_vs_nsim[w]->Fill(rT,st);
849  w++;
850  } // End of for (unsigned int www=0;www<label.size();www++){
851  } //END of for (unsigned int ww=0;ww<associators.size();ww++){
852 }
853 
855 
856  int w=0;
857  for (unsigned int ww=0;ww<associators.size();ww++){
858  for (unsigned int www=0;www<label.size();www++){
859 
860  //chi2 and #hit vs eta: get mean from 2D histos
861  doProfileX(chi2_vs_eta[w],h_chi2meanh[w]);
862  doProfileX(nhits_vs_eta[w],h_hits_eta[w]);
863  doProfileX(nDThits_vs_eta[w],h_DThits_eta[w]);
864  doProfileX(nCSChits_vs_eta[w],h_CSChits_eta[w]);
865  doProfileX(nRPChits_vs_eta[w],h_RPChits_eta[w]);
866 
867  doProfileX(nlosthits_vs_eta[w],h_losthits_eta[w]);
868  //vs phi
869  doProfileX(chi2_vs_nhits[w],h_chi2meanhitsh[w]);
870  doProfileX(chi2_vs_phi[w],h_chi2mean_vs_phi[w]);
871  doProfileX(nhits_vs_phi[w],h_hits_phi[w]);
872 
873  fillPlotFromVector(h_recoeta[w],totRECeta[w]);
874  fillPlotFromVector(h_simuleta[w],totSIMeta[w]);
875  fillPlotFromVector(h_assoceta[w],totASSeta[w]);
876  fillPlotFromVector(h_assoc2eta[w],totASS2eta[w]);
877 
878  fillPlotFromVector(h_recopT[w],totRECpT[w]);
879  fillPlotFromVector(h_simulpT[w],totSIMpT[w]);
880  fillPlotFromVector(h_assocpT[w],totASSpT[w]);
881  fillPlotFromVector(h_assoc2pT[w],totASS2pT[w]);
882 
883  fillPlotFromVector(h_recohit[w],totREC_hit[w]);
884  fillPlotFromVector(h_simulhit[w],totSIM_hit[w]);
885  fillPlotFromVector(h_assochit[w],totASS_hit[w]);
886  fillPlotFromVector(h_assoc2hit[w],totASS2_hit[w]);
887 
888  fillPlotFromVector(h_recophi[w],totREC_phi[w]);
889  fillPlotFromVector(h_simulphi[w],totSIM_phi[w]);
890  fillPlotFromVector(h_assocphi[w],totASS_phi[w]);
891  fillPlotFromVector(h_assoc2phi[w],totASS2_phi[w]);
892 
893  fillPlotFromVector(h_recodxy[w],totREC_dxy[w]);
894  fillPlotFromVector(h_simuldxy[w],totSIM_dxy[w]);
895  fillPlotFromVector(h_assocdxy[w],totASS_dxy[w]);
896  fillPlotFromVector(h_assoc2dxy[w],totASS2_dxy[w]);
897 
898  fillPlotFromVector(h_recodz[w],totREC_dz[w]);
899  fillPlotFromVector(h_simuldz[w],totSIM_dz[w]);
900  fillPlotFromVector(h_assocdz[w],totASS_dz[w]);
901  fillPlotFromVector(h_assoc2dz[w],totASS2_dz[w]);
902 
903  fillPlotFromVector(h_simulvertpos[w],totSIM_vertpos[w]);
904  fillPlotFromVector(h_assocvertpos[w],totASS_vertpos[w]);
905 
906  fillPlotFromVector(h_simulzpos[w],totSIM_zpos[w]);
907  fillPlotFromVector(h_assoczpos[w],totASS_zpos[w]);
908 
909  if (MABH) {
910 fillPlotFromVector(h_assoceta_Quality05[w] ,totASSeta_Quality05[w]);
911 fillPlotFromVector(h_assoceta_Quality075[w],totASSeta_Quality075[w]);
912 fillPlotFromVector(h_assocpT_Quality05[w] ,totASSpT_Quality05[w]);
913 fillPlotFromVector(h_assocpT_Quality075[w],totASSpT_Quality075[w]);
914 fillPlotFromVector(h_assocphi_Quality05[w] ,totASS_phi_Quality05[w]);
915 fillPlotFromVector(h_assocphi_Quality075[w],totASS_phi_Quality075[w]);
916  }
917 
918  w++;
919  }
920  }
921 
922  if ( out.size() != 0 && dbe_ ) dbe_->save(out);
923 }
924 
925 
926 void
927 MuonTrackValidator::getRecoMomentum (const reco::Track& track, double& pt, double& ptError,
928 double& qoverp, double& qoverpError, double& lambda,double& lambdaError, double& phi, double& phiError ) const {
929  pt = track.pt();
930  ptError = track.ptError();
931  qoverp = track.qoverp();
932  qoverpError = track.qoverpError();
933  lambda = track.lambda();
934  lambdaError = track.lambdaError();
935  phi = track.phi();
936  phiError = track.phiError();
937 
938 }
939 
940 void
941 MuonTrackValidator::getRecoMomentum (const reco::GsfTrack& gsfTrack, double& pt, double& ptError,
942 double& qoverp, double& qoverpError, double& lambda,double& lambdaError, double& phi, double& phiError ) const {
943 
944  pt = gsfTrack.ptMode();
945  ptError = gsfTrack.ptModeError();
946  qoverp = gsfTrack.qoverpMode();
947  qoverpError = gsfTrack.qoverpModeError();
948  lambda = gsfTrack.lambdaMode();
949  lambdaError = gsfTrack.lambdaModeError();
950  phi = gsfTrack.phiMode();
951  phiError = gsfTrack.phiModeError();
952 
953 }
double qoverp() const
q/p
Definition: TrackBase.h:113
virtual char const * what() const
Definition: Exception.cc:141
double phiModeError() const
error on phi from mode
Definition: GsfTrack.h:94
int i
Definition: DBlmapReader.cc:9
const Vector & momentum() const
track momentum vector
Definition: TrackBase.h:148
const double w
Definition: UKUtility.cc:23
std::vector< TrackingParticle > TrackingParticleCollection
double lambdaMode() const
Lambda angle from mode.
Definition: GsfTrack.h:45
const_iterator end() const
last iterator over the map (read only)
double normalizedChi2() const
chi-squared divided by n.d.o.f. (or chi-squared * 1e6 if n.d.o.f. is zero)
Definition: TrackBase.h:109
MonitorElement * bookProfile(Args &&...args)
Definition: DQMStore.h:155
tuple maxDxy
Definition: gather_cfg.py:52
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
void cd(void)
Definition: DQMStore.cc:266
double theta() const
polar angle
Definition: TrackBase.h:115
double dxyError() const
error on dxy
Definition: TrackBase.h:207
Point vertex() const
Parent vertex position.
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
const_iterator find(const key_type &k) const
find element with specified reference key
double phi() const
azimuthal angle of momentum vector
Definition: TrackBase.h:137
unsigned short numberOfLostHits() const
number of cases where track crossed a layer without getting a hit.
Definition: TrackBase.h:232
void getRecoMomentum(const reco::Track &track, double &pt, double &ptError, double &qoverp, double &qoverpError, double &lambda, double &lambdaError, double &phi, double &phiError) const
retrieval of reconstructed momentum components from reco::Track (== mean values for GSF) ...
uint16_t size_type
int numberOfValidMuonCSCHits() const
Definition: HitPattern.h:637
double qoverpMode() const
q/p from mode
Definition: GsfTrack.h:41
int numberOfValidMuonRPCHits() const
Definition: HitPattern.h:641
double ptModeError() const
error on Pt (set to 1000 TeV if charge==0 for safety) from mode
Definition: GsfTrack.h:81
math::XYZPointD Point
point in the space
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:139
double chi2() const
chi-squared of the fit
Definition: TrackBase.h:105
ParameterVector parameters() const
Track parameters with one-to-one correspondence to the covariance matrix.
Definition: TrackBase.h:176
MonitorElement * bookProfile2D(Args &&...args)
Definition: DQMStore.h:161
void post_insert()
post insert action
double ndof() const
number of degrees of freedom of the fit
Definition: TrackBase.h:107
T sqrt(T t)
Definition: SSEVec.h:48
double pt() const
track transverse momentum
Definition: TrackBase.h:129
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
double ptError() const
error on Pt (set to 1000 TeV if charge==0 for safety)
Definition: TrackBase.h:192
double phiError() const
error on phi
Definition: TrackBase.h:205
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:113
unsigned int size_type
Definition: View.h:85
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int j
Definition: DBlmapReader.cc:9
double lambda() const
Lambda angle.
Definition: TrackBase.h:117
double f[11][100]
TH1F * getTH1F(std::string name, std::string process, std::string rootfolder, DQMStore *dbe_, bool verb, bool clone)
void analyze(const edm::Event &, const edm::EventSetup &)
Method called before the event loop.
unsigned short numberOfValidHits() const
number of valid hits found
Definition: TrackBase.h:230
T min(T a, T b)
Definition: MathUtil.h:58
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
Definition: TrackBase.h:221
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
size_t key() const
Definition: RefToBase.h:228
#define LogTrace(id)
#define M_PI
DQMStore * dbe_
int nint(float a)
Return the nearest integer - analogous to the FORTRAN intrinsic NINT.
Definition: nint.h:8
double qoverpError() const
error on signed transverse curvature
Definition: TrackBase.h:190
double dz() const
dz parameter (= dsz/cos(lambda)). This is the track z0 w.r.t (0,0,0) only if the refPoint is close to...
Definition: TrackBase.h:125
double dzError() const
error on dz
Definition: TrackBase.h:213
tuple out
Definition: dbtoconf.py:99
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:274
void goUp(void)
Definition: DQMStore.cc:278
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:131
double qoverpModeError() const
error on signed transverse curvature from mode
Definition: GsfTrack.h:79
const T & get() const
Definition: EventSetup.h:55
key_type key() const
Accessor for product key.
Definition: Ref.h:266
T const * product() const
Definition: ESHandle.h:62
T const * product() const
Definition: Handle.h:81
std::string const & label() const
Definition: InputTag.h:42
std::string const & process() const
Definition: InputTag.h:46
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
double lambdaError() const
error on lambda
Definition: TrackBase.h:201
void save(const std::string &filename, const std::string &path="", const std::string &pattern="", const std::string &rewrite="", const uint32_t run=0, const uint32_t lumi=0, SaveReferenceTag ref=SaveWithReference, int minStatus=dqm::qstatus::STATUS_OK, const std::string &fileupdate="RECREATE", const bool resetMEsAfterWriting=false)
Definition: DQMStore.cc:2540
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &)
unsigned short found() const
Number of valid hits on track.
Definition: Track.h:100
int numberOfValidMuonDTHits() const
Definition: HitPattern.h:633
Vector momentum() const
spatial momentum vector
TH2F * getTH2F(std::string name, std::string process, std::string rootfolder, DQMStore *dbe_, bool verb, bool clone)
double phiMode() const
azimuthal angle of momentum vector from mode
Definition: GsfTrack.h:57
Monte Carlo truth information used for tracking validation.
int charge() const
track electric charge
Definition: TrackBase.h:111
double lambdaModeError() const
error on lambda from mode
Definition: GsfTrack.h:90
math::XYZVectorD Vector
point in the space
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:242
double dxy() const
dxy parameter. (This is the transverse impact parameter w.r.t. to (0,0,0) ONLY if refPoint is close t...
Definition: TrackBase.h:119
double ptMode() const
track transverse momentum from mode
Definition: GsfTrack.h:49
std::string const & instance() const
Definition: InputTag.h:43
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
Definition: Run.h:41
list at
Definition: asciidump.py:428
void endRun(edm::Run const &, edm::EventSetup const &)
Method called at the end of the event loop.
Definition: DDAxes.h:10