CMS 3D CMS Logo

PrimaryVertexValidation.h
Go to the documentation of this file.
1 #ifndef PrimaryVertexValidation_h
2 #define PrimaryVertexValidation_h
3 
4 // system include files
5 #include <string>
6 #include <sstream>
7 #include <vector>
8 #include <map>
9 
10 // ROOT Included
11 #include "TFile.h"
12 #include "TH1D.h"
13 #include "TH1I.h"
14 #include "TH2D.h"
15 #include "TTree.h"
16 
17 // CMSSW includes
55 
56 //
57 // ancyllary enum for
58 // residuals moments estimation
59 //
60 
61 namespace statmode{
62  enum estimator
63  { MEAN = 1,
64  WIDTH = 2,
65  MEDIAN = 3,
66  MAD = 4,
67  UNKWN = -1
68  };
69 }
70 
71 //
72 // class decleration
73 //
74 
75 class PrimaryVertexValidation : public edm::one::EDAnalyzer<edm::one::SharedResources> {
76 
77  public:
80 
81  private:
82  virtual void beginJob();
83  virtual void analyze(const edm::Event&, const edm::EventSetup&);
84  virtual void endJob();
85  bool isBFieldConsistentWithMode(const edm::EventSetup& iSetup) const;
86  bool isHit2D(const TrackingRecHit &hit) const;
87  bool hasFirstLayerPixelHits(const reco::TransientTrack track);
88  std::pair<bool,bool> pixelHitsCheck(const reco::TransientTrack track);
89  std::pair<Double_t,Double_t> getMedian(TH1F *histo);
90  std::pair<Double_t,Double_t> getMAD(TH1F *histo);
91  std::pair<std::pair<Double_t,Double_t>, std::pair<Double_t,Double_t> > fitResiduals(TH1 *hist);
92  void fillTrendPlot(TH1F* trendPlot, TH1F *residualsPlot[100], statmode::estimator fitPar_, TString var_);
93  void fillTrendPlotByIndex(TH1F* trendPlot,std::vector<TH1F*>& h, statmode::estimator fitPar_);
94 
95  static bool vtxSort( const reco::Vertex & a, const reco::Vertex & b );
96  bool passesTrackCuts(const reco::Track & track, const reco::Vertex & vertex,std::string qualityString_, double dxyErrMax_,double dzErrMax_, double ptErrMax_);
97 
98  std::vector<TH1F*> bookResidualsHistogram(TFileDirectory dir,unsigned int theNOfBins,TString resType,TString varType);
99  std::map<std::string, TH1*> bookVertexHistograms(TFileDirectory dir);
100  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);
101  void add(std::map<std::string, TH1*>& h, TH1* hist);
102  void fill(std::map<std::string, TH1*>& h, std::string s, double x);
103  void fill(std::map<std::string, TH1*>& h, std::string s, double x, double y);
104  void fillByIndex(std::vector<TH1F*>& h, unsigned int index, double x);
105  void fillMap(TH2F* trendMap, TH1F* residualsMapPlot[100][100], statmode::estimator fitPar_);
106 
107  inline double square(double x){
108  return x*x;
109  }
110 
111  // ----------member data ---------------------------
113  int Nevt_;
114 
117 
118  // setting of the number of plots
119  static const int nMaxBins_ = 100; // maximum number of bookable histograms
120 
121  // Output
123  bool lightNtupleSwitch_; // switch to keep only info for daily validation
125 
126  // requirements on the vertex
127  double vertexZMax_;
128 
129  // integrated lumi (if info available)
130  double intLumi_;
131 
132  // requirements on the probe
133  bool askFirstLayerHit_; // ask hit in the first layer of pixels
134  bool doBPix_;
135  bool doFPix_;
136  double ptOfProbe_;
137  double etaOfProbe_;
138  bool isPhase1_;
139  int nBins_; // actual number of histograms
140  std::vector<unsigned int> runControlNumbers_;
141 
142  bool debug_;
144 
148 
149  TTree* rootTree_;
150 
151  // Root-Tuple variables :
152  //=======================
153  void SetVarToZero();
154 
155  static const int nMaxtracks_ = 1000;
156  static const int cmToum = 10000;
157  static const int nPtBins_ = 48;
158 
159  float phiSect_;
160  float etaSect_;
161 
162  // pT binning as in paragraph 3.2 of CMS-PAS-TRK-10-005 (https://cds.cern.ch/record/1279383/files/TRK-10-005-pas.pdf)
163 
164  // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
165  const float mypT_bins_[nPtBins_+1] = {0.5,0.6,0.7,0.8,0.9,1.0,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2.0,2.1,2.2,2.3,2.4,2.5,2.6,2.7,2.8,2.9,3.0,3.1,3.2,3.3,3.4,3.5,3.6,3.7,3.8,3.9,4.0,4.1,4.25,4.5,4.75,5.0,5.5,6.0,7.0,8.0,9.0,11.0,14.0,20.};
166 
167  // event-related quantities
168  int nTracks_;
170  int nClus_;
172  unsigned int RunNumber_;
173  unsigned int EventNumber_;
178 
182 
183  double BSx0_;
184  double BSy0_;
185  double BSz0_;
186  double Beamsigmaz_;
187  double Beamdxdz_;
188  double BeamWidthX_;
189  double BeamWidthY_;
190  double wxy2_;
191 
192  // track-related quantities
193  double pt_[nMaxtracks_];
194  double p_[nMaxtracks_];
195  int nhits_[nMaxtracks_];
196  int nhits1D_[nMaxtracks_];
197  int nhits2D_[nMaxtracks_];
198  int nhitsBPIX_[nMaxtracks_];
199  int nhitsFPIX_[nMaxtracks_];
200  int nhitsTIB_[nMaxtracks_];
201  int nhitsTID_[nMaxtracks_];
202  int nhitsTOB_[nMaxtracks_];
203  int nhitsTEC_[nMaxtracks_];
204  int isHighPurity_[nMaxtracks_];
205  double eta_[nMaxtracks_];
206  double theta_[nMaxtracks_];
207  double phi_[nMaxtracks_];
208  double chi2_[nMaxtracks_];
209  double chi2ndof_[nMaxtracks_];
210  int charge_[nMaxtracks_];
211  double qoverp_[nMaxtracks_];
212  double dz_[nMaxtracks_];
213  double dxy_[nMaxtracks_];
214  double dxyBs_[nMaxtracks_];
215  double dzBs_[nMaxtracks_];
216  double xPCA_[nMaxtracks_];
217  double yPCA_[nMaxtracks_];
218  double zPCA_[nMaxtracks_];
219  double xUnbiasedVertex_[nMaxtracks_];
220  double yUnbiasedVertex_[nMaxtracks_];
221  double zUnbiasedVertex_[nMaxtracks_];
222  float chi2normUnbiasedVertex_[nMaxtracks_];
223  float chi2UnbiasedVertex_[nMaxtracks_];
224  float chi2ProbUnbiasedVertex_[nMaxtracks_];
225  float DOFUnbiasedVertex_[nMaxtracks_];
226  float sumOfWeightsUnbiasedVertex_[nMaxtracks_];
227  int tracksUsedForVertexing_[nMaxtracks_];
228 
229  double dxyFromMyVertex_[nMaxtracks_];
230  double dzFromMyVertex_[nMaxtracks_];
231  double d3DFromMyVertex_[nMaxtracks_];
232 
233  double dxyErrorFromMyVertex_[nMaxtracks_];
234  double dzErrorFromMyVertex_[nMaxtracks_];
235  double d3DErrorFromMyVertex_[nMaxtracks_];
236 
237  double IPTsigFromMyVertex_[nMaxtracks_];
238  double IPLsigFromMyVertex_[nMaxtracks_];
239  double IP3DsigFromMyVertex_[nMaxtracks_];
240 
241  int hasRecVertex_[nMaxtracks_];
242  int isGoodTrack_[nMaxtracks_];
243 
244  // histogram for max(eta)
245  TH1F* h_etaMax;
246  TH1F* h_nbins;
247 
248  // ---- directly histograms // ===> unbiased residuals
249 
250  // absolute residuals
251 
252  TH1F* a_dxyPhiResiduals[nMaxBins_];
253  TH1F* a_dxyEtaResiduals[nMaxBins_];
254 
255  TH1F* a_dxPhiResiduals[nMaxBins_];
256  TH1F* a_dxEtaResiduals[nMaxBins_];
257 
258  TH1F* a_dyPhiResiduals[nMaxBins_];
259  TH1F* a_dyEtaResiduals[nMaxBins_];
260 
261  TH1F* a_dzPhiResiduals[nMaxBins_];
262  TH1F* a_dzEtaResiduals[nMaxBins_];
263 
264  TH1F* a_IP2DPhiResiduals[nMaxBins_];
265  TH1F* a_IP2DEtaResiduals[nMaxBins_];
266 
267  TH1F* a_IP3DPhiResiduals[nMaxBins_];
268  TH1F* a_IP3DEtaResiduals[nMaxBins_];
269 
270  TH1F* a_reszPhiResiduals[nMaxBins_];
271  TH1F* a_reszEtaResiduals[nMaxBins_];
272 
273  TH1F* a_d3DPhiResiduals[nMaxBins_];
274  TH1F* a_d3DEtaResiduals[nMaxBins_];
275 
276  // normalized residuals
277 
278  TH1F* n_dxyPhiResiduals[nMaxBins_];
279  TH1F* n_dxyEtaResiduals[nMaxBins_];
280 
281  TH1F* n_dzPhiResiduals[nMaxBins_];
282  TH1F* n_dzEtaResiduals[nMaxBins_];
283 
284  TH1F* n_IP2DPhiResiduals[nMaxBins_];
285  TH1F* n_IP2DEtaResiduals[nMaxBins_];
286 
287  TH1F* n_IP3DPhiResiduals[nMaxBins_];
288  TH1F* n_IP3DEtaResiduals[nMaxBins_];
289 
290  TH1F* n_reszPhiResiduals[nMaxBins_];
291  TH1F* n_reszEtaResiduals[nMaxBins_];
292 
293  TH1F* n_d3DPhiResiduals[nMaxBins_];
294  TH1F* n_d3DEtaResiduals[nMaxBins_];
295 
296  // for the maps
297 
298  TH1F* a_dxyResidualsMap[nMaxBins_][nMaxBins_];
299  TH1F* a_dzResidualsMap[nMaxBins_][nMaxBins_];
300  TH1F* a_d3DResidualsMap[nMaxBins_][nMaxBins_];
301 
302  TH1F* n_dxyResidualsMap[nMaxBins_][nMaxBins_];
303  TH1F* n_dzResidualsMap[nMaxBins_][nMaxBins_];
304  TH1F* n_d3DResidualsMap[nMaxBins_][nMaxBins_];
305 
306  // ---- trends as function of phi and eta
307 
312 
317 
322 
327 
328  // ---- trends as a function of pT
329 
334 
339 
344 
349 
350  // ---- medians and MAD
351 
356 
361 
366 
371 
372  // 2D residuals
373 
374  TH2F* a_dxyVsPhi;
375  TH2F* a_dzVsPhi;
376 
377  TH2F* n_dxyVsPhi;
378  TH2F* n_dzVsPhi;
379 
380  TH2F* a_dxyVsEta;
381  TH2F* a_dzVsEta;
382 
383  TH2F* n_dxyVsEta;
384  TH2F* n_dzVsEta;
385 
386  // 2D maps
387 
389  TH2F* a_dzMeanMap;
390 
392  TH2F* n_dzMeanMap;
393 
396 
399 
400  // ---- directly histograms =================> biased residuals
401 
402  // absolute residuals
403 
404  TH1F* a_dxyPhiBiasResiduals[nMaxBins_];
405  TH1F* a_dxyEtaBiasResiduals[nMaxBins_];
406 
407  TH1F* a_dzPhiBiasResiduals[nMaxBins_];
408  TH1F* a_dzEtaBiasResiduals[nMaxBins_];
409 
410  // normalized BiasResiduals
411 
412  TH1F* n_dxyPhiBiasResiduals[nMaxBins_];
413  TH1F* n_dxyEtaBiasResiduals[nMaxBins_];
414 
415  TH1F* n_dzPhiBiasResiduals[nMaxBins_];
416  TH1F* n_dzEtaBiasResiduals[nMaxBins_];
417 
418  // for the maps
419 
420  TH1F* a_dxyBiasResidualsMap[nMaxBins_][nMaxBins_];
421  TH1F* a_dzBiasResidualsMap[nMaxBins_][nMaxBins_];
422 
423  TH1F* n_dxyBiasResidualsMap[nMaxBins_][nMaxBins_];
424  TH1F* n_dzBiasResidualsMap[nMaxBins_][nMaxBins_];
425 
426  // ---- trends as function of phi
427 
432 
437 
442 
447 
448  // ---- medians and MAD
449 
454 
459 
464 
469 
470  // 2D maps
471 
474 
477 
480 
483 
484  // check event
485  TH1F* h_nTracks;
486  TH1F* h_nClus;
488  TH1F* h_runNumber;
498  TH1F* h_BSx0;
499  TH1F* h_BSy0;
500  TH1F* h_BSz0;
501  TH1F* h_Beamsigmaz;
503  TH1F* h_BeamWidthY;
504 
505  // check probe
506 
509 
510  TH1F* h_probeP_;
511  TH1F* h_probePt_;
512  TH1F* h_probeEta_;
513  TH1F* h_probePhi_;
518 
521 
524 
527 
531 
539 
540  TH1F* h_probeHits_;
549 
550  // check vertex
551 
559 
564 
565  std::map<std::string, TH1*> hDA;
566 
567  // histograms for the plots as function of pT
568 
569  std::vector<TH1F*> h_dxy_pT_;
570  std::vector<TH1F*> h_dz_pT_;
571  std::vector<TH1F*> h_norm_dxy_pT_;
572  std::vector<TH1F*> h_norm_dz_pT_;
573 
574  std::vector<TH1F*> h_dxy_Central_pT_;
575  std::vector<TH1F*> h_dz_Central_pT_;
576  std::vector<TH1F*> h_norm_dxy_Central_pT_;
577  std::vector<TH1F*> h_norm_dz_Central_pT_;
578 
579 };
580 
581 #endif
std::vector< unsigned int > runControlNumbers_
def analyze(function, filename, filter=None)
Definition: Profiling.py:11
std::vector< TH1F * > h_dxy_pT_
TrackFilterForPVFindingBase * theTrackFilter_
std::map< std::string, TH1 * > hDA
std::vector< TH1F * > h_norm_dz_Central_pT_
void add(const std::vector< const T * > &source, std::vector< const T * > &dest)
void beginJob()
Definition: Breakpoints.cc:15
T x() const
Cartesian x coordinate.
std::vector< TH1F * > h_norm_dxy_pT_
edm::EDGetTokenT< reco::VertexCollection > theVertexCollectionToken
std::vector< TH1F * > h_norm_dz_pT_
std::vector< TH1F * > h_dz_pT_
std::vector< TH1F * > h_dz_Central_pT_
TrackClusterizerInZ * theTrackClusterizer_
double b
Definition: hdecay.h:120
std::vector< TH1F * > h_dxy_Central_pT_
edm::EDGetTokenT< reco::BeamSpot > theBeamspotToken
edm::EDGetTokenT< reco::TrackCollection > theTrackCollectionToken
double a
Definition: hdecay.h:121
dbl *** dir
Definition: mlp_gen.cc:35
std::vector< TH1F * > h_norm_dxy_Central_pT_