]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PHOS/AliPHOSCalibHistoProducer.cxx
correct coding violation
[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"
1ab07e55 34
35ClassImp(AliPHOSCalibHistoProducer)
36
37//-----------------------------------------------------------------------------
383d8adb 38AliPHOSCalibHistoProducer::AliPHOSCalibHistoProducer() :
a3925367 39 fRawDecoder(0),fHistoFile(0),fUpdatingRate(100),fIsOldRCUFormat(kFALSE),
67346abc 40 fEvents(0),fNbins(100),fXlow(0.),fXup(1000.)
1ab07e55 41{
383d8adb 42 // Constructor: initializes data members
1ab07e55 43 // Checks existence of histograms which might have been left
44 // from the previous runs to continues their filling
45
46 fHistoFile = new TFile("calibHisto.root","update");
a3925367 47
1ab07e55 48 for(Int_t module=0; module<5; module++) {
49 for(Int_t column=0; column<56; column++) {
50 for(Int_t row=0; row<64; row++) {
51 char hname[128];
52 sprintf(hname,"mod%dcol%drow%d",module,column,row);
53 TH1F* hist = (TH1F*)fHistoFile->Get(hname);
54 if(hist)
55 fAmpHisto[module][column][row]=hist;
a3925367 56 else
57 fAmpHisto[module][column][row] = 0;
1ab07e55 58 }
59 }
60 }
61}
62
67346abc 63//-----------------------------------------------------------------------------
64AliPHOSCalibHistoProducer::AliPHOSCalibHistoProducer(Int_t nbinsx, Double_t xlow, Double_t xup) :
65 fRawDecoder(0),fHistoFile(0),fUpdatingRate(100),fIsOldRCUFormat(kFALSE),
66 fEvents(0),fNbins(nbinsx),fXlow(xlow),fXup(xup)
67{
68 // Constructor: initializes data members.
69 // Checks existence of histograms which might have been left
70 // from the previous runs to continues their filling.
71 // In addition sets number of bins, low and upper limits common for all histograms.
72
73 fHistoFile = new TFile("calibHisto.root","update");
74
75 for(Int_t module=0; module<5; module++) {
76 for(Int_t column=0; column<56; column++) {
77 for(Int_t row=0; row<64; row++) {
78 char hname[128];
79 sprintf(hname,"mod%dcol%drow%d",module,column,row);
80 TH1F* hist = (TH1F*)fHistoFile->Get(hname);
81 if(hist)
82 fAmpHisto[module][column][row]=hist;
83 else
84 fAmpHisto[module][column][row] = 0;
85 }
86 }
87 }
88}
89
1ab07e55 90//-----------------------------------------------------------------------------
383d8adb 91AliPHOSCalibHistoProducer::~AliPHOSCalibHistoProducer()
1ab07e55 92{
383d8adb 93 // Destructor
94
95 UpdateHistoFile();
383d8adb 96 if(fHistoFile) delete fHistoFile;
383d8adb 97
1ab07e55 98}
99
100//-----------------------------------------------------------------------------
383d8adb 101AliPHOSCalibHistoProducer::AliPHOSCalibHistoProducer(const AliPHOSCalibHistoProducer &histoproducer) :
a3925367 102 TObject(histoproducer),fRawDecoder(histoproducer.fRawDecoder),fHistoFile(histoproducer.fHistoFile),
383d8adb 103 fUpdatingRate(histoproducer.fUpdatingRate),fIsOldRCUFormat(histoproducer.fIsOldRCUFormat),
67346abc 104 fEvents(histoproducer.fEvents),fNbins(histoproducer.fNbins),fXlow(histoproducer.fXlow),fXup(histoproducer.fXup)
1ab07e55 105{
383d8adb 106 //Copy constructor.
107
108 for(Int_t module=0; module<5; module++) {
109 for(Int_t column=0; column<56; column++) {
110 for(Int_t row=0; row<64; row++) {
111 char hname[128];
112 sprintf(hname,"mod%dcol%drow%d",module,column,row);
113 TH1F* hist = (TH1F*)histoproducer.fHistoFile->Get(hname);
114 if(hist)
115 fAmpHisto[module][column][row]= new TH1F(*hist);
116 else
117 fAmpHisto[module][column][row]=0;
118 }
119 }
120 }
1ab07e55 121}
122
383d8adb 123//-----------------------------------------------------------------------------
124AliPHOSCalibHistoProducer& AliPHOSCalibHistoProducer::operator=
125(const AliPHOSCalibHistoProducer &histoproducer)
126{
127 //Assignment operator.
128
129 if(this != &histoproducer) {
130
a3925367 131 fRawDecoder = histoproducer.fRawDecoder;
383d8adb 132 fHistoFile = histoproducer.fHistoFile;
133 fUpdatingRate = histoproducer.fUpdatingRate;
134 fIsOldRCUFormat = histoproducer.fIsOldRCUFormat;
383d8adb 135 fEvents = histoproducer.fEvents;
67346abc 136 fEvents = histoproducer.fEvents;
137 fNbins = histoproducer.fNbins;
138 fXlow = histoproducer.fXlow;
139 fXup = histoproducer.fXup;
140
383d8adb 141 for(Int_t module=0; module<5; module++) {
142 for(Int_t column=0; column<56; column++) {
143 for(Int_t row=0; row<64; row++) {
144 if(fAmpHisto[module][column][row]){
145 delete fAmpHisto[module][column][row];
146 fAmpHisto[module][column][row] = histoproducer.fAmpHisto[module][column][row];
147 }
148 else
149 fAmpHisto[module][column][row] = histoproducer.fAmpHisto[module][column][row];
150 }
151 }
152 }
153
154
155 }
156
157 return *this;
158}
1ab07e55 159//-----------------------------------------------------------------------------
160void AliPHOSCalibHistoProducer::Run()
161{
383d8adb 162 // Reads raw data of current event and fills amplitude histograms
1ab07e55 163 // The histograms are written to file every fUpdatingRate events
164
a3925367 165 if(!fRawDecoder) AliFatal("Raw decoder not set!");
166
4fc0021f 167 Double_t energy;
a3925367 168 Int_t mod,col,row;
383d8adb 169
72429802 170 if(fIsOldRCUFormat)
a3925367 171 fRawDecoder->SetOldRCUFormat(kTRUE);
172
173 while(fRawDecoder->NextDigit()) {
4fc0021f 174
a3925367 175 if(fRawDecoder->IsLowGain()) continue;
383d8adb 176
a3925367 177 energy = fRawDecoder->GetEnergy();
a3925367 178
179 mod = fRawDecoder->GetModule()-1;
180 col = fRawDecoder->GetColumn()-1;
181 row = fRawDecoder->GetRow()-1;
182
383d8adb 183 if(fAmpHisto[mod][col][row]) {
184 fAmpHisto[mod][col][row]->Fill(energy);
1ab07e55 185 }
383d8adb 186 else {
187 char hname[128];
188 sprintf(hname,"mod%dcol%drow%d",mod,col,row);
67346abc 189 fAmpHisto[mod][col][row] = new TH1F(hname,hname,fNbins,fXlow,fXup);
a3925367 190 fAmpHisto[mod][col][row]->Fill(energy);
383d8adb 191 }
88852132 192 }
383d8adb 193 // update histograms in local file every 100th event
88852132 194 if(fEvents != 0 && fEvents%fUpdatingRate == 0) {
a3925367 195 AliInfo(Form("Updating histo file, event %d, run %d\n",
196 fEvents,fRawDecoder->GetRawReader()->GetRunNumber()));
383d8adb 197 UpdateHistoFile();
a3925367 198 }
199
200 // UpdateHistoFile();
201 // AliInfo(Form("%d events of run %d processed.",iEvent,runNum));
383d8adb 202
383d8adb 203 fEvents++;
a3925367 204
1ab07e55 205}
206
207//-----------------------------------------------------------------------------
208void AliPHOSCalibHistoProducer::UpdateHistoFile()
209{
210 // Write histograms to file
211
212 if(!fHistoFile) return;
213 if(!fHistoFile->IsOpen()) return;
214
215 TH1F* hist=0;
a3925367 216 char hname[128];
217 char htitle[128];
1ab07e55 218
219 for(Int_t module=0; module<5; module++) {
a3925367 220 sprintf(hname,"hMeanE%d",module);
221 sprintf(htitle,"Mean energies in module %d",module);
222 TH2F hMeanE(hname,htitle,56,0.,56.,64,0.,64);
223
1ab07e55 224 for(Int_t column=0; column<56; column++) {
225 for(Int_t row=0; row<64; row++) {
226 hist = fAmpHisto[module][column][row];
227 if(hist) hist->Write(hist->GetName(),TObject::kWriteDelete);
a3925367 228 if(hist) hMeanE.SetBinContent(column,row,hist->GetMean());
1ab07e55 229 }
230 }
a3925367 231 hMeanE.Write(hMeanE.GetName(),TObject::kWriteDelete);
1ab07e55 232 }
233
234}