]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/MUONCDB.C
- Adding handling of track info in digits.
[u/mrichter/AliRoot.git] / MUON / MUONCDB.C
CommitLineData
b3c7c475 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/// By Laurent Aphecetche
19
20#if !defined(__CINT__) || defined(__MAKECINT__)
21#include "MUONCDB.h"
22#include "AliCDBEntry.h"
23#include "AliCDBManager.h"
24#include "AliMUON3DMap.h"
25#include "AliMUONV3DStore.h"
26#include "AliMUONCalibParam.h"
27#include "AliMpDEIterator.h"
28#include "AliMpDEManager.h"
29#include "AliMpPlaneType.h"
30#include "AliMpSegFactory.h"
31#include "AliMpStationType.h"
32#include "AliMpVSegmentation.h"
33#include "Riostream.h"
34#include "TH1F.h"
35#include "TList.h"
36#include "TRandom.h"
37#include "TStopwatch.h"
38#include "TSystem.h"
39#endif
40
41ClassImp(Triplet)
42
43static const char* CDBPath = "local://$ALICE_ROOT/MUON/CDB/Random";
44
45//_____________________________________________________________________________
46AliMpSegFactory* segFactory()
47{
48 static AliMpSegFactory* sf = new AliMpSegFactory();
49 return sf;
50}
51
52//_____________________________________________________________________________
53AliMUONV3DStore* readCDB(const char* calibType="MUON/Calib/Pedestals")
54{
55 AliCDBManager* man = AliCDBManager::Instance();
56 man->SetDefaultStorage(CDBPath);
57
58 AliCDBEntry* entry = man->Get(calibType,0);
59
60 if (entry)
61 {
62 return (AliMUONV3DStore*)entry->GetObject();
63 }
64 return 0;
65}
66
67//_____________________________________________________________________________
68void plotCDB(const char* calibType="MUON/Calib/Gains")
69{
70 TString c(calibType);
71
72 TH1* h = 0;
73
74 if ( c == "MUON/Calib/Gains" )
75 {
76 h = new TH1F("gains","gains",100,0,1.5);
77 }
78 else if ( c == "MUON/Calib/Pedestals" )
79 {
80 h = new TH1F("pedestals","pedestals",4096,-0.5,4095.5);
81 }
82 else
83 {
84 cerr << "Don't know how to deal with " << calibType << endl;
85 return;
86 }
87
88 AliMUONV3DStore* store = readCDB(calibType);
89 if (!store) return;
90
91 TIter next(padList());
92 Triplet* t;
93
94 while ( ( t = (Triplet*)next() ) )
95 {
96 Int_t detElemId = t->DetElemId();
97 Int_t manuId = t->ManuId();
98 Int_t manuChannel = t->ManuChannel();
99
100 AliMUONCalibParam* value =
101 dynamic_cast<AliMUONCalibParam*>(store->Get(detElemId,manuId,manuChannel));
102 if (value)
103 {
104 h->Fill(value->Mean());
105 }
106 else
107 {
108 cout << "Got a null value for DE=" << detElemId << " manuId="
109 << manuId << " manuChannel=" << manuChannel << endl;
110 }
111 }
112
113 delete store;
114}
115
116//_____________________________________________________________________________
117void testReadStore(const AliMUONV3DStore& store, Int_t n)
118{
119 TIter next(padList());
120 Triplet* t;
121
122 while ( ( t = (Triplet*)next() ) )
123 {
124 for ( Int_t i = 0; i < n; ++i )
125 {
126 store.Get(t->DetElemId(),t->ManuId(),t->ManuChannel());
127 }
128 }
129}
130
131//_____________________________________________________________________________
132Int_t makeStores(AliMUONV3DStore& pedestalStore,
133 AliMUONV3DStore& gainStore,
134 Bool_t defaultValues)
135{
136 TIter next(padList());
137
138 Triplet* t;
139
140 Int_t ngenerated(0);
141
142 Bool_t replace = kFALSE;
143
144 while ( ( t = (Triplet*)next() ) )
145 {
146 Float_t meanPedestal;
147 Float_t sigmaPedestal;
148 Float_t meanGain;
149 if ( defaultValues )
150 {
151 meanPedestal = 0.0;
152 sigmaPedestal = 1.0;
153 meanGain = 1.0;
154 }
155 else
156 {
157 meanPedestal = -1;
158 while ( meanPedestal < 0 )
159 {
160 meanPedestal = gRandom->Gaus(150,10);
161 }
162 sigmaPedestal = -1;
163 while ( sigmaPedestal < 0 )
164 {
165 sigmaPedestal = gRandom->Gaus(1,0.2);
166 }
167 meanGain = -1;
168 while ( meanGain < 0 )
169 {
170 meanGain = gRandom->Gaus(1,0.05);
171 }
172 }
173 Int_t detElemId = t->DetElemId();
174 Int_t manuId = t->ManuId();
175 Int_t manuChannel = t->ManuChannel();
176 Bool_t ok1 = pedestalStore.Set(detElemId,manuId,manuChannel,
177 new AliMUONCalibParam(meanPedestal,sigmaPedestal),replace);
178 Bool_t ok2 = gainStore.Set(detElemId,manuId,manuChannel,
179 new AliMUONCalibParam(meanGain,0),replace);
180 if (!ok1 || !ok2)
181 {
182 cout << "Could not set DetElemId=" << detElemId << " manuId="
183 << manuId << " manuChannel=" << manuChannel << endl;
184 }
185 else
186 {
187 ++ngenerated;
188 }
189 }
190
191 return ngenerated;
192}
193
194//_____________________________________________________________________________
195TList* padList(Bool_t reset)
196{
197 static TList* fgPadList = new TList;
198
199 if (reset)
200 {
201 fgPadList->Delete();
202 return fgPadList;
203 }
204
205 if (!fgPadList->IsEmpty()) return fgPadList;
206
207 TStopwatch timer;
208
209 cout << "Generating pad list. Please wait" << endl;
210
211 fgPadList->SetOwner(kTRUE);
212
213 timer.Start();
214
215 AliMpDEIterator it;
216
217 it.First();
218
219 while ( !it.IsDone() )
220 {
221 Int_t detElemId = it.CurrentDE();
222 AliMpStationType stationType = AliMpDEManager::GetStationType(detElemId);
223 if ( stationType != kStationTrigger )
224 {
225 for ( Int_t cath = 0; cath <=1 ; ++cath )
226 {
227 AliMpVSegmentation* seg = segFactory()->CreateMpSegmentation(detElemId,cath);
228 AliMpPlaneType planeType = AliMpDEManager::GetPlaneType(detElemId,cath);
229
230 for ( Int_t ix = 0; ix <= seg->MaxPadIndexX(); ++ix )
231 {
232 for ( Int_t iy = 0; iy <= seg->MaxPadIndexY(); ++iy )
233 {
234 AliMpPad pad = seg->PadByIndices(AliMpIntPair(ix,iy),kFALSE);
235 if ( pad.IsValid() )
236 {
237 Int_t manuId = pad.GetLocation().GetFirst();
238 if ( planeType == kNonBendingPlane )
239 {
240 manuId |= (1<<11);
241 }
242 Int_t manuChannel = pad.GetLocation().GetSecond();
243 fgPadList->Add(new Triplet(detElemId,manuId,manuChannel));
244 }
245 }
246 }
247 }
248 }
249 it.Next();
250 }
251
252 cout << "Time to make the pad list = ";
253 timer.Print();
254
255 return fgPadList;
256}
257
258//_____________________________________________________________________________
259void testMakeStores(Int_t readLoop=10)
260{
261 padList();
262
263 AliMUONV3DStore* pedestalStore = new AliMUON3DMap;
264 AliMUONV3DStore* gainStore = new AliMUON3DMap;
265
266 TStopwatch timer;
267
268 cout << "Creating" << endl;
269
270 timer.Start(kTRUE);
271 makeStores(*pedestalStore,*gainStore,true);
272 timer.Print();
273
274 cout << "Reading..." << endl;
275 timer.Start(kTRUE);
276 testReadStore(*pedestalStore,readLoop);
277 testReadStore(*gainStore,readLoop);
278 cout << timer.CpuTime()/readLoop << " CPUs (mean of " << readLoop
279 <<" samples." << endl;
280
281 delete pedestalStore;
282 delete gainStore;
283}
284
285//_____________________________________________________________________________
286void generateCalibrations(const char* cdbpath = CDBPath,
287 Bool_t defaultValues = kFALSE)
288{
289 //
290 //
291 //
292
293 AliMUONV3DStore* pedestalStore = new AliMUON3DMap;
294 AliMUONV3DStore* gainStore = new AliMUON3DMap;
295
296 makeStores(*pedestalStore,*gainStore,defaultValues);
297
298 Int_t ever = 99999999;
299
300 AliCDBId id("MUON/Calib/Pedestals",0,ever);
301 AliCDBMetaData md;
302 md.SetBeamPeriod(1);
303 md.SetAliRootVersion(gROOT->GetVersion());
304 if ( defaultValues )
305 {
306 md.SetComment("Test with default values");
307 }
308 else
309 {
310 md.SetComment("Test with random values");
311 }
312 md.SetResponsible("Laurent Aphecetche");
313
314 AliCDBManager* man = AliCDBManager::Instance();
315 man->SetDefaultStorage(cdbpath);
316 man->Put(pedestalStore,id,&md);
317
318 id.SetPath("MUON/Calib/Gains");
319
320 man->Put(gainStore,id,(AliCDBMetaData*)md.Clone());
321
322 delete pedestalStore;
323 delete gainStore;
324}
325
326