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