EvtAddRawDigitBlockModule Class Reference

#include <EvtAddRawDigitBlockModule.h>

Inheritance diagram for EvtAddRawDigitBlockModule:
JobCModule

List of all members.

Public Member Functions

 EvtAddRawDigitBlockModule ()
 ~EvtAddRawDigitBlockModule ()
JobCResult Reco (MomNavigator *mom)
JobCResult Ana (const MomNavigator *mom)
const RegistryDefaultConfig () const
void Config (const Registry &r)
void BeginJob ()
void EndJob ()
void BookHist (int run, int subrun)

Private Attributes

double fMaxDeltaT
 private data
int fSmallT0
std::string fHM_pots_dir

Detailed Description

Definition at line 24 of file EvtAddRawDigitBlockModule.h.


Constructor & Destructor Documentation

EvtAddRawDigitBlockModule::EvtAddRawDigitBlockModule (  ) 

Definition at line 59 of file EvtAddRawDigitBlockModule.cxx.

00060   : fMaxDeltaT(1.3)
00061   , fSmallT0(20)   // less than 20n crateT0ns is "small"
00062 {
00063    // construct a new "EvtAddRawDigitBlockModule" JobControl module
00064 
00065 }

EvtAddRawDigitBlockModule::~EvtAddRawDigitBlockModule (  ) 

Definition at line 69 of file EvtAddRawDigitBlockModule.cxx.

References Msg::kVerbose, and MSG.

00070 {
00071   MSG("Hepevt", Msg::kVerbose) << "EvtAddRawDigitBlockModule::Destructor\n";
00072 
00073 }


Member Function Documentation

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

Implement this for read only access to the MomNavigator

Reimplemented from JobCModule.

Definition at line 146 of file EvtAddRawDigitBlockModule.cxx.

References VldTimeStamp::AsString(), RawChannelId::AsString(), BookHist(), digit(), BeamMonSpill::fBpmInt, fHM_pots_dir, fSmallT0, HistMan::Get(), VldTimeStamp::GetBOT(), RawDigit::GetChannel(), EvtOverlaySingleton::GetClosestBeamMonSpill(), EvtOverlaySingleton::GetClosestSpillPOTs(), RawChannelId::GetCrate(), RawDigit::GetCrateT0(), EvtOverlaySingleton::GetCrateT0s(), RawDigitDataBlock::GetDatumIter(), MomNavigator::GetFragment(), minos::GetFromWhiteBoard(), VldTimeStamp::GetNanoSec(), RawRecord::GetRawBlockIter(), RawRecord::GetRawHeader(), PlexHandle::GetReadoutType(), RawDaqHeader::GetRun(), VldTimeStamp::GetSec(), RawDaqSnarlHeader::GetSnarl(), RawDaqHeader::GetSubRun(), RawDigit::GetTDC(), Calibrator::GetTimeFromTDC(), VldContext::GetTimeStamp(), RecMinosHdr::GetVldContext(), EvtOverlaySingleton::Instance(), Calibrator::Instance(), Msg::kDebug, JobCResult::kFailed, JobCResult::kPassed, ReadoutType::kScintStrip, Msg::kSynopsis, Msg::kWarning, Munits::microsecond, MSG, CalScheme::Reset(), and run().

00147 {
00148    // Check out current RecSimSnarl Record
00149 
00150   RawRecord* rawrec = 
00151     dynamic_cast<RawRecord*>(mom->GetFragment("RawRecord",0,"DaqSnarl"));
00152   if ( ! rawrec ) {
00153     MSG("Overlay",Msg::kWarning)
00154       << "No RawRecord found" << std::endl;
00155     return JobCResult::kFailed;
00156   }
00157 
00158   const RawDaqSnarlHeader* snarlHdr =
00159     dynamic_cast<const RawDaqSnarlHeader*>(rawrec->GetRawHeader());
00160   if ( ! snarlHdr ) {
00161     MSG("Overlay",Msg::kWarning)
00162       << "No RawDaqSnarlHeader found" << std::endl;
00163     return JobCResult::kFailed;
00164   }
00165 
00166   // book histograms after we know what run/subrun
00167   // can't necessarily use BeginRun() or BeginSubrun() because
00168   // there might not be marker records if MC
00169   static bool first = true;
00170   if ( first ) {
00171     int run = snarlHdr->GetRun();
00172     int subrun = snarlHdr->GetSubRun();
00173     BookHist(run,subrun);
00174     first = false;
00175   }
00176 
00177   VldContext vldc = snarlHdr->GetVldContext();
00178   Calibrator& cal = Calibrator::Instance();
00179   cal.Reset(vldc);
00180   PlexHandle ph(vldc);
00181 
00182   EvtOverlaySingleton& eos = EvtOverlaySingleton::Instance();
00183 
00184   // fill some HistMan histograms
00185   HistMan hm("overlay");
00186 
00187   std::vector<int> tdc0v, tdc1v;
00188   VldTimeStamp t0_0(VldTimeStamp::GetBOT()), t0_1(VldTimeStamp::GetBOT());
00189 
00190   int nrddb = -1;  // which RawDigitDataBlock do we have 
00191   TIter rbitr = rawrec->GetRawBlockIter();
00192   RawDataBlock* rdb = 0;
00193   // need to do cast from TObject
00194   // also rbitr() advances iterator as side effect
00195   while ( (rdb = dynamic_cast<RawDataBlock*>(rbitr())) ) {
00196     RawDigitDataBlock* rddb = dynamic_cast<RawDigitDataBlock*>(rdb);
00197     if ( ! rddb ) continue; // no what we want?
00198 
00199     ++nrddb;  // got one
00200 
00201     // figure out what histograms we might fill
00202     const char* name_small = ((nrddb==0) ? "smallT0 block0":"smallT0 block1");
00203     const char* name_big   = ((nrddb==0) ? "bigT0 block0"  :"bigT0 block1");
00204     TH1D* hsmall = hm.Get<TH1D>(name_small);
00205     TH1D* hbig   = hm.Get<TH1D>(name_big);
00206 
00207     std::vector<int>& tdcv = ((nrddb==0)? tdc0v : tdc1v);
00208 
00209     //RWH test
00210     //if ( nrddb == 0 ) rddb->FormatToOStream(std::cout,"");
00211 
00212 
00213     std::set<VldTimeStamp> t0s = eos.GetCrateT0s(rddb,vldc);
00214     if ( ! t0s.empty() ) {
00215       if (nrddb==0) t0_0 = *(t0s.begin());
00216       else          t0_1 = *(t0s.begin());
00217       if ( t0s.size() > 1 ) {
00218         MSG("Overlay",Msg::kWarning) 
00219           << "!!!!!!! more than one crateT0 nrddb=" << nrddb << endl;
00220       }
00221     } else {
00222         MSG("Overlay",Msg::kWarning) 
00223           << "!!!!!!! no crateT0 nrddb=" << nrddb << endl;      
00224     }
00225 
00226     // loop over the digits
00227     TIter rditer = rddb->GetDatumIter();
00228     RawDigit* digit = 0;
00229     int lastCrate = -1;
00230     VldTimeStamp crateT0;
00231     bool isSmallT0 = true;
00232     while ( ( digit = (RawDigit*)rditer() ) ) {
00233       RawChannelId rcid = digit->GetChannel();
00234       ReadoutType::Readout_t digitType = ph.GetReadoutType(rcid);
00235       if ( ReadoutType::kScintStrip != digitType ) continue;
00236 
00237       // new crate ? check T0 
00238       int crate = rcid.GetCrate();
00239       if ( crate != lastCrate ) {
00240         lastCrate = crate;
00241         crateT0 = digit->GetCrateT0();
00242         isSmallT0 = ( abs(crateT0.GetNanoSec()) < fSmallT0 );
00243       }
00244 
00245       tdcv.push_back(digit->GetTDC());
00246 
00247       // calculate time like AlgDigit would ... (hopefully)
00248       // calibrator returns ticks to seconds (not ns like it says)
00249       double digitTimeNS = cal.GetTimeFromTDC(digit->GetTDC(),rcid)*1.0e9;
00250       //  double calns = digitTimeNS;  // testing
00251       // adjust for skew
00252       digitTimeNS += ( digit->GetCrateT0().GetSec() -
00253                        vldc.GetTimeStamp().GetSec()    ) * 1.0e9;
00254 
00255       double tadj = digitTimeNS - 
00256         ( vldc.GetTimeStamp().GetNanoSec() - crateT0.GetNanoSec() );
00257       tadj *= 1.0e-9;  // convert to seconds
00258 
00259       MSG("Overlay",Msg::kDebug)
00260         << "nrddb " << nrddb << "|" << ((isSmallT0)?"s":"B")
00261         << " tadj = " << setw(8) << tadj/Munits::microsecond << " usec " 
00262         << " TDC " << digit->GetTDC()
00263         //  << " ditiTimeNS " << calns << " / " << digitTimeNS 
00264         //  << " vldc.ns " << vldc.GetTimeStamp().GetNanoSec()
00265         //  << " crateT0.ns " << crateT0.GetNanoSec()
00266         << "  " << rcid.AsString("c")
00267         << endl;
00268 
00269       if ( isSmallT0 ) hsmall->Fill(tadj);
00270       else             hbig->Fill(tadj);
00271 
00272     } // loop over digits
00273 
00274     if ( lastCrate != -1 ) {
00275       // did we see anything?  if not then crateT0 & isSmallT0 are meaningless
00276       TH1I* hseen = hm.Get<TH1I>("rddb seen");
00277       if ( isSmallT0 ) hseen->Fill(name_small,1.0);
00278       else             hseen->Fill(name_big,1.0);
00279 
00280       /*
00281       int ibtype = ((isSmallT0)?0:2) + ((nrddb==0)?0:1);
00282       //hseen->Fill(ibtype);  // how many blocks of each type have we seen
00283       if (   isSmallT0 && nrddb==0 ) hseen->Fill("smallT0 block0",1);
00284       if (   isSmallT0 && nrddb==1 ) hseen->Fill("smallT0 block1",1);
00285       if ( ! isSmallT0 && nrddb==0 ) hseen->Fill("bigT0 block0",1);
00286       if ( ! isSmallT0 && nrddb==1 ) hseen->Fill("bigT0 block1",1);
00287 
00288       MSG("Overlay",Msg::kWarning)
00289         << "#RWH ibtype " << ibtype << " nrddb " << nrddb 
00290         << " isSmallT0 " << isSmallT0 << " crateT0 " << crateT0.AsString("c")
00291         << endl;
00292       */
00293 
00294     }
00295 
00296   } // loop over blocks
00297 
00298   // make some snarl specific histograms
00299 
00300   if ( t0_0 != t0_1 ) {
00301     MSG("Overlay",Msg::kWarning)
00302       << "!!!!!!! RDDB blocks had different crateT0 "
00303       << t0_0.AsString("c") << " " << t0_1.AsString("c") << endl;
00304   }
00305 
00306   std::sort(tdc0v.begin(),tdc0v.end());
00307   std::sort(tdc1v.begin(),tdc1v.end());
00308 
00309   int maxtdc = *(tdc1v.rbegin());
00310   int mintdc = *(tdc1v.begin());
00311 
00312   int snarl = snarlHdr->GetSnarl();
00313   std::ostringstream s;
00314   s << "snarl" << snarl << "_";
00315   std::string name0 = s.str() + "0";
00316   std::string name1 = s.str() + "1";
00317 
00318   MSG("Overlay",Msg::kSynopsis)
00319     << "Snarl " << snarl << " TDC min/max " << mintdc << " " << maxtdc 
00320     << " range " << (maxtdc-mintdc) << endl;
00321 
00322 #undef HIST_INDIVIDUAL
00323 #ifdef HIST_INDIVIDUAL
00324   HistMan hmMany("individual");
00325   TH1I* htdc0 = hmMany.Book<TH1I>(name0.c_str(),name0.c_str(),(maxtdc-mintdc)+1,mintdc,maxtdc+1);
00326   TH1I* htdc1 = hmMany.Book<TH1I>(name1.c_str(),name1.c_str(),(maxtdc-mintdc)+1,mintdc,maxtdc+1);
00327 
00328   for (size_t i=0; i<tdc0v.size(); ++i) htdc0->Fill(tdc0v[i]);
00329   for (size_t i=0; i<tdc1v.size(); ++i) htdc1->Fill(tdc1v[i]);
00330 #endif
00331 
00332   // some info about POTs and beam spill structure 
00333   int index = 0;
00334   minos::GetFromWhiteBoard("EvtInfo","TimeIndex",index);
00335   double pots             = eos.GetClosestSpillPOTs(true);
00336   const BeamMonSpill* bms = eos.GetClosestBeamMonSpill();
00337 
00338   HistMan hmPOTs(fHM_pots_dir.c_str());
00339   hmPOTs.Get<TH1D>("POTs")->Fill(index,pots);
00340   TH2D* hbi =  hmPOTs.Get<TH2D>("BatchIntensity");
00341   if ( tdc0v.size() > 0 ) {
00342     double x = 100. + log((double)(tdc0v.size()));
00343     hbi->Fill(index,7,x);  // scale up so colors work
00344   }
00345   if ( bms ) {
00346     for (int ib = 0; ib < 6; ++ib) {
00347       double batchi = bms->fBpmInt[ib];
00348      hbi->Fill(index,ib,batchi);
00349     }
00350   }
00351 
00352   return JobCResult::kPassed; // All Ok
00353 }

void EvtAddRawDigitBlockModule::BeginJob ( void   )  [virtual]

Implement for notification of begin of job

Reimplemented from JobCModule.

Definition at line 395 of file EvtAddRawDigitBlockModule.cxx.

00396 {
00397 
00398 }

void EvtAddRawDigitBlockModule::BookHist ( int  run,
int  subrun 
)

Definition at line 400 of file EvtAddRawDigitBlockModule.cxx.

References HistMan::Book(), MuELoss::e, fHM_pots_dir, Form(), EvtOverlaySingleton::Instance(), Msg::kInfo, MSG, and tdc_convert.

Referenced by Ana().

00401 {
00402   // protect against being called more than once
00403   static bool first = true;
00404   if ( ! first ) return;
00405   first = false;
00406 
00407   // book some HistMan histograms
00408   HistMan hm("overlay");
00409 
00410   double upper = 20000. * 1.0e-9;  // look over 20usec, in seconds
00411   int ngang = 1;          // 1 or 4 tdc ticks per bin
00412   int nbins = TMath::Nint((double)upper/ (tdc_convert*1.0e-9)) / ngang;
00413 
00414   TH1I* hseen = hm.Book<TH1I>("rddb seen","rddb seen",4,0,4);
00415   hseen->SetBit(TH1::kCanRebin);
00416 
00417   const char* hnames[4] = { "smallT0 block0", "smallT0 block1",
00418                             "bigT0 block0",   "bigT0 block1" };
00419 
00420   for (int ihn=0; ihn<4; ++ihn) {
00421     const char* hname = hnames[ihn];
00422     std::string htitle(hname);
00423     htitle += "; (sec); # digits";
00424     hm.Book<TH1D>(hname,htitle.c_str(),nbins,0,upper);
00425     // can only alphabetize labels after some filling
00426     hseen->Fill(hname,0.0);
00427   }
00428   hseen->LabelsOption("a");
00429 
00430   MSG("Overlay",Msg::kInfo) 
00431     <<"EvtAddRawDigitBlockModule BOOK block[0|1] [small|big]T0 "
00432     << "(" << nbins << ",0," << upper <<")" << endl;
00433 
00434   // set the directory for the POTs info
00435   // separate out by run/subrun so "hadd" doesn't smack them together
00436   fHM_pots_dir = Form("r%ds%d POTs",run,subrun);
00437   HistMan hmPOTs(fHM_pots_dir.c_str());
00438 
00439   // keep track of POTs and 5-6 batch intensities for each snarl
00440   // use "7" for (scaled) # digits in RawDigitDataBlock 0 (Minerva)
00441   EvtOverlaySingleton& eos = EvtOverlaySingleton::Instance();
00442   size_t ntimes = eos.NumUserTimes();
00443 
00444   hmPOTs.Book<TH1D>("POTs","POTs",ntimes,0,ntimes);
00445   hmPOTs.Book<TH2D>("BatchIntensity","BatchIntensity",ntimes,0,ntimes,8,0,8);
00446 
00447 }

void EvtAddRawDigitBlockModule::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 380 of file EvtAddRawDigitBlockModule.cxx.

References fMaxDeltaT, and Registry::Get().

00381 {
00382 //======================================================================
00383 // Configure the module given the registry r
00384 //======================================================================
00385   //const char*  tmps;
00386   double tmpd;
00387   //int    tmpi;
00388 
00389   if (r.Get("MaxDeltaT", tmpd)) { fMaxDeltaT = tmpd; }
00390 
00391 }

const Registry & EvtAddRawDigitBlockModule::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 356 of file EvtAddRawDigitBlockModule.cxx.

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

00357 {
00358 //======================================================================
00359 // Create a registry which holds the default configuration and return it
00360 //======================================================================
00361   static Registry r;
00362  
00363   // Set name of config
00364   std::string name = this->GetName();
00365   name += ".config.default";
00366   r.SetName(name.c_str());
00367 
00368   // Set values of config
00369   r.UnLockValues();
00370 
00371   r.Set("MaxDeltaT",1.3);  // warn if found snarl data is more than this away
00372 
00373   r.LockValues();
00374 
00375   return r;
00376 }

void EvtAddRawDigitBlockModule::EndJob (  )  [virtual]

Implement for notification of end of job

Reimplemented from JobCModule.

Definition at line 451 of file EvtAddRawDigitBlockModule.cxx.

References Msg::kInfo, and MSG.

00452 {
00453 
00454   MSG("Hepevt",Msg::kInfo)
00455     << "EvtAddRawDigitBlockModule Added " << endl;
00456 
00457 }

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

Implement this for read-write access to the MomNavigator

Find the RawRecord and add a RawDigitDataBlock from real data

Reimplemented from JobCModule.

Definition at line 77 of file EvtAddRawDigitBlockModule.cxx.

References RawRecord::AdoptRawBlock(), VldTimeStamp::AsString(), EvtOverlaySingleton::FindClosestDaqSnarl(), EvtOverlaySingleton::FindLowerBoundDaqMonitor(), fMaxDeltaT, EvtOverlaySingleton::GetClosestRawDigitDataBlock(), MomNavigator::GetFragment(), EvtOverlaySingleton::GetLowerBoundRawVtmTimeInfoBlock(), EvtOverlaySingleton::GetMonitorTimeDifference(), RawRecord::GetRawHeader(), EvtOverlaySingleton::GetSnarlTimeDifference(), VldContext::GetTimeStamp(), RecMinosHdr::GetVldContext(), EvtOverlaySingleton::Instance(), EvtOverlaySingleton::IsValidMonitor(), EvtOverlaySingleton::IsValidSnarl(), JobCResult::kAOK, Msg::kError, JobCResult::kFailed, Msg::kWarning, and MSG.

00078 {
00080 
00081   // get what we can
00082   RawRecord* rawrec = 
00083     dynamic_cast<RawRecord*>(mom->GetFragment("RawRecord",0,"DaqSnarl"));
00084   if ( ! rawrec ) return JobCResult::kFailed;
00085 
00086   const RawDaqSnarlHeader* snarlHdr =
00087     dynamic_cast<const RawDaqSnarlHeader*>(rawrec->GetRawHeader());
00088   if ( ! snarlHdr ) return JobCResult::kFailed;
00089 
00090   VldTimeStamp vts = snarlHdr->GetVldContext().GetTimeStamp();
00091 
00092   EvtOverlaySingleton& eos = EvtOverlaySingleton::Instance();
00093   eos.FindClosestDaqSnarl(vts);  // find it
00094   if ( ! eos.IsValidSnarl() ) {
00095     MSG("EvtDataOverlay",Msg::kError) << "invalid DaqSnarl match for "
00096                                       << vts.AsString("c") << std::endl;
00097     return JobCResult::kFailed;
00098   }
00099   double deltat = eos.GetSnarlTimeDifference();
00100   if ( std::abs(deltat) > fMaxDeltaT ) {
00101     MSG("EvtDataOverlay",Msg::kWarning) << "found closest DaqSnarl record was " 
00102                                         << deltat << " away from " 
00103                                         << vts.AsString("c") << std::endl;
00104   }
00105 
00106   // get an unowned pointer to the raw block in the .mdaq.root file
00107   const RawDigitDataBlock* origRDDB = eos.GetClosestRawDigitDataBlock();
00108 
00109   // now get our very own copy ... to love and keep forever
00110   RawDigitDataBlock* copyRDDB = new RawDigitDataBlock(*origRDDB);
00111 
00112   // oh, wait, I can't keep this poor little thing
00113   // I have neither the means nor wherewithal to care for it
00114   // guess I'll look around for a good home
00115   rawrec->AdoptRawBlock(copyRDDB);
00116 
00117   // Minerva also expects NtpSRTimeStatus to be filled
00118   // ... that is filled from the DaqMonitor stream RawVtmTimeInfoBlock
00119   // we're not faking up a DaqMonitor stream, so just find the right
00120   // one of those blocks and copy it into the DaqSnarl stream
00121   eos.FindLowerBoundDaqMonitor(vts);  // find it
00122   if ( ! eos.IsValidMonitor() ) {
00123     MSG("EvtDataOverlay",Msg::kError) << "invalid DaqMonitor match for "
00124                                       << vts.AsString("c") << std::endl;
00125     return JobCResult::kFailed;
00126   }
00127   double deltatm = eos.GetMonitorTimeDifference();
00128   // record time should preceed requested time (req-found>0)
00129   if ( deltatm > fMaxDeltaT || deltatm < 0 ) {
00130     MSG("EvtDataOverlay",Msg::kWarning) << "found lowerbound DaqMonitor record was " 
00131                                         << deltatm << " away from " 
00132                                         << vts.AsString("c") << std::endl;
00133   }
00134 
00135   // get an unowned pointer to the raw block in the .mdaq.root file
00136   const RawVtmTimeInfoBlock* origRVTIB = 
00137     eos.GetLowerBoundRawVtmTimeInfoBlock();
00138   RawVtmTimeInfoBlock* copyRVTIB = new RawVtmTimeInfoBlock(*origRVTIB);
00139   rawrec->AdoptRawBlock(copyRVTIB);
00140 
00141   return JobCResult::kAOK; // All Ok
00142 }


Member Data Documentation

Definition at line 61 of file EvtAddRawDigitBlockModule.h.

Referenced by Ana(), and BookHist().

private data

Definition at line 58 of file EvtAddRawDigitBlockModule.h.

Referenced by Config(), and Reco().

Definition at line 59 of file EvtAddRawDigitBlockModule.h.

Referenced by Ana().


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

Generated on 2 Nov 2017 for loon by  doxygen 1.6.1