ROOT logo
#include "hshowerrawhist.h"
#include "hruntimedb.h"
#include "hevent.h"
#include "hspectrometer.h"
#include "hdetector.h"
#include "hshowerdetector.h"
#include "hcategory.h"
#include "hmatrixcatiter.h"
#include "hlocation.h"
#include "hshowerraw.h"
#include "hdebug.h"
#include "hades.h"
#include "hiterator.h"
#include "showerdef.h"

#include "TH1.h"
#include "TH2.h"

ClassImp(HShowerRawHist)

HShowerRawHist::~HShowerRawHist(void) {
     if (fIter) delete fIter;
}

Bool_t HShowerRawHist::init() {
    printf("initialization of shower calibrater\n");
    m_nEvents = 0;
    HShowerDetector *pShowerDet = (HShowerDetector*)gHades->getSetup()
                                                  ->getDetector("Shower");

    m_pRawCat=gHades->getCurrentEvent()->getCategory(catShowerRaw);
    if (!m_pRawCat) {
      m_pRawCat=pShowerDet->buildCategory(catShowerRaw);

      if (!m_pRawCat) return kFALSE;
      else gHades->getCurrentEvent()
                         ->addCategory(catShowerRaw, m_pRawCat, "Shower");
    }

    fIter=(HIterator*)m_pRawCat->MakeIterator();

    bookHist();
    return kTRUE;
}

Bool_t HShowerRawHist::finalize(void) {
   finalizeHist();
   return kTRUE;
}

Int_t HShowerRawHist::execute()
{
  HShowerRaw *pRaw;

  Int_t n = 0;
 
  fIter->Reset();
  while((pRaw = (HShowerRaw *)fIter->Next()))
  {
    fillHist(pRaw);
    n++;
  }

  m_nEvents++;
  return 0;
}

/***********************************************************/
/* definition of private function                          */
/***********************************************************/

Bool_t HShowerRawHist::bookHist() {
  Char_t name[80];
  Char_t title[80];

  m_pChargeHist = new TH1F("ShowerRawCharge", "Shower Raw Level - Charge",
                   128, 0, 256); 

  for(Int_t i = 0; i < 3; i++) {
     sprintf(name, "ShowerRawCharge%d", i);
     sprintf(title, "Shower Raw Level - Charge in Module %d", i);
     m_pChargeModHist[i] = new TH1F(name, title, 128, 0, 256);   

     sprintf(name, "ShowerRawAvg%d", i);
     sprintf(title, "Shower Raw Level - Average Charge in Module %d", i);
     m_pChargeAvgHist[i] =new TH2F(name, title, 32, 0, 32, 32, 0, 32);
      
     sprintf(name, "ShowerRawFreq%d", i);
     sprintf(title, "Shower Raw Level - Freq in Module %d", i);
     m_pChargeFreqHist[i] =new TH2F(name, title, 32, 0, 32, 32, 0, 32);
  }
  return kTRUE;
}


Bool_t HShowerRawHist::fillHist(Int_t nModule, Int_t nRow, 
                                         Int_t nColumn, Float_t fCharge) {

  m_pChargeHist->Fill(fCharge);
  m_pChargeModHist[nModule]->Fill(fCharge);

  m_pChargeFreqHist[nModule]->Fill(nColumn, nRow, 1 );
  m_pChargeAvgHist[nModule]->Fill(nColumn, nRow, fCharge);

  return kTRUE; 
}

Bool_t HShowerRawHist::fillHist(HShowerRaw* pRaw) {
  Int_t mod = pRaw->getModule();
  Int_t row = pRaw->getRow();
  Int_t col = pRaw->getCol();
  Float_t charge = pRaw->getCharge();

  fillHist(mod, row, col, charge);

  return kTRUE;
}


Bool_t HShowerRawHist::finalizeHist() {
  for(Int_t i = 0; i < 3; i++) {
    m_pChargeAvgHist[i]->Divide(m_pChargeFreqHist[i]);
    m_pChargeFreqHist[i]->Scale(1.0/m_nEvents);
  }  
  writeHist();
  return kTRUE;
}

Bool_t HShowerRawHist::writeHist() {
  printf("writing histograms ...\n");
  m_pChargeHist->Write();
  for(Int_t i = 0; i < 3; i++) {
       m_pChargeModHist[i]->Write();  
       m_pChargeFreqHist[i]->Write();  
       m_pChargeAvgHist[i]->Write();  
  }

  return kTRUE;
}

 hshowerrawhist.cc:1
 hshowerrawhist.cc:2
 hshowerrawhist.cc:3
 hshowerrawhist.cc:4
 hshowerrawhist.cc:5
 hshowerrawhist.cc:6
 hshowerrawhist.cc:7
 hshowerrawhist.cc:8
 hshowerrawhist.cc:9
 hshowerrawhist.cc:10
 hshowerrawhist.cc:11
 hshowerrawhist.cc:12
 hshowerrawhist.cc:13
 hshowerrawhist.cc:14
 hshowerrawhist.cc:15
 hshowerrawhist.cc:16
 hshowerrawhist.cc:17
 hshowerrawhist.cc:18
 hshowerrawhist.cc:19
 hshowerrawhist.cc:20
 hshowerrawhist.cc:21
 hshowerrawhist.cc:22
 hshowerrawhist.cc:23
 hshowerrawhist.cc:24
 hshowerrawhist.cc:25
 hshowerrawhist.cc:26
 hshowerrawhist.cc:27
 hshowerrawhist.cc:28
 hshowerrawhist.cc:29
 hshowerrawhist.cc:30
 hshowerrawhist.cc:31
 hshowerrawhist.cc:32
 hshowerrawhist.cc:33
 hshowerrawhist.cc:34
 hshowerrawhist.cc:35
 hshowerrawhist.cc:36
 hshowerrawhist.cc:37
 hshowerrawhist.cc:38
 hshowerrawhist.cc:39
 hshowerrawhist.cc:40
 hshowerrawhist.cc:41
 hshowerrawhist.cc:42
 hshowerrawhist.cc:43
 hshowerrawhist.cc:44
 hshowerrawhist.cc:45
 hshowerrawhist.cc:46
 hshowerrawhist.cc:47
 hshowerrawhist.cc:48
 hshowerrawhist.cc:49
 hshowerrawhist.cc:50
 hshowerrawhist.cc:51
 hshowerrawhist.cc:52
 hshowerrawhist.cc:53
 hshowerrawhist.cc:54
 hshowerrawhist.cc:55
 hshowerrawhist.cc:56
 hshowerrawhist.cc:57
 hshowerrawhist.cc:58
 hshowerrawhist.cc:59
 hshowerrawhist.cc:60
 hshowerrawhist.cc:61
 hshowerrawhist.cc:62
 hshowerrawhist.cc:63
 hshowerrawhist.cc:64
 hshowerrawhist.cc:65
 hshowerrawhist.cc:66
 hshowerrawhist.cc:67
 hshowerrawhist.cc:68
 hshowerrawhist.cc:69
 hshowerrawhist.cc:70
 hshowerrawhist.cc:71
 hshowerrawhist.cc:72
 hshowerrawhist.cc:73
 hshowerrawhist.cc:74
 hshowerrawhist.cc:75
 hshowerrawhist.cc:76
 hshowerrawhist.cc:77
 hshowerrawhist.cc:78
 hshowerrawhist.cc:79
 hshowerrawhist.cc:80
 hshowerrawhist.cc:81
 hshowerrawhist.cc:82
 hshowerrawhist.cc:83
 hshowerrawhist.cc:84
 hshowerrawhist.cc:85
 hshowerrawhist.cc:86
 hshowerrawhist.cc:87
 hshowerrawhist.cc:88
 hshowerrawhist.cc:89
 hshowerrawhist.cc:90
 hshowerrawhist.cc:91
 hshowerrawhist.cc:92
 hshowerrawhist.cc:93
 hshowerrawhist.cc:94
 hshowerrawhist.cc:95
 hshowerrawhist.cc:96
 hshowerrawhist.cc:97
 hshowerrawhist.cc:98
 hshowerrawhist.cc:99
 hshowerrawhist.cc:100
 hshowerrawhist.cc:101
 hshowerrawhist.cc:102
 hshowerrawhist.cc:103
 hshowerrawhist.cc:104
 hshowerrawhist.cc:105
 hshowerrawhist.cc:106
 hshowerrawhist.cc:107
 hshowerrawhist.cc:108
 hshowerrawhist.cc:109
 hshowerrawhist.cc:110
 hshowerrawhist.cc:111
 hshowerrawhist.cc:112
 hshowerrawhist.cc:113
 hshowerrawhist.cc:114
 hshowerrawhist.cc:115
 hshowerrawhist.cc:116
 hshowerrawhist.cc:117
 hshowerrawhist.cc:118
 hshowerrawhist.cc:119
 hshowerrawhist.cc:120
 hshowerrawhist.cc:121
 hshowerrawhist.cc:122
 hshowerrawhist.cc:123
 hshowerrawhist.cc:124
 hshowerrawhist.cc:125
 hshowerrawhist.cc:126
 hshowerrawhist.cc:127
 hshowerrawhist.cc:128
 hshowerrawhist.cc:129
 hshowerrawhist.cc:130
 hshowerrawhist.cc:131
 hshowerrawhist.cc:132
 hshowerrawhist.cc:133
 hshowerrawhist.cc:134
 hshowerrawhist.cc:135
 hshowerrawhist.cc:136
 hshowerrawhist.cc:137
 hshowerrawhist.cc:138
 hshowerrawhist.cc:139
 hshowerrawhist.cc:140