CMS 3D CMS Logo

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