CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HLTHcalTowerNoiseCleaner.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Class: HLTHcalTowerNoiseCleaner
4 //
12 //
13 // Original Author: Alexander Mott
14 // Created: Mon Nov 21 11:32:00 CEST 2011
15 //
16 //
17 //
18 
19 
25 
27 
34 
38 
39 #include <iostream>
40 #include <string>
41 #include <fstream>
42 #include <TVector3.h>
43 #include <TLorentzVector.h>
44 #include <set>
45 
47 
48 //#include <Point.h>
49 
51  : HcalNoiseRBXCollectionTag_(iConfig.getParameter<edm::InputTag>("HcalNoiseRBXCollection")),
52  TowerCollectionTag_(iConfig.getParameter<edm::InputTag>("CaloTowerCollection")),
53  severity_(iConfig.getParameter<int> ("severity")),
54  maxNumRBXs_(iConfig.getParameter<int>("maxNumRBXs")),
55  numRBXsToConsider_(iConfig.getParameter<int>("numRBXsToConsider")),
56  needEMFCoincidence_(iConfig.getParameter<bool>("needEMFCoincidence")),
57  minRBXEnergy_(iConfig.getParameter<double>("minRBXEnergy")),
58  minRatio_(iConfig.getParameter<double>("minRatio")),
59  maxRatio_(iConfig.getParameter<double>("maxRatio")),
60  minHPDHits_(iConfig.getParameter<int>("minHPDHits")),
61  minRBXHits_(iConfig.getParameter<int>("minRBXHits")),
62  minHPDNoOtherHits_(iConfig.getParameter<int>("minHPDNoOtherHits")),
63  minZeros_(iConfig.getParameter<int>("minZeros")),
64  minHighEHitTime_(iConfig.getParameter<double>("minHighEHitTime")),
65  maxHighEHitTime_(iConfig.getParameter<double>("maxHighEHitTime")),
66  maxRBXEMF_(iConfig.getParameter<double>("maxRBXEMF")),
67  minRecHitE_(iConfig.getParameter<double>("minRecHitE")),
68  minLowHitE_(iConfig.getParameter<double>("minLowHitE")),
69  minHighHitE_(iConfig.getParameter<double>("minHighHitE")),
70  minR45HitE_(5.0),
71  TS4TS5EnergyThreshold_(iConfig.getParameter<double>("TS4TS5EnergyThreshold"))
72 {
73 
74  std::vector<double> TS4TS5UpperThresholdTemp = iConfig.getParameter<std::vector<double> >("TS4TS5UpperThreshold");
75  std::vector<double> TS4TS5UpperCutTemp = iConfig.getParameter<std::vector<double> >("TS4TS5UpperCut");
76  std::vector<double> TS4TS5LowerThresholdTemp = iConfig.getParameter<std::vector<double> >("TS4TS5LowerThreshold");
77  std::vector<double> TS4TS5LowerCutTemp = iConfig.getParameter<std::vector<double> >("TS4TS5LowerCut");
78 
79  for(int i = 0; i < (int)TS4TS5UpperThresholdTemp.size() && i < (int)TS4TS5UpperCutTemp.size(); i++)
80  TS4TS5UpperCut_.push_back(std::pair<double, double>(TS4TS5UpperThresholdTemp[i], TS4TS5UpperCutTemp[i]));
81  sort(TS4TS5UpperCut_.begin(), TS4TS5UpperCut_.end());
82 
83  for(int i = 0; i < (int)TS4TS5LowerThresholdTemp.size() && i < (int)TS4TS5LowerCutTemp.size(); i++)
84  TS4TS5LowerCut_.push_back(std::pair<double, double>(TS4TS5LowerThresholdTemp[i], TS4TS5LowerCutTemp[i]));
85  sort(TS4TS5LowerCut_.begin(), TS4TS5LowerCut_.end());
86 
87  m_theHcalNoiseToken = consumes<reco::HcalNoiseRBXCollection>(HcalNoiseRBXCollectionTag_);
88  m_theCaloTowerCollectionToken = consumes<CaloTowerCollection>(TowerCollectionTag_);
89 
90  if(iConfig.existsAs<double>("minR45HitE"))
91  minR45HitE_ = iConfig.getParameter<double>("minR45HitE");
92 
93  produces<CaloTowerCollection>();
94 }
95 
96 
98 
99 void
102  desc.add<edm::InputTag>("HcalNoiseRBXCollection",edm::InputTag("hltHcalNoiseInfoProducer"));
103  desc.add<edm::InputTag>("CaloTowerCollection",edm::InputTag("hltTowerMakerForAll"));
104  desc.add<double>("maxTowerNoiseEnergyFraction",0.5);
105  desc.add<int>("severity",1);
106  desc.add<int>("maxNumRBXs",2);
107  desc.add<int>("numRBXsToConsider",2);
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("hltHcalTowerNoiseCleaner",desc);
139 }
140 
141 //
142 // member functions
143 //
144 
146 {
147  using namespace reco;
148 
149  //get the calo MET / MHT
152 
153  std::set<unsigned int> noisyTowers;
154 
155  if(not tower_h.isValid()){ //No towers MET, don't do anything and accept the event
156  edm::LogError("HLTHcalTowerNoiseCleaner") << "Input Tower Collection is not Valid";
157  return;
158  }
159 
160 
161  // get the RBXs produced by RecoMET/METProducers/HcalNoiseInfoProducer
163  iEvent.getByToken(m_theHcalNoiseToken,rbxs_h);
164  if(!rbxs_h.isValid()) {
165  edm::LogWarning("HLTHcalTowerNoiseCleaner") << "Could not find HcalNoiseRBXCollection product named "
166  << HcalNoiseRBXCollectionTag_ << "." << std::endl;
167  severity_=0;
168  }
169 
170  // create a sorted set of the RBXs, ordered by energy
172  for(HcalNoiseRBXCollection::const_iterator it=rbxs_h->begin(); it!=rbxs_h->end(); ++it) {
173  const HcalNoiseRBX &rbx=(*it);
176  data.insert(d);
177  }
178 
179  // data is now sorted by RBX energy
180  // only consider top N=numRBXsToConsider_ energy RBXs
181  if(severity_>0){
182  for(noisedataset_t::const_iterator it=data.begin();
183  it!=data.end();
184  it++) {
185 
186 
187  bool passFilter=true;
188  bool passEMF=true;
189  if(it->energy()>minRBXEnergy_) {
190  if(it->validRatio() && it->ratio()<minRatio_) passFilter=false;
191  else if(it->validRatio() && it->ratio()>maxRatio_) passFilter=false;
192  else if(it->numHPDHits()>=minHPDHits_) passFilter=false;
193  else if(it->numRBXHits()>=minRBXHits_) passFilter=false;
194  else if(it->numHPDNoOtherHits()>=minHPDNoOtherHits_) passFilter=false;
195  else if(it->numZeros()>=minZeros_) passFilter=false;
196  else if(it->minHighEHitTime()<minHighEHitTime_) passFilter=false;
197  else if(it->maxHighEHitTime()>maxHighEHitTime_) passFilter=false;
198  else if(!it->PassTS4TS5()) passFilter=false;
199 
200  if(it->RBXEMF()<maxRBXEMF_){
201  passEMF=false;
202  }
203  }
204 
205  if((needEMFCoincidence_ && !passEMF && !passFilter) ||
206  (!needEMFCoincidence_ && !passFilter)) { // check for noise
207  LogDebug("") << "HLTHcalTowerNoiseCleaner debug: Found a noisy RBX: "
208  << "energy=" << it->energy() << "; "
209  << "ratio=" << it->ratio() << "; "
210  << "# RBX hits=" << it->numRBXHits() << "; "
211  << "# HPD hits=" << it->numHPDHits() << "; "
212  << "# Zeros=" << it->numZeros() << "; "
213  << "min time=" << it->minHighEHitTime() << "; "
214  << "max time=" << it->maxHighEHitTime() << "; "
215  << "passTS4TS5=" << it->PassTS4TS5() << "; "
216  << "RBX EMF=" << it->RBXEMF()
217  << std::endl;
218  // add calotowers associated with this RBX to the noise list
219  edm::RefVector<CaloTowerCollection> noiseTowers = it->rbxTowers();
221  //add these calotowers to the noisy list
222  for( noiseTowersIt = noiseTowers.begin(); noiseTowersIt != noiseTowers.end(); noiseTowersIt++){
223  edm::Ref<edm::SortedCollection<CaloTower> > tower_ref = *noiseTowersIt;
224  CaloTowerDetId id = tower_ref->id();
225  noisyTowers.insert( id.denseIndex() );
226  }}
227  } // done with noise loop
228  }//if(severity_>0)
229 
230  //output collection
231  std::auto_ptr<CaloTowerCollection> OutputTowers(new CaloTowerCollection() );
232 
234 
235  for(inTowersIt = tower_h->begin(); inTowersIt != tower_h->end(); inTowersIt++){
236  const CaloTower & tower = (*inTowersIt);
237  CaloTowerDetId id = tower.id();
238  if(noisyTowers.find( id.denseIndex() ) == noisyTowers.end()){ // the tower is not noisy
239  OutputTowers->push_back(*inTowersIt);
240  }
241  }
242  iEvent.put(OutputTowers);
243 
244 }
245 
246 
#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:184
HLTHcalTowerNoiseCleaner(const edm::ParameterSet &)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:446
std::set< CommonHcalNoiseRBXData, noisedatacomp > noisedataset_t
std::vector< CaloTower >::const_iterator const_iterator
const_iterator end() const
Termination of iteration.
Definition: RefVector.h:249
ProductID id() const
Accessor for product ID.
Definition: Ref.h:256
const_iterator begin() const
Initialize an iterator over the RefVector.
Definition: RefVector.h:244
std::vector< std::pair< double, double > > TS4TS5UpperCut_
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
edm::EDGetTokenT< CaloTowerCollection > m_theCaloTowerCollectionToken
ParameterDescriptionBase * add(U const &iLabel, T const &value)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
virtual void produce(edm::Event &, const edm::EventSetup &)
CaloTowerDetId id() const
Definition: CaloTower.h:87
edm::EDGetTokenT< reco::HcalNoiseRBXCollection > m_theHcalNoiseToken
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
std::vector< std::pair< double, double > > TS4TS5LowerCut_