]>
Commit | Line | Data |
---|---|---|
1b41ab20 | 1 | // $Id$ |
2 | ||
6a76e30e | 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 "AliHLTPHOSRcuCalibrationProcessor.h" | |
20 | #include <iostream> | |
21 | #include "AliHLTPHOSRcuCellEnergyDataStruct.h" | |
22 | #include "TFile.h" | |
23 | #include "unistd.h" | |
24 | #include <time.h> | |
2589c3a3 | 25 | //#include "AliHLTPHOSUtilities.h" |
6a76e30e | 26 | |
27 | #define THRESHOLD 30 | |
28 | ||
29 | using namespace std; | |
30 | ||
31 | ||
2589c3a3 | 32 | |
6a76e30e | 33 | /************************************************************************* |
34 | * Class AliHLTPHOSRcuCalibrationProcessor accumulating histograms * | |
35 | * with amplitudes per PHOS channel * | |
36 | * It is intended to run at the HLT farm * | |
37 | * and it fills the histograms with amplitudes per channel. * | |
38 | * Usage example see in PHOS/macros/Shuttle/AliPHOSCalibHistoProducer.C * | |
39 | **************************************************************************/ | |
40 | ||
2589c3a3 | 41 | /* |
b444d727 | 42 | AliHLTPHOSRcuCalibrationProcessor:: AliHLTPHOSRcuCalibrationProcessor(): AliHLTPHOSBase(), |
43 | fCellAccEnergy(), | |
44 | fModuleID(0), | |
45 | fRcuX(0), | |
46 | fRcuZ(0) | |
2589c3a3 | 47 | // fUtilitiesPtr(0) |
48 | */ | |
49 | //{ | |
50 | ||
51 | // fUtilitiesPtr = new AliHLTPHOSUtilities(); | |
6a76e30e | 52 | //Default constructor |
8efbf5fe | 53 | // cout << "WARNING: You cannot invoke the AliHLTPHOSRcuCalibrationProcessor without arguments" << endl; |
54 | // cout << "Usage AliHLTPHOSRcuCalibrationProcessor(ModuleID, X. Z)" << endl; | |
2589c3a3 | 55 | //} |
6a76e30e | 56 | |
57 | //AliHLTPHOSRcuCalibrationProcessor::AliHLTPHOSRcuCalibrationProcessor(AliHLTUInt8_t moduleID, AliHLTUInt8_t rcuX, AliHLTUInt8_t rcuZ) | |
b444d727 | 58 | AliHLTPHOSRcuCalibrationProcessor::AliHLTPHOSRcuCalibrationProcessor(AliHLTUInt8_t moduleID, AliHLTUInt8_t rcuX, AliHLTUInt8_t rcuZ):AliHLTPHOSBase(), |
59 | fCellAccEnergy(), | |
60 | fModuleID(moduleID), | |
61 | fRcuX(rcuX), | |
62 | fRcuZ(rcuZ) | |
2589c3a3 | 63 | |
6a76e30e | 64 | { |
65 | //Se header file for documentation | |
2589c3a3 | 66 | // fUtilitiesPtr = new AliHLTPHOSUtilities(); |
67 | ||
6a76e30e | 68 | char *tmp = getenv("HOME"); |
69 | ||
70 | if(tmp == 0) | |
71 | { | |
8efbf5fe | 72 | // cout << "ERROR, environment vriable HOME is not set" << endl; |
6a76e30e | 73 | } |
6a76e30e | 74 | else |
75 | { | |
76 | // sprintf(fHistoOutDir,"%s/rundir/output/histograms",tmp); | |
77 | sprintf(fHistoOutDir,"%s/rundir/output/histograms/",tmp); | |
78 | } | |
79 | ||
6a76e30e | 80 | Init(); |
81 | } | |
82 | ||
83 | AliHLTPHOSRcuCalibrationProcessor::~ AliHLTPHOSRcuCalibrationProcessor() | |
84 | { | |
85 | //Destructor | |
86 | } | |
87 | ||
88 | ||
89 | void | |
90 | AliHLTPHOSRcuCalibrationProcessor::SetHistoOutDir(char *outDir) | |
91 | { | |
92 | //comment | |
93 | sprintf(fHistoOutDir,"%s", outDir); | |
94 | } | |
95 | ||
96 | void | |
97 | AliHLTPHOSRcuCalibrationProcessor::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 | { | |
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 AliHLTPHOSRcuCalibrationProcessor::SetHistoOutDir(*char outdir) "<< endl; | |
6a76e30e | 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 AliHLTPHOSRcuCalibrationProcessor::SetHistoOutDir(*char outdir)" << endl; | |
6a76e30e | 118 | } |
119 | ||
120 | } | |
121 | ||
122 | void | |
123 | AliHLTPHOSRcuCalibrationProcessor::Init() | |
124 | { | |
125 | //See header file for documentation | |
126 | char tmpHistoName[256]; | |
127 | int geomx; | |
128 | int geomz; | |
6a76e30e | 129 | |
27029341 | 130 | for(int gain=0; gain< NGAINS; gain++) |
6a76e30e | 131 | { |
132 | sprintf(tmpHistoName, "DeadChanneMap_Module%d_rcuz%d_rcux%d_gain%d",(int)fModuleID, fRcuZ, fRcuX, gain); | |
6a76e30e | 133 | fDeadChannelMapHistogramPtrs[gain] = new TH2D(tmpHistoName, tmpHistoName, |
27029341 | 134 | NXCOLUMNSRCU , 0, NXCOLUMNSRCU , |
135 | NZROWSRCU, 0, NZROWSRCU); | |
6a76e30e | 136 | fDeadChannelMapHistogramPtrs[gain]->Reset(); |
6a76e30e | 137 | } |
138 | ||
27029341 | 139 | for(int x = 0; x < NXCOLUMNSRCU; x ++) |
6a76e30e | 140 | { |
27029341 | 141 | for(int z = 0; z < NZROWSRCU; z ++) |
6a76e30e | 142 | { |
27029341 | 143 | for(int gain = 0; gain < NGAINS; gain ++) |
6a76e30e | 144 | { |
27029341 | 145 | geomx = x + NXCOLUMNSRCU*fRcuX; |
146 | geomz = z + NZROWSRCU*fRcuZ; | |
6a76e30e | 147 | |
148 | fEnergyAverageValues[x][z][gain] = 0; | |
149 | fAccumulatedValues[x][z][gain] = 0; | |
150 | fTimingAverageValues[x][z][gain] = 0; | |
151 | fHits[x][z][gain] = 0; | |
152 | fDeadChannelMap[x][z][gain] = 0; | |
6a76e30e | 153 | sprintf(tmpHistoName, "Edistribution_%d_%d_%d_%d",(int)fModuleID, geomx, geomz, gain); |
27029341 | 154 | fEnergyHistogramPtrs[x][z][gain] = new TH1F( tmpHistoName, tmpHistoName, NBINS, XBINLOW, XBINUP); |
6a76e30e | 155 | sprintf(tmpHistoName, "TOFdistribution_module%d_x%d_z%d_gain%d", (int)fModuleID, geomx, geomz, gain); |
27029341 | 156 | fTimingHistogramPtrs[x][z][gain] = new TH1F(tmpHistoName , tmpHistoName, NBINS, XBINLOW, XBINUP); |
6a76e30e | 157 | fCellAccEnergy.fAccumulatedEnergies[x][z][gain] = 0; |
158 | fCellAccEnergy.fHits[x][z][gain] = 0; | |
159 | fCellAccEnergy.fDeadChannelMap[x][z][gain] = 0; | |
160 | fCellAccEnergy.fModuleID = 0; | |
161 | fCellAccEnergy.fRcuX = 0; | |
162 | fCellAccEnergy.fRcuZ = 0; | |
163 | } | |
164 | } | |
165 | } | |
166 | } | |
167 | ||
168 | ||
169 | ||
6a76e30e | 170 | void |
171 | AliHLTPHOSRcuCalibrationProcessor::FillEnergy(AliHLTUInt8_t x, AliHLTUInt8_t z, AliHLTUInt8_t gain, float energy) | |
172 | { | |
173 | //comment | |
174 | fCellAccEnergy.fAccumulatedEnergies[x][z][gain] += energy; | |
175 | fCellAccEnergy.fHits[x][z][gain] ++; | |
176 | fEnergyHistogramPtrs[x][z][gain]->Fill(energy); | |
177 | } | |
178 | ||
179 | ||
180 | void | |
181 | AliHLTPHOSRcuCalibrationProcessor::FillTime(AliHLTUInt8_t x, AliHLTUInt8_t z, AliHLTUInt8_t gain, float time) | |
182 | { | |
183 | //See header file for documentation | |
184 | fTimingHistogramPtrs[x][z][gain]->Fill(time); | |
185 | } | |
186 | ||
187 | const AliHLTPHOSRcuCellAccumulatedEnergyDataStruct& | |
188 | AliHLTPHOSRcuCalibrationProcessor::GetCellAccumulatedEnergies() | |
189 | { | |
190 | // return &fCellAccEnergy ; | |
191 | return fCellAccEnergy ; | |
192 | } | |
193 | ||
194 | void | |
195 | AliHLTPHOSRcuCalibrationProcessor::FillLiveChannels(Int_t data[], int size, Int_t x, Int_t z, Int_t gain) | |
196 | { | |
197 | //comment | |
b444d727 | 198 | for(int i = 0; i < size; i++) |
6a76e30e | 199 | { |
200 | if(data[i] > THRESHOLD) | |
201 | { | |
202 | if(data[i+1] > THRESHOLD) | |
203 | { | |
204 | if(data[i+2] > THRESHOLD) | |
205 | { | |
206 | if(data[i+3] > THRESHOLD) | |
207 | { | |
208 | ||
209 | fCellAccEnergy.fDeadChannelMap[x][z][gain] = 10; | |
210 | ||
211 | return; | |
212 | } | |
213 | } | |
214 | } | |
215 | } | |
216 | } | |
217 | } | |
218 | ||
219 | void | |
220 | AliHLTPHOSRcuCalibrationProcessor::FillLiveChannelHistograms() | |
221 | { | |
222 | //comment | |
27029341 | 223 | for(int x = 0; x < NXCOLUMNSRCU; x ++) |
6a76e30e | 224 | { |
27029341 | 225 | for(int z = 0; z < NZROWSRCU; z ++) |
6a76e30e | 226 | { |
27029341 | 227 | for(int gain = 0; gain < NGAINS; gain ++) |
6a76e30e | 228 | { |
229 | fDeadChannelMapHistogramPtrs[gain]->SetBinContent(x ,z , fCellAccEnergy.fDeadChannelMap[x][z][gain]); | |
230 | } | |
231 | } | |
232 | } | |
233 | ||
234 | } | |
235 | ||
236 | void | |
237 | AliHLTPHOSRcuCalibrationProcessor::Reset() | |
238 | { | |
239 | //See header file for documentation | |
27029341 | 240 | for(int x = 0; x < NXCOLUMNSRCU; x ++) |
6a76e30e | 241 | { |
27029341 | 242 | for(int z = 0; z < NZROWSRCU; z ++) |
6a76e30e | 243 | { |
27029341 | 244 | for(int gain = 0; gain < NGAINS; gain ++) |
6a76e30e | 245 | { |
246 | fEnergyAverageValues[x][z][gain] = 0; | |
247 | fAccumulatedValues[x][z][gain] = 0; | |
248 | fTimingAverageValues[x][z][gain] = 0; | |
249 | fHits[x][z][gain] = 0; | |
250 | fDeadChannelMap[x][z][gain] = 0; | |
251 | } | |
252 | } | |
253 | } | |
254 | ||
27029341 | 255 | for(int i = 0; i <ALTROMAXSAMPLES; i++) |
6a76e30e | 256 | { |
257 | fTmpChannelData[i] = 0; | |
258 | } | |
259 | } | |
260 | ||
261 | ||
262 | void | |
263 | AliHLTPHOSRcuCalibrationProcessor::WriteAllHistograms(char *opt) | |
264 | { | |
265 | //comment | |
6a76e30e | 266 | FillLiveChannelHistograms(); |
6a76e30e | 267 | int runNumber = 0; |
268 | char tmpEFileName[256]; | |
269 | char tmpDeadFileName_gain0[256]; | |
270 | char tmpDeadFileName_gain1[256]; | |
6a76e30e | 271 | char runNumberFile[256]; |
272 | char timeString[256]; | |
2589c3a3 | 273 | |
274 | /* | |
275 | fUtilitiesPtr->ResetArray(runNumberFile, 256); | |
276 | fUtilitiesPtr->ResetArray(tmpEFileName, 256); | |
277 | fUtilitiesPtr->ResetArray(timeString, 256); | |
278 | */ | |
6a76e30e | 279 | |
280 | sprintf(runNumberFile, "%s/rundir/runNumber.txt", getenv("HOME")); | |
281 | ||
282 | FILE *fp = fopen(runNumberFile, "r"); | |
e304ea31 | 283 | Int_t res = 0; //OD to get rid of warnings |
6a76e30e | 284 | if(fp == 0) |
285 | { | |
286 | ScanTimeString(timeString); | |
8efbf5fe | 287 | // cout << "WARNING, could not find file "<< runNumberFile <<endl; |
288 | // cout <<"Filename will be stamped with data and time instead " << endl; | |
6a76e30e | 289 | sprintf(tmpEFileName, "%s/Energy/EnergyHistograms_%s_mod%d_rcuZ%d_rcuX%d.root", fHistoOutDir, timeString, (int)fModuleID, (int)fRcuZ, (int)fRcuZ); |
290 | sprintf(tmpDeadFileName_gain0, "%s/DeadMap/DeadChannelHistograms_%s_mod%d_rcuZ%d_rcuX%d_LG.root", fHistoOutDir, timeString, (int)fModuleID, (int)fRcuZ, (int)fRcuZ); | |
291 | sprintf(tmpDeadFileName_gain1, "%s/DeadMap/DeadChannelHistograms_%s_mod%d_rcuZ%d_rcuX%d_HG.root", fHistoOutDir, timeString, (int)fModuleID, (int)fRcuZ, (int)fRcuZ); | |
292 | } | |
293 | else | |
294 | { | |
e304ea31 | 295 | res = fscanf(fp, "%d", &runNumber); |
6a76e30e | 296 | sprintf(tmpEFileName, "%s/Energy/EnergyHisttograms_run%d_mod%d_rcuZ%d_rcuX%d.root", fHistoOutDir, runNumber, (int)fModuleID, (int)fRcuZ, (int)fRcuX); |
297 | sprintf(tmpDeadFileName_gain0, "%s/DeadMap/DeadChannleHistograms_run%d_mod%d_rcuZ%d_rcuX%d_LG.root", fHistoOutDir, runNumber, (int)fModuleID, (int)fRcuZ, (int)fRcuX); | |
298 | sprintf(tmpDeadFileName_gain1, "%s/DeadMap/DeadChannleHistograms_run%d_mod%d_rcuZ%d_rcuX%d_HG.root", fHistoOutDir, runNumber, (int)fModuleID, (int)fRcuZ, (int)fRcuX); | |
299 | fclose(fp); | |
300 | } | |
301 | ||
6a76e30e | 302 | |
303 | TFile *energyHistoFile = new TFile(tmpEFileName, opt); | |
304 | if(!energyHistoFile) return; | |
305 | if(!energyHistoFile->IsOpen()) return; | |
306 | ||
8efbf5fe | 307 | // cout <<"printing histograms"<< endl; |
6a76e30e | 308 | |
27029341 | 309 | for(int x = 0; x < NXCOLUMNSRCU; x ++) |
6a76e30e | 310 | { |
27029341 | 311 | for(int z = 0; z < NZROWSRCU; z ++) |
6a76e30e | 312 | { |
27029341 | 313 | for(int gain = 0; gain < NGAINS; gain ++) |
6a76e30e | 314 | { |
6a76e30e | 315 | fEnergyHistogramPtrs[x][z][gain]->Write(); |
316 | } | |
317 | } | |
318 | } | |
319 | energyHistoFile->Close(); | |
320 | ||
321 | ||
322 | //LOW GAIN | |
6a76e30e | 323 | TFile *deadHistoFile_gain0 = new TFile(tmpDeadFileName_gain0, opt); |
324 | ||
325 | if(!deadHistoFile_gain0) return; | |
326 | if(!deadHistoFile_gain0->IsOpen()) return; | |
327 | fDeadChannelMapHistogramPtrs[0]->Write(); | |
6a76e30e | 328 | //HIGH GAIN |
6a76e30e | 329 | TFile *deadHistoFile_gain1 = new TFile(tmpDeadFileName_gain1, opt); |
330 | if(!deadHistoFile_gain1) return; | |
331 | if(!deadHistoFile_gain1->IsOpen()) return; | |
332 | fDeadChannelMapHistogramPtrs[1]->Write(); | |
6a76e30e | 333 | deadHistoFile_gain0->Close(); |
334 | deadHistoFile_gain1->Close(); | |
8efbf5fe | 335 | // cout << "printing histograms, finished"<< endl; |
6a76e30e | 336 | } |
337 | ||
338 | void | |
339 | AliHLTPHOSRcuCalibrationProcessor::ScanTimeString(char *timeString) | |
340 | { | |
341 | //comment | |
342 | time_t timePtr; | |
343 | tm *tmPtr; | |
6a76e30e | 344 | time(&timePtr); |
345 | tmPtr=localtime(&timePtr); | |
346 | timeString=asctime(tmPtr); | |
6a76e30e | 347 | char day[10]; |
348 | char month[10]; | |
349 | int date; | |
350 | int hour; | |
351 | int min; | |
352 | int sec; | |
353 | int year; | |
6a76e30e | 354 | sscanf(timeString, "%s %s %d %d:%d:%d %d\n", day, month, &date, &hour, &min, &sec, &year); |
6a76e30e | 355 | } |