File indexing completed on 2024-04-06 12:11:15
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #include <memory>
0021
0022
0023 #include "FWCore/Framework/interface/Frameworkfwd.h"
0024 #include "FWCore/Framework/interface/stream/EDProducer.h"
0025
0026 #include "FWCore/Framework/interface/Event.h"
0027 #include "FWCore/Framework/interface/MakerMacros.h"
0028
0029 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0030 #include "FWCore/Utilities/interface/StreamID.h"
0031
0032
0033 #include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
0034
0035
0036 #include <vector>
0037 #include <iostream>
0038
0039
0040 #include "HepMC/GenEvent.h"
0041 #include "HepMC/GenVertex.h"
0042 #include "HepMC/GenParticle.h"
0043 #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
0044 #include "SimDataFormats/Forward/interface/LHCTransportLink.h"
0045
0046 #include "DataFormats/Math/interface/LorentzVector.h"
0047
0048 #include "DataFormats/GeometryVector/interface/LocalPoint.h"
0049 #include "DataFormats/GeometryVector/interface/LocalVector.h"
0050
0051 #include "Utilities/PPS/interface/PPSUnitConversion.h"
0052
0053
0054
0055
0056
0057 class CTPPSSimHitProducer : public edm::stream::EDProducer<> {
0058 public:
0059 explicit CTPPSSimHitProducer(const edm::ParameterSet&);
0060 ~CTPPSSimHitProducer() override;
0061
0062 private:
0063 void beginStream(edm::StreamID) override;
0064 void produce(edm::Event&, const edm::EventSetup&) override;
0065 void endStream() override;
0066
0067 edm::EDGetTokenT<edm::HepMCProduct> mcEventToken;
0068 edm::Handle<edm::HepMCProduct> EvtHandle;
0069
0070 double fz_tracker1, fz_tracker2, fz_timing;
0071 };
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084 CTPPSSimHitProducer::CTPPSSimHitProducer(const edm::ParameterSet& iConfig) {
0085 produces<edm::PSimHitContainer>("CTPPSHits");
0086
0087 mcEventToken =
0088 mayConsume<edm::HepMCProduct>(iConfig.getUntrackedParameter<edm::InputTag>("MCEvent", std::string("")));
0089
0090
0091 fz_tracker1 = iConfig.getParameter<double>("Z_Tracker1");
0092 fz_tracker2 = iConfig.getParameter<double>("Z_Tracker2");
0093 fz_timing = iConfig.getParameter<double>("Z_Timing");
0094 }
0095
0096 CTPPSSimHitProducer::~CTPPSSimHitProducer() {}
0097
0098
0099
0100
0101
0102
0103 void CTPPSSimHitProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0104 using namespace edm;
0105
0106 std::vector<PSimHit> theCTPPSHits;
0107 iEvent.getByToken(mcEventToken, EvtHandle);
0108
0109 const HepMC::GenEvent* Evt = EvtHandle->GetEvent();
0110 std::vector<math::XYZTLorentzVector> protonCTPPS;
0111 protonCTPPS.clear();
0112 for (HepMC::GenEvent::vertex_const_iterator ivtx = Evt->vertices_begin(); ivtx != Evt->vertices_end(); ivtx++) {
0113 if ((*ivtx)->id() != 0)
0114 continue;
0115 double prim_vtxZ = (*ivtx)->position().z() * mm_to_m;
0116
0117 for (HepMC::GenVertex::particles_out_const_iterator i = (*ivtx)->particles_out_const_begin();
0118 i != (*ivtx)->particles_out_const_end();
0119 ++i) {
0120 int pid = (*i)->pdg_id();
0121 if (pid != 2212)
0122 continue;
0123
0124 HepMC::GenVertex* pv = (*i)->production_vertex();
0125 const HepMC::FourVector& vertex = pv->position();
0126 const HepMC::FourVector p((*i)->momentum());
0127 protonCTPPS.push_back(math::XYZTLorentzVector(p.x(), p.y(), p.z(), p.t()));
0128
0129 LocalPoint initialPosition_tr1, initialPosition_tr2, initialPosition_tof;
0130
0131 double t0_tr1 = 0., t0_tr2 = 0., t0_tof = 0.;
0132
0133
0134 const double c_light_s = 2.99792458e+11;
0135 const double s_to_ns = 1.e9;
0136 const double m_to_mm = 1.e3;
0137 double x_tr1 = 0., x_tr2 = 0., x_tof = 0., y_tr1 = 0., y_tr2 = 0., y_tof = 0., z_tr1 = 0.;
0138 double z_tr2 = fz_tracker2;
0139 double z_tof = fz_timing;
0140 int Direction = 0;
0141
0142
0143 if (std::abs(vertex.eta()) > 8. && (*i)->status() == 1) {
0144 if (vertex.z() > 0)
0145 Direction = 1;
0146 else if (vertex.z() < 0)
0147 Direction = -1;
0148
0149
0150 x_tr1 = vertex.x();
0151 y_tr1 = vertex.y();
0152 z_tr1 = vertex.z() * mm_to_m;
0153 Local3DPoint xyzzy_tr1(x_tr1, y_tr1, z_tr1);
0154 initialPosition_tr1 = xyzzy_tr1;
0155 t0_tr1 = vertex.t() / c_light_s * s_to_ns;
0156
0157 t0_tr2 = z_tr2 * m_to_mm / c_light_s * s_to_ns;
0158 t0_tr2 = t0_tr1 + (z_tr2 - z_tr1) * m_to_mm / c_light_s * s_to_ns;
0159 z_tr2 *= Direction;
0160 x_tr2 = x_tr1 + (p.x() / p.z()) * (z_tr2 - z_tr1) * m_to_mm;
0161 y_tr2 = y_tr1 + (p.y() / p.z()) * (z_tr2 - z_tr1) * m_to_mm;
0162 Local3DPoint xyzzy_tr2(x_tr2, y_tr2, z_tr2);
0163 initialPosition_tr2 = xyzzy_tr2;
0164
0165 t0_tof = z_tof * m_to_mm / c_light_s * s_to_ns;
0166 t0_tof = (z_tof - prim_vtxZ) * m_to_mm / c_light_s * s_to_ns;
0167 z_tof *= Direction;
0168 x_tof = x_tr1 + (p.x() / p.z()) * (z_tof - z_tr1) * m_to_mm;
0169 y_tof = y_tr1 + (p.y() / p.z()) * (z_tof - z_tr1) * m_to_mm;
0170 Local3DPoint xyzzy_tof(x_tof, y_tof, z_tof);
0171 initialPosition_tof = xyzzy_tof;
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181 if (Direction > 0.) {
0182 PSimHit hit_tr1(xyzzy_tr1, xyzzy_tr1, 0., t0_tr1, 0., pid, 2014314496, 0, 0., 0., 2);
0183 PSimHit hit_tr2(xyzzy_tr2, xyzzy_tr2, 0., t0_tr2, 0., pid, 2014838784, 0, 0., 0., 2);
0184 PSimHit hit_tof(xyzzy_tof, xyzzy_tof, 0., t0_tof, 0., pid, 2046820352, 0, 0., 0., 2);
0185 theCTPPSHits.push_back(hit_tr1);
0186 theCTPPSHits.push_back(hit_tr2);
0187 theCTPPSHits.push_back(hit_tof);
0188 }
0189 if (Direction < 0.) {
0190 PSimHit hit_tr1(xyzzy_tr1, xyzzy_tr1, 0., t0_tr1, 0., pid, 2031091712, 0, 0., 0., 2);
0191 PSimHit hit_tr2(xyzzy_tr2, xyzzy_tr2, 0., t0_tr2, 0., pid, 2031616000, 0, 0., 0., 2);
0192 PSimHit hit_tof(xyzzy_tof, xyzzy_tof, 0., t0_tof, 0., pid, 2063597568, 0, 0., 0., 2);
0193 theCTPPSHits.push_back(hit_tr1);
0194 theCTPPSHits.push_back(hit_tr2);
0195 theCTPPSHits.push_back(hit_tof);
0196 }
0197 }
0198 }
0199 }
0200 std::unique_ptr<edm::PSimHitContainer> pctpps(new edm::PSimHitContainer);
0201 for (std::vector<PSimHit>::const_iterator i = theCTPPSHits.begin(); i != theCTPPSHits.end(); i++) {
0202 pctpps->push_back(*i);
0203 }
0204 iEvent.put(std::move(pctpps), "CTPPSHits");
0205 }
0206
0207
0208 void CTPPSSimHitProducer::beginStream(edm::StreamID) {}
0209
0210
0211 void CTPPSSimHitProducer::endStream() {}
0212
0213
0214 DEFINE_FWK_MODULE(CTPPSSimHitProducer);