]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/PHOS/AliHLTPHOSRcuHistogramProducer.cxx
bugfix: '-nextevent' command in configuration file for publisher inserted correctly...
[u/mrichter/AliRoot.git] / HLT / PHOS / AliHLTPHOSRcuHistogramProducer.cxx
CommitLineData
1b41ab20 1// $Id$
2
792f66f1 3/**************************************************************************
4 * Copyright(c) 2006, ALICE Experiment at CERN, All rights reserved. *
5 * *
6 * Authors: Boris Polichtchouk & Per Thomas Hille for the ALICE *
7 * offline/HLT Project. Contributors are mentioned in the code where *
8 * appropriate. *
9 * *
10 * Permission to use, copy, modify and distribute this software and its *
11 * documentation strictly for non-commercial purposes is hereby granted *
12 * without fee, provided that the above copyright notice appears in all *
13 * copies and that both the copyright notice and this permission notice *
14 * appear in the supporting documentation. The authors make no claims *
15 * about the suitability of this software for any purpose. It is *
16 * provided "as is" without express or implied warranty. *
17 **************************************************************************/
18
19#include "AliHLTPHOSRcuHistogramProducer.h"
20#include <iostream>
0bba8357 21//#include "AliHLTPHOSRcuCellEnergyDataStruct.h"
792f66f1 22#include "TFile.h"
c0b4e7eb 23#include "unistd.h"
24#include <time.h>
1a53578c 25#include "AliHLTCaloUtilities.h"
8efbf5fe 26
c0b4e7eb 27#define THRESHOLD 30
792f66f1 28
1b486665 29using namespace std;
30
31
792f66f1 32/*************************************************************************
c37f821f 33* Class AliHLTPHOSRcuHistogramProducer accumulating histograms *
792f66f1 34* with amplitudes per PHOS channel *
35* It is intended to run at the HLT farm *
36* and it fills the histograms with amplitudes per channel. *
37* Usage example see in PHOS/macros/Shuttle/AliPHOSCalibHistoProducer.C *
38**************************************************************************/
1b486665 39
40
2589c3a3 41AliHLTPHOSRcuHistogramProducer:: AliHLTPHOSRcuHistogramProducer(): // AliHLTPHOSBase(),
42 // AliHLTPHOSRcuProcessor(),
b444d727 43 fCellAccEnergy(),
44 fModuleID(0),
45 fRcuX(0),
2589c3a3 46 fRcuZ(0),
47 fUtilitiesPtr(0)
792f66f1 48{
2589c3a3 49 fUtilitiesPtr = new AliHLTPHOSUtilities;
50
1b486665 51 //Default constructor
8efbf5fe 52 // cout << "WARNING: You cannot invoke the AliHLTPHOSRcuHistogramProducer without arguments" << endl;
53 // cout << "Usage AliHLTPHOSRcuHistogramProducer(ModuleID, X. Z)" << endl;
792f66f1 54}
55
b444d727 56
2589c3a3 57AliHLTPHOSRcuHistogramProducer::AliHLTPHOSRcuHistogramProducer(AliHLTUInt8_t moduleID, AliHLTUInt8_t rcuX, AliHLTUInt8_t rcuZ): //AliHLTPHOSBase(),
58 // AliHLTPHOSRcuProcessor(),
04751caa 59 fCellAccEnergy(),
b444d727 60 fModuleID(moduleID),
61 fRcuX(rcuX),
2589c3a3 62 fRcuZ(rcuZ),
63 fUtilitiesPtr(0)
792f66f1 64{
04751caa 65
1b486665 66 //Se header file for documentation
2589c3a3 67 fUtilitiesPtr = new AliHLTPHOSUtilities();
68
c0b4e7eb 69 char *tmp = getenv("HOME");
c0b4e7eb 70 if(tmp == 0)
71 {
8efbf5fe 72 // cout << "ERROR, environment vriable HOME is not set" << endl;
c0b4e7eb 73 }
c0b4e7eb 74 else
75 {
76 // sprintf(fHistoOutDir,"%s/rundir/output/histograms",tmp);
77 sprintf(fHistoOutDir,"%s/rundir/output/histograms/",tmp);
78 }
792f66f1 79 Init();
80}
81
b444d727 82
04751caa 83AliHLTPHOSRcuHistogramProducer::~AliHLTPHOSRcuHistogramProducer()
792f66f1 84{
1b486665 85 //Destructor
792f66f1 86}
87
88
c0b4e7eb 89void
90AliHLTPHOSRcuHistogramProducer::SetHistoOutDir(char *outDir)
91{
ab38011b 92 //comment
c0b4e7eb 93 sprintf(fHistoOutDir,"%s", outDir);
94}
95
96void
97AliHLTPHOSRcuHistogramProducer::SetDefaultHistoOutDir()
98{
ab38011b 99 //comment
c0b4e7eb 100 char *tmp = getenv("HOME/rundir");
101 sprintf(fHistoOutDir,"%s/rundir/output/histograms", tmp);
102 //testing wether or not directry exist
103 FILE *fp = fopen(fHistoOutDir, "w");
104
105 if(fp == 0)
106 {
8efbf5fe 107// cout << "ERROR, directory =" << fHistoOutDir << " Doesnt exist, or you don have write permissions to the directory" << endl;
108// cout << "WARNING: Histograms will not bew written to files at end of run unless a valid directory is set" << endl;
109// cout << "INFO, You must either" << endl;
110// cout << "1) Create the directory " << fHistoOutDir << "Manually" <<endl;
111// cout << "OR "<< endl;
112// cout << "2) Se a valid output directory with the function AliHLTPHOSRcuHistogramProducer::SetHistoOutDir(*char outdir) "<< endl;
c0b4e7eb 113 }
114 else
115 {
8efbf5fe 116 // cout << "INFO: Output ddirectory for Histograms was set tot" << fHistoOutDir << endl;
117 // cout << "INFO: if you want another output directory use the AliHLTPHOSRcuHistogramProducer::SetHistoOutDir(*char outdir)" << endl;
c0b4e7eb 118 }
119
120}
121
792f66f1 122void
123AliHLTPHOSRcuHistogramProducer::Init()
124{
1b486665 125 //See header file for documentation
792f66f1 126 char tmpHistoName[256];
127 int geomx;
128 int geomz;
792f66f1 129
27029341 130 for(int gain=0; gain< NGAINS; gain++)
c0b4e7eb 131 {
132 sprintf(tmpHistoName, "DeadChanneMap_Module%d_rcuz%d_rcux%d_gain%d",(int)fModuleID, fRcuZ, fRcuX, gain);
27029341 133 // fDeadChannelMapHistogramPtrs[gain] = new TH2D( tmpHistoName, tmpHistoName, NBINS, XBINLOW, XBINUP);
c0b4e7eb 134 fDeadChannelMapHistogramPtrs[gain] = new TH2D(tmpHistoName, tmpHistoName,
27029341 135 NXCOLUMNSRCU , 0, NXCOLUMNSRCU ,
136 NZROWSRCU, 0, NZROWSRCU);
c0b4e7eb 137 fDeadChannelMapHistogramPtrs[gain]->Reset();
138 // fgCalibHistPtr[gain]->GetXaxis()->SetRange(128, 128 + 64);
c0b4e7eb 139 }
140
27029341 141 for(int x = 0; x < NXCOLUMNSRCU; x ++)
792f66f1 142 {
27029341 143 for(int z = 0; z < NZROWSRCU; z ++)
792f66f1 144 {
27029341 145 for(int gain = 0; gain < NGAINS; gain ++)
792f66f1 146 {
27029341 147 geomx = x + NXCOLUMNSRCU*fRcuX;
148 geomz = z + NZROWSRCU*fRcuZ;
792f66f1 149 fEnergyAverageValues[x][z][gain] = 0;
150 fAccumulatedValues[x][z][gain] = 0;
151 fTimingAverageValues[x][z][gain] = 0;
152 fHits[x][z][gain] = 0;
c0b4e7eb 153 fDeadChannelMap[x][z][gain] = 0;
792f66f1 154 sprintf(tmpHistoName, "Edistribution_%d_%d_%d_%d",(int)fModuleID, geomx, geomz, gain);
c0b4e7eb 155 // fEnergyHistogramPtrs[x][z][gain] = 0;
27029341 156 fEnergyHistogramPtrs[x][z][gain] = new TH1F( tmpHistoName, tmpHistoName, NBINS, XBINLOW, XBINUP);
c0b4e7eb 157 sprintf(tmpHistoName, "TOFdistribution_module%d_x%d_z%d_gain%d", (int)fModuleID, geomx, geomz, gain);
158
159 // fTimingHistogramPtrs[x][z][gain] = 0;
160
161 // sprintf(tmpHistoName, "DeadChanneMap_%d_%d_%d_%d",(int)fModuleID, geomx, geomz, gain);
162 // fDeadChannelMapHistogramPtrs[x][z][gain] = new TH1D( tmpHistoName, tmpHistoName, N_BINS, XBIN_LOW, XBIN_UP);
163
164
27029341 165 fTimingHistogramPtrs[x][z][gain] = new TH1F(tmpHistoName , tmpHistoName, NBINS, XBINLOW, XBINUP);
792f66f1 166 fCellAccEnergy.fAccumulatedEnergies[x][z][gain] = 0;
167 fCellAccEnergy.fHits[x][z][gain] = 0;
c0b4e7eb 168 fCellAccEnergy.fDeadChannelMap[x][z][gain] = 0;
792f66f1 169 fCellAccEnergy.fModuleID = 0;
170 fCellAccEnergy.fRcuX = 0;
171 fCellAccEnergy.fRcuZ = 0;
172 }
173 }
174 }
175}
176
792f66f1 177
792f66f1 178
179void
180AliHLTPHOSRcuHistogramProducer::FillEnergy(AliHLTUInt8_t x, AliHLTUInt8_t z, AliHLTUInt8_t gain, float energy)
181{
ab38011b 182 //comment
792f66f1 183 fCellAccEnergy.fAccumulatedEnergies[x][z][gain] += energy;
c0b4e7eb 184 fCellAccEnergy.fHits[x][z][gain] ++;
185 fEnergyHistogramPtrs[x][z][gain]->Fill(energy);
792f66f1 186}
187
188
189void
190AliHLTPHOSRcuHistogramProducer::FillTime(AliHLTUInt8_t x, AliHLTUInt8_t z, AliHLTUInt8_t gain, float time)
191{
1b486665 192 //See header file for documentation
792f66f1 193 fTimingHistogramPtrs[x][z][gain]->Fill(time);
194}
195
196const AliHLTPHOSRcuCellAccumulatedEnergyDataStruct&
197AliHLTPHOSRcuHistogramProducer::GetCellAccumulatedEnergies()
198{
199 // return &fCellAccEnergy ;
200 return fCellAccEnergy ;
201}
202
c0b4e7eb 203void
204AliHLTPHOSRcuHistogramProducer::FillLiveChannels(Int_t data[], int size, Int_t x, Int_t z, Int_t gain)
205{
ab38011b 206 //comment
c0b4e7eb 207 for(Int_t i = 0; i < size; i++)
208 {
209 if(data[i] > THRESHOLD)
210 {
211 if(data[i+1] > THRESHOLD)
212 {
213 if(data[i+2] > THRESHOLD)
214 {
215 if(data[i+3] > THRESHOLD)
216 {
217
218 fCellAccEnergy.fDeadChannelMap[x][z][gain] = 10;
219
220 return;
221 }
222 }
223 }
224 }
225 }
226}
227
228void
229AliHLTPHOSRcuHistogramProducer::FillLiveChannelHistograms()
230{
ab38011b 231 //comment
27029341 232 for(int x = 0; x < NXCOLUMNSRCU; x ++)
c0b4e7eb 233 {
27029341 234 for(int z = 0; z < NZROWSRCU; z ++)
c0b4e7eb 235 {
27029341 236 for(int gain = 0; gain < NGAINS; gain ++)
c0b4e7eb 237 {
238 fDeadChannelMapHistogramPtrs[gain]->SetBinContent(x ,z , fCellAccEnergy.fDeadChannelMap[x][z][gain]);
239 }
240 }
241 }
242
243}
792f66f1 244
b444d727 245
792f66f1 246void
247AliHLTPHOSRcuHistogramProducer::Reset()
248{
1b486665 249 //See header file for documentation
27029341 250 for(int x = 0; x < NXCOLUMNSRCU; x ++)
792f66f1 251 {
27029341 252 for(int z = 0; z < NZROWSRCU; z ++)
792f66f1 253 {
27029341 254 for(int gain = 0; gain < NGAINS; gain ++)
792f66f1 255 {
256 fEnergyAverageValues[x][z][gain] = 0;
257 fAccumulatedValues[x][z][gain] = 0;
258 fTimingAverageValues[x][z][gain] = 0;
259 fHits[x][z][gain] = 0;
c0b4e7eb 260 fDeadChannelMap[x][z][gain] = 0;
792f66f1 261 }
262 }
263 }
264
27029341 265 for(int i = 0; i <ALTROMAXSAMPLES; i++)
792f66f1 266 {
267 fTmpChannelData[i] = 0;
268 }
269}
270
1b486665 271
792f66f1 272void
c0b4e7eb 273AliHLTPHOSRcuHistogramProducer::WriteAllHistograms(char *opt)
792f66f1 274{
ab38011b 275 //comment
c0b4e7eb 276 printf("\nAliHLTPHOSRcuHistogramProducer::WriteAllHistogram, opt = %s\n", opt);
277
278 FillLiveChannelHistograms();
279 // cout <<<< endl;
280
281 int runNumber = 0;
282 char tmpEFileName[256];
283 char tmpDeadFileName_gain0[256];
284 char tmpDeadFileName_gain1[256];
285 // char *tmpRundir = getenv("HOME");
286 char runNumberFile[256];
287 char timeString[256];
288
2589c3a3 289 fUtilitiesPtr->ResetArray(runNumberFile, 256);
290 fUtilitiesPtr->ResetArray(tmpEFileName, 256);
291 fUtilitiesPtr->ResetArray(timeString, 256);
c0b4e7eb 292
293
294 sprintf(runNumberFile, "%s/rundir/runNumber.txt", getenv("HOME"));
295
296 FILE *fp = fopen(runNumberFile, "r");
e304ea31 297
298 Int_t res = 0; //OD to get rid of warnings
c0b4e7eb 299 if(fp == 0)
300 {
301 ScanTimeString(timeString);
8efbf5fe 302 // cout << "WARNING, could not find file "<< runNumberFile <<endl;
303 // cout <<"Filename will be stamped with data and time instead " << endl;
c0b4e7eb 304 sprintf(tmpEFileName, "%s/Energy/EnergyHistograms_%s_mod%d_rcuZ%d_rcuX%d.root", fHistoOutDir, timeString, (int)fModuleID, (int)fRcuZ, (int)fRcuZ);
305 sprintf(tmpDeadFileName_gain0, "%s/DeadMap/DeadChannelHistograms_%s_mod%d_rcuZ%d_rcuX%d_LG.root", fHistoOutDir, timeString, (int)fModuleID, (int)fRcuZ, (int)fRcuZ);
306 sprintf(tmpDeadFileName_gain1, "%s/DeadMap/DeadChannelHistograms_%s_mod%d_rcuZ%d_rcuX%d_HG.root", fHistoOutDir, timeString, (int)fModuleID, (int)fRcuZ, (int)fRcuZ);
307 }
308 else
309 {
e304ea31 310 res = fscanf(fp, "%d", &runNumber);
c0b4e7eb 311 sprintf(tmpEFileName, "%s/Energy/EnergyHisttograms_run%d_mod%d_rcuZ%d_rcuX%d.root", fHistoOutDir, runNumber, (int)fModuleID, (int)fRcuZ, (int)fRcuX);
312 sprintf(tmpDeadFileName_gain0, "%s/DeadMap/DeadChannleHistograms_run%d_mod%d_rcuZ%d_rcuX%d_LG.root", fHistoOutDir, runNumber, (int)fModuleID, (int)fRcuZ, (int)fRcuX);
313 sprintf(tmpDeadFileName_gain1, "%s/DeadMap/DeadChannleHistograms_run%d_mod%d_rcuZ%d_rcuX%d_HG.root", fHistoOutDir, runNumber, (int)fModuleID, (int)fRcuZ, (int)fRcuX);
314 fclose(fp);
315 }
316
8efbf5fe 317 // cout << "tmpEFileName = "<< tmpEFileName << endl;
c0b4e7eb 318
319 TFile *energyHistoFile = new TFile(tmpEFileName, opt);
320 if(!energyHistoFile) return;
321 if(!energyHistoFile->IsOpen()) return;
792f66f1 322
8efbf5fe 323 // cout <<"printing histograms"<< endl;
792f66f1 324
27029341 325 for(int x = 0; x < NXCOLUMNSRCU; x ++)
792f66f1 326 {
27029341 327 for(int z = 0; z < NZROWSRCU; z ++)
792f66f1 328 {
27029341 329 for(int gain = 0; gain < NGAINS; gain ++)
792f66f1 330 {
c0b4e7eb 331 // cout << "the number of entries is " <<fEnergyHistogramPtrs[x][z][gain]->GetEntries()<< endl;
792f66f1 332 fEnergyHistogramPtrs[x][z][gain]->Write();
333 }
334 }
335 }
c0b4e7eb 336 energyHistoFile->Close();
337
792f66f1 338
c0b4e7eb 339 //LOW GAIN
340 //TFile *deadHistoFile_gain0 = new TFile(tmpDeadFileName_gain0,"update");
341 TFile *deadHistoFile_gain0 = new TFile(tmpDeadFileName_gain0, opt);
792f66f1 342
c0b4e7eb 343 if(!deadHistoFile_gain0) return;
344 if(!deadHistoFile_gain0->IsOpen()) return;
345 fDeadChannelMapHistogramPtrs[0]->Write();
346
347
348 //HIGH GAIN
349 // TFile *deadHistoFile_gain1 = new TFile(tmpDeadFileName_gain1,"update");
350 TFile *deadHistoFile_gain1 = new TFile(tmpDeadFileName_gain1, opt);
351 if(!deadHistoFile_gain1) return;
352 if(!deadHistoFile_gain1->IsOpen()) return;
353 fDeadChannelMapHistogramPtrs[1]->Write();
354
355
356 deadHistoFile_gain0->Close();
357 deadHistoFile_gain1->Close();
8efbf5fe 358
359 // cout << "printing histograms, finished"<< endl;
c0b4e7eb 360}
361
362void
363AliHLTPHOSRcuHistogramProducer::ScanTimeString(char *timeString)
364{
ab38011b 365 //comment
c0b4e7eb 366 time_t timePtr;
367 tm *tmPtr;
c0b4e7eb 368 time(&timePtr);
369 tmPtr=localtime(&timePtr);
370 timeString=asctime(tmPtr);
c0b4e7eb 371 char day[10];
372 char month[10];
373 int date;
374 int hour;
375 int min;
376 int sec;
377 int year;
c0b4e7eb 378 sscanf(timeString, "%s %s %d %d:%d:%d %d\n", day, month, &date, &hour, &min, &sec, &year);
379
792f66f1 380}