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

PlexSEIdAltL.cxx

Go to the documentation of this file.
00001 
00002 // $Id: PlexSEIdAltL.cxx,v 1.34 2005/08/26 18:47:03 rhatcher Exp $
00003 //
00004 // PlexSEIdAltL
00005 //
00006 // PlexSEIdAltL is a vector+iterator for PlexSEIdAltLItems
00007 //
00008 // Author:  R. Hatcher 2001.10.22
00009 //
00011 
00012 #include "Plex/PlexSEIdAltL.h"
00013 #include "Plex/PlexCalib.h"
00014 
00015 #include "MessageService/MsgService.h"
00016 #include "MessageService/MsgStream.h"
00017 #include "MessageService/MsgFormat.h"
00018 CVSID("$Id: PlexSEIdAltL.cxx,v 1.34 2005/08/26 18:47:03 rhatcher Exp $");
00019 
00020 #include "TMath.h"
00021 
00022 #include <string>
00023 #include <algorithm>
00024 #include <cassert>
00025 
00026 // a static dummy PlexSEIdAltLItem for when we need to return a
00027 // reference to an item and the list is empty
00028 static PlexSEIdAltLItem dummyPlexSEIdAltLItem;
00029 
00030 ClassImp(PlexSEIdAltL)
00031 
00032 //_____________________________________________________________________________
00033 
00034 UInt_t PlexSEIdAltL::fgFmtFlag = 0;
00035 const UInt_t defaultFmtFlag = 0xFFFFFFFF & ~PlexSEIdAltL::fmt_PixelSpot;
00036 
00037 UInt_t lastFmtFlag = 0;
00038 string fmtHeaderTitle = "";
00039 string fmtHeaderULine = "";
00040 
00041 //_____________________________________________________________________________
00042 ostream& operator<<(ostream& os, const PlexSEIdAltL& alt)
00043 {
00044   // Print out the list
00045   if (alt.size() <= 0) {
00046      os << "Empty-PlexSEIdAltL " << endl;
00047      return os;
00048   }
00049 
00050   UInt_t fmt = PlexSEIdAltL::GetFmtFlag();
00051   // disallow no formatting bits
00052   if (!fmt) fmt = defaultFmtFlag;
00053   bool doFmtIndex     = fmt & PlexSEIdAltL::fmt_Index;
00054   bool doFmtCursor    = fmt & PlexSEIdAltL::fmt_Cursor;
00055   bool doFmtBest      = fmt & PlexSEIdAltL::fmt_Best;
00056   bool doFmtStripEnd  = fmt & PlexSEIdAltL::fmt_StripEnd;
00057   bool doFmtPixelSpot = fmt & PlexSEIdAltL::fmt_PixelSpot;
00058   bool doFmtWeight    = fmt & PlexSEIdAltL::fmt_Weight;
00059   bool doFmtPE        = fmt & PlexSEIdAltL::fmt_PE;
00060   bool doFmtSigLin    = fmt & PlexSEIdAltL::fmt_SigLin;
00061   bool doFmtSigCorr   = fmt & PlexSEIdAltL::fmt_SigCorr;
00062   bool doFmtTime      = fmt & PlexSEIdAltL::fmt_Time;
00063 
00064   static const MsgFormat i1("%1d");
00065   static const MsgFormat f3p1("%3.1f");
00066   static const MsgFormat f5p1("%5.1f");
00067   static const MsgFormat f7p2("%7.2f");
00068 
00069   if (lastFmtFlag != fmt) {
00070     // construct the header line and the line of "---"'s and "+"'s
00071     lastFmtFlag = fmt;
00072     fmtHeaderTitle = "";
00073     fmtHeaderULine = "";
00074     if (doFmtBest) {
00075       fmtHeaderTitle += " ";
00076       fmtHeaderULine += "-";
00077     }
00078     if (doFmtCursor) {
00079       fmtHeaderTitle += " ";
00080       fmtHeaderULine += "-";
00081     }
00082     if (doFmtIndex) {
00083       fmtHeaderTitle += " i |";
00084       fmtHeaderULine += "---+";
00085     }
00086     if (doFmtStripEnd) {
00087       //                  F0001Uc003-
00088       fmtHeaderTitle += " StripEndId  |";
00089       fmtHeaderULine += "-------------+";
00090     }
00091     if (doFmtPixelSpot) {
00092       //                  MUXB-UV-?L00:00-SPOT-0-00-00
00093       fmtHeaderTitle += " PixelSpot                    |";
00094       fmtHeaderULine += "------------------------------+";
00095     }
00096     if (doFmtWeight) {
00097       fmtHeaderTitle += " wgt |";
00098       fmtHeaderULine += "-----+";
00099     }
00100     if (doFmtPE) {
00101       fmtHeaderTitle += " PE    |";
00102       fmtHeaderULine += "-------+";
00103     }
00104     if (doFmtSigLin) {
00105       fmtHeaderTitle += " Linear  |";
00106       fmtHeaderULine += "---------+";
00107     }
00108     if (doFmtSigCorr) {
00109       fmtHeaderTitle += " S2SCorr |";
00110       fmtHeaderULine += "---------+";
00111     }
00112     if (doFmtTime) {
00113       fmtHeaderTitle += " Time    |";
00114       fmtHeaderULine += "---------+";
00115     }
00116   }
00117   
00118   os << fmtHeaderTitle << endl;
00119   os << fmtHeaderULine << endl;
00120 
00121   PlexSEIdAltLItem& best    = dummyPlexSEIdAltLItem;
00122 
00123   for (unsigned int i=0; i<alt.size(); ++i) {
00124     const PlexSEIdAltLItem& item = alt[i];
00125     if (doFmtBest)   {   best    = alt.GetBestItem();
00126                          os << ((item == best)      ? '!' : ' ');
00127     }
00128     if (doFmtCursor) {  
00129                          os << ((i == alt.fCurrent) ? '@' : ' ');
00130     }
00131     if (doFmtIndex)      os << " " << i1(i) << " |";
00132     if (doFmtStripEnd)   os << " " << item.GetSEId().AsString("C") << " |";
00133     if (doFmtPixelSpot)  os << " " << item.GetPixelSpotId().AsString("c") << " |";
00134     if (doFmtWeight)     os << " " << f3p1(item.GetWeight()) << " |";
00135     if (doFmtPE)         os << " " << f5p1(item.GetPE()) << " |";
00136     if (doFmtSigLin)     os << " " << f7p2(item.GetSigLin()) << " |";
00137     if (doFmtSigCorr)    os << " " << f7p2(item.GetSigCorr()) << " |";
00138     if (doFmtTime)       os << " " << f7p2(item.GetTime()) << " |";
00139     os << endl;
00140   }
00141       
00142 #ifdef OLDFORMATTING
00143     char marker;
00144     PlexStripEndId seid;
00145     MsgFormat i2("%2d");
00146     MsgFormat i3("%3d");
00147     //     MsgFormat f10("%10.5f");
00148     
00149     // format the header line
00150     os << "     i | StripEndId (size=" << i2(alt.size()) 
00151        << ",cur=" << i2(alt.fCurrent) << ") "
00152        << "| weight    " 
00153        << "| muon unit " 
00154        << "| t offset  " 
00155        << endl;
00156     os << "-------+-----------------------------"
00157        << "+-----------" 
00158        << "+-----------" 
00159        << "+-----------" 
00160        << endl;
00161     
00162     for (unsigned int i=0; i<alt.size(); ++i) {
00163       (i==alt.fCurrent) ? marker = '*' : marker = ' ';
00164       PlexSEIdAltLItem item = alt[i];
00165       seid   = item.GetSEId();
00166       os << " " << marker << " " << i3(i) 
00167          << " " << item
00168          << endl;
00169     }
00170 #endif
00171 
00172   return os;
00173 }
00174 
00175 //_____________________________________________________________________________
00176 PlexSEIdAltL::PlexSEIdAltL()
00177    : fCurrent(0), fDemuxVetoFlag(0), fError(kUnchecked)     
00178 {
00179    // Default constructor
00180 }
00181 
00182 //_____________________________________________________________________________
00183 PlexSEIdAltL::PlexSEIdAltL(const PlexSEIdAltL &rhs)
00184    : std::vector<PlexSEIdAltLItem>(),
00185      fCurrent(rhs.fCurrent), 
00186      fDemuxVetoFlag(rhs.fDemuxVetoFlag), 
00187      fError(kUnchecked)
00188 {
00189 
00190    // deep copy constructor
00191    for (unsigned int i=0; i<rhs.size(); ++i) {
00192       this->push_back(rhs[i]);
00193    }
00194 
00195 }
00196 
00197 //_____________________________________________________________________________
00198 PlexSEIdAltL::~PlexSEIdAltL()
00199 {
00200    // delete all the owned sub-objects
00201 }
00202 
00203 #ifdef ALTL_EXPLICIT_ASSIGNMENT
00204 //_____________________________________________________________________________
00205 PlexSEIdAltL& PlexSEIdAltL::operator=(const PlexSEIdAltL& rhs)
00206 {
00207    // deep assignment
00208    clear();
00209    for (unsigned int i=0; i<rhs.size(); ++i) {
00210       this->push_back(rhs[i]);
00211    }
00212    fCurrent       = rhs.fCurrent;
00213    fDemuxVetoFlag = rhs.fDemuxVetoFlag;
00214    fError         = rhs.fError;
00215 }
00216 #endif
00217 
00218 //_____________________________________________________________________________
00219 void PlexSEIdAltL::AddStripEndId(const PlexStripEndId& seid, 
00220                                  const PlexPixelSpotId& spot,
00221                                  Float_t weight, const PlexCalib* calib, 
00222                                  Int_t adc, Double_t time)
00223 {
00224    // add a new item to the list
00225 
00226    fError = kUnchecked;  // adding a new strip makes consistency unknown
00227 
00228    if (calib) {
00229       PlexSEIdAltLItem item = calib->CalibStripEnd(seid,spot,adc,time);
00230       item.SetWeight(weight);
00231       this->push_back(item);
00232    }
00233    else {
00234       PlexSEIdAltLItem item(seid,spot,weight);
00235       this->push_back(item);
00236    }
00237 }
00238 
00239 //_____________________________________________________________________________
00240 void PlexSEIdAltL::DropCurrent()
00241 {
00242    // Remove current item from the list.
00243    // Do not reset current position of iterator.
00244    // An iterative removal should start from Last() and use Previous().
00245 
00246    UShort_t n = size();
00247 
00248    if (n <= 0) return;  // one cannot drop what one doesn't have
00249    if (fCurrent>=n) {   
00250       MSG("Plex",Msg::kWarning)
00251          << "can not DropCurrent (fCurrent=" << fCurrent 
00252          << ") on a list of " << n << " items " << endl;
00253       return;
00254    }
00255 
00256    PlexSEIdAltLIter cursor = this->begin() + fCurrent;
00257    // delete the owned item
00258    this->erase(cursor);
00259 
00260 }
00261 
00262 //_____________________________________________________________________________
00263 void PlexSEIdAltL::DropZeroWeights()
00264 {
00265    // Remove pairs from the list that have weight == 0
00266 
00267    if (size() <= 0) return;  // one cannot drop what one doesn't have
00268 
00269    // move all zero items to the end
00270    PlexSEIdAltLIter new_end = 
00271       remove_if(this->begin(), this->end(), 
00272                 mem_fun_ref(&PlexSEIdAltLItem::IsZeroWeight));
00273 
00274    // erase the moved items out of the array 
00275    this->erase(new_end,this->end());
00276 
00277 }
00278 
00279 //_____________________________________________________________________________
00280 void PlexSEIdAltL::KeepTopWeights(UInt_t n, Bool_t keeporder)
00281 {
00282    // Remove all but "n" pairs from the list (top "n" sorted by weight)
00283    // Final relative order of elements in the list is unchanged
00284    // if keeporder=kTRUE otherwise list ordered by decending weights.
00285    // If "n" would separate values of the same weight then
00286    // more than "n" are kept.
00287 
00288    unsigned int i, cnt = size();
00289 
00290    if (cnt <= 0) return;  // one cannot drop what one doesn't have
00291 
00292    if (n >= cnt) {
00293       if (keeporder) return; // keep everything, no change in order
00294       else n = cnt;          // perform sort but don't go beyond end
00295    }
00296 
00297    PlexSEIdAltL& self = *this;
00298 
00299    if (n <= 0) { // special case for new size=0
00300       this->clear();
00301       return;
00302    }
00303 
00304    // make a copy of the weights
00305    // sort it
00306    // select the nth down the list for lowest weight value to keep
00307    Float_t *sortedwgt = new Float_t[cnt];
00308    Int_t   *sortedindx = new Int_t[cnt];
00309    for (i=0; i<cnt; i++) sortedwgt[i] = self[i].GetWeight();
00310    Bool_t down=kTRUE;
00311    TMath::Sort(cnt,sortedwgt,sortedindx,down);
00312    // n-1 because C arrays start with 0
00313    Int_t   icut = sortedindx[n-1];
00314    Float_t  cut = sortedwgt[icut]; 
00315 
00316    // count final size
00317    // may not be ==n because of two entries with same weight
00318    vector<PlexSEIdAltLItem> tempVector;
00319    for (i=0; i<cnt; i++) {
00320       unsigned int indxold = i;
00321       if (!keeporder) indxold = sortedindx[i];
00322       if (self[indxold].GetWeight() >= cut) {
00323          tempVector.push_back(self[indxold]);
00324       }
00325    }
00326 
00327    // replace current vector with newly created temporary
00328    this->swap(tempVector);
00329 
00330    delete [] sortedwgt;
00331    delete [] sortedindx;
00332 
00333 }
00334 
00335 //_____________________________________________________________________________
00336 void PlexSEIdAltL::ClearWeights()
00337 {
00338    // set all the weights to zero
00339 
00340    PlexSEIdAltL& self = *this;
00341    for (unsigned int i=0; i<size(); i++) (self[i]).SetWeight(0.0);
00342 }
00343 
00344 //_____________________________________________________________________________
00345 const PlexSEIdAltLItem& PlexSEIdAltL::GetBestItem() const
00346 {
00347    // find the PlexSEIdAltLItem with the highest weight (const version)
00348 
00349    unsigned int thesize = size();
00350    if (thesize == 0) {
00351      static int msglimit = 25;  // limit the number of complaints
00352      if (msglimit) {
00353        // Empty lists generally happen because of raw channel id's
00354        // that don't map back to real strips (for instance due to
00355        // unused pixels on a tube being illuminated by crosstalk).
00356        // Complain a bit ... but then shut up.
00357        MSG("Plex",Msg::kWarning)
00358          << "can not GetBestItem() from an empty list" << endl;
00359        if (--msglimit == 0) 
00360          MSG("Plex",Msg::kWarning)
00361            << " ... last warning of this type" << endl;
00362      }
00363      return dummyPlexSEIdAltLItem;;
00364    }
00365    else if (thesize == 1) {
00366      // simple case of only one element
00367      return (*this)[0];
00368    }
00369 
00370    PlexSEIdAltLConstIter cursor = this->begin();
00371    PlexSEIdAltLConstIter best   = this->begin();
00372    Float_t wgt, maxwgt = -1.0e-37;
00373    while (cursor != this->end()) {
00374       const PlexSEIdAltLItem& item = *cursor;
00375       if ( (wgt = item.GetWeight()) > maxwgt ) {
00376          maxwgt = wgt; best = cursor;
00377       }
00378       cursor++;
00379    }
00380    return *best;
00381       
00382 }
00383 
00384 //_____________________________________________________________________________
00385 PlexSEIdAltLItem& PlexSEIdAltL::GetBestItem()
00386 {
00387    // find the PlexSEIdAltLItem with the highest weight
00388 
00389    unsigned int thesize = size();
00390    if (thesize == 0) {
00391      static int msglimit = 25;  // limit the number of complaints
00392      if (msglimit) {
00393        // Empty lists generally happen because of raw channel id's
00394        // that don't map back to real strips (for instance due to
00395        // unused pixels on a tube being illuminated by crosstalk).
00396        // Complain a bit ... but then shut up.
00397        MSG("Plex",Msg::kWarning)
00398          << "can not GetBestItem() from an empty list" << endl;
00399        if (--msglimit == 0) 
00400          MSG("Plex",Msg::kWarning)
00401            << " ... last warning of this type" << endl;
00402      }
00403      return dummyPlexSEIdAltLItem;;
00404    }
00405    else if (thesize == 1) {
00406      // simple case of only one element
00407      return (*this)[0];
00408    }
00409    
00410    PlexSEIdAltLIter cursor = this->begin();
00411    PlexSEIdAltLIter best   = this->begin();
00412    Float_t wgt, maxwgt = -1.0e-37;
00413    while (cursor != this->end()) {
00414       PlexSEIdAltLItem& item = *cursor;
00415       if ( (wgt = item.GetWeight()) > maxwgt ) {
00416          maxwgt = wgt; best = cursor;
00417       }
00418       cursor++;
00419    }
00420    return *best;
00421       
00422 }
00423 
00424 //_____________________________________________________________________________
00425 PlexStripEndId PlexSEIdAltL::GetBestSEId() const
00426 {
00427    // find the PlexStripEndId with the highest weight and return by value
00428 
00429    return GetBestItem().GetSEId();
00430 
00431 }
00432 
00433 //_____________________________________________________________________________
00434 Float_t PlexSEIdAltL::GetBestWeight() const
00435 {
00436    // find the highest weight
00437 
00438    return GetBestItem().GetWeight();
00439 
00440 }
00441 
00442 //_____________________________________________________________________________
00443 const PlexSEIdAltLItem& PlexSEIdAltL::GetCurrentItem() const
00444 {
00445    // return by value current PlexSEIdAltLItem (const version)
00446 
00447    if (!IsValid()) {
00448      if (size() <= 0) 
00449        MSG("Plex",Msg::kWarning)
00450          << "can not GetCurrentItem() from an empty list" << endl;
00451      else
00452        MSG("Plex",Msg::kWarning)
00453          << "can not GetCurrentItem() when !IsValid()" << endl;
00454      return dummyPlexSEIdAltLItem;;
00455    }
00456 
00457    PlexSEIdAltLConstIter cursor = this->begin() + fCurrent;
00458    return *cursor;
00459 
00460 }
00461 
00462 //_____________________________________________________________________________
00463 PlexSEIdAltLItem& PlexSEIdAltL::GetCurrentItem()
00464 {
00465    // return by value current PlexSEIdAltLItem
00466 
00467    if (!IsValid()) {
00468      if (size() <= 0) 
00469        MSG("Plex",Msg::kWarning)
00470          << "can not GetCurrentItem() from an empty list" << endl;
00471      else
00472        MSG("Plex",Msg::kWarning)
00473          << "can not GetCurrentItem() when !IsValid()" << endl;
00474      return dummyPlexSEIdAltLItem;;
00475    }
00476 
00477    PlexSEIdAltLIter cursor = this->begin() + fCurrent;
00478    return *cursor;
00479 
00480 }
00481 
00482 //_____________________________________________________________________________
00483 PlexStripEndId PlexSEIdAltL::GetCurrentSEId() const
00484 {
00485    // return by value current PlexStripEndId
00486 
00487    return GetCurrentItem().GetSEId();
00488 
00489 }
00490 
00491 //_____________________________________________________________________________
00492 Float_t PlexSEIdAltL::GetCurrentWeight() const
00493 {
00494    // return the weight attached to the current PlexStripEndId
00495 
00496    return GetCurrentItem().GetWeight();
00497 
00498 }
00499 
00500 //_____________________________________________________________________________
00501 Detector::Detector_t PlexSEIdAltL::GetDetector(Bool_t reportError) const
00502 {
00503    // Return the Detector of the PlexStripEndID's in this list.
00504    // This is meaningful only in a correctly filled PlexSEIdAltL
00505 
00506    TestConsistency(reportError);
00507    
00508    if ( fError & kBadDetector || size() < 1 ) 
00509       return (Detector::Detector_t)0; // bad detector
00510 
00511    PlexSEIdAltLConstIter cursor = this->begin();
00512    return (*cursor).GetSEId().GetDetector();
00513 
00514 }
00515 
00516 //_____________________________________________________________________________
00517 Bool_t PlexSEIdAltL::IsVetoShield(Bool_t reportError) const
00518 {
00519    // Return the whether this alt-list reflect veto shield strips
00520    // This is meaningful only in a correctly filled PlexSEIdAltL
00521 
00522    TestConsistency(reportError);
00523    
00524    // if inconsistent ... don't take it as part of veto shield
00525    // "nothing" isn't part of a veto shield
00526    if ( fError & kBadIsVeto || size() < 1 ) return false;
00527 
00528    PlexSEIdAltLConstIter cursor = this->begin();
00529    return (*cursor).GetSEId().IsVetoShield();
00530 
00531 }
00532 
00533 //_____________________________________________________________________________
00534 StripEnd::StripEnd_t PlexSEIdAltL::GetEnd(Bool_t reportError) const
00535 {
00536    // Return the end (kEast,kWest) of the PlexStripEndID's in this list.
00537    // This is meaningful only in a correctly cabled detector
00538    // if there are mis-cablings then it could return nonsense.
00539 
00540    TestConsistency(reportError);
00541 
00542    if ( fError & kBadEnd || size() < 1 ) 
00543       return StripEnd::kUnknown;  // bad end
00544 
00545    PlexSEIdAltLConstIter cursor = this->begin();
00546    return (*cursor).GetSEId().GetEnd();
00547 
00548 }
00549 
00550 //_____________________________________________________________________________
00551 Int_t PlexSEIdAltL::GetPlane(Bool_t reportError) const
00552 {
00553    // Return the plane # of the PlexStripEndId's in this list.
00554    // This is meaningful only in a correctly cabled detector
00555    // if there are mis-cablings then it could return nonsense.
00556 
00557    TestConsistency(reportError);
00558 
00559    if ( fError & kBadPlane || size() < 1 )
00560       return -1;  // bad plane
00561 
00562    PlexSEIdAltLConstIter cursor = this->begin();
00563    return (*cursor).GetSEId().GetPlane();
00564 
00565 }
00566 
00567 
00568 //_____________________________________________________________________________
00569 PlaneView::PlaneView_t PlexSEIdAltL::GetPlaneView(Bool_t reportError) const
00570 {
00571    // Return the PlaneView of the PlexStripEndID's in this list.
00572    // This is meaningful only in a correctly cabled detector
00573    // if there are mis-cablings then it could return nonsense.
00574 
00575    TestConsistency(reportError);
00576 
00577    if ( fError & kBadPlaneView || size() < 1 )
00578       return PlaneView::kUnknown;  // bad view
00579 
00580    PlexSEIdAltLConstIter cursor = this->begin();
00581    return (*cursor).GetSEId().GetPlaneView();
00582 
00583 }
00584 
00585 //_____________________________________________________________________________
00586 Bool_t PlexSEIdAltL::SetToOppositeEnds(PlexSEIdAltL& that)
00587 {
00588    // Given two PlexSEIdAltL's set both "current" iterators
00589    // to entries that are at opposite ends of the same strip
00590    // and return true.  If no legal combination exists then
00591    // return false leaving current positions unchanged.
00592 
00593    UInt_t where_this =      fCurrent;
00594    UInt_t where_that = that.fCurrent;
00595 
00596    this->SetFirst();
00597    while (this->IsValid()) {
00598       PlexStripEndId seid_this = this->GetCurrentSEId();
00599       that.SetFirst();
00600       while (that.IsValid()) {
00601          PlexStripEndId seid_that = that.GetCurrentSEId();
00602          if (seid_this.IsOppositeStripEnd(seid_that)) return true;
00603          that.Next();
00604       }
00605       this->Next();
00606    }
00607    // fell through means no legal match
00608    fCurrent      = where_this;
00609    that.fCurrent = where_that;
00610    return false;
00611 
00612 }
00613 //_____________________________________________________________________________
00614 Bool_t PlexSEIdAltL::IsValid() const
00615 {
00616    // is current position a valid entry
00617 
00618   return size()>0 && fCurrent<size(); 
00619 
00620 }
00621 
00622 //_____________________________________________________________________________
00623 void PlexSEIdAltL::Print(Option_t *option) const
00624 {
00625    // Print out the list
00626 
00627    unsigned int n = size();
00628 
00629    if (n <= 0) {
00630       printf("Empty PlexSEIdAltL\n");
00631       return;
00632    }
00633 
00634    const PlexSEIdAltLItem& best = GetBestItem();
00635 
00636    const PlexSEIdAltL& self = *this;
00637    unsigned int i;
00638    char cursormarker, bestmarker;
00639    PlexStripEndId seid;
00640 //   Float_t        weight;
00641 
00642    switch (option[0]) {
00643    case 'c':
00644    case 'C':
00645       // compact notation assumes that there isn't a mixup
00646       // and all items share a common detector/plane/subpart/end
00647       seid = GetCurrentSEId(); // any will do
00648       printf("[%1.1s|%4d %1.1s%1.1s|%1.1s%1.1s]",
00649              Detector::AsString(seid.GetDetector()),
00650              seid.GetPlane(),
00651              PlaneView::AsString(seid.GetPlaneView()),
00652              PlaneCoverage::AsString(seid.GetPlaneCoverage()),
00653              StripEnd::AsString(seid.GetSubPart()),
00654              StripEnd::AsString(seid.GetEnd()));
00655       for (i=0; i<n; i++) {
00656          const PlexSEIdAltLItem& item = self[i];
00657          bestmarker   = (item == best)     ? '!' : ' ';
00658          cursormarker = (i    == fCurrent) ? '@' : ' ';
00659          seid   = item.GetSEId();
00660          printf(" %c%c%3d",bestmarker,cursormarker,seid.GetStrip());
00661 
00662       }
00663       if (option[0] == 'C') {
00664          printf("\n          wgt ");
00665          for (i=0; i<n; i++) {
00666             const PlexSEIdAltLItem& item = self[i];
00667             printf(" %5.3f",item.GetWeight());
00668          }
00669       }
00670       printf("\n");
00671 
00672       break;
00673    default:
00674 
00675      cout << *this;
00676 
00677    }
00678 }
00679 
00680 //_____________________________________________________________________________
00681 void PlexSEIdAltL::SetCurrentWeight(Float_t weight)
00682 {
00683    // set the weight attached to the current PlexStripEndId
00684 
00685    if (!IsValid()) return; // no list or out of range
00686    PlexSEIdAltLIter cursor = this->begin() + fCurrent;
00687    (*cursor).SetWeight(weight);
00688 
00689 }
00690 
00691 //_____________________________________________________________________________
00692 void PlexSEIdAltL::AddToCurrentWeight(Float_t wgtadd)
00693 {
00694    // add to the weight attached to the current PlexStripEndId
00695 
00696    if (!IsValid()) return; // no list or out of range
00697    PlexSEIdAltLIter cursor = this->begin() + fCurrent;
00698    (*cursor).AddToWeight(wgtadd);
00699 
00700 }
00701 
00702 //_____________________________________________________________________________
00703 void PlexSEIdAltL::NormalizeWeights(Float_t wgtsum)
00704 {
00705    // normalize the weights so sum adds up to "wgtsum"
00706    // if all values are exactly zero, then this sets them
00707    // to wgtsum/fSize
00708 
00709    unsigned int n=size();
00710 
00711    if (n < 1) return;
00712 
00713    Float_t sum = 0.0;
00714 
00715    PlexSEIdAltLIter iter, the_end=this->end();
00716 
00717    iter = this->begin();
00718    while (iter != the_end) { sum += (*iter).GetWeight(); iter++; }
00719 
00720    iter = this->begin();
00721    if ( sum != 0.0 ) {
00722       Float_t scale = wgtsum/sum;
00723       while (iter != the_end) {
00724          Float_t wgt = (*iter).GetWeight() * scale;
00725          (*iter).SetWeight(wgt);
00726          iter++;
00727       }
00728    } else {
00729       // all weight values were zero
00730       Float_t equalwgt = wgtsum/(float)n;
00731       while (iter != the_end) { (*iter).SetWeight(equalwgt); iter++; }
00732    }
00733 
00734 }
00735 
00736 //_____________________________________________________________________________
00737 
00738 void PlexSEIdAltL::TestConsistency(Bool_t reportError) const
00739 {
00740    // Set the fError flag if the list is inconsistent
00741    // in terms of GetDetector, GetEnd, GetPlane, GetPlaneView
00742 
00743    // skip if already checked (adding values clears this flag)
00744    if ( kUnchecked != fError ) return;
00745 
00746    // clear all errors
00747    fError = 0;
00748 
00749    unsigned int n = size();
00750 
00751    // a single entry is consistent with itself
00752    if ( 1 == n ) return;
00753 
00754    // an empty list is consistent with nothing
00755    // and asking for these value will be problematic
00756    if ( 0 == n ) {
00757       fError = kBadDetector | kBadEnd | kBadPlane | kBadPlaneView;
00758       return;
00759    }
00760 
00761    PlexSEIdAltLConstIter iter = this->begin();
00762    PlexSEIdAltLConstIter the_end = this->end();
00763 
00764    PlexStripEndId first_seid = (*iter).GetSEId();
00765    Detector::Detector_t     firstdet = first_seid.GetDetector();
00766    StripEnd::StripEnd_t     firstend = first_seid.GetEnd();
00767    Int_t                    firstpln = first_seid.GetPlane();
00768    PlaneView::PlaneView_t   firstpvw = first_seid.GetPlaneView();
00769    Bool_t                   firstisv = first_seid.IsVetoShield();
00770 
00771    iter++;  // no need to recheck the first against itself
00772    while (iter != the_end) {
00773       PlexStripEndId alt_seid = (*iter).GetSEId();
00774       Detector::Detector_t     altdet = alt_seid.GetDetector();
00775       StripEnd::StripEnd_t     altend = alt_seid.GetEnd();
00776       Int_t                    altpln = alt_seid.GetPlane();
00777       PlaneView::PlaneView_t   altpvw = alt_seid.GetPlaneView();
00778       Bool_t                   altisv = alt_seid.IsVetoShield();
00779       if ( altdet != firstdet ) fError |= kBadDetector;
00780       if ( altend != firstend ) fError |= kBadEnd;
00781       // veto shield connections span modules (and thus "planes"
00782       // and "planeviews")
00783       if ( ! altisv ) {
00784         if ( altpln != firstpln ) fError |= kBadPlane;
00785         if ( altpvw != firstpvw ) fError |= kBadPlaneView;
00786       }
00787       if ( altisv != firstisv ) fError |= kBadIsVeto;
00788       iter++;
00789    }
00790    
00791    if ( fError != kOkay && reportError ) {
00792       MSG("Plex",Msg::kWarning)
00793          << "PlexSEIdAltL::TestConsistency - list is inconsistent " 
00794          << "(0x" << hex << setfill('0') << setw(2) << fError
00795          << setfill(' ') << dec << ")" << endl;
00796 
00797       UInt_t old_fmt = GetFmtFlag();
00798       SetFmtFlag(fmt_Index|fmt_StripEnd|fmt_PixelSpot);
00799       this->Print();
00800       SetFmtFlag(old_fmt);
00801    }
00802 
00803 }
00804 
00805 //_____________________________________________________________________________

Generated on Fri Mar 28 15:37:42 2008 for loon by  doxygen 1.3.9.1