示例#1
0
文件: tkgeom.C 项目: krafczyk/AMS
void BuildHybrid(AMSgvolume *mvol, int tkid)
{
// Build hybrid geometry

  TkLadder *lad = TkDBc::Head->FindTkId(tkid);
  if (!lad) return;

  int layer = std::abs(tkid)/100;
  int plane= TkDBc::Head->_plane_layer[layer-1];
  int sign  = (tkid > 0) ? 1 : -1;

  char name[5];
  std::ostrstream ost(name,sizeof(name));
  ost << ((tkid < 0) ? "ELL" : "ELR") << layer << std::ends;

  geant par[3];
  if(layer==1 ||layer==8||layer==9){
    par[0] = TkDBc::Head->_zelec[2]/2.;
    par[1] = TkDBc::Head->_zelec[1]/2.;
    par[2] = TkDBc::Head->_zelec[0]/2.;
  }else{
    par[0] = TkDBc::Head->_zelec[0]/2.;
    par[1] = TkDBc::Head->_zelec[1]/2.;
    par[2] = TkDBc::Head->_zelec[2]/2.;
  }
  double hlen = TkCoo::GetLadderLength(tkid)/2
    -(TkDBc::Head->_ssize_inactive[0]-TkDBc::Head->_ssize_active[0])/2;
  double hwid = TkDBc::Head->_ssize_active[1]/2;

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

  AMSPoint  pos = lad->GetPos()+lad->GetPosT();
  AMSPoint  loc(hlen, hwid, 0);
  AMSPoint  oo = rot*loc+pos;

  // Get coordinate w.r.t. the mother layer
  geant coo[3];
  coo[0] = oo.x() +sign*(TkCoo::GetLadderLength(tkid)/2+par[0]+0.003);
  coo[1] = oo.y();
  coo[2] = (std::abs(oo.z())/oo.z())*(TkDBc::Head->_sup_hc_w[plane-1]/2.+par[2]+0.1); 
  if(layer==1) coo[2] -= TkDBc::Head->_dz[0];
  if(layer==8) coo[2] -= TkDBc::Head->_dz[4];
  if(layer==9) coo[2] -= TkDBc::Head->_dz[5];


  
  number nrm[3][3];
  VZERO(nrm,9*sizeof(nrm[0][0])/4);
  nrm[0][0] = nrm[1][1] = nrm[2][2] = 1;

  int gid = tkid+1000;
  mvol->add(new AMSgvolume("ELECTRONICS", _nrot++, name,
			   "BOX", par, 3, coo, nrm, "ONLY", 1, gid, 1));
}
示例#2
0
bool TofGeometry::IsInsidePlane(AMSPoint x[3], AMSPoint point) {
  float x0 = x[0].x(); float y0 = x[0].y(); float z0 = x[0].z();
  float x1 = x[1].x(); float y1 = x[1].y(); float z1 = x[1].z();
  float x2 = x[2].x(); float y2 = x[2].y(); float z2 = x[2].z();
  float a = (y2 - y0)*(z1 - z0) - (z2 - z0)*(y1 - y0);
  float b = (z2 - z0)*(x1 - x0) - (x2 - x0)*(z1 - z0);
  float c = (x2 - x0)*(y1 - y0) - (y2 - y0)*(x1 - x0);
  float d = - a*x0 - b*y0 - c*z0;
  float result = a*point.x() + b*point.y() + c*point.z() + d;
  return (fabs(result)<0.01); // .1 mm
}
示例#3
0
文件: GausBF.C 项目: krafczyk/AMS
Int_t GausBF::Find(AMSPoint pt1, AMSPoint pt2)
{
  AMSDir   d  = pt2-pt1;
  AMSPoint p1 = pt1+d*(TkDBc()->GetZlayerAJ(1)-pt1.z())/d.z();
  AMSPoint p9 = pt1+d*(TkDBc()->GetZlayerAJ(9)-pt1.z())/d.z();

  if (p1.x() < 0) { p1[0] *= -1; p9[0] *= -1; }
  if (p1.y() < 0) { p1[1] *= -1; p9[1] *= -1; }

  Int_t l1 = TMath::Floor(p1.y()/TkDBc()->_ladder_Ypitch+0.5);
  Int_t l9 = TMath::Floor(p9.y()/TkDBc()->_ladder_Ypitch);
  Int_t s1 = TMath::Floor(p1.x()/TkDBc()->_SensorPitchK);
  Int_t s9 = TMath::Floor(p9.x()/TkDBc()->_SensorPitchK);

  if (l1 <  0 || l1 > 5 || s1 <   0 || s1 >= Nsen1[l1] ||
      l9 < -4 || l9 > 3 || s9 < -11 || s9 >= 11) return -1;

  Int_t is1 = s1;
  for (Int_t l = 0; l < l1; l++) is1 += Nsen1[l];

  if (s9 >= 0) l9 = 11-l9; else { l9 += 4; s9 = -s9-1; }
  Int_t is9 = l9*11+s9;

  if ((is1 == 59 && is9 == 98) || (is1 == 59 && is9 == 109) ||
      (is1 == 73 && is9 == 98) || (is1 == 86 && is9 ==  97) ||
      (is1 == 86 && is9 == 98) || (is1 == 97 && is9 ==  98)) return -1;

  return is9*100+is1;
}
示例#4
0
int TofGeometry::GetTofPaddleIndex(AMSPoint point, float delta) {
  int index = -1;
  int nfound = 0;
  for (int ilayer=0; ilayer<4; ilayer++) {
    for (int ibar=0; ibar<GetNBars(ilayer); ibar++) {
      // z check
      if (fabs(point.z()-GetZPaddle(ilayer,ibar))>0.5) continue;
      // xy check
      if (HitCounter(point.x(),point.y(),ilayer,ibar,delta)) {
        index = ilayer*10 + ibar;
        nfound++;
      }
    }
  }
  if (nfound>1) return -nfound; 
  return index;
}
示例#5
0
AMSPoint TofGeometry::GetIntersection(AMSPoint x[3], AMSPoint point, AMSDir dir) {
  // plane equation, ax + by + cz + d = 0
  float x0 = x[0].x(); float y0 = x[0].y(); float z0 = x[0].z();
  float x1 = x[1].x(); float y1 = x[1].y(); float z1 = x[1].z();
  float x2 = x[2].x(); float y2 = x[2].y(); float z2 = x[2].z();
  float a = (y2 - y0)*(z1 - z0) - (z2 - z0)*(y1 - y0);
  float b = (z2 - z0)*(x1 - x0) - (x2 - x0)*(z1 - z0);
  float c = (x2 - x0)*(y1 - y0) - (y2 - y0)*(x1 - x0);
  float d = - a*x0 - b*y0 - c*z0;
  // parametric line (x,y,z) = (A,B,C)*t + (X,Y,Z) 
  float A = dir.x();   float B = dir.y();   float C = dir.z();
  float X = point.x(); float Y = point.y(); float Z = point.z();
  // intersection  
  if (fabs(a*A + b*B + c*C)<1e-6) return AMSPoint(-300,-300,-300);
  float t = - (a*X + b*Y + c*Z + d) / (a*A + b*B + c*C);
  return AMSPoint(A*t + X, B*t + Y, C*t + Z);
}
示例#6
0
float TofGeometry::PathLengthInAPaddle(int il, int ib, AMSPoint point, AMSDir dir) {
  if ( (il<0)||(il>3)||(ib<0)||(ib>9) ) return false;
  // check intersection with every surface 
  AMSPoint points[6];
  int      npoints = 0;
  for (int isurface=0; isurface<6; isurface++) {
    AMSPoint x[4] = {
      TofGeometry::GetPaddleSurfaceCorner(il,ib,isurface,0),
      TofGeometry::GetPaddleSurfaceCorner(il,ib,isurface,1),
      TofGeometry::GetPaddleSurfaceCorner(il,ib,isurface,2),
      TofGeometry::GetPaddleSurfaceCorner(il,ib,isurface,3)
    };
    AMSPoint intersection = GetIntersection(x,point,dir);
    if (!IsInsideRectangle(x,intersection)) continue;
    points[npoints].setp(intersection.x(),intersection.y(),intersection.z());
    npoints++;
  }
  // in the case of 2 intersection the particle is entering and exiting 
  if (npoints!=2) return 0.;
  return (points[1] - points[0]).norm();
}
示例#7
0
bool goldenTRD(AMSEventR* ev, int s,int fit) {
    //chiedo che la traccia del TRD sia compatibile con quella del TRACKER

    int TRDclustersontrack=0;
    if (!ev->pTrdTrack(0)) return false;
    for(int i=0;i<ev->pTrdTrack(0)->NTrdSegment();i++) {
    for(int j=0; j<ev->pTrdTrack(0)->pTrdSegment(i)->NTrdCluster();j++)
    TRDclustersontrack++;}
    if(!ev->pTrTrack(0)) return false;
    TrTrackR* track=ev->pTrTrack(0);
    int fitID=track->iTrTrackPar(1,fit,1);
    bool golden=false;
    TrdHTrackR* trd_track;
    for(int i=0;/* i<ev->nTrdHTrack()*/i<1;i++)
    {
            trd_track=ev->pTrdHTrack(i);
            if(trd_track>0)
            {
                    int nHits=ev->nTrdRawHit();
                    int nHitsonTrack=trd_track->Nhits;
                    if(1!=10000000000)
                    {
                            if(trd_track->status>0)
                            {
                                    AMSPoint pnt;
                                    AMSDir dir;
                                    TrTrackR* track=ev->pTrTrack(0);
                                    track->Interpolate(trd_track->Coo[2],pnt,dir,fitID);

                                    Double_t dtx=pnt.x()-trd_track->Coo[0];
                                    Double_t dty=pnt.y()-trd_track->Coo[1];
                                    if(dtx*dtx+dty*dty<(1.5-(s*10*1.5/100))*(1.5-(s*10*1.5/100))) golden=true;
                            }
                    }
            }
    }
    return golden;
}
示例#8
0
文件: GausBF.C 项目: krafczyk/AMS
TF1 *GausBF::GetPr(Int_t is1, Int_t is9, Double_t rgt) const
{
  AMSPoint  p1 = GetP1(is1);
  AMSPoint  p9 = GetP9(is9);
  AMSPoint pnt = p1;
  AMSDir   dir = p9-p1;

  TF1 *fdr = GetDf(is1, is9, rgt);
  Double_t dy0 = fdr->Eval(p1.z())-dir.y()/dir.z();

  Int_t ip = 11;
  TString str = Form("[0]+[1]*(x-%.4f)-(%f)*(x-27)-[3]", p1.z(), dy0);
  str += SE(5)+SE(8);
  str += "+[4]*[2]*TMath::C()/1e12*(0";
  for (Int_t i = 0; i < 7; i++) str += SE(i*3+ip);
  str += ")";

  static TF1 *func = 0;
  if (!func) func = new TF1("fpr", str);
  func->SetParameter(0, pnt.y());
  func->SetParameter(1, dir.y()/dir.z());
  func->SetParameter(2, 1/rgt);
  func->SetParameter(3, 0);
  func->FixParameter(4, TMath::Sqrt(1.+(dir[0]*dir[0]
				       +dir[1]*dir[1])/dir[2]/dir[2])*
		                    (1.+dir[1]*dir[1] /dir[2]/dir[2]));

  func->SetParameter(5,   0); func->SetParameter( 8,   0);
  func->FixParameter(6,  65); func->FixParameter( 9, -65);
  func->FixParameter(7, 0.1); func->FixParameter(10, 0.1);

  for (Int_t i = 0; i < 21; i++) func->FixParameter(i+ip, GetPar(is1, is9, i));

  func->FixParameter(3, func->Eval(pnt.z())-p1.y());

  return func;
}
示例#9
0
文件: trcls.C 项目: krafczyk/AMS
void trcls(const char *fname, const char *oname, const char *tkdbc)
{
  AMSChain ch;
  TString sfn = fname;
  if (!sfn.Contains(".root")) sfn += "*.root";
  if (ch.Add(sfn) <= 0) return;

  Int_t ntr  = ch.GetNtrees();
  Int_t nent = ch.GetEntries();
  if (ntr <= 0 || nent <= 0) return;

  cout << "Ntr,Nent= " << ntr << " " << nent << endl;

  for (Int_t i = 0; i < ntr; i++)
    cout << ch.GetListOfFiles()->At(i)->GetTitle() << endl;

  Int_t   idata[13];
  Float_t fdata[28];

  TFile of(oname, "recreate");
  TTree *tree = new TTree("tree", "trcls");
  tree->Branch("idata", idata, "run/I:event/I:ient/I:time/I:tkml[9]/I");
  tree->Branch("fdata", fdata, "engc/F:enge/F:rgt/F:chrg/F:"
	                       "p0x/F:p0y/F:dzx/F:dzy/F:csqx/F:csqy/F:"
	                       "xcog[9]/F:ycog[9]/F");

  if (tkdbc && tkdbc[0] && tkdbc[0] != '0') {
    ch.GetEvent(0);
    TkDBc::Head->init(3, tkdbc);
  }
  TrExtAlignDB::OverLoadFlag = 0;

  Int_t malg = 2; // kAlcaraz | kMultScat
  Int_t pat0 = 3; // Inner only

  Int_t nevt = 0;
  Int_t nrsl = 0;
  Int_t npsl = 0;
  Int_t nfil = 0;
  Int_t intv = 10000;

  signal(SIGTERM, handler);
  signal(SIGINT,  handler);

  TStopwatch timer;
  timer.Start();

  for (Int_t ient = 0; ient < nent && !SigTERM; ient++) {
    AMSEventR *evt = ch.GetEvent(ient);
    nevt++;

    if (nevt%intv == 0 || nevt == nent) {
      Double_t tm = timer.RealTime();
      timer.Continue();
      cout << Form("%6d %6d %6d %7d (%5.1f%%) %4.0f sec (%4.1f kHz)",
		   nrsl, npsl, nfil, nevt,
		   100.*nevt/nent, tm, nevt/tm*1e-3)
	   << endl;
    }
    if (evt->nTrRecHit() >= 1600) continue;
    if (evt->nTrTrack () !=    1) continue;

    TrTrackR *trk = evt->pTrTrack(0);
    if (!trk) continue;

    Double_t chgp = TrCharge::GetQ(trk, 1);
    Double_t chgn = TrCharge::GetQ(trk, 0);
    if (chgp <= 0 || chgn <= 0) continue;

    Int_t mfp = trk->iTrTrackPar(malg, pat0, 0);
    if (mfp < 0) continue;

    Double_t rgtp = trk->GetRigidity(mfp);
    if (TMath::Abs(rgtp) < 5) continue;


    //////////////////// Recalc and refit ////////////////////
    trk->RecalcHitCoordinates();

    Int_t mf0 = trk->iTrTrackPar(malg, pat0, 2);
    if (mf0 < 0) continue;

    Double_t rgt0 = trk->GetRigidity(mf0);
    if (TMath::Abs(rgt0) < 10) continue;
    nrsl++;


    //////////////////// Pre-selection ////////////////////
    Bool_t psel = kTRUE;
    Int_t  span = (TrTrackSelection::GetSpanFlags(trk) & 0xff);
    if (!(span & TrTrackSelection::kMaxInt) ||
	!(span & TrTrackSelection::kAllPlane)) psel = kFALSE;

    if   (!(span & TrTrackSelection::kHalfL1N)) {
      if (!(span & TrTrackSelection::kHalfL9)) psel = kFALSE;

      AMSPoint pnt = trk->InterpolateLayerJ(9);
      if (TMath::Abs(pnt.x()) > 33) psel = kFALSE;
    }
    if (psel) npsl++;

    TrTrackR::AdvancedFitBits = 0x0f;

    TrRecon trec;
    Int_t nadd = trec.MergeExtHits(trk, mf0);
    if (!psel && nadd <= 0) continue;

    //////////////////// Remerge ////////////////////
    if (nadd > 0) {
      psel = kTRUE;
      span = (TrTrackSelection::GetSpanFlags(trk) & 0xff);
      if (!(span & TrTrackSelection::kMaxInt) ||
	  !(span & TrTrackSelection::kAllPlane)) psel = kFALSE;

      if   (!(span & TrTrackSelection::kHalfL1N)) {
	if (!(span & TrTrackSelection::kHalfL9)) psel = kFALSE;

	AMSPoint pnt = trk->InterpolateLayerJ(9);
	if (TMath::Abs(pnt.x()) > 33) psel = kFALSE;
      }
    }
    if (!psel) continue;

    idata[0] = evt->Run();
    idata[1] = evt->Event();
    idata[2] = ient;
    idata[3] = evt->fHeader.Time[0];

    EcalShowerR *ecal = evt->pEcalShower(0);
    fdata[0] = (ecal) ? ecal->EnergyC : 0;
    fdata[1] = (ecal) ? ecal->EnergyE : 0;
    fdata[2] = rgt0;
    fdata[3] = (chgp+chgn)/2;
    fdata[4] = trk->GetP0x(mf0);
    fdata[5] = trk->GetP0y(mf0);
    fdata[6] = trk->GetThetaXZ(mf0);
    fdata[7] = trk->GetThetaYZ(mf0);
    fdata[8] = trk->GetNormChisqX(mf0);
    fdata[9] = trk->GetNormChisqY(mf0);

    if (evt->nMCEventg() > 0) {
      MCEventgR *mcg = evt->pMCEventg(0);
      if (mcg) fdata[0] = mcg->Momentum;
    }

    Int_t   *tkml = &idata[ 4];
    Float_t *xcog = &fdata[10];
    Float_t *ycog = &fdata[19];
    for (Int_t i = 0; i < 9; i++) { tkml[i] = 0; xcog[i] = ycog[i] = 0; }

    for (Int_t i = 0; i < trk->GetNhits(); i++) {
      TrRecHitR *hit = trk->GetHit(i);
      if (!hit) continue;

      Int_t layer = hit->GetLayer();
      //if (layer != 8 && layer != 9) continue;

      Int_t il   = layer-1;//layer-8;
      Int_t tkid = hit->GetTkId();
      Int_t imlt = hit->GetResolvedMultiplicity();

      TrClusterR *clx = hit->GetXCluster();
      TrClusterR *cly = hit->GetYCluster();
      tkml[il] = TMath::Sign(imlt*1000+TMath::Abs(tkid), tkid);
      xcog[il] = (!clx) ? -(hit->GetDummyX()+640)
	       : clx->GetCofG()+clx->GetSeedAddress();
      ycog[il] = cly->GetCofG()+cly->GetSeedAddress();
    }

    tree->Fill();
    nfil++;
  }

  of.cd();
  tree->Write();
}
示例#10
0
文件: TkSens.C 项目: krafczyk/AMS
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;
}
示例#11
0
文件: TkSens.C 项目: krafczyk/AMS
//--------------------------------------------------
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;
}
示例#12
0
文件: swtrack.cpp 项目: krafczyk/AMS
void SWTrack::drawHits(QPainter *pnt)
{
  int *zly = (TkDBc::Head->GetSetup() == 3) ? &zLayer2[NLAY*lyrConf] : zLayer1;

  int zl1 = -200, zl2 = 200;
  for (int i = 0; i < NLAY; i++) {
    if (zly[i] > zl1) zl1 = zly[i];
    if (zly[i] < zl2) zl2 = zly[i];
  }

  int zl  = zl1-zl2;
  int px  = (wWid-zl)/2+LYR_PX+zl1;
  int py  = (wHei-tHei-LYR_H)/2+tHei+LYR_PY;
  int py1 = py+RES_H+LYR_D;
  int py2 = py-RES_H-LYR_D+LYR_H;
  int px1 = px-zl1-20;
  int px2 = px-zl2+20;

  int ifc = focusStatus/FOCUS_DOBJ/2-1;
  if (!(focusStatus & FOCUS_DOBJ)) ifc = -1;

  for (int i = 0; i < NLAY; i++) {
    if (zly[i] == 0) continue;
    pnt->setPen(QColor(100, 255, 200));
    pnt->drawLine(px-zly[i], py, px-zly[i], py+LYR_H);
    pnt->setPen((ifc == i) ? Qt::white : Qt::green);
    pnt->drawLine(px-zly[i]+1, py, px-zly[i]+1, py+LYR_H);
    pnt->setPen((ifc == i) ? Qt::gray : Qt::darkGreen);
    pnt->drawLine(px-zly[i]+2, py, px-zly[i]+2, py+LYR_H);

    pnt->setPen(Qt::green);
    drawText(pnt, px-zly[i]-3, py-17, Form("%d", i+1));
  }

  TrTrackR *trk = rEvent->pTrTrack(tID);
  if (!trk) return;

  int mfit = (0 <= fID && fID < NPAR) ? fitPar[fID] : 0;
  if (mfit <= 0) return;

  double rscx = 0.001, rscy = 0.001;

  int nhit = trk->GetNhits();

  for (int i = 0; i < nhit; i++) {
    TrRecHitR *hit = trk->GetHit(i);
    if (!hit) continue;

    int ily = hit->GetLayer()-1;
    if (zly[ily] == 0) continue;

    AMSPoint res = trk->GetResidualO(hit->GetLayer(), mfit);
    if (!hit->OnlyY() && abs(res.x()) > rscx) rscx = abs(res.x());
    if (!hit->OnlyX() && abs(res.y()) > rscy) rscy = abs(res.y());
  }

  rscx = (rscx < 0.005) ? (int)(rscx*2000)*0.0005 
       : (rscx < 1.000) ? (int)(rscx*200) *0.005
                        : (int)(rscx*20)  *0.05;
  rscy = (rscy < 0.005) ? (int)(rscy*2000)*0.0005 
       : (rscy < 1.000) ? (int)(rscy*200) *0.005
                        : (int)(rscy*20)  *0.05;

  int bx1, bx2, by1, by2;
  int n1 = 0, n2 = 0;

  int    idx[NLAY];
  double zht[NLAY];
  for (int i = 0; i < nhit; i++)
    zht[i] = trk->GetHit(i)->GetCoord().z();

  TMath::Sort(nhit, zht, idx);

  for (int i = 0; i < nhit; i++) {
    TrRecHitR *hit = trk->GetHit(idx[i]);
    int lay = hit->GetLayer();
    int ily = lay-1;
    if (zly[ily] == 0) continue;

    int x  = px-zly[ily];
    int y1 = py1-RES_H*trk->GetResidualO(lay, mfit).x()/rscx;
    int y2 = py2-RES_H*trk->GetResidualO(lay, mfit).y()/rscy;

    if (lyrSta[ily] == LSTA_HITT) {
      pnt->setPen(Qt::white);
      pnt->drawRect(x-3, y1-3, 6, 6);
      pnt->setPen((ifc == ily) ? Qt::darkGray : Qt::darkRed);
      pnt->drawRect(x-2, y1-2, 6, 6);
      pnt->fillRect(x-2, y1-2, 6, 6, 
		    (ifc == ily) ? QColor(Qt::gray) : QColor(Qt::red));

      if (n1++ > 0) {
	pnt->setPen(Qt::red);
	pnt->drawLine(bx1, by1, x, y1);
	pnt->setPen(Qt::darkRed);
	if (abs(x-bx1) > abs(y1-by1))
	  pnt->drawLine(bx1, by1+1, x, y1+1);
	else
	  pnt->drawLine(bx1+1, by1, x+1, y1);
      }
      bx1 = x;
      by1 = y1;
    }

    pnt->setPen(Qt::white);
    pnt->drawRect(x-3, y2-3, 6, 6);
    pnt->setPen((ifc == ily) ? Qt::darkGray : Qt::darkRed);
    pnt->drawRect(x-2, y2-2, 6, 6);
    pnt->fillRect(x-2, y2-2, 6, 6, 
		  (ifc == ily) ? QColor(Qt::gray) : QColor(Qt::red));

    if (n2++ > 0) {
      pnt->setPen(Qt::red);
      pnt->drawLine(bx2, by2, x, y2);
      pnt->setPen(Qt::darkRed);
      if (abs(x-bx2) > abs(y2-by2))
	pnt->drawLine(bx2, by2+1, x, y2+1);
      else
	pnt->drawLine(bx2+1, by2, x+1, y2);
    }
    bx2 = x;
    by2 = y2;
  }

  pnt->save();
  pnt->rotate(-90);
  pnt->setPen(QColor(255, 50, 50));
  drawText(pnt, -py1-14, px1-47, "ResX");
  drawText(pnt, -py2-14, px1-47, "ResY");
  drawText(pnt, -py1-20, px1-30, (rscx < 0.005) ? Form("%.0fum", rscx*2e4)
	                       : (rscx < 1.000) ? Form("%.1fmm", rscx*2e1)
	                                        : Form("%.1fcm", rscx*2));
  drawText(pnt, -py2-20, px1-30, (rscy < 0.005) ? Form("%.0fum", rscy*2e4)
	                       : (rscy < 1.000) ? Form("%.1fmm", rscy*2e1)
	                                        : Form("%.1fcm", rscy*2));
  pnt->restore();

  pnt->setPen(QColor(255, 30, 30));
  pnt->drawLine(px1, py1, px2, py1);
  pnt->drawLine(px1, py2, px2, py2);

  pnt->drawLine(px1-7, py1-RES_H, px1-7, py1+RES_H);
  pnt->drawLine(px1-9, py1-RES_H, px1-5, py1-RES_H);
  pnt->drawLine(px1-9, py1+RES_H, px1-5, py1+RES_H);

  pnt->drawLine(px1-7, py2-RES_H, px1-7, py2+RES_H);
  pnt->drawLine(px1-9, py2-RES_H, px1-5, py2-RES_H);
  pnt->drawLine(px1-9, py2+RES_H, px1-5, py2+RES_H);
}
示例#13
0
文件: swladder.cpp 项目: krafczyk/AMS
void SWLadder::drawInfobar(QPainter *pnt)
{
  pnt->fillRect(0, 0, wWid-2, tHei, QColor(0, 0, 0, 200));
  drawClose(pnt);
  drawMore (pnt);

  pnt->setPen(Qt::white);
  drawText(pnt,  28, 10, "Ladder");
  drawText(pnt,  80, 10, Form(" TkID: %d", tkID));
  drawText(pnt, 170, 10, Form("nClsX: %d", nClsX));
  drawText(pnt, 240, 10, Form("nClsY: %d", nClsY));
  drawText(pnt,  78, 30, Form(" nSen: %d", nSen ));
  drawText(pnt, 175, 30, Form(" nHit: %d", nHit ));
  drawText(pnt, 241, 30, Form("nHitT: %d", nHitT));
  drawText(pnt, 310, 30, Form("nHitG: %d", nHitG));

  if (focusStatus & FOCUS_DOBJ) {
    DrawObj dobj = drawObj.at(focusStatus/FOCUS_DOBJ/2-1);
    if ((dobj.atrb & ATR_CLSX) || (dobj.atrb & ATR_CLSY)) {
      TrClusterR *cls = rEvent->pTrCluster(dobj.idx);
      double sig = cls->GetTotSignal(TrClusterR::kAsym);
      drawText(pnt,  27, 50, Form("Cluster    Side: %d", cls->GetSide()));
      drawText(pnt, 140, 50, Form("Seed: %d", cls->GetAddress()
				             +cls->GetSeedIndex()));
      drawText(pnt, 220, 50, Form("Len: %d",  cls->GetLength()));
      drawText(pnt, 270, 50, Form("Signal: %.0f", sig));
      if (dobj.atrb & ATR_CLSX)
	drawText(pnt, 350, 50, Form("Mult: %d", dobj.mult));
    }
    else if (dobj.atrb & ATR_HIT) {
      TrRecHitR *hit = rEvent->pTrRecHit(dobj.idx);
      char cf1 = (hit->OnlyY()) ? 'G' : '_';
      char cf2 = (hit->checkstatus(AMSDBc::USED)) ? 'T' : '_';
      AMSPoint coo = hit->GetCoord(dobj.mult);
      drawText(pnt,  48, 50, Form("Hit     Flag: %c%c", cf1, cf2));
      drawText(pnt, 150, 50, Form("Coo: (%.2f, %.2f, %.2f)",
				  coo.x(), coo.y(), coo.z()));
      drawText(pnt, 350, 50, Form("Mult: %d",   dobj.mult));
    }
    else if (dobj.atrb & ATR_TRK) {
      TrTrackR *trk = rEvent->pTrTrack(dobj.idx);
      int fpat[8];
      for (int i = 0; i < 8; i++) fpat[i] = 0;

      TString hpat;
      for (int i = 0; i < trk->GetNhits(); i++) {
	TrRecHitR *hit = trk->GetHit(i);
	int ily = hit->GetLayer()-1;
	fpat[ily] = (hit->OnlyY()) ? 1 : 2;
      }
      for (int i = 0; i < 8; i++) {
	if      (fpat[i] == 1) hpat += "Y";
	else if (fpat[i] == 2) hpat += "O";
	else                   hpat += "_";
      }

      drawText(pnt,  48, 50, "Track");
      drawText(pnt, 100, 50, Form("nHit: %d",   trk->GetNhits()));
      drawText(pnt, 170, 50, Form("nHitXY: %d", trk->GetNhitsXY()));
      drawText(pnt, 270, 50, Form("fPat: %s",   hpat.Data()));
    }
  }
}
示例#14
0
////////////////// New version for ISS //////////////////
double TrTasClusterR::Fit(TH1 *hist, int ibeam, int mode, double *par,
			                                  double *per)
{
  if (!par) return -1;

  if (!TkDBc::Head) TkDBc::GetFromTDV(1325000000, 5);
  if (!TrTasDB::Filled()) {
    TString sdb = getenv("AMSDataDir");
    sdb += "/v5.01/tasdb";

    if (getenv("TasDB")) sdb = getenv("TasDB");
    TrTasDB::Load(sdb);
  }

  for (int i = 0;        i < 5; i++) par[i] = 0;
  for (int i = 0; per && i < 5; i++) per[i] = 0;

  TString stt = hist->GetTitle();
  if (stt == "Type: 00CC TkID:  310") hist->SetBinContent(133, 0);
  if (stt == "Type: 30CC TkID: -606") hist->SetBinContent(102, 0);
  if (stt == "Type: 31CC TkID: -609") hist->SetBinContent(129, 0);
  if (stt == "Type: 31CC TkID: -609") hist->SetBinContent(131, 0);
  if (stt == "Type: 40CC TkID: -609") hist->SetBinContent( 79, 0);

  int id = TrTasDB::Find(hist->GetTitle(), ibeam);
  if (id < 0) return -1;

  static TF1 *func = 0;
  if (!func) func = new TF1("func", TrTasClusterR::SGaus, 0, 1, 5);

  double csq = -1;
  double mn = TrTasDB::Mean(id);
  int    tf = TrTasDB::Tfit(id);
  int  tkid = TrTasDB::TkID(id);

  if (mn > 0) {
    hist->GetXaxis()->SetRangeUser(mn-15, mn+15);

    Int_t    rng = tf%10;
    Int_t    ib1 = hist->FindBin(mn-rng);
    Int_t    ib2 = hist->FindBin(mn+rng);
    Double_t sum = hist->Integral(ib1, ib2);
    if (sum < 100) return -1;

    if (mode > 100) {
      Int_t nb1 = (mode/10)%10;
      Int_t nb2 =  mode    %10;
      Int_t ib  = hist->FindBin(mn);
      Double_t sx = 0;
      Double_t sw = 0;

      for (Int_t i = 0; i <= nb1; i++) {
	if (hist->GetBinContent(ib-i) > 0) {
	  sx += hist->GetBinContent(ib-i)*hist->GetBinCenter(ib-i);
	  sw += hist->GetBinContent(ib-i);
	}
      }
      for (Int_t i = 1; i <= nb2; i++) {
	if (hist->GetBinContent(ib+i) > 0) {
	  sx += hist->GetBinContent(ib+i)*hist->GetBinCenter(ib+i);
	  sw += hist->GetBinContent(ib+i);
	}
      }
      if (sw != 0) sx /= sw;
      par[0] = hist->GetBinContent(hist->FindBin(sx));
      par[1] = sx;
      par[2] = sw;
      csq = 1;
    }
    else if (mode == 2 || (mode == 0 && tf > 10)) {
      double hmax = hist->GetMaximum();
      func->SetParameters(hmax*1.5, mn, 3, hmax, 500);
      func->FixParameter(4, 25);
      func->ReleaseParameter(3);

      hist->Fit(func, "q0", "", mn-rng, mn+rng);
      for (int i = 0;        i < 4; i++) par[i] = func->GetParameter(i);
      for (int i = 0; per && i < 4; i++) per[i] = func->GetParError (i);

      if (func->GetNDF() > 0) csq = func->GetChisquare()/func->GetNDF();
    }
    else {
      hist->Fit("gaus", "q0", "", mn-rng, mn+rng);

      TF1 *fg = hist->GetFunction("gaus");
      for (int i = 0; fg &&        i < 3; i++) par[i] = fg->GetParameter(i);
      for (int i = 0; fg && per && i < 3; i++) per[i] = fg->GetParError (i);

      if (fg && fg->GetNDF() > 0) csq = fg->GetChisquare()/fg->GetNDF();
    }
    if (par[2] < 0) par[2] = TMath::Abs(par[2]);

    float    xch = 830;
    float    ych = par[1];
    int       ml = TkCoo::GetMaxMult (tkid, xch);
    float     lx = TkCoo::GetLocalCoo(tkid, xch, ml-1);
    float     ly = TkCoo::GetLocalCoo(tkid, ych, ml-1);
    AMSPoint coo = TkCoo::GetGlobalA (tkid, lx, ly);
    par[4] = coo.y();
    if (per) per[4] = per[1]*TkDBc::Head->_PitchS;
  }

  return csq;
}
示例#15
0
文件: tkgeom.C 项目: krafczyk/AMS
void BuildSupport(AMSgvolume *mvol, int tkid)
{
// Build ladder support geometry

  TkLadder *lad = TkDBc::Head->FindTkId(tkid);

  if (!lad) return;


  int layer = std::abs(tkid)/100;
  
  char name[5];
  std::ostrstream ost(name,sizeof(name));
  ost << "FOA" << layer << std::ends;
  

  geant par[3];
  par[0] = TkCoo::GetLadderLength(tkid)/2;
  par[1] = TkDBc::Head->_ssize_inactive[1]/2;
  par[2] = sup_foam_w/2;    
  

  double hlen = TkCoo::GetLadderLength(tkid)/2
    -(TkDBc::Head->_ssize_inactive[0]-TkDBc::Head->_ssize_active[0])/2;
  double hwid = TkDBc::Head->_ssize_active[1]/2;
  
  AMSRotMat rot0 = lad->GetRotMatT();
  AMSRotMat rot = rot0*lad->GetRotMat();

  AMSPoint  pos = lad->GetPos()+lad->GetPosT();
  AMSPoint  loc(hlen, hwid, 0);
  AMSPoint  oo = rot*loc+pos;

// Get coordinate w.r.t. the mother layer
  geant coo[3];
  coo[0] = oo.x();
  coo[1] = oo.y();
  coo[2] = (std::abs(oo.z())/oo.z())*(std::abs(oo.z())-TkDBc::Head->_silicon_z/2-par[2]-sup_foam_tol);
  if(layer==1) coo[2] -= TkDBc::Head->_dz[0];
  if(layer==8) coo[2] -= TkDBc::Head->_dz[4];
  if(layer==9) coo[2] -= TkDBc::Head->_dz[5];

	     
	     
  number nrm[3][3];
  VZERO(nrm,9*sizeof(nrm[0][0])/4);
  nrm[0][0] = nrm[1][1] = nrm[2][2] = 1;

  int gid = tkid+1000;
  mvol->add(new AMSgvolume("Tr_Foam", _nrot++, name, "BOX",
			   par, 3, coo, nrm, "ONLY", 1, gid, 1));
  
  if(TRMCFFKEY.ActivateShielding){

    //shielding

    par[0] = TkCoo::GetLadderLength(tkid)/2;
    par[1] = TkDBc::Head->_ssize_inactive[1]/2;
    par[2] = 0.01/2.;  // 100 um

    coo[0] = oo.x();
    coo[1] = oo.y();
    coo[2] = (std::abs(oo.z())/oo.z())*(std::abs(oo.z())+TkDBc::Head->_silicon_z/2+par[2]+0.1);
    if(layer==1) coo[2] -= TkDBc::Head->_dz[0];
    if(layer==8) coo[2] -= TkDBc::Head->_dz[4];
    if(layer==9) coo[2] -= TkDBc::Head->_dz[5];

    VZERO(nrm,9*sizeof(nrm[0][0])/4);
    nrm[0][0] = nrm[1][1] = nrm[2][2] = 1;
    char name2[5];
    std::ostrstream ost2(name2,sizeof(name2));
    ost2 << "SHD" << layer << std::ends;
    gid = tkid+1000;
    mvol->add(new AMSgvolume("TrShield-M", _nrot++, name2, "BOX",
	  par, 3, coo, nrm, "ONLY", 1, gid, 1));
  }
}
示例#16
0
文件: tkgeom.C 项目: krafczyk/AMS
AMSgvolume *BuildLadder(AMSgvolume *mvol, int tkid)
{
// Build ladder geometry

    TkLadder *lad = TkDBc::Head->FindTkId(tkid);
  if (!lad) return 0;

  int layer = std::abs(tkid)/100;
  int islot = (tkid > 0) ? tkid%100 : -tkid%100+20;
  int iname = layer*100+islot;

  char name[5];
  std::ostrstream ost(name,sizeof(name));
  ost << "L" << iname << std::ends;

  geant par[3];
  par[0] = TkCoo::GetLadderLength(tkid)/2;
  par[1] = TkDBc::Head->_ssize_inactive[1]/2;
  par[2] = TkDBc::Head->_silicon_z/2;

  double hlen = TkCoo::GetLadderLength(tkid)/2
    -(TkDBc::Head->_ssize_inactive[0]-TkDBc::Head->_ssize_active[0])/2;
  double hwid = TkDBc::Head->_ssize_active[1]/2;

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

  AMSPoint  pos = lad->GetPos()+lad->GetPosT();
  AMSPoint  loc(hlen, hwid, 0);
  AMSPoint  oo = rot*loc+pos;

  // Get coordinate w.r.t. the mother layer
  geant coo[3];
  coo[0] = oo.x();
  coo[1] = oo.y();
  coo[2] = oo.z();
  if(layer==1) coo[2] -= TkDBc::Head->_dz[0];
  if(layer==8) coo[2] -= TkDBc::Head->_dz[4];
  if(layer==9) coo[2] -= TkDBc::Head->_dz[5];

  AMSRotMat lrm0 = lad->GetRotMatT();
  AMSRotMat lrm = lrm0*lad->GetRotMat();
  

  number nrm[3][3];
  for (int ii = 0; ii < 9; ii++) nrm[ii/3][ii%3] = lrm.GetEl(ii/3,ii%3);

  int gid =abs(tkid)/tkid* (abs(tkid)+1000);
  // printf("Sensor name %s  %+03d   %+9d %f %f %f\n",name,tkid,gid,coo[0],coo[1],coo[2]);
  AMSgvolume* ladd=(AMSgvolume*)mvol
    ->add(new AMSgvolume("NONACTIVE_SILICON", _nrot++, name, "BOX",
			 par, 3, coo, nrm, "ONLY", 1, gid, 1));

  //  printf("Ladder name %s\n",name);
  
  // Build sensors
  for (int sensor = 0; sensor < lad->GetNSensors(); sensor++){
    char nameS[5];
    std::ostrstream ost2(nameS,sizeof(nameS));
    ost2 << "S" << iname << std::ends;

    geant par[3];
    par[0] = TkDBc::Head->_ssize_active[0]/2;
    par[1] = TkDBc::Head->_ssize_active[1]/2;
    par[2] = TkDBc::Head->_silicon_z/2;
    
    // Get coordinate w.r.t. the mother ladder
    geant coo[3];
    coo[0] = -TkCoo::GetLadderLength(tkid)/2+ TkDBc::Head->_ssize_inactive[0]/2.+ sensor * TkDBc::Head->_SensorPitchK;
    coo[1] = coo[2] = 0;



    number nrm[3][3];
    VZERO(nrm, 9*sizeof(nrm[0][0])/4);
    nrm[0][0] = nrm[1][1] = nrm[2][2] = 1;
    int lside= (tkid>0)? 1:0;
    int gid = abs(tkid)+1000*(lside)+10000*(sensor+1); 
    //    printf("Sensor name %s  %+03d   %+9d %f %f %f\n",nameS,tkid,gid,coo[0],coo[1],coo[2]);
   ladd->add(new AMSgvolume("ACTIVE_SILICON", _nrot++, nameS, "BOX",
			     par, 3, coo, nrm, "ONLY", 1, gid, 1));
  }
  return ladd;
}