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=1.0)
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];
63 t->SetSuperModuleNum(iSM); // assume SMs are coming in order
65 for (Int_t j=0; j<nAPDPerSM; j++) {
68 t->GetCorrection(iCol,iRow)->Set(nCorr);
69 for (Int_t k=0; k<nCorr; k++) {
71 t->GetCorrection(iCol,iRow)->AddAt(correction, k); // AddAt = SetAt..
80 //____________________________________________________________________________
81 void AliEMCALCalibTimeDepCorrection::SetCorrection(Int_t supModIndex, Int_t iCol, Int_t iRow, Int_t iBin, Float_t val)
82 { // if you call for non-existing data, there may be a crash..
83 ((AliEMCALSuperModuleCalibTimeDepCorrection*)fSuperModuleData[supModIndex])->GetCorrection(iCol,iRow)->AddAt(val, iBin); // AddAt = SetAt..
87 //____________________________________________________________________________
88 Float_t AliEMCALCalibTimeDepCorrection::GetCorrection(Int_t supModIndex, Int_t iCol, Int_t iRow, Int_t iBin) const
89 { // if you call for non-existing data, there may be a crash..
90 return ((AliEMCALSuperModuleCalibTimeDepCorrection*)fSuperModuleData[supModIndex])->GetCorrection(iCol,iRow)->At(iBin);
93 //____________________________________________________________________________
94 void AliEMCALCalibTimeDepCorrection::ReadTextInfo(Int_t nSM, const TString &txtFileName,
97 //Read data from txt file. ; coordinates given on SuperModule basis
99 std::ifstream inputFile(txtFileName.Data());
101 printf("AliEMCALCalibTimeDepCorrection::ReadTextInfo - Cannot open the APD info file %s\n", txtFileName.Data());
107 Int_t iSM = 0; // SuperModule index
111 Float_t correction = 0;
113 Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
116 inputFile >> fStartTime >> fNTimeBins >> fTimeBinSize;
118 for (Int_t i = 0; i < fNSuperModule; i++) {
119 AliEMCALSuperModuleCalibTimeDepCorrection * t = (AliEMCALSuperModuleCalibTimeDepCorrection*) fSuperModuleData[i];
122 printf("AliEMCALCalibTimeDepCorrection::ReadTextInfo - Error while reading input file; likely EOF..");
126 t->SetSuperModuleNum(iSM);
128 for (Int_t j=0; j<nAPDPerSM; j++) {
129 inputFile >> iCol >> iRow >> nCorr;
131 // assume that this info is already swapped and done for this basis?
133 // C side, oriented differently than A side: swap is requested
134 iCol = AliEMCALGeoParams::fgkEMCALCols-1 - iCol;
135 iRow = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
138 // set size of TArray
139 t->GetCorrection(iCol,iRow)->Set(nCorr);
140 for (Int_t k=0; k<nCorr; k++) {
141 inputFile >> correction;
143 t->GetCorrection(iCol,iRow)->AddAt(correction, k);
154 //____________________________________________________________________________
155 void AliEMCALCalibTimeDepCorrection::WriteTextInfo(const TString &txtFileName,
158 // write data to txt file. ; coordinates given on SuperModule basis
160 std::ofstream outputFile(txtFileName.Data());
162 printf("AliEMCALCalibTimeDepCorrection::WriteTextInfo - Cannot open the APD output file %s\n", txtFileName.Data());
170 Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
173 outputFile << fStartTime << " " << fNTimeBins << " " << fTimeBinSize << endl;
175 for (Int_t i = 0; i < fNSuperModule; i++) {
176 AliEMCALSuperModuleCalibTimeDepCorrection * t = (AliEMCALSuperModuleCalibTimeDepCorrection*) fSuperModuleData[i];
177 outputFile << t->GetSuperModuleNum() << endl;
179 for (Int_t j=0; j<nAPDPerSM; j++) {
180 iCol = j / AliEMCALGeoParams::fgkEMCALRows;
181 iRow = j % AliEMCALGeoParams::fgkEMCALRows;
183 nCorr = t->GetCorrection(iCol,iRow)->GetSize();
186 // C side, oriented differently than A side: swap is requested
187 iCol = AliEMCALGeoParams::fgkEMCALCols-1 - iCol;
188 iRow = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
191 outputFile << iCol << " " << iRow << " " << nCorr << endl;
192 for (Int_t k=0; k<nCorr; k++) {
193 outputFile << t->GetCorrection(iCol,iRow)->At(k) << " ";
206 //____________________________________________________________________________
207 void AliEMCALCalibTimeDepCorrection::ReadRootInfo(const TString &rootFileName,
210 //Read data from root file. ; coordinates given on SuperModule basis
211 TFile inputFile(rootFileName, "read");
213 TTree *treeGlob = (TTree*) inputFile.Get("treeGlob");
214 TTree *treeCorr = (TTree*) inputFile.Get("treeCorr");
216 ReadTreeInfo(treeGlob, treeCorr, swapSides);
223 //____________________________________________________________________________
224 void AliEMCALCalibTimeDepCorrection::ReadTreeInfo(TTree *treeGlob, TTree *treeCorr,
227 // how many SuperModule's worth of entries / APDs do we have?
228 Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
229 fNSuperModule = treeCorr->GetEntries() / nAPDPerSM;
231 // global variables : only one entry
232 treeGlob->SetBranchAddress("fStartTime", &fStartTime);
233 treeGlob->SetBranchAddress("fNTimeBins", &fNTimeBins);
234 treeGlob->SetBranchAddress("fTimeBinSize", &fTimeBinSize);
235 treeGlob->GetEntry(0);
237 Int_t iSM = 0; // SuperModule index
240 // list of values to be read
242 Float_t correction[fgkMaxTimeBins] = {0};
243 // make sure it's really initialized correctly
244 memset(correction, 0, sizeof(correction)); // better safe than sorry
247 // declare the branches
248 treeCorr->SetBranchAddress("iSM", &iSM);
249 treeCorr->SetBranchAddress("iCol", &iCol);
250 treeCorr->SetBranchAddress("iRow", &iRow);
251 treeCorr->SetBranchAddress("nCorr", &nCorr);
252 treeCorr->SetBranchAddress("correction", correction);
254 for (int ient=0; ient<treeCorr->GetEntries(); ient++) {
255 treeCorr->GetEntry(ient);
257 // assume the index SuperModules come in order: i=iSM
258 AliEMCALSuperModuleCalibTimeDepCorrection * t = (AliEMCALSuperModuleCalibTimeDepCorrection*) fSuperModuleData[iSM];
259 t->SetSuperModuleNum(iSM);
261 // assume that this info is already swapped and done for this basis?
263 // C side, oriented differently than A side: swap is requested
264 iCol = AliEMCALGeoParams::fgkEMCALCols-1 - iCol;
265 iRow = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
269 // set size of TArray
270 t->GetCorrection(iCol,iRow)->Set(nCorr);
271 for (Int_t k=0; k<nCorr; k++) {
273 t->GetCorrection(iCol,iRow)->AddAt(correction[k], k);
281 //____________________________________________________________________________
282 void AliEMCALCalibTimeDepCorrection::WriteRootInfo(const TString &rootFileName,
285 // write data to root file. ; coordinates given on SuperModule basis
286 TFile destFile(rootFileName, "recreate");
287 if (destFile.IsZombie()) {
292 TTree *treeGlob = new TTree("treeGlob","");
293 TTree *treeCorr = new TTree("treeCorr","");
295 // global part only has one entry
296 treeGlob->Branch("fStartTime", &fStartTime, "fStartTime/I"); // really unsigned int..
297 treeGlob->Branch("fNTimeBins", &fNTimeBins, "fNTimeBins/I");
298 treeGlob->Branch("fTimeBinSize", &fTimeBinSize, "fTimeBinSize/I");
301 // variables for filling the TTree
302 Int_t iSM = 0; // SuperModule index
306 Float_t correction[fgkMaxTimeBins] = {0};
307 // make sure it's really initialized correctly
308 memset(correction, 0, sizeof(correction)); // better safe than sorry
310 // declare the branches
311 treeCorr->Branch("iSM", &iSM, "iSM/I");
312 treeCorr->Branch("iCol", &iCol, "iCol/I");
313 treeCorr->Branch("iRow", &iRow, "iRow/I");
314 treeCorr->Branch("nCorr", &nCorr, "nCorr/I");
315 treeCorr->Branch("correction", &correction, "correction[nCorr]/F");
317 Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
319 for (iSM = 0; iSM < fNSuperModule; iSM++) {
320 AliEMCALSuperModuleCalibTimeDepCorrection * t = (AliEMCALSuperModuleCalibTimeDepCorrection*) fSuperModuleData[iSM];
322 for (Int_t j=0; j<nAPDPerSM; j++) {
323 iCol = j / AliEMCALGeoParams::fgkEMCALRows;
324 iRow = j % AliEMCALGeoParams::fgkEMCALRows;
326 nCorr = t->GetCorrection(iCol,iRow)->GetSize();
327 if (nCorr > fgkMaxTimeBins) {
328 printf("AliEMCALCalibTimeDepCorrection::WriteRootInfo - too many correction/timebins %d kept\n", nCorr);
333 // C side, oriented differently than A side: swap is requested
334 iCol = AliEMCALGeoParams::fgkEMCALCols-1 - iCol;
335 iRow = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
338 for (Int_t k=0; k<nCorr; k++) {
339 correction[k] = t->GetCorrection(iCol,iRow)->At(k);
354 //____________________________________________________________________________
355 AliEMCALCalibTimeDepCorrection::~AliEMCALCalibTimeDepCorrection()
357 fSuperModuleData.Delete();
360 //____________________________________________________________________________
361 AliEMCALSuperModuleCalibTimeDepCorrection * AliEMCALCalibTimeDepCorrection::GetSuperModuleCalibTimeDepCorrectionNum(Int_t supModIndex)const
363 for (int i=0; i<fNSuperModule; i++) {
364 AliEMCALSuperModuleCalibTimeDepCorrection * t = (AliEMCALSuperModuleCalibTimeDepCorrection*) fSuperModuleData[i];
365 if (t->GetSuperModuleNum() == supModIndex) {
370 // if we arrived here, then nothing was found.. just return a NULL pointer