CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HLTHcalTowerNoiseCleanerWithrechit.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Class: HLTHcalTowerNoiseCleanerWithrechit
4 //
12 //
13 // Original Author: Alexander Mott
14 // Created: Mon Nov 21 11:32:00 CEST 2011
15 //
16 //
17 //
18 
19 
25 
27 
37 
41 
42 #include <iostream>
43 #include <string>
44 #include <fstream>
45 #include <TVector3.h>
46 #include <TLorentzVector.h>
47 #include <set>
48 
50 
51 //#include <Point.h>
52 
54  : HcalNoiseRBXCollectionTag_(iConfig.getParameter<edm::InputTag>("HcalNoiseRBXCollection")),
55  TowerCollectionTag_(iConfig.getParameter<edm::InputTag>("CaloTowerCollection")),
56  severity_(iConfig.getParameter<int> ("severity")),
57  maxNumRBXs_(iConfig.getParameter<int>("maxNumRBXs")),
58  numRBXsToConsider_(iConfig.getParameter<int>("numRBXsToConsider")),
59  needEMFCoincidence_(iConfig.getParameter<bool>("needEMFCoincidence")),
60  minRBXEnergy_(iConfig.getParameter<double>("minRBXEnergy")),
61  minRatio_(iConfig.getParameter<double>("minRatio")),
62  maxRatio_(iConfig.getParameter<double>("maxRatio")),
63  minHPDHits_(iConfig.getParameter<int>("minHPDHits")),
64  minRBXHits_(iConfig.getParameter<int>("minRBXHits")),
65  minHPDNoOtherHits_(iConfig.getParameter<int>("minHPDNoOtherHits")),
66  minZeros_(iConfig.getParameter<int>("minZeros")),
67  minHighEHitTime_(iConfig.getParameter<double>("minHighEHitTime")),
68  maxHighEHitTime_(iConfig.getParameter<double>("maxHighEHitTime")),
69  maxRBXEMF_(iConfig.getParameter<double>("maxRBXEMF")),
70  minRecHitE_(iConfig.getParameter<double>("minRecHitE")),
71  minLowHitE_(iConfig.getParameter<double>("minLowHitE")),
72  minHighHitE_(iConfig.getParameter<double>("minHighHitE")),
73  minR45HitE_(5.0),
74  TS4TS5EnergyThreshold_(iConfig.getParameter<double>("TS4TS5EnergyThreshold"))
75 {
76 
77  hltMinRBXRechitR45Cuts_ = iConfig.getParameter<std::vector<double> >("hltRBXRecHitR45Cuts");
78  std::vector<double> TS4TS5UpperThresholdTemp = iConfig.getParameter<std::vector<double> >("TS4TS5UpperThreshold");
79  std::vector<double> TS4TS5UpperCutTemp = iConfig.getParameter<std::vector<double> >("TS4TS5UpperCut");
80  std::vector<double> TS4TS5LowerThresholdTemp = iConfig.getParameter<std::vector<double> >("TS4TS5LowerThreshold");
81  std::vector<double> TS4TS5LowerCutTemp = iConfig.getParameter<std::vector<double> >("TS4TS5LowerCut");
82 
83  for(int i = 0; i < (int)TS4TS5UpperThresholdTemp.size() && i < (int)TS4TS5UpperCutTemp.size(); i++)
84  TS4TS5UpperCut_.push_back(std::pair<double, double>(TS4TS5UpperThresholdTemp[i], TS4TS5UpperCutTemp[i]));
85  sort(TS4TS5UpperCut_.begin(), TS4TS5UpperCut_.end());
86 
87  for(int i = 0; i < (int)TS4TS5LowerThresholdTemp.size() && i < (int)TS4TS5LowerCutTemp.size(); i++)
88  TS4TS5LowerCut_.push_back(std::pair<double, double>(TS4TS5LowerThresholdTemp[i], TS4TS5LowerCutTemp[i]));
89  sort(TS4TS5LowerCut_.begin(), TS4TS5LowerCut_.end());
90 
91  m_theHcalNoiseToken = consumes<reco::HcalNoiseRBXCollection>(HcalNoiseRBXCollectionTag_);
92  m_theCaloTowerCollectionToken = consumes<CaloTowerCollection>(TowerCollectionTag_);
93 
94  if(iConfig.existsAs<double>("minR45HitE"))
95  minR45HitE_ = iConfig.getParameter<double>("minR45HitE");
96 
97  produces<CaloTowerCollection>();
98 }
99 
100 
102 
103 void
106  desc.add<edm::InputTag>("HcalNoiseRBXCollection",edm::InputTag("hltHcalNoiseInfoProducer"));
107  desc.add<edm::InputTag>("CaloTowerCollection",edm::InputTag("hltTowerMakerForAll"));
108  desc.add<double>("maxTowerNoiseEnergyFraction",0.5);
109  desc.add<int>("severity",1);
110  desc.add<int>("maxNumRBXs",2);
111  desc.add<int>("numRBXsToConsider",2);
112  desc.add<bool>("needEMFCoincidence",true);
113  desc.add<double>("minRBXEnergy",50.0);
114  desc.add<double>("minRatio",-999.);
115  desc.add<double>("maxRatio",999.);
116  desc.add<int>("minHPDHits",17);
117  desc.add<int>("minRBXHits",999);
118  desc.add<int>("minHPDNoOtherHits",10);
119  desc.add<int>("minZeros",10);
120  desc.add<double>("minHighEHitTime",-9999.0);
121  desc.add<double>("maxHighEHitTime",9999.0);
122  desc.add<double>("maxRBXEMF",0.02);
123  desc.add<double>("minRecHitE",1.5);
124  desc.add<double>("minLowHitE",10.0);
125  desc.add<double>("minHighHitE",25.0);
126  desc.add<double>("minR45HitE",5.0);
127  desc.add<double>("TS4TS5EnergyThreshold",50.0);
128 
129  double TS4TS5UpperThresholdArray[5] = {70, 90, 100, 400, 4000 };
130  double TS4TS5UpperCutArray[5] = {1, 0.8, 0.75, 0.72, 0.72};
131  double TS4TS5LowerThresholdArray[7] = {100, 120, 150, 200, 300, 400, 500};
132  double TS4TS5LowerCutArray[7] = {-1, -0.7, -0.4, -0.2, -0.08, 0, 0.1};
133  double hltRBXRecHitR45CutsArray[8] = { 0.0, 1.0, 0.0, -1.0, 0.0, 0.0, 1.0, -1.0 };
134  std::vector<double> TS4TS5UpperThreshold(TS4TS5UpperThresholdArray, TS4TS5UpperThresholdArray+5);
135  std::vector<double> TS4TS5UpperCut(TS4TS5UpperCutArray, TS4TS5UpperCutArray+5);
136  std::vector<double> TS4TS5LowerThreshold(TS4TS5LowerThresholdArray, TS4TS5LowerThresholdArray+7);
137  std::vector<double> TS4TS5LowerCut(TS4TS5LowerCutArray, TS4TS5LowerCutArray+7);
138  std::vector<double> hltRBXRecHitR45Cuts(hltRBXRecHitR45CutsArray, hltRBXRecHitR45CutsArray+8);
139 
140  desc.add<std::vector<double> >("TS4TS5UpperThreshold", TS4TS5UpperThreshold);
141  desc.add<std::vector<double> >("TS4TS5UpperCut", TS4TS5UpperCut);
142  desc.add<std::vector<double> >("TS4TS5LowerThreshold", TS4TS5LowerThreshold);
143  desc.add<std::vector<double> >("TS4TS5LowerCut", TS4TS5LowerCut);
144  desc.add<std::vector<double> >("hltRBXRecHitR45Cuts", hltRBXRecHitR45Cuts);
145  descriptions.add("hltHcalTowerNoiseCleanerWithrechit",desc);
146 }
147 
148 //
149 // member functions
150 //
151 
153 {
154  using namespace reco;
155 
156 
157  edm::ESHandle<CaloTowerTopology> caloTowerTopology;
158  iSetup.get<HcalRecNumberingRecord>().get(caloTowerTopology);
159 
160 
161  //get the calo MET / MHT
164 
165  std::set<unsigned int> noisyTowers;
166 
167  if(not tower_h.isValid()){ //No towers MET, don't do anything and accept the event
168  edm::LogError("HLTHcalTowerNoiseCleanerWithrechit") << "Input Tower Collection is not Valid";
169  return;
170  }
171 
172 
173  // get the RBXs produced by RecoMET/METProducers/HcalNoiseInfoProducer
175  iEvent.getByToken(m_theHcalNoiseToken,rbxs_h);
176  if(!rbxs_h.isValid()) {
177  edm::LogWarning("HLTHcalTowerNoiseCleanerWithrechit") << "Could not find HcalNoiseRBXCollection product named "
178  << HcalNoiseRBXCollectionTag_ << "." << std::endl;
179  severity_=0;
180  }
181 
182  // create a sorted set of the RBXs, ordered by energy
184  for(HcalNoiseRBXCollection::const_iterator it=rbxs_h->begin(); it!=rbxs_h->end(); ++it) {
185  const HcalNoiseRBX &rbx=(*it);
188  data.insert(d);
189  }
190 
191  // data is now sorted by RBX energy
192  // only consider top N=numRBXsToConsider_ energy RBXs
193  if(severity_>0){
194  for(noisedataset_t::const_iterator it=data.begin();
195  it!=data.end();
196  it++) {
197  // Check the Rechit-R45 filter
198  // Taken from http://cmslxr.fnal.gov/lxr/source/RecoMET/METAlgorithms/src/HcalNoiseAlgo.cc?v=CMSSW_7_4_6#0256
199  bool passRechitr45 = true;
200  int r45Count = it->r45Count();
201  double r45Fraction = it->r45Fraction();
202  double r45EnergyFraction = it->r45EnergyFraction();
203  for(int i = 0; i + 3 < (int)hltMinRBXRechitR45Cuts_.size(); i = i + 4) {
204  double Value = r45Count * hltMinRBXRechitR45Cuts_[i] + r45Fraction * hltMinRBXRechitR45Cuts_[i+1] + r45EnergyFraction * hltMinRBXRechitR45Cuts_[i+2] + hltMinRBXRechitR45Cuts_[i+3];
205  if (Value > 0) passRechitr45=false;
206  }
207 
208  bool passFilter=true;
209  bool passEMF=true;
210  if(it->energy()>minRBXEnergy_) {
211  if(it->validRatio() && it->ratio()<minRatio_) passFilter=false;
212  else if(it->validRatio() && it->ratio()>maxRatio_) passFilter=false;
213  else if(it->numHPDHits()>=minHPDHits_) passFilter=false;
214  else if(it->numRBXHits()>=minRBXHits_) passFilter=false;
215  else if(it->numHPDNoOtherHits()>=minHPDNoOtherHits_) passFilter=false;
216  else if(it->numZeros()>=minZeros_) passFilter=false;
217  else if(it->minHighEHitTime()<minHighEHitTime_) passFilter=false;
218  else if(it->maxHighEHitTime()>maxHighEHitTime_) passFilter=false;
219  else if (passRechitr45==false) passFilter=false;
220  if(it->RBXEMF()<maxRBXEMF_){
221  passEMF=false;
222  }
223  }
224 
225  if((needEMFCoincidence_ && !passEMF && !passFilter) ||
226  (!needEMFCoincidence_ && !passFilter)) { // check for noise
227  LogDebug("") << "HLTHcalTowerNoiseCleanerWithrechit debug: Found a noisy RBX: "
228  << "energy=" << it->energy() << "; "
229  << "ratio=" << it->ratio() << "; "
230  << "# RBX hits=" << it->numRBXHits() << "; "
231  << "# HPD hits=" << it->numHPDHits() << "; "
232  << "# Zeros=" << it->numZeros() << "; "
233  << "min time=" << it->minHighEHitTime() << "; "
234  << "max time=" << it->maxHighEHitTime() << "; "
235  << "RBX EMF=" << it->RBXEMF()
236  << std::endl;
237  // add calotowers associated with this RBX to the noise list
238  edm::RefVector<CaloTowerCollection> noiseTowers = it->rbxTowers();
240  //add these calotowers to the noisy list
241  for( noiseTowersIt = noiseTowers.begin(); noiseTowersIt != noiseTowers.end(); noiseTowersIt++){
242  edm::Ref<edm::SortedCollection<CaloTower> > tower_ref = *noiseTowersIt;
243  CaloTowerDetId id = tower_ref->id();
244  noisyTowers.insert( caloTowerTopology->denseIndex(id) );
245  }}
246  } // done with noise loop
247  }//if(severity_>0)
248 
249  //output collection
250  std::auto_ptr<CaloTowerCollection> OutputTowers(new CaloTowerCollection() );
251 
253 
254  for(inTowersIt = tower_h->begin(); inTowersIt != tower_h->end(); inTowersIt++){
255  const CaloTower & tower = (*inTowersIt);
256  CaloTowerDetId id = tower.id();
257 
258  if(noisyTowers.find( caloTowerTopology->denseIndex(id) ) == noisyTowers.end()){ // the tower is not noisy
259  OutputTowers->push_back(*inTowersIt);
260  }
261  }
262  iEvent.put(OutputTowers);
263 
264 }
265 
266 
#define LogDebug(id)
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:186
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
edm::EDGetTokenT< CaloTowerCollection > m_theCaloTowerCollectionToken
std::vector< CaloTower >::const_iterator const_iterator
std::vector< std::pair< double, double > > TS4TS5UpperCut_
const_iterator end() const
Termination of iteration.
Definition: RefVector.h:255
ProductID id() const
Accessor for product ID.
Definition: Ref.h:258
const_iterator begin() const
Initialize an iterator over the RefVector.
Definition: RefVector.h:250
tuple d
Definition: ztail.py:151
std::set< CommonHcalNoiseRBXData, noisedatacomp > noisedataset_t
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:120
reco::JetExtendedAssociation::JetExtendedData Value
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
CaloTowerDetId id() const
Definition: CaloTower.h:102
const T & get() const
Definition: EventSetup.h:56
void add(std::string const &label, ParameterSetDescription const &psetDescription)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
edm::SortedCollection< CaloTower > CaloTowerCollection
Definition: CaloTowerFwd.h:15
edm::EDGetTokenT< reco::HcalNoiseRBXCollection > m_theHcalNoiseToken
std::vector< std::pair< double, double > > TS4TS5LowerCut_
virtual void produce(edm::Event &, const edm::EventSetup &)