CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
HFPhase1Reconstructor.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: RecoLocalCalo/HcalRecProducers
4 // Class: HFPhase1Reconstructor
5 //
13 //
14 // Original Author: Igor Volobouev
15 // Created: Thu, 25 May 2016 00:17:51 GMT
16 //
17 //
18 
19 // system include files
20 
21 // user include files
28 
31 
33 
38 
41 
42 // Noise cleanup algos
46 
47 // Parser for Phase 1 HF reco algorithms
49 
50 //
51 // class declaration
52 //
54 public:
56  ~HFPhase1Reconstructor() override;
57 
58  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
59 
60 private:
61  void beginRun(const edm::Run&, const edm::EventSetup&) override;
62  void produce(edm::Event&, const edm::EventSetup&) override;
63 
64  // Configuration parameters
70 
71  // Other members
73  std::unique_ptr<AbsHFPhase1Algo> reco_;
74  std::unique_ptr<AbsHcalAlgoData> recoConfig_;
76 
77  // Noise cleanup algos
78  std::unique_ptr<HcalHF_S9S1algorithm> hfS9S1_;
79  std::unique_ptr<HcalHF_S9S1algorithm> hfS8S1_;
80  std::unique_ptr<HcalHF_PETalgorithm> hfPET_;
81  std::unique_ptr<HFStripFilter> hfStripFilter_;
82 
83  // ES tokens
87 };
88 
89 //
90 // constructors and destructor
91 //
93  : algoConfigClass_(conf.getParameter<std::string>("algoConfigClass")),
94  setNoiseFlags_(conf.getParameter<bool>("setNoiseFlags")),
95  runHFStripFilter_(conf.getParameter<bool>("runHFStripFilter")),
96  useChannelQualityFromDB_(conf.getParameter<bool>("useChannelQualityFromDB")),
97  checkChannelQualityForDepth3and4_(conf.getParameter<bool>("checkChannelQualityForDepth3and4")),
98  reco_(parseHFPhase1AlgoDescription(conf.getParameter<edm::ParameterSet>("algorithm"))) {
99  // Check that the reco algorithm has been successfully configured
100  if (!reco_.get())
101  throw cms::Exception("HFPhase1BadConfig") << "Invalid HFPhase1Reconstructor algorithm configuration" << std::endl;
102 
103  if (reco_->isConfigurable()) {
104  if ("HFPhase1PMTParams" != algoConfigClass_) {
105  throw cms::Exception("HBHEPhase1BadConfig")
106  << "Invalid HBHEPhase1Reconstructor \"algoConfigClass\" parameter value \"" << algoConfigClass_ << '"'
107  << std::endl;
108  }
109  recoConfigToken_ = esConsumes<edm::Transition::BeginRun>();
110  }
111 
112  // Configure the noise cleanup algorithms
113  if (setNoiseFlags_) {
114  const edm::ParameterSet& psS9S1 = conf.getParameter<edm::ParameterSet>("S9S1stat");
115  hfS9S1_ = std::make_unique<HcalHF_S9S1algorithm>(psS9S1.getParameter<std::vector<double> >("short_optimumSlope"),
116  psS9S1.getParameter<std::vector<double> >("shortEnergyParams"),
117  psS9S1.getParameter<std::vector<double> >("shortETParams"),
118  psS9S1.getParameter<std::vector<double> >("long_optimumSlope"),
119  psS9S1.getParameter<std::vector<double> >("longEnergyParams"),
120  psS9S1.getParameter<std::vector<double> >("longETParams"),
121  psS9S1.getParameter<int>("HcalAcceptSeverityLevel"),
122  psS9S1.getParameter<bool>("isS8S1"));
123 
124  const edm::ParameterSet& psS8S1 = conf.getParameter<edm::ParameterSet>("S8S1stat");
125  hfS8S1_ = std::make_unique<HcalHF_S9S1algorithm>(psS8S1.getParameter<std::vector<double> >("short_optimumSlope"),
126  psS8S1.getParameter<std::vector<double> >("shortEnergyParams"),
127  psS8S1.getParameter<std::vector<double> >("shortETParams"),
128  psS8S1.getParameter<std::vector<double> >("long_optimumSlope"),
129  psS8S1.getParameter<std::vector<double> >("longEnergyParams"),
130  psS8S1.getParameter<std::vector<double> >("longETParams"),
131  psS8S1.getParameter<int>("HcalAcceptSeverityLevel"),
132  psS8S1.getParameter<bool>("isS8S1"));
133 
134  const edm::ParameterSet& psPET = conf.getParameter<edm::ParameterSet>("PETstat");
135  hfPET_ = std::make_unique<HcalHF_PETalgorithm>(psPET.getParameter<std::vector<double> >("short_R"),
136  psPET.getParameter<std::vector<double> >("shortEnergyParams"),
137  psPET.getParameter<std::vector<double> >("shortETParams"),
138  psPET.getParameter<std::vector<double> >("long_R"),
139  psPET.getParameter<std::vector<double> >("longEnergyParams"),
140  psPET.getParameter<std::vector<double> >("longETParams"),
141  psPET.getParameter<int>("HcalAcceptSeverityLevel"),
142  psPET.getParameter<std::vector<double> >("short_R_29"),
143  psPET.getParameter<std::vector<double> >("long_R_29"));
144 
145  // Configure HFStripFilter
146  if (runHFStripFilter_) {
147  const edm::ParameterSet& psStripFilter = conf.getParameter<edm::ParameterSet>("HFStripFilter");
149  }
150  }
151 
152  // Describe consumed data
153  tok_PreRecHit_ = consumes<HFPreRecHitCollection>(conf.getParameter<edm::InputTag>("inputLabel"));
154 
155  // Register the product
156  produces<HFRecHitCollection>();
157 
158  // ES tokens
159  conditionsToken_ = esConsumes<HcalDbService, HcalDbRecord>();
160  qualToken_ = esConsumes<HcalChannelQuality, HcalChannelQualityRcd>(edm::ESInputTag("", "withTopo"));
161  sevToken_ = esConsumes<HcalSeverityLevelComputer, HcalSeverityLevelComputerRcd>();
162 }
163 
165  // do anything here that needs to be done at destruction time
166  // (e.g. close files, deallocate resources etc.)
167 }
168 
170  if (reco_->isConfigurable()) {
171  recoConfig_ = std::make_unique<HFPhase1PMTParams>(es.getData(recoConfigToken_));
172  if (!reco_->configure(recoConfig_.get()))
173  throw cms::Exception("HFPhase1BadConfig")
174  << "Failed to configure HFPhase1Reconstructor algorithm from EventSetup" << std::endl;
175  }
176 }
177 
178 // ------------ method called to produce the data ------------
180  using namespace edm;
181 
182  // Fetch the calibrations
183  const HcalDbService* conditions = &eventSetup.getData(conditionsToken_);
184  const HcalChannelQuality* myqual = &eventSetup.getData(qualToken_);
185  const HcalSeverityLevelComputer* mySeverity = &eventSetup.getData(sevToken_);
186 
187  // Get the input data
189  e.getByToken(tok_PreRecHit_, preRecHits);
190 
191  // Create a new output collection
192  std::unique_ptr<HFRecHitCollection> rec(std::make_unique<HFRecHitCollection>());
193  rec->reserve(preRecHits->size());
194 
195  // Iterate over the input and fill the output collection
196  for (HFPreRecHitCollection::const_iterator it = preRecHits->begin(); it != preRecHits->end(); ++it) {
197  // The check whether this PMT is single-anode one should go here.
198  // Fix this piece of code if/when mixed-anode readout configurations
199  // become available.
200  const bool thisIsSingleAnodePMT = false;
201 
202  // Check if the anodes were tagged bad in the database
203  bool taggedBadByDb[2] = {false, false};
205  if (checkChannelQualityForDepth3and4_ && !thisIsSingleAnodePMT) {
206  HcalDetId anodeIds[2];
207  anodeIds[0] = it->id();
208  anodeIds[1] = anodeIds[0].secondAnodeId();
209  for (unsigned i = 0; i < 2; ++i) {
210  const HcalChannelStatus* mydigistatus = myqual->getValues(anodeIds[i].rawId());
211  taggedBadByDb[i] = mySeverity->dropChannel(mydigistatus->getValue());
212  }
213  } else {
214  const HcalChannelStatus* mydigistatus = myqual->getValues(it->id().rawId());
215  const bool b = mySeverity->dropChannel(mydigistatus->getValue());
216  taggedBadByDb[0] = b;
217  taggedBadByDb[1] = b;
218  }
219  }
220 
221  // Reconstruct the rechit
222  const HFRecHit& rh =
223  reco_->reconstruct(*it, conditions->getHcalCalibrations(it->id()), taggedBadByDb, thisIsSingleAnodePMT);
224 
225  // The rechit will have the id of 0 if the algorithm
226  // decides that it should be dropped
227  if (rh.id().rawId())
228  rec->push_back(rh);
229  }
230 
231  // At this point, the rechits contain energy, timing,
232  // as well as proper auxiliary words. We do still need
233  // to set certain flags using the noise cleanup algoritms.
234 
235  // The following flags require the full set of rechits.
236  // These flags need to be set consecutively.
237  if (setNoiseFlags_) {
238  // Step 1: Set PET flag (short fibers of |ieta|==29)
239  for (HFRecHitCollection::iterator i = rec->begin(); i != rec->end(); ++i) {
240  int depth = i->id().depth();
241  int ieta = i->id().ieta();
242  // Short fibers and all channels at |ieta|=29 use PET settings in Algo 3
243  if (depth == 2 || abs(ieta) == 29)
244  hfPET_->HFSetFlagFromPET(*i, *rec, myqual, mySeverity);
245  }
246 
247  // Step 2: Set S8S1 flag (short fibers or |ieta|==29)
248  for (HFRecHitCollection::iterator i = rec->begin(); i != rec->end(); ++i) {
249  int depth = i->id().depth();
250  int ieta = i->id().ieta();
251  // Short fibers and all channels at |ieta|=29 use PET settings in Algo 3
252  if (depth == 2 || abs(ieta) == 29)
253  hfS8S1_->HFSetFlagFromS9S1(*i, *rec, myqual, mySeverity);
254  }
255 
256  // Step 3: Set S9S1 flag (long fibers)
257  for (HFRecHitCollection::iterator i = rec->begin(); i != rec->end(); ++i) {
258  int depth = i->id().depth();
259  int ieta = i->id().ieta();
260  // Short fibers and all channels at |ieta|=29 use PET settings in Algo 3
261  if (depth == 1 && abs(ieta) != 29)
262  hfS9S1_->HFSetFlagFromS9S1(*i, *rec, myqual, mySeverity);
263  }
264 
265  // Step 4: Run HFStripFilter if requested
266  if (runHFStripFilter_)
267  hfStripFilter_->runFilter(*rec, myqual);
268  }
269 
270  // Add the output collection to the event record
271  e.put(std::move(rec));
272 }
273 
274 #define add_param_set(name) \
275  edm::ParameterSetDescription name; \
276  name.setAllowAnything(); \
277  desc.add<edm::ParameterSetDescription>(#name, name)
278 
279 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
282 
283  desc.add<edm::InputTag>("inputLabel");
284  desc.add<std::string>("algoConfigClass");
285  desc.add<bool>("setNoiseFlags");
286  desc.add<bool>("runHFStripFilter", false);
287  desc.add<bool>("useChannelQualityFromDB");
288  desc.add<bool>("checkChannelQualityForDepth3and4");
291 
295 
296  descriptions.addDefault(desc);
297 }
298 
299 //define this as a plug-in
edm::ESGetToken< HFPhase1PMTParams, HFPhase1PMTParamsRcd > recoConfigToken_
edm::ESGetToken< HcalDbService, HcalDbRecord > conditionsToken_
constexpr HcalDetId secondAnodeId() const
second PMT anode detId for HF dual channels
Definition: HcalDetId.h:241
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
void beginRun(const edm::Run &, const edm::EventSetup &) override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
static edm::ParameterSetDescription fillDescription()
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
std::vector< T >::const_iterator const_iterator
bool getData(T &iHolder) const
Definition: EventSetup.h:128
std::unique_ptr< HcalHF_PETalgorithm > hfPET_
#define add_param_set(name)
void produce(edm::Event &, const edm::EventSetup &) override
std::unique_ptr< HFStripFilter > hfStripFilter_
void addDefault(ParameterSetDescription const &psetDescription)
std::unique_ptr< AbsHcalAlgoData > recoConfig_
std::unique_ptr< AbsHFPhase1Algo > reco_
std::unique_ptr< AbsHFPhase1Algo > parseHFPhase1AlgoDescription(const edm::ParameterSet &ps)
def move
Definition: eostools.py:511
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
static std::unique_ptr< HFStripFilter > parseParameterSet(const edm::ParameterSet &ps)
std::unique_ptr< HcalHF_S9S1algorithm > hfS8S1_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
std::vector< T >::iterator iterator
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
double b
Definition: hdecay.h:118
edm::ESGetToken< HcalChannelQuality, HcalChannelQualityRcd > qualToken_
HFPhase1Reconstructor(const edm::ParameterSet &)
edm::ESGetToken< HcalSeverityLevelComputer, HcalSeverityLevelComputerRcd > sevToken_
edm::ParameterSetDescription fillDescriptionForParseHFPhase1AlgoDescription()
constexpr HcalDetId id() const
Definition: HFRecHit.h:26
uint32_t getValue() const
edm::EDGetTokenT< HFPreRecHitCollection > tok_PreRecHit_
std::unique_ptr< HcalHF_S9S1algorithm > hfS9S1_
Definition: Run.h:45