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

Generated on Mon Nov 23 05:25:53 2009 for loon by  doxygen 1.3.9.1