]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONTrackerOCDBDataMaker.cxx
In AliMUONContourHandler:
[u/mrichter/AliRoot.git] / MUON / AliMUONTrackerOCDBDataMaker.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 // $Id$
17
18 #include "AliMUONTrackerOCDBDataMaker.h"
19
20 #include "AliCDBManager.h"
21 #include "AliCDBStorage.h"
22 #include "AliDCSValue.h"
23 #include "AliLog.h"
24 #include "AliMUON2DMap.h"
25 #include "AliMUONCalibParamND.h"
26 #include "AliMUONCalibParamNI.h"
27 #include "AliMUONCalibrationData.h"
28 #include "AliMUONDigitCalibrator.h"
29 #include "AliMUONPadStatusMapMaker.h"
30 #include "AliMUONTrackerData.h"
31 #include "AliMUONVStore.h"
32 #include "AliMpConstants.h"
33 #include "AliMpDDLStore.h"
34 #include "AliMpDetElement.h"
35 #include "AliMpDEManager.h"
36 #include "AliMpDCSNamer.h"
37 #include "AliMpManuIterator.h"
38 #include "Riostream.h"
39 #include <TClass.h>
40 #include <TMap.h>
41 #include <TObjArray.h>
42 #include <TObjString.h>
43 #include <TString.h>
44
45 ///\class AliMUONTrackerOCDBDataMaker
46 ///
47 /// Producer of AliMUONVTrackerData from OCDB data
48 ///
49 ///\author Laurent Aphecetche, Subatech
50
51 ///\cond CLASSIMP
52 ClassImp(AliMUONTrackerOCDBDataMaker)
53 ///\endcond
54
55 //_____________________________________________________________________________
56 AliMUONTrackerOCDBDataMaker::AliMUONTrackerOCDBDataMaker(const char* ocdbPath,
57                                                            Int_t runNumber,
58                                                            const char* type)
59 : AliMUONVTrackerDataMaker(),
60   fIsValid(kTRUE),
61   fData(0x0),
62   fSource(Form("%s-%010d-%s",ocdbPath,runNumber,type))
63 {
64         /// Ctor
65         AliCDBStorage* storage = AliCDBManager::Instance()->GetDefaultStorage();
66         
67         AliCDBManager::Instance()->SetDefaultStorage(ocdbPath);
68         
69         AliMUONVStore* store(0x0);
70         
71         TString stype(type);
72         stype.ToUpper();
73         Bool_t isSingleEvent(kTRUE);
74         Int_t startOfValidity(0);
75         
76         if ( stype == "PEDESTALS" )
77         {
78                 store = AliMUONCalibrationData::CreatePedestals(runNumber,&startOfValidity);
79                 fData = CreateDataPedestals(startOfValidity);
80         }
81         else if ( stype == "OCCUPANCY" )
82         {
83                 store = AliMUONCalibrationData::CreateOccupancyMap(runNumber,&startOfValidity);
84     
85     if (store)
86     {
87       fData = new AliMUONTrackerData(Form("OCC%d",runNumber),"OccupancyMap",*store);
88       fData->SetDimensionName(0,"One");
89       fData->SetDimensionName(1,"Zero");
90     }
91         }
92         else if ( stype == "GAINS" ) 
93         {
94     AliMUONVStore* gains = AliMUONCalibrationData::CreateGains(runNumber,&startOfValidity);
95     store = PatchGainStore(*gains);
96     delete gains;
97                 fData = CreateDataGains(startOfValidity);
98         }
99         else if ( stype == "CAPACITANCES" )
100         {
101                 store = AliMUONCalibrationData::CreateCapacitances(runNumber,&startOfValidity);
102                 fData = CreateDataCapacitances(startOfValidity);
103         }
104         else if ( stype == "HV" )
105         {
106                 TMap* m = AliMUONCalibrationData::CreateHV(runNumber,&startOfValidity);
107                 fData = new AliMUONTrackerData(Form("HV%d",startOfValidity),"High Voltages",1,!isSingleEvent);
108                 fData->SetDimensionName(0,"HV");
109                 store = CreateHVStore(*m);
110                 delete m;
111         }
112   else if ( stype == "STATUSMAP" )
113   {
114     fData = new AliMUONTrackerData(Form("STATUSMAP%d",runNumber),"Status map",2,kTRUE);
115     fData->SetDimensionName(0,"Bits");
116     fData->SetDimensionName(1,"Dead");
117     store = CreateStatusMapStore(runNumber);
118   }
119   else if ( stype == "STATUS" )
120   {
121     fData = new AliMUONTrackerData(Form("STATUS%d",runNumber),"Status",1,kTRUE);
122     fData->SetDimensionName(0,"Bits");
123     store = CreateStatusStore(runNumber);
124   }
125
126         AliCDBManager::Instance()->SetDefaultStorage(storage);
127         
128         if (!store)
129         {
130                 fIsValid = kFALSE;
131                 delete fData;
132                 fData = 0x0;
133                 AliError("Could not create store");
134                 return;
135         }
136         
137   if ( stype != "OCCUPANCY" )
138   {
139     fData->Add(*store);
140         }
141   
142         delete store;
143 }
144
145 //_____________________________________________________________________________
146 AliMUONTrackerOCDBDataMaker::~AliMUONTrackerOCDBDataMaker()
147 {
148   /// dtor
149   delete fData;
150 }
151
152 //_____________________________________________________________________________
153 AliMUONVTrackerData*
154 AliMUONTrackerOCDBDataMaker::CreateDataCapacitances(Int_t runNumber)
155 {
156   /// Create data to hold capa values
157   
158   AliMUONVTrackerData* data = new AliMUONTrackerData(Form("CAPA%d",runNumber),"Capacitances",2,kTRUE);
159   data->SetDimensionName(0,"Capa");
160   data->SetDimensionName(1,"Injection gain");
161   return data;
162 }
163
164 //_____________________________________________________________________________
165 AliMUONVTrackerData*
166 AliMUONTrackerOCDBDataMaker::CreateDataGains(Int_t runNumber)
167 {
168   /// Create data to hold gains values
169   
170   AliMUONVTrackerData* data = new AliMUONTrackerData(Form("GAIN%d",runNumber),"Gains",7,kTRUE);
171   data->SetDimensionName(0,"gain");
172   data->SetDimensionName(1,"a1");
173   data->SetDimensionName(2,"a2");
174   data->SetDimensionName(3,"thres");
175   data->SetDimensionName(4,"qual1");
176   data->SetDimensionName(5,"qual2");
177   data->SetDimensionName(6,"sat");
178   return data;
179 }
180
181 //_____________________________________________________________________________
182 AliMUONVStore*
183 AliMUONTrackerOCDBDataMaker::PatchGainStore(AliMUONVStore& gains)
184 {
185   /// Polish the gain store : 
186   /// a) adding a dimension, computed from a1, and called gain = 1/a1/0.2 
187   ///     where 0.2 is internal capa in pF, and gain is then in mV/fC
188   /// b) splitting the quality in two
189   
190   AliMUONVStore* store = gains.Create();
191   
192   TIter next(gains.CreateIterator());
193   AliMUONVCalibParam* param;
194   
195   while ( ( param = static_cast<AliMUONVCalibParam*>(next()) ) ) 
196   {
197     AliMUONVCalibParam* nd = new AliMUONCalibParamND(param->Dimension()+2,
198                                                      param->Size(),
199                                                      param->ID0(),
200                                                      param->ID1());
201     for ( Int_t i = 0; i < param->Size(); ++i ) 
202     {
203
204       Int_t qual = param->ValueAsInt(i,3);
205                         Int_t q1 = (qual & 0xF0) >> 4;  // linear fit quality
206                         Int_t q2 = qual & 0xF;          // parabolic fit quality
207                         Double_t gain = 0.0;
208       
209       if ( param->ValueAsFloat(i,0) > 1E-9 ) gain = 1.0/param->ValueAsFloat(i,0)/0.2;
210                         
211       nd->SetValueAsDouble(i,0,gain); // gain
212       nd->SetValueAsDouble(i,1,param->ValueAsFloat(i,0)); // a1
213       nd->SetValueAsDouble(i,2,param->ValueAsFloat(i,1)); // a2
214       nd->SetValueAsInt(i,3,param->ValueAsInt(i,2)); // thres
215       nd->SetValueAsInt(i,4,q1); // qual1
216       nd->SetValueAsInt(i,5,q2); // qual2
217       nd->SetValueAsInt(i,6,param->ValueAsInt(i,4)); // sat
218     }
219     store->Add(nd);
220   }
221   
222   return store;
223 }
224
225 //_____________________________________________________________________________
226 AliMUONVTrackerData*
227 AliMUONTrackerOCDBDataMaker::CreateDataPedestals(Int_t runNumber)
228 {
229   /// Create data to hold pedestal values
230   
231   AliMUONVTrackerData* data  = new AliMUONTrackerData(Form("PED%d",runNumber),"Pedestals",2,kTRUE);
232   data->SetDimensionName(0,"Mean");
233   data->SetDimensionName(1,"Sigma");
234   return data;
235 }
236
237 //_____________________________________________________________________________
238 AliMUONVStore*
239 AliMUONTrackerOCDBDataMaker::CreateStatusStore(Int_t runNumber)
240 {
241   /// Get the status store
242   
243   AliMUONDigitCalibrator calibrator(runNumber);
244   
245   AliMUONVStore* sm = new AliMUON2DMap(kTRUE);
246   
247   AliMpManuIterator it;
248   Int_t detElemId, manuId;
249   
250   while (it.Next(detElemId,manuId))
251   {
252     AliMUONVCalibParam* np = new AliMUONCalibParamNI(1,AliMpConstants::ManuNofChannels(),detElemId,manuId);
253     for ( Int_t i = 0; i < np->Size(); ++i ) 
254     {
255       Int_t value = calibrator.PadStatus(detElemId,manuId,i);
256       np->SetValueAsInt(i,0,value); // "raw" value of the status
257     }
258     sm->Add(np);
259   }
260   
261   return sm;
262 }
263
264 //_____________________________________________________________________________
265 AliMUONVStore*
266 AliMUONTrackerOCDBDataMaker::CreateStatusMapStore(Int_t runNumber)
267 {
268   /// Get the status map, and polish it a bit for representation purposes
269
270   AliMUONDigitCalibrator calibrator(runNumber);
271   
272   AliMUONVStore* sm = new AliMUON2DMap(kTRUE);
273   
274   AliMpManuIterator it;
275   Int_t detElemId, manuId;
276   
277   while (it.Next(detElemId,manuId))
278   {
279     AliMUONVCalibParam* np = new AliMUONCalibParamNI(2,AliMpConstants::ManuNofChannels(),detElemId,manuId);
280     for ( Int_t i = 0; i < np->Size(); ++i ) 
281     {
282       Int_t value = calibrator.StatusMap(detElemId,manuId,i);
283       Int_t channelIsDead = ( value & AliMUONPadStatusMapMaker::SelfDeadMask() );
284       np->SetValueAsInt(i,0,value); // "raw" value of the status map
285       np->SetValueAsInt(i,1,channelIsDead); // simple 0 or 1 for this channel
286     }
287     sm->Add(np);
288   }
289   
290   return sm;
291 }
292
293 //_____________________________________________________________________________
294 AliMUONVStore*
295 AliMUONTrackerOCDBDataMaker::CreateHVStore(TMap& m)
296 {
297   /// Create a store from hv values
298   
299   AliMUONVStore* store = new AliMUON2DMap(kTRUE);
300   
301   TIter next(&m);
302   TObjString* s;
303   AliMpDCSNamer hvNamer("TRACKER");
304   
305   while ( ( s = static_cast<TObjString*>(next()) ) )
306   {
307     TString name(s->String());
308
309     Int_t detElemId = hvNamer.DetElemIdFromDCSAlias(name.Data());
310     
311     if ( !AliMpDEManager::IsValidDetElemId(detElemId) )
312     {
313       AliErrorClass(Form("Got an invalid DE = %d from alias = %s",
314                          detElemId,name.Data()));
315       continue;
316     }
317     
318     Int_t nindex = 1;
319     Int_t hvIndex = hvNamer.DCSIndexFromDCSAlias(name.Data());
320     
321     if ( hvIndex > 0 && detElemId >= 500 ) 
322     {
323       AliFatalClass("FIXME"); // there's now switch aliases which should be taken into account
324     }
325
326     if ( hvIndex == -2 ) // we should consider switch alias there...
327     {
328       nindex = hvNamer.NumberOfPCBs(detElemId);
329       hvIndex = 0;
330     }
331
332     AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
333
334     for ( int i = 0 ; i < nindex; ++i )
335     {
336       Int_t index = hvIndex + i ;
337       
338       const AliMpArrayI* manus = de->ManusForHV(index);
339       
340       TPair* p = static_cast<TPair*>(m.FindObject(name.Data()));
341       TObjArray* a = static_cast<TObjArray*>(p->Value());
342       TIter n2(a);
343       AliDCSValue* v;
344       Float_t hvValue(0);
345       Int_t n(0);
346       while ( ( v = static_cast<AliDCSValue*>(n2()) ) )
347       {
348         hvValue += v->GetFloat();  
349         ++n;
350       }
351       if ( n ) hvValue /= n;
352       
353       Int_t nofChannels(AliMpConstants::ManuNofChannels());
354       
355       for ( Int_t k = 0 ; k < manus->GetSize(); ++k )
356       {
357         Int_t manuId = manus->GetValue(k);
358         AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(store->FindObject(detElemId,manuId));
359         if ( ! param ) 
360         {
361           param = new AliMUONCalibParamND(1,nofChannels,detElemId,manuId,0);
362           store->Add(param);
363         }
364         for ( Int_t j = 0 ; j < nofChannels; ++j )
365         {
366           param->SetValueAsDouble(j,0,hvValue);
367         }
368       }
369     }
370   }
371   
372   return store;
373   
374 }
375
376 //_____________________________________________________________________________
377 Long64_t 
378 AliMUONTrackerOCDBDataMaker::Merge(TCollection*)
379 {
380   /// Merge
381   AliError("Not implemented. Does it have sense ?");
382   return 0;
383 }