1 /**************************************************************************
2 * Copyright(c) 2006, ALICE Experiment at CERN, All rights reserved. *
4 * Authors: Boris Polichtchouk & Per Thomas Hille for the ALICE *
5 * offline/HLT Project. Contributors are mentioned in the code where *
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 **************************************************************************/
17 #include "AliHLTPHOSRcuHistogramProducer.h"
19 #include "AliHLTPHOSRcuCellEnergyDataStruct.h"
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 **************************************************************************/
39 AliHLTPHOSRcuHistogramProducer:: AliHLTPHOSRcuHistogramProducer(): AliHLTPHOSBase(),
46 // cout << "WARNING: You cannot invoke the AliHLTPHOSRcuHistogramProducer without arguments" << endl;
47 // cout << "Usage AliHLTPHOSRcuHistogramProducer(ModuleID, X. Z)" << endl;
51 AliHLTPHOSRcuHistogramProducer::AliHLTPHOSRcuHistogramProducer(AliHLTUInt8_t moduleID, AliHLTUInt8_t rcuX, AliHLTUInt8_t rcuZ): AliHLTPHOSBase(),
58 //Se header file for documentation
59 char *tmp = getenv("HOME");
62 // cout << "ERROR, environment vriable HOME is not set" << endl;
66 // sprintf(fHistoOutDir,"%s/rundir/output/histograms",tmp);
67 sprintf(fHistoOutDir,"%s/rundir/output/histograms/",tmp);
73 AliHLTPHOSRcuHistogramProducer::~AliHLTPHOSRcuHistogramProducer()
80 AliHLTPHOSRcuHistogramProducer::SetHistoOutDir(char *outDir)
83 sprintf(fHistoOutDir,"%s", outDir);
87 AliHLTPHOSRcuHistogramProducer::SetDefaultHistoOutDir()
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");
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;
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;
113 AliHLTPHOSRcuHistogramProducer::Init()
115 //See header file for documentation
116 char tmpHistoName[256];
120 for(int gain=0; gain< N_GAINS; gain++)
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);
131 for(int x = 0; x < N_XCOLUMNS_RCU; x ++)
133 for(int z = 0; z < N_ZROWS_RCU; z ++)
135 for(int gain = 0; gain < N_GAINS; gain ++)
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);
149 // fTimingHistogramPtrs[x][z][gain] = 0;
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);
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;
170 AliHLTPHOSRcuHistogramProducer::FillEnergy(AliHLTUInt8_t x, AliHLTUInt8_t z, AliHLTUInt8_t gain, float energy)
173 fCellAccEnergy.fAccumulatedEnergies[x][z][gain] += energy;
174 fCellAccEnergy.fHits[x][z][gain] ++;
175 fEnergyHistogramPtrs[x][z][gain]->Fill(energy);
180 AliHLTPHOSRcuHistogramProducer::FillTime(AliHLTUInt8_t x, AliHLTUInt8_t z, AliHLTUInt8_t gain, float time)
182 //See header file for documentation
183 fTimingHistogramPtrs[x][z][gain]->Fill(time);
186 const AliHLTPHOSRcuCellAccumulatedEnergyDataStruct&
187 AliHLTPHOSRcuHistogramProducer::GetCellAccumulatedEnergies()
189 // return &fCellAccEnergy ;
190 return fCellAccEnergy ;
194 AliHLTPHOSRcuHistogramProducer::FillLiveChannels(Int_t data[], int size, Int_t x, Int_t z, Int_t gain)
197 for(Int_t i = 0; i < size; i++)
199 if(data[i] > THRESHOLD)
201 if(data[i+1] > THRESHOLD)
203 if(data[i+2] > THRESHOLD)
205 if(data[i+3] > THRESHOLD)
208 fCellAccEnergy.fDeadChannelMap[x][z][gain] = 10;
219 AliHLTPHOSRcuHistogramProducer::FillLiveChannelHistograms()
222 for(int x = 0; x < N_XCOLUMNS_RCU; x ++)
224 for(int z = 0; z < N_ZROWS_RCU; z ++)
226 for(int gain = 0; gain < N_GAINS; gain ++)
228 fDeadChannelMapHistogramPtrs[gain]->SetBinContent(x ,z , fCellAccEnergy.fDeadChannelMap[x][z][gain]);
237 AliHLTPHOSRcuHistogramProducer::Reset()
239 //See header file for documentation
240 for(int x = 0; x < N_XCOLUMNS_RCU; x ++)
242 for(int z = 0; z < N_ZROWS_RCU; z ++)
244 for(int gain = 0; gain < N_GAINS; 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 <ALTRO_MAX_SAMPLES; i++)
257 fTmpChannelData[i] = 0;
263 AliHLTPHOSRcuHistogramProducer::WriteAllHistograms(char *opt)
266 printf("\nAliHLTPHOSRcuHistogramProducer::WriteAllHistogram, opt = %s\n", opt);
268 FillLiveChannelHistograms();
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];
279 ResetArray(runNumberFile, 256);
280 ResetArray(tmpEFileName, 256);
281 ResetArray(timeString, 256);
284 sprintf(runNumberFile, "%s/rundir/runNumber.txt", getenv("HOME"));
286 FILE *fp = fopen(runNumberFile, "r");
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);
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);
305 // cout << "tmpEFileName = "<< tmpEFileName << endl;
307 TFile *energyHistoFile = new TFile(tmpEFileName, opt);
308 if(!energyHistoFile) return;
309 if(!energyHistoFile->IsOpen()) return;
311 // cout <<"printing histograms"<< endl;
313 for(int x = 0; x < N_XCOLUMNS_RCU; x ++)
315 for(int z = 0; z < N_ZROWS_RCU; z ++)
317 for(int gain = 0; gain < N_GAINS; gain ++)
319 // cout << "the number of entries is " <<fEnergyHistogramPtrs[x][z][gain]->GetEntries()<< endl;
320 fEnergyHistogramPtrs[x][z][gain]->Write();
324 energyHistoFile->Close();
328 //TFile *deadHistoFile_gain0 = new TFile(tmpDeadFileName_gain0,"update");
329 TFile *deadHistoFile_gain0 = new TFile(tmpDeadFileName_gain0, opt);
331 if(!deadHistoFile_gain0) return;
332 if(!deadHistoFile_gain0->IsOpen()) return;
333 fDeadChannelMapHistogramPtrs[0]->Write();
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();
344 deadHistoFile_gain0->Close();
345 deadHistoFile_gain1->Close();
347 // cout << "printing histograms, finished"<< endl;
351 AliHLTPHOSRcuHistogramProducer::ScanTimeString(char *timeString)
357 tmPtr=localtime(&timePtr);
358 timeString=asctime(tmPtr);
366 sscanf(timeString, "%s %s %d %d:%d:%d %d\n", day, month, &date, &hour, &min, &sec, &year);