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;
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  edm::EventSetup const&) override {}
59  edm::EventSetup const&) override {}
60 
61  // ----------member data ---------------------------
62 
66 };
67 
68 //
69 // constants, enums and typedefs
70 //
71 
72 //
73 // static data member definitions
74 //
75 
76 //
77 // constructors and destructor
78 //
80  const edm::ParameterSet& iConfig) {
81  // now do what ever initialization is needed
82  edm::InputTag tmp0 = iConfig.getParameter<edm::InputTag>("HepMCProductLabel");
83  verbosity_ = iConfig.getUntrackedParameter<bool>("Verbosity", false);
84  method2_ = iConfig.getUntrackedParameter<bool>("Method2", false);
85  hepMCproductLabel_ = consumes<edm::HepMCProduct>(tmp0);
86 
87  // hexside = 7; //cm - check it
88  tan30deg_ = 0.5773502693;
89  hexwidth_ = 6.185;
90  hexside_ = 2.0 * hexwidth_ * tan30deg_;
91 }
92 
94 
95 //
96 // member functions
97 //
98 
99 // ------------ method called on each new Event ------------
101  const edm::EventSetup& iSetup) {
103  iEvent.getByToken(hepMCproductLabel_, hepmc);
104 #ifdef DebugLog
105  if (verbosity_)
106  edm::LogVerbatim("HGCSim") << "isHandle valid: " << isHandle valid;
107 #endif
108  double x(0), y(0);
109 
110  if (hepmc.isValid()) {
111  const HepMC::GenEvent* Evt = hepmc->GetEvent();
112 
113 #ifdef DebugLog
114  if (verbosity_)
115  edm::LogVerbatim("HGCSim") << "vertex " << Evt->vertices_size();
116 #endif
117  for (HepMC::GenEvent::vertex_const_iterator p = Evt->vertices_begin();
118  p != Evt->vertices_end(); ++p) {
119  x = (*p)->position().x() / 10.; // in cm
120  y = (*p)->position().y() / 10.; // in cm
121 #ifdef DebugLog
122  z = (*p)->position().z() / 10.; // in cm
123  if (verbosity_)
124  edm::LogVerbatim("HGCSim")
125  << " x: " << (*p)->position().x() << ":" << x
126  << " y: " << (*p)->position().y() << ":" << y
127  << " z: " << (*p)->position().z() << ":" << z;
128 #endif
129  }
130  } // if (genEventInfoHandle.isValid())
131 
132  bool flag(false);
133  if (method2_) {
134  bool cond1 = y == 0 && x >= (-hexside_ * sqrt(3) / 2.);
135  bool cond2 = ((y + hexside_) >= -x / sqrt(3)) && (y < 0 && x < 0);
136  bool cond3 = (y * sqrt(3) >= (x - hexside_ * sqrt(3))) && (y < 0 && x > 0);
137  bool cond4 = y == 0 && x <= (hexside_ * sqrt(3) / 2.);
138  bool cond5 = (-y * sqrt(3) >= (x - hexside_ * sqrt(3))) && (y > 0 && x > 0);
139  bool cond6 = ((y - hexside_) <= x / sqrt(3)) && (y > 0 && x < 0);
140  flag = cond1 || cond2 || cond3 || cond4 || cond5 || cond6;
141  } else {
142  double absx = std::abs(x);
143  double absy = std::abs(y);
144  if (absx <= hexwidth_ && absy <= hexside_) {
145  if (absy <= hexwidth_ * tan30deg_ ||
146  absx <= (2. * hexwidth_ - absy / tan30deg_))
147  flag = true;
148  }
149  }
150 
151 #ifdef DebugLog
152  if (verbosity_) edm::LogVerbatim("HGCSim") << "Selection Flag " << flag;
153 #endif
154  return flag;
155 }
156 
157 // ------------ method fills 'descriptions' with the allowed parameters for the
158 // module ------------
160  edm::ConfigurationDescriptions& descriptions) {
161  // The following says we do not know what parameters are allowed so do no
162  // validation
163  // Please change this to state exactly what you do use, even if it is no
164  // parameters
166  desc.setUnknown();
167  descriptions.addDefault(desc);
168 }
169 
170 // define this as a plug-in
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
HGCalTBCheckGunPostion(const edm::ParameterSet &)
int iEvent
Definition: GenABIO.cc:224
void beginStream(edm::StreamID) override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void addDefault(ParameterSetDescription const &psetDescription)
T sqrt(T t)
Definition: SSEVec.h:18
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
edm::EDGetTokenT< edm::HepMCProduct > hepMCproductLabel_
bool isValid() const
Definition: HandleBase.h:74
void beginRun(edm::Run const &, edm::EventSetup const &) override
void endRun(edm::Run const &, edm::EventSetup const &) override
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:38
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