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