]>
Commit | Line | Data |
---|---|---|
792f66f1 | 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> | |
792f66f1 | 19 | #include "AliHLTPHOSRcuCellEnergyDataStruct.h" |
20 | #include "TFile.h" | |
c0b4e7eb | 21 | #include "unistd.h" |
22 | #include <time.h> | |
23 | ||
24 | #define THRESHOLD 30 | |
792f66f1 | 25 | |
1b486665 | 26 | using namespace std; |
27 | ||
28 | ||
792f66f1 | 29 | /************************************************************************* |
c37f821f | 30 | * Class AliHLTPHOSRcuHistogramProducer accumulating histograms * |
792f66f1 | 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 | **************************************************************************/ | |
1b486665 | 36 | |
37 | ||
c0b4e7eb | 38 | AliHLTPHOSRcuHistogramProducer:: AliHLTPHOSRcuHistogramProducer(): AliHLTPHOSBase(), fModuleID(0), fRcuX(0), fRcuZ(0) |
1b486665 | 39 | |
c0b4e7eb | 40 | //AliHLTPHOSRcuHistogramProducer:: AliHLTPHOSRcuHistogramProducer(): AliHLTPHOSRcuProcessor(), fModuleID(0), fRcuX(0), fRcuZ(0) |
792f66f1 | 41 | { |
1b486665 | 42 | //Default constructor |
792f66f1 | 43 | cout << "WARNING: You cannot invoke the AliHLTPHOSRcuHistogramProducer without arguments" << endl; |
44 | cout << "Usage AliHLTPHOSRcuHistogramProducer(ModuleID, X. Z)" << endl; | |
792f66f1 | 45 | } |
46 | ||
1b486665 | 47 | //AliHLTPHOSRcuHistogramProducer::AliHLTPHOSRcuHistogramProducer(AliHLTUInt8_t moduleID, AliHLTUInt8_t rcuX, AliHLTUInt8_t rcuZ) |
792f66f1 | 48 | AliHLTPHOSRcuHistogramProducer::AliHLTPHOSRcuHistogramProducer(AliHLTUInt8_t moduleID, AliHLTUInt8_t rcuX, AliHLTUInt8_t rcuZ) |
49 | { | |
1b486665 | 50 | //Se header file for documentation |
c0b4e7eb | 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 | ||
792f66f1 | 67 | SetModuleID(moduleID); |
68 | SetRcuX(rcuX); | |
69 | SetRcuZ(rcuZ); | |
70 | Init(); | |
71 | } | |
72 | ||
73 | AliHLTPHOSRcuHistogramProducer::~ AliHLTPHOSRcuHistogramProducer() | |
74 | { | |
1b486665 | 75 | //Destructor |
792f66f1 | 76 | } |
77 | ||
78 | ||
c0b4e7eb | 79 | void |
80 | AliHLTPHOSRcuHistogramProducer::SetHistoOutDir(char *outDir) | |
81 | { | |
ab38011b | 82 | //comment |
c0b4e7eb | 83 | sprintf(fHistoOutDir,"%s", outDir); |
84 | } | |
85 | ||
86 | void | |
87 | AliHLTPHOSRcuHistogramProducer::SetDefaultHistoOutDir() | |
88 | { | |
ab38011b | 89 | //comment |
c0b4e7eb | 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 AliHLTPHOSRcuHistogramProducer::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 AliHLTPHOSRcuHistogramProducer::SetHistoOutDir(*char outdir)" << endl; | |
108 | } | |
109 | ||
110 | } | |
111 | ||
792f66f1 | 112 | void |
113 | AliHLTPHOSRcuHistogramProducer::Init() | |
114 | { | |
1b486665 | 115 | //See header file for documentation |
792f66f1 | 116 | char tmpHistoName[256]; |
117 | int geomx; | |
118 | int geomz; | |
119 | ||
120 | ||
1804b020 | 121 | for(unsigned int gain=0; gain< N_GAINS; gain++) |
c0b4e7eb | 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 | ||
1804b020 | 138 | for(unsigned int x = 0; x < N_XCOLUMNS_RCU; x ++) |
792f66f1 | 139 | { |
1804b020 | 140 | for(unsigned int z = 0; z < N_ZROWS_RCU; z ++) |
792f66f1 | 141 | { |
1804b020 | 142 | for(unsigned int gain = 0; gain < N_GAINS; gain ++) |
792f66f1 | 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; | |
c0b4e7eb | 151 | fDeadChannelMap[x][z][gain] = 0; |
152 | ||
792f66f1 | 153 | sprintf(tmpHistoName, "Edistribution_%d_%d_%d_%d",(int)fModuleID, geomx, geomz, gain); |
c0b4e7eb | 154 | // fEnergyHistogramPtrs[x][z][gain] = 0; |
792f66f1 | 155 | fEnergyHistogramPtrs[x][z][gain] = new TH1F( tmpHistoName, tmpHistoName, N_BINS, XBIN_LOW, XBIN_UP); |
c0b4e7eb | 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 | ||
792f66f1 | 164 | fTimingHistogramPtrs[x][z][gain] = new TH1F(tmpHistoName , tmpHistoName, N_BINS, XBIN_LOW, XBIN_UP); |
792f66f1 | 165 | fCellAccEnergy.fAccumulatedEnergies[x][z][gain] = 0; |
166 | fCellAccEnergy.fHits[x][z][gain] = 0; | |
c0b4e7eb | 167 | fCellAccEnergy.fDeadChannelMap[x][z][gain] = 0; |
792f66f1 | 168 | fCellAccEnergy.fModuleID = 0; |
169 | fCellAccEnergy.fRcuX = 0; | |
170 | fCellAccEnergy.fRcuZ = 0; | |
171 | } | |
172 | } | |
173 | } | |
174 | } | |
175 | ||
792f66f1 | 176 | |
c0b4e7eb | 177 | |
792f66f1 | 178 | void |
179 | AliHLTPHOSRcuHistogramProducer::SetRcuX(AliHLTUInt8_t X) | |
180 | { | |
1b486665 | 181 | //See header file for documentation |
792f66f1 | 182 | fRcuX = X; |
183 | fCellAccEnergy.fRcuX = X; | |
184 | } | |
185 | ||
186 | ||
1b486665 | 187 | |
792f66f1 | 188 | void |
189 | AliHLTPHOSRcuHistogramProducer::SetRcuZ(AliHLTUInt8_t Z) | |
190 | { | |
1b486665 | 191 | //See header file for documentation |
792f66f1 | 192 | fRcuZ = Z; |
193 | fCellAccEnergy.fRcuZ = Z; | |
194 | } | |
195 | ||
196 | ||
792f66f1 | 197 | |
198 | ||
199 | void | |
1b486665 | 200 | AliHLTPHOSRcuHistogramProducer::SetModuleID(AliHLTUInt8_t moduleID) |
792f66f1 | 201 | { |
1b486665 | 202 | //See header file for documentation |
203 | fModuleID = moduleID; | |
792f66f1 | 204 | } |
205 | ||
206 | ||
207 | void | |
208 | AliHLTPHOSRcuHistogramProducer::FillEnergy(AliHLTUInt8_t x, AliHLTUInt8_t z, AliHLTUInt8_t gain, float energy) | |
209 | { | |
ab38011b | 210 | //comment |
792f66f1 | 211 | fCellAccEnergy.fAccumulatedEnergies[x][z][gain] += energy; |
c0b4e7eb | 212 | fCellAccEnergy.fHits[x][z][gain] ++; |
213 | fEnergyHistogramPtrs[x][z][gain]->Fill(energy); | |
792f66f1 | 214 | } |
215 | ||
216 | ||
217 | void | |
218 | AliHLTPHOSRcuHistogramProducer::FillTime(AliHLTUInt8_t x, AliHLTUInt8_t z, AliHLTUInt8_t gain, float time) | |
219 | { | |
1b486665 | 220 | //See header file for documentation |
792f66f1 | 221 | fTimingHistogramPtrs[x][z][gain]->Fill(time); |
222 | } | |
223 | ||
224 | const AliHLTPHOSRcuCellAccumulatedEnergyDataStruct& | |
225 | AliHLTPHOSRcuHistogramProducer::GetCellAccumulatedEnergies() | |
226 | { | |
227 | // return &fCellAccEnergy ; | |
228 | return fCellAccEnergy ; | |
229 | } | |
230 | ||
c0b4e7eb | 231 | void |
232 | AliHLTPHOSRcuHistogramProducer::FillLiveChannels(Int_t data[], int size, Int_t x, Int_t z, Int_t gain) | |
233 | { | |
ab38011b | 234 | //comment |
c0b4e7eb | 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 | AliHLTPHOSRcuHistogramProducer::FillLiveChannelHistograms() | |
258 | { | |
ab38011b | 259 | //comment |
1804b020 | 260 | for(unsigned int x = 0; x < N_XCOLUMNS_RCU; x ++) |
c0b4e7eb | 261 | { |
1804b020 | 262 | for(unsigned int z = 0; z < N_ZROWS_RCU; z ++) |
c0b4e7eb | 263 | { |
1804b020 | 264 | for(unsigned int gain = 0; gain < N_GAINS; gain ++) |
c0b4e7eb | 265 | { |
266 | fDeadChannelMapHistogramPtrs[gain]->SetBinContent(x ,z , fCellAccEnergy.fDeadChannelMap[x][z][gain]); | |
267 | } | |
268 | } | |
269 | } | |
270 | ||
271 | } | |
792f66f1 | 272 | |
273 | void | |
274 | AliHLTPHOSRcuHistogramProducer::Reset() | |
275 | { | |
1b486665 | 276 | //See header file for documentation |
1804b020 | 277 | for(unsigned int x = 0; x < N_XCOLUMNS_RCU; x ++) |
792f66f1 | 278 | { |
1804b020 | 279 | for(unsigned int z = 0; z < N_ZROWS_RCU; z ++) |
792f66f1 | 280 | { |
1804b020 | 281 | for(unsigned int gain = 0; gain < N_GAINS; gain ++) |
792f66f1 | 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; | |
c0b4e7eb | 287 | fDeadChannelMap[x][z][gain] = 0; |
792f66f1 | 288 | } |
289 | } | |
290 | } | |
291 | ||
1804b020 | 292 | for(unsigned int i = 0; i <ALTRO_MAX_SAMPLES; i++) |
792f66f1 | 293 | { |
294 | fTmpChannelData[i] = 0; | |
295 | } | |
296 | } | |
297 | ||
1b486665 | 298 | |
792f66f1 | 299 | void |
c0b4e7eb | 300 | AliHLTPHOSRcuHistogramProducer::WriteAllHistograms(char *opt) |
792f66f1 | 301 | { |
ab38011b | 302 | //comment |
c0b4e7eb | 303 | printf("\nAliHLTPHOSRcuHistogramProducer::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; | |
792f66f1 | 358 | |
359 | cout <<"printing histograms"<< endl; | |
792f66f1 | 360 | |
1804b020 | 361 | for(unsigned int x = 0; x < N_XCOLUMNS_RCU; x ++) |
792f66f1 | 362 | { |
1804b020 | 363 | for(unsigned int z = 0; z < N_ZROWS_RCU; z ++) |
792f66f1 | 364 | { |
1804b020 | 365 | for(unsigned int gain = 0; gain < N_GAINS; gain ++) |
792f66f1 | 366 | { |
c0b4e7eb | 367 | // cout << "the number of entries is " <<fEnergyHistogramPtrs[x][z][gain]->GetEntries()<< endl; |
792f66f1 | 368 | fEnergyHistogramPtrs[x][z][gain]->Write(); |
369 | } | |
370 | } | |
371 | } | |
c0b4e7eb | 372 | energyHistoFile->Close(); |
373 | ||
792f66f1 | 374 | |
c0b4e7eb | 375 | //LOW GAIN |
376 | //TFile *deadHistoFile_gain0 = new TFile(tmpDeadFileName_gain0,"update"); | |
377 | TFile *deadHistoFile_gain0 = new TFile(tmpDeadFileName_gain0, opt); | |
792f66f1 | 378 | |
c0b4e7eb | 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 | AliHLTPHOSRcuHistogramProducer::ScanTimeString(char *timeString) | |
400 | { | |
ab38011b | 401 | //comment |
c0b4e7eb | 402 | time_t timePtr; |
403 | tm *tmPtr; | |
404 | // char *timeString; | |
405 | time(&timePtr); | |
406 | tmPtr=localtime(&timePtr); | |
407 | timeString=asctime(tmPtr); | |
9de64fb3 | 408 | // char tShort [strlen(timeString)+1]; |
c0b4e7eb | 409 | char day[10]; |
410 | char month[10]; | |
411 | int date; | |
412 | int hour; | |
413 | int min; | |
414 | int sec; | |
415 | int year; | |
1804b020 | 416 | //char sDate[5]; |
417 | //char sHour[5]; | |
418 | //char sMin[5]; | |
419 | //char sSec[5]; | |
420 | //char sYear[10]; | |
c0b4e7eb | 421 | sscanf(timeString, "%s %s %d %d:%d:%d %d\n", day, month, &date, &hour, &min, &sec, &year); |
422 | ||
792f66f1 | 423 | } |