00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00017
00018 #include "NoiseFilter/NoiseFilterModule.h"
00019 #include "JobControl/JobCModuleRegistry.h"
00020 #include "MessageService/MsgService.h"
00021 #include "Plex/PlexHandle.h"
00022 #include "Plex/PlexSEIdAltL.h"
00023 #include "RawData/RawRecord.h"
00024 #include "RawData/RawDigitDataBlock.h"
00025 #include "RawData/RawDaqSnarlHeader.h"
00026 #include "RawData/RawDigit.h"
00027 #include "MinosObjectMap/MomNavigator.h"
00028 #include "Validity/VldContext.h"
00029 #include "Calibrator/Calibrator.h"
00030 #include "Conventions/Munits.h"
00031 #include "Conventions/ReadoutType.h"
00032 #include <vector>
00033
00034 ClassImp(NoiseFilterModule)
00035
00036
00037
00038 CVSID("$Id: NoiseFilterModule.cxx,v 1.14 2007/11/11 05:58:26 rhatcher Exp $");
00039 JOBMODULE(NoiseFilterModule, "NoiseFilterModule",
00040 "NoiseFilters removes non physics triggers");
00041
00042
00043
00044 NoiseFilterModule::NoiseFilterModule()
00045 {
00046 MSG("NoiseFilter", Msg::kVerbose)
00047 << "NoiseFilterModule::Constructor\n";
00048 }
00049
00050
00051
00052 NoiseFilterModule::~NoiseFilterModule()
00053 {
00054 MSG("NoiseFilter", Msg::kVerbose)
00055 << "NoiseFilterModule::Destructor\n";
00056 }
00057
00058
00059
00060 void NoiseFilterModule::BeginJob()
00061 {
00062 MSG("NoiseFilter", Msg::kVerbose)
00063 << "NoiseFilterModule::BeginJob\n";
00064
00065 }
00066
00067
00068
00069 JobCResult NoiseFilterModule::Ana(const MomNavigator *mom)
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079 {
00080
00081 MSG("NoiseFilter", Msg::kDebug) << "NoiseFilterModule::Ana\n";
00082
00083 TObject* tobj;
00084 TIter fragiter = mom->FragmentIter();
00085
00086 RawRecord* rr = 0;
00087 const RawDigitDataBlock* rddb = 0;
00088 const RawDaqSnarlHeader* rdsh = 0;
00089
00090
00091
00092 while( ( tobj = fragiter.Next() ) ) {
00093 if( ( rr = dynamic_cast<RawRecord*>(tobj) ) ) {
00094
00095 MSG("NoiseFilter", Msg::kDebug)
00096 << "Found Next RawRecord at "<<rr<<".\n";
00097
00098 if ( !rddb ) rddb = dynamic_cast<const RawDigitDataBlock*>
00099 (rr->FindRawBlock("RawDigitDataBlock"));
00100
00101 if ( !rdsh ) rdsh = dynamic_cast<const RawDaqSnarlHeader*>
00102 (rr->GetRawHeader());
00103
00104 }
00105 }
00106
00107
00108
00109 if ( !rddb) {
00110 MSG("NoiseFilter", Msg::kWarning)
00111 <<"No RawDigitDataBlock in RawRecord.\n";
00112 return JobCResult::kFailed;
00113 }
00114
00115 if ( !rdsh) {
00116 MSG("NoiseFilter", Msg::kWarning)
00117 <<"No RawDaqSnarlHeader in RawRecord.\n";
00118 return JobCResult::kFailed;
00119 }
00120
00121
00122
00123 VldContext vldc = rdsh->GetVldContext();
00124 Detector::Detector_t Detector = vldc.GetDetector();
00125 if ( Detector != Detector::kNear &&
00126 Detector != Detector::kFar ) {
00127 MSG("NoiseFilter", Msg::kDebug)
00128 << "Accepting snarl: Neither Near nor Far Detector.\n";
00129 return JobCResult::kPassed;
00130 }
00131
00132
00133
00134 Int_t MinPH = 0;
00135 Int_t MinEL = 0;
00136 Int_t PlaneMax = 0;
00137 Bool_t TriggerTimeCut = false;
00138 switch (Detector) {
00139 case Detector::kNear:
00140 MinPH = fMinPulseHeightND;
00141 MinEL = fMinEventLengthND;
00142 PlaneMax = 282;
00143 TriggerTimeCut = fTriggerTimeCutND;
00144 break;
00145 case Detector::kFar:
00146 MinPH = fMinPulseHeightFD;
00147 MinEL = fMinEventLengthFD;
00148 PlaneMax = 486;
00149 TriggerTimeCut = fTriggerTimeCutFD;
00150 break;
00151 default:
00152 break;
00153 }
00154
00155 PlexHandle ph(vldc);
00156 VldTimeStamp vldcts = vldc.GetTimeStamp();
00157
00158 MSG("NoiseFilter", Msg::kDebug) << "VldTimeStamp = "
00159 << vldcts.AsString("c") << endl;
00160
00161 Double_t TrigTime = vldcts.GetNanoSec()*Munits::ns;
00162 MSG("NoiseFilter", Msg::kDebug) << "TrigTime = " << TrigTime
00163 << " (in sec)" <<endl;
00164
00165
00166
00167 Int_t TotAdc = 0;
00168 Int_t rdcount = 0;
00169 std::vector<Bool_t> HitInPlane(PlaneMax,kFALSE);
00170
00171
00172
00173 Calibrator& calibrator = Calibrator::Instance();
00174 TIter rdit = rddb->GetDatumIter();
00175
00176 while (RawDigit *rd = dynamic_cast<RawDigit*>(rdit())) {
00177
00178 RawChannelId rcid = rd->GetChannel();
00179 Int_t adc = rd->GetADC();
00180 Int_t tdc = rd->GetTDC();
00181 Int_t error = rd->GetErrorCode();
00182 Double_t time = calibrator.GetTimeFromTDC(tdc, rcid);
00183 PlexSEIdAltL seid = ph.GetSEIdAltL(rcid);
00184 Int_t plane = seid.GetPlane();
00185
00186
00187 time += ( (rd->GetCrateT0()).GetSec()
00188 - (vldc.GetTimeStamp()).GetSec() )*Munits::s
00189
00190 + (rd->GetCrateT0()).GetNanoSec()*Munits::ns;
00191
00192
00193
00194 Int_t planeRAW = plane;
00195 if ( (vldc.GetDetector() == Detector::kNear) && (plane>121) )
00196 plane = 121 + (plane-121) / 5;
00197
00198 MSG("NoiseFilter", Msg::kDebug) << "Digit(" << setw(3) << rdcount << "):"
00199 << " plane =" << setw(5) << plane <<"/"
00200 << setw(3) << planeRAW
00201 << " ADC =" << setw(6) << adc
00202 << " TDC =" << setw(12) << tdc
00203 << " err = " << error
00204 << " Dt = " << time-TrigTime
00205 << endl;
00206
00207
00208
00209
00210
00211
00212
00213
00214 if ( !(seid.IsVetoShield()) &&
00215 ph.GetReadoutType(rcid) == ReadoutType::kScintStrip &&
00216 !error &&
00217 ( (time+50*Munits::ns>=TrigTime) || !TriggerTimeCut ) ) {
00218
00219
00220
00221 if ( (plane>=0) && (plane<PlaneMax) ) {
00222
00223 TotAdc += adc;
00224 HitInPlane[plane] = kTRUE;
00225
00226 } else {
00227
00228 MAXMSG("NoiseFilter", Msg::kWarning, 20)
00229 << "Found plane number " << plane
00230 << " outside allowed range 0 - " << PlaneMax << endl
00231 << " ADC = "<< adc << " TDC = " << tdc << " t = " << time
00232 << endl << " rcid = " << rcid.AsString("e") << endl;
00233
00234 }
00235
00236 }
00237
00238 rdcount++;
00239
00240 }
00241
00242
00243
00244 MSG("NoiseFilter", Msg::kDebug) << "Now calculating snarl length.\n";
00245
00246 Int_t EventLength = 0;
00247 Int_t PlaneCount = 0;
00248
00249 for (Int_t plane = 0; plane<PlaneMax; plane++) {
00250 if ( HitInPlane[plane] ) {
00251 PlaneCount++;
00252 if ( PlaneCount > EventLength ) {
00253 EventLength = PlaneCount;
00254 }
00255 MSG("NoiseFilter", Msg::kVerbose)
00256 << "Plane " << plane << " was hit. PC = " << PlaneCount
00257 << " EL = " << EventLength << endl;
00258 } else {
00259 MSG("NoiseFilter", Msg::kVerbose)
00260 << "Plane " << plane << " was not hit."<< endl;
00261 PlaneCount = 0;
00262 }
00263 }
00264
00265
00266
00267 if (TotAdc<MinPH) {
00268 MSG("NoiseFilter", Msg::kDebug) << "Failing snarl: SumAdc = "
00269 << TotAdc << "/" << MinPH
00270 << endl;
00271 return JobCResult::kFailed;
00272 }
00273
00274
00275
00276 if (EventLength<MinEL) {
00277 MSG("NoiseFilter", Msg::kDebug) << "Failing snarl: EventLength = "
00278 << EventLength << "/" << MinEL
00279 << endl;
00280 return JobCResult::kFailed;
00281 }
00282
00283 MSG("NoiseFilter", Msg::kDebug)
00284 << "Snarl passed filter: EventLength = "
00285 << EventLength << " and total ADC = "
00286 << TotAdc << endl;
00287
00288 return JobCResult::kPassed;
00289
00290 }
00291
00292
00293
00294 const Registry &NoiseFilterModule::DefaultConfig() const
00295 {
00296
00297
00298
00299
00300
00301
00302
00303 MSG("NoiseFilter", Msg::kDebug)
00304 << "NoiseFilterModule::DefaultConfig\n";
00305
00306 static Registry r;
00307
00308 std::string name = this->JobCModule::GetName();
00309 name += ".config.default";
00310 r.SetName(name.c_str());
00311
00312 r.UnLockValues();
00313
00314 r.Set("MinPulseHeightFD", 2000);
00315 r.Set("MinEventLengthFD", 2);
00316 r.Set("TriggerTimeCutFD", kTRUE);
00317 r.Set("MinPulseHeightND", 3000);
00318 r.Set("MinEventLengthND", 1);
00319 r.Set("TriggerTimeCutND", kTRUE);
00320
00321 r.LockValues();
00322
00323 return r;
00324
00325 }
00326
00327
00328
00329 void NoiseFilterModule::Config(const Registry& r)
00330 {
00331
00332
00333
00334
00335
00336
00337 MSG("NoiseFilter", Msg::kDebug) << "NoiseFilterModule::Config\n";
00338
00339 Int_t tmpi;
00340
00341 if (r.Get("MinPulseHeightND", tmpi)) { fMinPulseHeightND = tmpi;}
00342 if (r.Get("MinEventLengthND", tmpi)) { fMinEventLengthND = tmpi;}
00343 if (r.Get("TriggerTimeCutND", tmpi)) { fTriggerTimeCutND = tmpi!=0;}
00344 if (r.Get("MinPulseHeightFD", tmpi)) { fMinPulseHeightFD = tmpi;}
00345 if (r.Get("MinEventLengthFD", tmpi)) { fMinEventLengthFD = tmpi;}
00346 if (r.Get("TriggerTimeCutFD", tmpi)) { fTriggerTimeCutFD = tmpi!=0;}
00347
00348 return;
00349
00350 }
00351
00352