#include <AlgFitTrackMS.h>
Inheritance diagram for AlgFitTrackMS:

Public Member Functions | |
| AlgFitTrackMS () | |
| virtual | ~AlgFitTrackMS () |
| virtual void | InitFitHandle (CandContext &cx) |
| virtual void | RunAlg (AlgConfig &ac, CandHandle &ch, CandContext &cx) |
| virtual void | Trace (const char *c) const |
Private Member Functions | |
| Double_t | ChiSquared (TMatrixD &ErrorMatrix) |
| void | DetermineQ () |
| Int_t | DoFitAlg (Double_t pInit, Double_t &pFit, Double_t &LFit) |
| void | FitTrack (Double_t p0, Double_t &LogCovMDeterminant, Double_t &chiSquared) |
| Double_t | GetSigmaMS (Double_t peloss) |
| void | InitArrays () |
| void | InvertCovMatrix (TMatrixD &CovMatrix, TMatrixD &ErrorMatrix, Double_t &LogDet) |
| void | MakeCovarianceMatrix (TMatrixD &CovMatrix, Double_t p0) |
| void | MakeStraightTrack () |
| void | MakePPlanes (Double_t p0) |
| void | MakeSolnMatrices (TMatrixD &VariableCoefMatrix, TMatrixD &ConstantCoefMatrix, TMatrixD &ErrorMatrix) |
| void | SetupAlg (AlgConfig &ac) |
| void | WriteFit (Double_t ChiSquared, Double_t p0) |
Private Attributes | |
| CandFitTrackMSHandle * | fCfh |
| Detector::Detector_t | fDetector |
| Double_t | fQ |
| Double_t | fFlag |
| Double_t | fLTolerance |
| Double_t | fPTolerance |
| Double_t | fPosErr |
| Double_t | fXZero |
| Double_t | fDedx |
| Double_t | fSuperModGapSize |
| Double_t | fSteelPlnWidth |
| Double_t | fScintPlnWidth |
| Double_t | fTotalPlnWidth |
| Int_t | fNofit |
| Int_t | fNoBField |
| Int_t | fNoMS |
| Int_t | fBothFit |
| Int_t | fFullAna |
| Int_t | fMaxHits |
| Int_t | fMinHits |
| Double_t | fMaxP |
| Double_t | fMinP |
| Int_t | fMaxIter |
| Int_t | fInShower |
| Int_t | fBFisFlipped |
| Int_t | fSuperModSkippedPlane |
| Int_t | fNHits |
| Int_t | fNPlanes |
| TMatrixD | fSolnMatrix |
| TVectorD | fXHits |
| TVectorD | fYHits |
| TVectorD | fStraightXHits |
| TVectorD | fStraightYHits |
| TVectorD | fZHits |
| TVectorD | fZPlanes |
| TVectorD | fPPlanes |
|
|
Definition at line 56 of file AlgFitTrackMS.cxx. 00057 {
00058 }
|
|
|
Definition at line 60 of file AlgFitTrackMS.cxx. 00061 {
00062 }
|
|
|
Definition at line 409 of file AlgFitTrackMS.cxx. References fSolnMatrix, fStraightXHits, fStraightYHits, and fZHits. Referenced by FitTrack(). 00410 {
00411 // calculate the Chi Squared. Add the contribution from the x
00412 // points and the y points.
00413 Double_t chiSquared=0;
00414 Int_t mfactor;
00415
00416 Double_t x0 = fSolnMatrix(0,0);
00417 Double_t xSlope = fSolnMatrix(1,0);
00418 Double_t y0 = fSolnMatrix(0,1);
00419 Double_t ySlope = fSolnMatrix(1,1);
00420
00421
00422 for(Int_t i=0; i<fNHits; i++){
00423 for(Int_t j=0; j<=i; j++){
00424
00425 // since the error matrix is symmetric, we can get away with
00426 // looping only over half of it plus the diagonal. we need to
00427 // account for, though, that each diagonal element should be
00428 // counted only once while all others should be counted twice to
00429 // make up for the half of the matrix that is skipped. hence,
00430 // this mfactor kludge.
00431 if(i!=j) mfactor=2;
00432 else mfactor=1;
00433
00434 chiSquared +=
00435 mfactor*(fStraightXHits(i)-x0-xSlope*(fZHits(i)-fZHits(0)))*
00436 (fStraightXHits(j)-x0-xSlope*(fZHits(j)-fZHits(0)))*
00437 ErrorMatrix(i,j);
00438 chiSquared +=
00439 mfactor*(fStraightYHits(i)-y0-ySlope*(fZHits(i)-fZHits(0)))*
00440 (fStraightYHits(j)-y0-ySlope*(fZHits(j)-fZHits(0)))*
00441 ErrorMatrix(i,j);
00442 }
00443 }
00444
00445 return chiSquared;
00446 }
|
|
|
Definition at line 449 of file AlgFitTrackMS.cxx. References fCfh, fNHits, fQ, fXHits, fYHits, fZHits, CandHandle::GetVldContext(), and MSG. Referenced by RunAlg(). 00450 {
00451 Double_t qCounter(0);
00452 TVector3 hit1,hit2,hit3,v1,v2,bvector,idealvector;
00453
00454 // for now use BFieldMS - in the future, when normal BField is
00455 // working without the map, use plain old BField.
00456 BFieldMS bf(fCfh->GetVldContext());
00457
00458 Int_t step = fNHits/10;
00459
00460 if(step==0)
00461 step = 1;
00462
00463 for(Int_t i=step;i < (fNHits-step);i++)
00464 {
00465 hit1.SetXYZ(fXHits(i-step),fYHits(i-step),fZHits(i-step));
00466 hit2.SetXYZ(fXHits(i),fYHits(i),fZHits(i));
00467 hit3.SetXYZ(fXHits(i+step),fYHits(i+step),fZHits(i+step));
00468
00469 v1 = hit2 - hit1;
00470 v2 = hit3 - hit2;
00471 v2 = v2 - (v1.Dot(v2)/v1.Mag()/v1.Mag())*v1; // Get Perp vector
00472
00473 if (v1.Mag()==0)
00474 MSG("FitTrackMS", Msg::kInfo) << "huh? " << i << endl;
00475
00476 bvector = bf.GetBField(hit2);
00477
00478 // this corrects for the stupid bfield being wrong!!!!
00479 if(fBFisFlipped)
00480 bvector*=-1.;
00481
00482 idealvector = v1.Cross(bvector);
00483
00484 // if(idealvector.Dot(v2) > 0)
00485 // qCounter++;
00486 // else if(idealvector.Dot(v2) < 0)
00487 // qCounter--;
00488
00489 qCounter += idealvector.Dot(v2);
00490
00491 }
00492
00493 if (qCounter >= 0)
00494 fQ = 1.0;
00495 else
00496 fQ = -1.0;
00497 }
|
|
||||||||||||||||
|
Definition at line 501 of file AlgFitTrackMS.cxx. References FitTrack(), fLTolerance, fMaxP, and MSG. Referenced by RunAlg(). 00503 {
00504 Double_t pmin,pmax,pmid;
00505 Double_t minDet,maxDet,midDet;
00506 Double_t minChi2,maxChi2,midChi2;
00507 Double_t minL,maxL,midL;
00508 Double_t logpmin,logpmid,logpmax;
00509 Double_t pnew, pbest,bestL;
00510
00511 Bool_t converged = false;
00512
00513 // begin new method
00514 /*
00515 Int_t iterations(0);
00516
00517 pmid = fCfh->GetMomentumL();
00518
00519 while(!converged && iterations < fMaxIter){
00520
00521 FitTrack(pmid,midDet,midChi2);
00522
00523 MSG("FitTrackMS", Msg::kDebug)
00524 << "tried " << pmid << " and got " << midChi2 << endl;
00525
00526 pmid = pmid*TMath::Sqrt(fNHits/midChi2);
00527
00528 iterations++;
00529
00530 }
00531 if(fQ==-1){
00532 pbest = pmid;
00533 bestL = midChi2;
00534 }
00535 else{
00536 if(midChi2 < bestL){
00537 pbest = pmid;
00538 bestL = midChi2;
00539 }
00540 }
00541
00542 WriteFit(bestL,pbest);
00543 }
00544 */
00545 // end new method
00546
00547
00548 // begin old method
00549
00550 // choose 3 beginning guesses for the momentum. as of now, we use
00551 // the length estimate to generate these.
00552 pmin = pInit*0.5;
00553 pmax = pInit*1.5;
00554 pmid = pInit;
00555
00556 // try the fit with the 3 guessed momenta.
00557 FitTrack(pmin,minDet,minChi2);
00558 FitTrack(pmax,maxDet,maxChi2);
00559 FitTrack(pmid,midDet,midChi2);
00560
00561 // calculate L for each fit. L is a likelihood function of momentum
00562 // that is calculated by summing Chi Squared and the log of the
00563 // determinant of the covariance matrix. A simple minimization of
00564 // Chi Squared will not work here because it scales with the
00565 // momentum squared. The determinant scales with one over the
00566 // momentum squared so, summing their logs, we get L, a quantity
00567 // which does not explicitly scale with momentum, so we can minimize
00568 // L to get a good approximation of the true momentum.
00569 minL = .5 * minDet + .5 * minChi2;
00570 maxL = .5 * maxDet + .5 * maxChi2;
00571 midL = .5 * midDet + .5 * midChi2;
00572
00573 MSG("FitTrackMS", Msg::kDebug)
00574 << "tried " << pmin << " and got " << minL << endl
00575 << "tried " << pmid << " and got " << midL << endl
00576 << "tried " << pmax << " and got " << maxL << endl;
00577
00578 if(minL < midL && minL < maxL){
00579
00580 pbest = pmin;
00581 bestL = minL;
00582 }
00583 else if(midL < maxL){
00584
00585 pbest = pmid;
00586 bestL = midL;
00587 }
00588 else{
00589
00590 pbest = pmax;
00591 bestL = maxL;
00592 }
00593
00594 Int_t iterations(0);
00595
00596 while(!converged){
00597
00598 MSG("FitTrackMS", Msg::kDebug)
00599 << "iteration # " << iterations << endl;
00600
00601 // use standard polynomial interpolation to fit minL, midL, and
00602 // maxL as a function of the logs of pmin,
00603 // pmid, and pmax to a parabola. then, use exponential of the
00604 // minimum of the parabola to get the next test momentum.
00605 logpmin = TMath::Log(pmin);
00606 logpmid = TMath::Log(pmid);
00607 logpmax = TMath::Log(pmax);
00608
00609 TMatrixD pmat(3,3);
00610 TMatrixD lmat(3,1);
00611 TMatrixD smat(3,1);
00612
00613 pmat(0,0) = 1.0;
00614 pmat(1,0) = 1.0;
00615 pmat(2,0) = 1.0;
00616 pmat(0,1) = logpmin;
00617 pmat(1,1) = logpmid;
00618 pmat(2,1) = logpmax;
00619 pmat(0,2) = logpmin*logpmin;
00620 pmat(1,2) = logpmid*logpmid;
00621 pmat(2,2) = logpmax*logpmax;
00622
00623 if(pmat.Determinant() != 0.)
00624 pmat.Invert();
00625
00626 lmat(0,0) = minL;
00627 lmat(1,0) = midL;
00628 lmat(2,0) = maxL;
00629
00630 smat.Mult(pmat,lmat);
00631
00632 if(smat(2,0)!=0)
00633 pnew = TMath::Exp(-1*smat(1,0)/2.0/smat(2,0));
00634 else
00635 break;
00636
00637 // if the (log p)^2 term of the fit is negative then the parabola
00638 // is convex, which means that pnew is a maximum instead of a
00639 // minimum. in this case, set pnew to a non fixed value (to avoid
00640 // repetition of guesses) in the neighborhood of pbest.
00641 if(smat(2,0)<0){
00642
00643 pnew = pbest*pbest/pnew;
00644 }
00645
00646 // if pnew = infinity, set pnew to a random value in the
00647 // neighborhood of pbest.
00648 if(1.0/pnew == 0){
00649
00650 pnew = pbest+gRandom->Rndm()*pbest/2.0 - pbest/4.0;
00651 }
00652
00653 // if pnew is a repeat of a p already tested, set it to a random
00654 // value in the neighborhood of itself.
00655 if(pnew == pmin || pnew == pmid || pnew == pmax){
00656
00657 pnew = pnew + gRandom->Rndm()*pnew/4.0 - pnew/8.0;
00658 }
00659
00660 // if p looks like it is diverging to infinity, then it is likely
00661 // that the charge on the particle is wrong. so, switch the
00662 // testing charge and restart the momentum search. if the charge
00663 // has already been changed and p is still diverging, abort the
00664 // test. if we develop a better method of determining the charge
00665 // of the particle, this section could be irrelevent.
00666 if(pmin > fMaxP && pnew > fMaxP){
00667
00668 // need to do something here!
00669 break;
00670 }
00671
00672 // dont allow testing of a negative or zero momentum - guess smaller
00673 if(pnew < fMinP){
00674
00675 pnew = pmin / 2.0;
00676 }
00677
00678 // now, determine where pnew falls in pmin, pmid, and pmax.
00679 // choose pnew and the 2 closest values to it to be the new pmin,
00680 // pmid, and pmax. test pnew. update pbest if necessary.
00681 if(pnew < pmin){
00682
00683 pmax = pmid;
00684 pmid = pmin;
00685 pmin = pnew;
00686 maxL = midL;
00687 midL = minL;
00688
00689 FitTrack(pmin,minDet,minChi2);
00690
00691 minL = .5 * minDet + .5 * minChi2;
00692 MSG("FitTrackMS", Msg::kDebug)
00693 << "iterate momentum of " << pmin
00694 <<" and got L of " << minL << endl;
00695
00696 if(minL < bestL){
00697
00698 pbest = pmin;
00699 bestL = minL;
00700 }
00701 }
00702 else if(pnew < pmid && pmax-pnew > pnew-pmid){
00703
00704 pmax = pmid;
00705 pmid = pnew;
00706 maxL = midL;
00707
00708 FitTrack(pmid,midDet,midChi2);
00709
00710 midL = .5 * midDet + .5 * midChi2;
00711
00712 MSG("FitTrackMS", Msg::kDebug)
00713 << "Tried momentum of " << pmid <<" and got L of " << midL << endl;
00714
00715 if(midL < bestL){
00716
00717 pbest = pmid;
00718 bestL = minL;
00719 }
00720 }
00721 else if(pnew < pmid && pmax-pnew < pnew-pmid){
00722
00723 pmin = pnew;
00724
00725 FitTrack(pmin,minDet,minChi2);
00726
00727 minL = .5 * minDet + .5 * minChi2;
00728
00729 MSG("FitTrackMS", Msg::kDebug)
00730 << "Tried momentum of " << pmin <<" and got L of " << minL << endl;
00731
00732 if(minL < bestL){
00733
00734 pbest = pmin;
00735 bestL = minL;
00736 }
00737 }
00738 else if(pnew < pmax && pmax-pnew > pnew-pmin){
00739
00740 pmax = pnew;
00741
00742 FitTrack(pmax,maxDet,maxChi2);
00743
00744 maxL = .5 * maxDet + .5 * maxChi2;
00745
00746 MSG("FitTrackMS", Msg::kDebug)
00747 << "Tried momentum of " << pmax <<" and got L of " << maxL << endl;
00748
00749 if(maxL < bestL){
00750
00751 pbest = pmax;
00752 bestL = maxL;
00753 }
00754 }
00755 else if(pnew < pmax && pmax-pnew < pnew-pmin){
00756
00757 pmin = pmid;
00758 pmid = pnew;
00759 minL = midL;
00760
00761 FitTrack(pmid,midDet,midChi2);
00762
00763 midL = .5 * midDet + .5 * midChi2;
00764
00765 MSG("FitTrackMS", Msg::kDebug)
00766 << "Tried momentum of " << pmid <<" and got L of " << midL << endl;
00767
00768 if(pmid < bestL){
00769
00770 pbest = pmid;
00771 bestL = midL;
00772 }
00773 }
00774 else{
00775
00776 pmin = pmid;
00777 pmid = pmax;
00778 pmax = pnew;
00779 minL = midL;
00780 midL = maxL;
00781
00782 FitTrack(pmax,maxDet,maxChi2);
00783
00784 maxL = .5 * maxDet + .5 * maxChi2;
00785
00786 MSG("FitTrackMS", Msg::kDebug)
00787 << "Tried momentum of " << pmax <<" and got L of " << maxL << endl;
00788
00789 if(maxL < bestL){
00790
00791 pbest = pmax;
00792 bestL = maxL;
00793 }
00794 }
00795
00796 // converging condition.
00797 if((TMath::Max(TMath::Max(minL,midL),maxL) -
00798 TMath::Min(TMath::Min(minL,midL),maxL))/
00799 TMath::Min(TMath::Min(minL,midL),maxL) < fLTolerance &&
00800
00801 (TMath::Max(TMath::Max(pmin,pmid),pmax) -
00802 TMath::Min(TMath::Min(pmin,pmid),pmax))/
00803 TMath::Min(TMath::Min(pmin,pmid),pmax) < fPTolerance){
00804
00805 converged = true;
00806 }
00807
00808 if(iterations > fMaxIter){
00809 converged = true;
00810 }
00811 iterations++;
00812 }
00813
00814 pFit = pbest;
00815 LFit = bestL;
00816
00817 return iterations;
00818 }
|
|
||||||||||||||||
|
Definition at line 822 of file AlgFitTrackMS.cxx. References ChiSquared(), fNHits, fPosErr, fSolnMatrix, MakeCovarianceMatrix(), MakePPlanes(), MakeSolnMatrices(), MakeStraightTrack(), and MSG. Referenced by DoFitAlg(). 00824 {
00825 TMatrixD CovMatrix(fNHits,fNHits);
00826 TMatrixD ErrorMatrix(fNHits,fNHits);
00827 TMatrixD VariableCoefMatrix(2,2);
00828 TMatrixD ConstantCoefMatrix(2,2);
00829
00830 MakePPlanes(p0);
00831
00832 MakeCovarianceMatrix(CovMatrix, p0);
00833
00834 // minimize Chi Squared by solving a matrix equation.
00835 // LogCovMDeterminant = TMath::Log(CovMatrix.Determinant());
00836
00837 if(fPosErr!=0.)
00838 CovMatrix*= 1/TMath::Power(fPosErr,2);
00839
00840 LogCovMDeterminant = TMath::Log(CovMatrix.Determinant());
00841
00842 if(1/LogCovMDeterminant == 0.0){
00843
00844 MSG("FitTrackMS", Msg::kDebug) << "ah!!!!!!!!!!!!!!!!!!!" << endl;
00845
00846 LogCovMDeterminant = 1000000;
00847 }
00848
00849 //InvertCovMatrix(CovMatrix, ErrorMatrix, LogCovMDeterminant);
00850 CovMatrix.Invert(); // Replaces CovMatrix.InvertPosDef();
00851 //gmi CovMatrix.InvertPosDef(); // InvertPosDef() eliminated in ROOT
00852 ErrorMatrix = CovMatrix;
00853
00854 if(fPosErr!=0.){
00855 LogCovMDeterminant += 2*fNHits*TMath::Log(fPosErr);
00856 ErrorMatrix*=1/TMath::Power(fPosErr,2);
00857 }
00858
00859 MakeStraightTrack();
00860
00861 MakeSolnMatrices(VariableCoefMatrix,ConstantCoefMatrix,ErrorMatrix);
00862
00863 if(VariableCoefMatrix.Determinant() != 0.)
00864 VariableCoefMatrix.Invert();
00865
00866 fSolnMatrix.Mult(VariableCoefMatrix, ConstantCoefMatrix);
00867
00868 // calculate Chi Squared.
00869 chiSquared = ChiSquared(ErrorMatrix);
00870
00871 // LogCovMDeterminant = -1*fNHits*TMath::Log(p0);
00872 //LogCovMDeterminant = 0;
00873 }
|
|
|
Definition at line 876 of file AlgFitTrackMS.cxx. References fSteelPlnWidth, and fXZero. Referenced by MakeCovarianceMatrix(). 00877 {
00878 // this is a standard formula for calculating the mean square
00879 // deflection angle in multiple scattering.
00880
00881 if(!fNoMS)
00882 return TMath::Power(.0136*TMath::Sqrt(fSteelPlnWidth/fXZero)*
00883 (1.0+.038*TMath::Log(fSteelPlnWidth/fXZero))/peloss,2);
00884 else
00885 return 0;
00886
00887 }
|
|
|
Definition at line 890 of file AlgFitTrackMS.cxx. References fCfh, fDedx, fDetector, fFlag, fNHits, fNPlanes, fPPlanes, fSteelPlnWidth, fStraightXHits, fStraightYHits, fSuperModGapSize, fTotalPlnWidth, fXHits, fYHits, fZHits, fZPlanes, CandRecoHandle::GetBegPlane(), CandRecoHandle::GetEndPlane(), PlexPlaneId::GetPlane(), CandTrackHandle::GetT(), CandTrackHandle::GetU(), CandTrackHandle::GetV(), CandHandle::GetVldContext(), UgliSteelPlnHandle::GetZ0(), UgliPlnHandle::GetZ0(), UgliSteelPlnHandle::IsValid(), UgliScintPlnHandle::IsValid(), MSG, PlexPlaneId::SetIsSteel(), and CandFitTrackMSHandle::SetMomentumL(). Referenced by RunAlg(). 00891 {
00892 MSG("FitTrackMS", Msg::kDebug) << "InitArray" << endl;
00893
00894 UgliGeomHandle ugh(*fCfh->GetVldContext());
00895
00896 Int_t sMod(-1);
00897 Double_t pathlength(0);
00898
00899 Int_t bPlane = TMath::Min(fCfh->GetBegPlane(),fCfh->GetEndPlane());
00900 Int_t ePlane = TMath::Max(fCfh->GetBegPlane(),fCfh->GetEndPlane());
00901
00902 // preliminarily resize these vectors to the number of
00903 // possible hits
00904 fXHits.ResizeTo(ePlane-bPlane+1);
00905 fYHits.ResizeTo(ePlane-bPlane+1);
00906 fZHits.ResizeTo(ePlane-bPlane+1);
00907 fZPlanes.ResizeTo(ePlane-bPlane+1);
00908
00909 fXHits.Zero();
00910 fYHits.Zero();
00911 fZHits.Zero();
00912 fZPlanes.Zero();
00913
00914 fNHits = 0;
00915 fNPlanes = 0;
00916
00917 Double_t timetemp(0);
00918
00919 for(Int_t i=bPlane;i<=ePlane;i++){
00920
00921 // check if you are in the supermodule -- if you are, record which
00922 // hit you are at so the supermodule gap can be subtracted from
00923 // pathlength later
00924 if(i==fSuperModSkippedPlane)
00925 sMod = fNHits;
00926
00927 // get the scintilator and steel plane numbered i. a couple of
00928 // problems here: it assumes that the scintilator and steel
00929 // planes of the same number are always next to eachother - it
00930 // assumes the planes are in ascending z order (which is true for
00931 // now, but wouldnt have to be)
00932 PlexPlaneId planeid(fDetector, i);
00933 UgliScintPlnHandle scintp = ugh.GetScintPlnHandle(planeid);
00934 planeid.SetIsSteel(true);
00935 UgliSteelPlnHandle steelp = ugh.GetSteelPlnHandle(planeid);
00936
00937 if(scintp.IsValid()){
00938
00939 fZHits(fNHits) = scintp.GetZ0() + .5*fScintPlnWidth;
00940
00941 // as of now, this whole algorithm uses x,y coordinates. should
00942 // be able to switch u,v without trouble though. have to switch
00943 // the b field is why i haven't gotten around to it yet.
00944 ugh.uv2xy(fCfh->GetU(i),fCfh->GetV(i),fXHits(fNHits),fYHits(fNHits));
00945
00946 // get the time so (for now) can test if this is a real hit or
00947 // an interpolated hit. if interpolated GetT will return
00948 // -99999.
00949
00950 timetemp = fCfh->GetT(i);
00951
00952 if(fXHits(fNHits)>-90000 && fYHits(fNHits)>-900000
00953 && timetemp>-90000 && fNHits<fMaxHits){
00954
00955 fNHits++;
00956 }
00957 }
00958
00959 if(steelp.IsValid() && (steelp.GetZ0() > fZHits(0))&& i!=ePlane){
00960
00961 fZPlanes(fNPlanes) = steelp.GetZ0() + .5*fSteelPlnWidth;
00962
00963 fNPlanes++;
00964 }
00965 }
00966
00967 Float_t zmin, zmax;
00968
00969 // this calculates the momentum based on the path length and stores
00970 // it with the SetMomentumL method. the geometry stuff is there to
00971 // determine if the last hit of the track is the last plane in the
00972 // detector - i.e. supposedly if the muon exited the detector. it
00973 // doesnt check, though, to see if the muon exited out of the sides
00974 // of the detector instead of the back, or if for some reason it
00975 // didnt hit the last plane but exited anyway.
00976 ugh.GetZExtent(zmin,zmax);
00977 PlexPlaneId maxPlane = ugh.GetPlaneIdFromZ(zmax);
00978
00979 // determine pathlength
00980 for(int i=1;i<fNHits;i++){
00981 pathlength +=
00982 TMath::Sqrt((fXHits(i)-fXHits(i-1))*(fXHits(i)-fXHits(i-1)) +
00983 (fYHits(i)-fYHits(i-1))*(fYHits(i)-fYHits(i-1)) +
00984 (fZHits(i)-fZHits(i-1))*(fZHits(i)-fZHits(i-1)));
00985 }
00986
00987 // subtract the supermodule
00988 if(fDetector == Detector::kFar && sMod!=-1 &&
00989 sMod!=0 && sMod!=fNHits){
00990
00991 pathlength-= fSuperModGapSize/(fZHits(sMod)-fZHits(sMod-1))*
00992 TMath::Sqrt(TMath::Power(fXHits(sMod)-fXHits(sMod-1),2) +
00993 TMath::Power(fYHits(sMod)-fYHits(sMod-1),2) +
00994 TMath::Power(fZHits(sMod)-fZHits(sMod-1),2));
00995
00996 if(pathlength<0){
00997 MSG("FitTrackMS", Msg::kDebug) << "supermodule problem!" << endl;
00998
00999 pathlength = 1.;
01000 fFlag=1;
01001 }
01002 }
01003
01004 // flag track if last hit is within .2 of the
01005 // end of the detector or last hit is outside a makeshift octagon
01006 // shaped area. Use u-v coordinates.
01007
01008 Double_t lastu, lastv;
01009
01010 ugh.xy2uv(fXHits(fNHits-1),fYHits(fNHits-1),lastu, lastv);
01011
01012 if(maxPlane.GetPlane() - 5 <= ePlane ||
01013 TMath::Abs(lastu) > 3.8 ||
01014 TMath::Abs(lastv) > 3.8 ||
01015 TMath::Abs(lastu) + TMath::Abs(lastv) > 5.3)
01016 {
01017 fFlag = 1;
01018 }
01019
01020 fCfh->SetMomentumL(pathlength*fDedx*fSteelPlnWidth/fTotalPlnWidth);
01021
01022 // rhb log p 94, my calculation of mean dE/dx replaces Tom's
01023 // I ignore fdedx
01024 // if(ePlane != maxPlane.GetPlane()){
01025 // the 21/18 is a total fudge -- it's in my log book. Other people
01026 // are also seeing a similar discrepancy in dE/dx, which is just a total
01027 //fudge at this point. Ne fuss pas.
01028 //fCfh->SetMomentumL((21/18.)*pathlength*.021/.0594);
01029
01030 // it's not working, so i'm restoring my method of calculating
01031 // this
01032 // fCfh->SetMomentumL(fdedx*pathlength*.0254/.0594);
01033 // fCfh->SetMomentumL(pathlength);
01034 // }
01035 // else{
01036 /* this occurs if the track leaves the back of the detector
01037 Tom tries 0.5, 1, and 1.5 times this momentum. But this can
01038 be totally unreasonable. Start with three */
01039 // fCfh->SetMomentumL(3.*pathlength*.021/.0594);
01040 // fCfh->SetMomentumL(-1);
01041 // }
01042 // resize the vectors correctly now
01043
01044 MSG("FitTrackMS", Msg::kDebug) << "nHits = " << fNHits << endl;
01045
01046 fXHits.ResizeTo(fNHits);
01047 fYHits.ResizeTo(fNHits);
01048 fZHits.ResizeTo(fNHits);
01049 fZPlanes.ResizeTo(fNPlanes);
01050 fPPlanes.ResizeTo(fNPlanes);
01051
01052 fStraightXHits.ResizeTo(fNHits);
01053 fStraightYHits.ResizeTo(fNHits);
01054 fStraightXHits = fXHits;
01055 fStraightYHits = fYHits;
01056 }
|
|
|
||||||||||||||||
|
Definition at line 1128 of file AlgFitTrackMS.cxx. References fNHits, MSG, TCL::trchlu(), and TCL::trinv(). 01130 {
01131 // this method uses the TCL functions to efficiently invert a
01132 // symmetric matrix. we ought to have a symmetric matrix class that
01133 // does this sort of thing.
01134 Int_t counter(0);
01135
01136 // we need fortran style matrices for TCL. CovMatrix is written to
01137 // a fortran matrix, which is inverted and whose inverse is written
01138 // to another fortram style matrix which is then written to
01139 // ErrorMatrix.
01140
01141 /* try another scheme */
01142
01143 //rwh: Double_t mat[fNHits*fNHits];
01144 //rwh: Double_t tempmat[fNHits*fNHits];
01145 //rwh: C++ forbids variable-size array --- need new/delete[]
01146 Double_t *mat = new Double_t[fNHits*fNHits];
01147 Double_t *tempmat = new Double_t[fNHits*fNHits];
01148
01149 MSG("FitTrackMS", Msg::kDebug) << "Cov Matrix" << endl;
01150
01151 for(Int_t i=0;i<fNHits;i++){
01152 // for(Int_t j=0;j<=i;j++){
01153 for(Int_t j=0;j<fNHits;j++){
01154
01155 tempmat[counter]=CovMatrix(i,j);
01156 counter++;
01157 MSG("FitTrackMS", Msg::kDebug)
01158 << i << " " << j << " " << CovMatrix(i,j) << endl;
01159 }
01160 }
01161
01162 TCL::trchlu(tempmat,mat,fNHits);
01163
01164 LogDet = 0;
01165
01166 MSG("FitTrackMS", Msg::kDebug) << "diag" << endl;
01167
01168 for(Int_t i=0;i<fNHits;i++) {
01169
01170 MSG("FitTrackMS", Msg::kDebug) << i << " " << mat[i*fNHits+i] << endl;
01171
01172 if(mat[i*fNHits+i] > 0){
01173 LogDet += 2*TMath::Log((Double_t)mat[i*fNHits+i]);
01174 }
01175 else if(mat[i*fNHits+i] == 0){
01176 MSG("FitTrackMS", Msg::kDebug) << "zero exactly" << endl;
01177 }
01178 else{
01179 MSG("FitTrackMS", Msg::kDebug) << "less than zero" << endl;
01180 }
01181 }
01182
01183 MSG("FitTrackMS", Msg::kDebug) << "log det = " << LogDet << endl;
01184
01185 TCL::trinv(tempmat,mat,fNHits);
01186
01187 counter=0;
01188
01189 MSG("FitTrackMS", Msg::kDebug) << "Error Matrix" << endl;
01190
01191 for(Int_t i=0;i<fNHits;i++) {
01192 for(Int_t j=0;j<fNHits;j++) {
01193
01194 ErrorMatrix(i,j)=(Double_t)mat[counter];
01195 // ErrorMatrix(j,i)=ErrorMatrix(i,j);
01196 counter++;
01197
01198 MSG("FitTrackMS", Msg::kDebug)
01199 << i << " " << j << " " << ErrorMatrix(i,j) << endl;
01200 }
01201 }
01202
01203 // Double_t determinant = CovMatrix.TMatrixD::Determinant();
01204 Double_t determinant = 1.0;
01205
01206 if (determinant <=0)
01207 {
01208 for(Int_t i=0;i<fNHits;i++) {
01209 for(Int_t j=0;j<=i;j++) {
01210
01211 if (i==j)
01212 {
01213 ErrorMatrix(i,j) = 1;
01214 CovMatrix(i,j) = 1.;
01215 }
01216 if (i!=j)
01217 {
01218 ErrorMatrix(i,j) = 0.;
01219 CovMatrix(i,j) = 0.;
01220 }
01221 }
01222 }
01223 }
01224
01225
01226 //rwh: delete allocated array
01227 delete [] mat;
01228 delete [] tempmat;
01229
01230 }
|
|
||||||||||||
|
Definition at line 1233 of file AlgFitTrackMS.cxx. References fNPlanes, fPosErr, fPPlanes, fSteelPlnWidth, fZHits, fZPlanes, and GetSigmaMS(). Referenced by FitTrack(). 01235 {
01236
01237 Double_t sigma2MS, dzi, dzj;
01238 Int_t k;
01239
01240 CovMatrix.Zero();
01241
01242 // make the covariance matrix -- loop over half of the matrix
01243 // because it is symmetric.
01244 for(Int_t i=0; i<fNHits; i++){
01245 for(Int_t j=0; j<=i; j++){
01246
01247 // add the uncertainty on position to diagonal elements
01248 if(i==j)
01249 {
01250 CovMatrix(i,j) += fPosErr*fPosErr;
01251 }
01252 if (1.)
01253 {
01254 k=0;
01255 // loop over all planes between the first hit to the jth hit. j
01256 // is always smaller than i.
01257 while(k<fNPlanes&&fZPlanes(k)<fZHits(j)){
01258
01259 dzi = fZHits(i) - fZPlanes(k);
01260 dzj = fZHits(j) - fZPlanes(k);
01261
01262 // get the square RMS scattering angle
01263 sigma2MS = GetSigmaMS(fPPlanes(k));
01264
01265 // add the covariance from the scattering
01266 CovMatrix(i,j) += sigma2MS*(fSteelPlnWidth*fSteelPlnWidth/3.0
01267 + fSteelPlnWidth*(dzi+dzj)/2.0 + dzi*dzj);
01268 k++;
01269 }
01270 }
01271 // the matrix is symmetric
01272 CovMatrix(j,i) = CovMatrix(i,j);
01273 }
01274 }
01275 }
|
|
|
Definition at line 1389 of file AlgFitTrackMS.cxx. References fNHits, fNPlanes, fPPlanes, fSteelPlnWidth, fXHits, fYHits, fZHits, and fZPlanes. Referenced by FitTrack(), and RunAlg(). 01390 {
01391 fPPlanes.Zero();
01392
01393 // The function makes a vector PPlanes which stores the value of p
01394 // for each plane, taking into account Dedx energy loss.
01395 //
01396 // Since the value of p you input into the function is actually the
01397 // p when the muon is created, it is the p approximately half way
01398 // through the steel plane before the first hit. In contrast,
01399 // fPPlanes(0) is the value of p half way through the plane after
01400 // the first hit.
01401
01402 Int_t i(0),k(0);
01403 Double_t pcounter(0);
01404
01405 while(i<fNHits-1 && k<fNPlanes){
01406
01407 while(k < fNPlanes && fZHits(i) < fZPlanes(k) &&
01408 fZPlanes(k) < fZHits(i+1)){
01409
01410 // The dist travelled in steel from one plane to another is
01411 // calculated by summing the dist travelled in the second half of
01412 // the last plane with the dist travelled in the first half of the
01413 // plane k. The direction is extrapolated from surrounding hit
01414 // data.
01415
01416 // this is done in such a way that the formula is simply...
01417 Double_t dz = fSteelPlnWidth/(fZHits(i+1)-fZHits(i))*
01418 (TMath::Sqrt(TMath::Power(fXHits(i+1)-fXHits(i),2) +
01419 TMath::Power(fYHits(i+1)-fYHits(i),2) +
01420 TMath::Power(fZHits(i+1)-fZHits(i),2)));
01421
01422 pcounter += dz*fDedx;
01423
01424 if(k!=0){
01425
01426 fPPlanes(k) = fPPlanes(k-1) - dz*fDedx;
01427 if(fPPlanes(k) < 0)
01428 fPPlanes(k) = fPPlanes(k-1)/2.;
01429 }
01430 else{
01431
01432 fPPlanes(k) = p0 - dz*fDedx;
01433 if(fPPlanes(k) < 0)
01434 fPPlanes(k) = p0/2.;
01435 }
01436
01437 k++;
01438 }
01439 i++;
01440 }
01441 assert(k==fNPlanes);
01442 }
|
|
||||||||||||||||
|
Definition at line 1446 of file AlgFitTrackMS.cxx. References fStraightXHits, fStraightYHits, and fZHits. Referenced by FitTrack(). 01448 {
01449
01450 Double_t z0 = fZHits(0);
01451
01452 VariableCoefMatrix.Zero();
01453 ConstantCoefMatrix.Zero();
01454
01455 // this is somewhat complicated. you can derive what goes into
01456 // these by taking partials of the Chi squared and solving - or you
01457 // can take my word for it.
01458
01459 // further complications arise because i foolishly insist on only
01460 // looping over half the matrix. and we're doing this for x and y.
01461
01462 for(Int_t i=0; i<ErrorMatrix.GetNrows(); i++){
01463 for(Int_t j=0; j<=i; j++){
01464
01465 if(i==j){
01466 VariableCoefMatrix(0,0) += ErrorMatrix(i,j);
01467 VariableCoefMatrix(1,0) +=
01468 (fZHits(i)-z0)*ErrorMatrix(i,j);
01469 VariableCoefMatrix(1,1) +=
01470 (fZHits(i)-z0)*(fZHits(j)-z0)*ErrorMatrix(i,j);
01471
01472 ConstantCoefMatrix(0,0) +=
01473 fStraightXHits(i)*ErrorMatrix(i,j);
01474 ConstantCoefMatrix(1,0) +=
01475 fStraightXHits(i)*(fZHits(j)-z0)*ErrorMatrix(i,j);
01476 ConstantCoefMatrix(0,1) +=
01477 fStraightYHits(i)*ErrorMatrix(i,j);
01478 ConstantCoefMatrix(1,1) +=
01479 fStraightYHits(i)*(fZHits(j)-z0)*ErrorMatrix(i,j);
01480 }
01481
01482 else{
01483 VariableCoefMatrix(0,0)+=2*ErrorMatrix(i,j);
01484 VariableCoefMatrix(1,0)+=(fZHits(i)+fZHits(j)-2*z0)*ErrorMatrix(i,j);
01485 VariableCoefMatrix(1,1) +=
01486 2*(fZHits(i)-z0)*(fZHits(j)-z0)*ErrorMatrix(i,j);
01487
01488 ConstantCoefMatrix(0,0) += (fStraightXHits(i) +
01489 fStraightXHits(j))*ErrorMatrix(i,j);
01490 ConstantCoefMatrix(1,0) +=
01491 (fStraightXHits(i)*(fZHits(j)-z0)+
01492 fStraightXHits(j)*(fZHits(i)-z0))*ErrorMatrix(i,j);
01493 ConstantCoefMatrix(0,1) += (fStraightYHits(i) +
01494 fStraightYHits(j))*ErrorMatrix(i,j);
01495 ConstantCoefMatrix(1,1) +=
01496 (fStraightYHits(i)*(fZHits(j)-z0)+
01497 fStraightYHits(j)*(fZHits(i)-z0))*ErrorMatrix(i,j);
01498 }
01499 }
01500 }
01501 VariableCoefMatrix(0,1) = VariableCoefMatrix(1,0);
01502 }
|
|
|
Definition at line 1278 of file AlgFitTrackMS.cxx. References fCfh, fNHits, fNPlanes, fPPlanes, fQ, fSteelPlnWidth, fStraightXHits, fStraightYHits, fXHits, fYHits, fZHits, fZPlanes, CandHandle::GetVldContext(), and MSG. Referenced by FitTrack(), and RunAlg(). 01279 {
01280
01281 if(!fNoBField){
01282 fStraightXHits.ResizeTo(fNHits);
01283 fStraightYHits.ResizeTo(fNHits);
01284
01285 fStraightXHits = fXHits;
01286 fStraightYHits = fYHits;
01287
01288 // for now use BFieldMS - in the future, when normal BField is
01289 // working without the map, use plain old BField.
01290 BFieldMS bf(fCfh->GetVldContext());
01291 TVector3 temp,bfield;
01292
01293 Double_t xslope,yslope, sinThetaDx, sinThetaDy, pz, dist;
01294
01295 Int_t i(0), k(0);
01296
01297 // loop over steel planes -- keep track of the 3 hits surrounding.
01298 while(i<fNHits && k<fNPlanes){
01299
01300 while(k < fNPlanes && fZHits(i) < fZPlanes(k) &&
01301 fZPlanes(k) < fZHits(i+1)){
01302
01303 // estimate the slope the particle had while going into the
01304 // plane. if no hits are missing, this is roughly the average of
01305 // the slopes of lines drawn connecting the hit before the plane
01306 // to the previous
01307 // hit and the hit before the plane to the following hit. If
01308 // planes are missing,
01309 // this gets more complicated. If hits are missing, use a
01310 // weighted average.
01311
01312 if(i!=0){
01313
01314 xslope = ((fZHits(i+1)-fZHits(i))*(fXHits(i) - fXHits(i-1)) /
01315 (fZHits(i) - fZHits(i-1)) +
01316 (fZHits(i)-fZHits(i-1))*(fXHits(i+1) - fXHits(i)) /
01317 (fZHits(i+1) - fZHits(i))) /
01318 (fZHits(i+1) - fZHits(i-1));
01319
01320 yslope = ((fZHits(i+1)-fZHits(i))*(fYHits(i) - fYHits(i-1)) /
01321 (fZHits(i) - fZHits(i-1)) +
01322 (fZHits(i)-fZHits(i-1))*(fYHits(i+1) - fYHits(i)) /
01323 (fZHits(i+1) - fZHits(i))) /
01324 (fZHits(i+1) - fZHits(i-1));
01325 }
01326 else{
01327
01328 xslope = (fXHits(1)-fXHits(0))/(fZHits(1)-fZHits(0));
01329 yslope = (fYHits(1)-fYHits(0))/(fZHits(1)-fZHits(0));
01330 }
01331
01332 // calculate p component in z direction. for now, ignore p in x
01333 // and y directions
01334
01335 pz = fPPlanes(k)*TMath::Cos(TMath::ATan(TMath::Sqrt(
01336 xslope*xslope + yslope*yslope)));
01337
01338 // calculate the actual amount of distance travelled through the
01339 // steel plane
01340
01341 dist = fSteelPlnWidth*TMath::Sqrt(1 + TMath::Power(xslope,2) +
01342 TMath::Power(yslope,2));
01343
01344 // calculate the BField deflection angle in plane k
01345
01346 temp.SetXYZ(fXHits(i) + xslope*(fZPlanes(k)-fZHits(i)),
01347 fYHits(i) + yslope*(fZPlanes(k)-fZHits(i)),
01348 fZPlanes(k));
01349
01350 bfield = bf.GetBField(temp);
01351
01352 // once again, correct for bfield being wrong
01353 if(fBFisFlipped)
01354 bfield*=-1.;
01355
01356 sinThetaDx = -fQ*.3*bfield.Y()*dist/pz;
01357 sinThetaDy = fQ *.3*bfield.X()*dist/pz;
01358 // sinThetaDx = 0;
01359 // sinThetaDy = 0;
01360
01361 // sum the bfield effects.
01362 for (Int_t j=i+1;j<fNHits;j++){
01363
01364 fStraightXHits(j) -= sinThetaDx*(fZHits(j)-fZPlanes(k));
01365 fStraightYHits(j) -= sinThetaDy*(fZHits(j)-fZPlanes(k));
01366 }
01367 k++;
01368 }
01369 i++;
01370 }
01371 }
01372 // if fStraightXHits not been initialized and fNoBField!=0 then
01373 // initialize them
01374 else if(fStraightXHits.GetNrows() == 0){
01375 fStraightXHits.ResizeTo(fNHits);
01376 fStraightYHits.ResizeTo(fNHits);
01377
01378 fStraightXHits.ResizeTo(fNHits);
01379 fStraightYHits.ResizeTo(fNHits);
01380 fStraightXHits = fXHits;
01381 fStraightYHits = fYHits;
01382
01383 MSG("FitTrackMS", Msg::kError)
01384 << "Shouldn't ever get here!!!!!!!!!!!!!!!!!" << endl;
01385 }
01386 }
|
|
||||||||||||||||
|
Implements AlgBase. Definition at line 65 of file AlgFitTrackMS.cxx. References DetermineQ(), DoFitAlg(), fBothFit, fCfh, fFlag, fFullAna, fNHits, fNoBField, fNofit, fNoMS, fQ, CandFitTrackMSHandle::GetMomentumL(), InitArrays(), InitFitHandle(), MakePPlanes(), MakeStraightTrack(), MSG, CandFitTrackHandle::SetChi2(), CandFitTrackMSHandle::SetChi2Alt(), CandFitTrackMSHandle::SetChi2BF(), CandFitTrackMSHandle::SetChi2Both(), CandFitTrackMSHandle::SetChi2MS(), CandFitTrackHandle::SetEMCharge(), CandFitTrackMSHandle::SetEMChargeD(), CandFitTrackMSHandle::SetFlag(), CandFitTrackMSHandle::SetIter(), CandTrackHandle::SetMomentum(), CandFitTrackMSHandle::SetMomentumAlt(), CandFitTrackMSHandle::SetMomentumBF(), CandFitTrackMSHandle::SetMomentumBoth(), CandFitTrackMSHandle::SetMomentumMS(), SetupAlg(), and WriteFit(). 00066 {
00067
00068 // set fCfh to ch so we can modify fCfh and return ch, the handle to the
00069 // fitted track, to the FitTrackMSModule.
00070 // this is telling the code that it actually points to a specific
00071 // CandFitTrackMSHandle, not a generic CandHandle (see void above
00072 assert(ch.InheritsFrom("CandFitTrackMSHandle"));
00073 fCfh = &dynamic_cast<CandFitTrackMSHandle &> (ch);
00074
00075 InitFitHandle(cx);
00076
00077 SetupAlg(ac);
00078
00079 InitArrays();
00080
00081 if(fNofit || (fNoBField && fNoMS) ||
00082 fNHits<fMinHits){
00083
00084 DetermineQ();
00085 fCfh->SetMomentum(fCfh->GetMomentumL());
00086 fCfh->SetChi2(-1);
00087 fCfh->SetEMCharge(0);
00088 fCfh->SetEMChargeD(fQ);
00089 fCfh->SetIter(0);
00090
00091 if(fFlag==1){
00092 fCfh->SetFlag(-3);
00093 }
00094 else{
00095 fCfh->SetFlag(3);
00096 }
00097 }
00098 else if(fNoMS!=0){
00099
00100 Double_t p, L, pplus, pminus,Lplus, Lminus;
00101
00102 Int_t temp1,temp2;
00103
00104 fQ = -1.;
00105 temp1 = DoFitAlg(fCfh->GetMomentumL(),pminus,Lminus);
00106
00107 fQ = 1.;
00108 temp2 = DoFitAlg(fCfh->GetMomentumL(),pplus,Lplus);
00109
00110 if(Lminus < Lplus){
00111
00112 p = pminus;
00113 L = Lminus;
00114 fQ = -1.;
00115 fCfh->SetEMCharge(-1.);
00116 fCfh->SetIter(temp1);
00117 }
00118 else{
00119
00120 p = pplus;
00121 L = Lplus;
00122 fCfh->SetEMCharge(1.);
00123 fCfh->SetIter(temp2);
00124 }
00125
00126 fCfh->SetMomentumBF(p);
00127 fCfh->SetChi2BF(L);
00128
00129 if(p <= fMaxP && p >= fMinP){
00130
00131 WriteFit(L,p);
00132
00133 if(fFlag == 1)
00134 fCfh->SetFlag(-1);
00135 else
00136 fCfh->SetFlag(1);
00137 }
00138 // momentum has diverged - use the length
00139 else{
00140
00141 fCfh->SetMomentum(fCfh->GetMomentumL());
00142 fCfh->SetChi2(-1);
00143
00144 if(fFlag == 1)
00145 fCfh->SetFlag(-2);
00146 else
00147 fCfh->SetFlag(2);
00148 }
00149 }
00150 else if(fNoBField!=0){
00151
00152 DetermineQ();
00153 fCfh->SetEMCharge(fQ);
00154
00155 Double_t p, L;
00156 Int_t temp;
00157
00158 temp = DoFitAlg(fCfh->GetMomentumL(),p,L);
00159
00160 fCfh->SetMomentumMS(p);
00161 fCfh->SetChi2MS(L);
00162 fCfh->SetIter(temp);
00163
00164 if(p <= fMaxP && p >= fMinP){
00165
00166 WriteFit(L,p);
00167
00168 if(fFlag == 1)
00169 fCfh->SetFlag(-1);
00170 else
00171 fCfh->SetFlag(1);
00172 }
00173 // momentum has diverged - use the length
00174 else{
00175
00176 fCfh->SetMomentum(fCfh->GetMomentumL());
00177 fCfh->SetChi2(-1);
00178
00179 if(fFlag == 1)
00180 fCfh->SetFlag(-2);
00181 else
00182 fCfh->SetFlag(2);
00183 }
00184 }
00185 else if(fFullAna==0 && fBothFit==0){
00186
00187 Double_t p, L, pplus, pminus,Lplus, Lminus, pMS;
00188 Int_t temp;
00189
00190 fNoMS = 1;
00191
00192 fQ = -1.;
00193 DoFitAlg(fCfh->GetMomentumL(),pminus,Lminus);
00194
00195 fQ = 1.;
00196 DoFitAlg(fCfh->GetMomentumL(),pplus,Lplus);
00197
00198 if(Lminus < Lplus){
00199
00200 p = pminus;
00201 L = Lminus;
00202 fQ = -1.;
00203 fCfh->SetEMCharge(-1.);
00204 }
00205 else{
00206
00207 p = pplus;
00208 L = Lplus;
00209 fCfh->SetEMCharge(1.);
00210 }
00211
00212 fNoMS = 0;
00213 fNoBField = 1;
00214
00215 MakePPlanes(p);
00216 MakeStraightTrack();
00217
00218 temp = DoFitAlg(p,pMS, L);
00219
00220 fCfh->SetMomentumAlt(pMS);
00221 fCfh->SetChi2Alt(L);
00222 fCfh->SetIter(temp);
00223
00224 if(pMS <= fMaxP && pMS >= fMinP){
00225
00226 WriteFit(L,pMS);
00227
00228 if(fFlag == 1)
00229 fCfh->SetFlag(-1);
00230 else
00231 fCfh->SetFlag(1);
00232 }
00233 // momentum has diverged - use the length
00234 else{
00235
00236 fCfh->SetMomentum(fCfh->GetMomentumL());
00237 fCfh->SetChi2(-1);
00238
00239 if(fFlag==1)
00240 fCfh->SetFlag(-2);
00241 else
00242 fCfh->SetFlag(2);
00243 }
00244 }
00245 else if(fFullAna==0 && fBothFit!=0){
00246
00247 // Double_t p, L, pplus, pminus,Lplus, Lminus;
00248 // Int_t temp1, temp2;
00249
00250 // fQ = -1.;
00251 // DoFitAlg(fCfh->GetMomentumL(),pminus,Lminus);
00252
00253 // fQ = 1.;
00254 // DoFitAlg(fCfh->GetMomentumL(),pplus,Lplus);
00255
00256 // if(Lminus < Lplus){
00257
00258 // p = pminus;
00259 // L = Lminus;
00260 // fQ = -1.;
00261 // fCfh->SetEMCharge(-1.);
00262 // fCfh->SetIter(temp1);
00263 // }
00264 // else{
00265
00266 // p = pplus;
00267 // L = Lplus;
00268 // fCfh->SetEMCharge(1.);
00269 // fCfh->SetIter(temp2);
00270 // }
00271
00272 Int_t temp;
00273 Double_t p,L;
00274
00275 DetermineQ();
00276 fCfh->SetEMChargeD(fQ);
00277 fCfh->SetEMCharge(0);
00278
00279 temp = DoFitAlg(fCfh->GetMomentumL(),p,L);
00280 fCfh->SetIter(temp);
00281
00282 fCfh->SetMomentumBoth(p);
00283 fCfh->SetChi2Both(L);
00284
00285 if(p <= fMaxP && p >= fMinP){
00286
00287 WriteFit(L,p);
00288
00289 if(fFlag == 1)
00290 fCfh->SetFlag(-1);
00291 else
00292 fCfh->SetFlag(1);
00293 }
00294 // momentum has diverged - use the length
00295 else{
00296
00297 fCfh->SetMomentum(fCfh->GetMomentumL());
00298 fCfh->SetChi2(-1);
00299
00300 if(fFlag == 1)
00301 fCfh->SetFlag(-2);
00302 else
00303 fCfh->SetFlag(2);
00304 }
00305 }
00306 else if(fFullAna != 0){
00307
00308 // doing a couple different kinds of fits for this
00309
00310 Double_t p, L, pMS,pminus,pplus,Lminus,Lplus;
00311 Int_t temp;
00312
00313 // since this will take forever anyway -- for now, find charge
00314 // with DetermineQ and use that
00315
00316 DetermineQ();
00317 fCfh->SetEMChargeD(fQ);
00318
00319 // do a fit with BField off -- only MS.
00320 fNoBField = 1;
00321 fNoMS = 0;
00322
00323 DoFitAlg(fCfh->GetMomentumL(),p,L);
00324
00325 fCfh->SetMomentumMS(p);
00326 fCfh->SetChi2MS(L);
00327
00328 // do a fit with BField only - no MS.
00329 fNoBField = 0;
00330 fNoMS = 1;
00331
00332 fQ=-1;
00333
00334 DoFitAlg(fCfh->GetMomentumL(),pminus,Lminus);
00335
00336 fQ=1;
00337
00338 DoFitAlg(fCfh->GetMomentumL(),pplus,Lplus);
00339
00340 if(Lminus < Lplus){
00341
00342 fCfh->SetEMCharge(-1.);
00343 fQ = -1;
00344 fCfh->SetMomentumBF(pminus);
00345 fCfh->SetChi2BF(Lminus);
00346 MakePPlanes(pminus);
00347 MakeStraightTrack();
00348 p = pminus;
00349 }
00350 else{
00351 fCfh->SetEMCharge(1.);
00352 fCfh->SetMomentumBF(pplus);
00353 fCfh->SetChi2BF(Lplus);
00354 MakePPlanes(pplus);
00355 MakeStraightTrack();
00356 p = pplus;
00357 }
00358
00359 // fitted BField, now fit MS again with BField off (straight track
00360 // stays)
00361 fNoBField = 1;
00362 fNoMS = 0;
00363
00364 DoFitAlg(p,pMS,L);
00365
00366 fCfh->SetMomentumAlt(pMS);
00367 fCfh->SetChi2Alt(L);
00368
00369 // now fit both at same time
00370 fNoBField = 0;
00371
00372 temp = DoFitAlg(fCfh->GetMomentumL(),p,L);
00373
00374 fCfh->SetMomentumBoth(p);
00375 fCfh->SetChi2Both(L);
00376 fCfh->SetIter(temp);
00377
00378 if(p <= fMaxP && p >= fMinP){
00379
00380 WriteFit(L,p);
00381
00382 if(fFlag == 1)
00383 fCfh->SetFlag(-1);
00384 else
00385 fCfh->SetFlag(1);
00386 }
00387 // momentum has diverged - use the length
00388 else{
00389
00390 fCfh->SetMomentum(fCfh->GetMomentumL());
00391 fCfh->SetChi2(-1);
00392
00393 if(fFlag == 1)
00394 fCfh->SetFlag(-2);
00395 else
00396 fCfh->SetFlag(2);
00397 }
00398 }
00399 else
00400 MSG("FitTrackMS", Msg::kError) << "shouldn't ever get here" << endl;
00401 }
|
|
|
Definition at line 1504 of file AlgFitTrackMS.cxx. References done(), fBFisFlipped, fBothFit, fCfh, fDedx, fDetector, fFlag, fFullAna, fInShower, fLTolerance, fMaxHits, fMaxIter, fMaxP, fMinHits, fMinP, fNoBField, fNofit, fNoMS, fPosErr, fPTolerance, fQ, fScintPlnWidth, fSolnMatrix, fSteelPlnWidth, fSuperModGapSize, fSuperModSkippedPlane, fTotalPlnWidth, fXZero, VldContext::GetDetector(), Registry::GetDouble(), UgliSteelPlnHandle::GetHalfThickness(), UgliPlnHandle::GetHalfThickness(), Registry::GetInt(), PlexPlaneId::GetNext(), CandHandle::GetVldContext(), UgliPlnHandle::GetZ0(), UgliSteelPlnHandle::IsValid(), UgliScintPlnHandle::IsValid(), and PlexPlaneId::SetIsSteel(). Referenced by RunAlg(). 01505 {
01506 fQ = 0;
01507 fFlag = 0;
01508
01509 fSolnMatrix.ResizeTo(2,2);
01510
01511 // for now - hard code in a lot of these constants. much of this
01512 // will be changed later so it can be accessed from JobC.
01513
01514 UgliGeomHandle ugh(*fCfh->GetVldContext());
01515
01516 // fPosErr is the uncertainty on a position measurement. this is
01517 // tricky because it would be easier to tell this uncertainty in a
01518 // u,v coordinate system. and there are different uncertainties
01519 // depending on how the scintilator plane is oriented. more work is
01520 // needed here.
01521 fPosErr = ac.GetDouble("PosErr");
01522
01523 // fXZero is radiation length of the steel
01524 fXZero = ac.GetDouble("XZero");
01525
01526 // fdedx is the approximate energy loss per meter in steel.
01527 fDedx = ac.GetDouble("Dedx");
01528
01529 // fSuperModGapSize is distance between 2 supermodules
01530 fSuperModGapSize = ac.GetDouble("SuperModGapSize");
01531
01532 // fSuperModSkippedPlane is the plane skipped by the supermodule
01533 // (currently 250) and is used to test if the particle passes
01534 // through the supermodule. Should the situation change to where
01535 // the supermodule does not skip any planes, the code would need to
01536 // be reworked slightly. Should it change to where the supermodule
01537 // skips multiple planes, setting fSuperModSkippedPlane to any one of
01538 // the skipped planes will do.
01539 fSuperModSkippedPlane = ac.GetInt("SuperModSkippedPlane");
01540
01541 // set fBFisFlipped != 0 (the default) if the BField map was made
01542 // with the current going the wrong way, making the magnetic field
01543 // wrong. this is currently the case.
01544 fBFisFlipped = ac.GetInt("BFisFlipped");
01545
01546 // if fNofit != 0, the actual fit is skipped for testing purposes.
01547 fNofit = ac.GetInt("Nofit");
01548
01549 // if fNoBField !=0, the fit is done with bfield identically zero.
01550 fNoBField = ac.GetInt("NoBField");
01551
01552 // if fNoMS !=0, the fit is done assuming no multiple scattering.
01553 fNoMS = ac.GetInt("NoMS");
01554
01555 // if fBothFit !=0, do MS and BField at same time, otherwise do
01556 // seperately.
01557 fBothFit = ac.GetInt("BothFit");
01558
01559 // if fFullAna !=0, fit in many different ways and save all kinds.
01560 fFullAna = ac.GetInt("FullAna");
01561
01562 // runs out of memory over a certain number - fit only the first
01563 // MaxHits hits if the track has more.
01564 fMaxHits = ac.GetInt("MaxHits");
01565
01566 // too few hits causes impossible fit - use length.
01567 fMinHits = ac.GetInt("MinHits");
01568
01569 // very unlikely that an event with p above maxp would occur. kill
01570 // fit if recommended momentum is above it
01571 fMaxP = ac.GetDouble("MaxP");
01572
01573 // kill also if p drops below minp
01574 fMinP = ac.GetDouble("MinP");
01575
01576 // Maximum number of iterations
01577 fMaxIter = ac.GetInt("MaxIter");
01578
01579 // To what extent cut bad hits - high number keeps all - zero keeps
01580 // fewest - 1 is more reasonable.
01581 fInShower = ac.GetInt("InShower");
01582
01583 // tolerance of L before converges
01584 fLTolerance = ac.GetDouble("LTolerance");
01585
01586 // tolerance of P before converges
01587 fPTolerance = ac.GetDouble("PTolerance");
01588
01589 // set the detector type.
01590 fDetector = fCfh->GetVldContext()->GetDetector();
01591
01592 Int_t done(0);
01593
01594 PlexPlaneId planeid1(fDetector,1);
01595 PlexPlaneId splaneid(fDetector,1);
01596 splaneid.SetIsSteel(true);
01597 PlexPlaneId planeid2(fDetector,2);
01598
01599 while(!done){
01600
01601 UgliScintPlnHandle scintp1 = ugh.GetScintPlnHandle(planeid1);
01602 UgliScintPlnHandle scintp2 = ugh.GetScintPlnHandle(planeid2);
01603
01604 if(scintp1.IsValid() && scintp2.IsValid()){
01605
01606 done = true;
01607
01608 fScintPlnWidth = scintp1.GetHalfThickness()*2.;
01609 fTotalPlnWidth = scintp2.GetZ0() - scintp1.GetZ0();
01610 }
01611 planeid1 = planeid2;
01612 planeid2 = planeid2.GetNext();
01613 }
01614 done = false;
01615
01616 while(!done){
01617
01618 UgliSteelPlnHandle steelp = ugh.GetSteelPlnHandle(splaneid);
01619
01620 if(steelp.IsValid()){
01621
01622 done = true;
01623
01624 fSteelPlnWidth = steelp.GetHalfThickness()*2.;
01625 }
01626 splaneid = splaneid.GetNext();
01627 }
01628 }
|
|
|
Reimplemented from AlgBase. Definition at line 404 of file AlgFitTrackMS.cxx. 00405 {
00406 }
|
|
||||||||||||
|
Definition at line 1631 of file AlgFitTrackMS.cxx. References fCfh, fNHits, fSolnMatrix, fXHits, fYHits, fZHits, CandRecoHandle::GetDirCosU(), CandRecoHandle::GetDirCosV(), CandRecoHandle::GetVtxU(), CandRecoHandle::GetVtxV(), MSG, CandFitTrackHandle::SetChi2(), CandRecoHandle::SetDirCosU(), CandRecoHandle::SetDirCosV(), CandRecoHandle::SetDirCosZ(), CandTrackHandle::SetMomentum(), CandRecoHandle::SetVtxPlane(), CandRecoHandle::SetVtxT(), CandRecoHandle::SetVtxU(), CandRecoHandle::SetVtxV(), and CandRecoHandle::SetVtxZ(). Referenced by RunAlg(). 01632 {
01633 // write the fit to the screen and to the objects
01634
01635 // right now this doesnt always work because we fit for x and y and
01636 // take the best, while this always uses the last SolnMatrix
01637 // tested. we should use something like a BestSolnMatrix.
01638 /*
01639 MSG("FitTrackMS", Msg::kInfo) << "# of hits = " <<
01640 fNHits << endl;
01641 MSG("FitTrackMS", Msg::kInfo) << "x intercept = " <<
01642 fSolnMatrix(0,0) << endl;
01643 MSG("FitTrackMS", Msg::kInfo) << "x slope = " <<
01644 fSolnMatrix(1,0) << endl;
01645 MSG("FitTrackMS", Msg::kInfo) << "y intercept = " <<
01646 fSolnMatrix(0,1) << endl;
01647 MSG("FitTrackMS", Msg::kInfo) << "y slope = " <<
01648 fSolnMatrix(1,1) << endl;
01649 .q MSG("FitTrackMS", Msg::kInfo) << "chi squared = " <<
01650 ChiSquared << endl << endl;
01651 MSG("FitTrackMS", Msg::kInfo) << "tom's momentum = " <<
01652 p0*Munits::GeV << " GeV" << endl << endl;
01653 */
01654 fCfh->SetDirCosU(fSolnMatrix(1,0));
01655 fCfh->SetVtxU(fSolnMatrix(0,0));
01656 fCfh->SetDirCosV(fSolnMatrix(1,1));
01657 fCfh->SetVtxV(fSolnMatrix(0,1));
01658 fCfh->SetChi2(ChiSquared/fNHits);
01659 fCfh->SetDirCosZ(1.);
01660 fCfh->SetVtxZ(fZHits(0));
01661 fCfh->SetVtxT(0.);
01662 fCfh->SetVtxPlane(0);
01663 fCfh->SetMomentum(p0);
01664 fCfh->SetChi2(ChiSquared);
01665 // fCfh->SetEMCharge(fQ);
01666
01667 MSG("FitTrackMS", Msg::kDebug) << "reco p = " << p0 << endl;
01668
01669 // all this stuff writes TPolyLine3Ds to the fitTrackMS.root file so
01670 // you can see what the fits and tracks are looking like.
01671 TPolyLine3D plHits(fNHits);
01672 TPolyLine3D plFit(fNHits);
01673
01674 // plFit.SetPoint(0,fCfh.GetVtxU(),fCfh.GetVtxV(),fZHits(0));
01675
01676 Double_t x0, y0, mx, my;
01677
01678 x0 = fCfh->GetVtxU();
01679 y0 = fCfh->GetVtxV();
01680 mx = fCfh->GetDirCosU();
01681 my = fCfh->GetDirCosV();
01682
01683 for(Int_t i=0;i<fNHits;i++){
01684
01685 plHits.SetPoint(i,fXHits(i),fYHits(i),fZHits(i));
01686
01687 // plFit.SetPoint(i,x0-fDThetas(i,0)+mx*(fZHits(i)-fZHits(0)),
01688 // y0-fDThetas(i,1)+my*(fZHits(i)-fZHits(0)),fZHits(i));
01689 }
01690
01691
01692 // plFit.SetPoint(1,fCfh.GetVtxU()+(fZHits(fNHits-1)-fZHits(0))*fCfh.GetDirCosU(),
01693 // fCfh.GetVtxV()+(fZHits(fNHits-1)-fZHits(0))*fCfh.GetDirCosV(),
01694 // fZHits(fNHits-1));
01695
01696
01697 //rwh: push this into a switchable code block
01698 bool writeit = false;
01699 if (writeit) {
01700 MSG("FitTrackMS",Msg::kInfo)
01701 << "writing fitTrackMS.root file, "
01702 << " fNHits = " << fNHits << endl;
01703 TFile* f = new TFile("fitTrackMS.root","UPDATE");
01704 plHits.Write("hits");
01705 plFit.Write("fit");
01706 f->Close();
01707 MSG("FitTrackMS",Msg::kInfo)
01708 << "done writing fitTrackMS.root file." << endl;
01709 }
01710
01711 }
|
|
|
Definition at line 95 of file AlgFitTrackMS.h. Referenced by SetupAlg(). |
|
|
Definition at line 85 of file AlgFitTrackMS.h. Referenced by RunAlg(), and SetupAlg(). |
|
|
Definition at line 65 of file AlgFitTrackMS.h. Referenced by DetermineQ(), InitArrays(), InitFitHandle(), MakeStraightTrack(), RunAlg(), SetupAlg(), and WriteFit(). |
|
|
Definition at line 76 of file AlgFitTrackMS.h. Referenced by InitArrays(), and SetupAlg(). |
|
|
Definition at line 67 of file AlgFitTrackMS.h. Referenced by InitArrays(), and SetupAlg(). |
|
|
Definition at line 70 of file AlgFitTrackMS.h. Referenced by InitArrays(), RunAlg(), and SetupAlg(). |
|
|
Definition at line 86 of file AlgFitTrackMS.h. Referenced by RunAlg(), and SetupAlg(). |
|
|
Definition at line 93 of file AlgFitTrackMS.h. Referenced by SetupAlg(). |
|
|
Definition at line 72 of file AlgFitTrackMS.h. Referenced by DoFitAlg(), and SetupAlg(). |
|
|
Definition at line 88 of file AlgFitTrackMS.h. Referenced by SetupAlg(). |
|
|
Definition at line 92 of file AlgFitTrackMS.h. Referenced by SetupAlg(). |
|
|
Definition at line 90 of file AlgFitTrackMS.h. Referenced by DoFitAlg(), and SetupAlg(). |
|
|
Definition at line 89 of file AlgFitTrackMS.h. Referenced by SetupAlg(). |
|
|
Definition at line 91 of file AlgFitTrackMS.h. Referenced by SetupAlg(). |
|
|
Definition at line 98 of file AlgFitTrackMS.h. Referenced by DetermineQ(), FitTrack(), InitArrays(), InvertCovMatrix(), MakePPlanes(), MakeStraightTrack(), RunAlg(), and WriteFit(). |
|
|
Definition at line 83 of file AlgFitTrackMS.h. Referenced by RunAlg(), and SetupAlg(). |
|
|
Definition at line 82 of file AlgFitTrackMS.h. Referenced by RunAlg(), and SetupAlg(). |
|
|
Definition at line 84 of file AlgFitTrackMS.h. Referenced by RunAlg(), and SetupAlg(). |
|
|
Definition at line 99 of file AlgFitTrackMS.h. Referenced by InitArrays(), MakeCovarianceMatrix(), MakePPlanes(), and MakeStraightTrack(). |
|
|
Definition at line 74 of file AlgFitTrackMS.h. Referenced by FitTrack(), MakeCovarianceMatrix(), and SetupAlg(). |
|
|
Definition at line 109 of file AlgFitTrackMS.h. Referenced by InitArrays(), MakeCovarianceMatrix(), MakePPlanes(), and MakeStraightTrack(). |
|
|
Definition at line 73 of file AlgFitTrackMS.h. Referenced by SetupAlg(). |
|
|
Definition at line 69 of file AlgFitTrackMS.h. Referenced by DetermineQ(), MakeStraightTrack(), RunAlg(), and SetupAlg(). |
|
|
Definition at line 79 of file AlgFitTrackMS.h. Referenced by SetupAlg(). |
|
|
Definition at line 101 of file AlgFitTrackMS.h. Referenced by ChiSquared(), FitTrack(), SetupAlg(), and WriteFit(). |
|
|
Definition at line 78 of file AlgFitTrackMS.h. Referenced by GetSigmaMS(), InitArrays(), MakeCovarianceMatrix(), MakePPlanes(), MakeStraightTrack(), and SetupAlg(). |
|
|
Definition at line 105 of file AlgFitTrackMS.h. Referenced by ChiSquared(), InitArrays(), MakeSolnMatrices(), and MakeStraightTrack(). |
|
|
Definition at line 106 of file AlgFitTrackMS.h. Referenced by ChiSquared(), InitArrays(), MakeSolnMatrices(), and MakeStraightTrack(). |
|
|
Definition at line 77 of file AlgFitTrackMS.h. Referenced by InitArrays(), and SetupAlg(). |
|
|
Definition at line 96 of file AlgFitTrackMS.h. Referenced by SetupAlg(). |
|
|
Definition at line 80 of file AlgFitTrackMS.h. Referenced by InitArrays(), and SetupAlg(). |
|
|
Definition at line 103 of file AlgFitTrackMS.h. Referenced by DetermineQ(), InitArrays(), MakePPlanes(), MakeStraightTrack(), and WriteFit(). |
|
|
Definition at line 75 of file AlgFitTrackMS.h. Referenced by GetSigmaMS(), and SetupAlg(). |
|
|
Definition at line 104 of file AlgFitTrackMS.h. Referenced by DetermineQ(), InitArrays(), MakePPlanes(), MakeStraightTrack(), and WriteFit(). |
|
|
Definition at line 107 of file AlgFitTrackMS.h. Referenced by ChiSquared(), DetermineQ(), InitArrays(), MakeCovarianceMatrix(), MakePPlanes(), MakeSolnMatrices(), MakeStraightTrack(), and WriteFit(). |
|
|
Definition at line 108 of file AlgFitTrackMS.h. Referenced by InitArrays(), MakeCovarianceMatrix(), MakePPlanes(), and MakeStraightTrack(). |
1.3.9.1