]>
Commit | Line | Data |
---|---|---|
1 | // $Id$ | |
2 | ||
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> | |
21 | //#include "AliHLTPHOSRcuCellEnergyDataStruct.h" | |
22 | #include "TFile.h" | |
23 | #include "unistd.h" | |
24 | #include <time.h> | |
25 | #include "AliHLTPHOSUtilities.h" | |
26 | ||
27 | #define THRESHOLD 30 | |
28 | ||
29 | using namespace std; | |
30 | ||
31 | ||
32 | /************************************************************************* | |
33 | * Class AliHLTPHOSRcuHistogramProducer accumulating histograms * | |
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 | **************************************************************************/ | |
39 | ||
40 | ||
41 | AliHLTPHOSRcuHistogramProducer:: AliHLTPHOSRcuHistogramProducer(): // AliHLTPHOSBase(), | |
42 | // AliHLTPHOSRcuProcessor(), | |
43 | fCellAccEnergy(), | |
44 | fModuleID(0), | |
45 | fRcuX(0), | |
46 | fRcuZ(0), | |
47 | fUtilitiesPtr(0) | |
48 | { | |
49 | fUtilitiesPtr = new AliHLTPHOSUtilities; | |
50 | ||
51 | //Default constructor | |
52 | // cout << "WARNING: You cannot invoke the AliHLTPHOSRcuHistogramProducer without arguments" << endl; | |
53 | // cout << "Usage AliHLTPHOSRcuHistogramProducer(ModuleID, X. Z)" << endl; | |
54 | } | |
55 | ||
56 | ||
57 | AliHLTPHOSRcuHistogramProducer::AliHLTPHOSRcuHistogramProducer(AliHLTUInt8_t moduleID, AliHLTUInt8_t rcuX, AliHLTUInt8_t rcuZ): //AliHLTPHOSBase(), | |
58 | // AliHLTPHOSRcuProcessor(), | |
59 | fCellAccEnergy(), | |
60 | fModuleID(moduleID), | |
61 | fRcuX(rcuX), | |
62 | fRcuZ(rcuZ), | |
63 | fUtilitiesPtr(0) | |
64 | { | |
65 | ||
66 | //Se header file for documentation | |
67 | fUtilitiesPtr = new AliHLTPHOSUtilities(); | |
68 | ||
69 | char *tmp = getenv("HOME"); | |
70 | if(tmp == 0) | |
71 | { | |
72 | // cout << "ERROR, environment vriable HOME is not set" << endl; | |
73 | } | |
74 | else | |
75 | { | |
76 | // sprintf(fHistoOutDir,"%s/rundir/output/histograms",tmp); | |
77 | sprintf(fHistoOutDir,"%s/rundir/output/histograms/",tmp); | |
78 | } | |
79 | Init(); | |
80 | } | |
81 | ||
82 | ||
83 | AliHLTPHOSRcuHistogramProducer::~AliHLTPHOSRcuHistogramProducer() | |
84 | { | |
85 | //Destructor | |
86 | } | |
87 | ||
88 | ||
89 | void | |
90 | AliHLTPHOSRcuHistogramProducer::SetHistoOutDir(char *outDir) | |
91 | { | |
92 | //comment | |
93 | sprintf(fHistoOutDir,"%s", outDir); | |
94 | } | |
95 | ||
96 | void | |
97 | AliHLTPHOSRcuHistogramProducer::SetDefaultHistoOutDir() | |
98 | { | |
99 | //comment | |
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 | { | |
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; | |
113 | } | |
114 | else | |
115 | { | |
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; | |
118 | } | |
119 | ||
120 | } | |
121 | ||
122 | void | |
123 | AliHLTPHOSRcuHistogramProducer::Init() | |
124 | { | |
125 | //See header file for documentation | |
126 | char tmpHistoName[256]; | |
127 | int geomx; | |
128 | int geomz; | |
129 | ||
130 | for(int gain=0; gain< NGAINS; gain++) | |
131 | { | |
132 | sprintf(tmpHistoName, "DeadChanneMap_Module%d_rcuz%d_rcux%d_gain%d",(int)fModuleID, fRcuZ, fRcuX, gain); | |
133 | // fDeadChannelMapHistogramPtrs[gain] = new TH2D( tmpHistoName, tmpHistoName, NBINS, XBINLOW, XBINUP); | |
134 | fDeadChannelMapHistogramPtrs[gain] = new TH2D(tmpHistoName, tmpHistoName, | |
135 | NXCOLUMNSRCU , 0, NXCOLUMNSRCU , | |
136 | NZROWSRCU, 0, NZROWSRCU); | |
137 | fDeadChannelMapHistogramPtrs[gain]->Reset(); | |
138 | // fgCalibHistPtr[gain]->GetXaxis()->SetRange(128, 128 + 64); | |
139 | } | |
140 | ||
141 | for(int x = 0; x < NXCOLUMNSRCU; x ++) | |
142 | { | |
143 | for(int z = 0; z < NZROWSRCU; z ++) | |
144 | { | |
145 | for(int gain = 0; gain < NGAINS; gain ++) | |
146 | { | |
147 | geomx = x + NXCOLUMNSRCU*fRcuX; | |
148 | geomz = z + NZROWSRCU*fRcuZ; | |
149 | fEnergyAverageValues[x][z][gain] = 0; | |
150 | fAccumulatedValues[x][z][gain] = 0; | |
151 | fTimingAverageValues[x][z][gain] = 0; | |
152 | fHits[x][z][gain] = 0; | |
153 | fDeadChannelMap[x][z][gain] = 0; | |
154 | sprintf(tmpHistoName, "Edistribution_%d_%d_%d_%d",(int)fModuleID, geomx, geomz, gain); | |
155 | // fEnergyHistogramPtrs[x][z][gain] = 0; | |
156 | fEnergyHistogramPtrs[x][z][gain] = new TH1F( tmpHistoName, tmpHistoName, NBINS, XBINLOW, XBINUP); | |
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 | ||
165 | fTimingHistogramPtrs[x][z][gain] = new TH1F(tmpHistoName , tmpHistoName, NBINS, XBINLOW, XBINUP); | |
166 | fCellAccEnergy.fAccumulatedEnergies[x][z][gain] = 0; | |
167 | fCellAccEnergy.fHits[x][z][gain] = 0; | |
168 | fCellAccEnergy.fDeadChannelMap[x][z][gain] = 0; | |
169 | fCellAccEnergy.fModuleID = 0; | |
170 | fCellAccEnergy.fRcuX = 0; | |
171 | fCellAccEnergy.fRcuZ = 0; | |
172 | } | |
173 | } | |
174 | } | |
175 | } | |
176 | ||
177 | ||
178 | ||
179 | void | |
180 | AliHLTPHOSRcuHistogramProducer::FillEnergy(AliHLTUInt8_t x, AliHLTUInt8_t z, AliHLTUInt8_t gain, float energy) | |
181 | { | |
182 | //comment | |
183 | fCellAccEnergy.fAccumulatedEnergies[x][z][gain] += energy; | |
184 | fCellAccEnergy.fHits[x][z][gain] ++; | |
185 | fEnergyHistogramPtrs[x][z][gain]->Fill(energy); | |
186 | } | |
187 | ||
188 | ||
189 | void | |
190 | AliHLTPHOSRcuHistogramProducer::FillTime(AliHLTUInt8_t x, AliHLTUInt8_t z, AliHLTUInt8_t gain, float time) | |
191 | { | |
192 | //See header file for documentation | |
193 | fTimingHistogramPtrs[x][z][gain]->Fill(time); | |
194 | } | |
195 | ||
196 | const AliHLTPHOSRcuCellAccumulatedEnergyDataStruct& | |
197 | AliHLTPHOSRcuHistogramProducer::GetCellAccumulatedEnergies() | |
198 | { | |
199 | // return &fCellAccEnergy ; | |
200 | return fCellAccEnergy ; | |
201 | } | |
202 | ||
203 | void | |
204 | AliHLTPHOSRcuHistogramProducer::FillLiveChannels(Int_t data[], int size, Int_t x, Int_t z, Int_t gain) | |
205 | { | |
206 | //comment | |
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 | ||
228 | void | |
229 | AliHLTPHOSRcuHistogramProducer::FillLiveChannelHistograms() | |
230 | { | |
231 | //comment | |
232 | for(int x = 0; x < NXCOLUMNSRCU; x ++) | |
233 | { | |
234 | for(int z = 0; z < NZROWSRCU; z ++) | |
235 | { | |
236 | for(int gain = 0; gain < NGAINS; gain ++) | |
237 | { | |
238 | fDeadChannelMapHistogramPtrs[gain]->SetBinContent(x ,z , fCellAccEnergy.fDeadChannelMap[x][z][gain]); | |
239 | } | |
240 | } | |
241 | } | |
242 | ||
243 | } | |
244 | ||
245 | ||
246 | void | |
247 | AliHLTPHOSRcuHistogramProducer::Reset() | |
248 | { | |
249 | //See header file for documentation | |
250 | for(int x = 0; x < NXCOLUMNSRCU; x ++) | |
251 | { | |
252 | for(int z = 0; z < NZROWSRCU; z ++) | |
253 | { | |
254 | for(int gain = 0; gain < NGAINS; gain ++) | |
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; | |
260 | fDeadChannelMap[x][z][gain] = 0; | |
261 | } | |
262 | } | |
263 | } | |
264 | ||
265 | for(int i = 0; i <ALTROMAXSAMPLES; i++) | |
266 | { | |
267 | fTmpChannelData[i] = 0; | |
268 | } | |
269 | } | |
270 | ||
271 | ||
272 | void | |
273 | AliHLTPHOSRcuHistogramProducer::WriteAllHistograms(char *opt) | |
274 | { | |
275 | //comment | |
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 | ||
289 | fUtilitiesPtr->ResetArray(runNumberFile, 256); | |
290 | fUtilitiesPtr->ResetArray(tmpEFileName, 256); | |
291 | fUtilitiesPtr->ResetArray(timeString, 256); | |
292 | ||
293 | ||
294 | sprintf(runNumberFile, "%s/rundir/runNumber.txt", getenv("HOME")); | |
295 | ||
296 | FILE *fp = fopen(runNumberFile, "r"); | |
297 | ||
298 | Int_t res = 0; //OD to get rid of warnings | |
299 | if(fp == 0) | |
300 | { | |
301 | ScanTimeString(timeString); | |
302 | // cout << "WARNING, could not find file "<< runNumberFile <<endl; | |
303 | // cout <<"Filename will be stamped with data and time instead " << endl; | |
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 | { | |
310 | res = fscanf(fp, "%d", &runNumber); | |
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 | ||
317 | // cout << "tmpEFileName = "<< tmpEFileName << endl; | |
318 | ||
319 | TFile *energyHistoFile = new TFile(tmpEFileName, opt); | |
320 | if(!energyHistoFile) return; | |
321 | if(!energyHistoFile->IsOpen()) return; | |
322 | ||
323 | // cout <<"printing histograms"<< endl; | |
324 | ||
325 | for(int x = 0; x < NXCOLUMNSRCU; x ++) | |
326 | { | |
327 | for(int z = 0; z < NZROWSRCU; z ++) | |
328 | { | |
329 | for(int gain = 0; gain < NGAINS; gain ++) | |
330 | { | |
331 | // cout << "the number of entries is " <<fEnergyHistogramPtrs[x][z][gain]->GetEntries()<< endl; | |
332 | fEnergyHistogramPtrs[x][z][gain]->Write(); | |
333 | } | |
334 | } | |
335 | } | |
336 | energyHistoFile->Close(); | |
337 | ||
338 | ||
339 | //LOW GAIN | |
340 | //TFile *deadHistoFile_gain0 = new TFile(tmpDeadFileName_gain0,"update"); | |
341 | TFile *deadHistoFile_gain0 = new TFile(tmpDeadFileName_gain0, opt); | |
342 | ||
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(); | |
358 | ||
359 | // cout << "printing histograms, finished"<< endl; | |
360 | } | |
361 | ||
362 | void | |
363 | AliHLTPHOSRcuHistogramProducer::ScanTimeString(char *timeString) | |
364 | { | |
365 | //comment | |
366 | time_t timePtr; | |
367 | tm *tmPtr; | |
368 | time(&timePtr); | |
369 | tmPtr=localtime(&timePtr); | |
370 | timeString=asctime(tmPtr); | |
371 | char day[10]; | |
372 | char month[10]; | |
373 | int date; | |
374 | int hour; | |
375 | int min; | |
376 | int sec; | |
377 | int year; | |
378 | sscanf(timeString, "%s %s %d %d:%d:%d %d\n", day, month, &date, &hour, &min, &sec, &year); | |
379 | ||
380 | } |