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