]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliDCSSensor.cxx
Possibility to fix some of the parameters. New method to get the number of free param...
[u/mrichter/AliRoot.git] / STEER / AliDCSSensor.cxx
index 7f51c247173a279e305e13921288b9fccb8bd4be..69af0d9e2849bbb8859c955ec082cd59af5fefdf 100644 (file)
 ////////////////////////////////////////////////////////////////////////////////
 
 
-// Running instructions:
-/*
-  TClonesArray * arr = AliDCSSensor::ReadList("TempSensor.txt");
-  TFile f("TempSensors.root","RECREATE");
-  TTree * tree = new TTree("TempSensor", "TempSensor");
-  tree->Branch("Temp",&arr);
-  tree->Fill();
-  tree->Write();
-  
- */
-//
-
-
 #include "AliDCSSensor.h"
 ClassImp(AliDCSSensor)
 
+const Double_t kSecInHour = 3600.; // seconds in one hour
+
+
 
 AliDCSSensor::AliDCSSensor():
   fId(),
   fIdDCS(0),
+  fStringID(),
   fStartTime(0),
+  fEndTime(0),
   fGraph(0),
   fFit(0),
   fX(0),
@@ -58,7 +50,9 @@ AliDCSSensor::AliDCSSensor(const AliDCSSensor& source) :
    TNamed(source),
    fId(source.fId),
    fIdDCS(source.fIdDCS),
+   fStringID(source.fStringID),
    fStartTime(source.fStartTime),
+   fEndTime(source.fEndTime),
    fGraph(source.fGraph),
    fFit(source.fFit),
    fX(source.fX),
@@ -75,19 +69,19 @@ AliDCSSensor& AliDCSSensor::operator=(const AliDCSSensor& source){
 //
   if (&source == this) return *this;
   new (this) AliDCSSensor(source);
-  
-  return *this;  
+
+  return *this;
 }
 
 //_____________________________________________________________________________
-Double_t AliDCSSensor::GetValue(UInt_t timeSec) 
+Double_t AliDCSSensor::GetValue(UInt_t timeSec)
 {
  //
  // Get temperature value for actual sensor
  //  timeSec given as offset from start-of-run measured in seconds
  //
Double_t timeHrs = timeSec/3600.0;
- return  fFit->Eval(timeHrs,0);
Bool_t inside=kTRUE;
+ return Eval(TTimeStamp((time_t)(fStartTime+timeSec),0),inside);
 }
 //_____________________________________________________________________________
 Double_t AliDCSSensor::GetValue(TTimeStamp time) 
@@ -95,8 +89,140 @@ Double_t AliDCSSensor::GetValue(TTimeStamp time)
  // Get temperature value for actual sensor
  //  time given as absolute TTimeStamp
  //
- Double_t timeHrs = (time.GetSec() - fStartTime)/3600.0;
- return fFit->Eval(timeHrs,0);
+ Bool_t inside=kTRUE;
+ return Eval(time, inside);
+}
+
+//_____________________________________________________________________________
+
+Double_t AliDCSSensor::Eval(const TTimeStamp& time, Bool_t inside) const
+{
+  // 
+  // Return temperature at given time
+  //  If time < start of map  return value at start of map, inside = false
+  //  If time > end of map    return value at end of map, inside = false
+  
+  UInt_t timeSec = time.GetSec();
+  UInt_t diff = timeSec-fStartTime;
+  inside = true;
+  
+  if ( timeSec < fStartTime ) { 
+     inside=false;
+     diff=0;
+  }
+  if ( timeSec > fEndTime ) {
+     inside=false;
+     diff = fEndTime-fStartTime;
+  }
+  Double_t timeHour = diff/kSecInHour;
+  if ( fFit ) {
+     return fFit->Eval(timeHour); 
+  } else {
+     if ( fGraph ) {
+       return EvalGraph(timeHour);
+     } else {  
+       return -99;
+     }
+  }
 }
+//_____________________________________________________________________________
+Double_t AliDCSSensor::EvalGraph(const Double_t& timeHour) const 
+{
+  //
+  // Extract last value in graph observed before time given by timeHour
+  //
+
+  // return -99 if point specified is before beginning of graph
+  Double_t x=0; Double_t y=0;
+  fGraph->GetPoint(0,x,y);
+  if ( timeHour < x ) return -99;
+  
+  // return previous point when first time > timeHour is observed
+  
+  Int_t npoints = fGraph->GetN();
+  for (Int_t i=1; i<npoints; i++) {
+     fGraph->GetPoint(i,x,y);
+     if ( timeHour < x ) {
+       fGraph->GetPoint(i-1,x,y);
+       return y;
+     }
+  }
+  
+  // return last point if all times are < timeHour
+  return y;
+} 
+       
 
+//_____________________________________________________________________________
+TGraph* AliDCSSensor::MakeGraph(Int_t nPoints) const
+{
+  //
+  // Make graph from start time to end time of DCS values 
+  //
+
+  UInt_t stepTime = (fEndTime-fStartTime)/nPoints;
+  
+  if ( !fFit ) return 0;
+
+  Double_t *x = new Double_t[nPoints+1];
+  Double_t *y = new Double_t[nPoints+1];
+  for (Int_t ip=0; ip<nPoints; ip++) {
+    x[ip] = fStartTime+ip*stepTime;
+    y[ip] = fFit->Eval(ip*stepTime/kSecInHour);
+  }
+  
+  TGraph *graph = new TGraph(nPoints,x,y);
+  delete [] x;
+  delete [] y;
+  
+  graph->GetXaxis()->SetTimeDisplay(1);
+  graph->GetXaxis()->SetLabelOffset(0.02);
+  graph->GetXaxis()->SetTimeFormat("#splitline{%d/%m}{%H:%M}");
+
+  return graph;
+}
+
+//_____________________________________________________________________________
+
+TClonesArray * AliDCSSensor::ReadTree(TTree* tree) {
+  //
+  // read values from ascii file
+  //
+
+  Int_t nentries = tree->GetEntries();
+
+  char stringId[100];
+  Int_t num=0;
+  Int_t idDCS=0;
+  Double_t x=0;
+  Double_t y=0;
+  Double_t z=0;
+
+  tree->SetBranchAddress("StringID",&stringId);
+  tree->SetBranchAddress("IdDCS",&idDCS);
+  tree->SetBranchAddress("Num",&num);
+  tree->SetBranchAddress("X",&x);
+  tree->SetBranchAddress("Y",&y);
+  tree->SetBranchAddress("Z",&z);
+
+  // firstSensor = (Int_t)tree->GetMinimum("ECha");
+  // lastSensor = (Int_t)tree->GetMaximum("ECha");
+
+  TClonesArray * array = new TClonesArray("AliDCSSensor",nentries);
+   printf ("nentries = %d\n",nentries);
+
+  for (Int_t isensor=0; isensor<nentries; isensor++){
+    AliDCSSensor * sens = new ((*array)[isensor])AliDCSSensor;
+    tree->GetEntry(isensor);
+    sens->SetId(isensor);
+    sens->SetIdDCS(idDCS);
+    sens->SetStringID(TString(stringId));
+    sens->SetX(x);
+    sens->SetY(y);
+    sens->SetZ(z);
+
+  }
+  return array;
+}