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