]>
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 | ||
b444d727 | 38 | AliHLTPHOSRcuCalibrationProcessor:: AliHLTPHOSRcuCalibrationProcessor(): AliHLTPHOSBase(), |
39 | fCellAccEnergy(), | |
40 | fModuleID(0), | |
41 | fRcuX(0), | |
42 | fRcuZ(0) | |
6a76e30e | 43 | { |
44 | //Default constructor | |
8efbf5fe | 45 | // cout << "WARNING: You cannot invoke the AliHLTPHOSRcuCalibrationProcessor without arguments" << endl; |
46 | // cout << "Usage AliHLTPHOSRcuCalibrationProcessor(ModuleID, X. Z)" << endl; | |
6a76e30e | 47 | } |
48 | ||
49 | //AliHLTPHOSRcuCalibrationProcessor::AliHLTPHOSRcuCalibrationProcessor(AliHLTUInt8_t moduleID, AliHLTUInt8_t rcuX, AliHLTUInt8_t rcuZ) | |
b444d727 | 50 | AliHLTPHOSRcuCalibrationProcessor::AliHLTPHOSRcuCalibrationProcessor(AliHLTUInt8_t moduleID, AliHLTUInt8_t rcuX, AliHLTUInt8_t rcuZ):AliHLTPHOSBase(), |
51 | fCellAccEnergy(), | |
52 | fModuleID(moduleID), | |
53 | fRcuX(rcuX), | |
54 | fRcuZ(rcuZ) | |
55 | ||
6a76e30e | 56 | { |
57 | //Se header file for documentation | |
6a76e30e | 58 | char *tmp = getenv("HOME"); |
59 | ||
60 | if(tmp == 0) | |
61 | { | |
8efbf5fe | 62 | // cout << "ERROR, environment vriable HOME is not set" << endl; |
6a76e30e | 63 | } |
6a76e30e | 64 | else |
65 | { | |
66 | // sprintf(fHistoOutDir,"%s/rundir/output/histograms",tmp); | |
67 | sprintf(fHistoOutDir,"%s/rundir/output/histograms/",tmp); | |
68 | } | |
69 | ||
6a76e30e | 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 | { | |
8efbf5fe | 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; | |
6a76e30e | 103 | } |
104 | else | |
105 | { | |
8efbf5fe | 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; | |
6a76e30e | 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; | |
6a76e30e | 119 | |
b444d727 | 120 | for(int gain=0; gain< N_GAINS; gain++) |
6a76e30e | 121 | { |
122 | sprintf(tmpHistoName, "DeadChanneMap_Module%d_rcuz%d_rcux%d_gain%d",(int)fModuleID, fRcuZ, fRcuX, gain); | |
6a76e30e | 123 | fDeadChannelMapHistogramPtrs[gain] = new TH2D(tmpHistoName, tmpHistoName, |
124 | N_XCOLUMNS_RCU , 0, N_XCOLUMNS_RCU , | |
125 | N_ZROWS_RCU, 0, N_ZROWS_RCU); | |
126 | fDeadChannelMapHistogramPtrs[gain]->Reset(); | |
6a76e30e | 127 | } |
128 | ||
b444d727 | 129 | for(int x = 0; x < N_XCOLUMNS_RCU; x ++) |
6a76e30e | 130 | { |
b444d727 | 131 | for(int z = 0; z < N_ZROWS_RCU; z ++) |
6a76e30e | 132 | { |
b444d727 | 133 | for(int gain = 0; gain < N_GAINS; gain ++) |
6a76e30e | 134 | { |
135 | geomx = x + N_XCOLUMNS_RCU*fRcuX; | |
136 | geomz = z + N_ZROWS_RCU*fRcuZ; | |
137 | ||
138 | fEnergyAverageValues[x][z][gain] = 0; | |
139 | fAccumulatedValues[x][z][gain] = 0; | |
140 | fTimingAverageValues[x][z][gain] = 0; | |
141 | fHits[x][z][gain] = 0; | |
142 | fDeadChannelMap[x][z][gain] = 0; | |
6a76e30e | 143 | sprintf(tmpHistoName, "Edistribution_%d_%d_%d_%d",(int)fModuleID, geomx, geomz, gain); |
6a76e30e | 144 | fEnergyHistogramPtrs[x][z][gain] = new TH1F( tmpHistoName, tmpHistoName, N_BINS, XBIN_LOW, XBIN_UP); |
145 | sprintf(tmpHistoName, "TOFdistribution_module%d_x%d_z%d_gain%d", (int)fModuleID, geomx, geomz, gain); | |
6a76e30e | 146 | fTimingHistogramPtrs[x][z][gain] = new TH1F(tmpHistoName , tmpHistoName, N_BINS, XBIN_LOW, XBIN_UP); |
147 | fCellAccEnergy.fAccumulatedEnergies[x][z][gain] = 0; | |
148 | fCellAccEnergy.fHits[x][z][gain] = 0; | |
149 | fCellAccEnergy.fDeadChannelMap[x][z][gain] = 0; | |
150 | fCellAccEnergy.fModuleID = 0; | |
151 | fCellAccEnergy.fRcuX = 0; | |
152 | fCellAccEnergy.fRcuZ = 0; | |
153 | } | |
154 | } | |
155 | } | |
156 | } | |
157 | ||
158 | ||
159 | ||
6a76e30e | 160 | void |
161 | AliHLTPHOSRcuCalibrationProcessor::FillEnergy(AliHLTUInt8_t x, AliHLTUInt8_t z, AliHLTUInt8_t gain, float energy) | |
162 | { | |
163 | //comment | |
164 | fCellAccEnergy.fAccumulatedEnergies[x][z][gain] += energy; | |
165 | fCellAccEnergy.fHits[x][z][gain] ++; | |
166 | fEnergyHistogramPtrs[x][z][gain]->Fill(energy); | |
167 | } | |
168 | ||
169 | ||
170 | void | |
171 | AliHLTPHOSRcuCalibrationProcessor::FillTime(AliHLTUInt8_t x, AliHLTUInt8_t z, AliHLTUInt8_t gain, float time) | |
172 | { | |
173 | //See header file for documentation | |
174 | fTimingHistogramPtrs[x][z][gain]->Fill(time); | |
175 | } | |
176 | ||
177 | const AliHLTPHOSRcuCellAccumulatedEnergyDataStruct& | |
178 | AliHLTPHOSRcuCalibrationProcessor::GetCellAccumulatedEnergies() | |
179 | { | |
180 | // return &fCellAccEnergy ; | |
181 | return fCellAccEnergy ; | |
182 | } | |
183 | ||
184 | void | |
185 | AliHLTPHOSRcuCalibrationProcessor::FillLiveChannels(Int_t data[], int size, Int_t x, Int_t z, Int_t gain) | |
186 | { | |
187 | //comment | |
b444d727 | 188 | for(int i = 0; i < size; i++) |
6a76e30e | 189 | { |
190 | if(data[i] > THRESHOLD) | |
191 | { | |
192 | if(data[i+1] > THRESHOLD) | |
193 | { | |
194 | if(data[i+2] > THRESHOLD) | |
195 | { | |
196 | if(data[i+3] > THRESHOLD) | |
197 | { | |
198 | ||
199 | fCellAccEnergy.fDeadChannelMap[x][z][gain] = 10; | |
200 | ||
201 | return; | |
202 | } | |
203 | } | |
204 | } | |
205 | } | |
206 | } | |
207 | } | |
208 | ||
209 | void | |
210 | AliHLTPHOSRcuCalibrationProcessor::FillLiveChannelHistograms() | |
211 | { | |
212 | //comment | |
b444d727 | 213 | for(int x = 0; x < N_XCOLUMNS_RCU; x ++) |
6a76e30e | 214 | { |
b444d727 | 215 | for(int z = 0; z < N_ZROWS_RCU; z ++) |
6a76e30e | 216 | { |
b444d727 | 217 | for(int gain = 0; gain < N_GAINS; gain ++) |
6a76e30e | 218 | { |
219 | fDeadChannelMapHistogramPtrs[gain]->SetBinContent(x ,z , fCellAccEnergy.fDeadChannelMap[x][z][gain]); | |
220 | } | |
221 | } | |
222 | } | |
223 | ||
224 | } | |
225 | ||
226 | void | |
227 | AliHLTPHOSRcuCalibrationProcessor::Reset() | |
228 | { | |
229 | //See header file for documentation | |
b444d727 | 230 | for(int x = 0; x < N_XCOLUMNS_RCU; x ++) |
6a76e30e | 231 | { |
b444d727 | 232 | for(int z = 0; z < N_ZROWS_RCU; z ++) |
6a76e30e | 233 | { |
b444d727 | 234 | for(int gain = 0; gain < N_GAINS; gain ++) |
6a76e30e | 235 | { |
236 | fEnergyAverageValues[x][z][gain] = 0; | |
237 | fAccumulatedValues[x][z][gain] = 0; | |
238 | fTimingAverageValues[x][z][gain] = 0; | |
239 | fHits[x][z][gain] = 0; | |
240 | fDeadChannelMap[x][z][gain] = 0; | |
241 | } | |
242 | } | |
243 | } | |
244 | ||
b444d727 | 245 | for(int i = 0; i <ALTRO_MAX_SAMPLES; i++) |
6a76e30e | 246 | { |
247 | fTmpChannelData[i] = 0; | |
248 | } | |
249 | } | |
250 | ||
251 | ||
252 | void | |
253 | AliHLTPHOSRcuCalibrationProcessor::WriteAllHistograms(char *opt) | |
254 | { | |
255 | //comment | |
6a76e30e | 256 | FillLiveChannelHistograms(); |
6a76e30e | 257 | int runNumber = 0; |
258 | char tmpEFileName[256]; | |
259 | char tmpDeadFileName_gain0[256]; | |
260 | char tmpDeadFileName_gain1[256]; | |
6a76e30e | 261 | char runNumberFile[256]; |
262 | char timeString[256]; | |
6a76e30e | 263 | ResetArray(runNumberFile, 256); |
264 | ResetArray(tmpEFileName, 256); | |
265 | ResetArray(timeString, 256); | |
266 | ||
267 | ||
268 | sprintf(runNumberFile, "%s/rundir/runNumber.txt", getenv("HOME")); | |
269 | ||
270 | FILE *fp = fopen(runNumberFile, "r"); | |
271 | if(fp == 0) | |
272 | { | |
273 | ScanTimeString(timeString); | |
8efbf5fe | 274 | // cout << "WARNING, could not find file "<< runNumberFile <<endl; |
275 | // cout <<"Filename will be stamped with data and time instead " << endl; | |
6a76e30e | 276 | sprintf(tmpEFileName, "%s/Energy/EnergyHistograms_%s_mod%d_rcuZ%d_rcuX%d.root", fHistoOutDir, timeString, (int)fModuleID, (int)fRcuZ, (int)fRcuZ); |
277 | sprintf(tmpDeadFileName_gain0, "%s/DeadMap/DeadChannelHistograms_%s_mod%d_rcuZ%d_rcuX%d_LG.root", fHistoOutDir, timeString, (int)fModuleID, (int)fRcuZ, (int)fRcuZ); | |
278 | sprintf(tmpDeadFileName_gain1, "%s/DeadMap/DeadChannelHistograms_%s_mod%d_rcuZ%d_rcuX%d_HG.root", fHistoOutDir, timeString, (int)fModuleID, (int)fRcuZ, (int)fRcuZ); | |
279 | } | |
280 | else | |
281 | { | |
282 | fscanf(fp, "%d", &runNumber); | |
283 | sprintf(tmpEFileName, "%s/Energy/EnergyHisttograms_run%d_mod%d_rcuZ%d_rcuX%d.root", fHistoOutDir, runNumber, (int)fModuleID, (int)fRcuZ, (int)fRcuX); | |
284 | sprintf(tmpDeadFileName_gain0, "%s/DeadMap/DeadChannleHistograms_run%d_mod%d_rcuZ%d_rcuX%d_LG.root", fHistoOutDir, runNumber, (int)fModuleID, (int)fRcuZ, (int)fRcuX); | |
285 | sprintf(tmpDeadFileName_gain1, "%s/DeadMap/DeadChannleHistograms_run%d_mod%d_rcuZ%d_rcuX%d_HG.root", fHistoOutDir, runNumber, (int)fModuleID, (int)fRcuZ, (int)fRcuX); | |
286 | fclose(fp); | |
287 | } | |
288 | ||
6a76e30e | 289 | |
290 | TFile *energyHistoFile = new TFile(tmpEFileName, opt); | |
291 | if(!energyHistoFile) return; | |
292 | if(!energyHistoFile->IsOpen()) return; | |
293 | ||
8efbf5fe | 294 | // cout <<"printing histograms"<< endl; |
6a76e30e | 295 | |
b444d727 | 296 | for(int x = 0; x < N_XCOLUMNS_RCU; x ++) |
6a76e30e | 297 | { |
b444d727 | 298 | for(int z = 0; z < N_ZROWS_RCU; z ++) |
6a76e30e | 299 | { |
b444d727 | 300 | for(int gain = 0; gain < N_GAINS; gain ++) |
6a76e30e | 301 | { |
6a76e30e | 302 | fEnergyHistogramPtrs[x][z][gain]->Write(); |
303 | } | |
304 | } | |
305 | } | |
306 | energyHistoFile->Close(); | |
307 | ||
308 | ||
309 | //LOW GAIN | |
6a76e30e | 310 | TFile *deadHistoFile_gain0 = new TFile(tmpDeadFileName_gain0, opt); |
311 | ||
312 | if(!deadHistoFile_gain0) return; | |
313 | if(!deadHistoFile_gain0->IsOpen()) return; | |
314 | fDeadChannelMapHistogramPtrs[0]->Write(); | |
6a76e30e | 315 | //HIGH GAIN |
6a76e30e | 316 | TFile *deadHistoFile_gain1 = new TFile(tmpDeadFileName_gain1, opt); |
317 | if(!deadHistoFile_gain1) return; | |
318 | if(!deadHistoFile_gain1->IsOpen()) return; | |
319 | fDeadChannelMapHistogramPtrs[1]->Write(); | |
6a76e30e | 320 | deadHistoFile_gain0->Close(); |
321 | deadHistoFile_gain1->Close(); | |
8efbf5fe | 322 | // cout << "printing histograms, finished"<< endl; |
6a76e30e | 323 | } |
324 | ||
325 | void | |
326 | AliHLTPHOSRcuCalibrationProcessor::ScanTimeString(char *timeString) | |
327 | { | |
328 | //comment | |
329 | time_t timePtr; | |
330 | tm *tmPtr; | |
6a76e30e | 331 | time(&timePtr); |
332 | tmPtr=localtime(&timePtr); | |
333 | timeString=asctime(tmPtr); | |
6a76e30e | 334 | char day[10]; |
335 | char month[10]; | |
336 | int date; | |
337 | int hour; | |
338 | int min; | |
339 | int sec; | |
340 | int year; | |
6a76e30e | 341 | sscanf(timeString, "%s %s %d %d:%d:%d %d\n", day, month, &date, &hour, &min, &sec, &year); |
6a76e30e | 342 | } |