]>
Commit | Line | Data |
---|---|---|
6a76e30e | 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 "AliHLTPHOSRcuCalibrationProcessor.h" | |
18 | #include <iostream> | |
19 | #include "AliHLTPHOSRcuCellEnergyDataStruct.h" | |
20 | #include "TFile.h" | |
21 | #include "unistd.h" | |
22 | #include <time.h> | |
23 | ||
24 | #define THRESHOLD 30 | |
25 | ||
26 | using namespace std; | |
27 | ||
28 | ||
29 | /************************************************************************* | |
30 | * Class AliHLTPHOSRcuCalibrationProcessor accumulating histograms * | |
31 | * with amplitudes per PHOS channel * | |
32 | * It is intended to run at the HLT farm * | |
33 | * and it fills the histograms with amplitudes per channel. * | |
34 | * Usage example see in PHOS/macros/Shuttle/AliPHOSCalibHistoProducer.C * | |
35 | **************************************************************************/ | |
36 | ||
37 | ||
38 | AliHLTPHOSRcuCalibrationProcessor:: AliHLTPHOSRcuCalibrationProcessor(): AliHLTPHOSBase(), fModuleID(0), fRcuX(0), fRcuZ(0) | |
39 | ||
40 | //AliHLTPHOSRcuCalibrationProcessor:: AliHLTPHOSRcuCalibrationProcessor(): AliHLTPHOSRcuProcessor(), fModuleID(0), fRcuX(0), fRcuZ(0) | |
41 | { | |
42 | //Default constructor | |
43 | cout << "WARNING: You cannot invoke the AliHLTPHOSRcuCalibrationProcessor without arguments" << endl; | |
44 | cout << "Usage AliHLTPHOSRcuCalibrationProcessor(ModuleID, X. Z)" << endl; | |
45 | } | |
46 | ||
47 | //AliHLTPHOSRcuCalibrationProcessor::AliHLTPHOSRcuCalibrationProcessor(AliHLTUInt8_t moduleID, AliHLTUInt8_t rcuX, AliHLTUInt8_t rcuZ) | |
48 | AliHLTPHOSRcuCalibrationProcessor::AliHLTPHOSRcuCalibrationProcessor(AliHLTUInt8_t moduleID, AliHLTUInt8_t rcuX, AliHLTUInt8_t rcuZ) | |
49 | { | |
50 | //Se header file for documentation | |
51 | // char *tmp = getenv("ALIHLT_BASEDIR"); | |
52 | char *tmp = getenv("HOME"); | |
53 | ||
54 | if(tmp == 0) | |
55 | { | |
56 | cout << "ERROR, environment vriable HOME is not set" << endl; | |
57 | ||
58 | } | |
59 | ||
60 | else | |
61 | { | |
62 | // sprintf(fHistoOutDir,"%s/rundir/output/histograms",tmp); | |
63 | sprintf(fHistoOutDir,"%s/rundir/output/histograms/",tmp); | |
64 | } | |
65 | ||
66 | ||
67 | SetModuleID(moduleID); | |
68 | SetRcuX(rcuX); | |
69 | SetRcuZ(rcuZ); | |
70 | Init(); | |
71 | } | |
72 | ||
73 | AliHLTPHOSRcuCalibrationProcessor::~ AliHLTPHOSRcuCalibrationProcessor() | |
74 | { | |
75 | //Destructor | |
76 | } | |
77 | ||
78 | ||
79 | void | |
80 | AliHLTPHOSRcuCalibrationProcessor::SetHistoOutDir(char *outDir) | |
81 | { | |
82 | //comment | |
83 | sprintf(fHistoOutDir,"%s", outDir); | |
84 | } | |
85 | ||
86 | void | |
87 | AliHLTPHOSRcuCalibrationProcessor::SetDefaultHistoOutDir() | |
88 | { | |
89 | //comment | |
90 | char *tmp = getenv("HOME/rundir"); | |
91 | sprintf(fHistoOutDir,"%s/rundir/output/histograms", tmp); | |
92 | //testing wether or not directry exist | |
93 | FILE *fp = fopen(fHistoOutDir, "w"); | |
94 | ||
95 | if(fp == 0) | |
96 | { | |
97 | cout << "ERROR, directory =" << fHistoOutDir << " Doesnt exist, or you don have write permissions to the directory" << endl; | |
98 | cout << "WARNING: Histograms will not bew written to files at end of run unless a valid directory is set" << endl; | |
99 | cout << "INFO, You must either" << endl; | |
100 | cout << "1) Create the directory " << fHistoOutDir << "Manually" <<endl; | |
101 | cout << "OR "<< endl; | |
102 | cout << "2) Se a valid output directory with the function AliHLTPHOSRcuCalibrationProcessor::SetHistoOutDir(*char outdir) "<< endl; | |
103 | } | |
104 | else | |
105 | { | |
106 | cout << "INFO: Output ddirectory for Histograms was set tot" << fHistoOutDir << endl; | |
107 | cout << "INFO: if you want another output directory use the AliHLTPHOSRcuCalibrationProcessor::SetHistoOutDir(*char outdir)" << endl; | |
108 | } | |
109 | ||
110 | } | |
111 | ||
112 | void | |
113 | AliHLTPHOSRcuCalibrationProcessor::Init() | |
114 | { | |
115 | //See header file for documentation | |
116 | char tmpHistoName[256]; | |
117 | int geomx; | |
118 | int geomz; | |
119 | ||
120 | ||
121 | for(unsigned int gain=0; gain< N_GAINS; gain++) | |
122 | { | |
123 | sprintf(tmpHistoName, "DeadChanneMap_Module%d_rcuz%d_rcux%d_gain%d",(int)fModuleID, fRcuZ, fRcuX, gain); | |
124 | // fDeadChannelMapHistogramPtrs[gain] = new TH2D( tmpHistoName, tmpHistoName, N_BINS, XBIN_LOW, XBIN_UP); | |
125 | ||
126 | ||
127 | fDeadChannelMapHistogramPtrs[gain] = new TH2D(tmpHistoName, tmpHistoName, | |
128 | N_XCOLUMNS_RCU , 0, N_XCOLUMNS_RCU , | |
129 | N_ZROWS_RCU, 0, N_ZROWS_RCU); | |
130 | fDeadChannelMapHistogramPtrs[gain]->Reset(); | |
131 | // fgCalibHistPtr[gain]->GetXaxis()->SetRange(128, 128 + 64); | |
132 | ||
133 | ||
134 | } | |
135 | ||
136 | ||
137 | ||
138 | for(unsigned int x = 0; x < N_XCOLUMNS_RCU; x ++) | |
139 | { | |
140 | for(unsigned int z = 0; z < N_ZROWS_RCU; z ++) | |
141 | { | |
142 | for(unsigned int gain = 0; gain < N_GAINS; gain ++) | |
143 | { | |
144 | geomx = x + N_XCOLUMNS_RCU*fRcuX; | |
145 | geomz = z + N_ZROWS_RCU*fRcuZ; | |
146 | ||
147 | fEnergyAverageValues[x][z][gain] = 0; | |
148 | fAccumulatedValues[x][z][gain] = 0; | |
149 | fTimingAverageValues[x][z][gain] = 0; | |
150 | fHits[x][z][gain] = 0; | |
151 | fDeadChannelMap[x][z][gain] = 0; | |
152 | ||
153 | sprintf(tmpHistoName, "Edistribution_%d_%d_%d_%d",(int)fModuleID, geomx, geomz, gain); | |
154 | // fEnergyHistogramPtrs[x][z][gain] = 0; | |
155 | fEnergyHistogramPtrs[x][z][gain] = new TH1F( tmpHistoName, tmpHistoName, N_BINS, XBIN_LOW, XBIN_UP); | |
156 | sprintf(tmpHistoName, "TOFdistribution_module%d_x%d_z%d_gain%d", (int)fModuleID, geomx, geomz, gain); | |
157 | ||
158 | // fTimingHistogramPtrs[x][z][gain] = 0; | |
159 | ||
160 | // sprintf(tmpHistoName, "DeadChanneMap_%d_%d_%d_%d",(int)fModuleID, geomx, geomz, gain); | |
161 | // fDeadChannelMapHistogramPtrs[x][z][gain] = new TH1D( tmpHistoName, tmpHistoName, N_BINS, XBIN_LOW, XBIN_UP); | |
162 | ||
163 | ||
164 | fTimingHistogramPtrs[x][z][gain] = new TH1F(tmpHistoName , tmpHistoName, N_BINS, XBIN_LOW, XBIN_UP); | |
165 | fCellAccEnergy.fAccumulatedEnergies[x][z][gain] = 0; | |
166 | fCellAccEnergy.fHits[x][z][gain] = 0; | |
167 | fCellAccEnergy.fDeadChannelMap[x][z][gain] = 0; | |
168 | fCellAccEnergy.fModuleID = 0; | |
169 | fCellAccEnergy.fRcuX = 0; | |
170 | fCellAccEnergy.fRcuZ = 0; | |
171 | } | |
172 | } | |
173 | } | |
174 | } | |
175 | ||
176 | ||
177 | ||
178 | void | |
179 | AliHLTPHOSRcuCalibrationProcessor::SetRcuX(AliHLTUInt8_t X) | |
180 | { | |
181 | //See header file for documentation | |
182 | fRcuX = X; | |
183 | fCellAccEnergy.fRcuX = X; | |
184 | } | |
185 | ||
186 | ||
187 | ||
188 | void | |
189 | AliHLTPHOSRcuCalibrationProcessor::SetRcuZ(AliHLTUInt8_t Z) | |
190 | { | |
191 | //See header file for documentation | |
192 | fRcuZ = Z; | |
193 | fCellAccEnergy.fRcuZ = Z; | |
194 | } | |
195 | ||
196 | ||
197 | ||
198 | ||
199 | void | |
200 | AliHLTPHOSRcuCalibrationProcessor::SetModuleID(AliHLTUInt8_t moduleID) | |
201 | { | |
202 | //See header file for documentation | |
203 | fModuleID = moduleID; | |
204 | } | |
205 | ||
206 | ||
207 | void | |
208 | AliHLTPHOSRcuCalibrationProcessor::FillEnergy(AliHLTUInt8_t x, AliHLTUInt8_t z, AliHLTUInt8_t gain, float energy) | |
209 | { | |
210 | //comment | |
211 | fCellAccEnergy.fAccumulatedEnergies[x][z][gain] += energy; | |
212 | fCellAccEnergy.fHits[x][z][gain] ++; | |
213 | fEnergyHistogramPtrs[x][z][gain]->Fill(energy); | |
214 | } | |
215 | ||
216 | ||
217 | void | |
218 | AliHLTPHOSRcuCalibrationProcessor::FillTime(AliHLTUInt8_t x, AliHLTUInt8_t z, AliHLTUInt8_t gain, float time) | |
219 | { | |
220 | //See header file for documentation | |
221 | fTimingHistogramPtrs[x][z][gain]->Fill(time); | |
222 | } | |
223 | ||
224 | const AliHLTPHOSRcuCellAccumulatedEnergyDataStruct& | |
225 | AliHLTPHOSRcuCalibrationProcessor::GetCellAccumulatedEnergies() | |
226 | { | |
227 | // return &fCellAccEnergy ; | |
228 | return fCellAccEnergy ; | |
229 | } | |
230 | ||
231 | void | |
232 | AliHLTPHOSRcuCalibrationProcessor::FillLiveChannels(Int_t data[], int size, Int_t x, Int_t z, Int_t gain) | |
233 | { | |
234 | //comment | |
235 | for(Int_t i = 0; i < size; i++) | |
236 | { | |
237 | if(data[i] > THRESHOLD) | |
238 | { | |
239 | if(data[i+1] > THRESHOLD) | |
240 | { | |
241 | if(data[i+2] > THRESHOLD) | |
242 | { | |
243 | if(data[i+3] > THRESHOLD) | |
244 | { | |
245 | ||
246 | fCellAccEnergy.fDeadChannelMap[x][z][gain] = 10; | |
247 | ||
248 | return; | |
249 | } | |
250 | } | |
251 | } | |
252 | } | |
253 | } | |
254 | } | |
255 | ||
256 | void | |
257 | AliHLTPHOSRcuCalibrationProcessor::FillLiveChannelHistograms() | |
258 | { | |
259 | //comment | |
260 | for(unsigned int x = 0; x < N_XCOLUMNS_RCU; x ++) | |
261 | { | |
262 | for(unsigned int z = 0; z < N_ZROWS_RCU; z ++) | |
263 | { | |
264 | for(unsigned int gain = 0; gain < N_GAINS; gain ++) | |
265 | { | |
266 | fDeadChannelMapHistogramPtrs[gain]->SetBinContent(x ,z , fCellAccEnergy.fDeadChannelMap[x][z][gain]); | |
267 | } | |
268 | } | |
269 | } | |
270 | ||
271 | } | |
272 | ||
273 | void | |
274 | AliHLTPHOSRcuCalibrationProcessor::Reset() | |
275 | { | |
276 | //See header file for documentation | |
277 | for(unsigned int x = 0; x < N_XCOLUMNS_RCU; x ++) | |
278 | { | |
279 | for(unsigned int z = 0; z < N_ZROWS_RCU; z ++) | |
280 | { | |
281 | for(unsigned int gain = 0; gain < N_GAINS; gain ++) | |
282 | { | |
283 | fEnergyAverageValues[x][z][gain] = 0; | |
284 | fAccumulatedValues[x][z][gain] = 0; | |
285 | fTimingAverageValues[x][z][gain] = 0; | |
286 | fHits[x][z][gain] = 0; | |
287 | fDeadChannelMap[x][z][gain] = 0; | |
288 | } | |
289 | } | |
290 | } | |
291 | ||
292 | for(unsigned int i = 0; i <ALTRO_MAX_SAMPLES; i++) | |
293 | { | |
294 | fTmpChannelData[i] = 0; | |
295 | } | |
296 | } | |
297 | ||
298 | ||
299 | void | |
300 | AliHLTPHOSRcuCalibrationProcessor::WriteAllHistograms(char *opt) | |
301 | { | |
302 | //comment | |
303 | printf("\nAliHLTPHOSRcuCalibrationProcessor::WriteAllHistogram, opt = %s\n", opt); | |
304 | ||
305 | FillLiveChannelHistograms(); | |
306 | // cout <<<< endl; | |
307 | ||
308 | int runNumber = 0; | |
309 | char tmpEFileName[256]; | |
310 | char tmpDeadFileName_gain0[256]; | |
311 | char tmpDeadFileName_gain1[256]; | |
312 | // char *tmpRundir = getenv("HOME"); | |
313 | char runNumberFile[256]; | |
314 | char timeString[256]; | |
315 | ||
316 | ResetArray(runNumberFile, 256); | |
317 | ResetArray(tmpEFileName, 256); | |
318 | ResetArray(timeString, 256); | |
319 | ||
320 | ||
321 | sprintf(runNumberFile, "%s/rundir/runNumber.txt", getenv("HOME")); | |
322 | ||
323 | FILE *fp = fopen(runNumberFile, "r"); | |
324 | if(fp == 0) | |
325 | { | |
326 | ScanTimeString(timeString); | |
327 | cout << "WARNING, could not find file "<< runNumberFile <<endl; | |
328 | cout <<"Filename will be stamped with data and time instead " << endl; | |
329 | sprintf(tmpEFileName, "%s/Energy/EnergyHistograms_%s_mod%d_rcuZ%d_rcuX%d.root", fHistoOutDir, timeString, (int)fModuleID, (int)fRcuZ, (int)fRcuZ); | |
330 | sprintf(tmpDeadFileName_gain0, "%s/DeadMap/DeadChannelHistograms_%s_mod%d_rcuZ%d_rcuX%d_LG.root", fHistoOutDir, timeString, (int)fModuleID, (int)fRcuZ, (int)fRcuZ); | |
331 | sprintf(tmpDeadFileName_gain1, "%s/DeadMap/DeadChannelHistograms_%s_mod%d_rcuZ%d_rcuX%d_HG.root", fHistoOutDir, timeString, (int)fModuleID, (int)fRcuZ, (int)fRcuZ); | |
332 | } | |
333 | else | |
334 | { | |
335 | fscanf(fp, "%d", &runNumber); | |
336 | sprintf(tmpEFileName, "%s/Energy/EnergyHisttograms_run%d_mod%d_rcuZ%d_rcuX%d.root", fHistoOutDir, runNumber, (int)fModuleID, (int)fRcuZ, (int)fRcuX); | |
337 | sprintf(tmpDeadFileName_gain0, "%s/DeadMap/DeadChannleHistograms_run%d_mod%d_rcuZ%d_rcuX%d_LG.root", fHistoOutDir, runNumber, (int)fModuleID, (int)fRcuZ, (int)fRcuX); | |
338 | sprintf(tmpDeadFileName_gain1, "%s/DeadMap/DeadChannleHistograms_run%d_mod%d_rcuZ%d_rcuX%d_HG.root", fHistoOutDir, runNumber, (int)fModuleID, (int)fRcuZ, (int)fRcuX); | |
339 | fclose(fp); | |
340 | } | |
341 | ||
342 | // cout << "tmpEFileName = "<< tmpEFileName <<endl; | |
343 | // cout << "tmpDeadFileName_gain0 (low gain) = " << tmpDeadFileName_gain0 <<endl; | |
344 | // cout << "tmpDeadFileName_gain1 (high gain) = " << tmpDeadFileName_gain1 <<endl; | |
345 | ||
346 | // sprintf(tmpEFileName,"/home/aliphoshlt/rundir/outdata/calibHisto_%d_%d_%d.root", (int)fModuleID, (int)fRcuX, (int)fRcuZ); | |
347 | ||
348 | ||
349 | // TFile *energyHistoFile = new TFile(tmpEFileName,"update"); | |
350 | // TFile *energyHistoFile = new TFile(tmpEFileName,"recreate"); | |
351 | // TFile *energyHistoFile = new TFile(tmpEFileName,"recreate"); | |
352 | ||
353 | cout << "tmpEFileName = "<< tmpEFileName << endl; | |
354 | ||
355 | TFile *energyHistoFile = new TFile(tmpEFileName, opt); | |
356 | if(!energyHistoFile) return; | |
357 | if(!energyHistoFile->IsOpen()) return; | |
358 | ||
359 | cout <<"printing histograms"<< endl; | |
360 | ||
361 | for(unsigned int x = 0; x < N_XCOLUMNS_RCU; x ++) | |
362 | { | |
363 | for(unsigned int z = 0; z < N_ZROWS_RCU; z ++) | |
364 | { | |
365 | for(unsigned int gain = 0; gain < N_GAINS; gain ++) | |
366 | { | |
367 | // cout << "the number of entries is " <<fEnergyHistogramPtrs[x][z][gain]->GetEntries()<< endl; | |
368 | fEnergyHistogramPtrs[x][z][gain]->Write(); | |
369 | } | |
370 | } | |
371 | } | |
372 | energyHistoFile->Close(); | |
373 | ||
374 | ||
375 | //LOW GAIN | |
376 | //TFile *deadHistoFile_gain0 = new TFile(tmpDeadFileName_gain0,"update"); | |
377 | TFile *deadHistoFile_gain0 = new TFile(tmpDeadFileName_gain0, opt); | |
378 | ||
379 | if(!deadHistoFile_gain0) return; | |
380 | if(!deadHistoFile_gain0->IsOpen()) return; | |
381 | fDeadChannelMapHistogramPtrs[0]->Write(); | |
382 | ||
383 | ||
384 | //HIGH GAIN | |
385 | // TFile *deadHistoFile_gain1 = new TFile(tmpDeadFileName_gain1,"update"); | |
386 | TFile *deadHistoFile_gain1 = new TFile(tmpDeadFileName_gain1, opt); | |
387 | if(!deadHistoFile_gain1) return; | |
388 | if(!deadHistoFile_gain1->IsOpen()) return; | |
389 | fDeadChannelMapHistogramPtrs[1]->Write(); | |
390 | ||
391 | ||
392 | deadHistoFile_gain0->Close(); | |
393 | deadHistoFile_gain1->Close(); | |
394 | ||
395 | cout << "printing histograms, finished"<< endl; | |
396 | } | |
397 | ||
398 | void | |
399 | AliHLTPHOSRcuCalibrationProcessor::ScanTimeString(char *timeString) | |
400 | { | |
401 | //comment | |
402 | time_t timePtr; | |
403 | tm *tmPtr; | |
404 | // char *timeString; | |
405 | time(&timePtr); | |
406 | tmPtr=localtime(&timePtr); | |
407 | timeString=asctime(tmPtr); | |
408 | // char tShort [strlen(timeString)+1]; | |
409 | char day[10]; | |
410 | char month[10]; | |
411 | int date; | |
412 | int hour; | |
413 | int min; | |
414 | int sec; | |
415 | int year; | |
416 | //char sDate[5]; | |
417 | //char sHour[5]; | |
418 | //char sMin[5]; | |
419 | //char sSec[5]; | |
420 | //char sYear[10]; | |
421 | sscanf(timeString, "%s %s %d %d:%d:%d %d\n", day, month, &date, &hour, &min, &sec, &year); | |
422 | ||
423 | } |