ROOT logo
#include "hshowerrawhist.h"
#include "hshowercalhist.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 "hshowercal.h"
#include "hdebug.h"
#include "hades.h"
#include "hiterator.h"
#include "showerdef.h"

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

ClassImp(HShowerCalHist)

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

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

    m_pCalCat=gHades->getCurrentEvent()->getCategory(catShowerCal);
    if (!m_pCalCat) {
      m_pCalCat=pShowerDet->buildCategory(catShowerCal);

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

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

    bookHist();
    return kTRUE;
}

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

Int_t HShowerCalHist::execute()
{
  HShowerCal *pCal;

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

  m_nEvents++;
  return 0;
}

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

Bool_t HShowerCalHist::bookHist() {
  Char_t name[80];
  Char_t title[80];
   
  m_pChargeCalHist = new TH1F("ShowerCalCharge", "Shower Cal Level - Charge",
                   128, 0, 256); 

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

     sprintf(name, "ShowerCalAvg%d", i);
     sprintf(title, "Shower Cal Level - Average Charge in Module %d", i);
     m_pChargeCalAvgHist[i] =new TH2F(name, title, 32, 0, 32, 32, 0, 32);
   //  m_pChargeCalAvgHist[i]->SetDrawOption(colz); 
     sprintf(name, "ShowerCalFreq%d", i);
     sprintf(title, "Shower Cal Level - Freq in Module %d", i);
     m_pChargeCalFreqHist[i] =new TH2F(name, title, 32, 0, 32, 32, 0, 32);
  }
  return kTRUE;
}


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

  m_pChargeCalHist->Fill(fCharge);
  m_pChargeCalModHist[nModule]->Fill(fCharge);

  m_pChargeCalFreqHist[nModule]->Fill(nColumn, nRow, 1 );
  m_pChargeCalAvgHist[nModule]->Fill(nColumn, nRow, fCharge);

  return kTRUE; 
}

Bool_t HShowerCalHist::fillHist(HShowerCal* pCal) {
  Int_t mod = pCal->getModule();
  Int_t row = pCal->getRow();
  Int_t col = pCal->getCol();
  Float_t charge = pCal->getCharge();

  fillHist(mod, row, col, charge);

  return kTRUE;
}


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

Bool_t HShowerCalHist::writeHist() {
  printf("writing histograms ...\n");
  m_pChargeCalHist->Write();
  for(Int_t i = 0; i < 3; i++) {
       m_pChargeCalModHist[i]->Write();  
       m_pChargeCalFreqHist[i]->Write();  
       m_pChargeCalAvgHist[i]->Write();  
  }

  return kTRUE;
}

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