00001
00002
00003
00004
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,
00060 CandContext &candContext)
00061 {
00062 assert(candHandle.InheritsFrom("CandChopListHandle"));
00063 CandChopListHandle &sliceList = dynamic_cast<CandChopListHandle &>(candHandle);
00064
00065 assert(candContext.GetDataIn());
00066
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
00088 AlgFactory &af = AlgFactory::GetInstance();
00089 AlgHandle ah = af.GetAlgHandle("AlgChop","default");
00090 CandContext cxx(this,candContext.GetMom());
00091
00092
00093 double cTimeGap = algConfig.GetDouble("TimeGap");
00094 double cExtraShieldWindow = algConfig.GetDouble("ExtraShieldWindow");
00095 bool cIgnorePreTrigger = algConfig.GetInt("IgnorePreTrigger");
00096
00097
00098
00099 DigitVector digits(cdlh_ptr);
00100
00101 UInt_t ndigits = digits.size();
00102
00103
00104 std::sort(digits.begin(), digits.end(), compareDigitTimes());
00105
00106
00107 double trigTime = cdlh_ptr->GetAbsTime();
00108 if(!cIgnorePreTrigger) trigTime = -100.0;
00109
00110
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
00121
00122 int nslice = 0;
00123 double slice_start = digits[first_digit].GetTime();
00124 double slice_end = slice_start;
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
00133 if(!(digits[i].GetPlexSEIdAltL().IsVetoShield()) ) {
00134
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
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
00156
00157
00158 double tstart = slice_start - cExtraShieldWindow;
00159 double tend = slice_end + cExtraShieldWindow;
00160
00161
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
00176 slice_start = t;
00177 }
00178
00179 slice_end = t;
00180
00181
00182 }
00183
00184 }
00185
00186
00187
00188 void AlgChopListFar::Trace(const char * ) const
00189 {
00190 }
00191