13#ifdef TRKRECO_DEBUG_DETAIL
22#include "GaudiKernel/Service.h"
23#include "GaudiKernel/ISvcLocator.h"
24#include "GaudiKernel/SvcFactory.h"
25#define HEP_SHORT_NAMES
29#include "CLHEP/Matrix/Vector.h"
30#include "CLHEP/Matrix/SymMatrix.h"
31#include "CLHEP/Matrix/Matrix.h"
36#include "GaudiKernel/StatusCode.h"
37#include "GaudiKernel/IInterface.h"
38#include "GaudiKernel/Kernel.h"
39#include "GaudiKernel/Service.h"
40#include "GaudiKernel/ISvcLocator.h"
41#include "GaudiKernel/SvcFactory.h"
42#include "GaudiKernel/IDataProviderSvc.h"
43#include "GaudiKernel/Bootstrap.h"
44#include "GaudiKernel/MsgStream.h"
45#include "GaudiKernel/SmartDataPtr.h"
46#include "GaudiKernel/IMessageSvc.h"
48#include "CLHEP/Matrix/Vector.h"
49#include "CLHEP/Matrix/SymMatrix.h"
50#include "CLHEP/Matrix/Matrix.h"
54#include "GaudiKernel/ISvcLocator.h"
57#include "GaudiKernel/Service.h"
58#include "GaudiKernel/ISvcLocator.h"
59#include "GaudiKernel/SvcFactory.h"
60#include "AIDA/IHistogram1D.h"
62#include "AIDA/IHistogram2D.h"
65#include "G4Material.hh"
70using CLHEP::HepVector;
71using CLHEP::HepMatrix;
72using CLHEP::HepSymMatrix;
94 StatusCode scmgn = Gaudi::svcLocator()->service(
"MagneticFieldSvc",m_pmgnIMF);
95 if(scmgn!=StatusCode::SUCCESS) {
96 std::cout<< __FILE__<<
" Unable to open Magnetic field service"<<std::endl;
100 bool m_sag,
int m_prop,
bool m_tof)
102 _sag(m_sag),_propagation(m_prop),_tof(
m_tof){
104 StatusCode scmgn = Gaudi::svcLocator()->service(
"MagneticFieldSvc",m_pmgnIMF);
105 if(scmgn!=StatusCode::SUCCESS) {
106 std::cout<<
"Unable to open Magnetic field service"<<std::endl;
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;
285 float tp[3] = {p.x(),p.y(),p.z()};
286 float x[3] = {onWire.x(), onWire.y(), onWire.z()};
287 double tprop = l_mdcCalFunSvc->
getTprop(layerId,onWire.z()*10.);
289 double T0 = l_mdcCalFunSvc->
getT0(layerId,wirelocal);
290 double drifttime = h.
reccdc()->
tdc -
tof - tprop - timeWalk -T0;
291 l->setDriftTime(drifttime);
294 int prop = _propagation;
295 const double x0 =
t.helix().pivot().x();
296 const double y0 =
t.helix().pivot().y();
297 Hep3Vector pivot_helix(x0,y0,0);
298 const double dr =
t.helix().a()[0];
299 const double phi0 =
t.helix().a()[1];
300 const double kappa =
t.helix().a()[2];
301 const double dz =
t.helix().a()[3];
302 const double tanl =
t.helix().a()[4];
305 const double alpha = 333.564095 / Bz;
307 const double cox = x0 + dr*
cos(phi0)-
alpha*
cos(phi0)/kappa;
308 const double coy = y0 + dr*
sin(phi0) -
alpha*
sin(phi0)/kappa;
309 HepPoint3D dir(onTrack.y()-coy,cox-onTrack.x(),0);
310 double pos_phi=onWire.phi();
311 double dir_phi=dir.phi();
312 while(pos_phi>
pi){pos_phi-=
pi;}
313 while(pos_phi<0){pos_phi+=
pi;}
314 while(dir_phi>
pi){dir_phi-=
pi;}
315 while(dir_phi<0){dir_phi+=
pi;}
316 double entrangle=dir_phi-pos_phi;
317 while(entrangle>
pi/2)entrangle-=
pi;
318 while(entrangle<(-1)*
pi/2)entrangle+=
pi;
319 dist = l_mdcCalFunSvc->
driftTimeToDist(drifttime,layerId, wirelocal, side, entrangle);
321 if(layer==-1||layerId!=layer){
322 edist = l_mdcCalFunSvc->
getSigma(layerId, side, dist, entrangle,tanl,onWire.z()*10,h.
reccdc()->
adc); }
323 else if(layerId==layer){edist=99999999;}
325 distance = (double) dist;
326 eDistance = (double) edist;
329 double eDistance2=eDistance*eDistance;
332 const double d0 = (onTrack-onWire).mag();
335 double dDistance = d0 - distance;
338 for(
int j=0;j<5;j++){
339 dDda[j]=(d[i-1][j]-d0)/ea[j];
344 dchi2da += (dDistance / eDistance2) * dDda;
345 d2chi2d2a += vT_times_v(dDda) / eDistance2;
346 double pChi2 = dDistance * dDistance / eDistance2;
355 l->update(onTrack, onWire, leftRight, pChi2);
356 l->drift(distance,0);
357 l->drift(distance,1);
358 l->dDrift(eDistance,0);
359 l->dDrift(eDistance,1);
362 else if(layerId==layer){
363 l->distance((onTrack-onWire).mag());
368 double change = chi2Old - chi2;
369 if (0 <= change && change < 0.01)
break;
378 }
else if(change > 0.){
389 std::cout<<
"TrkReco:TRF:: bad chi2 = "<<chi2<<std::endl;
395 for(
unsigned j=0;j<5;j++) alpha2[j][j]*=(1+factor);
397 da = solve(alpha2,beta);
411 ea[i]=0.0001*
abs(da[i]);
412 if(ea[i]>ea_init) ea[i]=ea_init;
413 if(ea[i]<1.0e-10) ea[i]=1.0e-10;
423 Ea = d2chi2d2a.inverse(err);
427 double y_[6]={0,0,0,0,0,0};
431 int nsign=a[2]/
abs(a[2]);
433 a[4]=y_[5]/sqrt(y_[4]*y_[4]+y_[3]*y_[3]);
434 a[2]=nsign*1/sqrt(y_[4]*y_[4]+y_[3]*y_[3]);
436 if(! err&&layer==-1){
440 }
else if(! err&&layer!=-1){
448 t._ndf = nCores - dim;
461 double Z(0.),A(0.),
Ionization(0.),Density(0.),Radlen(0.);
463 G4LogicalVolume *logicalMdc = 0;
468 G4Material* mdcMaterial = logicalMdc->GetMaterial();
470 for(i=0; i<mdcMaterial->GetElementVector()->size(); i++){
471 Z += (mdcMaterial->GetElement(i)->GetZ())*
472 (mdcMaterial->GetFractionVector()[i]);
473 A += (mdcMaterial->GetElement(i)->GetA())*
474 (mdcMaterial->GetFractionVector()[i]);
476 Ionization = mdcMaterial->GetIonisation()->GetMeanExcitationEnergy();
477 Density = mdcMaterial->GetDensity()/(g/cm3);
478 Radlen = mdcMaterial->GetRadlen();
480 cout<<
"mdcgas: Z: "<<Z<<
" A: "<<(A/(g/mole))<<
" Ionization: "<<(
Ionization/eV)<<
" Density: "<<Density<<
" Radlen: "<<Radlen<<endl;
485 G4LogicalVolume* innerwallVolume =
const_cast<G4LogicalVolume*
>(GDMLProcessor::GetInstance()->GetLogicalVolume(
"logicalMdcSegment2"));
486 G4Material* innerwallMaterial = innerwallVolume->GetMaterial();
487 G4Tubs* innerwallTub =
dynamic_cast<G4Tubs*
>(innerwallVolume->GetSolid());
491 for(i=0; i<innerwallMaterial->GetElementVector()->size(); i++){
492 Z += (innerwallMaterial->GetElement(i)->GetZ())*
493 (innerwallMaterial->GetFractionVector()[i]);
494 A += (innerwallMaterial->GetElement(i)->GetA())*
495 (innerwallMaterial->GetFractionVector()[i]);
498 Ionization = innerwallMaterial->GetIonisation()->GetMeanExcitationEnergy();
499 Density = innerwallMaterial->GetDensity()/(g/cm3);
500 Radlen = innerwallMaterial->GetRadlen();
501 cout<<
"Mdc innerwall, Al: Z: "<<Z<<
" A: "<<(A/(g/mole))<<
" Ionization: "<<(
Ionization/eV)<<
" Density: "<<Density<<
" Radlen: "<<Radlen<<endl;
506 G4LogicalVolume *logicalBes = 0;
511 G4LogicalVolume* logicalAirVolume =
const_cast<G4LogicalVolume*
>(GDMLProcessor::GetInstance()->GetLogicalVolume(
"logicalWorld"));
512 G4Material* airMaterial = logicalAirVolume->GetMaterial();
515 for(i=0; i<airMaterial->GetElementVector()->size(); i++){
516 Z += (airMaterial->GetElement(i)->GetZ())*
517 (airMaterial->GetFractionVector()[i]);
518 A += (airMaterial->GetElement(i)->GetA())*
519 (airMaterial->GetFractionVector()[i]);
521 Ionization = airMaterial->GetIonisation()->GetMeanExcitationEnergy();
522 Density = airMaterial->GetDensity()/(g/cm3);
523 Radlen = airMaterial->GetRadlen();
524 cout<<
"air: Z: "<<Z<<
" A: "<<(A/(g/mole))<<
" Ionization: "<<(
Ionization/eV)<<
" Density: "<<Density<<
" Radlen: "<<Radlen<<endl;
529 G4LogicalVolume* logicalOuterBeVolume =
const_cast<G4LogicalVolume*
>(GDMLProcessor::GetInstance()->GetLogicalVolume(
"logicalouterBe"));
530 G4Material* outerBeMaterial = logicalOuterBeVolume->GetMaterial();
532 G4Tubs* outerBeTub =
dynamic_cast<G4Tubs*
>(logicalOuterBeVolume->GetSolid());
535 for(i=0; i<outerBeMaterial->GetElementVector()->size(); i++){
536 Z += (outerBeMaterial->GetElement(i)->GetZ())*
537 (outerBeMaterial->GetFractionVector()[i]);
538 A += (outerBeMaterial->GetElement(i)->GetA())*
539 (outerBeMaterial->GetFractionVector()[i]);
541 Ionization = outerBeMaterial->GetIonisation()->GetMeanExcitationEnergy();
542 Density = outerBeMaterial->GetDensity()/(g/cm3);
543 Radlen = outerBeMaterial->GetRadlen();
544 cout<<
"outer beryllium: Z: "<<Z<<
" A: "<<(A/(g/mole))<<
" Ionization: "<<(
Ionization/eV)<<
" Density: "<<Density<<
" Radlen: "<<Radlen<<endl;
549 G4LogicalVolume* logicalOilLayerVolume =
const_cast<G4LogicalVolume*
>(GDMLProcessor::GetInstance()->GetLogicalVolume(
"logicaloilLayer"));
550 G4Material* oilLayerMaterial = logicalOilLayerVolume->GetMaterial();
551 G4Tubs* oilLayerTub =
dynamic_cast<G4Tubs*
>(logicalOilLayerVolume->GetSolid());
555 for(i=0; i<oilLayerMaterial->GetElementVector()->size(); i++){
556 Z += (oilLayerMaterial->GetElement(i)->GetZ())*
557 (oilLayerMaterial->GetFractionVector()[i]);
558 A += (oilLayerMaterial->GetElement(i)->GetA())*
559 (oilLayerMaterial->GetFractionVector()[i]);
561 Ionization = oilLayerMaterial->GetIonisation()->GetMeanExcitationEnergy();
562 Density = oilLayerMaterial->GetDensity()/(g/cm3);
563 Radlen = oilLayerMaterial->GetRadlen();
564 cout<<
"cooling oil: Z: "<<Z<<
" A: "<<(A/(g/mole))<<
" Ionization: "<<(
Ionization/eV)<<
" Density: "<<Density<<
" Radlen: "<<Radlen<<endl;
570 G4LogicalVolume* logicalInnerBeVolume =
const_cast<G4LogicalVolume*
>(GDMLProcessor::GetInstance()->GetLogicalVolume(
"logicalinnerBe"));
572 G4Material* innerBeMaterial = logicalInnerBeVolume->GetMaterial();
573 G4Tubs* innerBeTub =
dynamic_cast<G4Tubs*
>(logicalInnerBeVolume->GetSolid());
576 for(i=0; i<innerBeMaterial->GetElementVector()->size(); i++){
577 Z += (innerBeMaterial->GetElement(i)->GetZ())*
578 (innerBeMaterial->GetFractionVector()[i]);
579 A += (innerBeMaterial->GetElement(i)->GetA())*
580 (innerBeMaterial->GetFractionVector()[i]);
582 Ionization = innerBeMaterial->GetIonisation()->GetMeanExcitationEnergy();
583 Density = innerBeMaterial->GetDensity()/(g/cm3);
584 Radlen = innerBeMaterial->GetRadlen();
585 cout<<
"inner beryllium: Z: "<<Z<<
" A: "<<(A/(g/mole))<<
" Ionization: "<<(
Ionization/eV)<<
" Density: "<<Density<<
" Radlen: "<<Radlen<<endl;
591 G4LogicalVolume* logicalGoldLayerVolume =
const_cast<G4LogicalVolume*
>(GDMLProcessor::GetInstance()->GetLogicalVolume(
"logicalgoldLayer"));
592 G4Material* goldLayerMaterial = logicalGoldLayerVolume->GetMaterial();
593 G4Tubs* goldLayerTub =
dynamic_cast<G4Tubs*
>(logicalGoldLayerVolume->GetSolid());
597 for(i=0; i<goldLayerMaterial->GetElementVector()->size(); i++){
598 Z += (goldLayerMaterial->GetElement(i)->GetZ())*
599 (goldLayerMaterial->GetFractionVector()[i]);
600 A += (goldLayerMaterial->GetElement(i)->GetA())*
601 (goldLayerMaterial->GetFractionVector()[i]);
603 Ionization = goldLayerMaterial->GetIonisation()->GetMeanExcitationEnergy();
604 Density = goldLayerMaterial->GetDensity()/(g/cm3);
605 Radlen = goldLayerMaterial->GetRadlen();
606 cout<<
"gold layer: Z: "<<Z<<
" A: "<<(A/(g/mole))<<
" Ionization: "<<(
Ionization/eV)<<
" Density: "<<Density<<
" Radlen: "<<Radlen<<endl;
612 double radius, thick,
length , z0;
615 radius = innerwallTub->GetInnerRadius()/(cm);
616 thick = innerwallTub->GetOuterRadius()/(cm) - innerwallTub->GetInnerRadius()/(cm);
617 length = 2.0*innerwallTub->GetZHalfLength()/(cm);
619 cout<<
"innerwall: "<<
" radius: "<<radius<<
" thick:"<<thick<<
" length: "<<
length<<endl;
624 radius = outerBeTub->GetOuterRadius()/(cm);
625 thick = innerwallTub->GetInnerRadius()/(cm) - outerBeTub->GetOuterRadius()/(cm);
626 length = 2.0*innerwallTub->GetZHalfLength()/(cm);
628 cout<<
"outer air: "<<
" radius: "<<radius<<
" thick:"<<thick<<
" length: "<<
length<<endl;
633 radius = outerBeTub->GetInnerRadius()/(cm);
634 thick = outerBeTub->GetOuterRadius()/(cm) - outerBeTub->GetInnerRadius()/(cm);
635 length = 2.0*outerBeTub->GetZHalfLength()/(cm);
637 cout<<
"outer Be: "<<
" radius: "<<radius<<
" thick:"<<thick<<
" length: "<<
length<<endl;
642 radius = oilLayerTub->GetInnerRadius()/(cm);
643 thick = oilLayerTub->GetOuterRadius()/(cm) - oilLayerTub->GetInnerRadius()/(cm);
644 length = 2.0*oilLayerTub->GetZHalfLength()/(cm);
646 cout<<
"oil layer: "<<
" radius: "<<radius<<
" thick:"<<thick<<
" length: "<<
length<<endl;
651 radius = innerBeTub->GetInnerRadius()/(cm);
652 thick = innerBeTub->GetOuterRadius()/(cm) - innerBeTub->GetInnerRadius()/(cm);
653 length = 2.0*innerBeTub->GetZHalfLength()/(cm);
655 cout<<
"inner Be: "<<
" radius: "<<radius<<
" thick:"<<thick<<
" length: "<<
length<<endl;
660 radius = goldLayerTub->GetInnerRadius()/(cm);
661 thick = goldLayerTub->GetOuterRadius()/(cm) - goldLayerTub->GetInnerRadius()/(cm);
662 length = 2.0*goldLayerTub->GetZHalfLength()/(cm);
664 cout<<
"gold layer: "<<
" radius: "<<radius<<
" thick:"<<thick<<
" length: "<<
length<<endl;
double sin(const BesAngle a)
double cos(const BesAngle a)
double abs(const EvtComplex &c)
NTuple::Array< double > m_tof
CLHEP::HepSymMatrix SymMatrix
const HepPoint3D ORIGIN
Constants.
#define TFitAlreadyFitted
unsigned NStereoHits(const AList< TMLink > &links)
returns # of stereo hits.
virtual double getReferField()=0
virtual double driftTimeToDist(double drifttime, int layid, int cellid, int lr, double entrance=0.0) const =0
virtual double getSigma(int layid, int lr, double dist, double entrance=0.0, double tanlam=0.0, double z=0.0, double Q=1000.0) const =0
virtual double getTprop(int lay, double z) const =0
virtual double getT0(int layid, int cellid) const =0
virtual double getTimeWalk(int layid, double Q) const =0
Cylinder is an Element whose shape is a cylinder.
G4LogicalVolume * GetTopVolume()
Get the top(world) volume;.
struct MdcRec_wirhit * reccdc(void) const
returns a pointer to RECMDC_WIRHIT.
float dDrift(unsigned) const
returns drift distance error.
const TMDCWire *const wire(void) const
returns a pointer to a TMDCWire.
unsigned id(void) const
returns id.
unsigned localId(void) const
returns local id in a wire layer.
unsigned layerId(void) const
returns layer id.
A class to fit a TTrackBase object.
A class to relate TMDCWireHit and TTrack objects.
void setBesFromGdml(void)
TRungeFitter(const std::string &name)
Constructor.
void innerwall(TRunge &trk, int l_mass, double y[6]) const
std::vector< RkFitMaterial > _BesBeamPipeMaterials
virtual int fit(TTrackBase &) const
virtual ~TRungeFitter()
Destructor.
std::vector< RkFitCylinder > _BesBeamPipeWalls
A class to represent a track in tracking.
A virtual class for a track class in tracking.
virtual unsigned objectType(void) const
returns object type.