]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONTrackerOCDBDataMaker.cxx
Update of the "data cleaning" part of the reconstruction.
[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 "AliMUONCalibrationData.h"
27 #include "AliMUONTrackerData.h"
28 #include "AliMUONVStore.h"
29 #include "AliMpConstants.h"
30 #include "AliMpDDLStore.h"
31 #include "AliMpDetElement.h"
32 #include "AliMpDEManager.h"
33 #include "AliMpDCSNamer.h"
34 #include <TClass.h>
35 #include <TMap.h>
36 #include <TObjArray.h>
37 #include <TObjString.h>
38 #include <TString.h>
39
40 ///\class AliMUONTrackerOCDBDataMaker
41 ///
42 /// Producer of AliMUONVTrackerData from OCDB data
43 ///
44 ///\author Laurent Aphecetche, Subatech
45
46 ///\cond CLASSIMP
47 ClassImp(AliMUONTrackerOCDBDataMaker)
48 ///\endcond
49
50 //_____________________________________________________________________________
51 AliMUONTrackerOCDBDataMaker::AliMUONTrackerOCDBDataMaker(const char* ocdbPath,
52                                                            Int_t runNumber,
53                                                            const char* type)
54 : AliMUONVTrackerDataMaker(),
55   fIsValid(kTRUE),
56   fData(0x0),
57   fSource(Form("%s-%010d-%s",ocdbPath,runNumber,type))
58 {
59         /// Ctor
60         AliCDBStorage* storage = AliCDBManager::Instance()->GetDefaultStorage();
61         
62         AliCDBManager::Instance()->SetDefaultStorage(ocdbPath);
63         
64         AliMUONVStore* store(0x0);
65         
66         TString stype(type);
67         stype.ToUpper();
68         Bool_t isSingleEvent(kTRUE);
69         Int_t startOfValidity(0);
70         
71         if ( stype == "PEDESTALS" )
72         {
73                 store = AliMUONCalibrationData::CreatePedestals(runNumber,&startOfValidity);
74                 fData = CreateDataPedestals(startOfValidity);
75         }
76         else if ( stype == "OCCUPANCY" )
77         {
78                 store = AliMUONCalibrationData::CreateOccupancyMap(runNumber,&startOfValidity);
79     
80     fData = new AliMUONTrackerData(Form("OCC%d",runNumber),"OccupancyMap",*store);
81     
82     fData->SetDimensionName(0,"One");
83     fData->SetDimensionName(1,"Zero");
84         }
85         else if ( stype == "GAINS" ) 
86         {
87                 AliMUONVStore* gains = AliMUONCalibrationData::CreateGains(runNumber,&startOfValidity);
88                 fData = CreateDataGains(startOfValidity);
89                 store = SplitQuality(*gains);
90                 delete gains;
91         }
92         else if ( stype == "CAPACITANCES" )
93         {
94                 store = AliMUONCalibrationData::CreateCapacitances(runNumber,&startOfValidity);
95                 fData = CreateDataCapacitances(startOfValidity);
96         }
97         else if ( stype == "HV" )
98         {
99                 TMap* m = AliMUONCalibrationData::CreateHV(runNumber,&startOfValidity);
100                 fData = new AliMUONTrackerData(Form("HV%d",startOfValidity),"High Voltages",1,!isSingleEvent);
101                 fData->SetDimensionName(0,"HV");
102                 store = CreateHVStore(*m);
103                 delete m;
104         }
105         
106         AliCDBManager::Instance()->SetDefaultStorage(storage);
107         
108         if (!store)
109         {
110                 fIsValid = kFALSE;
111                 delete fData;
112                 fData = 0x0;
113                 AliError("Could not create store");
114                 return;
115         }
116         
117   if ( type != "OCCUPANCY" )
118   {
119     fData->Add(*store);
120         }
121   
122         delete store;
123 }
124
125 //_____________________________________________________________________________
126 AliMUONTrackerOCDBDataMaker::~AliMUONTrackerOCDBDataMaker()
127 {
128   /// dtor
129   delete fData;
130 }
131
132 //_____________________________________________________________________________
133 AliMUONVTrackerData*
134 AliMUONTrackerOCDBDataMaker::CreateDataCapacitances(Int_t runNumber)
135 {
136   /// Create data to hold capa values
137   
138   AliMUONVTrackerData* data = new AliMUONTrackerData(Form("CAPA%d",runNumber),"Capacitances",2,kTRUE);
139   data->SetDimensionName(0,"Capa");
140   data->SetDimensionName(1,"Injection gain");
141   return data;
142 }
143
144 //_____________________________________________________________________________
145 AliMUONVTrackerData*
146 AliMUONTrackerOCDBDataMaker::CreateDataGains(Int_t runNumber)
147 {
148   /// Create data to hold gains values
149   
150   AliMUONVTrackerData* data = new AliMUONTrackerData(Form("GAIN%d",runNumber),"Gains",6,kTRUE);
151   data->SetDimensionName(0,"a1");
152   data->SetDimensionName(1,"a2");
153   data->SetDimensionName(2,"thres");
154   data->SetDimensionName(3,"qual1");
155   data->SetDimensionName(4,"qual2");
156   data->SetDimensionName(5,"sat");
157   return data;
158 }
159
160 //_____________________________________________________________________________
161 AliMUONVTrackerData*
162 AliMUONTrackerOCDBDataMaker::CreateDataPedestals(Int_t runNumber)
163 {
164   /// Create data to hold pedestal values
165   
166   AliMUONVTrackerData* data  = new AliMUONTrackerData(Form("PED%d",runNumber),"Pedestals",2,kTRUE);
167   data->SetDimensionName(0,"Mean");
168   data->SetDimensionName(1,"Sigma");
169   return data;
170 }
171
172 //_____________________________________________________________________________
173 AliMUONVStore*
174 AliMUONTrackerOCDBDataMaker::CreateHVStore(TMap& m)
175 {
176   /// Create a store from hv values
177   
178   AliMUONVStore* store = new AliMUON2DMap(kTRUE);
179   
180   TIter next(&m);
181   TObjString* s;
182   AliMpDCSNamer hvNamer("TRACKER");
183   
184   while ( ( s = static_cast<TObjString*>(next()) ) )
185   {
186     TString name(s->String());
187
188     Int_t detElemId = hvNamer.DetElemIdFromDCSAlias(name.Data());
189     
190     if ( !AliMpDEManager::IsValidDetElemId(detElemId) )
191     {
192       AliErrorClass(Form("Got an invalid DE = %d from alias = %s",
193                          detElemId,name.Data()));
194       continue;
195     }
196     
197     Int_t nindex = 1;
198     Int_t hvIndex = hvNamer.DCSIndexFromDCSAlias(name.Data());
199     
200     if ( hvIndex > 0 && detElemId >= 500 ) 
201     {
202       AliFatalClass("FIXME"); // there's now switch aliases which should be taken into account
203     }
204
205     if ( hvIndex == -2 ) // we should consider switch alias there...
206     {
207       nindex = hvNamer.NumberOfPCBs(detElemId);
208       hvIndex = 0;
209     }
210
211     AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
212
213     for ( int i = 0 ; i < nindex; ++i )
214     {
215       Int_t index = hvIndex + i ;
216       
217       const AliMpArrayI* manus = de->ManusForHV(index);
218       
219       TPair* p = static_cast<TPair*>(m.FindObject(name.Data()));
220       TObjArray* a = static_cast<TObjArray*>(p->Value());
221       TIter n2(a);
222       AliDCSValue* v;
223       Float_t hvValue(0);
224       Int_t n(0);
225       while ( ( v = static_cast<AliDCSValue*>(n2()) ) )
226       {
227         hvValue += v->GetFloat();  
228         ++n;
229       }
230       if ( n ) hvValue /= n;
231       
232       Int_t nofChannels(AliMpConstants::ManuNofChannels());
233       
234       for ( Int_t k = 0 ; k < manus->GetSize(); ++k )
235       {
236         Int_t manuId = manus->GetValue(k);
237         AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(store->FindObject(detElemId,manuId));
238         if ( ! param ) 
239         {
240           param = new AliMUONCalibParamND(1,nofChannels,detElemId,manuId,0);
241           store->Add(param);
242         }
243         for ( Int_t j = 0 ; j < nofChannels; ++j )
244         {
245           param->SetValueAsDouble(j,0,hvValue);
246         }
247       }
248     }
249   }
250   
251   return store;
252   
253 }
254
255 //_____________________________________________________________________________
256 Long64_t 
257 AliMUONTrackerOCDBDataMaker::Merge(TCollection*)
258 {
259   /// Merge
260   AliError("Not implemented. Does it have sense ?");
261   return 0;
262 }
263
264 //_____________________________________________________________________________
265 AliMUONVStore*
266 AliMUONTrackerOCDBDataMaker::SplitQuality(const AliMUONVStore& gains)
267 {
268   /// Create a new store, identical to source gain store, except that qual 
269   /// dimension is "decompacted" in two separated values
270   
271   AliMUONVStore* store = gains.Create();
272   
273   TIter next(gains.CreateIterator());
274   AliMUONVCalibParam* param;
275   
276   while ( ( param = static_cast<AliMUONVCalibParam*>(next()) ) ) 
277   {
278     AliMUONVCalibParam* nd = new AliMUONCalibParamND(param->Dimension()+1,
279                                                       param->Size(),
280                                                       param->ID0(),
281                                                       param->ID1());
282     for ( Int_t i = 0; i < param->Size(); ++i ) 
283     {
284       for ( Int_t k = 0; k < param->Dimension(); ++k ) 
285       {
286         if ( k == 3 ) continue;
287         Int_t m = ( k < 3 ? k : k+1 ) ;
288         nd->SetValueAsDouble(i,m,param->ValueAsFloat(i,k));
289       }
290       Int_t qual = param->ValueAsInt(i,3);
291                         
292                         Int_t q1 = (qual & 0xF0) >> 4;  // linear fit quality
293                         Int_t q2 = qual & 0xF;          // parabolic fit quality
294                         
295       nd->SetValueAsInt(i,3,q1);
296       nd->SetValueAsInt(i,4,q2);
297     }
298     store->Add(nd);
299   }
300   return store;
301 }