]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - EMCAL/AliEMCALCalibAbs.cxx
Set default PF pattern when not set properly in OCDB
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALCalibAbs.cxx
index 2d21563bceeda1bfa2c39774a82ae88de70b425f..4313b4817490ecc5fa4ac1a697c0090562bbecf8 100644 (file)
@@ -20,6 +20,8 @@
 
 #include <fstream>
 #include <TString.h>
+#include <TFile.h>
+#include <TTree.h>
 
 #include "AliEMCALCalibAbs.h"
 
@@ -28,16 +30,21 @@ using namespace std;
 ClassImp(AliEMCALCalibAbs)
 
 //____________________________________________________________________________
-AliEMCALCalibAbs::AliEMCALCalibAbs() : 
-  fNSuperModule(0),
-  fSuperModuleData(0)
+AliEMCALCalibAbs::AliEMCALCalibAbs(const int nSM) : 
+  fNSuperModule(nSM),
+  fSuperModuleData()
 {
   //Default constructor.
+  for (int i=0; i<fNSuperModule; i++) {
+    fSuperModuleData.Add(new AliEMCALSuperModuleCalibAbs(i));
+  }
+  fSuperModuleData.Compress(); // compress the TObjArray
+  fSuperModuleData.SetOwner(kTRUE); 
 }
 
 //____________________________________________________________________________
-void AliEMCALCalibAbs::ReadCalibAbsInfo(Int_t nSM, const TString &txtFileName,
-                                     Bool_t swapSides)
+void AliEMCALCalibAbs::ReadTextCalibAbsInfo(Int_t nSM, const TString &txtFileName,
+                                           Bool_t swapSides)
 {
   //Read data from txt file. ; coordinates given on SuperModule basis
 
@@ -48,71 +55,47 @@ void AliEMCALCalibAbs::ReadCalibAbsInfo(Int_t nSM, const TString &txtFileName,
   }
 
   fNSuperModule = nSM;
-  if (fSuperModuleData) delete [] fSuperModuleData;
-  fSuperModuleData = new AliEMCALSuperModuleCalibAbs[fNSuperModule];
 
   Int_t iSM = 0; // SuperModule index
   Int_t iCol = 0;
   Int_t iRow = 0;
-  Int_t id = 0;
 
   // list of values to be read
   // first: overall values for the whole SuperModule
-  Int_t CalibMethod; 
-  Int_t CalibPass; 
-  Int_t CalibTime; 
-  Float_t AbsoluteGain; 
-  // second: additional info for LED Reference and SM temperature
-  Float_t LEDRefAmp;
-  Float_t LEDRefAmpRMS;
-  Float_t LEDRefHighLowRatio;
-  Int_t LEDRefHighLow;
-  Float_t Temperature;
-  Float_t TemperatureRMS;
+  Int_t iCalibMethod = 0; 
+  Int_t iCalibPass = 0; 
+  Float_t absoluteCalib = 0; 
   // third: info for each tower
-  Float_t RelativeGain; // (ADC>GeV relative gain/conversion), value around 1
-  Float_t HighLowRatio; // value around 16 or so
-  Int_t HighLow; // 
-  Float_t LEDAmp; // low gain eq. amplitude
-  Float_t LEDAmpRMS; //
+  Float_t relativeCalib = 0; // (ADC>GeV relative gain/conversion), value around 1
   // end - all values
 
   Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
 
   for (Int_t i = 0; i < fNSuperModule; i++) {
-    AliEMCALSuperModuleCalibAbs &t = fSuperModuleData[i];
+    AliEMCALSuperModuleCalibAbs * t = (AliEMCALSuperModuleCalibAbs*) fSuperModuleData[i];
     if (!inputFile) {
-      printf("AliEMCALCalibAbs::ReadCalibAbsInfo - Error while reading input file; likely EOF..");
+      printf("AliEMCALCalibAbs::ReadCalibAbsInfo - Error while reading input file; likely EOF..\n");
       return;
     }
     inputFile >> iSM;
-    t.fSuperModuleNum = iSM;
+    t->SetSuperModuleNum(iSM);
 
     // first: overall values for the whole SuperModule
-    inputFile >> CalibMethod >> CalibPass >> CalibTime >> AbsoluteGain;
-    t.fCalibMethod = CalibMethod;
-    t.fCalibPass = CalibPass;
-    t.fCalibTime = CalibTime;
-    t.fAbsoluteGain = AbsoluteGain;
-
-    // second: additional info for LED Reference and SM temperature
-    for (Int_t j=0; j<AliEMCALGeoParams::fgkEMCALLEDRefs; j++) {
-      inputFile >> id >> LEDRefAmp >> LEDRefAmpRMS >> LEDRefHighLowRatio >> LEDRefHighLow;
-      t.fLEDRefAmp[id] = LEDRefAmp;
-      t.fLEDRefAmpRMS[id] = LEDRefAmpRMS;
-      t.fLEDRefHighLowRatio[id] = LEDRefHighLowRatio;
-      t.fLEDRefHighLow[id] = LEDRefHighLow;
-    }
-    for (Int_t j=0; j<AliEMCALGeoParams::fgkEMCALTempSensors; j++) {
-      inputFile >> id >> Temperature >> TemperatureRMS;
-      t.fTemperature[id] = Temperature;
-      t.fTemperatureRMS[id] = TemperatureRMS;
-    }
+    inputFile >> iCalibMethod >> iCalibPass >> absoluteCalib;
+    t->SetCalibMethod(iCalibMethod);
+    t->SetCalibPass(iCalibPass);
+    t->SetAbsoluteCalib(absoluteCalib);
 
     // third: info for each tower
     for (Int_t j=0; j<nAPDPerSM; j++) {
-      inputFile >> iCol >> iRow 
-               >> RelativeGain >> HighLowRatio >> HighLow >> LEDAmp >> LEDAmpRMS;
+      inputFile >> iCol >> iRow >> relativeCalib;
+
+      // check that input values are not out bounds
+      if (iCol<0 || iCol>(AliEMCALGeoParams::fgkEMCALCols-1) ||
+         iRow<0 || iRow>(AliEMCALGeoParams::fgkEMCALRows-1) ) {
+       printf("AliEMCALCalibAbs::ReadCalibAbsInfo - Error while reading input file; j %d iCol %d iRow %d\n", j, iCol, iRow);
+      return;
+      }
 
       // assume that this info is already swapped and done for this basis?
       if (swapSides) {
@@ -121,13 +104,7 @@ void AliEMCALCalibAbs::ReadCalibAbsInfo(Int_t nSM, const TString &txtFileName,
        iRow = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
       }
 
-      AliEMCALCalibAbsVal &v = t.fAPDVal[iCol][iRow];
-
-      v.fRelativeGain = RelativeGain;
-      v.fHighLowRatio = HighLowRatio;
-      v.fHighLow = HighLow;
-      v.fLEDAmp = LEDAmp;
-      v.fLEDAmpRMS = LEDAmpRMS;
+      t->SetRelativeCalib(iCol, iRow, relativeCalib);
     }
 
   } // i, SuperModule
@@ -138,8 +115,8 @@ void AliEMCALCalibAbs::ReadCalibAbsInfo(Int_t nSM, const TString &txtFileName,
 }
 
 //____________________________________________________________________________
-void AliEMCALCalibAbs::WriteCalibAbsInfo(const TString &txtFileName,
-                                      Bool_t swapSides)
+void AliEMCALCalibAbs::WriteTextCalibAbsInfo(const TString &txtFileName,
+                                            Bool_t swapSides)
 {
   // write data to txt file. ; coordinates given on SuperModule basis
 
@@ -153,31 +130,22 @@ void AliEMCALCalibAbs::WriteCalibAbsInfo(const TString &txtFileName,
   Int_t iRow = 0;
 
   Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
-
+  Float_t relativeCalib = 0;
   for (Int_t i = 0; i < fNSuperModule; i++) {
-    AliEMCALSuperModuleCalibAbs &t = fSuperModuleData[i];
+    AliEMCALSuperModuleCalibAbs * t = (AliEMCALSuperModuleCalibAbs*) fSuperModuleData[i];
+
     // first: overall values for the whole SuperModule
-    outputFile << t.fSuperModuleNum << endl;
-    outputFile << t.fCalibMethod << " " 
-              << t.fCalibPass << " " 
-              << t.fCalibTime << " " 
-              << t.fAbsoluteGain << endl;
-
-    // second: additional info for LED Reference and SM temperature
-    for (Int_t j=0; j<AliEMCALGeoParams::fgkEMCALLEDRefs; j++) {
-      outputFile << j << " " << t.fLEDRefAmp[j] << " " << t.fLEDRefAmpRMS[j] 
-                << " " << t.fLEDRefHighLowRatio[j] << " " << t.fLEDRefHighLow[j] 
-                << endl;
-    }
-    for (Int_t j=0; j<AliEMCALGeoParams::fgkEMCALTempSensors; j++) {
-      outputFile << j << " " << t.fTemperature[j] << " " << t.fTemperatureRMS[j] << endl;
-    }
+    outputFile << t->GetSuperModuleNum() << endl;
+    outputFile << t->GetCalibMethod() << " " 
+              << t->GetCalibPass() << " " 
+              << t->GetAbsoluteCalib() << endl;
 
+    // third: info for each tower
     for (Int_t j=0; j<nAPDPerSM; j++) {
       iCol = j / AliEMCALGeoParams::fgkEMCALRows;
       iRow = j % AliEMCALGeoParams::fgkEMCALRows;
 
-      AliEMCALCalibAbsVal &v = t.fAPDVal[iCol][iRow];
+      relativeCalib = t->GetRelativeCalib(iCol, iRow);
 
       if (swapSides) {
        // C side, oriented differently than A side: swap is requested
@@ -186,11 +154,7 @@ void AliEMCALCalibAbs::WriteCalibAbsInfo(const TString &txtFileName,
       }
 
       outputFile << iCol << " " << iRow 
-                << " " << v.fRelativeGain
-                << " " << v.fHighLowRatio 
-                << " " << v.fHighLow 
-                << " " << v.fLEDAmp 
-                << " " << v.fLEDAmpRMS << endl;
+                << " " << relativeCalib << endl;
     }
 
   } // i, SuperModule
@@ -201,34 +165,183 @@ void AliEMCALCalibAbs::WriteCalibAbsInfo(const TString &txtFileName,
 }
 
 //____________________________________________________________________________
-AliEMCALCalibAbs::~AliEMCALCalibAbs()
+void AliEMCALCalibAbs::ReadRootCalibAbsInfo(const TString &rootFileName,
+                                           Bool_t swapSides)
 {
-  delete [] fSuperModuleData;
+  //Read data from root file. ; coordinates given on SuperModule basis
+  TFile inputFile(rootFileName, "read");  
+
+  TTree *tree = (TTree*) inputFile.Get("tree");
+
+  ReadTreeCalibAbsInfo(tree, swapSides);
+
+  inputFile.Close();
+
+  return;
 }
 
 //____________________________________________________________________________
-AliEMCALCalibAbs::AliEMCALSuperModuleCalibAbs AliEMCALCalibAbs::GetSuperModuleCalibAbsId(Int_t supModIndex)const
+void AliEMCALCalibAbs::ReadTreeCalibAbsInfo(TTree *tree,
+                                           Bool_t swapSides)
 {
-  AliEMCALSuperModuleCalibAbs 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 info do we have?
+  Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
+  fNSuperModule = tree->GetEntries();
+
+  Int_t iSM = 0; // SuperModule index
+  // list of values to be read
+  // first: overall values for the whole SuperModule
+  Int_t iCalibMethod = 0; 
+  Int_t iCalibPass = 0; 
+  Float_t absoluteCalib = 0; 
+  // third: info for each tower
+  Float_t relativeCalib[AliEMCALGeoParams::fgkEMCALCols][AliEMCALGeoParams::fgkEMCALRows]; 
+  // end - all values
+
+  // just to make the initializations of the arrays are done correctly, let's use memset
+  memset(relativeCalib, 0, sizeof(relativeCalib)); 
+
+  // declare the branches
+  tree->SetBranchAddress("iSM", &iSM);
+  tree->SetBranchAddress("CalibMethod", &iCalibMethod);
+  tree->SetBranchAddress("CalibPass", &iCalibPass);
+  tree->SetBranchAddress("AbsoluteCalib", &absoluteCalib);
+  //
+  tree->SetBranchAddress("RelativeCalib", relativeCalib);
+
+  // indices for looping over the towers
+  Int_t iCol = 0;
+  Int_t iRow = 0;
+
+  for (int ient=0; ient<tree->GetEntries(); ient++) {
+    tree->GetEntry(ient);
+
+    // assume the index SuperModules come in order: i=iSM
+    AliEMCALSuperModuleCalibAbs * t = (AliEMCALSuperModuleCalibAbs*) fSuperModuleData[iSM];
+
+    t->SetSuperModuleNum(iSM);
+    // first, overall values
+    t->SetCalibMethod(iCalibMethod);
+    t->SetCalibPass(iCalibPass);
+    t->SetAbsoluteCalib(absoluteCalib);
+
+    // third: info for each tower
+    for (Int_t j=0; j<nAPDPerSM; j++) {
+      iCol = j / AliEMCALGeoParams::fgkEMCALRows;
+      iRow = j % AliEMCALGeoParams::fgkEMCALRows;
+
+      // help variables: possibly modified or swapped indices
+      int iColMod = iCol;
+      int iRowMod = iRow;
+      // assume that this info is already swapped and done for this basis?
+      if (swapSides) {
+       // C side, oriented differently than A side: swap is requested
+       iColMod = AliEMCALGeoParams::fgkEMCALCols-1 - iCol;
+       iRowMod = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
+      }
 
-  return fSuperModuleData[supModIndex];
+      t->SetRelativeCalib(iColMod, iRowMod, relativeCalib[iCol][iRow]);
+    }
+
+  } // loop over entries
+
+  return;
 }
 
 //____________________________________________________________________________
-AliEMCALCalibAbs::AliEMCALSuperModuleCalibAbs AliEMCALCalibAbs::GetSuperModuleCalibAbsNum(Int_t supModIndex)const
+void AliEMCALCalibAbs::WriteRootCalibAbsInfo(const TString &rootFileName,
+                                            Bool_t swapSides)
 {
-  AliEMCALSuperModuleCalibAbs 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 *tree = new TTree("tree","");
+
+  // variables for filling the TTree
+  Int_t iSM = 0; // SuperModule index
+  // list of values to be written
+  // first: overall values for the whole SuperModule
+  Int_t iCalibMethod = 0; 
+  Int_t iCalibPass = 0; 
+  Float_t absoluteCalib = 0; 
+  // third: info for each tower
+  Float_t relativeCalib[AliEMCALGeoParams::fgkEMCALCols][AliEMCALGeoParams::fgkEMCALRows]; 
+  // end - all values
 
+  // just to make the initializations of the arrays are done correctly, let's use memset
+  memset(relativeCalib, 0, sizeof(relativeCalib)); 
+
+  Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
+  // for looping over towers
+  Int_t iCol = 0;
+  Int_t iRow = 0;
+
+  // declare the branches
+  // first
+  tree->Branch("iSM", &iSM, "iSM/I");
+  tree->Branch("CalibMethod", &iCalibMethod, "CalibMethod/I");
+  tree->Branch("CalibPass", &iCalibPass, "CalibPass/I");
+  tree->Branch("AbsoluteCalib", &absoluteCalib, "AbsoluteCalib/F");
+  // third: info for each tower; see if a 2D array works OK or if we'll have to use 1D arrays instead 
+  tree->Branch( "RelativeCalib", &relativeCalib, Form("RelativeCalib[%d][%d]/F", AliEMCALGeoParams::fgkEMCALCols, AliEMCALGeoParams::fgkEMCALRows) );
+
+  for (iSM = 0; iSM < fNSuperModule; iSM++) {
+    AliEMCALSuperModuleCalibAbs * t = (AliEMCALSuperModuleCalibAbs*) fSuperModuleData[iSM];
+
+    iSM = t->GetSuperModuleNum();
+    // first, overall values
+    iCalibMethod = t->GetCalibMethod();
+    iCalibPass = t->GetCalibPass();
+    absoluteCalib = t->GetAbsoluteCalib();
+
+    // third: info for each tower
+    for (Int_t j=0; j<nAPDPerSM; j++) {
+      iCol = j / AliEMCALGeoParams::fgkEMCALRows;
+      iRow = j % AliEMCALGeoParams::fgkEMCALRows;
+
+      // help variables: possibly modified or swapped indices
+      int iColMod = iCol;
+      int iRowMod = iRow;
+      // assume that this info is already swapped and done for this basis?
+      if (swapSides) {
+       // C side, oriented differently than A side: swap is requested
+       iColMod = AliEMCALGeoParams::fgkEMCALCols-1 - iCol;
+       iRowMod = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
+      }
+
+      relativeCalib[iColMod][iRowMod] = t->GetRelativeCalib(iCol, iRow);
+    }
+
+    tree->Fill();
+  } // i, SuperModule
+
+  tree->Write();
+  destFile.Close();
+
+  return;
+}
+
+//____________________________________________________________________________
+AliEMCALCalibAbs::~AliEMCALCalibAbs()
+{
+  fSuperModuleData.Delete();
+}
+
+//____________________________________________________________________________
+AliEMCALSuperModuleCalibAbs * AliEMCALCalibAbs::GetSuperModuleCalibAbsNum(Int_t supModIndex)const
+{ // getter via index
   for (int i=0; i<fNSuperModule; i++) {
-    if (fSuperModuleData[i].fSuperModuleNum == supModIndex) {
-      return fSuperModuleData[i];
+    AliEMCALSuperModuleCalibAbs * t = (AliEMCALSuperModuleCalibAbs*) fSuperModuleData[i];
+    if (t->GetSuperModuleNum() == supModIndex) {
+      return t;
     }
   }
 
-  return t;
+  // if we arrived here, then nothing was found.. just return a NULL pointer 
+  return NULL;
 }