00001
00002
00003
00004
00005
00006
00007
00008
00010
00011
00012
00014
00015 #include <cassert>
00016 #include <cmath>
00017
00018 #include "Algorithm/AlgConfig.h"
00019 #include "Algorithm/AlgFactory.h"
00020 #include "Algorithm/AlgHandle.h"
00021 #include "CandData/CandHeader.h"
00022 #include "CandData/CandRecord.h"
00023 #include "CandDigit/CandDigit.h"
00024 #include "CandDigit/CandDigitHandle.h"
00025 #include "CandDigit/CandDigitList.h"
00026 #include "CandDigit/CandDigitListHandle.h"
00027 #include "Candidate/CandContext.h"
00028 #include "Conventions/ReadoutType.h"
00029 #include "FilterDigitSR/AlgFilterDigitListSR.h"
00030 #include "MessageService/MsgService.h"
00031 #include "Navigation/NavKey.h"
00032 #include "Navigation/NavSet.h"
00033 #include "Plex/PlexHandle.h"
00034 #include "Validity/VldContext.h"
00035
00036
00037 ClassImp(AlgFilterDigitListSR)
00038
00039
00040 CVSID("$Id: AlgFilterDigitListSR.cxx,v 1.6 2009/03/02 16:43:18 bckhouse Exp $");
00041
00042
00043 AlgFilterDigitListSR::AlgFilterDigitListSR()
00044 {
00045 }
00046
00047
00048 AlgFilterDigitListSR::~AlgFilterDigitListSR()
00049 {
00050 }
00051
00052 static NavKey KeyFromDigitTime(const CandDigitHandle* digit) {
00053 Int_t itime = (Int_t)(digit->GetSubtractedTime()*1.e9);
00054 return itime;
00055 }
00056
00057
00058
00059 void AlgFilterDigitListSR::RunAlg(AlgConfig &ac, CandHandle &ch,
00060 CandContext &cx)
00061 {
00062
00063
00064 MSG("FilterDigitSR", Msg::kDebug)
00065 << "Starting AlgFilterDigitListSR::RunAlg()" << endl;
00066
00067
00068 assert(cx.GetDataIn());
00069
00070
00071 const CandDigitListHandle *cdlh =
00072 dynamic_cast<const CandDigitListHandle *> (cx.GetDataIn());
00073 assert(cdlh);
00074
00075
00076 Int_t tmpi = 0;
00077 Double_t tmpd = 0.;
00078 Int_t filterstrategy = 0;
00079 Double_t dt_trig = 100.e-9;
00080 Double_t dt_readout = 150.e-9;
00081 Double_t dt_prereadout = 50.e-9;
00082 Int_t shieldmode = 0;
00083 if (ac.Get("FilterStrategy", tmpi)) filterstrategy = tmpi;
00084 if (ac.Get("TriggerWindow",tmpd)) dt_trig = (tmpd)*1.e-9;
00085 if (ac.Get("PostReadoutWindow",tmpd)) dt_readout = (tmpd)*1.e-9;
00086 if (ac.Get("PreReadoutWindow",tmpd)) dt_prereadout = (tmpd)*1.e-9;
00087 if (ac.Get("ShieldMode",tmpi)) shieldmode = tmpi;
00088 dt_trig = fabs(dt_trig);
00089 dt_readout = fabs(dt_readout);
00090 dt_prereadout = fabs(dt_prereadout);
00091 if (shieldmode<0 || shieldmode>2) shieldmode=0;
00092
00093
00094 ch.SetCandRecord((cdlh->GetCandRecord()));
00095
00096
00097 CandDigitListHandle &cddlh = dynamic_cast<CandDigitListHandle &>(ch);
00098 cddlh.SetIsSparse(cdlh->GetIsSparse());
00099 cddlh.SetAbsTime(cdlh->GetAbsTime());
00100
00101
00102 const VldContext &vldc = *(cdlh->GetCandRecord()->GetVldContext());
00103
00104 PlexHandle ph(vldc);
00105
00106
00107 CandDigitHandleItr cdhiter(cdlh->GetDaughterIterator());
00108 CandDigitHandleKeyFunc *cdhKf = cdhiter.CreateKeyFunc();
00109 cdhKf->SetFun(KeyFromDigitTime);
00110 cdhiter.GetSet()->AdoptSortKeyFunc(cdhKf);
00111 cdhKf = 0;
00112
00113 Float_t totadc = 0.;
00114 Float_t totadcfilter = 0.;
00115
00116 Double_t endtime = 0.;
00117 TObject *tob;
00118 TObjArray digitlist;
00119 map<CandDigitHandle*,Bool_t> shielddigitmap;
00120 map<CandDigitHandle*,Bool_t>::iterator shielddigitmapiter;
00121 while ((tob = cdhiter())) {
00122 CandDigitHandle *cdh = dynamic_cast<CandDigitHandle *>(tob);
00123 if (cdh == 0) continue;
00124 Bool_t isshielddigit = 0;
00125 if (cdh->GetPlexSEIdAltL().IsVetoShield()) isshielddigit=1;
00126 if (shieldmode==2 && isshielddigit) continue;
00127 if (isshielddigit) shielddigitmap[cdh] = 1;
00128 if (ph.GetReadoutType(cdh->GetChannelId()) != ReadoutType::kScintStrip) continue;
00129 if (!isshielddigit && cdh->GetSubtractedTime()<0.) continue;
00130 if (cdh->GetSubtractedTime()>endtime) endtime = cdh->GetSubtractedTime();
00131 totadc += cdh->GetCharge();
00132 digitlist.Add(cdh);
00133 }
00134
00135
00136 CandDigitHandle *gooddgt = 0;
00137 Float_t goodadc = 0.;
00138 Int_t timeplane[500];
00139 for (int i=0; i<500; i++) {
00140 timeplane[i] = -999999999;
00141 }
00142 for (int i=0; i<=digitlist.GetLast(); i++) {
00143 CandDigitHandle *dgt0 = dynamic_cast<CandDigitHandle*>(digitlist.At(i));
00144 shielddigitmapiter = shielddigitmap.find(dgt0);
00145 if (shielddigitmapiter!=shielddigitmap.end()) continue;
00146 Float_t trigplane[500];
00147 for (int j=0; j<500; j++) trigplane[j] = 0.;
00148 Int_t iplane0 = dgt0->GetPlexSEIdAltL().GetPlane();
00149 if (iplane0<=0 ||iplane0>=500) continue;
00150 if (dgt0->GetSubtractedTime()<=timeplane[iplane0]) continue;
00151 timeplane[iplane0] = (Int_t)(dgt0->GetSubtractedTime()*1.e9);
00152 trigplane[iplane0] = dgt0->GetCharge();
00153 CandDigitHandle *dgt1 = 0;
00154 Int_t ipln0=iplane0;
00155 Int_t ipln1=iplane0;
00156 for (int j=i+1; j<=digitlist.GetLast() && (!dgt1 || dgt1->GetSubtractedTime()-dgt0->GetSubtractedTime()<=dt_trig); j++) {
00157 dgt1 = dynamic_cast<CandDigitHandle*>(digitlist.At(j));
00158 Int_t iplane1 = dgt1->GetPlexSEIdAltL().GetPlane();
00159 if (iplane1<=0 ||iplane1>=500) continue;
00160 trigplane[iplane1] += dgt1->GetCharge();
00161 if (iplane1<ipln0) ipln0 = iplane1;
00162 if (iplane1>ipln1) ipln1 = iplane1;
00163 }
00164 for (int iplane = ipln0; iplane<=ipln1-3; iplane++) {
00165 Int_t nhitplane = 0;
00166 Int_t mintrigplane = 9999;
00167 Int_t maxtrigplane = -1;
00168 Float_t thisadc = 0.;
00169 for (int dplane=0; dplane<5 && iplane+dplane<=ipln1; dplane++) {
00170 if (trigplane[iplane+dplane]>0.) {
00171 nhitplane++;
00172 thisadc += trigplane[iplane+dplane];
00173 if (iplane+dplane<mintrigplane) mintrigplane = iplane+dplane;
00174 if (iplane+dplane>maxtrigplane) maxtrigplane = iplane+dplane;
00175 }
00176 }
00177 if (nhitplane>=4 && iplane0>=mintrigplane && iplane0<=maxtrigplane && thisadc>goodadc) {
00178 gooddgt = dgt0;
00179 goodadc = thisadc;
00180 }
00181 }
00182 }
00183
00184 if (gooddgt) {
00185 cddlh.SetAbsTime(gooddgt->GetTime());
00186 for (int i=0; i<=digitlist.GetLast(); i++) {
00187 CandDigitHandle *dgt = dynamic_cast<CandDigitHandle*>(digitlist.At(i));
00188 Bool_t isshielddigit = 0;
00189 shielddigitmapiter = shielddigitmap.find(dgt);
00190 if (shielddigitmapiter!=shielddigitmap.end()) isshielddigit = 1;
00191 if ((isshielddigit && shieldmode==0) || (gooddgt->GetSubtractedTime()-dgt->GetSubtractedTime()<=dt_prereadout && gooddgt->GetSubtractedTime()-dgt->GetSubtractedTime()>=0.) || (dgt->GetSubtractedTime()-gooddgt->GetSubtractedTime()<=dt_readout && dgt->GetSubtractedTime()-gooddgt->GetSubtractedTime()>=0.)) {
00192 CandDigitHandle cddh(*dgt);
00193 ch.AddDaughterLink(cddh, kFALSE);
00194 totadcfilter += cddh.GetCharge();
00195 MSG("FilterDigitSR",Msg::kVerbose) << "adding digit, plane " << dgt->GetPlexSEIdAltL().GetPlane() << " relative time " << (dgt->GetSubtractedTime()-gooddgt->GetSubtractedTime())*1.e9 << " isshield " << isshielddigit << endl;
00196 }
00197 }
00198 }
00199
00200 const CandHeader *candheader = cdlh->GetCandRecord()->GetCandHeader();
00201 assert(candheader);
00202 double fraction = 0;
00203 if (totadc != 0) fraction = totadcfilter/totadc;
00204
00205 MSG("FilterDigitSR",Msg::kDebug) << "Run " << candheader->GetRun() << " Snarl " << candheader->GetSnarl() << " trigger = " << (gooddgt ? 1 : 0) << " adc = " << totadc << " fraction = " << fraction << " timelength = " << endtime*1.e9 << endl;
00206
00207
00208 }
00209
00210
00211 void AlgFilterDigitListSR::Trace(const char * ) const
00212 {
00213 }