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 #include "AliMUONGainEventGenerator.h"
20 /// \class AliMUONGainEventGenerator
22 /// Generate raw data files that mimics the one we'll get from the
23 /// online gain calibration procedure.
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)
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]
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.
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.
42 /// \author Laurent Aphecetche
44 #include "AliMUONCalibrationData.h"
45 #include "AliMUONVStore.h"
46 #include "AliMUONVCalibParam.h"
48 #include "AliCDBEntry.h"
49 #include "AliCDBManager.h"
50 #include "AliMUONPedestalEventGenerator.h"
54 #include "AliMUONDigitizerV3.h"
55 #include "AliCodeTimer.h"
58 ClassImp(AliMUONGainEventGenerator)
61 //_____________________________________________________________________________
62 AliMUONGainEventGenerator::AliMUONGainEventGenerator( Int_t sourceGainRunNumber,
63 Int_t sourcePedRunNumber,
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))
77 AliFatal(Form("Cannot get gains for run %d",sourceGainRunNumber));
79 if (!fSourcePedestals)
81 AliFatal(Form("Cannot get pedestals for run %d",sourcePedRunNumber));
85 //_____________________________________________________________________________
86 AliMUONGainEventGenerator::~AliMUONGainEventGenerator()
90 delete fSourcePedestals;
93 //_____________________________________________________________________________
95 AliMUONGainEventGenerator::Exec(Option_t*)
99 AliCodeTimer::Instance()->Reset();
101 const Int_t kNInjections = 9;
102 Float_t injections[kNInjections] = { 0, 200 , 400, 800, 1200, 1600,
105 for ( Int_t i = 0; i < kNInjections; ++i )
107 Int_t runNumber = fSourcePedestalRunNumber + i;
110 GeneratePedestals(runNumber,injections[i]);
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));
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));
123 gSystem->ChangeDirectory(pwd.Data());
126 AliCodeTimer::Instance()->Print();
129 //_____________________________________________________________________________
131 AliMUONGainEventGenerator::GeneratePedestals(Int_t runNumber, Float_t injection)
133 /// Generate "pedestal" values for a given run, by "decalibrating"
136 AliCodeTimerAuto(Form("Run %d injection %7.2f",runNumber,injection));
137 TIter next(fSourceGains->CreateIterator());
139 AliMUONVStore* generatedPedestals = fSourcePedestals->Create();
141 AliMUONVCalibParam* gain;
142 AliMUONVCalibParam* ped;
144 while ( ( gain = static_cast<AliMUONVCalibParam*>(next()) ) )
146 ped = static_cast<AliMUONVCalibParam*>(fSourcePedestals->FindObject(gain->ID0(),gain->ID1()));
148 AliMUONVCalibParam* genPed = static_cast<AliMUONVCalibParam*>(generatedPedestals->FindObject(gain->ID0(),gain->ID1()));
151 genPed = static_cast<AliMUONVCalibParam*>(ped->Clone());
152 generatedPedestals->Add(genPed);
155 for ( Int_t i = 0; i < ped->Size(); ++i )
157 Float_t mean = ped->ValueAsFloat(i,0);
158 if ( mean == AliMUONVCalibParam::InvalidFloatValue() )
160 // non existing channel
163 Int_t adc = AliMUONDigitizerV3::DecalibrateTrackerDigit(*ped,*gain,i,
166 Float_t res = (ped->ValueAsFloat(i,1)/mean);
168 genPed->SetValueAsFloat(i,0,adc);
169 genPed->SetValueAsFloat(i,1,adc*res);
173 WriteToCDB(generatedPedestals,runNumber);
175 delete generatedPedestals;
178 //_____________________________________________________________________________
180 AliMUONGainEventGenerator::WriteToCDB(TObject* object, Int_t runNumber)
182 /// Write a given object to OCDB
184 AliCDBId id("MUON/Calib/Pedestals",runNumber,runNumber);
186 md.SetAliRootVersion(gROOT->GetVersion());
187 md.SetComment("Pedestal values generated from AliMUONGainEventGenerator");
188 md.SetResponsible("AliMUONGainEventGenerator");
190 AliCDBManager* man = AliCDBManager::Instance();
191 man->SetDefaultStorage("local://$ALICE_ROOT/SHUTTLE/TestShuttle/TestCDB");
192 man->Put(object,id,&md);