CMS 3D CMS Logo

CosmicTIFTrigFilter.cc
Go to the documentation of this file.
1 // livio.fano@cern.ch
2 
7 //#include "MagneticField/Engine/interface/MagneticField.h"
8 //#include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
9 #include "HepMC/GenVertex.h"
10 #include <map>
11 #include <vector>
12 
13 using namespace std;
14 namespace cms
15 
16 {
17  CosmicTIFTrigFilter::CosmicTIFTrigFilter(const edm::ParameterSet &conf)
18  : m_Token(consumes<edm::HepMCProduct>(
19  conf.getParameter<edm::ParameterSet>("Generator").getParameter<std::string>("HepMCProductLabel"))) {
20  trigconf = conf.getParameter<int>("trig_conf");
21  trigS1 = conf.getParameter<std::vector<double>>("PosScint1");
22  trigS2 = conf.getParameter<std::vector<double>>("PosScint2");
23  trigS3 = conf.getParameter<std::vector<double>>("PosScint3");
24  trigS4 = conf.getParameter<std::vector<double>>("PosScint4");
25 
26  /*
27  std::cout << "S1 = " << trigS1[0] << ", " << trigS1[1] << ", " <<trigS1[2]
28  << "\nS2 = " << trigS2[0] << ", " << trigS2[1] << ", " <<trigS2[2]
29  << "\nS3 = " << trigS3[0] << ", " << trigS3[1] << ", " <<trigS3[2]
30  << "\nS4 = " << trigS4[0] << ", " << trigS4[1] << ", " <<trigS4[2]
31  << std::endl;
32  */
33  }
34 
37  iEvent.getByToken(m_Token, HepMCEvt);
38 
39  const HepMC::GenEvent *MCEvt = HepMCEvt->GetEvent();
40 
41  bool hit1 = false;
42  bool hit2 = false;
43  bool hit3 = false;
44  bool hit4 = false;
45 
46  for (HepMC::GenEvent::particle_const_iterator i = MCEvt->particles_begin(); i != MCEvt->particles_end(); ++i) {
47  int myId = (*i)->pdg_id();
48  if (abs(myId) == 13) {
49  // Get the muon position and momentum
50  HepMC::GenVertex *pv = (*i)->production_vertex();
51  const HepMC::FourVector &vertex = pv->position();
52 
53  HepMC::FourVector momentum = (*i)->momentum();
54 
55  // std::cout << "\t vertex for cut = " << vertex << std::endl;
56  // std::cout << "\t momentum = " << momentum << std::endl;
57 
58  if (trigconf == 1) {
59  HepMC::FourVector S1(trigS1[0], trigS1[1], trigS1[2], 0.);
60  HepMC::FourVector S2(trigS2[0], trigS2[1], trigS2[2], 0.);
61  HepMC::FourVector S3(trigS3[0], trigS3[1], trigS3[2], 0.);
62 
63  hit1 = Sci_trig(vertex, momentum, S1);
64  hit2 = Sci_trig(vertex, momentum, S2);
65  hit3 = Sci_trig(vertex, momentum, S3);
66 
67  // trigger conditions
68 
69  if ((hit1 && hit2) || (hit3 && hit2)) {
70  /*
71  cout << "\tGot a trigger in configuration A " << endl;
72  if(hit1)cout << "hit1 " << endl;
73  if(hit2)cout << "hit2 " << endl;
74  if(hit3)cout << "hit3 " << endl;
75  */
76  trig1++;
77  return true;
78  }
79  } else if (trigconf == 2) {
80  HepMC::FourVector S1(trigS1[0], trigS1[1], trigS1[2], 0.);
81  HepMC::FourVector S2(trigS2[0], trigS2[1], trigS2[2], 0.);
82  HepMC::FourVector S3(trigS3[0], trigS3[1], trigS3[2], 0.);
83 
84  hit1 = Sci_trig(vertex, momentum, S1);
85  hit2 = Sci_trig(vertex, momentum, S2);
86  hit3 = Sci_trig(vertex, momentum, S3);
87 
88  // trigger conditions
89 
90  if ((hit1 && hit2) || (hit3 && hit2)) {
91  /*
92  cout << "\tGot a trigger in configuration B " << endl;
93  if(hit1)cout << "hit1 " << endl;
94  if(hit2)cout << "hit2 " << endl;
95  if(hit3)cout << "hit3 " << endl;
96  */
97  trig2++;
98  return true;
99  }
100 
101  } else if (trigconf == 3) {
102  HepMC::FourVector S1(trigS1[0], trigS1[1], trigS1[2], 0.);
103  HepMC::FourVector S2(trigS2[0], trigS2[1], trigS2[2], 0.);
104  HepMC::FourVector S3(trigS3[0], trigS3[1], trigS3[2], 0.);
105  HepMC::FourVector S4(trigS4[0], trigS4[1], trigS4[2], 0.);
106 
107  /* std::cout << "S1 = " << S1.x() << "," << S1.y() << ", " <<
108  S1.z()
109  << "\nS2 = " << S2.x() << "," << S2.y() << ", " << S2.z()
110  << "\nS3 = " << S3.x() << "," << S3.y() << ", " << S3.z()
111  << "\nS4 = " << S4.x() << "," << S4.y() << ", " << S4.z()
112  << std::endl;
113  */
114 
115  hit1 = Sci_trig(vertex, momentum, S1);
116  hit2 = Sci_trig(vertex, momentum, S2);
117  hit3 = Sci_trig(vertex, momentum, S3);
118  hit4 = Sci_trig(vertex, momentum, S4);
119 
120  // trigger conditions
121  if ((hit1 && hit2) || (hit3 && hit2) || (hit1 && hit4) || (hit3 && hit4)) {
122  /*
123  cout << "\tGot a trigger in configuration C " << endl;
124  if(hit1)cout << "hit1 " << endl;
125  if(hit2)cout << "hit2 " << endl;
126  if(hit3)cout << "hit3 " << endl;
127  if(hit4)cout << "hit4 " << endl;
128  */
129 
130  trig3++;
131  return true;
132  }
133  }
134  }
135  }
136 
137  return false;
138  }
139 
140  bool CosmicTIFTrigFilter::Sci_trig(const HepMC::FourVector &vertex,
141  const HepMC::FourVector &momentum,
142  const HepMC::FourVector &S) {
143  float x0 = vertex.x();
144  float y0 = vertex.y();
145  float z0 = vertex.z();
146  float px0 = momentum.x();
147  float py0 = momentum.y();
148  float pz0 = momentum.z();
149  float Sx = S.x();
150  float Sy = S.y();
151  float Sz = S.z();
152 
153  float zs = (Sy - y0) * (pz0 / py0) + z0;
154  float xs = (Sy - y0) * (px0 / py0) + x0;
155 
156  // std::cout << Sx << " " << Sz << " " << xs << " " << zs << std::endl;
157  // std::cout << x0 << " " << z0 << " " << px0 << " " << py0 << " " << pz0 <<
158  // endl;
159 
160  if ((xs < Sx + 500 && xs > Sx - 500) && (zs < Sz + 500 && zs > Sz - 500)) {
161  // std::cout << "PASSED" << std::endl;
162  return true;
163  } else {
164  return false;
165  }
166  }
167 } // namespace cms
T getParameter(std::string const &) const
std::vector< double > trigS2
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
std::vector< double > trigS3
int iEvent
Definition: GenABIO.cc:224
std::vector< double > trigS1
std::vector< double > trigS4
def pv(vc)
Definition: MetAnalyzer.py:7
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
Namespace of DDCMS conversion namespace.
bool filter(edm::Event &iEvent, edm::EventSetup const &c) override
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:38
HLT enums.
bool Sci_trig(const HepMC::FourVector &, const HepMC::FourVector &, const HepMC::FourVector &)
edm::EDGetTokenT< edm::HepMCProduct > m_Token