]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/AliTRDPreprocessor.cxx
Add the first version of the TRD preprocessor
[u/mrichter/AliRoot.git] / TRD / AliTRDPreprocessor.cxx
CommitLineData
e5c60cc7 1////////////////////////////////////////////////////////
2//
3// This class is a first implementation for the TRD.
4// It takes data from HLT and computes the parameters
5// and stores both reference data and online calibration parameters in the CDB
6//
7/////////////////////////////////////////////////////////
8
9#include "AliTRDPreprocessor.h"
10
11#include <TTimeStamp.h>
12#include <TFile.h>
13#include <TProfile2D.h>
14#include <TH2I.h>
15#include <TStopwatch.h>
16#include <TObjString.h>
17#include <TString.h>
18#include <TList.h>
19#include <TCollection.h>
20
21#include "AliCDBMetaData.h"
22#include "AliDCSValue.h"
23#include "AliLog.h"
24
25#include "AliTRDCalibra.h"
26#include "Cal/AliTRDCalDet.h"
27
28
29ClassImp(AliTRDPreprocessor)
30
31//______________________________________________________________________________________________
32AliTRDPreprocessor::AliTRDPreprocessor(const Char_t *detector, AliShuttleInterface *shuttle)
33 :AliPreprocessor(detector, shuttle)
34{
35 //
36 // Constructor
37 //
38
39}
40
41//______________________________________________________________________________________________
42AliTRDPreprocessor::~AliTRDPreprocessor()
43{
44 //
45 // Destructor
46 //
47
48}
49
50//______________________________________________________________________________________________
51void AliTRDPreprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
52{
53 //
54 // Initialization routine for the TRD preprocessor
55 //
56
57 AliPreprocessor::Initialize(run,startTime,endTime);
58
59}
60
61//______________________________________________________________________________________________
62UInt_t AliTRDPreprocessor::Process(TMap* /*dcsAliasMap*/)
63{
64 //
65 // Process the calibraion data for the HLT part
66 //
67
68 // How long does it take for the HLT part?
69 TStopwatch timer;
70 timer.Start();
71
72 // Metadata for the reference data
73 AliCDBMetaData metaData;
74 metaData.SetBeamPeriod(1);
75 metaData.SetResponsible("Raphaelle Bailhache");
76 metaData.SetComment("This preprocessor fills reference data.");
77
78
79 // Take the file from the HLT file exchange server
80 TList *filesources = GetFileSources(kHLT,"GAINDRIFTPRF");
81 if (!filesources) {
82 AliError(Form("No sources found for GAINDRIFTPRF for run %d !",fRun));
83 return 0;
84 }
85 if (filesources->GetSize() != 1) {
86 AliError(Form("More than one source found for GAINDRIFTPRF for run %d!",fRun));
87 return 0;
88 }
89
90 // Call a AliTRDCalibra instance for fit
91 AliTRDCalibra *calibra = AliTRDCalibra::Instance();
92
93 // Init some things
94 AliTRDCalDet *objgaindet = 0x0; // Object for det average gain factor
95 AliTRDCalDet *objdriftvelocitydet = 0x0; // Object for det average drift velocity
96 AliTRDCalDet *objtime0det = 0x0; // Object for det average time0
97 TObject *objgainpad = 0x0; // Object for pad (relative to the det) gain factor
98 TObject *objdriftvelocitypad = 0x0; // Object for pad (relative to the det) drift velocity
99 TObject *objtime0pad = 0x0; // Object for pad (relative to the det) time0
100 TObject *objPRFpad = 0x0; // Object for pad prf width
101 TH2I *histogain = 0x0; // Histogram taken from HLT for gain factor
102 TProfile2D *histodriftvelocity = 0x0; // Profile taken from HLT for drift velocity and time0
103 TProfile2D *histoprf = 0x0; // Profile taken from HLT for prf
104
105 Int_t numberfit[3] = { 0, 0, 0 }; // Number of histos fitted for gain, drift velocity and prf
106 Int_t numberEnt[3] = { 0, 0, 0 }; // Number of histos with entries
107 Double_t statisticmean[3] = { 0.0, 0.0, 0.0 }; // Mean values of the number of entries in these histos
108 Int_t numbertotalgroup[3] = { 0, 0, 0 }; // Total number of groups
109
110
111 // Loop over the files taken from the HLT/
112 TIter iter(filesources);
113 TObjString *source;
114 while ((source = dynamic_cast<TObjString *> (iter.Next()))) {
115
116 TString filename = GetFile(kHLT,"GAINDRIFTPRF",source->GetName());
117 if (!filename.Data()) {
118 AliError(Form("Error retrieving file from source %d failed!", source->GetName()));
119 delete filesources;
120 return 0;
121 }
122
123 // Take the histos
124 TFile *file = TFile::Open(filename);
125 histogain = (TH2I *) file->Get("CH2d");
126 histogain->SetDirectory(0);
127 if (!histogain) {
128 AliError("Error retrieving 2D histos for gain failed!");
129 }
130 histodriftvelocity = (TProfile2D *) file->Get("PH2d");
131 histodriftvelocity->SetDirectory(0);
132 if (!histodriftvelocity) {
133 AliError("Error retrieving 2D Profile for average pulse height failed!");
134 }
135 histoprf = (TProfile2D *) file->Get("PRF2d");
136 histoprf->SetDirectory(0);
137 if (!histoprf) {
138 AliError("Error retrieving 2D Profile for Pad Response Function failed!");
139 }
140 file->Close();
141
142 // Set the mode of calibration from the TObject, store the reference data and try to fit them
143 if (histogain) {
144 calibra->SetModeCalibrationFromTObject((TObject *) histogain,0);
145 Store("Data","Gain",(TObject *) histogain,&metaData,0,0);
146 AliInfo("Take the CH reference data. Now we will try to fit\n");
147 calibra->SetMinEntries(100); // If there is less than 100 entries in the histo: no fit
148 calibra->FitCHOnline(histogain);
149 numbertotalgroup[0] = 6*4*18*((Int_t) calibra->GetDetChamb0(0))
150 + 6* 18*((Int_t) calibra->GetDetChamb2(0));
151 numberfit[0] = calibra->GetNumberFit();
152 statisticmean[0] = calibra->GetStatisticMean();
153 numberEnt[0] = calibra->GetNumberEnt();
154 objgaindet = calibra->CreateDetObjectTree(calibra->GetGain(),0);
155 objgainpad = calibra->CreatePadObjectTree(calibra->GetGain(),0,objgaindet);
156 }
157
158 if (histodriftvelocity) {
159 calibra->SetModeCalibrationFromTObject((TObject *) histodriftvelocity,1);
160 Store("Data","VdriftT0",(TObject *) histodriftvelocity,&metaData,0,0);
161 AliInfo("Take the PH reference data. Now we will try to fit\n");
162 calibra->SetMinEntries(100*20); // If there is less than 2000
163 calibra->FitPHOnline(histodriftvelocity);
164 numbertotalgroup[1] = 6*4*18*((Int_t) calibra->GetDetChamb0(1))
165 + 6* 18*((Int_t) calibra->GetDetChamb2(1));
166 numberfit[1] = calibra->GetNumberFit();
167 statisticmean[1] = calibra->GetStatisticMean();
168 numberEnt[1] = calibra->GetNumberEnt();
169 objdriftvelocitydet = calibra->CreateDetObjectTree(calibra->GetVdrift(),1);
170 objdriftvelocitypad = calibra->CreatePadObjectTree(calibra->GetVdrift(),1,objdriftvelocitydet);
171 objtime0det = calibra->CreateDetObjectTree(calibra->GetT0(),3);
172 objtime0pad = calibra->CreatePadObjectTree(calibra->GetT0(),3,objtime0det);
173 }
174
175 if (histoprf) {
176 calibra->SetModeCalibrationFromTObject((TObject *) histoprf,2);
177 Store("Data","PRF",(TObject *) histoprf,&metaData,0,0);
178 AliInfo("Take the PRF reference data. Now we will try to fit\n");
179 calibra->SetMinEntries(100*20); // If there is less than 2000
180 calibra->SetRangeFitPRF(0.5);
181 calibra->FitPRFOnline(histoprf);
182 numbertotalgroup[2] = 6*4*18*((Int_t) calibra->GetDetChamb0(2))
183 + 6* 18*((Int_t) calibra->GetDetChamb2(2));
184 numberfit[2] = calibra->GetNumberFit();
185 statisticmean[2] = calibra->GetStatisticMean();
186 numberEnt[2] = calibra->GetNumberEnt();
187 objPRFpad = calibra->CreatePadObjectTree(calibra->GetPRF());
188 }
189
190 }
191
192 // Bilan of the fit statistic
193 AliInfo(Form("The mean number of entries required for a fit is: %d"
194 ,(Int_t) calibra->GetMinEntries()));
195 AliInfo(Form("FOR THE CH: There is a mean statistic of: %f, with %d fits for %d groups and %d histos with entries"
196 ,statisticmean[0],numberfit[0],numbertotalgroup[0],numberEnt[0]));
197 AliInfo(Form("FOR THE PH: There is a mean statistic of: %f, with %d fits for %d groups and %d histos with entries"
198 ,statisticmean[1],numberfit[1],numbertotalgroup[1],numberEnt[1]));
199 AliInfo(Form("FOR THE PRF: There is a mean statistic of: %f, with %d fits for %d groups and %d histos with entries"
200 ,statisticmean[2],numberfit[2],numbertotalgroup[2],numberEnt[2]));
201
202
203 //
204 // Store the coefficients in the grid OCDB if enough statistics
205 //
206
207 // Store the infos for the detector
208 AliCDBMetaData *md1= new AliCDBMetaData();
209 md1->SetObjectClassName("AliTRDCalDet");
210 md1->SetResponsible("Raphaelle Bailhache");
211 md1->SetBeamPeriod(1);
212 md1->SetAliRootVersion("01-10-06"); // root version
213 md1->SetComment("The dummy values in this calibration file are for testing only");
214 if ((numbertotalgroup[0] > 0) &&
215 (numberfit[0] >= 0.95*numberEnt[0])) {
216 Store("Calib","ChamberGainFactor",(TObject *) objgaindet ,md1,0,kTRUE);
217 }
218 if ((numbertotalgroup[1] > 0) &&
219 (numberfit[1] >= 0.95*numberEnt[1])) {
220 Store("Calib","ChamberVdrift" ,(TObject *) objdriftvelocitydet,md1,0,kTRUE);
221 Store("Calib","ChamberT0" ,(TObject *) objtime0det ,md1,0,kTRUE);
222 }
223
224 // Store the infos for the pads
225 AliCDBMetaData *md2= new AliCDBMetaData();
226 md2->SetObjectClassName("AliTRDCalPad");
227 md2->SetResponsible("Raphaelle Bailhache");
228 md2->SetBeamPeriod(1);
229 md2->SetAliRootVersion("01-10-06"); //root version
230 md2->SetComment("The dummy values in this calibration file are for testing only");
231 if ((numbertotalgroup[0] > 0) &&
232 (numberfit[0] >= 0.95*numberEnt[0])) {
233 Store("Calib","LocalGainFactor" ,(TObject *) objgainpad ,md2,0,kTRUE);
234 }
235 if ((numbertotalgroup[1] > 0) &&
236 (numberfit[1] >= 0.95*numberEnt[1])) {
237 Store("Calib","LocalVdrift" ,(TObject *) objdriftvelocitypad,md2,0,kTRUE);
238 Store("Calib","LocalT0" ,(TObject *) objtime0pad ,md2,0,kTRUE);
239 }
240 if ((numbertotalgroup[2] > 0) &&
241 (numberfit[2] >= 0.95*numberEnt[2])) {
242 Store("Calib","PRFWidth" ,(TObject *) objPRFpad ,md2,0,kTRUE);
243 }
244
245 // End
246 delete filesources;
247 timer.Stop();
248 timer.Print();
249 return 1;
250
251}