CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
MTDTrackQualityMVAProducer.cc
Go to the documentation of this file.
8 
15 
17 
18 using namespace std;
19 using namespace edm;
20 
22 public:
24 
25  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
26 
27  template <class H, class T>
28  void fillValueMap(edm::Event& iEvent,
29  const edm::Handle<H>& handle,
30  const std::vector<T>& vec,
31  const std::string& name) const;
32 
33  void produce(edm::Event& ev, const edm::EventSetup& es) final;
34 
35 private:
36  static constexpr char mvaName[] = "mtdQualMVA";
37 
40 
49 
51 };
52 
54  : tracksToken_(consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("tracksSrc"))),
55  btlMatchChi2Token_(consumes<edm::ValueMap<float>>(iConfig.getParameter<edm::InputTag>("btlMatchChi2Src"))),
56  btlMatchTimeChi2Token_(
57  consumes<edm::ValueMap<float>>(iConfig.getParameter<edm::InputTag>("btlMatchTimeChi2Src"))),
58  etlMatchChi2Token_(consumes<edm::ValueMap<float>>(iConfig.getParameter<edm::InputTag>("etlMatchChi2Src"))),
59  etlMatchTimeChi2Token_(
60  consumes<edm::ValueMap<float>>(iConfig.getParameter<edm::InputTag>("etlMatchTimeChi2Src"))),
61  mtdTimeToken_(consumes<edm::ValueMap<float>>(iConfig.getParameter<edm::InputTag>("mtdTimeSrc"))),
62  pathLengthToken_(consumes<edm::ValueMap<float>>(iConfig.getParameter<edm::InputTag>("pathLengthSrc"))),
63  npixBarrelToken_(consumes<edm::ValueMap<int>>(iConfig.getParameter<edm::InputTag>("npixBarrelSrc"))),
64  npixEndcapToken_(consumes<edm::ValueMap<int>>(iConfig.getParameter<edm::InputTag>("npixEndcapSrc"))),
65  mva_(iConfig.getParameter<edm::FileInPath>("qualityBDT_weights_file").fullPath()) {
66  produces<edm::ValueMap<float>>(mvaName);
67 }
68 
69 // Configuration descriptions
72  desc.add<edm::InputTag>("tracksSrc", edm::InputTag("generalTracks"))->setComment("Input tracks collection");
73  desc.add<edm::InputTag>("btlMatchChi2Src", edm::InputTag("trackExtenderWithMTD", "btlMatchChi2"))
74  ->setComment("BTL Chi2 Matching value Map");
75  desc.add<edm::InputTag>("btlMatchTimeChi2Src", edm::InputTag("trackExtenderWithMTD", "btlMatchTimeChi2"))
76  ->setComment("BTL Chi2 Matching value Map");
77  desc.add<edm::InputTag>("etlMatchChi2Src", edm::InputTag("trackExtenderWithMTD", "etlMatchChi2"))
78  ->setComment("ETL Chi2 Matching value Map");
79  desc.add<edm::InputTag>("etlMatchTimeChi2Src", edm::InputTag("trackExtenderWithMTD", "etlMatchTimeChi2"))
80  ->setComment("ETL Chi2 Matching value Map");
81  desc.add<edm::InputTag>("mtdTimeSrc", edm::InputTag("trackExtenderWithMTD", "generalTracktmtd"))
82  ->setComment("MTD TIme value Map");
83  desc.add<edm::InputTag>("pathLengthSrc", edm::InputTag("trackExtenderWithMTD", "generalTrackPathLength"))
84  ->setComment("MTD PathLength value Map");
85  desc.add<edm::InputTag>("npixBarrelSrc", edm::InputTag("trackExtenderWithMTD", "npixBarrel"))
86  ->setComment("# of Barrel pixel associated to refitted tracks");
87  desc.add<edm::InputTag>("npixEndcapSrc", edm::InputTag("trackExtenderWithMTD", "npixEndcap"))
88  ->setComment("# of Endcap pixel associated to refitted tracks");
89  desc.add<edm::FileInPath>("qualityBDT_weights_file",
90  edm::FileInPath("RecoMTD/TimingIDTools/data/clf4D_MTDquality_bo.xml"))
91  ->setComment("Track MTD quality BDT weights");
92  descriptions.add("mtdTrackQualityMVAProducer", desc);
93 }
94 
95 template <class H, class T>
97  const edm::Handle<H>& handle,
98  const std::vector<T>& vec,
99  const std::string& name) const {
100  auto out = std::make_unique<edm::ValueMap<T>>();
101  typename edm::ValueMap<T>::Filler filler(*out);
102  filler.insert(handle, vec.begin(), vec.end());
103  filler.fill();
104  iEvent.put(std::move(out), name);
105 }
106 
109  ev.getByToken(tracksToken_, tracksH);
110  const auto& tracks = *tracksH;
111 
112  const auto& btlMatchChi2 = ev.get(btlMatchChi2Token_);
113  const auto& btlMatchTimeChi2 = ev.get(btlMatchTimeChi2Token_);
114  const auto& etlMatchChi2 = ev.get(etlMatchChi2Token_);
115  const auto& etlMatchTimeChi2 = ev.get(etlMatchTimeChi2Token_);
116  const auto& pathLength = ev.get(pathLengthToken_);
117  const auto& npixBarrel = ev.get(npixBarrelToken_);
118  const auto& npixEndcap = ev.get(npixEndcapToken_);
119  const auto& mtdTime = ev.get(mtdTimeToken_);
120 
121  std::vector<float> mvaOutRaw;
122 
123  //Loop over tracks collection
124  for (unsigned int itrack = 0; itrack < tracks.size(); ++itrack) {
125  const reco::TrackRef trackref(tracksH, itrack);
126  if (pathLength[trackref] == -1.)
127  mvaOutRaw.push_back(-1.);
128  else {
129  mvaOutRaw.push_back(mva_(trackref,
130  npixBarrel,
131  npixEndcap,
132  btlMatchChi2,
133  btlMatchTimeChi2,
134  etlMatchChi2,
135  etlMatchTimeChi2,
136  mtdTime,
137  pathLength));
138  }
139  }
140  fillValueMap(ev, tracksH, mvaOutRaw, mvaName);
141 }
142 
143 //define this as a plug-in
void fillValueMap(edm::Event &iEvent, const edm::Handle< H > &handle, const std::vector< T > &vec, const std::string &name) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
edm::EDGetTokenT< edm::ValueMap< float > > mtdTimeToken_
edm::EDGetTokenT< reco::TrackCollection > tracksToken_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
edm::EDGetTokenT< edm::ValueMap< float > > etlMatchTimeChi2Token_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
auto const & tracks
cannot be loose
int iEvent
Definition: GenABIO.cc:224
edm::EDGetTokenT< edm::ValueMap< float > > btlMatchTimeChi2Token_
def move
Definition: eostools.py:511
tuple handle
Definition: patZpeak.py:25
bool get(ProductID const &oid, Handle< PROD > &result) const
Definition: Event.h:346
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void produce(edm::Event &ev, const edm::EventSetup &es) final
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
edm::EDGetTokenT< edm::ValueMap< float > > btlMatchChi2Token_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
edm::EDGetTokenT< edm::ValueMap< int > > npixEndcapToken_
edm::EDGetTokenT< edm::ValueMap< float > > pathLengthToken_
edm::EDGetTokenT< reco::TrackCollection > tracksMTDToken_
edm::EDGetTokenT< edm::ValueMap< float > > etlMatchChi2Token_
edm::EDGetTokenT< edm::ValueMap< int > > npixBarrelToken_
MTDTrackQualityMVAProducer(const ParameterSet &pset)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)