test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HLTRecHitInAllL1RegionsProducer.h
Go to the documentation of this file.
1 #ifndef RecoEgamma_EgammayHLTProducers_HLTRecHitInAllL1RegionsProducer_h_
2 #define RecoEgamma_EgammayHLTProducers_HLTRecHitInAllL1RegionsProducer_h_
3 
4 #include <memory>
5 
13 
15 
16 // Reco candidates (might not need)
19 
20 // Geometry and topology
25 
27 // Level 1 Trigger
34 
38 
41 
44 
46 
48 
49 //this is a re-write of HLTRechitInRegionsProducer to be able to handle arbitary L1 collections as inputs
50 //in the process, some of the cruft was cleaned up but it mantains almost all the old behaviour
51 //think the only difference now is that it wont throw if its not ECALBarrel, ECALEndcap or ECAL PS rec-hit type
53 public:
54  virtual ~L1RegionDataBase(){}
55  virtual void getEtaPhiRegions(const edm::Event&,std::vector<EcalEtaPhiRegion>&,const L1CaloGeometry&)const=0;
56 };
57 
58 template<typename T1> class L1RegionData : public L1RegionDataBase {
59 private:
60  double minEt_;
61  double maxEt_;
65 public:
67  minEt_(para.getParameter<double>("minEt")),
68  maxEt_(para.getParameter<double>("maxEt")),
69  regionEtaMargin_(para.getParameter<double>("regionEtaMargin")),
70  regionPhiMargin_(para.getParameter<double>("regionPhiMargin")),
71  token_(consumesColl.consumes<T1>(para.getParameter<edm::InputTag>("inputColl"))){}
72 
73  void getEtaPhiRegions(const edm::Event&,std::vector<EcalEtaPhiRegion>&,const L1CaloGeometry&)const override;
74  template<typename T2>static typename T2::const_iterator beginIt(const T2& coll){return coll.begin();}
75  template<typename T2>static typename T2::const_iterator endIt(const T2& coll){return coll.end();}
76  template<typename T2>static typename BXVector<T2>::const_iterator beginIt(const BXVector<T2>& coll){return coll.begin(0);}
77  template<typename T2>static typename BXVector<T2>::const_iterator endIt(const BXVector<T2>& coll){return coll.end(0);}
78 
79 
80 };
81 
82 
83 
84 template<typename RecHitType>
86 
88 
89  public:
90 
93 
94  void produce(edm::Event&, const edm::EventSetup&) override;
95  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
96 
97  private:
98  L1RegionDataBase* createL1RegionData(const std::string&,const edm::ParameterSet&,edm::ConsumesCollector &&); //calling function owns this
99 
100  std::vector<std::unique_ptr<L1RegionDataBase>> l1RegionData_;
101 
102  std::vector<edm::InputTag> recHitLabels_;
103  std::vector<std::string> productLabels_;
104 
105  std::vector<edm::EDGetTokenT<RecHitCollectionType>> recHitTokens_;
106 
107 
108 };
109 
110 
111 template<typename RecHitType>
113 {
114  const std::vector<edm::ParameterSet> l1InputRegions = para.getParameter<std::vector<edm::ParameterSet>>("l1InputRegions");
115  for(auto& pset : l1InputRegions){
116  const std::string type=pset.getParameter<std::string>("type");
117  l1RegionData_.emplace_back(createL1RegionData(type,pset,consumesCollector())); //meh I was going to use a factory but it was going to be overly complex for my needs
118  }
119  recHitLabels_ =para.getParameter<std::vector<edm::InputTag>>("recHitLabels");
120  productLabels_=para.getParameter<std::vector<std::string>>("productLabels");
121 
122  for (unsigned int collNr=0; collNr<recHitLabels_.size(); collNr++) {
123  recHitTokens_.push_back(consumes<RecHitCollectionType>(recHitLabels_[collNr]));
124  produces<RecHitCollectionType> (productLabels_[collNr]);
125  }
126 }
127 template<typename RecHitType>
129 {
131  std::vector<std::string> productTags;
132  productTags.push_back("EcalRegionalRecHitsEB");
133  productTags.push_back("EcalRegionalRecHitsEE");
134  desc.add<std::vector<std::string>>("productLabels", productTags);
135  std::vector<edm::InputTag> recHitLabels;
136  recHitLabels.push_back(edm::InputTag("hltEcalRegionalEgammaRecHit:EcalRecHitsEB"));
137  recHitLabels.push_back(edm::InputTag("hltEcalRegionalEgammaRecHit:EcalRecHitsEE"));
138  recHitLabels.push_back(edm::InputTag("hltESRegionalEgammaRecHit:EcalRecHitsES"));
139  desc.add<std::vector<edm::InputTag>>("recHitLabels", recHitLabels);
140  std::vector<edm::ParameterSet> l1InputRegions;
141 
142  edm::ParameterSet emIsoPSet;
143  emIsoPSet.addParameter<std::string>("type","L1EmParticle");
144  emIsoPSet.addParameter<double>("minEt",5);
145  emIsoPSet.addParameter<double>("maxEt",999);
146  emIsoPSet.addParameter<double>("regionEtaMargin",0.14);
147  emIsoPSet.addParameter<double>("regionPhiMargin",0.4);
148  emIsoPSet.addParameter<edm::InputTag>("inputColl",edm::InputTag("hltL1extraParticles:NonIsolated"));
149  l1InputRegions.push_back(emIsoPSet);
150  edm::ParameterSet emNonIsoPSet;
151  emNonIsoPSet.addParameter<std::string>("type","L1EmParticle");
152  emNonIsoPSet.addParameter<double>("minEt",5);
153  emNonIsoPSet.addParameter<double>("maxEt",999);
154  emNonIsoPSet.addParameter<double>("regionEtaMargin",0.14);
155  emNonIsoPSet.addParameter<double>("regionPhiMargin",0.4);
156  emNonIsoPSet.addParameter<edm::InputTag>("inputColl",edm::InputTag("hltL1extraParticles:Isolated"));
157  l1InputRegions.push_back(emNonIsoPSet);
158 
159  // Why no Central Jets here? They are present in the python config, e.g. OnLine_HLT_GRun.py
160  // SHarper: because these are the default parameters designed to reproduce the original (no jets) behaviour
161  //
162  edm::ParameterSet egPSet;
163  egPSet.addParameter<std::string>("type","EGamma");
164  egPSet.addParameter<double>("minEt",5);
165  egPSet.addParameter<double>("maxEt",999);
166  egPSet.addParameter<double>("regionEtaMargin",0.4);
167  egPSet.addParameter<double>("regionPhiMargin",0.5);
168  egPSet.addParameter<edm::InputTag>("inputColl",edm::InputTag("hltCaloStage2Digis"));
169  l1InputRegions.push_back(egPSet);
170 
171  edm::ParameterSet jetPSet;
172  jetPSet.addParameter<std::string>("type","EGamma");
173  jetPSet.addParameter<double>("minEt",200);
174  jetPSet.addParameter<double>("maxEt",999);
175  jetPSet.addParameter<double>("regionEtaMargin",0.4);
176  jetPSet.addParameter<double>("regionPhiMargin",0.5);
177  jetPSet.addParameter<edm::InputTag>("inputColl",edm::InputTag("hltCaloStage2Digis"));
178  l1InputRegions.push_back(jetPSet);
179 
180 
181  edm::ParameterSetDescription l1InputRegionDesc;
182  l1InputRegionDesc.add<std::string>("type");
183  l1InputRegionDesc.add<double>("minEt");
184  l1InputRegionDesc.add<double>("maxEt");
185  l1InputRegionDesc.add<double>("regionEtaMargin");
186  l1InputRegionDesc.add<double>("regionPhiMargin");
187  l1InputRegionDesc.add<edm::InputTag>("inputColl");
188  desc.addVPSet("l1InputRegions",l1InputRegionDesc,l1InputRegions);
189 
191 }
192 
193 
194 template<typename RecHitType>
196 
197  // get the collection geometry:
198  edm::ESHandle<CaloGeometry> caloGeomHandle;
199  setup.get<CaloGeometryRecord>().get(caloGeomHandle);
200 
201  // Get the CaloGeometry
202  edm::ESHandle<L1CaloGeometry> l1CaloGeom ;
203  setup.get<L1CaloGeometryRecord>().get(l1CaloGeom) ;
204 
205  std::vector<EcalEtaPhiRegion> regions;
206  std::for_each(l1RegionData_.begin(),l1RegionData_.end(),
207  [&event,&regions,l1CaloGeom](const std::unique_ptr<L1RegionDataBase>& input)
208  {input->getEtaPhiRegions(event,regions,*l1CaloGeom);}
209  );
210 
211  for(size_t recHitCollNr=0;recHitCollNr<recHitTokens_.size();recHitCollNr++){
213  event.getByToken(recHitTokens_[recHitCollNr],recHits);
214 
215  if (!(recHits.isValid())) {
216  edm::LogError("ProductNotFound")<< "could not get a handle on the "<<typeid(RecHitCollectionType).name() <<" named "<< recHitLabels_[recHitCollNr].encode() << std::endl;
217  continue;
218  }
219 
220  auto filteredRecHits = std::make_unique<RecHitCollectionType>();
221 
222  if(!recHits->empty()){
223  const CaloSubdetectorGeometry* subDetGeom=caloGeomHandle->getSubdetectorGeometry(recHits->front().id());
224  if(!regions.empty()){
225 
226  for(const RecHitType& recHit : *recHits){
227  const CaloCellGeometry & this_cell = *subDetGeom->getGeometry(recHit.id());
228  for(const auto& region : regions){
229  if (region.inRegion(this_cell.etaPos(),this_cell.phiPos())) {
230  filteredRecHits->push_back(recHit);
231  break;
232  }
233  }
234  }
235  }//end check of empty regions
236  }//end check of empty rec-hits
237  // std::cout <<"putting fileter coll in "<<filteredRecHits->size()<<std::endl;
238  event.put(std::move(filteredRecHits),productLabels_[recHitCollNr]);
239  }//end loop over all rec hit collections
240 
241 }
242 
243 
244 
245 
246 
247 template<typename RecHitType>
249 {
250  if(type=="L1EmParticle"){
251  return new L1RegionData<l1extra::L1EmParticleCollection>(para,consumesColl);
252  }else if(type=="L1JetParticle"){
253  return new L1RegionData<l1extra::L1JetParticleCollection>(para,consumesColl);
254  }else if(type=="L1MuonParticle"){
255  return new L1RegionData<l1extra::L1MuonParticleCollection>(para,consumesColl);
256  }else if(type=="EGamma"){
257  return new L1RegionData<l1t::EGammaBxCollection>(para,consumesColl);
258  }else if(type=="Jet"){
259  return new L1RegionData<l1t::JetBxCollection>(para,consumesColl);
260  }else if(type=="Muon"){
261  return new L1RegionData<l1t::MuonBxCollection>(para,consumesColl);
262  }else if(type=="Tau"){
263  return new L1RegionData<l1t::TauBxCollection>(para,consumesColl);
264  }else{
265  //this is a major issue and could lead to rather subtle efficiency losses, so if its incorrectly configured, we're aborting the job!
266  throw cms::Exception("InvalidConfig") << " type "<<type<<" is not recognised, this means the rec-hit you think you are keeping may not be and you should fix this error as it can lead to hard to find efficiency loses"<<std::endl;
267  }
268 
269 }
270 
271 
272 template<typename L1CollType>
273 void L1RegionData<L1CollType>::getEtaPhiRegions(const edm::Event& event,std::vector<EcalEtaPhiRegion>&regions,const L1CaloGeometry&)const
274 {
275  edm::Handle<L1CollType> l1Cands;
276  event.getByToken(token_,l1Cands);
277 
278  for(auto l1CandIt = beginIt(*l1Cands);l1CandIt!=endIt(*l1Cands);++l1CandIt){
279  if(l1CandIt->et() >= minEt_ && l1CandIt->et() < maxEt_){
280 
281  double etaLow = l1CandIt->eta() - regionEtaMargin_;
282  double etaHigh = l1CandIt->eta() + regionEtaMargin_;
283  double phiLow = l1CandIt->phi() - regionPhiMargin_;
284  double phiHigh = l1CandIt->phi() + regionPhiMargin_;
285 
286  regions.push_back(EcalEtaPhiRegion(etaLow,etaHigh,phiLow,phiHigh));
287  }
288  }
289 }
290 
291 template<>
292 void L1RegionData<l1extra::L1JetParticleCollection>::getEtaPhiRegions(const edm::Event& event,std::vector<EcalEtaPhiRegion>&regions,const L1CaloGeometry& l1CaloGeom)const
293 {
295  event.getByToken(token_,l1Cands);
296 
297  for(const auto& l1Cand : *l1Cands){
298  if(l1Cand.et() >= minEt_ && l1Cand.et() < maxEt_){
299 
300  // Access the GCT hardware object corresponding to the L1Extra EM object.
301  int etaIndex = l1Cand.gctJetCand()->etaIndex();
302  int phiIndex = l1Cand.gctJetCand()->phiIndex();
303 
304  // Use the L1CaloGeometry to find the eta, phi bin boundaries.
305  double etaLow = l1CaloGeom.etaBinLowEdge(etaIndex);
306  double etaHigh = l1CaloGeom.etaBinHighEdge(etaIndex);
307  double phiLow = l1CaloGeom.emJetPhiBinLowEdge( phiIndex ) ;
308  double phiHigh = l1CaloGeom.emJetPhiBinHighEdge( phiIndex ) ;
309 
310  etaLow -= regionEtaMargin_;
311  etaHigh += regionEtaMargin_;
312  phiLow -= regionPhiMargin_;
313  phiHigh += regionPhiMargin_;
314 
315 
316  regions.push_back(EcalEtaPhiRegion(etaLow,etaHigh,phiLow,phiHigh));
317  }
318  }
319 }
320 
321 template<>
322 void L1RegionData<l1extra::L1EmParticleCollection>::getEtaPhiRegions(const edm::Event& event,std::vector<EcalEtaPhiRegion>&regions,const L1CaloGeometry& l1CaloGeom)const
323 {
325  event.getByToken(token_,l1Cands);
326 
327  for(const auto& l1Cand : *l1Cands){
328  if(l1Cand.et() >= minEt_ && l1Cand.et() < maxEt_){
329 
330  // Access the GCT hardware object corresponding to the L1Extra EM object.
331  int etaIndex = l1Cand.gctEmCand()->etaIndex();
332  int phiIndex = l1Cand.gctEmCand()->phiIndex();
333 
334  // Use the L1CaloGeometry to find the eta, phi bin boundaries.
335  double etaLow = l1CaloGeom.etaBinLowEdge(etaIndex);
336  double etaHigh = l1CaloGeom.etaBinHighEdge(etaIndex);
337  double phiLow = l1CaloGeom.emJetPhiBinLowEdge( phiIndex ) ;
338  double phiHigh = l1CaloGeom.emJetPhiBinHighEdge( phiIndex ) ;
339 
340  etaLow -= regionEtaMargin_;
341  etaHigh += regionEtaMargin_;
342  phiLow -= regionPhiMargin_;
343  phiHigh += regionPhiMargin_;
344 
345  regions.push_back(EcalEtaPhiRegion(etaLow,etaHigh,phiLow,phiHigh));
346  }
347  }
348 }
349 
350 
351 
356 
357 
358 #endif
359 
360 
void getEtaPhiRegions(const edm::Event &, std::vector< EcalEtaPhiRegion > &, const L1CaloGeometry &) const override
const_iterator end(int bx) const
type
Definition: HCALResponse.h:21
T getParameter(std::string const &) const
std::string defaultModuleLabel()
ParameterDescriptionBase * addVPSet(U const &iLabel, ParameterSetDescription const &validator, std::vector< ParameterSet > const &defaults)
double etaBinHighEdge(unsigned int etaIndex, bool central=true) const
HLTRecHitInAllL1RegionsProducer< EcalRecHit > HLTEcalRecHitInAllL1RegionsProducer
ProductID id() const
Definition: HandleBase.cc:15
double etaBinLowEdge(unsigned int etaIndex, bool central=true) const
std::vector< std::unique_ptr< L1RegionDataBase > > l1RegionData_
void produce(edm::Event &, const edm::EventSetup &) override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
float phiPos() const
L1RegionData(const edm::ParameterSet &para, edm::ConsumesCollector &consumesColl)
static BXVector< T2 >::const_iterator beginIt(const BXVector< T2 > &coll)
HLTRecHitInAllL1RegionsProducer(const edm::ParameterSet &ps)
virtual const CaloCellGeometry * getGeometry(const DetId &id) const
Get the cell geometry of a given detector id. Should return false if not found.
static std::string const input
Definition: EdmProvDump.cc:44
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:144
HLTRecHitInAllL1RegionsProducer< EcalUncalibratedRecHit > HLTEcalUncalibratedRecHitInAllL1RegionsProducer
def move
Definition: eostools.py:510
ParameterDescriptionBase * add(U const &iLabel, T const &value)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
bool isValid() const
Definition: HandleBase.h:75
edm::EDGetTokenT< T1 > token_
static T2::const_iterator endIt(const T2 &coll)
SubDetector subDetGeom[18]
JetCorrectorParametersCollection coll
Definition: classes.h:10
const T & get() const
Definition: EventSetup.h:56
void add(std::string const &label, ParameterSetDescription const &psetDescription)
static BXVector< T2 >::const_iterator endIt(const BXVector< T2 > &coll)
float etaPos() const
virtual void getEtaPhiRegions(const edm::Event &, std::vector< EcalEtaPhiRegion > &, const L1CaloGeometry &) const =0
static T2::const_iterator beginIt(const T2 &coll)
double emJetPhiBinLowEdge(unsigned int phiIndex) const
std::vector< edm::EDGetTokenT< RecHitCollectionType > > recHitTokens_
const_iterator begin(int bx) const
L1RegionDataBase * createL1RegionData(const std::string &, const edm::ParameterSet &, edm::ConsumesCollector &&)
double emJetPhiBinHighEdge(unsigned int phiIndex) const