CMS 3D CMS Logo

EgammaRecHitExtractor.cc
Go to the documentation of this file.
1 //*****************************************************************************
2 // File: EgammaRecHitExtractor.cc
3 // ----------------------------------------------------------------------------
4 // OrigAuth: Matthias Mozer, hacked by Sam Harper (ie the ugly stuff is mine)
5 // Institute: IIHE-VUB, RAL
6 //=============================================================================
7 //*****************************************************************************
8 //C++ includes
9 #include <vector>
10 #include <functional>
11 
12 //ROOT includes
13 #include <Math/VectorUtil.h>
14 
15 //CMSSW includes
17 
32 
34 
36 
37 using namespace std;
38 using namespace egammaisolation;
39 using namespace reco::isodeposit;
40 
41 EgammaRecHitExtractor::EgammaRecHitExtractor(const edm::ParameterSet& par, edm::ConsumesCollector& iC)
42  : etMin_(par.getParameter<double>("etMin")),
43  energyMin_(par.getParameter<double>("energyMin")),
44  extRadius_(par.getParameter<double>("extRadius")),
45  intRadius_(par.getParameter<double>("intRadius")),
46  intStrip_(par.getParameter<double>("intStrip")),
47  barrelEcalHitsTag_(par.getParameter<edm::InputTag>("barrelEcalHits")),
48  endcapEcalHitsTag_(par.getParameter<edm::InputTag>("endcapEcalHits")),
49  barrelEcalHitsToken_(iC.consumes<EcalRecHitCollection>(barrelEcalHitsTag_)),
50  endcapEcalHitsToken_(iC.consumes<EcalRecHitCollection>(endcapEcalHitsTag_)),
51  fakeNegativeDeposit_(par.getParameter<bool>("subtractSuperClusterEnergy")),
52  tryBoth_(par.getParameter<bool>("tryBoth")),
53  vetoClustered_(par.getParameter<bool>("vetoClustered")),
54  sameTag_(false)
55 //severityLevelCut_(par.getParameter<int>("severityLevelCut"))
56 //severityRecHitThreshold_(par.getParameter<double>("severityRecHitThreshold")),
57 //spIdString_(par.getParameter<std::string>("spikeIdString")),
58 //spIdThreshold_(par.getParameter<double>("spikeIdThreshold")),
59 {
60  const std::vector<std::string> flagnamesEB = par.getParameter<std::vector<std::string> >("RecHitFlagToBeExcludedEB");
61 
62  const std::vector<std::string> flagnamesEE = par.getParameter<std::vector<std::string> >("RecHitFlagToBeExcludedEE");
63 
64  flagsexclEB_ = StringToEnumValue<EcalRecHit::Flags>(flagnamesEB);
65 
66  flagsexclEE_ = StringToEnumValue<EcalRecHit::Flags>(flagnamesEE);
67 
68  const std::vector<std::string> severitynamesEB =
69  par.getParameter<std::vector<std::string> >("RecHitSeverityToBeExcludedEB");
70 
71  severitiesexclEB_ = StringToEnumValue<EcalSeverityLevel::SeverityLevel>(severitynamesEB);
72 
73  const std::vector<std::string> severitynamesEE =
74  par.getParameter<std::vector<std::string> >("RecHitSeverityToBeExcludedEE");
75 
76  severitiesexclEE_ = StringToEnumValue<EcalSeverityLevel::SeverityLevel>(severitynamesEE);
77 
78  if ((intRadius_ != 0.0) && (fakeNegativeDeposit_)) {
79  throw cms::Exception("Configuration Error") << "EgammaRecHitExtractor: "
80  << "If you use 'subtractSuperClusterEnergy', you *must* set "
81  "'intRadius' to ZERO; it does not make sense, otherwise.";
82  }
83  std::string isoVariable = par.getParameter<std::string>("isolationVariable");
84  if (isoVariable == "et") {
85  useEt_ = true;
86  } else if (isoVariable == "energy") {
87  useEt_ = false;
88  } else {
89  throw cms::Exception("Configuration Error")
90  << "EgammaRecHitExtractor: isolationVariable '" << isoVariable << "' not known. "
91  << " Supported values are 'et', 'energy'. ";
92  }
94  sameTag_ = true;
95  if (tryBoth_) {
96  edm::LogWarning("EgammaRecHitExtractor")
97  << "If you have configured 'barrelRecHits' == 'endcapRecHits', so I'm switching 'tryBoth' to FALSE.";
98  tryBoth_ = false;
99  }
100  }
101 }
102 
104 
106  const edm::EventSetup& iSetup,
107  const reco::Candidate& emObject) const {
109  iSetup.get<CaloGeometryRecord>().get(pG);
110 
111  //Get the channel status from the db
112  //edm::ESHandle<EcalChannelStatus> chStatus;
113  //iSetup.get<EcalChannelStatusRcd>().get(chStatus);
114 
116  iSetup.get<EcalSeverityLevelAlgoRcd>().get(sevlv);
117  const EcalSeverityLevelAlgo* sevLevel = sevlv.product();
118 
119  const CaloGeometry* caloGeom = pG.product();
122 
123  static const std::string metname = "EgammaIsolationAlgos|EgammaRecHitExtractor";
124 
125  //Get barrel ECAL RecHits
126  edm::Handle<EcalRecHitCollection> barrelEcalRecHitsH;
127  iEvent.getByToken(barrelEcalHitsToken_, barrelEcalRecHitsH);
128 
129  //Get endcap ECAL RecHits
130  edm::Handle<EcalRecHitCollection> endcapEcalRecHitsH;
131  iEvent.getByToken(endcapEcalHitsToken_, endcapEcalRecHitsH);
132 
133  //define isodeposit starting from candidate
135  math::XYZPoint caloPosition = sc->position();
136 
137  Direction candDir(caloPosition.eta(), caloPosition.phi());
138  reco::IsoDeposit deposit(candDir);
140  double sinTheta = sin(2 * atan(exp(-sc->eta())));
141  deposit.addCandEnergy(sc->energy() * (useEt_ ? sinTheta : 1.0));
142 
143  // subtract supercluster if desired
144  double fakeEnergy = -sc->rawEnergy();
145  if (fakeNegativeDeposit_) {
146  deposit.addDeposit(candDir, fakeEnergy * (useEt_ ? sinTheta : 1.0)); // not exactly clean...
147  }
148 
149  // fill rechits
150  bool inBarrel = sameTag_ || (abs(sc->eta()) < 1.479); //check for barrel. If only one collection is used, use barrel
151  if (inBarrel || tryBoth_) {
152  collect(deposit, sc, barrelgeom, caloGeom, *barrelEcalRecHitsH, sevLevel, true);
153  }
154 
155  if ((!inBarrel) || tryBoth_) {
156  collect(deposit, sc, endcapgeom, caloGeom, *endcapEcalRecHitsH, sevLevel, false);
157  }
158 
159  return deposit;
160 }
161 
163  const reco::SuperClusterRef& sc,
164  const CaloSubdetectorGeometry* subdet,
165  const CaloGeometry* caloGeom,
166  const EcalRecHitCollection& hits,
167  //const EcalChannelStatus* chStatus,
168  const EcalSeverityLevelAlgo* sevLevel,
169  bool barrel) const {
170  GlobalPoint caloPosition(sc->position().x(), sc->position().y(), sc->position().z());
171  CaloSubdetectorGeometry::DetIdSet chosen = subdet->getCells(caloPosition, extRadius_);
173  double caloeta = caloPosition.eta();
174  double calophi = caloPosition.phi();
175  double r2 = intRadius_ * intRadius_;
176 
177  std::vector<std::pair<DetId, float> >::const_iterator rhIt;
178 
179  for (CaloSubdetectorGeometry::DetIdSet::const_iterator i = chosen.begin(), end = chosen.end(); i != end; ++i) {
180  j = hits.find(*i);
181  if (j != hits.end()) {
182  const GlobalPoint& position = caloGeom->getPosition(*i);
183  double eta = position.eta();
184  double phi = position.phi();
185  double energy = j->energy();
186  double et = energy * position.perp() / position.mag();
187  double phiDiff = reco::deltaPhi(phi, calophi);
188 
189  //check if we are supposed to veto clustered and then do so
190  if (vetoClustered_) {
191  //Loop over basic clusters:
192  bool isClustered = false;
193  for (reco::CaloCluster_iterator bcIt = sc->clustersBegin(); bcIt != sc->clustersEnd(); ++bcIt) {
194  for (rhIt = (*bcIt)->hitsAndFractions().begin(); rhIt != (*bcIt)->hitsAndFractions().end(); ++rhIt) {
195  if (rhIt->first == *i)
196  isClustered = true;
197  if (isClustered)
198  break;
199  }
200  if (isClustered)
201  break;
202  } //end loop over basic clusters
203 
204  if (isClustered)
205  continue;
206  } //end if removeClustered
207 
208  std::vector<int>::const_iterator sit;
209  int severityFlag = sevLevel->severityLevel(j->detid(), hits);
210  if (barrel) {
211  sit = std::find(severitiesexclEB_.begin(), severitiesexclEB_.end(), severityFlag);
212  if (sit != severitiesexclEB_.end())
213  continue;
214  } else {
215  sit = std::find(severitiesexclEE_.begin(), severitiesexclEE_.end(), severityFlag);
216  if (sit != severitiesexclEE_.end())
217  continue;
218  }
219 
220  if (barrel) {
221  // new rechit flag checks
222  if (!j->checkFlag(EcalRecHit::kGood)) {
223  if (j->checkFlags(flagsexclEB_)) {
224  continue;
225  }
226  }
227  } else {
228  // new rechit flag checks
229  if (!j->checkFlag(EcalRecHit::kGood)) {
230  if (j->checkFlags(flagsexclEE_)) {
231  continue;
232  }
233  }
234  }
235 
236  if (et > etMin_ && energy > energyMin_ //Changed to fabs - then changed back to energy
237  && fabs(eta - caloeta) > intStrip_ && (eta - caloeta) * (eta - caloeta) + phiDiff * phiDiff > r2) {
239  }
240  }
241  }
242 }
egammaisolation::EgammaRecHitExtractor::tryBoth_
bool tryBoth_
Definition: EgammaRecHitExtractor.h:78
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
EcalSeverityLevelAlgo
Definition: EcalSeverityLevelAlgo.h:33
egammaisolation::EgammaRecHitExtractor::extRadius_
double extRadius_
Definition: EgammaRecHitExtractor.h:70
electrons_cff.bool
bool
Definition: electrons_cff.py:393
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
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
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
BasicCluster.h
CaloGeometryRecord
Definition: CaloGeometryRecord.h:30
egammaisolation::EgammaRecHitExtractor::endcapEcalHitsTag_
edm::InputTag endcapEcalHitsTag_
Definition: EgammaRecHitExtractor.h:74
edm
HLT enums.
Definition: AlignableModifier.h:19
egammaisolation::EgammaRecHitExtractor::severitiesexclEB_
std::vector< int > severitiesexclEB_
Definition: EgammaRecHitExtractor.h:88
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:89353
CaloGeometry::getSubdetectorGeometry
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:34
edm::PtrVectorItr
Definition: PtrVector.h:51
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.h:48
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:103
egammaisolation::EgammaRecHitExtractor::intRadius_
double intRadius_
Definition: EgammaRecHitExtractor.h:71
edm::Handle
Definition: AssociativeIterator.h:50
RecoCandidate.h
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
EcalBarrel
Definition: EcalSubdetector.h:10
BasicClusterFwd.h
edm::Ref< SuperClusterCollection >
funct::sin
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
egammaisolation::EgammaRecHitExtractor::fakeNegativeDeposit_
bool fakeNegativeDeposit_
Definition: EgammaRecHitExtractor.h:77
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
edm::EventSetup::get
T get() const
Definition: EventSetup.h:80
reco::isodeposit
Definition: IsoDeposit.h:31
PVValHelper::eta
Definition: PVValidationHelpers.h:69
egammaisolation::EgammaRecHitExtractor::vetoClustered_
bool vetoClustered_
Definition: EgammaRecHitExtractor.h:80
mps_fire.end
end
Definition: mps_fire.py:242
edm::ESHandle< CaloGeometry >
EcalSeverityLevelAlgoRcd
Definition: EcalSeverityLevelAlgoRcd.h:12
CaloClusterFwd.h
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.h:90
CaloGeometryRecord.h
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
EcalSubdetector.h
EcalEndcap
Definition: EcalSubdetector.h:10
TrackerDigiGeometryRecord.h
CaloSubdetectorGeometry.h
egammaisolation::EgammaRecHitExtractor::useEt_
bool useEt_
Definition: EgammaRecHitExtractor.h:79
edm::ParameterSet
Definition: ParameterSet.h:47
math::XYZPoint
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
diffTwoXMLs.r2
r2
Definition: diffTwoXMLs.py:73
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.h:72
edm::EventSetup
Definition: EventSetup.h:57
egammaisolation::EgammaRecHitExtractor::energyMin_
double energyMin_
Definition: EgammaRecHitExtractor.h:69
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:162
egammaisolation::EgammaRecHitExtractor::endcapEcalHitsToken_
edm::EDGetTokenT< EcalRecHitCollection > endcapEcalHitsToken_
Definition: EgammaRecHitExtractor.h:76
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.h:75
DetId.h
reco::isodeposit::Direction
Definition: IsoDepositDirection.h:19
Exception
Definition: hltDiff.cc:246
EgammaRecHitExtractor.h
GlobalVector.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.h:89
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
egammaisolation::EgammaRecHitExtractor::sameTag_
bool sameTag_
Definition: EgammaRecHitExtractor.h:81
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
JetChargeProducer_cfi.exp
exp
Definition: JetChargeProducer_cfi.py:6
egammaisolation::EgammaRecHitExtractor::etMin_
double etMin_
Definition: EgammaRecHitExtractor.h:68
edm::Event
Definition: Event.h:73
GlobalPoint.h
edm::ConsumesCollector
Definition: ConsumesCollector.h:45
egammaisolation::EgammaRecHitExtractor::barrelEcalHitsTag_
edm::InputTag barrelEcalHitsTag_
Definition: EgammaRecHitExtractor.h:73
reco::IsoDeposit::setVeto
void setVeto(const Veto &aVeto)
Set veto.
Definition: IsoDeposit.h:82
CaloCluster.h
egammaisolation::EgammaRecHitExtractor::flagsexclEE_
std::vector< int > flagsexclEE_
Definition: EgammaRecHitExtractor.h:91
metname
const std::string metname
Definition: MuonSeedOrcaPatternRecognition.cc:40