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  std::auto_ptr<RecHitCollectionType> filteredRecHits(new 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* recHitGeom = subDetGeom->getGeometry(recHit.id());
228  GlobalPoint position = recHitGeom->getPosition();
229  for(const auto& region : regions){
230  if(region.inRegion(position)) {
231  filteredRecHits->push_back(recHit);
232  break;
233  }
234  }
235  }
236  }//end check of empty regions
237  }//end check of empty rec-hits
238  // std::cout <<"putting fileter coll in "<<filteredRecHits->size()<<std::endl;
239  event.put(filteredRecHits,productLabels_[recHitCollNr]);
240  }//end loop over all rec hit collections
241 
242 }
243 
244 
245 
246 
247 
248 template<typename RecHitType>
250 {
251  if(type=="L1EmParticle"){
252  return new L1RegionData<l1extra::L1EmParticleCollection>(para,consumesColl);
253  }else if(type=="L1JetParticle"){
254  return new L1RegionData<l1extra::L1JetParticleCollection>(para,consumesColl);
255  }else if(type=="L1MuonParticle"){
256  return new L1RegionData<l1extra::L1MuonParticleCollection>(para,consumesColl);
257  }else if(type=="EGamma"){
258  return new L1RegionData<l1t::EGammaBxCollection>(para,consumesColl);
259  }else if(type=="Jet"){
260  return new L1RegionData<l1t::JetBxCollection>(para,consumesColl);
261  }else if(type=="Muon"){
262  return new L1RegionData<l1t::MuonBxCollection>(para,consumesColl);
263  }else if(type=="Tau"){
264  return new L1RegionData<l1t::TauBxCollection>(para,consumesColl);
265  }else{
266  //this is a major issue and could lead to rather subtle efficiency losses, so if its incorrectly configured, we're aborting the job!
267  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;
268  }
269 
270 }
271 
272 
273 template<typename L1CollType>
274 void L1RegionData<L1CollType>::getEtaPhiRegions(const edm::Event& event,std::vector<EcalEtaPhiRegion>&regions,const L1CaloGeometry&)const
275 {
276  edm::Handle<L1CollType> l1Cands;
277  event.getByToken(token_,l1Cands);
278 
279  for(auto l1CandIt = beginIt(*l1Cands);l1CandIt!=endIt(*l1Cands);++l1CandIt){
280  if(l1CandIt->et() >= minEt_ && l1CandIt->et() < maxEt_){
281 
282  double etaLow = l1CandIt->eta() - regionEtaMargin_;
283  double etaHigh = l1CandIt->eta() + regionEtaMargin_;
284  double phiLow = l1CandIt->phi() - regionPhiMargin_;
285  double phiHigh = l1CandIt->phi() + regionPhiMargin_;
286 
287  regions.push_back(EcalEtaPhiRegion(etaLow,etaHigh,phiLow,phiHigh));
288  }
289  }
290 }
291 
292 template<>
293 void L1RegionData<l1extra::L1JetParticleCollection>::getEtaPhiRegions(const edm::Event& event,std::vector<EcalEtaPhiRegion>&regions,const L1CaloGeometry& l1CaloGeom)const
294 {
296  event.getByToken(token_,l1Cands);
297 
298  for(const auto& l1Cand : *l1Cands){
299  if(l1Cand.et() >= minEt_ && l1Cand.et() < maxEt_){
300 
301  // Access the GCT hardware object corresponding to the L1Extra EM object.
302  int etaIndex = l1Cand.gctJetCand()->etaIndex();
303  int phiIndex = l1Cand.gctJetCand()->phiIndex();
304 
305  // Use the L1CaloGeometry to find the eta, phi bin boundaries.
306  double etaLow = l1CaloGeom.etaBinLowEdge(etaIndex);
307  double etaHigh = l1CaloGeom.etaBinHighEdge(etaIndex);
308  double phiLow = l1CaloGeom.emJetPhiBinLowEdge( phiIndex ) ;
309  double phiHigh = l1CaloGeom.emJetPhiBinHighEdge( phiIndex ) ;
310 
311  etaLow -= regionEtaMargin_;
312  etaHigh += regionEtaMargin_;
313  phiLow -= regionPhiMargin_;
314  phiHigh += regionPhiMargin_;
315 
316 
317  regions.push_back(EcalEtaPhiRegion(etaLow,etaHigh,phiLow,phiHigh));
318  }
319  }
320 }
321 
322 template<>
323 void L1RegionData<l1extra::L1EmParticleCollection>::getEtaPhiRegions(const edm::Event& event,std::vector<EcalEtaPhiRegion>&regions,const L1CaloGeometry& l1CaloGeom)const
324 {
326  event.getByToken(token_,l1Cands);
327 
328  for(const auto& l1Cand : *l1Cands){
329  if(l1Cand.et() >= minEt_ && l1Cand.et() < maxEt_){
330 
331  // Access the GCT hardware object corresponding to the L1Extra EM object.
332  int etaIndex = l1Cand.gctEmCand()->etaIndex();
333  int phiIndex = l1Cand.gctEmCand()->phiIndex();
334 
335  // Use the L1CaloGeometry to find the eta, phi bin boundaries.
336  double etaLow = l1CaloGeom.etaBinLowEdge(etaIndex);
337  double etaHigh = l1CaloGeom.etaBinHighEdge(etaIndex);
338  double phiLow = l1CaloGeom.emJetPhiBinLowEdge( phiIndex ) ;
339  double phiHigh = l1CaloGeom.emJetPhiBinHighEdge( phiIndex ) ;
340 
341  etaLow -= regionEtaMargin_;
342  etaHigh += regionEtaMargin_;
343  phiLow -= regionPhiMargin_;
344  phiHigh += regionPhiMargin_;
345 
346  regions.push_back(EcalEtaPhiRegion(etaLow,etaHigh,phiLow,phiHigh));
347  }
348  }
349 }
350 
351 
352 
357 
358 
359 #endif
360 
361 
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)
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
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 int position[264][3]
Definition: ReadPGInfo.cc:509
static BXVector< T2 >::const_iterator endIt(const BXVector< T2 > &coll)
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 GlobalPoint & getPosition() const
Returns the position of reference for this cell.
const_iterator begin(int bx) const
L1RegionDataBase * createL1RegionData(const std::string &, const edm::ParameterSet &, edm::ConsumesCollector &&)
double emJetPhiBinHighEdge(unsigned int phiIndex) const