]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliDCSSensorArray.cxx
Releasing the covariance matrix of intersection point along the track direction
[u/mrichter/AliRoot.git] / STEER / AliDCSSensorArray.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16
17 ///////////////////////////////////////////////////////////////////////////////
18 //                                                                           //
19 //  Calibration class for DCS sensors                                        //
20 //  Authors: Marian Ivanov and Haavard Helstrup                              //
21 //                                                                           //
22 ///////////////////////////////////////////////////////////////////////////////
23
24 #include "AliDCSSensorArray.h"
25
26 ClassImp(AliDCSSensorArray)
27
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
33
34 //_____________________________________________________________________________
35 AliDCSSensorArray::AliDCSSensorArray():TNamed(), 
36   fFirstSensor(0),
37   fLastSensor(0),
38   fStartTime (2000,1,1,0,0,0),
39   fEndTime   (2000,1,1,0,0,0),
40   fSensors(0)
41 {
42   //
43   // AliDCSSensorArray default constructor
44   //
45
46 }
47 //_____________________________________________________________________________
48 AliDCSSensorArray::AliDCSSensorArray(Int_t prevRun, const char* dbEntry) : 
49   TNamed(),
50   fFirstSensor(0),
51   fLastSensor(0),
52   fStartTime (2000,1,1,0,0,0),
53   fEndTime   (2000,1,1,0,0,0),
54   fSensors(0)
55 {
56   //
57   // Read positions etc. from data base entry for previous run
58   // Delete all fits and graphs
59   //
60    AliDCSSensorArray *temp=0;
61    AliCDBEntry* entry = 
62        AliCDBManager::Instance()->Get(dbEntry,prevRun); 
63    if (entry){
64      entry->SetOwner(kTRUE);
65      temp = (AliDCSSensorArray*)entry->GetObject();
66    } 
67
68    TGraph *gr;
69    AliSplineFit* fit;
70
71 // Delete previous values
72    
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();
77      if ( gr != 0 ) {
78        delete gr;
79        gr = 0;
80      }
81      fit = entry->GetFit();
82      if ( fit != 0 ) {
83        delete fit;
84        fit = 0;
85      }
86    }    
87    
88    new (this) AliDCSSensorArray(*temp);
89    delete temp;
90 }
91
92
93
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),
100   fSensors(0)
101
102 {
103   //
104   // AliDCSSensorArray copy constructor
105   //
106
107   ((AliDCSSensorArray &) c).Copy(*this);
108
109 }
110
111 ///_____________________________________________________________________________
112 AliDCSSensorArray::~AliDCSSensorArray()
113 {
114   //
115   // AliDCSSensorArray destructor
116   //
117   fSensors->Delete();
118   delete fSensors;
119
120 }
121
122 //_____________________________________________________________________________
123 AliDCSSensorArray &AliDCSSensorArray::operator=(const AliDCSSensorArray &c)
124 {
125   //
126   // Assignment operator
127   //
128
129   if (this != &c) ((AliDCSSensorArray &) c).Copy(*this);
130   return *this;
131
132 }
133
134 //_____________________________________________________________________________
135 void AliDCSSensorArray::Copy(TObject &c) const
136 {
137   //
138   // Copy function
139   //
140
141   TObject::Copy(c);
142 }
143 //_____________________________________________________________________________
144 void AliDCSSensorArray::SetGraph(TMap *map, const char *amandaString) 
145 {
146   // 
147   // Read graphs from DCS maps 
148   //
149   char dname[100];
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);
156     entry->SetGraph(gr);
157   } 
158 }  
159 //_____________________________________________________________________________
160 void AliDCSSensorArray::MakeSplineFit(TMap *map, const char *amandaString) 
161 {
162   // 
163   // Make spline fits from DCS maps 
164   //
165   char dname[100];
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);
177     fit->Cleanup();
178     entry->SetFit(fit);
179   } 
180 }  
181
182 //_____________________________________________________________________________
183 Double_t AliDCSSensorArray::GetValue(UInt_t timeSec, Int_t sensor) 
184 {
185   // 
186   // Return sensor value at time timeSec (obtained from fitted function)
187   //  timeSec = time in seconds from start of run
188   //
189   AliDCSSensor *entry = (AliDCSSensor*)fSensors->At(sensor);
190   return entry->GetValue(timeSec);
191 }
192     
193
194 //_____________________________________________________________________________
195 TMap* AliDCSSensorArray::ExtractDCS(TMap *dcsMap, const char *amandaString) 
196 {
197  //
198  // Extract temperature graphs from DCS maps
199  //
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);
211  }
212  return values;
213 }
214
215 //_____________________________________________________________________________
216 TGraph* AliDCSSensorArray::MakeGraph(TObjArray* valueSet){
217   //
218   // Make graph of temperature values read from DCS map
219   //   (spline fit parameters will subsequently be obtained from this graph) 
220   //
221   Int_t nentries = valueSet->GetEntriesFast(); 
222   Float_t *x = new Float_t[nentries];
223   Float_t *y = new Float_t[nentries];
224   Int_t time0=0;
225   Int_t out=0;
226   Int_t skipped=0;
227   Float_t value;  
228   for (Int_t i=0; i<nentries; i++){
229     AliDCSValue * val = (AliDCSValue *)valueSet->At(i);
230     if (!val) continue;
231     if (time0==0){
232       time0=val->GetTimeStamp();
233     }
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
239     }                                          
240     skipped=0;                                        
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();
244     out++;
245     
246   }
247   TGraph * graph = new TGraph(out,x,y);
248   delete [] x;
249   delete [] y;
250   return graph;
251 }
252   
253 //_____________________________________________________________________________
254 AliDCSSensor* AliDCSSensorArray::GetSensor(Int_t IdDCS) 
255 {
256  //
257  //  Return sensor information for sensor specified by IdDCS
258  //
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;
263  }
264  return 0;
265 }
266 //_____________________________________________________________________________
267 AliDCSSensor* AliDCSSensorArray::GetSensor(Double_t x, Double_t y, Double_t z) 
268 {
269  //
270  //  Return sensor closest to given position
271  //
272  Int_t nsensors = fSensors->GetEntries();
273  Double_t dist2min=1e99;
274  Double_t xs,ys,zs,dist2;
275  Int_t ind=-1;
276  for (Int_t isensor=0; isensor<nsensors; isensor++) {
277    AliDCSSensor *entry = (AliDCSSensor*)fSensors->At(isensor);
278    xs = entry->GetX();
279    ys = entry->GetY();
280    zs = entry->GetZ();
281    dist2 = (x-xs)*(x-xs) + (y-ys)*(y-ys) + (z-zs)*(z-zs);
282    if (dist2 < dist2min) {
283       ind=isensor;
284       dist2min = dist2;
285    } 
286  }
287  if ( ind >= 0 ) {
288     return (AliDCSSensor*)fSensors->At(ind);
289  } else {
290     return 0;
291  }
292 }