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