]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/PHOS/AliHLTPHOSRcuCalibrationProcessor.cxx
Bugfix: lowercase b should be upper case B for component id: TPCClusterFinder32Bit
[u/mrichter/AliRoot.git] / HLT / PHOS / AliHLTPHOSRcuCalibrationProcessor.cxx
1 // $Id$
2
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>
25 //#include "AliHLTPHOSUtilities.h" 
26
27 #define THRESHOLD 30
28
29 using  namespace std;
30
31
32
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
41 /*
42 AliHLTPHOSRcuCalibrationProcessor:: AliHLTPHOSRcuCalibrationProcessor():  AliHLTPHOSBase(), 
43                                                                           fCellAccEnergy(),
44                                                                           fModuleID(0), 
45                                                                           fRcuX(0), 
46                                                                           fRcuZ(0)
47                                                                           //  fUtilitiesPtr(0)
48                                                                           */
49 //{
50   
51   //  fUtilitiesPtr = new  AliHLTPHOSUtilities(); 
52   //Default constructor
53   //  cout << "WARNING: You cannot invoke the AliHLTPHOSRcuCalibrationProcessor without arguments" << endl;
54   //  cout << "Usage AliHLTPHOSRcuCalibrationProcessor(ModuleID, X. Z)" << endl;
55 //} 
56
57 //AliHLTPHOSRcuCalibrationProcessor::AliHLTPHOSRcuCalibrationProcessor(AliHLTUInt8_t moduleID, AliHLTUInt8_t rcuX, AliHLTUInt8_t rcuZ)
58 AliHLTPHOSRcuCalibrationProcessor::AliHLTPHOSRcuCalibrationProcessor(AliHLTUInt8_t moduleID, AliHLTUInt8_t rcuX, AliHLTUInt8_t rcuZ):AliHLTPHOSBase(),
59                                                                                                                                      fCellAccEnergy(),
60                                                                                                                                      fModuleID(moduleID), 
61                                                                                                                                      fRcuX(rcuX), 
62                                                                                                                                      fRcuZ(rcuZ)
63                                                                                                                                      
64 {
65   //Se header file for documentation
66   //  fUtilitiesPtr = new  AliHLTPHOSUtilities(); 
67
68   char *tmp = getenv("HOME");
69
70   if(tmp == 0)
71     {
72       //      cout << "ERROR, environment vriable HOME is not set" << endl;
73     }
74   else
75     {
76       //  sprintf(fHistoOutDir,"%s/rundir/output/histograms",tmp);
77       sprintf(fHistoOutDir,"%s/rundir/output/histograms/",tmp);
78     }
79   
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     {
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;
113    }
114   else
115     {
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;
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;
129
130   for(int gain=0; gain< NGAINS; gain++)
131     {
132       sprintf(tmpHistoName, "DeadChanneMap_Module%d_rcuz%d_rcux%d_gain%d",(int)fModuleID,  fRcuZ, fRcuX, gain);
133       fDeadChannelMapHistogramPtrs[gain] = new TH2D(tmpHistoName, tmpHistoName,  
134                                       NXCOLUMNSRCU , 0, NXCOLUMNSRCU , 
135                                       NZROWSRCU,         0, NZROWSRCU);
136       fDeadChannelMapHistogramPtrs[gain]->Reset(); 
137     }
138
139   for(int x = 0; x < NXCOLUMNSRCU; x ++)
140     {
141       for(int z = 0; z < NZROWSRCU; z ++)
142         {
143           for(int gain = 0; gain < NGAINS; gain ++)
144             {
145               geomx = x + NXCOLUMNSRCU*fRcuX;
146               geomz = z + NZROWSRCU*fRcuZ;
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;
153               sprintf(tmpHistoName, "Edistribution_%d_%d_%d_%d",(int)fModuleID,  geomx, geomz, gain);
154               fEnergyHistogramPtrs[x][z][gain] = new TH1F( tmpHistoName, tmpHistoName, NBINS, XBINLOW, XBINUP);
155               sprintf(tmpHistoName, "TOFdistribution_module%d_x%d_z%d_gain%d", (int)fModuleID,  geomx, geomz, gain);
156               fTimingHistogramPtrs[x][z][gain] = new TH1F(tmpHistoName , tmpHistoName, NBINS, XBINLOW, XBINUP);
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
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
198   for(int i = 0; i < size; i++)
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
223   for(int x = 0; x <  NXCOLUMNSRCU; x ++)
224     {
225       for(int z = 0; z < NZROWSRCU; z ++)
226         {
227           for(int gain = 0; gain < NGAINS; gain ++)
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
240   for(int x = 0; x < NXCOLUMNSRCU; x ++)
241     {
242       for(int z = 0; z < NZROWSRCU; z ++)
243         {
244           for(int gain = 0; gain < NGAINS; 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 <ALTROMAXSAMPLES;  i++)
256     {
257       fTmpChannelData[i] = 0;
258     }
259 }
260
261
262 void 
263 AliHLTPHOSRcuCalibrationProcessor::WriteAllHistograms(char *opt)
264 {
265   //comment
266   FillLiveChannelHistograms();
267   int runNumber = 0;
268   char tmpEFileName[256];
269   char tmpDeadFileName_gain0[256];
270   char tmpDeadFileName_gain1[256]; 
271   char runNumberFile[256]; 
272   char timeString[256];
273
274   /*
275   fUtilitiesPtr->ResetArray(runNumberFile, 256);
276   fUtilitiesPtr->ResetArray(tmpEFileName, 256);
277   fUtilitiesPtr->ResetArray(timeString, 256);
278   */
279
280   sprintf(runNumberFile, "%s/rundir/runNumber.txt", getenv("HOME"));
281
282   FILE *fp = fopen(runNumberFile, "r");
283   Int_t res = 0; //OD to get rid of warnings
284   if(fp == 0)
285     {
286       ScanTimeString(timeString);  
287       //      cout << "WARNING, could not find file "<< runNumberFile  <<endl;
288       //      cout <<"Filename will be stamped with data and time instead " << endl;
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     {
295       res = fscanf(fp, "%d", &runNumber);
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
302
303   TFile *energyHistoFile =  new TFile(tmpEFileName, opt);
304   if(!energyHistoFile) return;
305   if(!energyHistoFile->IsOpen()) return;
306
307   //  cout <<"printing histograms"<< endl;
308
309   for(int x = 0; x <  NXCOLUMNSRCU; x ++)
310     {
311       for(int z = 0; z < NZROWSRCU; z ++)
312         {
313           for(int gain = 0; gain < NGAINS; gain ++)
314             {
315               fEnergyHistogramPtrs[x][z][gain]->Write();
316             }
317         } 
318     }
319   energyHistoFile->Close();
320
321
322   //LOW GAIN
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();
328   //HIGH GAIN
329   TFile *deadHistoFile_gain1 =  new TFile(tmpDeadFileName_gain1, opt);
330   if(!deadHistoFile_gain1) return;
331   if(!deadHistoFile_gain1->IsOpen()) return;
332   fDeadChannelMapHistogramPtrs[1]->Write();
333   deadHistoFile_gain0->Close();
334   deadHistoFile_gain1->Close(); 
335   //  cout << "printing histograms, finished"<< endl;
336 }
337
338 void
339 AliHLTPHOSRcuCalibrationProcessor::ScanTimeString(char *timeString)
340 {
341   //comment
342   time_t timePtr;
343   tm *tmPtr;
344   time(&timePtr); 
345   tmPtr=localtime(&timePtr);
346   timeString=asctime(tmPtr);
347   char day[10];
348   char month[10];
349   int date;
350   int hour;
351   int min;
352   int sec;
353   int year;
354   sscanf(timeString, "%s %s %d %d:%d:%d %d\n", day, month, &date, &hour, &min, &sec, &year);
355 }