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 
37 
40 
41 
43 
44 //this is a re-write of HLTRechitInRegionsProducer to be able to handle arbitary L1 collections as inputs
45 //in the process, some of the cruft was cleaned up but it mantains almost all the old behaviour
46 //think the only difference now is that it wont throw if its not ECALBarrel, ECALEndcap or ECAL PS rec-hit type
48 public:
49  virtual ~L1RegionDataBase(){}
50  virtual void getEtaPhiRegions(const edm::Event&,std::vector<EcalEtaPhiRegion>&,const L1CaloGeometry&)const=0;
51 };
52 
53 template<typename T1> class L1RegionData : public L1RegionDataBase {
54 private:
55  double minEt_;
56  double maxEt_;
60 public:
62  minEt_(para.getParameter<double>("minEt")),
63  maxEt_(para.getParameter<double>("maxEt")),
64  regionEtaMargin_(para.getParameter<double>("regionEtaMargin")),
65  regionPhiMargin_(para.getParameter<double>("regionPhiMargin")),
66  token_(consumesColl.consumes<T1>(para.getParameter<edm::InputTag>("inputColl"))){}
67 
68  void getEtaPhiRegions(const edm::Event&,std::vector<EcalEtaPhiRegion>&,const L1CaloGeometry&)const override;
69 };
70 
71 
72 
73 template<typename RecHitType>
75 
77 
78  public:
79 
82 
83  void produce(edm::Event&, const edm::EventSetup&) override;
84  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
85 
86  private:
87  L1RegionDataBase* createL1RegionData(const std::string&,const edm::ParameterSet&,edm::ConsumesCollector &&); //calling function owns this
88 
89  std::vector<std::unique_ptr<L1RegionDataBase>> l1RegionData_;
90 
91  std::vector<edm::InputTag> recHitLabels_;
92  std::vector<std::string> productLabels_;
93 
94  std::vector<edm::EDGetTokenT<RecHitCollectionType>> recHitTokens_;
95 
96 
97 };
98 
99 
100 template<typename RecHitType>
102 {
103  const std::vector<edm::ParameterSet> l1InputRegions = para.getParameter<std::vector<edm::ParameterSet>>("l1InputRegions");
104  for(auto& pset : l1InputRegions){
105  const std::string type=pset.getParameter<std::string>("type");
106  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
107  }
108  recHitLabels_ =para.getParameter<std::vector<edm::InputTag>>("recHitLabels");
109  productLabels_=para.getParameter<std::vector<std::string>>("productLabels");
110 
111  for (unsigned int collNr=0; collNr<recHitLabels_.size(); collNr++) {
112  recHitTokens_.push_back(consumes<RecHitCollectionType>(recHitLabels_[collNr]));
113  produces<RecHitCollectionType> (productLabels_[collNr]);
114  }
115 }
116 template<typename RecHitType>
118 {
120  std::vector<std::string> productTags;
121  productTags.push_back("EcalRegionalRecHitsEB");
122  productTags.push_back("EcalRegionalRecHitsEE");
123  desc.add<std::vector<std::string>>("productLabels", productTags);
124  std::vector<edm::InputTag> recHitLabels;
125  recHitLabels.push_back(edm::InputTag("hltEcalRegionalEgammaRecHit:EcalRecHitsEB"));
126  recHitLabels.push_back(edm::InputTag("hltEcalRegionalEgammaRecHit:EcalRecHitsEE"));
127  recHitLabels.push_back(edm::InputTag("hltESRegionalEgammaRecHit:EcalRecHitsES"));
128  desc.add<std::vector<edm::InputTag>>("recHitLabels", recHitLabels);
129  std::vector<edm::ParameterSet> l1InputRegions;
130  edm::ParameterSet emIsoPSet;
131  emIsoPSet.addParameter<std::string>("type","L1EmParticle");
132  emIsoPSet.addParameter<double>("minEt",5);
133  emIsoPSet.addParameter<double>("maxEt",999);
134  emIsoPSet.addParameter<double>("regionEtaMargin",0.14);
135  emIsoPSet.addParameter<double>("regionPhiMargin",0.4);
136  emIsoPSet.addParameter<edm::InputTag>("inputColl",edm::InputTag("hltL1extraParticles:NonIsolated"));
137  l1InputRegions.push_back(emIsoPSet);
138  edm::ParameterSet emNonIsoPSet;
139  emNonIsoPSet.addParameter<std::string>("type","L1EmParticle");
140  emNonIsoPSet.addParameter<double>("minEt",5);
141  emNonIsoPSet.addParameter<double>("maxEt",999);
142  emNonIsoPSet.addParameter<double>("regionEtaMargin",0.14);
143  emNonIsoPSet.addParameter<double>("regionPhiMargin",0.4);
144  emNonIsoPSet.addParameter<edm::InputTag>("inputColl",edm::InputTag("hltL1extraParticles:Isolated"));
145  l1InputRegions.push_back(emNonIsoPSet);
146 
147  edm::ParameterSetDescription l1InputRegionDesc;
148  l1InputRegionDesc.add<std::string>("type");
149  l1InputRegionDesc.add<double>("minEt");
150  l1InputRegionDesc.add<double>("maxEt");
151  l1InputRegionDesc.add<double>("regionEtaMargin");
152  l1InputRegionDesc.add<double>("regionPhiMargin");
153  l1InputRegionDesc.add<edm::InputTag>("inputColl");
154  desc.addVPSet("l1InputRegions",l1InputRegionDesc,l1InputRegions);
155 
157 }
158 
159 
160 template<typename RecHitType>
162 
163  // get the collection geometry:
164  edm::ESHandle<CaloGeometry> caloGeomHandle;
165  setup.get<CaloGeometryRecord>().get(caloGeomHandle);
166 
167  // Get the CaloGeometry
168  edm::ESHandle<L1CaloGeometry> l1CaloGeom ;
169  setup.get<L1CaloGeometryRecord>().get(l1CaloGeom) ;
170 
171  std::vector<EcalEtaPhiRegion> regions;
172  std::for_each(l1RegionData_.begin(),l1RegionData_.end(),
173  [&event,&regions,l1CaloGeom](const std::unique_ptr<L1RegionDataBase>& input)
174  {input->getEtaPhiRegions(event,regions,*l1CaloGeom);}
175  );
176 
177  for(size_t recHitCollNr=0;recHitCollNr<recHitTokens_.size();recHitCollNr++){
179  event.getByToken(recHitTokens_[recHitCollNr],recHits);
180 
181  if (!(recHits.isValid())) {
182  edm::LogError("ProductNotFound")<< "could not get a handle on the "<<typeid(RecHitCollectionType).name() <<" named "<< recHitLabels_[recHitCollNr].encode() << std::endl;
183  continue;
184  }
185 
186  std::auto_ptr<RecHitCollectionType> filteredRecHits(new RecHitCollectionType);
187 
188  if(!recHits->empty()){
189  const CaloSubdetectorGeometry* subDetGeom=caloGeomHandle->getSubdetectorGeometry(recHits->front().id());
190  if(!regions.empty()){
191 
192  for(const RecHitType& recHit : *recHits){
193  const CaloCellGeometry* recHitGeom = subDetGeom->getGeometry(recHit.id());
194  GlobalPoint position = recHitGeom->getPosition();
195  for(const auto& region : regions){
196  if(region.inRegion(position)) {
197  filteredRecHits->push_back(recHit);
198  break;
199  }
200  }
201  }
202  }//end check of empty regions
203  }//end check of empty rec-hits
204  // std::cout <<"putting fileter coll in "<<filteredRecHits->size()<<std::endl;
205  event.put(filteredRecHits,productLabels_[recHitCollNr]);
206  }//end loop over all rec hit collections
207 
208 }
209 
210 
211 
212 
213 
214 template<typename RecHitType>
216 {
217  if(type=="L1EmParticle"){
218  return new L1RegionData<l1extra::L1EmParticleCollection>(para,consumesColl);
219  }else if(type=="L1JetParticle"){
220  return new L1RegionData<l1extra::L1JetParticleCollection>(para,consumesColl);
221  }else if(type=="L1MuonParticle"){
222  return new L1RegionData<l1extra::L1MuonParticleCollection>(para,consumesColl);
223  }else{
224  //this is a major issue and could lead to rather subtle efficiency losses, so if its incorrectly configured, we're aborting the job!
225  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;
226  }
227 
228 }
229 
230 
231 
232 template<typename L1CollType>
233 void L1RegionData<L1CollType>::getEtaPhiRegions(const edm::Event& event,std::vector<EcalEtaPhiRegion>&regions,const L1CaloGeometry&)const
234 {
235  edm::Handle<L1CollType> l1Cands;
236  event.getByToken(token_,l1Cands);
237 
238  for(const auto& l1Cand : *l1Cands){
239  if(l1Cand.et() >= minEt_ && l1Cand.et() < maxEt_){
240 
241  double etaLow = l1Cand.eta() - regionEtaMargin_;
242  double etaHigh = l1Cand.eta() + regionEtaMargin_;
243  double phiLow = l1Cand.phi() - regionPhiMargin_;
244  double phiHigh = l1Cand.phi() + regionPhiMargin_;
245 
246  regions.push_back(EcalEtaPhiRegion(etaLow,etaHigh,phiLow,phiHigh));
247  }
248  }
249 }
250 
251 template<>
252 void L1RegionData<l1extra::L1JetParticleCollection>::getEtaPhiRegions(const edm::Event& event,std::vector<EcalEtaPhiRegion>&regions,const L1CaloGeometry& l1CaloGeom)const
253 {
255  event.getByToken(token_,l1Cands);
256 
257  for(const auto& l1Cand : *l1Cands){
258  if(l1Cand.et() >= minEt_ && l1Cand.et() < maxEt_){
259 
260  // Access the GCT hardware object corresponding to the L1Extra EM object.
261  int etaIndex = l1Cand.gctJetCand()->etaIndex();
262  int phiIndex = l1Cand.gctJetCand()->phiIndex();
263 
264  // Use the L1CaloGeometry to find the eta, phi bin boundaries.
265  double etaLow = l1CaloGeom.etaBinLowEdge(etaIndex);
266  double etaHigh = l1CaloGeom.etaBinHighEdge(etaIndex);
267  double phiLow = l1CaloGeom.emJetPhiBinLowEdge( phiIndex ) ;
268  double phiHigh = l1CaloGeom.emJetPhiBinHighEdge( phiIndex ) ;
269 
270  etaLow -= regionEtaMargin_;
271  etaHigh += regionEtaMargin_;
272  phiLow -= regionPhiMargin_;
273  phiHigh += regionPhiMargin_;
274 
275 
276  regions.push_back(EcalEtaPhiRegion(etaLow,etaHigh,phiLow,phiHigh));
277  }
278  }
279 }
280 
281 template<>
282 void L1RegionData<l1extra::L1EmParticleCollection>::getEtaPhiRegions(const edm::Event& event,std::vector<EcalEtaPhiRegion>&regions,const L1CaloGeometry& l1CaloGeom)const
283 {
285  event.getByToken(token_,l1Cands);
286 
287  for(const auto& l1Cand : *l1Cands){
288  if(l1Cand.et() >= minEt_ && l1Cand.et() < maxEt_){
289 
290  // Access the GCT hardware object corresponding to the L1Extra EM object.
291  int etaIndex = l1Cand.gctEmCand()->etaIndex();
292  int phiIndex = l1Cand.gctEmCand()->phiIndex();
293 
294  // Use the L1CaloGeometry to find the eta, phi bin boundaries.
295  double etaLow = l1CaloGeom.etaBinLowEdge(etaIndex);
296  double etaHigh = l1CaloGeom.etaBinHighEdge(etaIndex);
297  double phiLow = l1CaloGeom.emJetPhiBinLowEdge( phiIndex ) ;
298  double phiHigh = l1CaloGeom.emJetPhiBinHighEdge( phiIndex ) ;
299 
300  etaLow -= regionEtaMargin_;
301  etaHigh += regionEtaMargin_;
302  phiLow -= regionPhiMargin_;
303  phiHigh += regionPhiMargin_;
304 
305  regions.push_back(EcalEtaPhiRegion(etaLow,etaHigh,phiLow,phiHigh));
306  }
307  }
308 }
309 
310 
311 
312 
317 
318 
319 #endif
320 
321 
void getEtaPhiRegions(const edm::Event &, std::vector< EcalEtaPhiRegion > &, const L1CaloGeometry &) const override
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)
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:43
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:143
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_
SubDetector subDetGeom[18]
const T & get() const
Definition: EventSetup.h:55
void add(std::string const &label, ParameterSetDescription const &psetDescription)
static int position[264][3]
Definition: ReadPGInfo.cc:509
virtual void getEtaPhiRegions(const edm::Event &, std::vector< EcalEtaPhiRegion > &, const L1CaloGeometry &) const =0
double emJetPhiBinLowEdge(unsigned int phiIndex) const
std::vector< edm::EDGetTokenT< RecHitCollectionType > > recHitTokens_
const GlobalPoint & getPosition() const
Returns the position of reference for this cell.
L1RegionDataBase * createL1RegionData(const std::string &, const edm::ParameterSet &, edm::ConsumesCollector &&)
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
double emJetPhiBinHighEdge(unsigned int phiIndex) const