CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Types | Private Attributes | Static Private Attributes
citk::PFIsolationSumProducerForPUPPI Class Reference
Inheritance diagram for citk::PFIsolationSumProducerForPUPPI:
edm::stream::EDProducer<>

Public Member Functions

void beginLuminosityBlock (const edm::LuminosityBlock &, const edm::EventSetup &) final
 
 PFIsolationSumProducerForPUPPI (const edm::ParameterSet &)
 
void produce (edm::Event &, const edm::EventSetup &) final
 
 ~PFIsolationSumProducerForPUPPI () override
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
bool hasAbilityToProduceInLumis () const final
 
bool hasAbilityToProduceInRuns () const final
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 

Private Types

typedef edm::View< reco::CandidateCandView
 
typedef std::vector< std::unique_ptr< IsolationConeDefinitionBase > > IsoTypes
 
typedef std::unordered_map< std::string, int > TypeMap
 

Private Attributes

edm::EDGetTokenT< CandView_isolate_with
 
std::array< IsoTypes, kNPFTypes_isolation_types
 
std::array< std::vector< std::string >, kNPFTypes_product_names
 
edm::EDGetTokenT< CandView_to_isolate
 
const TypeMap _typeMap
 
edm::Handle< edm::ValueMap< float > > puppiValueMap
 
edm::EDGetTokenT< edm::ValueMap< float > > puppiValueMapToken_
 
bool usePUPPINoLepton = false
 
bool useValueMapForPUPPI = true
 

Static Private Attributes

static unsigned kNPFTypes = 8
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer<>
typedef CacheContexts< T... > CacheTypes
 
typedef CacheTypes::GlobalCache GlobalCache
 
typedef AbilityChecker< T... > HasAbility
 
typedef CacheTypes::LuminosityBlockCache LuminosityBlockCache
 
typedef LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCacheLuminosityBlockContext
 
typedef CacheTypes::LuminosityBlockSummaryCache LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache, GlobalCacheRunContext
 
typedef CacheTypes::RunSummaryCache RunSummaryCache
 

Detailed Description

Definition at line 26 of file CITKPFIsolationSumProducerForPUPPI.cc.

Member Typedef Documentation

Definition at line 45 of file CITKPFIsolationSumProducerForPUPPI.cc.

typedef std::vector<std::unique_ptr<IsolationConeDefinitionBase> > citk::PFIsolationSumProducerForPUPPI::IsoTypes
private

Definition at line 44 of file CITKPFIsolationSumProducerForPUPPI.cc.

typedef std::unordered_map<std::string,int> citk::PFIsolationSumProducerForPUPPI::TypeMap
private

Definition at line 43 of file CITKPFIsolationSumProducerForPUPPI.cc.

Constructor & Destructor Documentation

citk::PFIsolationSumProducerForPUPPI::PFIsolationSumProducerForPUPPI ( const edm::ParameterSet c)

Definition at line 63 of file CITKPFIsolationSumProducerForPUPPI.cc.

References _isolate_with, _isolation_types, _product_names, _to_isolate, _typeMap, beginLuminosityBlock(), EnergyCorrector::c, highPtTrackIsolations_cff::coneSize, Exception, reco::get(), edm::InputTag::label(), eostools::move(), dataset::name, BPhysicsValidation_cfi::pname, puppiValueMapToken_, AlCaHLTBitMon_QueryRunRegistry::string, usePUPPINoLepton, and useValueMapForPUPPI.

63  :
64  _typeMap( { {"h+",1},
65  {"h0",5},
66  {"gamma",4},
67  {"electron",2},
68  {"muon",3},
69  {"HFh",6},
70  {"HFgamma",7} } ){
71  _to_isolate =
72  consumes<CandView>(c.getParameter<edm::InputTag>("srcToIsolate"));
73  _isolate_with =
74  consumes<CandView>(c.getParameter<edm::InputTag>("srcForIsolationCone"));
75  if (!c.getParameter<edm::InputTag>("puppiValueMap").label().empty()) {
76  puppiValueMapToken_ = mayConsume<edm::ValueMap<float>>(c.getParameter<edm::InputTag>("puppiValueMap")); //getting token for puppiValueMap
77  useValueMapForPUPPI = true;
78  }
79  else {
80  useValueMapForPUPPI = false;
81  usePUPPINoLepton = c.getParameter<bool>("usePUPPINoLepton");
82  }
83  const std::vector<edm::ParameterSet>& isoDefs =
84  c.getParameterSetVector("isolationConeDefinitions");
85  for( const auto& isodef : isoDefs ) {
86  const std::string& name =
87  isodef.getParameter<std::string>("isolationAlgo");
88  const float coneSize = isodef.getParameter<double>("coneSize");
89  char buf[50];
90  std::sprintf(buf,"DR%.2f",coneSize);
91  std::string coneName(buf);
92  auto decimal = coneName.find('.');
93  if( decimal != std::string::npos ) coneName.erase(decimal,1);
94  const std::string& isotype =
95  isodef.getParameter<std::string>("isolateAgainst");
96  auto theisolator =
97  CITKIsolationConeDefinitionFactory::get()->create(name,isodef);
98  theisolator->setConsumes(consumesCollector());
99  const auto thetype = _typeMap.find(isotype);
100  if( thetype == _typeMap.end() ) {
101  throw cms::Exception("InvalidIsolationType")
102  << "Isolation type: " << isotype << " is not available in the "
103  << "list of allowed isolations!.";
104  }
105  _isolation_types[thetype->second].emplace_back(std::move(theisolator));
106  const std::string dash("-");
107  std::string pname = isotype+dash+coneName+dash+theisolator->additionalCode();
108  _product_names[thetype->second].emplace_back(pname);
109  produces<edm::ValueMap<float> >(pname);
110  }
111  }
T getParameter(std::string const &) const
VParameterSet const & getParameterSetVector(std::string const &name) const
std::array< std::vector< std::string >, kNPFTypes > _product_names
edm::EDGetTokenT< edm::ValueMap< float > > puppiValueMapToken_
std::string const & label() const
Definition: InputTag.h:36
def move(src, dest)
Definition: eostools.py:511
T get(const Candidate &c)
Definition: component.h:55
citk::PFIsolationSumProducerForPUPPI::~PFIsolationSumProducerForPUPPI ( )
inlineoverride

Definition at line 31 of file CITKPFIsolationSumProducerForPUPPI.cc.

References beginLuminosityBlock(), fillDescriptions(), and produce().

31 {}

Member Function Documentation

void citk::PFIsolationSumProducerForPUPPI::beginLuminosityBlock ( const edm::LuminosityBlock ,
const edm::EventSetup es 
)
final

Definition at line 114 of file CITKPFIsolationSumProducerForPUPPI.cc.

References _isolation_types, and produce().

Referenced by PFIsolationSumProducerForPUPPI(), and ~PFIsolationSumProducerForPUPPI().

115  {
116  for( const auto& isolators_for_type : _isolation_types ) {
117  for( const auto& isolator : isolators_for_type ) {
118  isolator->getEventSetupInfo(es);
119  }
120  }
121  }
void citk::PFIsolationSumProducerForPUPPI::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 192 of file CITKPFIsolationSumProducerForPUPPI.cc.

References edm::ConfigurationDescriptions::add(), edm::ParameterSetDescription::add(), edm::ParameterSetDescription::addOptional(), edm::ParameterSetDescription::addVPSet(), egmElectronIsolationPUPPI_cff::isolationConeDefinitions, nano_cff::photons, edm::ParameterSetDescription::setComment(), and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by ~PFIsolationSumProducerForPUPPI().

193 {
195  iDesc.setComment("PUPPI isolation sum producer");
196 
197  iDesc.add<edm::InputTag>("srcToIsolate", edm::InputTag("no default"))->setComment("calculate isolation for this collection");
198  iDesc.add<edm::InputTag>("srcForIsolationCone", edm::InputTag("no default"))->setComment("collection for the isolation calculation: like particleFlow ");
199  iDesc.add<edm::InputTag>("puppiValueMap", edm::InputTag("puppi"))->setComment("source for puppi, if left empty weight from packedCandidate is taken");
200 
201  edm::ParameterSetDescription descIsoConeDefinitions;
202  descIsoConeDefinitions.add<std::string>("isolationAlgo", "no default");
203  descIsoConeDefinitions.add<double>("coneSize", 0.3);
204  descIsoConeDefinitions.add<std::string>("isolateAgainst", "no default");
205  descIsoConeDefinitions.add<std::vector<unsigned>>("miniAODVertexCodes", {2,3});
206  descIsoConeDefinitions.addOptional<double>("VetoConeSizeBarrel", 0.0);
207  descIsoConeDefinitions.addOptional<double>("VetoConeSizeEndcaps", 0.0);
208  descIsoConeDefinitions.addOptional<double>("VetoThreshold", 0.0);
209  descIsoConeDefinitions.addOptional<double>("VetoConeSize", 0.0);
210  descIsoConeDefinitions.addOptional<int>("vertexIndex",0);
211  descIsoConeDefinitions.addOptional<edm::InputTag>("particleBasedIsolation",edm::InputTag("no default"))->setComment("map for footprint removal that is used for photons");
212 
213 
214  std::vector<edm::ParameterSet> isolationConeDefinitions;
215  edm::ParameterSet chargedHadrons, neutralHadrons,photons;
216  isolationConeDefinitions.push_back(chargedHadrons);
217  isolationConeDefinitions.push_back(neutralHadrons);
218  isolationConeDefinitions.push_back(photons);
219  iDesc.addVPSet("isolationConeDefinitions", descIsoConeDefinitions, isolationConeDefinitions);
220  iDesc.add<bool>("usePUPPINoLepton",false);
221 
222  descriptions.add("CITKPFIsolationSumProducerForPUPPI", iDesc);
223 }
void setComment(std::string const &value)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void citk::PFIsolationSumProducerForPUPPI::produce ( edm::Event ev,
const edm::EventSetup es 
)
final

Definition at line 124 of file CITKPFIsolationSumProducerForPUPPI.cc.

References _isolate_with, _isolation_types, _product_names, _to_isolate, begin, EnergyCorrector::c, end, edm::helper::Filler< Map >::fill(), edm::Event::getByToken(), mps_fire::i, edm::helper::Filler< Map >::insert(), gen::k, kNPFTypes, eostools::move(), edm::View< T >::ptrAt(), puppiValueMap, puppiValueMapToken_, edm::Event::put(), edm::View< T >::size(), reco::PFCandidate::translatePdgIdToType(), usePUPPINoLepton, and useValueMapForPUPPI.

Referenced by beginLuminosityBlock(), and ~PFIsolationSumProducerForPUPPI().

124  {
125  typedef std::unique_ptr<edm::ValueMap<float> > product_type;
126  typedef std::vector<float> product_values;
127  edm::Handle<CandView> to_isolate;
128  edm::Handle<CandView> isolate_with;
129  ev.getByToken(_to_isolate,to_isolate);
130  ev.getByToken(_isolate_with,isolate_with);
132 
133  // the list of value vectors indexed as "to_isolate"
134  std::array<std::vector<product_values>,kNPFTypes> the_values;
135  // get extra event info and setup value cache
136  unsigned i = 0;
137  for( const auto& isolators_for_type : _isolation_types ) {
138  the_values[i++].resize(isolators_for_type.size());
139  for( const auto& isolator : isolators_for_type ) {
140  isolator->getEventInfo(ev);
141  }
142  }
143  reco::PFCandidate helper; // to translate pdg id to type
144  // loop over the candidates we are isolating and fill the values
145  for( size_t c = 0; c < to_isolate->size(); ++c ) {
146  auto cand_to_isolate = to_isolate->ptrAt(c);
147  std::array<std::vector<float>,kNPFTypes> cand_values;
148  unsigned k = 0;
149  for( const auto& isolators_for_type : _isolation_types ) {
150  cand_values[k].resize(isolators_for_type.size());
151  for( auto& value : cand_values[k] ) value = 0.0;
152  ++k;
153  }
154  for( size_t ic = 0; ic < isolate_with->size(); ++ic ) {
155  auto isocand = isolate_with->ptrAt(ic);
156  edm::Ptr<pat::PackedCandidate> aspackedCandidate(isocand);
157  auto isotype = helper.translatePdgIdToType(isocand->pdgId());
158  const auto& isolations = _isolation_types[isotype];
159  for( unsigned i = 0; i < isolations.size(); ++ i ) {
160  if( isolations[i]->isInIsolationCone(cand_to_isolate,isocand) ) {
161  double puppiWeight = 0.;
162  if (!useValueMapForPUPPI && !usePUPPINoLepton) puppiWeight = aspackedCandidate -> puppiWeight(); // if miniAOD, take puppiWeight directly from the object
163  else if (!useValueMapForPUPPI && usePUPPINoLepton) puppiWeight = aspackedCandidate -> puppiWeightNoLep(); // if miniAOD, take puppiWeightNoLep directly from the object
164  else puppiWeight = (*puppiValueMap)[isocand]; // if AOD, take puppiWeight from the valueMap
165  if (puppiWeight > 0.)cand_values[isotype][i] += (isocand->pt())*puppiWeight; // this is basically the main change to Lindsey's code: scale pt with puppiWeight for candidates with puppiWeight > 0.
166  }
167  }
168  }
169  // add this candidate to isolation value list
170  for( unsigned i = 0; i < kNPFTypes; ++i ) {
171  for( unsigned j = 0; j < cand_values[i].size(); ++j ) {
172  the_values[i][j].push_back(cand_values[i][j]);
173  }
174  }
175  }
176  // fill and put all products
177  for( unsigned i = 0; i < kNPFTypes; ++ i ) {
178  for( unsigned j = 0; j < the_values[i].size(); ++j ) {
179  product_type the_product( new edm::ValueMap<float> );
180  edm::ValueMap<float>::Filler fillerprod(*the_product);
181  fillerprod.insert(to_isolate,
182  the_values[i][j].begin(),
183  the_values[i][j].end());
184  fillerprod.fill();
185  ev.put(std::move(the_product),_product_names[i][j]);
186  }
187  }
188  }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
Definition: helper.py:1
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
Ptr< value_type > ptrAt(size_type i) const
edm::Handle< edm::ValueMap< float > > puppiValueMap
std::array< std::vector< std::string >, kNPFTypes > _product_names
size_type size() const
edm::EDGetTokenT< edm::ValueMap< float > > puppiValueMapToken_
#define end
Definition: vmac.h:39
Definition: value.py:1
int k[5][pyjets_maxn]
ParticleType translatePdgIdToType(int pdgid) const
Definition: PFCandidate.cc:233
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:40
#define begin
Definition: vmac.h:32
def move(src, dest)
Definition: eostools.py:511

Member Data Documentation

edm::EDGetTokenT<CandView> citk::PFIsolationSumProducerForPUPPI::_isolate_with
private
std::array<IsoTypes,kNPFTypes> citk::PFIsolationSumProducerForPUPPI::_isolation_types
private
std::array<std::vector<std::string>,kNPFTypes> citk::PFIsolationSumProducerForPUPPI::_product_names
private
edm::EDGetTokenT<CandView> citk::PFIsolationSumProducerForPUPPI::_to_isolate
private
const TypeMap citk::PFIsolationSumProducerForPUPPI::_typeMap
private
unsigned citk::PFIsolationSumProducerForPUPPI::kNPFTypes = 8
staticprivate

Definition at line 42 of file CITKPFIsolationSumProducerForPUPPI.cc.

Referenced by produce().

edm::Handle<edm::ValueMap<float> > citk::PFIsolationSumProducerForPUPPI::puppiValueMap
private

Definition at line 49 of file CITKPFIsolationSumProducerForPUPPI.cc.

Referenced by produce().

edm::EDGetTokenT<edm::ValueMap<float> > citk::PFIsolationSumProducerForPUPPI::puppiValueMapToken_
private
bool citk::PFIsolationSumProducerForPUPPI::usePUPPINoLepton = false
private
bool citk::PFIsolationSumProducerForPUPPI::useValueMapForPUPPI = true
private