Example #1
0
AMSPoint TkSens::FindCloseSensorCenter(){
  AMSPoint pret;
  AMSPoint gcoo=GlobalCoo;
  int Layer = -1;
  Layer=GetLayer();
  if (Layer<=0) return pret;
  TkPlane* pp=TkDBc::Head->GetPlane(TkDBc::Head->_plane_layer[Layer-1]);
  int layJ=TkDBc::Head->GetJFromLayer(Layer);
  AMSPoint planeA;
  if(Layer>7)
     planeA.setp( TrExtAlignDB::GetDynCorr(layJ,0),
		  TrExtAlignDB::GetDynCorr(layJ,1),
		  TrExtAlignDB::GetDynCorr(layJ,2));
  else
    planeA=pp->GetPosA();
  //Alignment corrected Plane postion

  float dzcorr=0;
  if (Layer<=7) dzcorr= TrInnerDzDB::LDZA[Layer-1];
  AMSPoint LayerZCorrection(0,0,dzcorr);
  
  AMSPoint PPosG=planeA+pp->GetPos()+LayerZCorrection;
  if(IsMC()) PPosG=pp->GetPosT()+pp->GetPos();

  //Alignment corrected Plane Rotation matrix
  AMSRotMat PRotG0=pp->GetRotMat();
  AMSRotMat PRotG1;
  if(Layer>7)
    PRotG1.SetRotAngles(TrExtAlignDB::GetDynCorr(layJ,3),
			TrExtAlignDB::GetDynCorr(layJ,4),
			TrExtAlignDB::GetDynCorr(layJ,5));
  else   
    PRotG1=pp->GetRotMatA();

  AMSRotMat PRotG=PRotG0.Invert()*PRotG1.Invert();

  if(IsMC()) {
	  PRotG0=pp->GetRotMat();
	  PRotG1=pp->GetRotMatT();
	  PRotG=PRotG0.Invert()*PRotG1.Invert();
  }
  AMSPoint oo = PRotG*(gcoo-PPosG);

  int otkid=0;
  float max=300;
  double hwid = TkDBc::Head->_ssize_inactive[1]/2;
  for(int ii=1;ii<15;ii++){
    int tkid=Layer*100+ii;
    TkLadder* lad=TkDBc::Head->FindTkId(tkid);
    if(lad==0) tkid*=-1;lad=TkDBc::Head->FindTkId(tkid);
    if(lad==0) continue;
    double hlen = TkCoo::GetLadderLength(tkid)/2
      -(TkDBc::Head->_ssize_inactive[0]-TkDBc::Head->_ssize_active[0])/2;

    AMSRotMat rot0 = lad->GetRotMatA();
    AMSRotMat rot = rot0*lad->GetRotMat();

    AMSPoint  pos = lad->GetPos()+lad->GetPosA();
    AMSPoint  loc(hlen, hwid, 0);
    AMSPoint  Center = rot*loc+pos;
    float dist=fabs(oo[1]-Center[1]);  // Bugfix 2015/01/01 SH
    if(dist<max) {otkid=tkid; max=dist;}
  }
  if(!TkDBc::Head->FindTkId(otkid)) return pret;

  int msens=-1;
  vector<float> csM;
  vector<float> csP;
  TkLadder* ladM=TkDBc::Head->FindTkId(abs(otkid)*-1);
  TkLadder* ladP=TkDBc::Head->FindTkId(abs(otkid));
  if(ladM)
    for (int ii=0;ii<ladM->GetNSensors();ii++)
      csM.push_back(ladM->GetPos()[0]+ladM->GetPosA()[0]+TkDBc::Head->_SensorPitchK*ii+TkDBc::Head->_ssize_active[0]/2);
  if(ladP)
    for (int ii=0;ii<ladP->GetNSensors();ii++)
      csP.push_back(ladP->GetPos()[0]+ladP->GetPosA()[0]-TkDBc::Head->_SensorPitchK*ii-TkDBc::Head->_ssize_active[0]/2);

  float distM=9999;
  int sM=-1;
  for (unsigned int ii=0;ii<csM.size();ii++){
    float dd=fabs(oo[0]-csM[ii]);
    if( dd< distM) {distM=dd; sM=ii;}
  }

  float distP=9999;
  int sP=-1;
  for (unsigned int ii=0;ii<csP.size();ii++){
    float dd=fabs(oo[0]-csP[ii]);
    if( dd< distP) {distP=dd; sP=ii;}
  }
  if(distP<distM){otkid=abs(otkid);msens=sP;}
  else {otkid=abs(otkid)*-1;msens=sM;}
  
  pret=TkCoo::GetGlobalA(otkid,msens*TkDBc::Head->_SensorPitchK+TkDBc::Head->_ssize_active[0]/2,TkDBc::Head->_ssize_inactive[1]/2);
  return pret;
}
Example #2
0
//--------------------------------------------------
int TkSens::GetSens(){
  if(lad_tkid==0) return -1;

  //Get the Ladder Pointer
  TkLadder* lad=TkDBc::Head->FindTkId(lad_tkid);
  if(!lad) return -1;

  //Get The Plane Pointer
  TkPlane * pp=lad->GetPlane();
  int Layer=lad->GetLayer();
  int layJ=lad->GetLayerJ();
  AMSPoint planeA;
  if(Layer>7)
     planeA.setp( TrExtAlignDB::GetDynCorr(layJ,0),
		  TrExtAlignDB::GetDynCorr(layJ,1),
		  TrExtAlignDB::GetDynCorr(layJ,2));
  else
     planeA=pp->GetPosA();
  //Alignment corrected Plane postion
  float dzcorr=0;
  if (Layer<=7) dzcorr= TrInnerDzDB::LDZA[Layer-1];
  AMSPoint LayerZCorrection(0,0,dzcorr);
  
  AMSPoint PPosG=planeA+pp->GetPos()+LayerZCorrection;

  if(IsMC()) PPosG=pp->GetPosT()+pp->GetPos();


  //Alignment corrected Plane Rotation matrix
  AMSRotMat PRotG0=pp->GetRotMat();

  AMSRotMat PRotG1;
  if(Layer>7)
    PRotG1.SetRotAngles(TrExtAlignDB::GetDynCorr(layJ,3),
		      TrExtAlignDB::GetDynCorr(layJ,4),
		      TrExtAlignDB::GetDynCorr(layJ,5));
  else   
    PRotG1=pp->GetRotMatA();

  AMSRotMat PRotG=PRotG0.Invert()*PRotG1.Invert();

  if(IsMC()) {
	  PRotG0=pp->GetRotMat();
	  PRotG1=pp->GetRotMatT();
	  PRotG=PRotG0.Invert()*PRotG1.Invert();
  }


  //Alignment corrected Ladder postion

  AMSPoint PosG=lad->GetPosA()+lad->GetPos();
  if(IsMC()) PosG=lad->GetPosT()+lad->GetPos();

  //Alignment corrected Ladder Rotation matrix
  AMSRotMat RotG0=lad->GetRotMat();
  AMSRotMat RotG1=lad->GetRotMatA();
  AMSRotMat RotG=RotG0.Invert()*RotG1.Invert();
  if(IsMC()) {
	  RotG0=lad->GetRotMat();
	  RotG1=lad->GetRotMatT();
	  RotG=RotG0.Invert()*RotG1.Invert();
  }


  //Convolute with the Plane pos in the space
  AMSPoint oo = PRotG*(GlobalCoo-PPosG);

  //Get the local coo on the Ladder
  SensCoo = RotG*(oo-PosG);

  // PZ Add local Z correction for high precision on z-unaligned cases 
  //Get the global coo from the geometry
  // We donot want this correction for the MC where the Truth rules
  AMSPoint g2;
  if(IsMC()){
    
    g2=GlobalCoo;   //TkCoo::GetGlobalT(lad_tkid,SensCoo[0],SensCoo[1]);

  } else{

    g2=TkCoo::GetGlobalA(lad_tkid,SensCoo[0],SensCoo[1]);
    
    double dz=g2[2]-GlobalCoo[2];
    if(GlobalDir[2]!=0){
      g2[0]=GlobalDir[0]/GlobalDir[2]*dz+GlobalCoo[0];
      g2[1]=GlobalDir[1]/GlobalDir[2]*dz+GlobalCoo[1];
    }else   {
      g2[0]=GlobalCoo[0];
      g2[1]=GlobalCoo[1];
    }
  }
  //Convolute with the Plane pos in the space
  oo = PRotG*(g2-PPosG);

  //Get the local coo on the Ladder
  SensCoo = RotG*(oo-PosG);

  LaddCoo = SensCoo;

  /*
  cout << "GLOBAL " << GlobalCoo.x() << " " << GlobalCoo.y() << " " << GlobalCoo.z() << endl;
  cout << "LADDER " << LaddCoo.x()   << " " << LaddCoo.y()   << " " << LaddCoo.z()   << endl;
  cout << "Plane Rotation" << endl;
  for (int irow=0; irow<3; irow++) 
    for (int icol=0; icol<3; icol++) 
       cout << pp->GetRotMat().GetEl(irow,icol) << " ";
  cout << endl;
  cout << "Plane Inverse Rotation" << endl;
  for (int irow=0; irow<3; irow++)
    for (int icol=0; icol<3; icol++)
       cout << PRotG.GetEl(irow,icol) << " ";
  cout << endl;
  cout << "Ladder Rotation" << endl;
  for (int irow=0; irow<3; irow++)
    for (int icol=0; icol<3; icol++)
       cout << lad->GetRotMat().GetEl(irow,icol) << " ";
  cout << endl;
  cout << "Ladder Inverse Rotation" << endl;
  for (int irow=0; irow<3; irow++)
    for (int icol=0; icol<3; icol++)
       cout << RotG.GetEl(irow,icol) << " ";
  cout << endl;
  cout << "GLODIR " << GlobalDir.x() << " " << GlobalDir.y() << " " << GlobalDir.z() << endl;
  cout << "LADDIR " << LaddDir.x() << " " << LaddDir.y() << " " << LaddDir.z() << endl;
  */

  SensDir = RotG*(PRotG*GlobalDir);
  LaddDir = SensDir;

  //Offset of the first strip position
  double Ax= (TkDBc::Head->_ssize_inactive[0]-
	      TkDBc::Head->_ssize_active[0])/2;

  //Sensor number
  int nsens = (int)(fabs(SensCoo[0]+Ax)/TkDBc::Head->_SensorPitchK); // Bugfix 2015/01/01 SH

  AMSPoint gcoo = GlobalCoo;


  //Sensor alignment correction
  if(
     (!IsMC())  // Sensor disalignement not in simulation
     && (TRCLFFKEY.UseSensorAlign==1)  //explicity enabled in datacard
     && (0 <= nsens && nsens < trconst::maxsen) // within the sensor range
     ) {
    gcoo[0] += lad->_sensx[nsens];
    gcoo[1] += lad->_sensy[nsens];
    gcoo[2] += lad->_sensz[nsens];

    //Get the local coo on the Ladder (again)
    AMSPoint oo2 = PRotG*(gcoo-PPosG);
    SensCoo = RotG*(oo2-PosG);
    LaddCoo = SensCoo;
  }

  //Sensor coordinate
  SensCoo[0] -= nsens*TkDBc::Head->_SensorPitchK;

  return nsens;
}