CMS 3D CMS Logo

HBHEIsolatedNoiseReflagger.cc
Go to the documentation of this file.
1 /*
2 Description: "Reflags" HB/HE hits based on their ECAL, HCAL, and tracking isolation.
3 
4 Original Author: John Paul Chou (Brown University)
5  Thursday, September 2, 2010
6 */
7 
9 
19 
25 
27 
28  LooseHcalIsol_(iConfig.getParameter<double>("LooseHcalIsol")),
29  LooseEcalIsol_(iConfig.getParameter<double>("LooseEcalIsol")),
30  LooseTrackIsol_(iConfig.getParameter<double>("LooseTrackIsol")),
31  TightHcalIsol_(iConfig.getParameter<double>("TightHcalIsol")),
32  TightEcalIsol_(iConfig.getParameter<double>("TightEcalIsol")),
33  TightTrackIsol_(iConfig.getParameter<double>("TightTrackIsol")),
34 
35  LooseRBXEne1_(iConfig.getParameter<double>("LooseRBXEne1")),
36  LooseRBXEne2_(iConfig.getParameter<double>("LooseRBXEne2")),
37  LooseRBXHits1_(iConfig.getParameter<int>("LooseRBXHits1")),
38  LooseRBXHits2_(iConfig.getParameter<int>("LooseRBXHits2")),
39  TightRBXEne1_(iConfig.getParameter<double>("TightRBXEne1")),
40  TightRBXEne2_(iConfig.getParameter<double>("TightRBXEne2")),
41  TightRBXHits1_(iConfig.getParameter<int>("TightRBXHits1")),
42  TightRBXHits2_(iConfig.getParameter<int>("TightRBXHits2")),
43 
44  LooseHPDEne1_(iConfig.getParameter<double>("LooseHPDEne1")),
45  LooseHPDEne2_(iConfig.getParameter<double>("LooseHPDEne2")),
46  LooseHPDHits1_(iConfig.getParameter<int>("LooseHPDHits1")),
47  LooseHPDHits2_(iConfig.getParameter<int>("LooseHPDHits2")),
48  TightHPDEne1_(iConfig.getParameter<double>("TightHPDEne1")),
49  TightHPDEne2_(iConfig.getParameter<double>("TightHPDEne2")),
50  TightHPDHits1_(iConfig.getParameter<int>("TightHPDHits1")),
51  TightHPDHits2_(iConfig.getParameter<int>("TightHPDHits2")),
52 
53  LooseDiHitEne_(iConfig.getParameter<double>("LooseDiHitEne")),
54  TightDiHitEne_(iConfig.getParameter<double>("TightDiHitEne")),
55  LooseMonoHitEne_(iConfig.getParameter<double>("LooseMonoHitEne")),
56  TightMonoHitEne_(iConfig.getParameter<double>("TightMonoHitEne")),
57 
58  RBXEneThreshold_(iConfig.getParameter<double>("RBXEneThreshold")),
59 
60  debug_(iConfig.getUntrackedParameter<bool>("debug",true)),
61  objvalidator_(iConfig)
62 {
63 
64  tok_hbhe_ = consumes<HBHERecHitCollection>(iConfig.getParameter<edm::InputTag>("hbheInput"));
65  tok_EB_ = consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("ebInput"));
66  tok_EE_ = consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("eeInput"));
67  tok_trackExt_ = consumes<std::vector<reco::TrackExtrapolation> >(iConfig.getParameter<edm::InputTag>("trackExtrapolationInput"));
68 
69  produces<HBHERecHitCollection>();
70 }
71 
73 {
74 }
75 
76 
77 void
79 {
80  // get the ECAL channel status map
82  evSetup.get<EcalChannelStatusRcd>().get( ecalChStatus );
83  const EcalChannelStatus* dbEcalChStatus = ecalChStatus.product();
84 
85  // get the HCAL channel status map
86 
88  evSetup.get<HcalChannelQualityRcd>().get( "withTopo", hcalChStatus );
89  const HcalChannelQuality* dbHcalChStatus = hcalChStatus.product();
90 
91  // get the severity level computers
92  edm::ESHandle<HcalSeverityLevelComputer> hcalSevLvlComputerHndl;
93  evSetup.get<HcalSeverityLevelComputerRcd>().get(hcalSevLvlComputerHndl);
94  const HcalSeverityLevelComputer* hcalSevLvlComputer = hcalSevLvlComputerHndl.product();
95 
96  edm::ESHandle<EcalSeverityLevelAlgo> ecalSevLvlAlgoHndl;
97  evSetup.get<EcalSeverityLevelAlgoRcd>().get(ecalSevLvlAlgoHndl);
98  const EcalSeverityLevelAlgo* ecalSevLvlAlgo = ecalSevLvlAlgoHndl.product();
99 
100  // get the calotower mappings
102  evSetup.get<CaloGeometryRecord>().get(ctcm);
103 
104  // get hcal frontend map
106  evSetup.get<HcalFrontEndMapRcd>().get(hfemapHndl);
107  hfemap = hfemapHndl.product();
108 
109  // get the HB/HE hits
111  iEvent.getByToken(tok_hbhe_, hbhehits_h);
112 
113  // get the ECAL hits
115  iEvent.getByToken(tok_EB_, ebhits_h);
117  iEvent.getByToken(tok_EE_, eehits_h);
118 
119  // get the tracks
121  iEvent.getByToken(tok_trackExt_, trackextraps_h);
122 
123  // set the status maps and severity level computers for the hit validator
124  objvalidator_.setHcalChannelQuality(dbHcalChStatus);
125  objvalidator_.setEcalChannelStatus(dbEcalChStatus);
126  objvalidator_.setHcalSeverityLevelComputer(hcalSevLvlComputer);
127  objvalidator_.setEcalSeverityLevelAlgo(ecalSevLvlAlgo);
128  objvalidator_.setEBRecHitCollection(&(*ebhits_h));
129  objvalidator_.setEERecHitCollection(&(*eehits_h));
130 
131  // organizer the hits
132  PhysicsTowerOrganizer pto(iEvent, evSetup, hbhehits_h, ebhits_h, eehits_h, trackextraps_h, objvalidator_, *(ctcm.product()));
133  HBHEHitMapOrganizer organizer(hbhehits_h, objvalidator_, pto, hfemap);
134 
135  // get the rbxs, hpds, dihits, and monohits
136  std::vector<HBHEHitMap> rbxs;
137  std::vector<HBHEHitMap> hpds;
138  std::vector<HBHEHitMap> dihits;
139  std::vector<HBHEHitMap> monohits;
144 
145  if(debug_ && (!rbxs.empty() || !hpds.empty() || !dihits.empty() || !monohits.empty())) {
146  edm::LogInfo("HBHEIsolatedNoiseReflagger") << "RBXs:" << std::endl;
147  DumpHBHEHitMap(rbxs);
148  edm::LogInfo("HBHEIsolatedNoiseReflagger") << "\nHPDs:" << std::endl;
149  DumpHBHEHitMap(hpds);
150  edm::LogInfo("HBHEIsolatedNoiseReflagger") << "\nDiHits:" << std::endl;
151  DumpHBHEHitMap(dihits);
152  edm::LogInfo("HBHEIsolatedNoiseReflagger") << "\nMonoHits:" << std::endl;
153  DumpHBHEHitMap(monohits);
154  }
155 
156  // bool result=true;
157 
158  // determine which hits are noisy
159  std::set<const HBHERecHit*> noisehits;
160  for(int i=0; i<static_cast<int>(rbxs.size()); i++) {
161  int nhits=rbxs[i].nHits();
162  double ene=rbxs[i].hitEnergy();
163  double trkfide=rbxs[i].hitEnergyTrackFiducial();
164  double isolhcale=rbxs[i].hcalEnergySameTowers()+rbxs[i].hcalEnergyNeighborTowers();
165  double isolecale=rbxs[i].ecalEnergySameTowers();
166  double isoltrke=rbxs[i].trackEnergySameTowers()+rbxs[i].trackEnergyNeighborTowers();
167  //
168  // RBX mistag reduction
169  bool isLooseIso=false;
170  bool isTightIso=false;
171  if( ene>RBXEneThreshold_ && ene>0 ){// New absolute iso-cut for high energy RBX clusters
173  isLooseIso=true;
174  if( isolhcale<TightHcalIsol_*RBXEneThreshold_ && isolecale<TightEcalIsol_*RBXEneThreshold_ && isoltrke<TightTrackIsol_*RBXEneThreshold_ )
175  isTightIso=true;
176  }
177  if( ene<=RBXEneThreshold_ && ene>0 ){// Old relative iso-cut for low energy RBX clusters
178  if( isolhcale/ene<LooseHcalIsol_ && isolecale/ene<LooseEcalIsol_ && isoltrke/ene<LooseTrackIsol_ )
179  isLooseIso=true;
180  if( isolhcale/ene<TightHcalIsol_ && isolecale/ene<TightEcalIsol_ && isoltrke/ene<TightTrackIsol_ )
181  isTightIso=true;
182  }
183  //
184  if((isLooseIso && ((trkfide>LooseRBXEne1_ && nhits>=LooseRBXHits1_) || (trkfide>LooseRBXEne2_ && nhits>=LooseRBXHits2_))) ||
185  (isTightIso && ((trkfide>TightRBXEne1_ && nhits>=TightRBXHits1_) || (trkfide>TightRBXEne2_ && nhits>=TightRBXHits2_)))) {
186  for(HBHEHitMap::hitmap_const_iterator it=rbxs[i].beginHits(); it!=rbxs[i].endHits(); ++it)
187  noisehits.insert(it->first);
188  // result=false;
189  }
190  }
191 
192  for(int i=0; i<static_cast<int>(hpds.size()); i++) {
193  int nhits=hpds[i].nHits();
194  double ene=hpds[i].hitEnergy();
195  double trkfide=hpds[i].hitEnergyTrackFiducial();
196  double isolhcale=hpds[i].hcalEnergySameTowers()+hpds[i].hcalEnergyNeighborTowers();
197  double isolecale=hpds[i].ecalEnergySameTowers();
198  double isoltrke=hpds[i].trackEnergySameTowers()+hpds[i].trackEnergyNeighborTowers();
199  if((ene>0 && isolhcale/ene<LooseHcalIsol_ && isolecale/ene<LooseEcalIsol_ && isoltrke/ene<LooseTrackIsol_ && ((trkfide>LooseHPDEne1_ && nhits>=LooseHPDHits1_) || (trkfide>LooseHPDEne2_ && nhits>=LooseHPDHits2_))) ||
200  (ene>0 && isolhcale/ene<TightHcalIsol_ && isolecale/ene<TightEcalIsol_ && isoltrke/ene<TightTrackIsol_ && ((trkfide>TightHPDEne1_ && nhits>=TightHPDHits1_) || (trkfide>TightHPDEne2_ && nhits>=TightHPDHits2_)))) {
201  for(HBHEHitMap::hitmap_const_iterator it=hpds[i].beginHits(); it!=hpds[i].endHits(); ++it)
202  noisehits.insert(it->first);
203  // result=false;
204  }
205  }
206 
207  for(int i=0; i<static_cast<int>(dihits.size()); i++) {
208  double ene=dihits[i].hitEnergy();
209  double trkfide=dihits[i].hitEnergyTrackFiducial();
210  double isolhcale=dihits[i].hcalEnergySameTowers()+dihits[i].hcalEnergyNeighborTowers();
211  double isolecale=dihits[i].ecalEnergySameTowers();
212  double isoltrke=dihits[i].trackEnergySameTowers()+dihits[i].trackEnergyNeighborTowers();
213  if((ene>0 && isolhcale/ene<LooseHcalIsol_ && isolecale/ene<LooseEcalIsol_ && isoltrke/ene<LooseTrackIsol_ && trkfide>0.99*ene && trkfide>LooseDiHitEne_) ||
214  (ene>0 && isolhcale/ene<TightHcalIsol_ && isolecale/ene<TightEcalIsol_ && isoltrke/ene<TightTrackIsol_ && ene>TightDiHitEne_)) {
215  for(HBHEHitMap::hitmap_const_iterator it=dihits[i].beginHits(); it!=dihits[i].endHits(); ++it)
216  noisehits.insert(it->first);
217  // result=false;
218  }
219  }
220 
221  for(int i=0; i<static_cast<int>(monohits.size()); i++) {
222  double ene=monohits[i].hitEnergy();
223  double trkfide=monohits[i].hitEnergyTrackFiducial();
224  double isolhcale=monohits[i].hcalEnergySameTowers()+monohits[i].hcalEnergyNeighborTowers();
225  double isolecale=monohits[i].ecalEnergySameTowers();
226  double isoltrke=monohits[i].trackEnergySameTowers()+monohits[i].trackEnergyNeighborTowers();
227  if((ene>0 && isolhcale/ene<LooseHcalIsol_ && isolecale/ene<LooseEcalIsol_ && isoltrke/ene<LooseTrackIsol_ && trkfide>0.99*ene && trkfide>LooseMonoHitEne_) ||
228  (ene>0 && isolhcale/ene<TightHcalIsol_ && isolecale/ene<TightEcalIsol_ && isoltrke/ene<TightTrackIsol_ && ene>TightMonoHitEne_)) {
229  for(HBHEHitMap::hitmap_const_iterator it=monohits[i].beginHits(); it!=monohits[i].endHits(); ++it)
230  noisehits.insert(it->first);
231  // result=false;
232  }
233  }
234 
235  // prepare the output HBHE RecHit collection
236  auto pOut = std::make_unique<HBHERecHitCollection>();
237  // loop over rechits, and set the new bit you wish to use
238  for(HBHERecHitCollection::const_iterator it=hbhehits_h->begin(); it!=hbhehits_h->end(); ++it) {
239  const HBHERecHit* hit=&(*it);
240  HBHERecHit newhit(*hit);
241  if(noisehits.end()!=noisehits.find(hit)) {
243  }
244  pOut->push_back(newhit);
245  }
246 
247  iEvent.put(std::move(pOut));
248 
249  return;
250 }
251 
252 
253 void HBHEIsolatedNoiseReflagger::DumpHBHEHitMap(std::vector<HBHEHitMap>& i) const
254 {
255  for(std::vector<HBHEHitMap>::const_iterator it=i.begin(); it!=i.end(); ++it) {
256  edm::LogInfo("HBHEIsolatedNoiseReflagger") << "hit energy=" << it->hitEnergy()
257  << "; # hits=" << it->nHits()
258  << "; hcal energy same=" << it->hcalEnergySameTowers()
259  << "; ecal energy same=" << it->ecalEnergySameTowers()
260  << "; track energy same=" << it->trackEnergySameTowers()
261  << "; neighbor hcal energy=" << it->hcalEnergyNeighborTowers() << std::endl;
262  edm::LogInfo("HBHEIsolatedNoiseReflagger") << "hits:" << std::endl;
263  for(HBHEHitMap::hitmap_const_iterator it2=it->beginHits(); it2!=it->endHits(); ++it2) {
264  const HBHERecHit *hit=it2->first;
265  edm::LogInfo("HBHEIsolatedNoiseReflagger")
266  << "RBX #=" << hfemap->lookupRBX(hit->id())
267  << "; HPD #=" << hfemap->lookupRMIndex(hit->id())
268  << "; " << (*hit) << std::endl;
269  }
270  }
271  return;
272 }
273 
274 
275 //define this as a plug-in
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:136
void DumpHBHEHitMap(std::vector< HBHEHitMap > &i) const
std::map< const HBHERecHit *, const PhysicsTower * >::const_iterator hitmap_const_iterator
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void setHcalChannelQuality(const HcalChannelQuality *q)
void getHPDs(std::vector< HBHEHitMap > &v, double energy) const
HcalDetId id() const
get the id
Definition: HBHERecHit.h:25
void setFlagField(uint32_t value, int base, int width=1)
Definition: CaloRecHit.cc:20
const int lookupRMIndex(DetId fId) const
std::vector< HBHERecHit >::const_iterator const_iterator
edm::EDGetTokenT< HBHERecHitCollection > tok_hbhe_
HBHEIsolatedNoiseReflagger(const edm::ParameterSet &)
void getRBXs(std::vector< HBHEHitMap > &v, double energy) const
void getMonoHits(std::vector< HBHEHitMap > &v, double energy) const
void setHcalSeverityLevelComputer(const HcalSeverityLevelComputer *q)
edm::EDGetTokenT< EcalRecHitCollection > tok_EE_
int iEvent
Definition: GenABIO.cc:230
edm::EDGetTokenT< std::vector< reco::TrackExtrapolation > > tok_trackExt_
const_iterator end() const
void setEcalSeverityLevelAlgo(const EcalSeverityLevelAlgo *q)
void setEcalChannelStatus(const EcalChannelStatus *q)
void setEERecHitCollection(const EcalRecHitCollection *q)
const T & get() const
Definition: EventSetup.h:59
void produce(edm::Event &, const edm::EventSetup &) override
void getDiHits(std::vector< HBHEHitMap > &v, double energy) const
edm::EDGetTokenT< EcalRecHitCollection > tok_EB_
void setEBRecHitCollection(const EcalRecHitCollection *q)
T const * product() const
Definition: ESHandle.h:86
const std::string lookupRBX(DetId fId) const
brief lookup the RBX associated with the given logical id
def move(src, dest)
Definition: eostools.py:510
const_iterator begin() const