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 "AliHLTPHOSRcuHistogramProducer.h"
21 //#include "AliHLTPHOSRcuCellEnergyDataStruct.h"
25 #include "AliHLTCaloUtilities.h"
32 /*************************************************************************
33 * Class AliHLTPHOSRcuHistogramProducer accumulating histograms *
34 * with amplitudes per PHOS channel *
35 * It is intended to run at the HLT farm *
36 * and it fills the histograms with amplitudes per channel. *
37 * Usage example see in PHOS/macros/Shuttle/AliPHOSCalibHistoProducer.C *
38 **************************************************************************/
41 AliHLTPHOSRcuHistogramProducer:: AliHLTPHOSRcuHistogramProducer(): // AliHLTPHOSBase(),
42 // AliHLTPHOSRcuProcessor(),
49 fUtilitiesPtr = new AliHLTPHOSUtilities;
52 // cout << "WARNING: You cannot invoke the AliHLTPHOSRcuHistogramProducer without arguments" << endl;
53 // cout << "Usage AliHLTPHOSRcuHistogramProducer(ModuleID, X. Z)" << endl;
57 AliHLTPHOSRcuHistogramProducer::AliHLTPHOSRcuHistogramProducer(AliHLTUInt8_t moduleID, AliHLTUInt8_t rcuX, AliHLTUInt8_t rcuZ): //AliHLTPHOSBase(),
58 // AliHLTPHOSRcuProcessor(),
66 //Se header file for documentation
67 fUtilitiesPtr = new AliHLTPHOSUtilities();
69 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 AliHLTPHOSRcuHistogramProducer::~AliHLTPHOSRcuHistogramProducer()
90 AliHLTPHOSRcuHistogramProducer::SetHistoOutDir(char *outDir)
93 sprintf(fHistoOutDir,"%s", outDir);
97 AliHLTPHOSRcuHistogramProducer::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 AliHLTPHOSRcuHistogramProducer::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 AliHLTPHOSRcuHistogramProducer::SetHistoOutDir(*char outdir)" << endl;
123 AliHLTPHOSRcuHistogramProducer::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, NBINS, XBINLOW, XBINUP);
134 fDeadChannelMapHistogramPtrs[gain] = new TH2D(tmpHistoName, tmpHistoName,
135 NXCOLUMNSRCU , 0, NXCOLUMNSRCU ,
136 NZROWSRCU, 0, NZROWSRCU);
137 fDeadChannelMapHistogramPtrs[gain]->Reset();
138 // fgCalibHistPtr[gain]->GetXaxis()->SetRange(128, 128 + 64);
141 for(int x = 0; x < NXCOLUMNSRCU; x ++)
143 for(int z = 0; z < NZROWSRCU; z ++)
145 for(int gain = 0; gain < NGAINS; gain ++)
147 geomx = x + NXCOLUMNSRCU*fRcuX;
148 geomz = z + NZROWSRCU*fRcuZ;
149 fEnergyAverageValues[x][z][gain] = 0;
150 fAccumulatedValues[x][z][gain] = 0;
151 fTimingAverageValues[x][z][gain] = 0;
152 fHits[x][z][gain] = 0;
153 fDeadChannelMap[x][z][gain] = 0;
154 sprintf(tmpHistoName, "Edistribution_%d_%d_%d_%d",(int)fModuleID, geomx, geomz, gain);
155 // fEnergyHistogramPtrs[x][z][gain] = 0;
156 fEnergyHistogramPtrs[x][z][gain] = new TH1F( tmpHistoName, tmpHistoName, NBINS, XBINLOW, XBINUP);
157 sprintf(tmpHistoName, "TOFdistribution_module%d_x%d_z%d_gain%d", (int)fModuleID, geomx, geomz, gain);
159 // fTimingHistogramPtrs[x][z][gain] = 0;
161 // sprintf(tmpHistoName, "DeadChanneMap_%d_%d_%d_%d",(int)fModuleID, geomx, geomz, gain);
162 // fDeadChannelMapHistogramPtrs[x][z][gain] = new TH1D( tmpHistoName, tmpHistoName, N_BINS, XBIN_LOW, XBIN_UP);
165 fTimingHistogramPtrs[x][z][gain] = new TH1F(tmpHistoName , tmpHistoName, NBINS, XBINLOW, XBINUP);
166 fCellAccEnergy.fAccumulatedEnergies[x][z][gain] = 0;
167 fCellAccEnergy.fHits[x][z][gain] = 0;
168 fCellAccEnergy.fDeadChannelMap[x][z][gain] = 0;
169 fCellAccEnergy.fModuleID = 0;
170 fCellAccEnergy.fRcuX = 0;
171 fCellAccEnergy.fRcuZ = 0;
180 AliHLTPHOSRcuHistogramProducer::FillEnergy(AliHLTUInt8_t x, AliHLTUInt8_t z, AliHLTUInt8_t gain, float energy)
183 fCellAccEnergy.fAccumulatedEnergies[x][z][gain] += energy;
184 fCellAccEnergy.fHits[x][z][gain] ++;
185 fEnergyHistogramPtrs[x][z][gain]->Fill(energy);
190 AliHLTPHOSRcuHistogramProducer::FillTime(AliHLTUInt8_t x, AliHLTUInt8_t z, AliHLTUInt8_t gain, float time)
192 //See header file for documentation
193 fTimingHistogramPtrs[x][z][gain]->Fill(time);
196 const AliHLTPHOSRcuCellAccumulatedEnergyDataStruct&
197 AliHLTPHOSRcuHistogramProducer::GetCellAccumulatedEnergies()
199 // return &fCellAccEnergy ;
200 return fCellAccEnergy ;
204 AliHLTPHOSRcuHistogramProducer::FillLiveChannels(Int_t data[], int size, Int_t x, Int_t z, Int_t gain)
207 for(Int_t i = 0; i < size; i++)
209 if(data[i] > THRESHOLD)
211 if(data[i+1] > THRESHOLD)
213 if(data[i+2] > THRESHOLD)
215 if(data[i+3] > THRESHOLD)
218 fCellAccEnergy.fDeadChannelMap[x][z][gain] = 10;
229 AliHLTPHOSRcuHistogramProducer::FillLiveChannelHistograms()
232 for(int x = 0; x < NXCOLUMNSRCU; x ++)
234 for(int z = 0; z < NZROWSRCU; z ++)
236 for(int gain = 0; gain < NGAINS; gain ++)
238 fDeadChannelMapHistogramPtrs[gain]->SetBinContent(x ,z , fCellAccEnergy.fDeadChannelMap[x][z][gain]);
247 AliHLTPHOSRcuHistogramProducer::Reset()
249 //See header file for documentation
250 for(int x = 0; x < NXCOLUMNSRCU; x ++)
252 for(int z = 0; z < NZROWSRCU; z ++)
254 for(int gain = 0; gain < NGAINS; gain ++)
256 fEnergyAverageValues[x][z][gain] = 0;
257 fAccumulatedValues[x][z][gain] = 0;
258 fTimingAverageValues[x][z][gain] = 0;
259 fHits[x][z][gain] = 0;
260 fDeadChannelMap[x][z][gain] = 0;
265 for(int i = 0; i <ALTROMAXSAMPLES; i++)
267 fTmpChannelData[i] = 0;
273 AliHLTPHOSRcuHistogramProducer::WriteAllHistograms(char *opt)
276 printf("\nAliHLTPHOSRcuHistogramProducer::WriteAllHistogram, opt = %s\n", opt);
278 FillLiveChannelHistograms();
282 char tmpEFileName[256];
283 char tmpDeadFileName_gain0[256];
284 char tmpDeadFileName_gain1[256];
285 // char *tmpRundir = getenv("HOME");
286 char runNumberFile[256];
287 char timeString[256];
289 fUtilitiesPtr->ResetArray(runNumberFile, 256);
290 fUtilitiesPtr->ResetArray(tmpEFileName, 256);
291 fUtilitiesPtr->ResetArray(timeString, 256);
294 sprintf(runNumberFile, "%s/rundir/runNumber.txt", getenv("HOME"));
296 FILE *fp = fopen(runNumberFile, "r");
298 Int_t res = 0; //OD to get rid of warnings
301 ScanTimeString(timeString);
302 // cout << "WARNING, could not find file "<< runNumberFile <<endl;
303 // cout <<"Filename will be stamped with data and time instead " << endl;
304 sprintf(tmpEFileName, "%s/Energy/EnergyHistograms_%s_mod%d_rcuZ%d_rcuX%d.root", fHistoOutDir, timeString, (int)fModuleID, (int)fRcuZ, (int)fRcuZ);
305 sprintf(tmpDeadFileName_gain0, "%s/DeadMap/DeadChannelHistograms_%s_mod%d_rcuZ%d_rcuX%d_LG.root", fHistoOutDir, timeString, (int)fModuleID, (int)fRcuZ, (int)fRcuZ);
306 sprintf(tmpDeadFileName_gain1, "%s/DeadMap/DeadChannelHistograms_%s_mod%d_rcuZ%d_rcuX%d_HG.root", fHistoOutDir, timeString, (int)fModuleID, (int)fRcuZ, (int)fRcuZ);
310 res = fscanf(fp, "%d", &runNumber);
311 sprintf(tmpEFileName, "%s/Energy/EnergyHisttograms_run%d_mod%d_rcuZ%d_rcuX%d.root", fHistoOutDir, runNumber, (int)fModuleID, (int)fRcuZ, (int)fRcuX);
312 sprintf(tmpDeadFileName_gain0, "%s/DeadMap/DeadChannleHistograms_run%d_mod%d_rcuZ%d_rcuX%d_LG.root", fHistoOutDir, runNumber, (int)fModuleID, (int)fRcuZ, (int)fRcuX);
313 sprintf(tmpDeadFileName_gain1, "%s/DeadMap/DeadChannleHistograms_run%d_mod%d_rcuZ%d_rcuX%d_HG.root", fHistoOutDir, runNumber, (int)fModuleID, (int)fRcuZ, (int)fRcuX);
317 // cout << "tmpEFileName = "<< tmpEFileName << endl;
319 TFile *energyHistoFile = new TFile(tmpEFileName, opt);
320 if(!energyHistoFile) return;
321 if(!energyHistoFile->IsOpen()) return;
323 // cout <<"printing histograms"<< endl;
325 for(int x = 0; x < NXCOLUMNSRCU; x ++)
327 for(int z = 0; z < NZROWSRCU; z ++)
329 for(int gain = 0; gain < NGAINS; gain ++)
331 // cout << "the number of entries is " <<fEnergyHistogramPtrs[x][z][gain]->GetEntries()<< endl;
332 fEnergyHistogramPtrs[x][z][gain]->Write();
336 energyHistoFile->Close();
340 //TFile *deadHistoFile_gain0 = new TFile(tmpDeadFileName_gain0,"update");
341 TFile *deadHistoFile_gain0 = new TFile(tmpDeadFileName_gain0, opt);
343 if(!deadHistoFile_gain0) return;
344 if(!deadHistoFile_gain0->IsOpen()) return;
345 fDeadChannelMapHistogramPtrs[0]->Write();
349 // TFile *deadHistoFile_gain1 = new TFile(tmpDeadFileName_gain1,"update");
350 TFile *deadHistoFile_gain1 = new TFile(tmpDeadFileName_gain1, opt);
351 if(!deadHistoFile_gain1) return;
352 if(!deadHistoFile_gain1->IsOpen()) return;
353 fDeadChannelMapHistogramPtrs[1]->Write();
356 deadHistoFile_gain0->Close();
357 deadHistoFile_gain1->Close();
359 // cout << "printing histograms, finished"<< endl;
363 AliHLTPHOSRcuHistogramProducer::ScanTimeString(char *timeString)
369 tmPtr=localtime(&timePtr);
370 timeString=asctime(tmPtr);
378 sscanf(timeString, "%s %s %d %d:%d:%d %d\n", day, month, &date, &hour, &min, &sec, &year);