Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

CheckND.cxx

Go to the documentation of this file.
00001 
00002 // $Id: CheckND.cxx,v 1.2 2007/03/01 17:02:25 rhatcher Exp $
00003 //
00004 // FILL_IN: [Document your code!!]
00005 //
00006 // n.tagg1@physics.ox.ac.uk
00008 #include "CheckND.h"
00009 #include "MessageService/MsgService.h"
00010 #include "MinosObjectMap/MomNavigator.h"
00011 #include "JobControl/JobCModuleRegistry.h" // For JOBMODULE macro
00012 #include "TTree.h"
00013 #include "TFile.h"
00014 #include "RawData/RawDigitDataBlock.h"
00015 #include "RawData/RawRecord.h"
00016 #include "RawData/RawDaqSnarlHeader.h"
00017 #include "DataUtil/GetRawBlock.h"
00018 #include "DataUtil/GetRawHeader.h"
00019 #include "SpillTiming/SpillTimeFinder.h"
00020 #include "Calibrator/Calibrator.h"
00021 #include "RawData/RawDigit.h"
00022 #include "RawData/RawVtmTimeInfoBlock.h"
00023 #include "OnlineUtil/mdTriggerCodes.h"
00024 #include <vector>
00025 #include <algorithm>
00026 #include <string>
00027 #include <TSystem.h>
00028 #include <TFile.h>
00029 #include <TH1.h>
00030 
00031 JOBMODULE(CheckND, "CheckND",
00032           "CheckND");
00033 
00034 CVSID("$Id: CheckND.cxx,v 1.2 2007/03/01 17:02:25 rhatcher Exp $");
00035 
00036 
00037 //......................................................................
00038 
00039 CheckND::CheckND()
00040 {
00041   fRawHist=fAdcHist=fHitHist=0;
00042 }
00043 
00044 //......................................................................
00045 
00046 CheckND::~CheckND()
00047 {
00048   TFile f("checknd.root","RECREATE");
00049   if(fAdcHist) fAdcHist->Write();
00050   if(fHitHist) fHitHist->Write();
00051   f.Write();
00052   f.Close();
00053 }
00054 
00055 //......................................................................
00056 
00057 JobCResult CheckND::Ana(const MomNavigator* mom)
00058 {
00059 
00060   static int latch53 = 0;
00061 
00062   const RawDaqSnarlHeader* header = 
00063     DataUtil::GetRawHeader<RawDaqSnarlHeader>(mom);
00064   if(header) {
00065     if((header->GetTrigSrc() & TRIGGER_BIT_SPILL)>0) {
00066 
00067       const RawDigitDataBlock* rddb = 
00068         DataUtil::GetRawBlock<RawDigitDataBlock>(mom);
00069       
00070       if(rddb) {
00071         
00072         rddb->SetDebugFlags(0);
00073         if(!fRawHist) fRawHist = new TH1F("hRaw","hRaw",5400000,0,54e6);
00074         if(!fAdcHist) fAdcHist = new TH1F("hAdc","hAdc",3000,-1000,2000);
00075         if(!fHitHist) fHitHist = new TH1F("hHit","hHit",3000,-1000,2000);
00076         
00077         fRawHist->Reset();
00078 
00079         double hits = 0;
00080         double ntdc = 0;
00081         double qtdc = 0;
00082         double q = 0;
00083         int first_tdc = 54000000;
00084         
00085         RawDigit *rawdigit;
00086         TIter iter = rddb->GetDatumIter();
00087         TObject* tobj;
00088         while( (tobj=iter.Next() ) ) {
00089           if( ( rawdigit = dynamic_cast<RawDigit*>(tobj) ) ) {;
00090             RawDigit* rawdigit = dynamic_cast<RawDigit*>(tobj);
00091             fRawHist->Fill(rawdigit->GetTDC(),rawdigit->GetADC());
00092             fAdcHist->Fill(rawdigit->GetTDC()-latch53,rawdigit->GetADC());
00093             fHitHist->Fill(rawdigit->GetTDC()-latch53);
00094             hits +=1;
00095             ntdc += rawdigit->GetTDC();
00096             qtdc += rawdigit->GetTDC()*rawdigit->GetADC();
00097             q    += rawdigit->GetADC();
00098             if(rawdigit->GetTDC() < first_tdc) first_tdc = rawdigit->GetTDC();
00099           }
00100         }
00101         cout << "Caught spill: "
00102              << "hits: " << hits
00103              << "\tq: " << q
00104              << "\tntdc: " << ntdc/hits
00105              << "\tqtdc: " << qtdc/q
00106              << "\tfirst: "  << first_tdc
00107              << "\tfirst-latch: "  << first_tdc-latch53
00108              << endl;
00109       }
00110     }
00111   }
00112   
00113   const std::vector<const RawVtmTimeInfoBlock*> vtmBlocks = 
00114     DataUtil::GetRawBlocks<RawVtmTimeInfoBlock>(mom);
00115   
00116   if(vtmBlocks.size()>0) {
00117 
00118     //for(UInt_t i=0;i<vtmBlocks.size(); i++) {
00119     //  vtmBlocks[i]->Print();
00120     // }
00121     
00122     // Find if a new value has been latched.
00123     static int sLast10MHz =0;
00124     if(vtmBlocks[0]->GetSpillTimeGPS() != sLast10MHz) {
00125       
00126       sLast10MHz = vtmBlocks[0]->GetSpillTimeGPS();
00127       
00128       // Get time to nearest spill.
00129       VldContext cx = vtmBlocks[0]->GetVldContext();
00130       VldTimeStamp spill = SpillTimeFinder::Instance().
00131         GetTimeOfRecentSpill(cx);
00132       
00133       int nsec_spill = spill.GetNanoSec();
00134       int nsec_10MHz = (int)(1e9*(double)vtmBlocks[0]->GetSpillTimeGPS()/10e6);
00135       int nsec_53MHz = (int)(1e9*(double)vtmBlocks[0]->GetSpillTimeRF()
00136                              /(double)vtmBlocks[0]->GetLastTimeStamp());
00137       
00138       static double offset_tot=0;
00139       static double nspill = 0;
00140 
00141       offset_tot +=  nsec_spill-nsec_10MHz;
00142       nspill += 1;
00143       
00144       std::cout << "Sec: " << spill.GetSec()
00145                 << "\tGPS latch: " << nsec_10MHz
00146                 << "\t RF latch: " << nsec_53MHz
00147                 << "\t spill: " << nsec_spill
00148                 << "\t spill-gps: " << nsec_spill-nsec_10MHz
00149                 << "\t GPS-RF: " << nsec_10MHz - nsec_53MHz
00150                 << std::endl;
00151       std::cout << "Avg spill-gps: " << offset_tot / nspill << endl;
00152 
00153 
00154       latch53 = vtmBlocks[0]->GetSpillTimeRF();
00155     }
00156   } 
00157   
00158   return JobCResult::kPassed;
00159 }
00160 
00161 //......................................................................
00162 
00163 const Registry& CheckND::DefaultConfig() const
00164 {
00165 //======================================================================
00166 // Supply the default configuration for the module
00167 //======================================================================
00168   static Registry r; // Default configuration for module
00169 
00170   // Set name of config
00171   std::string name = this->GetName();
00172   name += ".config.default";
00173   r.SetName(name.c_str());
00174 
00175   // Set values in configuration
00176   r.UnLockValues();
00177 
00178 
00179 
00180   r.LockValues();
00181 
00182   return r;
00183 }
00184 
00185 //......................................................................
00186 
00187 void CheckND::Config(const Registry& /*r*/)
00188 {
00189 //======================================================================
00190 // Configure the module given the Registry r
00191 //======================================================================
00192 
00193 }
00194 

Generated on Mon Feb 15 11:06:31 2010 for loon by  doxygen 1.3.9.1