LCOV - code coverage report
Current view: top level - EMCAL/EMCALbase - AliEMCALCalibAbs.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 147 0.7 %
Date: 2016-06-14 17:26:59 Functions: 1 12 8.3 %

          Line data    Source code
       1             : /**************************************************************************
       2             :  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
       3             :  *                                                                        *
       4             :  * Author: The ALICE Off-line Project.                                    *
       5             :  * Contributors are mentioned in the code where appropriate.              *
       6             :  *                                                                        *
       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             :  **************************************************************************/
      15             : 
      16             : /* $Id: $ */
      17             : 
      18             : // Objects of this class contain basis for absolute calibrations
      19             : //
      20             : 
      21             : #include <fstream>
      22             : #include <TString.h>
      23             : #include <TFile.h>
      24             : #include <TTree.h>
      25             : 
      26             : #include "AliEMCALCalibAbs.h"
      27             : 
      28             : using namespace std;
      29             : 
      30          42 : ClassImp(AliEMCALCalibAbs)
      31             : 
      32             : //____________________________________________________________________________
      33           0 : AliEMCALCalibAbs::AliEMCALCalibAbs(const int nSM) : 
      34           0 :   fNSuperModule(nSM),
      35           0 :   fSuperModuleData()
      36           0 : {
      37             :   //Default constructor.
      38           0 :   for (int i=0; i<fNSuperModule; i++) {
      39           0 :     fSuperModuleData.Add(new AliEMCALSuperModuleCalibAbs(i));
      40             :   }
      41           0 :   fSuperModuleData.Compress(); // compress the TObjArray
      42           0 :   fSuperModuleData.SetOwner(kTRUE); 
      43           0 : }
      44             : 
      45             : //____________________________________________________________________________
      46             : void AliEMCALCalibAbs::ReadTextCalibAbsInfo(Int_t nSM, const TString &txtFileName,
      47             :                                             Bool_t swapSides)
      48             : {
      49             :   //Read data from txt file. ; coordinates given on SuperModule basis
      50             : 
      51           0 :   std::ifstream inputFile(txtFileName.Data());
      52           0 :   if (!inputFile) {
      53           0 :     printf("AliEMCALCalibAbs::ReadCalibAbsInfo - Cannot open the APD info file %s\n", txtFileName.Data());
      54           0 :     return;
      55             :   }
      56             : 
      57           0 :   fNSuperModule = nSM;
      58             : 
      59           0 :   Int_t iSM = 0; // SuperModule index
      60           0 :   Int_t iCol = 0;
      61           0 :   Int_t iRow = 0;
      62             : 
      63             :   // list of values to be read
      64             :   // first: overall values for the whole SuperModule
      65           0 :   Int_t iCalibMethod = 0; 
      66           0 :   Int_t iCalibPass = 0; 
      67           0 :   Float_t absoluteCalib = 0; 
      68             :   // third: info for each tower
      69           0 :   Float_t relativeCalib = 0; // (ADC>GeV relative gain/conversion), value around 1
      70             :   // end - all values
      71             : 
      72             :   Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
      73             : 
      74           0 :   for (Int_t i = 0; i < fNSuperModule; i++) {
      75           0 :     AliEMCALSuperModuleCalibAbs * t = (AliEMCALSuperModuleCalibAbs*) fSuperModuleData[i];
      76           0 :     if (!inputFile) {
      77           0 :       printf("AliEMCALCalibAbs::ReadCalibAbsInfo - Error while reading input file; likely EOF..\n");
      78           0 :       return;
      79             :     }
      80           0 :     inputFile >> iSM;
      81           0 :     t->SetSuperModuleNum(iSM);
      82             : 
      83             :     // first: overall values for the whole SuperModule
      84           0 :     inputFile >> iCalibMethod >> iCalibPass >> absoluteCalib;
      85           0 :     t->SetCalibMethod(iCalibMethod);
      86           0 :     t->SetCalibPass(iCalibPass);
      87           0 :     t->SetAbsoluteCalib(absoluteCalib);
      88             : 
      89             :     // third: info for each tower
      90           0 :     for (Int_t j=0; j<nAPDPerSM; j++) {
      91           0 :       inputFile >> iCol >> iRow >> relativeCalib;
      92             : 
      93             :       // check that input values are not out bounds
      94           0 :       if (iCol<0 || iCol>(AliEMCALGeoParams::fgkEMCALCols-1) ||
      95           0 :           iRow<0 || iRow>(AliEMCALGeoParams::fgkEMCALRows-1) ) {
      96           0 :         printf("AliEMCALCalibAbs::ReadCalibAbsInfo - Error while reading input file; j %d iCol %d iRow %d\n", j, iCol, iRow);
      97           0 :       return;
      98             :       }
      99             : 
     100             :       // assume that this info is already swapped and done for this basis?
     101           0 :       if (swapSides) {
     102             :         // C side, oriented differently than A side: swap is requested
     103           0 :         iCol = AliEMCALGeoParams::fgkEMCALCols-1 - iCol;
     104           0 :         iRow = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
     105           0 :       }
     106             : 
     107           0 :       t->SetRelativeCalib(iCol, iRow, relativeCalib);
     108             :     }
     109             : 
     110           0 :   } // i, SuperModule
     111             : 
     112           0 :   inputFile.close();
     113             : 
     114           0 :   return;
     115           0 : }
     116             : 
     117             : //____________________________________________________________________________
     118             : void AliEMCALCalibAbs::WriteTextCalibAbsInfo(const TString &txtFileName,
     119             :                                              Bool_t swapSides)
     120             : {
     121             :   // write data to txt file. ; coordinates given on SuperModule basis
     122             : 
     123           0 :   std::ofstream outputFile(txtFileName.Data());
     124           0 :   if (!outputFile) {
     125           0 :     printf("AliEMCALCalibAbs::WriteCalibAbsInfo - Cannot open the APD output file %s\n", txtFileName.Data());
     126           0 :     return;
     127             :   }
     128             : 
     129             :   Int_t iCol = 0;
     130             :   Int_t iRow = 0;
     131             : 
     132             :   Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
     133             :   Float_t relativeCalib = 0;
     134           0 :   for (Int_t i = 0; i < fNSuperModule; i++) {
     135           0 :     AliEMCALSuperModuleCalibAbs * t = (AliEMCALSuperModuleCalibAbs*) fSuperModuleData[i];
     136             : 
     137             :     // first: overall values for the whole SuperModule
     138           0 :     outputFile << t->GetSuperModuleNum() << endl;
     139           0 :     outputFile << t->GetCalibMethod() << " " 
     140           0 :                << t->GetCalibPass() << " " 
     141           0 :                << t->GetAbsoluteCalib() << endl;
     142             : 
     143             :     // third: info for each tower
     144           0 :     for (Int_t j=0; j<nAPDPerSM; j++) {
     145           0 :       iCol = j / AliEMCALGeoParams::fgkEMCALRows;
     146           0 :       iRow = j % AliEMCALGeoParams::fgkEMCALRows;
     147             : 
     148           0 :       relativeCalib = t->GetRelativeCalib(iCol, iRow);
     149             : 
     150           0 :       if (swapSides) {
     151             :         // C side, oriented differently than A side: swap is requested
     152           0 :         iCol = AliEMCALGeoParams::fgkEMCALCols-1 - iCol;
     153           0 :         iRow = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
     154           0 :       }
     155             : 
     156           0 :       outputFile << iCol << " " << iRow 
     157           0 :                  << " " << relativeCalib << endl;
     158             :     }
     159             : 
     160             :   } // i, SuperModule
     161             : 
     162           0 :   outputFile.close();
     163             : 
     164             :   return;
     165           0 : }
     166             : 
     167             : //____________________________________________________________________________
     168             : void AliEMCALCalibAbs::ReadRootCalibAbsInfo(const TString &rootFileName,
     169             :                                             Bool_t swapSides)
     170             : {
     171             :   //Read data from root file. ; coordinates given on SuperModule basis
     172           0 :   TFile inputFile(rootFileName, "read");  
     173             : 
     174           0 :   TTree *tree = (TTree*) inputFile.Get("tree");
     175             : 
     176           0 :   ReadTreeCalibAbsInfo(tree, swapSides);
     177             : 
     178           0 :   inputFile.Close();
     179             : 
     180             :   return;
     181           0 : }
     182             : 
     183             : //____________________________________________________________________________
     184             : void AliEMCALCalibAbs::ReadTreeCalibAbsInfo(TTree *tree,
     185             :                                             Bool_t swapSides)
     186             : {
     187             :   // how many SuperModule's worth of info do we have?
     188             :   Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
     189           0 :   fNSuperModule = tree->GetEntries();
     190             : 
     191           0 :   Int_t iSM = 0; // SuperModule index
     192             :   // list of values to be read
     193             :   // first: overall values for the whole SuperModule
     194           0 :   Int_t iCalibMethod = 0; 
     195           0 :   Int_t iCalibPass = 0; 
     196           0 :   Float_t absoluteCalib = 0; 
     197             :   // third: info for each tower
     198           0 :   Float_t relativeCalib[AliEMCALGeoParams::fgkEMCALCols][AliEMCALGeoParams::fgkEMCALRows]; 
     199             :   // end - all values
     200             : 
     201             :   // just to make the initializations of the arrays are done correctly, let's use memset
     202           0 :   memset(relativeCalib, 0, sizeof(relativeCalib)); 
     203             : 
     204             :   // declare the branches
     205           0 :   tree->SetBranchAddress("iSM", &iSM);
     206           0 :   tree->SetBranchAddress("CalibMethod", &iCalibMethod);
     207           0 :   tree->SetBranchAddress("CalibPass", &iCalibPass);
     208           0 :   tree->SetBranchAddress("AbsoluteCalib", &absoluteCalib);
     209             :   //
     210           0 :   tree->SetBranchAddress("RelativeCalib", relativeCalib);
     211             : 
     212             :   // indices for looping over the towers
     213             :   Int_t iCol = 0;
     214             :   Int_t iRow = 0;
     215             : 
     216           0 :   for (int ient=0; ient<tree->GetEntries(); ient++) {
     217           0 :     tree->GetEntry(ient);
     218             : 
     219             :     // assume the index SuperModules come in order: i=iSM
     220           0 :     AliEMCALSuperModuleCalibAbs * t = (AliEMCALSuperModuleCalibAbs*) fSuperModuleData[iSM];
     221             : 
     222           0 :     t->SetSuperModuleNum(iSM);
     223             :     // first, overall values
     224           0 :     t->SetCalibMethod(iCalibMethod);
     225           0 :     t->SetCalibPass(iCalibPass);
     226           0 :     t->SetAbsoluteCalib(absoluteCalib);
     227             : 
     228             :     // third: info for each tower
     229           0 :     for (Int_t j=0; j<nAPDPerSM; j++) {
     230           0 :       iCol = j / AliEMCALGeoParams::fgkEMCALRows;
     231           0 :       iRow = j % AliEMCALGeoParams::fgkEMCALRows;
     232             : 
     233             :       // help variables: possibly modified or swapped indices
     234             :       int iColMod = iCol;
     235             :       int iRowMod = iRow;
     236             :       // assume that this info is already swapped and done for this basis?
     237           0 :       if (swapSides) {
     238             :         // C side, oriented differently than A side: swap is requested
     239           0 :         iColMod = AliEMCALGeoParams::fgkEMCALCols-1 - iCol;
     240           0 :         iRowMod = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
     241           0 :       }
     242             : 
     243           0 :       t->SetRelativeCalib(iColMod, iRowMod, relativeCalib[iCol][iRow]);
     244             :     }
     245             : 
     246             :   } // loop over entries
     247             : 
     248             :   return;
     249           0 : }
     250             : 
     251             : //____________________________________________________________________________
     252             : void AliEMCALCalibAbs::WriteRootCalibAbsInfo(const TString &rootFileName,
     253             :                                              Bool_t swapSides)
     254             : {
     255             :   // write data to root file. ; coordinates given on SuperModule basis
     256           0 :   TFile destFile(rootFileName, "recreate");  
     257           0 :   if (destFile.IsZombie()) {
     258           0 :     return;
     259             :   }  
     260           0 :   destFile.cd();
     261             : 
     262           0 :   TTree *tree = new TTree("tree","");
     263             : 
     264             :   // variables for filling the TTree
     265           0 :   Int_t iSM = 0; // SuperModule index
     266             :   // list of values to be written
     267             :   // first: overall values for the whole SuperModule
     268           0 :   Int_t iCalibMethod = 0; 
     269           0 :   Int_t iCalibPass = 0; 
     270           0 :   Float_t absoluteCalib = 0; 
     271             :   // third: info for each tower
     272           0 :   Float_t relativeCalib[AliEMCALGeoParams::fgkEMCALCols][AliEMCALGeoParams::fgkEMCALRows]; 
     273             :   // end - all values
     274             : 
     275             :   // just to make the initializations of the arrays are done correctly, let's use memset
     276           0 :   memset(relativeCalib, 0, sizeof(relativeCalib)); 
     277             : 
     278             :   Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
     279             :   // for looping over towers
     280             :   Int_t iCol = 0;
     281             :   Int_t iRow = 0;
     282             : 
     283             :   // declare the branches
     284             :   // first
     285           0 :   tree->Branch("iSM", &iSM, "iSM/I");
     286           0 :   tree->Branch("CalibMethod", &iCalibMethod, "CalibMethod/I");
     287           0 :   tree->Branch("CalibPass", &iCalibPass, "CalibPass/I");
     288           0 :   tree->Branch("AbsoluteCalib", &absoluteCalib, "AbsoluteCalib/F");
     289             :   // third: info for each tower; see if a 2D array works OK or if we'll have to use 1D arrays instead 
     290           0 :   tree->Branch( "RelativeCalib", &relativeCalib, Form("RelativeCalib[%d][%d]/F", AliEMCALGeoParams::fgkEMCALCols, AliEMCALGeoParams::fgkEMCALRows) );
     291             : 
     292           0 :   for (iSM = 0; iSM < fNSuperModule; iSM++) {
     293           0 :     AliEMCALSuperModuleCalibAbs * t = (AliEMCALSuperModuleCalibAbs*) fSuperModuleData[iSM];
     294             : 
     295           0 :     iSM = t->GetSuperModuleNum();
     296             :     // first, overall values
     297           0 :     iCalibMethod = t->GetCalibMethod();
     298           0 :     iCalibPass = t->GetCalibPass();
     299           0 :     absoluteCalib = t->GetAbsoluteCalib();
     300             : 
     301             :     // third: info for each tower
     302           0 :     for (Int_t j=0; j<nAPDPerSM; j++) {
     303           0 :       iCol = j / AliEMCALGeoParams::fgkEMCALRows;
     304           0 :       iRow = j % AliEMCALGeoParams::fgkEMCALRows;
     305             : 
     306             :       // help variables: possibly modified or swapped indices
     307             :       int iColMod = iCol;
     308             :       int iRowMod = iRow;
     309             :       // assume that this info is already swapped and done for this basis?
     310           0 :       if (swapSides) {
     311             :         // C side, oriented differently than A side: swap is requested
     312           0 :         iColMod = AliEMCALGeoParams::fgkEMCALCols-1 - iCol;
     313           0 :         iRowMod = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
     314           0 :       }
     315             : 
     316           0 :       relativeCalib[iColMod][iRowMod] = t->GetRelativeCalib(iCol, iRow);
     317             :     }
     318             : 
     319           0 :     tree->Fill();
     320             :   } // i, SuperModule
     321             : 
     322           0 :   tree->Write();
     323           0 :   destFile.Close();
     324             : 
     325             :   return;
     326           0 : }
     327             : 
     328             : //____________________________________________________________________________
     329             : AliEMCALCalibAbs::~AliEMCALCalibAbs()
     330           0 : {
     331           0 :   fSuperModuleData.Delete();
     332           0 : }
     333             : 
     334             : //____________________________________________________________________________
     335             : AliEMCALSuperModuleCalibAbs * AliEMCALCalibAbs::GetSuperModuleCalibAbsNum(Int_t supModIndex)const
     336             : { // getter via index
     337           0 :   for (int i=0; i<fNSuperModule; i++) {
     338           0 :     AliEMCALSuperModuleCalibAbs * t = (AliEMCALSuperModuleCalibAbs*) fSuperModuleData[i];
     339           0 :     if (t->GetSuperModuleNum() == supModIndex) {
     340           0 :       return t;
     341             :     }
     342           0 :   }
     343             : 
     344             :   // if we arrived here, then nothing was found.. just return a NULL pointer 
     345           0 :   return NULL;
     346           0 : }
     347             : 

Generated by: LCOV version 1.11