CMS 3D CMS Logo

HcalHitSelection.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: HcalHitSelection
4 // Class: HcalHitSelection
5 //
13 //
14 // Original Author: Jean-Roch Vlimant,40 3-A28,+41227671209,
15 // Created: Thu Nov 4 22:17:56 CET 2010
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 
22 // user include files
25 
28 
30 
38 
41 
44 
45 //
46 // class declaration
47 //
48 
50 public:
51  explicit HcalHitSelection(const edm::ParameterSet&);
52  ~HcalHitSelection() override;
53 
54 private:
55  void produce(edm::Event&, const edm::EventSetup&) override;
56 
61  std::vector<edm::EDGetTokenT<DetIdCollection> > toks_did_;
63  std::vector<edm::InputTag> interestingDetIdCollections;
65 
66  //hcal severity ES
69  std::set<DetId> toBeKept;
70  template <typename CollectionType>
71  void skim(const edm::Handle<CollectionType>& input, CollectionType& output, int severityThreshold = 0) const;
72 
73  // ----------member data ---------------------------
74 };
75 
76 template <class CollectionType>
78  CollectionType& output,
79  int severityThreshold) const {
80  output.reserve(input->size());
81  typename CollectionType::const_iterator begin = input->begin();
82  typename CollectionType::const_iterator end = input->end();
83  typename CollectionType::const_iterator hit = begin;
84 
85  for (; hit != end; ++hit) {
86  // edm::LogError("HcalHitSelection")<<"the hit pointer is"<<&(*hit);
87  HcalDetId id = hit->detid();
88  if (theHcalTopology_->getMergePositionFlag() && id.subdet() == HcalEndcap) {
89  id = theHcalTopology_->idFront(id);
90  }
91  const uint32_t& recHitFlag = hit->flags();
92  // edm::LogError("HcalHitSelection")<<"the hit id and flag are "<<id.rawId()<<" "<<recHitFlag;
93 
94  const uint32_t& dbStatusFlag = theHcalChStatus->getValues(id)->getValue();
95  int severityLevel = theHcalSevLvlComputer->getSeverityLevel(id, recHitFlag, dbStatusFlag);
96  //anything that is not "good" goes in
97  if (severityLevel > severityThreshold) {
98  output.push_back(*hit);
99  } else {
100  //chek on the detid list
101  if (toBeKept.find(id) != toBeKept.end())
102  output.push_back(*hit);
103  }
104  }
105 }
106 
107 //
108 // constants, enums and typedefs
109 //
110 
111 //
112 // static data member definitions
113 //
114 
115 //
116 // constructors and destructor
117 //
119  hbheTag = iConfig.getParameter<edm::InputTag>("hbheTag");
120  hfTag = iConfig.getParameter<edm::InputTag>("hfTag");
121  hoTag = iConfig.getParameter<edm::InputTag>("hoTag");
122 
123  // register for data access
124  tok_hbhe_ = consumes<HBHERecHitCollection>(hbheTag);
125  tok_hf_ = consumes<HFRecHitCollection>(hfTag);
126  tok_ho_ = consumes<HORecHitCollection>(hoTag);
127 
128  interestingDetIdCollections = iConfig.getParameter<std::vector<edm::InputTag> >("interestingDetIds");
129 
130  const unsigned nLabels = interestingDetIdCollections.size();
131  for (unsigned i = 0; i != nLabels; i++)
132  toks_did_.push_back(consumes<DetIdCollection>(interestingDetIdCollections[i]));
133 
134  hoSeverityLevel = iConfig.getParameter<int>("hoSeverityLevel");
135 
136  produces<HBHERecHitCollection>(hbheTag.label());
137  produces<HFRecHitCollection>(hfTag.label());
138  produces<HORecHitCollection>(hoTag.label());
139 }
140 
142  // do anything here that needs to be done at desctruction time
143  // (e.g. close files, deallocate resources etc.)
144 }
145 
146 //
147 // member functions
148 //
149 
150 // ------------ method called to produce the data ------------
152  iSetup.get<HcalChannelQualityRcd>().get("withTopo", theHcalChStatus);
155  iSetup.get<HcalRecNumberingRecord>().get(topo);
156  theHcalTopology_ = topo.product();
157 
161 
162  iEvent.getByToken(tok_hbhe_, hbhe);
163  iEvent.getByToken(tok_hf_, hf);
164  iEvent.getByToken(tok_ho_, ho);
165 
166  toBeKept.clear();
168  for (unsigned int t = 0; t < toks_did_.size(); ++t) {
169  iEvent.getByToken(toks_did_[t], detId);
170  if (!detId.isValid()) {
171  edm::LogError("MissingInput") << "the collection of interesting detIds:" << interestingDetIdCollections[t]
172  << " is not found.";
173  continue;
174  }
175  toBeKept.insert(detId->begin(), detId->end());
176  }
177 
178  auto hbhe_out = std::make_unique<HBHERecHitCollection>();
179  skim(hbhe, *hbhe_out);
180  iEvent.put(std::move(hbhe_out), hbheTag.label());
181 
182  auto hf_out = std::make_unique<HFRecHitCollection>();
183  skim(hf, *hf_out);
184  iEvent.put(std::move(hf_out), hfTag.label());
185 
186  auto ho_out = std::make_unique<HORecHitCollection>();
187  skim(ho, *ho_out, hoSeverityLevel);
188  iEvent.put(std::move(ho_out), hoTag.label());
189 }
190 
191 //define this as a plug-in
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
std::vector< edm::InputTag > interestingDetIdCollections
~HcalHitSelection() override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
std::set< DetId > toBeKept
const_iterator end() const
Definition: EDCollection.h:122
edm::ESHandle< HcalChannelQuality > theHcalChStatus
edm::EDGetTokenT< HORecHitCollection > tok_ho_
const Item * getValues(DetId fId, bool throwOnFail=true) const
std::vector< edm::EDGetTokenT< DetIdCollection > > toks_did_
edm::InputTag hoTag
bool getMergePositionFlag() const
Definition: HcalTopology.h:167
edm::InputTag hfTag
static std::string const input
Definition: EdmProvDump.cc:48
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDGetTokenT< HBHERecHitCollection > tok_hbhe_
void skim(const edm::Handle< CollectionType > &input, CollectionType &output, int severityThreshold=0) const
#define end
Definition: vmac.h:39
bool isValid() const
Definition: HandleBase.h:70
void produce(edm::Event &, const edm::EventSetup &) override
const_iterator begin() const
Definition: EDCollection.h:117
edm::EDGetTokenT< HFRecHitCollection > tok_hf_
int getSeverityLevel(const DetId &myid, const uint32_t &myflag, const uint32_t &mystatus) const
const HcalTopology * theHcalTopology_
std::string const & label() const
Definition: InputTag.h:36
edm::ESHandle< HcalSeverityLevelComputer > theHcalSevLvlComputer
#define begin
Definition: vmac.h:32
T get() const
Definition: EventSetup.h:73
HcalHitSelection(const edm::ParameterSet &)
HcalDetId idFront(const HcalDetId &id) const
Definition: HcalTopology.h:170
edm::InputTag hbheTag
uint32_t getValue() const
T const * product() const
Definition: ESHandle.h:86
def move(src, dest)
Definition: eostools.py:511