CMS 3D CMS Logo

HLTHcalMETNoiseCleaner.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Class: HLTHcalMETNoiseCleaner
4 //
12 //
13 // Original Author: Alexander Mott
14 // Created: Mon Nov 21 11:32:00 CEST 2011
15 //
16 //
17 //
18 
20 
26 
28 
35 
39 
40 #include <iostream>
41 #include <string>
42 #include <fstream>
43 #include <TVector3.h>
44 #include <TLorentzVector.h>
45 //#include <Point.h>
46 
48  : HcalNoiseRBXCollectionTag_(iConfig.getParameter<edm::InputTag>("HcalNoiseRBXCollection")),
49  CaloMetCollectionTag_(iConfig.getParameter<edm::InputTag>("CaloMetCollection")),
50  CaloMetCut_(iConfig.getParameter<double>("CaloMetCut")),
51  severity_(iConfig.getParameter<int> ("severity")),
52  maxNumRBXs_(iConfig.getParameter<int>("maxNumRBXs")),
53  numRBXsToConsider_(iConfig.getParameter<int>("numRBXsToConsider")),
54  accept2NoiseRBXEvents_(iConfig.getParameter<bool>("accept2NoiseRBXEvents")),
55  needEMFCoincidence_(iConfig.getParameter<bool>("needEMFCoincidence")),
56  minRBXEnergy_(iConfig.getParameter<double>("minRBXEnergy")),
57  minRatio_(iConfig.getParameter<double>("minRatio")),
58  maxRatio_(iConfig.getParameter<double>("maxRatio")),
59  minHPDHits_(iConfig.getParameter<int>("minHPDHits")),
60  minRBXHits_(iConfig.getParameter<int>("minRBXHits")),
61  minHPDNoOtherHits_(iConfig.getParameter<int>("minHPDNoOtherHits")),
62  minZeros_(iConfig.getParameter<int>("minZeros")),
63  minHighEHitTime_(iConfig.getParameter<double>("minHighEHitTime")),
64  maxHighEHitTime_(iConfig.getParameter<double>("maxHighEHitTime")),
65  maxRBXEMF_(iConfig.getParameter<double>("maxRBXEMF")),
66  minRecHitE_(iConfig.getParameter<double>("minRecHitE")),
67  minLowHitE_(iConfig.getParameter<double>("minLowHitE")),
68  minHighHitE_(iConfig.getParameter<double>("minHighHitE")),
69  minR45HitE_(5.0),
70  TS4TS5EnergyThreshold_(iConfig.getParameter<double>("TS4TS5EnergyThreshold"))
71 {
72 
73  std::vector<double> TS4TS5UpperThresholdTemp = iConfig.getParameter<std::vector<double> >("TS4TS5UpperThreshold");
74  std::vector<double> TS4TS5UpperCutTemp = iConfig.getParameter<std::vector<double> >("TS4TS5UpperCut");
75  std::vector<double> TS4TS5LowerThresholdTemp = iConfig.getParameter<std::vector<double> >("TS4TS5LowerThreshold");
76  std::vector<double> TS4TS5LowerCutTemp = iConfig.getParameter<std::vector<double> >("TS4TS5LowerCut");
77 
78  for(int i = 0; i < (int)TS4TS5UpperThresholdTemp.size() && i < (int)TS4TS5UpperCutTemp.size(); i++)
79  TS4TS5UpperCut_.push_back(std::pair<double, double>(TS4TS5UpperThresholdTemp[i], TS4TS5UpperCutTemp[i]));
80  sort(TS4TS5UpperCut_.begin(), TS4TS5UpperCut_.end());
81 
82  for(int i = 0; i < (int)TS4TS5LowerThresholdTemp.size() && i < (int)TS4TS5LowerCutTemp.size(); i++)
83  TS4TS5LowerCut_.push_back(std::pair<double, double>(TS4TS5LowerThresholdTemp[i], TS4TS5LowerCutTemp[i]));
84  sort(TS4TS5LowerCut_.begin(), TS4TS5LowerCut_.end());
85 
86  m_theCaloMetToken = consumes<reco::CaloMETCollection>(CaloMetCollectionTag_);
87  m_theHcalNoiseToken = consumes<reco::HcalNoiseRBXCollection>(HcalNoiseRBXCollectionTag_);
88 
89  if(iConfig.existsAs<double>("minR45HitE"))
90  minR45HitE_ = iConfig.getParameter<double>("minR45HitE");
91 
92  produces<reco::CaloMETCollection>();
93 }
94 
95 
97 
98 void
101  desc.add<edm::InputTag>("HcalNoiseRBXCollection",edm::InputTag("hltHcalNoiseInfoProducer"));
102  desc.add<edm::InputTag>("CaloMetCollection",edm::InputTag("hltMet"));
103  desc.add<double>("CaloMetCut",0.0);
104  desc.add<int>("severity",1);
105  desc.add<int>("maxNumRBXs",2);
106  desc.add<int>("numRBXsToConsider",2);
107  desc.add<bool>("accept2NoiseRBXEvents",true);
108  desc.add<bool>("needEMFCoincidence",true);
109  desc.add<double>("minRBXEnergy",50.0);
110  desc.add<double>("minRatio",-999.);
111  desc.add<double>("maxRatio",999.);
112  desc.add<int>("minHPDHits",17);
113  desc.add<int>("minRBXHits",999);
114  desc.add<int>("minHPDNoOtherHits",10);
115  desc.add<int>("minZeros",10);
116  desc.add<double>("minHighEHitTime",-9999.0);
117  desc.add<double>("maxHighEHitTime",9999.0);
118  desc.add<double>("maxRBXEMF",0.02);
119  desc.add<double>("minRecHitE",1.5);
120  desc.add<double>("minLowHitE",10.0);
121  desc.add<double>("minHighHitE",25.0);
122  desc.add<double>("minR45HitE",5.0);
123  desc.add<double>("TS4TS5EnergyThreshold",50.0);
124 
125  double TS4TS5UpperThresholdArray[5] = {70, 90, 100, 400, 4000 };
126  double TS4TS5UpperCutArray[5] = {1, 0.8, 0.75, 0.72, 0.72};
127  double TS4TS5LowerThresholdArray[7] = {100, 120, 150, 200, 300, 400, 500};
128  double TS4TS5LowerCutArray[7] = {-1, -0.7, -0.4, -0.2, -0.08, 0, 0.1};
129  std::vector<double> TS4TS5UpperThreshold(TS4TS5UpperThresholdArray, TS4TS5UpperThresholdArray+5);
130  std::vector<double> TS4TS5UpperCut(TS4TS5UpperCutArray, TS4TS5UpperCutArray+5);
131  std::vector<double> TS4TS5LowerThreshold(TS4TS5LowerThresholdArray, TS4TS5LowerThresholdArray+7);
132  std::vector<double> TS4TS5LowerCut(TS4TS5LowerCutArray, TS4TS5LowerCutArray+7);
133 
134  desc.add<std::vector<double> >("TS4TS5UpperThreshold", TS4TS5UpperThreshold);
135  desc.add<std::vector<double> >("TS4TS5UpperCut", TS4TS5UpperCut);
136  desc.add<std::vector<double> >("TS4TS5LowerThreshold", TS4TS5LowerThreshold);
137  desc.add<std::vector<double> >("TS4TS5LowerCut", TS4TS5LowerCut);
138  descriptions.add("hltHcalMETNoiseCleaner",desc);
139 }
140 
141 //
142 // member functions
143 //
144 
146 {
147  using namespace reco;
148 
149  //output collection
150  std::unique_ptr<CaloMETCollection> CleanedMET(new CaloMETCollection);
151 
152  //get the calo MET / MHT
154  iEvent.getByToken(m_theCaloMetToken,met_h);
155 
156  if(not met_h.isValid() or met_h->size()==0 or met_h->front().pt()<0){ //No Valid MET, don't do anything and accept the event
157  return true; // we shouldn't get here, but lets not crash
158  }
159 
160  reco::CaloMET inCaloMet = met_h->front();
161 
162 
163  // in this case, do not filter anything
164  if(severity_==0){
165  CleanedMET->push_back(inCaloMet);
166  iEvent.put(std::move(CleanedMET));
167  return true;
168  }
169 
170  // get the RBXs produced by RecoMET/METProducers/HcalNoiseInfoProducer
172  iEvent.getByToken(m_theHcalNoiseToken,rbxs_h);
173  if(!rbxs_h.isValid()) {
174  edm::LogError("DataNotFound") << "HLTHcalMETNoiseCleaner: Could not find HcalNoiseRBXCollection product named "
175  << HcalNoiseRBXCollectionTag_ << "." << std::endl;
176  CleanedMET->push_back(inCaloMet);
177  iEvent.put(std::move(CleanedMET));
178  return true; // no valid RBXs
179  }
180 
181  // create a sorted set of the RBXs, ordered by energy
183  for(auto const & rbx : *rbxs_h) {
186  data.insert(d);
187  }
188  //if 0 RBXs are in the list, just accept
189  if(data.size()<1){
190  CleanedMET->push_back(inCaloMet);
191  iEvent.put(std::move(CleanedMET));
192  return true;
193  }
194  // data is now sorted by RBX energy
195  // only consider top N=numRBXsToConsider_ energy RBXs
196  int cntr=0;
197  int nNoise=0;
198 
199  TVector3 metVec;
200  metVec.SetPtEtaPhi(met_h->front().pt(), 0, met_h->front().phi() );
201 
202  TVector3 noiseHPDVector(0,0,0);
203  TVector3 secondHPDVector(0,0,0);
204  for(auto it=data.begin();
205  it!=data.end() && cntr<numRBXsToConsider_;
206  it++, cntr++) {
207  bool isNoise=false;
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(!it->PassTS4TS5()) passFilter=false;
220 
221  if(it->RBXEMF()<maxRBXEMF_){
222  passEMF=false;
223  }
224  }
225 
226  if((needEMFCoincidence_ && !passEMF && !passFilter) ||
227  (!needEMFCoincidence_ && !passFilter)) { // check for noise
228  LogDebug("") << "HLTHcalMETNoiseCleaner debug: Found a noisy RBX: "
229  << "energy=" << it->energy() << "; "
230  << "ratio=" << it->ratio() << "; "
231  << "# RBX hits=" << it->numRBXHits() << "; "
232  << "# HPD hits=" << it->numHPDHits() << "; "
233  << "# Zeros=" << it->numZeros() << "; "
234  << "min time=" << it->minHighEHitTime() << "; "
235  << "max time=" << it->maxHighEHitTime() << "; "
236  << "passTS4TS5=" << it->PassTS4TS5() << "; "
237  << "RBX EMF=" << it->RBXEMF()
238  << std::endl;
239  nNoise++;
240  isNoise=true;
241  }// OK, checked for noise
242 
243  //------------First Noisy RBX-----------------------
244  if(isNoise && nNoise==1){
245  edm::RefVector<CaloTowerCollection> noiseTowers = it->rbxTowers();
247  // get the energy vector for this RBX from the calotowers
248  for( noiseTowersIt = noiseTowers.begin(); noiseTowersIt != noiseTowers.end(); noiseTowersIt++){
249  TVector3 towerVec;
250  towerVec.SetPtEtaPhi((*noiseTowersIt)->pt(),(*noiseTowersIt)->eta(),(*noiseTowersIt)->phi());
251  noiseHPDVector+=towerVec; // add this tower to the vector for the RBX
252  }
253  if(noiseHPDVector.Mag()>0) noiseHPDVector.SetPtEtaPhi(noiseHPDVector.Pt(),0,noiseHPDVector.Phi()); // make the noise transverse
254  else noiseHPDVector.SetPtEtaPhi(0,0,0);
255  }
256  //-----------FOUND a SECOND NOISY RBX-------------------
257  if(isNoise && cntr > 0){
258  CleanedMET->push_back(inCaloMet);
259  iEvent.put(std::move(CleanedMET));
260  return accept2NoiseRBXEvents_; // don't try to clean these for the moment, just keep or throw away
261  }
262  //----------LEADING RBX is NOT NOISY--------------------
263  if(!isNoise && cntr == 0){
264  CleanedMET->push_back(inCaloMet);
265  iEvent.put(std::move(CleanedMET));
266  return true; // don't reject the event if the leading RBX isn't noise
267  }
268  //-----------SUBLEADING RBX is NOT NOISY: STORE INFO----
269  if(!isNoise && nNoise>0){ //second RBX isn't noisy (and first one was), so clean
270  edm::RefVector<CaloTowerCollection> noiseTowers = it->rbxTowers();
272  for( noiseTowersIt = noiseTowers.begin(); noiseTowersIt != noiseTowers.end(); noiseTowersIt++){
273  TVector3 towerVec;
274  towerVec.SetPtEtaPhi((*noiseTowersIt)->pt(),(*noiseTowersIt)->eta(),(*noiseTowersIt)->phi());
275  secondHPDVector+=towerVec; // add this tower to the vector for the RBX
276  }
277  if(secondHPDVector.Mag()>0) secondHPDVector.SetPtEtaPhi(secondHPDVector.Pt(),0,secondHPDVector.Phi()); // make the second transverse
278  else secondHPDVector.SetPtEtaPhi(0,0,0);
279  break;
280  }
281  } // end RBX loop
282 
283  if(noiseHPDVector.Mag()==0){
284  CleanedMET->push_back(inCaloMet);
285  iEvent.put(std::move(CleanedMET));
286  return true; // don't reject the event if the leading RBX isn't noise
287  }
288 
289  //********************************************************************************
290  //The Event gets here only if it had exactly 1 noisy RBX in the lead position
291  //********************************************************************************
292 
293  float METsumet = met_h->front().energy();
294 
295  metVec+=noiseHPDVector;
296 
297  float ZMETsumet = METsumet-noiseHPDVector.Mag();
298  float ZMETpt = metVec.Pt();
299  float ZMETphi = metVec.Phi();
300 
301  //put the second RBX vector in the eta phi position of the leading RBX vector
302 
303  float SMETsumet = 0;
304  float SMETpt = 0;
305  float SMETphi = 0;
306  if(secondHPDVector.Mag()>0.){
307  secondHPDVector.SetPtEtaPhi(secondHPDVector.Pt(),noiseHPDVector.Eta(),noiseHPDVector.Phi());
308  metVec-= secondHPDVector;
309  SMETsumet = METsumet-noiseHPDVector.Mag();
310  SMETpt = metVec.Pt();
311  SMETphi = metVec.Phi();
312  }
313  //Get the maximum MET:
314  float CorMetSumEt,CorMetPt,CorMetPhi;
315  if(ZMETpt>SMETpt){
316  CorMetSumEt = ZMETsumet;
317  CorMetPt = ZMETpt;
318  CorMetPhi = ZMETphi;
319  }else{
320  CorMetSumEt = SMETsumet;
321  CorMetPt = SMETpt;
322  CorMetPhi = SMETphi;
323  }
324 
325  reco::CaloMET corMet = BuildCaloMet(CorMetSumEt,CorMetPt,CorMetPhi);
326  CleanedMET->push_back(corMet);
327  iEvent.put(std::move(CleanedMET));
328 
329  return (corMet.pt() > CaloMetCut_);
330 }
331 
333  // Instantiate the container to hold the calorimeter specific information
334 
335  typedef math::XYZPoint Point;
337 
338  SpecificCaloMETData specific;
339  // Initialise the container
340  specific.MaxEtInEmTowers = 0.0; // Maximum energy in EM towers
341  specific.MaxEtInHadTowers = 0.0; // Maximum energy in HCAL towers
342  specific.HadEtInHO = 0.0; // Hadronic energy fraction in HO
343  specific.HadEtInHB = 0.0; // Hadronic energy in HB
344  specific.HadEtInHF = 0.0; // Hadronic energy in HF
345  specific.HadEtInHE = 0.0; // Hadronic energy in HE
346  specific.EmEtInEB = 0.0; // Em energy in EB
347  specific.EmEtInEE = 0.0; // Em energy in EE
348  specific.EmEtInHF = 0.0; // Em energy in HF
349  specific.EtFractionHadronic = 0.0; // Hadronic energy fraction
350  specific.EtFractionEm = 0.0; // Em energy fraction
351  specific.CaloSETInpHF = 0.0; // CaloSET in HF+
352  specific.CaloSETInmHF = 0.0; // CaloSET in HF-
353  specific.CaloMETInpHF = 0.0; // CaloMET in HF+
354  specific.CaloMETInmHF = 0.0; // CaloMET in HF-
355  specific.CaloMETPhiInpHF = 0.0; // CaloMET-phi in HF+
356  specific.CaloMETPhiInmHF = 0.0; // CaloMET-phi in HF-
357  specific.METSignificance = 0.0;
358 
359  TLorentzVector p4TL;
360  p4TL.SetPtEtaPhiM(pt,0.,phi,0.);
361  const LorentzVector p4(p4TL.X(),p4TL.Y(),0,p4TL.T());
362  const Point vtx( 0.0, 0.0, 0.0 );
363  reco::CaloMET specificmet( specific, sumet, p4, vtx );
364  return specificmet;
365  }
366 
#define LogDebug(id)
T getParameter(std::string const &) const
virtual double pt() const final
transverse momentum
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
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:460
std::vector< std::pair< double, double > > TS4TS5UpperCut_
edm::EDGetTokenT< reco::CaloMETCollection > m_theCaloMetToken
std::set< CommonHcalNoiseRBXData, noisedatacomp > noisedataset_t
const_iterator end() const
Termination of iteration.
Definition: RefVector.h:253
std::pair< double, double > Point
Definition: CaloEllipse.h:18
reco::CaloMET BuildCaloMet(float sumet, float pt, float phi)
const_iterator begin() const
Initialize an iterator over the RefVector.
Definition: RefVector.h:248
virtual bool filter(edm::Event &, const edm::EventSetup &)
Collection of Calo MET.
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
int iEvent
Definition: GenABIO.cc:230
double p4[4]
Definition: TauolaWrapper.h:92
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
HLTHcalMETNoiseCleaner(const edm::ParameterSet &)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
bool isValid() const
Definition: HandleBase.h:74
edm::InputTag HcalNoiseRBXCollectionTag_
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
edm::EDGetTokenT< reco::HcalNoiseRBXCollection > m_theHcalNoiseToken
void add(std::string const &label, ParameterSetDescription const &psetDescription)
fixed size matrix
HLT enums.
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
def move(src, dest)
Definition: eostools.py:510
math::PtEtaPhiELorentzVectorF LorentzVector
std::vector< std::pair< double, double > > TS4TS5LowerCut_