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