Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

DataFT.cxx

Go to the documentation of this file.
00001 /***************************************************************************
00002                         DataFT.cxx  -  description
00003   Class encapsulates the track measurement - coordinates measured in each
00004   plane; used by the least squares track fitter.
00005                              -------------------
00006     begin                : Thu Jun 26 2003
00007     author               : Sergei Avvakumov
00008     email                : avva@dunk
00009  ***************************************************************************/
00010 #include <vector>
00011 #include <algorithm>
00012 #include <cassert>
00013 #include <cmath>
00014 
00015 #include "TVectorD.h"
00016 #include "TGraph.h"
00017 #include "TSpline.h"
00018 
00019 #include "DataUtil/CDL2STL.h"
00020 #include "MessageService/MsgService.h"
00021 #include "MessageService/MsgFormat.h"
00022 #include "CandTrackSR/TrackClusterSR.h"
00023 #include "RecoBase/CandStripHandle.h"
00024 #include "RecoBase/CandTrackHandle.h"
00025 #include "Plex/PlexPlaneId.h"
00026 #include "Swimmer/SwimSwimmer.h"
00027 #include "Swimmer/SwimParticle.h"
00028 #include "Swimmer/SwimZCondition.h"
00029 
00030 #include "GeoSwimmer/GeoSwimmer.h"
00031 #include "GeoSwimmer/GeoSwimParticle.h"
00032 #include "GeoSwimmer/GeoSwimZCondition.h"
00033 
00034 #include "CandFitTrackSA/ConstFT.h"
00035 #include "CandFitTrackSA/DataFT.h"
00036 #include "CandFitTrackSA/TracerSA.h"
00037 #include "CandFitTrackSA/TrackContext.h"
00038 
00039 using namespace ConstFT;
00040 
00041 CVSID("$Id: DataFT.cxx,v 1.20 2008/03/04 00:42:07 ishi Exp $");
00042 
00046 // DataFT::DataFT() :
00047 //     fNPlanesUsed(0), fEMCharge(0), fDir(0),
00048 //     fInitialTrack(NTrackParams), fZVtx(0.),
00049 //     fPlanes(NPlanesMax)
00050 // {
00051 //     TracerSA trace("DataFT::DataFT()");
00052 // }
00053 
00057 DataFT::DataFT(const AlgConfig& ac, const TrackContext& tc) :
00058     fNPlanesUsed(tc.GetNPlanes()), fDir(tc.GetDir()),
00059     fInitialTrack(NTrackParams), fZVtx(0.),
00060     fPlanes(tc.GetNPlanes()),
00061     fUHitUse(tc.GetNPlanes()), fVHitUse(tc.GetNPlanes()),
00062     fGeo(tc), fMinStripCharge(kMinStripCharge),
00063     fSetLPos(kTRUE), fNHitsInViewMin(4),
00064     fUseGeoSwimmer(false)
00065 {
00066     TracerSA trace("DataFT::DataFT(const AlgConfig& , const TrackContext& )");
00067 
00068     Config(ac);
00069 
00070     Bool_t status;
00071 
00072     status = Init(tc);
00073     assert(status && "DataFT::Init(const TrackContext&) failed!");
00074 
00075     status = Fill(tc);
00076     assert(status && "DataFT::Fill(const TrackContext&) failed!");
00077 
00078     if ( GetNUHits() >= fNHitsInViewMin &&
00079             GetNVHits() >= fNHitsInViewMin ) {
00080         status = FillLinWithSpline();
00081         assert(status && "DataFT::FillLinWithSpline() failed!");
00082     }
00083     
00084     PrintData();
00085 }
00086 
00087 
00091 DataFT::~DataFT()
00092 {
00093     TracerSA trace("DataFT::~DataFT()");
00094 }
00095 
00096 
00100 void DataFT::Reset()
00101 {
00102     TracerSA trace("DataFT::Reset()");
00103     fNPlanesUsed = 0;
00104     fDir = 0;
00105     fInitialTrack.Zero();
00106     fZVtx = 0.;
00107     fPlanes.clear();
00108 }
00109 
00110 
00114 void DataFT::Config(const AlgConfig& ac)
00115 {
00116     TracerSA trace("DataFT::Config(const AlgConfig&)");
00117 
00118     if ( ac.KeyExists("NHitsInViewMin") ) {
00119         fNHitsInViewMin = ac.GetInt("NHitsInViewMin");
00120     }
00121 
00122     if ( ac.KeyExists("MinStripCharge") ) {
00123         fMinStripCharge = ac.GetDouble("MinStripCharge");
00124     }
00125 
00126     if ( ac.KeyExists("SetLPos") ) {
00127         fSetLPos = (Bool_t) ac.GetInt("SetLPos");
00128     }
00129 
00130     if ( ac.KeyExists("UseGeoSwimmer") ) {
00131       fUseGeoSwimmer = ac.GetInt("UseGeoSwimmer");
00132     }
00133 
00134 }
00135 
00136 
00140 Bool_t DataFT::Init(const TrackContext& tc)
00141 {
00142     TracerSA trace("DataFT::Init(const TrackContext& )");
00143 
00144     Int_t begin = tc.GetBegPlane();
00145     Int_t end   = tc.GetEndPlane();
00146 
00147     //
00148     fNPlanesUsed = abs(begin - end) + 1;
00149     fDir = end > begin ? 1 : -1;
00150     fInitialTrack.Zero();
00151 
00152     // fill plane information - Z positions, thickness, X0
00153     fPlanes.resize(fNPlanesUsed);
00154     Int_t plane = begin;
00155     VldContext vldc = tc.GetVldContext();
00156 
00157     if(fUseGeoSwimmer) {
00158       GeoSwimmer::Instance()->Initialize(vldc);      
00159     }
00160 
00161     for (PlaneDataItr it = fPlanes.begin(); it != fPlanes.end(); ++it) {
00162         PlexPlaneId planeid = PlexPlaneId(vldc.GetDetector(), plane);
00163         it->plane = planeid;
00164         it->z = fGeo.GetZ(planeid);
00165         it->dz = fGeo.GetdZSteel(planeid);
00166         it->x0 = fGeo.GetX0(planeid);
00167         plane += fDir;
00168     }
00169 
00170     // set vertex z position - either in the middle of 
00171     // the "previous" steel plane or just 0.03m back
00172     // from the begin plane
00173     fZVtx = fGeo.GetZVtx(PlexPlaneId(vldc.GetDetector(), begin), fDir);
00174     
00175     return kTRUE;
00176 }
00177 
00178 
00179 // following methods used these typedefs (defined in .h)
00180 // typedef const CandStripHandle CSH;
00181 // typedef CSH* CSHPtr;
00182 // typedef std::vector<CSHPtr>::iterator CSHItr;
00183 // typedef std::multimap<Int_t, CSHPtr> StripMap;
00184 // typedef StripMap::iterator StripMapItr;
00185 
00189 Bool_t DataFT::Fill(const TrackContext& tc)
00190 {
00191   TracerSA trace("DataFT::Fill(const TrackContext&)");
00192 
00193   // convert daughter list to STL vector
00194   //vector<CSHPtr> stripList(DataUtil::CDL2STLvector<CSH>(*tc.GetTrackHandle()));
00195 
00196   Reco::StripVec_t stripList = tc.GetStripVec();
00197   
00198   // sort using ByPlane functor    
00199   sort(stripList.begin(), stripList.end(), Reco::ByPlane());
00200   // reverse order if track direction against Z axis
00201   if (fDir<0) reverse(stripList.begin(), stripList.end());
00202 
00203   // strip _multi_map - can hold more than one strip per plane 
00204   StripMap stripMap;
00205 
00206   // Fill stripMap
00207   for ( Reco::StripIter_t it = stripList.begin();  it != stripList.end(); ++it) {
00208 
00209       MSG("FitTrackSA", Msg::kVerbose)
00210       << "P " << (*it)->GetPlane()
00211       << ": Charge=" << (*it)->GetCharge()
00212       << "; Strip=" << (*it)->GetStrip() << "\n";
00213 
00214       // check if strip is not demux vetoed and charge is not too small
00215       if ( (*it)->GetDemuxVetoFlag() ) continue;
00216       if ( (*it)->GetCharge() < fMinStripCharge ) continue;
00217 
00218       // And add it to the multimap
00219       Int_t plane = (*it)->GetPlane();
00220       stripMap.insert(pair<Int_t, Reco::Strip_t> (plane, *it));
00221   }
00222 
00223   // Loop over planes, use only planes with one or two (consecutive) hit strips
00224   // ignore planes with more than two hit strips - let shower code deal with them
00225   Int_t begplane = GetBegPlaneId().GetPlane();
00226   Int_t nplanes  = GetNPlanes();
00227   for (Int_t i = 0; i < nplanes; ++i) {
00228       Int_t plane = begplane + i*fDir;
00229       switch ( stripMap.count(plane) ) {
00230       case 1:
00231           {
00232           StripMapItr itr = stripMap.find(plane);
00233           OneStripPlane(i, itr, tc.GetTrackHandle());
00234           }
00235           break;
00236 
00237       case 2:
00238           {
00239           StripMapItr itLower = stripMap.lower_bound(plane);
00240           StripMapItr itUpper = stripMap.upper_bound(plane);
00241           TwoStripPlane(i, itLower, itUpper, tc.GetTrackHandle());
00242           }
00243           break;
00244 
00245       default:
00246           // do nothing
00247           assert(1);
00248       }
00249   }
00250   return kTRUE;
00251 }
00252 
00253 
00257 void DataFT::SetHitCoords(  Count_t planeIndex,
00258                             PlaneData::Data_t tpos,
00259                             PlaneData::Data_t error )
00260 {
00261     TracerSA trace("DataFT::SetHitCoords(Int_t, PlaneData::Data_t, PlaneData::Data_t)");
00262     PlexPlaneId id = GetPlaneId(planeIndex);
00263     if ( id.GetPlaneView() == PlaneView::kU ) {
00264         SetUHit(planeIndex);
00265         SetUHitUse(planeIndex);
00266         SetU(planeIndex, tpos);
00267         SetSigmaU(planeIndex, error);
00268 
00269         UnsetVHit(planeIndex);
00270         UnsetVHitUse(planeIndex);
00271         SetV(planeIndex, 0.0);
00272         SetSigmaV(planeIndex, 0.0);
00273     } else if ( id.GetPlaneView() == PlaneView::kV ) {
00274         SetVHit(planeIndex);
00275         SetVHitUse(planeIndex);
00276         SetV(planeIndex, tpos);
00277         SetSigmaV(planeIndex, error);
00278 
00279         UnsetUHit(planeIndex);
00280         UnsetUHitUse(planeIndex);
00281         SetU(planeIndex, 0.0);
00282         SetSigmaU(planeIndex, 0.0);
00283     }
00284 }
00285 
00289 void DataFT::OneStripPlane(Count_t planeIndex, StripMapItr it,
00290                                                     const CandTrackHandle* cth)
00291 {
00292     TracerSA trace("DataFT::OneStripPlane");
00293     PlaneData::Data_t tpos(0.);
00294     if ( fSetLPos ) {
00295         tpos = fGeo.GetRotationCorrectedTPos(it->second, cth);
00296     } else {
00297         tpos = it->second->GetTPos();
00298     }
00299 
00300     PlaneData::Data_t tposrms = kOneStripError;
00301 
00302     SetHitCoords(planeIndex, tpos, tposrms);
00303 }
00304 
00305 
00309 void DataFT::TwoStripPlane(Count_t planeIndex,
00310                             StripMapItr lower, StripMapItr upper,
00311                             const CandTrackHandle* cth)
00312 {
00313     TracerSA trace("DataFT::TwoStripPlane");
00314 
00315   // running sums
00316   PlaneData::Data_t chargesum(0.);
00317   PlaneData::Data_t tpossum(0.);
00318   PlaneData::Data_t tposrmssum(0.);
00319   Int_t nstrip(0);
00320 
00321   // loop over strips
00322   for (StripMapItr it = lower; it != upper; ++it) {
00323     // cache strip charge, tpos
00324     PlaneData::Data_t charge = it->second->GetCharge();
00325     // make sure strips with negative charge have been
00326     // cleaned
00327     assert( charge > 0. && "Strip charge < 0.!!!!");
00328 
00329     PlaneData::Data_t tpos(0.);
00330     if ( fSetLPos ) {
00331         tpos = fGeo.GetRotationCorrectedTPos(it->second, cth);
00332     } else {
00333         tpos = it->second->GetTPos();
00334     }
00335 
00336     // increment running sums
00337     chargesum  += charge;
00338     tpossum    += tpos;
00339     tposrmssum += tpos*tpos;
00340     ++nstrip;
00341   }
00342 
00343   // calculate charge weighted position, rms
00344   // of the hit
00345   PlaneData::Data_t tpos = tpossum/nstrip;
00346 
00347   // initialize rms to that of a songle strip measurement
00348   PlaneData::Data_t tposrms = kOneStripError;
00349 
00350   PlaneData::Data_t tposrms2 = tposrmssum/nstrip - tpos*tpos;
00351   // ignore zero values, they only happen if the same strip is used twice
00352   // (this happens in cedar mc)
00353   if (tposrms2 > 0.) {
00354     tposrms = sqrt(tposrms2);
00355   }
00356 
00357   SetHitCoords(planeIndex, tpos, tposrms);
00358 }
00359 
00360 
00364 void DataFT::SetNPlanesUsed(Count_t n)
00365 {
00366     TracerSA trace("DataFT::SetNPlanesUsed");
00367     assert( n <= GetNPlanes() && "# of used planes must not be greater "
00368                                 "than the total # of planes!");
00369     fNPlanesUsed = n;
00370 }
00371 
00372 
00376 Int_t DataFT::GetEMCharge() const
00377 {
00378     return (Int_t) TMath::Sign(1., fInitialTrack(kQoverP));
00379 }
00380 
00381 
00385 PlaneData::Data_t
00386 DataFT::GetUMean() const
00387 {
00388     if ( fNPlanesUsed > 0 ) {
00389         return (GetUf(0) + GetUf(fNPlanesUsed-1))/2.;
00390     } else {
00391         return GetUf(0);
00392     }
00393 }
00394 
00395 
00399 PlaneData::Data_t
00400 DataFT::GetVMean() const
00401 {
00402     if ( fNPlanesUsed > 0 ) {
00403         return (GetVf(0) + GetVf(fNPlanesUsed-1))/2.;
00404     } else {
00405         return GetVf(0);
00406     }
00407 }
00408 
00409 
00413 DataFT::Count_t DataFT::GetNUPlanes() const
00414 {
00415     TracerSA trace("DataFT::GetNUPlanes");
00416     int nplanes=0;
00417 
00418     PlaneDataCItr beg = fPlanes.begin();
00419     PlaneDataCItr end = fPlanes.end();
00420 
00421     for (PlaneDataCItr it = beg; it != end; ++it) {
00422         if ( it->plane.GetPlaneView() == PlaneView::kU ) ++nplanes;
00423     }
00424     return nplanes;
00425 }
00426 
00427 
00431 DataFT::Count_t DataFT::GetNVPlanes() const
00432 {
00433     TracerSA trace("DataFT::GetNVPlanes");
00434     int nplanes=0;
00435 
00436     PlaneDataCItr beg = fPlanes.begin();
00437     PlaneDataCItr end = fPlanes.end();
00438 
00439     for (PlaneDataCItr it = beg; it != end; ++it) {
00440         if ( it->plane.GetPlaneView() == PlaneView::kV ) ++nplanes;
00441     }
00442     return nplanes;
00443 }
00444 
00445 
00449 DataFT::Count_t DataFT::GetNUHits() const
00450 {
00451     TracerSA trace("DataFT::GetNUHits");
00452     int nhits=0;
00453     int size = GetNPlanes();
00454 
00455     for (int i = 0; i < size; ++i) {
00456         if ( IsHitU(i) ) ++nhits;
00457     }
00458     return nhits;
00459 }
00460 
00461 
00465 DataFT::Count_t DataFT::GetNVHits() const
00466 {
00467     TracerSA trace("DataFT::GetNVHits");
00468     int nhits=0;
00469     int size = GetNPlanes();
00470 
00471     for (int i = 0; i < size; ++i) {
00472         if ( IsHitV(i) ) ++nhits;
00473     }
00474     return nhits;
00475 }
00476 
00477 
00481 DataFT::Count_t DataFT::GetNHits() const
00482 {
00483     TracerSA trace("DataFT::GetNHits");
00484     int nhits=0;
00485     int size = GetNPlanes();
00486 
00487     for (int i = 0; i < size; ++i) {
00488         if ( IsHitU(i) ) ++nhits;
00489         if ( IsHitV(i) ) ++nhits;
00490     }
00491     return nhits;
00492 }
00493 
00494 
00498 DataFT::Count_t DataFT::GetNUHitsUsed() const
00499 {
00500     TracerSA trace("DataFT::GetNUHitsUsed");
00501     int nhits=0;
00502     int size = GetNPlanesUsed();
00503     for (int i = 0; i < size; ++i) {
00504         if ( UHitUse(i) ) ++nhits;
00505     }
00506     return nhits;
00507 }
00508 
00509 
00513 DataFT::Count_t DataFT::GetNVHitsUsed() const
00514 {
00515     TracerSA trace("DataFT::GetNVHitsUsed");
00516     int nhits=0;
00517     int size = GetNPlanesUsed();
00518     for (int i = 0; i < size; ++i) {
00519         if ( VHitUse(i) ) ++nhits;
00520     }
00521     return nhits;
00522 }
00523 
00527 DataFT::Count_t DataFT::GetNPlanesMin(Count_t nhitsperview) const
00528 {
00529     TracerSA trace("DataFT::GetNPlanesMin");
00530     int nplanesmin=0;
00531     int nuhits=0;
00532     int nvhits=0;
00533 
00534     int size = GetNPlanes();
00535     for (int i = 0; i != size; ++i) {
00536         ++nplanesmin;
00537         if ( UHitUse(i) ) ++nuhits;
00538         if ( VHitUse(i) ) ++nvhits;
00539 
00540         if ( nuhits >= nhitsperview && nvhits >= nhitsperview )
00541                                                         return nplanesmin;
00542     }
00543 
00544     assert(0 && "Not enough planes in view!");
00545     return 0;
00546 }
00547 
00548 
00552 DataFT::Count_t DataFT::GetNHitsUsed() const
00553 {
00554     TracerSA trace("DataFT::GetNHitsUsed");
00555     int nhits=0;
00556     int size = GetNPlanesUsed();
00557     for (int i = 0; i < size; ++i) {
00558         if ( UHitUse(i) ) ++nhits;
00559         if ( VHitUse(i) ) ++nhits;
00560     }
00561     return nhits;
00562 }
00563 
00564 
00568 DataFT::Count_t DataFT::GetBegHit() const
00569 {
00570     TracerSA trace("DataFT::GetBegHit");
00571     int size = GetNPlanesUsed();
00572     for (int i = 0; i < size; ++i) {
00573         if ( IsHitU(i) || IsHitV(i) ) return GetPlane(i);
00574     }
00575     return 0;
00576 }
00577 
00578 
00582 DataFT::Count_t  DataFT::GetEndHit() const
00583 {
00584     TracerSA trace("DataFT::GetEndHit");
00585     int size = GetNPlanesUsed();
00586     for (int i = 0; i < size; ++i) {
00587         if ( IsHitU(size-1-i) || IsHitV(size-1-i) ) 
00588             return GetPlane(size-1-i);
00589     }
00590     return 0;
00591 }
00592 
00593 
00594 
00598 DataFT::Count_t DataFT::GetBegHitUsed() const
00599 {
00600     TracerSA trace("DataFT::GetBegHit");
00601     int size = GetNPlanesUsed();
00602     for (int i = 0; i < size; ++i) {
00603         if ( UHitUse(i) || VHitUse(i) ) return GetPlane(i);
00604     }
00605     return 0;
00606 }
00607 
00608 
00612 DataFT::Count_t DataFT::GetEndHitUsed() const
00613 {
00614     TracerSA trace("DataFT::GetEndHit");
00615     int size = GetNPlanesUsed();
00616     for (int i = 0; i < size; ++i) {
00617         if ( UHitUse(size-1-i) || VHitUse(size-1-i) ) 
00618             return GetPlane(size-1-i);
00619     }
00620     return 0;
00621 }
00622 
00623 
00624 
00628 void DataFT::PrintData() const
00629 {
00630     TracerSA trace("DataFT::PrintData");
00631     MsgStream *mftsa = &MSGSTREAM("FitTrackSA", Msg::kVerbose);
00632     (*mftsa) << "Data:\n";
00633     MsgFormat ffmt("%7.3f");
00634     
00635     for (PlaneDataCItr it = fPlanes.begin(); it != fPlanes.end(); ++it) {
00636         (*mftsa) << it->plane 
00637         << ": U=" << ffmt(it->u) << "; EU=" << ffmt(it->eu) 
00638         << "; UL=" << ffmt(it->ulin) << "; dU/dZL=" << ffmt(it->dudzlin) 
00639         << "; V=" << ffmt(it->v) << "; EV=" << ffmt(it->ev) 
00640         << "; VL=" << ffmt(it->vlin) << "; dV/dZL=" << ffmt(it->dvdzlin)
00641         << "; Z=" << ffmt(it->z) << "; X0="   << ffmt(it->x0) << std::endl;
00642     }
00643     return;
00644 }
00645 
00646 
00650 void DataFT::FillVectorRes(TMatrixD& vC, PlaneData::Data_t cdata, PlaneData::Data_t ctrack) const
00651 {
00652     TracerSA trace("DataFT::FillVectorRes");
00653     vC.ResizeTo(GetNHitsUsed(),1);
00654     Int_t ihits = 0;
00655     for (Int_t i=0; i<GetNPlanesUsed(); ++i) {
00656         if ( UHitUse(i) ) {
00657             vC(ihits,0) = cdata*GetU(i) + ctrack*GetUf(i);
00658             ++ihits;
00659         }
00660     }
00661     for (Int_t i=0; i<GetNPlanesUsed(); ++i) {
00662         if ( VHitUse(i) ) {
00663             vC(ihits,0) = cdata*GetV(i) + ctrack*GetVf(i);
00664             ++ihits;
00665         }
00666     }
00667     return;
00668 }
00669 
00670 
00674 void DataFT::FillVectorC(TMatrixD& vC) const
00675 {
00676     TracerSA trace("DataFT::FillVectorC");
00677     FillVectorRes(vC, 1., 0.);
00678 }
00679 
00680 
00684 void DataFT::FillVectorCF(TMatrixD& vC) const
00685 {
00686     TracerSA trace("DataFT::FillVectorCF");
00687     FillVectorRes(vC, 0., 1.);
00688 }
00689 
00690 
00694 Bool_t DataFT::FillUArrays(Double_t zu[], Double_t u[], Int_t n)
00695 {
00696     TracerSA trace("DataFT::FillUArrays(Double_t zu[], Double_t u[],Int_t)");
00697     
00698     Int_t index = 0;    
00699     Count_t size = GetNPlanes();
00700     for (Count_t i = 0; i < size; ++i) {
00701         if ( IsHitU(i) ) {
00702             assert( index < n && "Array bound check failed!");
00703             zu[index] = (Double_t) GetZ(i);
00704             u[index] = (Double_t) GetU(i);
00705             ++index;
00706         }
00707     }
00708     
00709     MsgStream *mftsa = &MSGSTREAM("FitTrackSA", Msg::kVerbose);
00710     (*mftsa) << "Filling UArrays: " << "\n";
00711     MsgFormat ffmt("%7.3f");
00712     // fill spline approximation of the track
00713     for (Count_t i = 0; i<n; ++i) {
00714         (*mftsa) << "z=" << ffmt(zu[i])
00715                  << "; u=" << ffmt(u[i]) << std::endl;
00716     }
00717     return kTRUE;
00718 }
00719 
00720 
00724 Bool_t DataFT::FillVArrays(Double_t zv[], Double_t v[], Int_t n)
00725 {
00726     TracerSA trace("DataFT::FillVArrays(Double_t zv[], Double_t v[],Int_t)");
00727     
00728     Int_t index = 0;
00729     int size = GetNPlanes();
00730     for (int i = 0; i < size; ++i) {
00731         if ( IsHitV(i) ) {
00732             assert( index < n && "Array bound check failed!");
00733             zv[index] = (Double_t) GetZ(i);
00734             v[index] = (Double_t) GetV(i);
00735             ++index;
00736         }
00737     }    
00738     
00739     MsgStream *mftsa = &MSGSTREAM("FitTrackSA", Msg::kVerbose);
00740     (*mftsa) << "Filling VArrays: " << "\n";
00741     MsgFormat ffmt("%7.3f");
00742     // fill spline approximation of the track
00743     for (Count_t i = 0; i<n; ++i) {
00744         (*mftsa) << "z=" << ffmt(zv[i]) << "; v=" << ffmt(v[i]) << std::endl;
00745     }
00746     return kTRUE;
00747 }
00748 
00749 
00753 Bool_t DataFT::FillLinWithSpline()
00754 {
00755     TracerSA trace("DataFT::FillLinWithSpline()");
00756 
00757     MsgStream *mftsa = &MSGSTREAM("FitTrackSA", Msg::kVerbose);
00758 
00759     const Int_t NU = GetNUHits();
00760     std::vector<Double_t> zu(NU);
00761     std::vector<Double_t> u(NU);
00762     FillUArrays(&zu[0], &u[0], NU);
00763     (*mftsa) << "NU = " << NU << std::endl;
00764     TSpline5 splineU("U", &zu[0], &u[0], NU);
00765 
00766     const Int_t NV = GetNVHits();
00767     std::vector<Double_t> zv(NV);
00768     std::vector<Double_t> v(NV);
00769     FillVArrays(&zv[0], &v[0], NV);
00770     (*mftsa) << "NV = " << NV << std::endl;
00771     TSpline5 splineV("V", &zv[0], &v[0], NV);
00772 
00773     (*mftsa) << "Filling from TSpline: " << "\n";
00774     MsgFormat ffmt("%7.3f");
00775     // fill spline approximation of the track
00776     for (Count_t i = 0; i<GetNPlanes(); ++i) {
00777         Double_t z = (Double_t) GetZ(i);
00778 
00779         (*mftsa) << "z=" << ffmt(z)
00780             << "; US=" << ffmt(splineU.Eval(z))
00781             << "; dU/dZS=" << ffmt(splineU.Derivative(z))
00782             << "; VS=" << ffmt(splineV.Eval(z))
00783             << "; dV/dZS=" << ffmt(splineV.Derivative(z))
00784             << std::endl;
00785 
00786         SetUlin(i, (PlaneData::Data_t) splineU.Eval(z));
00787         SetDudzlin(i, (PlaneData::Data_t) splineU.Derivative(z));
00788         SetVlin(i, (PlaneData::Data_t) splineV.Eval(z));
00789         SetDvdzlin(i, (PlaneData::Data_t) splineV.Derivative(z));
00790     }
00791     return kTRUE;
00792 }
00793 
00794 
00798 DataFT::Count_t DataFT::GetNPlanesPCut(PlaneData::Data_t pcut) const
00799 {
00800     TracerSA trace("DataFT::GetNPlanesPCut");
00801     // return number of planes with p>pcut
00802     PlaneData::Data_t invpcut = 1./pcut;
00803     
00804     //CRItr itlastused = fPlanes.rend()-fNPlanesUsed;
00805     for (PlaneDataCRItr it = fPlanes.rend()-fNPlanesUsed; 
00806                                                 it != fPlanes.rend(); ++it) {
00807         if ( fabs(it->invp) < invpcut ) return fPlanes.rend()-it; 
00808     }
00809     
00810     return 0;
00811 }
00812 
00813 
00817 DataFT::Count_t DataFT::SwimAsSwimmer(Count_t nplanesuse, SwimSwimmer& swimmer)
00818 {
00819     TracerSA trace("DataFT::SwimAsSwimmer");
00820     
00821     MSG("FitTrackSA",Msg::kVerbose) << "Request to swim " 
00822                                     << nplanesuse << " planes.\n"; 
00823 
00824     // Swim track starting from the first plane, initial values 
00825     // from fInitialTrack. Swim through nplanesuse planes.
00826     
00827     // Check if number of planes to swim is reasonable
00828     if ( nplanesuse<1 ) {
00829         MSG("FitTrackSA",Msg::kWarning) 
00830             << "Request to swim less than one plane. Doing Nothing\n";
00831         return 0;
00832     } else if ( nplanesuse > GetNPlanes() ) {
00833         MSG("FitTrackSA",Msg::kWarning) 
00834         << "Request to swim more planes than we have.\n";
00835         nplanesuse = GetNPlanes();
00836     }
00837 
00838     // Initialize the swim particle from initial values of parameters
00839     
00840     // need these to get return values from xy2uv, uv2xy functions
00841     double x=0.;
00842     double y=0.;
00843     double u=0.;
00844     double v=0.;
00845     
00846     // convert track position (u, v) -> (x, y)
00847     fGeo.uv2xy(fInitialTrack(kU), fInitialTrack(kV), x, y);
00848     TVector3 position(x, y, fZVtx);
00849     
00850     // convert track direction
00851     PlaneData::Data_t pz, invpz;
00852     invpz = sqrt(1. + pow(fInitialTrack(kdUdZ),2) +
00853                       pow(fInitialTrack(kdVdZ),2)) * 
00854             TMath::Abs(fInitialTrack(kQoverP));
00855             
00856     if ( invpz < TinyNumber ) {
00857         MSG("FitTrackSA",Msg::kDebug) 
00858             << "1./Pz=" <<invpz<<" too small => replace with TinyNumber\n" ;
00859         invpz = TinyNumber;
00860     }
00861     
00862     pz = GetZdir()/invpz;
00863     fGeo.uv2xy(fInitialTrack(kdUdZ), fInitialTrack(kdVdZ), x, y);
00864     TVector3 momentum(pz*x, pz*y, pz);
00865 
00866     // create the swim particle
00867     SwimParticle muon(position,momentum);
00868     muon.SetCharge(GetEMCharge());
00869 
00870     int nplanesused = 0; // reset to 0
00871     MsgStream *mftsa = &MSGSTREAM("FitTrackSA", Msg::kVerbose);
00872     (*mftsa) << "Swimming track:\n";
00873     MsgFormat ffmt("%7.3f");
00874     // Loop over planes
00875     for (PlaneDataItr it = fPlanes.begin(); 
00876                                         it != fPlanes.begin()+nplanesuse; ++it) {
00877         // Swim condition -> to the current plane
00878         SwimZCondition zc(it->z);
00879 
00880         Bool_t status; // Swimmer status
00881 
00882         if(fUseGeoSwimmer) {
00883           status = GeoSwimmer::Instance()->SwimForward(muon,it->z);
00884         } else {
00885           status = swimmer.SwimForward(muon,zc);
00886         }
00887 
00888         if ( status ) {
00889  
00890             fGeo.xy2uv(muon.GetPosition().X(), muon.GetPosition().Y(), u, v);
00891             it->uf = u;
00892             it->vf = v;
00893             
00894             fGeo.xy2uv(muon.GetDirection().X(), muon.GetDirection().Y(), u, v);
00895             it->dudz = u/muon.GetDirection().Z();
00896             it->dvdz = v/muon.GetDirection().Z();
00897             
00898             it->invp = muon.GetCharge()/muon.GetMomentumModulus();
00899             it->cos = pow(1.+pow(it->dudz,2)+pow(it->dvdz,2), -0.5);
00900             
00901             it->s = muon.GetS();
00902             it->r = muon.GetRange();
00903             
00904                 
00905             ++nplanesused;
00906             
00907             // swim succeded -> fill track parameters for the next plane
00908             (*mftsa) 
00909                 << it->plane << ": z = " << ffmt(it->z) 
00910                 << "; u = " << ffmt(it->uf) << "; v = " << ffmt(it->vf) 
00911                 << "; dudz = " << ffmt(it->dudz)<<"; dvdz = " << ffmt(it->dvdz)
00912                 << "; invp = " << ffmt(it->invp)<<"; cos = " << ffmt(it->cos)
00913                 << "; s = " << ffmt(it->s) << "; r = " << ffmt(it->r) << "\n";
00914         } else {
00915             // swim failed -> print info and break out of the loop
00916             MSG("FitTrackSA",Msg::kDebug) 
00917                 << "Swim failed at " << it->plane 
00918                 << ", z = " << it->z << "\n";
00919             DumpTrack();
00920             // SetNPlanesUsed(it - fPlanes.begin());
00921             SetNPlanesUsed(nplanesused);
00922             return nplanesused;
00923         }
00924     }
00925     
00926     SetNPlanesUsed(nplanesused);
00927     return nplanesused;
00928 }
00929 
00930 
00934 DataFT::Count_t DataFT::SwimAsSwimmer(SwimSwimmer& swimmer)
00935 {
00936     return SwimAsSwimmer(GetNPlanes(), swimmer);
00937 }
00938 
00939 
00943 PlaneData::Data_t
00944 DataFT::ThetaMCS(Count_t i) const
00945 {
00946     // Calculate MCS angle in the i-th plane
00947     return Theta0_P1*sqrt(GetX0(i)/GetCos(i))*
00948             (1.+Theta0_P2*log(GetX0(i)/GetCos(i)))*GetInvP(i);
00949 }
00950 
00951 
00955 PlaneData::Data_t
00956 DataFT::T(Count_t i, Count_t n) const
00957 {
00958     // Calculate T(i,n) - for the covarince matrix
00959     //   return ( (n-i)*dz + d )/fCos(i);
00960     return  TMath::Abs(GetZ(n)-GetZ(i)) ;
00961 }
00962 
00963 
00967 void DataFT::DumpTrack() const
00968 {
00969     TracerSA trace("DataFT::DumpTrack");
00970     // Print out track (for debugging)
00971     if ( GetNPlanesUsed()>0 ) {
00972         MsgFormat ffmt("%7.3f");
00973         MsgStream *mftsa = &MSGSTREAM("FitTrackSA", Msg::kVerbose);
00974         (*mftsa) << "Generated track:\n";
00975         for (Int_t i = 0; i<GetNPlanesUsed(); i++) {
00976             (*mftsa)
00977                 << GetPlane(i) <<  ": u=" << ffmt(GetUf(i))
00978                 << "; du/dz=" << ffmt(GetDudz(i)) <<  "; v=" << ffmt(GetVf(i))
00979                 << "; dv/dz=" << ffmt(GetDvdz(i)) 
00980                 << "; p=" <<ffmt(1./TMath::Max(TinyNumber,(Double_t)GetInvP(i)))
00981                 << "; z=" << ffmt(GetZ(i)) <<  "\n";
00982         }
00983     } else {
00984         MSG("FitTrackSA",Msg::kVerbose) << "No track generated yet!\n";
00985     }
00986 
00987 }
00988 
00989 
00993 void DataFT::PrintMomenta() const
00994 {
00995     TracerSA trace("DataFT::PrintMomenta");
00996     MsgFormat ffmt("%7.3f");
00997     MsgStream *mftsa = &MSGSTREAM("FitTrackSA", Msg::kVerbose);
00998     (*mftsa) << "Generated track:\n";
00999     for (Int_t i = 0; i<GetNPlanesUsed(); i++) {
01000         (*mftsa) << GetPlane(i) 
01001             << ": p=" << ffmt(1./GetInvP(i)) <<  "\n";
01002     }
01003 
01004 }
01005 
01006 
01010 void DataFT::SetInitial(const TVectorD& inittrack)
01011 {
01012     TracerSA trace("DataFT::SetInitial");
01013     //
01014     fInitialTrack = inittrack;
01015     return;
01016 }
01017 
01021 DataFT::Count_t DataFT::SetInitial(const TVectorD& inittrack, Count_t nplanesuse,
01022                                                     SwimSwimmer& swimmer)
01023 {
01024     TracerSA trace("DataFT::SetInitial(const TVectorD&,Int_t,SwimSwimmer&)");
01025     //
01026     fInitialTrack = inittrack;
01027     
01028     return SwimAsSwimmer(nplanesuse, swimmer);
01029 }

Generated on Mon Nov 23 05:26:30 2009 for loon by  doxygen 1.3.9.1