CMS 3D CMS Logo

BeamSplash.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: BeamSplash
4 // Class: BeamSPlash
5 //
6 //
7 // Original Author: Luca Malgeri
8 
9 #include <iostream>
10 #include <memory>
11 #include <vector>
12 #include <map>
13 #include <set>
14 
15 // user include files
17 
31 
32 using namespace edm;
33 using namespace std;
34 
36  EBRecHitCollection_ = iConfig.getParameter<edm::InputTag>("ebrechitcollection");
37  EERecHitCollection_ = iConfig.getParameter<edm::InputTag>("eerechitcollection");
38  HBHERecHitCollection_ = iConfig.getParameter<edm::InputTag>("hbherechitcollection");
39 
40  EnergyCutTot = iConfig.getUntrackedParameter<double>("energycuttot");
41  EnergyCutEcal = iConfig.getUntrackedParameter<double>("energycutecal");
42  EnergyCutHcal = iConfig.getUntrackedParameter<double>("energycuthcal");
43  applyfilter = iConfig.getUntrackedParameter<bool>("applyfilter", true);
44 }
45 
47 
49  bool accepted = false;
50 
51  bool acceptedtot = false;
52  bool acceptedEcal = false;
53  bool acceptedHcal = false;
54 
55  int ievt = iEvent.id().event();
56  int irun = iEvent.id().run();
57  int ils = iEvent.luminosityBlock();
58  int ibx = iEvent.bunchCrossing();
59 
60  double totene = 0;
61  double ecalene = 0;
62  double hcalene = 0;
63 
64  Handle<EBRecHitCollection> pEBRecHits;
65  Handle<EERecHitCollection> pEERecHits;
66  Handle<HBHERecHitCollection> pHBHERecHits;
67 
68  const EBRecHitCollection* EBRecHits = nullptr;
69  const EERecHitCollection* EERecHits = nullptr;
70  const HBHERecHitCollection* HBHERecHits = nullptr;
71 
72  if (!EBRecHitCollection_.label().empty() && !EBRecHitCollection_.instance().empty()) {
73  iEvent.getByLabel(EBRecHitCollection_, pEBRecHits);
74  if (pEBRecHits.isValid()) {
75  EBRecHits = pEBRecHits.product(); // get a ptr to the product
76  } else {
77  edm::LogError("EcalRecHitError") << "Error! can't get the product " << EBRecHitCollection_.label();
78  }
79  }
80 
81  if (!EERecHitCollection_.label().empty() && !EERecHitCollection_.instance().empty()) {
82  iEvent.getByLabel(EERecHitCollection_, pEERecHits);
83 
84  if (pEERecHits.isValid()) {
85  EERecHits = pEERecHits.product(); // get a ptr to the product
86  } else {
87  edm::LogError("EcalRecHitError") << "Error! can't get the product " << EERecHitCollection_.label();
88  }
89  }
90 
91  if (!HBHERecHitCollection_.label().empty()) {
92  iEvent.getByLabel(HBHERecHitCollection_, pHBHERecHits);
93 
94  if (pHBHERecHits.isValid()) {
95  HBHERecHits = pHBHERecHits.product(); // get a ptr to the product
96  } else {
97  edm::LogError("HcalRecHitError") << "Error! can't get the product " << HBHERecHitCollection_.label();
98  }
99  }
100 
101  // now sum over them
102  if (EBRecHits) {
103  for (EBRecHitCollection::const_iterator it = EBRecHits->begin(); it != EBRecHits->end(); ++it) {
104  totene += it->energy();
105  ecalene += it->energy();
106  }
107  }
108  if (EERecHits) {
109  for (EERecHitCollection::const_iterator it = EERecHits->begin(); it != EERecHits->end(); ++it) {
110  totene += it->energy();
111  ecalene += it->energy();
112  }
113  }
114  if (HBHERecHits) {
115  for (HBHERecHitCollection::const_iterator it = HBHERecHits->begin(); it != HBHERecHits->end(); ++it) {
116  totene += it->energy();
117  hcalene += it->energy();
118  }
119  }
120 
121  if (totene > EnergyCutTot)
122  acceptedtot = true;
123  if (ecalene > EnergyCutEcal)
124  acceptedEcal = true;
125  if (hcalene > EnergyCutHcal)
126  acceptedHcal = true;
127 
128  accepted = acceptedtot | acceptedEcal | acceptedHcal;
129 
130  if (accepted) {
131  edm::LogVerbatim("BeamSplash") << "!!!!!!!BeamSplash!!!!!!!: run:" << irun << " event:" << ievt << " ls:" << ils
132  << " bx= " << ibx << " totene=" << totene << " ecalene=" << ecalene
133  << " hcalene=" << hcalene;
134  std::cout << "!!!!!!!BeamSplash!!!!!!!: run:" << irun << " event:" << ievt << " ls:" << ils << " bx= " << ibx
135  << " totene=" << totene << " ecalene=" << ecalene << " hcalene=" << hcalene << std::endl;
136  }
137 
138  if (applyfilter)
139  return accepted;
140  else
141  return true;
142 }
143 
144 //define this as a plug-in
Log< level::Info, true > LogVerbatim
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
applyfilter
Definition: DMR_cfg.py:138
T const * product() const
Definition: Handle.h:70
std::vector< EcalRecHit >::const_iterator const_iterator
Log< level::Error, false > LogError
T getUntrackedParameter(std::string const &, T const &) const
int iEvent
Definition: GenABIO.cc:224
bool filter(edm::Event &, const edm::EventSetup &) override
Definition: BeamSplash.cc:48
BeamSplash(const edm::ParameterSet &)
Definition: BeamSplash.cc:35
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
~BeamSplash() override
Definition: BeamSplash.cc:46
bool isValid() const
Definition: HandleBase.h:70
HLT enums.