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&);
52  ~HFPreReconstructor() override;
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  void beginRun(const edm::Run&, const edm::EventSetup&) override;
61  void produce(edm::Event&, const edm::EventSetup&) override;
62 
63  // Module configuration parameters
65  int forceSOI_;
66  int soiShift_;
68  bool tsFromDB_;
69 
70  // Other members
73  std::vector<HFQIE10Info> qie10Infos_;
74  std::vector<QIE10InfoWithId> sortedQIE10Infos_;
75  std::unique_ptr<HcalRecoParams> paramTS_;
76 
77  // Fill qie10Infos_ from the event data
78  void fillInfos(const edm::Event& e, const edm::EventSetup& eventSetup);
79 
80  // Fill out sortedQIE10Infos_ from qie10Infos_ and return the PMT count
81  unsigned sortDataByPmt();
82 };
83 
84 //
85 // constructors and destructor
86 //
88  : inputLabel_(conf.getParameter<edm::InputTag>("digiLabel")),
89  forceSOI_(conf.getParameter<int>("forceSOI")),
90  soiShift_(conf.getParameter<int>("soiShift")),
91  dropZSmarkedPassed_(conf.getParameter<bool>("dropZSmarkedPassed")),
92  tsFromDB_(conf.getParameter<bool>("tsFromDB")),
93  reco_(conf.getParameter<bool>("sumAllTimeSlices"))
94 {
95  // Describe consumed data
96  tok_hfQIE10_ = consumes<QIE10DigiCollection>(inputLabel_);
97 
98  // Register the product
99  produces<HFPreRecHitCollection>();
100 }
101 
102 
104 {
105 
106  // do anything here that needs to be done at destruction time
107  // (e.g. close files, deallocate resources etc.)
108 
109 }
110 
111 
112 //
113 // member functions
114 //
115 unsigned
117 {
118  sortedQIE10Infos_.clear();
119  unsigned pmtCount = 0;
120  const unsigned sz = qie10Infos_.size();
121  if (sz)
122  {
123  // Perform sorting
124  sortedQIE10Infos_.reserve(sz);
125  const HFQIE10Info* info = &qie10Infos_[0];
126  for (unsigned i=0; i<sz; ++i)
127  {
128  const HcalDetId id(info[i].id());
129  sortedQIE10Infos_.push_back(QIE10InfoWithId(PmtAnodeId(id.baseDetId(), id.depth()), info+i));
130  }
131  std::sort(sortedQIE10Infos_.begin(), sortedQIE10Infos_.end());
132 
133  // Count the PMTs
134  HcalDetId previousBaseId(sortedQIE10Infos_[0].first.first);
135  pmtCount = 1;
136  for (unsigned i=1; i<sz; ++i)
137  {
138  const HcalDetId baseId(sortedQIE10Infos_[i].first.first);
139  if (baseId != previousBaseId)
140  {
141  previousBaseId = baseId;
142  ++pmtCount;
143  }
144  }
145  }
146  return pmtCount;
147 }
148 
149 void
151 {
152  using namespace edm;
153 
154  // Clear the collection we want to fill in this method
155  qie10Infos_.clear();
156 
157  // Get the Hcal topology if needed
159  if (tsFromDB_)
160  {
161  eventSetup.get<HcalRecNumberingRecord>().get(htopo);
162  paramTS_->setTopo(htopo.product());
163  }
164 
165  // Get the calibrations
166  ESHandle<HcalDbService> conditions;
167  eventSetup.get<HcalDbRecord>().get(conditions);
168 
169  // Get the input collection
171  e.getByToken(tok_hfQIE10_, digi);
172 
173  const unsigned inputSize = digi->size();
174  if (inputSize)
175  {
176  // Process the digis and fill out the HFQIE10Info vector
177  qie10Infos_.reserve(inputSize);
178 
179  for (QIE10DigiCollection::const_iterator it = digi->begin();
180  it != digi->end(); ++it)
181  {
182  const QIE10DataFrame& frame(*it);
183  const HcalDetId cell(frame.id());
184 
185  // Protection against calibration channels which are not
186  // in the database but can still come in the QIE10DataFrame
187  // in the laser calibs, etc.
188  if (cell.subdet() != HcalSubdetector::HcalForward)
189  continue;
190 
191  // Check zero suppression
193  if (frame.zsMarkAndPass())
194  continue;
195 
196  const HcalCalibrations& calibrations(conditions->getHcalCalibrations(cell));
197  const HcalQIECoder* channelCoder = conditions->getHcalCoder(cell);
198  const HcalQIEShape* shape = conditions->getHcalShape(channelCoder);
199  const HcalCoderDb coder(*channelCoder, *shape);
200 
201  int tsToUse = forceSOI_;
202  if (tsToUse < 0)
203  {
204  if (tsFromDB_)
205  {
206  const HcalRecoParam* param_ts = paramTS_->getValues(cell.rawId());
207  tsToUse = param_ts->firstSample();
208  }
209  else
210  // Get the "sample of interest" from the data frame itself
211  tsToUse = frame.presamples();
212  }
213 
214  // Reconstruct the charge, energy, etc
215  const HFQIE10Info& info = reco_.reconstruct(frame, tsToUse+soiShift_, coder, calibrations);
216  if (info.id().rawId())
217  qie10Infos_.push_back(info);
218  }
219  }
220 }
221 
222 void
224 {
225  if (tsFromDB_)
226  {
228  es.get<HcalRecoParamsRcd>().get(p);
229  paramTS_ = std::make_unique<HcalRecoParams>(*p.product());
230  }
231 }
232 
233 // ------------ method called to produce the data ------------
234 void
236 {
237  // Process the input data
238  fillInfos(e, eventSetup);
239 
240  // Create a new output collection
241  std::unique_ptr<HFPreRecHitCollection> out(std::make_unique<HFPreRecHitCollection>());
242 
243  // Fill the output collection
244  const unsigned pmtCount = sortDataByPmt();
245  if (pmtCount)
246  {
247  out->reserve(pmtCount);
248  const unsigned sz = sortedQIE10Infos_.size();
249  HcalDetId previousBaseId(sortedQIE10Infos_[0].first.first);
250  unsigned nFound = 1;
251  for (unsigned i=1; i<=sz; ++i)
252  {
253  bool appendData = i == sz;
254  if (i < sz)
255  {
256  const HcalDetId baseId(sortedQIE10Infos_[i].first.first);
257  if (baseId == previousBaseId)
258  ++nFound;
259  else
260  {
261  appendData = true;
262  previousBaseId = baseId;
263  }
264  }
265 
266  if (appendData)
267  {
268  // If we have found more than two QIE10 with the same base id,
269  // there is a bug somewhere in the dataframe. We can't do
270  // anything useful about it here. Once we make sure that
271  // everything works as expected, this assertion can be removed.
272  assert(nFound <= 2);
273 
274  const HFQIE10Info* first = nullptr;
275  const HFQIE10Info* second = sortedQIE10Infos_[i-1].second;
276 
277  if (nFound >= 2)
278  first = sortedQIE10Infos_[i-2].second;
279  else if (sortedQIE10Infos_[i-1].first.second < 3)
280  {
281  // Only one QIE10 readout found for this PMT.
282  // Arrange for depth 1 and 2 to be "first".
283  first = second;
284  second = nullptr;
285  }
286 
287  out->push_back(HFPreRecHit(sortedQIE10Infos_[i-nFound].first.first,
288  first, second));
289 
290  // Reset the QIE find count for this base id
291  nFound = 1;
292  }
293  }
294 
295  assert(out->size() == pmtCount);
296  }
297 
298  // Add the output collection to the event record
299  e.put(std::move(out));
300 }
301 
302 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
303 void
305 {
307 
308  desc.add<edm::InputTag>("digiLabel");
309  desc.add<int>("forceSOI", -1);
310  desc.add<int>("soiShift", 0);
311  desc.add<bool>("dropZSmarkedPassed");
312  desc.add<bool>("tsFromDB");
313  desc.add<bool>("sumAllTimeSlices");
314 
315  descriptions.addDefault(desc);
316 }
317 
318 //define this as a plug-in
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
std::vector< HFQIE10Info > qie10Infos_
static const TGPicture * info(bool iBackgroundIsBlack)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
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:517
int presamples() const
for backward compatibility
std::unique_ptr< HcalRecoParams > paramTS_
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
edm::DataFrame::id_type id() const
const_iterator begin() const
std::vector< QIE10InfoWithId > sortedQIE10Infos_
U second(std::pair< T, U > const &p)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void beginRun(const edm::Run &, const edm::EventSetup &) override
void addDefault(ParameterSetDescription const &psetDescription)
std::pair< PmtAnodeId, const HFQIE10Info * > QIE10InfoWithId
bool zsMarkAndPass() const
HcalDetId id() const
Definition: HFQIE10Info.h:68
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void fillInfos(const edm::Event &e, const edm::EventSetup &eventSetup)
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_
T get() const
Definition: EventSetup.h:71
const HcalCalibrations & getHcalCalibrations(const HcalGenericDetId &fId) const
T const * product() const
Definition: ESHandle.h:86
def move(src, dest)
Definition: eostools.py:511
std::pair< HcalDetId, int > PmtAnodeId
constexpr unsigned int firstSample() const
Definition: HcalRecoParam.h:32
Definition: Run.h:45
HFPreReconstructor(const edm::ParameterSet &)