129 Gaudi::svcLocator() -> service(
"MdcCalibFunSvc", l_mdcCalFunSvc);
138 unsigned nCores = cores.length();
143 for(
int i=0;i<nCores;i++){
144 layerid=(*cores[i]->hit()).wire()->layerId();
169 for(
int i=0;i<
t.links().length();i++){
170 chi2Old=chi2Old+
t.links()[i]->pull();
180 double (*d)[5]=
new double[nCores][5];
192 const double ea_init=0.000001;
213 for (
unsigned j=0;j<5;j++) dchi2da[j]=0;
219 for(
unsigned j=0;j<5;j++){
226 while(
TMLink * l = cores[i++]){
229 const HepPoint3D& onTrack=l->positionOnTrack();
231 d[i-1][j]=(onTrack-onWire).mag();
261 while(
TMLink * l = cores[i++]){
265 std::cout<<
"TrkReco:TRF:: bad wire"<<std::endl;
269 const HepPoint3D& onTrack=l->positionOnTrack();
272 if (onWire.cross(onTrack).z() < 0.) leftRight =
WireHitLeft;
275 if ((t0Offset == 0.) && (_propagation==0) && (! _tof)) {
277 distance = l->drift(leftRight);
278 eDistance = h.
dDrift(leftRight);
281 int wire = h.
wire()->
id();
283 int side = leftRight;
284 if (side==0) side = 0;
286 double tp[3] = {p.x(),p.y(),p.z()};
288 double x[3] = {onWire.x(), onWire.y(), onWire.z()};
289 double tprop = l_mdcCalFunSvc->
getTprop(layerId,onWire.z()*10.);
291 double T0 = l_mdcCalFunSvc->
getT0(layerId,wirelocal);
292 double drifttime = h.
reccdc()->
tdc -
tof - tprop - timeWalk -T0;
293 l->setDriftTime(drifttime);
296 int prop = _propagation;
297 const double x0 =
t.helix().pivot().x();
298 const double y0 =
t.helix().pivot().y();
299 Hep3Vector pivot_helix(x0,y0,0);
300 const double dr =
t.helix().a()[0];
301 const double phi0 =
t.helix().a()[1];
302 const double kappa =
t.helix().a()[2];
303 const double dz =
t.helix().a()[3];
304 const double tanl =
t.helix().a()[4];
307 const double alpha = 333.564095 / Bz;
309 const double cox = x0 + dr*
cos(phi0)-
alpha*
cos(phi0)/kappa;
310 const double coy = y0 + dr*
sin(phi0) -
alpha*
sin(phi0)/kappa;
311 HepPoint3D dir(onTrack.y()-coy,cox-onTrack.x(),0);
312 double pos_phi=onWire.phi();
313 double dir_phi=dir.phi();
314 while(pos_phi>
pi){pos_phi-=
pi;}
315 while(pos_phi<0){pos_phi+=
pi;}
316 while(dir_phi>
pi){dir_phi-=
pi;}
317 while(dir_phi<0){dir_phi+=
pi;}
318 double entrangle=dir_phi-pos_phi;
319 while(entrangle>
pi/2)entrangle-=
pi;
320 while(entrangle<(-1)*
pi/2)entrangle+=
pi;
321 dist = l_mdcCalFunSvc->
driftTimeToDist(drifttime,layerId, wirelocal, side, entrangle);
323 if(layer==-1||layerId!=layer){
324 edist = l_mdcCalFunSvc->
getSigma(layerId, side, dist, entrangle,tanl,onWire.z()*10,h.
reccdc()->
adc); }
325 else if(layerId==layer){edist=99999999;}
327 distance = (double) dist;
328 eDistance = (double) edist;
331 double eDistance2=eDistance*eDistance;
334 const double d0 = (onTrack-onWire).mag();
337 double dDistance = d0 - distance;
340 for(
int j=0;j<5;j++){
341 dDda[j]=(d[i-1][j]-d0)/ea[j];
346 dchi2da += (dDistance / eDistance2) * dDda;
347 d2chi2d2a += vT_times_v(dDda) / eDistance2;
348 double pChi2 = dDistance * dDistance / eDistance2;
357 l->update(onTrack, onWire, leftRight, pChi2);
358 l->drift(distance,0);
359 l->drift(distance,1);
360 l->dDrift(eDistance,0);
361 l->dDrift(eDistance,1);
364 else if(layerId==layer){
365 l->distance((onTrack-onWire).mag());
370 double change = chi2Old - chi2;
371 if (0 <= change && change < 0.01)
break;
380 }
else if(change > 0.){
391 std::cout<<
"TrkReco:TRF:: bad chi2 = "<<chi2<<std::endl;
397 for(
unsigned j=0;j<5;j++) alpha2[j][j]*=(1+factor);
399 da = solve(alpha2,beta);
413 ea[i]=0.0001*
abs(da[i]);
414 if(ea[i]>ea_init) ea[i]=ea_init;
415 if(ea[i]<1.0e-10) ea[i]=1.0e-10;
425 Ea = d2chi2d2a.inverse(err);
429 double y_[6]={0,0,0,0,0,0};
433 int nsign=a[2]/
abs(a[2]);
435 a[4]=y_[5]/sqrt(y_[4]*y_[4]+y_[3]*y_[3]);
436 a[2]=nsign*1/sqrt(y_[4]*y_[4]+y_[3]*y_[3]);
438 if(! err&&layer==-1){
442 }
else if(! err&&layer!=-1){
450 t._ndf = nCores - dim;
463 double Z(0.),A(0.),Ionization(0.),Density(0.),Radlen(0.);
465 G4LogicalVolume *logicalMdc = 0;
470 G4Material* mdcMaterial = logicalMdc->GetMaterial();
472 for(i=0; i<mdcMaterial->GetElementVector()->size(); i++){
473 Z += (mdcMaterial->GetElement(i)->GetZ())*
474 (mdcMaterial->GetFractionVector()[i]);
475 A += (mdcMaterial->GetElement(i)->GetA())*
476 (mdcMaterial->GetFractionVector()[i]);
478 Ionization = mdcMaterial->GetIonisation()->GetMeanExcitationEnergy();
479 Density = mdcMaterial->GetDensity()/(g/cm3);
480 Radlen = mdcMaterial->GetRadlen();
481 RkFitMaterial FitMdcMaterial(Z,A/g/mole,Ionization/eV,Density,Radlen/10.);
482 cout<<
"mdcgas: Z: "<<Z<<
" A: "<<(A/(g/mole))<<
" Ionization: "<<(Ionization/eV)<<
" Density: "<<Density<<
" Radlen: "<<Radlen<<endl;
487 G4LogicalVolume* innerwallVolume =
const_cast<G4LogicalVolume*
>(GDMLProcessor::GetInstance()->GetLogicalVolume(
"logicalMdcSegment2"));
488 G4Material* innerwallMaterial = innerwallVolume->GetMaterial();
489 G4Tubs* innerwallTub =
dynamic_cast<G4Tubs*
>(innerwallVolume->GetSolid());
493 for(i=0; i<innerwallMaterial->GetElementVector()->size(); i++){
494 Z += (innerwallMaterial->GetElement(i)->GetZ())*
495 (innerwallMaterial->GetFractionVector()[i]);
496 A += (innerwallMaterial->GetElement(i)->GetA())*
497 (innerwallMaterial->GetFractionVector()[i]);
500 Ionization = innerwallMaterial->GetIonisation()->GetMeanExcitationEnergy();
501 Density = innerwallMaterial->GetDensity()/(g/cm3);
502 Radlen = innerwallMaterial->GetRadlen();
503 cout<<
"Mdc innerwall, Al: Z: "<<Z<<
" A: "<<(A/(g/mole))<<
" Ionization: "<<(Ionization/eV)<<
" Density: "<<Density<<
" Radlen: "<<Radlen<<endl;
504 RkFitMaterial FitInnerwallMaterial(Z,A/g/mole,Ionization/eV,Density,Radlen/10.);
508 G4LogicalVolume *logicalBes = 0;
513 G4LogicalVolume* logicalAirVolume =
const_cast<G4LogicalVolume*
>(GDMLProcessor::GetInstance()->GetLogicalVolume(
"logicalWorld"));
514 G4Material* airMaterial = logicalAirVolume->GetMaterial();
517 for(i=0; i<airMaterial->GetElementVector()->size(); i++){
518 Z += (airMaterial->GetElement(i)->GetZ())*
519 (airMaterial->GetFractionVector()[i]);
520 A += (airMaterial->GetElement(i)->GetA())*
521 (airMaterial->GetFractionVector()[i]);
523 Ionization = airMaterial->GetIonisation()->GetMeanExcitationEnergy();
524 Density = airMaterial->GetDensity()/(g/cm3);
525 Radlen = airMaterial->GetRadlen();
526 cout<<
"air: Z: "<<Z<<
" A: "<<(A/(g/mole))<<
" Ionization: "<<(Ionization/eV)<<
" Density: "<<Density<<
" Radlen: "<<Radlen<<endl;
527 RkFitMaterial FitAirMaterial(Z,A/g/mole,Ionization/eV,Density,Radlen/10.);
531 G4LogicalVolume* logicalOuterBeVolume =
const_cast<G4LogicalVolume*
>(GDMLProcessor::GetInstance()->GetLogicalVolume(
"logicalouterBe"));
532 G4Material* outerBeMaterial = logicalOuterBeVolume->GetMaterial();
534 G4Tubs* outerBeTub =
dynamic_cast<G4Tubs*
>(logicalOuterBeVolume->GetSolid());
537 for(i=0; i<outerBeMaterial->GetElementVector()->size(); i++){
538 Z += (outerBeMaterial->GetElement(i)->GetZ())*
539 (outerBeMaterial->GetFractionVector()[i]);
540 A += (outerBeMaterial->GetElement(i)->GetA())*
541 (outerBeMaterial->GetFractionVector()[i]);
543 Ionization = outerBeMaterial->GetIonisation()->GetMeanExcitationEnergy();
544 Density = outerBeMaterial->GetDensity()/(g/cm3);
545 Radlen = outerBeMaterial->GetRadlen();
546 cout<<
"outer beryllium: Z: "<<Z<<
" A: "<<(A/(g/mole))<<
" Ionization: "<<(Ionization/eV)<<
" Density: "<<Density<<
" Radlen: "<<Radlen<<endl;
547 RkFitMaterial FitOuterBeMaterial(Z,A/g/mole,Ionization/eV,Density,Radlen/10.);
551 G4LogicalVolume* logicalOilLayerVolume =
const_cast<G4LogicalVolume*
>(GDMLProcessor::GetInstance()->GetLogicalVolume(
"logicaloilLayer"));
552 G4Material* oilLayerMaterial = logicalOilLayerVolume->GetMaterial();
553 G4Tubs* oilLayerTub =
dynamic_cast<G4Tubs*
>(logicalOilLayerVolume->GetSolid());
557 for(i=0; i<oilLayerMaterial->GetElementVector()->size(); i++){
558 Z += (oilLayerMaterial->GetElement(i)->GetZ())*
559 (oilLayerMaterial->GetFractionVector()[i]);
560 A += (oilLayerMaterial->GetElement(i)->GetA())*
561 (oilLayerMaterial->GetFractionVector()[i]);
563 Ionization = oilLayerMaterial->GetIonisation()->GetMeanExcitationEnergy();
564 Density = oilLayerMaterial->GetDensity()/(g/cm3);
565 Radlen = oilLayerMaterial->GetRadlen();
566 cout<<
"cooling oil: Z: "<<Z<<
" A: "<<(A/(g/mole))<<
" Ionization: "<<(Ionization/eV)<<
" Density: "<<Density<<
" Radlen: "<<Radlen<<endl;
567 RkFitMaterial FitOilLayerMaterial(Z,A/g/mole,Ionization/eV,Density,Radlen/10.);
572 G4LogicalVolume* logicalInnerBeVolume =
const_cast<G4LogicalVolume*
>(GDMLProcessor::GetInstance()->GetLogicalVolume(
"logicalinnerBe"));
574 G4Material* innerBeMaterial = logicalInnerBeVolume->GetMaterial();
575 G4Tubs* innerBeTub =
dynamic_cast<G4Tubs*
>(logicalInnerBeVolume->GetSolid());
578 for(i=0; i<innerBeMaterial->GetElementVector()->size(); i++){
579 Z += (innerBeMaterial->GetElement(i)->GetZ())*
580 (innerBeMaterial->GetFractionVector()[i]);
581 A += (innerBeMaterial->GetElement(i)->GetA())*
582 (innerBeMaterial->GetFractionVector()[i]);
584 Ionization = innerBeMaterial->GetIonisation()->GetMeanExcitationEnergy();
585 Density = innerBeMaterial->GetDensity()/(g/cm3);
586 Radlen = innerBeMaterial->GetRadlen();
587 cout<<
"inner beryllium: Z: "<<Z<<
" A: "<<(A/(g/mole))<<
" Ionization: "<<(Ionization/eV)<<
" Density: "<<Density<<
" Radlen: "<<Radlen<<endl;
588 RkFitMaterial FitInnerBeMaterial(Z,A/g/mole,Ionization/eV,Density,Radlen/10.);
593 G4LogicalVolume* logicalGoldLayerVolume =
const_cast<G4LogicalVolume*
>(GDMLProcessor::GetInstance()->GetLogicalVolume(
"logicalgoldLayer"));
594 G4Material* goldLayerMaterial = logicalGoldLayerVolume->GetMaterial();
595 G4Tubs* goldLayerTub =
dynamic_cast<G4Tubs*
>(logicalGoldLayerVolume->GetSolid());
599 for(i=0; i<goldLayerMaterial->GetElementVector()->size(); i++){
600 Z += (goldLayerMaterial->GetElement(i)->GetZ())*
601 (goldLayerMaterial->GetFractionVector()[i]);
602 A += (goldLayerMaterial->GetElement(i)->GetA())*
603 (goldLayerMaterial->GetFractionVector()[i]);
605 Ionization = goldLayerMaterial->GetIonisation()->GetMeanExcitationEnergy();
606 Density = goldLayerMaterial->GetDensity()/(g/cm3);
607 Radlen = goldLayerMaterial->GetRadlen();
608 cout<<
"gold layer: Z: "<<Z<<
" A: "<<(A/(g/mole))<<
" Ionization: "<<(Ionization/eV)<<
" Density: "<<Density<<
" Radlen: "<<Radlen<<endl;
609 RkFitMaterial FitGoldLayerMaterial(Z,A/g/mole,Ionization/eV,Density,Radlen/10.);
614 double radius, thick, length , z0;
617 radius = innerwallTub->GetInnerRadius()/(cm);
618 thick = innerwallTub->GetOuterRadius()/(cm) - innerwallTub->GetInnerRadius()/(cm);
619 length = 2.0*innerwallTub->GetZHalfLength()/(cm);
621 cout<<
"innerwall: "<<
" radius: "<<radius<<
" thick:"<<thick<<
" length: "<<length<<endl;
626 radius = outerBeTub->GetOuterRadius()/(cm);
627 thick = innerwallTub->GetInnerRadius()/(cm) - outerBeTub->GetOuterRadius()/(cm);
628 length = 2.0*innerwallTub->GetZHalfLength()/(cm);
630 cout<<
"outer air: "<<
" radius: "<<radius<<
" thick:"<<thick<<
" length: "<<length<<endl;
635 radius = outerBeTub->GetInnerRadius()/(cm);
636 thick = outerBeTub->GetOuterRadius()/(cm) - outerBeTub->GetInnerRadius()/(cm);
637 length = 2.0*outerBeTub->GetZHalfLength()/(cm);
639 cout<<
"outer Be: "<<
" radius: "<<radius<<
" thick:"<<thick<<
" length: "<<length<<endl;
644 radius = oilLayerTub->GetInnerRadius()/(cm);
645 thick = oilLayerTub->GetOuterRadius()/(cm) - oilLayerTub->GetInnerRadius()/(cm);
646 length = 2.0*oilLayerTub->GetZHalfLength()/(cm);
648 cout<<
"oil layer: "<<
" radius: "<<radius<<
" thick:"<<thick<<
" length: "<<length<<endl;
653 radius = innerBeTub->GetInnerRadius()/(cm);
654 thick = innerBeTub->GetOuterRadius()/(cm) - innerBeTub->GetInnerRadius()/(cm);
655 length = 2.0*innerBeTub->GetZHalfLength()/(cm);
657 cout<<
"inner Be: "<<
" radius: "<<radius<<
" thick:"<<thick<<
" length: "<<length<<endl;
662 radius = goldLayerTub->GetInnerRadius()/(cm);
663 thick = goldLayerTub->GetOuterRadius()/(cm) - goldLayerTub->GetInnerRadius()/(cm);
664 length = 2.0*goldLayerTub->GetZHalfLength()/(cm);
666 cout<<
"gold layer: "<<
" radius: "<<radius<<
" thick:"<<thick<<
" length: "<<length<<endl;