1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 ///////////////////////////////////////////////////////////////////////////////
19 // Calibration class for DCS sensors //
20 // Authors: Marian Ivanov and Haavard Helstrup //
22 ///////////////////////////////////////////////////////////////////////////////
24 #include "AliDCSSensorArray.h"
26 ClassImp(AliDCSSensorArray)
28 const Int_t kMinGraph = 10; // minimum #points of graph to be fitted
29 const Int_t kMinPoints = 10; // minimum number of points per knot in fit
30 const Int_t kIter = 10; // number of iterations for spline fit
31 const Double_t kMaxDelta = 0.00; // precision parameter for spline fit
32 const Int_t kFitReq = 2; // fit requirement, 2 = continuous 2nd derivative
34 //_____________________________________________________________________________
35 AliDCSSensorArray::AliDCSSensorArray():TNamed(),
38 fStartTime (2000,1,1,0,0,0),
39 fEndTime (2000,1,1,0,0,0),
43 // AliDCSSensorArray default constructor
47 //_____________________________________________________________________________
48 AliDCSSensorArray::AliDCSSensorArray(Int_t prevRun, const char* dbEntry) :
52 fStartTime (2000,1,1,0,0,0),
53 fEndTime (2000,1,1,0,0,0),
57 // Read positions etc. from data base entry for previous run
58 // Delete all fits and graphs
60 AliDCSSensorArray *temp=0;
62 AliCDBManager::Instance()->Get(dbEntry,prevRun);
64 entry->SetOwner(kTRUE);
65 temp = (AliDCSSensorArray*)entry->GetObject();
71 // Delete previous values
73 Int_t nsensors = temp->fSensors->GetEntries();
74 for ( Int_t isensor=0; isensor<nsensors; isensor++) {
75 AliDCSSensor *entry = (AliDCSSensor*)temp->fSensors->At(isensor);
76 gr = entry->GetGraph();
81 fit = entry->GetFit();
88 new (this) AliDCSSensorArray(*temp);
94 //_____________________________________________________________________________
95 AliDCSSensorArray::AliDCSSensorArray(const AliDCSSensorArray &c):TNamed(c),
96 fFirstSensor(c.fFirstSensor),
97 fLastSensor(c.fLastSensor),
98 fStartTime (c.fStartTime),
99 fEndTime (c.fEndTime),
104 // AliDCSSensorArray copy constructor
107 ((AliDCSSensorArray &) c).Copy(*this);
111 ///_____________________________________________________________________________
112 AliDCSSensorArray::~AliDCSSensorArray()
115 // AliDCSSensorArray destructor
122 //_____________________________________________________________________________
123 AliDCSSensorArray &AliDCSSensorArray::operator=(const AliDCSSensorArray &c)
126 // Assignment operator
129 if (this != &c) ((AliDCSSensorArray &) c).Copy(*this);
134 //_____________________________________________________________________________
135 void AliDCSSensorArray::Copy(TObject &c) const
143 //_____________________________________________________________________________
144 void AliDCSSensorArray::SetGraph(TMap *map, const char *amandaString)
147 // Read graphs from DCS maps
150 Int_t nsensors = fSensors->GetEntries();
151 for ( Int_t isensor=0; isensor<nsensors; isensor++) {
152 AliDCSSensor *entry = (AliDCSSensor*)fSensors->At(isensor);
153 Int_t dcsSensor=entry->GetIdDCS();
154 sprintf(dname,amandaString,dcsSensor);
155 TGraph *gr = (TGraph*)map->GetValue(dname);
159 //_____________________________________________________________________________
160 void AliDCSSensorArray::MakeSplineFit(TMap *map, const char *amandaString)
163 // Make spline fits from DCS maps
166 Int_t nsensors = fSensors->GetEntries();
167 for ( Int_t isensor=0; isensor<nsensors; isensor++) {
168 AliDCSSensor *entry = (AliDCSSensor*)fSensors->At(isensor);
169 Int_t dcsSensor=entry->GetIdDCS();
170 sprintf(dname,amandaString,dcsSensor);
171 TGraph *gr = (TGraph*)map->GetValue(dname);
172 if (gr->GetN() < kMinGraph ) continue;
173 AliSplineFit *fit = new AliSplineFit();
174 fit->InitKnots(gr,kMinPoints,kIter,kMaxDelta);
175 fit->SplineFit(kFitReq);
176 entry->SetStartTime(fStartTime);
182 //_____________________________________________________________________________
183 Double_t AliDCSSensorArray::GetValue(UInt_t timeSec, Int_t sensor)
186 // Return sensor value at time timeSec (obtained from fitted function)
187 // timeSec = time in seconds from start of run
189 AliDCSSensor *entry = (AliDCSSensor*)fSensors->At(sensor);
190 return entry->GetValue(timeSec);
194 //_____________________________________________________________________________
195 TMap* AliDCSSensorArray::ExtractDCS(TMap *dcsMap, const char *amandaString)
198 // Extract temperature graphs from DCS maps
200 TMap *values = new TMap;
201 TObjArray * valueSet;
202 Int_t nsensors = fSensors->GetEntries();
203 for ( Int_t isensor=0; isensor<nsensors; isensor++) {
204 AliDCSSensor *entry = (AliDCSSensor*)fSensors->At(isensor);
205 Int_t dcsSensor=entry->GetIdDCS();
206 TString DPname = Form (amandaString,dcsSensor);
207 TPair *pair = (TPair*)dcsMap->FindObject(DPname.Data());
208 valueSet = (TObjArray*)pair->Value();
209 TGraph *graph = MakeGraph(valueSet);
210 values->Add(new TObjString(DPname.Data()),graph);
215 //_____________________________________________________________________________
216 TGraph* AliDCSSensorArray::MakeGraph(TObjArray* valueSet){
218 // Make graph of temperature values read from DCS map
219 // (spline fit parameters will subsequently be obtained from this graph)
221 Int_t nentries = valueSet->GetEntriesFast();
222 Float_t *x = new Float_t[nentries];
223 Float_t *y = new Float_t[nentries];
228 for (Int_t i=0; i<nentries; i++){
229 AliDCSValue * val = (AliDCSValue *)valueSet->At(i);
232 time0=val->GetTimeStamp();
234 value = val->GetFloat();
235 if (TMath::Abs(value)>100) continue; // refuse values exceeding 100
236 if ( out>0 && skipped<10 && TMath::Abs(value-y[out-1])>5) {
237 skipped++; // refuse temperatures changing
238 continue; // by > 5 degrees in one time step
241 if (val->GetTimeStamp()-time0>1000000) continue;
242 x[out] = (val->GetTimeStamp()-time0)/3600.0; // give times in fractions of hours
243 y[out] = val->GetFloat();
247 TGraph * graph = new TGraph(out,x,y);
253 //_____________________________________________________________________________
254 AliDCSSensor* AliDCSSensorArray::GetSensor(Int_t IdDCS)
257 // Return sensor information for sensor specified by IdDCS
259 Int_t nsensors = fSensors->GetEntries();
260 for (Int_t isensor=0; isensor<nsensors; isensor++) {
261 AliDCSSensor *entry = (AliDCSSensor*)fSensors->At(isensor);
262 if (entry->GetIdDCS() == IdDCS) return entry;
266 //_____________________________________________________________________________
267 AliDCSSensor* AliDCSSensorArray::GetSensor(Double_t x, Double_t y, Double_t z)
270 // Return sensor closest to given position
272 Int_t nsensors = fSensors->GetEntries();
273 Double_t dist2min=1e99;
274 Double_t xs,ys,zs,dist2;
276 for (Int_t isensor=0; isensor<nsensors; isensor++) {
277 AliDCSSensor *entry = (AliDCSSensor*)fSensors->At(isensor);
281 dist2 = (x-xs)*(x-xs) + (y-ys)*(y-ys) + (z-zs)*(z-zs);
282 if (dist2 < dist2min) {
288 return (AliDCSSensor*)fSensors->At(ind);