Public Member Functions | Private Attributes | List of all members
evgendp::Trigger Class Reference

Public Member Functions

 Trigger ()
 
 ~Trigger ()
 
void AddMuon (simb::MCParticle particle)
 
int GetTriggerId ()
 
double GetTriggerOffsetX ()
 
double GetTriggerOffsetY ()
 
double GetTriggerOffsetZ ()
 
double GetTriggerOffsetT ()
 
TLorentzVector GetTriggerPos ()
 
double GetTriggerPosX ()
 
double GetTriggerPosY ()
 
double GetTriggerPosZ ()
 
double GetTriggerPosT ()
 
TLorentzVector GetTriggerMom ()
 
double GetTriggerMomX ()
 
double GetTriggerMomY ()
 
double GetTriggerMomZ ()
 
double GetTriggerMomT ()
 
void MakeTrigger (CLHEP::HepRandomEngine &engine)
 
double GetPhi (const double py, const double pz)
 
void GetMatrix (double theta, double phi, double(*p_R)[3][3])
 
void DoRotation (double urv[], double dir[], double theta, double phi)
 
bool Intersect (const double x0[], const double dx[], const double bounds[])
 
void ProjectToBoxEdge (const double xyz[], const double indxyz[], const double xlo, const double xhi, const double ylo, const double yhi, const double zlo, const double zhi, double xyzout[])
 
void GetTPCSize (double tpc[])
 
void GetCryoSize (double cryo[])
 
void SetCryoBuffer (std::vector< double > buffer)
 
void SetTPCBuffer (std::vector< double > buffer)
 

Private Attributes

art::ServiceHandle< geo::Geometrygeom
 
std::vector< simb::MCParticlefMuonList
 
simb::MCParticle fTriggerMu
 
TLorentzVector fTriggerPos
 
double fTriggerID = -999
 
double fTriggerPosX
 
double fTriggerPosY
 
double fTriggerPosZ
 
double fTriggerPosT
 
double fTriggerOffsetX
 
double fTriggerOffsetY
 
double fTriggerOffsetZ
 
double fTriggerOffsetT
 
std::vector< double > fTPCBuffer
 
std::vector< double > fCryoBuffer
 

Detailed Description

Definition at line 124 of file Gen311_module.cc.

Constructor & Destructor Documentation

evgendp::Trigger::Trigger ( )

Definition at line 822 of file Gen311_module.cc.

822  {
823  fMuonList.clear();
824 }
std::vector< simb::MCParticle > fMuonList
evgendp::Trigger::~Trigger ( )

Definition at line 826 of file Gen311_module.cc.

826 {}

Member Function Documentation

void evgendp::Trigger::AddMuon ( simb::MCParticle  particle)
inline

Definition at line 131 of file Gen311_module.cc.

131  {
132  fMuonList.push_back(particle); return;
133  };
std::vector< simb::MCParticle > fMuonList
void evgendp::Trigger::DoRotation ( double  urv[],
double  dir[],
double  theta,
double  phi 
)

Definition at line 864 of file Gen311_module.cc.

864  {
865 
866  //build the rotation matrix;
867  double R[3][3];
868  double (*p_R)[3][3]=&R;
869  GetMatrix(theta, phi, p_R);
870 
871  for(int i=0; i<3; i++){
872  for(int j=0; j<3; j++){
873  dir[i] += (*p_R)[i][j]*urv[j];
874  //cout << i << " " << j << " " << urv[j] << " " << (*p_R)[i][j] << " " << dir[i] << endl;
875  }
876  }
877 
878  return;
879 }
string dir
void GetMatrix(double theta, double phi, double(*p_R)[3][3])
void evgendp::Trigger::GetCryoSize ( double  cryo[])

Definition at line 944 of file Gen311_module.cc.

944  {
945 
946  //;
947 
948  double dummy[6] = {0};
949  for(unsigned int c = 0; c < geom->Ncryostats(); ++c){
950  geom->CryostatBoundaries(dummy, c);
951  }
952 
953  for(int i=0;i<6;i++){cryo[i] = dummy[i];}
954 
955  return;
956 }
art::ServiceHandle< geo::Geometry > geom
unsigned int Ncryostats() const
Returns the number of cryostats in the detector.
void CryostatBoundaries(double *boundaries, geo::CryostatID const &cid) const
Returns the boundaries of the specified cryostat.
cet::LibraryManager dummy("noplugin")
void evgendp::Trigger::GetMatrix ( double  theta,
double  phi,
double(*)  p_R[3][3] 
)

Definition at line 849 of file Gen311_module.cc.

849  {
850 
851  (*p_R)[0][0]= cos(phi)*cos(theta);
852  (*p_R)[0][1]= cos(phi)*sin(theta);
853  (*p_R)[0][2]= -sin(phi);
854  (*p_R)[1][0]= -sin(theta);
855  (*p_R)[1][1]= cos(theta);
856  (*p_R)[1][2]= 0;
857  (*p_R)[2][0]= sin(phi)*cos(theta);
858  (*p_R)[2][1]= sin(phi)*sin(theta);
859  (*p_R)[2][2]= cos(phi);
860 
861  return;
862 }
double evgendp::Trigger::GetPhi ( const double  py,
const double  pz 
)

Definition at line 828 of file Gen311_module.cc.

828  {
829 
830  if( pz !=0 ){
831  if( pz > 0 ){
832  return atan( py/pz );
833  }
834  else if( atan( py/pz ) < 0 ){
835  return atan( py/pz )+3.1415926;
836  }
837  else{
838  return atan( py/pz )-3.1415926;
839  }
840  }
841  else if( py > 0 ){
842  return 3.1415926/2.;
843  }
844  else{
845  return -3.1415926/2.;
846  }
847 }
void evgendp::Trigger::GetTPCSize ( double  tpc[])

Definition at line 915 of file Gen311_module.cc.

915  {
916 
917  //art::ServiceHandle<geo::Geometry> geom;
918 
919  double minx=0, miny=0, minz=0;
920  double maxx=0, maxy=0, maxz=0;
921  for (size_t c = 0; c < geom->Ncryostats(); c++){
922  const geo::CryostatGeo& cryostat = geom->Cryostat(c);
923  for (size_t t = 0; t < cryostat.NTPC(); t++){
924  const geo::TPCGeo& tpcg = cryostat.TPC(t);
925  if (tpcg.MinX() < minx) minx = tpcg.MinX();
926  if (tpcg.MaxX() > maxx) maxx = tpcg.MaxX();
927  if (tpcg.MinY() < miny) miny = tpcg.MinY();
928  if (tpcg.MaxY() > maxy) maxy = tpcg.MaxY();
929  if (tpcg.MinZ() < minz) minz = tpcg.MinZ();
930  if (tpcg.MaxZ() > maxz) maxz = tpcg.MaxZ();
931  }
932  }
933 
934  tpc[0] = minx;
935  tpc[1] = maxx;
936  tpc[2] = miny;
937  tpc[3] = maxy;
938  tpc[4] = minz;
939  tpc[5] = maxz;
940 
941  return;
942 }
art::ServiceHandle< geo::Geometry > geom
double MinX() const
Returns the world x coordinate of the start of the box.
Definition: BoxBoundedGeo.h:88
Geometry information for a single TPC.
Definition: TPCGeo.h:38
double MaxX() const
Returns the world x coordinate of the end of the box.
Definition: BoxBoundedGeo.h:91
Geometry information for a single cryostat.
Definition: CryostatGeo.h:43
unsigned int Ncryostats() const
Returns the number of cryostats in the detector.
double MinZ() const
Returns the world z coordinate of the start of the box.
unsigned int NTPC() const
Number of TPCs in this cryostat.
Definition: CryostatGeo.h:181
CryostatGeo const & Cryostat(geo::CryostatID const &cryoid) const
Returns the specified cryostat.
double MaxY() const
Returns the world y coordinate of the end of the box.
const TPCGeo & TPC(unsigned int itpc) const
Return the itpc&#39;th TPC in the cryostat.
Definition: CryostatGeo.cxx:93
double MaxZ() const
Returns the world z coordinate of the end of the box.
double MinY() const
Returns the world y coordinate of the start of the box.
int evgendp::Trigger::GetTriggerId ( )
inline

Definition at line 136 of file Gen311_module.cc.

136  {
137  return fTriggerID;
138  };
TLorentzVector evgendp::Trigger::GetTriggerMom ( )
inline

Definition at line 176 of file Gen311_module.cc.

176  {
177  return fTriggerMu.Momentum();
178  };
const TLorentzVector & Momentum(const int i=0) const
Definition: MCParticle.h:220
simb::MCParticle fTriggerMu
double evgendp::Trigger::GetTriggerMomT ( )
inline

Definition at line 192 of file Gen311_module.cc.

192  {
193  return fTriggerMu.Momentum().T();
194  };
const TLorentzVector & Momentum(const int i=0) const
Definition: MCParticle.h:220
simb::MCParticle fTriggerMu
double evgendp::Trigger::GetTriggerMomX ( )
inline

Definition at line 180 of file Gen311_module.cc.

180  {
181  return fTriggerMu.Momentum().X();
182  };
const TLorentzVector & Momentum(const int i=0) const
Definition: MCParticle.h:220
simb::MCParticle fTriggerMu
double evgendp::Trigger::GetTriggerMomY ( )
inline

Definition at line 184 of file Gen311_module.cc.

184  {
185  return fTriggerMu.Momentum().Y();
186  };
const TLorentzVector & Momentum(const int i=0) const
Definition: MCParticle.h:220
simb::MCParticle fTriggerMu
double evgendp::Trigger::GetTriggerMomZ ( )
inline

Definition at line 188 of file Gen311_module.cc.

188  {
189  return fTriggerMu.Momentum().Z();
190  };
const TLorentzVector & Momentum(const int i=0) const
Definition: MCParticle.h:220
simb::MCParticle fTriggerMu
double evgendp::Trigger::GetTriggerOffsetT ( )
inline

Definition at line 152 of file Gen311_module.cc.

152  {
153  return fTriggerOffsetT;
154  };
double evgendp::Trigger::GetTriggerOffsetX ( )
inline

Definition at line 140 of file Gen311_module.cc.

140  {
141  return fTriggerOffsetX;
142  };
double evgendp::Trigger::GetTriggerOffsetY ( )
inline

Definition at line 144 of file Gen311_module.cc.

144  {
145  return fTriggerOffsetY;
146  };
double evgendp::Trigger::GetTriggerOffsetZ ( )
inline

Definition at line 148 of file Gen311_module.cc.

148  {
149  return fTriggerOffsetZ;
150  };
TLorentzVector evgendp::Trigger::GetTriggerPos ( )
inline

Definition at line 156 of file Gen311_module.cc.

156  {
157  return fTriggerPos;
158  };
TLorentzVector fTriggerPos
double evgendp::Trigger::GetTriggerPosT ( )
inline

Definition at line 172 of file Gen311_module.cc.

172  {
173  return fTriggerPosT;
174  };
double evgendp::Trigger::GetTriggerPosX ( )
inline

Definition at line 160 of file Gen311_module.cc.

160  {
161  return fTriggerPosX;
162  };
double evgendp::Trigger::GetTriggerPosY ( )
inline

Definition at line 164 of file Gen311_module.cc.

164  {
165  return fTriggerPosY;
166  };
double evgendp::Trigger::GetTriggerPosZ ( )
inline

Definition at line 168 of file Gen311_module.cc.

168  {
169  return fTriggerPosZ;
170  };
bool evgendp::Trigger::Intersect ( const double  x0[],
const double  dx[],
const double  bounds[] 
)

Definition at line 881 of file Gen311_module.cc.

881  {
882  //check if the particle intercept the tpc
883 
884  bool intersects_tpc = false;
885  for (int bnd=0; bnd!=6; ++bnd) {
886  if (bnd<2) {
887  double p2[3] = {bounds[bnd], x0[1] + (dx[1]/dx[0])*(bounds[bnd] - x0[0]), x0[2] + (dx[2]/dx[0])*(bounds[bnd] - x0[0])};
888  if ( p2[1] >= bounds[2] && p2[1] <= bounds[3] &&
889  p2[2] >= bounds[4] && p2[2] <= bounds[5] ) {
890  intersects_tpc = true;
891  break;
892  }
893  }
894  else if (bnd>=2 && bnd<4) {
895  double p2[3] = {x0[0] + (dx[0]/dx[1])*(bounds[bnd] - x0[1]), bounds[bnd], x0[2] + (dx[2]/dx[1])*(bounds[bnd] - x0[1])};
896  if ( p2[0] >= bounds[0] && p2[0] <= bounds[1] &&
897  p2[2] >= bounds[4] && p2[2] <= bounds[5] ) {
898  intersects_tpc = true;
899  break;
900  }
901  }
902  else if (bnd>=4) {
903  double p2[3] = {x0[0] + (dx[0]/dx[2])*(bounds[bnd] - x0[2]), x0[1] + (dx[1]/dx[2])*(bounds[bnd] - x0[2]), bounds[bnd]};
904  if ( p2[0] >= bounds[0] && p2[0] <= bounds[1] &&
905  p2[1] >= bounds[2] && p2[1] <= bounds[3] ) {
906  intersects_tpc = true;
907  break;
908  }
909  }
910  }
911 
912  return intersects_tpc;
913 }
BoundingBox bounds(int x, int y, int w, int h)
Definition: main.cpp:37
void evgendp::Trigger::MakeTrigger ( CLHEP::HepRandomEngine &  engine)

Definition at line 997 of file Gen311_module.cc.

997  {
998 
999  //get the coordinates of the tpc and an active volume arount it
1000  double tpc[6] ={0.}; this->GetTPCSize(tpc);
1001  for(int i=0; i<6; i++){ tpc[i] += fTPCBuffer[i]; }
1002 
1003  //get the coordinates of the cryo + a buffer around it
1004  double cryo[6] ={0.}; this->GetCryoSize(cryo);
1005  for(int i=0; i<6; i++){ cryo[i] += fCryoBuffer[i]; }
1006 
1007  CLHEP::RandFlat flat(engine);
1008 
1009  //choose a random muon
1010  if( fMuonList.size() == 0){
1011  mf::LogInfo("Gen311") << "Trigger muon not found! Only Background";
1012  return;
1013  }
1014 
1015  fTriggerMu = fMuonList.at( (int)flat()*fMuonList.size() );
1016 
1017  double px=0,py=0,pz=0;
1018  double p=0, theta=0, phi=0;
1019 
1020  px = fTriggerMu.Momentum().X();
1021  py = fTriggerMu.Momentum().Y();
1022  pz = fTriggerMu.Momentum().Z();
1023 
1024 
1025  p = sqrt(px*px+py*py+pz*pz);
1026  theta = acos(px/p);
1027  phi = this->GetPhi( py, pz );
1028 
1029  double xyz[3] ={0.};
1030  xyz[0]=(tpc[5]-tpc[4])/2-tpc[5];
1031  xyz[1]=(tpc[1]-tpc[0])/2-tpc[1];
1032  xyz[2]=(tpc[3]-tpc[2])/2-tpc[2];
1033 
1034  //define direction
1035  double cos_x=cos(theta);
1036  double cos_y=sin(phi)*sin(theta);
1037  double cos_z=cos(phi)*sin(theta);
1038  double dxyz[3] = { cos_z, cos_x, cos_y };
1039 
1040  //get cr impact size along u and v
1041  double length[2]={0.}; //0 along u, 1 along v
1042  double corner[3]={0.};
1043  double rdm_start[3] ={0.};
1044  double xyzo[3]={0.};
1045 
1046  //loop over the tpc boundaries and project them on u and v
1047  for(int i=0; i<2; i++){
1048  for(int j=2; j<4; j++){
1049  for(int k=4; k<6; k++){
1050 
1051  double dot=0;
1052  double proj[3]={0.}; //projection on the plane
1053  double u=0; double v=0;
1054 
1055  //coordinates of the tpc corner
1056  corner[0] = tpc[k];
1057  corner[1] = tpc[i];
1058  corner[2] = tpc[j];
1059 
1060  //now get the dot product between the corner vector and the plane versor
1061  for( int p=0; p<3; p++ ){ dot+=(corner[p]-xyz[p])*dxyz[p]; }
1062  for( int p=0; p<3; p++ ){ proj[p] = corner[p]-(dot*dxyz[p]); }
1063 
1064  proj[0] -= (tpc[5]-tpc[4])/2; //NB: not really elegant...makes things work though
1065 
1066  //build the rotation matrix;
1067  double R[3][3];
1068  double (*p_R)[3][3]=&R;
1069  this->GetMatrix(theta, phi, p_R);
1070 
1071  //project proj along u and pick the longest
1072  for( int p=0; p<3; p++ ){ u += (*p_R)[p][0]*proj[p]; }
1073  if(length[0] < u){ length[0] = u; }
1074 
1075  //project proj along v and pick the longest projection
1076  for( int p=0; p<3; p++ ){ v += (*p_R)[p][2]*proj[p]; }
1077  if(length[1] < v){ length[1] = v; }
1078 
1079  }//end for k
1080  }//end for j
1081  } //end for i
1082 
1083  bool is_inside=false;
1084  int iteration = 20; //NB: It is harcoded
1085 
1086  while(!is_inside && iteration > 0){
1087 
1088  //We extract a random start over the plane u, v
1089  double u = flat()*2*length[0]-length[0];
1090  double v = flat()*2*length[1]-length[1];;
1091 
1092  //now rotate along the r direction
1093  double urv[3] ={ u, 0, v };
1094  double dir[3]={ 0., 0., 0. };
1095  this->DoRotation( urv, dir, theta, phi );
1096 
1097  //parse the correct direction of our reference system
1098  rdm_start[0] = (double)dir[1];
1099  rdm_start[1] = (double)dir[2];
1100  rdm_start[2] = (double)dir[0]+(tpc[5]-tpc[4])/2;
1101 
1102  double dx[3]={px,py,pz};
1103  this->ProjectToBoxEdge(rdm_start, dx, cryo[0], cryo[1], cryo[2], cryo[3], cryo[4], cryo[5], xyzo);
1104 
1105  if( this->Intersect(xyzo, dx, tpc) ){
1106  is_inside=true;
1107  //mf::LogInfo("Gen311")<< "======> " << iteration;
1108  }else{
1109  //mf::LogInfo("Gen311")<< "======> " << iteration;
1110  iteration--;
1111  }
1112  }//end while
1113 
1114 
1115  if(iteration==0){
1116  mf::LogInfo("Gen311") << "Trigger muon not found in 20 iterations. Only Background";
1117  }
1118 
1119  /*
1120 
1121  double rdm_start[3] ={0.};
1122  rdm_start[0] = 0;
1123  rdm_start[1] = flat()*(tpc[3]-tpc[2])-(tpc[3]-tpc[2])/2;
1124  rdm_start[2] = flat()*(tpc[5]-tpc[4])-(tpc[5]-tpc[4])/2;
1125 
1126  */
1127 
1129  fTriggerPosX = rdm_start[0];
1130  fTriggerPosY = rdm_start[1];
1131  fTriggerPosZ = rdm_start[2];
1132  fTriggerPosT = 0;
1133  fTriggerPos.SetXYZT(rdm_start[0],rdm_start[1],rdm_start[2],0);
1134  fTriggerOffsetX = rdm_start[0] - fTriggerMu.Position().X();
1135  fTriggerOffsetY = rdm_start[1] - fTriggerMu.Position().Y();
1136  fTriggerOffsetZ = rdm_start[2] - fTriggerMu.Position().Z();
1137  fTriggerOffsetT = 0 - fTriggerMu.Position().T();
1138 
1139  return;
1140  }//end make trigger
const TLorentzVector & Position(const int i=0) const
Definition: MCParticle.h:219
void DoRotation(double urv[], double dir[], double theta, double phi)
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
std::vector< double > fCryoBuffer
void GetCryoSize(double cryo[])
string dir
TLorentzVector fTriggerPos
int TrackId() const
Definition: MCParticle.h:210
void ProjectToBoxEdge(const double xyz[], const double indxyz[], const double xlo, const double xhi, const double ylo, const double yhi, const double zlo, const double zhi, double xyzout[])
void GetMatrix(double theta, double phi, double(*p_R)[3][3])
p
Definition: test.py:223
void GetTPCSize(double tpc[])
double GetPhi(const double py, const double pz)
const TLorentzVector & Momentum(const int i=0) const
Definition: MCParticle.h:220
simb::MCParticle fTriggerMu
std::vector< double > fTPCBuffer
std::vector< simb::MCParticle > fMuonList
bool Intersect(const double x0[], const double dx[], const double bounds[])
void evgendp::Trigger::ProjectToBoxEdge ( const double  xyz[],
const double  indxyz[],
const double  xlo,
const double  xhi,
const double  ylo,
const double  yhi,
const double  zlo,
const double  zhi,
double  xyzout[] 
)

Definition at line 958 of file Gen311_module.cc.

966  {
967 
968 
969  //we want to project backwards, so take mirror of momentum
970  const double dxyz[3]={-indxyz[0],-indxyz[1],-indxyz[2]};
971 
972  // Compute the distances to the x/y/z walls
973  double dx = 99.E99;
974  double dy = 99.E99;
975  double dz = 99.E99;
976  if (dxyz[0] > 0.0) { dx = (xhi-xyz[0])/dxyz[0]; }
977  else if (dxyz[0] < 0.0) { dx = (xlo-xyz[0])/dxyz[0]; }
978  if (dxyz[1] > 0.0) { dy = (yhi-xyz[1])/dxyz[1]; }
979  else if (dxyz[1] < 0.0) { dy = (ylo-xyz[1])/dxyz[1]; }
980  if (dxyz[2] > 0.0) { dz = (zhi-xyz[2])/dxyz[2]; }
981  else if (dxyz[2] < 0.0) { dz = (zlo-xyz[2])/dxyz[2]; }
982 
983 
984  // Choose the shortest distance
985  double d = 0.0;
986  if (dx < dy && dx < dz) d = dx;
987  else if (dy < dz && dy < dx) d = dy;
988  else if (dz < dx && dz < dy) d = dz;
989 
990  // Make the step
991  for (int i = 0; i < 3; ++i) {
992  xyzout[i] = xyz[i] + dxyz[i]*d;
993  }
994 
995 }
void evgendp::Trigger::SetCryoBuffer ( std::vector< double >  buffer)
inline

Definition at line 216 of file Gen311_module.cc.

216  {
217  for(int i=0; i<6; i++){ fCryoBuffer.assign( buffer.begin(), buffer.end() ); }
218  }
std::vector< double > fCryoBuffer
void evgendp::Trigger::SetTPCBuffer ( std::vector< double >  buffer)
inline

Definition at line 219 of file Gen311_module.cc.

219  {
220  for(int i=0; i<6; i++){ fTPCBuffer.assign( buffer.begin(), buffer.end() ); }
221  }
std::vector< double > fTPCBuffer

Member Data Documentation

std::vector<double> evgendp::Trigger::fCryoBuffer
private

Definition at line 241 of file Gen311_module.cc.

std::vector<simb::MCParticle> evgendp::Trigger::fMuonList
private

Definition at line 228 of file Gen311_module.cc.

std::vector<double> evgendp::Trigger::fTPCBuffer
private

Definition at line 240 of file Gen311_module.cc.

double evgendp::Trigger::fTriggerID = -999
private

Definition at line 231 of file Gen311_module.cc.

simb::MCParticle evgendp::Trigger::fTriggerMu
private

Definition at line 229 of file Gen311_module.cc.

double evgendp::Trigger::fTriggerOffsetT
private

Definition at line 239 of file Gen311_module.cc.

double evgendp::Trigger::fTriggerOffsetX
private

Definition at line 236 of file Gen311_module.cc.

double evgendp::Trigger::fTriggerOffsetY
private

Definition at line 237 of file Gen311_module.cc.

double evgendp::Trigger::fTriggerOffsetZ
private

Definition at line 238 of file Gen311_module.cc.

TLorentzVector evgendp::Trigger::fTriggerPos
private

Definition at line 230 of file Gen311_module.cc.

double evgendp::Trigger::fTriggerPosT
private

Definition at line 235 of file Gen311_module.cc.

double evgendp::Trigger::fTriggerPosX
private

Definition at line 232 of file Gen311_module.cc.

double evgendp::Trigger::fTriggerPosY
private

Definition at line 233 of file Gen311_module.cc.

double evgendp::Trigger::fTriggerPosZ
private

Definition at line 234 of file Gen311_module.cc.

art::ServiceHandle<geo::Geometry> evgendp::Trigger::geom
private

Definition at line 226 of file Gen311_module.cc.


The documentation for this class was generated from the following file: