]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PHOS/AliPHOSCalibHistoProducer.cxx
Added #include <cassert> by request of Mateusz Ploskon
[u/mrichter/AliRoot.git] / PHOS / AliPHOSCalibHistoProducer.cxx
CommitLineData
1ab07e55 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16/* $Id$ */
17
18///////////////////////////////////////////////////////////////////////////////
19// Class AliPHOSCalibHistoProducer accumulating histograms
20// with amplitudes per PHOS channel
21// It is intended to run at DAQ computers (LDC, GDC, HLT or MOOD)
22// and it fills the histograms with amplitudes per channel.
23// Usage example see in PHOS/macros/Shuttle/AliPHOSCalibHistoProducer.C
24//
25// Author: Boris Polichtchouk, 4 October 2006
26///////////////////////////////////////////////////////////////////////////////
27
28#include "AliLog.h"
29#include "AliPHOSCalibHistoProducer.h"
30#include "TH1.h"
a3925367 31#include "TH2F.h"
1ab07e55 32#include "TFile.h"
4fc0021f 33#include "AliPHOSRawDecoder.h"
92908c5a 34#include "AliRawReader.h"
1ab07e55 35
36ClassImp(AliPHOSCalibHistoProducer)
37
38//-----------------------------------------------------------------------------
383d8adb 39AliPHOSCalibHistoProducer::AliPHOSCalibHistoProducer() :
a3925367 40 fRawDecoder(0),fHistoFile(0),fUpdatingRate(100),fIsOldRCUFormat(kFALSE),
67346abc 41 fEvents(0),fNbins(100),fXlow(0.),fXup(1000.)
1ab07e55 42{
383d8adb 43 // Constructor: initializes data members
1ab07e55 44 // Checks existence of histograms which might have been left
45 // from the previous runs to continues their filling
46
47 fHistoFile = new TFile("calibHisto.root","update");
a3925367 48
1ab07e55 49 for(Int_t module=0; module<5; module++) {
50 for(Int_t column=0; column<56; column++) {
51 for(Int_t row=0; row<64; row++) {
52 char hname[128];
53 sprintf(hname,"mod%dcol%drow%d",module,column,row);
54 TH1F* hist = (TH1F*)fHistoFile->Get(hname);
55 if(hist)
56 fAmpHisto[module][column][row]=hist;
a3925367 57 else
58 fAmpHisto[module][column][row] = 0;
1ab07e55 59 }
60 }
61 }
62}
63
67346abc 64//-----------------------------------------------------------------------------
65AliPHOSCalibHistoProducer::AliPHOSCalibHistoProducer(Int_t nbinsx, Double_t xlow, Double_t xup) :
66 fRawDecoder(0),fHistoFile(0),fUpdatingRate(100),fIsOldRCUFormat(kFALSE),
67 fEvents(0),fNbins(nbinsx),fXlow(xlow),fXup(xup)
68{
69 // Constructor: initializes data members.
70 // Checks existence of histograms which might have been left
71 // from the previous runs to continues their filling.
72 // In addition sets number of bins, low and upper limits common for all histograms.
73
74 fHistoFile = new TFile("calibHisto.root","update");
75
76 for(Int_t module=0; module<5; module++) {
77 for(Int_t column=0; column<56; column++) {
78 for(Int_t row=0; row<64; row++) {
79 char hname[128];
80 sprintf(hname,"mod%dcol%drow%d",module,column,row);
81 TH1F* hist = (TH1F*)fHistoFile->Get(hname);
82 if(hist)
83 fAmpHisto[module][column][row]=hist;
84 else
85 fAmpHisto[module][column][row] = 0;
86 }
87 }
88 }
89}
90
1ab07e55 91//-----------------------------------------------------------------------------
383d8adb 92AliPHOSCalibHistoProducer::~AliPHOSCalibHistoProducer()
1ab07e55 93{
383d8adb 94 // Destructor
95
96 UpdateHistoFile();
383d8adb 97 if(fHistoFile) delete fHistoFile;
383d8adb 98
1ab07e55 99}
100
101//-----------------------------------------------------------------------------
383d8adb 102AliPHOSCalibHistoProducer::AliPHOSCalibHistoProducer(const AliPHOSCalibHistoProducer &histoproducer) :
a3925367 103 TObject(histoproducer),fRawDecoder(histoproducer.fRawDecoder),fHistoFile(histoproducer.fHistoFile),
383d8adb 104 fUpdatingRate(histoproducer.fUpdatingRate),fIsOldRCUFormat(histoproducer.fIsOldRCUFormat),
67346abc 105 fEvents(histoproducer.fEvents),fNbins(histoproducer.fNbins),fXlow(histoproducer.fXlow),fXup(histoproducer.fXup)
1ab07e55 106{
383d8adb 107 //Copy constructor.
108
109 for(Int_t module=0; module<5; module++) {
110 for(Int_t column=0; column<56; column++) {
111 for(Int_t row=0; row<64; row++) {
112 char hname[128];
113 sprintf(hname,"mod%dcol%drow%d",module,column,row);
114 TH1F* hist = (TH1F*)histoproducer.fHistoFile->Get(hname);
115 if(hist)
116 fAmpHisto[module][column][row]= new TH1F(*hist);
117 else
118 fAmpHisto[module][column][row]=0;
119 }
120 }
121 }
1ab07e55 122}
123
383d8adb 124//-----------------------------------------------------------------------------
125AliPHOSCalibHistoProducer& AliPHOSCalibHistoProducer::operator=
126(const AliPHOSCalibHistoProducer &histoproducer)
127{
128 //Assignment operator.
129
130 if(this != &histoproducer) {
131
a3925367 132 fRawDecoder = histoproducer.fRawDecoder;
383d8adb 133 fHistoFile = histoproducer.fHistoFile;
134 fUpdatingRate = histoproducer.fUpdatingRate;
135 fIsOldRCUFormat = histoproducer.fIsOldRCUFormat;
383d8adb 136 fEvents = histoproducer.fEvents;
67346abc 137 fEvents = histoproducer.fEvents;
138 fNbins = histoproducer.fNbins;
139 fXlow = histoproducer.fXlow;
140 fXup = histoproducer.fXup;
141
383d8adb 142 for(Int_t module=0; module<5; module++) {
143 for(Int_t column=0; column<56; column++) {
144 for(Int_t row=0; row<64; row++) {
145 if(fAmpHisto[module][column][row]){
146 delete fAmpHisto[module][column][row];
147 fAmpHisto[module][column][row] = histoproducer.fAmpHisto[module][column][row];
148 }
149 else
150 fAmpHisto[module][column][row] = histoproducer.fAmpHisto[module][column][row];
151 }
152 }
153 }
154
155
156 }
157
158 return *this;
159}
1ab07e55 160//-----------------------------------------------------------------------------
161void AliPHOSCalibHistoProducer::Run()
162{
383d8adb 163 // Reads raw data of current event and fills amplitude histograms
1ab07e55 164 // The histograms are written to file every fUpdatingRate events
165
a3925367 166 if(!fRawDecoder) AliFatal("Raw decoder not set!");
167
4fc0021f 168 Double_t energy;
a3925367 169 Int_t mod,col,row;
383d8adb 170
72429802 171 if(fIsOldRCUFormat)
a3925367 172 fRawDecoder->SetOldRCUFormat(kTRUE);
173
174 while(fRawDecoder->NextDigit()) {
4fc0021f 175
a3925367 176 if(fRawDecoder->IsLowGain()) continue;
383d8adb 177
a3925367 178 energy = fRawDecoder->GetEnergy();
a3925367 179
180 mod = fRawDecoder->GetModule()-1;
181 col = fRawDecoder->GetColumn()-1;
182 row = fRawDecoder->GetRow()-1;
183
383d8adb 184 if(fAmpHisto[mod][col][row]) {
185 fAmpHisto[mod][col][row]->Fill(energy);
1ab07e55 186 }
383d8adb 187 else {
188 char hname[128];
189 sprintf(hname,"mod%dcol%drow%d",mod,col,row);
67346abc 190 fAmpHisto[mod][col][row] = new TH1F(hname,hname,fNbins,fXlow,fXup);
a3925367 191 fAmpHisto[mod][col][row]->Fill(energy);
383d8adb 192 }
88852132 193 }
383d8adb 194 // update histograms in local file every 100th event
88852132 195 if(fEvents != 0 && fEvents%fUpdatingRate == 0) {
a3925367 196 AliInfo(Form("Updating histo file, event %d, run %d\n",
197 fEvents,fRawDecoder->GetRawReader()->GetRunNumber()));
383d8adb 198 UpdateHistoFile();
a3925367 199 }
200
201 // UpdateHistoFile();
202 // AliInfo(Form("%d events of run %d processed.",iEvent,runNum));
383d8adb 203
383d8adb 204 fEvents++;
a3925367 205
1ab07e55 206}
207
208//-----------------------------------------------------------------------------
209void AliPHOSCalibHistoProducer::UpdateHistoFile()
210{
211 // Write histograms to file
212
213 if(!fHistoFile) return;
214 if(!fHistoFile->IsOpen()) return;
215
216 TH1F* hist=0;
a3925367 217 char hname[128];
218 char htitle[128];
1ab07e55 219
220 for(Int_t module=0; module<5; module++) {
a3925367 221 sprintf(hname,"hMeanE%d",module);
222 sprintf(htitle,"Mean energies in module %d",module);
223 TH2F hMeanE(hname,htitle,56,0.,56.,64,0.,64);
224
1ab07e55 225 for(Int_t column=0; column<56; column++) {
226 for(Int_t row=0; row<64; row++) {
227 hist = fAmpHisto[module][column][row];
228 if(hist) hist->Write(hist->GetName(),TObject::kWriteDelete);
a3925367 229 if(hist) hMeanE.SetBinContent(column,row,hist->GetMean());
1ab07e55 230 }
231 }
a3925367 232 hMeanE.Write(hMeanE.GetName(),TObject::kWriteDelete);
1ab07e55 233 }
234
235}