CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
PFCandIsolatorFromDeposits::SingleDeposit Class Reference

Public Member Functions

void cleanup ()
 
double compute (const reco::CandidateBaseRef &cand)
 
const reco::IsoDepositMapmap ()
 
void open (const edm::Event &iEvent, const edm::EventSetup &iSetup)
 
 SingleDeposit (const edm::ParameterSet &, edm::ConsumesCollector &&iC)
 

Private Member Functions

bool isNumber (const std::string &str) const
 
double toNumber (const std::string &str) const
 

Private Attributes

reco::isodeposit::AbsVetos barrelVetos_
 
double deltaR_
 
reco::isodeposit::AbsVetos endcapVetos_
 
reco::isodeposit::EventDependentAbsVetos evdepVetos_
 
edm::Handle< reco::IsoDepositMaphDeps_
 
Mode mode_
 
bool skipDefaultVeto_
 
edm::EDGetTokenT< reco::IsoDepositMapsrcToken_
 
bool usePivotForBarrelEndcaps_
 
bool usesFunction_
 
double weight_
 
StringObjectFunction< reco::CandidateweightExpr_
 

Detailed Description

Definition at line 39 of file PFCandIsolatorFromDeposit.h.

Constructor & Destructor Documentation

PFCandIsolatorFromDeposits::SingleDeposit::SingleDeposit ( const edm::ParameterSet iConfig,
edm::ConsumesCollector &&  iC 
)

Definition at line 38 of file PFCandIsolatorFromDeposit.cc.

References barrelVetos_, PFCandIsolatorFromDeposits::Count, endcapVetos_, evdepVetos_, Exception, edm::ParameterSet::getParameter(), isNumber(), IsoDepositVetoFactory::make(), match(), PFCandIsolatorFromDeposits::Max, PFCandIsolatorFromDeposits::MaxRelative, ALCARECOPromptCalibProdSiPixelAli0T_cff::mode, mode_, PFCandIsolatorFromDeposits::NearestDR, AlCaHLTBitMon_QueryRunRegistry::string, PFCandIsolatorFromDeposits::Sum, PFCandIsolatorFromDeposits::Sum2, PFCandIsolatorFromDeposits::Sum2Relative, PFCandIsolatorFromDeposits::SumRelative, toNumber(), usePivotForBarrelEndcaps_, usesFunction_, boostedElectronIsolation_cff::vetos, and weight_.

Referenced by PFCandIsolatorFromDeposits::PFCandIsolatorFromDeposits().

40  deltaR_(iConfig.getParameter<double>("deltaR")),
41  weightExpr_(iConfig.getParameter<std::string>("weight")),
42  skipDefaultVeto_(iConfig.getParameter<bool>("skipDefaultVeto")),
43  usePivotForBarrelEndcaps_(iConfig.getParameter<bool>("PivotCoordinatesForEBEE"))
44 //,vetos_(new AbsVetos())
45 {
46  std::string mode = iConfig.getParameter<std::string>("mode");
47  if (mode == "sum")
48  mode_ = Sum;
49  else if (mode == "sumRelative")
51  else if (mode == "sum2")
52  mode_ = Sum2;
53  else if (mode == "sum2Relative")
55  else if (mode == "max")
56  mode_ = Max;
57  else if (mode == "maxRelative")
59  else if (mode == "nearestDR")
60  mode_ = NearestDR;
61  else if (mode == "count")
62  mode_ = Count;
63  else
64  throw cms::Exception("Not Implemented") << "Mode '" << mode << "' not implemented. "
65  << "Supported modes are 'sum', 'sumRelative', 'count'." <<
66  //"Supported modes are 'sum', 'sumRelative', 'max', 'maxRelative', 'count'." << // TODO: on request only
67  "New methods can be easily implemented if requested.";
68  typedef std::vector<std::string> vstring;
69  vstring vetos = iConfig.getParameter<vstring>("vetos");
71  static const std::regex ecalSwitch("^Ecal(Barrel|Endcaps):(.*)");
72 
73  for (vstring::const_iterator it = vetos.begin(), ed = vetos.end(); it != ed; ++it) {
74  std::cmatch match;
75  // in that case, make two series of vetoes
77  if (regex_match(it->c_str(), match, ecalSwitch)) {
78  if (match[1] == "Barrel") {
79  // std::cout << " Adding Barrel veto " << std::string(match[2]) << std::endl;
80  barrelVetos_.push_back(
81  IsoDepositVetoFactory::make(std::string(match[2]).c_str(), evdep, iC)); // I don't know a better syntax
82  }
83  if (match[1] == "Endcaps") {
84  // std::cout << " Adding Endcap veto " << std::string(match[2]) << std::endl;
85  endcapVetos_.push_back(IsoDepositVetoFactory::make(std::string(match[2]).c_str(), evdep, iC));
86  }
87  } else {
88  barrelVetos_.push_back(IsoDepositVetoFactory::make(it->c_str(), evdep, iC));
89  endcapVetos_.push_back(IsoDepositVetoFactory::make(it->c_str(), evdep, iC));
90  }
91  } else {
92  //only one serie of vetoes, just barrel
93  barrelVetos_.push_back(IsoDepositVetoFactory::make(it->c_str(), evdep, iC));
94  }
95  if (evdep)
96  evdepVetos_.push_back(evdep);
97  }
98 
99  std::string weight = iConfig.getParameter<std::string>("weight");
100  if (isNumber(weight)) {
101  //std::cout << "Weight is a simple number, " << toNumber(weight) << std::endl;
102  weight_ = toNumber(weight);
103  usesFunction_ = false;
104  } else {
105  usesFunction_ = true;
106  //std::cout << "Weight is a function, this might slow you down... " << std::endl;
107  }
108  //std::cout << "PFCandIsolatorFromDeposits::SingleDeposit::SingleDeposit: Total of " << vetos_.size() << " vetos" << std::endl;
109 }
static reco::isodeposit::AbsVeto * make(const char *string, edm::ConsumesCollector &iC)
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
vector< string > vstring
Definition: ExoticaDQM.cc:8
StringObjectFunction< reco::Candidate > weightExpr_
Definition: weight.py:1
reco::isodeposit::EventDependentAbsVetos evdepVetos_
edm::EDGetTokenT< reco::IsoDepositMap > srcToken_
bool isNumber(const std::string &str) const
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
double toNumber(const std::string &str) const

Member Function Documentation

void PFCandIsolatorFromDeposits::SingleDeposit::cleanup ( )

Definition at line 110 of file PFCandIsolatorFromDeposit.cc.

References barrelVetos_, endcapVetos_, and evdepVetos_.

Referenced by esMonitoring.FDJsonServer::handle_close().

110  {
111  for (AbsVetos::iterator it = barrelVetos_.begin(), ed = barrelVetos_.end(); it != ed; ++it) {
112  delete *it;
113  }
114  for (AbsVetos::iterator it = endcapVetos_.begin(), ed = endcapVetos_.end(); it != ed; ++it) {
115  delete *it;
116  }
117  barrelVetos_.clear();
118  endcapVetos_.clear();
119  // NOTE: we DON'T have to delete the evdepVetos_, they have already been deleted above. We just clear the vectors
120  evdepVetos_.clear();
121 }
reco::isodeposit::EventDependentAbsVetos evdepVetos_
double PFCandIsolatorFromDeposits::SingleDeposit::compute ( const reco::CandidateBaseRef cand)

Definition at line 129 of file PFCandIsolatorFromDeposit.cc.

References Reference_intrackfit_cff::barrel, barrelVetos_, reco::IsoDeposit::candEnergy(), PFCandIsolatorFromDeposits::Count, reco::IsoDeposit::countWithin(), deltaR_, endcapVetos_, PVValHelper::eta, reco::IsoDeposit::eta(), Exception, PFCandIsolatorFromDeposits::Max, PFCandIsolatorFromDeposits::MaxRelative, reco::IsoDeposit::maxWithin(), mode_, PFCandIsolatorFromDeposits::NearestDR, reco::IsoDeposit::nearestDR(), phi, reco::IsoDeposit::phi(), reco::PFCandidate::positionAtECALEntrance(), skipDefaultVeto_, PFCandIsolatorFromDeposits::Sum, PFCandIsolatorFromDeposits::Sum2, PFCandIsolatorFromDeposits::Sum2Relative, reco::IsoDeposit::sum2Within(), PFCandIsolatorFromDeposits::SumRelative, reco::IsoDeposit::sumWithin(), reco::RecoCandidate::superCluster(), usePivotForBarrelEndcaps_, usesFunction_, boostedElectronIsolation_cff::vetos, weight_, and weightExpr_.

129  {
130  const IsoDeposit &dep = (*hDeps_)[cand];
131  double eta = dep.eta(), phi = dep.phi(); // better to center on the deposit direction
132  // that could be, e.g., the impact point at calo
133  bool barrel = true;
135  const reco::PFCandidate *myPFCand = dynamic_cast<const reco::PFCandidate *>(&(*cand));
136  if (myPFCand) {
137  // exact barrel boundary
138  barrel = fabs(myPFCand->positionAtECALEntrance().eta()) < 1.479;
139  } else {
140  const reco::RecoCandidate *myRecoCand = dynamic_cast<const reco::RecoCandidate *>(&(*cand));
141  if (myRecoCand) {
142  // not optimal. isEB should be used.
143  barrel = (fabs(myRecoCand->superCluster()->eta()) < 1.479);
144  }
145  }
146  }
147  // if ! usePivotForBarrelEndcaps_ only the barrel series is used, which does not prevent the vetoes do be different in barrel & endcaps
149 
150  for (AbsVetos::iterator it = vetos->begin(), ed = vetos->end(); it != ed; ++it) {
151  (*it)->centerOn(eta, phi);
152  }
153  double weight = (usesFunction_ ? weightExpr_(*cand) : weight_);
154  switch (mode_) {
155  case Count:
156  return weight * dep.countWithin(deltaR_, *vetos, skipDefaultVeto_);
157  case Sum:
158  return weight * dep.sumWithin(deltaR_, *vetos, skipDefaultVeto_);
159  case SumRelative:
160  return weight * dep.sumWithin(deltaR_, *vetos, skipDefaultVeto_) / dep.candEnergy();
161  case Sum2:
162  return weight * dep.sum2Within(deltaR_, *vetos, skipDefaultVeto_);
163  case Sum2Relative:
164  return weight * dep.sum2Within(deltaR_, *vetos, skipDefaultVeto_) / (dep.candEnergy() * dep.candEnergy());
165  case Max:
166  return weight * dep.maxWithin(deltaR_, *vetos, skipDefaultVeto_);
167  case NearestDR:
168  return weight * dep.nearestDR(deltaR_, *vetos, skipDefaultVeto_);
169  case MaxRelative:
170  return weight * dep.maxWithin(deltaR_, *vetos, skipDefaultVeto_) / dep.candEnergy();
171  }
172  throw cms::Exception("Logic error") << "Should not happen at " << __FILE__ << ", line "
173  << __LINE__; // avoid gcc warning
174 }
double candEnergy() const
Get energy or pT attached to cand trajectory.
Definition: IsoDeposit.h:129
double sum2Within(double coneSize, const AbsVetos &vetos=AbsVetos(), bool skipDepositVeto=false) const
Definition: IsoDeposit.cc:143
double eta() const
Definition: IsoDeposit.h:76
double phi() const
Definition: IsoDeposit.h:77
StringObjectFunction< reco::Candidate > weightExpr_
Definition: weight.py:1
double countWithin(double coneSize, const AbsVetos &vetos=AbsVetos(), bool skipDepositVeto=false) const
Definition: IsoDeposit.cc:134
double maxWithin(double coneSize, const AbsVetos &vetos=AbsVetos(), bool skipDepositVeto=false) const
Definition: IsoDeposit.cc:146
const math::XYZPointF & positionAtECALEntrance() const
Definition: PFCandidate.h:362
double sumWithin(double coneSize, const AbsVetos &vetos=AbsVetos(), bool skipDepositVeto=false) const
Definition: IsoDeposit.cc:137
double nearestDR(double coneSize, const AbsVetos &vetos=AbsVetos(), bool skipDepositVeto=false) const
Definition: IsoDeposit.cc:150
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:40
std::vector< AbsVeto * > AbsVetos
Definition: IsoDeposit.h:43
virtual reco::SuperClusterRef superCluster() const
reference to a SuperCluster
bool PFCandIsolatorFromDeposits::SingleDeposit::isNumber ( const std::string &  str) const
private

Definition at line 32 of file PFCandIsolatorFromDeposit.cc.

Referenced by SingleDeposit().

32  {
33  static const std::regex re("^[+-]?(\\d+\\.?|\\d*\\.\\d*)$");
34  return regex_match(str.c_str(), re);
35 }
#define str(s)
const reco::IsoDepositMap& PFCandIsolatorFromDeposits::SingleDeposit::map ( )
inline

Definition at line 45 of file PFCandIsolatorFromDeposit.h.

Referenced by PFCandIsolatorFromDeposits::produce().

45 { return *hDeps_; }
edm::Handle< reco::IsoDepositMap > hDeps_
void PFCandIsolatorFromDeposits::SingleDeposit::open ( const edm::Event iEvent,
const edm::EventSetup iSetup 
)

Definition at line 122 of file PFCandIsolatorFromDeposit.cc.

References evdepVetos_, edm::Event::getByToken(), hDeps_, and srcToken_.

Referenced by Vispa.Plugins.ConfigEditor.ConfigEditorTabController.ConfigEditorTabController::importConfig().

122  {
123  iEvent.getByToken(srcToken_, hDeps_);
124  for (EventDependentAbsVetos::iterator it = evdepVetos_.begin(), ed = evdepVetos_.end(); it != ed; ++it) {
125  (*it)->setEvent(iEvent, iSetup);
126  }
127 }
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
reco::isodeposit::EventDependentAbsVetos evdepVetos_
edm::Handle< reco::IsoDepositMap > hDeps_
edm::EDGetTokenT< reco::IsoDepositMap > srcToken_
double PFCandIsolatorFromDeposits::SingleDeposit::toNumber ( const std::string &  str) const
private

Definition at line 36 of file PFCandIsolatorFromDeposit.cc.

Referenced by SingleDeposit().

36 { return atof(str.c_str()); }
#define str(s)

Member Data Documentation

reco::isodeposit::AbsVetos PFCandIsolatorFromDeposits::SingleDeposit::barrelVetos_
private

Definition at line 55 of file PFCandIsolatorFromDeposit.h.

Referenced by cleanup(), compute(), and SingleDeposit().

double PFCandIsolatorFromDeposits::SingleDeposit::deltaR_
private

Definition at line 50 of file PFCandIsolatorFromDeposit.h.

Referenced by compute().

reco::isodeposit::AbsVetos PFCandIsolatorFromDeposits::SingleDeposit::endcapVetos_
private

Definition at line 56 of file PFCandIsolatorFromDeposit.h.

Referenced by cleanup(), compute(), and SingleDeposit().

reco::isodeposit::EventDependentAbsVetos PFCandIsolatorFromDeposits::SingleDeposit::evdepVetos_
private

Definition at line 57 of file PFCandIsolatorFromDeposit.h.

Referenced by cleanup(), open(), and SingleDeposit().

edm::Handle<reco::IsoDepositMap> PFCandIsolatorFromDeposits::SingleDeposit::hDeps_
private

Definition at line 60 of file PFCandIsolatorFromDeposit.h.

Referenced by open().

Mode PFCandIsolatorFromDeposits::SingleDeposit::mode_
private

Definition at line 48 of file PFCandIsolatorFromDeposit.h.

Referenced by compute(), and SingleDeposit().

bool PFCandIsolatorFromDeposits::SingleDeposit::skipDefaultVeto_
private

Definition at line 58 of file PFCandIsolatorFromDeposit.h.

Referenced by compute().

edm::EDGetTokenT<reco::IsoDepositMap> PFCandIsolatorFromDeposits::SingleDeposit::srcToken_
private

Definition at line 49 of file PFCandIsolatorFromDeposit.h.

Referenced by open().

bool PFCandIsolatorFromDeposits::SingleDeposit::usePivotForBarrelEndcaps_
private

Definition at line 59 of file PFCandIsolatorFromDeposit.h.

Referenced by compute(), and SingleDeposit().

bool PFCandIsolatorFromDeposits::SingleDeposit::usesFunction_
private

Definition at line 51 of file PFCandIsolatorFromDeposit.h.

Referenced by compute(), and SingleDeposit().

double PFCandIsolatorFromDeposits::SingleDeposit::weight_
private

Definition at line 52 of file PFCandIsolatorFromDeposit.h.

Referenced by compute(), and SingleDeposit().

StringObjectFunction<reco::Candidate> PFCandIsolatorFromDeposits::SingleDeposit::weightExpr_
private

Definition at line 54 of file PFCandIsolatorFromDeposit.h.

Referenced by compute().