45 template <
typename EL,
typename FID,
typename FTRK>
56 const std::vector<std::string>
names_;
57 std::vector<edm::EDPutTokenT<edm::ValueMap<float>>>
putTokens_;
61 std::vector<std::unique_ptr<const GBRForest>>
models_;
71 : useGsfToTrack_(conf.getParameter<bool>(
"useGsfToTrack")),
72 usePAT_(conf.getParameter<bool>(
"usePAT")),
75 rho_(consumes<double>(conf.getParameter<edm::
InputTag>(
"rho"))),
79 names_(conf.getParameter<std::
vector<std::
string>>(
"ModelNames")),
80 passThrough_(conf.getParameter<bool>(
"PassThrough")),
81 minPtThreshold_(conf.getParameter<double>(
"MinPtThreshold")),
82 maxPtThreshold_(conf.getParameter<double>(
"MaxPtThreshold")),
83 thresholds_(conf.getParameter<std::
vector<double>>(
"ModelThresholds")),
84 versionName_(conf.getParameter<std::
string>(
"Version")) {
99 <<
"'ModelNames' size (" <<
names_.size() <<
") != 'ModelWeights' size (" <<
models_.size() <<
").\n";
103 <<
"'ModelWeights' size (" <<
models_.size() <<
") != 'ModelThresholds' size (" <<
thresholds_.size() <<
").\n";
126 event.getByToken(
rho_, hRho);
127 if (!hRho.isValid()) {
128 std::ostringstream os;
129 os <<
"Problem accessing rho collection for low-pT electrons" << std::endl;
136 event.getByToken(
gsf2trk_, gsf2trk);
151 [&](
auto const& ele) {
152 if (!ele.isElectronIDAvailable(kUnbiased)) {
155 return ele.electronID(kUnbiased);
157 [&](
auto const& ele) {
160 const PackedPtr* ptr1 = ele.template userData<PackedPtr>(
"ele2packed");
161 const PackedPtr* ptr2 = ele.template userData<PackedPtr>(
"ele2lost");
162 auto hasBestTrack = [](
const PackedPtr* ptr) {
163 return ptr !=
nullptr && ptr->
isNonnull() && ptr->isAvailable() && ptr->get() !=
nullptr &&
164 ptr->get()->bestTrack() !=
nullptr;
166 if (hasBestTrack(ptr1)) {
167 return ptr1->get()->bestTrack();
168 }
else if (hasBestTrack(ptr2)) {
169 return ptr2->get()->bestTrack();
181 auto const& electrons =
event.getHandle(
electrons_);
188 [&](
auto const& ele) {
189 if (ele.core().isNull()) {
192 const auto& gsf = ele.core()->gsfTrack();
196 return unbiasedH[gsf];
198 [&](
auto const& ele) {
200 const auto& gsf = ele.core()->gsfTrack();
201 if (gsf.isNonnull() && gsf.isAvailable()) {
202 auto const& ref = (*gsf2trk)[gsf];
203 if (ref.isNonnull() && ref.isAvailable()) {
219 template <
typename EL,
typename FID,
typename FTRK>
222 auto nElectrons = electrons->size();
223 std::vector<float> ids;
224 ids.reserve(nElectrons);
225 std::transform(electrons->begin(), electrons->end(), std::back_inserter(ids), idFunctor);
226 std::vector<const reco::Track*> trks;
227 trks.reserve(nElectrons);
228 std::transform(electrons->begin(), electrons->end(), std::back_inserter(trks), trkFunctor);
230 std::vector<float>
output(nElectrons);
233 for (
unsigned int iele = 0; iele < nElectrons; iele++) {
234 auto const& ele = (*electrons)[iele];
238 output[iele] = -999.;
243 filler.
insert(electrons, output.begin(), output.end());
257 std::vector<float>
inputs;
270 desc.
add<
bool>(
"useGsfToTrack",
false);
271 desc.
add<
bool>(
"usePAT",
false);
276 desc.
add<std::vector<std::string>>(
"ModelNames", {
""});
277 desc.
add<std::vector<std::string>>(
278 "ModelWeights", {
"RecoEgamma/ElectronIdentification/data/LowPtElectrons/LowPtElectrons_ID_2020Nov28.root"});
279 desc.
add<std::vector<double>>(
"ModelThresholds", {-99.});
280 desc.
add<
bool>(
"PassThrough",
false);
281 desc.
add<
double>(
"MinPtThreshold", 0.5);
282 desc.
add<
double>(
"MaxPtThreshold", 15.);
284 descriptions.
add(
"defaultLowPtGsfElectronID", desc);
const bool useGsfToTrack_
const double minPtThreshold_
double GetResponse(const float *vector) const
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
bool isNonnull() const
Checks for non-null.
static void fillDescriptions(edm::ConfigurationDescriptions &)
#define DEFINE_FWK_MODULE(type)
void insert(const H &h, I begin, I end)
Global3DPoint GlobalPoint
edm::EDGetTokenT< reco::GsfElectronCollection > electrons_
const std::vector< double > thresholds_
const std::vector< std::string > names_
std::vector< std::unique_ptr< const GBRForest > > models_
bool getData(T &iHolder) const
void doWork(double rho, float bz, EL const &electrons, FID &&idFunctor, FTRK &&trkFunctor, edm::Event &) const
LowPtGsfElectronIDProducer(const edm::ParameterSet &)
const double maxPtThreshold_
edm::EDGetTokenT< pat::ElectronCollection > patElectrons_
T const * get() const
Returns C++ pointer to the item.
std::vector< float > features_V0(reco::GsfElectron const &ele, float rho, float unbiased)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
const_reference_type get(ProductID id, size_t idx) const
bool isNonnull() const
Checks for non-null.
std::vector< float > features_V1(reco::GsfElectron const &ele, float rho, float unbiased, float field_z, const reco::Track *trk=nullptr)
const edm::EDGetTokenT< double > rho_
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
const std::string versionName_
XYZVectorD XYZVector
spatial vector with cartesian internal representation
T getParameter(std::string const &) const
edm::EDGetTokenT< edm::ValueMap< float > > unbiased_
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > fieldToken_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
edm::EDGetTokenT< edm::Association< reco::TrackCollection > > gsf2trk_
std::vector< edm::EDPutTokenT< edm::ValueMap< float > > > putTokens_
double eval(const GBRForest &model, const reco::GsfElectron &, double rho, float unbiased, float field_z, const reco::Track *trk=nullptr) const