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

DmxHypothesis.cxx

Go to the documentation of this file.
00001 
00002 //$Id: DmxHypothesis.cxx,v 1.62 2007/02/04 05:55:06 rhatcher Exp $
00003 //
00004 //DmxHypothesis.cxx
00005 //
00006 //DmxHypothesis owns the description of signal to strip 
00007 //correllations for the hypothesis.  it is passed a pointer to the
00008 //stat to use to evaluate the goodness of the reconstruction
00009 //
00010 //Author:  B. Rebel 6/2000
00012 
00013 //#include "DeMux/DmxHypothesis.h"
00014 #include "DeMux/DmxHypothesis.h"
00015 #include "MessageService/MsgService.h"
00016 #include "MessageService/MsgFormat.h"
00017 #include "DeMux/DmxChiSqrStat.h"
00018 #include "DeMux/DmxRMSStat.h"
00019 #include "DeMux/DmxStatTypes.h"
00020 #include "Navigation/NavSet.h"
00021 #include "UgliGeometry/UgliStripHandle.h"
00022 #include "UgliGeometry/UgliScintPlnHandle.h"
00023 #include "UgliGeometry/UgliGeomHandle.h"
00024 #include "Algorithm/AlgConfig.h"
00025 #include "CandDigit/CandDeMuxDigit.h"
00026 #include "CandDigit/CandDeMuxDigitHandle.h"
00027 
00028 #include "TMath.h"
00029 
00030 ClassImp(DmxHypothesis)
00031 XXXITRIMP(DmxHypothesis)
00032 
00033 //______________________________________________________________________
00034 CVSID("$Id: DmxHypothesis.cxx,v 1.62 2007/02/04 05:55:06 rhatcher Exp $");
00035 
00036 //----------------------------------------------------------------------
00037 DmxHypothesis::DmxHypothesis() :
00038   fStat(0)
00039 {
00040 }
00041 
00042 //----------------------------------------------------------------------
00043 DmxHypothesis::DmxHypothesis(AlgConfig &acd, CandDeMuxDigitHandleItr &cdhitr,
00044                              Int_t lowerStrip, Int_t upperStrip) :
00045   fAllUsed(true),
00046   fCdhit(cdhitr),
00047   fCompare(0),
00048   fCoG(0.),
00049   fLowerBound(lowerStrip),
00050   fMaxSeparation(23),
00051   fMatedSignalRatio(0.0),
00052   fRequiredMatedSignalRatio(acd.GetDouble("RatioMatedSignalForValid")),
00053   fStat(0),
00054   fStripsUsed(0),
00055   //fTimeOffset(-10.),
00056   fUpperBound(upperStrip)
00057 {
00058   
00059   fCdhit.Reset();
00060 
00061   //loop over the digits to set the values
00062 
00063   //variables to calculate the center of gravity for the hypothesis
00064   Float_t numerator = 0.;       
00065   Float_t denominator = 0.;
00066 
00067   //initialize the signal and strip arrays
00068   Float_t signalE[192];
00069   Float_t signalW[192];
00070 
00071   //make arrays to hold the clear fiber + wls pigtail lengths for each digit
00072   //Float_t westFiber[192];
00073   //Float_t eastFiber[192];
00074   //Float_t eastTime[192];
00075   //Float_t westTime[192];
00076 
00077   //reset the arrays
00078   for(Int_t i = 0; i<192; i++){
00079    }
00080 
00081   for(Int_t vv = 0; vv < 192; vv++){
00082     signalE[vv] = 0.;
00083     signalW[vv] = 0.;
00084     //westFiber[vv] = -1.;
00085     //eastFiber[vv] = -1.;
00086     //eastTime[vv] = -1.;
00087     //westTime[vv] = -1.;
00088  }
00089 
00090   while( fCdhit.IsValid() ){
00091     
00092     //get the next CandDeMuxDigitHanlde object
00093     CandDeMuxDigitHandle *currentDigit = fCdhit.Ptr();
00094     
00095     //set the alternatives list to the first one
00096     currentDigit->GetPlexSEIdAltL().SetFirst();
00097       
00098     //loop through the Strip End Alternative list and see which one is
00099     //in the current hypothesis
00100     
00101     bool digitUsed = false;
00102 
00103     while( currentDigit->GetPlexSEIdAltL().IsValid() ){
00104       Int_t strip = currentDigit->GetPlexSEIdAltL().GetCurrentSEId().GetStrip();
00105       if(strip >= fLowerBound && strip <= fUpperBound){
00106 
00107         //if the flag isnt set, then use the digit - flags are set only if
00108         //the signal fraction is below the limit or the signal is too low
00109         if(currentDigit->GetDeMuxDigitFlagWord() == 0){
00110           
00111           digitUsed = true;
00112           
00113           if( currentDigit->GetPlexSEIdAltL().GetEnd() == StripEnd::kEast ){
00114             signalE[strip] = currentDigit->GetCharge();
00115             //MSG("DmxHyp", Msg::kDebug)<<"\teast strip " << strip << " charge " << signalE[strip] << endl;
00116           }
00117           else if( currentDigit->GetPlexSEIdAltL().GetEnd() == StripEnd::kWest ){
00118             signalW[strip] = currentDigit->GetCharge();
00119             //MSG("DmxHyp", Msg::kDebug)<<"\twest strip " << strip << " charge " << signalW[strip] << endl;
00120           }
00121           
00122           numerator += currentDigit->GetCharge() * strip;
00123           denominator += currentDigit->GetCharge();
00124                 
00125         }//end if this is a good digit to use
00126 
00127         //you found the strip for this digit, so break the loop
00128         break;
00129       }//end if stripend is in hypothesis limit
00130 
00131       //if that Strip End Id wasnt in the hypothesis go to the next one
00132       currentDigit->GetPlexSEIdAltL().Next();
00133 
00134     }//end loop over strip ends
00135     
00136     if( !digitUsed && currentDigit->GetDeMuxDigitFlagWord() == 0){ fAllUsed = false; }
00137     //advance to the next digit
00138     fCdhit.Next(); 
00139   }//end loop over digits
00140 
00141   fCdhit.ResetFirst();
00142 
00143   //find the mated signal and get the timing offset for this hypothesis
00144   //also see how many strips are used in this hypothesis
00145   Float_t matches = 0.0;
00146 
00147   for(Int_t j = 0; j < 192; j++){
00148           if( signalW[j] > 0. && signalE[j] > 0.)
00149                   matches += signalW[j] + signalE[j]; 
00150           if(signalW[j]>0. || signalE[j]>0.) ++fStripsUsed;
00151   }
00152   
00153   if(denominator > 0.){
00154     fCoG = numerator / denominator;
00155     fMatedSignalRatio = matches / denominator;
00156   }
00157 
00158   //get the correct DmxStatistic object from the AlgDeMuxConfig object
00159       
00160   //if(acd.GetStatParameter() == DmxStatTypes::kChi2){ 
00161     fStat = new DmxChiSqrStat(signalW, signalE, fCoG); 
00162     //}
00163     //else if(acd.GetStatParameter() == DmxStatTypes::kRms){ 
00164     //fStat = new DmxRMSStat(signalW, signalE, fCoG); 
00165     //}
00166   
00167   return;
00168 }
00169 
00170 //-----------------------------------------------------------------------
00171 DmxHypothesis::~DmxHypothesis()
00172 {
00173   //MSG("Dmx", Msg::kVerbose) << "deleting DmxHypothesis with lowerbound = " 
00174   //              << fLowerBound << endl;
00175   delete fStat;
00176 }
00177 
00178 //-----------------------------------------------------------------------
00179 Int_t DmxHypothesis::GetNumberOfStripsUsed() const
00180 {
00181         return fStripsUsed;
00182 }
00183 
00184 //-----------------------------------------------------------------------
00185 Float_t DmxHypothesis::GetCoG() const
00186 {
00187   return fCoG;
00188 }
00189 
00190 //-----------------------------------------------------------------------
00191 Int_t DmxHypothesis::GetCompareFlag() const 
00192 {
00193   return fCompare;
00194 }
00195 
00196 //-----------------------------------------------------------------------
00197 Int_t DmxHypothesis::GetLowerBound() const 
00198 {
00199   return fLowerBound;
00200 }
00201 
00202 //-----------------------------------------------------------------------
00203 Float_t DmxHypothesis::GetMatedSignalRatio() const  
00204 {
00205   return fMatedSignalRatio;
00206 }
00207 
00208 //-----------------------------------------------------------------------
00209 Float_t DmxHypothesis::GetStat() const  
00210 {
00211   return fStat->GetGoodness();
00212 }
00213 
00214 //-----------------------------------------------------------------------
00215 DmxStatistic *DmxHypothesis::GetStatObject() const  
00216 {
00217   return fStat;
00218 }
00219 
00220 //-----------------------------------------------------------------------
00221 Float_t DmxHypothesis::GetTieBreakerStat() const 
00222 {
00223   return fStat->GetTieBreaker();
00224 }
00225 
00226 //-----------------------------------------------------------------------
00227 Int_t DmxHypothesis::GetUpperBound() const 
00228 {
00229   return fUpperBound;
00230 }
00231 
00232 //-----------------------------------------------------------------------
00233 Bool_t DmxHypothesis::IsValid() const
00234 {
00235   //MSG("Dmx", Msg::kDebug) << "used flag = " << fAllUsed 
00236   //              << " for lowerbound = " << fLowerBound << endl;
00237   //return fMaxSeparation<24 && fMaxSeparation>0 && fAllUsed>0 && fMatedSignalRatio>0.3;
00238   //return fAllUsed>0 && fMatedSignalRatio>fRequiredMatedSignalRatio;
00239   return fMatedSignalRatio>fRequiredMatedSignalRatio && fAllUsed;
00240 }
00241 
00242 //-----------------------------------------------------------------------
00243 void DmxHypothesis::PrintRecon()
00244 {
00245   MSG("DMX", Msg::kInfo) << "\tLower Bound = " << fLowerBound
00246                          << "\tGoodness of Fit = " << fStat->GetGoodness()
00247                          << "\tTieBreaker = " << fStat->GetTieBreaker() << endl;
00248   while( fCdhit.IsValid() ){
00249     while( fCdhit.Ptr()->GetPlexSEIdAltL().IsValid() ){
00250         if( fCdhit.Ptr()->GetPlexSEIdAltL().GetCurrentSEId().GetStrip() >= fLowerBound && 
00251             fCdhit.Ptr()->GetPlexSEIdAltL().GetCurrentSEId().GetStrip() <= fUpperBound){
00252 
00253           if( fCdhit.Ptr()->GetPlexSEIdAltL().GetEnd() == StripEnd::kWest ){
00254             MSG("DMX", Msg::kInfo)<< "\t\tWest\t" 
00255                                   << fCdhit.Ptr()->GetPlexSEIdAltL().GetCurrentSEId().GetStrip() 
00256                                   << "\t" << fCdhit.Ptr()->GetCharge() << endl;
00257           }
00258           if( fCdhit.Ptr()->GetPlexSEIdAltL().GetEnd() == StripEnd::kEast ){
00259             MSG("DMX", Msg::kInfo)<< "\t\tEast\t" 
00260                                   << fCdhit.Ptr()->GetPlexSEIdAltL().GetCurrentSEId().GetStrip() 
00261                                   << "\t" << fCdhit.Ptr()->GetCharge() << endl;
00262           }
00263         }
00264     }
00265     fCdhit.Next();
00266   }
00267 
00268   return;
00269 }
00270 
00271 //----------------------------------------------------------------------
00272 void DmxHypothesis::SetStrips()
00273 {
00274   fCdhit.Reset();
00275   while( fCdhit.IsValid() ){
00276     
00277     //get the next CandDigitHanlde object
00278     CandDeMuxDigitHandle *currentDigit = fCdhit.Ptr();
00279     
00280     //clear all weights for the digit
00281     currentDigit->GetPlexSEIdAltLWritable().ClearWeights();
00282     
00283     //set the alternatives list to the first one
00284     currentDigit->GetPlexSEIdAltL().SetFirst();
00285       
00286     //set the veto flag to nonzero, if the digit has a SEId in this hypothesis
00287     //set it back to 0
00288     currentDigit->GetPlexSEIdAltLWritable().SetDemuxVetoFlag(1);
00289 
00290     //loop through the Strip End Alternative list and see which one is
00291     //in the current hypothesis
00292       
00293     while( currentDigit->GetPlexSEIdAltL().IsValid() ){
00294         if( currentDigit->GetPlexSEIdAltL().GetCurrentSEId().GetStrip() >= fLowerBound && 
00295             currentDigit->GetPlexSEIdAltL().GetCurrentSEId().GetStrip() <= fUpperBound){
00296 
00297           //set the Strip weight to 1 if it is in the hypothesis and veto flag to 0
00298           currentDigit->GetPlexSEIdAltLWritable().SetCurrentWeight(1.0);
00299           currentDigit->GetPlexSEIdAltLWritable().SetDemuxVetoFlag(0);
00300 
00301           //print the association
00302           //MSG("Dmx", Msg::kDebug) << "strip = " 
00303           //  << currentDigit->GetPlexSEIdAltLWritable().GetCurrentSEId().GetStrip() 
00304           //      << "\tside = " 
00305           //      << (Int_t)currentDigit->GetPlexSEIdAltLWritable().GetCurrentSEId().GetEnd() 
00306           //      << "\tsignal = " << currentDigit->GetCharge() 
00307           //  << endl;
00308 
00309           //you found the Strip End Id in the current hypothesis so quit looking
00310           break;
00311         }
00312         //if that Strip End Id wasnt in the hypothesis go to the next one
00313         currentDigit->GetPlexSEIdAltL().Next();
00314     }
00315     
00316     fCdhit.Next();
00317   }
00318   fCdhit.Reset();
00319 }
00320 
00321 //-------------------------------------------------------------------------------
00322 // Float_t DmxHypothesis::GetTimingOffset()
00323 // {
00324 //   MSG("DmxHyp", Msg::kDebug) << "timing offset = " << fTimeOffset << endl;
00325 //   return fTimeOffset;
00326 // }
00327 
00328 //--------------------------------------------------------------------------------
00329 Float_t DmxHypothesis::GetTimingOffset(UgliGeomHandle *ugh)
00330 {
00331   
00332   //make arrays to hold the clear fiber + wls pigtail lengths for each digit
00333   Float_t westFiber[192];
00334   Float_t eastFiber[192];
00335   Float_t eastTime[192];
00336   Float_t westTime[192];
00337 
00338   //reset the arrays
00339   for(Int_t i = 0; i<192; i++){
00340     westFiber[i] = -1.;
00341     eastFiber[i] = -1.;
00342     eastTime[i] = -1.;
00343     westTime[i] = -1.;
00344   }
00345 
00346   //MSG("DmxHyp", Msg::kDebug) << "starting the timing offset in hypothesis" << endl;
00347     
00348   fCdhit.ResetFirst();
00349   //MSG("DmxHyp", Msg::kDebug) << "reset digit iterator in hypothesis" << endl;
00350 
00351   while(fCdhit.IsValid()){
00352     
00353     CandDeMuxDigitHandle *digit = fCdhit.Ptr();
00354     
00355     if(digit->GetPlexSEIdAltL().GetDemuxVetoFlag() == 0 && digit->GetDeMuxDigitFlagWord() == 0){
00356       
00357       Int_t strip = digit->GetPlexSEIdAltL().GetBestSEId().GetStrip();
00358       
00359       //get the side for this digit and fill the array
00360       UgliStripHandle ush = ugh->GetStripHandle(digit->GetPlexSEIdAltL().GetBestSEId());
00361         
00362       if( digit->GetPlexSEIdAltL().GetEnd() == StripEnd::kEast ){
00363         eastFiber[strip] = ush.ClearFiber(StripEnd::kEast) + ush.WlsPigtail(StripEnd::kEast);
00364         eastTime[strip] = 1e9*digit->GetTime(CalTimeType::kT0) - 2093./(102.+TMath::Power(1.*digit->GetCharge(),1.2));
00365       }
00366       else if( digit->GetPlexSEIdAltL().GetEnd() == StripEnd::kWest ){
00367         westFiber[strip] = ush.ClearFiber(StripEnd::kWest) + ush.WlsPigtail(StripEnd::kWest);
00368         westTime[strip] = 1e9*digit->GetTime(CalTimeType::kT0) - 2093./(102.+TMath::Power(1.*digit->GetCharge(),1.2));
00369       }
00370       
00371     }
00372     fCdhit.Next();
00373   }
00374   
00375   //find the average offset from center for this plane based on timing and fill the array
00376   Float_t avTimeNum = 0.;
00377   Float_t avTimeDenom = 0.;
00378   Float_t offset = -10.;
00379   for(Int_t k=0; k<192; k++){
00380     
00381     //if the strip has doubled sided readout, then use it
00382     if(westTime[k] != -1.&& eastTime[k] != -1.){
00383       offset = (0.0825*(eastTime[k] - westTime[k]) + (westFiber[k]-eastFiber[k])/2.);
00384       //MSG("DmxTim", Msg::kDebug) << "shower plane offset = " << offset << endl;
00385       avTimeNum += offset;
00386       avTimeDenom += 1.;
00387     }
00388   }
00389         
00390   if(avTimeDenom>0) offset = avTimeNum/avTimeDenom;
00391   //MSG("DmxTim", Msg::kDebug) << "shower plane offset = " << offset << endl;
00392        
00393   //clear the digit slice
00394   fCdhit.Reset();
00395 
00396   return offset;
00397 } 
00398 
00399 
00400 
00401 
00402 
00403 
00404 
00405 
00406 
00407 
00408 

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