Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-05-31 04:19:51

0001 #include "RecoMuon/TrackerSeedGenerator/interface/SeedMvaEstimator.h"
0002 
0003 #include "DataFormats/Math/interface/deltaPhi.h"
0004 #include "DataFormats/Math/interface/deltaR.h"
0005 
0006 #include "FWCore/ParameterSet/interface/FileInPath.h"
0007 #include "CommonTools/MVAUtils/interface/GBRForestTools.h"
0008 
0009 SeedMvaEstimator::SeedMvaEstimator(const edm::FileInPath& weightsfile,
0010                                    const std::vector<double>& scale_mean,
0011                                    const std::vector<double>& scale_std,
0012                                    const bool isFromL1,
0013                                    const int minL1Qual)
0014     : scale_mean_(scale_mean.begin(), scale_mean.end()), isFromL1_(isFromL1), minL1Qual_(minL1Qual) {
0015   scale_istd_.reserve(scale_std.size());
0016   for (auto v : scale_std)
0017     scale_istd_.push_back(1. / v);
0018   gbrForest_ = createGBRForest(weightsfile);
0019 }
0020 
0021 SeedMvaEstimator::~SeedMvaEstimator() {}
0022 
0023 void SeedMvaEstimator::getL1MuonVariables(const GlobalVector& global_p,
0024                                           const l1t::MuonBxCollection& l1Muons,
0025                                           float& dR2dRL1SeedP,
0026                                           float& dPhidRL1SeedP) const {
0027   int ibx = 0;  // -- only take when ibx == 0 -- //
0028 
0029   auto eta = global_p.eta();
0030   auto phi = global_p.barePhi();
0031   for (auto it = l1Muons.begin(ibx); it != l1Muons.end(ibx); it++) {
0032     if (it->hwQual() < minL1Qual_)
0033       continue;
0034 
0035     float dR2tmp = reco::deltaR2(it->etaAtVtx(), it->phiAtVtx(), eta, phi);
0036     if (dR2tmp < dR2dRL1SeedP) {
0037       dR2dRL1SeedP = dR2tmp;
0038       dPhidRL1SeedP = reco::deltaPhi(it->phiAtVtx(), phi);
0039     }
0040   }
0041 }
0042 
0043 void SeedMvaEstimator::getL2MuonVariables(const GlobalVector& global_p,
0044                                           const reco::RecoChargedCandidateCollection& l2Muons,
0045                                           float& dR2dRL2SeedP,
0046                                           float& dPhidRL2SeedP) const {
0047   auto eta = global_p.eta();
0048   auto phi = global_p.barePhi();
0049   for (auto it = l2Muons.begin(); it != l2Muons.end(); it++) {
0050     float dR2tmp = reco::deltaR2(it->eta(), it->phi(), eta, phi);
0051     if (dR2tmp < dR2dRL2SeedP) {
0052       dR2dRL2SeedP = dR2tmp;
0053       dPhidRL2SeedP = reco::deltaPhi(it->phi(), phi);
0054     }
0055   }
0056 }
0057 
0058 double SeedMvaEstimator::computeMva(const TrajectorySeed& seed,
0059                                     const GlobalVector& global_p,
0060                                     const l1t::MuonBxCollection& l1Muons,
0061                                     const reco::RecoChargedCandidateCollection& l2Muons) const {
0062   static constexpr float initDRdPhi(99999.);
0063   auto kLast = isFromL1_ ? kLastL1 : kLastL2;
0064   float var[kLast];
0065 
0066   var[kTsosErr0] = seed.startingState().error(0);
0067   var[kTsosErr2] = seed.startingState().error(2);
0068   var[kTsosErr5] = seed.startingState().error(5);
0069   var[kTsosDxdz] = seed.startingState().parameters().dxdz();
0070   var[kTsosDydz] = seed.startingState().parameters().dydz();
0071   var[kTsosQbp] = seed.startingState().parameters().qbp();
0072 
0073   float dR2dRL1SeedP = initDRdPhi;
0074   float dPhidRL1SeedP = initDRdPhi;
0075   getL1MuonVariables(global_p, l1Muons, dR2dRL1SeedP, dPhidRL1SeedP);
0076 
0077   var[kDRdRL1SeedP] = std::sqrt(dR2dRL1SeedP);
0078   var[kDPhidRL1SeedP] = dPhidRL1SeedP;
0079 
0080   if (!isFromL1_) {
0081     float dR2dRL2SeedP = initDRdPhi;
0082     float dPhidRL2SeedP = initDRdPhi;
0083     getL2MuonVariables(global_p, l2Muons, dR2dRL2SeedP, dPhidRL2SeedP);
0084 
0085     var[kDRdRL2SeedP] = std::sqrt(dR2dRL2SeedP);
0086     var[kDPhidRL2SeedP] = dPhidRL2SeedP;
0087   }
0088 
0089   for (int iv = 0; iv < kLast; ++iv) {
0090     var[iv] = (var[iv] - scale_mean_[iv]) * scale_istd_[iv];
0091   }
0092 
0093   return gbrForest_->GetResponse(var);
0094 }