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 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, const CaloSubdetectorGeometry* subdet,
168  const CaloGeometry* caloGeom,
169  const EcalRecHitCollection &hits,
170  //const EcalChannelStatus* chStatus,
171  const EcalSeverityLevelAlgo* sevLevel,
172  bool barrel) const {
173 
174  GlobalPoint caloPosition(sc->position().x(), sc->position().y() , sc->position().z());
175  CaloSubdetectorGeometry::DetIdSet chosen = subdet->getCells(caloPosition,extRadius_);
177  double caloeta=caloPosition.eta();
178  double calophi=caloPosition.phi();
179  double r2 = intRadius_*intRadius_;
180 
181  std::vector< std::pair<DetId, float> >::const_iterator rhIt;
182 
183 
184  for (CaloSubdetectorGeometry::DetIdSet::const_iterator i = chosen.begin(), end = chosen.end() ; i != end; ++i) {
185  j = hits.find(*i);
186  if (j != hits.end()) {
187  const GlobalPoint & position = caloGeom->getPosition(*i);
188  double eta = position.eta();
189  double phi = position.phi();
190  double energy = j->energy();
191  double et = energy*position.perp()/position.mag();
192  double phiDiff= reco::deltaPhi(phi,calophi);
193 
194  //check if we are supposed to veto clustered and then do so
195  if(vetoClustered_) {
196 
197  //Loop over basic clusters:
198  bool isClustered = false;
199  for( reco::CaloCluster_iterator bcIt = sc->clustersBegin();bcIt != sc->clustersEnd(); ++bcIt) {
200  for(rhIt = (*bcIt)->hitsAndFractions().begin();rhIt != (*bcIt)->hitsAndFractions().end(); ++rhIt) {
201  if( rhIt->first == *i ) isClustered = true;
202  if( isClustered ) break;
203  }
204  if( isClustered ) break;
205  } //end loop over basic clusters
206 
207  if(isClustered) continue;
208  } //end if removeClustered
209 
210  std::vector<int>::const_iterator sit;
211  int severityFlag = sevLevel->severityLevel(j->detid(), hits);
212  if (barrel) {
213  sit = std::find(severitiesexclEB_.begin(), severitiesexclEB_.end(), severityFlag);
214  if (sit != severitiesexclEB_.end())
215  continue;
216  } else {
217  sit = std::find(severitiesexclEE_.begin(), severitiesexclEE_.end(), severityFlag);
218  if (sit != severitiesexclEE_.end())
219  continue;
220  }
221 
222  std::vector<int>::const_iterator vit;
223  if (barrel) {
224  // new rechit flag checks
225  //vit = std::find(flagsexclEB_.begin(), flagsexclEB_.end(), ((EcalRecHit*)(&*j))->recoFlag());
226  //if (vit != flagsexclEB_.end())
227  // continue;
228  if (!((EcalRecHit*)(&*j))->checkFlag(EcalRecHit::kGood)) {
229  if (((EcalRecHit*)(&*j))->checkFlags(flagsexclEB_)) {
230  continue;
231  }
232  }
233  } else {
234  // new rechit flag checks
235  //vit = std::find(flagsexclEE_.begin(), flagsexclEE_.end(), ((EcalRecHit*)(&*j))->recoFlag());
236  //if (vit != flagsexclEE_.end())
237  // continue;
238  if (!((EcalRecHit*)(&*j))->checkFlag(EcalRecHit::kGood)) {
239  if (((EcalRecHit*)(&*j))->checkFlags(flagsexclEE_)) {
240  continue;
241  }
242  }
243  }
244 
245  if(et > etMin_
246  && energy > energyMin_ //Changed to fabs - then changed back to energy
247  && fabs(eta-caloeta) > intStrip_
248  && (eta-caloeta)*(eta-caloeta) + phiDiff*phiDiff >r2 ) {
249 
250  deposit.addDeposit( Direction(eta, phi), (useEt_ ? et : energy));
251  }
252  }
253  }
254 }
255 
256 
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:45
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:508
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
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const GlobalPoint & getPosition(const DetId &id) const
Get the position of a given detector id.
Definition: CaloGeometry.cc:70
#define end
Definition: vmac.h:37
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:55
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