LCOV - code coverage report
Current view: top level - EMCAL/EMCALbase - AliCaloCalibPedestal.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 61 701 8.7 %
Date: 2016-06-14 17:26:59 Functions: 4 26 15.4 %

          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             : //* $Id$ */
      16             : 
      17             : //________________________________________________________________________
      18             : //
      19             : // A help class for monitoring and calibration tools: MOOD, AMORE etc.,
      20             : // It can be created and used a la (ctor):
      21             : /*
      22             :   //Create the object for making the histograms
      23             :   fPedestals = new AliCaloCalibPedestal( fDetType );
      24             :   // AliCaloCalibPedestal knows how many modules we have for PHOS or EMCAL
      25             :   fNumModules = fPedestals->GetModules();
      26             : */
      27             : // fed an event:
      28             : //  fPedestals->ProcessEvent(fCaloRawStream);
      29             : // asked to draw histograms:
      30             : //  fPedestals->GetDeadMap(i)->Draw("col");
      31             : // or
      32             : //  fPedestals->GetPeakProfileHighGainRatio((i < fNumModules) ? i : fVisibleModule)->Draw("colz");
      33             : // etc.
      34             : // The pseudo-code examples above were from the first implementation in MOOD (summer 2007).
      35             : //________________________________________________________________________
      36             : 
      37             : //#include "TCanvas.h"
      38             : #include "TH1.h"
      39             : #include "TF1.h"
      40             : #include "TFile.h"
      41             : #include <fstream>
      42             : #include <sstream>
      43             : #include <iostream>
      44             : #include <stdexcept>
      45             : #include <cmath>
      46             : 
      47             : #include "AliRawReader.h"
      48             : #include "AliCaloRawStreamV3.h"
      49             : 
      50             : //The include file
      51             : #include "AliCaloCalibPedestal.h"
      52             : #include "AliDAQ.h"
      53             : 
      54          42 : ClassImp(AliCaloCalibPedestal)
      55             : 
      56             : using namespace std;
      57             : 
      58             : // ctor; initialize everything in order to avoid compiler warnings
      59             : AliCaloCalibPedestal::AliCaloCalibPedestal(kDetType detectorType) :  
      60           3 :   TObject(),
      61           3 :   fPedestalLowGain(),
      62           3 :   fPedestalHighGain(),
      63           3 :   fPedestalLEDRefLowGain(),
      64           3 :   fPedestalLEDRefHighGain(),
      65           3 :   fPeakMinusPedLowGain(),
      66           3 :   fPeakMinusPedHighGain(),
      67           3 :   fPeakMinusPedHighGainHisto(),
      68           3 :   fPedestalLowGainDiff(),
      69           3 :   fPedestalHighGainDiff(),
      70           3 :   fPedestalLEDRefLowGainDiff(),
      71           3 :   fPedestalLEDRefHighGainDiff(),
      72           3 :   fPeakMinusPedLowGainDiff(),
      73           3 :   fPeakMinusPedHighGainDiff(),
      74           3 :   fPedestalLowGainRatio(),
      75           3 :   fPedestalHighGainRatio(),
      76           3 :   fPedestalLEDRefLowGainRatio(),
      77           3 :   fPedestalLEDRefHighGainRatio(),
      78           3 :   fPeakMinusPedLowGainRatio(),
      79           3 :   fPeakMinusPedHighGainRatio(),
      80           3 :   fDeadMap(),
      81           3 :   fNEvents(0),
      82           3 :   fNChanFills(0),
      83           3 :   fDeadTowers(0),
      84           3 :   fNewDeadTowers(0),
      85           3 :   fResurrectedTowers(0),
      86           3 :   fReference(0),
      87           3 :   fDetType(kNone),
      88           3 :   fColumns(0),
      89           3 :   fRows(0),
      90           3 :   fLEDRefs(0),
      91           3 :   fModules(0),
      92           3 :   fRowMin(0),
      93           3 :   fRowMax(0),
      94           3 :   fRowMultiplier(0),
      95           3 :   fCaloString(),
      96           3 :   fMapping(NULL),
      97           3 :   fRunNumber(-1),
      98           3 :   fSelectPedestalSamples(kTRUE), 
      99           3 :   fFirstPedestalSample(0),
     100           3 :   fLastPedestalSample(15),
     101           3 :   fDeadThreshold(5),
     102           3 :   fWarningThreshold(50),
     103           3 :   fWarningFraction(0.002),
     104           3 :   fHotSigma(5)
     105          15 : {
     106             :   //Default constructor. First we set the detector-type related constants.
     107           3 :   if (detectorType == kPhos) {
     108           3 :     fColumns = fgkPhosCols;
     109           3 :     fRows = fgkPhosRows;
     110           3 :     fLEDRefs = fgkPhosLEDRefs;
     111           3 :     fModules = fgkPhosModules;
     112           3 :     fCaloString = "PHOS";
     113           3 :     fRowMin = -1*fRows;
     114           3 :     fRowMax = 0;
     115           3 :     fRowMultiplier = -1;
     116           3 :   } 
     117             :   else {
     118             :     //We'll just trust the enum to keep everything in line, so that if detectorType
     119             :     //isn't kPhos then it is kEmCal. Note, however, that this is not necessarily the
     120             :     //case, if someone intentionally gives another number
     121           0 :     fColumns = AliEMCALGeoParams::fgkEMCALCols;
     122           0 :     fRows = AliEMCALGeoParams::fgkEMCALRows;
     123           0 :     fLEDRefs = AliEMCALGeoParams::fgkEMCALLEDRefs;
     124           0 :     fModules = AliEMCALGeoParams::fgkEMCALModules;
     125           0 :     fCaloString = "EMCAL";
     126           0 :     fRowMin = 0;
     127           0 :     fRowMax = fRows;
     128           0 :     fRowMultiplier = 1;
     129             :   } 
     130           3 :   fDetType = detectorType;
     131             : 
     132             :   // ValidateProfiles(); // not to be done in ctor; info from Axel N. 
     133           6 : }
     134             : 
     135             : //_____________________________________________________________________
     136             : void AliCaloCalibPedestal::ValidateProfiles()
     137             : {
     138             :   //Make sure the basic histos exist
     139        1104 :   if (!fPedestalLowGain.IsEmpty()) return; //The profiles already exist. We just check one, because they're all created at
     140             :   //the same time
     141             : 
     142             :   //Then, loop for the requested number of modules
     143           0 :   TString title, name;
     144           0 :   for (int i = 0; i < fModules; i++) {
     145             :     //Pedestals, low gain
     146           0 :     name = "hPedlowgain";
     147           0 :     name += i;
     148           0 :     title = "Pedestals, low gain, module ";
     149           0 :     title += i; 
     150           0 :     fPedestalLowGain.Add(new TProfile2D(name, title,
     151           0 :                                         fColumns, 0.0, fColumns, 
     152           0 :                                         fRows, fRowMin, fRowMax,"s"));
     153             :   
     154             :     //Pedestals, high gain
     155           0 :     name = "hPedhighgain";
     156           0 :     name += i;
     157           0 :     title = "Pedestals, high gain, module ";
     158           0 :     title += i; 
     159           0 :     fPedestalHighGain.Add(new TProfile2D(name, title,
     160           0 :                                          fColumns, 0.0, fColumns, 
     161           0 :                                          fRows, fRowMin, fRowMax,"s"));
     162             : 
     163             :     //LED Ref/Mon pedestals, low gain
     164           0 :     name = "hPedestalLEDReflowgain";
     165           0 :     name += i;
     166           0 :     title = "Pedestal LEDRef, low gain, module ";
     167           0 :     title += i; 
     168           0 :     fPedestalLEDRefLowGain.Add(new TProfile(name, title,
     169           0 :                                             fLEDRefs, 0.0, fLEDRefs, "s"));
     170             :     
     171             :     //LED Ref/Mon pedestals, high gain
     172           0 :     name = "hPedestalLEDRefhighgain";
     173           0 :     name += i;
     174           0 :     title = "Pedestal LEDRef, high gain, module ";
     175           0 :     title += i; 
     176           0 :     fPedestalLEDRefHighGain.Add(new TProfile(name, title,
     177           0 :                                              fLEDRefs, 0.0, fLEDRefs, "s"));
     178             :   
     179             :     //Peak-Pedestals, low gain
     180           0 :     name = "hPeakMinusPedlowgain";
     181           0 :     name += i;
     182           0 :     title = "Peak-Pedestal, low gain, module ";
     183           0 :     title += i; 
     184           0 :     fPeakMinusPedLowGain.Add(new TProfile2D(name, title,
     185           0 :                                             fColumns, 0.0, fColumns, 
     186           0 :                                             fRows, fRowMin, fRowMax,"s"));
     187             :   
     188             :     //Peak-Pedestals, high gain
     189           0 :     name = "hPeakMinusPedhighgain";
     190           0 :     name += i;
     191           0 :     title = "Peak-Pedestal, high gain, module ";
     192           0 :     title += i; 
     193           0 :     fPeakMinusPedHighGain.Add(new TProfile2D(name, title,
     194           0 :                                              fColumns, 0.0, fColumns, 
     195           0 :                                              fRows, fRowMin, fRowMax,"s"));
     196             : 
     197             :     //Peak-Pedestals, high gain - TH2F histo
     198           0 :     name = "hPeakMinusPedhighgainHisto";
     199           0 :     name += i;
     200           0 :     title = "Peak-Pedestal, high gain, module ";
     201           0 :     title += i; 
     202           0 :     fPeakMinusPedHighGainHisto.Add(new TH2F(name, title,
     203           0 :                                             fColumns*fRows, 0.0, fColumns*fRows, 
     204             :                                             100, 0, 1000));
     205             :  
     206           0 :     name = "hDeadMap";
     207           0 :     name += i;
     208           0 :     title = "Dead map, module ";
     209           0 :     title += i;
     210           0 :     fDeadMap.Add(new TH2D(name, title, fColumns, 0.0, fColumns, 
     211           0 :                           fRows, fRowMin, fRowMax));
     212             :   
     213             :   }//end for nModules create the histograms
     214             : 
     215           0 :   CompressAndSetOwner();
     216         552 : }
     217             : 
     218             : //_____________________________________________________________________
     219             : void AliCaloCalibPedestal::CompressAndSetOwner()
     220             : { 
     221             :   //Compress the arrays, in order to remove the empty objects (a 16 slot array is created by default)
     222           0 :   fPedestalLowGain.Compress();
     223           0 :   fPedestalHighGain.Compress();
     224           0 :   fPedestalLEDRefLowGain.Compress();
     225           0 :   fPedestalLEDRefHighGain.Compress();
     226           0 :   fPeakMinusPedLowGain.Compress();
     227           0 :   fPeakMinusPedHighGain.Compress();
     228           0 :   fPeakMinusPedHighGainHisto.Compress();
     229           0 :   fDeadMap.Compress();
     230             : 
     231             :   // set owner ship for everyone
     232           0 :   fPedestalLowGain.SetOwner(kTRUE);
     233           0 :   fPedestalHighGain.SetOwner(kTRUE);
     234           0 :   fPedestalLEDRefLowGain.SetOwner(kTRUE);
     235           0 :   fPedestalLEDRefHighGain.SetOwner(kTRUE);
     236           0 :   fPeakMinusPedLowGain.SetOwner(kTRUE);
     237           0 :   fPeakMinusPedHighGain.SetOwner(kTRUE);
     238           0 :   fPeakMinusPedHighGainHisto.SetOwner(kTRUE);
     239           0 :   fPedestalLowGainDiff.SetOwner(kTRUE);
     240           0 :   fPedestalHighGainDiff.SetOwner(kTRUE);
     241           0 :   fPedestalLEDRefLowGainDiff.SetOwner(kTRUE);
     242           0 :   fPedestalLEDRefHighGainDiff.SetOwner(kTRUE);
     243           0 :   fPeakMinusPedLowGainDiff.SetOwner(kTRUE);
     244           0 :   fPeakMinusPedHighGainDiff.SetOwner(kTRUE);
     245           0 :   fPedestalLowGainRatio.SetOwner(kTRUE);
     246           0 :   fPedestalHighGainRatio.SetOwner(kTRUE);
     247           0 :   fPedestalLEDRefLowGainRatio.SetOwner(kTRUE);
     248           0 :   fPedestalLEDRefHighGainRatio.SetOwner(kTRUE);
     249           0 :   fPeakMinusPedLowGainRatio.SetOwner(kTRUE);
     250           0 :   fPeakMinusPedHighGainRatio.SetOwner(kTRUE);
     251           0 :   fDeadMap.SetOwner(kTRUE);
     252           0 : }
     253             : 
     254             : // dtor
     255             : //_____________________________________________________________________
     256             : AliCaloCalibPedestal::~AliCaloCalibPedestal()
     257           0 : {
     258             :   //dtor
     259             :   
     260           0 :   if (fReference) delete fReference;//Delete the reference object, if it has been loaded
     261             :   
     262             :   // delete also TObjArray's 
     263           0 :   fPedestalLowGain.Delete(); 
     264           0 :   fPedestalHighGain.Delete();
     265           0 :   fPedestalLEDRefLowGain.Delete();
     266           0 :   fPedestalLEDRefHighGain.Delete();
     267           0 :   fPeakMinusPedLowGain.Delete();
     268           0 :   fPeakMinusPedHighGain.Delete();
     269           0 :   fPeakMinusPedHighGainHisto.Delete();
     270           0 :   fPedestalLowGainDiff.Delete();
     271           0 :   fPedestalHighGainDiff.Delete();
     272           0 :   fPedestalLEDRefLowGainDiff.Delete();
     273           0 :   fPedestalLEDRefHighGainDiff.Delete();
     274           0 :   fPeakMinusPedLowGainDiff.Delete();
     275           0 :   fPeakMinusPedHighGainDiff.Delete();
     276           0 :   fPedestalLowGainRatio.Delete();
     277           0 :   fPedestalHighGainRatio.Delete();
     278           0 :   fPedestalLEDRefLowGainRatio.Delete();
     279           0 :   fPedestalLEDRefHighGainRatio.Delete();
     280           0 :   fPeakMinusPedLowGainRatio.Delete();
     281           0 :   fPeakMinusPedHighGainRatio.Delete();
     282           0 :   fDeadMap.Delete();
     283             :   
     284           0 : }
     285             : 
     286             : // copy ctor
     287             : //_____________________________________________________________________
     288             : AliCaloCalibPedestal::AliCaloCalibPedestal(AliCaloCalibPedestal &ped) :
     289           0 :   TObject(ped),
     290           0 :   fPedestalLowGain(),
     291           0 :   fPedestalHighGain(),
     292           0 :   fPedestalLEDRefLowGain(),
     293           0 :   fPedestalLEDRefHighGain(),
     294           0 :   fPeakMinusPedLowGain(),
     295           0 :   fPeakMinusPedHighGain(),
     296           0 :   fPeakMinusPedHighGainHisto(),
     297           0 :   fPedestalLowGainDiff(),
     298           0 :   fPedestalHighGainDiff(),
     299           0 :   fPedestalLEDRefLowGainDiff(),
     300           0 :   fPedestalLEDRefHighGainDiff(),
     301           0 :   fPeakMinusPedLowGainDiff(),
     302           0 :   fPeakMinusPedHighGainDiff(),
     303           0 :   fPedestalLowGainRatio(),
     304           0 :   fPedestalHighGainRatio(),
     305           0 :   fPedestalLEDRefLowGainRatio(),
     306           0 :   fPedestalLEDRefHighGainRatio(),
     307           0 :   fPeakMinusPedLowGainRatio(),
     308           0 :   fPeakMinusPedHighGainRatio(),
     309           0 :   fDeadMap(),
     310           0 :   fNEvents(ped.GetNEvents()),
     311           0 :   fNChanFills(ped.GetNChanFills()),
     312           0 :   fDeadTowers(ped.GetDeadTowerCount()),
     313           0 :   fNewDeadTowers(ped.GetDeadTowerNew()),
     314           0 :   fResurrectedTowers(ped.GetDeadTowerResurrected()),
     315           0 :   fReference( 0 ), //! note that we do not try to copy the reference info here
     316           0 :   fDetType(ped.GetDetectorType()),
     317           0 :   fColumns(ped.GetColumns()),
     318           0 :   fRows(ped.GetRows()),
     319           0 :   fLEDRefs(ped.GetLEDRefs()),
     320           0 :   fModules(ped.GetModules()),
     321           0 :   fRowMin(ped.GetRowMin()),
     322           0 :   fRowMax(ped.GetRowMax()),
     323           0 :   fRowMultiplier(ped.GetRowMultiplier()),
     324           0 :   fCaloString(ped.GetCaloString()),
     325           0 :   fMapping(NULL), //! note that we are not copying the map info
     326           0 :   fRunNumber(ped.GetRunNumber()),
     327           0 :   fSelectPedestalSamples(ped.GetSelectPedestalSamples()),
     328           0 :   fFirstPedestalSample(ped.GetFirstPedestalSample()),
     329           0 :   fLastPedestalSample(ped.GetLastPedestalSample()),
     330           0 :   fDeadThreshold(ped.GetDeadThreshold()),
     331           0 :   fWarningThreshold(ped.GetWarningThreshold()),
     332           0 :   fWarningFraction(ped.GetWarningFraction()),
     333           0 :   fHotSigma(ped.GetHotSigma())
     334           0 : {
     335             :   // Then the ObjArray ones; we add the histograms rather than trying TObjArray = assignment
     336             :   //DS: this has not really been tested yet..
     337           0 :   for (int i = 0; i < fModules; i++) {
     338           0 :     fPedestalLowGain.Add( ped.GetPedProfileLowGain(i) );
     339           0 :     fPedestalHighGain.Add( ped.GetPedProfileHighGain(i) );
     340           0 :     fPedestalLEDRefLowGain.Add( ped.GetPedLEDRefProfileLowGain(i) );
     341           0 :     fPedestalLEDRefHighGain.Add( ped.GetPedLEDRefProfileHighGain(i) );
     342           0 :     fPeakMinusPedLowGain.Add( ped.GetPeakProfileLowGain(i) );
     343           0 :     fPeakMinusPedHighGain.Add( ped.GetPeakProfileHighGain(i) );
     344           0 :     fPeakMinusPedHighGainHisto.Add( ped.GetPeakHighGainHisto(i) );
     345             : 
     346           0 :     fDeadMap.Add( ped.GetDeadMap(i) );  
     347             :   }//end for nModules 
     348             :  
     349           0 :   CompressAndSetOwner();
     350           0 : }
     351             : 
     352             : // assignment operator; use copy ctor to make life easy..
     353             : //_____________________________________________________________________
     354             : AliCaloCalibPedestal& AliCaloCalibPedestal::operator = (AliCaloCalibPedestal &source)
     355             : {
     356             :   // assignment operator; use copy ctor
     357           0 :   if (&source == this) return *this;
     358             : 
     359           0 :   new (this) AliCaloCalibPedestal(source);
     360           0 :   return *this;
     361           0 : }
     362             : 
     363             : //_____________________________________________________________________
     364             : void AliCaloCalibPedestal::Reset()
     365             : {   // Reset all arrays/histograms
     366           0 :   ValidateProfiles(); // make sure histos/profiles exist
     367           0 :   for (int i = 0; i < fModules; i++) {
     368           0 :     GetPedProfileLowGain(i)->Reset();
     369           0 :     GetPedProfileHighGain(i)->Reset();
     370           0 :     GetPedLEDRefProfileLowGain(i)->Reset();
     371           0 :     GetPedLEDRefProfileHighGain(i)->Reset();
     372           0 :     GetPeakProfileLowGain(i)->Reset();
     373           0 :     GetPeakProfileHighGain(i)->Reset();
     374           0 :     GetPeakHighGainHisto(i)->Reset();
     375           0 :     GetDeadMap(i)->Reset();
     376             :     
     377           0 :     if (!fPedestalLowGainDiff.IsEmpty()) {
     378             :       //This means that the comparison profiles have been created.
     379             :   
     380           0 :       GetPedProfileLowGainDiff(i)->Reset();
     381           0 :       GetPedProfileHighGainDiff(i)->Reset();
     382           0 :       GetPedLEDRefProfileLowGainDiff(i)->Reset();
     383           0 :       GetPedLEDRefProfileHighGainDiff(i)->Reset();
     384           0 :       GetPeakProfileLowGainDiff(i)->Reset();
     385           0 :       GetPeakProfileHighGainDiff(i)->Reset();
     386             :       
     387           0 :       GetPedProfileLowGainRatio(i)->Reset();
     388           0 :       GetPedProfileHighGainRatio(i)->Reset();
     389           0 :       GetPedLEDRefProfileLowGainRatio(i)->Reset();
     390           0 :       GetPedLEDRefProfileHighGainRatio(i)->Reset();
     391           0 :       GetPeakProfileLowGainRatio(i)->Reset();
     392           0 :       GetPeakProfileHighGainRatio(i)->Reset();
     393           0 :     }
     394             :   }
     395           0 :   fNEvents = 0;
     396           0 :   fNChanFills = 0;
     397           0 :   fDeadTowers = 0;
     398           0 :   fNewDeadTowers = 0;
     399           0 :   fResurrectedTowers = 0;
     400             :  
     401             :   //To think about: should fReference be deleted too?... let's not do it this time, at least...
     402           0 : }
     403             : 
     404             : // Parameter/cut handling
     405             : //_____________________________________________________________________
     406             : void AliCaloCalibPedestal::SetParametersFromFile(const char *parameterFile)
     407             : {  
     408             :   // Note: this method is a bit more complicated than it really has to be
     409             :   // - allowing for multiple entries per line, arbitrary order of the
     410             :   // different variables etc. But I wanted to try and do this in as
     411             :   // correct a C++ way as I could (as an exercise).
     412             : 
     413           0 :   static const string delimitor("::");
     414             :         
     415             :   // open, check input file
     416           0 :   ifstream in( parameterFile );
     417           0 :   if( !in ) {
     418           0 :     printf("in AliCaloCalibPedestal::SetParametersFromFile - Using default/run_time parameters.\n");
     419           0 :     return;
     420             :   } 
     421             : 
     422             : 
     423             :   // read in
     424           0 :   char readline[1024];
     425           0 :   while ((in.rdstate() & ios::failbit) == 0 ) {
     426             :     
     427             :     // Read into the raw char array and then construct a string
     428             :     // to do the searching
     429           0 :     in.getline(readline, 1024);
     430           0 :     istringstream s(readline);          
     431             :                 
     432           0 :     while ( ( s.rdstate() & ios::failbit ) == 0 ) {
     433             :                         
     434           0 :       string keyValue; 
     435           0 :       s >> keyValue;
     436             :       
     437             :       // check stream status
     438           0 :       if( ( s.rdstate() & ios::failbit ) == ios::failbit) break;
     439             :                         
     440             :       // skip rest of line if comments found
     441           0 :       if( keyValue.substr( 0, 2 ) == "//" ) break;
     442             :                         
     443             :       // look for "::" in keyValue pair
     444           0 :       size_t position = keyValue.find( delimitor );
     445           0 :       if( position == string::npos ) {
     446           0 :         printf("wrong format for key::value pair: %s\n", keyValue.c_str());
     447             :       }
     448             :                                 
     449             :       // split keyValue pair
     450           0 :       string key( keyValue.substr( 0, position ) );
     451           0 :       string value( keyValue.substr( position+delimitor.size(), 
     452           0 :                                       keyValue.size()-delimitor.size() ) );
     453             :                         
     454             :       // check value does not contain a new delimitor
     455           0 :       if( value.find( delimitor ) != string::npos ) {
     456           0 :         printf("wrong format for key::value pair: %s\n", keyValue.c_str());
     457             :       }
     458             :       
     459             :       // debug: check key value pair
     460             :       // printf("AliCaloCalibPedestal::SetParametersFromFile - key %s value %s\n", key.c_str(), value.c_str());
     461             : 
     462             :       // if the key matches with something we expect, we assign the new value
     463           0 :       istringstream iss(value);
     464             :       // the comparison strings defined at the beginning of this method
     465           0 :       if ( (key == "fFirstPedestalSample") || (key == "fLastPedestalSample") || (key == "fDeadThreshold") || (key == "fWarningThreshold") || (key == "fWarningFraction") || (key == "fHotSigma") ) {
     466           0 :         printf("AliCaloCalibPedestal::SetParametersFromFile - key %s value %s\n", key.c_str(), value.c_str());
     467             : 
     468           0 :         if (key == "fFirstPedestalSample") { 
     469           0 :           iss >> fFirstPedestalSample; 
     470             :         }
     471           0 :         else if (key == "fLastPedestalSample") { 
     472           0 :           iss >> fLastPedestalSample; 
     473             :         }
     474           0 :         else if (key == "fDeadThreshold") { 
     475           0 :           iss >> fDeadThreshold; 
     476             :         }
     477           0 :         else if (key == "fWarningThreshold") { 
     478           0 :           iss >> fWarningThreshold; 
     479             :         }
     480           0 :         else if (key == "fWarningFraction") { 
     481           0 :           iss >> fWarningFraction; 
     482             :         }
     483           0 :         else if (key == "fHotSigma") { 
     484           0 :           iss >> fHotSigma; 
     485             :         }
     486             : 
     487             :       } // some match
     488             : 
     489           0 :     }           
     490           0 :   }
     491             : 
     492           0 :   in.close();
     493             :   return;
     494             :         
     495           0 : }
     496             : 
     497             : //_____________________________________________________________________
     498             : void AliCaloCalibPedestal::WriteParametersToFile(const char *parameterFile)
     499             : {
     500             :   //Write parameters in file.
     501             :         
     502           0 :   static const string delimitor("::");
     503           0 :   ofstream out( parameterFile );
     504           0 :   out << "// " << parameterFile << endl;
     505           0 :   out << "fFirstPedestalSample" << "::" << fFirstPedestalSample << endl;
     506           0 :   out << "fLastPedestalSample" << "::" << fLastPedestalSample << endl;
     507           0 :   out << "fDeadThreshold" << "::" << fDeadThreshold << endl;
     508           0 :   out << "fWarningThreshold" << "::" << fWarningThreshold << endl;
     509           0 :   out << "fWarningFraction" << "::" << fWarningFraction << endl;
     510           0 :   out << "fHotSigma" << "::" << fHotSigma << endl;
     511             : 
     512           0 :   out.close();
     513             :   return;
     514           0 : }
     515             : 
     516             : //_____________________________________________________________________
     517             : Bool_t AliCaloCalibPedestal::AddInfo(AliCaloCalibPedestal *ped)
     518             : {
     519             :   // just do this for the basic histograms/profiles that get filled in ProcessEvent
     520             :   // may not have data for all modules, but let's just Add everything..
     521           0 :   ValidateProfiles(); // make sure histos/profiles exist
     522             : 
     523           0 :   for (int i = 0; i < fModules; i++) {
     524           0 :     GetPedProfileLowGain(i)->Add( ped->GetPedProfileLowGain(i) );
     525           0 :     GetPedProfileHighGain(i)->Add( ped->GetPedProfileHighGain(i) );
     526           0 :     GetPedLEDRefProfileLowGain(i)->Add( ped->GetPedLEDRefProfileLowGain(i) );
     527           0 :     GetPedLEDRefProfileHighGain(i)->Add( ped->GetPedLEDRefProfileHighGain(i) );
     528           0 :     GetPeakProfileLowGain(i)->Add( ped->GetPeakProfileLowGain(i) );
     529           0 :     GetPeakProfileHighGain(i)->Add( ped->GetPeakProfileHighGain(i) );
     530           0 :     GetPeakHighGainHisto(i)->Add( ped->GetPeakHighGainHisto(i) );
     531             :   }//end for nModules 
     532             : 
     533             :   // We should also copy other pieces of info: counters and parameters 
     534             :   // (not number of columns and rows etc which should be the same)
     535             :   // note that I just assign them here rather than Add them, but we
     536             :   // normally just Add (e.g. in Preprocessor) one object so this should be fine.
     537           0 :   fNEvents = ped->GetNEvents();
     538           0 :   fNChanFills = ped->GetNChanFills();
     539           0 :   fDeadTowers = ped->GetDeadTowerCount();
     540           0 :   fNewDeadTowers = ped->GetDeadTowerNew();
     541           0 :   fResurrectedTowers = ped->GetDeadTowerResurrected();
     542           0 :   fRunNumber = ped->GetRunNumber();
     543           0 :   fSelectPedestalSamples = ped->GetSelectPedestalSamples();
     544           0 :   fFirstPedestalSample = ped->GetFirstPedestalSample();
     545           0 :   fLastPedestalSample = ped->GetLastPedestalSample();
     546           0 :   fDeadThreshold = ped->GetDeadThreshold();
     547           0 :   fWarningThreshold = ped->GetWarningThreshold();
     548           0 :   fWarningFraction = ped->GetWarningFraction();
     549           0 :   fHotSigma = ped->GetHotSigma();
     550             : 
     551             :   // DeadMap; Diff profiles etc would need to be redone after this operation
     552             : 
     553           0 :   return kTRUE;//We succesfully added info from the supplied object
     554             : }
     555             : 
     556             : //_____________________________________________________________________
     557             : Bool_t AliCaloCalibPedestal::ProcessEvent(AliRawReader *rawReader)
     558             : { 
     559             :   // if fMapping is NULL the rawstream will crate its own mapping
     560           0 :   AliCaloRawStreamV3 rawStream(rawReader, fCaloString, (AliAltroMapping**)fMapping);
     561           0 :   if (fDetType == kEmCal) {
     562           0 :     rawReader->Select("EMCAL",0,AliDAQ::GetFirstSTUDDL()-1) ; //select EMCAL DDL range 
     563             :   }
     564           0 :   return ProcessEvent(&rawStream);
     565           0 : }
     566             : 
     567             : //_____________________________________________________________________
     568             : Bool_t AliCaloCalibPedestal::ProcessEvent(AliCaloRawStreamV3 *in)
     569             : { 
     570             :   // Method to process=analyze one event in the data stream
     571           0 :   if (!in) return kFALSE; //Return right away if there's a null pointer
     572           0 :   in->Reset(); // just in case the next customer forgets to check if the stream was reset..
     573             : 
     574           0 :   fNEvents++; // one more event
     575             : 
     576           0 :   if (fNEvents==1) ValidateProfiles(); // 1st event, make sure histos/profiles exist
     577             :   
     578             :   // indices for the reading
     579             :   int sample = 0;
     580             :   int time = 0;
     581             :   int i = 0; // sample counter
     582             :   int startBin = 0;
     583             : 
     584             :   // start loop over input stream 
     585           0 :   while (in->NextDDL()) {
     586           0 :     while (in->NextChannel()) {
     587             : 
     588             :       // counters
     589             :       int max = AliEMCALGeoParams::fgkSampleMin, min = AliEMCALGeoParams::fgkSampleMax; // min and max sample values
     590             :       int nsamples = 0;
     591             : 
     592             :       // pedestal samples
     593             :       int nPed = 0;
     594           0 :       vector<int> pedSamples; 
     595             : 
     596           0 :       while (in->NextBunch()) {
     597           0 :         const UShort_t *sig = in->GetSignals();
     598           0 :         startBin = in->GetStartTimeBin();
     599           0 :         nsamples += in->GetBunchLength();
     600           0 :         for (i = 0; i < in->GetBunchLength(); i++) {
     601           0 :           sample = sig[i];
     602           0 :           time = startBin--;
     603             : 
     604             :           // check if it's a min or max value
     605           0 :           if (sample < min) min = sample;
     606           0 :           if (sample > max) max = sample;
     607             :           
     608             :           // should we add it for the pedestal calculation?
     609           0 :           if ( (fFirstPedestalSample<=time && time<=fLastPedestalSample) || // sample time in range
     610           0 :                !fSelectPedestalSamples ) { // or we don't restrict the sample range.. - then we'll take all 
     611           0 :             pedSamples.push_back( sig[i] );
     612           0 :             nPed++;
     613           0 :           }
     614             :           
     615             :         } // loop over samples in bunch
     616             :       } // loop over bunches
     617             : 
     618           0 :       if (nsamples > 0) { // this check is needed for when we have zero-supp. on, but not sparse readout
     619             : 
     620             :       // it should be enough to check the SuperModule info for each DDL really, but let's keep it here for now
     621           0 :       int arrayPos = in->GetModule(); //The modules are numbered starting from 0
     622           0 :       if (arrayPos >= fModules) {
     623             :         //TODO: return an error message, if appopriate (perhaps if debug>0?)
     624           0 :         return kFALSE;
     625             :       }     
     626             :       //Debug
     627           0 :       if (arrayPos < 0 || arrayPos >= fModules) {
     628           0 :         printf("Oh no: arrayPos = %i.\n", arrayPos); 
     629             :       }
     630             :       
     631           0 :       fNChanFills++; // one more channel found, and profile to be filled
     632             :       //NOTE: coordinates are (column, row) for the profiles
     633           0 :       if ( in->IsLowGain() ) {
     634             :         //fill the low gain histograms
     635           0 :         ((TProfile2D*)fPeakMinusPedLowGain[arrayPos])->Fill(in->GetColumn(), fRowMultiplier*in->GetRow(), max - min);
     636           0 :         if (nPed>0) { // only fill pedestal info in case it could be calculated
     637           0 :           for ( i=0; i<nPed; i++) {
     638           0 :             ((TProfile2D*)fPedestalLowGain[arrayPos])->Fill(in->GetColumn(), fRowMultiplier*in->GetRow(), pedSamples[i]); 
     639             :           }
     640             :         }
     641             :       } 
     642           0 :       else if ( in->IsHighGain() ) { 
     643             :         //fill the high gain ones
     644           0 :         ((TProfile2D*)fPeakMinusPedHighGain[arrayPos])->Fill(in->GetColumn(), fRowMultiplier*in->GetRow(), max - min);
     645           0 :         if (nPed>0) { // only fill pedestal info in case it could be calculated
     646           0 :           for ( i=0; i<nPed; i++) {
     647           0 :             ((TProfile2D*)fPedestalHighGain[arrayPos])->Fill(in->GetColumn(), fRowMultiplier*in->GetRow(), pedSamples[i]); 
     648             :           }       
     649             :         }
     650             :         // for warning checks
     651           0 :         int idx = in->GetRow() + fRows * in->GetColumn();
     652           0 :         ((TH2F*)fPeakMinusPedHighGainHisto[arrayPos])->Fill(idx, max - min);
     653           0 :       } 
     654           0 :       else if ( in->IsLEDMonData() ) {
     655             :         // for LED Mon data, the mapping class holds the gain info in the Row variable
     656             :         // and the Strip number in the Column..
     657           0 :         int gain = in->GetRow(); 
     658           0 :         int stripId = in->GetColumn();
     659           0 :         if (nPed>0 && stripId<fLEDRefs) {
     660           0 :           if (gain == 0) {
     661           0 :             for ( i=0; i<nPed; i++) {
     662           0 :               ((TProfile*)fPedestalLEDRefLowGain[arrayPos])->Fill(stripId, pedSamples[i]);
     663             :             }
     664             :           }
     665             :           else {
     666           0 :             for ( i=0; i<nPed; i++) {
     667           0 :               ((TProfile*)fPedestalLEDRefHighGain[arrayPos])->Fill(stripId, pedSamples[i]);
     668             :             }
     669             :           }
     670             :         }
     671           0 :       }
     672             : 
     673           0 :       } // nsamples>0 check, some data found for this channel; not only trailer/header
     674           0 :     }// end while over channel   
     675             :   }//end while over DDL's, of input stream 
     676             : 
     677             :  
     678           0 :   return kTRUE;
     679           0 : }
     680             : 
     681             : //_____________________________________________________________________
     682             : Bool_t AliCaloCalibPedestal::SaveHistograms(TString fileName, Bool_t saveEmptyHistos)
     683             : {
     684             :   //Saves all the histograms (or profiles, to be accurate) to the designated file
     685           0 :   ValidateProfiles(); // make sure histos/profiles exist
     686           0 :   TFile destFile(fileName, "recreate");
     687             :   
     688           0 :   if (destFile.IsZombie()) {
     689           0 :     return kFALSE;
     690             :   }
     691             :   
     692           0 :   destFile.cd();
     693             :   
     694           0 :   for (int i = 0; i < fModules; i++) {
     695           0 :     if( ((TProfile2D *)fPeakMinusPedLowGain[i])->GetEntries() || saveEmptyHistos) {
     696           0 :       fPeakMinusPedLowGain[i]->Write();
     697             :     }
     698           0 :     if( ((TProfile2D *)fPeakMinusPedHighGain[i])->GetEntries() || saveEmptyHistos) { 
     699           0 :       fPeakMinusPedHighGain[i]->Write();
     700             :     }
     701           0 :     if( ((TProfile2D *)fPedestalLowGain[i])->GetEntries() || saveEmptyHistos) {
     702           0 :       fPedestalLowGain[i]->Write();
     703             :     }
     704           0 :     if( ((TProfile2D *)fPedestalHighGain[i])->GetEntries() || saveEmptyHistos) {
     705           0 :       fPedestalHighGain[i]->Write();
     706             :     }
     707           0 :     if( ((TProfile *)fPedestalLEDRefLowGain[i])->GetEntries() || saveEmptyHistos) {
     708           0 :       fPedestalLEDRefLowGain[i]->Write();
     709             :     }
     710           0 :     if( ((TProfile *)fPedestalLEDRefHighGain[i])->GetEntries() || saveEmptyHistos) {
     711           0 :       fPedestalLEDRefHighGain[i]->Write();
     712             :     }
     713           0 :     if( ((TH2F *)fPeakMinusPedHighGainHisto[i])->GetEntries() || saveEmptyHistos) { 
     714           0 :       fPeakMinusPedHighGainHisto[i]->Write();
     715             :     }
     716             : 
     717             :   } 
     718             :   
     719           0 :   destFile.Close();
     720             :   
     721           0 :   return kTRUE;
     722           0 : }
     723             : 
     724             : //_____________________________________________________________________
     725             : Bool_t AliCaloCalibPedestal::LoadReferenceCalib(TString fileName, TString objectName)
     726             : {
     727             :   
     728             :   //Make sure that the histograms created when loading the object are not destroyed as the file object is destroyed
     729           0 :   TH1::AddDirectory(kFALSE);
     730             :   
     731           0 :   TFile *sourceFile = new TFile(fileName);
     732           0 :   if (sourceFile->IsZombie()) {
     733           0 :     return kFALSE;//We couldn't load the reference
     734             :   }
     735             : 
     736           0 :   if (fReference) delete fReference;//Delete the reference object, if it already exists
     737           0 :   fReference = 0;
     738             :   
     739           0 :   fReference = (AliCaloCalibPedestal*)sourceFile->Get(objectName);
     740             :  
     741           0 :   if (!fReference || !(fReference->InheritsFrom(AliCaloCalibPedestal::Class())) || (fReference->GetDetectorType() != fDetType)) {
     742           0 :     if (fReference) delete fReference;//Delete the object, in case we had an object of the wrong type
     743           0 :     fReference = 0;
     744           0 :     return kFALSE;
     745             :   }
     746             :         
     747           0 :   delete sourceFile;
     748             : 
     749             :   //Reset the histogram ownership behaviour. NOTE: a better workaround would be good, since this may accidentally set AddDirectory to true, even
     750             :   //if we are called by someone who has set it to false...
     751           0 :   TH1::AddDirectory(kTRUE);
     752             :  
     753           0 :   return kTRUE;//We succesfully loaded the object
     754           0 : }
     755             : 
     756             : 
     757             : //_____________________________________________________________________
     758             : Bool_t AliCaloCalibPedestal::SetReference(AliCaloCalibPedestal *ref)
     759             : { // set reference object
     760           0 :   if (fReference) delete fReference;//Delete the reference object, if it already exists
     761             :   fReference = 0;
     762             :   
     763           0 :   fReference = ref;
     764             :  
     765           0 :   if (!fReference || (fReference->GetDetectorType() != fDetType)) {
     766           0 :     if (fReference) delete fReference;//Delete the object, in case we had an object of the wrong type
     767           0 :     fReference = 0;
     768           0 :     return kFALSE;
     769             :   }
     770             : 
     771           0 :   return kTRUE;//We succesfully loaded the object
     772           0 : }
     773             : 
     774             : //_____________________________________________________________________
     775             : void AliCaloCalibPedestal::ValidateComparisonProfiles()
     776             : {
     777             :   //Make sure the comparison histos exist
     778           0 :   if (!fPedestalLowGainDiff.IsEmpty()) return; //The profiles already exist. We just check one, because they're all created at
     779             :   //the same time
     780             :                                                 
     781             :                                                 
     782             :   //Then, loop for the requested number of modules
     783           0 :   TString title, name;
     784           0 :   for (int i = 0; i < fModules; i++) {
     785             :     //Pedestals, low gain
     786           0 :     name = "hPedlowgainDiff";
     787           0 :     name += i;
     788           0 :     title = "Pedestals difference, low gain, module ";
     789           0 :     title += i; 
     790           0 :     fPedestalLowGainDiff.Add(new TProfile2D(name, title,
     791           0 :                                             fColumns, 0.0, fColumns, 
     792           0 :                                             fRows, fRowMin, fRowMax,"s"));
     793             :   
     794             :     //Pedestals, high gain
     795           0 :     name = "hPedhighgainDiff";
     796           0 :     name += i;
     797           0 :     title = "Pedestals difference, high gain, module ";
     798           0 :     title += i; 
     799           0 :     fPedestalHighGainDiff.Add(new TProfile2D(name, title,
     800           0 :                                              fColumns, 0.0, fColumns, 
     801           0 :                                              fRows, fRowMin, fRowMax,"s"));
     802             : 
     803             :     //LED Ref/Mon pedestals, low gain
     804           0 :     name = "hPedestalLEDReflowgainDiff";
     805           0 :     name += i;
     806           0 :     title = "Pedestal difference LEDRef, low gain, module ";
     807           0 :     title += i; 
     808           0 :     fPedestalLEDRefLowGainDiff.Add(new TProfile(name, title,
     809           0 :                                                 fLEDRefs, 0.0, fLEDRefs, "s"));
     810             :     
     811             :     //LED Ref/Mon pedestals, high gain
     812           0 :     name = "hPedestalLEDRefhighgainDiff";
     813           0 :     name += i;
     814           0 :     title = "Pedestal difference LEDRef, high gain, module ";
     815           0 :     title += i; 
     816           0 :     fPedestalLEDRefHighGainDiff.Add(new TProfile(name, title,
     817           0 :                                                  fLEDRefs, 0.0, fLEDRefs, "s"));
     818             : 
     819             :     //Peak-Pedestals, high gain
     820           0 :     name = "hPeakMinusPedhighgainDiff";
     821           0 :     name += i;
     822           0 :     title = "Peak-Pedestal difference, high gain, module ";
     823           0 :     title += i; 
     824           0 :     fPeakMinusPedHighGainDiff.Add(new TProfile2D(name, title,
     825           0 :                                                  fColumns, 0.0, fColumns, 
     826           0 :                                                  fRows, fRowMin, fRowMax,"s"));
     827             : 
     828             :     //Peak-Pedestals, low gain
     829           0 :     name = "hPeakMinusPedlowgainDiff";
     830           0 :     name += i;
     831           0 :     title = "Peak-Pedestal difference, low gain, module ";
     832           0 :     title += i; 
     833           0 :     fPeakMinusPedLowGainDiff.Add(new TProfile2D(name, title,
     834           0 :                                                 fColumns, 0.0, fColumns, 
     835           0 :                                                 fRows, fRowMin, fRowMax,"s"));
     836             :   
     837             :     //Pedestals, low gain
     838           0 :     name = "hPedlowgainRatio";
     839           0 :     name += i;
     840           0 :     title = "Pedestals ratio, low gain, module ";
     841           0 :     title += i; 
     842           0 :     fPedestalLowGainRatio.Add(new TProfile2D(name, title,
     843           0 :                                              fColumns, 0.0, fColumns, 
     844           0 :                                              fRows, fRowMin, fRowMax,"s"));
     845             :   
     846             :     //Pedestals, high gain
     847           0 :     name = "hPedhighgainRatio";
     848           0 :     name += i;
     849           0 :     title = "Pedestals ratio, high gain, module ";
     850           0 :     title += i; 
     851           0 :     fPedestalHighGainRatio.Add(new TProfile2D(name, title,
     852           0 :                                               fColumns, 0.0, fColumns, 
     853           0 :                                               fRows, fRowMin, fRowMax,"s"));
     854             : 
     855             :     //LED Ref/Mon pedestals, low gain
     856           0 :     name = "hPedestalLEDReflowgainRatio";
     857           0 :     name += i;
     858           0 :     title = "Pedestal ratio LEDRef, low gain, module ";
     859           0 :     title += i; 
     860           0 :     fPedestalLEDRefLowGainRatio.Add(new TProfile(name, title,
     861           0 :                                                  fLEDRefs, 0.0, fLEDRefs, "s"));
     862             :     
     863             :     //LED Ref/Mon pedestals, high gain
     864           0 :     name = "hPedestalLEDRefhighgainRatio";
     865           0 :     name += i;
     866           0 :     title = "Pedestal ratio LEDRef, high gain, module ";
     867           0 :     title += i; 
     868           0 :     fPedestalLEDRefHighGainRatio.Add(new TProfile(name, title,
     869           0 :                                                   fLEDRefs, 0.0, fLEDRefs, "s"));
     870             :   
     871             :     //Peak-Pedestals, low gain
     872           0 :     name = "hPeakMinusPedlowgainRatio";
     873           0 :     name += i;
     874           0 :     title = "Peak-Pedestal ratio, low gain, module ";
     875           0 :     title += i; 
     876           0 :     fPeakMinusPedLowGainRatio.Add(new TProfile2D(name, title,
     877           0 :                                                  fColumns, 0.0, fColumns, 
     878           0 :                                                  fRows, fRowMin, fRowMax,"s"));
     879             :   
     880             :     //Peak-Pedestals, high gain
     881           0 :     name = "hPeakMinusPedhighgainRatio";
     882           0 :     name += i;
     883           0 :     title = "Peak-Pedestal ratio, high gain, module ";
     884           0 :     title += i; 
     885           0 :     fPeakMinusPedHighGainRatio.Add(new TProfile2D(name, title,
     886           0 :                                                   fColumns, 0.0, fColumns, 
     887           0 :                                                   fRows, fRowMin, fRowMax,"s"));
     888             :     
     889             :   }//end for nModules create the histograms
     890           0 : }
     891             : 
     892             : //_____________________________________________________________________
     893             : void AliCaloCalibPedestal::ComputeDiffAndRatio()
     894             : { // calculate differences and ratios relative to a reference
     895           0 :   ValidateProfiles(); // make sure histos/profiles exist
     896           0 :   ValidateComparisonProfiles();//Make sure the comparison histos exist
     897             :  
     898           0 :   if (!fReference) {
     899             :     return;//Return if the reference object isn't loaded
     900             :   }
     901             : 
     902             :   int bin = 0;
     903             :   double diff = 0;
     904             :   double ratio = 1;
     905           0 :   for (int i = 0; i < fModules; i++) {
     906             :     //For computing the difference, we cannot simply do TProfile2D->Add(), because that subtracts the sum of all entries,
     907             :     //which means that the mean of the new profile will not be the difference of the means. So do it by hand:
     908           0 :     for (int j = 0; j < fColumns; j++) {
     909           0 :       for (int k = 0; k < fRows; k++) {
     910           0 :         bin = ((TProfile2D*)fPeakMinusPedHighGainDiff[i])->GetBin(j+1, k+1);//Note that we assume here that all histos have the same structure...
     911             : 
     912           0 :         if (fReference->GetPeakProfileHighGain(i)->GetBinContent(bin) > 0) {
     913           0 :           diff = GetPeakProfileHighGain(i)->GetBinContent(bin) - fReference->GetPeakProfileHighGain(i)->GetBinContent(bin);
     914           0 :           ((TProfile2D*)fPeakMinusPedHighGainDiff[i])->SetBinContent(bin, diff);
     915           0 :           ((TProfile2D*)fPeakMinusPedHighGainDiff[i])->SetBinEntries(bin, 1);
     916           0 :           ratio = GetPeakProfileHighGain(i)->GetBinContent(bin) / fReference->GetPeakProfileHighGain(i)->GetBinContent(bin);  
     917           0 :           ((TProfile2D*)fPeakMinusPedHighGainRatio[i])->SetBinContent(bin, ratio);
     918           0 :           ((TProfile2D*)fPeakMinusPedHighGainRatio[i])->SetBinEntries(bin, 1);
     919           0 :         }
     920             : 
     921           0 :         if (fReference->GetPeakProfileLowGain(i)->GetBinContent(bin) > 0) {
     922           0 :           diff = GetPeakProfileLowGain(i)->GetBinContent(bin) - fReference->GetPeakProfileLowGain(i)->GetBinContent(bin);
     923           0 :           ((TProfile2D*)fPeakMinusPedLowGainDiff[i])->SetBinContent(bin, diff);
     924           0 :           ((TProfile2D*)fPeakMinusPedLowGainDiff[i])->SetBinEntries(bin, 1);
     925           0 :           ratio = GetPeakProfileLowGain(i)->GetBinContent(bin) / fReference->GetPeakProfileLowGain(i)->GetBinContent(bin);  
     926           0 :           ((TProfile2D*)fPeakMinusPedLowGainRatio[i])->SetBinContent(bin, ratio);
     927           0 :           ((TProfile2D*)fPeakMinusPedLowGainRatio[i])->SetBinEntries(bin, 1);
     928           0 :         }
     929             : 
     930           0 :         if (fReference->GetPedProfileHighGain(i)->GetBinContent(bin) > 0) {
     931           0 :           diff = GetPedProfileHighGain(i)->GetBinContent(bin) - fReference->GetPedProfileHighGain(i)->GetBinContent(bin);
     932           0 :           ((TProfile2D*)fPedestalHighGainDiff[i])->SetBinContent(bin, diff);
     933           0 :           ((TProfile2D*)fPedestalHighGainDiff[i])->SetBinEntries(bin, 1);
     934           0 :           ratio = GetPedProfileHighGain(i)->GetBinContent(bin) / fReference->GetPedProfileHighGain(i)->GetBinContent(bin);  
     935           0 :           ((TProfile2D*)fPedestalHighGainRatio[i])->SetBinContent(bin, ratio);
     936           0 :           ((TProfile2D*)fPedestalHighGainRatio[i])->SetBinEntries(bin, 1);
     937           0 :         }
     938             : 
     939           0 :         if (fReference->GetPedProfileLowGain(i)->GetBinContent(bin) > 0) {
     940           0 :           diff = GetPedProfileLowGain(i)->GetBinContent(bin) - fReference->GetPedProfileLowGain(i)->GetBinContent(bin);
     941           0 :           ((TProfile2D*)fPedestalLowGainDiff[i])->SetBinContent(bin, diff);
     942           0 :           ((TProfile2D*)fPedestalLowGainDiff[i])->SetBinEntries(bin, 1);
     943           0 :           ratio = GetPedProfileLowGain(i)->GetBinContent(bin) / fReference->GetPedProfileLowGain(i)->GetBinContent(bin);  
     944           0 :           ((TProfile2D*)fPedestalLowGainRatio[i])->SetBinContent(bin, ratio);
     945           0 :           ((TProfile2D*)fPedestalLowGainRatio[i])->SetBinEntries(bin, 1);
     946           0 :         }
     947             : 
     948             :       } // rows
     949             :     } // columns
     950             : 
     951             :     // same for LED Ref/Mon channels
     952           0 :     for (int j = 0; j <= fLEDRefs; j++) {    
     953           0 :       bin = j+1;//Note that we assume here that all histos have the same structure...
     954             : 
     955           0 :       if (fReference->GetPedLEDRefProfileHighGain(i)->GetBinContent(bin) > 0) {
     956           0 :         diff = GetPedLEDRefProfileHighGain(i)->GetBinContent(bin) - fReference->GetPedLEDRefProfileHighGain(i)->GetBinContent(bin);
     957           0 :         ((TProfile*)fPedestalLEDRefHighGainDiff[i])->SetBinContent(bin, diff);
     958           0 :         ((TProfile*)fPedestalLEDRefHighGainDiff[i])->SetBinEntries(bin, 1);
     959           0 :         ratio = GetPedLEDRefProfileHighGain(i)->GetBinContent(bin) / fReference->GetPedLEDRefProfileHighGain(i)->GetBinContent(bin);  
     960           0 :         ((TProfile*)fPedestalLEDRefHighGainRatio[i])->SetBinContent(bin, ratio);
     961           0 :         ((TProfile*)fPedestalLEDRefHighGainRatio[i])->SetBinEntries(bin, 1);
     962           0 :       }
     963             : 
     964           0 :       if (fReference->GetPedLEDRefProfileLowGain(i)->GetBinContent(bin) > 0) {
     965           0 :         diff = GetPedLEDRefProfileLowGain(i)->GetBinContent(bin) - fReference->GetPedLEDRefProfileLowGain(i)->GetBinContent(bin);
     966           0 :         ((TProfile*)fPedestalLEDRefLowGainDiff[i])->SetBinContent(bin, diff);
     967           0 :         ((TProfile*)fPedestalLEDRefLowGainDiff[i])->SetBinEntries(bin, 1);
     968           0 :         ratio = GetPedLEDRefProfileLowGain(i)->GetBinContent(bin) / fReference->GetPedLEDRefProfileLowGain(i)->GetBinContent(bin);  
     969           0 :         ((TProfile*)fPedestalLEDRefLowGainRatio[i])->SetBinContent(bin, ratio);
     970           0 :         ((TProfile*)fPedestalLEDRefLowGainRatio[i])->SetBinEntries(bin, 1);
     971           0 :       } 
     972             :      
     973             :     }
     974             : 
     975             :   } // modules
     976             :  
     977           0 : }
     978             : 
     979             : //_____________________________________________________________________
     980             : void AliCaloCalibPedestal::ComputeHotAndWarningTowers(const char * hotMapFile)
     981             : { // look for hot/noisy towers
     982           0 :   ValidateProfiles(); // make sure histos/profiles exist
     983             :   ofstream * fout = 0;
     984           0 :   char name[512];//Quite a long temp buffer, just in case the filename includes a path
     985             : 
     986           0 :   if (hotMapFile) {
     987           0 :     snprintf(name, 512, "%s.txt", hotMapFile);
     988           0 :     fout = new ofstream(name);
     989           0 :     if (!fout->is_open()) {
     990           0 :       delete fout;
     991             :       fout = 0;//Set the pointer to empty if the file was not opened
     992           0 :     }
     993             :   }
     994             :  
     995           0 :   for(int i = 0; i < fModules; i++){
     996             :                 
     997             :     //first we compute the peak-pedestal distribution for each supermodule...
     998           0 :     if( GetPeakHighGainHisto(i)->GetEntries() > 0 ) {
     999           0 :       double min = GetPeakProfileHighGain(i)->GetBinContent(GetPeakProfileHighGain(i)->GetMinimumBin());
    1000           0 :       double max = GetPeakProfileHighGain(i)->GetBinContent(GetPeakProfileHighGain(i)->GetMaximumBin());
    1001           0 :       TH1D *hPeakFit = new TH1D(Form("hFit_%d", i), Form("hFit_%d", i), (int)((max-min)*10), min-1, max+1);
    1002             : 
    1003           0 :       for (int j = 1; j <= fColumns; j++) {
    1004           0 :         for (int k = 1; k <= fRows; k++) {     
    1005           0 :           hPeakFit->Fill(GetPeakProfileHighGain(i)->GetBinContent(j, k));
    1006             :         }
    1007             :       }
    1008             : 
    1009             :       //...and then we try to fit it
    1010           0 :       double mean  = hPeakFit->GetMean();
    1011           0 :       double sigma = hPeakFit->GetRMS();
    1012             :       try {
    1013           0 :         hPeakFit->Fit("gaus", "OQ", "",  mean - 3*sigma, mean + 3*sigma);
    1014           0 :         mean  = hPeakFit->GetFunction("gaus")->GetParameter(1);
    1015           0 :         sigma = hPeakFit->GetFunction("gaus")->GetParameter(2);
    1016           0 :       }
    1017             :       catch (const std::exception & e) {
    1018           0 :         printf("AliCaloCalibPedestal: TH1D PeakFit exception %s", e.what()); 
    1019           0 :       }      
    1020             :       //hPeakFit->Draw();
    1021             : 
    1022           0 :       delete hPeakFit;
    1023             : 
    1024             :       //Then we look for warm/hot towers
    1025           0 :       TH2F * hPeak2D = GetPeakHighGainHisto(i);
    1026           0 :       hPeak2D->GetYaxis()->SetRangeUser( fWarningThreshold, hPeak2D->GetYaxis()->GetBinUpEdge(hPeak2D->GetNbinsY()) );
    1027             : 
    1028             :       int idx = 0 ;
    1029             :       int warnCounter = 0;
    1030           0 :       for (int j = 1; j <= fColumns; j++) {
    1031           0 :         for (int k = 1; k <= fRows; k++) {                           
    1032             :           //we start looking for warm/warning towers...
    1033             :           // histogram x-axis index
    1034           0 :           idx = k-1 + fRows*(j-1); // this is what is used in the Fill call
    1035           0 :           hPeak2D->GetXaxis()->SetRangeUser(idx, idx);
    1036           0 :           warnCounter = (int) hPeak2D->Integral();
    1037           0 :           if(warnCounter > fNEvents * fWarningFraction) {
    1038           0 :             ((TH2D*)fDeadMap[i])->SetBinContent(j, k, kWarning);         
    1039             :             /* printf("mod %d col %d row %d warnCounter %d - status %d\n", 
    1040             :                i, j-1, k-1, warnCounter, (int) (kWarning)); */  
    1041           0 :           }
    1042             :           //...then we look for hot ones (towers whose values are greater than mean + X*sigma)  
    1043           0 :           if(GetPeakProfileHighGain(i)->GetBinContent(j, k) > mean + fHotSigma*sigma ) {
    1044           0 :             ((TH2D*)fDeadMap[i])->SetBinContent(j, k, kHot); 
    1045             :             /* printf("mod %d col %d row %d  binc %d - status %d\n", 
    1046             :                i, j-1, k-1, (int)(GetPeakProfileHighGain(i)->GetBinContent(j, k)), (int) (kHot)); */   
    1047           0 :           }
    1048             : 
    1049             :           //Write the status to the hot/warm map file, if the file is open.
    1050             :           // module - column - row - status (1=dead, 2= warm/warning , 3 = hot, see .h file enum)
    1051           0 :           if (fout && ((TH2D*)fDeadMap[i])->GetBinContent(j, k) > 1) {
    1052             :             
    1053           0 :             (*fout) << i << " " 
    1054           0 :                     << (j - 1) << " " 
    1055           0 :                     << (k - 1) << " " 
    1056           0 :                     << ((TH2D*)fDeadMap[i])->GetBinContent(j, k) << endl;                }
    1057             :           
    1058             :         }
    1059             :       }
    1060             : 
    1061           0 :     } 
    1062             :   }
    1063             :   return;
    1064           0 : }
    1065             : 
    1066             : //_____________________________________________________________________
    1067             : void AliCaloCalibPedestal::ComputeDeadTowers(const char * deadMapFile)
    1068             : {
    1069           0 :   ValidateProfiles(); // make sure histos/profiles exist
    1070             :   //Computes the number of dead towers etc etc into memory, after this you can call the GetDead... -functions
    1071             :   int countTot = 0;
    1072             :   int countNew = 0;
    1073             :   int countRes = 0;
    1074             :   ofstream * fout = 0;
    1075             :   ofstream * diff = 0;
    1076           0 :   char name[512];//Quite a long temp buffer, just in case the filename includes a path
    1077             :   
    1078           0 :   if (deadMapFile) {
    1079           0 :     snprintf(name, 512, "%s.txt", deadMapFile);
    1080           0 :     fout = new ofstream(name);
    1081           0 :     snprintf(name, 512, "%sdiff.txt", deadMapFile);
    1082           0 :     diff = new ofstream(name);
    1083           0 :     if (!fout->is_open()) {
    1084           0 :       delete fout;
    1085             :       fout = 0;//Set the pointer to empty if the file was not opened
    1086           0 :     }
    1087           0 :     if (!diff->is_open()) {
    1088           0 :       delete diff;
    1089             :       diff = 0;//Set the pointer to empty if the file was not opened
    1090           0 :     }
    1091             :   }
    1092             :  
    1093           0 :   for (int i = 0; i < fModules; i++) {
    1094           0 :     if (GetPeakProfileHighGain(i)->GetEntries() > 0) { //don't care about empty histos
    1095           0 :       for (int j = 1; j <= fColumns; j++) {
    1096           0 :         for (int k = 1; k <= fRows; k++) {
    1097             : 
    1098           0 :           if (GetPeakProfileHighGain(i)->GetBinContent(j, k) < fDeadThreshold) {//It's dead
    1099           0 :             countTot++;//One more dead total
    1100           0 :             if (fout) {
    1101           0 :               (*fout) << i << " " 
    1102           0 :                       << (j - 1) << " " 
    1103           0 :                       << (k - 1) << " " 
    1104           0 :                       << "1" << " " 
    1105           0 :                       << "0" << endl;//Write the status to the deadmap file, if the file is open.
    1106           0 :             }
    1107             :             
    1108           0 :             if (fReference && fReference->GetPeakProfileHighGain(i)->GetBinContent(j, k) >= fDeadThreshold) {
    1109           0 :               ((TH2D*)fDeadMap[i])->SetBinContent(j, k, kRecentlyDeceased); 
    1110           0 :               countNew++;//This tower wasn't dead before!
    1111           0 :               if (diff) {
    1112           0 :                 ( *diff) << i << " " 
    1113           0 :                          << (j - 1) << " " 
    1114           0 :                          << (k - 1) << " " 
    1115           0 :                          << "1" << " " 
    1116           0 :                          << "0" << endl;//Write the status to the deadmap difference file, if the file is open.
    1117           0 :               }
    1118             :             } 
    1119             :             else {
    1120           0 :               ((TH2D*)fDeadMap[i])->SetBinContent(j, k, kDead);//This has been dead before. Nothing new              
    1121             :             }
    1122             :           } 
    1123             :           else { //It's ALIVE!!
    1124             :             //Don't bother with writing the live ones.
    1125           0 :             if (fReference && fReference->GetPeakProfileHighGain(i)->GetBinContent(j, k) < fDeadThreshold) {
    1126           0 :               ((TH2D*)fDeadMap[i])->SetBinContent(j, k, kResurrected);
    1127           0 :               countRes++; //This tower was dead before => it's a miracle! :P
    1128           0 :               if (diff) {
    1129           0 :                 (*diff) << i << " " 
    1130           0 :                         << (j - 1) << " " 
    1131           0 :                         << (k - 1) << " " 
    1132           0 :                         << "1" << " " 
    1133           0 :                         << "1" << endl;//Write the status to the deadmap difference file, if the file is open.
    1134           0 :               }
    1135             :             } 
    1136             :             else {
    1137           0 :               ((TH2D*)fDeadMap[i])->SetBinContent(j, k, kAlive);
    1138             :             }
    1139             :           }
    1140             :             
    1141             :         }//end for k/rows
    1142             :       }//end for j/columns
    1143           0 :     }//end if GetEntries >= 0
    1144             :   
    1145             :   }//end for modules
    1146             :  
    1147           0 :  if (fout) {
    1148           0 :    fout->close();
    1149           0 :    delete fout;
    1150             :  }
    1151             :  
    1152           0 :  fDeadTowers = countTot;
    1153           0 :  fNewDeadTowers = countNew;
    1154           0 :  fResurrectedTowers = countRes;
    1155           0 : }
    1156             : 
    1157             : //_____________________________________________________________________
    1158             : Bool_t AliCaloCalibPedestal::IsBadChannel(int imod, int icol, int irow) const
    1159             : {
    1160             :   // Check if status info histo exists
    1161           0 :   if (!fDeadMap[imod]) { 
    1162           0 :     return kFALSE;
    1163             :   }
    1164             : 
    1165             :   //Check if channel is dead or hot.  
    1166           0 :   Int_t status =  (Int_t) ( ((TH2D*)fDeadMap[imod])->GetBinContent(icol,irow) );
    1167           0 :   if(status == kAlive)
    1168           0 :     return kFALSE;
    1169             :   else 
    1170           0 :     return kTRUE;
    1171             :   
    1172           0 : }
    1173             : 
    1174             : //_____________________________________________________________________
    1175             : void AliCaloCalibPedestal::SetChannelStatus(int imod, int icol, int irow, int status)
    1176             : {
    1177           0 :   ValidateProfiles(); // make sure histos/profiles exist
    1178             :   //Set status of channel dead, hot, alive ...  
    1179           0 :   ((TH2D*)fDeadMap[imod])->SetBinContent(icol, irow, status);        
    1180           0 : }

Generated by: LCOV version 1.11