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 // system include files
20 #include <memory>
21 #include <utility>
22 #include <cassert>
23 
24 // user include files
30 
33 
36 
40 
42 
43 //
44 // class declaration
45 //
46 
48 public:
49  explicit HFPreReconstructor(const edm::ParameterSet&);
50  ~HFPreReconstructor() override;
51 
52  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
53 
54 private:
55  typedef std::pair<HcalDetId, int> PmtAnodeId;
56  typedef std::pair<PmtAnodeId, const HFQIE10Info*> QIE10InfoWithId;
57 
58  void beginRun(const edm::Run&, const edm::EventSetup&) override;
59  void produce(edm::Event&, const edm::EventSetup&) override;
60 
61  // Module configuration parameters
63  int forceSOI_;
64  int soiShift_;
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  forceSOI_(conf.getParameter<int>("forceSOI")),
88  soiShift_(conf.getParameter<int>("soiShift")),
89  dropZSmarkedPassed_(conf.getParameter<bool>("dropZSmarkedPassed")),
90  tsFromDB_(conf.getParameter<bool>("tsFromDB")),
91  reco_(conf.getParameter<bool>("sumAllTimeSlices")) {
92  // Describe consumed data
93  tok_hfQIE10_ = consumes<QIE10DigiCollection>(inputLabel_);
94 
95  // Register the product
96  produces<HFPreRecHitCollection>();
97 }
98 
100  // do anything here that needs to be done at destruction time
101  // (e.g. close files, deallocate resources etc.)
102 }
103 
104 //
105 // member functions
106 //
108  sortedQIE10Infos_.clear();
109  unsigned pmtCount = 0;
110  const unsigned sz = qie10Infos_.size();
111  if (sz) {
112  // Perform sorting
113  sortedQIE10Infos_.reserve(sz);
114  const HFQIE10Info* info = &qie10Infos_[0];
115  for (unsigned i = 0; i < sz; ++i) {
116  const HcalDetId id(info[i].id());
117  sortedQIE10Infos_.push_back(QIE10InfoWithId(PmtAnodeId(id.baseDetId(), id.depth()), info + i));
118  }
119  std::sort(sortedQIE10Infos_.begin(), sortedQIE10Infos_.end());
120 
121  // Count the PMTs
122  HcalDetId previousBaseId(sortedQIE10Infos_[0].first.first);
123  pmtCount = 1;
124  for (unsigned i = 1; i < sz; ++i) {
125  const HcalDetId baseId(sortedQIE10Infos_[i].first.first);
126  if (baseId != previousBaseId) {
127  previousBaseId = baseId;
128  ++pmtCount;
129  }
130  }
131  }
132  return pmtCount;
133 }
134 
136  using namespace edm;
137 
138  // Clear the collection we want to fill in this method
139  qie10Infos_.clear();
140 
141  // Get the Hcal topology if needed
143  if (tsFromDB_) {
144  eventSetup.get<HcalRecNumberingRecord>().get(htopo);
145  paramTS_->setTopo(htopo.product());
146  }
147 
148  // Get the calibrations
149  ESHandle<HcalDbService> conditions;
150  eventSetup.get<HcalDbRecord>().get(conditions);
151 
152  // Get the input collection
154  e.getByToken(tok_hfQIE10_, digi);
155 
156  const unsigned inputSize = digi->size();
157  if (inputSize) {
158  // Process the digis and fill out the HFQIE10Info vector
159  qie10Infos_.reserve(inputSize);
160 
161  for (QIE10DigiCollection::const_iterator it = digi->begin(); it != digi->end(); ++it) {
162  const QIE10DataFrame& frame(*it);
163  const HcalDetId cell(frame.id());
164 
165  // Protection against calibration channels which are not
166  // in the database but can still come in the QIE10DataFrame
167  // in the laser calibs, etc.
168  if (cell.subdet() != HcalSubdetector::HcalForward)
169  continue;
170 
171  // Check zero suppression
173  if (frame.zsMarkAndPass())
174  continue;
175 
176  const HcalCalibrations& calibrations(conditions->getHcalCalibrations(cell));
177  const HcalQIECoder* channelCoder = conditions->getHcalCoder(cell);
178  const HcalQIEShape* shape = conditions->getHcalShape(channelCoder);
179  const HcalCoderDb coder(*channelCoder, *shape);
180 
181  int tsToUse = forceSOI_;
182  if (tsToUse < 0) {
183  if (tsFromDB_) {
184  const HcalRecoParam* param_ts = paramTS_->getValues(cell.rawId());
185  tsToUse = param_ts->firstSample();
186  } else
187  // Get the "sample of interest" from the data frame itself
188  tsToUse = frame.presamples();
189  }
190 
191  // Reconstruct the charge, energy, etc
192  const HFQIE10Info& info = reco_.reconstruct(frame, tsToUse + soiShift_, coder, calibrations);
193  if (info.id().rawId())
194  qie10Infos_.push_back(info);
195  }
196  }
197 }
198 
200  if (tsFromDB_) {
202  es.get<HcalRecoParamsRcd>().get(p);
203  paramTS_ = std::make_unique<HcalRecoParams>(*p.product());
204  }
205 }
206 
207 // ------------ method called to produce the data ------------
209  // Process the input data
210  fillInfos(e, eventSetup);
211 
212  // Create a new output collection
213  std::unique_ptr<HFPreRecHitCollection> out(std::make_unique<HFPreRecHitCollection>());
214 
215  // Fill the output collection
216  const unsigned pmtCount = sortDataByPmt();
217  if (pmtCount) {
218  out->reserve(pmtCount);
219  const unsigned sz = sortedQIE10Infos_.size();
220  HcalDetId previousBaseId(sortedQIE10Infos_[0].first.first);
221  unsigned nFound = 1;
222  for (unsigned i = 1; i <= sz; ++i) {
223  bool appendData = i == sz;
224  if (i < sz) {
225  const HcalDetId baseId(sortedQIE10Infos_[i].first.first);
226  if (baseId == previousBaseId)
227  ++nFound;
228  else {
229  appendData = true;
230  previousBaseId = baseId;
231  }
232  }
233 
234  if (appendData) {
235  // If we have found more than two QIE10 with the same base id,
236  // there is a bug somewhere in the dataframe. We can't do
237  // anything useful about it here. Once we make sure that
238  // everything works as expected, this assertion can be removed.
239  assert(nFound <= 2);
240 
241  const HFQIE10Info* first = nullptr;
242  const HFQIE10Info* second = sortedQIE10Infos_[i - 1].second;
243 
244  if (nFound >= 2)
245  first = sortedQIE10Infos_[i - 2].second;
246  else if (sortedQIE10Infos_[i - 1].first.second < 3) {
247  // Only one QIE10 readout found for this PMT.
248  // Arrange for depth 1 and 2 to be "first".
249  first = second;
250  second = nullptr;
251  }
252 
253  out->push_back(HFPreRecHit(sortedQIE10Infos_[i - nFound].first.first, first, second));
254 
255  // Reset the QIE find count for this base id
256  nFound = 1;
257  }
258  }
259 
260  assert(out->size() == pmtCount);
261  }
262 
263  // Add the output collection to the event record
264  e.put(std::move(out));
265 }
266 
267 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
270 
271  desc.add<edm::InputTag>("digiLabel");
272  desc.add<int>("forceSOI", -1);
273  desc.add<int>("soiShift", 0);
274  desc.add<bool>("dropZSmarkedPassed");
275  desc.add<bool>("tsFromDB");
276  desc.add<bool>("sumAllTimeSlices");
277 
278  descriptions.addDefault(desc);
279 }
280 
281 //define this as a plug-in
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
HFPreReconstructor::tok_hfQIE10_
edm::EDGetTokenT< QIE10DigiCollection > tok_hfQIE10_
Definition: HFPreReconstructor.cc:70
electrons_cff.bool
bool
Definition: electrons_cff.py:372
mps_fire.i
i
Definition: mps_fire.py:355
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
HFPreReconstructor::reco_
HFPreRecAlgo reco_
Definition: HFPreReconstructor.cc:69
ESHandle.h
edm::DataFrameContainer::const_iterator
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
Definition: DataFrameContainer.h:61
HFQIE10Info
Definition: HFQIE10Info.h:15
edm::Run
Definition: Run.h:45
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
HFPreReconstructor::soiShift_
int soiShift_
Definition: HFPreReconstructor.cc:64
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
HFPreReconstructor::qie10Infos_
std::vector< HFQIE10Info > qie10Infos_
Definition: HFPreReconstructor.cc:71
cms::cuda::assert
assert(be >=bs)
HFPreReconstructor::HFPreReconstructor
HFPreReconstructor(const edm::ParameterSet &)
Definition: HFPreReconstructor.cc:85
EDProducer.h
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:215
HFPreReconstructor::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: HFPreReconstructor.cc:208
info
static const TGPicture * info(bool iBackgroundIsBlack)
Definition: FWCollectionSummaryWidget.cc:152
AlignmentProducer_cff.calibrations
calibrations
Definition: AlignmentProducer_cff.py:59
HFPreReconstructor::beginRun
void beginRun(const edm::Run &, const edm::EventSetup &) override
Definition: HFPreReconstructor.cc:199
edm::Handle
Definition: AssociativeIterator.h:50
HFPreRecAlgo::reconstruct
HFQIE10Info reconstruct(const QIE10DataFrame &digi, int tsToUse, const HcalCoder &coder, const HcalCalibrations &calibs) const
Definition: HFPreRecAlgo.cc:12
dqmdumpme.first
first
Definition: dqmdumpme.py:55
HcalDbService::getHcalShape
const HcalQIEShape * getHcalShape(const HcalGenericDetId &fId) const
Definition: HcalDbService.cc:326
HcalCoderDb.h
HcalDbService::getHcalCalibrations
const HcalCalibrations & getHcalCalibrations(const HcalGenericDetId &fId) const
Definition: HcalDbService.cc:65
HFPreReconstructor::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: HFPreReconstructor.cc:268
HcalDbService::getHcalCoder
const HcalQIECoder * getHcalCoder(const HcalGenericDetId &fId) const
Definition: HcalDbService.cc:319
HFPreReconstructor::paramTS_
std::unique_ptr< HcalRecoParams > paramTS_
Definition: HFPreReconstructor.cc:73
HFPreRecAlgo
Definition: HFPreRecAlgo.h:10
MakerMacros.h
edm::EventSetup::get
T get() const
Definition: EventSetup.h:73
HcalRecoParam
Definition: HcalRecoParam.h:16
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
HFPreReconstructor
Definition: HFPreReconstructor.cc:47
HFPreReconstructor::fillInfos
void fillInfos(const edm::Event &e, const edm::EventSetup &eventSetup)
Definition: HFPreReconstructor.cc:135
HcalDigiCollections.h
edm::ESHandle< HcalTopology >
HFPreReconstructor::QIE10InfoWithId
std::pair< PmtAnodeId, const HFQIE10Info * > QIE10InfoWithId
Definition: HFPreReconstructor.cc:56
HFPreReconstructor::sortedQIE10Infos_
std::vector< QIE10InfoWithId > sortedQIE10Infos_
Definition: HFPreReconstructor.cc:72
HcalDbRecord.h
HcalCalibrations
Definition: HcalCalibrations.h:9
LEDCalibrationChannels.depth
depth
Definition: LEDCalibrationChannels.py:65
HcalRecNumberingRecord
Definition: HcalRecNumberingRecord.h:23
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
edm::ParameterSet
Definition: ParameterSet.h:36
Event.h
HFPreReconstructor::dropZSmarkedPassed_
bool dropZSmarkedPassed_
Definition: HFPreReconstructor.cc:65
HFPreReconstructor::inputLabel_
edm::InputTag inputLabel_
Definition: HFPreReconstructor.cc:62
HcalDetId
Definition: HcalDetId.h:12
createfilelist.int
int
Definition: createfilelist.py:10
HFPreReconstructor::~HFPreReconstructor
~HFPreReconstructor() override
Definition: HFPreReconstructor.cc:99
edm::DataFrameContainer::begin
const_iterator begin() const
The iterator returned can not safely be used across threads.
Definition: DataFrameContainer.h:149
edm::stream::EDProducer
Definition: EDProducer.h:38
HFPreReconstructor::tsFromDB_
bool tsFromDB_
Definition: HFPreReconstructor.cc:66
edm::EventSetup
Definition: EventSetup.h:57
get
#define get
HcalQIECoder
Definition: HcalQIECoder.h:20
alignCSCRings.r
r
Definition: alignCSCRings.py:93
HcalForward
Definition: HcalAssistant.h:36
HFPreReconstructor::forceSOI_
int forceSOI_
Definition: HFPreReconstructor.cc:63
HcalRecoParam::firstSample
constexpr unsigned int firstSample() const
Definition: HcalRecoParam.h:31
eostools.move
def move(src, dest)
Definition: eostools.py:511
QIE10DataFrame
Definition: QIE10DataFrame.h:11
Frameworkfwd.h
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:31
amptDefault_cfi.frame
frame
Definition: amptDefault_cfi.py:12
HcalRecoParamsRcd
Definition: HcalRecoParamsRcd.h:6
HcalRecHitCollections.h
HFPreReconstructor::PmtAnodeId
std::pair< HcalDetId, int > PmtAnodeId
Definition: HFPreReconstructor.cc:55
HcalQIEShape
Definition: HcalQIEShape.h:17
HcalCoderDb
Definition: HcalCoderDb.h:15
HcalDbService.h
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
HFPreRecAlgo.h
HcalDbRecord
Definition: HcalDbRecord.h:30
ParameterSet.h
edm::Event
Definition: Event.h:73
HFPreReconstructor::sortDataByPmt
unsigned sortDataByPmt()
Definition: HFPreReconstructor.cc:107
edm::ConfigurationDescriptions::addDefault
void addDefault(ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:99
HFPreRecHit
Definition: HFPreRecHit.h:14
StreamID.h
edm::DataFrameContainer::end
const_iterator end() const
Definition: DataFrameContainer.h:152
edm::InputTag
Definition: InputTag.h:15
edm::DataFrameContainer::size
size_type size() const
Definition: DataFrameContainer.h:162
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37