3 /**************************************************************************
4 * Copyright(c) 2006, ALICE Experiment at CERN, All rights reserved. *
6 * Authors: Boris Polichtchouk & Per Thomas Hille for the ALICE *
7 * offline/HLT Project. Contributors are mentioned in the code where *
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 **************************************************************************/
19 #include "AliHLTPHOSRcuCalibrationProcessor.h"
21 #include "AliHLTPHOSRcuCellEnergyDataStruct.h"
25 //#include "AliHLTPHOSUtilities.h"
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 **************************************************************************/
42 AliHLTPHOSRcuCalibrationProcessor:: AliHLTPHOSRcuCalibrationProcessor(): AliHLTPHOSBase(),
51 // fUtilitiesPtr = new AliHLTPHOSUtilities();
53 // cout << "WARNING: You cannot invoke the AliHLTPHOSRcuCalibrationProcessor without arguments" << endl;
54 // cout << "Usage AliHLTPHOSRcuCalibrationProcessor(ModuleID, X. Z)" << endl;
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(),
65 //Se header file for documentation
66 // fUtilitiesPtr = new AliHLTPHOSUtilities();
68 char *tmp = getenv("HOME");
72 // cout << "ERROR, environment vriable HOME is not set" << endl;
76 // sprintf(fHistoOutDir,"%s/rundir/output/histograms",tmp);
77 sprintf(fHistoOutDir,"%s/rundir/output/histograms/",tmp);
83 AliHLTPHOSRcuCalibrationProcessor::~ AliHLTPHOSRcuCalibrationProcessor()
90 AliHLTPHOSRcuCalibrationProcessor::SetHistoOutDir(char *outDir)
93 sprintf(fHistoOutDir,"%s", outDir);
97 AliHLTPHOSRcuCalibrationProcessor::SetDefaultHistoOutDir()
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");
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;
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;
123 AliHLTPHOSRcuCalibrationProcessor::Init()
125 //See header file for documentation
126 char tmpHistoName[256];
130 for(int gain=0; gain< NGAINS; gain++)
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();
139 for(int x = 0; x < NXCOLUMNSRCU; x ++)
141 for(int z = 0; z < NZROWSRCU; z ++)
143 for(int gain = 0; gain < NGAINS; gain ++)
145 geomx = x + NXCOLUMNSRCU*fRcuX;
146 geomz = z + NZROWSRCU*fRcuZ;
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;
171 AliHLTPHOSRcuCalibrationProcessor::FillEnergy(AliHLTUInt8_t x, AliHLTUInt8_t z, AliHLTUInt8_t gain, float energy)
174 fCellAccEnergy.fAccumulatedEnergies[x][z][gain] += energy;
175 fCellAccEnergy.fHits[x][z][gain] ++;
176 fEnergyHistogramPtrs[x][z][gain]->Fill(energy);
181 AliHLTPHOSRcuCalibrationProcessor::FillTime(AliHLTUInt8_t x, AliHLTUInt8_t z, AliHLTUInt8_t gain, float time)
183 //See header file for documentation
184 fTimingHistogramPtrs[x][z][gain]->Fill(time);
187 const AliHLTPHOSRcuCellAccumulatedEnergyDataStruct&
188 AliHLTPHOSRcuCalibrationProcessor::GetCellAccumulatedEnergies()
190 // return &fCellAccEnergy ;
191 return fCellAccEnergy ;
195 AliHLTPHOSRcuCalibrationProcessor::FillLiveChannels(Int_t data[], int size, Int_t x, Int_t z, Int_t gain)
198 for(int i = 0; i < size; i++)
200 if(data[i] > THRESHOLD)
202 if(data[i+1] > THRESHOLD)
204 if(data[i+2] > THRESHOLD)
206 if(data[i+3] > THRESHOLD)
209 fCellAccEnergy.fDeadChannelMap[x][z][gain] = 10;
220 AliHLTPHOSRcuCalibrationProcessor::FillLiveChannelHistograms()
223 for(int x = 0; x < NXCOLUMNSRCU; x ++)
225 for(int z = 0; z < NZROWSRCU; z ++)
227 for(int gain = 0; gain < NGAINS; gain ++)
229 fDeadChannelMapHistogramPtrs[gain]->SetBinContent(x ,z , fCellAccEnergy.fDeadChannelMap[x][z][gain]);
237 AliHLTPHOSRcuCalibrationProcessor::Reset()
239 //See header file for documentation
240 for(int x = 0; x < NXCOLUMNSRCU; x ++)
242 for(int z = 0; z < NZROWSRCU; z ++)
244 for(int gain = 0; gain < NGAINS; gain ++)
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;
255 for(int i = 0; i <ALTROMAXSAMPLES; i++)
257 fTmpChannelData[i] = 0;
263 AliHLTPHOSRcuCalibrationProcessor::WriteAllHistograms(char *opt)
266 FillLiveChannelHistograms();
268 char tmpEFileName[256];
269 char tmpDeadFileName_gain0[256];
270 char tmpDeadFileName_gain1[256];
271 char runNumberFile[256];
272 char timeString[256];
275 fUtilitiesPtr->ResetArray(runNumberFile, 256);
276 fUtilitiesPtr->ResetArray(tmpEFileName, 256);
277 fUtilitiesPtr->ResetArray(timeString, 256);
280 sprintf(runNumberFile, "%s/rundir/runNumber.txt", getenv("HOME"));
282 FILE *fp = fopen(runNumberFile, "r");
283 Int_t res = 0; //OD to get rid of warnings
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);
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);
303 TFile *energyHistoFile = new TFile(tmpEFileName, opt);
304 if(!energyHistoFile) return;
305 if(!energyHistoFile->IsOpen()) return;
307 // cout <<"printing histograms"<< endl;
309 for(int x = 0; x < NXCOLUMNSRCU; x ++)
311 for(int z = 0; z < NZROWSRCU; z ++)
313 for(int gain = 0; gain < NGAINS; gain ++)
315 fEnergyHistogramPtrs[x][z][gain]->Write();
319 energyHistoFile->Close();
323 TFile *deadHistoFile_gain0 = new TFile(tmpDeadFileName_gain0, opt);
325 if(!deadHistoFile_gain0) return;
326 if(!deadHistoFile_gain0->IsOpen()) return;
327 fDeadChannelMapHistogramPtrs[0]->Write();
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;
339 AliHLTPHOSRcuCalibrationProcessor::ScanTimeString(char *timeString)
345 tmPtr=localtime(&timePtr);
346 timeString=asctime(tmPtr);
354 sscanf(timeString, "%s %s %d %d:%d:%d %d\n", day, month, &date, &hour, &min, &sec, &year);