File indexing completed on 2023-03-17 11:25:46
0001
0002
0003 #include "CosmicTIFTrigFilter.h"
0004
0005 #include "DataFormats/Common/interface/Handle.h"
0006 #include "FWCore/Framework/interface/ESHandle.h"
0007 #include "FWCore/Framework/interface/EventSetup.h"
0008 #include "HepMC/GenVertex.h"
0009 #include <map>
0010 #include <vector>
0011
0012 using namespace std;
0013 namespace cms
0014
0015 {
0016 CosmicTIFTrigFilter::CosmicTIFTrigFilter(const edm::ParameterSet &conf)
0017 : m_Token(consumes<edm::HepMCProduct>(
0018 conf.getParameter<edm::ParameterSet>("Generator").getParameter<std::string>("HepMCProductLabel"))) {
0019 trigconf = conf.getParameter<int>("trig_conf");
0020 trigS1 = conf.getParameter<std::vector<double>>("PosScint1");
0021 trigS2 = conf.getParameter<std::vector<double>>("PosScint2");
0022 trigS3 = conf.getParameter<std::vector<double>>("PosScint3");
0023 trigS4 = conf.getParameter<std::vector<double>>("PosScint4");
0024
0025
0026
0027
0028
0029
0030
0031
0032 }
0033
0034 bool CosmicTIFTrigFilter::filter(edm::Event &iEvent, const edm::EventSetup &iSetup) {
0035 edm::Handle<edm::HepMCProduct> HepMCEvt;
0036 iEvent.getByToken(m_Token, HepMCEvt);
0037
0038 const HepMC::GenEvent *MCEvt = HepMCEvt->GetEvent();
0039
0040 bool hit1 = false;
0041 bool hit2 = false;
0042 bool hit3 = false;
0043 bool hit4 = false;
0044
0045 for (HepMC::GenEvent::particle_const_iterator i = MCEvt->particles_begin(); i != MCEvt->particles_end(); ++i) {
0046 int myId = (*i)->pdg_id();
0047 if (abs(myId) == 13) {
0048
0049 HepMC::GenVertex *pv = (*i)->production_vertex();
0050 const HepMC::FourVector &vertex = pv->position();
0051
0052 HepMC::FourVector momentum = (*i)->momentum();
0053
0054
0055
0056
0057 if (trigconf == 1) {
0058 HepMC::FourVector S1(trigS1[0], trigS1[1], trigS1[2], 0.);
0059 HepMC::FourVector S2(trigS2[0], trigS2[1], trigS2[2], 0.);
0060 HepMC::FourVector S3(trigS3[0], trigS3[1], trigS3[2], 0.);
0061
0062 hit1 = Sci_trig(vertex, momentum, S1);
0063 hit2 = Sci_trig(vertex, momentum, S2);
0064 hit3 = Sci_trig(vertex, momentum, S3);
0065
0066
0067
0068 if ((hit1 && hit2) || (hit3 && hit2)) {
0069
0070
0071
0072
0073
0074
0075 trig1++;
0076 return true;
0077 }
0078 } else if (trigconf == 2) {
0079 HepMC::FourVector S1(trigS1[0], trigS1[1], trigS1[2], 0.);
0080 HepMC::FourVector S2(trigS2[0], trigS2[1], trigS2[2], 0.);
0081 HepMC::FourVector S3(trigS3[0], trigS3[1], trigS3[2], 0.);
0082
0083 hit1 = Sci_trig(vertex, momentum, S1);
0084 hit2 = Sci_trig(vertex, momentum, S2);
0085 hit3 = Sci_trig(vertex, momentum, S3);
0086
0087
0088
0089 if ((hit1 && hit2) || (hit3 && hit2)) {
0090
0091
0092
0093
0094
0095
0096 trig2++;
0097 return true;
0098 }
0099
0100 } else if (trigconf == 3) {
0101 HepMC::FourVector S1(trigS1[0], trigS1[1], trigS1[2], 0.);
0102 HepMC::FourVector S2(trigS2[0], trigS2[1], trigS2[2], 0.);
0103 HepMC::FourVector S3(trigS3[0], trigS3[1], trigS3[2], 0.);
0104 HepMC::FourVector S4(trigS4[0], trigS4[1], trigS4[2], 0.);
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114 hit1 = Sci_trig(vertex, momentum, S1);
0115 hit2 = Sci_trig(vertex, momentum, S2);
0116 hit3 = Sci_trig(vertex, momentum, S3);
0117 hit4 = Sci_trig(vertex, momentum, S4);
0118
0119
0120 if ((hit1 && hit2) || (hit3 && hit2) || (hit1 && hit4) || (hit3 && hit4)) {
0121
0122
0123
0124
0125
0126
0127
0128
0129 trig3++;
0130 return true;
0131 }
0132 }
0133 }
0134 }
0135
0136 return false;
0137 }
0138
0139 bool CosmicTIFTrigFilter::Sci_trig(const HepMC::FourVector &vertex,
0140 const HepMC::FourVector &momentum,
0141 const HepMC::FourVector &S) {
0142 float x0 = vertex.x();
0143 float y0 = vertex.y();
0144 float z0 = vertex.z();
0145 float px0 = momentum.x();
0146 float py0 = momentum.y();
0147 float pz0 = momentum.z();
0148 float Sx = S.x();
0149 float Sy = S.y();
0150 float Sz = S.z();
0151
0152 float zs = (Sy - y0) * (pz0 / py0) + z0;
0153 float xs = (Sy - y0) * (px0 / py0) + x0;
0154
0155
0156
0157
0158
0159 if ((xs < Sx + 500 && xs > Sx - 500) && (zs < Sz + 500 && zs > Sz - 500)) {
0160
0161 return true;
0162 } else {
0163 return false;
0164 }
0165 }
0166 }