2 /**************************************************************************
3 * This file is property of and copyright by the ALICE HLT Project *
4 * All rights reserved. *
6 * Primary Authors: Oystein Djuvsland *
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 **************************************************************************/
16 #include "AliHLTPHOSBaselineAnalyzerComponent.h"
17 #include "AliHLTPHOSBaselineAnalyzer.h"
18 #include "AliHLTPHOSRcuCellEnergyDataStruct.h"
19 #include "AliHLTPHOSBaseline.h"
22 #include "AliHLTPHOSProcessor.h"
23 #include "TClonesArray.h"
27 #include <sys/types.h>
30 * Class does baseline analysis
32 * @file AliHLTPHOSBaselineAnalyzerComponent.cxx
33 * @author Oystein Djuvsland
35 * @brief A baseline analyzer for PHOS HLT
38 // see below for class documentation
40 // refer to README to build package
42 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
44 const AliHLTComponentDataType AliHLTPHOSBaselineAnalyzerComponent::fgkInputDataTypes[]={kAliHLTVoidDataType,{0,"",""}};
46 AliHLTPHOSBaselineAnalyzerComponent gAliHLTPHOSBaselineAnalyzerComponent;
48 AliHLTPHOSBaselineAnalyzerComponent::AliHLTPHOSBaselineAnalyzerComponent() :
49 AliHLTPHOSProcessor(),
50 fBaselineAnalyzerPtr(0),
62 //See header file for documentation
65 AliHLTPHOSBaselineAnalyzerComponent::~AliHLTPHOSBaselineAnalyzerComponent()
67 //See header file for documentation
73 AliHLTPHOSBaselineAnalyzerComponent::Deinit()
75 //See header file for documentation
76 fBaselineAnalyzerPtr->CalculateChannelsBaselineRMS();
78 cout << "Writing files...";
79 sprintf(filename, "%s/run%d_baselineTree_%d.root", fDirectory, fRunNb,fEvCnt/fWriteInterval);
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);
91 if(fBaselineAnalyzerPtr)
93 delete fBaselineAnalyzerPtr;
94 fBaselineAnalyzerPtr = 0;
110 AliHLTPHOSBaselineAnalyzerComponent::GetComponentID()
112 //See header file for documentation
113 return "PhosBaselineAnalyzer";
118 AliHLTPHOSBaselineAnalyzerComponent::GetInputDataTypes(vector<AliHLTComponentDataType>& list)
120 //Get datatypes for input
121 const AliHLTComponentDataType* pType=fgkInputDataTypes;
122 while (pType->fID!=0) {
123 list.push_back(*pType);
128 AliHLTComponentDataType
129 AliHLTPHOSBaselineAnalyzerComponent::GetOutputDataType()
131 //See header file for documentation
132 return AliHLTPHOSDefinitions::fgkBaselineDataType;
137 AliHLTPHOSBaselineAnalyzerComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
139 //See header file for documentation
145 AliHLTPHOSBaselineAnalyzerComponent::DoEvent(const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
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*/)
156 //Int_t fileCount = 0;
157 //Int_t digitCount = 0;
158 //char filename [50];
161 AliHLTUInt8_t* outBPtr;
163 const AliHLTComponentBlockData* iter = 0;
166 for( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
170 if(iter->fDataType != AliHLTPHOSDefinitions::fgkCellEnergyDataType)
172 // cout << "Warning: data type is not fgkCellEnergyDataType " << endl;
176 fBaselineAnalyzerPtr->CalculateRcuBaselines(reinterpret_cast<AliHLTPHOSRcuCellEnergyDataStruct*>(iter->fPtr));
181 //PushBack(fDigitArrayPtr, kAliHLTAnyDataType, (AliHLTUInt32_t)0);
185 cout << "Event #: " << fEvCnt << endl;
188 if(fEvCnt % fFillInterval == 0)
190 fBaselineAnalyzerPtr->FillTree();
192 if(fEvCnt % fWriteInterval == 0)
195 cout << "Writing file...";
196 sprintf(filename, "%s/run%d_baselineTree_%d.root", fDirectory, fRunNb,fEvCnt/fWriteInterval - 1);
197 fBaselineAnalyzerPtr->WriteAccumulatedBaselines(filename);
200 fTreePtr = new TTree("baselineTree", "Baselines");
201 fBaselineAnalyzerPtr->SetRootObjects(fTreePtr, fBaselineArrayPtr);
209 AliHLTPHOSBaselineAnalyzerComponent::DoInit(int argc, const char** argv )
211 //See header file for documentation
213 Bool_t pathSet = false;
214 Bool_t histPathSet = false;
215 Bool_t nSamplesSet = false;
218 fFilename = new char[50];
219 fDirectory = new char[50];
220 fHistPath = new char[50];
227 runNbFile.open("/opt/HLT-public/rundir/runNumber.txt");
230 /* newRunNb = fRunNb + 1;
231 runNbFile.open("/opt/HLT-public/rundir/runNumber.txt");
232 runNbFile << newRunNb;
235 // sprintf(dir, "//tmp//phoshlt//aldaqpc019//hlt//data//baselines//run%d", fRunNb);
236 // if(mkdir(dir, 0777))
238 // cerr << "WARNING! Could not create directory!\n";
241 fBaselineAnalyzerPtr = new AliHLTPHOSBaselineAnalyzer();
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);
249 for(int i = 0; i < argc; i++)
251 if(!strcmp("-totalbaselineoutput", argv[i]))
253 fCalculateAll = true;
254 strcpy(fFilename, argv[i+1]);
256 if(!strcmp("-path", argv[i]))
258 strcpy(fDirectory, argv[i+1]);
261 if( !strcmp("-histpath", argv[i]))
263 strcpy(fHistPath, argv[i+1]);
266 if(!strcmp("-nsamples", argv[i]))
268 fBaselineAnalyzerPtr->SetNumberOfSamples(atoi(argv[i+1]));
271 if(!strcmp("-maxsignal", argv[i]))
273 fBaselineAnalyzerPtr->SetMaxSignal(atoi(argv[i+1]));
278 fWriteInterval = 100;
281 cout << "Path to total baseline file: " << fFilename << endl;
282 cout << endl << "Run number is: " << fRunNb << " -- Check that this is correct!!!\n";
288 AliHLTPHOSBaselineAnalyzerComponent::Spawn()
290 //See header file for documentation
291 return new AliHLTPHOSBaselineAnalyzerComponent();
295 AliHLTPHOSBaselineAnalyzerComponent::CalculateAll()
297 //See header file for documentation
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);
307 Float_t tmpBaselines[N_XCOLUMNS_MOD][N_ZROWS_MOD][N_GAINS][2];
309 for(UInt_t x = 0; x < N_XCOLUMNS_MOD; x++)
311 for(UInt_t z = 0; z < N_ZROWS_MOD; z++)
313 for(UInt_t gain = 0; gain < N_GAINS; gain++)
315 for(UInt_t d = 0; d < 2; d++)
317 tmpBaselines[x][z][gain][d] = 0;
323 sprintf(filepath, "%s/run%d*", fDirectory, fRunNb);
324 cout << "Adding files from: " << filepath << endl;
325 chain->Add(filepath);
327 cout << "Gives a total number of " << chain->GetEntries() << " events.\n";
329 chain->SetBranchAddress("Baselines", &baselineArray);
330 totalTree->Branch("Baselines", &totalBaselineArray);
333 Int_t totEntries = 0;
334 Float_t baseline = 0;
335 Float_t oldBaseline = 0;
341 for(int i = 0; i < chain->GetEntries(); i++)
344 for(int j = 0; j < baselineArray->GetEntriesFast(); j++)
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;
361 for(x = 0; x < (Int_t)N_XCOLUMNS_MOD; x++)
363 for(z = 0; z < (Int_t)N_ZROWS_MOD; z++)
365 for(gain = 0; gain < (Int_t)N_GAINS; gain++)
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)
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);
379 if( tmpBaselines[x][z][gain][1] == 0)
381 cout << "Warning! Number of entries for x: " << x << " - z: " << z << " - gain: " << gain << " = "
382 << tmpBaselines[x][z][gain][1] << endl;
384 baselineObject->SetEntries( Int_t(tmpBaselines[x][z][gain][1]) );
392 cout << "Writing to: " << fFilename << endl;
393 TFile *outfile = new TFile(fFilename,"recreate");