]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/PHOS/AliHLTPHOSRcuHistogramProducer.cxx
New classes that updates histograms contniously during run.
[u/mrichter/AliRoot.git] / HLT / PHOS / AliHLTPHOSRcuHistogramProducer.cxx
1 /**************************************************************************
2  * Copyright(c) 2006, ALICE Experiment at CERN, All rights reserved.      *
3  *                                                                        *
4  * Authors: Boris Polichtchouk & Per Thomas Hille for the ALICE           *
5  * offline/HLT Project. Contributors are mentioned in the code where      *
6  * appropriate.                                                           *
7  *                                                                        *
8  * Permission to use, copy, modify and distribute this software and its   *
9  * documentation strictly for non-commercial purposes is hereby granted   *
10  * without fee, provided that the above copyright notice appears in all   *
11  * copies and that both the copyright notice and this permission notice   *
12  * appear in the supporting documentation. The authors make no claims     *
13  * about the suitability of this software for any purpose. It is          *
14  * provided "as is" without express or implied warranty.                  *
15  **************************************************************************/
16
17 #include "AliHLTPHOSRcuHistogramProducer.h"
18 #include <iostream>
19 #include "stdio.h"
20 #include <cstdlib>
21 #include "AliHLTPHOSRcuCellEnergyDataStruct.h"
22 #include "TFile.h"
23
24 /*************************************************************************
25 * Class AliHLTPHOSRcuHistogramProducer accumulating histograms     *
26 * with amplitudes per PHOS channel                                       *
27 * It is intended to run at the HLT farm                                  *
28 * and it fills the histograms with amplitudes per channel.               * 
29 * Usage example see in PHOS/macros/Shuttle/AliPHOSCalibHistoProducer.C   *
30 **************************************************************************/
31 AliHLTPHOSRcuHistogramProducer:: AliHLTPHOSRcuHistogramProducer(): fEventCount(0), fEquippmentID(0), fModuleID(0), fRcuX(0), fRcuZ(0)
32 {
33   cout << "WARNING: You cannot invoke the AliHLTPHOSRcuHistogramProducer without arguments" << endl;
34   cout << "Usage AliHLTPHOSRcuHistogramProducer(ModuleID, X. Z)" << endl;
35   //  Reset();
36   //  Init();
37
38
39 AliHLTPHOSRcuHistogramProducer::AliHLTPHOSRcuHistogramProducer(AliHLTUInt8_t moduleID, AliHLTUInt8_t rcuX, AliHLTUInt8_t rcuZ)
40 {
41   SetModuleID(moduleID);
42   SetRcuX(rcuX); 
43   SetRcuZ(rcuZ); 
44   Init();
45 }
46
47 AliHLTPHOSRcuHistogramProducer::~ AliHLTPHOSRcuHistogramProducer()
48 {
49
50 }
51
52
53 void
54 AliHLTPHOSRcuHistogramProducer::Init()
55 {
56   char tmpHistoName[256];
57   int geomx;
58   int geomz;
59     
60
61   for(int x = 0; x < N_XCOLUMNS_RCU; x ++)
62     {
63       for(int z = 0; z < N_ZROWS_RCU; z ++)
64         {
65           for(int gain = 0; gain < N_GAINS; gain ++)
66             {
67               geomx = x + N_XCOLUMNS_RCU*fRcuX;
68               geomz = z + N_ZROWS_RCU*fRcuZ;
69
70               fEnergyAverageValues[x][z][gain] = 0; 
71               fAccumulatedValues[x][z][gain]   = 0;
72               fTimingAverageValues[x][z][gain] = 0; 
73               fHits[x][z][gain]                = 0;
74               sprintf(tmpHistoName, "Edistribution_%d_%d_%d_%d",(int)fModuleID,  geomx, geomz, gain);
75               fEnergyHistogramPtrs[x][z][gain] = 0;
76
77               fEnergyHistogramPtrs[x][z][gain] = new TH1F( tmpHistoName, tmpHistoName, N_BINS, XBIN_LOW, XBIN_UP);
78
79               sprintf(tmpHistoName, "TOFdistribution_%d_%d_%d_%d",(int)fModuleID,  geomx, geomz, gain);
80         
81               fTimingHistogramPtrs[x][z][gain] = 0;
82
83               fTimingHistogramPtrs[x][z][gain] = new TH1F(tmpHistoName , tmpHistoName, N_BINS, XBIN_LOW, XBIN_UP);
84
85               fCellAccEnergy.fAccumulatedEnergies[x][z][gain] = 0;
86               fCellAccEnergy.fHits[x][z][gain] = 0;
87               fCellAccEnergy.fModuleID = 0;
88               fCellAccEnergy.fRcuX = 0;
89               fCellAccEnergy.fRcuZ = 0; 
90             }
91         } 
92     } 
93 }
94
95 int 
96 AliHLTPHOSRcuHistogramProducer::GetEquippmentId()
97 {
98   return  fEquippmentID;
99 }
100
101
102 void 
103 AliHLTPHOSRcuHistogramProducer::SetRcuX(AliHLTUInt8_t X)
104 {
105   fRcuX = X; 
106   fCellAccEnergy.fRcuX = X;
107 }
108
109
110 void 
111 AliHLTPHOSRcuHistogramProducer::SetRcuZ(AliHLTUInt8_t Z)
112 {
113   fRcuZ = Z; 
114   fCellAccEnergy.fRcuZ = Z;
115 }
116
117
118 void 
119 AliHLTPHOSRcuHistogramProducer::SetModuleID(AliHLTUInt8_t moduleID)
120 {
121  fModuleID = moduleID;
122 }
123
124
125 void 
126 AliHLTPHOSRcuHistogramProducer::SetEquippmentId(int id)
127 {
128   fEquippmentID = id;
129 }
130
131
132 void 
133 AliHLTPHOSRcuHistogramProducer::FillEnergy(AliHLTUInt8_t x, AliHLTUInt8_t z,  AliHLTUInt8_t gain, float energy)
134 {
135   fCellAccEnergy.fAccumulatedEnergies[x][z][gain] += energy;
136   fCellAccEnergy.fHits[x][z][gain] ++; 
137   fEnergyHistogramPtrs[x][z][gain]->Fill(energy);
138 }
139
140
141 void 
142 AliHLTPHOSRcuHistogramProducer::FillTime(AliHLTUInt8_t x, AliHLTUInt8_t z, AliHLTUInt8_t gain, float time)
143 {
144   fTimingHistogramPtrs[x][z][gain]->Fill(time);
145 }
146
147 const AliHLTPHOSRcuCellAccumulatedEnergyDataStruct& 
148 AliHLTPHOSRcuHistogramProducer::GetCellAccumulatedEnergies()
149 {
150   //  return &fCellAccEnergy ;
151   return fCellAccEnergy ;
152 }
153
154 int 
155 AliHLTPHOSRcuHistogramProducer::IncrementEventCounter()
156 {
157    fEventCount ++;
158    return  fEventCount;
159 }
160
161
162 void
163 AliHLTPHOSRcuHistogramProducer::Reset()
164 {
165   for(int x = 0; x < N_XCOLUMNS_RCU; x ++)
166     {
167       for(int z = 0; z < N_ZROWS_RCU; z ++)
168         {
169           for(int gain = 0; gain < N_GAINS; gain ++)
170             {
171               fEnergyAverageValues[x][z][gain] = 0; 
172               fAccumulatedValues[x][z][gain]   = 0;
173               fTimingAverageValues[x][z][gain] = 0; 
174               fHits[x][z][gain]                = 0;
175             }
176         } 
177     }
178   
179   for(int i = 0; i <ALTRO_MAX_SAMPLES;  i++)
180     {
181       fTmpChannelData[i] = 0;
182     }
183 }
184
185 void 
186 AliHLTPHOSRcuHistogramProducer::WriteEnergyHistograms()
187 {
188   char tmpFileName[256];
189   sprintf(tmpFileName,"/home/aliphoshlt/rundir/outdata/calibHisto_%d_%d_%d.root", (int)fModuleID, (int)fRcuX, (int)fRcuZ);
190   TFile *histoFile =  new TFile(tmpFileName,"update");
191   char hname[128];
192   if(!histoFile) return;
193   if(!histoFile->IsOpen()) return;
194
195   cout <<"printing histograms"<< endl;
196   cout <<"histofile-Getname() =" << histoFile->GetName() << endl;
197
198     for(int x = 0; x <  N_XCOLUMNS_RCU; x ++)
199     {
200       for(int z = 0; z < N_ZROWS_RCU; z ++)
201         {
202           for(int gain = 0; gain < N_GAINS; gain ++)
203             {
204               fEnergyHistogramPtrs[x][z][gain]->Write();
205             }
206         } 
207     }
208
209     cout << "printing histograms, finished"<< endl;
210     histoFile->Close();
211
212 }