]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/PHOS/AliHLTPHOSBaselineAnalyzerComponent.cxx
Selectiv readout and writing to FXS (oystein)
[u/mrichter/AliRoot.git] / HLT / PHOS / AliHLTPHOSBaselineAnalyzerComponent.cxx
CommitLineData
5c6503dc 1
ab38011b 2/**************************************************************************
3 * This file is property of and copyright by the ALICE HLT Project *
4 * All rights reserved. *
5 * *
6 * Primary Authors: Oystein Djuvsland *
7 * *
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 **************************************************************************/
5c6503dc 16#include "AliHLTPHOSBaselineAnalyzerComponent.h"
17#include "AliHLTPHOSBaselineAnalyzer.h"
18#include "AliHLTPHOSRcuCellEnergyDataStruct.h"
19#include "AliHLTPHOSBaseline.h"
20#include "TTree.h"
21#include "TChain.h"
22#include "AliHLTPHOSProcessor.h"
23#include "TClonesArray.h"
24#include "TFile.h"
25//#include <direct.h>
26#include <sys/stat.h>
27#include <sys/types.h>
28
2374af72 29/**
30 * Class does baseline analysis
31 *
32 * @file AliHLTPHOSBaselineAnalyzerComponent.cxx
33 * @author Oystein Djuvsland
34 * @date
35 * @brief A baseline analyzer for PHOS HLT
36*/
37
38// see below for class documentation
39// or
40// refer to README to build package
41// or
42// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
43
5c6503dc 44const AliHLTComponentDataType AliHLTPHOSBaselineAnalyzerComponent::fgkInputDataTypes[]={kAliHLTVoidDataType,{0,"",""}};
45
46AliHLTPHOSBaselineAnalyzerComponent gAliHLTPHOSBaselineAnalyzerComponent;
47
48AliHLTPHOSBaselineAnalyzerComponent::AliHLTPHOSBaselineAnalyzerComponent() :
49 AliHLTPHOSProcessor(),
50 fBaselineAnalyzerPtr(0),
51 fTreePtr(0),
25b7f84c 52 fBaselineArrayPtr(0),
ab38011b 53 fEvCnt(0),
5c6503dc 54 fWriteInterval(100),
55 fFillInterval(100),
56 fFilename(0),
57 fDirectory(0),
58 fHistPath(0),
25b7f84c 59 fRunNb(0),
60 fCalculateAll(false)
5c6503dc 61{
2374af72 62 //See header file for documentation
5c6503dc 63}
64
65AliHLTPHOSBaselineAnalyzerComponent::~AliHLTPHOSBaselineAnalyzerComponent()
66{
2374af72 67 //See header file for documentation
5c6503dc 68}
69
ab38011b 70
71
5c6503dc 72int
73AliHLTPHOSBaselineAnalyzerComponent::Deinit()
74{
2374af72 75 //See header file for documentation
5c6503dc 76 fBaselineAnalyzerPtr->CalculateChannelsBaselineRMS();
77 char filename [50];
78 cout << "Writing files...";
ab38011b 79 sprintf(filename, "%s/run%d_baselineTree_%d.root", fDirectory, fRunNb,fEvCnt/fWriteInterval);
5c6503dc 80 fBaselineAnalyzerPtr->WriteAccumulatedBaselines(filename);
81 sprintf(filename, "%s/run%d_channelHistograms.root", fHistPath, fRunNb);
82 fBaselineAnalyzerPtr->WriteChannelHistograms(filename);
83 sprintf(filename, "%s/run%d_RMSHistogram.root", fHistPath, fRunNb);
84 fBaselineAnalyzerPtr->WriteRMSHistogram(filename);
85 cout << "Done!\n";
86
87 if(fCalculateAll)
88 {
89 CalculateAll();
90 }
91 if(fBaselineAnalyzerPtr)
92 {
93 delete fBaselineAnalyzerPtr;
94 fBaselineAnalyzerPtr = 0;
95 }
96 if(fTreePtr)
97 {
98 // delete fTreePtr;
99 fTreePtr = 0;
100 }
101 if(fFilename)
102 {
103 delete fFilename;
104 fFilename = 0;
105 }
52be7fb0 106 return 0;
5c6503dc 107}
108
109const char*
110AliHLTPHOSBaselineAnalyzerComponent::GetComponentID()
111{
2374af72 112 //See header file for documentation
5c6503dc 113 return "PhosBaselineAnalyzer";
114}
115
116void
117
118AliHLTPHOSBaselineAnalyzerComponent::GetInputDataTypes(vector<AliHLTComponentDataType>& list)
119{
120 //Get datatypes for input
121 const AliHLTComponentDataType* pType=fgkInputDataTypes;
122 while (pType->fID!=0) {
123 list.push_back(*pType);
124 pType++;
125 }
126}
127
128AliHLTComponentDataType
129AliHLTPHOSBaselineAnalyzerComponent::GetOutputDataType()
130{
2374af72 131 //See header file for documentation
25b7f84c 132 return AliHLTPHOSDefinitions::fgkBaselineDataType;
5c6503dc 133}
134
135
136void
137AliHLTPHOSBaselineAnalyzerComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
138{
2374af72 139 //See header file for documentation
5c6503dc 140 constBase = 30;
141 inputMultiplier = 1;
142}
143
144int
145AliHLTPHOSBaselineAnalyzerComponent::DoEvent(const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
1804b020 146 AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr, AliHLTUInt32_t& /*size*/, //TODO: I think that not setting the size explicitly to zero when returning from this method may be a subtle bug in this component. Please check.
147 std::vector<AliHLTComponentBlockData>& /*outputBlocks*/)
5c6503dc 148{
149 //Do event
150
1804b020 151 //UInt_t tSize = 0;
152 //UInt_t offset = 0;
153 //UInt_t mysize = 0;
154 //Int_t index = 0;
5c6503dc 155
1804b020 156 //Int_t fileCount = 0;
157 //Int_t digitCount = 0;
158 //char filename [50];
5c6503dc 159
160
161 AliHLTUInt8_t* outBPtr;
162 outBPtr = outputPtr;
163 const AliHLTComponentBlockData* iter = 0;
164 unsigned long ndx;
165
166 for( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
167 {
168 iter = blocks+ndx;
169
170 if(iter->fDataType != AliHLTPHOSDefinitions::fgkCellEnergyDataType)
171 {
172 // cout << "Warning: data type is not fgkCellEnergyDataType " << endl;
173 continue;
174
175 }
176 fBaselineAnalyzerPtr->CalculateRcuBaselines(reinterpret_cast<AliHLTPHOSRcuCellEnergyDataStruct*>(iter->fPtr));
177 }
178
ab38011b 179 fEvCnt++;
5c6503dc 180
181 //PushBack(fDigitArrayPtr, kAliHLTAnyDataType, (AliHLTUInt32_t)0);
182
ab38011b 183 if(fEvCnt % 10 == 0)
5c6503dc 184 {
ab38011b 185 cout << "Event #: " << fEvCnt << endl;
5c6503dc 186 }
187
ab38011b 188 if(fEvCnt % fFillInterval == 0)
5c6503dc 189 {
190 fBaselineAnalyzerPtr->FillTree();
191 }
ab38011b 192 if(fEvCnt % fWriteInterval == 0)
5c6503dc 193 {
194 char filename [50];
195 cout << "Writing file...";
ab38011b 196 sprintf(filename, "%s/run%d_baselineTree_%d.root", fDirectory, fRunNb,fEvCnt/fWriteInterval - 1);
5c6503dc 197 fBaselineAnalyzerPtr->WriteAccumulatedBaselines(filename);
198 cout << "Done!\n";
199 delete fTreePtr;
200 fTreePtr = new TTree("baselineTree", "Baselines");
201 fBaselineAnalyzerPtr->SetRootObjects(fTreePtr, fBaselineArrayPtr);
202 }
203
204 return 0;
205}
206
207
208int
209AliHLTPHOSBaselineAnalyzerComponent::DoInit(int argc, const char** argv )
210{
2374af72 211 //See header file for documentation
5c6503dc 212
213 Bool_t pathSet = false;
214 Bool_t histPathSet = false;
215 Bool_t nSamplesSet = false;
216
217
218 fFilename = new char[50];
219 fDirectory = new char[50];
220 fHistPath = new char[50];
221
222
223 fstream runNbFile;
224 //char dir [10];
225
1804b020 226 //Int_t newRunNb;
5c6503dc 227 runNbFile.open("/opt/HLT-public/rundir/runNumber.txt");
228 runNbFile >> fRunNb;
229 runNbFile.close();
230 /* newRunNb = fRunNb + 1;
231 runNbFile.open("/opt/HLT-public/rundir/runNumber.txt");
232 runNbFile << newRunNb;
233 runNbFile.close();*/
234
235 // sprintf(dir, "//tmp//phoshlt//aldaqpc019//hlt//data//baselines//run%d", fRunNb);
236 // if(mkdir(dir, 0777))
237 //{
238 // cerr << "WARNING! Could not create directory!\n";
239 //}
240
241 fBaselineAnalyzerPtr = new AliHLTPHOSBaselineAnalyzer();
242
243 fTreePtr = new TTree("baselineTree", "Baselines");
244 fBaselineArrayPtr = new TClonesArray("AliHLTPHOSBaseline",N_XCOLUMNS_MOD*N_ZROWS_MOD*N_GAINS);
245 fBaselineAnalyzerPtr->SetRootObjects(fTreePtr, fBaselineArrayPtr);
246 fBaselineAnalyzerPtr->SetMaxCrazyDifference(15);
247 fBaselineAnalyzerPtr->SetMaxSignal(120);
248
249 for(int i = 0; i < argc; i++)
250 {
251 if(!strcmp("-totalbaselineoutput", argv[i]))
252 {
253 fCalculateAll = true;
254 strcpy(fFilename, argv[i+1]);
255 }
256 if(!strcmp("-path", argv[i]))
257 {
258 strcpy(fDirectory, argv[i+1]);
259 pathSet = true;
260 }
261 if( !strcmp("-histpath", argv[i]))
262 {
263 strcpy(fHistPath, argv[i+1]);
264 histPathSet = true;
265 }
266 if(!strcmp("-nsamples", argv[i]))
267 {
268 fBaselineAnalyzerPtr->SetNumberOfSamples(atoi(argv[i+1]));
269 nSamplesSet = true;
270 }
271 if(!strcmp("-maxsignal", argv[i]))
272 {
273 fBaselineAnalyzerPtr->SetMaxSignal(atoi(argv[i+1]));
274 }
275 }
276
277
278 fWriteInterval = 100;
279 fFillInterval = 100;
280 if(fCalculateAll)
281 cout << "Path to total baseline file: " << fFilename << endl;
282 cout << endl << "Run number is: " << fRunNb << " -- Check that this is correct!!!\n";
283
284 return 0;
285}
286
287AliHLTComponent*
288AliHLTPHOSBaselineAnalyzerComponent::Spawn()
289{
2374af72 290 //See header file for documentation
5c6503dc 291 return new AliHLTPHOSBaselineAnalyzerComponent();
292}
293
294void
295AliHLTPHOSBaselineAnalyzerComponent::CalculateAll()
296{
2374af72 297 //See header file for documentation
5c6503dc 298 cout << "Calculating total baselines... \n";
299 AliHLTPHOSBaseline *baselineObject = 0;
300 TChain* chain = new TChain("baselineTree");
301 TTree* totalTree = new TTree("baselineTree", "Baselines");
302 TClonesArray* baselineArray = new TClonesArray("AliHLTPHOSBaseline", N_XCOLUMNS_MOD*N_ZROWS_MOD*N_GAINS);
303 TClonesArray* totalBaselineArray = new TClonesArray("AliHLTPHOSBaseline", N_XCOLUMNS_MOD*N_ZROWS_MOD*N_GAINS);
304
305 char filepath [50];
306
307 Float_t tmpBaselines[N_XCOLUMNS_MOD][N_ZROWS_MOD][N_GAINS][2];
308
1804b020 309 for(UInt_t x = 0; x < N_XCOLUMNS_MOD; x++)
5c6503dc 310 {
1804b020 311 for(UInt_t z = 0; z < N_ZROWS_MOD; z++)
5c6503dc 312 {
1804b020 313 for(UInt_t gain = 0; gain < N_GAINS; gain++)
5c6503dc 314 {
1804b020 315 for(UInt_t d = 0; d < 2; d++)
5c6503dc 316 {
317 tmpBaselines[x][z][gain][d] = 0;
318 }
319 }
320 }
321 }
322
323 sprintf(filepath, "%s/run%d*", fDirectory, fRunNb);
324 cout << "Adding files from: " << filepath << endl;
325 chain->Add(filepath);
326
327 cout << "Gives a total number of " << chain->GetEntries() << " events.\n";
328
329 chain->SetBranchAddress("Baselines", &baselineArray);
330 totalTree->Branch("Baselines", &totalBaselineArray);
331
332 Int_t nEntries = 0;
333 Int_t totEntries = 0;
334 Float_t baseline = 0;
335 Float_t oldBaseline = 0;
336
337 Int_t x = 0;
338 Int_t z = 0;
339 Int_t gain = 0;
340
341 for(int i = 0; i < chain->GetEntries(); i++)
342 {
343 chain->GetEntry(i);
344 for(int j = 0; j < baselineArray->GetEntriesFast(); j++)
345 {
346 baselineObject = (AliHLTPHOSBaseline*)baselineArray->At(j);
347 x = baselineObject->GetX();
348 z = baselineObject->GetZ();
349 gain = baselineObject->GetGain();
350 nEntries = baselineObject->GetEntries();
351 baseline = baselineObject->GetBaseline();
352 oldBaseline = tmpBaselines[x][z][gain][0];
353 totEntries = (Int_t)tmpBaselines[x][z][gain][1];
354 tmpBaselines[x][z][gain][0] = (oldBaseline*totEntries + baseline)/(totEntries + 1);
355 tmpBaselines[x][z][gain][1] = totEntries + 1;
356 }
357 }
358
359 Int_t n = 0;
360
1804b020 361 for(x = 0; x < (Int_t)N_XCOLUMNS_MOD; x++)
5c6503dc 362 {
1804b020 363 for(z = 0; z < (Int_t)N_ZROWS_MOD; z++)
5c6503dc 364 {
1804b020 365 for(gain = 0; gain < (Int_t)N_GAINS; gain++)
5c6503dc 366 {
367 baselineObject = (AliHLTPHOSBaseline*)totalBaselineArray->New(n);
368 baselineObject->SetBaseline(tmpBaselines[x][z][gain][0]);
369 baselineObject->SetX(x);
370 baselineObject->SetZ(z);
371 baselineObject->SetGain(gain);
372 if( tmpBaselines[x][z][gain][1] == 0)
373 {
374 cout << "Warning! Number of entries for x: " << x << " - z: " << z << " - gain: " << gain << " = 0\n"
375 << "Setting baseline to 40\n\n";
376 baselineObject->SetBaseline(40);
377 continue;
378 }
379 if( tmpBaselines[x][z][gain][1] == 0)
380 {
381 cout << "Warning! Number of entries for x: " << x << " - z: " << z << " - gain: " << gain << " = "
382 << tmpBaselines[x][z][gain][1] << endl;
383 }
1804b020 384 baselineObject->SetEntries( Int_t(tmpBaselines[x][z][gain][1]) );
5c6503dc 385 n++;
386 }
387 }
388 }
389
390 totalTree->Fill();
391
392 cout << "Writing to: " << fFilename << endl;
393 TFile *outfile = new TFile(fFilename,"recreate");
394 totalTree->Write();
395 outfile->Close();
396 cout << "Done!\n";
397
398}