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