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 
61  const std::vector<std::string> flagnamesEB =
62  par.getParameter<std::vector<std::string> >("RecHitFlagToBeExcludedEB");
63 
64  const std::vector<std::string> flagnamesEE =
65  par.getParameter<std::vector<std::string> >("RecHitFlagToBeExcludedEE");
66 
68  StringToEnumValue<EcalRecHit::Flags>(flagnamesEB);
69 
71  StringToEnumValue<EcalRecHit::Flags>(flagnamesEE);
72 
73  const std::vector<std::string> severitynamesEB =
74  par.getParameter<std::vector<std::string> >("RecHitSeverityToBeExcludedEB");
75 
77  StringToEnumValue<EcalSeverityLevel::SeverityLevel>(severitynamesEB);
78 
79  const std::vector<std::string> severitynamesEE =
80  par.getParameter<std::vector<std::string> >("RecHitSeverityToBeExcludedEE");
81 
83  StringToEnumValue<EcalSeverityLevel::SeverityLevel>(severitynamesEE);
84 
85  if ((intRadius_ != 0.0) && (fakeNegativeDeposit_)) {
86  throw cms::Exception("Configuration Error") << "EgammaRecHitExtractor: " <<
87  "If you use 'subtractSuperClusterEnergy', you *must* set 'intRadius' to ZERO; it does not make sense, otherwise.";
88  }
89  std::string isoVariable = par.getParameter<std::string>("isolationVariable");
90  if (isoVariable == "et") {
91  useEt_ = true;
92  } else if (isoVariable == "energy") {
93  useEt_ = false;
94  } else {
95  throw cms::Exception("Configuration Error") << "EgammaRecHitExtractor: isolationVariable '" << isoVariable << "' not known. "
96  << " Supported values are 'et', 'energy'. ";
97  }
99  sameTag_ = true;
100  if (tryBoth_) {
101  edm::LogWarning("EgammaRecHitExtractor") << "If you have configured 'barrelRecHits' == 'endcapRecHits', so I'm switching 'tryBoth' to FALSE.";
102  tryBoth_ = false;
103  }
104  }
105 }
106 
108 {}
109 
111  const edm::EventSetup & iSetup, const reco::Candidate &emObject ) const {
113  iSetup.get<CaloGeometryRecord>().get(pG);
114 
115  //Get the channel status from the db
116  //edm::ESHandle<EcalChannelStatus> chStatus;
117  //iSetup.get<EcalChannelStatusRcd>().get(chStatus);
118 
120  iSetup.get<EcalSeverityLevelAlgoRcd>().get(sevlv);
121  const EcalSeverityLevelAlgo* sevLevel = sevlv.product();
122 
123  const CaloGeometry* caloGeom = pG.product();
126 
127  static const std::string metname = "EgammaIsolationAlgos|EgammaRecHitExtractor";
128 
129  //Get barrel ECAL RecHits
130  edm::Handle<EcalRecHitCollection> barrelEcalRecHitsH;
131  iEvent.getByToken(barrelEcalHitsToken_, barrelEcalRecHitsH);
132 
133  //Get endcap ECAL RecHits
134  edm::Handle<EcalRecHitCollection> endcapEcalRecHitsH;
135  iEvent.getByToken(endcapEcalHitsToken_, endcapEcalRecHitsH);
136 
137  //define isodeposit starting from candidate
139  math::XYZPoint caloPosition = sc->position();
140 
141  Direction candDir(caloPosition.eta(), caloPosition.phi());
142  reco::IsoDeposit deposit( candDir );
143  deposit.setVeto( reco::IsoDeposit::Veto(candDir, intRadius_) );
144  double sinTheta = sin(2*atan(exp(-sc->eta())));
145  deposit.addCandEnergy(sc->energy() * (useEt_ ? sinTheta : 1.0)) ;
146 
147  // subtract supercluster if desired
148  double fakeEnergy = -sc->rawEnergy();
149  if (fakeNegativeDeposit_) {
150  deposit.addDeposit(candDir, fakeEnergy * (useEt_ ? sinTheta : 1.0)); // not exactly clean...
151  }
152 
153  // fill rechits
154  bool inBarrel = sameTag_ || ( abs(sc->eta()) < 1.479 ); //check for barrel. If only one collection is used, use barrel
155  if (inBarrel || tryBoth_) {
156  collect(deposit, sc, barrelgeom, caloGeom, *barrelEcalRecHitsH, sevLevel, true);
157  }
158 
159  if ((!inBarrel) || tryBoth_) {
160  collect(deposit, sc, endcapgeom, caloGeom, *endcapEcalRecHitsH, sevLevel, false);
161  }
162 
163  return deposit;
164 }
165 
167  const reco::SuperClusterRef& sc,
168  const CaloSubdetectorGeometry* subdet,
169  const CaloGeometry* caloGeom,
170  const EcalRecHitCollection &hits,
171  //const EcalChannelStatus* chStatus,
172  const EcalSeverityLevelAlgo* sevLevel,
173  bool barrel) const {
174 
175  GlobalPoint caloPosition(sc->position().x(), sc->position().y() , sc->position().z());
176  CaloSubdetectorGeometry::DetIdSet chosen = subdet->getCells(caloPosition,extRadius_);
178  double caloeta=caloPosition.eta();
179  double calophi=caloPosition.phi();
180  double r2 = intRadius_*intRadius_;
181 
182  std::vector< std::pair<DetId, float> >::const_iterator rhIt;
183 
184 
185  for (CaloSubdetectorGeometry::DetIdSet::const_iterator i = chosen.begin(), end = chosen.end() ; i != end; ++i) {
186  j = hits.find(*i);
187  if (j != hits.end()) {
188  const GlobalPoint & position = caloGeom->getPosition(*i);
189  double eta = position.eta();
190  double phi = position.phi();
191  double energy = j->energy();
192  double et = energy*position.perp()/position.mag();
193  double phiDiff= reco::deltaPhi(phi,calophi);
194 
195  //check if we are supposed to veto clustered and then do so
196  if(vetoClustered_) {
197 
198  //Loop over basic clusters:
199  bool isClustered = false;
200  for( reco::CaloCluster_iterator bcIt = sc->clustersBegin();bcIt != sc->clustersEnd(); ++bcIt) {
201  for(rhIt = (*bcIt)->hitsAndFractions().begin();rhIt != (*bcIt)->hitsAndFractions().end(); ++rhIt) {
202  if( rhIt->first == *i ) isClustered = true;
203  if( isClustered ) break;
204  }
205  if( isClustered ) break;
206  } //end loop over basic clusters
207 
208  if(isClustered) continue;
209  } //end if removeClustered
210 
211  std::vector<int>::const_iterator sit;
212  int severityFlag = sevLevel->severityLevel(j->detid(), hits);
213  if (barrel) {
214  sit = std::find(severitiesexclEB_.begin(), severitiesexclEB_.end(), severityFlag);
215  if (sit != severitiesexclEB_.end())
216  continue;
217  } else {
218  sit = std::find(severitiesexclEE_.begin(), severitiesexclEE_.end(), severityFlag);
219  if (sit != severitiesexclEE_.end())
220  continue;
221  }
222 
223  std::vector<int>::const_iterator vit;
224  if (barrel) {
225  // new rechit flag checks
226  //vit = std::find(flagsexclEB_.begin(), flagsexclEB_.end(), j->recoFlag());
227  //if (vit != flagsexclEB_.end())
228  // continue;
229  if (!j->checkFlag(EcalRecHit::kGood)) {
230  if (j->checkFlags(flagsexclEB_)) {
231  continue;
232  }
233  }
234  } else {
235  // new rechit flag checks
236  //vit = std::find(flagsexclEE_.begin(), flagsexclEE_.end(), j->recoFlag());
237  //if (vit != flagsexclEE_.end())
238  // continue;
239  if (!j->checkFlag(EcalRecHit::kGood)) {
240  if (j->checkFlags(flagsexclEE_)) {
241  continue;
242  }
243  }
244  }
245 
246  if(et > etMin_
247  && energy > energyMin_ //Changed to fabs - then changed back to energy
248  && fabs(eta-caloeta) > intStrip_
249  && (eta-caloeta)*(eta-caloeta) + phiDiff*phiDiff >r2 ) {
250 
251  deposit.addDeposit( Direction(eta, phi), (useEt_ ? et : energy));
252  }
253  }
254  }
255 }
256 
257 
T getParameter(std::string const &) const
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:44
reco::IsoDeposit deposit(const edm::Event &ev, const edm::EventSetup &evSetup, const reco::Track &track) const override
T perp() const
Definition: PV3DBase.h:72
EcalSeverityLevel::SeverityLevel severityLevel(const DetId &id) const
Evaluate status from id use channelStatus from DB.
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
const std::string metname
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
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:20
std::string encode() const
Definition: InputTag.cc:166
void collect(reco::IsoDeposit &deposit, const reco::SuperClusterRef &sc, const CaloSubdetectorGeometry *subdet, const CaloGeometry *caloGeom, const EcalRecHitCollection &hits, const EcalSeverityLevelAlgo *sevLevel, bool barrel) const
void addDeposit(double dr, double deposit)
Add deposit (ie. transverse energy or pT)
Definition: IsoDeposit.cc:23
int iEvent
Definition: GenABIO.cc:230
virtual DetIdSet getCells(const GlobalPoint &r, double dR) const
Get a list of all cells within a dR of the given cell.
T mag() const
Definition: PV3DBase.h:67
GlobalPoint getPosition(const DetId &id) const
Get the position of a given detector id.
Definition: CaloGeometry.cc:69
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define end
Definition: vmac.h:39
const_iterator end() const
double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:22
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
const T & get() const
Definition: EventSetup.h:58
et
define resolution functions of each parameter
edm::EDGetTokenT< EcalRecHitCollection > endcapEcalHitsToken_
T eta() const
Definition: PV3DBase.h:76
iterator find(key_type k)
HLT enums.
static int position[264][3]
Definition: ReadPGInfo.cc:509
edm::EDGetTokenT< EcalRecHitCollection > barrelEcalHitsToken_
T get() const
get a component
Definition: Candidate.h:217
T const * product() const
Definition: ESHandle.h:86