CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
23 
25 
26  LooseHcalIsol_(iConfig.getParameter<double>("LooseHcalIsol")),
27  LooseEcalIsol_(iConfig.getParameter<double>("LooseEcalIsol")),
28  LooseTrackIsol_(iConfig.getParameter<double>("LooseTrackIsol")),
29  TightHcalIsol_(iConfig.getParameter<double>("TightHcalIsol")),
30  TightEcalIsol_(iConfig.getParameter<double>("TightEcalIsol")),
31  TightTrackIsol_(iConfig.getParameter<double>("TightTrackIsol")),
32 
33  LooseRBXEne1_(iConfig.getParameter<double>("LooseRBXEne1")),
34  LooseRBXEne2_(iConfig.getParameter<double>("LooseRBXEne2")),
35  LooseRBXHits1_(iConfig.getParameter<int>("LooseRBXHits1")),
36  LooseRBXHits2_(iConfig.getParameter<int>("LooseRBXHits2")),
37  TightRBXEne1_(iConfig.getParameter<double>("TightRBXEne1")),
38  TightRBXEne2_(iConfig.getParameter<double>("TightRBXEne2")),
39  TightRBXHits1_(iConfig.getParameter<int>("TightRBXHits1")),
40  TightRBXHits2_(iConfig.getParameter<int>("TightRBXHits2")),
41 
42  LooseHPDEne1_(iConfig.getParameter<double>("LooseHPDEne1")),
43  LooseHPDEne2_(iConfig.getParameter<double>("LooseHPDEne2")),
44  LooseHPDHits1_(iConfig.getParameter<int>("LooseHPDHits1")),
45  LooseHPDHits2_(iConfig.getParameter<int>("LooseHPDHits2")),
46  TightHPDEne1_(iConfig.getParameter<double>("TightHPDEne1")),
47  TightHPDEne2_(iConfig.getParameter<double>("TightHPDEne2")),
48  TightHPDHits1_(iConfig.getParameter<int>("TightHPDHits1")),
49  TightHPDHits2_(iConfig.getParameter<int>("TightHPDHits2")),
50 
51  LooseDiHitEne_(iConfig.getParameter<double>("LooseDiHitEne")),
52  TightDiHitEne_(iConfig.getParameter<double>("TightDiHitEne")),
53  LooseMonoHitEne_(iConfig.getParameter<double>("LooseMonoHitEne")),
54  TightMonoHitEne_(iConfig.getParameter<double>("TightMonoHitEne")),
55 
56  RBXEneThreshold_(iConfig.getParameter<double>("RBXEneThreshold")),
57 
58  debug_(iConfig.getUntrackedParameter<bool>("debug",true)),
59  objvalidator_(iConfig)
60 {
61 
62  tok_hbhe_ = consumes<HBHERecHitCollection>(iConfig.getParameter<edm::InputTag>("hbheInput"));
63  tok_EB_ = consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("ebInput"));
64  tok_EE_ = consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("eeInput"));
65  tok_trackExt_ = consumes<std::vector<reco::TrackExtrapolation> >(iConfig.getParameter<edm::InputTag>("trackExtrapolationInput"));
66 
67  produces<HBHERecHitCollection>();
68 }
69 
71 {
72 }
73 
74 
75 void
77 {
78  // get the ECAL channel status map
80  evSetup.get<EcalChannelStatusRcd>().get( ecalChStatus );
81  const EcalChannelStatus* dbEcalChStatus = ecalChStatus.product();
82 
83  // get the HCAL channel status map
84 
86  evSetup.get<HcalChannelQualityRcd>().get( "withTopo", hcalChStatus );
87  const HcalChannelQuality* dbHcalChStatus = hcalChStatus.product();
88 
89  // get the severity level computers
90  edm::ESHandle<HcalSeverityLevelComputer> hcalSevLvlComputerHndl;
91  evSetup.get<HcalSeverityLevelComputerRcd>().get(hcalSevLvlComputerHndl);
92  const HcalSeverityLevelComputer* hcalSevLvlComputer = hcalSevLvlComputerHndl.product();
93 
94  edm::ESHandle<EcalSeverityLevelAlgo> ecalSevLvlAlgoHndl;
95  evSetup.get<EcalSeverityLevelAlgoRcd>().get(ecalSevLvlAlgoHndl);
96  const EcalSeverityLevelAlgo* ecalSevLvlAlgo = ecalSevLvlAlgoHndl.product();
97 
98  // get the calotower mappings
100  evSetup.get<CaloGeometryRecord>().get(ctcm);
101 
102  // get the HB/HE hits
104  iEvent.getByToken(tok_hbhe_, hbhehits_h);
105 
106  // get the ECAL hits
108  iEvent.getByToken(tok_EB_, ebhits_h);
110  iEvent.getByToken(tok_EE_, eehits_h);
111 
112  // get the tracks
114  iEvent.getByToken(tok_trackExt_, trackextraps_h);
115 
116  // set the status maps and severity level computers for the hit validator
117  objvalidator_.setHcalChannelQuality(dbHcalChStatus);
118  objvalidator_.setEcalChannelStatus(dbEcalChStatus);
119  objvalidator_.setHcalSeverityLevelComputer(hcalSevLvlComputer);
120  objvalidator_.setEcalSeverityLevelAlgo(ecalSevLvlAlgo);
121  objvalidator_.setEBRecHitCollection(&(*ebhits_h));
122  objvalidator_.setEERecHitCollection(&(*eehits_h));
123 
124  // organizer the hits
125  PhysicsTowerOrganizer pto(iEvent, evSetup, hbhehits_h, ebhits_h, eehits_h, trackextraps_h, objvalidator_, *(ctcm.product()));
126  HBHEHitMapOrganizer organizer(hbhehits_h, objvalidator_, pto);
127 
128  // get the rbxs, hpds, dihits, and monohits
129  std::vector<HBHEHitMap> rbxs;
130  std::vector<HBHEHitMap> hpds;
131  std::vector<HBHEHitMap> dihits;
132  std::vector<HBHEHitMap> monohits;
137 
138  if(debug_ && (rbxs.size()>0 || hpds.size()>0 || dihits.size()>0 || monohits.size()>0)) {
139  edm::LogInfo("HBHEIsolatedNoiseReflagger") << "RBXs:" << std::endl;
140  DumpHBHEHitMap(rbxs);
141  edm::LogInfo("HBHEIsolatedNoiseReflagger") << "\nHPDs:" << std::endl;
142  DumpHBHEHitMap(hpds);
143  edm::LogInfo("HBHEIsolatedNoiseReflagger") << "\nDiHits:" << std::endl;
144  DumpHBHEHitMap(dihits);
145  edm::LogInfo("HBHEIsolatedNoiseReflagger") << "\nMonoHits:" << std::endl;
146  DumpHBHEHitMap(monohits);
147  }
148 
149  // bool result=true;
150 
151  // determine which hits are noisy
152  std::set<const HBHERecHit*> noisehits;
153  for(int i=0; i<static_cast<int>(rbxs.size()); i++) {
154  int nhits=rbxs[i].nHits();
155  double ene=rbxs[i].hitEnergy();
156  double trkfide=rbxs[i].hitEnergyTrackFiducial();
157  double isolhcale=rbxs[i].hcalEnergySameTowers()+rbxs[i].hcalEnergyNeighborTowers();
158  double isolecale=rbxs[i].ecalEnergySameTowers();
159  double isoltrke=rbxs[i].trackEnergySameTowers()+rbxs[i].trackEnergyNeighborTowers();
160  //
161  // RBX mistag reduction
162  bool isLooseIso=false;
163  bool isTightIso=false;
164  if( ene>RBXEneThreshold_ && ene>0 ){// New absolute iso-cut for high energy RBX clusters
166  isLooseIso=true;
167  if( isolhcale<TightHcalIsol_*RBXEneThreshold_ && isolecale<TightEcalIsol_*RBXEneThreshold_ && isoltrke<TightTrackIsol_*RBXEneThreshold_ )
168  isTightIso=true;
169  }
170  if( ene<=RBXEneThreshold_ && ene>0 ){// Old relative iso-cut for low energy RBX clusters
171  if( isolhcale/ene<LooseHcalIsol_ && isolecale/ene<LooseEcalIsol_ && isoltrke/ene<LooseTrackIsol_ )
172  isLooseIso=true;
173  if( isolhcale/ene<TightHcalIsol_ && isolecale/ene<TightEcalIsol_ && isoltrke/ene<TightTrackIsol_ )
174  isTightIso=true;
175  }
176  //
177  if((isLooseIso && ((trkfide>LooseRBXEne1_ && nhits>=LooseRBXHits1_) || (trkfide>LooseRBXEne2_ && nhits>=LooseRBXHits2_))) ||
178  (isTightIso && ((trkfide>TightRBXEne1_ && nhits>=TightRBXHits1_) || (trkfide>TightRBXEne2_ && nhits>=TightRBXHits2_)))) {
179  for(HBHEHitMap::hitmap_const_iterator it=rbxs[i].beginHits(); it!=rbxs[i].endHits(); ++it)
180  noisehits.insert(it->first);
181  // result=false;
182  }
183  }
184 
185  for(int i=0; i<static_cast<int>(hpds.size()); i++) {
186  int nhits=hpds[i].nHits();
187  double ene=hpds[i].hitEnergy();
188  double trkfide=hpds[i].hitEnergyTrackFiducial();
189  double isolhcale=hpds[i].hcalEnergySameTowers()+hpds[i].hcalEnergyNeighborTowers();
190  double isolecale=hpds[i].ecalEnergySameTowers();
191  double isoltrke=hpds[i].trackEnergySameTowers()+hpds[i].trackEnergyNeighborTowers();
192  if((ene>0 && isolhcale/ene<LooseHcalIsol_ && isolecale/ene<LooseEcalIsol_ && isoltrke/ene<LooseTrackIsol_ && ((trkfide>LooseHPDEne1_ && nhits>=LooseHPDHits1_) || (trkfide>LooseHPDEne2_ && nhits>=LooseHPDHits2_))) ||
193  (ene>0 && isolhcale/ene<TightHcalIsol_ && isolecale/ene<TightEcalIsol_ && isoltrke/ene<TightTrackIsol_ && ((trkfide>TightHPDEne1_ && nhits>=TightHPDHits1_) || (trkfide>TightHPDEne2_ && nhits>=TightHPDHits2_)))) {
194  for(HBHEHitMap::hitmap_const_iterator it=hpds[i].beginHits(); it!=hpds[i].endHits(); ++it)
195  noisehits.insert(it->first);
196  // result=false;
197  }
198  }
199 
200  for(int i=0; i<static_cast<int>(dihits.size()); i++) {
201  double ene=dihits[i].hitEnergy();
202  double trkfide=dihits[i].hitEnergyTrackFiducial();
203  double isolhcale=dihits[i].hcalEnergySameTowers()+dihits[i].hcalEnergyNeighborTowers();
204  double isolecale=dihits[i].ecalEnergySameTowers();
205  double isoltrke=dihits[i].trackEnergySameTowers()+dihits[i].trackEnergyNeighborTowers();
206  if((ene>0 && isolhcale/ene<LooseHcalIsol_ && isolecale/ene<LooseEcalIsol_ && isoltrke/ene<LooseTrackIsol_ && trkfide>0.99*ene && trkfide>LooseDiHitEne_) ||
207  (ene>0 && isolhcale/ene<TightHcalIsol_ && isolecale/ene<TightEcalIsol_ && isoltrke/ene<TightTrackIsol_ && ene>TightDiHitEne_)) {
208  for(HBHEHitMap::hitmap_const_iterator it=dihits[i].beginHits(); it!=dihits[i].endHits(); ++it)
209  noisehits.insert(it->first);
210  // result=false;
211  }
212  }
213 
214  for(int i=0; i<static_cast<int>(monohits.size()); i++) {
215  double ene=monohits[i].hitEnergy();
216  double trkfide=monohits[i].hitEnergyTrackFiducial();
217  double isolhcale=monohits[i].hcalEnergySameTowers()+monohits[i].hcalEnergyNeighborTowers();
218  double isolecale=monohits[i].ecalEnergySameTowers();
219  double isoltrke=monohits[i].trackEnergySameTowers()+monohits[i].trackEnergyNeighborTowers();
220  if((ene>0 && isolhcale/ene<LooseHcalIsol_ && isolecale/ene<LooseEcalIsol_ && isoltrke/ene<LooseTrackIsol_ && trkfide>0.99*ene && trkfide>LooseMonoHitEne_) ||
221  (ene>0 && isolhcale/ene<TightHcalIsol_ && isolecale/ene<TightEcalIsol_ && isoltrke/ene<TightTrackIsol_ && ene>TightMonoHitEne_)) {
222  for(HBHEHitMap::hitmap_const_iterator it=monohits[i].beginHits(); it!=monohits[i].endHits(); ++it)
223  noisehits.insert(it->first);
224  // result=false;
225  }
226  }
227 
228  // prepare the output HBHE RecHit collection
229  std::auto_ptr<HBHERecHitCollection> pOut(new HBHERecHitCollection());
230  // loop over rechits, and set the new bit you wish to use
231  for(HBHERecHitCollection::const_iterator it=hbhehits_h->begin(); it!=hbhehits_h->end(); ++it) {
232  const HBHERecHit* hit=&(*it);
233  HBHERecHit newhit(*hit);
234  if(noisehits.end()!=noisehits.find(hit)) {
236  }
237  pOut->push_back(newhit);
238  }
239 
240  iEvent.put(pOut);
241 
242  return;
243 }
244 
245 
246 void HBHEIsolatedNoiseReflagger::DumpHBHEHitMap(std::vector<HBHEHitMap>& i) const
247 {
248  for(std::vector<HBHEHitMap>::const_iterator it=i.begin(); it!=i.end(); ++it) {
249  edm::LogInfo("HBHEIsolatedNoiseReflagger") << "hit energy=" << it->hitEnergy()
250  << "; # hits=" << it->nHits()
251  << "; hcal energy same=" << it->hcalEnergySameTowers()
252  << "; ecal energy same=" << it->ecalEnergySameTowers()
253  << "; track energy same=" << it->trackEnergySameTowers()
254  << "; neighbor hcal energy=" << it->hcalEnergyNeighborTowers() << std::endl;
255  edm::LogInfo("HBHEIsolatedNoiseReflagger") << "hits:" << std::endl;
256  for(HBHEHitMap::hitmap_const_iterator it2=it->beginHits(); it2!=it->endHits(); ++it2) {
257  const HBHERecHit *hit=it2->first;
258  edm::LogInfo("HBHEIsolatedNoiseReflagger") << "RBX #=" << HcalHPDRBXMap::indexRBX(hit->id())
259  << "; HPD #=" << HcalHPDRBXMap::indexHPD(hit->id())
260  << "; " << (*hit) << std::endl;
261  }
262  }
263  return;
264 }
265 
266 
267 //define this as a plug-in
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
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:462
static int indexRBX(const HcalDetId &)
#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:23
void setFlagField(uint32_t value, int base, int width=1)
Definition: CaloRecHit.cc:20
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
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
edm::EDGetTokenT< std::vector< reco::TrackExtrapolation > > tok_trackExt_
edm::SortedCollection< HBHERecHit > HBHERecHitCollection
void setEcalSeverityLevelAlgo(const EcalSeverityLevelAlgo *q)
void setEcalChannelStatus(const EcalChannelStatus *q)
void setEERecHitCollection(const EcalRecHitCollection *q)
const T & get() const
Definition: EventSetup.h:56
virtual void produce(edm::Event &, const edm::EventSetup &) override
T const * product() const
Definition: ESHandle.h:86
void getDiHits(std::vector< HBHEHitMap > &v, double energy) const
edm::EDGetTokenT< EcalRecHitCollection > tok_EB_
static int indexHPD(const HcalDetId &)
void setEBRecHitCollection(const EcalRecHitCollection *q)