EconAna.hh 2.71 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 78 79 80 81 82 83 84 85 86
#ifndef EconAna_HH
#define EconAna_HH

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

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

#include "Buffering/EconSim.hh"


class EconAna {
public:
  EconAna(const EconSim &e, unsigned nHistory=100000) :
    fEconSim(e) {
    
    std::ostringstream sout;
    sout << "EconAna" << std::setw(2) << std::setfill('0')
	 << fEconSim.econNumber();
    
    std::string sHgcroc[18]={"00","01","02","03","04","05","06","07","08",
			     "09","10","11","12","13","14","15","16","17"};

    hMapWordsVsChannels=new TH1I((sout.str()+"MapWordsVsChannels").c_str(),
				";Number of channels per HGCROC packet;Number of words per HGCROC packet",73,0,73);
    hLabelWordsVsChannels=new TH1I((sout.str()+"LabelWordsVsChannels").c_str(),
				   ";Number of channels per HGCROC packet;Number of words per HGCROC packet",73,0,73);
    
    hTotalWords=new TH1D((sout.str()+"TotalWords").c_str(),
			      ";Total number of words",1000,0,1000);
    hEventBufferUsed=new TH1D((sout.str()+"EventBufferUsed").c_str(),
			      ";Number of event buffer words used",10000,0,10000);
    hEventBufferUsedHistory=new TH1I((sout.str()+"EventBufferUsedHistory").c_str(),
				     ";BX;Number of event buffer words used",nHistory,0,nHistory);
    
    for(unsigned c(0);c<=72;c++) {
      hMapWordsVsChannels->Fill(c,fEconSim.channelsToWords(c,true));
      hLabelWordsVsChannels->Fill(c,fEconSim.channelsToWords(c,false));
    }
    
    
    for(unsigned h(0);h<18;h++) {
      hChannels[h]=new TH1D((sout.str()+"Hgcroc"+sHgcroc[h]+"Channels").c_str(),
			    ";Number of channels per HGCROC packet",73,0,73);
      hWords[h]=new TH1D((sout.str()+"Hgcroc"+sHgcroc[h]+"Words").c_str(),
			 ";Number of words per HGCROC packet",60,0,60);
      hWordsVsChannels[h]=new TH2D((sout.str()+"Hgcroc"+sHgcroc[h]+"WordsVsChannels").c_str(),
				   ";Number of channels per HGCROC packet;Number of words per HGCROC packet",73,0,73,60,0,60);
    }
  }
  
  void analyseZs(uint64_t bx) {
    unsigned nWords(0);
    for(unsigned h(0);h<18;h++) {
      hChannels[h]->Fill(fEconSim.numberOfChannels(h));
      hWords[h]->Fill(fEconSim.numberOfWords(h));
      hWordsVsChannels[h]->Fill(fEconSim.numberOfChannels(h),fEconSim.numberOfWords(h));
      nWords+=fEconSim.numberOfWords(h);
    }
    hTotalWords->Fill(nWords);
  }
  
  void analyseBx(uint64_t bx) {
    hEventBufferUsed->Fill(fEconSim.fEventBuffer.used());
    hEventBufferUsedHistory->Fill(bx,fEconSim.fEventBuffer.used());
  }

private:
  const EconSim &fEconSim;

  TH1I *hMapWordsVsChannels;
  TH1I *hLabelWordsVsChannels;

  TH1D *hChannels[18];
  TH1D *hWords[18];
  TH2D *hWordsVsChannels[18];

  TH1D *hTotalWords;
  TH1D *hEventBufferUsed;
  TH1I *hEventBufferUsedHistory;
};

#endif