CMS 3D CMS Logo

CaloExtractorByAssociator.cc
Go to the documentation of this file.
2 
6 
10 
12 
14 
18 
20 
21 using namespace edm;
22 using namespace std;
23 using namespace reco;
24 using namespace muonisolation;
26 
27 namespace {
28  constexpr double dRMax_CandDep = 1.0; //pick up candidate own deposits up to this dR if theDR_Max is smaller
29 }
30 
31 CaloExtractorByAssociator::CaloExtractorByAssociator(const ParameterSet& par, edm::ConsumesCollector&& iC)
32  : theUseRecHitsFlag(par.getParameter<bool>("UseRecHitsFlag")),
33  theDepositLabel(par.getUntrackedParameter<string>("DepositLabel")),
34  theDepositInstanceLabels(par.getParameter<std::vector<std::string> >("DepositInstanceLabels")),
35  thePropagatorName(par.getParameter<std::string>("PropagatorName")),
36  theThreshold_E(par.getParameter<double>("Threshold_E")),
37  theThreshold_H(par.getParameter<double>("Threshold_H")),
38  theThreshold_HO(par.getParameter<double>("Threshold_HO")),
39  theDR_Veto_E(par.getParameter<double>("DR_Veto_E")),
40  theDR_Veto_H(par.getParameter<double>("DR_Veto_H")),
41  theDR_Veto_HO(par.getParameter<double>("DR_Veto_HO")),
42  theCenterConeOnCalIntersection(par.getParameter<bool>("CenterConeOnCalIntersection")),
43  theDR_Max(par.getParameter<double>("DR_Max")),
44  theNoise_EB(par.getParameter<double>("Noise_EB")),
45  theNoise_EE(par.getParameter<double>("Noise_EE")),
46  theNoise_HB(par.getParameter<double>("Noise_HB")),
47  theNoise_HE(par.getParameter<double>("Noise_HE")),
48  theNoise_HO(par.getParameter<double>("Noise_HO")),
49  theNoiseTow_EB(par.getParameter<double>("NoiseTow_EB")),
50  theNoiseTow_EE(par.getParameter<double>("NoiseTow_EE")),
51  theService(nullptr),
52  theAssociator(nullptr),
53  bFieldToken_(iC.esConsumes()),
54  thePrintTimeReport(par.getUntrackedParameter<bool>("PrintTimeReport")) {
55  ParameterSet serviceParameters = par.getParameter<ParameterSet>("ServiceParameters");
56  theService = new MuonServiceProxy(serviceParameters, edm::ConsumesCollector(iC));
57 
58  //theAssociatorParameters = new TrackAssociatorParameters(par.getParameter<edm::ParameterSet>("TrackAssociatorParameters"), iC);
60  theAssociatorParameters->loadParameters(par.getParameter<edm::ParameterSet>("TrackAssociatorParameters"), iC);
62 
63  if (theUseRecHitsFlag) {
64  caloGeomToken_ = iC.esConsumes();
65  }
66 }
67 
71  if (theService)
72  delete theService;
73  if (theAssociator)
74  delete theAssociator;
75 }
76 
79  const TrackCollection& muons) {
80  // LogWarning("CaloExtractorByAssociator")
81  // <<"fillVetos does nothing now: IsoDeposit provides enough functionality\n"
82  // <<"to remove a deposit at/around given (eta, phi)";
83 }
84 
86  const EventSetup& eventSetup,
87  const Track& muon) const {
88  IsoDeposit::Direction muonDir(muon.eta(), muon.phi());
89  IsoDeposit dep(muonDir);
90 
91  // LogWarning("CaloExtractorByAssociator")
92  // <<"single deposit is not an option here\n"
93  // <<"use ::deposits --> extract all and reweight as necessary";
94 
95  return dep;
96 }
97 
99 std::vector<IsoDeposit> CaloExtractorByAssociator::deposits(const Event& event,
100  const EventSetup& eventSetup,
101  const Track& muon) const {
102  theService->update(eventSetup);
104 
107  if (theDepositInstanceLabels.size() != 3) {
108  LogError("MuonIsolation") << "Configuration is inconsistent: Need 3 deposit instance labels";
109  }
110  if (!(theDepositInstanceLabels[0].compare(0, 1, std::string("e")) == 0) ||
111  !(theDepositInstanceLabels[1].compare(0, 1, std::string("h")) == 0) ||
112  !(theDepositInstanceLabels[2].compare(0, 2, std::string("ho")) == 0)) {
113  LogWarning("MuonIsolation")
114  << "Deposit instance labels do not look like (e*, h*, ho*):"
115  << "proceed at your own risk. The extractor interprets lab0=from ecal; lab1=from hcal; lab2=from ho";
116  }
117 
118  typedef IsoDeposit::Veto Veto;
121  IsoDeposit::Direction muonDir(muon.eta(), muon.phi());
122 
123  IsoDeposit depEcal(muonDir);
124  IsoDeposit depHcal(muonDir);
125  IsoDeposit depHOcal(muonDir);
126 
127  auto const& bField = eventSetup.getData(bFieldToken_);
128 
130  FreeTrajectoryState iFTS = tMuon.initialFreeState();
132 
134  depEcal.setVeto(
136  depHcal.setVeto(
138  depHOcal.setVeto(
140 
142  reco::isodeposit::Direction dirTmp = depEcal.veto().vetoDir;
143  double dRtmp = depEcal.veto().dR;
144  depEcal = IsoDeposit(dirTmp);
145  depEcal.setVeto(Veto(dirTmp, dRtmp));
146 
147  dirTmp = depHcal.veto().vetoDir;
148  dRtmp = depHcal.veto().dR;
149  depHcal = IsoDeposit(dirTmp);
150  depHcal.setVeto(Veto(dirTmp, dRtmp));
151 
152  dirTmp = depHOcal.veto().vetoDir;
153  dRtmp = depHOcal.veto().dR;
154  depHOcal = IsoDeposit(dirTmp);
155  depHOcal.setVeto(Veto(dirTmp, dRtmp));
156  }
157 
158  if (theUseRecHitsFlag) {
161  auto const& caloGeom = eventSetup.getData(caloGeomToken_);
162 
163  //Ecal
164  std::vector<const EcalRecHit*>::const_iterator eHitCI = mInfo.ecalRecHits.begin();
165  for (; eHitCI != mInfo.ecalRecHits.end(); ++eHitCI) {
166  const EcalRecHit* eHitCPtr = *eHitCI;
167  GlobalPoint eHitPos = caloGeom.getPosition(eHitCPtr->detid());
168  double deltar0 = reco::deltaR(muon, eHitPos);
169  double cosTheta = 1. / cosh(eHitPos.eta());
170  double energy = eHitCPtr->energy();
171  double et = energy * cosTheta;
172  if (deltar0 > std::max(dRMax_CandDep, theDR_Max) ||
173  !(et > theThreshold_E && energy > 3 * noiseRecHit(eHitCPtr->detid())))
174  continue;
175 
176  bool vetoHit = false;
177  double deltar = reco::deltaR(mInfo.trkGlobPosAtEcal, eHitPos);
179  if (deltar < theDR_Veto_E) {
180  LogDebug("RecoMuon|CaloExtractorByAssociator") << " >>> Veto ECAL hit: Calo deltaR= " << deltar;
181  LogDebug("RecoMuon|CaloExtractorByAssociator")
182  << " >>> Calo eta phi ethcal: " << eHitPos.eta() << " " << eHitPos.phi() << " " << et;
183  vetoHit = true;
184  }
186  if (!vetoHit) {
187  for (unsigned int iH = 0; iH < mInfo.crossedEcalIds.size() && !vetoHit; ++iH) {
188  if (mInfo.crossedEcalIds[iH].rawId() == eHitCPtr->detid().rawId())
189  vetoHit = true;
190  }
191  }
192 
193  //check theDR_Max only here to keep vetoHits being added to the veto energy
194  if (deltar0 > theDR_Max && !vetoHit)
195  continue;
196 
197  if (vetoHit) {
198  depEcal.addCandEnergy(et);
199  } else {
200  depEcal.addDeposit(reco::isodeposit::Direction(eHitPos.eta(), eHitPos.phi()), et);
201  }
202  }
203 
204  //Hcal
205  std::vector<const HBHERecHit*>::const_iterator hHitCI = mInfo.hcalRecHits.begin();
206  for (; hHitCI != mInfo.hcalRecHits.end(); ++hHitCI) {
207  const HBHERecHit* hHitCPtr = *hHitCI;
208  GlobalPoint hHitPos = caloGeom.getPosition(hHitCPtr->detid());
209  double deltar0 = reco::deltaR(muon, hHitPos);
210  double cosTheta = 1. / cosh(hHitPos.eta());
211  double energy = hHitCPtr->energy();
212  double et = energy * cosTheta;
213  if (deltar0 > std::max(dRMax_CandDep, theDR_Max) ||
214  !(et > theThreshold_H && energy > 3 * noiseRecHit(hHitCPtr->detid())))
215  continue;
216 
217  bool vetoHit = false;
218  double deltar = reco::deltaR(mInfo.trkGlobPosAtHcal, hHitPos);
220  if (deltar < theDR_Veto_H) {
221  LogDebug("RecoMuon|CaloExtractorByAssociator") << " >>> Veto HBHE hit: Calo deltaR= " << deltar;
222  LogDebug("RecoMuon|CaloExtractorByAssociator")
223  << " >>> Calo eta phi ethcal: " << hHitPos.eta() << " " << hHitPos.phi() << " " << et;
224  vetoHit = true;
225  }
227  if (!vetoHit) {
228  for (unsigned int iH = 0; iH < mInfo.crossedHcalIds.size() && !vetoHit; ++iH) {
229  if (mInfo.crossedHcalIds[iH].rawId() == hHitCPtr->detid().rawId())
230  vetoHit = true;
231  }
232  }
233 
234  //check theDR_Max only here to keep vetoHits being added to the veto energy
235  if (deltar0 > theDR_Max && !vetoHit)
236  continue;
237 
238  if (vetoHit) {
239  depHcal.addCandEnergy(et);
240  } else {
241  depHcal.addDeposit(reco::isodeposit::Direction(hHitPos.eta(), hHitPos.phi()), et);
242  }
243  }
244 
245  //HOcal
246  std::vector<const HORecHit*>::const_iterator hoHitCI = mInfo.hoRecHits.begin();
247  for (; hoHitCI != mInfo.hoRecHits.end(); ++hoHitCI) {
248  const HORecHit* hoHitCPtr = *hoHitCI;
249  GlobalPoint hoHitPos = caloGeom.getPosition(hoHitCPtr->detid());
250  double deltar0 = reco::deltaR(muon, hoHitPos);
251  double cosTheta = 1. / cosh(hoHitPos.eta());
252  double energy = hoHitCPtr->energy();
253  double et = energy * cosTheta;
254  if (deltar0 > std::max(dRMax_CandDep, theDR_Max) ||
255  !(et > theThreshold_HO && energy > 3 * noiseRecHit(hoHitCPtr->detid())))
256  continue;
257 
258  bool vetoHit = false;
259  double deltar = reco::deltaR(mInfo.trkGlobPosAtHO, hoHitPos);
261  if (deltar < theDR_Veto_HO) {
262  LogDebug("RecoMuon|CaloExtractorByAssociator") << " >>> Veto HO hit: Calo deltaR= " << deltar;
263  LogDebug("RecoMuon|CaloExtractorByAssociator")
264  << " >>> Calo eta phi ethcal: " << hoHitPos.eta() << " " << hoHitPos.phi() << " " << et;
265  vetoHit = true;
266  }
268  if (!vetoHit) {
269  for (unsigned int iH = 0; iH < mInfo.crossedHOIds.size() && !vetoHit; ++iH) {
270  if (mInfo.crossedHOIds[iH].rawId() == hoHitCPtr->detid().rawId())
271  vetoHit = true;
272  }
273  }
274 
275  //check theDR_Max only here to keep vetoHits being added to the veto energy
276  if (deltar0 > theDR_Max && !vetoHit)
277  continue;
278 
279  if (vetoHit) {
280  depHOcal.addCandEnergy(et);
281  } else {
282  depHOcal.addDeposit(reco::isodeposit::Direction(hoHitPos.eta(), hoHitPos.phi()), et);
283  }
284  }
285 
286  } else {
288  std::vector<const CaloTower*>::const_iterator calCI = mInfo.towers.begin();
289  for (; calCI != mInfo.towers.end(); ++calCI) {
290  const CaloTower* calCPtr = *calCI;
291  double deltar0 = reco::deltaR(muon, *calCPtr);
292  if (deltar0 > std::max(dRMax_CandDep, theDR_Max))
293  continue;
294 
295  //even more copy-pasting .. need to refactor
296  double etecal = calCPtr->emEt();
297  double eecal = calCPtr->emEnergy();
298  bool doEcal = etecal > theThreshold_E && eecal > 3 * noiseEcal(*calCPtr);
299  double ethcal = calCPtr->hadEt();
300  double ehcal = calCPtr->hadEnergy();
301  bool doHcal = ethcal > theThreshold_H && ehcal > 3 * noiseHcal(*calCPtr);
302  double ethocal = calCPtr->outerEt();
303  double ehocal = calCPtr->outerEnergy();
304  bool doHOcal = ethocal > theThreshold_HO && ehocal > 3 * noiseHOcal(*calCPtr);
305  if ((!doEcal) && (!doHcal) && (!doHcal))
306  continue;
307 
308  bool vetoTowerEcal = false;
309  double deltarEcal = reco::deltaR(mInfo.trkGlobPosAtEcal, *calCPtr);
311  if (deltarEcal < theDR_Veto_E) {
312  LogDebug("RecoMuon|CaloExtractorByAssociator") << " >>> Veto ecal tower: Calo deltaR= " << deltarEcal;
313  LogDebug("RecoMuon|CaloExtractorByAssociator")
314  << " >>> Calo eta phi ethcal: " << calCPtr->eta() << " " << calCPtr->phi() << " " << ethcal;
315  vetoTowerEcal = true;
316  }
317  bool vetoTowerHcal = false;
318  double deltarHcal = reco::deltaR(mInfo.trkGlobPosAtHcal, *calCPtr);
320  if (deltarHcal < theDR_Veto_H) {
321  LogDebug("RecoMuon|CaloExtractorByAssociator") << " >>> Veto hcal tower: Calo deltaR= " << deltarHcal;
322  LogDebug("RecoMuon|CaloExtractorByAssociator")
323  << " >>> Calo eta phi ethcal: " << calCPtr->eta() << " " << calCPtr->phi() << " " << ethcal;
324  vetoTowerHcal = true;
325  }
326  bool vetoTowerHOCal = false;
327  double deltarHOcal = reco::deltaR(mInfo.trkGlobPosAtHO, *calCPtr);
329  if (deltarHOcal < theDR_Veto_HO) {
330  LogDebug("RecoMuon|CaloExtractorByAssociator") << " >>> Veto HO tower: Calo deltaR= " << deltarHOcal;
331  LogDebug("RecoMuon|CaloExtractorByAssociator")
332  << " >>> Calo eta phi ethcal: " << calCPtr->eta() << " " << calCPtr->phi() << " " << ethcal;
333  vetoTowerHOCal = true;
334  }
335 
337  if (!(vetoTowerHOCal && vetoTowerHcal && vetoTowerEcal)) {
338  for (unsigned int iH = 0; iH < mInfo.crossedTowerIds.size(); ++iH) {
339  if (mInfo.crossedTowerIds[iH].rawId() == calCPtr->id().rawId()) {
340  vetoTowerEcal = true;
341  vetoTowerHcal = true;
342  vetoTowerHOCal = true;
343  break;
344  }
345  }
346  }
347 
348  if (deltar0 > theDR_Max && !(vetoTowerEcal || vetoTowerHcal || vetoTowerHOCal))
349  continue;
350 
351  reco::isodeposit::Direction towerDir(calCPtr->eta(), calCPtr->phi());
353  if (doEcal) {
354  if (vetoTowerEcal)
355  depEcal.addCandEnergy(etecal);
356  else if (deltar0 <= theDR_Max)
357  depEcal.addDeposit(towerDir, etecal);
358  }
359  if (doHcal) {
360  if (vetoTowerHcal)
361  depHcal.addCandEnergy(ethcal);
362  else if (deltar0 <= theDR_Max)
363  depHcal.addDeposit(towerDir, ethcal);
364  }
365  if (doHOcal) {
366  if (vetoTowerHOCal)
367  depHOcal.addCandEnergy(ethocal);
368  else if (deltar0 <= theDR_Max)
369  depHOcal.addDeposit(towerDir, ethocal);
370  }
371  }
372  }
373 
374  std::vector<IsoDeposit> resultDeps;
375  resultDeps.push_back(depEcal);
376  resultDeps.push_back(depHcal);
377  resultDeps.push_back(depHOcal);
378 
379  return resultDeps;
380 }
381 
383  double noise = theNoiseTow_EB;
384  double eta = tower.eta();
385  if (fabs(eta) > 1.479)
387  return noise;
388 }
389 
391  double noise = fabs(tower.eta()) > 1.479 ? theNoise_HE : theNoise_HB;
392  return noise;
393 }
394 
396  double noise = theNoise_HO;
397  return noise;
398 }
399 
401  double noise = 100;
402  DetId::Detector det = detId.det();
403  if (det == DetId::Ecal) {
404  EcalSubdetector subDet = (EcalSubdetector)(detId.subdetId());
405  if (subDet == EcalBarrel) {
406  noise = theNoise_EB;
407  } else if (subDet == EcalEndcap) {
408  noise = theNoise_EE;
409  }
410  } else if (det == DetId::Hcal) {
411  HcalSubdetector subDet = (HcalSubdetector)(detId.subdetId());
412  if (subDet == HcalBarrel) {
413  noise = theNoise_HB;
414  } else if (subDet == HcalEndcap) {
415  noise = theNoise_HE;
416  } else if (subDet == HcalOuter) {
417  noise = theNoise_HO;
418  }
419  }
420  return noise;
421 }
double noiseHcal(const CaloTower &tower) const
bool compare(const P &i, const P &j)
math::XYZPoint trkGlobPosAtHO
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > bFieldToken_
constexpr const DetId & detid() const
Definition: CaloRecHit.h:33
double outerEnergy() const
Definition: CaloTower.h:132
std::vector< const CaloTower * > towers
void setVeto(const Veto &aVeto)
Set veto.
Definition: IsoDeposit.h:82
std::vector< DetId > crossedTowerIds
std::string thePropagatorName
propagator name to feed into the track associator
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
std::vector< const EcalRecHit * > ecalRecHits
hits in the cone
std::vector< DetId > crossedEcalIds
double theDR_Max
max cone size in which towers are considered
T eta() const
Definition: PV3DBase.h:73
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
double hadEt() const
Definition: CaloTower.h:136
void loadParameters(const edm::ParameterSet &, edm::ConsumesCollector &)
std::vector< std::string > theDepositInstanceLabels
multiple deposits: labels – expect 3 labels beginning with "e", "h", "ho"
double theDR_Veto_E
cone sizes inside which the Et (towers) are not counted
TrackAssociatorParameters * theAssociatorParameters
associator, its&#39; parameters and the propagator
Log< level::Error, false > LogError
muons
the two sets of parameters below are mutually exclusive, depending if RECO or ALCARECO is used the us...
Definition: DiMuonV_cfg.py:214
std::vector< DetId > crossedHcalIds
std::vector< reco::IsoDeposit > deposits(const edm::Event &ev, const edm::EventSetup &evSetup, const reco::Track &track) const override
return deposits for 3 calorimeter subdetectors (ecal, hcal, ho) – in this order
void addDeposit(double dr, double deposit)
Add deposit (ie. transverse energy or pT)
Definition: IsoDeposit.cc:19
double outerEt() const
Definition: CaloTower.h:137
math::XYZPoint trkGlobPosAtHcal
constexpr float energy() const
Definition: CaloRecHit.h:29
FreeTrajectoryState initialFreeState() const
void setPropagator(const Propagator *)
use a user configured propagator
std::vector< const HBHERecHit * > hcalRecHits
void addCandEnergy(double et)
Set energy or pT attached to cand trajectory.
Definition: IsoDeposit.h:132
std::vector< DetId > crossedHOIds
HcalSubdetector
Definition: HcalAssistant.h:31
const Veto & veto() const
Get veto area.
Definition: IsoDeposit.h:80
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:30
Definition: DetId.h:17
reco::IsoDeposit IsoDeposit
Definition: Isolation.h:7
Definition: deltar.py:1
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
double emEnergy() const
Definition: CaloTower.h:130
MuonServiceProxy * theService
the event setup proxy, it takes care the services update
double noiseEcal(const CaloTower &tower) const
Determine noise for HCAL and ECAL (take some defaults for the time being)
void fillVetos(const edm::Event &ev, const edm::EventSetup &evSetup, const reco::TrackCollection &tracks) override
allows to set extra vetoes (in addition to the muon) – no-op at this point
Detector
Definition: DetId.h:24
double hadEnergy() const
Definition: CaloTower.h:131
const DetId & detid() const
Definition: EcalRecHit.h:73
double emEt() const
Definition: CaloTower.h:135
fixed size matrix
HLT enums.
TrackDetMatchInfo associate(const edm::Event &, const edm::EventSetup &, const FreeTrajectoryState &, const AssociatorParameters &)
math::XYZPoint trkGlobPosAtEcal
Track position at different parts of the calorimeter.
Log< level::Warning, false > LogWarning
float energy() const
Definition: EcalRecHit.h:69
edm::ESGetToken< CaloGeometry, CaloGeometryRecord > caloGeomToken_
std::vector< const HORecHit * > hoRecHits
EcalSubdetector
double phi() const final
momentum azimuthal angle
double noiseHOcal(const CaloTower &tower) const
CaloTowerDetId id() const
Definition: CaloTower.h:123
Definition: event.py:1
reco::IsoDeposit deposit(const edm::Event &ev, const edm::EventSetup &evSetup, const reco::Track &track) const override
no-op: by design of this extractor the deposits are pulled out all at a time
#define LogDebug(id)
double eta() const final
momentum pseudorapidity