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

AlgChopListFar.cxx

Go to the documentation of this file.
00001 
00002 // $Id: AlgChopListFar.cxx,v 1.2 2005/06/08 10:16:46 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.2 2005/06/08 10:16:46 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 
00103    // Sort the list by time.
00104    std::sort(digits.begin(), digits.end(), compareDigitTimes());
00105 
00106    // Trigger time.
00107    double trigTime = cdlh_ptr->GetAbsTime();
00108    if(!cIgnorePreTrigger) trigTime = -100.0; // Set trigger time infinately early.
00109 
00110    // Find the first digit after the pre-trigger window.
00111    int first_digit = 0;
00112    for(UInt_t i=0;i<ndigits;i++) {
00113      if( (digits[i].GetTime()-trigTime) >0) {
00114        first_digit = i;
00115        break;
00116      }
00117    }
00118 
00119     
00120    // Go through, look for gaps. When you find a gap, make a new slice.
00121 
00122    int nslice = 0;
00123    double slice_start = digits[first_digit].GetTime();    // start time (inclusive)
00124    double slice_end   = slice_start;                      // stop  time (inclusive)
00125    double t_last = 99e9;
00126    bool have_slice = false;
00127 
00128    for(UInt_t i=first_digit; i<ndigits; i++) {     
00129      double t = digits[i].GetTime();
00130      bool create_slice = false;
00131 
00132      // Only look at non-veto digits.
00133      if(!(digits[i].GetPlexSEIdAltL().IsVetoShield()) ) {
00134        // This digit isn't in veto.. use it.
00135        double delta_t = t-t_last;
00136        t_last = t;
00137        if(!have_slice) {
00138          slice_start = t;
00139          have_slice = true;
00140        } else {
00141          if( (delta_t >= cTimeGap) ) create_slice = true;
00142        }
00143      }
00144 
00145      // Hack for last digit: close off the slice:
00146      if(i == ndigits-1) {
00147        if(have_slice) {
00148          create_slice = true;
00149          slice_end = 99e9;
00150        }
00151      }
00152      
00153      if(create_slice) {
00154 
00155        // Set start and end times. Note that the extra window
00156        // will only catch shield hits, assuming the extra window 
00157        // is smaller than the gap window.
00158        double tstart = slice_start - cExtraShieldWindow;
00159        double tend   = slice_end   + cExtraShieldWindow;
00160        
00161        // Make a new slice.
00162        MSG("Chop",Msg::kDebug) << "Forming new slice, digit " << slice_start
00163                                << " to " << slice_end << endl;
00164        DigitVector slice_data;
00165        for(UInt_t j=0; j<ndigits; j++) {
00166          double tt = digits[j].GetTime();            
00167          if((tt>=tstart)&&(tt<=tend))  slice_data.push_back(digits[j]);
00168        }
00169          
00170        cxx.SetDataIn(&(slice_data));
00171        CandDigitListHandle sliceHandle = CandDigitList::MakeCandidate(ah,cxx);
00172        sliceHandle.SetName(Form("Chop %d",nslice++));
00173        sliceList.AddDaughterLink(sliceHandle);
00174        
00175        // Prep next slice.
00176        slice_start = t;
00177      }
00178 
00179      slice_end = t;
00180 
00181 
00182    }      
00183    
00184 }
00185   
00186 
00187 //______________________________________________________________________
00188 void AlgChopListFar::Trace(const char * /* c */) const
00189 {
00190 }
00191 

Generated on Thu Nov 1 15:51:40 2007 for loon by  doxygen 1.3.9.1