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 //-----------------------------------------------------------------------------
21 /// \class AliMUONGainEventGenerator
23 /// Generate raw data files that mimics the one we'll get from the
24 /// online gain calibration procedure.
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)
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]
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.
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.
43 /// \author Laurent Aphecetche
44 //-----------------------------------------------------------------------------
46 #include "AliMUONCalibrationData.h"
47 #include "AliMUONVStore.h"
48 #include "AliMUONVCalibParam.h"
50 #include "AliCDBEntry.h"
51 #include "AliCDBManager.h"
52 #include "AliMUONPedestalEventGenerator.h"
56 #include "AliMUONDigitizerV3.h"
57 #include "AliCodeTimer.h"
60 ClassImp(AliMUONGainEventGenerator)
63 //_____________________________________________________________________________
64 AliMUONGainEventGenerator::AliMUONGainEventGenerator( Int_t sourceGainRunNumber,
65 Int_t sourcePedRunNumber,
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))
79 AliFatal(Form("Cannot get gains for run %d",sourceGainRunNumber));
81 if (!fSourcePedestals)
83 AliFatal(Form("Cannot get pedestals for run %d",sourcePedRunNumber));
87 //_____________________________________________________________________________
88 AliMUONGainEventGenerator::~AliMUONGainEventGenerator()
92 delete fSourcePedestals;
95 //_____________________________________________________________________________
97 AliMUONGainEventGenerator::Exec(Option_t*)
101 AliCodeTimer::Instance()->Reset();
103 const Int_t kNInjections = 9;
104 Float_t injections[kNInjections] = { 0, 200 , 400, 800, 1200, 1600,
107 for ( Int_t i = 0; i < kNInjections; ++i )
109 Int_t runNumber = fSourcePedestalRunNumber + i;
112 GeneratePedestals(runNumber,injections[i]);
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());
119 AliCodeTimerAuto(Form("generation of pedestal for run %d",runNumber),0);
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));
125 gSystem->ChangeDirectory(pwd.Data());
128 AliCodeTimer::Instance()->Print();
131 //_____________________________________________________________________________
133 AliMUONGainEventGenerator::GeneratePedestals(Int_t runNumber, Float_t injection)
135 /// Generate "pedestal" values for a given run, by "decalibrating"
138 AliCodeTimerAuto(Form("Run %d injection %7.2f",runNumber,injection),0);
139 TIter next(fSourceGains->CreateIterator());
141 AliMUONVStore* generatedPedestals = fSourcePedestals->Create();
143 AliMUONVCalibParam* gain;
144 AliMUONVCalibParam* ped;
146 while ( ( gain = static_cast<AliMUONVCalibParam*>(next()) ) )
148 ped = static_cast<AliMUONVCalibParam*>(fSourcePedestals->FindObject(gain->ID0(),gain->ID1()));
150 AliMUONVCalibParam* genPed = static_cast<AliMUONVCalibParam*>(generatedPedestals->FindObject(gain->ID0(),gain->ID1()));
153 genPed = static_cast<AliMUONVCalibParam*>(ped->Clone());
154 generatedPedestals->Add(genPed);
157 for ( Int_t i = 0; i < ped->Size(); ++i )
159 Float_t mean = ped->ValueAsFloat(i,0);
160 if ( mean == AliMUONVCalibParam::InvalidFloatValue() )
162 // non existing channel
165 Int_t adc = AliMUONDigitizerV3::DecalibrateTrackerDigit(*ped,gain,i,
168 Float_t res = (ped->ValueAsFloat(i,1)/mean);
170 genPed->SetValueAsFloat(i,0,adc);
171 genPed->SetValueAsFloat(i,1,adc*res);
175 WriteToCDB(generatedPedestals,runNumber);
177 delete generatedPedestals;
180 //_____________________________________________________________________________
182 AliMUONGainEventGenerator::WriteToCDB(TObject* object, Int_t runNumber)
184 /// Write a given object to OCDB
186 AliCDBId id("MUON/Calib/Pedestals",runNumber,runNumber);
188 md.SetAliRootVersion(gROOT->GetVersion());
189 md.SetComment("Pedestal values generated from AliMUONGainEventGenerator");
190 md.SetResponsible("AliMUONGainEventGenerator");
192 AliCDBManager* man = AliCDBManager::Instance();
193 man->SetDefaultStorage("local://$ALICE_ROOT/OCDB/SHUTTLE/TestShuttle/TestCDB");
194 man->Put(object,id,&md);