File indexing completed on 2024-04-06 12:30:08
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 #include <memory>
0022
0023
0024 #include "FWCore/Framework/interface/Event.h"
0025 #include "FWCore/Framework/interface/Frameworkfwd.h"
0026 #include "FWCore/Framework/interface/MakerMacros.h"
0027 #include "FWCore/Framework/interface/stream/EDFilter.h"
0028 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0029
0030 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0031 #include "FWCore/Utilities/interface/StreamID.h"
0032
0033 #include <iostream>
0034 #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
0035
0036
0037
0038
0039
0040
0041
0042 class HGCalTBCheckGunPostion : public edm::stream::EDFilter<> {
0043 public:
0044 explicit HGCalTBCheckGunPostion(const edm::ParameterSet&);
0045 ~HGCalTBCheckGunPostion() override = default;
0046
0047 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0048
0049 private:
0050 void beginStream(edm::StreamID) override {}
0051 bool filter(edm::Event&, const edm::EventSetup&) override;
0052 void endStream() override {}
0053
0054 void beginRun(edm::Run const&, edm::EventSetup const&) override {}
0055 void endRun(edm::Run const&, edm::EventSetup const&) override {}
0056 void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override {}
0057 void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override {}
0058
0059
0060
0061 const edm::InputTag labelGen_;
0062 const bool verbosity_, method2_;
0063 const edm::EDGetTokenT<edm::HepMCProduct> hepMCproductLabel_;
0064 double tan30deg_, hexwidth_, hexside_;
0065 };
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078 HGCalTBCheckGunPostion::HGCalTBCheckGunPostion(const edm::ParameterSet& iConfig)
0079 : labelGen_(iConfig.getParameter<edm::InputTag>("HepMCProductLabel")),
0080 verbosity_(iConfig.getUntrackedParameter<bool>("Verbosity", false)),
0081 method2_(iConfig.getUntrackedParameter<bool>("Method2", false)),
0082 hepMCproductLabel_(consumes<edm::HepMCProduct>(labelGen_)) {
0083
0084
0085 tan30deg_ = 0.5773502693;
0086 hexwidth_ = 6.185;
0087 hexside_ = 2.0 * hexwidth_ * tan30deg_;
0088 }
0089
0090
0091
0092
0093
0094
0095 bool HGCalTBCheckGunPostion::filter(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0096 const edm::Handle<edm::HepMCProduct>& hepmc = iEvent.getHandle(hepMCproductLabel_);
0097 #ifdef EDM_ML_DEBUG
0098 if (verbosity_)
0099 edm::LogVerbatim("HGCSim") << "is hepmc Handle valid: " << hepmc.isValid();
0100 #endif
0101 double x(0), y(0);
0102
0103 if (hepmc.isValid()) {
0104 const HepMC::GenEvent* Evt = hepmc->GetEvent();
0105
0106 #ifdef EDM_ML_DEBUG
0107 if (verbosity_)
0108 edm::LogVerbatim("HGCSim") << "vertex " << Evt->vertices_size();
0109 #endif
0110 for (HepMC::GenEvent::vertex_const_iterator p = Evt->vertices_begin(); p != Evt->vertices_end(); ++p) {
0111 x = (*p)->position().x() / 10.;
0112 y = (*p)->position().y() / 10.;
0113 #ifdef EDM_ML_DEBUG
0114 double z = (*p)->position().z() / 10.;
0115 if (verbosity_)
0116 edm::LogVerbatim("HGCSim") << " x: " << (*p)->position().x() << ":" << x << " y: " << (*p)->position().y()
0117 << ":" << y << " z: " << (*p)->position().z() << ":" << z;
0118 #endif
0119 }
0120 }
0121
0122 bool flag(false);
0123 if (method2_) {
0124 bool cond1 = y == 0 && x >= (-hexside_ * sqrt(3) / 2.);
0125 bool cond2 = ((y + hexside_) >= -x / sqrt(3)) && (y < 0 && x < 0);
0126 bool cond3 = (y * sqrt(3) >= (x - hexside_ * sqrt(3))) && (y < 0 && x > 0);
0127 bool cond4 = y == 0 && x <= (hexside_ * sqrt(3) / 2.);
0128 bool cond5 = (-y * sqrt(3) >= (x - hexside_ * sqrt(3))) && (y > 0 && x > 0);
0129 bool cond6 = ((y - hexside_) <= x / sqrt(3)) && (y > 0 && x < 0);
0130 flag = cond1 || cond2 || cond3 || cond4 || cond5 || cond6;
0131 } else {
0132 double absx = std::abs(x);
0133 double absy = std::abs(y);
0134 if (absx <= hexwidth_ && absy <= hexside_) {
0135 if (absy <= hexwidth_ * tan30deg_ || absx <= (2. * hexwidth_ - absy / tan30deg_))
0136 flag = true;
0137 }
0138 }
0139
0140 #ifdef EDM_ML_DEBUG
0141 if (verbosity_)
0142 edm::LogVerbatim("HGCSim") << "Selection Flag " << flag;
0143 #endif
0144 return flag;
0145 }
0146
0147
0148
0149 void HGCalTBCheckGunPostion::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0150
0151
0152
0153
0154 edm::ParameterSetDescription desc;
0155 desc.setUnknown();
0156 descriptions.addDefault(desc);
0157 }
0158
0159
0160 DEFINE_FWK_MODULE(HGCalTBCheckGunPostion);