CMS 3D CMS Logo

EgammaRecHitExtractor.cc
Go to the documentation of this file.
1 //*****************************************************************************
2 // File: EgammaRecHitExtractor.cc
3 // ----------------------------------------------------------------------------
4 // OrigAuth: Matthias Mozer, adapted from EgammaHcalExtractor by S. Harper
5 // Institute: IIHE-VUB, RAL
6 //=============================================================================
7 //*****************************************************************************
8 
35 
36 #include <Math/VectorUtil.h>
37 
38 #include <vector>
39 #include <functional>
40 
41 namespace egammaisolation {
42 
44  public:
47  ~EgammaRecHitExtractor() override;
48  void fillVetos(const edm::Event& ev, const edm::EventSetup& evSetup, const reco::TrackCollection& tracks) override {
49  }
51  const edm::EventSetup& evSetup,
52  const reco::Track& track) const override {
53  throw cms::Exception("Configuration Error")
54  << "This extractor " << (typeid(this).name()) << " is not made for tracks";
55  }
57  const edm::EventSetup& evSetup,
58  const reco::Candidate& c) const override;
59 
60  private:
62  const reco::SuperClusterRef& sc,
63  const CaloSubdetectorGeometry* subdet,
64  const CaloGeometry* caloGeom,
66  //const EcalChannelStatus* chStatus,
67  const EcalSeverityLevelAlgo* sevLevel,
68  bool barrel) const;
69 
70  double etMin_;
71  double energyMin_;
72  double extRadius_;
73  double intRadius_;
74  double intStrip_;
82  bool tryBoth_;
83  bool useEt_;
85  bool sameTag_;
86  //int severityLevelCut_;
87  //float severityRecHitThreshold_;
88  //std::string spIdString_;
89  //float spIdThreshold_;
90  //EcalSeverityLevelAlgo::SpikeId spId_;
91  //std::vector<int> v_chstatus_;
92  std::vector<int> severitiesexclEB_;
93  std::vector<int> severitiesexclEE_;
94  std::vector<int> flagsexclEB_;
95  std::vector<int> flagsexclEE_;
96  };
97 } // namespace egammaisolation
98 
102 
103 using namespace std;
104 using namespace egammaisolation;
105 using namespace reco::isodeposit;
106 
107 EgammaRecHitExtractor::EgammaRecHitExtractor(const edm::ParameterSet& par, edm::ConsumesCollector& iC)
108  : etMin_(par.getParameter<double>("etMin")),
109  energyMin_(par.getParameter<double>("energyMin")),
110  extRadius_(par.getParameter<double>("extRadius")),
111  intRadius_(par.getParameter<double>("intRadius")),
112  intStrip_(par.getParameter<double>("intStrip")),
113  barrelEcalHitsTag_(par.getParameter<edm::InputTag>("barrelEcalHits")),
114  endcapEcalHitsTag_(par.getParameter<edm::InputTag>("endcapEcalHits")),
115  barrelEcalHitsToken_(iC.consumes<EcalRecHitCollection>(barrelEcalHitsTag_)),
116  endcapEcalHitsToken_(iC.consumes<EcalRecHitCollection>(endcapEcalHitsTag_)),
117  geometryToken_(iC.esConsumes()),
118  sevlvToken_(iC.esConsumes()),
119  fakeNegativeDeposit_(par.getParameter<bool>("subtractSuperClusterEnergy")),
120  tryBoth_(par.getParameter<bool>("tryBoth")),
121  vetoClustered_(par.getParameter<bool>("vetoClustered")),
122  sameTag_(false)
123 //severityLevelCut_(par.getParameter<int>("severityLevelCut"))
124 //severityRecHitThreshold_(par.getParameter<double>("severityRecHitThreshold")),
125 //spIdString_(par.getParameter<std::string>("spikeIdString")),
126 //spIdThreshold_(par.getParameter<double>("spikeIdThreshold")),
127 {
128  const std::vector<std::string> flagnamesEB = par.getParameter<std::vector<std::string> >("RecHitFlagToBeExcludedEB");
129 
130  const std::vector<std::string> flagnamesEE = par.getParameter<std::vector<std::string> >("RecHitFlagToBeExcludedEE");
131 
132  flagsexclEB_ = StringToEnumValue<EcalRecHit::Flags>(flagnamesEB);
133 
134  flagsexclEE_ = StringToEnumValue<EcalRecHit::Flags>(flagnamesEE);
135 
136  const std::vector<std::string> severitynamesEB =
137  par.getParameter<std::vector<std::string> >("RecHitSeverityToBeExcludedEB");
138 
139  severitiesexclEB_ = StringToEnumValue<EcalSeverityLevel::SeverityLevel>(severitynamesEB);
140 
141  const std::vector<std::string> severitynamesEE =
142  par.getParameter<std::vector<std::string> >("RecHitSeverityToBeExcludedEE");
143 
144  severitiesexclEE_ = StringToEnumValue<EcalSeverityLevel::SeverityLevel>(severitynamesEE);
145 
146  if ((intRadius_ != 0.0) && (fakeNegativeDeposit_)) {
147  throw cms::Exception("Configuration Error") << "EgammaRecHitExtractor: "
148  << "If you use 'subtractSuperClusterEnergy', you *must* set "
149  "'intRadius' to ZERO; it does not make sense, otherwise.";
150  }
151  std::string isoVariable = par.getParameter<std::string>("isolationVariable");
152  if (isoVariable == "et") {
153  useEt_ = true;
154  } else if (isoVariable == "energy") {
155  useEt_ = false;
156  } else {
157  throw cms::Exception("Configuration Error")
158  << "EgammaRecHitExtractor: isolationVariable '" << isoVariable << "' not known. "
159  << " Supported values are 'et', 'energy'. ";
160  }
162  sameTag_ = true;
163  if (tryBoth_) {
164  edm::LogWarning("EgammaRecHitExtractor")
165  << "If you have configured 'barrelRecHits' == 'endcapRecHits', so I'm switching 'tryBoth' to FALSE.";
166  tryBoth_ = false;
167  }
168  }
169 }
170 
172 
174  const edm::EventSetup& iSetup,
175  const reco::Candidate& emObject) const {
176  //Get the channel status from the db
177  //edm::ESHandle<EcalChannelStatus> chStatus;
178  //iSetup.get<EcalChannelStatusRcd>().get(chStatus);
179 
180  const EcalSeverityLevelAlgo* sevLevel = &iSetup.getData(sevlvToken_);
181 
182  const CaloGeometry* caloGeom = &iSetup.getData(geometryToken_);
185 
186  static const std::string metname = "EgammaIsolationAlgos|EgammaRecHitExtractor";
187 
188  //define isodeposit starting from candidate
190  math::XYZPoint caloPosition = sc->position();
191 
192  Direction candDir(caloPosition.eta(), caloPosition.phi());
193  reco::IsoDeposit deposit(candDir);
195  double sinTheta = sin(2 * atan(exp(-sc->eta())));
196  deposit.addCandEnergy(sc->energy() * (useEt_ ? sinTheta : 1.0));
197 
198  // subtract supercluster if desired
199  double fakeEnergy = -sc->rawEnergy();
200  if (fakeNegativeDeposit_) {
201  deposit.addDeposit(candDir, fakeEnergy * (useEt_ ? sinTheta : 1.0)); // not exactly clean...
202  }
203 
204  // fill rechits
205  bool inBarrel = sameTag_ || (abs(sc->eta()) < 1.479); //check for barrel. If only one collection is used, use barrel
206  if (inBarrel || tryBoth_) {
207  collect(deposit, sc, barrelgeom, caloGeom, iEvent.get(barrelEcalHitsToken_), sevLevel, true);
208  }
209 
210  if ((!inBarrel) || tryBoth_) {
211  collect(deposit, sc, endcapgeom, caloGeom, iEvent.get(endcapEcalHitsToken_), sevLevel, false);
212  }
213 
214  return deposit;
215 }
216 
218  const reco::SuperClusterRef& sc,
219  const CaloSubdetectorGeometry* subdet,
220  const CaloGeometry* caloGeom,
221  const EcalRecHitCollection& hits,
222  //const EcalChannelStatus* chStatus,
223  const EcalSeverityLevelAlgo* sevLevel,
224  bool barrel) const {
225  GlobalPoint caloPosition(sc->position().x(), sc->position().y(), sc->position().z());
226  CaloSubdetectorGeometry::DetIdSet chosen = subdet->getCells(caloPosition, extRadius_);
228  double caloeta = caloPosition.eta();
229  double calophi = caloPosition.phi();
230  double r2 = intRadius_ * intRadius_;
231 
232  std::vector<std::pair<DetId, float> >::const_iterator rhIt;
233 
234  for (CaloSubdetectorGeometry::DetIdSet::const_iterator i = chosen.begin(), end = chosen.end(); i != end; ++i) {
235  j = hits.find(*i);
236  if (j != hits.end()) {
237  const GlobalPoint& position = caloGeom->getPosition(*i);
238  double eta = position.eta();
239  double phi = position.phi();
240  double energy = j->energy();
241  double et = energy * position.perp() / position.mag();
242  double phiDiff = reco::deltaPhi(phi, calophi);
243 
244  //check if we are supposed to veto clustered and then do so
245  if (vetoClustered_) {
246  //Loop over basic clusters:
247  bool isClustered = false;
248  for (auto bcIt = sc->clustersBegin(); bcIt != sc->clustersEnd(); ++bcIt) {
249  for (rhIt = (*bcIt)->hitsAndFractions().begin(); rhIt != (*bcIt)->hitsAndFractions().end(); ++rhIt) {
250  if (rhIt->first == *i)
251  isClustered = true;
252  if (isClustered)
253  break;
254  }
255  if (isClustered)
256  break;
257  } //end loop over basic clusters
258 
259  if (isClustered)
260  continue;
261  } //end if removeClustered
262 
263  std::vector<int>::const_iterator sit;
264  int severityFlag = sevLevel->severityLevel(j->detid(), hits);
265  if (barrel) {
266  sit = std::find(severitiesexclEB_.begin(), severitiesexclEB_.end(), severityFlag);
267  if (sit != severitiesexclEB_.end())
268  continue;
269  } else {
270  sit = std::find(severitiesexclEE_.begin(), severitiesexclEE_.end(), severityFlag);
271  if (sit != severitiesexclEE_.end())
272  continue;
273  }
274 
275  if (barrel) {
276  // new rechit flag checks
277  if (!j->checkFlag(EcalRecHit::kGood)) {
278  if (j->checkFlags(flagsexclEB_)) {
279  continue;
280  }
281  }
282  } else {
283  // new rechit flag checks
284  if (!j->checkFlag(EcalRecHit::kGood)) {
285  if (j->checkFlags(flagsexclEE_)) {
286  continue;
287  }
288  }
289  }
290 
291  if (et > etMin_ && energy > energyMin_ //Changed to fabs - then changed back to energy
292  && fabs(eta - caloeta) > intStrip_ && (eta - caloeta) * (eta - caloeta) + phiDiff * phiDiff > r2) {
294  }
295  }
296  }
297 }
constexpr double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:26
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
reco::IsoDeposit deposit(const edm::Event &ev, const edm::EventSetup &evSetup, const reco::Track &track) const override
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
void setVeto(const Veto &aVeto)
Set veto.
Definition: IsoDeposit.h:82
const std::string metname
std::string encode() const
Definition: InputTag.cc:159
T get() const
get a component
Definition: Candidate.h:221
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
std::vector< EcalRecHit >::const_iterator const_iterator
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
void addDeposit(double dr, double deposit)
Add deposit (ie. transverse energy or pT)
Definition: IsoDeposit.cc:19
EcalSeverityLevel::SeverityLevel severityLevel(const DetId &id) const
Evaluate status from id use channelStatus from DB.
int iEvent
Definition: GenABIO.cc:224
virtual DetIdSet getCells(const GlobalPoint &r, double dR) const
Get a list of all cells within a dR of the given cell.
GlobalPoint getPosition(const DetId &id) const
Get the position of a given detector id.
Definition: CaloGeometry.cc:50
void addCandEnergy(double et)
Set energy or pT attached to cand trajectory.
Definition: IsoDeposit.h:132
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void fillVetos(const edm::Event &ev, const edm::EventSetup &evSetup, const reco::TrackCollection &tracks) override
EgammaRecHitExtractor(const edm::ParameterSet &par, edm::ConsumesCollector &&iC)
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
void collect(reco::IsoDeposit &deposit, const reco::SuperClusterRef &sc, const CaloSubdetectorGeometry *subdet, const CaloGeometry *caloGeom, const EcalRecHitCollection &hits, const EcalSeverityLevelAlgo *sevLevel, bool barrel) const
edm::ESGetToken< CaloGeometry, CaloGeometryRecord > geometryToken_
edm::EDGetTokenT< EcalRecHitCollection > endcapEcalHitsToken_
HLT enums.
static int position[264][3]
Definition: ReadPGInfo.cc:289
edm::EDGetTokenT< EcalRecHitCollection > barrelEcalHitsToken_
edm::ESGetToken< EcalSeverityLevelAlgo, EcalSeverityLevelAlgoRcd > sevlvToken_
#define DEFINE_EDM_PLUGIN(factory, type, name)
Log< level::Warning, false > LogWarning
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:34