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