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