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)
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];
121 for(unsigned int gain=0; gain< N_GAINS; gain++)
123 sprintf(tmpHistoName, "DeadChanneMap_Module%d_rcuz%d_rcux%d_gain%d",(int)fModuleID, fRcuZ, fRcuX, gain);
124 // fDeadChannelMapHistogramPtrs[gain] = new TH2D( tmpHistoName, tmpHistoName, N_BINS, XBIN_LOW, XBIN_UP);
127 fDeadChannelMapHistogramPtrs[gain] = new TH2D(tmpHistoName, tmpHistoName,
128 N_XCOLUMNS_RCU , 0, N_XCOLUMNS_RCU ,
129 N_ZROWS_RCU, 0, N_ZROWS_RCU);
130 fDeadChannelMapHistogramPtrs[gain]->Reset();
131 // fgCalibHistPtr[gain]->GetXaxis()->SetRange(128, 128 + 64);
138 for(unsigned int x = 0; x < N_XCOLUMNS_RCU; x ++)
140 for(unsigned int z = 0; z < N_ZROWS_RCU; z ++)
142 for(unsigned int gain = 0; gain < N_GAINS; gain ++)
144 geomx = x + N_XCOLUMNS_RCU*fRcuX;
145 geomz = z + N_ZROWS_RCU*fRcuZ;
147 fEnergyAverageValues[x][z][gain] = 0;
148 fAccumulatedValues[x][z][gain] = 0;
149 fTimingAverageValues[x][z][gain] = 0;
150 fHits[x][z][gain] = 0;
151 fDeadChannelMap[x][z][gain] = 0;
153 sprintf(tmpHistoName, "Edistribution_%d_%d_%d_%d",(int)fModuleID, geomx, geomz, gain);
154 // fEnergyHistogramPtrs[x][z][gain] = 0;
155 fEnergyHistogramPtrs[x][z][gain] = new TH1F( tmpHistoName, tmpHistoName, N_BINS, XBIN_LOW, XBIN_UP);
156 sprintf(tmpHistoName, "TOFdistribution_module%d_x%d_z%d_gain%d", (int)fModuleID, geomx, geomz, gain);
158 // fTimingHistogramPtrs[x][z][gain] = 0;
160 // sprintf(tmpHistoName, "DeadChanneMap_%d_%d_%d_%d",(int)fModuleID, geomx, geomz, gain);
161 // fDeadChannelMapHistogramPtrs[x][z][gain] = new TH1D( tmpHistoName, tmpHistoName, N_BINS, XBIN_LOW, XBIN_UP);
164 fTimingHistogramPtrs[x][z][gain] = new TH1F(tmpHistoName , tmpHistoName, N_BINS, XBIN_LOW, XBIN_UP);
165 fCellAccEnergy.fAccumulatedEnergies[x][z][gain] = 0;
166 fCellAccEnergy.fHits[x][z][gain] = 0;
167 fCellAccEnergy.fDeadChannelMap[x][z][gain] = 0;
168 fCellAccEnergy.fModuleID = 0;
169 fCellAccEnergy.fRcuX = 0;
170 fCellAccEnergy.fRcuZ = 0;
179 AliHLTPHOSRcuHistogramProducer::SetRcuX(AliHLTUInt8_t X)
181 //See header file for documentation
183 fCellAccEnergy.fRcuX = X;
189 AliHLTPHOSRcuHistogramProducer::SetRcuZ(AliHLTUInt8_t Z)
191 //See header file for documentation
193 fCellAccEnergy.fRcuZ = Z;
200 AliHLTPHOSRcuHistogramProducer::SetModuleID(AliHLTUInt8_t moduleID)
202 //See header file for documentation
203 fModuleID = moduleID;
208 AliHLTPHOSRcuHistogramProducer::FillEnergy(AliHLTUInt8_t x, AliHLTUInt8_t z, AliHLTUInt8_t gain, float energy)
211 fCellAccEnergy.fAccumulatedEnergies[x][z][gain] += energy;
212 fCellAccEnergy.fHits[x][z][gain] ++;
213 fEnergyHistogramPtrs[x][z][gain]->Fill(energy);
218 AliHLTPHOSRcuHistogramProducer::FillTime(AliHLTUInt8_t x, AliHLTUInt8_t z, AliHLTUInt8_t gain, float time)
220 //See header file for documentation
221 fTimingHistogramPtrs[x][z][gain]->Fill(time);
224 const AliHLTPHOSRcuCellAccumulatedEnergyDataStruct&
225 AliHLTPHOSRcuHistogramProducer::GetCellAccumulatedEnergies()
227 // return &fCellAccEnergy ;
228 return fCellAccEnergy ;
232 AliHLTPHOSRcuHistogramProducer::FillLiveChannels(Int_t data[], int size, Int_t x, Int_t z, Int_t gain)
235 for(Int_t i = 0; i < size; i++)
237 if(data[i] > THRESHOLD)
239 if(data[i+1] > THRESHOLD)
241 if(data[i+2] > THRESHOLD)
243 if(data[i+3] > THRESHOLD)
246 fCellAccEnergy.fDeadChannelMap[x][z][gain] = 10;
257 AliHLTPHOSRcuHistogramProducer::FillLiveChannelHistograms()
260 for(unsigned int x = 0; x < N_XCOLUMNS_RCU; x ++)
262 for(unsigned int z = 0; z < N_ZROWS_RCU; z ++)
264 for(unsigned int gain = 0; gain < N_GAINS; gain ++)
266 fDeadChannelMapHistogramPtrs[gain]->SetBinContent(x ,z , fCellAccEnergy.fDeadChannelMap[x][z][gain]);
274 AliHLTPHOSRcuHistogramProducer::Reset()
276 //See header file for documentation
277 for(unsigned int x = 0; x < N_XCOLUMNS_RCU; x ++)
279 for(unsigned int z = 0; z < N_ZROWS_RCU; z ++)
281 for(unsigned int gain = 0; gain < N_GAINS; gain ++)
283 fEnergyAverageValues[x][z][gain] = 0;
284 fAccumulatedValues[x][z][gain] = 0;
285 fTimingAverageValues[x][z][gain] = 0;
286 fHits[x][z][gain] = 0;
287 fDeadChannelMap[x][z][gain] = 0;
292 for(unsigned int i = 0; i <ALTRO_MAX_SAMPLES; i++)
294 fTmpChannelData[i] = 0;
300 AliHLTPHOSRcuHistogramProducer::WriteAllHistograms(char *opt)
303 printf("\nAliHLTPHOSRcuHistogramProducer::WriteAllHistogram, opt = %s\n", opt);
305 FillLiveChannelHistograms();
309 char tmpEFileName[256];
310 char tmpDeadFileName_gain0[256];
311 char tmpDeadFileName_gain1[256];
312 // char *tmpRundir = getenv("HOME");
313 char runNumberFile[256];
314 char timeString[256];
316 ResetArray(runNumberFile, 256);
317 ResetArray(tmpEFileName, 256);
318 ResetArray(timeString, 256);
321 sprintf(runNumberFile, "%s/rundir/runNumber.txt", getenv("HOME"));
323 FILE *fp = fopen(runNumberFile, "r");
326 ScanTimeString(timeString);
327 cout << "WARNING, could not find file "<< runNumberFile <<endl;
328 cout <<"Filename will be stamped with data and time instead " << endl;
329 sprintf(tmpEFileName, "%s/Energy/EnergyHistograms_%s_mod%d_rcuZ%d_rcuX%d.root", fHistoOutDir, timeString, (int)fModuleID, (int)fRcuZ, (int)fRcuZ);
330 sprintf(tmpDeadFileName_gain0, "%s/DeadMap/DeadChannelHistograms_%s_mod%d_rcuZ%d_rcuX%d_LG.root", fHistoOutDir, timeString, (int)fModuleID, (int)fRcuZ, (int)fRcuZ);
331 sprintf(tmpDeadFileName_gain1, "%s/DeadMap/DeadChannelHistograms_%s_mod%d_rcuZ%d_rcuX%d_HG.root", fHistoOutDir, timeString, (int)fModuleID, (int)fRcuZ, (int)fRcuZ);
335 fscanf(fp, "%d", &runNumber);
336 sprintf(tmpEFileName, "%s/Energy/EnergyHisttograms_run%d_mod%d_rcuZ%d_rcuX%d.root", fHistoOutDir, runNumber, (int)fModuleID, (int)fRcuZ, (int)fRcuX);
337 sprintf(tmpDeadFileName_gain0, "%s/DeadMap/DeadChannleHistograms_run%d_mod%d_rcuZ%d_rcuX%d_LG.root", fHistoOutDir, runNumber, (int)fModuleID, (int)fRcuZ, (int)fRcuX);
338 sprintf(tmpDeadFileName_gain1, "%s/DeadMap/DeadChannleHistograms_run%d_mod%d_rcuZ%d_rcuX%d_HG.root", fHistoOutDir, runNumber, (int)fModuleID, (int)fRcuZ, (int)fRcuX);
342 // cout << "tmpEFileName = "<< tmpEFileName <<endl;
343 // cout << "tmpDeadFileName_gain0 (low gain) = " << tmpDeadFileName_gain0 <<endl;
344 // cout << "tmpDeadFileName_gain1 (high gain) = " << tmpDeadFileName_gain1 <<endl;
346 // sprintf(tmpEFileName,"/home/aliphoshlt/rundir/outdata/calibHisto_%d_%d_%d.root", (int)fModuleID, (int)fRcuX, (int)fRcuZ);
349 // TFile *energyHistoFile = new TFile(tmpEFileName,"update");
350 // TFile *energyHistoFile = new TFile(tmpEFileName,"recreate");
351 // TFile *energyHistoFile = new TFile(tmpEFileName,"recreate");
353 cout << "tmpEFileName = "<< tmpEFileName << endl;
355 TFile *energyHistoFile = new TFile(tmpEFileName, opt);
356 if(!energyHistoFile) return;
357 if(!energyHistoFile->IsOpen()) return;
359 cout <<"printing histograms"<< endl;
361 for(unsigned int x = 0; x < N_XCOLUMNS_RCU; x ++)
363 for(unsigned int z = 0; z < N_ZROWS_RCU; z ++)
365 for(unsigned int gain = 0; gain < N_GAINS; gain ++)
367 // cout << "the number of entries is " <<fEnergyHistogramPtrs[x][z][gain]->GetEntries()<< endl;
368 fEnergyHistogramPtrs[x][z][gain]->Write();
372 energyHistoFile->Close();
376 //TFile *deadHistoFile_gain0 = new TFile(tmpDeadFileName_gain0,"update");
377 TFile *deadHistoFile_gain0 = new TFile(tmpDeadFileName_gain0, opt);
379 if(!deadHistoFile_gain0) return;
380 if(!deadHistoFile_gain0->IsOpen()) return;
381 fDeadChannelMapHistogramPtrs[0]->Write();
385 // TFile *deadHistoFile_gain1 = new TFile(tmpDeadFileName_gain1,"update");
386 TFile *deadHistoFile_gain1 = new TFile(tmpDeadFileName_gain1, opt);
387 if(!deadHistoFile_gain1) return;
388 if(!deadHistoFile_gain1->IsOpen()) return;
389 fDeadChannelMapHistogramPtrs[1]->Write();
392 deadHistoFile_gain0->Close();
393 deadHistoFile_gain1->Close();
395 cout << "printing histograms, finished"<< endl;
399 AliHLTPHOSRcuHistogramProducer::ScanTimeString(char *timeString)
406 tmPtr=localtime(&timePtr);
407 timeString=asctime(tmPtr);
408 // char tShort [strlen(timeString)+1];
421 sscanf(timeString, "%s %s %d %d:%d:%d %d\n", day, month, &date, &hour, &min, &sec, &year);