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

AlgChopListSharp Class Reference

#include <AlgChopListSharp.h>

Inheritance diagram for AlgChopListSharp:

AlgBase List of all members.

Public Member Functions

 AlgChopListSharp ()
virtual ~AlgChopListSharp ()
virtual void RunAlg (AlgConfig &ac, CandHandle &ch, CandContext &cx)
virtual void Trace (const char *c) const

Private Member Functions

bool ShouldSplit (float this_ph, float next_ph, float d_tmax)

Constructor & Destructor Documentation

AlgChopListSharp::AlgChopListSharp  ) 
 

Definition at line 49 of file AlgChopListSharp.cxx.

00050 {
00051 }

AlgChopListSharp::~AlgChopListSharp  )  [virtual]
 

Definition at line 54 of file AlgChopListSharp.cxx.

00055 {
00056 }


Member Function Documentation

void AlgChopListSharp::RunAlg AlgConfig ac,
CandHandle candHandle,
CandContext candContext
[virtual]
 

Algorithm to chop by using the summed energy waveform of the whole calorimeter.

Implements AlgBase.

Definition at line 83 of file AlgChopListSharp.cxx.

References CandHandle::AddDaughterLink(), digits(), done(), RawRecord::FindRawBlock(), Form(), AlgFactory::GetAlgHandle(), CandContext::GetCandRecord(), CandContext::GetDataIn(), VldContext::GetDetector(), MomNavigator::GetFragment(), AlgFactory::GetInstance(), CandContext::GetMom(), Calibrator::GetTDCFromTime(), RecMinos::GetVldContext(), Calibrator::Instance(), kQieRcid, PlexPlaneId::LastPlaneNearCalor(), CandDigitList::MakeCandidate(), MSG, CandHandle::SetName(), and ShouldSplit().

00086 {
00090 
00091   assert(candHandle.InheritsFrom("CandChopListHandle"));
00092   CandChopListHandle &chopList = dynamic_cast<CandChopListHandle &>(candHandle);
00093 
00094    assert(candContext.GetDataIn());
00095    // Check for CandDigitListHandle input
00096    if (!(candContext.GetDataIn()->InheritsFrom("CandDigitListHandle"))) {
00097      MSG("Chop",Msg::kWarning ) << "Data into AlgChopListSharp is not a digit list." << std::endl;
00098    }
00099    
00100    const CandDigitListHandle *cdlh_ptr = 
00101      dynamic_cast<const CandDigitListHandle*>(candContext.GetDataIn());
00102    
00103    const MomNavigator *mom = candContext.GetMom();
00104    RawRecord *rr = dynamic_cast<RawRecord *>(mom->GetFragment("RawRecord"));
00105    if (!rr) {
00106      MSG("Chop", Msg::kWarning) << "No RawRecord in MOM." << endl;
00107      return;
00108    }
00109    const RawDigitDataBlock *rddb = dynamic_cast<const RawDigitDataBlock *>
00110      (rr->FindRawBlock("RawDigitDataBlock"));
00111    if (!rddb) {
00112      MSG("Chop", Msg::kWarning) << "No RawDigitDataBlock in RawRecord." << endl;
00113      return;
00114    }
00115    
00116    // Get setup for the DigitList maker algorithm
00117    AlgFactory &af = AlgFactory::GetInstance();
00118    AlgHandle ah = af.GetAlgHandle("AlgChop","default");
00119    CandContext cxx(this,candContext.GetMom());
00120 
00121    const VldContext &context = *(candContext.GetCandRecord()->GetVldContext());
00122    if(context.GetDetector() != Detector::kNear) 
00123      MSG("Chop",Msg::kError) << "Running the Sharp algorithm on FD data is a no-no!" << endl;
00124 
00125    Calibrator& cal = Calibrator::Instance();
00126    UgliGeomHandle ugli(context);
00127   
00128    // Now do the actual slicing.
00129 
00130    // First, make a nice stl vector of the digits.
00131    DigitVector digits(cdlh_ptr);
00132 
00133    UInt_t ndigits = digits.size();
00134    UInt_t nchop = 0;
00135     
00136    // Sort the list by time.
00137    // Not neccessary for this algorithm.
00138    // std::sort(digits.begin(), digits.end(), compareDigitTimes());
00139 
00140 
00141    // Also, I want some other pieces of info:
00142    std::vector<int>    digit_tdc(ndigits);
00143    std::vector<UInt_t> digit_plane(ndigits);
00144    //std::vector<float>  digit_tpos(ndigits);
00145    for(UInt_t i=0;i<ndigits;i++) {
00146      digit_tdc[i] = (cal.GetTDCFromTime(digits[i].GetTime(CalTimeType::kNone), kQieRcid));
00147      digit_plane[i] = digits[i].GetPlexSEIdAltL().GetPlane(); 
00148      //if(digit_plane[i]<=PlexPlaneId::LastPlaneNearCalor())
00149      //  digit_tpos[i]  = ugli.GetStripHandle(digits[i].GetPlexSEIdAltL().GetBestSEId()).GetTPos(); 
00150      //else 
00151      //  digit_tpos[i]  = -999;
00152    }
00153 
00154    // Find first and last times. Add some padding so sertain operations are easier to code.
00155    Int_t tfirst = digit_tdc[0];
00156    Int_t tlast  = digit_tdc[0];
00157    for(UInt_t i=0;i<ndigits;i++) {
00158      if(digit_tdc[i] < tfirst) tfirst = digit_tdc[i];
00159      if(digit_tdc[i] > tlast ) tlast  = digit_tdc[i];
00160    }
00161    tfirst-=5;
00162    tlast +=5;
00163 
00164 
00165    // Make the energy histogram.
00166    MSG("Chop",Msg::kDebug) << "Running Chop_Sharp" << endl;
00167       
00168    UInt_t numBins = tlast-tfirst;
00169 
00170    // Create the energy-time profile.
00171    std::vector<float> energyVsTime(numBins,0.);
00172    
00173    for(UInt_t idig = 0; idig < ndigits; idig++ ) {
00174      float sigcor = digits[idig].GetCharge(CalDigitType::kSigCorr);
00175      int tdcbin = digit_tdc[idig]-tfirst;
00176      if((tdcbin<0) || ((int)numBins<=tdcbin)) MSG("Chop",Msg::kDebug) << "Whups!" << endl;
00177      else if(digit_plane[idig]<=PlexPlaneId::LastPlaneNearCalor()) {
00178        energyVsTime[digit_tdc[idig]-tfirst] += sigcor; 
00179      }
00180    }
00181 
00182    // Used bins:
00183    std::vector<char> binsUsed(numBins,0);
00184 
00185    do {
00186      // Look for biggest peak. 
00187      UInt_t biggest_bin  = 99999;
00188      float  biggest_size = 0;
00189      for(UInt_t i=0;i<numBins;i++) {
00190        if(binsUsed[i]==0) 
00191          if(energyVsTime[i]>biggest_size) {
00192            biggest_size = energyVsTime[i];
00193            biggest_bin = i;
00194          }
00195      }
00196      
00197      if(biggest_bin==99999) break; // We've gone through all of them.
00198      if(biggest_size<100.) break; // We've hit 1 pe, rock bottom.
00199      
00200      // Collect the start and stop time for this chop.
00201      // Start 1 bin before the peak, and at least 1 bin after the peak.
00202      UInt_t bin_start = biggest_bin;
00203      UInt_t bin_stop =  biggest_bin;
00204      
00205      //for(Int_t i=-3;i<5;i++) {
00206      //  MSG("Chop",Msg::kDebug) << i << "\t" << energyVsTime[biggest_bin+i] << endl;
00207      // }
00208      
00209      if(binsUsed[bin_start-1]==0) bin_start--;
00210      if(binsUsed[bin_stop +1]==0) bin_stop++;
00211      
00212      bool done = false;
00213      while(!done) {
00214        // Stop at start of spill.
00215        if(bin_start==0) {
00216          //MSG("Chop",Msg::kDebug) << "Hit start of spill" << endl; 
00217          done=true;
00218        }
00219        
00220        if(ShouldSplit(energyVsTime[bin_start], 
00221                       energyVsTime[bin_start-1],
00222                       bin_start-1 - biggest_bin ) ) {
00223          //MSG("Chop",Msg::kDebug) << "Didn't move back.  dE = " << energyVsTime[bin_start-1] << "-" << energyVsTime[bin_start] << "  maxdE = " << max << endl;
00224          done = true;
00225        }
00226        
00227        // Stop if we've hit another chop.
00228        if(binsUsed[bin_start-1]) {
00229          //MSG("Chop",Msg::kDebug) << "Hit another chop." << endl;
00230          done = true;
00231        }
00232        
00233        if(!done) {
00234          //MSG("Chop",Msg::kDebug) << "Moving start back 1 notch. dE = " << climb << "  maxdE = " << max << endl;
00235          bin_start--;
00236        }
00237      };
00238      
00239      // Expand forwards until the energy starts climbing.
00240      // But, allow small pulses in for the first 5 buckets.
00241      done = false;
00242      while(!done) {
00243        // Stop at end of spill
00244        if(bin_stop >= numBins-1) {
00245          //MSG("Chop",Msg::kDebug) << "Hit end of spill" << endl;
00246          done = true;
00247        }
00248        
00249        // Allow 5 buckets worth of small stuff:
00250        if((energyVsTime[bin_stop+1] < 500.) && (bin_stop+1 < biggest_bin+7)) {
00251          // keep going
00252        } else {
00253          if(ShouldSplit(energyVsTime[bin_stop],
00254                         energyVsTime[bin_stop+1],
00255                         bin_stop+1 - biggest_bin) ) {
00256            //MSG("Chop",Msg::kDebug) << "Didn't move forward.  dE = " << energyVsTime[bin_stop+1] << "-" << energyVsTime[bin_stop] << "  maxdE = " << max << endl;
00257            done = true;
00258          }
00259        }
00260        
00261        // Stop if we hit another chop.
00262        if(binsUsed[bin_stop+1]) {
00263          //MSG("Chop",Msg::kDebug) << "Didn't move forward; hit another chop." << endl;
00264          done = true;
00265        }
00266        
00267        // If we're ok, increment and continue.
00268        if(!done) bin_stop++;
00269      }
00270      
00271      int tdc_start = bin_start+tfirst;
00272      int tdc_stop  = bin_stop+tfirst;
00273      
00274      // We have a chop candidate. Create it.
00275      DigitVector slc;
00276 
00277      for(UInt_t idig = 0; idig < ndigits; idig++ ) {
00278        int tdc = digit_tdc[idig];
00279        if((tdc>=(int)tdc_start)&&(tdc<=(int)tdc_stop))
00280          slc.push_back(digits[idig]);
00281      }
00282      cxx.SetDataIn(&(slc));
00283      CandDigitListHandle chopHandle = CandDigitList::MakeCandidate(ah,cxx);
00284      chopHandle.SetName(Form("Chop %d",nchop++));
00285      chopList.AddDaughterLink(chopHandle);
00286      
00287      MSG("Chop",Msg::kDebug) << "Creating chop. Big: " << biggest_bin
00288           << "  Start: " << bin_start << "   Stop: " << bin_stop 
00289           << "  Digits: " << slc.size() 
00290           << endl;
00291 
00292      
00293 
00294      // Zero out these buckets so they won't be caught again.
00295      for(UInt_t i=bin_start; i<=bin_stop; i++) {
00296        binsUsed[i] = 1;
00297      }
00298      
00299    } while(true); 
00300  
00301 }

bool AlgChopListSharp::ShouldSplit float  this_ph,
float  next_ph,
float  d_tmax
[private]
 

Definition at line 59 of file AlgChopListSharp.cxx.

References k1pe.

Referenced by RunAlg().

00063 {
00064   float climb = next_ph - this_ph;
00065   
00066   // the maximum delta that the algorithm will climb before making a new chop
00067   float max_climb = 2.5*sqrt(fabs(this_ph)/k1pe)*k1pe;
00068   if(max_climb < (6 * k1pe)) max_climb=max_climb*2;
00069 
00070   // the maximum pulse height in this bin if we're making a new chop.
00071   //const float size_limit = 20 * k1pe; 
00072   //const float min_time = 2;
00073 
00074   //if(d_tmax  < min_time) return false;
00075   //if(this_ph < size_limit) return false;
00076 
00077   if( climb >= max_climb ) return true;
00078   else return false;    
00079 }

void AlgChopListSharp::Trace const char *  c  )  const [virtual]
 

Reimplemented from AlgBase.

Definition at line 304 of file AlgChopListSharp.cxx.

00305 {
00306 }


The documentation for this class was generated from the following files:
Generated on Sat Nov 21 22:49:14 2009 for loon by  doxygen 1.3.9.1