1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 // Objects of this class contain info on time-dependent corrections
26 #include "AliEMCALCalibTimeDepCorrection.h"
30 ClassImp(AliEMCALCalibTimeDepCorrection)
32 //____________________________________________________________________________
33 AliEMCALCalibTimeDepCorrection::AliEMCALCalibTimeDepCorrection(const int nSM) :
40 //Default constructor.
41 for (int i=0; i<fNSuperModule; i++) {
42 fSuperModuleData.Add(new AliEMCALSuperModuleCalibTimeDepCorrection(i));
44 fSuperModuleData.Compress(); // compress the TObjArray
47 //____________________________________________________________________________
48 void AliEMCALCalibTimeDepCorrection::InitCorrection(Int_t nSM, Int_t nBins, Float_t val)
50 // This methods assumes that you are using SuperModules 0..nSM-1
53 Int_t iSM = 0; // SuperModule index
57 Float_t correction = val;
59 Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
61 for (Int_t i = 0; i < fNSuperModule; i++) {
62 AliEMCALSuperModuleCalibTimeDepCorrection * t = (AliEMCALSuperModuleCalibTimeDepCorrection*) fSuperModuleData[i];
64 t->SetSuperModuleNum(iSM); // assume SMs are coming in order
66 for (Int_t j=0; j<nAPDPerSM; j++) {
67 iCol = j / AliEMCALGeoParams::fgkEMCALRows;
68 iRow = j % AliEMCALGeoParams::fgkEMCALRows;
71 t->GetCorrection(iCol,iRow)->Set(nCorr);
72 for (Int_t k=0; k<nCorr; k++) {
74 t->GetCorrection(iCol,iRow)->AddAt(correction, k); // AddAt = SetAt..
83 //____________________________________________________________________________
84 void AliEMCALCalibTimeDepCorrection::SetCorrection(Int_t supModIndex, Int_t iCol, Int_t iRow, Int_t iBin, Float_t val)
85 { // if you call for non-existing data, there may be a crash..
86 ((AliEMCALSuperModuleCalibTimeDepCorrection*)fSuperModuleData[supModIndex])->GetCorrection(iCol,iRow)->AddAt(val, iBin); // AddAt = SetAt..
90 //____________________________________________________________________________
91 Float_t AliEMCALCalibTimeDepCorrection::GetCorrection(Int_t supModIndex, Int_t iCol, Int_t iRow, Int_t iBin) const
92 { // if you call for non-existing data, there may be a crash..
93 return ((AliEMCALSuperModuleCalibTimeDepCorrection*)fSuperModuleData[supModIndex])->GetCorrection(iCol,iRow)->At(iBin);
96 //____________________________________________________________________________
97 void AliEMCALCalibTimeDepCorrection::ReadTextInfo(Int_t nSM, const TString &txtFileName,
100 //Read data from txt file. ; coordinates given on SuperModule basis
102 std::ifstream inputFile(txtFileName.Data());
104 printf("AliEMCALCalibTimeDepCorrection::ReadTextInfo - Cannot open the APD info file %s\n", txtFileName.Data());
110 Int_t iSM = 0; // SuperModule index
114 Float_t correction = 0;
116 Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
119 inputFile >> fStartTime >> fNTimeBins >> fTimeBinSize;
121 for (Int_t i = 0; i < fNSuperModule; i++) {
122 AliEMCALSuperModuleCalibTimeDepCorrection * t = (AliEMCALSuperModuleCalibTimeDepCorrection*) fSuperModuleData[i];
125 printf("AliEMCALCalibTimeDepCorrection::ReadTextInfo - Error while reading input file; likely EOF..");
129 t->SetSuperModuleNum(iSM);
131 for (Int_t j=0; j<nAPDPerSM; j++) {
132 inputFile >> iCol >> iRow >> nCorr;
134 // assume that this info is already swapped and done for this basis?
136 // C side, oriented differently than A side: swap is requested
137 iCol = AliEMCALGeoParams::fgkEMCALCols-1 - iCol;
138 iRow = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
141 // set size of TArray
142 t->GetCorrection(iCol,iRow)->Set(nCorr);
143 for (Int_t k=0; k<nCorr; k++) {
144 inputFile >> correction;
146 t->GetCorrection(iCol,iRow)->AddAt(correction, k);
157 //____________________________________________________________________________
158 void AliEMCALCalibTimeDepCorrection::WriteTextInfo(const TString &txtFileName,
161 // write data to txt file. ; coordinates given on SuperModule basis
163 std::ofstream outputFile(txtFileName.Data());
165 printf("AliEMCALCalibTimeDepCorrection::WriteTextInfo - Cannot open the APD output file %s\n", txtFileName.Data());
173 Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
176 outputFile << fStartTime << " " << fNTimeBins << " " << fTimeBinSize << endl;
178 for (Int_t i = 0; i < fNSuperModule; i++) {
179 AliEMCALSuperModuleCalibTimeDepCorrection * t = (AliEMCALSuperModuleCalibTimeDepCorrection*) fSuperModuleData[i];
180 outputFile << t->GetSuperModuleNum() << endl;
182 for (Int_t j=0; j<nAPDPerSM; j++) {
183 iCol = j / AliEMCALGeoParams::fgkEMCALRows;
184 iRow = j % AliEMCALGeoParams::fgkEMCALRows;
186 nCorr = t->GetCorrection(iCol,iRow)->GetSize();
189 // C side, oriented differently than A side: swap is requested
190 iCol = AliEMCALGeoParams::fgkEMCALCols-1 - iCol;
191 iRow = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
194 outputFile << iCol << " " << iRow << " " << nCorr << endl;
195 for (Int_t k=0; k<nCorr; k++) {
196 outputFile << t->GetCorrection(iCol,iRow)->At(k) << " ";
209 //____________________________________________________________________________
210 void AliEMCALCalibTimeDepCorrection::ReadRootInfo(const TString &rootFileName,
213 //Read data from root file. ; coordinates given on SuperModule basis
214 TFile inputFile(rootFileName, "read");
216 TTree *treeGlob = (TTree*) inputFile.Get("treeGlob");
217 TTree *treeCorr = (TTree*) inputFile.Get("treeCorr");
219 ReadTreeInfo(treeGlob, treeCorr, swapSides);
226 //____________________________________________________________________________
227 void AliEMCALCalibTimeDepCorrection::ReadTreeInfo(TTree *treeGlob, TTree *treeCorr,
230 // how many SuperModule's worth of entries / APDs do we have?
231 Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
232 fNSuperModule = treeCorr->GetEntries() / nAPDPerSM;
234 // global variables : only one entry
235 treeGlob->SetBranchAddress("fStartTime", &fStartTime);
236 treeGlob->SetBranchAddress("fNTimeBins", &fNTimeBins);
237 treeGlob->SetBranchAddress("fTimeBinSize", &fTimeBinSize);
238 treeGlob->GetEntry(0);
240 Int_t iSM = 0; // SuperModule index
243 // list of values to be read
245 Float_t correction[fgkMaxTimeBins] = {0};
246 // make sure it's really initialized correctly
247 memset(correction, 0, sizeof(correction)); // better safe than sorry
250 // declare the branches
251 treeCorr->SetBranchAddress("iSM", &iSM);
252 treeCorr->SetBranchAddress("iCol", &iCol);
253 treeCorr->SetBranchAddress("iRow", &iRow);
254 treeCorr->SetBranchAddress("nCorr", &nCorr);
255 treeCorr->SetBranchAddress("correction", correction);
257 for (int ient=0; ient<treeCorr->GetEntries(); ient++) {
258 treeCorr->GetEntry(ient);
260 // assume the index SuperModules come in order: i=iSM
261 AliEMCALSuperModuleCalibTimeDepCorrection * t = (AliEMCALSuperModuleCalibTimeDepCorrection*) fSuperModuleData[iSM];
262 t->SetSuperModuleNum(iSM);
264 // assume that this info is already swapped and done for this basis?
266 // C side, oriented differently than A side: swap is requested
267 iCol = AliEMCALGeoParams::fgkEMCALCols-1 - iCol;
268 iRow = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
272 // set size of TArray
273 t->GetCorrection(iCol,iRow)->Set(nCorr);
274 for (Int_t k=0; k<nCorr; k++) {
276 t->GetCorrection(iCol,iRow)->AddAt(correction[k], k);
284 //____________________________________________________________________________
285 void AliEMCALCalibTimeDepCorrection::WriteRootInfo(const TString &rootFileName,
288 // write data to root file. ; coordinates given on SuperModule basis
289 TFile destFile(rootFileName, "recreate");
290 if (destFile.IsZombie()) {
295 TTree *treeGlob = new TTree("treeGlob","");
296 TTree *treeCorr = new TTree("treeCorr","");
298 // global part only has one entry
299 treeGlob->Branch("fStartTime", &fStartTime, "fStartTime/I"); // really unsigned int..
300 treeGlob->Branch("fNTimeBins", &fNTimeBins, "fNTimeBins/I");
301 treeGlob->Branch("fTimeBinSize", &fTimeBinSize, "fTimeBinSize/I");
304 // variables for filling the TTree
305 Int_t iSM = 0; // SuperModule index
309 Float_t correction[fgkMaxTimeBins] = {0};
310 // make sure it's really initialized correctly
311 memset(correction, 0, sizeof(correction)); // better safe than sorry
313 // declare the branches
314 treeCorr->Branch("iSM", &iSM, "iSM/I");
315 treeCorr->Branch("iCol", &iCol, "iCol/I");
316 treeCorr->Branch("iRow", &iRow, "iRow/I");
317 treeCorr->Branch("nCorr", &nCorr, "nCorr/I");
318 treeCorr->Branch("correction", &correction, "correction[nCorr]/F");
320 Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
322 for (iSM = 0; iSM < fNSuperModule; iSM++) {
323 AliEMCALSuperModuleCalibTimeDepCorrection * t = (AliEMCALSuperModuleCalibTimeDepCorrection*) fSuperModuleData[iSM];
325 for (Int_t j=0; j<nAPDPerSM; j++) {
326 iCol = j / AliEMCALGeoParams::fgkEMCALRows;
327 iRow = j % AliEMCALGeoParams::fgkEMCALRows;
329 nCorr = t->GetCorrection(iCol,iRow)->GetSize();
330 if (nCorr > fgkMaxTimeBins) {
331 printf("AliEMCALCalibTimeDepCorrection::WriteRootInfo - too many correction/timebins %d kept\n", nCorr);
336 // C side, oriented differently than A side: swap is requested
337 iCol = AliEMCALGeoParams::fgkEMCALCols-1 - iCol;
338 iRow = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
341 for (Int_t k=0; k<nCorr; k++) {
342 correction[k] = t->GetCorrection(iCol,iRow)->At(k);
357 //____________________________________________________________________________
358 AliEMCALCalibTimeDepCorrection::~AliEMCALCalibTimeDepCorrection()
360 fSuperModuleData.Delete();
363 //____________________________________________________________________________
364 AliEMCALSuperModuleCalibTimeDepCorrection * AliEMCALCalibTimeDepCorrection::GetSuperModuleCalibTimeDepCorrectionNum(Int_t supModIndex)const
366 for (int i=0; i<fNSuperModule; i++) {
367 AliEMCALSuperModuleCalibTimeDepCorrection * t = (AliEMCALSuperModuleCalibTimeDepCorrection*) fSuperModuleData[i];
368 if (t->GetSuperModuleNum() == supModIndex) {
373 // if we arrived here, then nothing was found.. just return a NULL pointer