CMS 3D CMS Logo

TTreeValidation.h
Go to the documentation of this file.
1 #ifndef RecoTracker_MkFitCore_standalone_TTreeValidation_h
2 #define RecoTracker_MkFitCore_standalone_TTreeValidation_h
3 
4 #include "Validation.h"
5 
6 #ifdef NO_ROOT
7 namespace mkfit {
8 
9  class TTreeValidation : public Validation {
10  public:
12  };
13 } // end namespace mkfit
14 #else
15 
16 #include <unordered_map>
17 #include <mutex>
18 #include "TFile.h"
19 #include "TTree.h"
20 #include "TROOT.h"
21 
22 namespace mkfit {
23  // FitVal defined in Validation.h
24  typedef std::map<int, FitVal> FitValLayMap;
25  typedef std::unordered_map<int, FitValLayMap> TkIDtoFitValLayMapMap;
26 
27  class TTreeValidation : public Validation {
28  public:
31 
34  void initializeConfigTree();
37  void initializeFitTree();
38 
39  void alignTracks(TrackVec& evt_tracks, TrackExtraVec& evt_extra, bool alignExtra) override;
40 
41  void collectFitInfo(const FitVal& tmpfitval, int tkid, int layer) override;
42 
43  void resetValidationMaps() override;
44  void resetFitBranches();
45 
46  void setTrackExtras(Event& ev) override;
47 
48  void makeSimTkToRecoTksMaps(Event& ev) override;
49  void mapRefTkToRecoTks(const TrackVec& evt_tracks, TrackExtraVec& evt_extras, TkIDToTkIDVecMap& refTkMap);
50  void makeSeedTkToRecoTkMaps(Event& ev) override;
51  void mapSeedTkToRecoTk(const TrackVec& evt_tracks, const TrackExtraVec& evt_extras, TkIDToTkIDMap& seedTkMap);
52  void makeRecoTkToRecoTkMaps(Event& ev) override;
53  void makeRecoTkToRecoTkMap(TkIDToTkIDMap& refToPairMap,
54  const TrackVec& reftracks,
55  const TrackExtraVec& refextras,
56  const TrackVec& pairtracks,
57  const TrackExtraVec& pairextras);
58  void makeCMSSWTkToRecoTksMaps(Event& ev) override;
59  void makeSeedTkToCMSSWTkMap(Event& ev) override;
60  void makeCMSSWTkToSeedTkMap(Event& ev) override;
62  void makeRecoTkToSeedTkMapDumbCMSSW(const TrackExtraVec& recoextras,
63  const TrackExtraVec& seedextras,
64  TkIDToTkIDMap& recoToSeedMap);
65 
66  void setTrackScoresDumbCMSSW(Event&) override;
67 
68  void storeSeedAndMCID(Event& ev);
69  void setupCMSSWMatching(const Event& ev, RedTrackVec& reducedCMSSW, LayIdxIDVecMapMap& cmsswHitIDMap);
70 
71  int getLastFoundHit(const int trackMCHitID, const int mcTrackID, const Event& ev);
72  int getMaskAssignment(const int refID);
73 
74  void fillMinHitInfo(const Track& track, std::vector<int>& lyrs, std::vector<int>& idxs);
75  void fillFullHitInfo(const Event& ev,
76  const Track& track,
77  std::vector<int>& lyrs,
78  std::vector<int>& idxs,
79  std::vector<int>& mcTkIDs,
80  std::vector<float>& xs,
81  std::vector<float>& ys,
82  std::vector<float>& zs);
83 
84  void fillEfficiencyTree(const Event& ev) override;
85  void fillFakeRateTree(const Event& ev) override;
86  void fillConfigTree() override;
87  void fillCMSSWEfficiencyTree(const Event& ev) override;
88  void fillCMSSWFakeRateTree(const Event& ev) override;
89  void fillFitTree(const Event& ev) override;
90 
91  void saveTTrees() override;
92 
93  private:
94  std::unique_ptr<TFile> f_; // output file!
95 
96  TkIDtoFitValLayMapMap fitValTkMapMap_; // map used for fit validation in mplex
97 
98  // Sim to Reco Maps
102 
103  // Reco to Reco Maps
106 
107  // CMSSW to Reco Maps
110 
111  // Special map for CMSSW tracks to seed track labels --> NOT used for fake rate!!
114 
115  // Special map for geting exact CMSSW track that originate build track from seed track through seedIDs
117 
118  // Special map for associating candidate to fit tracks in CMSSW only
121 
122  // Special map for associating reco tracks to seed tracks for sim_val_for_cmssw
125 
126  // Efficiency Tree
127  std::unique_ptr<TTree> efftree_;
128  int evtID_eff_ = 0, mcID_eff_ = 0;
132 
133  // for efficiency and duplicate rate plots
134  float x_mc_gen_eff_ = 0., y_mc_gen_eff_ = 0., z_mc_gen_eff_ = 0.;
138 
139  // for getting last hit positions track ended up on
143 
144  // for track resolutions / pulls
154 
155  // for hit countings
161 
162  // swim phi
164 
165  // quality info of tracks
169 
170  // for duplicate track matches
173 
174  //iterations provenance for each match - a bit mask similar to the ones used in the hit masking
177  ULong64_t algo_seed_eff_ = 0;
178 
179  // hit info
186 
187  // Fake Rate tree and variables
188  std::unique_ptr<TTree> frtree_;
189  int evtID_FR_ = 0, seedID_FR_ = 0;
190 
192 
193  // for getting last hit positions track ended up on
194  float xhit_seed_FR_ = 0., xhit_build_FR_ = 0., xhit_fit_FR_ = 0.;
195  float yhit_seed_FR_ = 0., yhit_build_FR_ = 0., yhit_fit_FR_ = 0.;
196  float zhit_seed_FR_ = 0., zhit_build_FR_ = 0., zhit_fit_FR_ = 0.;
197 
198  // track state info
200  float pt_seed_FR_ = 0., pt_build_FR_ = 0., pt_fit_FR_ = 0., ept_seed_FR_ = 0., ept_build_FR_ = 0., ept_fit_FR_ = 0.;
207 
213  int algorithm_FR_ = 0;
214 
215  // swim phi
216  float dphi_seed_FR_ = 0., dphi_build_FR_ = 0., dphi_fit_FR_ = 0.;
217 
220 
227 
229 
232 
233  // hit info
246 
247  // Configuration tree
248  std::unique_ptr<TTree> configtree_;
249  int Ntracks_ = 0, Nevents_ = 0;
250  float nLayers_ = 0;
252  float chi2Cut_min_ = 0., nSigma_ = 0., minDPhi_ = 0., maxDPhi_ = 0., minDEta_ = 0., maxDEta_ = 0.;
253  float beamspotX_ = 0., beamspotY_ = 0., beamspotZ_ = 0.;
254  float minSimPt_ = 0., maxSimPt_ = 0.;
255  float hitposerrXY_ = 0., hitposerrZ_ = 0., hitposerrR_ = 0.;
256  float varXY_ = 0., varZ_ = 0.;
257  float ptinverr049_ = 0., phierr049_ = 0., thetaerr049_ = 0., ptinverr012_ = 0., phierr012_ = 0., thetaerr012_ = 0.;
258 
259  // CMSSW Efficiency tree
260  std::unique_ptr<TTree> cmsswefftree_;
262 
263  float x_cmssw_ceff_ = 0., y_cmssw_ceff_ = 0., z_cmssw_ceff_ = 0.;
267 
268  // build
271 
272  float pt_build_ceff_ = 0., ept_build_ceff_ = 0.;
275 
278 
282 
284 
285  // chi2 of tracks + phi swim
288  float dphi_build_ceff_ = 0.;
289 
291 
292  // fit
295 
296  float pt_fit_ceff_ = 0., ept_fit_ceff_ = 0.;
297  float phi_fit_ceff_ = 0., ephi_fit_ceff_ = 0.;
298  float eta_fit_ceff_ = 0., eeta_fit_ceff_ = 0.;
299 
302 
303  float nLayers_fit_ceff_ = 0;
306 
308 
309  // chi2 of tracks + phi swim
312  float dphi_fit_ceff_ = 0.;
313 
315 
318  ULong64_t algo_seed_ceff_ = 0;
319 
320  // hit info
325 
326  // CMSSW FakeRate tree
327  std::unique_ptr<TTree> cmsswfrtree_;
329 
330  //seed algo
331  int algorithm_cFR_ = 0;
332 
333  // build info
335 
336  float pt_build_cFR_ = 0., ept_build_cFR_ = 0.;
337  float phi_build_cFR_ = 0., ephi_build_cFR_ = 0.;
338  float eta_build_cFR_ = 0., eeta_build_cFR_ = 0.;
339 
340  float x_mc_cFR_ = 0., y_mc_cFR_ = 0., z_mc_cFR_ = 0.;
341  float pt_mc_cFR_ = 0., phi_mc_cFR_ = 0., eta_mc_cFR_ = 0.;
342 
346 
348 
349  // chi2 of tracks
352  float dphi_build_cFR_ = 0.;
353 
354  // for duplicate track matches
356 
357  // cmssw info
363 
364  // fit info
366 
367  float pt_fit_cFR_ = 0., ept_fit_cFR_ = 0.;
368  float phi_fit_cFR_ = 0., ephi_fit_cFR_ = 0.;
369  float eta_fit_cFR_ = 0., eeta_fit_cFR_ = 0.;
370 
371  float nLayers_fit_cFR_ = 0;
374 
375  float xhit_fit_cFR_ = 0., yhit_fit_cFR_ = 0., zhit_fit_cFR_ = 0.;
376 
377  // chi2 of tracks
379  int score_fit_cFR_ = 0;
380  float dphi_fit_cFR_ = 0.;
381 
382  // for duplicate track matches
384 
385  // cmssw info
391 
392  // hit info
397 
398  // Fit tree (for fine tuning z-phi windows and such --> MPlex Only
399  std::unique_ptr<TTree> fittree_;
401 
402  static const int nfvs_ = 24;
403  std::vector<float> fvs_[nfvs_];
404 
405  std::vector<float>&z_prop_fit_ = fvs_[0], &ez_prop_fit_ = fvs_[1];
406  std::vector<float>&z_hit_fit_ = fvs_[2], &ez_hit_fit_ = fvs_[3], &z_sim_fit_ = fvs_[4], &ez_sim_fit_ = fvs_[5];
407  std::vector<float>&pphi_prop_fit_ = fvs_[6], &epphi_prop_fit_ = fvs_[7];
408  std::vector<float>&pphi_hit_fit_ = fvs_[8], &epphi_hit_fit_ = fvs_[9], &pphi_sim_fit_ = fvs_[10],
410  std::vector<float>&pt_up_fit_ = fvs_[12], &ept_up_fit_ = fvs_[13], &pt_sim_fit_ = fvs_[14],
412  std::vector<float>&mphi_up_fit_ = fvs_[16], &emphi_up_fit_ = fvs_[17], &mphi_sim_fit_ = fvs_[18],
414  std::vector<float>&meta_up_fit_ = fvs_[20], &emeta_up_fit_ = fvs_[21], &meta_sim_fit_ = fvs_[22],
416 
418  };
419 } // end namespace mkfit
420 #endif
421 #endif
std::vector< int > hitlyrs_mc_seed_FR_
std::vector< int > hitidxs_build_ceff_
std::unique_ptr< TFile > f_
std::unique_ptr< TTree > cmsswfrtree_
std::vector< int > hitmcTkIDs_fit_FR_
TkIDToTkIDMap fitToSeedMapDumbCMSSW_
std::vector< float > & emeta_up_fit_
void setTrackExtras(Event &ev) override
void fillFitTree(const Event &ev) override
std::vector< TrackExtra > TrackExtraVec
std::vector< int > hitidxs_mc_build_ceff_
TkIDToTkIDVecMap simToBuildMap_
std::vector< float > hitzs_mc_seed_FR_
std::vector< float > & ez_hit_fit_
void makeRecoTkToSeedTkMapsDumbCMSSW(Event &ev) override
std::unordered_map< int, FitValLayMap > TkIDtoFitValLayMapMap
std::vector< int > hitlyrs_build_cFR_
std::vector< int > hitmcTkIDs_mc_fit_FR_
TkIDToTkIDVecMap simToFitMap_
void makeCMSSWTkToSeedTkMap(Event &ev) override
void fillCMSSWFakeRateTree(const Event &ev) override
void makeSeedTkToCMSSWTkMap(Event &ev) override
std::vector< int > hitlyrs_fit_FR_
std::vector< float > hitzs_seed_eff_
std::vector< int > hitidxs_fit_cFR_
std::vector< int > hitmcTkIDs_mc_seed_FR_
std::vector< int > hitidxs_cmssw_fit_cFR_
std::vector< int > hitidxs_build_FR_
int getMaskAssignment(const int refID)
static std::mutex mutex
Definition: Proxy.cc:8
std::vector< float > hitxs_mc_fit_FR_
std::vector< float > & ez_prop_fit_
TkIDToTkIDMap buildToCmsswMap_
std::vector< float > hitxs_fit_eff_
void setTrackScoresDumbCMSSW(Event &) override
std::vector< float > & mphi_up_fit_
void mapSeedTkToRecoTk(const TrackVec &evt_tracks, const TrackExtraVec &evt_extras, TkIDToTkIDMap &seedTkMap)
std::vector< int > hitlyrs_mc_cFR_
TkIDToTkIDVecMap cmsswToBuildMap_
std::vector< int > hitlyrs_build_eff_
void saveTTrees() override
static const int nfvs_
std::vector< float > & mphi_sim_fit_
TkIDToTkIDMap seedToCmsswMap_
TkIDToTkIDMap fitToBuildMap_
void makeRecoTkToSeedTkMapDumbCMSSW(const TrackExtraVec &recoextras, const TrackExtraVec &seedextras, TkIDToTkIDMap &recoToSeedMap)
std::vector< int > hitmcTkIDs_mc_build_FR_
std::vector< int > hitidxs_mc_build_FR_
std::vector< float > & pphi_prop_fit_
std::vector< float > & meta_up_fit_
std::unordered_map< int, std::vector< int > > TkIDToTkIDVecMap
Definition: TrackExtra.h:125
std::vector< int > hitlyrs_seed_eff_
std::vector< int > hitidxs_fit_ceff_
std::vector< float > & ept_up_fit_
void fillConfigTree() override
std::vector< float > hitys_build_eff_
std::vector< int > hitlyrs_cmssw_build_cFR_
std::vector< float > & emphi_sim_fit_
std::vector< int > hitlyrs_fit_cFR_
std::vector< int > hitidxs_seed_FR_
TkIDToTkIDMap seedToFitMap_
std::vector< int > hitidxs_fit_FR_
std::vector< float > & pphi_hit_fit_
std::vector< float > & pt_up_fit_
std::vector< float > & pphi_sim_fit_
std::vector< int > hitidxs_mc_eff_
std::vector< int > hitmcTkIDs_mc_eff_
std::unique_ptr< TTree > cmsswefftree_
void fillFakeRateTree(const Event &ev) override
std::vector< float > hitys_mc_fit_FR_
std::vector< int > hitidxs_mc_cFR_
void setupCMSSWMatching(const Event &ev, RedTrackVec &reducedCMSSW, LayIdxIDVecMapMap &cmsswHitIDMap)
std::vector< int > hitlyrs_build_ceff_
std::vector< int > hitlyrs_build_FR_
std::vector< float > hitxs_build_eff_
std::vector< int > hitlyrs_fit_eff_
std::unordered_map< int, int > TkIDToTkIDMap
Definition: TrackExtra.h:124
std::unique_ptr< TTree > fittree_
std::vector< float > & ez_sim_fit_
std::unique_ptr< TTree > efftree_
std::vector< int > hitidxs_mc_fit_FR_
std::vector< int > hitidxs_cmssw_build_cFR_
ULong64_t iterduplmask_build_ceff_
std::vector< ReducedTrack > RedTrackVec
Definition: TrackExtra.h:35
std::vector< float > & z_sim_fit_
std::vector< float > hitzs_mc_build_FR_
std::vector< float > & emeta_sim_fit_
std::vector< int > hitmcTkIDs_fit_eff_
void makeRecoTkToRecoTkMap(TkIDToTkIDMap &refToPairMap, const TrackVec &reftracks, const TrackExtraVec &refextras, const TrackVec &pairtracks, const TrackExtraVec &pairextras)
std::vector< float > hitxs_seed_FR_
void fillCMSSWEfficiencyTree(const Event &ev) override
TkIDToTkIDMap candToSeedMapDumbCMSSW_
std::vector< int > hitidxs_cmssw_ceff_
std::vector< float > hitys_mc_eff_
void makeCMSSWTkToRecoTksMaps(Event &ev) override
TkIDtoFitValLayMapMap fitValTkMapMap_
std::vector< int > hitlyrs_cmssw_fit_cFR_
void mapRefTkToRecoTks(const TrackVec &evt_tracks, TrackExtraVec &evt_extras, TkIDToTkIDVecMap &refTkMap)
std::vector< float > hitxs_build_FR_
TTreeValidation(std::string fileName, const TrackerInfo *trk_info)
std::vector< float > hitzs_seed_FR_
int getLastFoundHit(const int trackMCHitID, const int mcTrackID, const Event &ev)
std::vector< int > hitidxs_build_cFR_
std::vector< float > & meta_sim_fit_
std::vector< float > hitxs_fit_FR_
std::vector< float > hitxs_mc_build_FR_
std::vector< float > & epphi_hit_fit_
std::vector< Track > TrackVec
std::vector< float > hitxs_seed_eff_
std::vector< float > hitys_build_FR_
std::vector< float > & emphi_up_fit_
std::vector< float > hitys_seed_FR_
std::vector< float > hitzs_mc_eff_
std::map< int, FitVal > FitValLayMap
TkIDToTkIDMap seedToBuildMap_
TkIDToTkIDVecMap simToSeedMap_
std::vector< float > hitzs_build_eff_
void fillEfficiencyTree(const Event &ev) override
std::vector< int > hitmcTkIDs_seed_FR_
std::vector< float > & ept_sim_fit_
std::vector< float > fvs_[nfvs_]
std::vector< float > hitzs_fit_eff_
std::vector< float > hitzs_build_FR_
std::vector< float > hitzs_mc_fit_FR_
void fillFullHitInfo(const Event &ev, const Track &track, std::vector< int > &lyrs, std::vector< int > &idxs, std::vector< int > &mcTkIDs, std::vector< float > &xs, std::vector< float > &ys, std::vector< float > &zs)
std::vector< float > hitxs_mc_seed_FR_
void alignTracks(TrackVec &evt_tracks, TrackExtraVec &evt_extra, bool alignExtra) override
std::vector< float > & z_hit_fit_
std::vector< float > & epphi_prop_fit_
std::vector< int > hitidxs_build_eff_
std::vector< float > hitys_mc_build_FR_
std::vector< int > hitlyrs_mc_eff_
std::vector< int > hitlyrs_mc_fit_FR_
std::vector< int > hitmcTkIDs_build_eff_
std::vector< float > hitys_fit_eff_
std::vector< float > hitzs_fit_FR_
std::vector< float > hitxs_mc_eff_
void storeSeedAndMCID(Event &ev)
void makeRecoTkToRecoTkMaps(Event &ev) override
std::vector< int > hitlyrs_seed_FR_
std::vector< int > hitlyrs_cmssw_ceff_
std::vector< float > hitys_mc_seed_FR_
std::vector< int > hitlyrs_fit_ceff_
std::vector< int > hitlyrs_mc_fit_ceff_
std::vector< int > hitidxs_mc_fit_ceff_
TkIDToTkIDVecMap cmsswToFitMap_
std::vector< int > hitmcTkIDs_build_FR_
TkIDToTkIDMap cmsswToSeedMap_
std::vector< float > hitys_fit_FR_
std::map< int, std::map< int, std::vector< int > > > LayIdxIDVecMapMap
Definition: TrackExtra.h:37
std::vector< int > hitmcTkIDs_seed_eff_
std::vector< int > hitlyrs_mc_build_ceff_
std::vector< float > hitys_seed_eff_
void makeSimTkToRecoTksMaps(Event &ev) override
std::unique_ptr< TTree > frtree_
std::vector< int > hitidxs_mc_seed_FR_
std::vector< float > & pt_sim_fit_
std::vector< float > & z_prop_fit_
void makeSeedTkToRecoTkMaps(Event &ev) override
void resetValidationMaps() override
void collectFitInfo(const FitVal &tmpfitval, int tkid, int layer) override
TkIDToTkIDMap buildToFitMap_
std::vector< int > hitidxs_seed_eff_
void fillMinHitInfo(const Track &track, std::vector< int > &lyrs, std::vector< int > &idxs)
std::unique_ptr< TTree > configtree_
std::vector< float > & epphi_sim_fit_
std::vector< int > hitidxs_fit_eff_
std::vector< int > hitlyrs_mc_build_FR_