test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
180  // Check zero suppression
182  if (frame.zsMarkAndPass())
183  continue;
184 
185  const HcalDetId cell(it->id());
186  const HcalCalibrations& calibrations(conditions->getHcalCalibrations(cell));
187  const HcalQIECoder* channelCoder = conditions->getHcalCoder(cell);
188  const HcalQIEShape* shape = conditions->getHcalShape(channelCoder);
189  const HcalCoderDb coder(*channelCoder, *shape);
190 
191  // Get the "sample of interest" from the data frame itself
192  int tsToUse = frame.presamples();
193  if (tsFromDB_)
194  {
195  const HcalRecoParam* param_ts = paramTS_->getValues(cell.rawId());
196  tsToUse = param_ts->firstSample();
197  }
198 
199  // Reconstruct the charge, energy, etc
200  qie10Infos_.push_back(reco_.reconstruct(frame, tsToUse, coder, calibrations));
201  }
202  }
203 }
204 
205 void
207 {
208  if (tsFromDB_)
209  {
211  es.get<HcalRecoParamsRcd>().get(p);
212  paramTS_ = std::make_unique<HcalRecoParams>(*p.product());
213  }
214 }
215 
216 // ------------ method called to produce the data ------------
217 void
219 {
220  // Process the input data
221  fillInfos(e, eventSetup);
222 
223  // Create a new output collection
224  std::unique_ptr<HFPreRecHitCollection> out(std::make_unique<HFPreRecHitCollection>());
225 
226  // Fill the output collection
227  const unsigned pmtCount = sortDataByPmt();
228  if (pmtCount)
229  {
230  out->reserve(pmtCount);
231  const unsigned sz = sortedQIE10Infos_.size();
232  HcalDetId previousBaseId(sortedQIE10Infos_[0].first.first);
233  unsigned nFound = 1;
234  for (unsigned i=1; i<=sz; ++i)
235  {
236  bool appendData = i == sz;
237  if (i < sz)
238  {
239  const HcalDetId baseId(sortedQIE10Infos_[i].first.first);
240  if (baseId == previousBaseId)
241  ++nFound;
242  else
243  {
244  appendData = true;
245  previousBaseId = baseId;
246  }
247  }
248 
249  if (appendData)
250  {
251  // If we have found more than two QIE10 with the same base id,
252  // there is a bug somewhere in the dataframe. We can't do
253  // anything useful about it here. Once we make sure that
254  // everything works as expected, this assertion can be removed.
255  assert(nFound <= 2);
256 
257  const HFQIE10Info* first = 0;
258  const HFQIE10Info* second = sortedQIE10Infos_[i-1].second;
259 
260  if (nFound >= 2)
261  first = sortedQIE10Infos_[i-2].second;
262  else if (sortedQIE10Infos_[i-1].first.second < 3)
263  {
264  // Only one QIE10 readout found for this PMT.
265  // Arrange for depth 1 and 2 to be "first".
266  first = second;
267  second = 0;
268  }
269 
270  out->push_back(HFPreRecHit(sortedQIE10Infos_[i-nFound].first.first,
271  first, second));
272 
273  // Reset the QIE find count for this base id
274  nFound = 1;
275  }
276  }
277 
278  assert(out->size() == pmtCount);
279  }
280 
281  // Add the output collection to the event record
282  e.put(std::move(out));
283 }
284 
285 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
286 void
288 {
290 
291  desc.add<edm::InputTag>("digiLabel");
292  desc.add<bool>("dropZSmarkedPassed");
293  desc.add<bool>("tsFromDB");
294  desc.add<bool>("sumAllTimeSlices");
295 
296  descriptions.addDefault(desc);
297 }
298 
299 //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_
assert(m_qm.get())
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
def move
Definition: eostools.py:510
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
T const * product() const
Definition: ESHandle.h:86
edm::InputTag inputLabel_
edm::EDGetTokenT< QIE10DigiCollection > tok_hfQIE10_
std::pair< HcalDetId, int > PmtAnodeId
Definition: Run.h:42
HFPreReconstructor(const edm::ParameterSet &)