Belle II Software  release-05-02-19
CDCCosmicSelectorModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2015 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: CDC group *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <cdc/modules/cdcCosmicSelector/CDCCosmicSelectorModule.h>
12 #include <framework/logging/Logger.h>
13 
14 #include <iostream>
15 
16 using namespace std;
17 using namespace Belle2;
18 
19 // register module
20 REG_MODULE(CDCCosmicSelector)
22 {
23  // Set description
24  setDescription("Modify MCParticles for cosmics so that the global time is zero at y=0 assuming a cosmic trajectory is a line. And select cosmics passing through a trigger counter. This module works only for the event with the no. of primary charged MC particles=1. Please place this module after the event-generator and before FullSim.");
25  setPropertyFlags(c_ParallelProcessingCertified);
26 
27  addParam("xOfCounter", m_xOfCounter, "x-position of trigger counter (cm)", -0.6);
28  addParam("yOfCounter", m_yOfCounter, "y-position of trigger counter (cm)", -13.25);
29  addParam("zOfCounter", m_zOfCounter, "z-position of trigger counter (cm)", 17.3);
30  addParam("phiOfCounter", m_phiOfCounter, "phi-angle of trigger counter (deg)", 0.);
31  addParam("wOfCounter", m_wOfCounter, "full-width of trigger counter (cm)", 7.0);
32  addParam("lOfCounter", m_lOfCounter, "full-length of trigger counter (cm)", 12.5);
33  addParam("TOF", m_tof, "Tof=1(2): TOF from production point to trigger counter (IP) is subtracted", 1);
34  addParam("TOP", m_top, "TOP from hit point to pmt in trigger counter is subtracted (assuming PMT is put at -z end of counter",
35  false);
36  addParam("propSpeed", m_propSpeed, "Light prop. speed in counter (cm/ns)", 14.4);
37  addParam("cryGenerator", m_cryGenerator, "true: CRY generator; false Cosmics generator", true);
38 }
39 
40 void CDCCosmicSelectorModule::initialize()
41 {
42  m_mcParticles.isRequired();
43 }
44 
45 
46 void CDCCosmicSelectorModule::event()
47 {
48  bool returnVal = false;
49 
50  int nMCPs = m_mcParticles.getEntries();
51  if (nMCPs == 0) {
52  B2ERROR("No. of MCParticles=0 in the current event.");
53  setReturnValue(returnVal);
54  return;
55  }
56 
57  /*
58  const double yOfCounter = -16.25 + 3.0;
59  const double wOfCounter = 3.5;
60  const double zminOfCounter = -1.5 - 15.5;
61  const double zmaxOfCounter = -1.5 + 15.5;
62  */
63 
64  // Loop over prim. charged MC particle
65  const double c = 29.9792458; //light speed (cm/ns)
66  double mass = 0.1056583715; //muon mass (GeV)
67  unsigned nPrimChgds = 0;
68 
69  for (int iMCPs = 0; iMCPs < nMCPs; ++iMCPs) {
70  MCParticle* m_P = m_mcParticles[iMCPs];
71 
72  // B2INFO("isPrimaryParticle= " << m_P->isPrimaryParticle());
73  if (!m_P->isPrimaryParticle()) continue;
74 
75  unsigned pid = abs(m_P->getPDG());
76  if (pid == 13) {
77  ++nPrimChgds;
78  } else if (pid == 11) {
79  ++nPrimChgds;
80  mass = 0.000510998928;
81  } else if (pid == 211) {
82  ++nPrimChgds;
83  mass = 0.13957018;
84  } else if (pid == 321) {
85  ++nPrimChgds;
86  mass = 0.493677;
87  } else if (pid == 2212) {
88  ++nPrimChgds;
89  mass = 0.938272046;
90  } else {
91  continue;
92  }
93 
94  // B2INFO("No .of prim. charged MC particles= " << nPrimChgds);
95  if (nPrimChgds > 1) continue;
96 
97  const TVector3 vertex = m_P->getProductionVertex();
98  const double vX0 = vertex.X();
99  const double vY0 = vertex.Y();
100  const double cosphi = cos(m_phiOfCounter * M_PI / 180.);
101  const double sinphi = sin(m_phiOfCounter * M_PI / 180.);
102  //(vx,vy) is prod. vertex in frame rotated in phi wrt lab. frame
103  const double vX = cosphi * vX0 + sinphi * vY0;
104  const double vY = -sinphi * vX0 + cosphi * vY0;
105  const double vZ = vertex.Z();
106 
107  // std::cout <<" "<< std::endl;
108  // std::cout <<"vr,vx,vy,yz= "<< sqrt(vX*vX + vY*vY) <<" "<<vX <<" "<< vY <<" "<< vZ << std::endl;
109 
110  const TVector3 momentum = m_P->getMomentum();
111  //(px,py) is momentum in frame rotated in phi wrt lab. frame
112  const double pX0 = momentum.X();
113  const double pY0 = momentum.Y();
114  const double pX = cosphi * pX0 + sinphi * pY0;
115  const double pY = -sinphi * pX0 + cosphi * pY0;
116  const double pZ = momentum.Z();
117 
118  double xi = -999.;
119  double yi = -999.;
120  double zi = -999.;
121 
122  //(x...,y...) is counter pos. in frame rotated in phi wrt lab. frame
123  const double xOfCounter = cosphi * m_xOfCounter + sinphi * m_yOfCounter;
124  const double yOfCounter = -sinphi * m_xOfCounter + cosphi * m_yOfCounter;
125 
126  if (pY != 0.) {
127  xi = (yOfCounter - vY) * (pX / pY) + vX;
128  yi = yOfCounter;
129  zi = (yOfCounter - vY) * (pZ / pY) + vZ;
130  } else {
131  //todo improve the following 3 lines and add check accept or not also in y-direction
132  xi = 0.;
133  yi = yOfCounter;
134  zi = -vX * (pZ / pX) + vZ;
135  }
136 
137  // std::cout << "xi,yi,zi= " << xi <<" "<< yi <<" "<< zi << std::endl;
138 
139  bool hitCounter = (fabs(xi - xOfCounter) < 0.5 * m_wOfCounter && fabs(zi - m_zOfCounter) < 0.5 * m_lOfCounter) ? true : false;
140 
141  //if hit, re-set the production time to zero at IP
142  if (hitCounter) {
143  // std::cout <<"checkxiyizi " << cosphi*xi-sinphi*yi<<" "<< sinphi*xi+cosphi *yi <<" "<< zi << std::endl;
144  returnVal = true;
145  const double p = sqrt(pX * pX + pY * pY + pZ * pZ);
146  const double cX = pX / p;
147  const double cY = pY / p;
148 
149  double fl = 0.;
150  if (m_tof == 1) {
151  fl = sqrt((xi - vX) * (xi - vX) + (yi - vY) * (yi - vY) + (zi - vZ) * (zi - vZ)); // fl to counter
152  // std::cout <<"fl= " << fl << std::endl;
153  } else if (m_tof == 2) {
154  fl = -(cX * vX + cY * vY) / (cX * cX + cY * cY); //fl to origin
155  } else {
156  B2FATAL("invalid tof option !");
157  }
158  // if (fl < 0.) B2FATAL("negative tof !");
159  // std::cout << "fl,flp,dif= " << fl <<" "<< flp <<" "<< fl-flp << std::endl;
160  // double dot = pX*(xi - vX) + pY*(yi - vY);
161  // if (dot < 0.) fl *= -1.;
162 
163  const double beta = p / sqrt(p * p + mass * mass);
164  double pTime = m_P->getProductionTime();
165  // const double pTimeOrg = pTime;
166 
167  if (m_cryGenerator) {
168  //calculate an intersection with y=0 plane
169  double xi4cry = -999.;
170  double yi4cry = 0.;
171  double zi4cry = -999.;
172  if (pY0 != 0.) {
173  xi4cry = (0. - vY0) * (pX0 / pY0) + vX0;
174  zi4cry = (0. - vY0) * (pZ / pY0) + vZ;
175  } else {
176  xi4cry = 0.;
177  zi4cry = -vX0 * (pZ / pX0) + vZ;
178  }
179 
180  const double fl4cry = sqrt((xi4cry - vX0) * (xi4cry - vX0) + (yi4cry - vY0) * (yi4cry - vY0) + (zi4cry - vZ) *
181  (zi4cry - vZ)); // fl to y=0 plane
182 
183  //reset production time (to the time which old CRY set) once
184  pTime += fl4cry / (c * beta);
185  }
186 
187  const double tofToCounter = fl / (c * beta);
188  const double topToPMT = m_top ? hypot(xi - xOfCounter, zi - (m_zOfCounter - 0.5 * m_lOfCounter)) / m_propSpeed : 0.;
189  /*
190  std::cout << "xi = " << xi << std::endl;
191  std::cout << "xOfCounter = " << xOfCounter << std::endl;
192  std::cout << "zi = " << zi << std::endl;
193  std::cout << "m_zOfCounter= " << m_zOfCounter << std::endl;
194  std::cout << "m_lOfCounter= " << m_lOfCounter << std::endl;
195  std::cout << "m_propSpeed = " << m_propSpeed << std::endl;
196  std::cout << "topToPMT = " << topToPMT << std::endl;
197  */
198  m_P->setProductionTime(pTime - tofToCounter - topToPMT);
199  // std::cout <<"org,mod= " << pTimeOrg << m_P->getProductionTime() << std::endl;
200  //if not hit, reverse the momentum vector so that the particle will not be simulated
201  //better to use condition in basf2...
202  } else {
203  // m_P->setMomentum(-1. * momentum);
204 
205  }
206  } // end loop over MCParticles
207  setReturnValue(returnVal);
208 }
Belle2::CDCCosmicSelectorModule
The Class for.
Definition: CDCCosmicSelectorModule.h:42
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::MCParticle::isPrimaryParticle
bool isPrimaryParticle() const
Check if particle is a primary particle which was created by the generator (and not,...
Definition: MCParticle.h:588
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2::MCParticle::setProductionTime
void setProductionTime(float time)
Set production time.
Definition: MCParticle.h:392
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::MCParticle::getProductionVertex
TVector3 getProductionVertex() const
Return production vertex position.
Definition: MCParticle.h:200
Belle2::MCParticle::getPDG
int getPDG() const
Return PDG code of particle.
Definition: MCParticle.h:123
Belle2::MCParticle::getMomentum
TVector3 getMomentum() const
Return momentum.
Definition: MCParticle.h:209
Belle2::MCParticle
A Class to store the Monte Carlo particle information.
Definition: MCParticle.h:43
Belle2::MCParticle::getProductionTime
float getProductionTime() const
Return production time in ns.
Definition: MCParticle.h:170