X-Git-Url: http://git.uio.no/git/?p=u%2Fmrichter%2FAliRoot.git;a=blobdiff_plain;f=EMCAL%2FAliEMCALCalibTimeDepCorrection.cxx;h=fcf71550029fcea894a8e28cc1be3e0488d72337;hp=6178d294b2b1c7d887433b7f3b3e056a2858199b;hb=1bd2ee2f8ef38e4987101a24d8bb6c3e7c9233ba;hpb=0c5b726e53d33d1d6f80431cde11bb2b4124c62b diff --git a/EMCAL/AliEMCALCalibTimeDepCorrection.cxx b/EMCAL/AliEMCALCalibTimeDepCorrection.cxx index 6178d294b2b..fcf71550029 100644 --- a/EMCAL/AliEMCALCalibTimeDepCorrection.cxx +++ b/EMCAL/AliEMCALCalibTimeDepCorrection.cxx @@ -15,12 +15,13 @@ /* $Id: $ */ -// Objects of this class contain info on APD bias settings/voltages +// Objects of this class contain info on time-dependent corrections // #include #include -#include +#include +#include #include "AliEMCALCalibTimeDepCorrection.h" @@ -29,14 +30,18 @@ using namespace std; ClassImp(AliEMCALCalibTimeDepCorrection) //____________________________________________________________________________ -AliEMCALCalibTimeDepCorrection::AliEMCALCalibTimeDepCorrection() : - fNSuperModule(0), - fSuperModuleData(0), +AliEMCALCalibTimeDepCorrection::AliEMCALCalibTimeDepCorrection(const int nSM) : + fNSuperModule(nSM), + fSuperModuleData(), fStartTime(0), fNTimeBins(0), fTimeBinSize(0) { //Default constructor. + for (int i=0; iSetSuperModuleNum(iSM); // assume SMs are coming in order for (Int_t j=0; jGetCorrection(iCol,iRow)->Set(nCorr); for (Int_t k=0; kGetCorrection(iCol,iRow)->AddAt(correction, k); // AddAt = SetAt.. } } @@ -77,52 +83,62 @@ void AliEMCALCalibTimeDepCorrection::InitCorrection(Int_t nSM, Int_t nBins, Floa //____________________________________________________________________________ void AliEMCALCalibTimeDepCorrection::SetCorrection(Int_t supModIndex, Int_t iCol, Int_t iRow, Int_t iBin, Float_t val) { // if you call for non-existing data, there may be a crash.. - fSuperModuleData[supModIndex].fCorrection[iCol][iRow].AddAt(val, iBin); // AddAt = SetAt.. + ((AliEMCALSuperModuleCalibTimeDepCorrection*)fSuperModuleData[supModIndex])->GetCorrection(iCol,iRow)->AddAt(val, iBin); // AddAt = SetAt.. return; } //____________________________________________________________________________ -Float_t AliEMCALCalibTimeDepCorrection::GetCorrection(Int_t supModIndex, Int_t iCol, Int_t iRow, Int_t iBin)const +Float_t AliEMCALCalibTimeDepCorrection::GetCorrection(Int_t supModIndex, Int_t iCol, Int_t iRow, Int_t iBin) const { // if you call for non-existing data, there may be a crash.. - return fSuperModuleData[supModIndex].fCorrection[iCol][iRow].At(iBin); + return ((AliEMCALSuperModuleCalibTimeDepCorrection*)fSuperModuleData[supModIndex])->GetCorrection(iCol,iRow)->At(iBin); } //____________________________________________________________________________ -void AliEMCALCalibTimeDepCorrection::ReadCalibTimeDepCorrectionInfo(Int_t nSM, const TString &txtFileName, - Bool_t swapSides) +void AliEMCALCalibTimeDepCorrection::ReadTextInfo(Int_t nSM, const TString &txtFileName, + Bool_t swapSides) { //Read data from txt file. ; coordinates given on SuperModule basis std::ifstream inputFile(txtFileName.Data()); if (!inputFile) { - printf("AliEMCALCalibTimeDepCorrection::ReadCalibTimeDepCorrectionInfo - Cannot open the APD info file %s\n", txtFileName.Data()); + printf("AliEMCALCalibTimeDepCorrection::ReadTextInfo - Cannot open the APD info file %s\n", txtFileName.Data()); return; } fNSuperModule = nSM; - if (fSuperModuleData) delete [] fSuperModuleData; - fSuperModuleData = new AliEMCALSuperModuleCalibTimeDepCorrection[fNSuperModule]; Int_t iSM = 0; // SuperModule index Int_t iCol = 0; Int_t iRow = 0; Int_t nCorr = 0; - Float_t Correction = 0; + Float_t correction = 0; Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows; + // read header info + inputFile >> fStartTime >> fNTimeBins >> fTimeBinSize; + for (Int_t i = 0; i < fNSuperModule; i++) { - AliEMCALSuperModuleCalibTimeDepCorrection &t = fSuperModuleData[i]; + AliEMCALSuperModuleCalibTimeDepCorrection * t = (AliEMCALSuperModuleCalibTimeDepCorrection*) fSuperModuleData[i]; + if (!inputFile) { - printf("AliEMCALCalibTimeDepCorrection::ReadCalibTimeDepCorrectionInfo - Error while reading input file; likely EOF.."); + printf("AliEMCALCalibTimeDepCorrection::ReadTextInfo - Error while reading input file; likely EOF..\n"); return; } inputFile >> iSM; - t.fSuperModuleNum = iSM; + t->SetSuperModuleNum(iSM); for (Int_t j=0; j> iCol >> iRow >> nCorr; + // check that input values are not out bounds + if (iCol<0 || iCol>(AliEMCALGeoParams::fgkEMCALCols-1) || + iRow<0 || iRow>(AliEMCALGeoParams::fgkEMCALRows-1) || + nCorr<0 ) { + printf("AliEMCALCalibTimeDepCorrection::ReadTextInfo - Error while reading input file; j %d iCol %d iRow %d nCorr %d\n", j, iCol, iRow, nCorr); + return; + } + // assume that this info is already swapped and done for this basis? if (swapSides) { // C side, oriented differently than A side: swap is requested @@ -131,11 +147,11 @@ void AliEMCALCalibTimeDepCorrection::ReadCalibTimeDepCorrectionInfo(Int_t nSM, c } // set size of TArray - t.fCorrection[iCol][iRow].Set(nCorr); + t->GetCorrection(iCol,iRow)->Set(nCorr); for (Int_t k=0; k> Correction; + inputFile >> correction; // add to TArray - t.fCorrection[iCol][iRow].AddAt(Correction, k); + t->GetCorrection(iCol,iRow)->AddAt(correction, k); } } @@ -147,14 +163,14 @@ void AliEMCALCalibTimeDepCorrection::ReadCalibTimeDepCorrectionInfo(Int_t nSM, c } //____________________________________________________________________________ -void AliEMCALCalibTimeDepCorrection::WriteCalibTimeDepCorrectionInfo(const TString &txtFileName, - Bool_t swapSides) +void AliEMCALCalibTimeDepCorrection::WriteTextInfo(const TString &txtFileName, + Bool_t swapSides) { // write data to txt file. ; coordinates given on SuperModule basis std::ofstream outputFile(txtFileName.Data()); if (!outputFile) { - printf("AliEMCALCalibTimeDepCorrection::WriteCalibTimeDepCorrectionInfo - Cannot open the APD output file %s\n", txtFileName.Data()); + printf("AliEMCALCalibTimeDepCorrection::WriteTextInfo - Cannot open the APD output file %s\n", txtFileName.Data()); return; } @@ -164,15 +180,18 @@ void AliEMCALCalibTimeDepCorrection::WriteCalibTimeDepCorrectionInfo(const TStri Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows; + // write header info + outputFile << fStartTime << " " << fNTimeBins << " " << fTimeBinSize << endl; + for (Int_t i = 0; i < fNSuperModule; i++) { - AliEMCALSuperModuleCalibTimeDepCorrection &t = fSuperModuleData[i]; - outputFile << t.fSuperModuleNum << endl; + AliEMCALSuperModuleCalibTimeDepCorrection * t = (AliEMCALSuperModuleCalibTimeDepCorrection*) fSuperModuleData[i]; + outputFile << t->GetSuperModuleNum() << endl; for (Int_t j=0; jGetCorrection(iCol,iRow)->GetSize(); if (swapSides) { // C side, oriented differently than A side: swap is requested @@ -182,7 +201,7 @@ void AliEMCALCalibTimeDepCorrection::WriteCalibTimeDepCorrectionInfo(const TStri outputFile << iCol << " " << iRow << " " << nCorr << endl; for (Int_t k=0; kGetCorrection(iCol,iRow)->At(k) << " "; } outputFile << endl; @@ -196,34 +215,170 @@ void AliEMCALCalibTimeDepCorrection::WriteCalibTimeDepCorrectionInfo(const TStri } //____________________________________________________________________________ -AliEMCALCalibTimeDepCorrection::~AliEMCALCalibTimeDepCorrection() +void AliEMCALCalibTimeDepCorrection::ReadRootInfo(const TString &rootFileName, + Bool_t swapSides) { - delete [] fSuperModuleData; + //Read data from root file. ; coordinates given on SuperModule basis + TFile inputFile(rootFileName, "read"); + + TTree *treeGlob = (TTree*) inputFile.Get("treeGlob"); + TTree *treeCorr = (TTree*) inputFile.Get("treeCorr"); + + ReadTreeInfo(treeGlob, treeCorr, swapSides); + + inputFile.Close(); + + return; } //____________________________________________________________________________ -AliEMCALCalibTimeDepCorrection::AliEMCALSuperModuleCalibTimeDepCorrection AliEMCALCalibTimeDepCorrection::GetSuperModuleCalibTimeDepCorrectionId(Int_t supModIndex)const +void AliEMCALCalibTimeDepCorrection::ReadTreeInfo(TTree *treeGlob, TTree *treeCorr, + Bool_t swapSides) { - AliEMCALSuperModuleCalibTimeDepCorrection t; // just to maybe prevent a crash, but we are returning something not-initialized so maybe not better really.. - if (!fSuperModuleData) - return t; + // how many SuperModule's worth of entries / APDs do we have? + Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows; + fNSuperModule = treeCorr->GetEntries() / nAPDPerSM; + + // global variables : only one entry + treeGlob->SetBranchAddress("fStartTime", &fStartTime); + treeGlob->SetBranchAddress("fNTimeBins", &fNTimeBins); + treeGlob->SetBranchAddress("fTimeBinSize", &fTimeBinSize); + treeGlob->GetEntry(0); - return fSuperModuleData[supModIndex]; + Int_t iSM = 0; // SuperModule index + Int_t iCol = 0; + Int_t iRow = 0; + // list of values to be read + Int_t nCorr = 0; + Float_t correction[fgkMaxTimeBins] = {0}; + // make sure it's really initialized correctly + memset(correction, 0, sizeof(correction)); // better safe than sorry + // end - all values + + // declare the branches + treeCorr->SetBranchAddress("iSM", &iSM); + treeCorr->SetBranchAddress("iCol", &iCol); + treeCorr->SetBranchAddress("iRow", &iRow); + treeCorr->SetBranchAddress("nCorr", &nCorr); + treeCorr->SetBranchAddress("correction", correction); + + for (int ient=0; ientGetEntries(); ient++) { + treeCorr->GetEntry(ient); + + // assume the index SuperModules come in order: i=iSM + AliEMCALSuperModuleCalibTimeDepCorrection * t = (AliEMCALSuperModuleCalibTimeDepCorrection*) fSuperModuleData[iSM]; + t->SetSuperModuleNum(iSM); + + // assume that this info is already swapped and done for this basis? + if (swapSides) { + // C side, oriented differently than A side: swap is requested + iCol = AliEMCALGeoParams::fgkEMCALCols-1 - iCol; + iRow = AliEMCALGeoParams::fgkEMCALRows-1 - iRow; + } + + + // set size of TArray + t->GetCorrection(iCol,iRow)->Set(nCorr); + for (Int_t k=0; kGetCorrection(iCol,iRow)->AddAt(correction[k], k); + } + + } // entry + + return; } //____________________________________________________________________________ -AliEMCALCalibTimeDepCorrection::AliEMCALSuperModuleCalibTimeDepCorrection AliEMCALCalibTimeDepCorrection::GetSuperModuleCalibTimeDepCorrectionNum(Int_t supModIndex)const +void AliEMCALCalibTimeDepCorrection::WriteRootInfo(const TString &rootFileName, + Bool_t swapSides) { - AliEMCALSuperModuleCalibTimeDepCorrection t; // just to maybe prevent a crash, but we are returning something not-initialized so maybe not better really.. - if (!fSuperModuleData) - return t; + // write data to root file. ; coordinates given on SuperModule basis + TFile destFile(rootFileName, "recreate"); + if (destFile.IsZombie()) { + return; + } + destFile.cd(); + + TTree *treeGlob = new TTree("treeGlob",""); + TTree *treeCorr = new TTree("treeCorr",""); + + // global part only has one entry + treeGlob->Branch("fStartTime", &fStartTime, "fStartTime/i"); // unsigned int.. + treeGlob->Branch("fNTimeBins", &fNTimeBins, "fNTimeBins/I"); + treeGlob->Branch("fTimeBinSize", &fTimeBinSize, "fTimeBinSize/I"); + treeGlob->Fill(); + // variables for filling the TTree + Int_t iSM = 0; // SuperModule index + Int_t iCol = 0; + Int_t iRow = 0; + Int_t nCorr = 0; + Float_t correction[fgkMaxTimeBins] = {0}; + // make sure it's really initialized correctly + memset(correction, 0, sizeof(correction)); // better safe than sorry + + // declare the branches + treeCorr->Branch("iSM", &iSM, "iSM/I"); + treeCorr->Branch("iCol", &iCol, "iCol/I"); + treeCorr->Branch("iRow", &iRow, "iRow/I"); + treeCorr->Branch("nCorr", &nCorr, "nCorr/I"); + treeCorr->Branch("correction", &correction, "correction[nCorr]/F"); + + Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows; + + for (iSM = 0; iSM < fNSuperModule; iSM++) { + AliEMCALSuperModuleCalibTimeDepCorrection * t = (AliEMCALSuperModuleCalibTimeDepCorrection*) fSuperModuleData[iSM]; + + for (Int_t j=0; jGetCorrection(iCol,iRow)->GetSize(); + if (nCorr > fgkMaxTimeBins) { + printf("AliEMCALCalibTimeDepCorrection::WriteRootInfo - too many correction/timebins %d kept\n", nCorr); + return; + } + + if (swapSides) { + // C side, oriented differently than A side: swap is requested + iCol = AliEMCALGeoParams::fgkEMCALCols-1 - iCol; + iRow = AliEMCALGeoParams::fgkEMCALRows-1 - iRow; + } + + for (Int_t k=0; kGetCorrection(iCol,iRow)->At(k); + } + + treeCorr->Fill(); + } + + } // i, SuperModule + + treeGlob->Write(); + treeCorr->Write(); + destFile.Close(); + + return; +} + +//____________________________________________________________________________ +AliEMCALCalibTimeDepCorrection::~AliEMCALCalibTimeDepCorrection() +{ + fSuperModuleData.Delete(); +} + +//____________________________________________________________________________ +AliEMCALSuperModuleCalibTimeDepCorrection * AliEMCALCalibTimeDepCorrection::GetSuperModuleCalibTimeDepCorrectionNum(Int_t supModIndex)const +{ for (int i=0; iGetSuperModuleNum() == supModIndex) { + return t; } } - return t; + // if we arrived here, then nothing was found.. just return a NULL pointer + return NULL; }