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 ////////////////////////////////////////////////////////////////////////////
20 // This class is a first implementation for the TRD. //
21 // It takes data from HLT and computes the parameters //
22 // and stores both reference data and online calibration //
23 // parameters in the CDB //
26 // R. Bailhache (R.Bailhache@gsi.de) //
28 ////////////////////////////////////////////////////////////////////////////
30 #include "AliTRDPreprocessor.h"
32 #include <TTimeStamp.h>
34 #include <TProfile2D.h>
36 #include <TStopwatch.h>
37 #include <TObjString.h>
40 #include <TCollection.h>
42 #include "AliCDBMetaData.h"
43 #include "AliDCSValue.h"
46 #include "AliTRDCalibra.h"
47 #include "Cal/AliTRDCalDet.h"
49 ClassImp(AliTRDPreprocessor)
51 //______________________________________________________________________________________________
52 AliTRDPreprocessor::AliTRDPreprocessor(AliShuttleInterface *shuttle)
53 :AliPreprocessor("TRD", shuttle)
61 //______________________________________________________________________________________________
62 AliTRDPreprocessor::~AliTRDPreprocessor()
70 //______________________________________________________________________________________________
71 void AliTRDPreprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
74 // Initialization routine for the TRD preprocessor
77 AliPreprocessor::Initialize(run,startTime,endTime);
81 //______________________________________________________________________________________________
82 UInt_t AliTRDPreprocessor::Process(TMap* /*dcsAliasMap*/)
85 // Process the calibration data for the HLT part
88 // How long does it take for the HLT part?
92 // Metadata for the reference data
93 AliCDBMetaData metaData;
94 metaData.SetBeamPeriod(1);
95 metaData.SetResponsible("Raphaelle Bailhache");
96 metaData.SetComment("This preprocessor fills reference data.");
98 // Take the file from the HLT file exchange server
99 TList *filesources = GetFileSources(kHLT,"GAINDRIFTPRF");
101 AliError(Form("No sources found for GAINDRIFTPRF for run %d !",fRun));
104 if (filesources->GetSize() != 1) {
105 AliError(Form("More than one source found for GAINDRIFTPRF for run %d!",fRun));
109 // Call a AliTRDCalibra instance for fit
110 AliTRDCalibra *calibra = AliTRDCalibra::Instance();
113 AliTRDCalDet *objgaindet = 0x0; // Object for det average gain factor
114 AliTRDCalDet *objdriftvelocitydet = 0x0; // Object for det average drift velocity
115 AliTRDCalDet *objtime0det = 0x0; // Object for det average time0
116 TObject *objgainpad = 0x0; // Object for pad (relative to the det) gain factor
117 TObject *objdriftvelocitypad = 0x0; // Object for pad (relative to the det) drift velocity
118 TObject *objtime0pad = 0x0; // Object for pad (relative to the det) time0
119 TObject *objPRFpad = 0x0; // Object for pad prf width
120 TH2I *histogain = 0x0; // Histogram taken from HLT for gain factor
121 TProfile2D *histodriftvelocity = 0x0; // Profile taken from HLT for drift velocity and time0
122 TProfile2D *histoprf = 0x0; // Profile taken from HLT for prf
124 Int_t numberfit[3] = { 0, 0, 0 }; // Number of histos fitted for gain, drift velocity and prf
125 Int_t numberEnt[3] = { 0, 0, 0 }; // Number of histos with entries
126 Double_t statisticmean[3] = { 0.0, 0.0, 0.0 }; // Mean values of the number of entries in these histos
127 Int_t numbertotalgroup[3] = { 0, 0, 0 }; // Total number of groups
129 // Loop over the files taken from the HLT
130 TIter iter(filesources);
132 while ((source = dynamic_cast<TObjString *> (iter.Next()))) {
134 TString filename = GetFile(kHLT,"GAINDRIFTPRF",source->GetName());
135 if (filename.Length() == 0) {
136 AliError(Form("Error retrieving file from source %d failed!", source->GetName()));
142 TFile *file = TFile::Open(filename);
143 histogain = (TH2I *) file->Get("CH2d");
144 histogain->SetDirectory(0);
146 AliError("Error retrieving 2D histos for gain failed!");
148 histodriftvelocity = (TProfile2D *) file->Get("PH2d");
149 histodriftvelocity->SetDirectory(0);
150 if (!histodriftvelocity) {
151 AliError("Error retrieving 2D Profile for average pulse height failed!");
153 histoprf = (TProfile2D *) file->Get("PRF2d");
154 histoprf->SetDirectory(0);
156 AliError("Error retrieving 2D Profile for Pad Response Function failed!");
160 // Set the mode of calibration from the TObject, store the reference data and try to fit them
162 calibra->SetModeCalibrationFromTObject((TObject *) histogain,0);
163 StoreReferenceData("HLTData","Gain",(TObject *) histogain,&metaData);
164 AliInfo("Take the CH reference data. Now we will try to fit\n");
165 calibra->SetMinEntries(100); // If there is less than 100 entries in the histo: no fit
166 calibra->FitCHOnline(histogain);
167 numbertotalgroup[0] = 6*4*18*((Int_t) calibra->GetDetChamb0(0))
168 + 6* 18*((Int_t) calibra->GetDetChamb2(0));
169 numberfit[0] = calibra->GetNumberFit();
170 statisticmean[0] = calibra->GetStatisticMean();
171 numberEnt[0] = calibra->GetNumberEnt();
172 objgaindet = calibra->CreateDetObjectTree(calibra->GetGain(),0);
173 objgainpad = calibra->CreatePadObjectTree(calibra->GetGain(),0,objgaindet);
176 if (histodriftvelocity) {
177 calibra->SetModeCalibrationFromTObject((TObject *) histodriftvelocity,1);
178 StoreReferenceData("HLTData","VdriftT0",(TObject *) histodriftvelocity,&metaData);
179 AliInfo("Take the PH reference data. Now we will try to fit\n");
180 calibra->SetMinEntries(100*20); // If there is less than 2000
181 calibra->FitPHOnline(histodriftvelocity);
182 numbertotalgroup[1] = 6*4*18*((Int_t) calibra->GetDetChamb0(1))
183 + 6* 18*((Int_t) calibra->GetDetChamb2(1));
184 numberfit[1] = calibra->GetNumberFit();
185 statisticmean[1] = calibra->GetStatisticMean();
186 numberEnt[1] = calibra->GetNumberEnt();
187 objdriftvelocitydet = calibra->CreateDetObjectTree(calibra->GetVdrift(),1);
188 objdriftvelocitypad = calibra->CreatePadObjectTree(calibra->GetVdrift(),1,objdriftvelocitydet);
189 objtime0det = calibra->CreateDetObjectTree(calibra->GetT0(),3);
190 objtime0pad = calibra->CreatePadObjectTree(calibra->GetT0(),3,objtime0det);
194 calibra->SetModeCalibrationFromTObject((TObject *) histoprf,2);
195 StoreReferenceData("HLTData","PRF",(TObject *) histoprf,&metaData);
196 AliInfo("Take the PRF reference data. Now we will try to fit\n");
197 calibra->SetMinEntries(100*20); // If there is less than 2000
198 calibra->SetRangeFitPRF(0.5);
199 calibra->FitPRFOnline(histoprf);
200 numbertotalgroup[2] = 6*4*18*((Int_t) calibra->GetDetChamb0(2))
201 + 6* 18*((Int_t) calibra->GetDetChamb2(2));
202 numberfit[2] = calibra->GetNumberFit();
203 statisticmean[2] = calibra->GetStatisticMean();
204 numberEnt[2] = calibra->GetNumberEnt();
205 objPRFpad = calibra->CreatePadObjectTree(calibra->GetPRF());
210 // Bilan of the fit statistic
211 AliInfo(Form("The mean number of entries required for a fit is: %d"
212 ,(Int_t) calibra->GetMinEntries()));
213 AliInfo(Form("FOR THE CH: There is a mean statistic of: %f, with %d fits for %d groups and %d histos with entries"
214 ,statisticmean[0],numberfit[0],numbertotalgroup[0],numberEnt[0]));
215 AliInfo(Form("FOR THE PH: There is a mean statistic of: %f, with %d fits for %d groups and %d histos with entries"
216 ,statisticmean[1],numberfit[1],numbertotalgroup[1],numberEnt[1]));
217 AliInfo(Form("FOR THE PRF: There is a mean statistic of: %f, with %d fits for %d groups and %d histos with entries"
218 ,statisticmean[2],numberfit[2],numbertotalgroup[2],numberEnt[2]));
222 // Store the coefficients in the grid OCDB if enough statistics
225 // Store the infos for the detector
226 AliCDBMetaData *md1= new AliCDBMetaData();
227 md1->SetObjectClassName("AliTRDCalDet");
228 md1->SetResponsible("Raphaelle Bailhache");
229 md1->SetBeamPeriod(1);
230 md1->SetAliRootVersion("01-10-06"); // root version
231 md1->SetComment("The dummy values in this calibration file are for testing only");
232 if ((numbertotalgroup[0] > 0) &&
233 (numberfit[0] >= 0.95*numberEnt[0])) {
234 Store("Calib","ChamberGainFactor",(TObject *) objgaindet ,md1,0,kTRUE);
236 if ((numbertotalgroup[1] > 0) &&
237 (numberfit[1] >= 0.95*numberEnt[1])) {
238 Store("Calib","ChamberVdrift" ,(TObject *) objdriftvelocitydet,md1,0,kTRUE);
239 Store("Calib","ChamberT0" ,(TObject *) objtime0det ,md1,0,kTRUE);
242 // Store the infos for the pads
243 AliCDBMetaData *md2= new AliCDBMetaData();
244 md2->SetObjectClassName("AliTRDCalPad");
245 md2->SetResponsible("Raphaelle Bailhache");
246 md2->SetBeamPeriod(1);
247 md2->SetAliRootVersion("01-10-06"); //root version
248 md2->SetComment("The dummy values in this calibration file are for testing only");
249 if ((numbertotalgroup[0] > 0) &&
250 (numberfit[0] >= 0.95*numberEnt[0])) {
251 Store("Calib","LocalGainFactor" ,(TObject *) objgainpad ,md2,0,kTRUE);
253 if ((numbertotalgroup[1] > 0) &&
254 (numberfit[1] >= 0.95*numberEnt[1])) {
255 Store("Calib","LocalVdrift" ,(TObject *) objdriftvelocitypad,md2,0,kTRUE);
256 Store("Calib","LocalT0" ,(TObject *) objtime0pad ,md2,0,kTRUE);
258 if ((numbertotalgroup[2] > 0) &&
259 (numberfit[2] >= 0.95*numberEnt[2])) {
260 Store("Calib","PRFWidth" ,(TObject *) objPRFpad ,md2,0,kTRUE);