CMS 3D CMS Logo

PrimaryVertexValidation.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Alignment/OfflineValidation
4 // Class: PrimaryVertexValidation
5 //
13 //
14 // Original Author: Marco Musich
15 // Created: Tue Mar 02 10:39:34 CDT 2010
16 //
17 
18 // system include files
19 #include <memory>
20 #include <vector>
21 
22 // user include files
24 
25 // ROOT includes
26 #include "TH1F.h"
27 #include "TH2F.h"
28 #include "TF1.h"
29 #include "TVector3.h"
30 #include "TFile.h"
31 #include "TMath.h"
32 #include "TROOT.h"
33 #include "TChain.h"
34 #include "TNtuple.h"
35 #include "TMatrixD.h"
36 #include "TVectorD.h"
37 
38 // CMSSW includes
62 
64 
65 // Constructor
67  storeNtuple_(iConfig.getParameter<bool>("storeNtuple")),
68  lightNtupleSwitch_(iConfig.getParameter<bool>("isLightNtuple")),
69  useTracksFromRecoVtx_(iConfig.getParameter<bool>("useTracksFromRecoVtx")),
70  vertexZMax_(iConfig.getUntrackedParameter<double>("vertexZMax",99.)),
71  askFirstLayerHit_(iConfig.getParameter<bool>("askFirstLayerHit")),
72  doBPix_(iConfig.getUntrackedParameter<bool>("doBPix",true)),
73  doFPix_(iConfig.getUntrackedParameter<bool>("doFPix",true)),
74  ptOfProbe_(iConfig.getUntrackedParameter<double>("probePt",0.)),
75  etaOfProbe_(iConfig.getUntrackedParameter<double>("probeEta",2.4)),
76  nBins_(iConfig.getUntrackedParameter<int>("numberOfBins",24)),
77  debug_(iConfig.getParameter<bool>("Debug")),
78  runControl_(iConfig.getUntrackedParameter<bool>("runControl",false))
79 {
80 
81  // now do what ever initialization is needed
82  // initialize phase space boundaries
83 
84  usesResource(TFileService::kSharedResource);
85 
86  std::vector<unsigned int> defaultRuns;
87  defaultRuns.push_back(0);
88  runControlNumbers_ = iConfig.getUntrackedParameter<std::vector<unsigned int> >("runControlNumber",defaultRuns);
89 
90  phiSect_ = (2*TMath::Pi())/nBins_;
92 
93  edm::InputTag TrackCollectionTag_ = iConfig.getParameter<edm::InputTag>("TrackCollectionTag");
94  theTrackCollectionToken = consumes<reco::TrackCollection>(TrackCollectionTag_);
95 
96  edm::InputTag VertexCollectionTag_ = iConfig.getParameter<edm::InputTag>("VertexCollectionTag");
97  theVertexCollectionToken = consumes<reco::VertexCollection>(VertexCollectionTag_);
98 
99  edm::InputTag BeamspotTag_ = edm::InputTag("offlineBeamSpot");
100  theBeamspotToken = consumes<reco::BeamSpot>(BeamspotTag_);
101 
102  // select and configure the track filter
103  theTrackFilter_= new TrackFilterForPVFinding(iConfig.getParameter<edm::ParameterSet>("TkFilterParameters") );
104  // select and configure the track clusterizer
105  std::string clusteringAlgorithm=iConfig.getParameter<edm::ParameterSet>("TkClusParameters").getParameter<std::string>("algorithm");
106  if (clusteringAlgorithm=="gap"){
107  theTrackClusterizer_ = new GapClusterizerInZ(iConfig.getParameter<edm::ParameterSet>("TkClusParameters").getParameter<edm::ParameterSet>("TkGapClusParameters"));
108  }else if(clusteringAlgorithm=="DA"){
109  theTrackClusterizer_ = new DAClusterizerInZ(iConfig.getParameter<edm::ParameterSet>("TkClusParameters").getParameter<edm::ParameterSet>("TkDAClusParameters"));
110  // provide the vectorized version of the clusterizer, if supported by the build
111  } else if(clusteringAlgorithm=="DA_vect") {
112  theTrackClusterizer_ = new DAClusterizerInZ_vect(iConfig.getParameter<edm::ParameterSet>("TkClusParameters").getParameter<edm::ParameterSet>("TkDAClusParameters"));
113  }else{
114  throw VertexException("PrimaryVertexProducerAlgorithm: unknown clustering algorithm: " + clusteringAlgorithm);
115  }
116 }
117 
118 // Destructor
120 {
121  // do anything here that needs to be done at desctruction time
122  // (e.g. close files, deallocate resources etc.)
123 }
124 
125 
126 //
127 // member functions
128 //
129 
130 // ------------ method called to for each event ------------
131 void
133 {
134 
135  using namespace std;
136  using namespace reco;
137  using namespace IPTools;
138 
139  if(nBins_!=24){
140  edm::LogInfo("PrimaryVertexValidation")<<"Using: "<<nBins_<<" bins plots";
141  }
142 
143  bool passesRunControl = false;
144 
145  if(runControl_){
146  for(unsigned int j=0;j<runControlNumbers_.size();j++){
147  if(iEvent.eventAuxiliary().run() == runControlNumbers_[j]){
148  if (debug_){
149  edm::LogInfo("PrimaryVertexValidation")<<" run number: "<<iEvent.eventAuxiliary().run()<<" keeping run:"<<runControlNumbers_[j];
150  }
151  passesRunControl = true;
152  break;
153  }
154  }
155  if (!passesRunControl) return;
156  }
157 
158  Nevt_++;
159 
160  //=======================================================
161  // Initialize Root-tuple variables
162  //=======================================================
163 
164  SetVarToZero();
165 
166  //=======================================================
167  // Retrieve the Magnetic Field information
168  //=======================================================
169 
170  edm::ESHandle<MagneticField> theMGField;
171  iSetup.get<IdealMagneticFieldRecord>().get( theMGField );
172 
173  //=======================================================
174  // Retrieve the Tracking Geometry information
175  //=======================================================
176 
177  edm::ESHandle<GlobalTrackingGeometry> theTrackingGeometry;
178  iSetup.get<GlobalTrackingGeometryRecord>().get( theTrackingGeometry );
179 
180  //=======================================================
181  // Retrieve geometry information
182  //=======================================================
183 
184  edm::LogInfo("read tracker geometry...");
186  iSetup.get<TrackerDigiGeometryRecord>().get( pDD );
187  edm::LogInfo("tracker geometry read")<<"There are: "<< pDD->dets().size() <<" detectors";
188 
189  // switch on the phase1
190  if( (pDD->isThere(GeomDetEnumerators::P1PXB)) ||
192  isPhase1_ = true;
193  edm::LogInfo("PrimaryVertexValidation")<<" pixel phase1 setup ";
194  } else {
195  isPhase1_ = false;
196  edm::LogInfo("PrimaryVertexValidation")<<" pixel phase0 setup ";
197  }
198 
199  if(isPhase1_){
201  } else {
203  }
204 
205  if(h_etaMax->GetEntries()==0.){
206  h_etaMax->SetBinContent(1,etaOfProbe_);
207  h_nbins->SetBinContent(1,nBins_);
208  }
209 
210  //=======================================================
211  // Retrieve the Transient Track Builder information
212  //=======================================================
213 
215  iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder",theB_);
216  double fBfield_=((*theB_).field()->inTesla(GlobalPoint(0.,0.,0.))).z();
217 
218  //=======================================================
219  // Retrieve the Track information
220  //=======================================================
221 
222  edm::Handle<TrackCollection> trackCollectionHandle;
223  iEvent.getByToken(theTrackCollectionToken, trackCollectionHandle);
224 
225  //=======================================================
226  // Retrieve offline vartex information (only for reco)
227  //=======================================================
228 
229  //edm::Handle<VertexCollection> vertices;
231 
232  try {
233  iEvent.getByToken(theVertexCollectionToken, vertices);
234  } catch ( cms::Exception& er ) {
235  LogTrace("PrimaryVertexValidation")<<"caught std::exception "<<er.what()<<std::endl;
236  }
237 
238  std::vector<Vertex> vsorted = *(vertices);
239  // sort the vertices by number of tracks in descending order
240  // use chi2 as tiebreaker
241  std::sort( vsorted.begin(), vsorted.end(), PrimaryVertexValidation::vtxSort );
242 
243  // skip events with no PV, this should not happen
244  if( vsorted.size() == 0) return;
245  // skip events failing vertex cut
246  if( fabs(vsorted[0].z()) > vertexZMax_ ) return;
247 
248  if ( vsorted[0].isValid() ) {
249  xOfflineVertex_ = (vsorted)[0].x();
250  yOfflineVertex_ = (vsorted)[0].y();
251  zOfflineVertex_ = (vsorted)[0].z();
252 
253  xErrOfflineVertex_ = (vsorted)[0].xError();
254  yErrOfflineVertex_ = (vsorted)[0].yError();
255  zErrOfflineVertex_ = (vsorted)[0].zError();
256  }
257 
264 
265  unsigned int vertexCollectionSize = vsorted.size();
266  int nvvertex = 0;
267 
268  for (unsigned int i=0; i<vertexCollectionSize; i++) {
269  const Vertex& vertex = vsorted.at(i);
270  if (vertex.isValid()) nvvertex++;
271  }
272 
273  nOfflineVertices_ = nvvertex;
274  h_nOfflineVertices->Fill(nvvertex);
275 
276  if ( vsorted.size() && useTracksFromRecoVtx_ ) {
277 
278  double sumpt = 0;
279  size_t ntracks = 0;
280  double chi2ndf = 0.;
281  double chi2prob = 0.;
282 
283  if (!vsorted.at(0).isFake()) {
284 
285  Vertex pv = vsorted.at(0);
286 
287  ntracks = pv.tracksSize();
288  chi2ndf = pv.normalizedChi2();
289  chi2prob = TMath::Prob(pv.chi2(),(int)pv.ndof());
290 
291  h_recoVtxNtracks_->Fill(ntracks);
292  h_recoVtxChi2ndf_->Fill(chi2ndf);
293  h_recoVtxChi2Prob_->Fill(chi2prob);
294 
295  for (Vertex::trackRef_iterator itrk = pv.tracks_begin();itrk != pv.tracks_end(); ++itrk) {
296  double pt = (**itrk).pt();
297  sumpt += pt*pt;
298 
299  const math::XYZPoint myVertex(pv.position().x(),pv.position().y(),pv.position().z());
300 
301  double dxyRes = (**itrk).dxy(myVertex);
302  double dzRes = (**itrk).dz(myVertex);
303 
304  double dxy_err = (**itrk).dxyError();
305  double dz_err = (**itrk).dzError();
306 
307  float trackphi = ((**itrk).phi())*(180/TMath::Pi());
308  float tracketa = (**itrk).eta();
309 
310  for(int i=0; i<nBins_; i++){
311 
312  float phiF = (-TMath::Pi()+i*phiSect_)*(180/TMath::Pi());
313  float phiL = (-TMath::Pi()+(i+1)*phiSect_)*(180/TMath::Pi());
314 
315  float etaF=-etaOfProbe_+i*etaSect_;
316  float etaL=-etaOfProbe_+(i+1)*etaSect_;
317 
318  if(tracketa >= etaF && tracketa < etaL ){
319 
320  a_dxyEtaBiasResiduals[i]->Fill(dxyRes*cmToum);
321  a_dzEtaBiasResiduals[i]->Fill(dzRes*cmToum);
322  n_dxyEtaBiasResiduals[i]->Fill((dxyRes)/dxy_err);
323  n_dzEtaBiasResiduals[i]->Fill((dzRes)/dz_err);
324 
325  }
326 
327  if(trackphi >= phiF && trackphi < phiL ){
328 
329  a_dxyPhiBiasResiduals[i]->Fill(dxyRes*cmToum);
330  a_dzPhiBiasResiduals[i]->Fill(dzRes*cmToum);
331  n_dxyPhiBiasResiduals[i]->Fill((dxyRes)/dxy_err);
332  n_dzPhiBiasResiduals[i]->Fill((dzRes)/dz_err);
333 
334  for(int j=0; j<nBins_; j++){
335 
336  float etaJ=-etaOfProbe_+j*etaSect_;
337  float etaK=-etaOfProbe_+(j+1)*etaSect_;
338 
339  if(tracketa >= etaJ && tracketa < etaK ){
340 
341  a_dxyBiasResidualsMap[i][j]->Fill(dxyRes*cmToum);
342  a_dzBiasResidualsMap[i][j]->Fill(dzRes*cmToum);
343 
344  n_dxyBiasResidualsMap[i][j]->Fill((dxyRes)/dxy_err);
345  n_dzBiasResidualsMap[i][j]->Fill((dzRes)/dz_err);
346 
347  }
348  }
349  }
350  }
351  }
352 
353  h_recoVtxSumPt_->Fill(sumpt);
354 
355  }
356  }
357 
358  //=======================================================
359  // Retrieve Beamspot information
360  //=======================================================
361 
363  edm::Handle<BeamSpot> beamSpotHandle;
364  iEvent.getByToken(theBeamspotToken, beamSpotHandle);
365 
366  if ( beamSpotHandle.isValid() ) {
367  beamSpot = *beamSpotHandle;
368  BSx0_ = beamSpot.x0();
369  BSy0_ = beamSpot.y0();
370  BSz0_ = beamSpot.z0();
371  Beamsigmaz_ = beamSpot.sigmaZ();
372  Beamdxdz_ = beamSpot.dxdz();
373  BeamWidthX_ = beamSpot.BeamWidthX();
374  BeamWidthY_ = beamSpot.BeamWidthY();
375 
376  wxy2_=TMath::Power(BeamWidthX_,2)+TMath::Power(BeamWidthY_,2);
377 
378  } else {
379  edm::LogWarning("PrimaryVertexValidation")<<"No BeamSpot found!";
380  }
381 
382  h_BSx0->Fill(BSx0_);
383  h_BSy0->Fill(BSy0_);
384  h_BSz0->Fill(BSz0_);
385  h_Beamsigmaz->Fill(Beamsigmaz_);
386  h_BeamWidthX->Fill(BeamWidthX_);
387  h_BeamWidthY->Fill(BeamWidthY_);
388 
389  if(debug_)
390  edm::LogInfo("PrimaryVertexValidation")<<"Beamspot x:" <<BSx0_<<" y:"<<BSy0_<<" z:"<<BSz0_;
391 
392  //=======================================================
393  // Starts here ananlysis
394  //=======================================================
395 
396  RunNumber_=iEvent.eventAuxiliary().run();
397  h_runNumber->Fill(RunNumber_);
399  EventNumber_=iEvent.eventAuxiliary().id().event();
400 
401  if(debug_)
402  edm::LogInfo("PrimaryVertexValidation")<<" looping over "<<trackCollectionHandle->size()<< "tracks";
403 
404  h_nTracks->Fill(trackCollectionHandle->size());
405 
406  //======================================================
407  // Interface RECO tracks to vertex reconstruction
408  //======================================================
409 
410  std::vector<TransientTrack> t_tks;
411  unsigned int k = 0;
412  for(TrackCollection::const_iterator track = trackCollectionHandle->begin(); track!= trackCollectionHandle->end(); ++track, ++k){
413 
414  TransientTrack tt = theB_->build(&(*track));
415  tt.setBeamSpot(beamSpot);
416  t_tks.push_back(tt);
417 
418  }
419 
420  if(debug_) {
421  edm::LogInfo("PrimaryVertexValidation") << "Found: " << t_tks.size() << " reconstructed tracks";
422  }
423 
424  //======================================================
425  // select the tracks
426  //======================================================
427 
428  std::vector<TransientTrack> seltks = theTrackFilter_->select(t_tks);
429 
430  //======================================================
431  // clusterize tracks in Z
432  //======================================================
433 
434  vector< vector<TransientTrack> > clusters = theTrackClusterizer_->clusterize(seltks);
435 
436  if (debug_){
437  edm::LogInfo("PrimaryVertexValidation")<<" looping over: "<< clusters.size() << " clusters from " << t_tks.size() << " selected tracks";
438  }
439 
440  nClus_=clusters.size();
441  h_nClus->Fill(nClus_);
442 
443  //======================================================
444  // Starts loop on clusters
445  //======================================================
446 
447  for (vector< vector<TransientTrack> >::const_iterator iclus = clusters.begin(); iclus != clusters.end(); iclus++) {
448 
449  nTracksPerClus_=0;
450 
451  unsigned int i = 0;
452  for(vector<TransientTrack>::const_iterator theTTrack = iclus->begin(); theTTrack!= iclus->end(); ++theTTrack, ++i)
453  {
454  if ( nTracks_ >= nMaxtracks_ ) {
455  edm::LogError("PrimaryVertexValidation")<<" Warning - Number of tracks: " << nTracks_ << " , greater than " << nMaxtracks_;
456  continue;
457  }
458 
459  const Track & theTrack = theTTrack->track();
460 
461  pt_[nTracks_] = theTrack.pt();
462  p_[nTracks_] = theTrack.p();
463  nhits_[nTracks_] = theTrack.numberOfValidHits();
464  eta_[nTracks_] = theTrack.eta();
465  theta_[nTracks_] = theTrack.theta();
466  phi_[nTracks_] = theTrack.phi();
467  chi2_[nTracks_] = theTrack.chi2();
468  chi2ndof_[nTracks_] = theTrack.normalizedChi2();
469  charge_[nTracks_] = theTrack.charge();
470  qoverp_[nTracks_] = theTrack.qoverp();
471  dz_[nTracks_] = theTrack.dz();
472  dxy_[nTracks_] = theTrack.dxy();
473 
474  TrackBase::TrackQuality _trackQuality = TrackBase::qualityByName("highPurity");
475  isHighPurity_[nTracks_] = theTrack.quality(_trackQuality);
476 
478  dxyBs_[nTracks_] = theTrack.dxy(point);
479  dzBs_[nTracks_] = theTrack.dz(point);
480 
481  xPCA_[nTracks_] = theTrack.vertex().x();
482  yPCA_[nTracks_] = theTrack.vertex().y();
483  zPCA_[nTracks_] = theTrack.vertex().z();
484 
485  //=======================================================
486  // Retrieve rechit information
487  //=======================================================
488 
489  const reco::HitPattern& hits = theTrack.hitPattern();
490 
491  int nRecHit1D=0;
492  int nRecHit2D=0;
493  int nhitinTIB = hits.numberOfValidStripTIBHits();
494  int nhitinTOB = hits.numberOfValidStripTOBHits();
495  int nhitinTID = hits.numberOfValidStripTIDHits();
496  int nhitinTEC = hits.numberOfValidStripTECHits();
497  int nhitinBPIX = hits.numberOfValidPixelBarrelHits();
498  int nhitinFPIX = hits.numberOfValidPixelEndcapHits();
499 
500  for (trackingRecHit_iterator iHit = theTTrack->recHitsBegin(); iHit != theTTrack->recHitsEnd(); ++iHit) {
501  if((*iHit)->isValid()) {
502 
503  if (this->isHit2D(**iHit)) {++nRecHit2D;}
504  else {++nRecHit1D; }
505  }
506  }
507 
508  nhits1D_[nTracks_] = nRecHit1D;
509  nhits2D_[nTracks_] = nRecHit2D;
510  nhitsBPIX_[nTracks_] = nhitinBPIX;
511  nhitsFPIX_[nTracks_] = nhitinFPIX;
512  nhitsTIB_[nTracks_] = nhitinTIB;
513  nhitsTID_[nTracks_] = nhitinTID;
514  nhitsTOB_[nTracks_] = nhitinTOB;
515  nhitsTEC_[nTracks_] = nhitinTEC;
516 
517  //=======================================================
518  // Good tracks for vertexing selection
519  //=======================================================
520 
521  bool pass = true;
522  if(askFirstLayerHit_) pass = this->hasFirstLayerPixelHits((*theTTrack));
523  if (pass && (theTrack.pt() >=ptOfProbe_) && fabs(theTrack.eta()) <= etaOfProbe_){
525  }
526 
527  //=======================================================
528  // Fit unbiased vertex
529  //=======================================================
530 
531  vector<TransientTrack> theFinalTracks;
532  theFinalTracks.clear();
533 
534  for(vector<TransientTrack>::const_iterator tk = iclus->begin(); tk!= iclus->end(); ++tk){
535 
536  pass = this->hasFirstLayerPixelHits((*tk));
537  if (pass){
538  if( tk == theTTrack ) continue;
539  else {
540  theFinalTracks.push_back((*tk));
541  }
542  }
543  }
544 
545  if(theFinalTracks.size() > 1){
546 
547  if(debug_)
548  edm::LogInfo("PrimaryVertexValidation")<<"Transient Track Collection size: "<<theFinalTracks.size();
549  try{
550 
551  VertexFitter<5>* theFitter = new AdaptiveVertexFitter;
552  TransientVertex theFittedVertex = theFitter->vertex(theFinalTracks);
553 
554  //AdaptiveVertexFitter* theFitter = new AdaptiveVertexFitter;
555  //TransientVertex theFittedVertex = theFitter->vertex(theFinalTracks,beamSpot); // if you want the beam constraint
556 
557  double totalTrackWeights=0;
558  if(theFittedVertex.isValid ()){
559 
560 
561  if(theFittedVertex.hasTrackWeight()){
562  for(size_t rtracks= 0; rtracks < theFinalTracks.size(); rtracks++){
563  sumOfWeightsUnbiasedVertex_[nTracks_] += theFittedVertex.trackWeight(theFinalTracks[rtracks]);
564  totalTrackWeights+= theFittedVertex.trackWeight(theFinalTracks[rtracks]);
565  h_fitVtxTrackWeights_->Fill(theFittedVertex.trackWeight(theFinalTracks[rtracks]));
566  }
567  }
568 
569  h_fitVtxTrackAverageWeight_->Fill(totalTrackWeights/theFinalTracks.size());
570 
572  const math::XYZPoint myVertex(theFittedVertex.position().x(),theFittedVertex.position().y(),theFittedVertex.position().z());
573 
574  const Vertex vertex = theFittedVertex;
575  fillTrackHistos(hDA,"all",&(*theTTrack),vertex,beamSpot,fBfield_);
576 
577  hasRecVertex_[nTracks_] = 1;
578  xUnbiasedVertex_[nTracks_] = theFittedVertex.position().x();
579  yUnbiasedVertex_[nTracks_] = theFittedVertex.position().y();
580  zUnbiasedVertex_[nTracks_] = theFittedVertex.position().z();
581 
583  chi2UnbiasedVertex_[nTracks_] = theFittedVertex.totalChiSquared();
584  DOFUnbiasedVertex_[nTracks_] = theFittedVertex.degreesOfFreedom();
585  chi2ProbUnbiasedVertex_[nTracks_] = TMath::Prob(theFittedVertex.totalChiSquared(),(int)theFittedVertex.degreesOfFreedom());
586  tracksUsedForVertexing_[nTracks_] = theFinalTracks.size();
587 
588  h_fitVtxNtracks_->Fill(theFinalTracks.size());
589  h_fitVtxChi2_->Fill(theFittedVertex.totalChiSquared());
590  h_fitVtxNdof_->Fill(theFittedVertex.degreesOfFreedom());
591  h_fitVtxChi2ndf_->Fill(theFittedVertex.normalisedChiSquared());
592  h_fitVtxChi2Prob_->Fill(TMath::Prob(theFittedVertex.totalChiSquared(),(int)theFittedVertex.degreesOfFreedom()));
593 
594  // from my Vertex
595  double dxyFromMyVertex = theTrack.dxy(myVertex);
596  double dzFromMyVertex = theTrack.dz(myVertex);
597 
598  GlobalPoint vert(theFittedVertex.position().x(),theFittedVertex.position().y(),theFittedVertex.position().z());
599 
600  //FreeTrajectoryState theTrackNearVertex = (*theTTrack).trajectoryStateClosestToPoint(vert).theState();
601  //double dz_err = sqrt(theFittedVertex.positionError().czz() + theTrackNearVertex.cartesianError().position().czz());
602  //double dz_err = hypot(theTrack.dzError(),theFittedVertex.positionError().czz());
603 
604  double dz_err = sqrt(std::pow(theTrack.dzError(), 2) + theFittedVertex.positionError().czz());
605 
606 
607  // PV2D
608  std::pair<bool,Measurement1D> s_ip2dpv = signedTransverseImpactParameter(*theTTrack,
609  GlobalVector(theTrack.px(),
610  theTrack.py(),
611  theTrack.pz()),
612  theFittedVertex);
613 
614  double s_ip2dpv_corr = s_ip2dpv.second.value();
615  double s_ip2dpv_err = s_ip2dpv.second.error();
616 
617  // PV3D
618  std::pair<bool, Measurement1D> s_ip3dpv = signedImpactParameter3D(*theTTrack,
619  GlobalVector(theTrack.px(),
620  theTrack.py(),
621  theTrack.pz()),
622  theFittedVertex);
623 
624  double s_ip3dpv_corr = s_ip3dpv.second.value();
625  double s_ip3dpv_err = s_ip3dpv.second.error();
626 
627  // PV3D absolute
628  std::pair<bool,Measurement1D> ip3dpv = absoluteImpactParameter3D(*theTTrack,theFittedVertex);
629  double ip3d_corr = ip3dpv.second.value();
630  double ip3d_err = ip3dpv.second.error();
631 
632  // with respect to any specified vertex, such as primary vertex
633  TrajectoryStateClosestToPoint traj = (*theTTrack).trajectoryStateClosestToPoint(vert);
634 
635  GlobalPoint refPoint = traj.position();
636  GlobalPoint cPToVtx = traj.theState().position();
637 
638  float my_dx = refPoint.x() - myVertex.x();
639  float my_dy = refPoint.y() - myVertex.y();
640 
641  float my_dx2 = cPToVtx.x() - myVertex.x();
642  float my_dy2 = cPToVtx.y() - myVertex.y();
643 
644  float my_dxy = std::sqrt(my_dx*my_dx + my_dy*my_dy);
645 
647  //double d0_error = traj.perigeeError().transverseImpactParameterError();
648  double z0 = traj.perigeeParameters().longitudinalImpactParameter();
649  double z0_error = traj.perigeeError().longitudinalImpactParameterError();
650 
651  edm::LogInfo("PrimaryVertexValidation")<< "my_dx:" << my_dx
652  << " my_dy:" << my_dy
653  << " my_dxy:" << my_dxy
654  << " my_dx2:" << my_dx2
655  << " my_dy2:" << my_dy2
656  << " d0: " << d0
657  << " dxyFromVtx:" << dxyFromMyVertex << "\n"
658  << " ============================== "<< "\n"
659  << "diff1:" << std::abs(d0) - std::abs(my_dxy) << "\n"
660  << "diff2:" << std::abs(d0) - std::abs(dxyFromMyVertex) << "\n"
661  << "diff3:" << (my_dx - my_dx2) << " " << (my_dy - my_dy2) << "\n"
662  << std::endl;
663 
664  // define IPs
665 
666  dxyFromMyVertex_[nTracks_] = dxyFromMyVertex;
667  dxyErrorFromMyVertex_[nTracks_] = s_ip2dpv_err;
668  IPTsigFromMyVertex_[nTracks_] = dxyFromMyVertex/s_ip2dpv_err;
669 
670  dzFromMyVertex_[nTracks_] = dzFromMyVertex;
671  dzErrorFromMyVertex_[nTracks_] = dz_err;
672  IPLsigFromMyVertex_[nTracks_] = dzFromMyVertex/dz_err;
673 
674  d3DFromMyVertex_[nTracks_] = ip3d_corr;
675  d3DErrorFromMyVertex_[nTracks_] = ip3d_err;
676  IP3DsigFromMyVertex_[nTracks_] = (ip3d_corr/ip3d_err);
677 
678  // fill directly the histograms of residuals
679 
680  float trackphi = (theTrack.phi())*(180/TMath::Pi());
681  float tracketa = theTrack.eta();
682  float trackpt = theTrack.pt();
683 
684  // checks on the probe track quality
685  if(trackpt >= ptOfProbe_ && fabs(tracketa)<= etaOfProbe_){
686 
687  std::pair<bool,bool> pixelOcc = pixelHitsCheck((*theTTrack));
688 
689  /*
690  if(pixelOcc.first == true)
691  std::cout<<"has BPIx hits"<<std::endl;
692  if(pixelOcc.second == true)
693  std::cout<<"has FPix hits"<<std::endl;
694  */
695 
696  if(!doBPix_ && (pixelOcc.first == true)) continue;
697  if(!doFPix_ && (pixelOcc.second == true)) continue;
698 
699  //std::cout<<"track passed"<<std::endl;
700 
701  fillTrackHistos(hDA,"sel",&(*theTTrack),vertex,beamSpot,fBfield_);
702 
703  // probe checks
704  h_probePt_->Fill(theTrack.pt());
705  h_probeP_->Fill(theTrack.p());
706  h_probeEta_->Fill(theTrack.eta());
707  h_probePhi_->Fill(theTrack.phi());
708  h2_probeEtaPhi_->Fill(theTrack.eta(),theTrack.phi());
709  h2_probeEtaPt_->Fill(theTrack.eta(),theTrack.pt());
710 
711  h_probeChi2_->Fill(theTrack.chi2());
712  h_probeNormChi2_->Fill(theTrack.normalizedChi2());
713  h_probeCharge_->Fill(theTrack.charge());
714  h_probeQoverP_->Fill(theTrack.qoverp());
715  h_probeHits_->Fill(theTrack.numberOfValidHits());
716  h_probeHits1D_->Fill(nRecHit1D);
717  h_probeHits2D_->Fill(nRecHit2D);
718  h_probeHitsInTIB_->Fill(nhitinBPIX);
719  h_probeHitsInTOB_->Fill(nhitinFPIX);
720  h_probeHitsInTID_->Fill(nhitinTIB);
721  h_probeHitsInTEC_->Fill(nhitinTID);
722  h_probeHitsInBPIX_->Fill(nhitinTOB);
723  h_probeHitsInFPIX_->Fill(nhitinTEC);
724 
725  float dxyRecoV = theTrack.dz(theRecoVertex);
726  float dzRecoV = theTrack.dxy(theRecoVertex);
727  float dxysigmaRecoV = TMath::Sqrt(theTrack.d0Error()*theTrack.d0Error()+xErrOfflineVertex_*yErrOfflineVertex_);
728  float dzsigmaRecoV = TMath::Sqrt(theTrack.dzError()*theTrack.dzError()+zErrOfflineVertex_*zErrOfflineVertex_);
729 
730  double zTrack=(theTTrack->stateAtBeamLine().trackStateAtPCA()).position().z();
731  double zVertex=theFittedVertex.position().z();
732  double tantheta=tan((theTTrack->stateAtBeamLine().trackStateAtPCA()).momentum().theta());
733 
734  double dz2= pow(theTrack.dzError(),2)+wxy2_/pow(tantheta,2);
735  double restrkz = zTrack-zVertex;
736  double pulltrkz = (zTrack-zVertex)/TMath::Sqrt(dz2);
737 
738  h_probedxyRecoV_->Fill(dxyRecoV);
739  h_probedzRecoV_->Fill(dzRecoV);
740 
741  h_probedzRefitV_->Fill(dxyFromMyVertex);
742  h_probedxyRefitV_->Fill(dzFromMyVertex);
743 
744  h_probed0RefitV_->Fill(d0);
745  h_probez0RefitV_->Fill(z0);
746 
747  h_probesignIP2DRefitV_->Fill(s_ip2dpv_corr);
748  h_probed3DRefitV_->Fill(ip3d_corr);
749  h_probereszRefitV_->Fill(restrkz);
750 
751  h_probeRecoVSigZ_->Fill(dzRecoV/dzsigmaRecoV);
752  h_probeRecoVSigXY_->Fill(dxyRecoV/dxysigmaRecoV);
753  h_probeRefitVSigZ_->Fill(dzFromMyVertex/dz_err);
754  h_probeRefitVSigXY_->Fill(dxyFromMyVertex/s_ip2dpv_err);
755  h_probeRefitVSig3D_->Fill(ip3d_corr/ip3d_err);
756  h_probeRefitVLogSig3D_->Fill(log10(ip3d_corr/ip3d_err));
757  h_probeRefitVSigResZ_->Fill(pulltrkz);
758 
759  a_dxyVsPhi->Fill(trackphi,dxyFromMyVertex*cmToum);
760  a_dzVsPhi->Fill(trackphi,z0*cmToum);
761  n_dxyVsPhi->Fill(trackphi,dxyFromMyVertex/s_ip2dpv_err);
762  n_dzVsPhi->Fill(trackphi,z0/z0_error);
763 
764  a_dxyVsEta->Fill(tracketa,dxyFromMyVertex*cmToum);
765  a_dzVsEta->Fill(tracketa,z0*cmToum);
766  n_dxyVsEta->Fill(tracketa,dxyFromMyVertex/s_ip2dpv_err);
767  n_dzVsEta->Fill(tracketa,z0/z0_error);
768 
769  // filling the binned distributions
770  for(int i=0; i<nBins_; i++){
771 
772  float phiF = (-TMath::Pi()+i*phiSect_)*(180/TMath::Pi());
773  float phiL = (-TMath::Pi()+(i+1)*phiSect_)*(180/TMath::Pi());
774 
775  float etaF=-etaOfProbe_+i*etaSect_;
776  float etaL=-etaOfProbe_+(i+1)*etaSect_;
777 
778  if(tracketa >= etaF && tracketa < etaL ){
779 
780  a_dxyEtaResiduals[i]->Fill(dxyFromMyVertex*cmToum);
781  a_dxEtaResiduals[i]->Fill(my_dx*cmToum);
782  a_dyEtaResiduals[i]->Fill(my_dy*cmToum);
783  a_dzEtaResiduals[i]->Fill(dzFromMyVertex*cmToum);
784  n_dxyEtaResiduals[i]->Fill(dxyFromMyVertex/s_ip2dpv_err);
785  n_dzEtaResiduals[i]->Fill(dzFromMyVertex/dz_err);
786  a_IP2DEtaResiduals[i]->Fill(s_ip2dpv_corr*cmToum);
787  n_IP2DEtaResiduals[i]->Fill(s_ip2dpv_corr/s_ip2dpv_err);
788  a_reszEtaResiduals[i]->Fill(restrkz*cmToum);
789  n_reszEtaResiduals[i]->Fill(pulltrkz);
790  a_d3DEtaResiduals[i]->Fill(ip3d_corr*cmToum);
791  n_d3DEtaResiduals[i]->Fill(ip3d_corr/ip3d_err);
792  a_IP3DEtaResiduals[i]->Fill(s_ip3dpv_corr*cmToum);
793  n_IP3DEtaResiduals[i]->Fill(s_ip3dpv_corr/s_ip3dpv_err);
794 
795  }
796 
797  if(trackphi >= phiF && trackphi < phiL ){
798  a_dxyPhiResiduals[i]->Fill(dxyFromMyVertex*cmToum);
799  a_dxPhiResiduals[i]->Fill(my_dx*cmToum);
800  a_dyPhiResiduals[i]->Fill(my_dy*cmToum);
801  a_dzPhiResiduals[i]->Fill(dzFromMyVertex*cmToum);
802  n_dxyPhiResiduals[i]->Fill(dxyFromMyVertex/s_ip2dpv_err);
803  n_dzPhiResiduals[i]->Fill(dzFromMyVertex/dz_err);
804  a_IP2DPhiResiduals[i]->Fill(s_ip2dpv_corr*cmToum);
805  n_IP2DPhiResiduals[i]->Fill(s_ip2dpv_corr/s_ip2dpv_err);
806  a_reszPhiResiduals[i]->Fill(restrkz*cmToum);
807  n_reszPhiResiduals[i]->Fill(pulltrkz);
808  a_d3DPhiResiduals[i]->Fill(ip3d_corr*cmToum);
809  n_d3DPhiResiduals[i]->Fill(ip3d_corr/ip3d_err);
810  a_IP3DPhiResiduals[i]->Fill(s_ip3dpv_corr*cmToum);
811  n_IP3DPhiResiduals[i]->Fill(s_ip3dpv_corr/s_ip3dpv_err);
812 
813  for(int j=0; j<nBins_; j++){
814 
815  float etaJ=-etaOfProbe_+j*etaSect_;
816  float etaK=-etaOfProbe_+(j+1)*etaSect_;
817 
818  if(tracketa >= etaJ && tracketa < etaK ){
819  a_dxyResidualsMap[i][j]->Fill(dxyFromMyVertex*cmToum);
820  a_dzResidualsMap[i][j]->Fill(dzFromMyVertex*cmToum);
821  n_dxyResidualsMap[i][j]->Fill(dxyFromMyVertex/s_ip2dpv_err);
822  n_dzResidualsMap[i][j]->Fill(dzFromMyVertex/dz_err);
823  a_d3DResidualsMap[i][j]->Fill(ip3d_corr*cmToum);
824  n_d3DResidualsMap[i][j]->Fill(ip3d_corr/ip3d_err);
825 
826  }
827  }
828  }
829  }
830  }
831 
832  if(debug_){
833  edm::LogInfo("PrimaryVertexValidation")<<" myVertex.x()= "<<myVertex.x()<<"\n"
834  <<" myVertex.y()= "<<myVertex.y()<<" \n"
835  <<" myVertex.z()= "<<myVertex.z()<<" \n"
836  <<" theTrack.dz(myVertex)= "<<theTrack.dz(myVertex)<<" \n"
837  <<" zPCA -myVertex.z() = "<<(theTrack.vertex().z() -myVertex.z());
838 
839  }// ends if debug_
840  } // ends if the fitted vertex is Valid
841 
842  delete theFitter;
843 
844  } catch ( cms::Exception& er ) {
845  LogTrace("PrimaryVertexValidation")<<"caught std::exception "<<er.what()<<std::endl;
846  }
847 
848  } //ends if theFinalTracks.size() > 2
849 
850  else {
851  if(debug_)
852  edm::LogInfo("PrimaryVertexValidation")<<"Not enough tracks to make a vertex. Returns no vertex info";
853  }
854 
855  ++nTracks_;
856  ++nTracksPerClus_;
857 
858  if(debug_)
859  edm::LogInfo("PrimaryVertexValidation")<<"Track "<<i<<" : pT = "<<theTrack.pt();
860 
861  }// for loop on tracks
862  } // for loop on track clusters
863 
864  // Fill the TTree if needed
865 
866  if(storeNtuple_){
867  rootTree_->Fill();
868  }
869 
870 
871 }
872 
873 // ------------ method called to discriminate 1D from 2D hits ------------
875 {
876  if (hit.dimension() < 2) {
877  return false; // some (muon...) stuff really has RecHit1D
878  } else {
879  const DetId detId(hit.geographicalId());
880  if (detId.det() == DetId::Tracker) {
881  if (detId.subdetId() == PixelSubdetector::PixelBarrel || detId.subdetId() == PixelSubdetector::PixelEndcap) {
882  return true; // pixel is always 2D
883  } else { // should be SiStrip now
884  if (dynamic_cast<const SiStripRecHit2D*>(&hit)) return false; // normal hit
885  else if (dynamic_cast<const SiStripMatchedRecHit2D*>(&hit)) return true; // matched is 2D
886  else if (dynamic_cast<const ProjectedSiStripRecHit2D*>(&hit)) return false; // crazy hit...
887  else {
888  edm::LogError("UnkownType") << "@SUB=AlignmentTrackSelector::isHit2D"
889  << "Tracker hit not in pixel and neither SiStripRecHit2D nor "
890  << "SiStripMatchedRecHit2D nor ProjectedSiStripRecHit2D.";
891  return false;
892  }
893  }
894  } else { // not tracker??
895  edm::LogWarning("DetectorMismatch") << "@SUB=AlignmentTrackSelector::isHit2D"
896  << "Hit not in tracker with 'official' dimension >=2.";
897  return true; // dimension() >= 2 so accept that...
898  }
899  }
900  // never reached...
901 }
902 
903 
904 // ------------ method to check the presence of pixel hits ------------
906 
907  bool hasBPixHits = false;
908  bool hasFPixHits = false;
909 
910  const reco::HitPattern& p = track.hitPattern();
911  if(p.numberOfValidPixelEndcapHits()!=0){
912  hasFPixHits = true;
913  }
914  if(p.numberOfValidPixelBarrelHits()!=0){
915  hasBPixHits = true;
916  }
917 
918  return std::make_pair(hasBPixHits,hasFPixHits);
919 }
920 
921 
922 // ------------ method to check the presence of pixel hits ------------
924 {
925  using namespace reco;
926  const HitPattern& p = track.hitPattern();
927  for (int i=0; i<p.numberOfHits(HitPattern::TRACK_HITS); i++) {
928  uint32_t pattern = p.getHitPattern(HitPattern::TRACK_HITS, i);
929  if (p.pixelBarrelHitFilter(pattern) || p.pixelEndcapHitFilter(pattern) ) {
930  if (p.getLayer(pattern) == 1) {
931  if (p.validHitFilter(pattern)) {
932  return true;
933  }
934  }
935  }
936  }
937  return false;
938 }
939 
940 // ------------ method called once each job before begining the event loop ------------
942 {
943  edm::LogInfo("PrimaryVertexValidation")
944  <<"######################################\n"
945  <<"Begin Job \n"
946  <<"######################################";
947 
948  // Define TTree for output
949  Nevt_ = 0;
950 
951  // rootFile_ = new TFile(filename_.c_str(),"recreate");
953  rootTree_ = fs->make<TTree>("tree","PV Validation tree");
954 
955  // Track Paramters
956 
957  if(lightNtupleSwitch_){
958 
959  rootTree_->Branch("EventNumber",&EventNumber_,"EventNumber/i");
960  rootTree_->Branch("RunNumber",&RunNumber_,"RunNumber/i");
961  rootTree_->Branch("LuminosityBlockNumber",&LuminosityBlockNumber_,"LuminosityBlockNumber/i");
962  rootTree_->Branch("nOfflineVertices",&nOfflineVertices_,"nOfflineVertices/I");
963  rootTree_->Branch("nTracks",&nTracks_,"nTracks/I");
964  rootTree_->Branch("phi",&phi_,"phi[nTracks]/D");
965  rootTree_->Branch("eta",&eta_,"eta[nTracks]/D");
966  rootTree_->Branch("pt",&pt_,"pt[nTracks]/D");
967  rootTree_->Branch("dxyFromMyVertex",&dxyFromMyVertex_,"dxyFromMyVertex[nTracks]/D");
968  rootTree_->Branch("dzFromMyVertex",&dzFromMyVertex_,"dzFromMyVertex[nTracks]/D");
969  rootTree_->Branch("d3DFromMyVertex",&d3DFromMyVertex_,"d3DFromMyVertex[nTracks]/D");
970  rootTree_->Branch("IPTsigFromMyVertex",&IPTsigFromMyVertex_,"IPTsigFromMyVertex_[nTracks]/D");
971  rootTree_->Branch("IPLsigFromMyVertex",&IPLsigFromMyVertex_,"IPLsigFromMyVertex_[nTracks]/D");
972  rootTree_->Branch("IP3DsigFromMyVertex",&IP3DsigFromMyVertex_,"IP3DsigFromMyVertex_[nTracks]/D");
973  rootTree_->Branch("hasRecVertex",&hasRecVertex_,"hasRecVertex[nTracks]/I");
974  rootTree_->Branch("isGoodTrack",&isGoodTrack_,"isGoodTrack[nTracks]/I");
975  rootTree_->Branch("isHighPurity",&isHighPurity_,"isHighPurity_[nTracks]/I");
976 
977  } else {
978 
979  rootTree_->Branch("nTracks",&nTracks_,"nTracks/I");
980  rootTree_->Branch("nTracksPerClus",&nTracksPerClus_,"nTracksPerClus/I");
981  rootTree_->Branch("nClus",&nClus_,"nClus/I");
982  rootTree_->Branch("xOfflineVertex",&xOfflineVertex_,"xOfflineVertex/D");
983  rootTree_->Branch("yOfflineVertex",&yOfflineVertex_,"yOfflineVertex/D");
984  rootTree_->Branch("zOfflineVertex",&zOfflineVertex_,"zOfflineVertex/D");
985  rootTree_->Branch("BSx0",&BSx0_,"BSx0/D");
986  rootTree_->Branch("BSy0",&BSy0_,"BSy0/D");
987  rootTree_->Branch("BSz0",&BSz0_,"BSz0/D");
988  rootTree_->Branch("Beamsigmaz",&Beamsigmaz_,"Beamsigmaz/D");
989  rootTree_->Branch("Beamdxdz",&Beamdxdz_,"Beamdxdz/D");
990  rootTree_->Branch("BeamWidthX",&BeamWidthX_,"BeamWidthX/D");
991  rootTree_->Branch("BeamWidthY",&BeamWidthY_,"BeamWidthY/D");
992  rootTree_->Branch("pt",&pt_,"pt[nTracks]/D");
993  rootTree_->Branch("p",&p_,"p[nTracks]/D");
994  rootTree_->Branch("nhits",&nhits_,"nhits[nTracks]/I");
995  rootTree_->Branch("nhits1D",&nhits1D_,"nhits1D[nTracks]/I");
996  rootTree_->Branch("nhits2D",&nhits2D_,"nhits2D[nTracks]/I");
997  rootTree_->Branch("nhitsBPIX",&nhitsBPIX_,"nhitsBPIX[nTracks]/I");
998  rootTree_->Branch("nhitsFPIX",&nhitsFPIX_,"nhitsFPIX[nTracks]/I");
999  rootTree_->Branch("nhitsTIB",&nhitsTIB_,"nhitsTIB[nTracks]/I");
1000  rootTree_->Branch("nhitsTID",&nhitsTID_,"nhitsTID[nTracks]/I");
1001  rootTree_->Branch("nhitsTOB",&nhitsTOB_,"nhitsTOB[nTracks]/I");
1002  rootTree_->Branch("nhitsTEC",&nhitsTEC_,"nhitsTEC[nTracks]/I");
1003  rootTree_->Branch("eta",&eta_,"eta[nTracks]/D");
1004  rootTree_->Branch("theta",&theta_,"theta[nTracks]/D");
1005  rootTree_->Branch("phi",&phi_,"phi[nTracks]/D");
1006  rootTree_->Branch("chi2",&chi2_,"chi2[nTracks]/D");
1007  rootTree_->Branch("chi2ndof",&chi2ndof_,"chi2ndof[nTracks]/D");
1008  rootTree_->Branch("charge",&charge_,"charge[nTracks]/I");
1009  rootTree_->Branch("qoverp",&qoverp_,"qoverp[nTracks]/D");
1010  rootTree_->Branch("dz",&dz_,"dz[nTracks]/D");
1011  rootTree_->Branch("dxy",&dxy_,"dxy[nTracks]/D");
1012  rootTree_->Branch("dzBs",&dzBs_,"dzBs[nTracks]/D");
1013  rootTree_->Branch("dxyBs",&dxyBs_,"dxyBs[nTracks]/D");
1014  rootTree_->Branch("xPCA",&xPCA_,"xPCA[nTracks]/D");
1015  rootTree_->Branch("yPCA",&yPCA_,"yPCA[nTracks]/D");
1016  rootTree_->Branch("zPCA",&zPCA_,"zPCA[nTracks]/D");
1017  rootTree_->Branch("xUnbiasedVertex",&xUnbiasedVertex_,"xUnbiasedVertex[nTracks]/D");
1018  rootTree_->Branch("yUnbiasedVertex",&yUnbiasedVertex_,"yUnbiasedVertex[nTracks]/D");
1019  rootTree_->Branch("zUnbiasedVertex",&zUnbiasedVertex_,"zUnbiasedVertex[nTracks]/D");
1020  rootTree_->Branch("chi2normUnbiasedVertex",&chi2normUnbiasedVertex_,"chi2normUnbiasedVertex[nTracks]/F");
1021  rootTree_->Branch("chi2UnbiasedVertex",&chi2UnbiasedVertex_,"chi2UnbiasedVertex[nTracks]/F");
1022  rootTree_->Branch("DOFUnbiasedVertex",&DOFUnbiasedVertex_," DOFUnbiasedVertex[nTracks]/F");
1023  rootTree_->Branch("chi2ProbUnbiasedVertex",&chi2ProbUnbiasedVertex_,"chi2ProbUnbiasedVertex[nTracks]/F");
1024  rootTree_->Branch("sumOfWeightsUnbiasedVertex",&sumOfWeightsUnbiasedVertex_,"sumOfWeightsUnbiasedVertex[nTracks]/F");
1025  rootTree_->Branch("tracksUsedForVertexing",&tracksUsedForVertexing_,"tracksUsedForVertexing[nTracks]/I");
1026  rootTree_->Branch("dxyFromMyVertex",&dxyFromMyVertex_,"dxyFromMyVertex[nTracks]/D");
1027  rootTree_->Branch("dzFromMyVertex",&dzFromMyVertex_,"dzFromMyVertex[nTracks]/D");
1028  rootTree_->Branch("dxyErrorFromMyVertex",&dxyErrorFromMyVertex_,"dxyErrorFromMyVertex_[nTracks]/D");
1029  rootTree_->Branch("dzErrorFromMyVertex",&dzErrorFromMyVertex_,"dzErrorFromMyVertex_[nTracks]/D");
1030  rootTree_->Branch("IPTsigFromMyVertex",&IPTsigFromMyVertex_,"IPTsigFromMyVertex_[nTracks]/D");
1031  rootTree_->Branch("IPLsigFromMyVertex",&IPLsigFromMyVertex_,"IPLsigFromMyVertex_[nTracks]/D");
1032  rootTree_->Branch("hasRecVertex",&hasRecVertex_,"hasRecVertex[nTracks]/I");
1033  rootTree_->Branch("isGoodTrack",&isGoodTrack_,"isGoodTrack[nTracks]/I");
1034  }
1035 
1036  // event histograms
1037  TFileDirectory EventFeatures = fs->mkdir("EventFeatures");
1038 
1039  TH1F::SetDefaultSumw2(kTRUE);
1040 
1041  h_nTracks = EventFeatures.make<TH1F>("h_nTracks","number of tracks per event;n_{tracks}/event;n_{events}",300,-0.5,299.5);
1042  h_nClus = EventFeatures.make<TH1F>("h_nClus","number of track clusters;n_{clusters}/event;n_{events}",50,-0.5,49.5);
1043  h_nOfflineVertices = EventFeatures.make<TH1F>("h_nOfflineVertices","number of offline reconstructed vertices;n_{vertices}/event;n_{events}",50,-0.5,49.5);
1044  h_runNumber = EventFeatures.make<TH1F>("h_runNumber","run number;run number;n_{events}",100000,150000.,250000.);
1045  h_xOfflineVertex = EventFeatures.make<TH1F>("h_xOfflineVertex","x-coordinate of offline vertex;x_{vertex};n_{events}",100,-0.1,0.1);
1046  h_yOfflineVertex = EventFeatures.make<TH1F>("h_yOfflineVertex","y-coordinate of offline vertex;y_{vertex};n_{events}",100,-0.1,0.1);
1047  h_zOfflineVertex = EventFeatures.make<TH1F>("h_zOfflineVertex","z-coordinate of offline vertex;z_{vertex};n_{events}",100,-30.,30.);
1048  h_xErrOfflineVertex = EventFeatures.make<TH1F>("h_xErrOfflineVertex","x-coordinate error of offline vertex;err_{x}^{vtx};n_{events}",100,0.,0.01);
1049  h_yErrOfflineVertex = EventFeatures.make<TH1F>("h_yErrOfflineVertex","y-coordinate error of offline vertex;err_{y}^{vtx};n_{events}",100,0.,0.01);
1050  h_zErrOfflineVertex = EventFeatures.make<TH1F>("h_zErrOfflineVertex","z-coordinate error of offline vertex;err_{z}^{vtx};n_{events}",100,0.,10.);
1051  h_BSx0 = EventFeatures.make<TH1F>("h_BSx0","x-coordinate of reco beamspot;x^{BS}_{0};n_{events}",100,-0.1,0.1);
1052  h_BSy0 = EventFeatures.make<TH1F>("h_BSy0","y-coordinate of reco beamspot;y^{BS}_{0};n_{events}",100,-0.1,0.1);
1053  h_BSz0 = EventFeatures.make<TH1F>("h_BSz0","z-coordinate of reco beamspot;z^{BS}_{0};n_{events}",100,-1.,1.);
1054  h_Beamsigmaz = EventFeatures.make<TH1F>("h_Beamsigmaz","z-coordinate beam width;#sigma_{Z}^{beam};n_{events}",100,0.,1.);
1055  h_BeamWidthX = EventFeatures.make<TH1F>("h_BeamWidthX","x-coordinate beam width;#sigma_{X}^{beam};n_{events}",100,0.,0.01);
1056  h_BeamWidthY = EventFeatures.make<TH1F>("h_BeamWidthY","y-coordinate beam width;#sigma_{Y}^{beam};n_{events}",100,0.,0.01);
1057 
1058  h_etaMax = EventFeatures.make<TH1F>("etaMax","etaMax",1,-0.5,0.5);
1059  h_nbins = EventFeatures.make<TH1F>("nbins","nbins",1,-0.5,0.5);
1060 
1061  // probe track histograms
1062  TFileDirectory ProbeFeatures = fs->mkdir("ProbeTrackFeatures");
1063 
1064  h_probePt_ = ProbeFeatures.make<TH1F>("h_probePt","p_{T} of probe track;track p_{T} (GeV); tracks",100,0.,50.);
1065  h_probeP_ = ProbeFeatures.make<TH1F>("h_probeP","momentum of probe track;track p (GeV); tracks",100,0.,100.);
1066  h_probeEta_ = ProbeFeatures.make<TH1F>("h_probeEta","#eta of the probe track;track #eta;tracks",54,-2.8,2.8);
1067  h_probePhi_ = ProbeFeatures.make<TH1F>("h_probePhi","#phi of probe track;track #phi (rad);tracks",100,-3.15,3.15);
1068 
1069  h2_probeEtaPhi_ = ProbeFeatures.make<TH2F>("h2_probeEtaPhi","probe track #phi vs #eta;#eta of probe track;track #phi of probe track (rad); tracks",54,-2.8,2.8,100,-3.15,3.15);
1070  h2_probeEtaPt_ = ProbeFeatures.make<TH2F>("h2_probeEtaPt","probe track p_{T} vs #eta;#eta of probe track;track p_{T} (GeV); tracks",54,-2.8,2.8,100,0.,50.);
1071 
1072  h_probeChi2_ = ProbeFeatures.make<TH1F>("h_probeChi2","#chi^{2} of probe track;track #chi^{2}; tracks",100,0.,100.);
1073  h_probeNormChi2_ = ProbeFeatures.make<TH1F>("h_probeNormChi2"," normalized #chi^{2} of probe track;track #chi^{2}/ndof; tracks",100,0.,10.);
1074  h_probeCharge_ = ProbeFeatures.make<TH1F>("h_probeCharge","charge of profe track;track charge Q;tracks",3,-1.5,1.5);
1075  h_probeQoverP_ = ProbeFeatures.make<TH1F>("h_probeQoverP","q/p of probe track; track Q/p (GeV^{-1});tracks",200,-1.,1.);
1076  h_probedzRecoV_ = ProbeFeatures.make<TH1F>("h_probedzRecoV","d_{z}(V_{offline}) of probe track;track d_{z}(V_{off}) (cm);tracks",200,-1.,1.);
1077  h_probedxyRecoV_ = ProbeFeatures.make<TH1F>("h_probedxyRecoV","d_{xy}(V_{offline}) of probe track;track d_{xy}(V_{off}) (cm);tracks",200,-1.,1.);
1078  h_probedzRefitV_ = ProbeFeatures.make<TH1F>("h_probedzRefitV","d_{z}(V_{refit}) of probe track;track d_{z}(V_{fit}) (cm);tracks",200,-1.,1.);
1079  h_probesignIP2DRefitV_ = ProbeFeatures.make<TH1F>("h_probesignIPRefitV","ip_{2D}(V_{refit}) of probe track;track ip_{2D}(V_{fit}) (cm);tracks",200,-1.,1.);
1080  h_probedxyRefitV_ = ProbeFeatures.make<TH1F>("h_probedxyRefitV","d_{xy}(V_{refit}) of probe track;track d_{xy}(V_{fit}) (cm);tracks",200,-1.,1.);
1081 
1082  h_probez0RefitV_ = ProbeFeatures.make<TH1F>("h_probez0RefitV","z_{0}(V_{refit}) of probe track;track z_{0}(V_{fit}) (cm);tracks",200,-1.,1.);
1083  h_probed0RefitV_ = ProbeFeatures.make<TH1F>("h_probed0RefitV","d_{0}(V_{refit}) of probe track;track d_{0}(V_{fit}) (cm);tracks",200,-1.,1.);
1084 
1085  h_probed3DRefitV_ = ProbeFeatures.make<TH1F>("h_probed3DRefitV","d_{3D}(V_{refit}) of probe track;track d_{3D}(V_{fit}) (cm);tracks",200,0.,1.);
1086  h_probereszRefitV_ = ProbeFeatures.make<TH1F>("h_probeReszRefitV","z_{track} -z_{V_{refit}};track res_{z}(V_{refit}) (cm);tracks",200,-1.,1.);
1087 
1088  h_probeRecoVSigZ_ = ProbeFeatures.make<TH1F>("h_probeRecoVSigZ" ,"Longitudinal DCA Significance (reco);d_{z}(V_{off})/#sigma_{dz};tracks",100,-8,8);
1089  h_probeRecoVSigXY_ = ProbeFeatures.make<TH1F>("h_probeRecoVSigXY" ,"Transverse DCA Significance (reco);d_{xy}(V_{off})/#sigma_{dxy};tracks",100,-8,8);
1090  h_probeRefitVSigZ_ = ProbeFeatures.make<TH1F>("h_probeRefitVSigZ" ,"Longitudinal DCA Significance (refit);d_{z}(V_{fit})/#sigma_{dz};tracks",100,-8,8);
1091  h_probeRefitVSigXY_= ProbeFeatures.make<TH1F>("h_probeRefitVSigXY","Transverse DCA Significance (refit);d_{xy}(V_{fit})/#sigma_{dxy};tracks",100,-8,8);
1092  h_probeRefitVSig3D_= ProbeFeatures.make<TH1F>("h_probeRefitVSig3D","3D DCA Significance (refit);d_{3D}/#sigma_{3D};tracks",100,0.,20.);
1093  h_probeRefitVLogSig3D_ = ProbeFeatures.make<TH1F>("h_probeRefitVLogSig3D","log_{10}(3D DCA-Significance) (refit);log_{10}(d_{3D}/#sigma_{3D});tracks",100,-5.,4.);
1094  h_probeRefitVSigResZ_ = ProbeFeatures.make<TH1F>("h_probeRefitVSigResZ" ,"Longitudinal residual significance (refit);(z_{track} -z_{V_{fit}})/#sigma_{res_{z}};tracks",100,-8,8);
1095 
1096  h_probeHits_ = ProbeFeatures.make<TH1F>("h_probeNRechits" ,"N_{hits} ;N_{hits} ;tracks",40,-0.5,39.5);
1097  h_probeHits1D_ = ProbeFeatures.make<TH1F>("h_probeNRechits1D" ,"N_{hits} 1D ;N_{hits} 1D ;tracks",40,-0.5,39.5);
1098  h_probeHits2D_ = ProbeFeatures.make<TH1F>("h_probeNRechits2D" ,"N_{hits} 2D ;N_{hits} 2D ;tracks",40,-0.5,39.5);
1099  h_probeHitsInTIB_ = ProbeFeatures.make<TH1F>("h_probeNRechitsTIB" ,"N_{hits} TIB ;N_{hits} TIB;tracks",40,-0.5,39.5);
1100  h_probeHitsInTOB_ = ProbeFeatures.make<TH1F>("h_probeNRechitsTOB" ,"N_{hits} TOB ;N_{hits} TOB;tracks",40,-0.5,39.5);
1101  h_probeHitsInTID_ = ProbeFeatures.make<TH1F>("h_probeNRechitsTID" ,"N_{hits} TID ;N_{hits} TID;tracks",40,-0.5,39.5);
1102  h_probeHitsInTEC_ = ProbeFeatures.make<TH1F>("h_probeNRechitsTEC" ,"N_{hits} TEC ;N_{hits} TEC;tracks",40,-0.5,39.5);
1103  h_probeHitsInBPIX_ = ProbeFeatures.make<TH1F>("h_probeNRechitsBPIX","N_{hits} BPIX;N_{hits} BPIX;tracks",40,-0.5,39.5);
1104  h_probeHitsInFPIX_ = ProbeFeatures.make<TH1F>("h_probeNRechitsFPIX","N_{hits} FPIX;N_{hits} FPIX;tracks",40,-0.5,39.5);
1105 
1106  // refit vertex features
1107  TFileDirectory RefitVertexFeatures = fs->mkdir("RefitVertexFeatures");
1108  h_fitVtxNtracks_ = RefitVertexFeatures.make<TH1F>("h_fitVtxNtracks" ,"N_{trks} used in vertex fit;N^{fit}_{tracks};vertices" ,100,-0.5,99.5);
1109  h_fitVtxNdof_ = RefitVertexFeatures.make<TH1F>("h_fitVtxNdof" ,"N_{DOF} of vertex fit;N_{DOF} of refit vertex;vertices" ,100,-0.5,99.5);
1110  h_fitVtxChi2_ = RefitVertexFeatures.make<TH1F>("h_fitVtxChi2" ,"#chi^{2} of vertex fit;vertex #chi^{2};vertices" ,100,-0.5,99.5);
1111  h_fitVtxChi2ndf_ = RefitVertexFeatures.make<TH1F>("h_fitVtxChi2ndf" ,"#chi^{2}/ndf of vertex fit;vertex #chi^{2}/ndf;vertices" ,100,-0.5,9.5);
1112  h_fitVtxChi2Prob_ = RefitVertexFeatures.make<TH1F>("h_fitVtxChi2Prob" ,"Prob(#chi^{2},ndf) of vertex fit;Prob(#chi^{2},ndf);vertices",40,0.,1.);
1113  h_fitVtxTrackWeights_ = RefitVertexFeatures.make<TH1F>("h_fitVtxTrackWeights","track weights associated to track;track weights;tracks",40,0.,1.);
1114  h_fitVtxTrackAverageWeight_ = RefitVertexFeatures.make<TH1F>("h_fitVtxTrackAverageWeight_","average track weight per vertex;#LT track weight #GT;vertices",40,0.,1.);
1115 
1116  if(useTracksFromRecoVtx_) {
1117 
1118  TFileDirectory RecoVertexFeatures = fs->mkdir("RecoVertexFeatures");
1119  h_recoVtxNtracks_ = RecoVertexFeatures.make<TH1F>("h_recoVtxNtracks" ,"N^{vtx}_{trks};N^{vtx}_{trks};vertices" ,100,-0.5,99.5);
1120  h_recoVtxChi2ndf_ = RecoVertexFeatures.make<TH1F>("h_recoVtxChi2ndf" ,"#chi^{2}/ndf vtx;#chi^{2}/ndf vtx;vertices" ,10,-0.5,9.5);
1121  h_recoVtxChi2Prob_ = RecoVertexFeatures.make<TH1F>("h_recoVtxChi2Prob" ,"Prob(#chi^{2},ndf);Prob(#chi^{2},ndf);vertices",40,0.,1.);
1122  h_recoVtxSumPt_ = RecoVertexFeatures.make<TH1F>("h_recoVtxSumPt" ,"Sum(p^{trks}_{T});Sum(p^{trks}_{T});vertices" ,100,0.,200.);
1123 
1124  }
1125 
1126 
1127  TFileDirectory DA = fs->mkdir("DA");
1128  //DA.cd();
1130  //for(std::map<std::string,TH1*>::const_iterator hist=hDA.begin(); hist!=hDA.end(); hist++){
1131  //hist->second->SetDirectory(DA);
1132  // DA.make<TH1F>(hist->second);
1133  // }
1134 
1135  // initialize the residuals histograms
1136 
1137  float dxymax_phi = 2000;
1138  float dzmax_phi = 2000;
1139  float dxymax_eta = 3000;
1140  float dzmax_eta = 3000;
1141 
1142  float d3Dmax_phi = hypot(dxymax_phi,dzmax_phi);
1143  float d3Dmax_eta = hypot(dxymax_eta,dzmax_eta);
1144 
1145  const int mybins_ = 500;
1146 
1148  //
1149  // Unbiased track-to-vertex residuals
1150  // The vertex is refit without the probe track
1151  //
1153 
1154  TFileDirectory AbsTransPhiRes = fs->mkdir("Abs_Transv_Phi_Residuals");
1155  TFileDirectory AbsTransEtaRes = fs->mkdir("Abs_Transv_Eta_Residuals");
1156 
1157  TFileDirectory AbsLongPhiRes = fs->mkdir("Abs_Long_Phi_Residuals");
1158  TFileDirectory AbsLongEtaRes = fs->mkdir("Abs_Long_Eta_Residuals");
1159 
1160  TFileDirectory Abs3DPhiRes = fs->mkdir("Abs_3D_Phi_Residuals");
1161  TFileDirectory Abs3DEtaRes = fs->mkdir("Abs_3D_Eta_Residuals");
1162 
1163  TFileDirectory NormTransPhiRes = fs->mkdir("Norm_Transv_Phi_Residuals");
1164  TFileDirectory NormTransEtaRes = fs->mkdir("Norm_Transv_Eta_Residuals");
1165 
1166  TFileDirectory NormLongPhiRes = fs->mkdir("Norm_Long_Phi_Residuals");
1167  TFileDirectory NormLongEtaRes = fs->mkdir("Norm_Long_Eta_Residuals");
1168 
1169  TFileDirectory Norm3DPhiRes = fs->mkdir("Norm_3D_Phi_Residuals");
1170  TFileDirectory Norm3DEtaRes = fs->mkdir("Norm_3D_Eta_Residuals");
1171 
1172  TFileDirectory AbsDoubleDiffRes = fs->mkdir("Abs_DoubleDiffResiduals");
1173  TFileDirectory NormDoubleDiffRes = fs->mkdir("Norm_DoubleDiffResiduals");
1174 
1175  for ( int i=0; i<nBins_; ++i ) {
1176 
1177  float phiF = (-TMath::Pi()+i*phiSect_)*(180/TMath::Pi());
1178  float phiL = (-TMath::Pi()+(i+1)*phiSect_)*(180/TMath::Pi());
1179 
1180  float etaF=-etaOfProbe_+i*etaSect_;
1181  float etaL=-etaOfProbe_+(i+1)*etaSect_;
1182 
1183  // dxy vs phi and eta
1184 
1185  a_dxyPhiResiduals[i] = AbsTransPhiRes.make<TH1F>(Form("histo_dxy_phi_plot%i",i),
1186  Form("%.2f#circ<#varphi^{probe}_{tk}<%.2f#circ;d_{xy} [#mum];tracks",phiF,phiL),
1187  mybins_,-dxymax_phi,dxymax_phi);
1188 
1189  a_dxyEtaResiduals[i] = AbsTransEtaRes.make<TH1F>(Form("histo_dxy_eta_plot%i",i),
1190  Form("%.2f<#eta^{probe}_{tk}<%.2f;d_{xy} [#mum];tracks",etaF,etaL),
1191  mybins_,-dxymax_eta,dxymax_eta);
1192 
1193 
1194  // dx vs phi and eta
1195 
1196  a_dxPhiResiduals[i] = AbsTransPhiRes.make<TH1F>(Form("histo_dx_phi_plot%i",i),
1197  Form("%.2f#circ<#varphi^{probe}_{tk}<%.2f#circ;d_{x} [#mum];tracks",phiF,phiL),
1198  mybins_,-dxymax_phi,dxymax_phi);
1199 
1200  a_dxEtaResiduals[i] = AbsTransEtaRes.make<TH1F>(Form("histo_dx_eta_plot%i",i),
1201  Form("%.2f<#eta^{probe}_{tk}<%.2f;d_{x} [#mum];tracks",etaF,etaL),
1202  mybins_,-dxymax_eta,dxymax_eta);
1203 
1204 
1205  // dy vs phi and eta
1206 
1207  a_dyPhiResiduals[i] = AbsTransPhiRes.make<TH1F>(Form("histo_dy_phi_plot%i",i),
1208  Form("%.2f#circ<#varphi^{probe}_{tk}<%.2f#circ;d_{y} [#mum];tracks",phiF,phiL),
1209  mybins_,-dxymax_phi,dxymax_phi);
1210 
1211  a_dyEtaResiduals[i] = AbsTransEtaRes.make<TH1F>(Form("histo_dy_eta_plot%i",i),
1212  Form("%.2f<#eta^{probe}_{tk}<%.2f;d_{y} [#mum];tracks",etaF,etaL),
1213  mybins_,-dxymax_eta,dxymax_eta);
1214 
1215  // IP2D vs phi and eta
1216 
1217  a_IP2DPhiResiduals[i] = AbsTransPhiRes.make<TH1F>(Form("histo_IP2D_phi_plot%i",i),
1218  Form("%.2f#circ<#varphi^{probe}_{tk}<%.2f#circ;IP_{2D} [#mum];tracks",phiF,phiL),
1219  mybins_,-dxymax_phi,dxymax_phi);
1220 
1221  a_IP2DEtaResiduals[i] = AbsTransEtaRes.make<TH1F>(Form("histo_IP2D_eta_plot%i",i),
1222  Form("%.2f<#eta^{probe}_{tk}<%.2f;IP_{2D} [#mum];tracks",etaF,etaL),
1223  mybins_,-dxymax_eta,dxymax_eta);
1224 
1225  // IP3D vs phi and eta
1226 
1227  a_IP3DPhiResiduals[i] = Abs3DPhiRes.make<TH1F>(Form("histo_IP3D_phi_plot%i",i),
1228  Form("%.2f#circ<#varphi^{probe}_{tk}<%.2f#circ;IP_{3D} [#mum];tracks",phiF,phiL),
1229  mybins_,-dxymax_phi,dxymax_phi);
1230 
1231  a_IP3DEtaResiduals[i] = Abs3DEtaRes.make<TH1F>(Form("histo_IP3D_eta_plot%i",i),
1232  Form("%.2f<#eta^{probe}_{tk}<%.2f;IP_{3D} [#mum];tracks",etaF,etaL),
1233  mybins_,-dxymax_eta,dxymax_eta);
1234 
1235  // dz vs phi and eta
1236 
1237  a_dzPhiResiduals[i] = AbsLongPhiRes.make<TH1F>(Form("histo_dz_phi_plot%i",i),
1238  Form("%.2f#circ<#varphi^{probe}_{tk}<%.2f#circ;d_{z} [#mum];tracks",phiF,phiL),
1239  mybins_,-dzmax_phi,dzmax_phi);
1240 
1241  a_dzEtaResiduals[i] = AbsLongEtaRes.make<TH1F>(Form("histo_dz_eta_plot%i",i),
1242  Form("%.2f<#eta^{probe}_{tk}<%.2f;d_{z} [#mum];tracks",etaF,etaL),
1243  mybins_,-dzmax_eta,dzmax_eta);
1244 
1245 
1246  // resz vs phi and eta
1247 
1248  a_reszPhiResiduals[i] = AbsLongPhiRes.make<TH1F>(Form("histo_resz_phi_plot%i",i),
1249  Form("%.2f#circ<#varphi^{probe}_{tk}<%.2f#circ;z_{trk} - z_{vtx} [#mum];tracks",phiF,phiL),
1250  mybins_,-dzmax_phi,dzmax_phi);
1251 
1252  a_reszEtaResiduals[i] = AbsLongEtaRes.make<TH1F>(Form("histo_resz_eta_plot%i",i),
1253  Form("%.2f<#eta^{probe}_{tk}<%.2f;z_{trk} - z_{vtx} [#mum];tracks",etaF,etaL),
1254  mybins_,-dzmax_eta,dzmax_eta);
1255 
1256  // d3D vs phi and eta
1257 
1258  a_d3DPhiResiduals[i] = Abs3DPhiRes.make<TH1F>(Form("histo_d3D_phi_plot%i",i),
1259  Form("%.2f#circ<#varphi^{probe}_{tk}<%.2f#circ;d_{3D} [#mum];tracks",phiF,phiL),
1260  mybins_,0.,d3Dmax_phi);
1261 
1262  a_d3DEtaResiduals[i] = Abs3DEtaRes.make<TH1F>(Form("histo_d3D_eta_plot%i",i),
1263  Form("%.2f<#eta^{probe}_{tk}<%.2f;d_{3D} [#mum];tracks",etaF,etaL),
1264  mybins_,0.,d3Dmax_eta);
1265 
1266  // _ _ _ _ _ ___ _ _ _
1267  // | \| |___ _ _ _ __ __ _| (_)______ __| | | _ \___ __(_)__| |_ _ __ _| |___
1268  // | .` / _ \ '_| ' \/ _` | | |_ / -_) _` | | / -_|_-< / _` | || / _` | (_-<
1269  // |_|\_\___/_| |_|_|_\__,_|_|_/__\___\__,_| |_|_\___/__/_\__,_|\_,_\__,_|_/__/
1270  //
1271 
1272  // normalized dxy vs eta and phi
1273 
1274  n_dxyPhiResiduals[i] = NormTransPhiRes.make<TH1F>(Form("histo_norm_dxy_phi_plot%i",i),
1275  Form("%.2f#circ<#varphi^{probe}_{tk}<%.2f#circ;d_{xy}/#sigma_{d_{xy}};tracks",phiF,phiL),
1276  mybins_,-dxymax_phi/100.,dxymax_phi/100.);
1277 
1278  n_dxyEtaResiduals[i] = NormTransEtaRes.make<TH1F>(Form("histo_norm_dxy_eta_plot%i",i),
1279  Form("%.2f<#eta^{probe}_{tk}<%.2f;d_{xy}/#sigma_{d_{xy}};tracks",etaF,etaL),
1280  mybins_,-dxymax_eta/100.,dxymax_eta/100.);
1281 
1282  // normalized IP2d vs eta and phi
1283 
1284  n_IP2DPhiResiduals[i] = NormTransPhiRes.make<TH1F>(Form("histo_norm_IP2D_phi_plot%i",i),
1285  Form("%.2f#circ<#varphi^{probe}_{tk}<%.2f#circ;IP_{2D}/#sigma_{IP_{2D}};tracks",phiF,phiL),
1286  mybins_,-dxymax_phi/100.,dxymax_phi/100.);
1287 
1288  n_IP2DEtaResiduals[i] = NormTransEtaRes.make<TH1F>(Form("histo_norm_IP2D_eta_plot%i",i),
1289  Form("%.2f<#eta^{probe}_{tk}<%.2f;IP_{2D}/#sigma_{IP_{2D}};tracks",etaF,etaL),
1290  mybins_,-dxymax_eta/100.,dxymax_eta/100.);
1291 
1292  // normalized IP3d vs eta and phi
1293 
1294  n_IP3DPhiResiduals[i] = Norm3DPhiRes.make<TH1F>(Form("histo_norm_IP3D_phi_plot%i",i),
1295  Form("%.2f#circ<#varphi^{probe}_{tk}<%.2f#circ;IP_{3D}/#sigma_{IP_{3D}};tracks",phiF,phiL),
1296  mybins_,-dxymax_phi/100.,dxymax_phi/100.);
1297 
1298  n_IP3DEtaResiduals[i] = Norm3DEtaRes.make<TH1F>(Form("histo_norm_IP3D_eta_plot%i",i),
1299  Form("%.2f<#eta^{probe}_{tk}<%.2f;IP_{3D}/#sigma_{IP_{3D}};tracks",etaF,etaL),
1300  mybins_,-dxymax_eta/100.,dxymax_eta/100.);
1301 
1302  // normalized dz vs phi and eta
1303 
1304  n_dzPhiResiduals[i] = NormLongPhiRes.make<TH1F>(Form("histo_norm_dz_phi_plot%i",i),
1305  Form("%.2f#circ<#varphi^{probe}_{tk}<%.2f#circ;d_{z}/#sigma_{d_{z}};tracks",phiF,phiL),
1306  mybins_,-dzmax_phi/100.,dzmax_phi/100.);
1307 
1308  n_dzEtaResiduals[i] = NormLongEtaRes.make<TH1F>(Form("histo_norm_dz_eta_plot%i",i),
1309  Form("%.2f<#eta^{probe}_{tk}<%.2f;d_{z}/#sigma_{d_{z}};tracks",etaF,etaL),
1310  mybins_,-dzmax_eta/100.,dzmax_eta/100.);
1311 
1312  // pull of resz
1313 
1314  n_reszPhiResiduals[i] = NormLongPhiRes.make<TH1F>(Form("histo_norm_resz_phi_plot%i",i),
1315  Form("%.2f#circ<#varphi^{probe}_{tk}<%.2f#circ;(z_{trk}-z_{vtx})/#sigma_{res_{z}};tracks",phiF,phiL),
1316  mybins_,-dzmax_phi/100.,dzmax_phi/100.);
1317 
1318  n_reszEtaResiduals[i] = NormLongEtaRes.make<TH1F>(Form("histo_norm_resz_eta_plot%i",i),
1319  Form("%.2f<#eta^{probe}_{tk}<%.2f;(z_{trk}-z_{vtx})/#sigma_{res_{z}};tracks",etaF,etaL),
1320  mybins_,-dzmax_eta/100.,dzmax_eta/100.);
1321 
1322  // normalized d3D vs phi and eta
1323 
1324  n_d3DPhiResiduals[i] = Norm3DPhiRes.make<TH1F>(Form("histo_norm_d3D_phi_plot%i",i),
1325  Form("%.2f#circ<#varphi^{probe}_{tk}<%.2f#circ;d_{3D}/#sigma_{d_{3D}};tracks",phiF,phiL),
1326  mybins_,0.,d3Dmax_phi/100.);
1327 
1328  n_d3DEtaResiduals[i] = Norm3DEtaRes.make<TH1F>(Form("histo_norm_d3D_eta_plot%i",i),
1329  Form("%.2f<#eta^{probe}_{tk}<%.2f;d_{3D}/#sigma_{d_{3D}};tracks",etaF,etaL),
1330  mybins_,0.,d3Dmax_eta/100.);
1331 
1332  // ___ _ _ ___ _ __ __ ___ _ _ _
1333  // | \ ___ _ _| |__| |___| \(_)/ _|/ _| | _ \___ __(_)__| |_ _ __ _| |___
1334  // | |) / _ \ || | '_ \ / -_) |) | | _| _| | / -_|_-< / _` | || / _` | (_-<
1335  // |___/\___/\_,_|_.__/_\___|___/|_|_| |_| |_|_\___/__/_\__,_|\_,_\__,_|_/__/
1336 
1337  for ( int j=0; j<nBins_; ++j ) {
1338 
1339  a_dxyResidualsMap[i][j] = AbsDoubleDiffRes.make<TH1F>(Form("histo_dxy_eta_plot%i_phi_plot%i",i,j),
1340  Form("%.2f<#eta_{tk}<%.2f %.2f#circ<#varphi_{tk}<%.2f#circ;d_{xy};tracks",etaF,etaL,phiF,phiL),
1341  mybins_,-dzmax_eta,dzmax_eta);
1342 
1343  a_dzResidualsMap[i][j] = AbsDoubleDiffRes.make<TH1F>(Form("histo_dz_eta_plot%i_phi_plot%i",i,j),
1344  Form("%.2f<#eta_{tk}<%.2f %.2f#circ<#varphi_{tk}<%.2f#circ;d_{z};tracks",etaF,etaL,phiF,phiL),
1345  mybins_,-dzmax_eta,dzmax_eta);
1346 
1347  a_d3DResidualsMap[i][j] = AbsDoubleDiffRes.make<TH1F>(Form("histo_d3D_eta_plot%i_phi_plot%i",i,j),
1348  Form("%.2f<#eta_{tk}<%.2f %.2f#circ<#varphi_{tk}<%.2f#circ;d_{3D};tracks",etaF,etaL,phiF,phiL),
1349  mybins_,0.,d3Dmax_eta);
1350 
1351  n_dxyResidualsMap[i][j] = NormDoubleDiffRes.make<TH1F>(Form("histo_norm_dxy_eta_plot%i_phi_plot%i",i,j),
1352  Form("%.2f<#eta_{tk}<%.2f %.2f#circ<#varphi_{tk}<%.2f#circ;d_{xy}/#sigma_{d_{xy}};tracks",etaF,etaL,phiF,phiL),
1353  mybins_,-dzmax_eta/100,dzmax_eta/100);
1354 
1355  n_dzResidualsMap[i][j] = NormDoubleDiffRes.make<TH1F>(Form("histo_norm_dz_eta_plot%i_phi_plot%i",i,j),
1356  Form("%.2f<#eta_{tk}<%.2f %.2f#circ<#varphi_{tk}<%.2f#circ;d_{z}/#sigma_{d_{z}};tracks",etaF,etaL,phiF,phiL),
1357  mybins_,-dzmax_eta/100,dzmax_eta/100);
1358 
1359  n_d3DResidualsMap[i][j] = NormDoubleDiffRes.make<TH1F>(Form("histo_norm_d3D_eta_plot%i_phi_plot%i",i,j),
1360  Form("%.2f<#eta_{tk}<%.2f %.2f#circ<#varphi_{tk}<%.2f#circ;d_{3D}/#sigma_{d_{3D}};tracks",etaF,etaL,phiF,phiL),
1361  mybins_,0.,d3Dmax_eta);
1362 
1363  }
1364  }
1365 
1366  // declaration of the directories
1367 
1368  TFileDirectory BiasVsParameter = fs->mkdir("BiasVsParameter");
1369 
1370  a_dxyVsPhi = BiasVsParameter.make<TH2F>("h2_dxy_vs_phi","d_{xy} vs track #phi;track #phi [rad];track d_{xy}(PV) [#mum]",
1371  48,-TMath::Pi(),TMath::Pi(),mybins_,-dxymax_phi,dxymax_phi);
1372 
1373  a_dzVsPhi = BiasVsParameter.make<TH2F>("h2_dz_vs_phi","d_{z} vs track #phi;track #phi [rad];track d_{z}(PV) [#mum]",
1374  48,-TMath::Pi(),TMath::Pi(),mybins_,-dzmax_phi,dzmax_phi);
1375 
1376  n_dxyVsPhi = BiasVsParameter.make<TH2F>("h2_n_dxy_vs_phi","d_{xy}/#sigma_{d_{xy}} vs track #phi;track #phi [rad];track d_{xy}(PV)/#sigma_{d_{xy}}",
1377  48,-TMath::Pi(),TMath::Pi(),mybins_,-dxymax_phi/100.,dxymax_phi/100.);
1378 
1379  n_dzVsPhi = BiasVsParameter.make<TH2F>("h2_n_dz_vs_phi","d_{z}/#sigma_{d_{z}} vs track #phi;track #phi [rad];track d_{z}(PV)/#sigma_{d_{z}}",
1380  48,-TMath::Pi(),TMath::Pi(),mybins_,-dzmax_phi/100.,dzmax_phi/100.);
1381 
1382  a_dxyVsEta = BiasVsParameter.make<TH2F>("h2_dxy_vs_eta","d_{xy} vs track #eta;track #eta;track d_{xy}(PV) [#mum]",
1383  48,-etaOfProbe_,etaOfProbe_,mybins_,-dxymax_eta,dzmax_eta);
1384 
1385  a_dzVsEta = BiasVsParameter.make<TH2F>("h2_dz_vs_eta","d_{z} vs track #eta;track #eta;track d_{z}(PV) [#mum]",
1386  48,-etaOfProbe_,etaOfProbe_,mybins_,-dzmax_eta,dzmax_eta);
1387 
1388  n_dxyVsEta = BiasVsParameter.make<TH2F>("h2_n_dxy_vs_eta","d_{xy}/#sigma_{d_{xy}} vs track #eta;track #eta;track d_{xy}(PV)/#sigma_{d_{xy}}",
1389  48,-etaOfProbe_,etaOfProbe_,mybins_,-dxymax_eta/100.,dxymax_eta/100.);
1390 
1391  n_dzVsEta = BiasVsParameter.make<TH2F>("h2_n_dz_vs_eta","d_{z}/#sigma_{d_{z}} vs track #eta;track #eta;track d_{z}(PV)/#sigma_{d_{z}}",
1392  48,-etaOfProbe_,etaOfProbe_,mybins_,-dzmax_eta/100.,dzmax_eta/100.);
1393 
1394  TFileDirectory MeanTrendsDir = fs->mkdir("MeanTrends");
1395  TFileDirectory WidthTrendsDir = fs->mkdir("WidthTrends");
1396  TFileDirectory MedianTrendsDir = fs->mkdir("MedianTrends");
1397  TFileDirectory MADTrendsDir = fs->mkdir("MADTrends");
1398 
1399  TFileDirectory Mean2DMapsDir = fs->mkdir("MeanMaps");
1400  TFileDirectory Width2DMapsDir = fs->mkdir("WidthMaps");
1401 
1402  Double_t highedge=nBins_-0.5;
1403  Double_t lowedge=-0.5;
1404 
1405  // means and widths from the fit
1406 
1407  a_dxyPhiMeanTrend = MeanTrendsDir.make<TH1F> ("means_dxy_phi",
1408  "#LT d_{xy} #GT vs #phi sector;#varphi (sector) [degrees];#LT d_{xy} #GT [#mum]",
1409  nBins_,lowedge,highedge);
1410 
1411  a_dxyPhiWidthTrend = WidthTrendsDir.make<TH1F>("widths_dxy_phi",
1412  "#sigma_{d_{xy}} vs #phi sector;#varphi (sector) [degrees];#sigma_{d_{xy}} [#mum]",
1413  nBins_,lowedge,highedge);
1414 
1415  a_dzPhiMeanTrend = MeanTrendsDir.make<TH1F> ("means_dz_phi",
1416  "#LT d_{z} #GT vs #phi sector;#varphi (sector) [degrees];#LT d_{z} #GT [#mum]",
1417  nBins_,lowedge,highedge);
1418 
1419  a_dzPhiWidthTrend = WidthTrendsDir.make<TH1F>("widths_dz_phi","#sigma_{d_{z}} vs #phi sector;#varphi (sector) [degrees];#sigma_{d_{z}} [#mum]",
1420  nBins_,lowedge,highedge);
1421 
1422  a_dxyEtaMeanTrend = MeanTrendsDir.make<TH1F> ("means_dxy_eta",
1423  "#LT d_{xy} #GT vs #eta sector;#eta (sector);#LT d_{xy} #GT [#mum]",
1424  nBins_,lowedge,highedge);
1425 
1426  a_dxyEtaWidthTrend = WidthTrendsDir.make<TH1F>("widths_dxy_eta",
1427  "#sigma_{d_{xy}} vs #eta sector;#eta (sector);#sigma_{d_{xy}} [#mum]",
1428  nBins_,lowedge,highedge);
1429 
1430  a_dzEtaMeanTrend = MeanTrendsDir.make<TH1F> ("means_dz_eta",
1431  "#LT d_{z} #GT vs #eta sector;#eta (sector);#LT d_{z} #GT [#mum]"
1432  ,nBins_,lowedge,highedge);
1433 
1434  a_dzEtaWidthTrend = WidthTrendsDir.make<TH1F>("widths_dz_eta",
1435  "#sigma_{d_{xy}} vs #eta sector;#eta (sector);#sigma_{d_{z}} [#mum]",
1436  nBins_,lowedge,highedge);
1437 
1438  n_dxyPhiMeanTrend = MeanTrendsDir.make<TH1F> ("norm_means_dxy_phi",
1439  "#LT d_{xy}/#sigma_{d_{xy}} #GT vs #phi sector;#varphi (sector) [degrees];#LT d_{xy}/#sigma_{d_{xy}} #GT",
1440  nBins_,lowedge,highedge);
1441 
1442  n_dxyPhiWidthTrend = WidthTrendsDir.make<TH1F>("norm_widths_dxy_phi",
1443  "width(d_{xy}/#sigma_{d_{xy}}) vs #phi sector;#varphi (sector) [degrees]; width(d_{xy}/#sigma_{d_{xy}})",
1444  nBins_,lowedge,highedge);
1445 
1446  n_dzPhiMeanTrend = MeanTrendsDir.make<TH1F> ("norm_means_dz_phi",
1447  "#LT d_{z}/#sigma_{d_{z}} #GT vs #phi sector;#varphi (sector) [degrees];#LT d_{z}/#sigma_{d_{z}} #GT",
1448  nBins_,lowedge,highedge);
1449 
1450  n_dzPhiWidthTrend = WidthTrendsDir.make<TH1F>("norm_widths_dz_phi",
1451  "width(d_{z}/#sigma_{d_{z}}) vs #phi sector;#varphi (sector) [degrees];width(d_{z}/#sigma_{d_{z}})",
1452  nBins_,lowedge,highedge);
1453 
1454  n_dxyEtaMeanTrend = MeanTrendsDir.make<TH1F> ("norm_means_dxy_eta",
1455  "#LT d_{xy}/#sigma_{d_{xy}} #GT vs #eta sector;#eta (sector);#LT d_{xy}/#sigma_{d_{z}} #GT",
1456  nBins_,lowedge,highedge);
1457 
1458  n_dxyEtaWidthTrend = WidthTrendsDir.make<TH1F>("norm_widths_dxy_eta",
1459  "width(d_{xy}/#sigma_{d_{xy}}) vs #eta sector;#eta (sector);width(d_{xy}/#sigma_{d_{z}})",
1460  nBins_,lowedge,highedge);
1461 
1462  n_dzEtaMeanTrend = MeanTrendsDir.make<TH1F> ("norm_means_dz_eta",
1463  "#LT d_{z}/#sigma_{d_{z}} #GT vs #eta sector;#eta (sector);#LT d_{z}/#sigma_{d_{z}} #GT",
1464  nBins_,lowedge,highedge);
1465 
1466  n_dzEtaWidthTrend = WidthTrendsDir.make<TH1F>("norm_widths_dz_eta",
1467  "width(d_{z}/#sigma_{d_{z}}) vs #eta sector;#eta (sector);width(d_{z}/#sigma_{d_{z}})",
1468  nBins_,lowedge,highedge);
1469 
1470  // 2D maps
1471 
1472  a_dxyMeanMap = Mean2DMapsDir.make<TH2F> ("means_dxy_map",
1473  "#LT d_{xy} #GT map;#eta (sector);#varphi (sector) [degrees]",
1474  nBins_,lowedge,highedge,nBins_,lowedge,highedge);
1475 
1476  a_dzMeanMap = Mean2DMapsDir.make<TH2F> ("means_dz_map",
1477  "#LT d_{z} #GT map;#eta (sector);#varphi (sector) [degrees]",
1478  nBins_,lowedge,highedge,nBins_,lowedge,highedge);
1479 
1480  n_dxyMeanMap = Mean2DMapsDir.make<TH2F> ("norm_means_dxy_map",
1481  "#LT d_{xy}/#sigma_{d_{xy}} #GT map;#eta (sector);#varphi (sector) [degrees]",
1482  nBins_,lowedge,highedge,nBins_,lowedge,highedge);
1483 
1484  n_dzMeanMap = Mean2DMapsDir.make<TH2F> ("norm_means_dz_map",
1485  "#LT d_{z}/#sigma_{d_{z}} #GT map;#eta (sector);#varphi (sector) [degrees]",
1486  nBins_,lowedge,highedge,nBins_,lowedge,highedge);
1487 
1488  a_dxyWidthMap = Width2DMapsDir.make<TH2F> ("widths_dxy_map",
1489  "#sigma_{d_{xy}} map;#eta (sector);#varphi (sector) [degrees]",
1490  nBins_,lowedge,highedge,nBins_,lowedge,highedge);
1491 
1492  a_dzWidthMap = Width2DMapsDir.make<TH2F> ("widths_dz_map",
1493  "#sigma_{d_{z}} map;#eta (sector);#varphi (sector) [degrees]",
1494  nBins_,lowedge,highedge,nBins_,lowedge,highedge);
1495 
1496  n_dxyWidthMap = Width2DMapsDir.make<TH2F> ("norm_widths_dxy_map",
1497  "width(d_{xy}/#sigma_{d_{xy}}) map;#eta (sector);#varphi (sector) [degrees]",
1498  nBins_,lowedge,highedge,nBins_,lowedge,highedge);
1499 
1500  n_dzWidthMap = Width2DMapsDir.make<TH2F> ("norm_widths_dz_map",
1501  "width(d_{z}/#sigma_{d_{z}}) map;#eta (sector);#varphi (sector) [degrees]",
1502  nBins_,lowedge,highedge,nBins_,lowedge,highedge);
1503 
1504  // medians and MADs
1505 
1506  a_dxyPhiMedianTrend = MedianTrendsDir.make<TH1F>("medians_dxy_phi",
1507  "Median of d_{xy} vs #phi sector;#varphi (sector) [degrees];#mu_{1/2}(d_{xy}) [#mum]",
1508  nBins_,lowedge,highedge);
1509 
1510  a_dxyPhiMADTrend = MADTrendsDir.make<TH1F> ("MADs_dxy_phi",
1511  "Median absolute deviation of d_{xy} vs #phi sector;#varphi (sector) [degrees];MAD(d_{xy}) [#mum]",
1512  nBins_,lowedge,highedge);
1513 
1514  a_dzPhiMedianTrend = MedianTrendsDir.make<TH1F>("medians_dz_phi",
1515  "Median of d_{z} vs #phi sector;#varphi (sector) [degrees];#mu_{1/2}(d_{z}) [#mum]",
1516  nBins_,lowedge,highedge);
1517 
1518  a_dzPhiMADTrend = MADTrendsDir.make<TH1F> ("MADs_dz_phi",
1519  "Median absolute deviation of d_{z} vs #phi sector;#varphi (sector) [degrees];MAD(d_{z}) [#mum]",
1520  nBins_,lowedge,highedge);
1521 
1522  a_dxyEtaMedianTrend = MedianTrendsDir.make<TH1F>("medians_dxy_eta",
1523  "Median of d_{xy} vs #eta sector;#eta (sector);#mu_{1/2}(d_{xy}) [#mum]",
1524  nBins_,lowedge,highedge);
1525 
1526  a_dxyEtaMADTrend = MADTrendsDir.make<TH1F> ("MADs_dxy_eta",
1527  "Median absolute deviation of d_{xy} vs #eta sector;#eta (sector);MAD(d_{xy}) [#mum]",
1528  nBins_,lowedge,highedge);
1529 
1530  a_dzEtaMedianTrend = MedianTrendsDir.make<TH1F>("medians_dz_eta",
1531  "Median of d_{z} vs #eta sector;#eta (sector);#mu_{1/2}(d_{z}) [#mum]",
1532  nBins_,lowedge,highedge);
1533 
1534  a_dzEtaMADTrend = MADTrendsDir.make<TH1F> ("MADs_dz_eta",
1535  "Median absolute deviation of d_{z} vs #eta sector;#eta (sector);MAD(d_{z}) [#mum]",
1536  nBins_,lowedge,highedge);
1537 
1538  n_dxyPhiMedianTrend = MedianTrendsDir.make<TH1F>("norm_medians_dxy_phi",
1539  "Median of d_{xy}/#sigma_{d_{xy}} vs #phi sector;#varphi (sector) [degrees];#mu_{1/2}(d_{xy}/#sigma_{d_{xy}})",
1540  nBins_,lowedge,highedge);
1541 
1542  n_dxyPhiMADTrend = MADTrendsDir.make<TH1F> ("norm_MADs_dxy_phi",
1543  "Median absolute deviation of d_{xy}/#sigma_{d_{xy}} vs #phi sector;#varphi (sector) [degrees]; MAD(d_{xy}/#sigma_{d_{xy}})",
1544  nBins_,lowedge,highedge);
1545 
1546  n_dzPhiMedianTrend = MedianTrendsDir.make<TH1F>("norm_medians_dz_phi",
1547  "Median of d_{z}/#sigma_{d_{z}} vs #phi sector;#varphi (sector) [degrees];#mu_{1/2}(d_{z}/#sigma_{d_{z}})",
1548  nBins_,lowedge,highedge);
1549 
1550  n_dzPhiMADTrend = MADTrendsDir.make<TH1F> ("norm_MADs_dz_phi",
1551  "Median absolute deviation of d_{z}/#sigma_{d_{z}} vs #phi sector;#varphi (sector) [degrees];MAD(d_{z}/#sigma_{d_{z}})",
1552  nBins_,lowedge,highedge);
1553 
1554  n_dxyEtaMedianTrend = MedianTrendsDir.make<TH1F>("norm_medians_dxy_eta",
1555  "Median of d_{xy}/#sigma_{d_{xy}} vs #eta sector;#eta (sector);#mu_{1/2}(d_{xy}/#sigma_{d_{z}})",
1556  nBins_,lowedge,highedge);
1557 
1558  n_dxyEtaMADTrend = MADTrendsDir.make<TH1F> ("norm_MADs_dxy_eta",
1559  "Median absolute deviation of d_{xy}/#sigma_{d_{xy}} vs #eta sector;#eta (sector);MAD(d_{xy}/#sigma_{d_{z}})",
1560  nBins_,lowedge,highedge);
1561 
1562  n_dzEtaMedianTrend = MedianTrendsDir.make<TH1F>("norm_medians_dz_eta",
1563  "Median of d_{z}/#sigma_{d_{z}} vs #eta sector;#eta (sector);#mu_{1/2}(d_{z}/#sigma_{d_{z}})",
1564  nBins_,lowedge,highedge);
1565 
1566  n_dzEtaMADTrend = MADTrendsDir.make<TH1F> ("norm_MADs_dz_eta",
1567  "Median absolute deviation of d_{z}/#sigma_{d_{z}} vs #eta sector;#eta (sector);MAD(d_{z}/#sigma_{d_{z}})",
1568  nBins_,lowedge,highedge);
1569 
1570 
1572  //
1573  // plots of biased residuals
1574  // The vertex includes the probe track
1575  //
1577 
1578  if (useTracksFromRecoVtx_){
1579 
1580  TFileDirectory AbsTransPhiBiasRes = fs->mkdir("Abs_Transv_Phi_BiasResiduals");
1581  TFileDirectory AbsTransEtaBiasRes = fs->mkdir("Abs_Transv_Eta_BiasResiduals");
1582 
1583  TFileDirectory AbsLongPhiBiasRes = fs->mkdir("Abs_Long_Phi_BiasResiduals");
1584  TFileDirectory AbsLongEtaBiasRes = fs->mkdir("Abs_Long_Eta_BiasResiduals");
1585 
1586  TFileDirectory NormTransPhiBiasRes = fs->mkdir("Norm_Transv_Phi_BiasResiduals");
1587  TFileDirectory NormTransEtaBiasRes = fs->mkdir("Norm_Transv_Eta_BiasResiduals");
1588 
1589  TFileDirectory NormLongPhiBiasRes = fs->mkdir("Norm_Long_Phi_BiasResiduals");
1590  TFileDirectory NormLongEtaBiasRes = fs->mkdir("Norm_Long_Eta_BiasResiduals");
1591 
1592  TFileDirectory AbsDoubleDiffBiasRes = fs->mkdir("Abs_DoubleDiffBiasResiduals");
1593  TFileDirectory NormDoubleDiffBiasRes = fs->mkdir("Norm_DoubleDiffBiasResiduals");
1594 
1595  for ( int i=0; i<nBins_; ++i ) {
1596 
1597  float phiF = (-TMath::Pi()+i*phiSect_)*(180/TMath::Pi());
1598  float phiL = (-TMath::Pi()+(i+1)*phiSect_)*(180/TMath::Pi());
1599 
1600  float etaF=-etaOfProbe_+i*etaSect_;
1601  float etaL=-etaOfProbe_+(i+1)*etaSect_;
1602 
1603  a_dxyPhiBiasResiduals[i] = AbsTransPhiBiasRes.make<TH1F>(Form("histo_dxy_phi_plot%i",i),
1604  Form("%.2f#circ<#varphi^{probe}_{tk}<%.2f#circ;d_{xy} [#mum];tracks",phiF,phiL),
1605  mybins_,-dxymax_phi,dxymax_phi);
1606 
1607  a_dxyEtaBiasResiduals[i] = AbsTransEtaBiasRes.make<TH1F>(Form("histo_dxy_eta_plot%i",i),
1608  Form("%.2f<#eta^{probe}_{tk}<%.2f;d_{xy} [#mum];tracks",etaF,etaL),
1609  mybins_,-dxymax_eta,dxymax_eta);
1610 
1611  a_dzPhiBiasResiduals[i] = AbsLongPhiBiasRes.make<TH1F>(Form("histo_dz_phi_plot%i",i),
1612  Form("%.2f#circ<#varphi^{probe}_{tk}<%.2f #circ;d_{z} [#mum];tracks",phiF,phiL),
1613  mybins_,-dzmax_phi,dzmax_phi);
1614 
1615  a_dzEtaBiasResiduals[i] = AbsLongEtaBiasRes.make<TH1F>(Form("histo_dz_eta_plot%i",i),
1616  Form("%.2f<#eta^{probe}_{tk}<%.2f;d_{z} [#mum];tracks",etaF,etaL),
1617  mybins_,-dzmax_eta,dzmax_eta);
1618 
1619  n_dxyPhiBiasResiduals[i] = NormTransPhiBiasRes.make<TH1F>(Form("histo_norm_dxy_phi_plot%i",i),
1620  Form("%.2f#circ<#varphi^{probe}_{tk}<%.2f#circ;d_{xy}/#sigma_{d_{xy}};tracks",phiF,phiL),
1621  mybins_,-dxymax_phi/100.,dxymax_phi/100.);
1622 
1623  n_dxyEtaBiasResiduals[i] = NormTransEtaBiasRes.make<TH1F>(Form("histo_norm_dxy_eta_plot%i",i),
1624  Form("%.2f<#eta^{probe}_{tk}<%.2f;d_{xy}/#sigma_{d_{xy}};tracks",etaF,etaL),
1625  mybins_,-dxymax_eta/100.,dxymax_eta/100.);
1626 
1627  n_dzPhiBiasResiduals[i] = NormLongPhiBiasRes.make<TH1F>(Form("histo_norm_dz_phi_plot%i",i),
1628  Form("%.2f#circ<#varphi^{probe}_{tk}<%.2f#circ;d_{z}/#sigma_{d_{z}};tracks",phiF,phiL),
1629  mybins_,-dzmax_phi/100.,dzmax_phi/100.);
1630 
1631  n_dzEtaBiasResiduals[i] = NormLongEtaBiasRes.make<TH1F>(Form("histo_norm_dz_eta_plot%i",i),
1632  Form("%.2f<#eta^{probe}_{tk}<%.2f;d_{z}/#sigma_{d_{z}};tracks",etaF,etaL),
1633  mybins_,-dzmax_eta/100.,dzmax_eta/100.);
1634 
1635  for ( int j=0; j<nBins_; ++j ) {
1636 
1637  a_dxyBiasResidualsMap[i][j] = AbsDoubleDiffBiasRes.make<TH1F>(Form("histo_dxy_eta_plot%i_phi_plot%i",i,j),
1638  Form("%.2f<#eta_{tk}<%.2f %.2f#circ<#varphi_{tk}<%.2f#circ;d_{xy} [#mum];tracks",etaF,etaL,phiF,phiL),
1639  mybins_,-dzmax_eta,dzmax_eta);
1640 
1641  a_dzBiasResidualsMap[i][j] = AbsDoubleDiffBiasRes.make<TH1F>(Form("histo_dxy_eta_plot%i_phi_plot%i",i,j),
1642  Form("%.2f<#eta_{tk}<%.2f %.2f#circ<#varphi_{tk}<%.2f#circ;d_{z} [#mum];tracks",etaF,etaL,phiF,phiL),
1643  mybins_,-dzmax_eta,dzmax_eta);
1644 
1645  n_dxyBiasResidualsMap[i][j] = NormDoubleDiffBiasRes.make<TH1F>(Form("histo_norm_dxy_eta_plot%i_phi_plot%i",i,j),
1646  Form("%.2f<#eta_{tk}<%.2f %.2f#circ<#varphi_{tk}<%.2f#circ;d_{xy}/#sigma_{d_{xy}};tracks",etaF,etaL,phiF,phiL),
1647  mybins_,-dzmax_eta/100,dzmax_eta/100);
1648 
1649  n_dzBiasResidualsMap[i][j] = NormDoubleDiffBiasRes.make<TH1F>(Form("histo_norm_dxy_eta_plot%i_phi_plot%i",i,j),
1650  Form("%.2f<#eta_{tk}<%.2f %.2f#circ<#varphi_{tk}<%.2f#circ;d_{z}/#sigma_{d_{z}};tracks",etaF,etaL,phiF,phiL),
1651  mybins_,-dzmax_eta/100,dzmax_eta/100);
1652  }
1653  }
1654 
1655  // declaration of the directories
1656 
1657  TFileDirectory MeanBiasTrendsDir = fs->mkdir("MeanBiasTrends");
1658  TFileDirectory WidthBiasTrendsDir = fs->mkdir("WidthBiasTrends");
1659  TFileDirectory MedianBiasTrendsDir = fs->mkdir("MedianBiasTrends");
1660  TFileDirectory MADBiasTrendsDir = fs->mkdir("MADBiasTrends");
1661 
1662  TFileDirectory Mean2DBiasMapsDir = fs->mkdir("MeanBiasMaps");
1663  TFileDirectory Width2DBiasMapsDir = fs->mkdir("WidthBiasMaps");
1664 
1665  // means and widths from the fit
1666 
1667  a_dxyPhiMeanBiasTrend = MeanBiasTrendsDir.make<TH1F> ("means_dxy_phi",
1668  "#LT d_{xy} #GT vs #phi sector;#varphi (sector) [degrees];#LT d_{xy} #GT [#mum]",
1669  nBins_,lowedge,highedge);
1670 
1671  a_dxyPhiWidthBiasTrend = WidthBiasTrendsDir.make<TH1F>("widths_dxy_phi",
1672  "#sigma_{d_{xy}} vs #phi sector;#varphi (sector) [degrees];#sigma_{d_{xy}} [#mum]",
1673  nBins_,lowedge,highedge);
1674 
1675  a_dzPhiMeanBiasTrend = MeanBiasTrendsDir.make<TH1F> ("means_dz_phi",
1676  "#LT d_{z} #GT vs #phi sector;#varphi (sector) [degrees];#LT d_{z} #GT [#mum]",
1677  nBins_,lowedge,highedge);
1678 
1679  a_dzPhiWidthBiasTrend = WidthBiasTrendsDir.make<TH1F>("widths_dz_phi",
1680  "#sigma_{d_{z}} vs #phi sector;#varphi (sector) [degrees];#sigma_{d_{z}} [#mum]",
1681  nBins_,lowedge,highedge);
1682 
1683  a_dxyEtaMeanBiasTrend = MeanBiasTrendsDir.make<TH1F> ("means_dxy_eta",
1684  "#LT d_{xy} #GT vs #eta sector;#eta (sector);#LT d_{xy} #GT [#mum]",
1685  nBins_,lowedge,highedge);
1686 
1687  a_dxyEtaWidthBiasTrend = WidthBiasTrendsDir.make<TH1F>("widths_dxy_eta",
1688  "#sigma_{d_{xy}} vs #eta sector;#eta (sector);#sigma_{d_{xy}} [#mum]",
1689  nBins_,lowedge,highedge);
1690 
1691  a_dzEtaMeanBiasTrend = MeanBiasTrendsDir.make<TH1F> ("means_dz_eta",
1692  "#LT d_{z} #GT vs #eta sector;#eta (sector);#LT d_{z} #GT [#mum]",
1693  nBins_,lowedge,highedge);
1694 
1695  a_dzEtaWidthBiasTrend = WidthBiasTrendsDir.make<TH1F>("widths_dz_eta",
1696  "#sigma_{d_{xy}} vs #eta sector;#eta (sector);#sigma_{d_{z}} [#mum]",
1697  nBins_,lowedge,highedge);
1698 
1699  n_dxyPhiMeanBiasTrend = MeanBiasTrendsDir.make<TH1F> ("norm_means_dxy_phi",
1700  "#LT d_{xy}/#sigma_{d_{xy}} #GT vs #phi sector;#varphi (sector) [degrees];#LT d_{xy}/#sigma_{d_{xy}} #GT",
1701  nBins_,lowedge,highedge);
1702 
1703  n_dxyPhiWidthBiasTrend = WidthBiasTrendsDir.make<TH1F>("norm_widths_dxy_phi",
1704  "width(d_{xy}/#sigma_{d_{xy}}) vs #phi sector;#varphi (sector) [degrees]; width(d_{xy}/#sigma_{d_{xy}})",
1705  nBins_,lowedge,highedge);
1706 
1707  n_dzPhiMeanBiasTrend = MeanBiasTrendsDir.make<TH1F> ("norm_means_dz_phi",
1708  "#LT d_{z}/#sigma_{d_{z}} #GT vs #phi sector;#varphi (sector) [degrees];#LT d_{z}/#sigma_{d_{z}} #GT",
1709  nBins_,lowedge,highedge);
1710 
1711  n_dzPhiWidthBiasTrend = WidthBiasTrendsDir.make<TH1F>("norm_widths_dz_phi",
1712  "width(d_{z}/#sigma_{d_{z}}) vs #phi sector;#varphi (sector) [degrees];width(d_{z}/#sigma_{d_{z}})",
1713  nBins_,lowedge,highedge);
1714 
1715  n_dxyEtaMeanBiasTrend = MeanBiasTrendsDir.make<TH1F> ("norm_means_dxy_eta",
1716  "#LT d_{xy}/#sigma_{d_{xy}} #GT vs #eta sector;#eta (sector);#LT d_{xy}/#sigma_{d_{z}} #GT",
1717  nBins_,lowedge,highedge);
1718 
1719  n_dxyEtaWidthBiasTrend = WidthBiasTrendsDir.make<TH1F>("norm_widths_dxy_eta",
1720  "width(d_{xy}/#sigma_{d_{xy}}) vs #eta sector;#eta (sector);width(d_{xy}/#sigma_{d_{z}})",
1721  nBins_,lowedge,highedge);
1722 
1723  n_dzEtaMeanBiasTrend = MeanBiasTrendsDir.make<TH1F> ("norm_means_dz_eta",
1724  "#LT d_{z}/#sigma_{d_{z}} #GT vs #eta sector;#eta (sector);#LT d_{z}/#sigma_{d_{z}} #GT",
1725  nBins_,lowedge,highedge);
1726 
1727  n_dzEtaWidthBiasTrend = WidthBiasTrendsDir.make<TH1F>("norm_widths_dz_eta",
1728  "width(d_{z}/#sigma_{d_{z}}) vs #eta sector;#eta (sector);width(d_{z}/#sigma_{d_{z}})",
1729  nBins_,lowedge,highedge);
1730 
1731  // 2D maps
1732 
1733  a_dxyMeanBiasMap = Mean2DBiasMapsDir.make<TH2F> ("means_dxy_map",
1734  "#LT d_{xy} #GT map;#eta (sector);#varphi (sector) [degrees]",
1735  nBins_,lowedge,highedge,nBins_,lowedge,highedge);
1736 
1737  a_dzMeanBiasMap = Mean2DBiasMapsDir.make<TH2F> ("means_dz_map",
1738  "#LT d_{z} #GT map;#eta (sector);#varphi (sector) [degrees]",
1739  nBins_,lowedge,highedge,nBins_,lowedge,highedge);
1740 
1741  n_dxyMeanBiasMap = Mean2DBiasMapsDir.make<TH2F> ("norm_means_dxy_map",
1742  "#LT d_{xy}/#sigma_{d_{xy}} #GT map;#eta (sector);#varphi (sector) [degrees]",
1743  nBins_,lowedge,highedge,nBins_,lowedge,highedge);
1744 
1745  n_dzMeanBiasMap = Mean2DBiasMapsDir.make<TH2F> ("norm_means_dz_map",
1746  "#LT d_{z}/#sigma_{d_{z}} #GT map;#eta (sector);#varphi (sector) [degrees]",
1747  nBins_,lowedge,highedge,nBins_,lowedge,highedge);
1748 
1749  a_dxyWidthBiasMap = Width2DBiasMapsDir.make<TH2F> ("widths_dxy_map",
1750  "#sigma_{d_{xy}} map;#eta (sector);#varphi (sector) [degrees]",
1751  nBins_,lowedge,highedge,nBins_,lowedge,highedge);
1752 
1753  a_dzWidthBiasMap = Width2DBiasMapsDir.make<TH2F> ("widths_dz_map",
1754  "#sigma_{d_{z}} map;#eta (sector);#varphi (sector) [degrees]",
1755  nBins_,lowedge,highedge,nBins_,lowedge,highedge);
1756 
1757  n_dxyWidthBiasMap = Width2DBiasMapsDir.make<TH2F> ("norm_widths_dxy_map",
1758  "width(d_{xy}/#sigma_{d_{xy}}) map;#eta (sector);#varphi (sector) [degrees]",
1759  nBins_,lowedge,highedge,nBins_,lowedge,highedge);
1760 
1761  n_dzWidthBiasMap = Width2DBiasMapsDir.make<TH2F> ("norm_widths_dz_map",
1762  "width(d_{z}/#sigma_{d_{z}}) map;#eta (sector);#varphi (sector) [degrees]",
1763  nBins_,lowedge,highedge,nBins_,lowedge,highedge);
1764 
1765  // medians and MADs
1766 
1767  a_dxyPhiMedianBiasTrend = MedianBiasTrendsDir.make<TH1F>("medians_dxy_phi",
1768  "Median of d_{xy} vs #phi sector;#varphi (sector) [degrees];#mu_{1/2}(d_{xy}) [#mum]",
1769  nBins_,lowedge,highedge);
1770 
1771  a_dxyPhiMADBiasTrend = MADBiasTrendsDir.make<TH1F> ("MADs_dxy_phi",
1772  "Median absolute deviation of d_{xy} vs #phi sector;#varphi (sector) [degrees];MAD(d_{xy}) [#mum]",
1773  nBins_,lowedge,highedge);
1774 
1775  a_dzPhiMedianBiasTrend = MedianBiasTrendsDir.make<TH1F>("medians_dz_phi",
1776  "Median of d_{z} vs #phi sector;#varphi (sector) [degrees];#mu_{1/2}(d_{z}) [#mum]",
1777  nBins_,lowedge,highedge);
1778 
1779  a_dzPhiMADBiasTrend = MADBiasTrendsDir.make<TH1F> ("MADs_dz_phi",
1780  "Median absolute deviation of d_{z} vs #phi sector;#varphi (sector) [degrees];MAD(d_{z}) [#mum]",
1781  nBins_,lowedge,highedge);
1782 
1783  a_dxyEtaMedianBiasTrend = MedianBiasTrendsDir.make<TH1F>("medians_dxy_eta",
1784  "Median of d_{xy} vs #eta sector;#eta (sector);#mu_{1/2}(d_{xy}) [#mum]",
1785  nBins_,lowedge,highedge);
1786 
1787  a_dxyEtaMADBiasTrend = MADBiasTrendsDir.make<TH1F> ("MADs_dxy_eta",
1788  "Median absolute deviation of d_{xy} vs #eta sector;#eta (sector);MAD(d_{xy}) [#mum]",
1789  nBins_,lowedge,highedge);
1790 
1791  a_dzEtaMedianBiasTrend = MedianBiasTrendsDir.make<TH1F>("medians_dz_eta",
1792  "Median of d_{z} vs #eta sector;#eta (sector);#mu_{1/2}(d_{z}) [#mum]",
1793  nBins_,lowedge,highedge);
1794 
1795  a_dzEtaMADBiasTrend = MADBiasTrendsDir.make<TH1F> ("MADs_dz_eta",
1796  "Median absolute deviation of d_{z} vs #eta sector;#eta (sector);MAD(d_{z}) [#mum]",
1797  nBins_,lowedge,highedge);
1798 
1799  n_dxyPhiMedianBiasTrend = MedianBiasTrendsDir.make<TH1F>("norm_medians_dxy_phi",
1800  "Median of d_{xy}/#sigma_{d_{xy}} vs #phi sector;#varphi (sector) [degrees];#mu_{1/2}(d_{xy}/#sigma_{d_{xy}})",
1801  nBins_,lowedge,highedge);
1802 
1803  n_dxyPhiMADBiasTrend = MADBiasTrendsDir.make<TH1F> ("norm_MADs_dxy_phi",
1804  "Median absolute deviation of d_{xy}/#sigma_{d_{xy}} vs #phi sector;#varphi (sector) [degrees]; MAD(d_{xy}/#sigma_{d_{xy}})",
1805  nBins_,lowedge,highedge);
1806 
1807  n_dzPhiMedianBiasTrend = MedianBiasTrendsDir.make<TH1F>("norm_medians_dz_phi",
1808  "Median of d_{z}/#sigma_{d_{z}} vs #phi sector;#varphi (sector) [degrees];#mu_{1/2}(d_{z}/#sigma_{d_{z}})",
1809  nBins_,lowedge,highedge);
1810 
1811  n_dzPhiMADBiasTrend = MADBiasTrendsDir.make<TH1F> ("norm_MADs_dz_phi",
1812  "Median absolute deviation of d_{z}/#sigma_{d_{z}} vs #phi sector;#varphi (sector) [degrees];MAD(d_{z}/#sigma_{d_{z}})",
1813  nBins_,lowedge,highedge);
1814 
1815  n_dxyEtaMedianBiasTrend = MedianBiasTrendsDir.make<TH1F>("norm_medians_dxy_eta",
1816  "Median of d_{xy}/#sigma_{d_{xy}} vs #eta sector;#eta (sector);#mu_{1/2}(d_{xy}/#sigma_{d_{z}})",
1817  nBins_,lowedge,highedge);
1818 
1819  n_dxyEtaMADBiasTrend = MADBiasTrendsDir.make<TH1F> ("norm_MADs_dxy_eta",
1820  "Median absolute deviation of d_{xy}/#sigma_{d_{xy}} vs #eta sector;#eta (sector);MAD(d_{xy}/#sigma_{d_{z}})",
1821  nBins_,lowedge,highedge);
1822 
1823  n_dzEtaMedianBiasTrend = MedianBiasTrendsDir.make<TH1F>("norm_medians_dz_eta",
1824  "Median of d_{z}/#sigma_{d_{z}} vs #eta sector;#eta (sector);#mu_{1/2}(d_{z}/#sigma_{d_{z}})",
1825  nBins_,lowedge,highedge);
1826 
1827  n_dzEtaMADBiasTrend = MADBiasTrendsDir.make<TH1F> ("norm_MADs_dz_eta",
1828  "Median absolute deviation of d_{z}/#sigma_{d_{z}} vs #eta sector;#eta (sector);MAD(d_{z}/#sigma_{d_{z}})",
1829  nBins_,lowedge,highedge);
1830 
1831  }
1832 }
1833 // ------------ method called once each job just after ending the event loop ------------
1835 {
1836 
1837  edm::LogInfo("PrimaryVertexValidation")
1838  <<"######################################\n"
1839  <<"# PrimaryVertexValidation::endJob()\n"
1840  <<"# Number of analyzed events: "<<Nevt_<<"\n"
1841  <<"######################################";
1842 
1844 
1849 
1854 
1859 
1864 
1865  // medians and MADs
1866 
1871 
1876 
1881 
1886 
1887  // 2d Maps
1888 
1893 
1898 
1899  }
1900 
1901  // do profiles
1902 
1907 
1912 
1917 
1922 
1923  // medians and MADs
1924 
1929 
1934 
1939 
1944 
1945  // 2D Maps
1946 
1951 
1956 
1957 }
1958 
1959 //*************************************************************
1961 //*************************************************************
1962 {
1963  nTracks_ = 0;
1964  nClus_ = 0;
1966  RunNumber_ =0;
1968  xOfflineVertex_ =-999.;
1969  yOfflineVertex_ =-999.;
1970  zOfflineVertex_ =-999.;
1971  xErrOfflineVertex_=0.;
1972  yErrOfflineVertex_=0.;
1973  zErrOfflineVertex_=0.;
1974  BSx0_ = -999.;
1975  BSy0_ = -999.;
1976  BSz0_ = -999.;
1977  Beamsigmaz_=-999.;
1978  Beamdxdz_=-999.;
1979  BeamWidthX_=-999.;
1980  BeamWidthY_=-999.;
1981  wxy2_=-999.;
1982 
1983  for ( int i=0; i<nMaxtracks_; ++i ) {
1984 
1985  pt_[i] = 0;
1986  p_[i] = 0;
1987  nhits_[i] = 0;
1988  nhits1D_[i] = 0;
1989  nhits2D_[i] = 0;
1990  nhitsBPIX_[i] = 0;
1991  nhitsFPIX_[i] = 0;
1992  nhitsTIB_[i] = 0;
1993  nhitsTID_[i] = 0;
1994  nhitsTOB_[i] = 0;
1995  nhitsTEC_[i] = 0;
1996  isHighPurity_[i] = 0;
1997  eta_[i] = 0;
1998  theta_[i] = 0;
1999  phi_[i] = 0;
2000  chi2_[i] = 0;
2001  chi2ndof_[i] = 0;
2002  charge_[i] = 0;
2003  qoverp_[i] = 0;
2004  dz_[i] = 0;
2005  dxy_[i] = 0;
2006  dzBs_[i] = 0;
2007  dxyBs_[i] = 0;
2008  xPCA_[i] = 0;
2009  yPCA_[i] = 0;
2010  zPCA_[i] = 0;
2011  xUnbiasedVertex_[i] =0;
2012  yUnbiasedVertex_[i] =0;
2013  zUnbiasedVertex_[i] =0;
2017  DOFUnbiasedVertex_[i]=0;
2020  dxyFromMyVertex_[i]=0;
2021  dzFromMyVertex_[i]=0;
2022  d3DFromMyVertex_[i]=0;
2026  IPTsigFromMyVertex_[i]=0;
2027  IPLsigFromMyVertex_[i]=0;
2029  hasRecVertex_[i] = 0;
2030  isGoodTrack_[i] = 0;
2031  }
2032 }
2033 
2034 //*************************************************************
2035 std::pair<Double_t,Double_t> PrimaryVertexValidation::getMedian(TH1F *histo)
2036 //*************************************************************
2037 {
2038  Double_t median = 999;
2039  int nbins = histo->GetNbinsX();
2040 
2041  //extract median from histogram
2042  double *x = new double[nbins];
2043  double *y = new double[nbins];
2044  for (int j = 0; j < nbins; j++) {
2045  x[j] = histo->GetBinCenter(j+1);
2046  y[j] = histo->GetBinContent(j+1);
2047  }
2048  median = TMath::Median(nbins, x, y);
2049 
2050  delete[] x; x = 0;
2051  delete[] y; y = 0;
2052 
2053  std::pair<Double_t,Double_t> result;
2054  result = std::make_pair(median,median/TMath::Sqrt(histo->GetEntries()));
2055 
2056  return result;
2057 
2058 }
2059 
2060 //*************************************************************
2061 std::pair<Double_t,Double_t> PrimaryVertexValidation::getMAD(TH1F *histo)
2062 //*************************************************************
2063 {
2064 
2065  int nbins = histo->GetNbinsX();
2066  Double_t median = getMedian(histo).first;
2067  Double_t x_lastBin = histo->GetBinLowEdge(nbins+1);
2068  const char *HistoName =histo->GetName();
2069  TString Finalname = Form("resMed%s",HistoName);
2070  TH1F *newHisto = new TH1F(Finalname,Finalname,nbins,0.,x_lastBin);
2071  Double_t *residuals = new Double_t[nbins];
2072  Double_t *weights = new Double_t[nbins];
2073 
2074  for (int j = 0; j < nbins; j++) {
2075  residuals[j] = TMath::Abs(median - histo->GetBinCenter(j+1));
2076  weights[j]=histo->GetBinContent(j+1);
2077  newHisto->Fill(residuals[j],weights[j]);
2078  }
2079 
2080  Double_t theMAD = (getMedian(newHisto).first)*1.4826;
2081 
2082  delete[] residuals; residuals=0;
2083  delete[] weights; weights=0;
2084  newHisto->Delete("");
2085 
2086  std::pair<Double_t,Double_t> result;
2087  result = std::make_pair(theMAD,theMAD/histo->GetEntries());
2088 
2089  return result;
2090 
2091 }
2092 
2093 //*************************************************************
2094 std::pair<std::pair<Double_t,Double_t>, std::pair<Double_t,Double_t> > PrimaryVertexValidation::fitResiduals(TH1 *hist)
2095 //*************************************************************
2096 {
2097  //float fitResult(9999);
2098  //if (hist->GetEntries() < 20) return ;
2099 
2100  float mean = hist->GetMean();
2101  float sigma = hist->GetRMS();
2102 
2103  TF1 func("tmp", "gaus", mean - 1.5*sigma, mean + 1.5*sigma);
2104  if (0 == hist->Fit(&func,"QNR")) { // N: do not blow up file by storing fit!
2105  mean = func.GetParameter(1);
2106  sigma = func.GetParameter(2);
2107  // second fit: three sigma of first fit around mean of first fit
2108  func.SetRange(mean - 2*sigma, mean + 2*sigma);
2109  // I: integral gives more correct results if binning is too wide
2110  // L: Likelihood can treat empty bins correctly (if hist not weighted...)
2111  if (0 == hist->Fit(&func, "Q0LR")) {
2112  if (hist->GetFunction(func.GetName())) { // Take care that it is later on drawn:
2113  hist->GetFunction(func.GetName())->ResetBit(TF1::kNotDraw);
2114  }
2115  }
2116  }
2117 
2118  float res_mean = func.GetParameter(1);
2119  float res_width = func.GetParameter(2);
2120 
2121  float res_mean_err = func.GetParError(1);
2122  float res_width_err = func.GetParError(2);
2123 
2124  std::pair<Double_t,Double_t> resultM;
2125  std::pair<Double_t,Double_t> resultW;
2126 
2127  resultM = std::make_pair(res_mean,res_mean_err);
2128  resultW = std::make_pair(res_width,res_width_err);
2129 
2130  std::pair<std::pair<Double_t,Double_t>, std::pair<Double_t,Double_t> > result;
2131 
2132  result = std::make_pair(resultM,resultW);
2133  return result;
2134 }
2135 
2136 //*************************************************************
2137 void PrimaryVertexValidation::fillTrendPlot(TH1F* trendPlot, TH1F* residualsPlot[100], TString fitPar_, TString var_)
2138 //*************************************************************
2139 {
2140 
2141  for ( int i=0; i<nBins_; ++i ) {
2142 
2143  char phipositionString[129];
2144  float phiInterval = phiSect_*(180/TMath::Pi());
2145  float phiposition = (-180+i*phiInterval)+(phiInterval/2);
2146  sprintf(phipositionString,"%.f",phiposition);
2147 
2148  char etapositionString[129];
2149  float etaposition = (-etaOfProbe_+i*etaSect_)+(etaSect_/2);
2150  sprintf(etapositionString,"%.1f",etaposition);
2151 
2152  if(fitPar_=="mean"){
2153  float mean_ = fitResiduals(residualsPlot[i]).first.first;
2154  float meanErr_ = fitResiduals(residualsPlot[i]).first.second;
2155  trendPlot->SetBinContent(i+1,mean_);
2156  trendPlot->SetBinError(i+1,meanErr_);
2157  } else if (fitPar_=="width"){
2158  float width_ = fitResiduals(residualsPlot[i]).second.first;
2159  float widthErr_ = fitResiduals(residualsPlot[i]).second.second;
2160  trendPlot->SetBinContent(i+1,width_);
2161  trendPlot->SetBinError(i+1,widthErr_);
2162  } else if (fitPar_=="median"){
2163  float median_ = getMedian(residualsPlot[i]).first;
2164  float medianErr_ = getMedian(residualsPlot[i]).second;
2165  trendPlot->SetBinContent(i+1,median_);
2166  trendPlot->SetBinError(i+1,medianErr_);
2167  } else if (fitPar_=="mad"){
2168  float mad_ = getMAD(residualsPlot[i]).first;
2169  float madErr_ = getMAD(residualsPlot[i]).second;
2170  trendPlot->SetBinContent(i+1,mad_);
2171  trendPlot->SetBinError(i+1,madErr_);
2172  } else {
2173  std::cout<<"PrimaryVertexValidation::fillTrendPlot() "<<fitPar_<<" unknown estimator!"<<std::endl;
2174  }
2175 
2176  if(var_=="eta"){
2177  trendPlot->GetXaxis()->SetBinLabel(i+1,etapositionString);
2178  } else if(var_=="phi"){
2179  trendPlot->GetXaxis()->SetBinLabel(i+1,phipositionString);
2180  } else {
2181  std::cout<<"PrimaryVertexValidation::fillTrendPlot() "<<var_<<" unknown track parameter!"<<std::endl;
2182  }
2183  }
2184 }
2185 
2186 //*************************************************************
2187 void PrimaryVertexValidation::fillMap(TH2F* trendMap, TH1F* residualsMapPlot[100][100], TString fitPar_)
2188 //*************************************************************
2189 {
2190 
2191  for ( int i=0; i<nBins_; ++i ) {
2192 
2193  char phipositionString[129];
2194  float phiInterval = phiSect_*(180/TMath::Pi());
2195  float phiposition = (-180+i*phiInterval)+(phiInterval/2);
2196  sprintf(phipositionString,"%.f",phiposition);
2197 
2198  trendMap->GetYaxis()->SetBinLabel(i+1,phipositionString);
2199 
2200  for ( int j=0; j<nBins_; ++j ) {
2201 
2202  char etapositionString[129];
2203  float etaposition = (-etaOfProbe_+j*etaSect_)+(etaSect_/2);
2204  sprintf(etapositionString,"%.1f",etaposition);
2205 
2206  if(i==0) { trendMap->GetXaxis()->SetBinLabel(j+1,etapositionString); }
2207 
2208  if(fitPar_=="mean"){
2209  float mean_ = fitResiduals(residualsMapPlot[i][j]).first.first;
2210  float meanErr_ = fitResiduals(residualsMapPlot[i][j]).first.second;
2211  trendMap->SetBinContent(j+1,i+1,mean_);
2212  trendMap->SetBinError(j+1,i+1,meanErr_);
2213  } else if (fitPar_=="width"){
2214  float width_ = fitResiduals(residualsMapPlot[i][j]).second.first;
2215  float widthErr_ = fitResiduals(residualsMapPlot[i][j]).second.second;
2216  trendMap->SetBinContent(j+1,i+1,width_);
2217  trendMap->SetBinError(j+1,i+1,widthErr_);
2218  } else if (fitPar_=="median"){
2219  float median_ = getMedian(residualsMapPlot[i][j]).first;
2220  float medianErr_ = getMedian(residualsMapPlot[i][j]).second;
2221  trendMap->SetBinContent(j+1,i+1,median_);
2222  trendMap->SetBinError(j+1,i+1,medianErr_);
2223  } else if (fitPar_=="mad"){
2224  float mad_ = getMAD(residualsMapPlot[i][j]).first;
2225  float madErr_ = getMAD(residualsMapPlot[i][j]).second;
2226  trendMap->SetBinContent(j+1,i+1,mad_);
2227  trendMap->SetBinError(j+1,i+1,madErr_);
2228  } else {
2229  std::cout<<"PrimaryVertexValidation::fillMap() "<<fitPar_<<" unknown estimator!"<<std::endl;
2230  }
2231  } // closes loop on eta bins
2232  } // cloeses loop on phi bins
2233 }
2234 
2235 //*************************************************************
2237 //*************************************************************
2238 {
2239  if( a.tracksSize() != b.tracksSize() )
2240  return a.tracksSize() > b.tracksSize() ? true : false ;
2241  else
2242  return a.chi2() < b.chi2() ? true : false ;
2243 }
2244 
2245 //*************************************************************
2246 bool PrimaryVertexValidation::passesTrackCuts(const reco::Track & track, const reco::Vertex & vertex,std::string qualityString_, double dxyErrMax_,double dzErrMax_, double ptErrMax_)
2247 //*************************************************************
2248 {
2249 
2250  math::XYZPoint vtxPoint(0.0,0.0,0.0);
2251  double vzErr =0.0, vxErr=0.0, vyErr=0.0;
2252  vtxPoint=vertex.position();
2253  vzErr=vertex.zError();
2254  vxErr=vertex.xError();
2255  vyErr=vertex.yError();
2256 
2257  double dxy=0.0, dz=0.0, dxysigma=0.0, dzsigma=0.0;
2258  dxy = track.dxy(vtxPoint);
2259  dz = track.dz(vtxPoint);
2260  dxysigma = sqrt(track.d0Error()*track.d0Error()+vxErr*vyErr);
2261  dzsigma = sqrt(track.dzError()*track.dzError()+vzErr*vzErr);
2262 
2263  if(track.quality(reco::TrackBase::qualityByName(qualityString_)) != 1)return false;
2264  if(fabs(dxy/dxysigma) > dxyErrMax_) return false;
2265  if(fabs(dz/dzsigma) > dzErrMax_) return false;
2266  if(track.ptError() / track.pt() > ptErrMax_) return false;
2267 
2268  return true;
2269 }
2270 
2271 
2272 //*************************************************************
2274 //*************************************************************
2275 {
2276 
2277  TH1F::SetDefaultSumw2(kTRUE);
2278 
2279  std::map<std::string, TH1*> h;
2280 
2281  // histograms of track quality (Data and MC)
2282  std::string types[] = {"all","sel"};
2283  for(int t=0; t<2; t++){
2284  h["pseudorapidity_"+types[t]] =dir.make <TH1F>(("rapidity_"+types[t]).c_str(),"track pseudorapidity; track #eta; tracks",100,-3., 3.);
2285  h["z0_"+types[t]] = dir.make<TH1F>(("z0_"+types[t]).c_str(),"track z_{0};track z_{0} (cm);tracks",80,-40., 40.);
2286  h["phi_"+types[t]] = dir.make<TH1F>(("phi_"+types[t]).c_str(),"track #phi; track #phi;tracks",80,-TMath::Pi(), TMath::Pi());
2287  h["eta_"+types[t]] = dir.make<TH1F>(("eta_"+types[t]).c_str(),"track #eta; track #eta;tracks",80,-4., 4.);
2288  h["pt_"+types[t]] = dir.make<TH1F>(("pt_"+types[t]).c_str(),"track p_{T}; track p_{T} [GeV];tracks",100,0., 20.);
2289  h["p_"+types[t]] = dir.make<TH1F>(("p_"+types[t]).c_str(),"track p; track p [GeV];tracks",100,0., 20.);
2290  h["found_"+types[t]] = dir.make<TH1F>(("found_"+types[t]).c_str(),"n. found hits;n^{found}_{hits};tracks",30, 0., 30.);
2291  h["lost_"+types[t]] = dir.make<TH1F>(("lost_"+types[t]).c_str(),"n. lost hits;n^{lost}_{hits};tracks",20, 0., 20.);
2292  h["nchi2_"+types[t]] = dir.make<TH1F>(("nchi2_"+types[t]).c_str(),"normalized track #chi^{2};track #chi^{2}/ndf;tracks",100, 0., 20.);
2293  h["rstart_"+types[t]] = dir.make<TH1F>(("rstart_"+types[t]).c_str(),"track start radius; track innermost radius r (cm);tracks",100, 0., 20.);
2294  h["expectedInner_"+types[t]] = dir.make<TH1F>(("expectedInner_"+types[t]).c_str(),"n. expected inner hits;n^{expected}_{inner};tracks",10, 0., 10.);
2295  h["expectedOuter_"+types[t]] = dir.make<TH1F>(("expectedOuter_"+types[t]).c_str(),"n. expected outer hits;n^{expected}_{outer};tracks ",10, 0., 10.);
2296  h["logtresxy_"+types[t]] = dir.make<TH1F>(("logtresxy_"+types[t]).c_str(),"log10(track r-#phi resolution/#mum);log10(track r-#phi resolution/#mum);tracks",100, 0., 5.);
2297  h["logtresz_"+types[t]] = dir.make<TH1F>(("logtresz_"+types[t]).c_str(),"log10(track z resolution/#mum);log10(track z resolution/#mum);tracks",100, 0., 5.);
2298  h["tpullxy_"+types[t]] = dir.make<TH1F>(("tpullxy_"+types[t]).c_str(),"track r-#phi pull;pull_{r-#phi};tracks",100, -10., 10.);
2299  h["tpullz_"+types[t]] = dir.make<TH1F>(("tpullz_"+types[t]).c_str(),"track r-z pull;pull_{r-z};tracks",100, -50., 50.);
2300  h["tlogDCAxy_"+types[t]] = dir.make<TH1F>(("tlogDCAxy_"+types[t]).c_str(),"track log_{10}(DCA_{r-#phi});track log_{10}(DCA_{r-#phi});tracks",200, -5., 3.);
2301  h["tlogDCAz_"+types[t]] = dir.make<TH1F>(("tlogDCAz_"+types[t]).c_str(),"track log_{10}(DCA_{r-z});track log_{10}(DCA_{r-z});tracks",200, -5., 5.);
2302  h["lvseta_"+types[t]] = dir.make<TH2F>(("lvseta_"+types[t]).c_str(),"cluster length vs #eta;track #eta;cluster length",60,-3., 3., 20, 0., 20);
2303  h["lvstanlambda_"+types[t]] = dir.make<TH2F>(("lvstanlambda_"+types[t]).c_str(),"cluster length vs tan #lambda; tan#lambda;cluster length",60,-6., 6., 20, 0., 20);
2304  h["restrkz_"+types[t]] = dir.make<TH1F>(("restrkz_"+types[t]).c_str(),"z-residuals (track vs vertex);res_{z} (cm);tracks", 200, -5., 5.);
2305  h["restrkzvsphi_"+types[t]] = dir.make<TH2F>(("restrkzvsphi_"+types[t]).c_str(),"z-residuals (track - vertex) vs track #phi;track #phi;res_{z} (cm)", 12,-TMath::Pi(),TMath::Pi(),100, -0.5,0.5);
2306  h["restrkzvseta_"+types[t]] = dir.make<TH2F>(("restrkzvseta_"+types[t]).c_str(),"z-residuals (track - vertex) vs track #eta;track #eta;res_{z} (cm)", 12,-3.,3.,200, -0.5,0.5);
2307  h["pulltrkzvsphi_"+types[t]] = dir.make<TH2F>(("pulltrkzvsphi_"+types[t]).c_str(),"normalized z-residuals (track - vertex) vs track #phi;track #phi;res_{z}/#sigma_{res_{z}}", 12,-TMath::Pi(),TMath::Pi(),100, -5., 5.);
2308  h["pulltrkzvseta_"+types[t]] = dir.make<TH2F>(("pulltrkzvseta_"+types[t]).c_str(),"normalized z-residuals (track - vertex) vs track #eta;track #eta;res_{z}/#sigma_{res_{z}}", 12,-3.,3.,100, -5., 5.);
2309  h["pulltrkz_"+types[t]] = dir.make<TH1F>(("pulltrkz_"+types[t]).c_str(),"normalized z-residuals (track vs vertex);res_{z}/#sigma_{res_{z}};tracks", 100, -5., 5.);
2310  h["sigmatrkz0_"+types[t]] = dir.make<TH1F>(("sigmatrkz0_"+types[t]).c_str(),"z-resolution (excluding beam);#sigma^{trk}_{z_{0}} (cm);tracks", 100, 0., 5.);
2311  h["sigmatrkz_"+types[t]] = dir.make<TH1F>(("sigmatrkz_"+types[t]).c_str(),"z-resolution (including beam);#sigma^{trk}_{z} (cm);tracks", 100,0., 5.);
2312  h["nbarrelhits_"+types[t]] = dir.make<TH1F>(("nbarrelhits_"+types[t]).c_str(),"number of pixel barrel hits;n. hits Barrel Pixel;tracks", 10, 0., 10.);
2313  h["nbarrelLayers_"+types[t]] = dir.make<TH1F>(("nbarrelLayers_"+types[t]).c_str(),"number of pixel barrel layers;n. layers Barrel Pixel;tracks", 10, 0., 10.);
2314  h["nPxLayers_"+types[t]] = dir.make<TH1F>(("nPxLayers_"+types[t]).c_str(),"number of pixel layers (barrel+endcap);n. Pixel layers;tracks", 10, 0., 10.);
2315  h["nSiLayers_"+types[t]] = dir.make<TH1F>(("nSiLayers_"+types[t]).c_str(),"number of Tracker layers;n. Tracker layers;tracks", 20, 0., 20.);
2316  h["trackAlgo_"+types[t]] = dir.make<TH1F>(("trackAlgo_"+types[t]).c_str(),"track algorithm;track algo;tracks", 30, 0., 30.);
2317  h["trackQuality_"+types[t]] = dir.make<TH1F>(("trackQuality_"+types[t]).c_str(),"track quality;track quality;tracks", 7, -1., 6.);
2318  }
2319 
2320  return h;
2321 
2322 }
2323 
2324 //*************************************************************
2325 void PrimaryVertexValidation::fillTrackHistos(std::map<std::string, TH1*> & h, const std::string & ttype, const reco::TransientTrack * tt,const reco::Vertex & v, const reco::BeamSpot & beamSpot, double fBfield_)
2326 //*************************************************************
2327 {
2328 
2329  using namespace reco;
2330 
2331  fill(h,"pseudorapidity_"+ttype,tt->track().eta());
2332  fill(h,"z0_"+ttype,tt->track().vz());
2333  fill(h,"phi_"+ttype,tt->track().phi());
2334  fill(h,"eta_"+ttype,tt->track().eta());
2335  fill(h,"pt_"+ttype,tt->track().pt());
2336  fill(h,"p_"+ttype,tt->track().p());
2337  fill(h,"found_"+ttype,tt->track().found());
2338  fill(h,"lost_"+ttype,tt->track().lost());
2339  fill(h,"nchi2_"+ttype,tt->track().normalizedChi2());
2340  fill(h,"rstart_"+ttype,(tt->track().innerPosition()).Rho());
2341 
2342  double d0Error=tt->track().d0Error();
2343  double d0=tt->track().dxy(beamSpot.position());
2344  double dz=tt->track().dz(beamSpot.position());
2345  if (d0Error>0){
2346  fill(h,"logtresxy_"+ttype,log(d0Error/0.0001)/log(10.));
2347  fill(h,"tpullxy_"+ttype,d0/d0Error);
2348  fill(h,"tlogDCAxy_"+ttype,log(fabs(d0/d0Error)));
2349 
2350  }
2351  //double z0=tt->track().vz();
2352  double dzError=tt->track().dzError();
2353  if(dzError>0){
2354  fill(h,"logtresz_"+ttype,log(dzError/0.0001)/log(10.));
2355  fill(h,"tpullz_"+ttype,dz/dzError);
2356  fill(h,"tlogDCAz_"+ttype,log(fabs(dz/dzError)));
2357  }
2358 
2359  //
2360  double wxy2_=pow(beamSpot.BeamWidthX(),2)+pow(beamSpot.BeamWidthY(),2);
2361 
2362  fill(h,"sigmatrkz_"+ttype,sqrt(pow(tt->track().dzError(),2)+wxy2_/pow(tan(tt->track().theta()),2)));
2363  fill(h,"sigmatrkz0_"+ttype,tt->track().dzError());
2364 
2365  // track vs vertex
2366  if( v.isValid()){ // && (v.ndof()<10.)) {
2367  // emulate clusterizer input
2368  //const TransientTrack & tt = theB_->build(&t); wrong !!!!
2369  //reco::TransientTrack tt = theB_->build(&t);
2370  //ttt->track().setBeamSpot(beamSpot); // need the setBeamSpot !
2371  double z=(tt->stateAtBeamLine().trackStateAtPCA()).position().z();
2372  double tantheta=tan((tt->stateAtBeamLine().trackStateAtPCA()).momentum().theta());
2373  double dz2= pow(tt->track().dzError(),2)+wxy2_/pow(tantheta,2);
2374 
2375  fill(h,"restrkz_"+ttype,z-v.position().z());
2376  fill(h,"restrkzvsphi_"+ttype,tt->track().phi(), z-v.position().z());
2377  fill(h,"restrkzvseta_"+ttype,tt->track().eta(), z-v.position().z());
2378  fill(h,"pulltrkzvsphi_"+ttype,tt->track().phi(), (z-v.position().z())/sqrt(dz2));
2379  fill(h,"pulltrkzvseta_"+ttype,tt->track().eta(), (z-v.position().z())/sqrt(dz2));
2380 
2381  fill(h,"pulltrkz_"+ttype,(z-v.position().z())/sqrt(dz2));
2382 
2383  double x1=tt->track().vx()-beamSpot.x0(); double y1=tt->track().vy()-beamSpot.y0();
2384 
2385  double kappa=-0.002998*fBfield_*tt->track().qoverp()/cos(tt->track().theta());
2386  double D0=x1*sin(tt->track().phi())-y1*cos(tt->track().phi())-0.5*kappa*(x1*x1+y1*y1);
2387  double q=sqrt(1.-2.*kappa*D0);
2388  double s0=(x1*cos(tt->track().phi())+y1*sin(tt->track().phi()))/q;
2389  // double s1;
2390  if (fabs(kappa*s0)>0.001){
2391  //s1=asin(kappa*s0)/kappa;
2392  }else{
2393  //double ks02=(kappa*s0)*(kappa*s0);
2394  //s1=s0*(1.+ks02/6.+3./40.*ks02*ks02+5./112.*pow(ks02,3));
2395  }
2396  // sp.ddcap=-2.*D0/(1.+q);
2397  //double zdcap=tt->track().vz()-s1/tan(tt->track().theta());
2398 
2399  }
2400  //
2401 
2402  // collect some info on hits and clusters
2403  fill(h,"nbarrelLayers_"+ttype,tt->track().hitPattern().pixelBarrelLayersWithMeasurement());
2404  fill(h,"nPxLayers_"+ttype,tt->track().hitPattern().pixelLayersWithMeasurement());
2405  fill(h,"nSiLayers_"+ttype,tt->track().hitPattern().trackerLayersWithMeasurement());
2406  fill(h,"expectedInner_"+ttype,tt->track().hitPattern().numberOfHits(HitPattern::MISSING_INNER_HITS));
2407  fill(h,"expectedOuter_"+ttype,tt->track().hitPattern().numberOfHits(HitPattern::MISSING_OUTER_HITS));
2408  fill(h,"trackAlgo_"+ttype,tt->track().algo());
2409  fill(h,"trackQuality_"+ttype,tt->track().qualityMask());
2410 
2411  //
2412  int longesthit=0, nbarrel=0;
2414  if ((**hit).isValid() && (**hit).geographicalId().det() == DetId::Tracker ){
2415  bool barrel = DetId((**hit).geographicalId()).subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel);
2416  //bool endcap = DetId::DetId((**hit).geographicalId()).subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap);
2417  if (barrel){
2418  const SiPixelRecHit *pixhit = dynamic_cast<const SiPixelRecHit*>( &(**hit));
2419  edm::Ref<edmNew::DetSetVector<SiPixelCluster>, SiPixelCluster> const& clust = (*pixhit).cluster();
2420  if (clust.isNonnull()) {
2421  nbarrel++;
2422  if (clust->sizeY()-longesthit>0) longesthit=clust->sizeY();
2423  if (clust->sizeY()>20.){
2424  fill(h,"lvseta_"+ttype,tt->track().eta(), 19.9);
2425  fill(h,"lvstanlambda_"+ttype,tan(tt->track().lambda()), 19.9);
2426  }else{
2427  fill(h,"lvseta_"+ttype,tt->track().eta(), float(clust->sizeY()));
2428  fill(h,"lvstanlambda_"+ttype,tan(tt->track().lambda()), float(clust->sizeY()));
2429  }
2430  }
2431  }
2432  }
2433  }
2434  fill(h,"nbarrelhits_"+ttype,float(nbarrel));
2435  //-------------------------------------------------------------------
2436 }
2437 
2438 //*************************************************************
2439 void PrimaryVertexValidation::add(std::map<std::string, TH1*>& h, TH1* hist)
2440 //*************************************************************
2441 {
2442  h[hist->GetName()]=hist;
2443  hist->StatOverflows(kTRUE);
2444 }
2445 
2446 //*************************************************************
2447 void PrimaryVertexValidation::fill(std::map<std::string, TH1*>& h, std::string s, double x)
2448 //*************************************************************
2449 {
2450  // cout << "fill1 " << s << endl;
2451  if(h.count(s)==0){
2452  std::cout << "Trying to fill non-exiting Histogram named " << s << std::endl;
2453  return;
2454  }
2455  h[s]->Fill(x);
2456 }
2457 
2458 //*************************************************************
2459 void PrimaryVertexValidation::fill(std::map<std::string, TH1*>& h, std::string s, double x, double y)
2460 //*************************************************************
2461 {
2462  // cout << "fill2 " << s << endl;
2463  if(h.count(s)==0){
2464  std::cout << "Trying to fill non-exiting Histogram named " << s << std::endl;
2465  return;
2466  }
2467  h[s]->Fill(x,y);
2468 }
2469 
2470 //define this as a plug-in
double qoverp() const
q / p
Definition: TrackBase.h:568
virtual char const * what() const
Definition: Exception.cc:141
static const std::string kSharedResource
Definition: TFileService.h:76
GlobalError positionError() const
double p() const
momentum vector magnitude
Definition: TrackBase.h:610
const double Pi
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:41
double z0() const
z coordinate
Definition: BeamSpot.h:68
T getUntrackedParameter(std::string const &, T const &) const
TH1F * n_dzResidualsMap[nMaxBins_][nMaxBins_]
static uint32_t getLayer(uint16_t pattern)
Definition: HitPattern.h:700
double d0Error() const
error on d0
Definition: TrackBase.h:797
double longitudinalImpactParameterError() const
TH1F * a_IP3DEtaResiduals[nMaxBins_]
std::vector< unsigned int > runControlNumbers_
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:252
unsigned short lost() const
Number of lost (=invalid) hits on track.
Definition: Track.h:199
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
static bool vtxSort(const reco::Vertex &a, const reco::Vertex &b)
const PerigeeTrajectoryError & perigeeError() const
trackRef_iterator tracks_end() const
last iterator over tracks
Definition: Vertex.cc:81
void setBeamSpot(const reco::BeamSpot &beamSpot)
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:556
const DetContainer & dets() const
Returm a vector of all GeomDet (including all GeomDetUnits)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
double zError() const
error on z
Definition: Vertex.h:123
TH1F * n_IP2DPhiResiduals[nMaxBins_]
TrackFilterForPVFindingBase * theTrackFilter_
TH1F * a_dxyResidualsMap[nMaxBins_][nMaxBins_]
std::map< std::string, TH1 * > hDA
TrackQuality
track quality
Definition: TrackBase.h:151
TH1F * n_dxyEtaBiasResiduals[nMaxBins_]
Common base class.
const FreeTrajectoryState & theState() const
double theta() const
polar angle
Definition: TrackBase.h:574
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
bool isValid() const
Tells whether the vertex is valid.
Definition: Vertex.h:68
Divides< arg, void > D0
Definition: Factorize.h:143
PrimaryVertexValidation(const edm::ParameterSet &)
std::pair< Double_t, Double_t > getMAD(TH1F *histo)
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
std::pair< bool, Measurement1D > signedTransverseImpactParameter(const reco::TransientTrack &track, const GlobalVector &direction, const reco::Vertex &vertex)
Definition: IPTools.cc:50
TH1F * n_dxyBiasResidualsMap[nMaxBins_][nMaxBins_]
float totalChiSquared() const
const HitPattern & hitPattern() const
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
reco::TransientTrack build(const reco::Track *p) const
std::pair< bool, Measurement1D > absoluteImpactParameter3D(const reco::TransientTrack &transientTrack, const reco::Vertex &vertex)
Definition: IPTools.cc:37
T y() const
Definition: PV3DBase.h:63
RunNumber_t run() const
std::pair< bool, Measurement1D > signedImpactParameter3D(const reco::TransientTrack &track, const GlobalVector &direction, const reco::Vertex &vertex)
Definition: IPTools.cc:71
double phi() const
azimuthal angle of momentum vector
Definition: TrackBase.h:640
float DOFUnbiasedVertex_[nMaxtracks_]
TH1F * a_dzPhiBiasResiduals[nMaxBins_]
bool passesTrackCuts(const reco::Track &track, const reco::Vertex &vertex, std::string qualityString_, double dxyErrMax_, double dzErrMax_, double ptErrMax_)
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
double d3DFromMyVertex_[nMaxtracks_]
TH1F * n_dzEtaBiasResiduals[nMaxBins_]
virtual void analyze(const edm::Event &, const edm::EventSetup &)
float chi2ProbUnbiasedVertex_[nMaxtracks_]
double px() const
x coordinate of momentum vector
Definition: TrackBase.h:622
int pixelLayersWithMeasurement() const
Definition: HitPattern.cc:499
double dxyFromMyVertex_[nMaxtracks_]
int trackerLayersWithMeasurement() const
Definition: HitPattern.cc:518
const Point & position() const
position
Definition: Vertex.h:109
static bool pixelBarrelHitFilter(uint16_t pattern)
Definition: HitPattern.h:575
TrajectoryStateClosestToBeamLine stateAtBeamLine() const
int numberOfValidStripTOBHits() const
Definition: HitPattern.h:868
double dzErrorFromMyVertex_[nMaxtracks_]
void fillTrackHistos(std::map< std::string, TH1 * > &h, const std::string &ttype, const reco::TransientTrack *tt, const reco::Vertex &v, const reco::BeamSpot &beamSpot, double fBfield)
LuminosityBlockNumber_t luminosityBlock() const
static bool pixelEndcapHitFilter(uint16_t pattern)
Definition: HitPattern.h:585
TH1F * a_dxyPhiBiasResiduals[nMaxBins_]
double IPTsigFromMyVertex_[nMaxtracks_]
static bool validHitFilter(uint16_t pattern)
Definition: HitPattern.h:787
bool isThere(GeomDetEnumerators::SubDetector subdet) const
const math::XYZPoint & innerPosition() const
position of the innermost hit
Definition: Track.h:55
TrackAlgorithm algo() const
Definition: TrackBase.h:492
std::pair< Double_t, Double_t > getMedian(TH1F *histo)
void fillMap(TH2F *trendMap, TH1F *residualsMapPlot[100][100], TString fitPar_)
TH1F * a_IP2DEtaResiduals[nMaxBins_]
float normalisedChiSquared() const
const Point & vertex() const
reference point on the track. This method is DEPRECATED, please use referencePoint() instead ...
Definition: TrackBase.h:682
int tracksUsedForVertexing_[nMaxtracks_]
int iEvent
Definition: GenABIO.cc:230
TH1F * n_IP2DEtaResiduals[nMaxBins_]
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:646
std::pair< bool, bool > pixelHitsCheck(const reco::TransientTrack track)
int numberOfValidPixelBarrelHits() const
Definition: HitPattern.h:843
const PerigeeTrajectoryParameters & perigeeParameters() const
bool hasFirstLayerPixelHits(const reco::TransientTrack track)
TH1F * n_reszEtaResiduals[nMaxBins_]
double chi2() const
chi-squared of the fit
Definition: TrackBase.h:544
TH1F * n_dzPhiBiasResiduals[nMaxBins_]
float degreesOfFreedom() const
double yUnbiasedVertex_[nMaxtracks_]
T sqrt(T t)
Definition: SSEVec.h:18
virtual int dimension() const =0
std::pair< std::pair< Double_t, Double_t >, std::pair< Double_t, Double_t > > fitResiduals(TH1 *hist)
GlobalPoint position() const
double pt() const
track transverse momentum
Definition: TrackBase.h:616
T z() const
Definition: PV3DBase.h:64
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:758
T Abs(T a)
Definition: MathUtil.h:49
TH1F * n_IP3DEtaResiduals[nMaxBins_]
int qualityMask() const
Definition: TrackBase.h:857
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
def pv(vc)
Definition: MetAnalyzer.py:6
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double chi2() const
chi-squares
Definition: Vertex.h:98
double zUnbiasedVertex_[nMaxtracks_]
int numberOfValidStripTIDHits() const
Definition: HitPattern.h:863
double lambda() const
Lambda angle.
Definition: TrackBase.h:580
TH1F * a_reszPhiResiduals[nMaxBins_]
double BeamWidthX() const
beam width X
Definition: BeamSpot.h:86
unsigned short numberOfValidHits() const
number of valid hits found
Definition: TrackBase.h:815
int numberOfValidStripTECHits() const
Definition: HitPattern.h:873
float chi2normUnbiasedVertex_[nMaxtracks_]
TH1F * n_d3DResidualsMap[nMaxBins_][nMaxBins_]
virtual CachingVertex< N > vertex(const std::vector< reco::TransientTrack > &tracks) const =0
T * make(const Args &...args) const
make new ROOT object
T min(T a, T b)
Definition: MathUtil.h:58
trackingRecHit_iterator recHitsBegin() const
Iterator to first hit on the track.
Definition: Track.h:104
edm::EDGetTokenT< reco::VertexCollection > theVertexCollectionToken
TH1F * a_d3DResidualsMap[nMaxBins_][nMaxBins_]
bool isValid() const
Definition: HandleBase.h:74
float trackWeight(const reco::TransientTrack &track) const
double IPLsigFromMyVertex_[nMaxtracks_]
#define LogTrace(id)
double dxdz() const
dxdz slope
Definition: BeamSpot.h:82
double ndof() const
Definition: Vertex.h:105
double pz() const
z coordinate of momentum vector
Definition: TrackBase.h:634
virtual std::vector< std::vector< reco::TransientTrack > > clusterize(const std::vector< reco::TransientTrack > &tracks) const =0
int k[5][pyjets_maxn]
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:604
double dzError() const
error on dz
Definition: TrackBase.h:809
double vz() const
z coordinate of the reference point on track
Definition: TrackBase.h:664
EventAuxiliary const & eventAuxiliary() const
Definition: Event.h:78
Definition: DetId.h:18
TH1F * a_IP2DPhiResiduals[nMaxBins_]
GlobalPoint position() const
static TrackQuality qualityByName(const std::string &name)
Definition: TrackBase.cc:125
double xError() const
error on x
Definition: Vertex.h:119
TFileDirectory mkdir(const std::string &dir, const std::string &descr="")
create a new subdirectory
Definition: TFileService.h:69
const Track & track() const
bool hasTrackWeight() const
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
Definition: TrackBase.h:445
bool isHit2D(const TrackingRecHit &hit) const
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
const T & get() const
Definition: EventSetup.h:56
double sigmaZ() const
sigma z
Definition: BeamSpot.h:80
TH1F * n_dxyPhiBiasResiduals[nMaxBins_]
int pixelBarrelLayersWithMeasurement() const
Definition: HitPattern.cc:558
double BeamWidthY() const
beam width Y
Definition: BeamSpot.h:88
TrackClusterizerInZ * theTrackClusterizer_
double b
Definition: hdecay.h:120
double xUnbiasedVertex_[nMaxtracks_]
virtual std::vector< reco::TransientTrack > select(const std::vector< reco::TransientTrack > &tracks) const =0
int numberOfValidStripTIBHits() const
Definition: HitPattern.h:858
bool quality(const TrackQuality) const
Track quality.
Definition: TrackBase.h:505
std::string HistoName
int numberOfValidPixelEndcapHits() const
Definition: HitPattern.h:848
TH1F * a_dxyEtaBiasResiduals[nMaxBins_]
edm::EDGetTokenT< reco::BeamSpot > theBeamspotToken
edm::EDGetTokenT< reco::TrackCollection > theTrackCollectionToken
EventID const & id() const
Pixel cluster – collection of neighboring pixels above threshold.
double vy() const
y coordinate of the reference point on track
Definition: TrackBase.h:658
double dzFromMyVertex_[nMaxtracks_]
fixed size matrix
TH1F * n_IP3DPhiResiduals[nMaxBins_]
double a
Definition: hdecay.h:121
static int position[264][3]
Definition: ReadPGInfo.cc:509
unsigned short found() const
Number of valid hits on track.
Definition: Track.h:194
void add(std::map< std::string, TH1 * > &h, TH1 *hist)
void fill(std::map< std::string, TH1 * > &h, std::string s, double x)
std::vector< TrackBaseRef >::const_iterator trackRef_iterator
The iteratator for the vector<TrackRef>
Definition: Vertex.h:37
double y0() const
y coordinate
Definition: BeamSpot.h:66
TH1F * a_reszEtaResiduals[nMaxBins_]
TH1F * a_dxyBiasResidualsMap[nMaxBins_][nMaxBins_]
TH1F * a_IP3DPhiResiduals[nMaxBins_]
int charge() const
track electric charge
Definition: TrackBase.h:562
const Point & position() const
position
Definition: BeamSpot.h:62
TH1F * n_dxyResidualsMap[nMaxBins_][nMaxBins_]
static const G4double kappa
double normalizedChi2() const
chi-squared divided by n.d.o.f.
Definition: Vertex.h:107
double dxyErrorFromMyVertex_[nMaxtracks_]
DetId geographicalId() const
dbl *** dir
Definition: mlp_gen.cc:35
trackRef_iterator tracks_begin() const
first iterator over tracks
Definition: Vertex.cc:76
TH1F * n_reszPhiResiduals[nMaxBins_]
uint16_t getHitPattern(HitCategory category, int position) const
Definition: HitPattern.h:515
float sumOfWeightsUnbiasedVertex_[nMaxtracks_]
TH1F * n_dzBiasResidualsMap[nMaxBins_][nMaxBins_]
double d3DErrorFromMyVertex_[nMaxtracks_]
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:586
TH1F * a_dzBiasResidualsMap[nMaxBins_][nMaxBins_]
T x() const
Definition: PV3DBase.h:62
TH1F * a_dzEtaBiasResiduals[nMaxBins_]
bool isValid() const
void fillTrendPlot(TH1F *trendPlot, TH1F *residualsPlot[100], TString fitPar_, TString var_)
TH1F * a_dzResidualsMap[nMaxBins_][nMaxBins_]
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
double yError() const
error on y
Definition: Vertex.h:121
float chi2UnbiasedVertex_[nMaxtracks_]
size_t tracksSize() const
number of tracks
Definition: Vertex.cc:71
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
Definition: invegas.h:5
double py() const
y coordinate of momentum vector
Definition: TrackBase.h:628
TrackingRecHitCollection::base::const_iterator trackingRecHit_iterator
iterator over a vector of reference to TrackingRecHit in the same collection
double vx() const
x coordinate of the reference point on track
Definition: TrackBase.h:652
Global3DVector GlobalVector
Definition: GlobalVector.h:10
int numberOfHits(HitCategory category) const
Definition: HitPattern.h:807
std::map< std::string, TH1 * > bookVertexHistograms(TFileDirectory dir)
Our base class.
Definition: SiPixelRecHit.h:23
double x0() const
x coordinate
Definition: BeamSpot.h:64
trackingRecHit_iterator recHitsEnd() const
Iterator to last hit on the track.
Definition: Track.h:109
double IP3DsigFromMyVertex_[nMaxtracks_]