CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
33 
35 
37 
38 using namespace std;
39 using namespace egammaisolation;
40 using namespace reco::isodeposit;
41 
42 EgammaRecHitExtractor::EgammaRecHitExtractor(const edm::ParameterSet& par, edm::ConsumesCollector & iC) :
43  etMin_(par.getParameter<double>("etMin")),
44  energyMin_(par.getParameter<double>("energyMin")),
45  extRadius_(par.getParameter<double>("extRadius")),
46  intRadius_(par.getParameter<double>("intRadius")),
47  intStrip_(par.getParameter<double>("intStrip")),
48  barrelEcalHitsTag_(par.getParameter<edm::InputTag>("barrelEcalHits")),
49  endcapEcalHitsTag_(par.getParameter<edm::InputTag>("endcapEcalHits")),
50  barrelEcalHitsToken_(iC.consumes<EcalRecHitCollection>(barrelEcalHitsTag_)),
51  endcapEcalHitsToken_(iC.consumes<EcalRecHitCollection>(endcapEcalHitsTag_)),
52  fakeNegativeDeposit_(par.getParameter<bool>("subtractSuperClusterEnergy")),
53  tryBoth_(par.getParameter<bool>("tryBoth")),
54  vetoClustered_(par.getParameter<bool>("vetoClustered")),
55  sameTag_(false)
56  //severityLevelCut_(par.getParameter<int>("severityLevelCut"))
57  //severityRecHitThreshold_(par.getParameter<double>("severityRecHitThreshold")),
58  //spIdString_(par.getParameter<std::string>("spikeIdString")),
59  //spIdThreshold_(par.getParameter<double>("spikeIdThreshold")),
60 {
61 
62  const std::vector<std::string> flagnamesEB =
63  par.getParameter<std::vector<std::string> >("RecHitFlagToBeExcludedEB");
64 
65  const std::vector<std::string> flagnamesEE =
66  par.getParameter<std::vector<std::string> >("RecHitFlagToBeExcludedEE");
67 
69  StringToEnumValue<EcalRecHit::Flags>(flagnamesEB);
70 
72  StringToEnumValue<EcalRecHit::Flags>(flagnamesEE);
73 
74  const std::vector<std::string> severitynamesEB =
75  par.getParameter<std::vector<std::string> >("RecHitSeverityToBeExcludedEB");
76 
78  StringToEnumValue<EcalSeverityLevel::SeverityLevel>(severitynamesEB);
79 
80  const std::vector<std::string> severitynamesEE =
81  par.getParameter<std::vector<std::string> >("RecHitSeverityToBeExcludedEE");
82 
84  StringToEnumValue<EcalSeverityLevel::SeverityLevel>(severitynamesEE);
85 
86  if ((intRadius_ != 0.0) && (fakeNegativeDeposit_)) {
87  throw cms::Exception("Configuration Error") << "EgammaRecHitExtractor: " <<
88  "If you use 'subtractSuperClusterEnergy', you *must* set 'intRadius' to ZERO; it does not make sense, otherwise.";
89  }
90  std::string isoVariable = par.getParameter<std::string>("isolationVariable");
91  if (isoVariable == "et") {
92  useEt_ = true;
93  } else if (isoVariable == "energy") {
94  useEt_ = false;
95  } else {
96  throw cms::Exception("Configuration Error") << "EgammaRecHitExtractor: isolationVariable '" << isoVariable << "' not known. "
97  << " Supported values are 'et', 'energy'. ";
98  }
100  sameTag_ = true;
101  if (tryBoth_) {
102  edm::LogWarning("EgammaRecHitExtractor") << "If you have configured 'barrelRecHits' == 'endcapRecHits', so I'm switching 'tryBoth' to FALSE.";
103  tryBoth_ = false;
104  }
105  }
106 }
107 
109 {}
110 
112  const edm::EventSetup & iSetup, const reco::Candidate &emObject ) const {
114  iSetup.get<CaloGeometryRecord>().get(pG);
115 
116  //Get the channel status from the db
117  //edm::ESHandle<EcalChannelStatus> chStatus;
118  //iSetup.get<EcalChannelStatusRcd>().get(chStatus);
119 
121  iSetup.get<EcalSeverityLevelAlgoRcd>().get(sevlv);
122  const EcalSeverityLevelAlgo* sevLevel = sevlv.product();
123 
124  const CaloGeometry* caloGeom = pG.product();
127 
128  static std::string metname = "EgammaIsolationAlgos|EgammaRecHitExtractor";
129 
130  std::auto_ptr<const CaloRecHitMetaCollectionV> barrelRecHits(0), endcapRecHits(0);
131 
132  //Get barrel ECAL RecHits
133  edm::Handle<EcalRecHitCollection> barrelEcalRecHitsH;
134  iEvent.getByToken(barrelEcalHitsToken_, barrelEcalRecHitsH);
135 
136  //Get endcap ECAL RecHits
137  edm::Handle<EcalRecHitCollection> endcapEcalRecHitsH;
138  iEvent.getByToken(endcapEcalHitsToken_, endcapEcalRecHitsH);
139 
140  //define isodeposit starting from candidate
142  math::XYZPoint caloPosition = sc->position();
143 
144  Direction candDir(caloPosition.eta(), caloPosition.phi());
145  reco::IsoDeposit deposit( candDir );
146  deposit.setVeto( reco::IsoDeposit::Veto(candDir, intRadius_) );
147  double sinTheta = sin(2*atan(exp(-sc->eta())));
148  deposit.addCandEnergy(sc->energy() * (useEt_ ? sinTheta : 1.0)) ;
149 
150  // subtract supercluster if desired
151  double fakeEnergy = -sc->rawEnergy();
152  if (fakeNegativeDeposit_) {
153  deposit.addDeposit(candDir, fakeEnergy * (useEt_ ? sinTheta : 1.0)); // not exactly clean...
154  }
155 
156  // fill rechits
157  bool inBarrel = sameTag_ || ( abs(sc->eta()) < 1.479 ); //check for barrel. If only one collection is used, use barrel
158  if (inBarrel || tryBoth_) {
159  collect(deposit, sc, barrelgeom, caloGeom, *barrelEcalRecHitsH, sevLevel, true);
160  }
161 
162  if ((!inBarrel) || tryBoth_) {
163  collect(deposit, sc, endcapgeom, caloGeom, *endcapEcalRecHitsH, sevLevel, false);
164  }
165 
166  return deposit;
167 }
168 
170  const reco::SuperClusterRef& sc, const CaloSubdetectorGeometry* subdet,
171  const CaloGeometry* caloGeom,
172  const EcalRecHitCollection &hits,
173  //const EcalChannelStatus* chStatus,
174  const EcalSeverityLevelAlgo* sevLevel,
175  bool barrel) const {
176 
177  GlobalPoint caloPosition(sc->position().x(), sc->position().y() , sc->position().z());
178  CaloSubdetectorGeometry::DetIdSet chosen = subdet->getCells(caloPosition,extRadius_);
180  double caloeta=caloPosition.eta();
181  double calophi=caloPosition.phi();
182  double r2 = intRadius_*intRadius_;
183 
184  std::vector< std::pair<DetId, float> >::const_iterator rhIt;
185 
186 
187  for (CaloSubdetectorGeometry::DetIdSet::const_iterator i = chosen.begin(), end = chosen.end() ; i != end; ++i) {
188  j = hits.find(*i);
189  if (j != hits.end()) {
190  const GlobalPoint & position = caloGeom->getPosition(*i);
191  double eta = position.eta();
192  double phi = position.phi();
193  double energy = j->energy();
194  double et = energy*position.perp()/position.mag();
195  double phiDiff= reco::deltaPhi(phi,calophi);
196 
197  //check if we are supposed to veto clustered and then do so
198  if(vetoClustered_) {
199 
200  //Loop over basic clusters:
201  bool isClustered = false;
202  for( reco::CaloCluster_iterator bcIt = sc->clustersBegin();bcIt != sc->clustersEnd(); ++bcIt) {
203  for(rhIt = (*bcIt)->hitsAndFractions().begin();rhIt != (*bcIt)->hitsAndFractions().end(); ++rhIt) {
204  if( rhIt->first == *i ) isClustered = true;
205  if( isClustered ) break;
206  }
207  if( isClustered ) break;
208  } //end loop over basic clusters
209 
210  if(isClustered) continue;
211  } //end if removeClustered
212 
213  std::vector<int>::const_iterator sit;
214  int severityFlag = sevLevel->severityLevel(j->detid(), hits);
215  if (barrel) {
216  sit = std::find(severitiesexclEB_.begin(), severitiesexclEB_.end(), severityFlag);
217  if (sit != severitiesexclEB_.end())
218  continue;
219  } else {
220  sit = std::find(severitiesexclEE_.begin(), severitiesexclEE_.end(), severityFlag);
221  if (sit != severitiesexclEE_.end())
222  continue;
223  }
224 
225  std::vector<int>::const_iterator vit;
226  if (barrel) {
227  // new rechit flag checks
228  //vit = std::find(flagsexclEB_.begin(), flagsexclEB_.end(), ((EcalRecHit*)(&*j))->recoFlag());
229  //if (vit != flagsexclEB_.end())
230  // continue;
231  if (!((EcalRecHit*)(&*j))->checkFlag(EcalRecHit::kGood)) {
232  if (((EcalRecHit*)(&*j))->checkFlags(flagsexclEB_)) {
233  continue;
234  }
235  }
236  } else {
237  // new rechit flag checks
238  //vit = std::find(flagsexclEE_.begin(), flagsexclEE_.end(), ((EcalRecHit*)(&*j))->recoFlag());
239  //if (vit != flagsexclEE_.end())
240  // continue;
241  if (!((EcalRecHit*)(&*j))->checkFlag(EcalRecHit::kGood)) {
242  if (((EcalRecHit*)(&*j))->checkFlags(flagsexclEE_)) {
243  continue;
244  }
245  }
246  }
247 
248  if(et > etMin_
249  && energy > energyMin_ //Changed to fabs - then changed back to energy
250  && fabs(eta-caloeta) > intStrip_
251  && (eta-caloeta)*(eta-caloeta) + phiDiff*phiDiff >r2 ) {
252 
253  deposit.addDeposit( Direction(eta, phi), (useEt_ ? et : energy));
254  }
255  }
256  }
257 }
258 
259 
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:43
int i
Definition: DBlmapReader.cc:9
T perp() const
Definition: PV3DBase.h:72
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
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
T eta() const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
std::string encode() const
Definition: InputTag.cc:164
void collect(reco::IsoDeposit &deposit, const reco::SuperClusterRef &sc, const CaloSubdetectorGeometry *subdet, const CaloGeometry *caloGeom, const EcalRecHitCollection &hits, const EcalSeverityLevelAlgo *sevLevel, bool barrel) const
static int position[TOTALCHAMBERS][3]
Definition: ReadPGInfo.cc:509
void addDeposit(double dr, double deposit)
Add deposit (ie. transverse energy or pT)
Definition: IsoDeposit.cc:23
int iEvent
Definition: GenABIO.cc:243
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
int j
Definition: DBlmapReader.cc:9
const GlobalPoint & getPosition(const DetId &id) const
Get the position of a given detector id.
Definition: CaloGeometry.cc:68
#define end
Definition: vmac.h:37
const_iterator end() const
double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:12
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
edm::EDGetTokenT< EcalRecHitCollection > endcapEcalHitsToken_
T eta() const
Definition: PV3DBase.h:76
iterator find(key_type k)
edm::EDGetTokenT< EcalRecHitCollection > barrelEcalHitsToken_
T get() const
get a component
Definition: Candidate.h:219
virtual reco::IsoDeposit deposit(const edm::Event &ev, const edm::EventSetup &evSetup, const reco::Track &track) const
volatile std::atomic< bool > shutdown_flag false
EcalSeverityLevel::SeverityLevel severityLevel(const DetId &id, const EcalRecHitCollection &rhs) const
Evaluate status from id.
Definition: DDAxes.h:10