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