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  debug_(iConfig.getUntrackedParameter<bool>("debug",true)),
57  objvalidator_(iConfig)
58 {
59 
60  tok_hbhe_ = consumes<HBHERecHitCollection>(iConfig.getParameter<edm::InputTag>("hbheInput"));
61  tok_EB_ = consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("ebInput"));
62  tok_EE_ = consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("eeInput"));
63  tok_trackExt_ = consumes<std::vector<reco::TrackExtrapolation> >(iConfig.getParameter<edm::InputTag>("trackExtrapolationInput"));
64 
65  produces<HBHERecHitCollection>();
66 }
67 
69 {
70 }
71 
72 
73 void
75 {
76  // get the ECAL channel status map
78  evSetup.get<EcalChannelStatusRcd>().get( ecalChStatus );
79  const EcalChannelStatus* dbEcalChStatus = ecalChStatus.product();
80 
81  // get the HCAL channel status map
82 
84  evSetup.get<HcalChannelQualityRcd>().get( "withTopo", hcalChStatus );
85  const HcalChannelQuality* dbHcalChStatus = hcalChStatus.product();
86 
87  // get the severity level computers
88  edm::ESHandle<HcalSeverityLevelComputer> hcalSevLvlComputerHndl;
89  evSetup.get<HcalSeverityLevelComputerRcd>().get(hcalSevLvlComputerHndl);
90  const HcalSeverityLevelComputer* hcalSevLvlComputer = hcalSevLvlComputerHndl.product();
91 
92  edm::ESHandle<EcalSeverityLevelAlgo> ecalSevLvlAlgoHndl;
93  evSetup.get<EcalSeverityLevelAlgoRcd>().get(ecalSevLvlAlgoHndl);
94  const EcalSeverityLevelAlgo* ecalSevLvlAlgo = ecalSevLvlAlgoHndl.product();
95 
96  // get the calotower mappings
98  evSetup.get<IdealGeometryRecord>().get(ctcm);
99 
100  // get the HB/HE hits
102  iEvent.getByToken(tok_hbhe_, hbhehits_h);
103 
104  // get the ECAL hits
106  iEvent.getByToken(tok_EB_, ebhits_h);
108  iEvent.getByToken(tok_EE_, eehits_h);
109 
110  // get the tracks
112  iEvent.getByToken(tok_trackExt_, trackextraps_h);
113 
114  // set the status maps and severity level computers for the hit validator
115  objvalidator_.setHcalChannelQuality(dbHcalChStatus);
116  objvalidator_.setEcalChannelStatus(dbEcalChStatus);
117  objvalidator_.setHcalSeverityLevelComputer(hcalSevLvlComputer);
118  objvalidator_.setEcalSeverityLevelAlgo(ecalSevLvlAlgo);
119  objvalidator_.setEBRecHitCollection(&(*ebhits_h));
120  objvalidator_.setEERecHitCollection(&(*eehits_h));
121 
122  // organizer the hits
123  PhysicsTowerOrganizer pto(iEvent, evSetup, hbhehits_h, ebhits_h, eehits_h, trackextraps_h, objvalidator_, *(ctcm.product()));
124  HBHEHitMapOrganizer organizer(hbhehits_h, objvalidator_, pto);
125 
126  // get the rbxs, hpds, dihits, and monohits
127  std::vector<HBHEHitMap> rbxs;
128  std::vector<HBHEHitMap> hpds;
129  std::vector<HBHEHitMap> dihits;
130  std::vector<HBHEHitMap> monohits;
135 
136  if(debug_ && (rbxs.size()>0 || hpds.size()>0 || dihits.size()>0 || monohits.size()>0)) {
137  edm::LogInfo("HBHEIsolatedNoiseReflagger") << "RBXs:" << std::endl;
138  DumpHBHEHitMap(rbxs);
139  edm::LogInfo("HBHEIsolatedNoiseReflagger") << "\nHPDs:" << std::endl;
140  DumpHBHEHitMap(hpds);
141  edm::LogInfo("HBHEIsolatedNoiseReflagger") << "\nDiHits:" << std::endl;
142  DumpHBHEHitMap(dihits);
143  edm::LogInfo("HBHEIsolatedNoiseReflagger") << "\nMonoHits:" << std::endl;
144  DumpHBHEHitMap(monohits);
145  }
146 
147  // bool result=true;
148 
149  // determine which hits are noisy
150  std::set<const HBHERecHit*> noisehits;
151  for(int i=0; i<static_cast<int>(rbxs.size()); i++) {
152  int nhits=rbxs[i].nHits();
153  double ene=rbxs[i].hitEnergy();
154  double trkfide=rbxs[i].hitEnergyTrackFiducial();
155  double isolhcale=rbxs[i].hcalEnergySameTowers()+rbxs[i].hcalEnergyNeighborTowers();
156  double isolecale=rbxs[i].ecalEnergySameTowers();
157  double isoltrke=rbxs[i].trackEnergySameTowers()+rbxs[i].trackEnergyNeighborTowers();
158  if((isolhcale/ene<LooseHcalIsol_ && isolecale/ene<LooseEcalIsol_ && isoltrke/ene<LooseTrackIsol_ && ((trkfide>LooseRBXEne1_ && nhits>=LooseRBXHits1_) || (trkfide>LooseRBXEne2_ && nhits>=LooseRBXHits2_))) ||
159  (isolhcale/ene<TightHcalIsol_ && isolecale/ene<TightEcalIsol_ && isoltrke/ene<TightTrackIsol_ && ((trkfide>TightRBXEne1_ && nhits>=TightRBXHits1_) || (trkfide>TightRBXEne2_ && nhits>=TightRBXHits2_)))) {
160  for(HBHEHitMap::hitmap_const_iterator it=rbxs[i].beginHits(); it!=rbxs[i].endHits(); ++it)
161  noisehits.insert(it->first);
162  // result=false;
163  }
164  }
165 
166  for(int i=0; i<static_cast<int>(hpds.size()); i++) {
167  int nhits=hpds[i].nHits();
168  double ene=hpds[i].hitEnergy();
169  double trkfide=hpds[i].hitEnergyTrackFiducial();
170  double isolhcale=hpds[i].hcalEnergySameTowers()+hpds[i].hcalEnergyNeighborTowers();
171  double isolecale=hpds[i].ecalEnergySameTowers();
172  double isoltrke=hpds[i].trackEnergySameTowers()+hpds[i].trackEnergyNeighborTowers();
173  if((isolhcale/ene<LooseHcalIsol_ && isolecale/ene<LooseEcalIsol_ && isoltrke/ene<LooseTrackIsol_ && ((trkfide>LooseHPDEne1_ && nhits>=LooseHPDHits1_) || (trkfide>LooseHPDEne2_ && nhits>=LooseHPDHits2_))) ||
174  (isolhcale/ene<TightHcalIsol_ && isolecale/ene<TightEcalIsol_ && isoltrke/ene<TightTrackIsol_ && ((trkfide>TightHPDEne1_ && nhits>=TightHPDHits1_) || (trkfide>TightHPDEne2_ && nhits>=TightHPDHits2_)))) {
175  for(HBHEHitMap::hitmap_const_iterator it=hpds[i].beginHits(); it!=hpds[i].endHits(); ++it)
176  noisehits.insert(it->first);
177  // result=false;
178  }
179  }
180 
181  for(int i=0; i<static_cast<int>(dihits.size()); i++) {
182  double ene=dihits[i].hitEnergy();
183  double trkfide=dihits[i].hitEnergyTrackFiducial();
184  double isolhcale=dihits[i].hcalEnergySameTowers()+dihits[i].hcalEnergyNeighborTowers();
185  double isolecale=dihits[i].ecalEnergySameTowers();
186  double isoltrke=dihits[i].trackEnergySameTowers()+dihits[i].trackEnergyNeighborTowers();
187  if((isolhcale/ene<LooseHcalIsol_ && isolecale/ene<LooseEcalIsol_ && isoltrke/ene<LooseTrackIsol_ && trkfide>0.99*ene && trkfide>LooseDiHitEne_) ||
188  (isolhcale/ene<TightHcalIsol_ && isolecale/ene<TightEcalIsol_ && isoltrke/ene<TightTrackIsol_ && ene>TightDiHitEne_)) {
189  for(HBHEHitMap::hitmap_const_iterator it=dihits[i].beginHits(); it!=dihits[i].endHits(); ++it)
190  noisehits.insert(it->first);
191  // result=false;
192  }
193  }
194 
195  for(int i=0; i<static_cast<int>(monohits.size()); i++) {
196  double ene=monohits[i].hitEnergy();
197  double trkfide=monohits[i].hitEnergyTrackFiducial();
198  double isolhcale=monohits[i].hcalEnergySameTowers()+monohits[i].hcalEnergyNeighborTowers();
199  double isolecale=monohits[i].ecalEnergySameTowers();
200  double isoltrke=monohits[i].trackEnergySameTowers()+monohits[i].trackEnergyNeighborTowers();
201  if((isolhcale/ene<LooseHcalIsol_ && isolecale/ene<LooseEcalIsol_ && isoltrke/ene<LooseTrackIsol_ && trkfide>0.99*ene && trkfide>LooseMonoHitEne_) ||
202  (isolhcale/ene<TightHcalIsol_ && isolecale/ene<TightEcalIsol_ && isoltrke/ene<TightTrackIsol_ && ene>TightMonoHitEne_)) {
203  for(HBHEHitMap::hitmap_const_iterator it=monohits[i].beginHits(); it!=monohits[i].endHits(); ++it)
204  noisehits.insert(it->first);
205  // result=false;
206  }
207  }
208 
209  // prepare the output HBHE RecHit collection
210  std::auto_ptr<HBHERecHitCollection> pOut(new HBHERecHitCollection());
211  // loop over rechits, and set the new bit you wish to use
212  for(HBHERecHitCollection::const_iterator it=hbhehits_h->begin(); it!=hbhehits_h->end(); ++it) {
213  const HBHERecHit* hit=&(*it);
214  HBHERecHit newhit(*hit);
215  if(noisehits.end()!=noisehits.find(hit)) {
217  }
218  pOut->push_back(newhit);
219  }
220 
221  iEvent.put(pOut);
222 
223  return;
224 }
225 
226 
227 void HBHEIsolatedNoiseReflagger::DumpHBHEHitMap(std::vector<HBHEHitMap>& i) const
228 {
229  for(std::vector<HBHEHitMap>::const_iterator it=i.begin(); it!=i.end(); ++it) {
230  edm::LogInfo("HBHEIsolatedNoiseReflagger") << "hit energy=" << it->hitEnergy()
231  << "; # hits=" << it->nHits()
232  << "; hcal energy same=" << it->hcalEnergySameTowers()
233  << "; ecal energy same=" << it->ecalEnergySameTowers()
234  << "; track energy same=" << it->trackEnergySameTowers()
235  << "; neighbor hcal energy=" << it->hcalEnergyNeighborTowers() << std::endl;
236  edm::LogInfo("HBHEIsolatedNoiseReflagger") << "hits:" << std::endl;
237  for(HBHEHitMap::hitmap_const_iterator it2=it->beginHits(); it2!=it->endHits(); ++it2) {
238  const HBHERecHit *hit=it2->first;
239  edm::LogInfo("HBHEIsolatedNoiseReflagger") << "RBX #=" << HcalHPDRBXMap::indexRBX(hit->id())
240  << "; HPD #=" << HcalHPDRBXMap::indexHPD(hit->id())
241  << "; " << (*hit) << std::endl;
242  }
243  }
244  return;
245 }
246 
247 
248 //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:449
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:113
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:55
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)