CMS 3D CMS Logo

PrimaryVertexValidation.h
Go to the documentation of this file.
1 #ifndef Alignment_OfflineValidation_PrimaryVertexValidation_h
2 #define Alignment_OfflineValidation_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
63 
64 //
65 // ancyllary enum for
66 // residuals moments estimation
67 //
68 
69 //
70 // class decleration
71 //
72 
73 class PrimaryVertexValidation : public edm::one::EDAnalyzer<edm::one::WatchRuns, edm::one::SharedResources> {
74 public:
76  ~PrimaryVertexValidation() override;
77  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
78 
79 private:
80  // framework provided methods
81  void beginJob() override;
82  void beginRun(edm::Run const& iRun, edm::EventSetup const& iSetup) override;
83  void analyze(const edm::Event&, const edm::EventSetup&) override;
84  void endRun(edm::Run const&, edm::EventSetup const&) override{};
85  void endJob() override;
86 
87  // user defined methods
88  bool isBFieldConsistentWithMode(const edm::EventSetup& iSetup) const;
89  std::pair<long long, long long> getRunTime(const edm::EventSetup& iSetup) const;
90  bool isHit2D(const TrackingRecHit& hit, const PVValHelper::detectorPhase& thePhase) const;
92  std::pair<bool, bool> pixelHitsCheck(const reco::TransientTrack& track);
94  Measurement1D getMAD(TH1F* histo);
95  std::pair<Measurement1D, Measurement1D> fitResiduals(TH1* hist);
96 
97  void fillTrendPlot(TH1F* trendPlot, TH1F* residualsPlot[100], PVValHelper::estimator fitPar_, const std::string& var_);
98  void fillTrendPlotByIndex(TH1F* trendPlot,
99  std::vector<TH1F*>& h,
100  PVValHelper::estimator fitPar_,
102 
103  static bool vtxSort(const reco::Vertex& a, const reco::Vertex& b);
104  bool passesTrackCuts(const reco::Track& track,
105  const reco::Vertex& vertex,
106  const std::string& qualityString_,
107  double dxyErrMax_,
108  double dzErrMax_,
109  double ptErrMax_);
110 
111  std::vector<TH1F*> bookResidualsHistogram(const TFileDirectory& dir,
112  unsigned int theNOfBins,
115  bool isNormalized = false);
116  std::map<std::string, TH1*> bookVertexHistograms(const TFileDirectory& dir);
117 
118  void fillTrackHistos(std::map<std::string, TH1*>& h,
119  const std::string& ttype,
120  const reco::TransientTrack* tt,
121  const reco::Vertex& v,
122  const reco::BeamSpot& beamSpot,
123  double fBfield);
124  void add(std::map<std::string, TH1*>& h, TH1* hist);
125 
126  void fill(std::map<std::string, TH1*>& h, const std::string& s, double x);
127  void fill(std::map<std::string, TH1*>& h, const std::string& s, double x, double y);
128  void fillByIndex(std::vector<TH1F*>& h, unsigned int index, double x, std::string tag = "");
129 
130  void shrinkHistVectorToFit(std::vector<TH1F*>& h, unsigned int desired_size);
131  std::tuple<std::string, std::string, std::string> getTypeString(PVValHelper::residualType type);
132  std::tuple<std::string, std::string, std::string> getVarString(PVValHelper::plotVariable var);
133 
134  void fillMap(TH2F* trendMap,
135  TH1F* residualsMapPlot[100][100],
136  PVValHelper::estimator fitPar_,
137  const int nXBins_,
138  const int nYBins_);
139 
140  inline double square(double x) { return x * x; }
141 
142  // ----------member data ---------------------------
143  int Nevt_;
144 
145  std::unique_ptr<TrackFilterForPVFindingBase> theTrackFilter_;
146  std::unique_ptr<TrackClusterizerInZ> theTrackClusterizer_;
147 
148  // setting of the number of plots
149  static const int nMaxBins_ = 100; // maximum number of bookable histograms
150 
151  // Output
152 
153  // tokens form the EventSetup
161 
162  const int compressionSettings_; // determines the ROOT compression settings in TFileService
164  bool lightNtupleSwitch_; // switch to keep only info for daily validation
166 
167  // histogram details
169 
170  // requirements on the vertex
171  double vertexZMax_;
172 
173  // integrated lumi (if info available)
174  double intLumi_;
175 
176  // requirements on the probe
177  bool askFirstLayerHit_; // ask hit in the first layer of pixels
178  bool doBPix_;
179  bool doFPix_;
180  double ptOfProbe_;
181  double pOfProbe_;
182  double etaOfProbe_;
185 
186  // actual number of histograms
187  int nBins_;
188 
189  // limits of the pt binned plots range
190  const double minPt_;
191  const double maxPt_;
192 
193  std::vector<unsigned int> runControlNumbers_;
194 
195  bool debug_;
197 
198  // force to use beamspot in the vertex fit
200 
204 
205  TTree* rootTree_;
206 
207  // Root-Tuple variables :
208  //=======================
209  void SetVarToZero();
210 
211  static const int nMaxtracks_ = 10000;
212  static const int cmToum = 10000;
213  static const int nPtBins_ = 48;
214 
215  // use the maximum of each of the three phases
216  unsigned int nLadders_ = 20;
217  unsigned int nModZ_ = 9;
218 
219  // 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)
220 
221  // 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
222  //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.};
223 
224  std::array<float, nPtBins_ + 1> mypT_bins_;
225 
226  // event-related quantities
227  int nTracks_;
229  int nClus_;
231  unsigned int RunNumber_;
232  unsigned int EventNumber_;
237 
241 
242  double BSx0_;
243  double BSy0_;
244  double BSz0_;
245  double Beamsigmaz_;
246  double Beamdxdz_;
247  double BeamWidthX_;
248  double BeamWidthY_;
249  double wxy2_;
250 
251  // track-related quantities
252  double pt_[nMaxtracks_];
253  double p_[nMaxtracks_];
264  double eta_[nMaxtracks_];
266  double phi_[nMaxtracks_];
271  double dz_[nMaxtracks_];
272  double dxy_[nMaxtracks_];
287 
291 
295 
299 
302 
304 
309 
312 
313  // histogram for sanity check
314  TH1F* h_etaMax;
315  TH1F* h_nbins;
316  TH1F* h_nLadders;
317  TH1F* h_nModZ;
318  TH1F* h_pTinfo;
319 
320  std::map<unsigned int, std::pair<long long, long long> > runNumbersTimesLog_;
323 
324  // ---- directly histograms // ===> unbiased residuals
325 
326  // absolute residuals
327 
328  std::vector<TH1F*> a_dxyPhiResiduals;
329  std::vector<TH1F*> a_dxyEtaResiduals;
330 
331  std::vector<TH1F*> a_dxPhiResiduals;
332  std::vector<TH1F*> a_dxEtaResiduals;
333 
334  std::vector<TH1F*> a_dyPhiResiduals;
335  std::vector<TH1F*> a_dyEtaResiduals;
336 
337  std::vector<TH1F*> a_dzPhiResiduals;
338  std::vector<TH1F*> a_dzEtaResiduals;
339 
340  std::vector<TH1F*> a_IP2DPhiResiduals;
341  std::vector<TH1F*> a_IP2DEtaResiduals;
342 
343  std::vector<TH1F*> a_IP3DPhiResiduals;
344  std::vector<TH1F*> a_IP3DEtaResiduals;
345 
346  std::vector<TH1F*> a_reszPhiResiduals;
347  std::vector<TH1F*> a_reszEtaResiduals;
348 
349  std::vector<TH1F*> a_d3DPhiResiduals;
350  std::vector<TH1F*> a_d3DEtaResiduals;
351 
352  // normalized residuals
353 
354  std::vector<TH1F*> n_dxyPhiResiduals;
355  std::vector<TH1F*> n_dxyEtaResiduals;
356 
357  std::vector<TH1F*> n_dzPhiResiduals;
358  std::vector<TH1F*> n_dzEtaResiduals;
359 
360  std::vector<TH1F*> n_IP2DPhiResiduals;
361  std::vector<TH1F*> n_IP2DEtaResiduals;
362 
363  std::vector<TH1F*> n_IP3DPhiResiduals;
364  std::vector<TH1F*> n_IP3DEtaResiduals;
365 
366  std::vector<TH1F*> n_reszPhiResiduals;
367  std::vector<TH1F*> n_reszEtaResiduals;
368 
369  std::vector<TH1F*> n_d3DPhiResiduals;
370  std::vector<TH1F*> n_d3DEtaResiduals;
371 
372  // for the maps
373 
377 
381 
382  // for the L1 maps
383 
388 
389  // ---- trends as function of phi and eta
390 
395 
400 
405 
410 
411  // ---- trends as a function of pT
412 
417 
422 
427 
432 
433  // --- trend as a function of the ladder/module number
434 
439 
444 
449 
454 
455  // ---- medians and MAD
456 
461 
466 
471 
476 
477  // 2D residuals
478 
479  TH2F* a_dxyVsPhi;
480  TH2F* a_dzVsPhi;
481 
482  TH2F* n_dxyVsPhi;
483  TH2F* n_dzVsPhi;
484 
485  TH2F* a_dxyVsEta;
486  TH2F* a_dzVsEta;
487 
488  TH2F* n_dxyVsEta;
489  TH2F* n_dzVsEta;
490 
491  // 2D maps
492 
494  TH2F* a_dzMeanMap;
495 
497  TH2F* n_dzMeanMap;
498 
501 
504 
505  //2D maps of residuals in bins of L1 modules
506 
509 
512 
515 
518 
519  //
520  // ---- directly histograms
521  // biased residuals
522 
523  // absolute residuals
524 
525  std::vector<TH1F*> a_dxyPhiBiasResiduals;
526  std::vector<TH1F*> a_dxyEtaBiasResiduals;
527 
528  std::vector<TH1F*> a_dzPhiBiasResiduals;
529  std::vector<TH1F*> a_dzEtaBiasResiduals;
530 
531  // normalized BiasResiduals
532 
533  std::vector<TH1F*> n_dxyPhiBiasResiduals;
534  std::vector<TH1F*> n_dxyEtaBiasResiduals;
535 
536  std::vector<TH1F*> n_dzPhiBiasResiduals;
537  std::vector<TH1F*> n_dzEtaBiasResiduals;
538 
539  // for the maps
540 
543 
546 
547  // ---- trends as function of phi / eta
548 
553 
558 
563 
568 
569  // ---- medians and MAD
570 
575 
580 
585 
590 
591  // 2D maps
592 
595 
598 
601 
604 
605  // check event
606  TH1F* h_nTracks;
607  TH1F* h_nClus;
609  TH1F* h_runNumber;
619  TH1F* h_BSx0;
620  TH1F* h_BSy0;
621  TH1F* h_BSz0;
625 
626  // check probe
627 
630 
631  TH1F* h_probeP_;
632  TH1F* h_probePt_;
634  TH1F* h_probeEta_;
635  TH1F* h_probePhi_;
640 
643 
646 
649 
653 
661 
671 
675 
679 
680  // check vertex
681 
689 
694 
695  std::map<std::string, TH1*> hDA;
696 
697  // histograms for the plots as function of pT
698 
699  std::vector<TH1F*> h_dxy_pT_;
700  std::vector<TH1F*> h_dz_pT_;
701  std::vector<TH1F*> h_norm_dxy_pT_;
702  std::vector<TH1F*> h_norm_dz_pT_;
703 
704  std::vector<TH1F*> h_dxy_Central_pT_;
705  std::vector<TH1F*> h_dz_Central_pT_;
706  std::vector<TH1F*> h_norm_dxy_Central_pT_;
707  std::vector<TH1F*> h_norm_dz_Central_pT_;
708 
709  // histograms for the plots as function of module ladder and number
710 
711  std::vector<TH1F*> h_dxy_modZ_;
712  std::vector<TH1F*> h_dz_modZ_;
713  std::vector<TH1F*> h_norm_dxy_modZ_;
714  std::vector<TH1F*> h_norm_dz_modZ_;
715 
716  std::vector<TH1F*> h_dxy_ladderOverlap_;
717  std::vector<TH1F*> h_dxy_ladderNoOverlap_;
718 
719  std::vector<TH1F*> h_dxy_ladder_;
720  std::vector<TH1F*> h_dz_ladder_;
721  std::vector<TH1F*> h_norm_dxy_ladder_;
722  std::vector<TH1F*> h_norm_dz_ladder_;
723 };
724 
725 #endif
std::vector< TH1F * > h_norm_dxy_modZ_
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)
edm::EDGetTokenT< reco::TrackCollection > theTrackCollectionToken_
std::vector< TH1F * > n_IP3DPhiResiduals
std::vector< TH1F * > a_dxyEtaResiduals
TH1F * n_dzResidualsMap[nMaxBins_][nMaxBins_]
std::vector< TH1F * > a_d3DEtaResiduals
std::vector< TH1F * > n_reszPhiResiduals
std::vector< unsigned int > runControlNumbers_
static bool vtxSort(const reco::Vertex &a, const reco::Vertex &b)
edm::EDGetTokenT< reco::BeamSpot > theBeamspotToken_
void shrinkHistVectorToFit(std::vector< TH1F *> &h, unsigned int desired_size)
void fillTrendPlot(TH1F *trendPlot, TH1F *residualsPlot[100], PVValHelper::estimator fitPar_, const std::string &var_)
std::vector< TH1F * > h_dxy_pT_
TH1F * a_dxyResidualsMap[nMaxBins_][nMaxBins_]
std::map< std::string, TH1 * > hDA
std::vector< TH1F * > a_IP3DEtaResiduals
void beginRun(edm::Run const &iRun, edm::EventSetup const &iSetup) override
std::vector< TH1F * > n_dzPhiResiduals
std::vector< TH1F * > a_d3DPhiResiduals
std::vector< TH1F * > n_d3DPhiResiduals
PrimaryVertexValidation(const edm::ParameterSet &)
std::vector< TH1F * > n_dxyPhiBiasResiduals
TH1F * n_dxyBiasResidualsMap[nMaxBins_][nMaxBins_]
std::vector< TH1F * > n_d3DEtaResiduals
const edm::ESGetToken< GlobalTrackingGeometry, GlobalTrackingGeometryRecord > trackingGeomToken_
std::vector< TH1F * > h_norm_dz_Central_pT_
float DOFUnbiasedVertex_[nMaxtracks_]
double d3DFromMyVertex_[nMaxtracks_]
std::vector< TH1F * > a_reszPhiResiduals
std::pair< Measurement1D, Measurement1D > fitResiduals(TH1 *hist)
std::vector< TH1F * > a_IP2DPhiResiduals
float chi2ProbUnbiasedVertex_[nMaxtracks_]
std::vector< TH1F * > n_reszEtaResiduals
double dxyFromMyVertex_[nMaxtracks_]
std::map< std::string, TH1 * > bookVertexHistograms(const TFileDirectory &dir)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::vector< TH1F * > h_dz_modZ_
std::vector< TH1F * > h_dxy_modZ_
std::vector< TH1F * > a_dxEtaResiduals
std::pair< bool, bool > pixelHitsCheck(const reco::TransientTrack &track)
double dzErrorFromMyVertex_[nMaxtracks_]
void endRun(edm::Run const &, edm::EventSetup const &) override
std::vector< TH1F * > n_dxyEtaBiasResiduals
std::vector< TH1F * > n_dxyEtaResiduals
double IPTsigFromMyVertex_[nMaxtracks_]
std::vector< TH1F * > a_dzPhiBiasResiduals
Measurement1D getMedian(TH1F *histo)
std::vector< TH1F * > h_norm_dxy_pT_
std::vector< TH1F * > a_dzEtaResiduals
edm::EDGetTokenT< reco::VertexCollection > theVertexCollectionToken_
int tracksUsedForVertexing_[nMaxtracks_]
Definition: TTTypes.h:54
std::vector< TH1F * > a_dxyEtaBiasResiduals
const edm::ESGetToken< RunInfo, RunInfoRcd > runInfoTokenBR_
std::vector< TH1F * > h_norm_dxy_ladder_
std::vector< TH1F * > a_dzPhiResiduals
double yUnbiasedVertex_[nMaxtracks_]
std::unique_ptr< TrackClusterizerInZ > theTrackClusterizer_
std::vector< TH1F * > n_dxyPhiResiduals
std::tuple< std::string, std::string, std::string > getTypeString(PVValHelper::residualType type)
TH1F * a_dzL1ResidualsMap[nMaxBins_][nMaxBins_]
double zUnbiasedVertex_[nMaxtracks_]
std::vector< TH1F * > h_dxy_ladder_
float chi2normUnbiasedVertex_[nMaxtracks_]
TH1F * n_d3DResidualsMap[nMaxBins_][nMaxBins_]
std::vector< TH1F * > a_dxyPhiResiduals
std::vector< TH1F * > a_dxyPhiBiasResiduals
void analyze(const edm::Event &, const edm::EventSetup &) override
TH1F * a_d3DResidualsMap[nMaxBins_][nMaxBins_]
std::vector< TH1F * > h_dxy_ladderNoOverlap_
void fillByIndex(std::vector< TH1F *> &h, unsigned int index, double x, std::string tag="")
TH1F * n_dxyL1ResidualsMap[nMaxBins_][nMaxBins_]
double IPLsigFromMyVertex_[nMaxtracks_]
void fillMap(TH2F *trendMap, TH1F *residualsMapPlot[100][100], PVValHelper::estimator fitPar_, const int nXBins_, const int nYBins_)
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > topoToken_
bool hasFirstLayerPixelHits(const reco::TransientTrack &track)
std::vector< TH1F * > n_dzEtaResiduals
std::unique_ptr< TrackFilterForPVFindingBase > theTrackFilter_
std::vector< TH1F * > n_IP3DEtaResiduals
__shared__ Hist hist
std::vector< TH1F * > h_norm_dz_pT_
bool isHit2D(const TrackingRecHit &hit, const PVValHelper::detectorPhase &thePhase) const
bool isBFieldConsistentWithMode(const edm::EventSetup &iSetup) const
TH1F * a_dxyL1ResidualsMap[nMaxBins_][nMaxBins_]
std::vector< TH1F * > h_dz_pT_
const edm::ESGetToken< TransientTrackBuilder, TransientTrackRecord > ttkToken_
std::vector< TH1F * > n_dzEtaBiasResiduals
std::vector< TH1F * > h_dz_Central_pT_
edm::Service< TFileService > fs
void add(std::map< std::string, TH1 *> &h, TH1 *hist)
std::vector< TH1F * > h_dz_ladder_
std::vector< TH1F * > a_IP2DEtaResiduals
double b
Definition: hdecay.h:118
std::vector< TH1F * > n_IP2DPhiResiduals
double xUnbiasedVertex_[nMaxtracks_]
std::vector< TH1F * > h_dxy_Central_pT_
PVValHelper::detectorPhase phase_
Measurement1D getMAD(TH1F *histo)
TH1F * n_dzL1ResidualsMap[nMaxBins_][nMaxBins_]
std::map< unsigned int, std::pair< long long, long long > > runNumbersTimesLog_
~PrimaryVertexValidation() override
double dzFromMyVertex_[nMaxtracks_]
double a
Definition: hdecay.h:119
std::vector< TH1F * > a_reszEtaResiduals
std::vector< TH1F * > bookResidualsHistogram(const TFileDirectory &dir, unsigned int theNOfBins, PVValHelper::residualType resType, PVValHelper::plotVariable varType, bool isNormalized=false)
std::tuple< std::string, std::string, std::string > getVarString(PVValHelper::plotVariable var)
TH1F * a_dxyBiasResidualsMap[nMaxBins_][nMaxBins_]
std::vector< TH1F * > a_dxPhiResiduals
std::vector< TH1F * > h_norm_dz_modZ_
TH1F * n_dxyResidualsMap[nMaxBins_][nMaxBins_]
bool passesTrackCuts(const reco::Track &track, const reco::Vertex &vertex, const std::string &qualityString_, double dxyErrMax_, double dzErrMax_, double ptErrMax_)
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > topoTokenBR_
double dxyErrorFromMyVertex_[nMaxtracks_]
std::vector< TH1F * > a_dyEtaResiduals
std::vector< TH1F * > n_IP2DEtaResiduals
std::vector< TH1F * > h_norm_dz_ladder_
float sumOfWeightsUnbiasedVertex_[nMaxtracks_]
TH1F * n_dzBiasResidualsMap[nMaxBins_][nMaxBins_]
double d3DErrorFromMyVertex_[nMaxtracks_]
std::vector< TH1F * > a_dyPhiResiduals
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
std::vector< TH1F * > h_dxy_ladderOverlap_
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > magFieldToken_
TH1F * a_dzBiasResidualsMap[nMaxBins_][nMaxBins_]
PVValHelper::histodetails theDetails_
std::array< float, nPtBins_+1 > mypT_bins_
TH1F * a_dzResidualsMap[nMaxBins_][nMaxBins_]
float chi2UnbiasedVertex_[nMaxtracks_]
std::pair< long long, long long > getRunTime(const edm::EventSetup &iSetup) const
void fill(std::map< std::string, TH1 *> &h, const std::string &s, double x)
std::vector< TH1F * > h_norm_dxy_Central_pT_
Definition: Run.h:45
void fillTrendPlotByIndex(TH1F *trendPlot, std::vector< TH1F *> &h, PVValHelper::estimator fitPar_, PVValHelper::plotVariable plotVar=PVValHelper::END_OF_PLOTS)
std::vector< TH1F * > a_dzEtaBiasResiduals
std::vector< TH1F * > a_IP3DPhiResiduals
std::vector< TH1F * > n_dzPhiBiasResiduals
double IP3DsigFromMyVertex_[nMaxtracks_]
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > geomTokenBR_