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

AlgStripSRList.cxx

Go to the documentation of this file.
00001 
00002 // $Id: AlgStripSRList.cxx,v 1.37 2010/01/06 18:27:37 rhatcher Exp $
00003 //
00004 // AlgStripSRList.cxx
00005 //
00006 // Begin_Html<img src="../../pedestrians.gif" align=center>
00007 // <a href="../source_warning.html">Warning for beginners</a>.<br> 
00008 //
00009 // AlgStripSRList is a concrete StripSRList Algorithm class.
00010 //
00011 // Author:  R. Lee 2001.01.23
00012 //
00013 // Also see <a href="../../root_crib/index.html">The ROOT Crib</a> and 
00014 // <a href="../CandStrip.html"> CandStrip Classes</a> (part of
00015 // <a href="../index.html">The MINOS Class User Guide</a>)End_Html
00017 
00018 #include <cassert>
00019 #include <cmath>
00020 
00021 #include <iostream>
00022 using namespace std;
00023 
00024 #include "TROOT.h"
00025 
00026 #include "Algorithm/AlgFactory.h"
00027 #include "Algorithm/AlgHandle.h"
00028 #include "Algorithm/AlgConfig.h"
00029 #include "CandDigit/CandDigitHandle.h"
00030 #include "CandDigit/CandDigitListHandle.h"
00031 #include "Candidate/CandContext.h"
00032 #include "CandStripSR/StripSRListModule.h"
00033 #include "CandStripSR/AlgStripSRList.h"
00034 #include "RecoBase/CandStrip.h"
00035 #include "RecoBase/CandStripHandle.h"
00036 #include "RecoBase/CandStripList.h"
00037 #include "RecoBase/CandStripListHandle.h"
00038 #include "Conventions/Munits.h"
00039 #include "MessageService/MsgService.h"
00040 #include "MinosObjectMap/MomNavigator.h"
00041 #include "Navigation/NavKey.h"
00042 #include "Navigation/NavSet.h"
00043 #include "RawData/RawDigit.h"
00044 #include "RawData/RawHeader.h"
00045 #include "RawData/RawRecord.h"
00046 #include "RawData/RawChannelId.h"
00047 #include "RawData/RawDigitDataBlock.h"
00048 #include "RawData/RawDaqSnarlHeader.h"
00049 #include "RawData/RawDaqHeaderBlock.h"
00050 #include "RawData/RawDigitDataBlock.h"
00051 #include "Validity/VldContext.h"
00052 #include "DataUtil/GetRawBlock.h"
00053 
00054 ClassImp(AlgStripSRList)
00055 
00056 static NavKey StripSRKeyFromPSEId(const CandDigitHandle *);
00057 static NavKey StripSRKeyFromTime(const CandDigitHandle *);
00058 static NavKey StripSRKeyFromTube(const CandDigitHandle *);
00059 
00060 //______________________________________________________________________
00061 
00062 CVSID("$Id: AlgStripSRList.cxx,v 1.37 2010/01/06 18:27:37 rhatcher Exp $");
00063 
00064 //______________________________________________________________________
00065 AlgStripSRList::AlgStripSRList(): fNoiseStatsSet(false)
00066 {
00067 }
00068 //_______________________________________________________________________
00069 AlgStripSRList::~AlgStripSRList()
00070 {
00071 }
00072 
00073 //______________________________________________________________________
00074 
00077 void AlgStripSRList::RunAlg(AlgConfig &ac, CandHandle &ch,CandContext &cx)
00078 {
00079    assert(cx.GetDataIn());
00080 // Check for CandDigitListHandle input
00081    if (cx.GetDataIn()->InheritsFrom("CandDigitListHandle")) {
00082       const CandDigitListHandle *cdlh =
00083             dynamic_cast<const CandDigitListHandle*>(cx.GetDataIn());
00084       const MomNavigator *mom = cx.GetMom();
00085 
00086       const RawDigitDataBlock *rddb = 
00087                 DataUtil::GetRawBlock<RawDigitDataBlock>(mom);
00088       if (!rddb) {
00089         MSG("AlgStripSRList", Msg::kWarning) << "No RawDigitDataBlock in RawRecord." << endl;
00090         return;
00091       }
00092       TIter digitItr(cdlh->GetDaughterIterator());
00093       Bool_t found(0);
00094       CandDigitHandle *digit = dynamic_cast<CandDigitHandle*>(digitItr());
00095       switch (cdlh->GetVldContext()->GetDetector()) {
00096       case Detector::kNear:
00097         RunAlgNear(ac,ch,cx);
00098         break;
00099       case Detector::kFar:
00100         RunAlgFar(ac,ch,cx);
00101         break;
00102       case Detector::kCalib:
00103          // need to check if far or near electronics
00104         while (digit && !found) {
00105           const RawDigit *rd = rddb->At(digit->GetRawDigitIndex());
00106           assert(rd);
00107           RawChannelId rawid = rd->GetChannel();
00108           if (rawid.GetElecType()==ElecType::kQIE) found=1;
00109           digit = dynamic_cast<CandDigitHandle*>(digitItr());
00110         }
00111         if (found) {
00112           RunAlgMixed(ac,ch,cx);
00113         } else {
00114           RunAlgFar(ac,ch,cx);
00115         }
00116         break;
00117       default:
00118         break;
00119       }
00120    }
00121 }
00122 
00123 //______________________________________________________________________
00128 void AlgStripSRList::RunAlgMixed(AlgConfig &ac, CandHandle &ch,CandContext &cx)
00129 {
00130 
00131    const CandDigitListHandle *cdlh =
00132          dynamic_cast<const CandDigitListHandle*>(cx.GetDataIn());
00133 
00134    // load parameters
00135    Double_t ldtime = ac.GetDouble("MaxLocTimeSep");
00136    Double_t gdtime = ac.GetDouble("MaxGloTimeSep");
00137    Int_t begplane = ac.GetInt("BegPlane");
00138    Int_t endplane = ac.GetInt("EndPlane");
00139    CalTimeType::CalTimeType_t caltimetype = (CalTimeType::CalTimeType_t)(ac.GetInt("CalTimeType"));
00140    
00141    /*CandDigits are sorted by plane, strip. */
00142 
00143    CandDigitHandleItr cdhItr(cdlh->GetDaughterIterator());
00144    CandDigitHandleKeyFunc *cdhKf = cdhItr.CreateKeyFunc();
00145    cdhKf->SetFun(StripSRKeyFromPSEId);
00146    cdhItr.GetSet()->AdoptSortKeyFunc(cdhKf);
00147    cdhKf = 0;
00148 
00149    AlgFactory &af = AlgFactory::GetInstance();
00150    AlgHandle ah = af.GetAlgHandle("AlgStripSR","default");
00151    CandContext cxx(this,cx.GetMom());
00152 
00153    /* Nested passes are made through the sorted list. The outer loop constructs an array of candigits  until a new strip id is seen. The inner loop is then made over this list of digits, which is sorted by time.  */
00154    CandDigitHandle *prev = 0;
00155    CandDigitHandle *first = 0;
00156    TObjArray cdhAr;
00157    cdhAr.Clear();
00158    TObjArray digitlist;
00159    digitlist.Clear();
00160    while (CandDigitHandle *curr = cdhItr()) {
00161      PlexSEIdAltL pseid = curr->GetPlexSEIdAltL();
00162      if (pseid.GetPlane()>=begplane && 
00163          pseid.GetPlane()<=endplane &&
00164          pseid.GetSize()>0) {
00165        if (prev) {
00166          PlexStripEndId pSEId = prev->GetPlexSEIdAltL().GetBestSEId();
00167          PlexStripEndId cSEId = curr->GetPlexSEIdAltL().GetBestSEId();
00168          if (pSEId.IsSameStrip(cSEId)) {
00169            digitlist.Add(curr);
00170          } else {
00171            TIter digitItr(&digitlist);
00172            CandDigitHandleItr timeItr(digitItr);
00173            CandDigitHandleKeyFunc *timeItrKf = timeItr.CreateKeyFunc();
00174            timeItrKf->SetFun(StripSRKeyFromTime);
00175            timeItr.GetSet()->AdoptSortKeyFunc(timeItrKf);
00176            timeItrKf = 0;
00177            first = 0;
00178            cdhAr.Clear();
00179            CandDigitHandle *prevdigit = 0;
00180            /* we check that adjacent entries are within the tolerances set by the variables MaxLocTimeSep and MaxGloTimeSep.  The first variable is used to check that no large time gaps occur within a CandStrip, and the second is used to ensure that the total duration of a CandStrip is sensible.*/
00181            while (CandDigitHandle *digit = timeItr()) {
00182              if (!first) {
00183                first = digit;
00184                cdhAr.Add(digit);
00185              } else if (digit->GetTime(caltimetype)-prevdigit->GetTime(caltimetype)<ldtime && 
00186                         digit->GetTime(caltimetype)-first->GetTime(caltimetype)<gdtime) {
00187                // CandDigit satisfies the requirements above, so add to the CandStrip. 
00188                cdhAr.Add(digit);
00189              } else {
00190                // else done, build this CandStrip
00191                cxx.SetDataIn(&cdhAr);
00192                CandStripHandle csh = CandStrip::MakeCandidate(ah,cxx);
00193                ch.AddDaughterLink(csh);
00194                cdhAr.Clear();
00195                cdhAr.Add(digit);
00196                first = digit;
00197              }
00198              prevdigit = digit;
00199            }
00200            if (cdhAr.GetSize()>=0) {
00201              cxx.SetDataIn(&cdhAr);
00202              CandStripHandle csh = CandStrip::MakeCandidate(ah,cxx);
00203              ch.AddDaughterLink(csh);
00204              cdhAr.Clear();
00205            }
00206            digitlist.Clear();
00207            digitlist.Add(curr);
00208          }
00209        } else {
00210          digitlist.Add(curr);
00211        }
00212        prev = curr;
00213      }
00214    }
00215  
00216    // final cleanup of digitlist to find remaining CandStrips
00217   if (digitlist.GetSize()>=0) {
00218      TIter digitItr(&digitlist);
00219      CandDigitHandleItr timeItr(digitItr);
00220      CandDigitHandleKeyFunc *timeItrKf = timeItr.CreateKeyFunc();
00221      timeItrKf->SetFun(StripSRKeyFromTime);
00222      timeItr.GetSet()->AdoptSortKeyFunc(timeItrKf);
00223      timeItrKf = 0;
00224      first = 0;
00225      cdhAr.Clear();
00226      CandDigitHandle *prevdigit = 0;
00227      while (CandDigitHandle *digit = timeItr()) {
00228        if (!first) {
00229          first = digit;
00230          cdhAr.Add(digit);
00231        } else if (digit->GetTime(caltimetype)-prevdigit->GetTime(caltimetype)<ldtime && 
00232                   digit->GetTime(caltimetype)-first->GetTime(caltimetype)<gdtime) {
00233          cdhAr.Add(digit);
00234        } else {
00235          cxx.SetDataIn(&cdhAr);
00236          CandStripHandle csh = CandStrip::MakeCandidate(ah,cxx);
00237          ch.AddDaughterLink(csh);
00238          cdhAr.Clear();
00239          cdhAr.Add(digit);
00240          first = digit;
00241        }
00242        prevdigit = digit;
00243      }
00244      if (cdhAr.GetSize()>=0) {
00245        cxx.SetDataIn(&cdhAr);
00246        CandStripHandle csh = CandStrip::MakeCandidate(ah,cxx);
00247        ch.AddDaughterLink(csh);
00248        cdhAr.Clear();
00249      }
00250      digitlist.Clear();
00251    }
00252 
00253 }
00254 
00255 //______________________________________________________________________
00260 void AlgStripSRList::RunAlgNear(AlgConfig &ac, CandHandle &ch,CandContext &cx)
00261 {
00262 
00263    // NOTE: for the present, do not remove xtalk from ND data.
00264    // load parameters
00265    Double_t ldtime;
00266    Double_t gdtime;
00267    Double_t timewin;
00268    
00269 // N. Saoulidou (niki@fnal.gov), 10-24-05. This time cut is introduced in order to exclude 
00270 // from the strip making process, digits that appear within xxx microseconds after a strip
00271 // has already been formed  in the same physical location (the same electronics channel).
00272  
00273    timewin = ac.GetDouble("TimeWin");
00274    ldtime  = ac.GetDouble("MaxLocTimeSep");
00275    gdtime  = ac.GetDouble("MaxGloTimeSep");
00276    Int_t    begplane = ac.GetInt("BegPlane");
00277    Int_t    endplane = ac.GetInt("EndPlane");
00278    Bool_t doNoiseNear=ac.GetInt("DoNoiseNear");
00279    Bool_t doNoiseStats=ac.GetInt("DoNoiseStats");
00280    Double_t nearNoiseAdc=ac.GetDouble("NearNoiseAdc");
00281   
00282    StripStat *NoiseStats=0;
00283    if (doNoiseNear&&doNoiseStats|| !fNoiseStatsSet)
00284    {
00285         NoiseStats=FindWhiteBoardStats(nearNoiseAdc);
00286    }
00287      
00288    //   Double_t maxAdjPixelChargeFraction = ac.GetDouble("AdjPixelChargeFraction");
00289    // Mike Kordosky : Jan 19, 2005 ... noticed while browsing
00290    // see comment on xtalkmap below
00291    // Double_t timewindow=ac.GetDouble("MaxXtalkTimeWindow");
00292 
00293    const CandDigitListHandle *cdlh =
00294          dynamic_cast<const CandDigitListHandle*>(cx.GetDataIn());
00295 
00296    /*  CandDigits are sorted by plane, strip, and time, which ensures that CandDigits wwhich will be associated into CandStrips occupy adjacent entries in this sorted list, and that the CandDigit with the earliest time in a given strip and plane will appear first.
00297     */
00298 
00299    CandDigitHandleItr cdhItr(cdlh->GetDaughterIterator());
00300    CandDigitHandleKeyFunc *cdhKf = cdhItr.CreateKeyFunc();
00301    
00302    //Rustem Ospanov: fixing NavKey bug 2005.01.20
00303    //Create NavKey for sorting by encoded PlexStripEndId
00304    //Do not sort until time NavKey is adopted
00305    cdhKf->SetFun(StripSRKeyFromPSEId);
00306    cdhItr.GetSet()->AdoptSortKeyFunc(cdhKf, kTRUE, kFALSE);
00307 
00308    //Created NavKey for sorting by time
00309    cdhKf = cdhItr.CreateKeyFunc();
00310    cdhKf -> SetFun(StripSRKeyFromTime);
00311 
00312    //Sort CandDigits first by encoded PlexStripEndId and then by time
00313    cdhItr.GetSet()->AdoptSortKeyFunc(cdhKf, kFALSE);
00314    cdhKf = 0;
00315 
00316 
00317 // Get singleton instance of AlgFactory
00318    AlgFactory &af = AlgFactory::GetInstance();
00319 
00320 // Get an AlgHandle to AlgStripSR with default AlgConfig
00321    AlgHandle ah = af.GetAlgHandle("AlgStripSR","default");
00322 
00323 // Create Candcontext
00324    CandContext cxx(this,cx.GetMom());
00325 
00326 // Iterate over CandDigitList daughters
00327    CandDigitHandle *prev = 0;
00328    CandDigitHandle *first = 0;
00329    TObjArray cdhAr;
00330    cdhAr.Clear();
00331 
00332    CalTimeType::CalTimeType_t caltimetype = (CalTimeType::CalTimeType_t)(ac.GetInt("CalTimeType"));
00333 
00334    // generate map containing ratio of digitization charge to 
00335    // xtalk charge associated with each digitization.
00336    // xtalk is defined to be the charge seen in adjacent pixels.  Diagonal
00337    // pixels are not included. 
00338 
00339    // Mike Kordosky : Jan 19, 2005 ... noticed while browsing
00340    // Why waste time making the map below if it's never used?
00341    // map<CandDigitHandle*,float> xtalkmap = MakeXtalkMap(cdlh,timewindow);
00342 
00343 
00344    /* One pass is made through the sorted list, checking for identical strip/plane values in adjacent entries, and checking that the time is within the tolerances set by the variables MaxLocTimeSep and MaxGloTimeSep.  The first variable is used to check that no large time gaps occur within a CandStrip, and the second is used to ensure that the total duration of a CandStrip is sensible.  If this occurs, and the CandDigit satisfies the requirements above, the CandDigits are added to the CandStrip.   */
00345    TObjArray cdhAru;
00346    cdhAru.Clear();
00347    
00348    while (CandDigitHandle *curr = cdhItr()) {
00349     
00350      PlexSEIdAltL pseid = curr->GetPlexSEIdAltL();     
00351      Bool_t dig_notprev  =true;
00352      Bool_t dig_notprev2 =true;
00353      PlexStripEndId pseid1 = curr->GetPlexSEIdAltL().GetBestSEId();     
00354      Bool_t isfirst2=false;
00355      
00356      for(Int_t i=0;i<cdhAru.GetLast()+1;i++){
00357       CandDigitHandle *prevv=dynamic_cast<CandDigitHandle*>(cdhAru.At(i));
00358       PlexStripEndId pseid2 = prevv->GetPlexSEIdAltL().GetBestSEId();      
00359       if( pseid1.IsSameStrip(pseid2) && isfirst2==false){
00360        isfirst2=true;
00361        Double_t timediff=curr->GetTime(caltimetype)-prevv->GetTime(caltimetype);
00362        if(timediff<timewin) dig_notprev=false;       
00363       }
00364      }       
00365      
00366      if (pseid.GetPlane()>=begplane && pseid.GetPlane()<=endplane && pseid.GetSize()>0&& dig_notprev) {
00367        if (prev) {
00368          PlexStripEndId pSEId = prev->GetPlexSEIdAltL().GetBestSEId();
00369          PlexStripEndId cSEId = curr->GetPlexSEIdAltL().GetBestSEId();
00370          if (pSEId.IsSameStrip(cSEId) &&
00371              curr->GetTime(caltimetype)-prev->GetTime(caltimetype)<ldtime && 
00372              curr->GetTime(caltimetype)-first->GetTime(caltimetype)<gdtime) {
00373            cdhAr.Add(curr);
00374          } 
00375          else {    
00376         
00377             for(Int_t ii=0;ii<cdhAr.GetLast()+1;ii++){       
00378               cdhAru.Add(cdhAr.At(ii));       
00379             }    
00380            if (!doNoiseNear || PassNearNoise(&cdhAr,nearNoiseAdc,NoiseStats)) { 
00381             //cout << " I AM LETTING IT " << endl;
00382             cxx.SetDataIn(&cdhAr);
00383             CandStripHandle csh = CandStrip::MakeCandidate(ah,cxx);
00384             ch.AddDaughterLink(csh);
00385            }       
00386            cdhAr.Clear();
00387            dig_notprev2=true;      
00388            Bool_t isfirst=false;
00389           
00390            for(Int_t i=0;i<cdhAru.GetLast()+1;i++){
00391              CandDigitHandle *prevv=dynamic_cast<CandDigitHandle*>(cdhAru.At(i));
00392              PlexStripEndId pseid2 = prevv->GetPlexSEIdAltL().GetBestSEId();
00393              if(pseid1.IsSameStrip(pseid2) && isfirst==false){
00394              isfirst=true;
00395              Double_t timediff2=curr->GetTime(caltimetype)-prevv->GetTime(caltimetype);
00396              if(timediff2<timewin) {
00397               dig_notprev2=false;             
00398              }
00399             }
00400            }
00401            if(dig_notprev2) {
00402             cdhAr.Add(curr);
00403             first=curr;
00404            }
00405          }
00406        } // end if if previous  
00407        else {
00408          cdhAr.Add(curr);
00409          first = curr;
00410        }
00411        if(dig_notprev2)       prev = curr;
00412        else if(!dig_notprev2) prev=0;
00413      }
00414    }
00415    
00416    if (prev) {
00417       if ( !doNoiseNear || PassNearNoise(&cdhAr,nearNoiseAdc,NoiseStats) )
00418       {
00419       cxx.SetDataIn(&cdhAr);
00420       CandStripHandle csh = CandStrip::MakeCandidate(ah,cxx);
00421       ch.AddDaughterLink(csh);
00422    }
00423   }
00424 
00425 }
00426 
00427 //______________________________________________________________________
00431 void AlgStripSRList::RunAlgFar(AlgConfig &ac, CandHandle &ch,CandContext &cx)
00432 {
00433   MSG("Alg", Msg::kDebug)
00434                           << "Starting AlgStripSRList::RunAlgFar()" << endl;
00435 
00436   const CandDigitListHandle *cdlh =
00437         dynamic_cast<const CandDigitListHandle*>(cx.GetDataIn());
00438   const MomNavigator *mom = cx.GetMom();
00439 
00440   const RawDigitDataBlock *rddb = 
00441     DataUtil::GetRawBlock<RawDigitDataBlock>(mom);
00442   if (!rddb) {                                         
00443     MSG("StripSR", Msg::kWarning) << "No RawDigitDataBlock in RawRecord." << endl;
00444     return;
00445   }
00446  
00447   Int_t begplane = ac.GetInt("BegPlane");
00448   Int_t endplane = ac.GetInt("EndPlane");
00449   Double_t maxAdjPixelChargeFraction = ac.GetDouble("AdjPixelChargeFraction");
00450   Double_t timewindow=ac.GetDouble("MaxXtalkTimeWindow");
00451 
00452   // generate map containing ratio of digitization charge to 
00453   // xtalk charge associated with each digitization.
00454   // xtalk is defined to be the charge seen in adjacent pixels.  Diagonal
00455   // pixels are not included. 
00456 
00457   map<CandDigitHandle*,float> xtalkmap = MakeXtalkMap(cdlh, timewindow);
00458 
00459   /*  CandDigits are sorted by plane and strip, which ensures that CandDigits which will be  associated into CandStrips occupy adjacent entries in this sorted list. */
00460    CandDigitHandleItr cdhItr(cdlh->GetDaughterIterator());
00461    CandDigitHandleKeyFunc *cdhKf = cdhItr.CreateKeyFunc();
00462    cdhKf->SetFun(StripSRKeyFromPSEId);
00463    cdhItr.GetSet()->AdoptSortKeyFunc(cdhKf);
00464    cdhKf = 0;
00465 
00466    AlgFactory &af = AlgFactory::GetInstance();
00467    AlgHandle ah = af.GetAlgHandle("AlgStripSR","default");
00468    CandContext cxx(this,cx.GetMom());
00469 
00470    /*
00471  One pass is made through the sorted list, checking for identical strip/plane values in adjacent entries.  If this occurs, and the CandDigit satisfies the requirements above, the CandDigits are added to the CandStrip.
00472    */
00473 
00474    CandDigitHandle *prev = 0;
00475    TObjArray cdhAr;
00476    cdhAr.Clear();
00477    while (CandDigitHandle *curr = cdhItr()) {
00478      if (curr->GetPlexSEIdAltL().GetPlane()>=begplane &&
00479          curr->GetPlexSEIdAltL().GetPlane()<=endplane &&
00480          xtalkmap[curr]>=maxAdjPixelChargeFraction &&
00481          !curr->GetPlexSEIdAltL().IsVetoShield() &&
00482          !curr->GetPlexSEIdAltL().GetDemuxVetoFlag() &&
00483          curr->GetPlexSEIdAltL().GetSize()>0) {
00484        if (prev) {
00485          PlexStripEndId pSEId = prev->GetPlexSEIdAltL().GetBestSEId();
00486          PlexStripEndId cSEId = curr->GetPlexSEIdAltL().GetBestSEId();
00487          if (pSEId.IsSameStrip(cSEId)) {
00488             cdhAr.Add(curr);
00489          } else {
00490             cxx.SetDataIn(&cdhAr);
00491             CandStripHandle csh = CandStrip::MakeCandidate(ah,cxx);
00492             ch.AddDaughterLink(csh);
00493             cdhAr.Clear();
00494             cdhAr.Add(curr);
00495          }
00496       } else {
00497          cdhAr.Add(curr);
00498       }
00499       prev = curr;
00500      }
00501    }
00502    if (prev) {
00503       cxx.SetDataIn(&cdhAr);
00504       CandStripHandle csh = CandStrip::MakeCandidate(ah,cxx);
00505       ch.AddDaughterLink(csh);
00506    }
00507 
00508 
00509 
00510 }
00511 
00512 //---------------------------------------------
00520 map<CandDigitHandle*,float> AlgStripSRList::MakeXtalkMap(const CandDigitListHandle * cdlh, Double_t timewindow){
00521 
00522   Int_t pmtcolumnsize=4;
00523   if(cdlh->GetVldContext()->GetDetector()==Detector::kNear)pmtcolumnsize=8;
00524        
00525   map<CandDigitHandle*,float> xtalkmap;
00526 
00527   // For inner loop, select digitizations on same PMT
00528  
00529   CandDigitHandleItr digitItr2(cdlh->GetDaughterIterator());
00530   CandDigitHandleKeyFunc *cdhKf = digitItr2.CreateKeyFunc();
00531   cdhKf->SetFun(StripSRKeyFromTube);
00532   digitItr2.GetSet()->AdoptSortKeyFunc(cdhKf);
00533   cdhKf = 0;
00534 
00535   CandDigitHandleItr digitItr1(cdlh->GetDaughterIterator());
00536   while (CandDigitHandle *digit1 = dynamic_cast<CandDigitHandle*>(digitItr1())) {
00537     Int_t pixel1=digit1->GetPlexSEIdAltL().GetBestItem().GetPixelSpotId().GetPixel();
00538     Int_t tube1=digit1->GetPlexSEIdAltL().GetBestItem().GetPixelSpotId().GetUniquePmtEncodedValue();
00539     Int_t ix1 = (pixel1)%pmtcolumnsize;
00540     Int_t iy1 = (Int_t)((pixel1)/pmtcolumnsize+.5);
00541     float pixelcharge = digit1->GetCharge();
00542     float xcharge = 0;
00543 
00544     // set digitIt2 to iterate over digitizations on same tube as digitItr1
00545     // Note:  This technique turned out to be a net time sink
00546     //    digitItr2.GetSet()->ClearSlice();
00547     //  digitItr2.GetSet()->Slice(tube1);
00548     
00549     digitItr2.Reset();
00550     while (CandDigitHandle *digit2 = dynamic_cast<CandDigitHandle*>(digitItr2())) {
00551       if (digit1!=digit2) {
00552         Int_t pixel2=digit2->GetPlexSEIdAltL().GetBestItem().GetPixelSpotId().GetPixel();
00553         Int_t tube2=digit1->GetPlexSEIdAltL().GetBestItem().GetPixelSpotId().GetUniquePmtEncodedValue();
00554         // break out of loop when we have passed the tube match
00555         Int_t comptube = StripSRKeyFromTube(digit2).CompareValue(tube1);
00556         if(comptube<0) break;
00557         if(tube1==tube2){
00558           if (pixel1!=pixel2) {
00559             Int_t ix2 = (pixel2)%pmtcolumnsize;
00560             Int_t iy2 = (Int_t)((pixel2)/pmtcolumnsize+.5);
00561             if(abs(ix1-ix2)+abs(iy1-iy2)==1 && 
00562                fabs(digit1->GetTime()-digit2->GetTime())<timewindow){
00563               xcharge += digit2->GetCharge();
00564             }
00565           }
00566           else if((pixel1==pixel2) &&
00567                   fabs(digit1->GetTime()-digit2->GetTime())<timewindow ){
00568             pixelcharge +=digit2->GetCharge();
00569           }
00570         }
00571       }
00572     }//end inner loop over digits to find xtalk
00573     if(xcharge+pixelcharge != 0.) xtalkmap[digit1] = pixelcharge/(xcharge+pixelcharge);
00574     else xtalkmap[digit1] = 0.;
00575   }//end loop over digit
00576   return xtalkmap;
00577 }
00578 
00579 //______________________________________________________________________
00580 void AlgStripSRList::Trace(const char * /* c */) const
00581 {
00582 }
00583 
00584 NavKey StripSRKeyFromPSEId(const CandDigitHandle *cdh)
00585 {
00586 //
00587 //  Purpose:  Generate a sort key based on the encoded strip end ID of
00588 //            a CandDigit.
00589 //
00590 //  Arguments:
00591 //    cdh        in    Handle to CandDigit to be sorted.
00592 //
00593 //  Return:   Encoded strip end ID.
00594 //
00595 
00596    return const_cast<CandDigitHandle *>(cdh)->GetPlexSEIdAltL()
00597                                       .GetBestSEId().GetEncoded();
00598 }
00599 
00600 
00601 NavKey StripSRKeyFromTime(const CandDigitHandle *cdh)
00602 {
00603 //
00604 //  Purpose:  Generate a sort key based on the encoded strip end ID and
00605 //            time of a CandDigit.
00606 //
00607 //  Arguments:
00608 //    cdh        in    Handle to CandDigit to be sorted.
00609 //
00610 //  Return:   Encoded strip end ID.
00611 //
00612 
00613 // Get Singleton instance of AlgFactory.
00614   AlgFactory &af = AlgFactory::GetInstance();
00615   AlgHandle adf = af.GetAlgHandle("AlgStripSRList","default");
00616   AlgConfig &ac = adf.GetAlgConfig(); 
00617 
00618   CalTimeType::CalTimeType_t caltimetype = (CalTimeType::CalTimeType_t)(ac.GetInt("CalTimeType"));
00619  
00620    Double_t time = cdh->GetTime(caltimetype);
00621    Int_t itime = static_cast<Int_t>((time/(1.*Munits::ns))+.5);
00622 
00623    Int_t navkey = itime;
00624    return navkey;
00625 }
00626 
00627 NavKey StripSRKeyFromTube(const CandDigitHandle *cdh)
00628 {
00629 //
00630 //  Purpose:  Generate a sort key based on the unique PMT id
00631 //           
00632 //
00633 //  Arguments:
00634 //    cdh        in    Handle to CandDigit to be sorted.
00635 //
00636 //  Return:   PMT id
00637 //
00638  
00639   Int_t navkey=cdh->GetPlexSEIdAltL().GetBestItem().GetPixelSpotId().GetUniquePmtEncodedValue();
00640    return navkey;
00641 }
00642 Bool_t AlgStripSRList::PassNearNoise(TObjArray* cdhAr, Float_t adcMin,
00643                         StripStat* stats)
00644 {
00645 
00646 
00647         Int_t ndig=cdhAr->GetEntriesFast();
00648         
00649         
00650         
00651         CandDigitHandle *cdh=(CandDigitHandle*)cdhAr->First();
00652 
00653         Float_t q=cdh->GetCharge(CalDigitType::kNone);
00654 
00655         //cout << " I am getting the entries in pass near noise " << ndig << " charge  " << q  << endl;
00656 
00657         RawChannelId rcid=cdh->GetChannelId();
00658         rcid.ClearModeBits();
00659 
00660         Bool_t isnoise=( 1 == ndig  && q < adcMin) ;
00661 
00662         MSG("AlgStripSRList", Msg::kDebug) <<
00663         " encoutered RawChannelId:"<<rcid<<
00664         " ndig="<<ndig << 
00665         " ADC="<<q << 
00666         " Noise=="<<isnoise << endl;
00667 
00668         if ( stats ) stats->Add(rcid,isnoise);
00669 
00670         return !isnoise;
00671 
00672 
00673 
00674 }
00675 StripStat* AlgStripSRList::FindWhiteBoardStats(Double_t adcMin)
00676 {
00677 
00678 // from George Irwin/Brian Rebel:
00679 // Find the StripStat object or create one for needed scratch space
00680         StripStat *stats = dynamic_cast<StripStat*>(gROOT->GetRootFolder()->
00681         FindObject("Loon/CandStripSR/StripStat"));
00682         if (stats == 0) {
00683                 MSG("AlgStripSRList", Msg::kWarning)
00684                 << "//root/Loon/CandStripSR/StripStat not found,"
00685                 << " although DoNoiseStats=true"
00686                 << endl;
00687         } else if (!fNoiseStatsSet) {
00688                         // the stats copies of these parameters are for
00689                         // printing only, and don't affect the Alg
00690                 stats->fDoNoiseNear=true;
00691                 stats->fDoNoiseStats=true;
00692                 stats->fNearNoiseADC=adcMin;
00693                 fNoiseStatsSet=true;
00694         }
00695 
00696         return stats;
00697 
00698 }

Generated on Mon Feb 15 11:06:20 2010 for loon by  doxygen 1.3.9.1