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 **************************************************************************/
18 /// By Laurent Aphecetche
20 #if !defined(__CINT__) || defined(__MAKECINT__)
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"
37 #include "TStopwatch.h"
43 static const char* CDBPath = "local://$ALICE_ROOT/MUON/CDB/Random";
45 //_____________________________________________________________________________
46 AliMpSegFactory* segFactory()
48 static AliMpSegFactory* sf = new AliMpSegFactory();
52 //_____________________________________________________________________________
53 AliMUONV3DStore* readCDB(const char* calibType="MUON/Calib/Pedestals")
55 AliCDBManager* man = AliCDBManager::Instance();
56 man->SetDefaultStorage(CDBPath);
58 AliCDBEntry* entry = man->Get(calibType,0);
62 return (AliMUONV3DStore*)entry->GetObject();
67 //_____________________________________________________________________________
68 void plotCDB(const char* calibType="MUON/Calib/Gains")
74 if ( c == "MUON/Calib/Gains" )
76 h = new TH1F("gains","gains",100,0,1.5);
78 else if ( c == "MUON/Calib/Pedestals" )
80 h = new TH1F("pedestals","pedestals",4096,-0.5,4095.5);
84 cerr << "Don't know how to deal with " << calibType << endl;
88 AliMUONV3DStore* store = readCDB(calibType);
91 TIter next(padList());
94 while ( ( t = (Triplet*)next() ) )
96 Int_t detElemId = t->DetElemId();
97 Int_t manuId = t->ManuId();
98 Int_t manuChannel = t->ManuChannel();
100 AliMUONCalibParam* value =
101 dynamic_cast<AliMUONCalibParam*>(store->Get(detElemId,manuId,manuChannel));
104 h->Fill(value->Mean());
108 cout << "Got a null value for DE=" << detElemId << " manuId="
109 << manuId << " manuChannel=" << manuChannel << endl;
116 //_____________________________________________________________________________
117 void testReadStore(const AliMUONV3DStore& store, Int_t n)
119 TIter next(padList());
122 while ( ( t = (Triplet*)next() ) )
124 for ( Int_t i = 0; i < n; ++i )
126 store.Get(t->DetElemId(),t->ManuId(),t->ManuChannel());
131 //_____________________________________________________________________________
132 Int_t makeStores(AliMUONV3DStore& pedestalStore,
133 AliMUONV3DStore& gainStore,
134 Bool_t defaultValues)
136 TIter next(padList());
142 Bool_t replace = kFALSE;
144 while ( ( t = (Triplet*)next() ) )
146 Float_t meanPedestal;
147 Float_t sigmaPedestal;
158 while ( meanPedestal < 0 )
160 meanPedestal = gRandom->Gaus(150,10);
163 while ( sigmaPedestal < 0 )
165 sigmaPedestal = gRandom->Gaus(1,0.2);
168 while ( meanGain < 0 )
170 meanGain = gRandom->Gaus(1,0.05);
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);
182 cout << "Could not set DetElemId=" << detElemId << " manuId="
183 << manuId << " manuChannel=" << manuChannel << endl;
194 //_____________________________________________________________________________
195 TList* padList(Bool_t reset)
197 static TList* fgPadList = new TList;
205 if (!fgPadList->IsEmpty()) return fgPadList;
209 cout << "Generating pad list. Please wait" << endl;
211 fgPadList->SetOwner(kTRUE);
219 while ( !it.IsDone() )
221 Int_t detElemId = it.CurrentDE();
222 AliMpStationType stationType = AliMpDEManager::GetStationType(detElemId);
223 if ( stationType != kStationTrigger )
225 for ( Int_t cath = 0; cath <=1 ; ++cath )
227 AliMpVSegmentation* seg = segFactory()->CreateMpSegmentation(detElemId,cath);
228 AliMpPlaneType planeType = AliMpDEManager::GetPlaneType(detElemId,cath);
230 for ( Int_t ix = 0; ix <= seg->MaxPadIndexX(); ++ix )
232 for ( Int_t iy = 0; iy <= seg->MaxPadIndexY(); ++iy )
234 AliMpPad pad = seg->PadByIndices(AliMpIntPair(ix,iy),kFALSE);
237 Int_t manuId = pad.GetLocation().GetFirst();
238 if ( planeType == kNonBendingPlane )
242 Int_t manuChannel = pad.GetLocation().GetSecond();
243 fgPadList->Add(new Triplet(detElemId,manuId,manuChannel));
252 cout << "Time to make the pad list = ";
258 //_____________________________________________________________________________
259 void testMakeStores(Int_t readLoop=10)
263 AliMUONV3DStore* pedestalStore = new AliMUON3DMap;
264 AliMUONV3DStore* gainStore = new AliMUON3DMap;
268 cout << "Creating" << endl;
271 makeStores(*pedestalStore,*gainStore,true);
274 cout << "Reading..." << endl;
276 testReadStore(*pedestalStore,readLoop);
277 testReadStore(*gainStore,readLoop);
278 cout << timer.CpuTime()/readLoop << " CPUs (mean of " << readLoop
279 <<" samples." << endl;
281 delete pedestalStore;
285 //_____________________________________________________________________________
286 void generateCalibrations(const char* cdbpath = CDBPath,
287 Bool_t defaultValues = kFALSE)
293 AliMUONV3DStore* pedestalStore = new AliMUON3DMap;
294 AliMUONV3DStore* gainStore = new AliMUON3DMap;
296 makeStores(*pedestalStore,*gainStore,defaultValues);
298 Int_t ever = 99999999;
300 AliCDBId id("MUON/Calib/Pedestals",0,ever);
303 md.SetAliRootVersion(gROOT->GetVersion());
306 md.SetComment("Test with default values");
310 md.SetComment("Test with random values");
312 md.SetResponsible("Laurent Aphecetche");
314 AliCDBManager* man = AliCDBManager::Instance();
315 man->SetDefaultStorage(cdbpath);
316 man->Put(pedestalStore,id,&md);
318 id.SetPath("MUON/Calib/Gains");
320 man->Put(gainStore,id,(AliCDBMetaData*)md.Clone());
322 delete pedestalStore;