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 43 of file PFCandIsolatorFromDeposit.cc.

Constructor & Destructor Documentation

◆ SingleDeposit()

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

Definition at line 83 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_.

85  deltaR_(iConfig.getParameter<double>("deltaR")),
86  weightExpr_(iConfig.getParameter<std::string>("weight")),
87  skipDefaultVeto_(iConfig.getParameter<bool>("skipDefaultVeto")),
88  usePivotForBarrelEndcaps_(iConfig.getParameter<bool>("PivotCoordinatesForEBEE"))
89 //,vetos_(new AbsVetos())
90 {
91  std::string mode = iConfig.getParameter<std::string>("mode");
92  if (mode == "sum")
93  mode_ = Sum;
94  else if (mode == "sumRelative")
96  else if (mode == "sum2")
97  mode_ = Sum2;
98  else if (mode == "sum2Relative")
100  else if (mode == "max")
101  mode_ = Max;
102  else if (mode == "maxRelative")
103  mode_ = MaxRelative;
104  else if (mode == "nearestDR")
105  mode_ = NearestDR;
106  else if (mode == "count")
107  mode_ = Count;
108  else
109  throw cms::Exception("Not Implemented") << "Mode '" << mode << "' not implemented. "
110  << "Supported modes are 'sum', 'sumRelative', 'count'." <<
111  //"Supported modes are 'sum', 'sumRelative', 'max', 'maxRelative', 'count'." << // TODO: on request only
112  "New methods can be easily implemented if requested.";
113  typedef std::vector<std::string> vstring;
114  vstring vetos = iConfig.getParameter<vstring>("vetos");
116  static const std::regex ecalSwitch("^Ecal(Barrel|Endcaps):(.*)");
117 
118  for (vstring::const_iterator it = vetos.begin(), ed = vetos.end(); it != ed; ++it) {
119  std::cmatch match;
120  // in that case, make two series of vetoes
122  if (regex_match(it->c_str(), match, ecalSwitch)) {
123  if (match[1] == "Barrel") {
124  // std::cout << " Adding Barrel veto " << std::string(match[2]) << std::endl;
125  barrelVetos_.push_back(
126  IsoDepositVetoFactory::make(std::string(match[2]).c_str(), evdep, iC)); // I don't know a better syntax
127  }
128  if (match[1] == "Endcaps") {
129  // std::cout << " Adding Endcap veto " << std::string(match[2]) << std::endl;
130  endcapVetos_.push_back(IsoDepositVetoFactory::make(std::string(match[2]).c_str(), evdep, iC));
131  }
132  } else {
133  barrelVetos_.push_back(IsoDepositVetoFactory::make(it->c_str(), evdep, iC));
134  endcapVetos_.push_back(IsoDepositVetoFactory::make(it->c_str(), evdep, iC));
135  }
136  } else {
137  //only one serie of vetoes, just barrel
138  barrelVetos_.push_back(IsoDepositVetoFactory::make(it->c_str(), evdep, iC));
139  }
140  if (evdep)
141  evdepVetos_.push_back(evdep);
142  }
143 
144  std::string weight = iConfig.getParameter<std::string>("weight");
145  if (isNumber(weight)) {
146  //std::cout << "Weight is a simple number, " << toNumber(weight) << std::endl;
148  usesFunction_ = false;
149  } else {
150  usesFunction_ = true;
151  //std::cout << "Weight is a function, this might slow you down... " << std::endl;
152  }
153  //std::cout << "PFCandIsolatorFromDeposits::SingleDeposit::SingleDeposit: Total of " << vetos_.size() << " vetos" << std::endl;
154 }
static reco::isodeposit::AbsVeto * make(const char *string, edm::ConsumesCollector &iC)
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
bool isNumber(const std::string &str) const
vector< string > vstring
Definition: ExoticaDQM.cc:7
StringObjectFunction< reco::Candidate > weightExpr_
Definition: weight.py:1
reco::isodeposit::EventDependentAbsVetos evdepVetos_
edm::EDGetTokenT< reco::IsoDepositMap > srcToken_
double toNumber(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

Member Function Documentation

◆ cleanup()

void PFCandIsolatorFromDeposits::SingleDeposit::cleanup ( )

Definition at line 155 of file PFCandIsolatorFromDeposit.cc.

Referenced by esMonitoring.FDJsonServer::handle_close().

155  {
156  for (AbsVetos::iterator it = barrelVetos_.begin(), ed = barrelVetos_.end(); it != ed; ++it) {
157  delete *it;
158  }
159  for (AbsVetos::iterator it = endcapVetos_.begin(), ed = endcapVetos_.end(); it != ed; ++it) {
160  delete *it;
161  }
162  barrelVetos_.clear();
163  endcapVetos_.clear();
164  // NOTE: we DON'T have to delete the evdepVetos_, they have already been deleted above. We just clear the vectors
165  evdepVetos_.clear();
166 }
reco::isodeposit::EventDependentAbsVetos evdepVetos_

◆ compute()

double PFCandIsolatorFromDeposits::SingleDeposit::compute ( const reco::CandidateBaseRef cand)

Definition at line 174 of file PFCandIsolatorFromDeposit.cc.

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

174  {
175  const IsoDeposit &dep = (*hDeps_)[cand];
176  double eta = dep.eta(), phi = dep.phi(); // better to center on the deposit direction
177  // that could be, e.g., the impact point at calo
178  bool barrel = true;
180  const reco::PFCandidate *myPFCand = dynamic_cast<const reco::PFCandidate *>(&(*cand));
181  if (myPFCand) {
182  // exact barrel boundary
183  barrel = fabs(myPFCand->positionAtECALEntrance().eta()) < 1.479;
184  } else {
185  const reco::RecoCandidate *myRecoCand = dynamic_cast<const reco::RecoCandidate *>(&(*cand));
186  if (myRecoCand) {
187  // not optimal. isEB should be used.
188  barrel = (fabs(myRecoCand->superCluster()->eta()) < 1.479);
189  }
190  }
191  }
192  // if ! usePivotForBarrelEndcaps_ only the barrel series is used, which does not prevent the vetoes do be different in barrel & endcaps
194 
195  for (AbsVetos::iterator it = vetos->begin(), ed = vetos->end(); it != ed; ++it) {
196  (*it)->centerOn(eta, phi);
197  }
198  double weight = (usesFunction_ ? weightExpr_(*cand) : weight_);
199  switch (mode_) {
200  case Count:
202  case Sum:
203  return weight * dep.sumWithin(deltaR_, *vetos, skipDefaultVeto_);
204  case SumRelative:
205  return weight * dep.sumWithin(deltaR_, *vetos, skipDefaultVeto_) / dep.candEnergy();
206  case Sum2:
208  case Sum2Relative:
209  return weight * dep.sum2Within(deltaR_, *vetos, skipDefaultVeto_) / (dep.candEnergy() * dep.candEnergy());
210  case Max:
211  return weight * dep.maxWithin(deltaR_, *vetos, skipDefaultVeto_);
212  case NearestDR:
213  return weight * dep.nearestDR(deltaR_, *vetos, skipDefaultVeto_);
214  case MaxRelative:
215  return weight * dep.maxWithin(deltaR_, *vetos, skipDefaultVeto_) / dep.candEnergy();
216  }
217  throw cms::Exception("Logic error") << "Should not happen at " << __FILE__ << ", line "
218  << __LINE__; // avoid gcc warning
219 }
double sumWithin(double coneSize, const AbsVetos &vetos=AbsVetos(), bool skipDepositVeto=false) const
Definition: IsoDeposit.cc:137
double phi() const
Definition: IsoDeposit.h:77
double sum2Within(double coneSize, const AbsVetos &vetos=AbsVetos(), bool skipDepositVeto=false) const
Definition: IsoDeposit.cc:143
double nearestDR(double coneSize, const AbsVetos &vetos=AbsVetos(), bool skipDepositVeto=false) const
Definition: IsoDeposit.cc:150
StringObjectFunction< reco::Candidate > weightExpr_
const math::XYZPointF & positionAtECALEntrance() const
Definition: PFCandidate.h:388
Definition: weight.py:1
double maxWithin(double coneSize, const AbsVetos &vetos=AbsVetos(), bool skipDepositVeto=false) const
Definition: IsoDeposit.cc:146
double candEnergy() const
Get energy or pT attached to cand trajectory.
Definition: IsoDeposit.h:129
double eta() const
Definition: IsoDeposit.h:76
virtual reco::SuperClusterRef superCluster() const
reference to a SuperCluster
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:41
std::vector< AbsVeto * > AbsVetos
Definition: IsoDeposit.h:43
double countWithin(double coneSize, const AbsVetos &vetos=AbsVetos(), bool skipDepositVeto=false) const
Definition: IsoDeposit.cc:134

◆ isNumber()

bool PFCandIsolatorFromDeposits::SingleDeposit::isNumber ( const std::string &  str) const
private

Definition at line 77 of file PFCandIsolatorFromDeposit.cc.

References str.

Referenced by SingleDeposit().

77  {
78  static const std::regex re("^[+-]?(\\d+\\.?|\\d*\\.\\d*)$");
79  return regex_match(str.c_str(), re);
80 }
#define str(s)

◆ map()

const reco::IsoDepositMap& PFCandIsolatorFromDeposits::SingleDeposit::map ( )
inline

Definition at line 49 of file PFCandIsolatorFromDeposit.cc.

References hDeps_.

49 { return *hDeps_; }

◆ open()

void PFCandIsolatorFromDeposits::SingleDeposit::open ( const edm::Event iEvent,
const edm::EventSetup iSetup 
)

Definition at line 167 of file PFCandIsolatorFromDeposit.cc.

References iEvent.

167  {
168  iEvent.getByToken(srcToken_, hDeps_);
169  for (EventDependentAbsVetos::iterator it = evdepVetos_.begin(), ed = evdepVetos_.end(); it != ed; ++it) {
170  (*it)->setEvent(iEvent, iSetup);
171  }
172 }
int iEvent
Definition: GenABIO.cc:224
reco::isodeposit::EventDependentAbsVetos evdepVetos_
edm::EDGetTokenT< reco::IsoDepositMap > srcToken_

◆ toNumber()

double PFCandIsolatorFromDeposits::SingleDeposit::toNumber ( const std::string &  str) const
private

Definition at line 81 of file PFCandIsolatorFromDeposit.cc.

References str.

Referenced by SingleDeposit().

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

Member Data Documentation

◆ barrelVetos_

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

Definition at line 59 of file PFCandIsolatorFromDeposit.cc.

Referenced by SingleDeposit().

◆ deltaR_

double PFCandIsolatorFromDeposits::SingleDeposit::deltaR_
private

Definition at line 54 of file PFCandIsolatorFromDeposit.cc.

◆ endcapVetos_

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

Definition at line 60 of file PFCandIsolatorFromDeposit.cc.

Referenced by SingleDeposit().

◆ evdepVetos_

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

Definition at line 61 of file PFCandIsolatorFromDeposit.cc.

Referenced by SingleDeposit().

◆ hDeps_

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

Definition at line 64 of file PFCandIsolatorFromDeposit.cc.

Referenced by map().

◆ mode_

Mode PFCandIsolatorFromDeposits::SingleDeposit::mode_
private

Definition at line 52 of file PFCandIsolatorFromDeposit.cc.

Referenced by SingleDeposit().

◆ skipDefaultVeto_

bool PFCandIsolatorFromDeposits::SingleDeposit::skipDefaultVeto_
private

Definition at line 62 of file PFCandIsolatorFromDeposit.cc.

◆ srcToken_

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

Definition at line 53 of file PFCandIsolatorFromDeposit.cc.

◆ usePivotForBarrelEndcaps_

bool PFCandIsolatorFromDeposits::SingleDeposit::usePivotForBarrelEndcaps_
private

Definition at line 63 of file PFCandIsolatorFromDeposit.cc.

Referenced by SingleDeposit().

◆ usesFunction_

bool PFCandIsolatorFromDeposits::SingleDeposit::usesFunction_
private

Definition at line 55 of file PFCandIsolatorFromDeposit.cc.

Referenced by SingleDeposit().

◆ weight_

double PFCandIsolatorFromDeposits::SingleDeposit::weight_
private

Definition at line 56 of file PFCandIsolatorFromDeposit.cc.

Referenced by SingleDeposit().

◆ weightExpr_

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

Definition at line 58 of file PFCandIsolatorFromDeposit.cc.