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) :
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  fakeNegativeDeposit_(par.getParameter<bool>("subtractSuperClusterEnergy")),
51  tryBoth_(par.getParameter<bool>("tryBoth")),
52  vetoClustered_(par.getParameter<bool>("vetoClustered")),
53  sameTag_(false),
54  severityLevelCut_(par.getParameter<int>("severityLevelCut"))
55  //severityRecHitThreshold_(par.getParameter<double>("severityRecHitThreshold")),
56  //spIdString_(par.getParameter<std::string>("spikeIdString")),
57  //spIdThreshold_(par.getParameter<double>("spikeIdThreshold")),
58 
59 {
60  const std::vector<std::string> flagnames =
61  par.getParameter<std::vector<std::string> >("recHitFlagsToBeExcluded");
62 
63  v_chstatus_= StringToEnumValue<EcalRecHit::Flags>(flagnames);
64 
65 // if ( !spIdString_.compare("kE1OverE9") ) spId_ = EcalSeverityLevelAlgo::kE1OverE9;
66 // else if( !spIdString_.compare("kSwissCross") ) spId_ = EcalSeverityLevelAlgo::kSwissCross;
67 // else if( !spIdString_.compare("kSwissCrossBordersIncluded") ) spId_ = EcalSeverityLevelAlgo::kSwissCrossBordersIncluded;
68 // else spId_ = EcalSeverityLevelAlgo::kSwissCross;
69 
70  if ((intRadius_ != 0.0) && (fakeNegativeDeposit_)) {
71  throw cms::Exception("Configuration Error") << "EgammaRecHitExtractor: " <<
72  "If you use 'subtractSuperClusterEnergy', you *must* set 'intRadius' to ZERO; it does not make sense, otherwise.";
73  }
74  std::string isoVariable = par.getParameter<std::string>("isolationVariable");
75  if (isoVariable == "et") {
76  useEt_ = true;
77  } else if (isoVariable == "energy") {
78  useEt_ = false;
79  } else {
80  throw cms::Exception("Configuration Error") << "EgammaRecHitExtractor: isolationVariable '" << isoVariable << "' not known. "
81  << " Supported values are 'et', 'energy'. ";
82  }
84  sameTag_ = true;
85  if (tryBoth_) {
86  edm::LogWarning("EgammaRecHitExtractor") << "If you have configured 'barrelRecHits' == 'endcapRecHits', so I'm switching 'tryBoth' to FALSE.";
87  tryBoth_ = false;
88  }
89  }
90 
91 }
92 
94 
96  const edm::EventSetup & iSetup, const reco::Candidate &emObject ) const {
98  iSetup.get<CaloGeometryRecord>().get(pG);
99 
100  //Get the channel status from the db
102  iSetup.get<EcalChannelStatusRcd>().get(chStatus);
103 
105  iSetup.get<EcalSeverityLevelAlgoRcd>().get(sevlv);
106 
107  const CaloGeometry* caloGeom = pG.product();
110 
111  static std::string metname = "EgammaIsolationAlgos|EgammaRecHitExtractor";
112 
113  std::auto_ptr<const CaloRecHitMetaCollectionV> barrelRecHits(0), endcapRecHits(0);
114 
115  //Get barrel ECAL RecHits
116  edm::Handle<EcalRecHitCollection> barrelEcalRecHitsH;
117  iEvent.getByLabel(barrelEcalHitsTag_, barrelEcalRecHitsH);
118 
119  //Get endcap ECAL RecHits
120  edm::Handle<EcalRecHitCollection> endcapEcalRecHitsH;
121  iEvent.getByLabel(endcapEcalHitsTag_, endcapEcalRecHitsH);
122 
123  //define isodeposit starting from candidate
125  math::XYZPoint caloPosition = sc->position();
126 
127  Direction candDir(caloPosition.eta(), caloPosition.phi());
128  reco::IsoDeposit deposit( candDir );
129  deposit.setVeto( reco::IsoDeposit::Veto(candDir, intRadius_) );
130  double sinTheta = sin(2*atan(exp(-sc->eta())));
131  deposit.addCandEnergy(sc->energy() * (useEt_ ? sinTheta : 1.0)) ;
132 
133  // subtract supercluster if desired
134  double fakeEnergy = -sc->rawEnergy();
135  if (fakeNegativeDeposit_) {
136  deposit.addDeposit(candDir, fakeEnergy * (useEt_ ? sinTheta : 1.0)); // not exactly clean...
137  }
138 
139  // fill rechits
140  bool inBarrel = sameTag_ || ( abs(sc->eta()) < 1.479 ); //check for barrel. If only one collection is used, use barrel
141  if (inBarrel || tryBoth_) {
142  collect(deposit, sc, barrelgeom, caloGeom, *barrelEcalRecHitsH, chStatus.product(), sevlv.product(), true);
143  }
144  if ((!inBarrel) || tryBoth_) {
145  collect(deposit, sc, endcapgeom, caloGeom, *endcapEcalRecHitsH, chStatus.product(), sevlv.product(), false);
146  }
147 
148  return deposit;
149 }
150 
152  const reco::SuperClusterRef& sc, const CaloSubdetectorGeometry* subdet,
153  const CaloGeometry* caloGeom,
154  const EcalRecHitCollection &hits,
155  const EcalChannelStatus* chStatus,
156  const EcalSeverityLevelAlgo* sevLevel,
157  bool barrel) const
158 {
159 
160  GlobalPoint caloPosition(sc->position().x(), sc->position().y() , sc->position().z());
161  CaloSubdetectorGeometry::DetIdSet chosen = subdet->getCells(caloPosition,extRadius_);
163  double caloeta=caloPosition.eta();
164  double calophi=caloPosition.phi();
165  double r2 = intRadius_*intRadius_;
166 
167  std::vector< std::pair<DetId, float> >::const_iterator rhIt;
168 
169 
170  for (CaloSubdetectorGeometry::DetIdSet::const_iterator i = chosen.begin(), end = chosen.end() ; i != end; ++i) {
171  j=hits.find(*i);
172  if(j != hits.end()){
173  const GlobalPoint & position = caloGeom->getPosition(*i);
174  double eta = position.eta();
175  double phi = position.phi();
176  double energy = j->energy();
177  double et = energy*position.perp()/position.mag();
178  double phiDiff= reco::deltaPhi(phi,calophi);
179 
180  //check if we are supposed to veto clustered and then do so
181  if(vetoClustered_) {
182 
183  //Loop over basic clusters:
184  bool isClustered = false;
185  for( reco::CaloCluster_iterator bcIt = sc->clustersBegin();bcIt != sc->clustersEnd(); ++bcIt) {
186  for(rhIt = (*bcIt)->hitsAndFractions().begin();rhIt != (*bcIt)->hitsAndFractions().end(); ++rhIt) {
187  if( rhIt->first == *i ) isClustered = true;
188  if( isClustered ) break;
189  }
190  if( isClustered ) break;
191  } //end loop over basic clusters
192 
193  if(isClustered) continue;
194  } //end if removeClustered
195 
196  //make sure we have a barrel rechit
197  //call the severity level method
198  //passing the EBDetId
199  //the rechit collection in order to calculate the swiss crss
200  //and the EcalChannelRecHitRcd
201  //only consider rechits with ET >
202  //the SpikeId method (currently kE1OverE9 or kSwissCross)
203  //cut value for above
204  //then if the severity level is too high, we continue to the next rechit
205  if(barrel && sevLevel->severityLevel(EBDetId(j->id()), hits) >= severityLevelCut_)
206  continue;
207  // *chStatus,
208  // severityRecHitThreshold_,
209  // spId_,
210  // spIdThreshold_
211  // ) >= severityLevelCut_) continue;
212 
213  //Check based on flags to protect from recovered channels from non-read towers
214  //Assumption is that v_chstatus_ is empty unless doFlagChecks() has been called
215  std::vector<int>::const_iterator vit = std::find( v_chstatus_.begin(), v_chstatus_.end(), ((EcalRecHit*)(&*j))->recoFlag() );
216  if ( vit != v_chstatus_.end() ) continue; // the recHit has to be excluded from the iso sum
217 
218 
219  if(et > etMin_
220  && energy > energyMin_ //Changed to fabs - then changed back to energy
221  && fabs(eta-caloeta) > intStrip_
222  && (eta-caloeta)*(eta-caloeta) + phiDiff*phiDiff >r2 ) {
223 
224  deposit.addDeposit( Direction(eta, phi), (useEt_ ? et : energy) );
225 
226  }
227  }
228  }
229 }
230 
231 
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:71
const std::string metname
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Geom::Phi< T > phi() const
Definition: PV3DBase.h:68
std::vector< EcalRecHit >::const_iterator const_iterator
#define abs(x)
Definition: mlp_lapack.h:159
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:72
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:66
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:38
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
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:13
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
void collect(reco::IsoDeposit &deposit, const reco::SuperClusterRef &sc, const CaloSubdetectorGeometry *subdet, const CaloGeometry *caloGeom, const EcalRecHitCollection &hits, const EcalChannelStatus *chStatus, const EcalSeverityLevelAlgo *sevLevel, bool barrel) const
T eta() const
Definition: PV3DBase.h:75
iterator find(key_type k)
static int position[264][3]
Definition: ReadPGInfo.cc:509
T get() const
get a component
Definition: Candidate.h:216
virtual reco::IsoDeposit deposit(const edm::Event &ev, const edm::EventSetup &evSetup, const reco::Track &track) const
EcalSeverityLevel::SeverityLevel severityLevel(const DetId &id, const EcalRecHitCollection &rhs) const
Evaluate status from id.
Definition: DDAxes.h:10