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