CMS 3D CMS Logo

HLTCaloObjInRegionsProducer.h
Go to the documentation of this file.
1 #ifndef RecoEgamma_EgammaHLTProducers_HLTCaloObjInRegionsProducer_h_
2 #define RecoEgamma_EgammaHLTProducers_HLTCaloObjInRegionsProducer_h_
3 
4 #include <memory>
5 
16 
25 
30 
34 
37 
38 /**************************************************************
39 / purpose: enable filtering of calo objects in eta/phi or deltaR
40 / regions around generic objects
41 /
42 / operation : accepts all objects with
43 / (dEta <dEtaMax && dPhi < dPhiMax) || dR < dRMax
44 / so the OR of a rectangular region and cone region
45 ****************************************************************/
46 
47 //this is a struct which contains all the eta/phi regions
48 //from which to filter the calo objs
50 private:
51  float centreEta_;
52  float centrePhi_;
53  float maxDeltaR2_;
54  float maxDEta_;
55  float maxDPhi_;
56  public:
57  EtaPhiRegion(float iEta,float iPhi,float iDR,float iDEta,float iDPhi):
58  centreEta_(iEta),centrePhi_(iPhi),maxDeltaR2_(iDR*iDR),
59  maxDEta_(iDEta),maxDPhi_(iDPhi){}
61  bool operator()(float eta,float phi)const{
62  return reco::deltaR2(eta,phi,centreEta_,centrePhi_)<maxDeltaR2_ ||
63  (std::abs(eta-centreEta_)<maxDEta_ && std::abs(reco::deltaPhi(phi,centrePhi_))<maxDPhi_);}
64 
65 };
66 
68 public:
70  virtual ~EtaPhiRegionDataBase() = default;
71  virtual void getEtaPhiRegions(const edm::Event&,std::vector<EtaPhiRegion>&)const=0;
72 };
73 
74 
75 //this class stores the tokens to access the objects around which we wish to filter
76 //it makes a vector of EtaPhiRegions which are then used to filter the CaloObjs
77 template<typename T1> class EtaPhiRegionData : public EtaPhiRegionDataBase{
78 private:
79  float minEt_;
80  float maxEt_;
81  float maxDeltaR_;
82  float maxDEta_;
83  float maxDPhi_;
85 public:
87  minEt_(para.getParameter<double>("minEt")),
88  maxEt_(para.getParameter<double>("maxEt")),
89  maxDeltaR_(para.getParameter<double>("maxDeltaR")),
90  maxDEta_(para.getParameter<double>("maxDEta")),
91  maxDPhi_(para.getParameter<double>("maxDPhi")),
92  token_(consumesColl.consumes<T1>(para.getParameter<edm::InputTag>("inputColl"))){}
93 
94  void getEtaPhiRegions(const edm::Event&,std::vector<EtaPhiRegion>&)const override;
95  template<typename T2>static typename T2::const_iterator beginIt(const T2& coll){return coll.begin();}
96  template<typename T2>static typename T2::const_iterator endIt(const T2& coll){return coll.end();}
97  template<typename T2>static typename BXVector<T2>::const_iterator beginIt(const BXVector<T2>& coll){return coll.begin(0);}
98  template<typename T2>static typename BXVector<T2>::const_iterator endIt(const BXVector<T2>& coll){return coll.end(0);}
99 
100 };
101 
102 
103 template<typename CaloObjType,
104  typename CaloObjCollType =edm::SortedCollection<CaloObjType> >
106 
107 
108  public:
109 
110 
111 
114 
115  void produce(edm::Event&, const edm::EventSetup&) override;
116  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
117 
118  private:
119  EtaPhiRegionDataBase* createEtaPhiRegionData(const std::string&,const edm::ParameterSet&,edm::ConsumesCollector &&); //calling function owns this
120  static std::unique_ptr<CaloObjCollType>
121  makeFilteredColl(const edm::Handle<CaloObjCollType>& inputColl,
122  const edm::ESHandle<CaloGeometry>& caloGeomHandle,
123  const std::vector<EtaPhiRegion>& regions);
124  static bool validIDForGeom(const DetId& id);
125  std::vector<std::string> outputProductNames_;
126  std::vector<edm::InputTag> inputCollTags_;
127  std::vector<edm::EDGetTokenT<CaloObjCollType>> inputTokens_;
128  std::vector<std::unique_ptr<EtaPhiRegionDataBase>> etaPhiRegionData_;
129 };
130 
131 
132 template<typename CaloObjType,typename CaloObjCollType>
134 {
135  const std::vector<edm::ParameterSet> etaPhiRegions = para.getParameter<std::vector<edm::ParameterSet>>("etaPhiRegions");
136  for(auto& pset : etaPhiRegions){
137  const std::string type=pset.getParameter<std::string>("type");
138  etaPhiRegionData_.emplace_back(createEtaPhiRegionData(type,pset,consumesCollector())); //meh I was going to use a factory but it was going to be overly complex for my needs
139  }
140 
141  outputProductNames_=para.getParameter<std::vector<std::string>>("outputProductNames");
142  inputCollTags_=para.getParameter<std::vector<edm::InputTag>>("inputCollTags");
143  if(outputProductNames_.size()!=inputCollTags_.size()){
144  throw cms::Exception("InvalidConfiguration") <<" error outputProductNames and inputCollTags must be the same size, they are "<<outputProductNames_.size()<<" vs "<<inputCollTags_.size();
145  }
146  for (unsigned int collNr=0; collNr<inputCollTags_.size(); collNr++) {
147  inputTokens_.push_back(consumes<CaloObjCollType>(inputCollTags_[collNr]));
148  produces<CaloObjCollType> (outputProductNames_[collNr]);
149  }
150 }
151 
152 template<typename CaloObjType,typename CaloObjCollType>
154 {
156  std::vector<std::string> outputProductNames;
157  outputProductNames.push_back("EcalRegionalRecHitsEB");
158  desc.add<std::vector<std::string>>("outputProductNames", outputProductNames);
159  std::vector<edm::InputTag> inputColls;
160  inputColls.push_back(edm::InputTag("hltHcalDigis"));
161  desc.add<std::vector<edm::InputTag>>("inputCollTags", inputColls);
162  std::vector<edm::ParameterSet> etaPhiRegions;
163 
164  edm::ParameterSet ecalCandPSet;
165  ecalCandPSet.addParameter<std::string>("type","RecoEcalCandidate");
166  ecalCandPSet.addParameter<double>("minEt",-1);
167  ecalCandPSet.addParameter<double>("maxEt",-1);
168  ecalCandPSet.addParameter<double>("maxDeltaR",0.5);
169  ecalCandPSet.addParameter<double>("maxDEta",0.);
170  ecalCandPSet.addParameter<double>("maxDPhi",0.);
171  ecalCandPSet.addParameter<edm::InputTag>("inputColl",edm::InputTag("hltEgammaCandidates"));
172  etaPhiRegions.push_back(ecalCandPSet);
173 
174  edm::ParameterSetDescription etaPhiRegionDesc;
175  etaPhiRegionDesc.add<std::string>("type");
176  etaPhiRegionDesc.add<double>("minEt");
177  etaPhiRegionDesc.add<double>("maxEt");
178  etaPhiRegionDesc.add<double>("maxDeltaR");
179  etaPhiRegionDesc.add<double>("maxDEta");
180  etaPhiRegionDesc.add<double>("maxDPhi");
181  etaPhiRegionDesc.add<edm::InputTag>("inputColl");
182  desc.addVPSet("etaPhiRegions",etaPhiRegionDesc,etaPhiRegions);
183 
185 }
186 
187 
188 template<typename CaloObjType,typename CaloObjCollType>
190 
191  // get the collection geometry:
192  edm::ESHandle<CaloGeometry> caloGeomHandle;
193  setup.get<CaloGeometryRecord>().get(caloGeomHandle);
194 
195  std::vector<EtaPhiRegion> regions;
196  std::for_each(etaPhiRegionData_.begin(),etaPhiRegionData_.end(),
197  [&event,&regions](const std::unique_ptr<EtaPhiRegionDataBase>& input)
198  {input->getEtaPhiRegions(event,regions);}
199  );
200 
201  for(size_t inputCollNr=0;inputCollNr<inputTokens_.size();inputCollNr++){
203  event.getByToken(inputTokens_[inputCollNr],inputColl);
204 
205  if (!(inputColl.isValid())) {
206  edm::LogError("ProductNotFound")<< "could not get a handle on the "<<typeid(CaloObjCollType).name() <<" named "<< inputCollTags_[inputCollNr].encode() << std::endl;
207  continue;
208  }
209  auto outputColl = makeFilteredColl(inputColl,caloGeomHandle,regions);
210  event.put(std::move(outputColl),outputProductNames_[inputCollNr]);
211  }
212 }
213 
214 template<typename CaloObjType,typename CaloObjCollType>
215 std::unique_ptr<CaloObjCollType>
218  const edm::ESHandle<CaloGeometry>& caloGeomHandle,
219  const std::vector<EtaPhiRegion>& regions)
220 {
221 
222  auto outputColl = std::make_unique<CaloObjCollType>();
223  if(!inputColl->empty()){
224  const CaloSubdetectorGeometry* subDetGeom=caloGeomHandle->getSubdetectorGeometry(inputColl->begin()->id());
225  if(!regions.empty()){
226  for(const CaloObjType& obj : *inputColl){
227  auto objGeom = subDetGeom->getGeometry(obj.id());
228  if(objGeom==nullptr){
229  //wondering what to do here
230  //something is very very wrong
231  //given HLT should never crash or throw, decided to log an error
232  //update: so turns out HCAL can pass through calibration channels in QIE11 so for that module, its an expected behaviour
233  //so we check if the ID is valid
234  if(validIDForGeom(obj.id())) {
235  edm::LogError("HLTCaloObjInRegionsProducer") << "for an object of type "<<typeid(CaloObjType).name()<<" the geometry returned null for id "<<DetId(obj.id()).rawId()<<" with initial ID "<<DetId(inputColl->begin()->id()).rawId()<<" in HLTCaloObjsInRegion, this shouldnt be possible and something has gone wrong, auto accepting hit";
236  }
237  outputColl->push_back(obj);
238  continue;
239  }
240  float eta = objGeom->getPosition().eta();
241  float phi = objGeom->getPosition().phi();
242 
243  for(const auto& region : regions){
244  if(region(eta,phi)) {
245  outputColl->push_back(obj);
246  break;
247  }
248  }
249  }
250  }//end check of empty regions
251  }//end check of empty rec-hits
252  return outputColl;
253 
254 }
255 
256 //tells us if an ID should have a valid geometry
257 //it assumes that all IDs do except those specifically mentioned
258 //HCAL for example have laser calibs in the digi collection so
259 //so we have to ensure that HCAL is HB,HE or HO
260 template<typename CaloObjType,typename CaloObjCollType>
263 {
264  if(id.det()==DetId::Hcal){
265  if(id.subdetId() == HcalSubdetector::HcalEmpty ||
266  id.subdetId() == HcalSubdetector::HcalOther){
267  return false;
268  }
269  }
270  return true;
271 }
272 
273 
274 
275 
276 template<typename CaloObjType,typename CaloObjCollType>
280  edm::ConsumesCollector && consumesColl)
281 {
282  if(type=="L1EGamma"){
283  return new EtaPhiRegionData<l1t::EGammaBxCollection>(para,consumesColl);
284  }else if(type=="L1Jet"){
285  return new EtaPhiRegionData<l1t::JetBxCollection>(para,consumesColl);
286  }else if(type=="L1Muon"){
287  return new EtaPhiRegionData<l1t::MuonBxCollection>(para,consumesColl);
288  }else if(type=="L1Tau"){
289  return new EtaPhiRegionData<l1t::TauBxCollection>(para,consumesColl);
290  }else if(type=="RecoEcalCandidate"){
291  return new EtaPhiRegionData<reco::RecoEcalCandidateCollection>(para,consumesColl);
292  }else if(type=="RecoChargedCandidate"){
293  return new EtaPhiRegionData<reco::RecoChargedCandidateCollection>(para,consumesColl);
294  }else if(type=="Electron"){
295  return new EtaPhiRegionData<reco::Electron>(para,consumesColl);
296  }else{
297  //this is a major issue and could lead to rather subtle efficiency losses, so if its incorrectly configured, we're aborting the job!
298  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;
299  }
300 
301 }
302 
303 template<typename CandCollType>
305 {
307  event.getByToken(token_,cands);
308 
309  for(auto candIt = beginIt(*cands);candIt!=endIt(*cands);++candIt){
310  if(candIt->et() >= minEt_ && (maxEt_<0 || candIt->et() < maxEt_)){
311  regions.push_back(EtaPhiRegion(candIt->eta(),candIt->phi(),
312  maxDeltaR_,maxDEta_,maxDPhi_));
313  }
314 
315  }
316 }
317 
318 
319 
320 #endif
321 
322 
constexpr double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:22
const_iterator end(int bx) const
type
Definition: HCALResponse.h:21
T getParameter(std::string const &) const
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:49
ParameterDescriptionBase * addVPSet(U const &iLabel, ParameterSetDescription const &validator, std::vector< ParameterSet > const &defaults)
std::vector< edm::EDGetTokenT< CaloObjCollType > > inputTokens_
std::vector< edm::InputTag > inputCollTags_
EtaPhiRegionDataBase * createEtaPhiRegionData(const std::string &, const edm::ParameterSet &, edm::ConsumesCollector &&)
ProductID id() const
Definition: HandleBase.cc:15
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:2
static BXVector< T2 >::const_iterator beginIt(const BXVector< T2 > &coll)
std::string defaultModuleLabel()
static T2::const_iterator beginIt(const T2 &coll)
static bool validIDForGeom(const DetId &id)
static std::string const input
Definition: EdmProvDump.cc:48
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::vector< std::string > outputProductNames_
static std::unique_ptr< CaloObjCollType > makeFilteredColl(const edm::Handle< CaloObjCollType > &inputColl, const edm::ESHandle< CaloGeometry > &caloGeomHandle, const std::vector< EtaPhiRegion > &regions)
static T2::const_iterator endIt(const T2 &coll)
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:125
bool operator()(float eta, float phi) const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
EtaPhiRegionData(const edm::ParameterSet &para, edm::ConsumesCollector &consumesColl)
SubDetector subDetGeom[21]
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:74
HLTCaloObjInRegionsProducer(const edm::ParameterSet &ps)
Definition: DetId.h:18
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
JetCorrectorParametersCollection coll
Definition: classes.h:10
edm::EDGetTokenT< T1 > token_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
virtual std::shared_ptr< const CaloCellGeometry > getGeometry(const DetId &id) const
Get the cell geometry of a given detector id. Should return false if not found.
void add(std::string const &label, ParameterSetDescription const &psetDescription)
HLT enums.
static BXVector< T2 >::const_iterator endIt(const BXVector< T2 > &coll)
T get() const
Definition: EventSetup.h:71
void getEtaPhiRegions(const edm::Event &, std::vector< EtaPhiRegion > &) const override
const_iterator begin(int bx) const
EtaPhiRegion(float iEta, float iPhi, float iDR, float iDEta, float iDPhi)
std::vector< std::unique_ptr< EtaPhiRegionDataBase > > etaPhiRegionData_
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1
void produce(edm::Event &, const edm::EventSetup &) override