1 #ifndef RecoEgamma_EgammaTools_EGExtraInfoModifierFromValueMaps_h 2 #define RecoEgamma_EgammaTools_EGExtraInfoModifierFromValueMaps_h 13 #include <unordered_map> 54 template<
typename OutputType>
61 template<
typename ObjType,
typename MapType>
63 addValueToObject(ObjType&
obj,
67 bool overrideExistingValues);
69 template<
typename ObjType,
typename MapType>
75 bool overrideExistingValues){
76 for(
auto itr = vmaps_token.begin(); itr != vmaps_token.end(); ++itr ) {
77 addValueToObject(obj,ptr,vmaps,*itr,overrideExistingValues);
83 template<
typename MapType,
typename OutputType=MapType>
87 using ValueMaps = std::unordered_map<std::string,ValMapToken>;
103 void modifyObject(
pat::
Photon&) const final;
113 mutable
unsigned ele_idx,pho_idx;
114 bool overrideExistingValues_;
118 template<typename MapType,typename OutputType>
124 overrideExistingValues_ = conf.exists(
"overrideExistingValues") ? conf.getParameter<
bool>(
"overrideExistingValues") :
false;
125 if( conf.exists(
"electron_config") ) {
137 if( conf.exists(
"photon_config") ) {
148 ele_idx = pho_idx = 0;
151 template<
typename MapType,
typename OutputType>
159 ele_idx = pho_idx = 0;
161 if( !e_conf.tok_electron_src.isUninitialized() ) {
165 eles_by_oop.resize(eles->size());
166 std::copy(eles->ptrs().begin(), eles->ptrs().end(), eles_by_oop.begin());
169 for(
auto const& itr : e_conf.tok_valuemaps) evt.
getByToken(itr.second,ele_vmaps[itr.second.index()]);
171 if( !ph_conf.tok_photon_src.isUninitialized() ) {
175 phos_by_oop.resize(phos->size());
176 std::copy(phos->ptrs().begin(), phos->ptrs().end(), phos_by_oop.begin());
179 for(
auto const& itr : ph_conf.tok_valuemaps) evt.
getByToken(itr.second,pho_vmaps[itr.second.index()]);
183 template<
typename T,
typename U,
typename V,
typename MapType >
184 inline void assignValue(
const T& ptr,
const U& tok,
const V&
map, MapType&
value) {
185 if( !tok.isUninitialized() ) value = map.find(tok.index())->
second->get(ptr.id(),ptr.key());
189 template<
typename MapType,
typename OutputType>
196 if( !e_conf.tok_electron_src.isUninitialized() ) ptr = eles_by_oop.at(ele_idx);
199 ele_vmaps,overrideExistingValues_);
204 template<
typename MapType,
typename OutputType>
211 if( !ph_conf.tok_photon_src.isUninitialized() ) ptr = phos_by_oop.at(pho_idx);
214 pho_vmaps,overrideExistingValues_);
220 template<
typename OutputType>
221 template<
typename ObjType,
typename MapType>
227 bool overrideExistingValues)
230 assignValue(ptr,val_map.second,vmaps,
value);
231 if( overrideExistingValues || !obj.hasUserData(val_map.first) ) {
232 obj.addUserData(val_map.first,
value,
true);
235 <<
"Trying to add new UserData = " << val_map.first
236 <<
" failed because it already exists and you didnt specify to override it (set in the config overrideExistingValues=cms.bool(True) )";
241 template<
typename ObjType,
typename MapType>
247 bool overrideExistingValues)
250 assignValue(ptr,val_map.second,vmaps,value);
251 if( overrideExistingValues || !obj.hasUserFloat(val_map.first) ) {
252 obj.addUserFloat(val_map.first,value,
true);
255 <<
"Trying to add new UserFloat = " << val_map.first
256 <<
" failed because it already exists and you didnt specify to override it (set in the config overrideExistingValues=cms.bool(True) )";
261 template<
typename ObjType,
typename MapType>
267 bool overrideExistingValues)
270 assignValue(ptr,val_map.second,vmaps,value);
271 if( overrideExistingValues || !obj.hasUserInt(val_map.first) ) {
272 obj.addUserInt(val_map.first,value,
true);
275 <<
"Trying to add new UserInt = " << val_map.first
276 <<
" failed because it already exists and you didnt specify to override it (set in the config overrideExistingValues=cms.bool(True) )";
287 bool overrideExistingValues)
289 std::vector<std::pair<std::string,float >>
ids;
290 for(
auto itr = vmaps_token.begin(); itr != vmaps_token.end(); ++itr ) {
292 assignValue(ptr,itr->second,vmaps,idVal);
293 ids.push_back({itr->first,idVal});
295 std::sort(ids.begin(),ids.end(),[](
auto& lhs,
auto& rhs){
return lhs.first<rhs.first;});
306 bool overrideExistingValues)
309 std::vector<std::pair<std::string,bool> >
ids;
310 for(
auto itr = vmaps_token.begin(); itr != vmaps_token.end(); ++itr ) {
312 assignValue(ptr,itr->second,vmaps,idVal);
313 ids.push_back({itr->first,idVal});
315 std::sort(ids.begin(),ids.end(),[](
auto& lhs,
auto& rhs){
return lhs.first<rhs.first;});
T getParameter(std::string const &) const
Analysis-level Photon class.
bool existsAs(std::string const ¶meterName, bool trackiness=true) const
checks if a parameter exists as a given type
void setElectronIDs(const std::vector< IdPair > &ids)
Store multiple electron ID values, discarding existing ones. The first one in the list becomes the 'd...
bool getByToken(EDGetToken token, Handle< PROD > &result) const
bool exists(std::string const ¶meterName) const
checks if a parameter exists
U second(std::pair< T, U > const &p)
static void addValueToObject(ObjType &obj, const edm::Ptr< reco::Candidate > &ptr, const std::unordered_map< unsigned, edm::Handle< edm::ValueMap< MapType > > > &vmaps, const std::pair< const std::string, edm::EDGetTokenT< edm::ValueMap< MapType > > > &val_map, bool overrideExistingValues)
void setPhotonIDs(const std::vector< IdPair > &ids)
static void addValuesToObject(ObjType &obj, const edm::Ptr< reco::Candidate > &ptr, const std::unordered_map< std::string, edm::EDGetTokenT< edm::ValueMap< MapType > > > &vmaps_token, const std::unordered_map< unsigned, edm::Handle< edm::ValueMap< MapType > > > &vmaps, bool overrideExistingValues)
def template(fileName, svg, replaceme="REPLACEME")
std::vector< std::string > getParameterNames() const
const edm::Ptr< reco::Candidate > & originalObjectRef() const
reference to original object. Returns a null reference if not available
Analysis-level electron class.