CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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 36 of file PFCandIsolatorFromDeposit.h.

Constructor & Destructor Documentation

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

Definition at line 40 of file PFCandIsolatorFromDeposit.cc.

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

40  :
42  deltaR_(iConfig.getParameter<double>("deltaR")),
43  weightExpr_(iConfig.getParameter<std::string>("weight")),
44  skipDefaultVeto_(iConfig.getParameter<bool>("skipDefaultVeto")),
45  usePivotForBarrelEndcaps_(iConfig.getParameter<bool>("PivotCoordinatesForEBEE"))
46  //,vetos_(new AbsVetos())
47 {
48  std::string mode = iConfig.getParameter<std::string>("mode");
49  if (mode == "sum") mode_ = Sum;
50  else if (mode == "sumRelative") mode_ = SumRelative;
51  else if (mode == "sum2") mode_ = Sum2;
52  else if (mode == "sum2Relative") mode_ = Sum2Relative;
53  else if (mode == "max") mode_ = Max;
54  else if (mode == "maxRelative") mode_ = MaxRelative;
55  else if (mode == "nearestDR") mode_ = NearestDR;
56  else if (mode == "count") mode_ = Count;
57  else throw cms::Exception("Not Implemented") << "Mode '" << mode << "' not implemented. " <<
58  "Supported modes are 'sum', 'sumRelative', 'count'." <<
59  //"Supported modes are 'sum', 'sumRelative', 'max', 'maxRelative', 'count'." << // TODO: on request only
60  "New methods can be easily implemented if requested.";
61  typedef std::vector<std::string> vstring;
62  vstring vetos = iConfig.getParameter< vstring >("vetos");
64  static boost::regex ecalSwitch("^Ecal(Barrel|Endcaps):(.*)");
65 
66  for (vstring::const_iterator it = vetos.begin(), ed = vetos.end(); it != ed; ++it) {
67  boost::cmatch match;
68  // in that case, make two series of vetoes
70  if (regex_match(it->c_str(), match, ecalSwitch))
71  {
72  if(match[1] == "Barrel") {
73  // std::cout << " Adding Barrel veto " << std::string(match[2]) << std::endl;
74  barrelVetos_.push_back(IsoDepositVetoFactory::make(std::string(match[2]).c_str(), evdep, iC)); // I don't know a better syntax
75  }
76  if(match[1] == "Endcaps") {
77  // std::cout << " Adding Endcap veto " << std::string(match[2]) << std::endl;
78  endcapVetos_.push_back(IsoDepositVetoFactory::make(std::string(match[2]).c_str(), evdep, iC));
79  }
80  }
81  else
82  {
83  barrelVetos_.push_back(IsoDepositVetoFactory::make(it->c_str(), evdep, iC));
84  endcapVetos_.push_back(IsoDepositVetoFactory::make(it->c_str(), evdep, iC));
85  }
86  } else {
87  //only one serie of vetoes, just barrel
88  barrelVetos_.push_back(IsoDepositVetoFactory::make(it->c_str(), evdep, iC));
89  }
90  if (evdep) evdepVetos_.push_back(evdep);
91  }
92 
93  std::string weight = iConfig.getParameter<std::string>("weight");
94  if (isNumber(weight)) {
95  //std::cout << "Weight is a simple number, " << toNumber(weight) << std::endl;
96  weight_ = toNumber(weight);
97  usesFunction_ = false;
98  } else {
99  usesFunction_ = true;
100  //std::cout << "Weight is a function, this might slow you down... " << std::endl;
101  }
102  //std::cout << "PFCandIsolatorFromDeposits::SingleDeposit::SingleDeposit: Total of " << vetos_.size() << " vetos" << std::endl;
103 }
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:86
StringObjectFunction< reco::Candidate > weightExpr_
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
int weight
Definition: histoStyle.py:50
double toNumber(const std::string &str) const

Member Function Documentation

void PFCandIsolatorFromDeposits::SingleDeposit::cleanup ( )

Definition at line 104 of file PFCandIsolatorFromDeposit.cc.

Referenced by esMonitoring.FDJsonServer::handle_close().

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

Definition at line 123 of file PFCandIsolatorFromDeposit.cc.

References Reference_intrackfit_cff::barrel, reco::IsoDeposit::candEnergy(), PFCandIsolatorFromDeposits::Count, reco::IsoDeposit::countWithin(), deltaR_, reco::IsoDeposit::eta(), 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.

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

Definition at line 32 of file PFCandIsolatorFromDeposit.cc.

Referenced by SingleDeposit().

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

Definition at line 42 of file PFCandIsolatorFromDeposit.h.

References hDeps_.

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

Definition at line 116 of file PFCandIsolatorFromDeposit.cc.

References edm::Event::getByToken().

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

116  {
117  iEvent.getByToken(srcToken_, hDeps_);
118  for (EventDependentAbsVetos::iterator it = evdepVetos_.begin(), ed = evdepVetos_.end(); it != ed; ++it) {
119  (*it)->setEvent(iEvent,iSetup);
120  }
121 }
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:449
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  {
37  return atof(str.c_str());
38 }

Member Data Documentation

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

Definition at line 51 of file PFCandIsolatorFromDeposit.h.

Referenced by SingleDeposit().

double PFCandIsolatorFromDeposits::SingleDeposit::deltaR_
private

Definition at line 46 of file PFCandIsolatorFromDeposit.h.

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

Definition at line 52 of file PFCandIsolatorFromDeposit.h.

Referenced by SingleDeposit().

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

Definition at line 53 of file PFCandIsolatorFromDeposit.h.

Referenced by SingleDeposit().

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

Definition at line 56 of file PFCandIsolatorFromDeposit.h.

Referenced by map().

Mode PFCandIsolatorFromDeposits::SingleDeposit::mode_
private

Definition at line 44 of file PFCandIsolatorFromDeposit.h.

Referenced by SingleDeposit().

bool PFCandIsolatorFromDeposits::SingleDeposit::skipDefaultVeto_
private

Definition at line 54 of file PFCandIsolatorFromDeposit.h.

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

Definition at line 45 of file PFCandIsolatorFromDeposit.h.

bool PFCandIsolatorFromDeposits::SingleDeposit::usePivotForBarrelEndcaps_
private

Definition at line 55 of file PFCandIsolatorFromDeposit.h.

Referenced by SingleDeposit().

bool PFCandIsolatorFromDeposits::SingleDeposit::usesFunction_
private

Definition at line 47 of file PFCandIsolatorFromDeposit.h.

Referenced by SingleDeposit().

double PFCandIsolatorFromDeposits::SingleDeposit::weight_
private

Definition at line 48 of file PFCandIsolatorFromDeposit.h.

Referenced by SingleDeposit().

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

Definition at line 50 of file PFCandIsolatorFromDeposit.h.