]>
Commit | Line | Data |
---|---|---|
a8c210bf | 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 "AliMUONGainEventGenerator.h" | |
19 | ||
20 | /// \class AliMUONGainEventGenerator | |
21 | /// | |
22 | /// Generate raw data files that mimics the one we'll get from the | |
23 | /// online gain calibration procedure. | |
24 | /// | |
25 | /// We start from one set of gain values, and one set of pedestal values, | |
26 | /// to be found in the OCDB | |
27 | /// (generated e.g. with AliMUONCDB class) | |
28 | /// | |
29 | /// We then use those gains and to generate n sets of pedestal values, | |
30 | /// that we store in OCDB in runs = [firstRunNumber+1,...firstRunNumber+n-1] | |
31 | /// | |
32 | /// Then we loop from 0 to n-1, and for each, we generate a pedestal file, | |
33 | /// using AliMUONPedestalEventGenerator, where the pedestals used are those | |
34 | /// stored in the previous step. | |
35 | /// | |
36 | /// Output files are supposed to be processed by the MUONTRKda (gain part) | |
37 | /// to produce 4 (one per LDC) ascii files (with computed gain values), that | |
38 | /// in turn will be processed by the Shuttle to put gain values in the OCDB. | |
39 | /// Those last gains in OCDB can be then compared with the ones generated in | |
40 | /// the first step, to check that everything is OK in the whole procedure. | |
41 | /// | |
42 | /// \author Laurent Aphecetche | |
43 | ||
44 | #include "AliMUONCalibrationData.h" | |
45 | #include "AliMUONVStore.h" | |
46 | #include "AliMUONVCalibParam.h" | |
47 | #include <TRandom.h> | |
48 | #include "AliCDBEntry.h" | |
49 | #include "AliCDBManager.h" | |
50 | #include "AliMUONPedestalEventGenerator.h" | |
51 | #include "AliLog.h" | |
52 | #include <TROOT.h> | |
53 | #include <TSystem.h> | |
54 | #include "AliMUONDigitizerV3.h" | |
55 | #include "AliCodeTimer.h" | |
56 | ||
57 | /// \cond CLASSIMP | |
58 | ClassImp(AliMUONGainEventGenerator) | |
59 | /// \endcond | |
60 | ||
61 | //_____________________________________________________________________________ | |
62 | AliMUONGainEventGenerator::AliMUONGainEventGenerator( Int_t sourceGainRunNumber, | |
63 | Int_t sourcePedRunNumber, | |
64 | Int_t nEventsPerFile, | |
65 | const char* dateBaseFileName) | |
66 | : TTask("AliMUONGainEventGenerator","Generate gain raw data files"), | |
67 | fNofEventsPerFile(nEventsPerFile), | |
68 | fSourcePedestalRunNumber(sourcePedRunNumber), | |
69 | fDateBaseFileName(dateBaseFileName), | |
70 | fSourceGains(AliMUONCalibrationData::CreateGains(sourceGainRunNumber)), | |
71 | fSourcePedestals(AliMUONCalibrationData::CreatePedestals(fSourcePedestalRunNumber)) | |
72 | { | |
73 | /// Ctor | |
74 | ||
75 | if (!fSourceGains) | |
76 | { | |
77 | AliFatal(Form("Cannot get gains for run %d",sourceGainRunNumber)); | |
78 | } | |
79 | if (!fSourcePedestals) | |
80 | { | |
81 | AliFatal(Form("Cannot get pedestals for run %d",sourcePedRunNumber)); | |
82 | } | |
83 | } | |
84 | ||
85 | //_____________________________________________________________________________ | |
86 | AliMUONGainEventGenerator::~AliMUONGainEventGenerator() | |
87 | { | |
88 | /// dtor | |
89 | delete fSourceGains; | |
90 | delete fSourcePedestals; | |
91 | } | |
92 | ||
93 | //_____________________________________________________________________________ | |
94 | void | |
95 | AliMUONGainEventGenerator::Exec(Option_t*) | |
96 | { | |
97 | /// Main method | |
98 | ||
99 | AliCodeTimer::Instance()->Reset(); | |
100 | ||
101 | const Int_t kNInjections = 9; | |
102 | Float_t injections[kNInjections] = { 0, 200 , 400, 800, 1200, 1600, | |
103 | 2000, 2500, 3000 }; | |
104 | ||
105 | for ( Int_t i = 0; i < kNInjections; ++i ) | |
106 | { | |
107 | Int_t runNumber = fSourcePedestalRunNumber + i; | |
108 | if (i) | |
109 | { | |
110 | GeneratePedestals(runNumber,injections[i]); | |
111 | } | |
112 | TString pwd(gSystem->WorkingDirectory()); | |
113 | TString dir(Form("%s/RUN%d",pwd.Data(),runNumber)); | |
114 | AliInfo(Form("Creating directory %s",dir.Data())); | |
115 | gSystem->MakeDirectory(dir.Data()); | |
116 | gSystem->ChangeDirectory(dir.Data()); | |
117 | AliCodeTimerAuto(Form("generation of pedestal for run %d",runNumber)); | |
118 | TString pedfile; | |
119 | if ( fDateBaseFileName.Length() > 0 ) pedfile = Form("%s.%d",fDateBaseFileName.Data(),runNumber); | |
120 | AliMUONPedestalEventGenerator pgen(runNumber,fNofEventsPerFile,pedfile.Data()); | |
121 | AliInfo(Form("Generating pedestal events for injection number %d. Please be patient.",i)); | |
122 | pgen.Exec(""); | |
123 | gSystem->ChangeDirectory(pwd.Data()); | |
124 | } | |
125 | ||
126 | AliCodeTimer::Instance()->Print(); | |
127 | } | |
128 | ||
129 | //_____________________________________________________________________________ | |
130 | void | |
131 | AliMUONGainEventGenerator::GeneratePedestals(Int_t runNumber, Float_t injection) | |
132 | { | |
133 | /// Generate "pedestal" values for a given run, by "decalibrating" | |
134 | /// charge injection | |
135 | ||
136 | AliCodeTimerAuto(Form("Run %d injection %7.2f",runNumber,injection)); | |
137 | TIter next(fSourceGains->CreateIterator()); | |
138 | ||
139 | AliMUONVStore* generatedPedestals = fSourcePedestals->Create(); | |
140 | ||
141 | AliMUONVCalibParam* gain; | |
142 | AliMUONVCalibParam* ped; | |
143 | ||
144 | while ( ( gain = static_cast<AliMUONVCalibParam*>(next()) ) ) | |
145 | { | |
146 | ped = static_cast<AliMUONVCalibParam*>(fSourcePedestals->FindObject(gain->ID0(),gain->ID1())); | |
147 | ||
148 | AliMUONVCalibParam* genPed = static_cast<AliMUONVCalibParam*>(generatedPedestals->FindObject(gain->ID0(),gain->ID1())); | |
149 | if (!genPed) | |
150 | { | |
151 | genPed = static_cast<AliMUONVCalibParam*>(ped->Clone()); | |
152 | generatedPedestals->Add(genPed); | |
153 | } | |
154 | ||
155 | for ( Int_t i = 0; i < ped->Size(); ++i ) | |
156 | { | |
157 | Float_t mean = ped->ValueAsFloat(i,0); | |
158 | if ( mean == AliMUONVCalibParam::InvalidFloatValue() ) | |
159 | { | |
160 | // non existing channel | |
161 | continue; | |
162 | } | |
163 | Int_t adc = AliMUONDigitizerV3::DecalibrateTrackerDigit(*ped,*gain,i, | |
164 | injection,kFALSE); | |
165 | ||
166 | Float_t res = (ped->ValueAsFloat(i,1)/mean); | |
167 | ||
168 | genPed->SetValueAsFloat(i,0,adc); | |
169 | genPed->SetValueAsFloat(i,1,adc*res); | |
170 | } | |
171 | } | |
172 | ||
173 | WriteToCDB(generatedPedestals,runNumber); | |
174 | ||
175 | delete generatedPedestals; | |
176 | } | |
177 | ||
178 | //_____________________________________________________________________________ | |
179 | void | |
180 | AliMUONGainEventGenerator::WriteToCDB(TObject* object, Int_t runNumber) | |
181 | { | |
182 | /// Write a given object to OCDB | |
183 | ||
184 | AliCDBId id("MUON/Calib/Pedestals",runNumber,runNumber); | |
185 | AliCDBMetaData md; | |
186 | md.SetAliRootVersion(gROOT->GetVersion()); | |
187 | md.SetComment("Pedestal values generated from AliMUONGainEventGenerator"); | |
188 | md.SetResponsible("AliMUONGainEventGenerator"); | |
189 | ||
190 | AliCDBManager* man = AliCDBManager::Instance(); | |
191 | man->SetDefaultStorage("local://$ALICE_ROOT/SHUTTLE/TestShuttle/TestCDB"); | |
192 | man->Put(object,id,&md); | |
193 | } |