MnvRawDigitSuppression Class Reference

#include <MnvRawDigitSuppression.h>

Inheritance diagram for MnvRawDigitSuppression:
JobCModule

List of all members.

Public Member Functions

 MnvRawDigitSuppression ()
 ~MnvRawDigitSuppression ()
JobCResult Reco (MomNavigator *mom)
JobCResult Ana (const MomNavigator *mom)
const RegistryDefaultConfig () const
void Config (const Registry &r)
void BeginJob ()
void EndJob ()

Private Member Functions

Int_t FindMCTDCMinMax (SimSnarlRecord *simrec, RawDigitDataBlock *rddb, Long_t &tdcMin, Long_t &tdcMax)
 private methods for doing the work
Int_t ZeroDataBasedOnTDC (RawDigitDataBlock *rddb, Long_t tdcMin, Long_t tdcMax)

Private Attributes

double fSideBandWindowTime
 private data
double fEvtExtentMinTime
double fEvtExtentMaxTime
std::string fResolutionScheme
int fResolutionValue
Long_t fSideBandTDCticks
Long_t fMinAllowedTDCticks
Long_t fMaxAllowedTDCticks
VldContext fVldContext

Detailed Description

Definition at line 27 of file MnvRawDigitSuppression.h.


Constructor & Destructor Documentation

MnvRawDigitSuppression::MnvRawDigitSuppression (  ) 

Definition at line 82 of file MnvRawDigitSuppression.cxx.

00083   : fSideBandWindowTime(0.4e-6)   // window padding around real MC digits
00084   , fEvtExtentMinTime(0.4e-6)     // min duration of central window
00085   , fEvtExtentMaxTime(1.0e-6)     // max duration of central window
00086   , fResolutionScheme("bothWide") // what to do if both user + digit time window
00087   , fResolutionValue(MnvRDSHelper::kUnknown)
00088 {
00089    // construct a new "MnvRawDigitSuppression" JobControl module
00090 
00091 }

MnvRawDigitSuppression::~MnvRawDigitSuppression (  ) 

Definition at line 95 of file MnvRawDigitSuppression.cxx.

References Msg::kVerbose, and MSG.

00096 {
00097   MSG("Hepevt", Msg::kVerbose) << "MnvRawDigitSuppression::Destructor\n";
00098 
00099 }


Member Function Documentation

JobCResult MnvRawDigitSuppression::Ana ( const MomNavigator mom  )  [virtual]

Implement this for read only access to the MomNavigator

Reimplemented from JobCModule.

Definition at line 683 of file MnvRawDigitSuppression.cxx.

References JobCResult::kPassed.

00684 {
00685 
00686   return JobCResult::kPassed; // All Ok
00687 }

void MnvRawDigitSuppression::BeginJob ( void   )  [virtual]

Implement for notification of begin of job

Reimplemented from JobCModule.

Definition at line 736 of file MnvRawDigitSuppression.cxx.

References HistMan::Book(), MuELoss::e, fEvtExtentMaxTime, fEvtExtentMinTime, fMaxAllowedTDCticks, fMinAllowedTDCticks, fResolutionScheme, fResolutionValue, fSideBandTDCticks, fSideBandWindowTime, MnvRDSHelper::kbothNarrow, MnvRDSHelper::kbothWide, Msg::kFatal, Msg::kInfo, MnvRDSHelper::konlyDigit, MnvRDSHelper::konlyUser, MnvRDSHelper::kUnknown, MSG, and tdc_convert.

00737 {
00738   // protect against being called more than once
00739   static bool first = true;
00740   if ( ! first ) return;
00741   first = false;
00742 
00743   // make sure that the configuration makes sense
00744   if ( fEvtExtentMinTime > fEvtExtentMaxTime ) {
00745     // user got it backwards
00746     MSG("MnvRawDigitSuppression",Msg::kInfo) 
00747       << "MnvRawDigitSuppression::BeginJob() min>max ... swap them "
00748       << std::endl;
00749     std::swap(fEvtExtentMinTime,fEvtExtentMaxTime);
00750   }
00751   // is the ResolutionScheme one of the know variants?
00752   
00753   // who knows what case structure the user supplied ... squash it lower
00754   std::string lowerS = fResolutionScheme;
00755   std::transform(lowerS.begin(), lowerS.end(), lowerS.begin(), ::tolower);
00756   fResolutionValue = MnvRDSHelper::kUnknown;
00757   if ( lowerS == "onlydigit"  ) fResolutionValue = MnvRDSHelper::konlyDigit;
00758   if ( lowerS == "onlyuser"   ) fResolutionValue = MnvRDSHelper::konlyUser;
00759   if ( lowerS == "bothnarrow" ) fResolutionValue = MnvRDSHelper::kbothNarrow;
00760   if ( lowerS == "bothwide"   ) fResolutionValue = MnvRDSHelper::kbothWide;
00761   if ( fResolutionValue == MnvRDSHelper::kUnknown ) {
00762     MSG("MnvRawDigitSuppression",Msg::kFatal)
00763       << "Don't know how to interpret \"" << fResolutionScheme << "\" "
00764       << "(" << lowerS << ") ... should be one of: "
00765       << "\"onlyDigit\",\"onlyUser\",\"bothNarrow\",\"bothWide\""
00766       << std::endl;
00767   }
00768 
00769   // come on be sensible, also prevent under/overflow
00770   if ( fEvtExtentMinTime < 0 ) fEvtExtentMinTime=0;
00771   if ( fEvtExtentMaxTime > 2 ) fEvtExtentMaxTime=2;
00772 
00773   fSideBandTDCticks   = TMath::CeilNint((fSideBandWindowTime*1.0e9)/tdc_convert);
00774   fMinAllowedTDCticks = TMath::CeilNint((fEvtExtentMinTime*1.0e9)/tdc_convert);
00775   fMaxAllowedTDCticks = TMath::CeilNint((fEvtExtentMaxTime*1.0e9)/tdc_convert);
00776 
00777   MSG("MnvRawDigitSuppression",Msg::kInfo) 
00778     << "MnvRawDigitSuppression::BeginJob() " << std::endl
00779     << " fSideBandWindowTime = "
00780     << fSideBandWindowTime << " seconds (" << fSideBandTDCticks << " ticks)" 
00781     << std::endl
00782     << " fEvtExtentMinTime = "
00783     << fEvtExtentMinTime << " seconds (" << fMinAllowedTDCticks << ")" 
00784     << std::endl
00785     << " fEvtExtentMaxTime = "
00786     << fEvtExtentMaxTime << " seconds (" << fMaxAllowedTDCticks << ")"
00787     << std::endl
00788     << " fResolutionScheme \"" << fResolutionScheme << "\" (" << fResolutionValue << ")" 
00789     << std::endl;
00790 
00791   // book some HistMan histograms
00792   HistMan hm("suppression");
00793 
00794   double upper = 10000. * 1.0e-9;  // look over 10usec, in seconds
00795   int ngang = 1;          // 1 or 4 tdc ticks per bin
00796   int nbins = TMath::Nint((double)upper/ (tdc_convert*1.0e-9)) / ngang;
00797 
00798   // "length" of the Minerva MC event in sec (binned in TDC ticks)
00799   TH1D* dtdcEvt  = hm.Book<TH1D>("dtdcEvt","Event #Delta TDC (sec)",nbins,0,upper);
00800   TH1D* dtdcUser = hm.Book<TH1D>("dtdcUser","User #Delta TDC (sec)",nbins,0,upper);
00801 
00802   // when we have both digit and user window how different were they?
00803   TH1D* dtdcMin = hm.Book<TH1D>("dtdcMin","tmin Digit-User TDC (sec)",2*nbins,-upper,upper);
00804   TH1D* dtdcMax = hm.Book<TH1D>("dtdcMax","tmax Digit-User TDC (sec)",2*nbins,-upper,upper);
00805 
00806   TH1I* hdispo = hm.Book<TH1I>("disposition","disposition",20,0,20);
00807   hdispo->SetBit(TH1::kCanRebin);
00808   // pre-populate labels
00809   hdispo->Fill("MRDSReco",0.0);
00810   hdispo->Fill("Look4RDDBs",0.0);
00811   hdispo->Fill("2RDDB",0.0);
00812   hdispo->Fill("gotDigit=1 gotUser=0",0.0);
00813   hdispo->Fill("gotDigit=0 gotUser=0",0.0);
00814   hdispo->Fill("gotDigit=0 gotUser=1",0.0);
00815   hdispo->Fill("onlyDigit",0.0);
00816   hdispo->Fill("onlyUser",0.0);
00817   hdispo->Fill("bothNarrow",0.0);
00818   hdispo->Fill("bothWide",0.0);
00819   hdispo->Fill("gotBoth use none",0.0);
00820   hdispo->Fill("illegalOrder",0.0);
00821   hdispo->Fill("expandEvtExtentMin",0.0);
00822   hdispo->Fill("narrowEvtExtentMax",0.0);
00823   hdispo->Fill("suppressSome",0.0);
00824   //no// hdispo->LabelsOption("a"); // alphabetize bin ordering
00825 
00826 }

void MnvRawDigitSuppression::Config ( const Registry r  )  [virtual]

Return the actual configuration. If your module directly pulls its configuration from the fConfig Registry, you don't need to override this. Override if you have local config variables.

Reimplemented from JobCModule.

Definition at line 718 of file MnvRawDigitSuppression.cxx.

References fEvtExtentMaxTime, fEvtExtentMinTime, fResolutionScheme, fSideBandWindowTime, and Registry::Get().

00719 {
00720 //======================================================================
00721 // Configure the module given the registry r
00722 //======================================================================
00723   const char*  tmps = 0;
00724   double tmpd;
00725   //int    tmpi;
00726 
00727   if (r.Get("SideBandWindowTime", tmpd)) { fSideBandWindowTime = tmpd; }
00728   if (r.Get("EvtExtentMinTime",   tmpd)) { fEvtExtentMinTime   = tmpd; }
00729   if (r.Get("EvtExtentMaxTime",   tmpd)) { fEvtExtentMaxTime   = tmpd; }
00730   if (r.Get("ResolutionScheme",   tmps)) { fResolutionScheme   = tmps; }
00731 
00732 }

const Registry & MnvRawDigitSuppression::DefaultConfig ( void   )  const [virtual]

Get the default configuration registry. This should normally be overridden. One useful idiom is to implement it like:

const Registry& MyModule::DefaultConfig() const { static Registry cfg; // never is destroyed if (cfg.Size()) return cfg; // already filled it // set defaults: cfg.Set("TheAnswer",42); cfg.Set("Units","unknown"); return cfg; }

Reimplemented from JobCModule.

Definition at line 690 of file MnvRawDigitSuppression.cxx.

References MuELoss::e, JobCModule::GetName(), Registry::LockValues(), Registry::Set(), Registry::UnLockKeys(), and Registry::UnLockValues().

00691 {
00692 //======================================================================
00693 // Create a registry which holds the default configuration and return it
00694 //======================================================================
00695   static Registry r;
00696  
00697   // Set name of config
00698   std::string name = this->GetName();
00699   name += ".config.default";
00700   r.SetName(name.c_str());
00701 
00702   // Set values of config
00703   r.UnLockValues();
00704   r.UnLockKeys();
00705 
00706   r.Set("SideBandWindowTime",0.4e-6);
00707   r.Set("EvtExtentMin",0.4e-6); 
00708   r.Set("EvtExtentMax",1.0e-6); 
00709   r.Set("ResolutionScheme","bothWide"); 
00710 
00711   r.LockValues();
00712 
00713   return r;
00714 }

void MnvRawDigitSuppression::EndJob (  )  [virtual]

Implement for notification of end of job

Reimplemented from JobCModule.

Definition at line 830 of file MnvRawDigitSuppression.cxx.

References Msg::kInfo, and MSG.

00831 {
00832 
00833   MSG("Hepevt",Msg::kInfo)
00834     << "MnvRawDigitSuppression Added " << endl;
00835 
00836 }

Int_t MnvRawDigitSuppression::FindMCTDCMinMax ( SimSnarlRecord simrec,
RawDigitDataBlock rddb,
Long_t &  tdcMin,
Long_t &  tdcMax 
) [private]

private methods for doing the work

Definition at line 427 of file MnvRawDigitSuppression.cxx.

References digit(), RecDataRecord< T >::FindComponent(), fVldContext, RawDigit::GetChannel(), RawChannelId::GetCrate(), RawDigit::GetCrateT0(), RawDigitDataBlock::GetDatumIter(), RawDigiDigitMixIn::GetDigiSignalIndex(), DigiSignal::GetId(), PlexHandle::GetReadoutType(), RawDigit::GetTDC(), DigiSignal::GetTruth(), Msg::kError, DigiSignal::kGenuine, Msg::kInfo, ReadoutType::kScintStrip, Msg::kWarning, MAXMSG, and MSG.

Referenced by Reco().

00430 {
00431 
00432   // we'll also need the 
00433   /*
00434     Class name: TClonesArray    Object name: DigiScintHits
00435     Class name: TObjArray       Object name: DigiSignal
00436   */
00437   const TObject* obj = 0;
00438 
00439   // yes, DigiScintHit*s*
00440   obj = simrec->FindComponent("TClonesArray","DigiScintHits");
00441   const TClonesArray* scinthits = dynamic_cast<const TClonesArray*>(obj);
00442   if ( ! scinthits ) { 
00443     MSG("MnvRawDigitSuppression",Msg::kError)
00444       << "Failed to find 'TClonesArray','DigiScintHits'" << endl;
00445     return 1;
00446   }
00447   Int_t nscinthits = scinthits->GetEntries();
00448 
00449   obj = simrec->FindComponent("TObjArray","DigiSignal");
00450   const TObjArray* signals = dynamic_cast<const TObjArray*>(obj);
00451   if ( ! signals ) { 
00452     MSG("MnvRawDigitSuppression",Msg::kError)
00453       << "Failed to find 'TObjArray','DigiSignal'" << endl;
00454     return 2;
00455   }
00456   Int_t nsignals = signals->GetEntries();
00457 
00458   MSG("MnvRawDigitSuppression",Msg::kInfo) 
00459     << "================== MnvRawDigitSuppression scinthits " 
00460     << nscinthits << " signals " << nsignals << endl;
00461 
00462   // build a map of signals "index" to signal objects
00463   std::map<UInt_t,const DigiSignal*> signalMap;
00464   TIter signalIter(signals);
00465   while ( ( obj = signalIter.Next() ) ) {
00466     const DigiSignal* asignal = dynamic_cast<const DigiSignal*>(obj);
00467     if ( asignal ) signalMap[asignal->GetId()] = asignal;
00468   }
00469 
00470   // now loop over rddb digits which should be the Minerva event itself
00471 
00472   PlexHandle ph(fVldContext);
00473 
00474   // assume user has initialized 
00475   //* tdcMin = 1<<31;
00476   //* int tdcMax = 0;
00477 
00478   TIter rditer = rddb->GetDatumIter();
00479   RawDigit* digit = 0;
00480   int lastCrate = -1;
00481   VldTimeStamp crateT0;
00482   while ( ( digit = (RawDigit*)rditer() ) ) {
00483     RawDigiDigitMixIn* mixin = dynamic_cast<RawDigiDigitMixIn*>(digit);
00484     if ( ! mixin ) {
00485       MAXMSG("MnvRawDigitSuppression",Msg::kWarning,20)
00486         << "HEY! digit wasn't a RawDigiDigitMixIn ... not MC!" << endl;
00487       break;
00488     }
00489 
00490     RawChannelId rcid = digit->GetChannel();
00491     ReadoutType::Readout_t digitType = ph.GetReadoutType(rcid);
00492     if ( ReadoutType::kScintStrip != digitType ) continue;
00493     
00494     // new crate ? check T0 
00495     int crate = rcid.GetCrate();
00496     if ( crate != lastCrate ) {
00497       lastCrate = crate;
00498       crateT0 = digit->GetCrateT0();
00499     }
00500     
00501     int    digitTDC   = digit->GetTDC();
00502     UInt_t indxSignal = mixin->GetDigiSignalIndex();
00503     
00504     // indxSignal *isn't* the index into the TObjArray
00505     // but rather the DigiSignal has a index value which we must find
00506     // by comparing to signal->GetId()
00507     // see Truthifier.cxx line 148+
00508 
00509     std::map<UInt_t,const DigiSignal*>::const_iterator mitr2signal =
00510       signalMap.find(indxSignal);
00511     if ( mitr2signal != signalMap.end() ) {
00512       const DigiSignal* signal = mitr2signal->second;
00513       if ( signal->GetTruth() & DigiSignal::kGenuine ) {
00514         // hey, this one's real
00515         if ( digitTDC > tdcMax ) tdcMax = digitTDC;
00516         if ( digitTDC < tdcMin ) tdcMin = digitTDC;
00517         MAXMSG("MnvRawDigitSuppression",Msg::kInfo,20)
00518           << "indxSignal " << std::setw(5) << indxSignal 
00519           << " was     kGenuine, TDC " 
00520           << std::setw(10) << digitTDC << std::endl; 
00521       } else {
00522         MAXMSG("MnvRawDigitSuppression",Msg::kInfo,20)
00523           << "indxSignal " << std::setw(5) << indxSignal 
00524           << " was NOT kGenuine, TDC " 
00525           << std::setw(10) << digitTDC << std::endl; 
00526       }
00527     } else {
00528       MAXMSG("MnvRawDigitSuppression",Msg::kWarning,20)
00529         << "hey, digit claims to have come from signal id " << indxSignal
00530         << " but no such signal exists" << std::endl;
00531     }
00532     
00533   } // loop over digits
00534   
00535   return 0;
00536 }

JobCResult MnvRawDigitSuppression::Reco ( MomNavigator mom  )  [virtual]

Implement this for read-write access to the MomNavigator

Find the RawRecord and get both RawDigitDataBlocks

Reimplemented from JobCModule.

Definition at line 103 of file MnvRawDigitSuppression.cxx.

References fEvtExtentMaxTime, fEvtExtentMinTime, FindMCTDCMinMax(), fMaxAllowedTDCticks, fMinAllowedTDCticks, fResolutionScheme, fResolutionValue, fSideBandTDCticks, fSideBandWindowTime, fVldContext, HistMan::Get(), VldTimeStamp::GetBOT(), VldContext::GetDetector(), MomNavigator::GetFragment(), minos::GetFromWhiteBoard(), VldTimeStamp::GetNanoSec(), RawRecord::GetRawBlockIter(), RawRecord::GetRawHeader(), Calibrator::GetTDCFromTime(), VldContext::GetTimeStamp(), EvtOverlaySingleton::GetUserTmax(), EvtOverlaySingleton::GetUserTmin(), RecMinosHdr::GetVldContext(), EvtOverlaySingleton::Instance(), Calibrator::Instance(), JobCResult::kAOK, MnvRDSHelper::kbothNarrow, MnvRDSHelper::kbothWide, Msg::kError, JobCResult::kFailed, Msg::kInfo, MnvRDSHelper::konlyDigit, MnvRDSHelper::konlyUser, JobCResult::kPassed, ElecType::kQIE, Msg::kWarning, MSG, Munits::ns, CalScheme::Reset(), tdc_convert, and ZeroDataBasedOnTDC().

00104 {
00106 
00107   MSG("MnvRawDigitSuppression",Msg::kInfo) 
00108     << "================== MnvRawDigitSuppression called" << endl;
00109 
00110   HistMan hm("suppression");
00111   TH1I* hdispo = hm.Get<TH1I>("disposition");
00112   hdispo->Fill("MRDSReco",1.0);
00113 
00114   // get what we can
00115   RawRecord* rawrec = 
00116     dynamic_cast<RawRecord*>(mom->GetFragment("RawRecord",0,"DaqSnarl"));
00117   if ( ! rawrec ) {
00118     MSG("MnvRawDigitSuppression",Msg::kWarning)
00119       << "Failed to get RawRecord from DaqSnarl stream" << std::endl;
00120     return JobCResult::kFailed;
00121   }
00122 
00123   SimSnarlRecord* simrec = 
00124     dynamic_cast<SimSnarlRecord*>(mom->GetFragment("SimSnarlRecord"));
00125   if ( ! simrec ) {
00126     MSG("MnvRawDigitSuppression",Msg::kWarning)
00127       << "Failed to get SimSnarlRecord" << std::endl;
00128     return JobCResult::kFailed;
00129   }
00130 
00131   const RawDaqSnarlHeader* snarlHdr =
00132     dynamic_cast<const RawDaqSnarlHeader*>(rawrec->GetRawHeader());
00133   if ( ! snarlHdr ) {
00134     MSG("MnvRawDigitSuppression",Msg::kWarning)
00135       << "Failed to get RawDaqSnarlHeader" << std::endl;
00136     return JobCResult::kFailed;
00137   }
00138 
00139   MSG("MnvRawDigitSuppression",Msg::kInfo) 
00140     << "================== MnvRawDigitSuppression looking for RDDBs" << endl;
00141   hdispo->Fill("Look4RDDBs",1.0);
00142 
00143   RawDigitDataBlock* rddb = 0;
00144   RawDigitDataBlock* rddbs[100] = {0,0}; // should really only be two
00145   int indx_rddb = -1;  // which RawDigitDataBlock do we have 
00146   TIter rbitr = rawrec->GetRawBlockIter();
00147   RawDataBlock* rdb = 0;
00148   // need to do cast from TObject
00149   // also rbitr() advances iterator as side effect
00150   while ( (rdb = dynamic_cast<RawDataBlock*>(rbitr())) ) {
00151     rddb = dynamic_cast<RawDigitDataBlock*>(rdb);
00152     if ( ! rddb ) continue; // not what we want?
00153     ++indx_rddb;  // got one
00154     if ( indx_rddb > 1 ) {
00155       MSG("MnvRawDigitSuppression",Msg::kError) 
00156         << "HEY! RawDigitDataBlocks # " << indx_rddb 
00157         << " found, should only be 0+1" << endl;
00158     }
00159     // protect overrunning the array
00160     if ( indx_rddb < 100 ) {
00161       rddbs[indx_rddb] = rddb;
00162     } else {
00163       break;
00164     }
00165   }
00166 
00167   // need two blocks to proceed
00168   int nrddb = indx_rddb+1;
00169   if ( nrddb < 2 ) {
00170     MSG("MnvRawDigitSuppression",Msg::kError) 
00171       << "HEY! only " << nrddb << " RawDigitDataBlocks found,"
00172       << " can't proceed on this procedure" << endl;
00173     return JobCResult::kPassed;  // put don't fail the path
00174   }
00175   hdispo->Fill("2RDDB",1.0);
00176 
00177   MSG("MnvRawDigitSuppression",Msg::kInfo) 
00178     << "================== MnvRawDigitSuppression nrddb=" << nrddb << endl;
00179 
00180 
00181   fVldContext = snarlHdr->GetVldContext();
00182   Calibrator& cal = Calibrator::Instance();
00183   cal.Reset(fVldContext);
00184 
00185   VldTimeStamp snarl_ts = fVldContext.GetTimeStamp();
00186 
00187   // user needs to initialize these before the call
00188   Long_t tdcMinDigit = 0x7FFFFFFF;
00189   Long_t tdcMaxDigit = 0;
00190 
00191   rddb = rddbs[0];  // assumes 0th is the MC ... should really check
00192   Int_t findError = FindMCTDCMinMax(simrec,rddb,tdcMinDigit,tdcMaxDigit);
00193   if ( findError ) {
00194     MSG("MnvRawDigitSuppression",Msg::kWarning)
00195       << "FindMCTDCMinMax returned error" << findError << std::endl;
00196     // if we can't find DigiScintHits or DigiSignal it may be that
00197     // the Minerva MC event didn't deposit any energy in MINOS
00198     // let's just move on for now, perhaps user set external times
00199     //return JobCResult::kAOK; // All Ok
00200   } else {
00201     // tdc_ticks * tdc_convert = ns
00202     double evtlen_sec = 1.0e-9*((tdcMaxDigit-tdcMinDigit+1)*tdc_convert);
00203     hm.Get<TH1D>("dtdcEvt")->Fill(evtlen_sec);
00204   }
00205 
00206   // some spills might lack tdc[Min|Max]Digit because
00207   // (1) Minerva supplied no particles
00208   // (2) the Minerva MC particles produced no real digits
00209   // allow for alternative means of reducing the window of interest
00210   //
00211   bool gotDigit = (tdcMinDigit<=tdcMaxDigit);
00212 
00213   Long_t tdcMinUser = 0x7FFFFFFF;
00214   Long_t tdcMaxUser = 0;
00215 
00216   bool gotUser = true;
00217   int index = -1;
00218   gotUser &= minos::GetFromWhiteBoard("EvtInfo","TimeIndex",index);
00219   // can't do anything here is no index
00220   if ( index >= 0 ) {
00221     
00222     // hopefully someone has writen what we should use on the whiteboard
00223     VldTimeStamp crateT0(VldTimeStamp::GetBOT());
00224     gotUser &= minos::GetFromWhiteBoard("EvtInfo","CrateT0",crateT0);
00225     if ( ! gotUser ) {
00226       MSG("Suppression",Msg::kError) << "failed to get EvtInfo/CrateT0" 
00227                                      << std::endl;
00228     }
00229 
00230     Long_t snarlStartNS = snarl_ts.GetNanoSec() - crateT0.GetNanoSec();
00231     Double_t snarlStartSec = snarlStartNS * Munits::ns;
00232 
00233     // Minerva times start from a spill T0 later than the MINOS one
00234     double vtxoffsetT = 0;
00235     gotUser &= minos::GetFromWhiteBoard("EvtInfo","VtxOffsetT",vtxoffsetT);
00236     if ( ! gotUser ) {
00237       MSG("Suppression",Msg::kError) << "failed to get EvtInfo/VtxOffsetT" 
00238                                      << std::endl;
00239     }
00240     snarlStartSec += vtxoffsetT;
00241 
00242     RawChannelId rcidQIE(fVldContext.GetDetector(),ElecType::kQIE,0,0);
00243     Long_t spillStartTDC = 
00244       Calibrator::Instance().GetTDCFromTime(snarlStartSec,rcidQIE);
00245 
00246     // get user supplied time range (relative to spill start)
00247     EvtOverlaySingleton& eos = EvtOverlaySingleton::Instance();
00248     double tminUser = eos.GetUserTmin(index);
00249     double tmaxUser = eos.GetUserTmax(index);
00250 
00251     hm.Get<TH1D>("dtdcUser")->Fill(tmaxUser-tminUser);
00252 
00253     // make sure values aren't magic flags of being "unset"
00254     if ( tminUser == -99 ) {
00255       // nothing to be done
00256       gotUser = false;
00257     } else if ( tmaxUser == +99 ) {
00258       // user only supplied tmin ... but not tmax
00259       tmaxUser = tminUser + fEvtExtentMaxTime; // this will do
00260     }
00261 
00262     if ( gotUser ) {
00263       tdcMinUser = spillStartTDC + TMath::Nint((tminUser*1.0e9)/tdc_convert);
00264       tdcMaxUser = spillStartTDC + TMath::Nint((tmaxUser*1.0e9)/tdc_convert);
00265     }
00266 
00267   }
00268 
00269   /***
00270    Several possible cases at this point
00271 
00272     1. no user supplied times (original case)
00273       a. found tdcMinDigit/tdcMaxDigit -- use tdcMinDigit/tdcMaxDigit
00274       b. neither -- no suppression
00275     2. user supplied times
00276       a. no tdcMinDigit/tdcMaxDigit -- the use tdcMinUser/tdcMaxUser
00277       b. both -- needs some resolution scheme
00278 
00279     resolution schemes to derive tdcMinEvt/tdcMaxEvt if have both is 4-fold:
00280 
00281       onlyDigit use tdcMinDigit/tdcMaxDigit
00282       onlyUser use tdcMinUser/tdcMaxUser
00283       bothNarrow use max(tdcMinDigit,tdcMinUser)/min(tdcMaxDigit,tdcMaxUser)
00284       bothWide use min(tdcMinDigit,tdcMinUser)/max(tdcMaxDigit,tdcMaxUser)
00285 
00286     "bothWide" is most inclusive of the digits and proposed as the default. 
00287 
00288      I'll also supply the option that given tdcMinEvt that after the above, 
00289      tdcMaxEvt can be forced to have limits:
00290 
00291        tdcMinEvt = max(tdcMaxEvt,tdcMinEvt+tdcMinEvtExtent)
00292        tdcMaxEvt = min(tdcMaxEvt,tdcMinEvt+tdcMaxEvtExtent)
00293 
00294      to avoid extremely short or long event extent window ... though one 
00295      can always set the min/max extents so that these are a NO-OP 
00296      (using 0/bignum). But this will deal can help mitigate the long 
00297      tdcMaxDigit tails due to late decays.
00298   */
00299 
00300   Long_t tdcMin = 0x7FFFFFFF;
00301   Long_t tdcMax = 0;
00302 
00303   if ( ! gotUser ) {
00304     if ( gotDigit ) {
00305       tdcMin = tdcMinDigit;
00306       tdcMax = tdcMaxDigit;
00307       hdispo->Fill("gotDigit=1 gotUser=0",1.0);
00308     } else {
00309       // nada ... no suppression
00310       hdispo->Fill("gotDigit=0 gotUser=0",1.0);
00311       return JobCResult::kAOK;
00312     }
00313   } else {
00314     // we do have user times
00315     if ( ! gotDigit ) {
00316       // no digit info, so fall back to user supplied times
00317       tdcMin = tdcMinUser;
00318       tdcMax = tdcMaxUser;
00319       hdispo->Fill("gotDigit=0 gotUser=1",1.0);
00320     } else {
00321       // got both:  need some resolution
00322 
00323       // histogram stuff
00324       double dtmin = 1.0e-9*((tdcMinDigit-tdcMinUser)*tdc_convert);
00325       hm.Get<TH1D>("dtdcMin")->Fill(dtmin);
00326       double dtmax = 1.0e-9*((tdcMaxDigit-tdcMaxUser)*tdc_convert);
00327       hm.Get<TH1D>("dtdcMax")->Fill(dtmax);
00328 
00329       switch ( fResolutionValue ) {
00330       case MnvRDSHelper::konlyDigit: {
00331         tdcMin = tdcMinDigit;
00332         tdcMax = tdcMaxDigit;
00333         hdispo->Fill("onlyDigit",1.0);
00334         break;
00335       }
00336       case MnvRDSHelper::konlyUser: {
00337         tdcMin = tdcMinUser;
00338         tdcMax = tdcMaxUser;
00339         hdispo->Fill("onlyUser",1.0);
00340         break;
00341       }
00342       case MnvRDSHelper::kbothNarrow: {
00343         tdcMin = TMath::Max(tdcMinDigit,tdcMinUser);
00344         tdcMax = TMath::Min(tdcMaxDigit,tdcMaxUser);
00345         hdispo->Fill("bothNarrow",1.0);
00346         break;
00347       }
00348       case MnvRDSHelper::kbothWide: {
00349         tdcMin = TMath::Min(tdcMinDigit,tdcMinUser);
00350         tdcMax = TMath::Max(tdcMaxDigit,tdcMaxUser);
00351         hdispo->Fill("bothWide",1.0);
00352         break;
00353       }
00354       default: {
00355         // should never happen, but don't do suppression ...
00356         hdispo->Fill("gotBoth use none",1.0);
00357         return JobCResult::kAOK;
00358       }
00359       } // end of switch
00360 
00361       MSG("MnvRawDigitSuppression",Msg::kInfo) 
00362         << "================== MnvRawDigitSuppression resolution (choosen/digit/user) " 
00363         << "min " << tdcMin << "/" << tdcMinDigit << "/" << tdcMinUser << " "
00364         << "max " << tdcMax << "/" << tdcMaxDigit << "/" << tdcMaxUser << " "
00365         << " \"" << fResolutionScheme << "\""
00366         << std::endl;
00367 
00368     }
00369   }
00370 
00371   if ( tdcMin >= tdcMax ) {
00372     hdispo->Fill("illegalOrder",1.0);
00373     MSG("MnvRawDigitSuppression",Msg::kInfo) 
00374       << "no MC tdc range found " << tdcMin << " " << tdcMax << endl;
00375     return JobCResult::kAOK; // All Ok
00376   }
00377 
00378   if ( tdcMax < tdcMin+fMinAllowedTDCticks ) {
00379     hdispo->Fill("expandEvtExtentMin",1.0);
00380     MSG("MnvRawDigitSuppression",Msg::kInfo) 
00381     << "================== MnvRawDigitSuppression limited by MinAllowedEvtTime " 
00382     << tdcMin << " " << tdcMax << " (delta=" << (tdcMax-tdcMin)
00383     << "<" << fMinAllowedTDCticks << " (" << fEvtExtentMinTime << "s))"
00384     << std::endl;
00385     tdcMax = tdcMin+fMinAllowedTDCticks;
00386   }
00387 
00388   if ( tdcMax > tdcMin+fMaxAllowedTDCticks ) {
00389     hdispo->Fill("narrowEvtExtentMax",1.0);
00390     MSG("MnvRawDigitSuppression",Msg::kInfo) 
00391     << "================== MnvRawDigitSuppression limited by MaxAllowedEvtTime " 
00392     << tdcMin << " " << tdcMax << " (delta=" << (tdcMax-tdcMin)
00393     << ">" << fMaxAllowedTDCticks << " (" << fEvtExtentMaxTime << "s))"
00394     << std::endl;
00395     tdcMax = tdcMin+fMaxAllowedTDCticks;
00396   }
00397 
00398 
00399   MSG("MnvRawDigitSuppression",Msg::kInfo) 
00400     << "================== MnvRawDigitSuppression settled on tdc Min Max " 
00401     << tdcMin << " " << tdcMax << endl;
00402 
00403   MSG("MnvRawDigitSuppression",Msg::kInfo) 
00404     << "================== MnvRawDigitSuppression window "
00405     << fSideBandWindowTime << " seconds = " 
00406     << fSideBandTDCticks << " TDC counts " 
00407     << ", tdc_convert = " << tdc_convert
00408     << endl;
00409   tdcMin -= fSideBandTDCticks;
00410   tdcMax += fSideBandTDCticks;
00411   MSG("MnvRawDigitSuppression",Msg::kInfo) 
00412     << "================== MnvRawDigitSuppression allowed tdc Min Max " 
00413     << tdcMin << " " << tdcMax << endl;
00414 
00415   rddb = rddbs[1];
00416   Int_t nsuppressed = ZeroDataBasedOnTDC(rddb,tdcMin,tdcMax);
00417   if ( nsuppressed > 0 ) hdispo->Fill("suppressSome",1.0);
00418 
00419   MSG("MnvRawDigitSuppression",Msg::kInfo) 
00420     << "================== MnvRawDigitSuppression suppressed " 
00421     << nsuppressed << " digits" << endl;
00422   
00423   return JobCResult::kAOK; // All Ok
00424 }

Int_t MnvRawDigitSuppression::ZeroDataBasedOnTDC ( RawDigitDataBlock rddb,
Long_t  tdcMin,
Long_t  tdcMax 
) [private]

Definition at line 539 of file MnvRawDigitSuppression.cxx.

References bfld::AsString(), RawDigitDataBlock::ClearUnpackedRawDigits(), RawDataBlock::GetBlockId(), RawDataBlock::GetData(), RawCrateStatus::GetElecType(), RawCrateStatus::GetEntries(), RawBlockId::GetSimFlag(), RawDataBlock::GetSize(), RawDigit::GetTDC(), SimFlag::kDaqFakeData, SimFlag::kData, Msg::kFatal, SimFlag::kMC, ElecType::kQIE, SimFlag::kReroot, SimFlag::kUnknown, ElecType::kVA, and MSG.

Referenced by Reco().

00541 {
00542   // for packed digits w/ TDC values < tdcMin or > tdcMax
00543   // suppress them by zero-ing out ADC values and changing raw channel
00544   // address to non-scint channel
00545   Int_t nzeroed = 0;
00546 
00547 
00548   // !!!!! DANGER WILL ROBINSON, DANGER !!!!
00549   // removing const'ness
00550   const Int_t *p   = rddb->GetData();
00551   const Int_t *end = p + rddb->GetSize();
00552   RawBlockId rbid = rddb->GetBlockId();
00553   RawDigitCrateStatus* cratestatus  = 0;
00554   RawDigit*            rawdigit = 0;
00555 
00556   // skip # words, blockid and checksum
00557   p += 3;
00558 
00559   while ( p < end ) {
00560     // use normal unpack procedure to advance pointer appropriately
00561     cratestatus = new RawDigitCrateStatus(rbid,p);
00562     Int_t ncdigits = cratestatus->GetEntries(); // how many digits in crate
00563 
00564     // loop over digit pairs (triplets?)
00565     for (Int_t icdigit = 0; icdigit < ncdigits; ++icdigit) {
00566       // assume that the readout type is consistent for whole crate
00567       // and that the status block knows what it is
00568       ElecType::Elec_t etype = cratestatus->GetElecType();
00569 
00570       // keep track of the start of this digit 
00571       // ... unpacking will move "p" forward, but we need to retain this p
00572       // cast away matey!    
00573       Int_t* pmod = const_cast<Int_t*>(p);
00574 
00575       
00576       // pointer is advanced by RawDigit ctor
00577       // knowing how many words it needed to eat
00578       switch (rbid.GetSimFlag()) {
00579       case SimFlag::kData:
00580       case SimFlag::kDaqFakeData:
00581         switch (etype) {
00582         case ElecType::kVA:
00583           rawdigit = new RawVaDigit(p,cratestatus);
00584           break;
00585         case ElecType::kQIE:
00586           rawdigit = new RawQieDigit(p,cratestatus);
00587           break;
00588         default:
00589           rawdigit = new RawDigit(p,cratestatus);
00590           break;
00591         }
00592         break;
00593       case SimFlag::kMC:
00594         // these are like their base RawVaDigit or RawQieDigit
00595         // with the additions of RawDigiDigitMixIn
00596         switch (etype) {
00597         case ElecType::kVA:
00598           rawdigit = new RawVaDigiDigit(p,cratestatus);
00599           break;
00600         case ElecType::kQIE:
00601           rawdigit = new RawQieDigiDigit(p,cratestatus);
00602           break;
00603         default:
00604           MSG("MnvRawDigitSuppression",Msg::kFatal) 
00605             << "SimFlag::kMC but not kVA or kQIE" << std::endl;
00606           break;             
00607         };
00608         break;
00609       case SimFlag::kReroot:
00610         // these are like their base RawVaDigit or RawQieDigit
00611         // with the additions of RawMCDigitMixIn
00612         switch (etype) {
00613         case ElecType::kVA:
00614           rawdigit = new RawVaMCDigit(p,cratestatus);
00615           break;
00616         case ElecType::kQIE:
00617           rawdigit = new RawQieMCDigit(p,cratestatus);
00618           break;
00619         default:
00620           MSG("MnvRawDigitSuppression",Msg::kFatal) 
00621             << "SimFlag::kReroot but not kVA or kQIE" << std::endl;
00622               break;
00623         }
00624         break;
00625       case SimFlag::kUnknown:
00626       default:
00627         MSG("MnvRawDigitSuppression",Msg::kFatal) 
00628           << "SimFlag::k" << SimFlag::AsString(rbid.GetSimFlag()) << std::endl;
00629         break;
00630       }
00631       
00632       Int_t tdc = rawdigit->GetTDC();
00633       if ( tdc < tdcMin || tdc > tdcMax ) {
00634         // here's where we abuse the supposedly "const" data
00635         
00636         // turns out that ChAdd (channel address) of 0x0001ffff is never 
00637         // connected to any scint strips (unforunately 0x0 is sometimes
00638         // used for VACommonMode)
00639         
00640         // so "p" is the pointer to the first word in the digit info
00641         // which contains the channel address info _and_ adc values
00642         const int adcmaskQIE = 0x0000ffff; // QIE
00643         const int adcmaskVA  = 0x00003fff; // VA
00644         const int chanmask   = ( 0x1fff << 16 );
00645 
00646         int zeroADC = ~adcmaskQIE;
00647         switch (etype) {
00648         case ElecType::kVA:   zeroADC = ~adcmaskVA;  break;
00649         case ElecType::kQIE:  zeroADC = ~adcmaskQIE; break;
00650         default:
00651           MSG("MnvRawDigitSuppression",Msg::kFatal) 
00652             << "ElecType::k" << ElecType::AsString(etype) << std::endl;
00653           break;
00654         }
00655         
00656         // zero out the ADC bits
00657         *pmod &= zeroADC;  // doing this causes failure
00658         // set all bits in the ChAdd
00659         *pmod |= chanmask;
00660 
00661         ++nzeroed;
00662 
00663       } // digit within TDC range
00664 
00665       // done with this digit ... delete it
00666       delete rawdigit; rawdigit = 0;
00667 
00668     } // loop on digits in crate
00669 
00670     // done with this crate status ... delete it
00671     delete cratestatus; cratestatus = 0;
00672 
00673   } // loop on crates
00674 
00675   // make sure that any unpacking is re-done from this point on
00676   rddb->ClearUnpackedRawDigits();
00677 
00678   return nzeroed;
00679 
00680 }


Member Data Documentation

Definition at line 61 of file MnvRawDigitSuppression.h.

Referenced by BeginJob(), Config(), and Reco().

Definition at line 59 of file MnvRawDigitSuppression.h.

Referenced by BeginJob(), Config(), and Reco().

Definition at line 69 of file MnvRawDigitSuppression.h.

Referenced by BeginJob(), and Reco().

Definition at line 68 of file MnvRawDigitSuppression.h.

Referenced by BeginJob(), and Reco().

Definition at line 63 of file MnvRawDigitSuppression.h.

Referenced by BeginJob(), Config(), and Reco().

Definition at line 64 of file MnvRawDigitSuppression.h.

Referenced by BeginJob(), and Reco().

Definition at line 67 of file MnvRawDigitSuppression.h.

Referenced by BeginJob(), and Reco().

private data

Definition at line 58 of file MnvRawDigitSuppression.h.

Referenced by BeginJob(), Config(), and Reco().

Definition at line 71 of file MnvRawDigitSuppression.h.

Referenced by FindMCTDCMinMax(), and Reco().


The documentation for this class was generated from the following files:

Generated on 22 Nov 2017 for loon by  doxygen 1.6.1