HgcrocAna.hh 1.97 KB
Newer Older
dauncey's avatar
dauncey committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
#ifndef HgcrocAna_HH
#define HgcrocAna_HH

#include <iostream>
#include <iomanip>
#include <cassert>

#include "TH1D.h"
#include "TH1I.h"

#include "Buffering/HgcrocSim.hh"


class HgcrocAna {
public:
  HgcrocAna(const HgcrocSim &h, unsigned nHistory=100000) :
    fHgcrocSim(h), fBusyLength(0) {

    unsigned bd(fHgcrocSim.bufferDepth());
    
    std::string sName("HgcrocAna");

    hEvents=new TH1D((sName+"Events").c_str(),
		     ";Number of events in buffer;BXs",bd,0,bd);
    hL1AEvents=new TH1D((sName+"L1AEvents").c_str(),
			";Number of events in buffer;L1Accepts",bd,0,bd);
    hBusyLength=new TH1D((sName+"BusyLength").c_str(),
			 ";Length of continuous output (Events);Number",1000,0,1000);

    hL1AcceptHistory=new TH1I((sName+"L1AcceptHistory").c_str(),
			    ";BX;L1Accept",nHistory,0,nHistory);
    hEventCompleteHistory=new TH1I((sName+"EventCompleteHistory").c_str(),
			    ";BX;Event complete",nHistory,0,nHistory);
    hEventsHistory=new TH1I((sName+"EventsHistory").c_str(),
			    ";BX;Number of events in buffer",nHistory,0,nHistory);
    hWordsHistory=new TH1I((sName+"WordsHistory").c_str(),
			    ";BX;Number of words transmitted",nHistory,0,nHistory);
  }
  
  void analyseBx(uint64_t bx) {
    hEvents->Fill(fHgcrocSim.numberOfEvents());

    if(fHgcrocSim.l1Accept()) {
      hL1AEvents->Fill(fHgcrocSim.numberOfEvents());
      hL1AcceptHistory->Fill(bx,3);
    }

    if(fHgcrocSim.eventComplete()) hEventCompleteHistory->Fill(bx,2); 
    hEventsHistory->Fill(bx,fHgcrocSim.numberOfEvents());
    hWordsHistory->Fill(bx,fHgcrocSim.numberOfWords());

    if(fHgcrocSim.numberOfEvents()>0) fBusyLength++;
    else {
      if(fBusyLength!=0) {
	hBusyLength->Fill((fBusyLength+1)/fHgcrocSim.eventLength());
	fBusyLength=0;
      }
    }

  }

private:
  const HgcrocSim &fHgcrocSim;

  unsigned fBusyLength;
  
  TH1D *hEvents;
  TH1D *hL1AEvents;
  TH1D *hBusyLength;

  TH1I *hL1AcceptHistory;
  TH1I *hEventCompleteHistory;
  TH1I *hEventsHistory;
  TH1I *hWordsHistory;
};

#endif