CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
CaloTowersCreator.cc
Go to the documentation of this file.
1 
6 // Now we allow for the creation of towers from
7 // rejected hists as well: requested by the MET group
8 // for studies of the effect of noise clean up.
9 
10 #include "CaloTowersCreationAlgo.h"
11 #include "EScales.h"
12 
28 
30 public:
31  explicit CaloTowersCreator(const edm::ParameterSet& ps);
32  ~CaloTowersCreator() override {}
33  void produce(edm::Event& e, const edm::EventSetup& c) override;
34  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
37 
38 private:
39  static const std::vector<double>& getGridValues();
40 
45  std::vector<edm::InputTag> ecalLabels_;
46  std::vector<edm::EDGetTokenT<EcalRecHitCollection> > toks_ecal_;
48 
57 
58  // more compact flags: all HCAL are combined
59 
62 
63  // flag to use recovered hits
66 
67  // paramaters for creating towers from rejected hits
68 
71  // for ECAL we have a list of problem flags
73 
74  // Flags wheteher to use recovered hits for production of
75  // "bad towers".
76  // If the recoverd hits were already used for good towers,
77  // these flags have no effect.
78  // Note: These flags have no effect on the default tower reconstruction.
81 
87 };
88 
91 
93  : algo_(conf.getParameter<double>("EBThreshold"),
94  conf.getParameter<double>("EEThreshold"),
95 
96  conf.getParameter<bool>("UseEtEBTreshold"),
97  conf.getParameter<bool>("UseEtEETreshold"),
98  conf.getParameter<bool>("UseSymEBTreshold"),
99  conf.getParameter<bool>("UseSymEETreshold"),
100 
101  conf.getParameter<double>("HcalThreshold"),
102  conf.getParameter<double>("HBThreshold"),
103  conf.getParameter<double>("HBThreshold1"),
104  conf.getParameter<double>("HBThreshold2"),
105  conf.getParameter<double>("HESThreshold"),
106  conf.getParameter<double>("HESThreshold1"),
107  conf.getParameter<double>("HEDThreshold"),
108  conf.getParameter<double>("HEDThreshold1"),
109  conf.getParameter<double>("HOThreshold0"),
110  conf.getParameter<double>("HOThresholdPlus1"),
111  conf.getParameter<double>("HOThresholdMinus1"),
112  conf.getParameter<double>("HOThresholdPlus2"),
113  conf.getParameter<double>("HOThresholdMinus2"),
114  conf.getParameter<double>("HF1Threshold"),
115  conf.getParameter<double>("HF2Threshold"),
116  conf.getParameter<std::vector<double> >("EBGrid"),
117  conf.getParameter<std::vector<double> >("EBWeights"),
118  conf.getParameter<std::vector<double> >("EEGrid"),
119  conf.getParameter<std::vector<double> >("EEWeights"),
120  conf.getParameter<std::vector<double> >("HBGrid"),
121  conf.getParameter<std::vector<double> >("HBWeights"),
122  conf.getParameter<std::vector<double> >("HESGrid"),
123  conf.getParameter<std::vector<double> >("HESWeights"),
124  conf.getParameter<std::vector<double> >("HEDGrid"),
125  conf.getParameter<std::vector<double> >("HEDWeights"),
126  conf.getParameter<std::vector<double> >("HOGrid"),
127  conf.getParameter<std::vector<double> >("HOWeights"),
128  conf.getParameter<std::vector<double> >("HF1Grid"),
129  conf.getParameter<std::vector<double> >("HF1Weights"),
130  conf.getParameter<std::vector<double> >("HF2Grid"),
131  conf.getParameter<std::vector<double> >("HF2Weights"),
132  conf.getParameter<double>("EBWeight"),
133  conf.getParameter<double>("EEWeight"),
134  conf.getParameter<double>("HBWeight"),
135  conf.getParameter<double>("HESWeight"),
136  conf.getParameter<double>("HEDWeight"),
137  conf.getParameter<double>("HOWeight"),
138  conf.getParameter<double>("HF1Weight"),
139  conf.getParameter<double>("HF2Weight"),
140  conf.getParameter<double>("EcutTower"),
141  conf.getParameter<double>("EBSumThreshold"),
142  conf.getParameter<double>("EESumThreshold"),
143  conf.getParameter<bool>("UseHO"),
144  // (for momentum reconstruction algorithm)
145  conf.getParameter<int>("MomConstrMethod"),
146  conf.getParameter<double>("MomHBDepth"),
147  conf.getParameter<double>("MomHEDepth"),
148  conf.getParameter<double>("MomEBDepth"),
149  conf.getParameter<double>("MomEEDepth"),
150  conf.getParameter<int>("HcalPhase")),
151 
152  ecalLabels_(conf.getParameter<std::vector<edm::InputTag> >("ecalInputs")),
153  allowMissingInputs_(conf.getParameter<bool>("AllowMissingInputs")),
154 
155  theHcalAcceptSeverityLevel_(conf.getParameter<unsigned int>("HcalAcceptSeverityLevel")),
156 
157  theRecoveredHcalHitsAreUsed_(conf.getParameter<bool>("UseHcalRecoveredHits")),
158  theRecoveredEcalHitsAreUsed_(conf.getParameter<bool>("UseEcalRecoveredHits")),
159 
160  // paramaters controlling the use of rejected hits
161 
162  useRejectedHitsOnly_(conf.getParameter<bool>("UseRejectedHitsOnly")),
163 
164  theHcalAcceptSeverityLevelForRejectedHit_(
165  conf.getParameter<unsigned int>("HcalAcceptSeverityLevelForRejectedHit")),
166 
167  useRejectedRecoveredHcalHits_(conf.getParameter<bool>("UseRejectedRecoveredHcalHits")),
168  useRejectedRecoveredEcalHits_(conf.getParameter<bool>("UseRejectedRecoveredEcalHits"))
169 
170 {
171  algo_.setMissingHcalRescaleFactorForEcal(conf.getParameter<double>("missingHcalRescaleFactorForEcal"));
172 
173  // register for data access
174  tok_hbhe_ = consumes<HBHERecHitCollection>(conf.getParameter<edm::InputTag>("hbheInput"));
175  tok_ho_ = consumes<HORecHitCollection>(conf.getParameter<edm::InputTag>("hoInput"));
176  tok_hf_ = consumes<HFRecHitCollection>(conf.getParameter<edm::InputTag>("hfInput"));
177  tok_geom_ = esConsumes<CaloGeometry, CaloGeometryRecord>();
178  tok_topo_ = esConsumes<HcalTopology, HcalRecNumberingRecord>();
179  tok_cttopo_ = esConsumes<CaloTowerTopology, HcalRecNumberingRecord>();
180  tok_ctmap_ = esConsumes<CaloTowerConstituentsMap, CaloGeometryRecord>();
181  tok_ecalChStatus_ = esConsumes<EcalChannelStatus, EcalChannelStatusRcd>();
182  tok_hcalChStatus_ = esConsumes<HcalChannelQuality, HcalChannelQualityRcd>(edm::ESInputTag("", "withTopo"));
183  tok_hcalSevComputer_ = esConsumes<HcalSeverityLevelComputer, HcalSeverityLevelComputerRcd>();
184  tok_ecalSevAlgo_ = esConsumes<EcalSeverityLevelAlgo, EcalSeverityLevelAlgoRcd>();
185 
186  const unsigned nLabels = ecalLabels_.size();
187  for (unsigned i = 0; i != nLabels; i++)
188  toks_ecal_.push_back(consumes<EcalRecHitCollection>(ecalLabels_[i]));
189 
198 
199  // get the Ecal severities to be excluded
200  const std::vector<std::string> severitynames =
201  conf.getParameter<std::vector<std::string> >("EcalRecHitSeveritiesToBeExcluded");
202 
203  theEcalSeveritiesToBeExcluded_ = StringToEnumValue<EcalSeverityLevel::SeverityLevel>(severitynames);
204 
205  // get the Ecal severities to be used for bad towers
206  theEcalSeveritiesToBeUsedInBadTowers_ = StringToEnumValue<EcalSeverityLevel::SeverityLevel>(
207  conf.getParameter<std::vector<std::string> >("EcalSeveritiesToBeUsedInBadTowers"));
208 
209  if (eScales_.instanceLabel.empty())
210  produces<CaloTowerCollection>();
211  else
212  produces<CaloTowerCollection>(eScales_.instanceLabel);
213 
214 #ifdef EDM_ML_DEBUG
215  std::cout << "VI Producer " << (useRejectedHitsOnly_ ? "use rejectOnly " : " ")
216  << (allowMissingInputs_ ? "allowMissing " : " ") << nLabels << ' ' << severitynames.size() << std::endl;
217 #endif
218 }
219 
221  // get the necessary event setup objects...
226 
227  // ECAL channel status map ****************************************
229  const EcalChannelStatus* dbEcalChStatus = ecalChStatus.product();
230 
231  // HCAL channel status map ****************************************
233 
234  const HcalChannelQuality* dbHcalChStatus = hcalChStatus.product();
235 
236  // Assignment of severity levels **********************************
238  const HcalSeverityLevelComputer* hcalSevLvlComputer = hcalSevLvlComputerHndl.product();
239 
241  const EcalSeverityLevelAlgo* ecalSevLvlAlgo = ecalSevLvlAlgoHndl.product();
242 
251  algo_.setGeometry(cttopo.product(), ctmap.product(), htopo.product(), pG.product());
252 
253  // for treatment of problematic and anomalous cells
254 
255  algo_.setHcalChStatusFromDB(dbHcalChStatus);
256  algo_.setEcalChStatusFromDB(dbEcalChStatus);
257 
260 
263 
264  algo_.setHcalSevLvlComputer(hcalSevLvlComputer);
265  algo_.setEcalSevLvlAlgo(ecalSevLvlAlgo);
266 
268 
271 
274 
275 #ifdef EDM_ML_DEBUG
276  std::cout << "VI Produce: " << (useRejectedHitsOnly_ ? "use rejectOnly " : " ")
277  << (allowMissingInputs_ ? "allowMissing " : " ")
278  << (theRecoveredEcalHitsAreUsed_ ? "use RecoveredEcal " : " ") << toks_ecal_.size() << ' '
280  << std::endl;
281 #endif
282 
283  algo_.begin(); // clear the internal buffer
284 
285  // can't chain these in a big OR statement, or else it'll
286  // get triggered for each of the first three events
287  bool check1 = hcalSevLevelWatcher_.check(c);
288  bool check2 = hcalChStatusWatcher_.check(c);
289  bool check3 = caloTowerConstituentsWatcher_.check(c);
290  if (check1 || check2 || check3) {
292  }
293 
294  // check ecal SevLev
297 
298  // ----------------------------------------------------------
299  // For ecal error handling need to
300  // have access to the EB and EE collections at the end of
301  // tower reconstruction.
302 
305 
306  for (std::vector<edm::EDGetTokenT<EcalRecHitCollection> >::const_iterator i = toks_ecal_.begin();
307  i != toks_ecal_.end();
308  i++) {
310 
311  if (!e.getByToken(*i, ec_tmp))
312  continue;
313  if (ec_tmp->empty())
314  continue;
315 
316  // check if this is EB or EE
317  if ((ec_tmp->begin()->detid()).subdetId() == EcalBarrel) {
318  ebHandle = ec_tmp;
319  } else if ((ec_tmp->begin()->detid()).subdetId() == EcalEndcap) {
320  eeHandle = ec_tmp;
321  }
322  }
323 
324  algo_.setEbHandle(ebHandle);
325  algo_.setEeHandle(eeHandle);
326 
327  //-----------------------------------------------------------
328 
329  bool present;
330 
331  // Step A/C: Get Inputs and process (repeatedly)
333  present = e.getByToken(tok_hbhe_, hbhe);
334  if (present || !allowMissingInputs_)
335  algo_.process(*hbhe);
336 
338  present = e.getByToken(tok_ho_, ho);
339  if (present || !allowMissingInputs_)
340  algo_.process(*ho);
341 
343  present = e.getByToken(tok_hf_, hf);
344  if (present || !allowMissingInputs_)
345  algo_.process(*hf);
346 
347  std::vector<edm::EDGetTokenT<EcalRecHitCollection> >::const_iterator i;
348  for (i = toks_ecal_.begin(); i != toks_ecal_.end(); i++) {
350  present = e.getByToken(*i, ec);
351  if (present || !allowMissingInputs_)
352  algo_.process(*ec);
353  }
354 
355  // Step B: Create empty output
356  auto prod = std::make_unique<CaloTowerCollection>();
357 
358  // Step C: Process
359  algo_.finish(*prod);
360 
361 #ifdef EDM_ML_DEBUG
362  int totc = 0;
363  float totE = 0;
365  for (auto const& tw : (*prod)) {
366  totc += tw.constituents().size();
367  totE += tw.energy();
368  totP4 += tw.p4();
369  std::cout << "CaloTowerCreator: " << tw.id() << " with E " << tw.energy() << " and " << tw.constituents().size()
370  << " constituents\n";
371  }
372  std::cout << "VI " << (*prod).size() << " " << totc << " " << totE << " " << totP4 << std::endl;
373 #endif
374 
375  // Step D: Put into the event
376  if (eScales_.instanceLabel.empty())
377  e.put(std::move(prod));
378  else
380 }
381 
384  desc.add<double>("EBSumThreshold", 0.2);
385  desc.add<double>("HF2Weight", 1.0);
386  desc.add<double>("EBWeight", 1.0);
387  desc.add<double>("EESumThreshold", 0.45);
388  desc.add<double>("HOThreshold0", 1.1);
389  desc.add<double>("HOThresholdPlus1", 3.5);
390  desc.add<double>("HOThresholdMinus1", 3.5);
391  desc.add<double>("HOThresholdPlus2", 3.5);
392  desc.add<double>("HOThresholdMinus2", 3.5);
393  desc.add<double>("HBThreshold", 0.7);
394  desc.add<double>("HBThreshold1", 0.7);
395  desc.add<double>("HBThreshold2", 0.7);
396  desc.add<double>("HF1Threshold", 0.5);
397  desc.add<double>("HEDWeight", 1.0);
398  desc.add<double>("EEWeight", 1.0);
399  desc.add<double>("HESWeight", 1.0);
400  desc.add<double>("HF1Weight", 1.0);
401  desc.add<double>("HOWeight", 1.0);
402  desc.add<double>("EBThreshold", 0.07);
403  desc.add<double>("EEThreshold", 0.3);
404  desc.add<double>("HcalThreshold", -1000.0);
405  desc.add<double>("HF2Threshold", 0.85);
406  desc.add<double>("HESThreshold", 0.8);
407  desc.add<double>("HESThreshold1", 0.8);
408  desc.add<double>("HEDThreshold", 0.8);
409  desc.add<double>("HEDThreshold1", 0.8);
410  desc.add<double>("EcutTower", -1000.0);
411  desc.add<double>("HBWeight", 1.0);
412  desc.add<double>("MomHBDepth", 0.2);
413  desc.add<double>("MomHEDepth", 0.4);
414  desc.add<double>("MomEBDepth", 0.3);
415  desc.add<double>("MomEEDepth", 0.0);
416  desc.add<bool>("UseHO", true);
417  desc.add<bool>("UseEtEBTreshold", false);
418  desc.add<bool>("UseSymEBTreshold", true);
419  desc.add<bool>("UseEtEETreshold", false);
420  desc.add<bool>("UseSymEETreshold", true);
421  desc.add<bool>("UseHcalRecoveredHits", true);
422  desc.add<bool>("UseEcalRecoveredHits", false);
423  desc.add<bool>("UseRejectedHitsOnly", false);
424  desc.add<bool>("UseRejectedRecoveredHcalHits", true);
425  desc.add<bool>("UseRejectedRecoveredEcalHits", false);
426  desc.add<double>("missingHcalRescaleFactorForEcal", 0.0);
427  desc.add<bool>("AllowMissingInputs", false);
428  desc.add<std::vector<double> >("HBGrid", {-1.0, 1.0, 10.0, 100.0, 1000.0});
429  desc.add<std::vector<double> >("EEWeights", {1.0, 1.0, 1.0, 1.0, 1.0});
430  desc.add<std::vector<double> >("HF2Weights", {1.0, 1.0, 1.0, 1.0, 1.0});
431  desc.add<std::vector<double> >("HOWeights", {1.0, 1.0, 1.0, 1.0, 1.0});
432  desc.add<std::vector<double> >("EEGrid", {-1.0, 1.0, 10.0, 100.0, 1000.0});
433  desc.add<std::vector<double> >("HBWeights", {1.0, 1.0, 1.0, 1.0, 1.0});
434  desc.add<std::vector<double> >("HF2Grid", {-1.0, 1.0, 10.0, 100.0, 1000.0});
435  desc.add<std::vector<double> >("HEDWeights", {1.0, 1.0, 1.0, 1.0, 1.0});
436  desc.add<std::vector<double> >("HF1Grid", {-1.0, 1.0, 10.0, 100.0, 1000.0});
437  desc.add<std::vector<double> >("EBWeights", {1.0, 1.0, 1.0, 1.0, 1.0});
438  desc.add<std::vector<double> >("HF1Weights", {1.0, 1.0, 1.0, 1.0, 1.0});
439  desc.add<std::vector<double> >("HESGrid", {-1.0, 1.0, 10.0, 100.0, 1000.0});
440  desc.add<std::vector<double> >("HESWeights", {1.0, 1.0, 1.0, 1.0, 1.0});
441  desc.add<std::vector<double> >("HEDGrid", {-1.0, 1.0, 10.0, 100.0, 1000.0});
442  desc.add<std::vector<double> >("HOGrid", {-1.0, 1.0, 10.0, 100.0, 1000.0});
443  desc.add<std::vector<double> >("EBGrid", {-1.0, 1.0, 10.0, 100.0, 1000.0});
444  desc.add<edm::InputTag>("hfInput", edm::InputTag("hfreco"));
445  desc.add<edm::InputTag>("hbheInput", edm::InputTag("hbhereco"));
446  desc.add<edm::InputTag>("hoInput", edm::InputTag("horeco"));
447  desc.add<std::vector<edm::InputTag> >(
448  "ecalInputs", {edm::InputTag("ecalRecHit", "EcalRecHitsEB"), edm::InputTag("ecalRecHit", "EcalRecHitsEE")});
449  desc.add<int>("MomConstrMethod", 1);
450  desc.add<unsigned int>("HcalAcceptSeverityLevel", 9);
451  desc.add<std::vector<std::string> >("EcalRecHitSeveritiesToBeExcluded", {"kTime", "kWeird", "kBad"});
452  desc.add<unsigned int>("HcalAcceptSeverityLevelForRejectedHit", 9999);
453  desc.add<std::vector<std::string> >("EcalSeveritiesToBeUsedInBadTowers", {});
454  desc.add<int>("HcalPhase", 0);
455 
456  descriptions.addDefault(desc);
457 }
CaloTowersCreator(const edm::ParameterSet &ps)
double HF2Scale
Definition: EScales.h:20
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
const edm::EventSetup & c
void setEcalChStatusFromDB(const EcalChannelStatus *s)
CaloTowersCreationAlgo algo_
double EEScale
Definition: EScales.h:14
edm::ESGetToken< HcalChannelQuality, HcalChannelQualityRcd > tok_hcalChStatus_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ESGetToken< HcalTopology, HcalRecNumberingRecord > tok_topo_
void produce(edm::Event &e, const edm::EventSetup &c) override
edm::ESGetToken< EcalSeverityLevelAlgo, EcalSeverityLevelAlgoRcd > tok_ecalSevAlgo_
void setHcalChStatusFromDB(const HcalChannelQuality *s)
edm::ESGetToken< CaloTowerConstituentsMap, CaloGeometryRecord > tok_ctmap_
void finish(CaloTowerCollection &destCollection)
void setEeHandle(const edm::Handle< EcalRecHitCollection > ee)
double HOScale
Definition: EScales.h:18
std::vector< int > theEcalSeveritiesToBeExcluded_
~CaloTowersCreator() override
static const std::vector< double > & getGridValues()
double HF1Scale
Definition: EScales.h:19
edm::EDGetTokenT< HORecHitCollection > tok_ho_
void setGeometry(const CaloTowerTopology *cttopo, const CaloTowerConstituentsMap *ctmap, const HcalTopology *htopo, const CaloGeometry *geo)
double HEDScale
Definition: EScales.h:17
void setEbHandle(const edm::Handle< EcalRecHitCollection > eb)
void setUseRejectedRecoveredEcalHits(bool flag)
edm::ESGetToken< EcalChannelStatus, EcalChannelStatusRcd > tok_ecalChStatus_
void addDefault(ParameterSetDescription const &psetDescription)
void setEcalSeveritiesToBeExcluded(const std::vector< int > &ecalSev)
void setHcalAcceptSeverityLevelForRejectedHit(unsigned int level)
def move
Definition: eostools.py:511
void setHcalSevLvlComputer(const HcalSeverityLevelComputer *c)
std::vector< edm::EDGetTokenT< EcalRecHitCollection > > toks_ecal_
edm::EDGetTokenT< HBHERecHitCollection > tok_hbhe_
void SetEcalSeveritiesToBeUsedInBadTowers(const std::vector< int > &ecalSev)
void setRecoveredEcalHitsAreUsed(bool flag)
double EBScale
Definition: EScales.h:13
ParameterDescriptionBase * add(U const &iLabel, T const &value)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
edm::ESGetToken< CaloGeometry, CaloGeometryRecord > tok_geom_
double HBScale
Definition: EScales.h:15
edm::ESWatcher< HcalChannelQualityRcd > hcalChStatusWatcher_
void process(const HBHERecHitCollection &hbhe)
edm::ESGetToken< HcalSeverityLevelComputer, HcalSeverityLevelComputerRcd > tok_hcalSevComputer_
std::string instanceLabel
Definition: EScales.h:21
unsigned int theHcalAcceptSeverityLevelForRejectedHit_
void setRecoveredHcalHitsAreUsed(bool flag)
T const * product() const
Definition: ESHandle.h:86
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
void setUseRejectedHitsOnly(bool flag)
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
void setMissingHcalRescaleFactorForEcal(float factor)
unsigned int theHcalAcceptSeverityLevel_
edm::ESGetToken< CaloTowerTopology, HcalRecNumberingRecord > tok_cttopo_
void setHcalAcceptSeverityLevel(unsigned int level)
tuple cout
Definition: gather_cfg.py:144
std::vector< edm::InputTag > ecalLabels_
double HESScale
Definition: EScales.h:16
edm::ESWatcher< HcalSeverityLevelComputerRcd > hcalSevLevelWatcher_
void setEcalSevLvlAlgo(const EcalSeverityLevelAlgo *a)
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:151
void setUseRejectedRecoveredHcalHits(bool flag)
edm::ESWatcher< IdealGeometryRecord > caloTowerConstituentsWatcher_
Definition: EScales.h:6
std::vector< int > theEcalSeveritiesToBeUsedInBadTowers_
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: LeafCandidate.h:23
edm::EDGetTokenT< HFRecHitCollection > tok_hf_
edm::ESWatcher< EcalSeverityLevelAlgoRcd > ecalSevLevelWatcher_