CMS 3D CMS Logo

HFPreReconstructor.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: RecoLocalCalo/HcalRecProducers
4 // Class: HFPreReconstructor
5 //
13 //
14 // Original Author: Igor Volobouev
15 // Created: Thu, 05 May 2016 00:17:51 GMT
16 //
17 //
18 
19 
20 // system include files
21 #include <memory>
22 #include <utility>
23 #include <cassert>
24 
25 // user include files
31 
34 
37 
41 
43 
44 //
45 // class declaration
46 //
47 
49 {
50 public:
51  explicit HFPreReconstructor(const edm::ParameterSet&);
53 
54  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
55 
56 private:
57  typedef std::pair<HcalDetId,int> PmtAnodeId;
58  typedef std::pair<PmtAnodeId,const HFQIE10Info*> QIE10InfoWithId;
59 
60  virtual void beginRun(const edm::Run&, const edm::EventSetup&) override;
61  virtual void produce(edm::Event&, const edm::EventSetup&) override;
62 
63  // Module configuration parameters
66  bool tsFromDB_;
67 
68  // Other members
71  std::vector<HFQIE10Info> qie10Infos_;
72  std::vector<QIE10InfoWithId> sortedQIE10Infos_;
73  std::unique_ptr<HcalRecoParams> paramTS_;
74 
75  // Fill qie10Infos_ from the event data
76  void fillInfos(const edm::Event& e, const edm::EventSetup& eventSetup);
77 
78  // Fill out sortedQIE10Infos_ from qie10Infos_ and return the PMT count
79  unsigned sortDataByPmt();
80 };
81 
82 //
83 // constructors and destructor
84 //
86  : inputLabel_(conf.getParameter<edm::InputTag>("digiLabel")),
87  dropZSmarkedPassed_(conf.getParameter<bool>("dropZSmarkedPassed")),
88  tsFromDB_(conf.getParameter<bool>("tsFromDB")),
89  reco_(conf.getParameter<bool>("sumAllTimeSlices"))
90 {
91  // Describe consumed data
92  tok_hfQIE10_ = consumes<QIE10DigiCollection>(inputLabel_);
93 
94  // Register the product
95  produces<HFPreRecHitCollection>();
96 }
97 
98 
100 {
101 
102  // do anything here that needs to be done at destruction time
103  // (e.g. close files, deallocate resources etc.)
104 
105 }
106 
107 
108 //
109 // member functions
110 //
111 unsigned
113 {
114  sortedQIE10Infos_.clear();
115  unsigned pmtCount = 0;
116  const unsigned sz = qie10Infos_.size();
117  if (sz)
118  {
119  // Perform sorting
120  sortedQIE10Infos_.reserve(sz);
121  const HFQIE10Info* info = &qie10Infos_[0];
122  for (unsigned i=0; i<sz; ++i)
123  {
124  const HcalDetId id(info[i].id());
125  sortedQIE10Infos_.push_back(QIE10InfoWithId(PmtAnodeId(id.baseDetId(), id.depth()), info+i));
126  }
127  std::sort(sortedQIE10Infos_.begin(), sortedQIE10Infos_.end());
128 
129  // Count the PMTs
130  HcalDetId previousBaseId(sortedQIE10Infos_[0].first.first);
131  pmtCount = 1;
132  for (unsigned i=1; i<sz; ++i)
133  {
134  const HcalDetId baseId(sortedQIE10Infos_[i].first.first);
135  if (baseId != previousBaseId)
136  {
137  previousBaseId = baseId;
138  ++pmtCount;
139  }
140  }
141  }
142  return pmtCount;
143 }
144 
145 void
147 {
148  using namespace edm;
149 
150  // Clear the collection we want to fill in this method
151  qie10Infos_.clear();
152 
153  // Get the Hcal topology if needed
155  if (tsFromDB_)
156  {
157  eventSetup.get<HcalRecNumberingRecord>().get(htopo);
158  paramTS_->setTopo(htopo.product());
159  }
160 
161  // Get the calibrations
162  ESHandle<HcalDbService> conditions;
163  eventSetup.get<HcalDbRecord>().get(conditions);
164 
165  // Get the input collection
167  e.getByToken(tok_hfQIE10_, digi);
168 
169  const unsigned inputSize = digi->size();
170  if (inputSize)
171  {
172  // Process the digis and fill out the HFQIE10Info vector
173  qie10Infos_.reserve(inputSize);
174 
175  for (QIE10DigiCollection::const_iterator it = digi->begin();
176  it != digi->end(); ++it)
177  {
178  const QIE10DataFrame& frame(*it);
179  const HcalDetId cell(frame.id());
180 
181  // Protection against calibration channels which are not
182  // in the database but can still come in the QIE10DataFrame
183  // in the laser calibs, etc.
184  if (cell.subdet() != HcalSubdetector::HcalForward)
185  continue;
186 
187  // Check zero suppression
189  if (frame.zsMarkAndPass())
190  continue;
191 
192  const HcalCalibrations& calibrations(conditions->getHcalCalibrations(cell));
193  const HcalQIECoder* channelCoder = conditions->getHcalCoder(cell);
194  const HcalQIEShape* shape = conditions->getHcalShape(channelCoder);
195  const HcalCoderDb coder(*channelCoder, *shape);
196 
197  // Get the "sample of interest" from the data frame itself
198  int tsToUse = frame.presamples();
199  if (tsFromDB_)
200  {
201  const HcalRecoParam* param_ts = paramTS_->getValues(cell.rawId());
202  tsToUse = param_ts->firstSample();
203  }
204 
205  // Reconstruct the charge, energy, etc
206  qie10Infos_.push_back(reco_.reconstruct(frame, tsToUse, coder, calibrations));
207  }
208  }
209 }
210 
211 void
213 {
214  if (tsFromDB_)
215  {
217  es.get<HcalRecoParamsRcd>().get(p);
218  paramTS_ = std::make_unique<HcalRecoParams>(*p.product());
219  }
220 }
221 
222 // ------------ method called to produce the data ------------
223 void
225 {
226  // Process the input data
227  fillInfos(e, eventSetup);
228 
229  // Create a new output collection
230  std::unique_ptr<HFPreRecHitCollection> out(std::make_unique<HFPreRecHitCollection>());
231 
232  // Fill the output collection
233  const unsigned pmtCount = sortDataByPmt();
234  if (pmtCount)
235  {
236  out->reserve(pmtCount);
237  const unsigned sz = sortedQIE10Infos_.size();
238  HcalDetId previousBaseId(sortedQIE10Infos_[0].first.first);
239  unsigned nFound = 1;
240  for (unsigned i=1; i<=sz; ++i)
241  {
242  bool appendData = i == sz;
243  if (i < sz)
244  {
245  const HcalDetId baseId(sortedQIE10Infos_[i].first.first);
246  if (baseId == previousBaseId)
247  ++nFound;
248  else
249  {
250  appendData = true;
251  previousBaseId = baseId;
252  }
253  }
254 
255  if (appendData)
256  {
257  // If we have found more than two QIE10 with the same base id,
258  // there is a bug somewhere in the dataframe. We can't do
259  // anything useful about it here. Once we make sure that
260  // everything works as expected, this assertion can be removed.
261  assert(nFound <= 2);
262 
263  const HFQIE10Info* first = 0;
264  const HFQIE10Info* second = sortedQIE10Infos_[i-1].second;
265 
266  if (nFound >= 2)
267  first = sortedQIE10Infos_[i-2].second;
268  else if (sortedQIE10Infos_[i-1].first.second < 3)
269  {
270  // Only one QIE10 readout found for this PMT.
271  // Arrange for depth 1 and 2 to be "first".
272  first = second;
273  second = 0;
274  }
275 
276  out->push_back(HFPreRecHit(sortedQIE10Infos_[i-nFound].first.first,
277  first, second));
278 
279  // Reset the QIE find count for this base id
280  nFound = 1;
281  }
282  }
283 
284  assert(out->size() == pmtCount);
285  }
286 
287  // Add the output collection to the event record
288  e.put(std::move(out));
289 }
290 
291 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
292 void
294 {
296 
297  desc.add<edm::InputTag>("digiLabel");
298  desc.add<bool>("dropZSmarkedPassed");
299  desc.add<bool>("tsFromDB");
300  desc.add<bool>("sumAllTimeSlices");
301 
302  descriptions.addDefault(desc);
303 }
304 
305 //define this as a plug-in
virtual void produce(edm::Event &, const edm::EventSetup &) override
HFQIE10Info reconstruct(const QIE10DataFrame &digi, int tsToUse, const HcalCoder &coder, const HcalCalibrations &calibs) const
Definition: HFPreRecAlgo.cc:12
unsigned int firstSample() const
Definition: HcalRecoParam.h:32
std::vector< HFQIE10Info > qie10Infos_
int i
Definition: DBlmapReader.cc:9
static const TGPicture * info(bool iBackgroundIsBlack)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
int presamples() const
for backward compatibility
std::unique_ptr< HcalRecoParams > paramTS_
edm::DataFrame::id_type id() const
const_iterator begin() const
std::vector< QIE10InfoWithId > sortedQIE10Infos_
U second(std::pair< T, U > const &p)
virtual void beginRun(const edm::Run &, const edm::EventSetup &) override
void addDefault(ParameterSetDescription const &psetDescription)
std::pair< PmtAnodeId, const HFQIE10Info * > QIE10InfoWithId
bool zsMarkAndPass() const
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void fillInfos(const edm::Event &e, const edm::EventSetup &eventSetup)
const T & get() const
Definition: EventSetup.h:56
const HcalQIECoder * getHcalCoder(const HcalGenericDetId &fId) const
const HcalQIEShape * getHcalShape(const HcalGenericDetId &fId) const
const_iterator end() const
HLT enums.
edm::InputTag inputLabel_
edm::EDGetTokenT< QIE10DigiCollection > tok_hfQIE10_
const HcalCalibrations & getHcalCalibrations(const HcalGenericDetId &fId) const
T const * product() const
Definition: ESHandle.h:86
def move(src, dest)
Definition: eostools.py:510
std::pair< HcalDetId, int > PmtAnodeId
Definition: Run.h:42
HFPreReconstructor(const edm::ParameterSet &)