CMS 3D CMS Logo

HGCalTBCheckGunPosition.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: HGCalTestBeam/HGCalTBCheckGunPostion
4 // Class: HGCalTBCheckGunPostion
5 //
14 //
15 // Original Author: Shilpi Jain
16 // Created: Wed, 31 Aug 2016 17:47:22 GMT
17 //
18 //
19 
20 // system include files
21 #include <memory>
22 
23 // user include files
29 
32 
33 #include <iostream>
35 
36 //#define EDM_ML_DEBUG
37 
38 //
39 // class declaration
40 //
41 
43 public:
45  ~HGCalTBCheckGunPostion() override = default;
46 
47  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
48 
49 private:
50  void beginStream(edm::StreamID) override {}
51  bool filter(edm::Event&, const edm::EventSetup&) override;
52  void endStream() override {}
53 
54  void beginRun(edm::Run const&, edm::EventSetup const&) override {}
55  void endRun(edm::Run const&, edm::EventSetup const&) override {}
57  void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override {}
58 
59  // ----------member data ---------------------------
60 
62  const bool verbosity_, method2_;
65 };
66 
67 //
68 // constants, enums and typedefs
69 //
70 
71 //
72 // static data member definitions
73 //
74 
75 //
76 // constructor
77 //
79  : labelGen_(iConfig.getParameter<edm::InputTag>("HepMCProductLabel")),
80  verbosity_(iConfig.getUntrackedParameter<bool>("Verbosity", false)),
81  method2_(iConfig.getUntrackedParameter<bool>("Method2", false)),
82  hepMCproductLabel_(consumes<edm::HepMCProduct>(labelGen_)) {
83  // now do what ever initialization is needed
84  // hexside = 7; //cm - check it
85  tan30deg_ = 0.5773502693;
86  hexwidth_ = 6.185;
87  hexside_ = 2.0 * hexwidth_ * tan30deg_;
88 }
89 
90 //
91 // member functions
92 //
93 
94 // ------------ method called on each new Event ------------
97 #ifdef EDM_ML_DEBUG
98  if (verbosity_)
99  edm::LogVerbatim("HGCSim") << "is hepmc Handle valid: " << hepmc.isValid();
100 #endif
101  double x(0), y(0);
102 
103  if (hepmc.isValid()) {
104  const HepMC::GenEvent* Evt = hepmc->GetEvent();
105 
106 #ifdef EDM_ML_DEBUG
107  if (verbosity_)
108  edm::LogVerbatim("HGCSim") << "vertex " << Evt->vertices_size();
109 #endif
110  for (HepMC::GenEvent::vertex_const_iterator p = Evt->vertices_begin(); p != Evt->vertices_end(); ++p) {
111  x = (*p)->position().x() / 10.; // in cm
112  y = (*p)->position().y() / 10.; // in cm
113 #ifdef EDM_ML_DEBUG
114  double z = (*p)->position().z() / 10.; // in cm
115  if (verbosity_)
116  edm::LogVerbatim("HGCSim") << " x: " << (*p)->position().x() << ":" << x << " y: " << (*p)->position().y()
117  << ":" << y << " z: " << (*p)->position().z() << ":" << z;
118 #endif
119  }
120  } // if (genEventInfoHandle.isValid())
121 
122  bool flag(false);
123  if (method2_) {
124  bool cond1 = y == 0 && x >= (-hexside_ * sqrt(3) / 2.);
125  bool cond2 = ((y + hexside_) >= -x / sqrt(3)) && (y < 0 && x < 0);
126  bool cond3 = (y * sqrt(3) >= (x - hexside_ * sqrt(3))) && (y < 0 && x > 0);
127  bool cond4 = y == 0 && x <= (hexside_ * sqrt(3) / 2.);
128  bool cond5 = (-y * sqrt(3) >= (x - hexside_ * sqrt(3))) && (y > 0 && x > 0);
129  bool cond6 = ((y - hexside_) <= x / sqrt(3)) && (y > 0 && x < 0);
130  flag = cond1 || cond2 || cond3 || cond4 || cond5 || cond6;
131  } else {
132  double absx = std::abs(x);
133  double absy = std::abs(y);
134  if (absx <= hexwidth_ && absy <= hexside_) {
135  if (absy <= hexwidth_ * tan30deg_ || absx <= (2. * hexwidth_ - absy / tan30deg_))
136  flag = true;
137  }
138  }
139 
140 #ifdef EDM_ML_DEBUG
141  if (verbosity_)
142  edm::LogVerbatim("HGCSim") << "Selection Flag " << flag;
143 #endif
144  return flag;
145 }
146 
147 // ------------ method fills 'descriptions' with the allowed parameters for the
148 // module ------------
150  // The following says we do not know what parameters are allowed so do no
151  // validation
152  // Please change this to state exactly what you do use, even if it is no
153  // parameters
155  desc.setUnknown();
156  descriptions.addDefault(desc);
157 }
158 
159 // define this as a plug-in
Log< level::Info, true > LogVerbatim
void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override
HGCalTBCheckGunPostion(const edm::ParameterSet &)
int iEvent
Definition: GenABIO.cc:224
void beginStream(edm::StreamID) override
void addDefault(ParameterSetDescription const &psetDescription)
~HGCalTBCheckGunPostion() override=default
T sqrt(T t)
Definition: SSEVec.h:19
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const edm::EDGetTokenT< edm::HepMCProduct > hepMCproductLabel_
void beginRun(edm::Run const &, edm::EventSetup const &) override
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:37
void endRun(edm::Run const &, edm::EventSetup const &) override
bool isValid() const
Definition: HandleBase.h:70
HLT enums.
void endLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override
bool filter(edm::Event &, const edm::EventSetup &) override
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: Run.h:45