CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
32 
33 using namespace edm;
34 using namespace std;
35 
37  EBRecHitCollection_ = iConfig.getParameter<edm::InputTag>("ebrechitcollection");
38  EERecHitCollection_ = iConfig.getParameter<edm::InputTag>("eerechitcollection");
39  HBHERecHitCollection_ = iConfig.getParameter<edm::InputTag>("hbherechitcollection");
40 
41  EnergyCutTot = iConfig.getUntrackedParameter<double>("energycuttot");
42  EnergyCutEcal = iConfig.getUntrackedParameter<double>("energycutecal");
43  EnergyCutHcal = iConfig.getUntrackedParameter<double>("energycuthcal");
44  applyfilter = iConfig.getUntrackedParameter<bool>("applyfilter", true);
45 }
46 
48 
50  bool accepted = false;
51 
52  bool acceptedtot = false;
53  bool acceptedEcal = false;
54  bool acceptedHcal = false;
55 
56  int ievt = iEvent.id().event();
57  int irun = iEvent.id().run();
58  int ils = iEvent.luminosityBlock();
59  int ibx = iEvent.bunchCrossing();
60 
61  double totene = 0;
62  double ecalene = 0;
63  double hcalene = 0;
64 
65  Handle<EBRecHitCollection> pEBRecHits;
66  Handle<EERecHitCollection> pEERecHits;
67  Handle<HBHERecHitCollection> pHBHERecHits;
68 
69  const EBRecHitCollection* EBRecHits = nullptr;
70  const EERecHitCollection* EERecHits = nullptr;
71  const HBHERecHitCollection* HBHERecHits = nullptr;
72 
73  if (!EBRecHitCollection_.label().empty() && !EBRecHitCollection_.instance().empty()) {
74  iEvent.getByLabel(EBRecHitCollection_, pEBRecHits);
75  if (pEBRecHits.isValid()) {
76  EBRecHits = pEBRecHits.product(); // get a ptr to the product
77  } else {
78  edm::LogError("EcalRecHitError") << "Error! can't get the product " << EBRecHitCollection_.label();
79  }
80  }
81 
82  if (!EERecHitCollection_.label().empty() && !EERecHitCollection_.instance().empty()) {
83  iEvent.getByLabel(EERecHitCollection_, pEERecHits);
84 
85  if (pEERecHits.isValid()) {
86  EERecHits = pEERecHits.product(); // get a ptr to the product
87  } else {
88  edm::LogError("EcalRecHitError") << "Error! can't get the product " << EERecHitCollection_.label();
89  }
90  }
91 
92  if (!HBHERecHitCollection_.label().empty()) {
93  iEvent.getByLabel(HBHERecHitCollection_, pHBHERecHits);
94 
95  if (pHBHERecHits.isValid()) {
96  HBHERecHits = pHBHERecHits.product(); // get a ptr to the product
97  } else {
98  edm::LogError("HcalRecHitError") << "Error! can't get the product " << HBHERecHitCollection_.label();
99  }
100  }
101 
102  // now sum over them
103  if (EBRecHits) {
104  for (EBRecHitCollection::const_iterator it = EBRecHits->begin(); it != EBRecHits->end(); ++it) {
105  totene += it->energy();
106  ecalene += it->energy();
107  }
108  }
109  if (EERecHits) {
110  for (EERecHitCollection::const_iterator it = EERecHits->begin(); it != EERecHits->end(); ++it) {
111  totene += it->energy();
112  ecalene += it->energy();
113  }
114  }
115  if (HBHERecHits) {
116  for (HBHERecHitCollection::const_iterator it = HBHERecHits->begin(); it != HBHERecHits->end(); ++it) {
117  totene += it->energy();
118  hcalene += it->energy();
119  }
120  }
121 
122  if (totene > EnergyCutTot)
123  acceptedtot = true;
124  if (ecalene > EnergyCutEcal)
125  acceptedEcal = true;
126  if (hcalene > EnergyCutHcal)
127  acceptedHcal = true;
128 
129  accepted = acceptedtot | acceptedEcal | acceptedHcal;
130 
131  if (accepted) {
132  edm::LogVerbatim("BeamSplash") << "!!!!!!!BeamSplash!!!!!!!: run:" << irun << " event:" << ievt << " ls:" << ils
133  << " bx= " << ibx << " totene=" << totene << " ecalene=" << ecalene
134  << " hcalene=" << hcalene;
135  std::cout << "!!!!!!!BeamSplash!!!!!!!: run:" << irun << " event:" << ievt << " ls:" << ils << " bx= " << ibx
136  << " totene=" << totene << " ecalene=" << ecalene << " hcalene=" << hcalene << std::endl;
137  }
138 
139  if (applyfilter)
140  return accepted;
141  else
142  return true;
143 }
144 
145 //define this as a plug-in
RunNumber_t run() const
Definition: EventID.h:38
Log< level::Info, true > LogVerbatim
EventNumber_t event() const
Definition: EventID.h:40
T getUntrackedParameter(std::string const &, T const &) const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::vector< EcalRecHit >::const_iterator const_iterator
int bunchCrossing() const
Definition: EventBase.h:64
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:61
Log< level::Error, false > LogError
int iEvent
Definition: GenABIO.cc:224
bool filter(edm::Event &, const edm::EventSetup &) override
Definition: BeamSplash.cc:49
BeamSplash(const edm::ParameterSet &)
Definition: BeamSplash.cc:36
bool isValid() const
Definition: HandleBase.h:70
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:500
const_iterator end() const
T const * product() const
Definition: Handle.h:70
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
~BeamSplash() override
Definition: BeamSplash.cc:47
edm::EventID id() const
Definition: EventBase.h:59
tuple cout
Definition: gather_cfg.py:144
const_iterator begin() const