CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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::IsoDepositMap
srcToken_
 
bool usePivotForBarrelEndcaps_
 
bool usesFunction_
 
double weight_
 
StringObjectFunction
< reco::Candidate
weightExpr_
 

Detailed Description

Definition at line 45 of file PFCandIsolatorFromDeposit.cc.

Constructor & Destructor Documentation

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

Definition at line 85 of file PFCandIsolatorFromDeposit.cc.

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

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

Member Function Documentation

void PFCandIsolatorFromDeposits::SingleDeposit::cleanup ( )

Definition at line 157 of file PFCandIsolatorFromDeposit.cc.

Referenced by esMonitoring.FDJsonServer::handle_close().

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

Definition at line 176 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 histoStyle::weight.

176  {
177  const IsoDeposit &dep = (*hDeps_)[cand];
178  double eta = dep.eta(), phi = dep.phi(); // better to center on the deposit direction
179  // that could be, e.g., the impact point at calo
180  bool barrel = true;
182  const reco::PFCandidate *myPFCand = dynamic_cast<const reco::PFCandidate *>(&(*cand));
183  if (myPFCand) {
184  // exact barrel boundary
185  barrel = fabs(myPFCand->positionAtECALEntrance().eta()) < 1.479;
186  } else {
187  const reco::RecoCandidate *myRecoCand = dynamic_cast<const reco::RecoCandidate *>(&(*cand));
188  if (myRecoCand) {
189  // not optimal. isEB should be used.
190  barrel = (fabs(myRecoCand->superCluster()->eta()) < 1.479);
191  }
192  }
193  }
194  // if ! usePivotForBarrelEndcaps_ only the barrel series is used, which does not prevent the vetoes do be different in barrel & endcaps
196 
197  for (AbsVetos::iterator it = vetos->begin(), ed = vetos->end(); it != ed; ++it) {
198  (*it)->centerOn(eta, phi);
199  }
200  double weight = (usesFunction_ ? weightExpr_(*cand) : weight_);
201  switch (mode_) {
202  case Count:
203  return weight * dep.countWithin(deltaR_, *vetos, skipDefaultVeto_);
204  case Sum:
205  return weight * dep.sumWithin(deltaR_, *vetos, skipDefaultVeto_);
206  case SumRelative:
207  return weight * dep.sumWithin(deltaR_, *vetos, skipDefaultVeto_) / dep.candEnergy();
208  case Sum2:
209  return weight * dep.sum2Within(deltaR_, *vetos, skipDefaultVeto_);
210  case Sum2Relative:
211  return weight * dep.sum2Within(deltaR_, *vetos, skipDefaultVeto_) / (dep.candEnergy() * dep.candEnergy());
212  case Max:
213  return weight * dep.maxWithin(deltaR_, *vetos, skipDefaultVeto_);
214  case NearestDR:
215  return weight * dep.nearestDR(deltaR_, *vetos, skipDefaultVeto_);
216  case MaxRelative:
217  return weight * dep.maxWithin(deltaR_, *vetos, skipDefaultVeto_) / dep.candEnergy();
218  }
219  throw cms::Exception("Logic error") << "Should not happen at " << __FILE__ << ", line "
220  << __LINE__; // avoid gcc warning
221 }
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_
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:388
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:41
std::vector< AbsVeto * > AbsVetos
Definition: IsoDeposit.h:43
int weight
Definition: histoStyle.py:51
virtual reco::SuperClusterRef superCluster() const
reference to a SuperCluster
bool PFCandIsolatorFromDeposits::SingleDeposit::isNumber ( const std::string &  str) const
private

Definition at line 79 of file PFCandIsolatorFromDeposit.cc.

Referenced by SingleDeposit().

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

Definition at line 51 of file PFCandIsolatorFromDeposit.cc.

References hDeps_.

51 { return *hDeps_; }
void PFCandIsolatorFromDeposits::SingleDeposit::open ( const edm::Event iEvent,
const edm::EventSetup iSetup 
)

Definition at line 169 of file PFCandIsolatorFromDeposit.cc.

References edm::Event::getByToken().

169  {
170  iEvent.getByToken(srcToken_, hDeps_);
171  for (EventDependentAbsVetos::iterator it = evdepVetos_.begin(), ed = evdepVetos_.end(); it != ed; ++it) {
172  (*it)->setEvent(iEvent, iSetup);
173  }
174 }
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
reco::isodeposit::EventDependentAbsVetos evdepVetos_
edm::EDGetTokenT< reco::IsoDepositMap > srcToken_
double PFCandIsolatorFromDeposits::SingleDeposit::toNumber ( const std::string &  str) const
private

Definition at line 83 of file PFCandIsolatorFromDeposit.cc.

Referenced by SingleDeposit().

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

Member Data Documentation

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

Definition at line 61 of file PFCandIsolatorFromDeposit.cc.

Referenced by SingleDeposit().

double PFCandIsolatorFromDeposits::SingleDeposit::deltaR_
private

Definition at line 56 of file PFCandIsolatorFromDeposit.cc.

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

Definition at line 62 of file PFCandIsolatorFromDeposit.cc.

Referenced by SingleDeposit().

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

Definition at line 63 of file PFCandIsolatorFromDeposit.cc.

Referenced by SingleDeposit().

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

Definition at line 66 of file PFCandIsolatorFromDeposit.cc.

Referenced by map().

Mode PFCandIsolatorFromDeposits::SingleDeposit::mode_
private

Definition at line 54 of file PFCandIsolatorFromDeposit.cc.

Referenced by SingleDeposit().

bool PFCandIsolatorFromDeposits::SingleDeposit::skipDefaultVeto_
private

Definition at line 64 of file PFCandIsolatorFromDeposit.cc.

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

Definition at line 55 of file PFCandIsolatorFromDeposit.cc.

bool PFCandIsolatorFromDeposits::SingleDeposit::usePivotForBarrelEndcaps_
private

Definition at line 65 of file PFCandIsolatorFromDeposit.cc.

Referenced by SingleDeposit().

bool PFCandIsolatorFromDeposits::SingleDeposit::usesFunction_
private

Definition at line 57 of file PFCandIsolatorFromDeposit.cc.

Referenced by SingleDeposit().

double PFCandIsolatorFromDeposits::SingleDeposit::weight_
private

Definition at line 58 of file PFCandIsolatorFromDeposit.cc.

Referenced by SingleDeposit().

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

Definition at line 60 of file PFCandIsolatorFromDeposit.cc.