00001
00002
00003
00004
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 #include "DataUtil/GetRawBlock.h"
00034
00035 ClassImp(AlgChopListFar)
00036 CVSID( " $Id: AlgChopListFar.cxx,v 1.5 2010/01/06 17:15:44 rhatcher Exp $ ");
00037
00038 struct compareDigitTimes : public binary_function<const CandDigitHandle&, const CandDigitHandle&, bool> {
00039 bool operator()(const CandDigitHandle& d1, const CandDigitHandle& d2) {
00040 return (d1.GetTime() < d2.GetTime());
00041 }
00042 };
00043
00044
00045
00046 AlgChopListFar::AlgChopListFar()
00047 {
00048 }
00049
00050
00051 AlgChopListFar::~AlgChopListFar()
00052 {
00053 }
00054
00055
00056
00060 void AlgChopListFar::RunAlg(AlgConfig &algConfig,
00061 CandHandle &candHandle,
00062 CandContext &candContext)
00063 {
00064 assert(candHandle.InheritsFrom("CandChopListHandle"));
00065 CandChopListHandle &sliceList = dynamic_cast<CandChopListHandle &>(candHandle);
00066
00067 assert(candContext.GetDataIn());
00068
00069 if (!(candContext.GetDataIn()->InheritsFrom("CandDigitListHandle"))) {
00070 MSG("Chop",Msg::kWarning ) << "Data into AlgChopListFar is not a digit list." << std::endl;
00071 }
00072
00073 const CandDigitListHandle *cdlh_ptr =
00074 dynamic_cast<const CandDigitListHandle*>(candContext.GetDataIn());
00075
00076 const MomNavigator *mom = candContext.GetMom();
00077 const RawDigitDataBlock* rddb = DataUtil::GetRawBlock<RawDigitDataBlock>(mom);
00078 if (!rddb) {
00079 MSG("Chop", Msg::kWarning) << "No RawDigitDataBlock in RawRecord." << endl;
00080 return;
00081 }
00082
00083
00084 AlgFactory &af = AlgFactory::GetInstance();
00085 AlgHandle ah = af.GetAlgHandle("AlgChop","default");
00086 CandContext cxx(this,candContext.GetMom());
00087
00088
00089 double cTimeGap = algConfig.GetDouble("TimeGap");
00090 double cExtraShieldWindow = algConfig.GetDouble("ExtraShieldWindow");
00091 bool cIgnorePreTrigger = algConfig.GetInt("IgnorePreTrigger");
00092
00093
00094
00095 DigitVector digits(cdlh_ptr);
00096
00097 UInt_t ndigits = digits.size();
00098 if(ndigits==0) return;
00099
00100
00101 std::sort(digits.begin(), digits.end(), compareDigitTimes());
00102
00103
00104 double trigTime = cdlh_ptr->GetAbsTime();
00105 if(!cIgnorePreTrigger) trigTime = -100.0;
00106
00107
00108 int first_digit = 0;
00109 for(UInt_t i=0;i<ndigits;i++) {
00110 if( (digits[i].GetTime()-trigTime) >0) {
00111 first_digit = i;
00112 break;
00113 }
00114 }
00115
00116
00117
00118
00119 int nslice = 0;
00120 double slice_start = digits[first_digit].GetTime();
00121 double slice_end = slice_start;
00122 double t_last = 99e9;
00123 bool have_slice = false;
00124
00125 for(UInt_t i=first_digit; i<ndigits; i++) {
00126 double t = digits[i].GetTime();
00127 bool create_slice = false;
00128
00129
00130 if(!(digits[i].GetPlexSEIdAltL().IsVetoShield()) ) {
00131
00132 double delta_t = t-t_last;
00133 t_last = t;
00134 if(!have_slice) {
00135 slice_start = t;
00136 have_slice = true;
00137 } else {
00138 if( (delta_t >= cTimeGap) ) create_slice = true;
00139 }
00140 }
00141
00142
00143 if(i == ndigits-1) {
00144 if(have_slice) {
00145 create_slice = true;
00146 slice_end = 99e9;
00147 }
00148 }
00149
00150 if(create_slice) {
00151
00152
00153
00154
00155 double tstart = slice_start - cExtraShieldWindow;
00156 double tend = slice_end + cExtraShieldWindow;
00157
00158
00159 MSG("Chop",Msg::kDebug) << "Forming new slice, digit " << slice_start
00160 << " to " << slice_end << endl;
00161 DigitVector slice_data;
00162 for(UInt_t j=0; j<ndigits; j++) {
00163 double tt = digits[j].GetTime();
00164 if((tt>=tstart)&&(tt<=tend)) slice_data.push_back(digits[j]);
00165 }
00166
00167 cxx.SetDataIn(&(slice_data));
00168 CandDigitListHandle sliceHandle = CandDigitList::MakeCandidate(ah,cxx);
00169 sliceHandle.SetName(Form("Chop %d",nslice++));
00170 sliceList.AddDaughterLink(sliceHandle);
00171
00172
00173 slice_start = t;
00174 }
00175
00176 slice_end = t;
00177
00178
00179 }
00180
00181 }
00182
00183
00184
00185 void AlgChopListFar::Trace(const char * ) const
00186 {
00187 }
00188