ROOT logo
/**************************************************************************
 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
 *                                                                        *
 * Author: The ALICE Off-line Project.                                    *
 * Contributors are mentioned in the code where appropriate.              *
 *                                                                        *
 * Permission to use, copy, modify and distribute this software and its   *
 * documentation strictly for non-commercial purposes is hereby granted   *
 * without fee, provided that the above copyright notice appears in all   *
 * copies and that both the copyright notice and this permission notice   *
 * appear in the supporting documentation. The authors make no claims     *
 * about the suitability of this software for any purpose. It is          *
 * provided "as is" without express or implied warranty.                  *
 **************************************************************************/


///////////////////////////////////////////////////////////////////////////////
//                                                                           //
//  EMCAL calibration class for saved temperature sensor parameters          //
//  Authors: David Silvermyr, copied from TPC (Ivanov, Helstrup)             //
//                                                                           //
///////////////////////////////////////////////////////////////////////////////

#include "AliEMCALSensorTempArray.h"
#include "TLinearFitter.h"
#include "TVectorD.h"
#include "AliLog.h"

ClassImp(AliEMCALSensorTempArray)

//_____________________________________________________________________________
AliEMCALSensorTempArray::AliEMCALSensorTempArray():AliDCSSensorArray()
{
  //
  // AliEMCALSensorTempArray default constructor
  //
}
//_____________________________________________________________________________
AliEMCALSensorTempArray::AliEMCALSensorTempArray(Int_t run) : AliDCSSensorArray() 
{
  //
  // Read configuration from OCDB
  //
  
  AliCDBEntry *entry =
    AliCDBManager::Instance()->Get("EMCAL/Config/Temperature",run); 
  if(entry){
    TTree *tree = (TTree*) entry->GetObject();
    fSensors = AliEMCALSensorTemp::ReadTree(tree);
    fSensors->BypassStreamer(kFALSE);
  }
  else AliFatal("CDB entry null!");
}
//_____________________________________________________________________________
AliEMCALSensorTempArray::AliEMCALSensorTempArray(UInt_t startTime, UInt_t endTime,
						 TTree* confTree, const TString& amandaString)
  :AliDCSSensorArray()
{
  //
  // AliEMCALSensorTempArray constructor for Shuttle preprocessor 
  //  (confTree read from OCDB)
  //
  fSensors = AliEMCALSensorTemp::ReadTree(confTree,amandaString);
  fSensors->BypassStreamer(kFALSE);
  fStartTime = TTimeStamp((time_t)startTime,0);
  fEndTime   = TTimeStamp((time_t)endTime,0);
}

//_____________________________________________________________________________
AliEMCALSensorTempArray::AliEMCALSensorTempArray(const char *fname,
                                          const TString& amandaString) :
                                                  AliDCSSensorArray()
{
  //
  // AliEMCALSensorTempArray constructor
  //
  fSensors = AliEMCALSensorTemp::ReadList(fname,amandaString);
  fSensors->BypassStreamer(kFALSE);
}

//_____________________________________________________________________________
AliEMCALSensorTempArray::AliEMCALSensorTempArray(const AliEMCALSensorTempArray &c):
  AliDCSSensorArray(c)
{
  //
  // AliEMCALSensorTempArray copy constructor
  //
}

//_____________________________________________________________________________
AliEMCALSensorTempArray::~AliEMCALSensorTempArray()
{
  //
  // AliEMCALSensorTempArray destructor
  //
}

//_____________________________________________________________________________
AliEMCALSensorTempArray &AliEMCALSensorTempArray::operator=(const AliEMCALSensorTempArray &c)
{
  //
  // Assignment operator
  //
  if (this != &c) {
    fSensors->Delete();
    new (this) AliEMCALSensorTempArray(c);
    fSensors = (TClonesArray*)c.fSensors->Clone();
  }
  return *this;
}

//_____________________________________________________________________________
void AliEMCALSensorTempArray::ReadSensors(const char *dbEntry)
{
  //
  // Read list of temperature sensors from text file
  //
  AliCDBEntry *entry = AliCDBManager::Instance()->Get(dbEntry);
  if(entry){
    TTree *tree = (TTree*) entry->GetObject();
    fSensors = AliEMCALSensorTemp::ReadTree(tree);
  }
  else AliFatal("NULL CDB entry!");
}  

//_____________________________________________________________________________
AliEMCALSensorTemp* AliEMCALSensorTempArray::GetSensor(Int_t side, Int_t sector, Int_t num) 
{
  //
  //  Return sensor information for sensor specified by side, sector and num
  //
  Int_t nsensors = fSensors->GetEntries();
  for (Int_t isensor=0; isensor<nsensors; isensor++) {
    AliEMCALSensorTemp *entry = (AliEMCALSensorTemp*)fSensors->At(isensor);
    if (entry->GetSide() == side &&
	entry->GetSector() == sector &&
	entry->GetNum() == num ) return entry;
  }
  return 0;
}

//_____________________________________________________________________________

AliEMCALSensorTemp* AliEMCALSensorTempArray::GetSensor(Int_t IdDCS){
  return dynamic_cast<AliEMCALSensorTemp*>(AliDCSSensorArray::GetSensor(IdDCS));
}

//_____________________________________________________________________________
AliEMCALSensorTemp* AliEMCALSensorTempArray::GetSensor(Double_t x, Double_t y, Double_t z){
  return dynamic_cast<AliEMCALSensorTemp*>(AliDCSSensorArray::GetSensor(x,y,z));
}

//_____________________________________________________________________________
Double_t AliEMCALSensorTempArray::GetTempGradientY(UInt_t timeSec, Int_t side){
  //
  // Extract Linear Vertical Temperature Gradient [K/cm] within the EMCAL on
  // Shaft Side(A): 0
  // Muon  Side(C): 1
  // Values based on TemperatureSensors within the EMCAL 
  //
  // FIXME: Also return residual-distribution, covariance Matrix
  //        or simply chi2 for validity check?
  //
  
  TLinearFitter fitter(3,"x0++x1++x2");
  TVectorD param(3);
  Int_t i = 0;
  
  Int_t nsensors = fSensors->GetEntries();
  for (Int_t isensor=0; isensor<nsensors; isensor++) { // loop over all sensors
    AliEMCALSensorTemp *entry = (AliEMCALSensorTemp*)fSensors->At(isensor);
    
    if (entry->GetSide()==side) { // only the selected side
      Double_t x[3];
      x[0]=1;
      x[1]=entry->GetX();
      x[2]=entry->GetY();
      Double_t y = entry->GetValue(timeSec); // get temperature value
      fitter.AddPoint(x,y,1); // add values to LinearFitter
      i++;
    }
    
  }
  fitter.Eval();
  fitter.GetParameters(param);
  
  return param[2]; // return vertical (Y) tempGradient
  
 }
 AliEMCALSensorTempArray.cxx:1
 AliEMCALSensorTempArray.cxx:2
 AliEMCALSensorTempArray.cxx:3
 AliEMCALSensorTempArray.cxx:4
 AliEMCALSensorTempArray.cxx:5
 AliEMCALSensorTempArray.cxx:6
 AliEMCALSensorTempArray.cxx:7
 AliEMCALSensorTempArray.cxx:8
 AliEMCALSensorTempArray.cxx:9
 AliEMCALSensorTempArray.cxx:10
 AliEMCALSensorTempArray.cxx:11
 AliEMCALSensorTempArray.cxx:12
 AliEMCALSensorTempArray.cxx:13
 AliEMCALSensorTempArray.cxx:14
 AliEMCALSensorTempArray.cxx:15
 AliEMCALSensorTempArray.cxx:16
 AliEMCALSensorTempArray.cxx:17
 AliEMCALSensorTempArray.cxx:18
 AliEMCALSensorTempArray.cxx:19
 AliEMCALSensorTempArray.cxx:20
 AliEMCALSensorTempArray.cxx:21
 AliEMCALSensorTempArray.cxx:22
 AliEMCALSensorTempArray.cxx:23
 AliEMCALSensorTempArray.cxx:24
 AliEMCALSensorTempArray.cxx:25
 AliEMCALSensorTempArray.cxx:26
 AliEMCALSensorTempArray.cxx:27
 AliEMCALSensorTempArray.cxx:28
 AliEMCALSensorTempArray.cxx:29
 AliEMCALSensorTempArray.cxx:30
 AliEMCALSensorTempArray.cxx:31
 AliEMCALSensorTempArray.cxx:32
 AliEMCALSensorTempArray.cxx:33
 AliEMCALSensorTempArray.cxx:34
 AliEMCALSensorTempArray.cxx:35
 AliEMCALSensorTempArray.cxx:36
 AliEMCALSensorTempArray.cxx:37
 AliEMCALSensorTempArray.cxx:38
 AliEMCALSensorTempArray.cxx:39
 AliEMCALSensorTempArray.cxx:40
 AliEMCALSensorTempArray.cxx:41
 AliEMCALSensorTempArray.cxx:42
 AliEMCALSensorTempArray.cxx:43
 AliEMCALSensorTempArray.cxx:44
 AliEMCALSensorTempArray.cxx:45
 AliEMCALSensorTempArray.cxx:46
 AliEMCALSensorTempArray.cxx:47
 AliEMCALSensorTempArray.cxx:48
 AliEMCALSensorTempArray.cxx:49
 AliEMCALSensorTempArray.cxx:50
 AliEMCALSensorTempArray.cxx:51
 AliEMCALSensorTempArray.cxx:52
 AliEMCALSensorTempArray.cxx:53
 AliEMCALSensorTempArray.cxx:54
 AliEMCALSensorTempArray.cxx:55
 AliEMCALSensorTempArray.cxx:56
 AliEMCALSensorTempArray.cxx:57
 AliEMCALSensorTempArray.cxx:58
 AliEMCALSensorTempArray.cxx:59
 AliEMCALSensorTempArray.cxx:60
 AliEMCALSensorTempArray.cxx:61
 AliEMCALSensorTempArray.cxx:62
 AliEMCALSensorTempArray.cxx:63
 AliEMCALSensorTempArray.cxx:64
 AliEMCALSensorTempArray.cxx:65
 AliEMCALSensorTempArray.cxx:66
 AliEMCALSensorTempArray.cxx:67
 AliEMCALSensorTempArray.cxx:68
 AliEMCALSensorTempArray.cxx:69
 AliEMCALSensorTempArray.cxx:70
 AliEMCALSensorTempArray.cxx:71
 AliEMCALSensorTempArray.cxx:72
 AliEMCALSensorTempArray.cxx:73
 AliEMCALSensorTempArray.cxx:74
 AliEMCALSensorTempArray.cxx:75
 AliEMCALSensorTempArray.cxx:76
 AliEMCALSensorTempArray.cxx:77
 AliEMCALSensorTempArray.cxx:78
 AliEMCALSensorTempArray.cxx:79
 AliEMCALSensorTempArray.cxx:80
 AliEMCALSensorTempArray.cxx:81
 AliEMCALSensorTempArray.cxx:82
 AliEMCALSensorTempArray.cxx:83
 AliEMCALSensorTempArray.cxx:84
 AliEMCALSensorTempArray.cxx:85
 AliEMCALSensorTempArray.cxx:86
 AliEMCALSensorTempArray.cxx:87
 AliEMCALSensorTempArray.cxx:88
 AliEMCALSensorTempArray.cxx:89
 AliEMCALSensorTempArray.cxx:90
 AliEMCALSensorTempArray.cxx:91
 AliEMCALSensorTempArray.cxx:92
 AliEMCALSensorTempArray.cxx:93
 AliEMCALSensorTempArray.cxx:94
 AliEMCALSensorTempArray.cxx:95
 AliEMCALSensorTempArray.cxx:96
 AliEMCALSensorTempArray.cxx:97
 AliEMCALSensorTempArray.cxx:98
 AliEMCALSensorTempArray.cxx:99
 AliEMCALSensorTempArray.cxx:100
 AliEMCALSensorTempArray.cxx:101
 AliEMCALSensorTempArray.cxx:102
 AliEMCALSensorTempArray.cxx:103
 AliEMCALSensorTempArray.cxx:104
 AliEMCALSensorTempArray.cxx:105
 AliEMCALSensorTempArray.cxx:106
 AliEMCALSensorTempArray.cxx:107
 AliEMCALSensorTempArray.cxx:108
 AliEMCALSensorTempArray.cxx:109
 AliEMCALSensorTempArray.cxx:110
 AliEMCALSensorTempArray.cxx:111
 AliEMCALSensorTempArray.cxx:112
 AliEMCALSensorTempArray.cxx:113
 AliEMCALSensorTempArray.cxx:114
 AliEMCALSensorTempArray.cxx:115
 AliEMCALSensorTempArray.cxx:116
 AliEMCALSensorTempArray.cxx:117
 AliEMCALSensorTempArray.cxx:118
 AliEMCALSensorTempArray.cxx:119
 AliEMCALSensorTempArray.cxx:120
 AliEMCALSensorTempArray.cxx:121
 AliEMCALSensorTempArray.cxx:122
 AliEMCALSensorTempArray.cxx:123
 AliEMCALSensorTempArray.cxx:124
 AliEMCALSensorTempArray.cxx:125
 AliEMCALSensorTempArray.cxx:126
 AliEMCALSensorTempArray.cxx:127
 AliEMCALSensorTempArray.cxx:128
 AliEMCALSensorTempArray.cxx:129
 AliEMCALSensorTempArray.cxx:130
 AliEMCALSensorTempArray.cxx:131
 AliEMCALSensorTempArray.cxx:132
 AliEMCALSensorTempArray.cxx:133
 AliEMCALSensorTempArray.cxx:134
 AliEMCALSensorTempArray.cxx:135
 AliEMCALSensorTempArray.cxx:136
 AliEMCALSensorTempArray.cxx:137
 AliEMCALSensorTempArray.cxx:138
 AliEMCALSensorTempArray.cxx:139
 AliEMCALSensorTempArray.cxx:140
 AliEMCALSensorTempArray.cxx:141
 AliEMCALSensorTempArray.cxx:142
 AliEMCALSensorTempArray.cxx:143
 AliEMCALSensorTempArray.cxx:144
 AliEMCALSensorTempArray.cxx:145
 AliEMCALSensorTempArray.cxx:146
 AliEMCALSensorTempArray.cxx:147
 AliEMCALSensorTempArray.cxx:148
 AliEMCALSensorTempArray.cxx:149
 AliEMCALSensorTempArray.cxx:150
 AliEMCALSensorTempArray.cxx:151
 AliEMCALSensorTempArray.cxx:152
 AliEMCALSensorTempArray.cxx:153
 AliEMCALSensorTempArray.cxx:154
 AliEMCALSensorTempArray.cxx:155
 AliEMCALSensorTempArray.cxx:156
 AliEMCALSensorTempArray.cxx:157
 AliEMCALSensorTempArray.cxx:158
 AliEMCALSensorTempArray.cxx:159
 AliEMCALSensorTempArray.cxx:160
 AliEMCALSensorTempArray.cxx:161
 AliEMCALSensorTempArray.cxx:162
 AliEMCALSensorTempArray.cxx:163
 AliEMCALSensorTempArray.cxx:164
 AliEMCALSensorTempArray.cxx:165
 AliEMCALSensorTempArray.cxx:166
 AliEMCALSensorTempArray.cxx:167
 AliEMCALSensorTempArray.cxx:168
 AliEMCALSensorTempArray.cxx:169
 AliEMCALSensorTempArray.cxx:170
 AliEMCALSensorTempArray.cxx:171
 AliEMCALSensorTempArray.cxx:172
 AliEMCALSensorTempArray.cxx:173
 AliEMCALSensorTempArray.cxx:174
 AliEMCALSensorTempArray.cxx:175
 AliEMCALSensorTempArray.cxx:176
 AliEMCALSensorTempArray.cxx:177
 AliEMCALSensorTempArray.cxx:178
 AliEMCALSensorTempArray.cxx:179
 AliEMCALSensorTempArray.cxx:180
 AliEMCALSensorTempArray.cxx:181
 AliEMCALSensorTempArray.cxx:182
 AliEMCALSensorTempArray.cxx:183
 AliEMCALSensorTempArray.cxx:184
 AliEMCALSensorTempArray.cxx:185
 AliEMCALSensorTempArray.cxx:186
 AliEMCALSensorTempArray.cxx:187
 AliEMCALSensorTempArray.cxx:188
 AliEMCALSensorTempArray.cxx:189