CMS 3D CMS Logo

MuonHLTSeedMVAClassifier.cc
Go to the documentation of this file.
1 
2 // Package: RecoMuon_TrackerSeedGenerator
3 // Class: MuonHLTSeedMVAClassifier
4 
5 // Original Author: Won Jun, OH Minseok
6 // Created: Fri, 28 May 2021
7 
8 // system include files
9 #include <memory>
10 #include <cmath>
11 
12 // user include files
15 
18 
21 
22 // Geometry
25 
26 // TrajectorySeed
33 
35 
36 // class declaration
37 bool sortByMvaScore(const std::pair<unsigned, double>& A, const std::pair<unsigned, double>& B) {
38  return (A.second > B.second);
39 };
40 
42 public:
44  ~MuonHLTSeedMVAClassifier() override = default;
45 
46  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
47 
48 private:
49  void produce(edm::Event&, const edm::EventSetup&) override;
50 
51  // member data
56 
57  typedef std::pair<std::unique_ptr<const SeedMvaEstimator>, std::unique_ptr<const SeedMvaEstimator>>
60 
61  const bool rejectAll_;
62  const bool isFromL1_;
63 
66 
67  const std::vector<double> mvaScaleMeanB_;
68  const std::vector<double> mvaScaleStdB_;
69  const std::vector<double> mvaScaleMeanE_;
70  const std::vector<double> mvaScaleStdE_;
71 
72  const bool doSort_;
73  const int nSeedsMaxB_;
74  const int nSeedsMaxE_;
75 
76  const double etaEdge_;
77  const double mvaCutB_;
78  const double mvaCutE_;
79 
80  const int minL1Qual_;
81  const double baseScore_;
82 
83  double getSeedMva(const PairSeedMvaEstimator& pairMvaEstimator,
84  const TrajectorySeed& seed,
85  const GlobalVector& global_p,
86  const l1t::MuonBxCollection& l1Muons,
88 };
89 
91  : seedToken_(consumes<TrajectorySeedCollection>(iConfig.getParameter<edm::InputTag>("src"))),
92  l1MuonToken_(consumes<l1t::MuonBxCollection>(iConfig.getParameter<edm::InputTag>("L1Muon"))),
93  l2MuonToken_(consumes<reco::RecoChargedCandidateCollection>(iConfig.getParameter<edm::InputTag>("L2Muon"))),
94  trackerGeometryToken_(esConsumes<TrackerGeometry, TrackerDigiGeometryRecord>()),
95 
96  rejectAll_(iConfig.getParameter<bool>("rejectAll")),
97  isFromL1_(iConfig.getParameter<bool>("isFromL1")),
98 
99  mvaFileB_(iConfig.getParameter<edm::FileInPath>(isFromL1_ ? "mvaFileBL1" : "mvaFileBL2")),
100  mvaFileE_(iConfig.getParameter<edm::FileInPath>(isFromL1_ ? "mvaFileEL1" : "mvaFileEL2")),
101 
102  mvaScaleMeanB_(iConfig.getParameter<std::vector<double>>(isFromL1_ ? "mvaScaleMeanBL1" : "mvaScaleMeanBL2")),
103  mvaScaleStdB_(iConfig.getParameter<std::vector<double>>(isFromL1_ ? "mvaScaleStdBL1" : "mvaScaleStdBL2")),
104  mvaScaleMeanE_(iConfig.getParameter<std::vector<double>>(isFromL1_ ? "mvaScaleMeanEL1" : "mvaScaleMeanEL2")),
105  mvaScaleStdE_(iConfig.getParameter<std::vector<double>>(isFromL1_ ? "mvaScaleStdEL1" : "mvaScaleStdEL2")),
106 
107  doSort_(iConfig.getParameter<bool>("doSort")),
108  nSeedsMaxB_(iConfig.getParameter<int>("nSeedsMaxB")),
109  nSeedsMaxE_(iConfig.getParameter<int>("nSeedsMaxE")),
110 
111  etaEdge_(iConfig.getParameter<double>("etaEdge")),
112  mvaCutB_(iConfig.getParameter<double>("mvaCutB")),
113  mvaCutE_(iConfig.getParameter<double>("mvaCutE")),
114 
115  minL1Qual_(iConfig.getParameter<int>("minL1Qual")),
116  baseScore_(iConfig.getParameter<double>("baseScore")) {
117  if (!rejectAll_) {
118  mvaEstimator_ = std::make_pair(
119  std::make_unique<SeedMvaEstimator>(mvaFileB_, mvaScaleMeanB_, mvaScaleStdB_, isFromL1_, minL1Qual_),
120  std::make_unique<SeedMvaEstimator>(mvaFileE_, mvaScaleMeanE_, mvaScaleStdE_, isFromL1_, minL1Qual_));
121  }
122 
123  produces<TrajectorySeedCollection>();
124 }
125 
126 // -- method called on each new Event
128  auto result = std::make_unique<TrajectorySeedCollection>();
129 
130  if (rejectAll_) {
131  iEvent.put(std::move(result));
132  return;
133  }
134 
135  if (doSort_ && nSeedsMaxB_ <= 0 && nSeedsMaxE_ <= 0) {
136  iEvent.put(std::move(result));
137  return;
138  }
139 
140  if (!doSort_ && mvaCutB_ > 1. && mvaCutE_ > 1.) {
141  iEvent.put(std::move(result));
142  return;
143  }
144 
146  const l1t::MuonBxCollection& l1Muons = iEvent.get(l1MuonToken_);
148  const TrackerGeometry& trkGeom = iEventSetup.getData(trackerGeometryToken_);
149 
150  std::vector<std::pair<unsigned, double>> pairSeedIdxMvaScoreB = {};
151  std::vector<std::pair<unsigned, double>> pairSeedIdxMvaScoreE = {};
152  for (auto& seed : seeds) {
153  const GlobalVector global_p =
154  trkGeom.idToDet(seed.startingState().detId())->surface().toGlobal(seed.startingState().parameters().momentum());
155 
156  bool isB = (std::abs(global_p.eta()) < etaEdge_);
157 
158  if (doSort_) {
159  if (isB) {
160  if (nSeedsMaxB_ <= 0) {
161  continue;
162  }
163  } else {
164  if (nSeedsMaxE_ <= 0) {
165  continue;
166  }
167  }
168  } else {
169  if (isB) {
170  if (mvaCutB_ > 1.0) {
171  continue;
172  } else if (mvaCutB_ <= 0.) {
173  result->emplace_back(seed);
174  continue;
175  }
176  } else {
177  if (mvaCutE_ > 1.0) {
178  continue;
179  } else if (mvaCutE_ <= 0.) {
180  result->emplace_back(seed);
181  continue;
182  }
183  }
184  }
185 
186  double mva = getSeedMva(mvaEstimator_, seed, global_p, l1Muons, l2Muons);
187 
188  double score = 1. / (1. + std::exp(-1. * mva));
189  bool passMva = isB ? score > mvaCutB_ : score > mvaCutE_;
190  if (!passMva)
191  continue;
192 
193  if (doSort_) {
194  if (isB)
195  pairSeedIdxMvaScoreB.push_back(std::make_pair(&seed - &seeds.at(0), score));
196  else
197  pairSeedIdxMvaScoreE.push_back(std::make_pair(&seed - &seeds.at(0), score));
198  } else {
199  result->emplace_back(seed);
200  }
201  }
202 
203  if (doSort_) {
204  std::sort(pairSeedIdxMvaScoreB.begin(), pairSeedIdxMvaScoreB.end(), sortByMvaScore);
205  std::sort(pairSeedIdxMvaScoreE.begin(), pairSeedIdxMvaScoreE.end(), sortByMvaScore);
206 
207  for (auto i = 0U; i < pairSeedIdxMvaScoreB.size(); ++i) {
208  if ((int)i == nSeedsMaxB_)
209  break;
210  const auto& seed(seeds.at(pairSeedIdxMvaScoreB.at(i).first));
211  result->emplace_back(seed);
212  }
213 
214  for (auto i = 0U; i < pairSeedIdxMvaScoreE.size(); ++i) {
215  if ((int)i == nSeedsMaxE_)
216  break;
217  const auto& seed(seeds.at(pairSeedIdxMvaScoreE.at(i).first));
218  result->emplace_back(seed);
219  }
220  }
221 
222  iEvent.put(std::move(result));
223 }
224 
226  const TrajectorySeed& seed,
227  const GlobalVector& global_p,
228  const l1t::MuonBxCollection& l1Muons,
229  const reco::RecoChargedCandidateCollection& l2Muons) {
230  double mva = 0.;
231  if (std::abs(global_p.eta()) < etaEdge_) {
232  mva = pairMvaEstimator.first->computeMva(seed, global_p, l1Muons, l2Muons);
233  } else {
234  mva = pairMvaEstimator.second->computeMva(seed, global_p, l1Muons, l2Muons);
235  }
236 
237  return (mva + baseScore_);
238 }
239 
240 // -- method fills 'descriptions' with the allowed parameters for the module ------------
243  desc.add<edm::InputTag>("src", edm::InputTag("hltIter2IterL3MuonPixelSeeds", ""));
244  desc.add<edm::InputTag>("L1Muon", edm::InputTag("hltGtStage2Digis", "Muon"));
245  desc.add<edm::InputTag>("L2Muon", edm::InputTag("hltL2MuonCandidates", ""));
246 
247  desc.add<bool>("rejectAll", false);
248  desc.add<bool>("isFromL1", false);
249 
250  desc.add<edm::FileInPath>("mvaFileBL1",
251  edm::FileInPath("RecoMuon/TrackerSeedGenerator/data/xgb_Run3_Iter2FromL1Seeds_barrel.xml"));
252  desc.add<edm::FileInPath>("mvaFileEL1",
253  edm::FileInPath("RecoMuon/TrackerSeedGenerator/data/xgb_Run3_Iter2FromL1Seeds_endcap.xml"));
254  desc.add<edm::FileInPath>("mvaFileBL2",
255  edm::FileInPath("RecoMuon/TrackerSeedGenerator/data/xgb_Run3_Iter2Seeds_barrel.xml"));
256  desc.add<edm::FileInPath>("mvaFileEL2",
257  edm::FileInPath("RecoMuon/TrackerSeedGenerator/data/xgb_Run3_Iter2Seeds_endcap.xml"));
258  desc.add<std::vector<double>>("mvaScaleMeanBL1", {0., 0., 0., 0., 0., 0., 0., 0.});
259  desc.add<std::vector<double>>("mvaScaleStdBL1", {1., 1., 1., 1., 1., 1., 1., 1.});
260  desc.add<std::vector<double>>("mvaScaleMeanEL1", {0., 0., 0., 0., 0., 0., 0., 0.});
261  desc.add<std::vector<double>>("mvaScaleStdEL1", {1., 1., 1., 1., 1., 1., 1., 1.});
262  desc.add<std::vector<double>>("mvaScaleMeanBL2", {0., 0., 0., 0., 0., 0., 0., 0., 0., 0.});
263  desc.add<std::vector<double>>("mvaScaleStdBL2", {1., 1., 1., 1., 1., 1., 1., 1., 1., 1.});
264  desc.add<std::vector<double>>("mvaScaleMeanEL2", {0., 0., 0., 0., 0., 0., 0., 0., 0., 0.});
265  desc.add<std::vector<double>>("mvaScaleStdEL2", {1., 1., 1., 1., 1., 1., 1., 1., 1., 1.});
266 
267  desc.add<bool>("doSort", false);
268  desc.add<int>("nSeedsMaxB", 1e6);
269  desc.add<int>("nSeedsMaxE", 1e6);
270 
271  desc.add<double>("etaEdge", 1.2);
272  desc.add<double>("mvaCutB", -1.);
273  desc.add<double>("mvaCutE", -1.);
274 
275  desc.add<int>("minL1Qual", 7);
276  desc.add<double>("baseScore", 0.5);
277 
278  descriptions.add("MuonHLTSeedMVAClassifier", desc);
279 }
280 
281 //define this as a plug-in
Vector3DBase
Definition: Vector3DBase.h:8
TrackerGeometry::idToDet
const TrackerGeomDet * idToDet(DetId) const override
Definition: TrackerGeometry.cc:193
MuonHLTSeedMVAClassifier::minL1Qual_
const int minL1Qual_
Definition: MuonHLTSeedMVAClassifier.cc:80
electrons_cff.bool
bool
Definition: electrons_cff.py:366
mps_fire.i
i
Definition: mps_fire.py:428
MuonHLTSeedMVAClassifier::~MuonHLTSeedMVAClassifier
~MuonHLTSeedMVAClassifier() override=default
TrackerGeometry.h
TrajectorySeedCollection
std::vector< TrajectorySeed > TrajectorySeedCollection
Definition: TrajectorySeedCollection.h:6
MuonHLTSeedMVAClassifier
Definition: MuonHLTSeedMVAClassifier.cc:41
MuonHLTSeedMVAClassifier::mvaCutE_
const double mvaCutE_
Definition: MuonHLTSeedMVAClassifier.cc:78
edm::EDGetTokenT< TrajectorySeedCollection >
MuonHLTSeedMVAClassifier::mvaEstimator_
PairSeedMvaEstimator mvaEstimator_
Definition: MuonHLTSeedMVAClassifier.cc:59
edm
HLT enums.
Definition: AlignableModifier.h:19
MuonHLTSeedMVAClassifier::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: MuonHLTSeedMVAClassifier.cc:241
l1t::MuonBxCollection
BXVector< Muon > MuonBxCollection
Definition: Muon.h:11
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89301
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
MuonHLTSeedMVAClassifier::MuonHLTSeedMVAClassifier
MuonHLTSeedMVAClassifier(const edm::ParameterSet &)
Definition: MuonHLTSeedMVAClassifier.cc:90
MuonHLTSeedMVAClassifier::mvaScaleMeanB_
const std::vector< double > mvaScaleMeanB_
Definition: MuonHLTSeedMVAClassifier.cc:67
MuonHLTSeedMVAClassifier::baseScore_
const double baseScore_
Definition: MuonHLTSeedMVAClassifier.cc:81
EDProducer.h
MuonHLTSeedMVAClassifier::nSeedsMaxB_
const int nSeedsMaxB_
Definition: MuonHLTSeedMVAClassifier.cc:73
MuonHLTSeedMVAClassifier::PairSeedMvaEstimator
std::pair< std::unique_ptr< const SeedMvaEstimator >, std::unique_ptr< const SeedMvaEstimator > > PairSeedMvaEstimator
Definition: MuonHLTSeedMVAClassifier.cc:58
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:46
beam_dqm_sourceclient-live_cfg.mva
mva
Definition: beam_dqm_sourceclient-live_cfg.py:127
MuonHLTSeedMVAClassifier::mvaFileB_
const edm::FileInPath mvaFileB_
Definition: MuonHLTSeedMVAClassifier.cc:64
reco::RecoChargedCandidateCollection
std::vector< RecoChargedCandidate > RecoChargedCandidateCollection
collectin of RecoChargedCandidate objects
Definition: RecoChargedCandidateFwd.h:9
MuonHLTSeedMVAClassifier::mvaFileE_
const edm::FileInPath mvaFileE_
Definition: MuonHLTSeedMVAClassifier.cc:65
fileCollector.seed
seed
Definition: fileCollector.py:127
BXVector
Definition: BXVector.h:15
edm::FileInPath
Definition: FileInPath.h:61
LocalTrajectoryParameters.h
MakerMacros.h
MuonHLTSeedMVAClassifier::mvaScaleStdB_
const std::vector< double > mvaScaleStdB_
Definition: MuonHLTSeedMVAClassifier.cc:68
TrackingRecHit.h
MuonHLTSeedMVAClassifier::etaEdge_
const double etaEdge_
Definition: MuonHLTSeedMVAClassifier.cc:76
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
PTrajectoryStateOnDet.h
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
TrackerDigiGeometryRecord
Definition: TrackerDigiGeometryRecord.h:16
MuonHLTSeedMVAClassifier::getSeedMva
double getSeedMva(const PairSeedMvaEstimator &pairMvaEstimator, const TrajectorySeed &seed, const GlobalVector &global_p, const l1t::MuonBxCollection &l1Muons, const reco::RecoChargedCandidateCollection &l2Muons)
Definition: MuonHLTSeedMVAClassifier.cc:225
MuonHLTSeedMVAClassifier::l2MuonToken_
const edm::EDGetTokenT< reco::RecoChargedCandidateCollection > l2MuonToken_
Definition: MuonHLTSeedMVAClassifier.cc:54
SeedMvaEstimator.h
TrajectorySeed.h
mitigatedMETSequence_cff.U
U
Definition: mitigatedMETSequence_cff.py:36
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
TrackerDigiGeometryRecord.h
GeomDet::toGlobal
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:49
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
MuonHLTSeedMVAClassifier::seedToken_
const edm::EDGetTokenT< TrajectorySeedCollection > seedToken_
Definition: MuonHLTSeedMVAClassifier.cc:52
l1t
delete x;
Definition: CaloConfig.h:22
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
A
PV3DBase::eta
T eta() const
Definition: PV3DBase.h:73
createfilelist.int
int
Definition: createfilelist.py:10
iEvent
int iEvent
Definition: GenABIO.cc:224
MuonHLTSeedMVAClassifier::nSeedsMaxE_
const int nSeedsMaxE_
Definition: MuonHLTSeedMVAClassifier.cc:74
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
edm::stream::EDProducer
Definition: EDProducer.h:36
edm::EventSetup
Definition: EventSetup.h:58
TrajectorySeedCollection.h
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord >
PropagationDirection.h
edm::EventSetup::getData
bool getData(T &iHolder) const
Definition: EventSetup.h:127
TtFullHadDaughter::B
static const std::string B
Definition: TtFullHadronicEvent.h:9
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
MuonHLTSeedMVAClassifier::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: MuonHLTSeedMVAClassifier.cc:127
DetachedQuadStep_cff.seeds
seeds
Definition: DetachedQuadStep_cff.py:195
Frameworkfwd.h
TrajectorySeed
Definition: TrajectorySeed.h:18
MuonHLTSeedMVAClassifier::mvaScaleMeanE_
const std::vector< double > mvaScaleMeanE_
Definition: MuonHLTSeedMVAClassifier.cc:69
MuonHLTSeedMVAClassifier::trackerGeometryToken_
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > trackerGeometryToken_
Definition: MuonHLTSeedMVAClassifier.cc:55
MuonHLTSeedMVAClassifier::mvaScaleStdE_
const std::vector< double > mvaScaleStdE_
Definition: MuonHLTSeedMVAClassifier.cc:70
MuonHLTSeedMVAClassifier::l1MuonToken_
const edm::EDGetTokenT< l1t::MuonBxCollection > l1MuonToken_
Definition: MuonHLTSeedMVAClassifier.cc:53
MuonHLTSeedMVAClassifier::rejectAll_
const bool rejectAll_
Definition: MuonHLTSeedMVAClassifier.cc:61
sortByMvaScore
bool sortByMvaScore(const std::pair< unsigned, double > &A, const std::pair< unsigned, double > &B)
Definition: MuonHLTSeedMVAClassifier.cc:37
mps_fire.result
result
Definition: mps_fire.py:311
MuonHLTSeedMVAClassifier::isFromL1_
const bool isFromL1_
Definition: MuonHLTSeedMVAClassifier.cc:62
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ParameterSet.h
offlineSlimmedPrimaryVertices_cfi.score
score
Definition: offlineSlimmedPrimaryVertices_cfi.py:6
MuonHLTSeedMVAClassifier::mvaCutB_
const double mvaCutB_
Definition: MuonHLTSeedMVAClassifier.cc:77
JetChargeProducer_cfi.exp
exp
Definition: JetChargeProducer_cfi.py:6
DeDxTools::esConsumes
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
MuonHLTSeedMVAClassifier::doSort_
const bool doSort_
Definition: MuonHLTSeedMVAClassifier.cc:72
edm::Event
Definition: Event.h:73
StreamID.h
edm::InputTag
Definition: InputTag.h:15
TrackerGeometry
Definition: TrackerGeometry.h:14