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

TrackClusterSR.cxx

Go to the documentation of this file.
00001 
00002 // $Id: TrackClusterSR.cxx,v 1.42 2006/12/01 18:57:23 rhatcher Exp $
00003 //
00004 // TrackClusterSR
00005 //
00006 // Author:  R. Lee 2001.02.26
00008 
00009 #include <cassert>
00010 #include <iostream>
00011 #include <string>
00012 #include <cmath>
00013 
00014 #include "TClass.h"
00015 
00016 #include "CandTrackSR/TrackClusterSR.h"
00017 #include "Validity/VldContext.h"
00018 #include "Conventions/PlaneView.h"
00019 #include "Conventions/Munits.h"
00020 #include "MessageService/MsgService.h"
00021 #include "RecoBase/CandStripHandle.h"
00022 #include "UgliGeometry/UgliGeometry.h"
00023 #include "UgliGeometry/UgliGeomHandle.h"
00024 
00025 
00026 ClassImp(TrackClusterSR)
00027 
00028 //______________________________________________________________________
00029 CVSID("$Id: TrackClusterSR.cxx,v 1.42 2006/12/01 18:57:23 rhatcher Exp $");
00030 
00031 //______________________________________________________________________
00032 TrackClusterSR::TrackClusterSR()
00033 {
00034   fNStrip = 0;
00035   fMinStrip = 0;
00036   fMaxStrip = 0;
00037   fTPos = 0.;
00038   fTime3D = 0.;
00039   fTPosRMS = 0.;
00040   fZPos = 0.;
00041   fLPos = 0.;
00042   fCharge = 0.;
00043   fIsWide = false;
00044   fIsValid = true;
00045   fInShowerLikePlane = false;
00046   fParmMisalignmentError = 30*Munits::mm;
00047 }
00048 
00049 //______________________________________________________________________
00050 TrackClusterSR::TrackClusterSR(Double_t misalignmentError)
00051 {
00052   fNStrip = 0;
00053   fMinStrip = 0;
00054   fMaxStrip = 0;
00055   fTPos = 0.;
00056   fTime3D = 0.;
00057   fTPosRMS = 0.;
00058   fZPos = 0.;
00059   fLPos = 0.;
00060   fCharge = 0.;
00061   fIsWide = false;
00062   fIsValid = true;
00063   fInShowerLikePlane = false;
00064   fParmMisalignmentError = misalignmentError;          // 30*Munits::mm;
00065 }
00066 
00067 //______________________________________________________________________
00068 TrackClusterSR::TrackClusterSR(CandStripHandle *strip, 
00069                                Double_t misalignmentError)
00070 {
00071   fNStrip = 0;
00072   fMinStrip = 0;
00073   fMaxStrip = 0;
00074   fTPos = 0.;
00075   fTPosRMS = 0.;
00076   fZPos = 0.;
00077   fLPos = 0.;
00078   fCharge = 0.;
00079   fTime3D = 0.;
00080   fIsWide = false;
00081   fIsValid = true;
00082   fInShowerLikePlane = false;
00083   fParmMisalignmentError = misalignmentError;          // 30*Munits::mm;
00084 
00085   AddStrip(strip);
00086 }
00087 
00088 //______________________________________________________________________
00089 TrackClusterSR::TrackClusterSR(const TrackClusterSR &rhs) : // Copy-ctor
00090   TObject(rhs)
00091 , fNStrip(rhs.fNStrip)
00092 , fMinStrip(rhs.fMinStrip)
00093 , fMaxStrip(rhs.fMaxStrip)
00094 , fZPos(rhs.fZPos)
00095 , fCharge(rhs.fCharge)
00096 , fTime3D(rhs.fTime3D)
00097 , fTPos(rhs.fTPos)
00098 , fTPosRMS(rhs.fTPosRMS)
00099 , fLPos(rhs.fLPos)
00100 , fIsWide(rhs.fIsWide)
00101 , fIsValid(rhs.fIsValid)
00102 , fInShowerLikePlane(rhs.fInShowerLikePlane)
00103 , fParmMisalignmentError(rhs.fParmMisalignmentError)
00104 {
00105 
00106 // Copy TObjArray's contents
00107   TIter rhsIter(&rhs.fStripList);
00108   TObject *rhsObj;
00109   while ((rhsObj = rhsIter())) {
00110     CandStripHandle *cshObj;
00111     if ((cshObj = dynamic_cast<CandStripHandle*>(rhsObj))) {
00112       fStripList.Add(cshObj->DupHandle());
00113     }
00114   }
00115 }
00116 
00117 //______________________________________________________________________
00118 TrackClusterSR::~TrackClusterSR()
00119 {
00120   fStripList.Delete(); // Owned CandHandle*'s from TrackClusterSR vers 9
00121 }
00122 
00123 //______________________________________________________________________
00124 void TrackClusterSR::AddStrip(CandStripHandle *strip)
00125 {
00126   if (fStripList.GetLast()<0) {
00127     fZPos = strip->GetZPos();
00128   }
00129 
00130   PlexStripEndId strip_seid = strip->GetStripEndId();
00131   
00132   for (Int_t i=0; i<=fStripList.GetLast(); i++) {
00133     CandStripHandle *strip1 = 
00134       dynamic_cast<CandStripHandle*>(fStripList.At(i));
00135     PlexStripEndId strip1_seid = strip1->GetStripEndId();
00136     if ( strip_seid == strip1_seid  &&  (strip1->GetTime()==strip->GetTime())  ) return;
00137   }
00138 
00139   Int_t stripnum = strip_seid.GetStrip();
00140 
00141   fNStrip++;
00142   if (fNStrip==1 || stripnum<fMinStrip) {
00143     fMinStrip = stripnum;
00144   }
00145   if (fNStrip==1 || stripnum>fMaxStrip) {
00146     fMaxStrip = stripnum;
00147   }
00148   fStripList.Add(strip->DupHandle());
00149   if (fNStrip==1) {
00150     fCharge  = strip->GetCharge();
00151     fTPos    = strip->GetTPos();
00152     fTPosRMS = 0.;
00153   } else {
00154     fCharge  = 0.;
00155     fTPos    = 0.;
00156     fTPosRMS = 0.;
00157     for (Int_t i=0; i<=fStripList.GetLast(); i++) {
00158       CandStripHandle *strip1 = 
00159         dynamic_cast<CandStripHandle*>(fStripList.At(i));
00160       Double_t charge = strip1->GetCharge();
00161       if (charge <= 0.0) {
00162         MSG("TrackSR", Msg::kWarning)
00163           << "AddStrip() strip1 charge "
00164           << charge << ", avoid corrupting avg/RMS of TPos." << endl;
00165         continue;  // skip polluting <TPos>,RMS(TPos) w/ funky charge
00166       }
00167       Double_t tpos   = strip1->GetTPos();
00168       //    fTPos    += charge*tpos;
00169       //  fTPosRMS += charge*tpos*tpos;
00170       //  fCharge  += charge;
00171       fTPos    += tpos;
00172       fTPosRMS += tpos*tpos;
00173       fCharge  += charge;
00174     }
00175     if (fCharge<=0.0) {
00176       MSG("TrackSR", Msg::kWarning)
00177         << "AddStrip() fCharge "
00178         << fCharge << ", avoid division." << endl;
00179       fCharge  = 1.0e-6;
00180       fTPos    = 0.0;
00181       fTPosRMS = 1.0e+6;
00182     }
00183     
00184     //    fTPos /= fCharge;
00185     //  fTPosRMS /= fCharge;
00186     // fTPosRMS -= fTPos*fTPos;
00187     fTPos /= fNStrip;
00188     fTPosRMS /= fNStrip;
00189     fTPosRMS -= fTPos*fTPos;
00190     if (fTPosRMS>=0.) {
00191       fTPosRMS = sqrt(fTPosRMS);
00192     } else {
00193       fTPosRMS = 0.;
00194     }
00195   } // fNStrip > 1
00196 
00197 }
00198 
00201 void TrackClusterSR::SetLPos(Double_t lpos)
00202 {
00203     MSG("TrackSR", Msg::kDebug)
00204           << "void TrackClusterSR::SetLPos(Double_t lpos)" << endl;
00205     MSG("TrackSR", Msg::kDebug)
00206           << "Setting fLPos = " << lpos << endl;
00207     fLPos = lpos;   
00208     RecalculateTPos();
00209 } // void TrackClusterSR::SetLPos(Double_t)
00210 
00211 
00215 Double_t TrackClusterSR::GetRotationCorrectedTPos(const CandStripHandle* csh) const
00216 {
00217     MSG("TrackSR", Msg::kDebug)
00218           << "Double_t TrackClusterSR::GetRotationCorrectedTPos(const CandStripHandle* csh) const" << endl;
00219           
00220     assert( csh && "Do not pass NULL pointers!!!");
00221     
00222     static CandStripHandle* lastCsh = 0;
00223     static Double_t lastLpos = 0.;
00224     static Double_t lastTpos = 0.;
00225         
00226     if ( csh != lastCsh || fLPos != lastLpos ) {
00227         UgliGeomHandle ugh(*csh->GetVldContext());    
00228         PlexStripEndId strip_seid = csh->GetStripEndId();
00229         UgliStripHandle ush = ugh.GetStripHandle(strip_seid);
00230         lastTpos = ush.GetTPos(fLPos);
00231     }        
00232 
00233     MSG("TrackSR", Msg::kDebug) << "TPos = " << csh->GetTPos() 
00234         << "; RotationCorrectedTPos = " << lastTpos << "; LPos = " << fLPos << endl;
00235     return lastTpos;
00236 } // Double_t TrackClusterSR::GetRotationCorrectedTPos(const CandStripHandle*)
00237 
00238 
00241 void TrackClusterSR::RecalculateTPos()
00242 {    
00243   // return when the cluster has no strips
00244   if ( fNStrip == 0 ) return;
00245   
00246   // running sums
00247   Double_t chargesum = 0.;
00248   Double_t tpossum = 0.;
00249   Double_t tposrmssum = 0.;
00250   
00251   // loop over strips
00252   for (Int_t i=0; i<=fStripList.GetLast(); i++) {
00253     CandStripHandle *strip = 
00254       dynamic_cast<CandStripHandle*>(fStripList.At(i));
00255     
00256     // cache strip charge, tpos
00257     Double_t stripcharge = strip->GetCharge();
00258     Double_t striptpos = GetRotationCorrectedTPos(strip);
00259     
00260     // ignore strips with negative charge
00261     if (stripcharge <= 0.0) {
00262       MSG("TrackSR", Msg::kWarning)
00263         << "Strip charge is "
00264         << stripcharge << ", avoid corrupting avg/RMS of TPos." << endl;
00265       continue;  // skip polluting <TPos>,RMS(TPos) w/ funky charge
00266     }
00267     
00268     // increment running sums
00269     chargesum  += stripcharge;
00270     tpossum    += striptpos;
00271     tposrmssum += striptpos*striptpos;
00272   }    
00273 
00274   // set zero values and return if total charge is <=0.    
00275   if (chargesum <= 0.0) {
00276     MSG("TrackSR", Msg::kWarning)
00277         << "AddStrip() fCharge "
00278         << fCharge << ", avoid division." << endl;
00279     fCharge  = 1.0e-6;
00280     fTPos    = 0.0;
00281     fTPosRMS = 1.0e+6;
00282     return;
00283   }
00284   
00285   // update TrackCluster fTPos, fTPosRMS  
00286   fTPos = tpossum/fNStrip;
00287   fTPosRMS = tposrmssum/fNStrip - fTPos*fTPos;
00288   if ( fTPosRMS>=0.) {
00289       fTPosRMS = sqrt(fTPosRMS);
00290   } else {
00291       fTPosRMS = 0.;
00292   }
00293 } // void TrackClusterSR::RecalculateTPos()
00294 
00295 //______________________________________________________________________
00296 Double_t TrackClusterSR::DTPos(Double_t tpos) const
00297 {
00298   if (fNStrip==0) {
00299     return -99999.;
00300   }
00301   CandStripHandle *strip =
00302                      dynamic_cast<CandStripHandle*>(fStripList.First());
00303   if (GetNStrip()==1) {
00304     return fabs(strip->GetTPos()-tpos); 
00305   }
00306   Double_t dtpos = 9999999.;
00307   Bool_t above(0);
00308   Bool_t below(0);
00309 
00310 // assume that trackcluster is contiguous set of strips
00311   for (Int_t i=0; i<=fStripList.GetLast(); i++) {
00312     strip = dynamic_cast<CandStripHandle*>(fStripList.At(i));
00313     if (strip->GetTPos()>tpos) {
00314       above = 1;
00315     }
00316     if (strip->GetTPos()<tpos) {
00317       below = 1;
00318     }
00319     dtpos = min(dtpos,fabs(strip->GetTPos()-tpos));
00320   }
00321   if (above && below) {
00322     dtpos = 0.;
00323   }
00324   return dtpos;
00325 }
00326 
00327 //______________________________________________________________________
00328 Double_t TrackClusterSR::GetBegTime() const
00329 {
00330   if (fNStrip==0) {
00331     return 0.;
00332   }
00333   Double_t begtime=0.;
00334   for (Int_t i=0; i<=fStripList.GetLast(); i++) {
00335     CandStripHandle *strip =
00336                        dynamic_cast<CandStripHandle*>(fStripList.At(i));
00337     if (!i || strip->GetBegTime()<begtime) {
00338       begtime = strip->GetBegTime();
00339     }
00340   }
00341   return begtime;
00342 }
00343 
00344 //______________________________________________________________________
00345 Double_t TrackClusterSR::GetCharge() const
00346 {
00347   if (fNStrip==0) {
00348     return 0.;
00349   }
00350   return fCharge;
00351 }
00352 
00353 //______________________________________________________________________
00354 Int_t TrackClusterSR::GetMaxStrip() const
00355 {
00356   return fMaxStrip;
00357 }
00358 
00359 //______________________________________________________________________
00360 Double_t TrackClusterSR::GetMaxTPos() const
00361 {
00362   if (fNStrip==0) {
00363     return 0.;
00364   }
00365   Double_t tpos=-5.;
00366   for (Int_t i=0; i<=fStripList.GetLast(); i++) {
00367     CandStripHandle *strip =
00368                        dynamic_cast<CandStripHandle*>(fStripList.At(i));
00369     if (!i || strip->GetTPos()>tpos) {
00370       tpos = strip->GetTPos();
00371     }
00372   }
00373   return tpos+0.02054;
00374 }
00375 
00376 //______________________________________________________________________
00377 Int_t TrackClusterSR::GetMinStrip() const
00378 {
00379   return fMinStrip;
00380 }
00381 
00382 //______________________________________________________________________
00383 Double_t TrackClusterSR::GetMinTPos() const
00384 {
00385   if (fNStrip==0) {
00386     return 0.;
00387   }
00388   Double_t tpos=5.;
00389   for (Int_t i=0; i<=fStripList.GetLast(); i++) {
00390     CandStripHandle *strip =
00391                        dynamic_cast<CandStripHandle*>(fStripList.At(i));
00392     if (!i || strip->GetTPos()<tpos) {
00393       tpos = strip->GetTPos();
00394     }
00395   }
00396   return tpos-0.02054;
00397 }
00398 
00399 //______________________________________________________________________
00400 Int_t TrackClusterSR::GetNStrip() const
00401 {
00402   return fNStrip;
00403 }
00404 
00405 //______________________________________________________________________
00406 Int_t TrackClusterSR::GetPlane() const
00407 {
00408   if (fStripList.GetLast()>=0) {
00409     CandStripHandle *strip =
00410                      dynamic_cast<CandStripHandle*>(fStripList.First());
00411     return strip->GetPlane();
00412   }
00413   else {
00414     return 0;
00415   }
00416 }
00417 
00418 //______________________________________________________________________
00419 PlaneView::PlaneView_t TrackClusterSR::GetPlaneView() const
00420 {
00421   if (fNStrip==0) {
00422     return PlaneView::kUnknown;
00423   }
00424   CandStripHandle *firststrip =
00425                      dynamic_cast<CandStripHandle*>(fStripList.First());
00426   return firststrip->GetPlaneView();
00427 }
00428 
00429 //______________________________________________________________________
00430 const TObjArray* TrackClusterSR::GetStripList() const
00431 {
00432   return &fStripList;
00433 }
00434 
00435 //______________________________________________________________________
00436 Double_t TrackClusterSR::GetTime3D() const
00437 {
00438   return fTime3D;
00439 }
00440 
00441 //______________________________________________________________________
00442 Double_t TrackClusterSR::GetTPos() const
00443 {
00444   if (fNStrip==0) {
00445     return 0.;
00446   }
00447   return fTPos;
00448 }
00449 
00450 //______________________________________________________________________
00451 Double_t TrackClusterSR::GetTPosError() const
00452 {
00453   Double_t err = 0.;
00454   if (fNStrip==0) {
00455     err = 0.;
00456   } else if (fNStrip==1) {
00457 
00458 // 4.108 cm / sqrt(12)
00459     err = 0.01185877;
00460   } else {
00461    
00462     err = max((GetMaxTPos()-GetMinTPos())*0.288,0.01185877);
00463                //    err = max(fTPosRMS,0.01185877);
00464   }
00465 
00466   // add value in quadrature to reflect misalignments
00467   err = sqrt(err*err+fParmMisalignmentError*fParmMisalignmentError);
00468   return err;
00469 }
00470 
00471 //______________________________________________________________________
00472 Double_t TrackClusterSR::GetTPosRMS() const
00473 {
00474   if (fNStrip==0) {
00475     return 0.;
00476   }
00477   return fTPosRMS;
00478 }
00479 
00480 //______________________________________________________________________
00481 Double_t TrackClusterSR::GetZPos() const
00482 {
00483   return fZPos;
00484 }
00485 
00486 //______________________________________________________________________
00487 Double_t TrackClusterSR::GetMisalignmentError() const
00488 {
00489   return fParmMisalignmentError;
00490 }
00491 
00492 //______________________________________________________________________
00493 Bool_t TrackClusterSR::InShowerLikePlane() const
00494 {
00495 
00496 // returns true if cluster is in a showerlike plane - ie one with a wide
00497 // cluster
00498   return fInShowerLikePlane;
00499 }
00500 
00501 //______________________________________________________________________
00502 Bool_t TrackClusterSR::IsContained(CandStripHandle *target) const
00503 { 
00504   for (Int_t i=0; i<=fStripList.GetLast(); i++) {
00505     CandStripHandle *strip =
00506                        dynamic_cast<CandStripHandle*>(fStripList.At(i));
00507 
00508 // check if object being pointed to is the same
00509     if (*strip == *target) {
00510       return 1;
00511     }
00512   }
00513   return 0;
00514 }
00515 
00516 //______________________________________________________________________
00517 Bool_t TrackClusterSR::IsDoubleEnded() const
00518 {
00519   for (Int_t i=0; i<=fStripList.GetLast(); i++) {
00520     CandStripHandle *strip =
00521                        dynamic_cast<CandStripHandle*>(fStripList.At(i));
00522     if (!i &&
00523            strip->GetVldContext()->GetDetector()==Detector::kNear) {
00524       return kFALSE;
00525     }
00526     if (strip->GetNDaughters()==2) {
00527       return kTRUE;
00528     }
00529   }
00530   return kFALSE;
00531 }
00532 
00533 //______________________________________________________________________
00534 Bool_t TrackClusterSR::IsEquivalent(const TObject *rhs) const
00535 {
00536   const TrackClusterSR *rcl = dynamic_cast<const TrackClusterSR*>(rhs);
00537 
00538 // compare simple members
00539   if ( !(this->fNStrip            == rcl->fNStrip            &&
00540          this->fInShowerLikePlane == rcl->fInShowerLikePlane )) {
00541     return false;
00542   }
00543 
00544 // compare TObjArray
00545   if (this->fStripList.GetEntries() != rcl->fStripList.GetEntries()) {
00546     return false;
00547   }
00548   else {
00549     TIter thisIter(&this->fStripList);
00550     TIter rhsIter(&rcl->fStripList);
00551     TObject *thisObj, *rhsObj;
00552     while ( ( (thisObj = thisIter.Next() ) != NULL) &&
00553             ( (rhsObj  = rhsIter.Next()  ) != NULL)    ) {
00554       CandStripHandle *thisStrip =
00555                                 dynamic_cast<CandStripHandle*>(thisObj);
00556       CandStripHandle *rhsStrip =
00557                                  dynamic_cast<CandStripHandle*>(rhsObj);
00558       if (!thisStrip || !rhsStrip) return false; // not CandStripHandle*
00559       if (*thisStrip != *rhsStrip) return false;  // Deep Handle compare
00560     }
00561   }
00562   return true;
00563 }
00564 
00565 //______________________________________________________________________
00566 Bool_t TrackClusterSR::IsValid() const
00567 {
00568 // returns true if cluster is a valid one to consider
00569   return fIsValid;
00570 }
00571 
00572 //______________________________________________________________________
00573 Bool_t TrackClusterSR::IsWide() const
00574 {
00575 
00576 // returns true if cluster is a wide cluster
00577   return fIsWide;
00578 }
00579 
00580 //______________________________________________________________________
00581 void TrackClusterSR::SetInShowerLikePlane(Bool_t showerLike)
00582 {
00583 
00584 // set the flag for this being in a shower like plane - ie 
00585 // the plane contains at least one wide cluster
00586   fInShowerLikePlane = showerLike;
00587 }
00588 
00589 //______________________________________________________________________
00590 void TrackClusterSR::SetIsValid(Bool_t isvalid)
00591 {
00592 
00593 // set the flag for this being a wide cluster - ie one with
00594 // more strips in it than expected based on slope
00595   fIsValid = isvalid;
00596 }
00597 
00598 //______________________________________________________________________
00599 void TrackClusterSR::SetIsWide(Bool_t iswide)
00600 {
00601 
00602 // set the flag for this being a wide cluster - ie one with
00603 // more strips in it than expected based on slope
00604   fIsWide = iswide;
00605 }
00606 
00607 //______________________________________________________________________
00608 void TrackClusterSR::SetTime3D(Double_t dvar)
00609 {
00610   fTime3D = dvar;
00611 }
00612 
00613 //______________________________________________________________________
00614 NavKey TrackClusterSR::KeyFromPlane(const TrackClusterSR *tcluster)
00615 {
00616   return tcluster->GetPlane();
00617 }
00618 
00619 //______________________________________________________________________
00620 NavKey TrackClusterSR::KeyFromPlaneTPosTime(
00621                                          const TrackClusterSR *tcluster)
00622 {
00623    Int_t iplane = tcluster->GetPlane();
00624    Double_t tpos = tcluster->GetMinTPos();
00625    Int_t itpos = static_cast<Int_t>(tpos);
00626    Double_t time = tcluster->GetBegTime();
00627    Int_t itime = static_cast<Int_t>(time*.1/18.7);
00628 
00629    Int_t navkey = (iplane<<22) | (itpos<<11) | itime;
00630 
00631    return navkey;
00632 }
00633 
00634 //______________________________________________________________________
00635 void TrackClusterSR::Streamer(TBuffer &R__b)
00636 {
00637 
00638 // Stream an object of class TrackClusterSR.
00639   if (R__b.IsReading()) {
00640     UInt_t R__s, R__c;
00641     Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
00642     TrackClusterSR::Class()->ReadBuffer(R__b, this, R__v, R__s, R__c);
00643     if (R__v < 9) {
00644 
00645 // fStripList contents owned from TrackClusterSR version 9
00646       CandHandle *ch;
00647       TIter cliter(&fStripList);
00648       while ((ch = dynamic_cast<CandHandle *>(cliter())))
00649         fStripList.AddAt(ch->DupHandle(), fStripList.IndexOf(ch));
00650     }
00651   }
00652   else {
00653     TrackClusterSR::Class()->WriteBuffer(R__b, this);
00654   }
00655 }
00656 
00657 XXXITRIMP(TrackClusterSR)

Generated on Thu Nov 1 11:53:27 2007 for loon by  doxygen 1.3.9.1