3 #include "AliHLTPHOSBaselineAnalyzerComponent.h"
4 #include "AliHLTPHOSBaselineAnalyzer.h"
5 #include "AliHLTPHOSRcuCellEnergyDataStruct.h"
6 #include "AliHLTPHOSBaseline.h"
9 #include "AliHLTPHOSProcessor.h"
10 #include "TClonesArray.h"
14 #include <sys/types.h>
16 const AliHLTComponentDataType AliHLTPHOSBaselineAnalyzerComponent::fgkInputDataTypes[]={kAliHLTVoidDataType,{0,"",""}};
18 AliHLTPHOSBaselineAnalyzerComponent gAliHLTPHOSBaselineAnalyzerComponent;
20 AliHLTPHOSBaselineAnalyzerComponent::AliHLTPHOSBaselineAnalyzerComponent() :
21 AliHLTPHOSProcessor(),
22 fBaselineAnalyzerPtr(0),
35 AliHLTPHOSBaselineAnalyzerComponent::~AliHLTPHOSBaselineAnalyzerComponent()
40 AliHLTPHOSBaselineAnalyzerComponent::Deinit()
43 fBaselineAnalyzerPtr->CalculateChannelsBaselineRMS();
45 cout << "Writing files...";
46 sprintf(filename, "%s/run%d_baselineTree_%d.root", fDirectory, fRunNb,fEventCount/fWriteInterval);
47 fBaselineAnalyzerPtr->WriteAccumulatedBaselines(filename);
48 sprintf(filename, "%s/run%d_channelHistograms.root", fHistPath, fRunNb);
49 fBaselineAnalyzerPtr->WriteChannelHistograms(filename);
50 sprintf(filename, "%s/run%d_RMSHistogram.root", fHistPath, fRunNb);
51 fBaselineAnalyzerPtr->WriteRMSHistogram(filename);
58 if(fBaselineAnalyzerPtr)
60 delete fBaselineAnalyzerPtr;
61 fBaselineAnalyzerPtr = 0;
76 AliHLTPHOSBaselineAnalyzerComponent::GetComponentID()
78 return "PhosBaselineAnalyzer";
83 AliHLTPHOSBaselineAnalyzerComponent::GetInputDataTypes(vector<AliHLTComponentDataType>& list)
85 //Get datatypes for input
86 const AliHLTComponentDataType* pType=fgkInputDataTypes;
87 while (pType->fID!=0) {
88 list.push_back(*pType);
93 AliHLTComponentDataType
94 AliHLTPHOSBaselineAnalyzerComponent::GetOutputDataType()
96 return AliHLTPHOSDefinitions::fgkAliHLTBaselineDataType;
101 AliHLTPHOSBaselineAnalyzerComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
108 AliHLTPHOSBaselineAnalyzerComponent::DoEvent(const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
109 AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr, AliHLTUInt32_t& size,
110 std::vector<AliHLTComponentBlockData>& outputBlocks)
120 Int_t digitCount = 0;
124 AliHLTUInt8_t* outBPtr;
126 const AliHLTComponentBlockData* iter = 0;
129 for( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
133 if(iter->fDataType != AliHLTPHOSDefinitions::fgkCellEnergyDataType)
135 // cout << "Warning: data type is not fgkCellEnergyDataType " << endl;
139 fBaselineAnalyzerPtr->CalculateRcuBaselines(reinterpret_cast<AliHLTPHOSRcuCellEnergyDataStruct*>(iter->fPtr));
144 //PushBack(fDigitArrayPtr, kAliHLTAnyDataType, (AliHLTUInt32_t)0);
146 if(fEventCount % 10 == 0)
148 cout << "Event #: " << fEventCount << endl;
151 if(fEventCount % fFillInterval == 0)
153 fBaselineAnalyzerPtr->FillTree();
155 if(fEventCount % fWriteInterval == 0)
158 cout << "Writing file...";
159 sprintf(filename, "%s/run%d_baselineTree_%d.root", fDirectory, fRunNb,fEventCount/fWriteInterval - 1);
160 fBaselineAnalyzerPtr->WriteAccumulatedBaselines(filename);
163 fTreePtr = new TTree("baselineTree", "Baselines");
164 fBaselineAnalyzerPtr->SetRootObjects(fTreePtr, fBaselineArrayPtr);
172 AliHLTPHOSBaselineAnalyzerComponent::DoInit(int argc, const char** argv )
174 //Do initialization sprintf(fFilename, "/tmp/phoshlt/analysis/data/run%d/run%d_digitTree_%d.root", fRunNb,fRunNb,(fEventCount/fWriteInterval - 1));
176 Bool_t pathSet = false;
177 Bool_t histPathSet = false;
178 Bool_t nSamplesSet = false;
181 fFilename = new char[50];
182 fDirectory = new char[50];
183 fHistPath = new char[50];
190 runNbFile.open("/opt/HLT-public/rundir/runNumber.txt");
193 /* newRunNb = fRunNb + 1;
194 runNbFile.open("/opt/HLT-public/rundir/runNumber.txt");
195 runNbFile << newRunNb;
198 // sprintf(dir, "//tmp//phoshlt//aldaqpc019//hlt//data//baselines//run%d", fRunNb);
199 // if(mkdir(dir, 0777))
201 // cerr << "WARNING! Could not create directory!\n";
204 fBaselineAnalyzerPtr = new AliHLTPHOSBaselineAnalyzer();
206 fTreePtr = new TTree("baselineTree", "Baselines");
207 fBaselineArrayPtr = new TClonesArray("AliHLTPHOSBaseline",N_XCOLUMNS_MOD*N_ZROWS_MOD*N_GAINS);
208 fBaselineAnalyzerPtr->SetRootObjects(fTreePtr, fBaselineArrayPtr);
209 fBaselineAnalyzerPtr->SetMaxCrazyDifference(15);
210 fBaselineAnalyzerPtr->SetMaxSignal(120);
212 for(int i = 0; i < argc; i++)
214 if(!strcmp("-totalbaselineoutput", argv[i]))
216 fCalculateAll = true;
217 strcpy(fFilename, argv[i+1]);
219 if(!strcmp("-path", argv[i]))
221 strcpy(fDirectory, argv[i+1]);
224 if( !strcmp("-histpath", argv[i]))
226 strcpy(fHistPath, argv[i+1]);
229 if(!strcmp("-nsamples", argv[i]))
231 fBaselineAnalyzerPtr->SetNumberOfSamples(atoi(argv[i+1]));
234 if(!strcmp("-maxsignal", argv[i]))
236 fBaselineAnalyzerPtr->SetMaxSignal(atoi(argv[i+1]));
241 fWriteInterval = 100;
244 cout << "Path to total baseline file: " << fFilename << endl;
245 cout << endl << "Run number is: " << fRunNb << " -- Check that this is correct!!!\n";
251 AliHLTPHOSBaselineAnalyzerComponent::Spawn()
253 return new AliHLTPHOSBaselineAnalyzerComponent();
257 AliHLTPHOSBaselineAnalyzerComponent::CalculateAll()
260 cout << "Calculating total baselines... \n";
261 AliHLTPHOSBaseline *baselineObject = 0;
262 TChain* chain = new TChain("baselineTree");
263 TTree* totalTree = new TTree("baselineTree", "Baselines");
264 TClonesArray* baselineArray = new TClonesArray("AliHLTPHOSBaseline", N_XCOLUMNS_MOD*N_ZROWS_MOD*N_GAINS);
265 TClonesArray* totalBaselineArray = new TClonesArray("AliHLTPHOSBaseline", N_XCOLUMNS_MOD*N_ZROWS_MOD*N_GAINS);
269 Float_t tmpBaselines[N_XCOLUMNS_MOD][N_ZROWS_MOD][N_GAINS][2];
271 for(Int_t x = 0; x < N_XCOLUMNS_MOD; x++)
273 for(Int_t z = 0; z < N_ZROWS_MOD; z++)
275 for(Int_t gain = 0; gain < N_GAINS; gain++)
277 for(Int_t d = 0; d < 2; d++)
279 tmpBaselines[x][z][gain][d] = 0;
285 sprintf(filepath, "%s/run%d*", fDirectory, fRunNb);
286 cout << "Adding files from: " << filepath << endl;
287 chain->Add(filepath);
289 cout << "Gives a total number of " << chain->GetEntries() << " events.\n";
291 chain->SetBranchAddress("Baselines", &baselineArray);
292 totalTree->Branch("Baselines", &totalBaselineArray);
295 Int_t totEntries = 0;
296 Float_t baseline = 0;
297 Float_t oldBaseline = 0;
303 for(int i = 0; i < chain->GetEntries(); i++)
306 for(int j = 0; j < baselineArray->GetEntriesFast(); j++)
308 baselineObject = (AliHLTPHOSBaseline*)baselineArray->At(j);
309 x = baselineObject->GetX();
310 z = baselineObject->GetZ();
311 gain = baselineObject->GetGain();
312 nEntries = baselineObject->GetEntries();
313 baseline = baselineObject->GetBaseline();
314 oldBaseline = tmpBaselines[x][z][gain][0];
315 totEntries = (Int_t)tmpBaselines[x][z][gain][1];
316 tmpBaselines[x][z][gain][0] = (oldBaseline*totEntries + baseline)/(totEntries + 1);
317 tmpBaselines[x][z][gain][1] = totEntries + 1;
323 for(x = 0; x < N_XCOLUMNS_MOD; x++)
325 for(z = 0; z < N_ZROWS_MOD; z++)
327 for(gain = 0; gain < N_GAINS; gain++)
329 baselineObject = (AliHLTPHOSBaseline*)totalBaselineArray->New(n);
330 baselineObject->SetBaseline(tmpBaselines[x][z][gain][0]);
331 baselineObject->SetX(x);
332 baselineObject->SetZ(z);
333 baselineObject->SetGain(gain);
334 if( tmpBaselines[x][z][gain][1] == 0)
336 cout << "Warning! Number of entries for x: " << x << " - z: " << z << " - gain: " << gain << " = 0\n"
337 << "Setting baseline to 40\n\n";
338 baselineObject->SetBaseline(40);
341 if( tmpBaselines[x][z][gain][1] == 0)
343 cout << "Warning! Number of entries for x: " << x << " - z: " << z << " - gain: " << gain << " = "
344 << tmpBaselines[x][z][gain][1] << endl;
346 baselineObject->SetEntries(tmpBaselines[x][z][gain][1]);
354 cout << "Writing to: " << fFilename << endl;
355 TFile *outfile = new TFile(fFilename,"recreate");