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"
29 /*************************************************************************
30 * Class AliHLTPHOSRcuHistogramProducer accumulating histograms *
31 * with amplitudes per PHOS channel *
32 * It is intended to run at the HLT farm *
33 * and it fills the histograms with amplitudes per channel. *
34 * Usage example see in PHOS/macros/Shuttle/AliPHOSCalibHistoProducer.C *
35 **************************************************************************/
38 AliHLTPHOSRcuHistogramProducer:: AliHLTPHOSRcuHistogramProducer(): AliHLTPHOSBase(), fModuleID(0), fRcuX(0), fRcuZ(0)
40 //AliHLTPHOSRcuHistogramProducer:: AliHLTPHOSRcuHistogramProducer(): AliHLTPHOSRcuProcessor(), fModuleID(0), fRcuX(0), fRcuZ(0)
43 cout << "WARNING: You cannot invoke the AliHLTPHOSRcuHistogramProducer without arguments" << endl;
44 cout << "Usage AliHLTPHOSRcuHistogramProducer(ModuleID, X. Z)" << endl;
47 //AliHLTPHOSRcuHistogramProducer::AliHLTPHOSRcuHistogramProducer(AliHLTUInt8_t moduleID, AliHLTUInt8_t rcuX, AliHLTUInt8_t rcuZ)
48 AliHLTPHOSRcuHistogramProducer::AliHLTPHOSRcuHistogramProducer(AliHLTUInt8_t moduleID, AliHLTUInt8_t rcuX, AliHLTUInt8_t rcuZ)
50 //Se header file for documentation
51 // char *tmp = getenv("ALIHLT_BASEDIR");
52 char *tmp = getenv("HOME");
56 cout << "ERROR, environment vriable HOME is not set" << endl;
62 // sprintf(fHistoOutDir,"%s/rundir/output/histograms",tmp);
63 sprintf(fHistoOutDir,"%s/rundir/output/histograms/",tmp);
67 SetModuleID(moduleID);
73 AliHLTPHOSRcuHistogramProducer::~ AliHLTPHOSRcuHistogramProducer()
80 AliHLTPHOSRcuHistogramProducer::SetHistoOutDir(char *outDir)
82 sprintf(fHistoOutDir,"%s", outDir);
86 AliHLTPHOSRcuHistogramProducer::SetDefaultHistoOutDir()
88 char *tmp = getenv("HOME/rundir");
89 sprintf(fHistoOutDir,"%s/rundir/output/histograms", tmp);
90 //testing wether or not directry exist
91 FILE *fp = fopen(fHistoOutDir, "w");
95 cout << "ERROR, directory =" << fHistoOutDir << " Doesnt exist, or you don have write permissions to the directory" << endl;
96 cout << "WARNING: Histograms will not bew written to files at end of run unless a valid directory is set" << endl;
97 cout << "INFO, You must either" << endl;
98 cout << "1) Create the directory " << fHistoOutDir << "Manually" <<endl;
100 cout << "2) Se a valid output directory with the function AliHLTPHOSRcuHistogramProducer::SetHistoOutDir(*char outdir) "<< endl;
104 cout << "INFO: Output ddirectory for Histograms was set tot" << fHistoOutDir << endl;
105 cout << "INFO: if you want another output directory use the AliHLTPHOSRcuHistogramProducer::SetHistoOutDir(*char outdir)" << endl;
111 AliHLTPHOSRcuHistogramProducer::Init()
113 //See header file for documentation
114 char tmpHistoName[256];
119 for(int gain=0; gain< N_GAINS; gain++)
121 sprintf(tmpHistoName, "DeadChanneMap_Module%d_rcuz%d_rcux%d_gain%d",(int)fModuleID, fRcuZ, fRcuX, gain);
122 // fDeadChannelMapHistogramPtrs[gain] = new TH2D( tmpHistoName, tmpHistoName, N_BINS, XBIN_LOW, XBIN_UP);
125 fDeadChannelMapHistogramPtrs[gain] = new TH2D(tmpHistoName, tmpHistoName,
126 N_XCOLUMNS_RCU , 0, N_XCOLUMNS_RCU ,
127 N_ZROWS_RCU, 0, N_ZROWS_RCU);
128 fDeadChannelMapHistogramPtrs[gain]->Reset();
129 // fgCalibHistPtr[gain]->GetXaxis()->SetRange(128, 128 + 64);
136 for(int x = 0; x < N_XCOLUMNS_RCU; x ++)
138 for(int z = 0; z < N_ZROWS_RCU; z ++)
140 for(int gain = 0; gain < N_GAINS; gain ++)
142 geomx = x + N_XCOLUMNS_RCU*fRcuX;
143 geomz = z + N_ZROWS_RCU*fRcuZ;
145 fEnergyAverageValues[x][z][gain] = 0;
146 fAccumulatedValues[x][z][gain] = 0;
147 fTimingAverageValues[x][z][gain] = 0;
148 fHits[x][z][gain] = 0;
149 fDeadChannelMap[x][z][gain] = 0;
151 sprintf(tmpHistoName, "Edistribution_%d_%d_%d_%d",(int)fModuleID, geomx, geomz, gain);
152 // fEnergyHistogramPtrs[x][z][gain] = 0;
153 fEnergyHistogramPtrs[x][z][gain] = new TH1F( tmpHistoName, tmpHistoName, N_BINS, XBIN_LOW, XBIN_UP);
154 sprintf(tmpHistoName, "TOFdistribution_module%d_x%d_z%d_gain%d", (int)fModuleID, geomx, geomz, gain);
156 // fTimingHistogramPtrs[x][z][gain] = 0;
158 // sprintf(tmpHistoName, "DeadChanneMap_%d_%d_%d_%d",(int)fModuleID, geomx, geomz, gain);
159 // fDeadChannelMapHistogramPtrs[x][z][gain] = new TH1D( tmpHistoName, tmpHistoName, N_BINS, XBIN_LOW, XBIN_UP);
162 fTimingHistogramPtrs[x][z][gain] = new TH1F(tmpHistoName , tmpHistoName, N_BINS, XBIN_LOW, XBIN_UP);
163 fCellAccEnergy.fAccumulatedEnergies[x][z][gain] = 0;
164 fCellAccEnergy.fHits[x][z][gain] = 0;
165 fCellAccEnergy.fDeadChannelMap[x][z][gain] = 0;
166 fCellAccEnergy.fModuleID = 0;
167 fCellAccEnergy.fRcuX = 0;
168 fCellAccEnergy.fRcuZ = 0;
177 AliHLTPHOSRcuHistogramProducer::SetRcuX(AliHLTUInt8_t X)
179 //See header file for documentation
181 fCellAccEnergy.fRcuX = X;
187 AliHLTPHOSRcuHistogramProducer::SetRcuZ(AliHLTUInt8_t Z)
189 //See header file for documentation
191 fCellAccEnergy.fRcuZ = Z;
198 AliHLTPHOSRcuHistogramProducer::SetModuleID(AliHLTUInt8_t moduleID)
200 //See header file for documentation
201 fModuleID = moduleID;
206 AliHLTPHOSRcuHistogramProducer::FillEnergy(AliHLTUInt8_t x, AliHLTUInt8_t z, AliHLTUInt8_t gain, float energy)
208 fCellAccEnergy.fAccumulatedEnergies[x][z][gain] += energy;
209 fCellAccEnergy.fHits[x][z][gain] ++;
210 fEnergyHistogramPtrs[x][z][gain]->Fill(energy);
215 AliHLTPHOSRcuHistogramProducer::FillTime(AliHLTUInt8_t x, AliHLTUInt8_t z, AliHLTUInt8_t gain, float time)
217 //See header file for documentation
218 fTimingHistogramPtrs[x][z][gain]->Fill(time);
221 const AliHLTPHOSRcuCellAccumulatedEnergyDataStruct&
222 AliHLTPHOSRcuHistogramProducer::GetCellAccumulatedEnergies()
224 // return &fCellAccEnergy ;
225 return fCellAccEnergy ;
229 AliHLTPHOSRcuHistogramProducer::FillLiveChannels(Int_t data[], int size, Int_t x, Int_t z, Int_t gain)
231 for(Int_t i = 0; i < size; i++)
233 if(data[i] > THRESHOLD)
235 if(data[i+1] > THRESHOLD)
237 if(data[i+2] > THRESHOLD)
239 if(data[i+3] > THRESHOLD)
242 fCellAccEnergy.fDeadChannelMap[x][z][gain] = 10;
253 AliHLTPHOSRcuHistogramProducer::FillLiveChannelHistograms()
255 for(int x = 0; x < N_XCOLUMNS_RCU; x ++)
257 for(int z = 0; z < N_ZROWS_RCU; z ++)
259 for(int gain = 0; gain < N_GAINS; gain ++)
261 fDeadChannelMapHistogramPtrs[gain]->SetBinContent(x ,z , fCellAccEnergy.fDeadChannelMap[x][z][gain]);
269 AliHLTPHOSRcuHistogramProducer::Reset()
271 //See header file for documentation
272 for(int x = 0; x < N_XCOLUMNS_RCU; x ++)
274 for(int z = 0; z < N_ZROWS_RCU; z ++)
276 for(int gain = 0; gain < N_GAINS; gain ++)
278 fEnergyAverageValues[x][z][gain] = 0;
279 fAccumulatedValues[x][z][gain] = 0;
280 fTimingAverageValues[x][z][gain] = 0;
281 fHits[x][z][gain] = 0;
282 fDeadChannelMap[x][z][gain] = 0;
287 for(int i = 0; i <ALTRO_MAX_SAMPLES; i++)
289 fTmpChannelData[i] = 0;
295 AliHLTPHOSRcuHistogramProducer::WriteAllHistograms(char *opt)
297 printf("\nAliHLTPHOSRcuHistogramProducer::WriteAllHistogram, opt = %s\n", opt);
299 FillLiveChannelHistograms();
303 char tmpEFileName[256];
304 char tmpDeadFileName_gain0[256];
305 char tmpDeadFileName_gain1[256];
306 // char *tmpRundir = getenv("HOME");
307 char runNumberFile[256];
308 char timeString[256];
310 ResetArray(runNumberFile, 256);
311 ResetArray(tmpEFileName, 256);
312 ResetArray(timeString, 256);
315 sprintf(runNumberFile, "%s/rundir/runNumber.txt", getenv("HOME"));
317 FILE *fp = fopen(runNumberFile, "r");
320 ScanTimeString(timeString);
321 cout << "WARNING, could not find file "<< runNumberFile <<endl;
322 cout <<"Filename will be stamped with data and time instead " << endl;
323 sprintf(tmpEFileName, "%s/Energy/EnergyHistograms_%s_mod%d_rcuZ%d_rcuX%d.root", fHistoOutDir, timeString, (int)fModuleID, (int)fRcuZ, (int)fRcuZ);
324 sprintf(tmpDeadFileName_gain0, "%s/DeadMap/DeadChannelHistograms_%s_mod%d_rcuZ%d_rcuX%d_LG.root", fHistoOutDir, timeString, (int)fModuleID, (int)fRcuZ, (int)fRcuZ);
325 sprintf(tmpDeadFileName_gain1, "%s/DeadMap/DeadChannelHistograms_%s_mod%d_rcuZ%d_rcuX%d_HG.root", fHistoOutDir, timeString, (int)fModuleID, (int)fRcuZ, (int)fRcuZ);
329 fscanf(fp, "%d", &runNumber);
330 sprintf(tmpEFileName, "%s/Energy/EnergyHisttograms_run%d_mod%d_rcuZ%d_rcuX%d.root", fHistoOutDir, runNumber, (int)fModuleID, (int)fRcuZ, (int)fRcuX);
331 sprintf(tmpDeadFileName_gain0, "%s/DeadMap/DeadChannleHistograms_run%d_mod%d_rcuZ%d_rcuX%d_LG.root", fHistoOutDir, runNumber, (int)fModuleID, (int)fRcuZ, (int)fRcuX);
332 sprintf(tmpDeadFileName_gain1, "%s/DeadMap/DeadChannleHistograms_run%d_mod%d_rcuZ%d_rcuX%d_HG.root", fHistoOutDir, runNumber, (int)fModuleID, (int)fRcuZ, (int)fRcuX);
336 // cout << "tmpEFileName = "<< tmpEFileName <<endl;
337 // cout << "tmpDeadFileName_gain0 (low gain) = " << tmpDeadFileName_gain0 <<endl;
338 // cout << "tmpDeadFileName_gain1 (high gain) = " << tmpDeadFileName_gain1 <<endl;
340 // sprintf(tmpEFileName,"/home/aliphoshlt/rundir/outdata/calibHisto_%d_%d_%d.root", (int)fModuleID, (int)fRcuX, (int)fRcuZ);
343 // TFile *energyHistoFile = new TFile(tmpEFileName,"update");
344 // TFile *energyHistoFile = new TFile(tmpEFileName,"recreate");
345 // TFile *energyHistoFile = new TFile(tmpEFileName,"recreate");
347 cout << "tmpEFileName = "<< tmpEFileName << endl;
349 TFile *energyHistoFile = new TFile(tmpEFileName, opt);
350 if(!energyHistoFile) return;
351 if(!energyHistoFile->IsOpen()) return;
353 cout <<"printing histograms"<< endl;
355 for(int x = 0; x < N_XCOLUMNS_RCU; x ++)
357 for(int z = 0; z < N_ZROWS_RCU; z ++)
359 for(int gain = 0; gain < N_GAINS; gain ++)
361 // cout << "the number of entries is " <<fEnergyHistogramPtrs[x][z][gain]->GetEntries()<< endl;
362 fEnergyHistogramPtrs[x][z][gain]->Write();
366 energyHistoFile->Close();
370 //TFile *deadHistoFile_gain0 = new TFile(tmpDeadFileName_gain0,"update");
371 TFile *deadHistoFile_gain0 = new TFile(tmpDeadFileName_gain0, opt);
373 if(!deadHistoFile_gain0) return;
374 if(!deadHistoFile_gain0->IsOpen()) return;
375 fDeadChannelMapHistogramPtrs[0]->Write();
379 // TFile *deadHistoFile_gain1 = new TFile(tmpDeadFileName_gain1,"update");
380 TFile *deadHistoFile_gain1 = new TFile(tmpDeadFileName_gain1, opt);
381 if(!deadHistoFile_gain1) return;
382 if(!deadHistoFile_gain1->IsOpen()) return;
383 fDeadChannelMapHistogramPtrs[1]->Write();
386 deadHistoFile_gain0->Close();
387 deadHistoFile_gain1->Close();
389 cout << "printing histograms, finished"<< endl;
393 AliHLTPHOSRcuHistogramProducer::ScanTimeString(char *timeString)
399 tmPtr=localtime(&timePtr);
400 timeString=asctime(tmPtr);
401 char tShort [strlen(timeString)+1];
414 sscanf(timeString, "%s %s %d %d:%d:%d %d\n", day, month, &date, &hour, &min, &sec, &year);