21 #include <unordered_map>
36 static const std::vector<std::string> float_var_names( {
"sigmaIPhiIPhi",
44 static const std::vector<std::string> integer_var_names( { } );
47 std::unordered_map<std::string,float>&
map) {
51 std::unordered_map<std::string,int>&
map) {
56 inline void check_map(
const std::unordered_map<std::string,T>&
map,
unsigned exp_size) {
57 if( map.size() != exp_size ) {
59 <<
"variable map size: " << map.size()
60 <<
" not equal to expected size: " << exp_size <<
" !"
61 <<
" The regression variable calculation code definitely has a bug, fix it!";
65 template<
typename LazyTools,
typename SeedType>
67 const SeedType& the_seed,
68 std::unordered_map<std::string,float>& float_vars,
69 std::unordered_map<std::string,int>& ) {
70 LazyTools* tools =
static_cast<LazyTools*
>(tools_tocast);
73 std::vector<float> vCov = tools->localCovariances( the_seed );
74 spp = (
isnan(vCov[2]) ? 0. :
sqrt(vCov[2]));
77 set_map_val(k_sigmaIPhiIPhi, spp, float_vars);
78 set_map_val(k_sigmaIEtaIPhi, sep, float_vars);
80 set_map_val(k_e2x5Max, tools->e2x5Max(the_seed), float_vars);
81 set_map_val(k_e2x5Left, tools->e2x5Left(the_seed), float_vars);
82 set_map_val(k_e2x5Right, tools->e2x5Right(the_seed), float_vars);
83 set_map_val(k_e2x5Top, tools->e2x5Top(the_seed), float_vars);
84 set_map_val(k_e2x5Bottom, tools->e2x5Bottom(the_seed), float_vars);
104 const std::vector<T> &
values,
126 use_full5x5_(iConfig.getParameter<bool>(
"useFull5x5")) {
132 (
"ebReducedRecHitCollection"));
134 (
"ebReducedRecHitCollectionMiniAOD"));
137 (
"eeReducedRecHitCollection"));
139 (
"eeReducedRecHitCollectionMiniAOD"));
142 (
"esReducedRecHitCollection"));
144 (
"esReducedRecHitCollectionMiniAOD"));
155 produces<edm::ValueMap<float> >(
name);
159 produces<edm::ValueMap<int> >(
name);
179 if( !
src.isValid() ) {
181 <<
"DataFormat does not contain a photon source!";
198 lazyTools = std::make_unique<noZS::EcalClusterLazyTools>(
iEvent, iSetup,
205 if( !isAOD &&
src->size() ) {
207 if(
test.isNull() || !
test.isAvailable() ) {
209 <<
"DataFormat is detected as miniAOD but cannot cast to pat::Photon!";
213 std::vector<std::vector<float> > float_vars(k_NFloatVars);
214 std::vector<std::vector<int> > int_vars(k_NIntVars);
216 std::unordered_map<std::string,float> float_vars_map;
217 std::unordered_map<std::string,int> int_vars_map;
220 for (
unsigned idxpho = 0; idxpho <
src->size(); ++idxpho) {
221 const auto& iPho =
src->ptrAt(idxpho);
226 const auto& theseed = *(iPho->superCluster()->seed());
229 calculateValues<noZS::EcalClusterLazyTools>(
lazyTools.get(),
234 calculateValues<EcalClusterLazyTools>(
lazyTools.get(),
240 check_map(float_vars_map, k_NFloatVars);
241 check_map(int_vars_map, k_NIntVars);
243 for(
unsigned i = 0;
i < float_vars.size(); ++
i ) {
244 float_vars[
i].emplace_back(float_vars_map.at(float_var_names[
i]));
248 for(
unsigned i = 0;
i < int_vars.size(); ++
i ) {
249 int_vars[
i].emplace_back(int_vars_map.at(integer_var_names[
i]));
254 for(
unsigned i = 0;
i < float_vars.size(); ++
i ) {
258 for(
unsigned i = 0;
i < int_vars.size(); ++
i ) {
268 const std::vector<T> &
values,
275 auto_ptr<TValueMap> valMap(
new TValueMap());
276 typename TValueMap::Filler filler(*valMap);
277 filler.insert(
handle, values.begin(), values.end());
279 iEvent.
put(valMap, label);
edm::EDGetToken srcMiniAOD_
T getParameter(std::string const &) const
std::unique_ptr< EcalClusterLazyToolsBase > lazyTools
edm::EDGetTokenT< EcalRecHitCollection > ebReducedRecHitCollectionMiniAOD_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
#define DEFINE_FWK_MODULE(type)
edm::EDGetTokenT< EcalRecHitCollection > esReducedRecHitCollectionMiniAOD_
edm::EDGetTokenT< EcalRecHitCollection > eeReducedRecHitCollection_
edm::EDGetTokenT< EcalRecHitCollection > ebReducedRecHitCollection_
void addDefault(ParameterSetDescription const &psetDescription)
PhotonRegressionValueMapProducer(const edm::ParameterSet &)
void writeValueMap(edm::Event &iEvent, const edm::Handle< edm::View< reco::Photon > > &handle, const std::vector< T > &values, const std::string &label) const
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
~PhotonRegressionValueMapProducer()
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
edm::EDGetTokenT< EcalRecHitCollection > esReducedRecHitCollection_
edm::EDGetTokenT< EcalRecHitCollection > eeReducedRecHitCollectionMiniAOD_
virtual void produce(edm::Event &, const edm::EventSetup &) override