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

AlgChopListFar.cxx

Go to the documentation of this file.
00001 
00002 // $Id: AlgChopListFar.cxx,v 1.3 2006/05/16 23:22:30 tagg Exp $
00003 //
00004 // AlgChopListFar.cxx
00005 //
00007 
00008 #include <cassert>
00009 
00010 #include "CandChop/AlgChopListFar.h"
00011 #include "CandChop/CandChopListHandle.h"
00012 #include "CandChop/DigitVector.h"
00013 
00014 
00015 #include "Algorithm/AlgConfig.h"
00016 #include "Algorithm/AlgFactory.h"
00017 #include "Algorithm/AlgHandle.h"
00018 #include "CandData/CandHeader.h"
00019 #include "CandData/CandRecord.h"
00020 #include "CandDigit/CandDigitHandle.h"
00021 #include "CandDigit/CandDigitListHandle.h"
00022 #include "CandDigit/CandDigitList.h"
00023 #include "Candidate/CandContext.h"
00024 #include "MessageService/MsgService.h"
00025 #include "MinosObjectMap/MomNavigator.h"
00026 #include "RawData/RawHeader.h"
00027 #include "RawData/RawRecord.h"
00028 #include "RawData/RawDigitDataBlock.h"
00029 #include "UgliGeometry/UgliGeomHandle.h"
00030 #include "UgliGeometry/UgliStripHandle.h"
00031 #include "Validity/VldContext.h"
00032 
00033 ClassImp(AlgChopListFar)
00034 CVSID( " $Id: AlgChopListFar.cxx,v 1.3 2006/05/16 23:22:30 tagg Exp $ ");
00035 
00036 struct compareDigitTimes : public binary_function<const CandDigitHandle&, const CandDigitHandle&, bool> {
00037   bool operator()(const CandDigitHandle& d1, const CandDigitHandle& d2) {
00038     return (d1.GetTime() < d2.GetTime());
00039   }
00040 };
00041 
00042 
00043 //______________________________________________________________________
00044 AlgChopListFar::AlgChopListFar()
00045 {
00046 }
00047 
00048 //______________________________________________________________________
00049 AlgChopListFar::~AlgChopListFar()
00050 {
00051 }
00052 
00053 //______________________________________________________________________
00054 
00058 void AlgChopListFar::RunAlg(AlgConfig &algConfig, 
00059                            CandHandle &candHandle,  // thing to make
00060                            CandContext &candContext)
00061 {
00062   assert(candHandle.InheritsFrom("CandChopListHandle"));
00063   CandChopListHandle &sliceList = dynamic_cast<CandChopListHandle &>(candHandle);
00064 
00065    assert(candContext.GetDataIn());
00066    // Check for CandDigitListHandle input
00067    if (!(candContext.GetDataIn()->InheritsFrom("CandDigitListHandle"))) {
00068      MSG("Chop",Msg::kWarning ) << "Data into AlgChopListFar is not a digit list." << std::endl;
00069    }
00070    
00071    const CandDigitListHandle *cdlh_ptr = 
00072      dynamic_cast<const CandDigitListHandle*>(candContext.GetDataIn());
00073    
00074    const MomNavigator *mom = candContext.GetMom();
00075    RawRecord *rr = dynamic_cast<RawRecord *>(mom->GetFragment("RawRecord"));
00076    if (!rr) {
00077      MSG("Chop", Msg::kWarning) << "No RawRecord in MOM." << endl;
00078      return;
00079    }
00080    const RawDigitDataBlock *rddb = dynamic_cast<const RawDigitDataBlock *>
00081      (rr->FindRawBlock("RawDigitDataBlock"));
00082    if (!rddb) {
00083      MSG("Chop", Msg::kWarning) << "No RawDigitDataBlock in RawRecord." << endl;
00084      return;
00085    }
00086    
00087    // Get setup for the DigitList maker algorithm
00088    AlgFactory &af = AlgFactory::GetInstance();
00089    AlgHandle ah = af.GetAlgHandle("AlgChop","default");
00090    CandContext cxx(this,candContext.GetMom());
00091 
00092    // Configuration:
00093    double cTimeGap           = algConfig.GetDouble("TimeGap");
00094    double cExtraShieldWindow = algConfig.GetDouble("ExtraShieldWindow");
00095    bool   cIgnorePreTrigger  = algConfig.GetInt("IgnorePreTrigger");
00096  
00097 
00098    // First, make a nice stl vector of the digits.
00099    DigitVector digits(cdlh_ptr);
00100 
00101    UInt_t ndigits = digits.size();
00102    if(ndigits==0) return; // No data.
00103 
00104    // Sort the list by time.
00105    std::sort(digits.begin(), digits.end(), compareDigitTimes());
00106 
00107    // Trigger time.
00108    double trigTime = cdlh_ptr->GetAbsTime();
00109    if(!cIgnorePreTrigger) trigTime = -100.0; // Set trigger time infinately early.
00110 
00111    // Find the first digit after the pre-trigger window.
00112    int first_digit = 0;
00113    for(UInt_t i=0;i<ndigits;i++) {
00114      if( (digits[i].GetTime()-trigTime) >0) {
00115        first_digit = i;
00116        break;
00117      }
00118    }
00119 
00120     
00121    // Go through, look for gaps. When you find a gap, make a new slice.
00122 
00123    int nslice = 0;
00124    double slice_start = digits[first_digit].GetTime();    // start time (inclusive)
00125    double slice_end   = slice_start;                      // stop  time (inclusive)
00126    double t_last = 99e9;
00127    bool have_slice = false;
00128 
00129    for(UInt_t i=first_digit; i<ndigits; i++) {     
00130      double t = digits[i].GetTime();
00131      bool create_slice = false;
00132 
00133      // Only look at non-veto digits.
00134      if(!(digits[i].GetPlexSEIdAltL().IsVetoShield()) ) {
00135        // This digit isn't in veto.. use it.
00136        double delta_t = t-t_last;
00137        t_last = t;
00138        if(!have_slice) {
00139          slice_start = t;
00140          have_slice = true;
00141        } else {
00142          if( (delta_t >= cTimeGap) ) create_slice = true;
00143        }
00144      }
00145 
00146      // Hack for last digit: close off the slice:
00147      if(i == ndigits-1) {
00148        if(have_slice) {
00149          create_slice = true;
00150          slice_end = 99e9;
00151        }
00152      }
00153      
00154      if(create_slice) {
00155 
00156        // Set start and end times. Note that the extra window
00157        // will only catch shield hits, assuming the extra window 
00158        // is smaller than the gap window.
00159        double tstart = slice_start - cExtraShieldWindow;
00160        double tend   = slice_end   + cExtraShieldWindow;
00161        
00162        // Make a new slice.
00163        MSG("Chop",Msg::kDebug) << "Forming new slice, digit " << slice_start
00164                                << " to " << slice_end << endl;
00165        DigitVector slice_data;
00166        for(UInt_t j=0; j<ndigits; j++) {
00167          double tt = digits[j].GetTime();            
00168          if((tt>=tstart)&&(tt<=tend))  slice_data.push_back(digits[j]);
00169        }
00170          
00171        cxx.SetDataIn(&(slice_data));
00172        CandDigitListHandle sliceHandle = CandDigitList::MakeCandidate(ah,cxx);
00173        sliceHandle.SetName(Form("Chop %d",nslice++));
00174        sliceList.AddDaughterLink(sliceHandle);
00175        
00176        // Prep next slice.
00177        slice_start = t;
00178      }
00179 
00180      slice_end = t;
00181 
00182 
00183    }      
00184    
00185 }
00186   
00187 
00188 //______________________________________________________________________
00189 void AlgChopListFar::Trace(const char * /* c */) const
00190 {
00191 }
00192 

Generated on Fri Mar 28 15:26:53 2008 for loon by  doxygen 1.3.9.1