]>
Commit | Line | Data |
---|---|---|
ec55623f | 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 | //////////////////////////////////////////////////////////////////////////// | |
19 | // // | |
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 // | |
a5e1169e | 24 | // It alsotakes DCS data, does spline fits // |
25 | // and stores both reference data and spline fits results // | |
26 | // in the CDB // | |
ec55623f | 27 | // // |
28 | // Author: // | |
29 | // R. Bailhache (R.Bailhache@gsi.de) // | |
a5e1169e | 30 | // W. Monange (wilfried.monange@free.fr) // |
ec55623f | 31 | // // |
32 | //////////////////////////////////////////////////////////////////////////// | |
e5c60cc7 | 33 | |
34 | #include "AliTRDPreprocessor.h" | |
35 | ||
36 | #include <TTimeStamp.h> | |
37 | #include <TFile.h> | |
38 | #include <TProfile2D.h> | |
39 | #include <TH2I.h> | |
40 | #include <TStopwatch.h> | |
41 | #include <TObjString.h> | |
42 | #include <TString.h> | |
43 | #include <TList.h> | |
44 | #include <TCollection.h> | |
45 | ||
46 | #include "AliCDBMetaData.h" | |
47 | #include "AliDCSValue.h" | |
48 | #include "AliLog.h" | |
49 | ||
67c25e8d | 50 | #include "AliTRDCalibraFit.h" |
51 | #include "AliTRDCalibraMode.h" | |
a5e1169e | 52 | #include "AliTRDDataDCS.h" |
e5c60cc7 | 53 | #include "Cal/AliTRDCalDet.h" |
54 | ||
e5c60cc7 | 55 | ClassImp(AliTRDPreprocessor) |
56 | ||
57 | //______________________________________________________________________________________________ | |
ec55623f | 58 | AliTRDPreprocessor::AliTRDPreprocessor(AliShuttleInterface *shuttle) |
59 | :AliPreprocessor("TRD", shuttle) | |
e5c60cc7 | 60 | { |
61 | // | |
62 | // Constructor | |
63 | // | |
64 | ||
65 | } | |
66 | ||
67 | //______________________________________________________________________________________________ | |
68 | AliTRDPreprocessor::~AliTRDPreprocessor() | |
69 | { | |
70 | // | |
71 | // Destructor | |
72 | // | |
73 | ||
74 | } | |
75 | ||
76 | //______________________________________________________________________________________________ | |
77 | void AliTRDPreprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime) | |
78 | { | |
79 | // | |
80 | // Initialization routine for the TRD preprocessor | |
81 | // | |
82 | ||
83 | AliPreprocessor::Initialize(run,startTime,endTime); | |
84 | ||
85 | } | |
86 | ||
87 | //______________________________________________________________________________________________ | |
a5e1169e | 88 | UInt_t AliTRDPreprocessor::Process(TMap* dcsAliasMap) |
e5c60cc7 | 89 | { |
a5e1169e | 90 | // |
91 | // Process DCS and calibration part for HLT | |
92 | // | |
93 | ||
94 | UInt_t result = 0; | |
95 | ||
96 | // | |
97 | // DCS | |
98 | // | |
99 | AliTRDDataDCS dataRef; | |
100 | ||
101 | AliCDBMetaData metaData; | |
102 | metaData.SetBeamPeriod(0); | |
103 | metaData.SetResponsible("Wilfried Monange/Raphaelle Bailhache"); | |
104 | metaData.SetComment("TRD calib test"); | |
105 | ||
106 | if (dataRef.ExtractDCS (dcsAliasMap)) { | |
107 | ||
108 | if (!StoreReferenceData("Calib", "DataRef", &dataRef, &metaData)) { | |
109 | AliError("Problem during StoreRef DCS"); | |
110 | result |= EStoreRefDCS; | |
111 | } | |
112 | ||
113 | if (dataRef.PerformFit()) { | |
114 | if(!Store("Calib", "Data", &dataRef, &metaData, 0, 0)) { | |
115 | AliError("Problem during Store DCS"); | |
116 | result |=EStoreDCS; | |
117 | } | |
118 | }else { | |
119 | AliError("Problem during PerformFit DCS"); | |
120 | result |= EFitDCS; | |
121 | } | |
122 | ||
123 | dataRef.ClearFits(); | |
124 | ||
125 | }else { | |
126 | AliError ("Problem during ExtractDCS"); | |
127 | result |= EExtractDCS; | |
128 | } | |
129 | ||
130 | dataRef.ClearGraphs(); | |
131 | ||
e5c60cc7 | 132 | // |
d37121c0 | 133 | // Process the calibration data for the HLT part |
e5c60cc7 | 134 | // |
135 | ||
136 | // How long does it take for the HLT part? | |
137 | TStopwatch timer; | |
138 | timer.Start(); | |
139 | ||
8dfa5624 | 140 | //Run type |
141 | TString runType = GetRunType(); | |
142 | Log(Form("Run type for run %d: %s", fRun, runType.Data())); | |
143 | if (strcmp(runType, "PHYSICS") != 0){ | |
144 | Log("Nothing to do!"); | |
145 | return 0; | |
146 | } | |
147 | ||
148 | ||
149 | // note that the parameters are returned as character strings! | |
150 | const char* nEvents = GetRunParameter("totalEvents"); | |
151 | if (nEvents) { | |
152 | Log(Form("Number of events for run %d: %s",fRun, nEvents)); | |
153 | } else { | |
154 | Log(Form("Number of events not put in logbook!")); | |
155 | } | |
156 | ||
e5c60cc7 | 157 | // Take the file from the HLT file exchange server |
158 | TList *filesources = GetFileSources(kHLT,"GAINDRIFTPRF"); | |
159 | if (!filesources) { | |
8dfa5624 | 160 | Log(Form("No sources found for GAINDRIFTPRF for run %d !",fRun)); |
161 | return 1; | |
e5c60cc7 | 162 | } |
163 | if (filesources->GetSize() != 1) { | |
8dfa5624 | 164 | Log(Form("More than one source found for GAINDRIFTPRF for run %d!",fRun)); |
165 | filesources->Print(); | |
166 | delete filesources; | |
167 | return 1; | |
e5c60cc7 | 168 | } |
169 | ||
170 | // Call a AliTRDCalibra instance for fit | |
67c25e8d | 171 | AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance(); |
172 | ||
173 | //Choose the fit methods | |
174 | calibra->SetFitChargeNDB(4); //for the relative gain | |
175 | calibra->SetFitMeanWOn(); //weighted mean | |
176 | calibra->SetFitPHNDB(3); //for the average pulse height | |
177 | calibra->SetFitLagrPolOn(); //LagrPol | |
178 | calibra->SetFitPRFNDB(0); //for the PRF | |
179 | calibra->SetFitPRFOn(); //gaussian fit | |
180 | ||
181 | //Debug mode | |
182 | //calibra->SetDebug(1); //Debug | |
e5c60cc7 | 183 | |
184 | // Init some things | |
185 | AliTRDCalDet *objgaindet = 0x0; // Object for det average gain factor | |
186 | AliTRDCalDet *objdriftvelocitydet = 0x0; // Object for det average drift velocity | |
187 | AliTRDCalDet *objtime0det = 0x0; // Object for det average time0 | |
188 | TObject *objgainpad = 0x0; // Object for pad (relative to the det) gain factor | |
189 | TObject *objdriftvelocitypad = 0x0; // Object for pad (relative to the det) drift velocity | |
190 | TObject *objtime0pad = 0x0; // Object for pad (relative to the det) time0 | |
191 | TObject *objPRFpad = 0x0; // Object for pad prf width | |
192 | TH2I *histogain = 0x0; // Histogram taken from HLT for gain factor | |
193 | TProfile2D *histodriftvelocity = 0x0; // Profile taken from HLT for drift velocity and time0 | |
194 | TProfile2D *histoprf = 0x0; // Profile taken from HLT for prf | |
195 | ||
196 | Int_t numberfit[3] = { 0, 0, 0 }; // Number of histos fitted for gain, drift velocity and prf | |
197 | Int_t numberEnt[3] = { 0, 0, 0 }; // Number of histos with entries | |
198 | Double_t statisticmean[3] = { 0.0, 0.0, 0.0 }; // Mean values of the number of entries in these histos | |
199 | Int_t numbertotalgroup[3] = { 0, 0, 0 }; // Total number of groups | |
200 | ||
d37121c0 | 201 | // Loop over the files taken from the HLT |
e5c60cc7 | 202 | TIter iter(filesources); |
203 | TObjString *source; | |
204 | while ((source = dynamic_cast<TObjString *> (iter.Next()))) { | |
205 | ||
206 | TString filename = GetFile(kHLT,"GAINDRIFTPRF",source->GetName()); | |
9f4780aa | 207 | if (filename.Length() == 0) { |
8dfa5624 | 208 | Log(Form("Error retrieving file from source %d failed!", source->GetName())); |
e5c60cc7 | 209 | delete filesources; |
8dfa5624 | 210 | return 2; |
e5c60cc7 | 211 | } |
212 | ||
213 | // Take the histos | |
214 | TFile *file = TFile::Open(filename); | |
215 | histogain = (TH2I *) file->Get("CH2d"); | |
216 | histogain->SetDirectory(0); | |
217 | if (!histogain) { | |
8dfa5624 | 218 | Log("Error retrieving 2D histos for gain failed!"); |
219 | delete filesources; | |
220 | return 2; | |
e5c60cc7 | 221 | } |
222 | histodriftvelocity = (TProfile2D *) file->Get("PH2d"); | |
223 | histodriftvelocity->SetDirectory(0); | |
224 | if (!histodriftvelocity) { | |
8dfa5624 | 225 | Log("Error retrieving 2D Profile for average pulse height failed!"); |
226 | delete filesources; | |
227 | return 2; | |
e5c60cc7 | 228 | } |
229 | histoprf = (TProfile2D *) file->Get("PRF2d"); | |
230 | histoprf->SetDirectory(0); | |
231 | if (!histoprf) { | |
8dfa5624 | 232 | Log("Error retrieving 2D Profile for Pad Response Function failed!"); |
233 | delete filesources; | |
234 | return 2; | |
e5c60cc7 | 235 | } |
236 | file->Close(); | |
237 | ||
238 | // Set the mode of calibration from the TObject, store the reference data and try to fit them | |
239 | if (histogain) { | |
240 | calibra->SetModeCalibrationFromTObject((TObject *) histogain,0); | |
8dfa5624 | 241 | if(!StoreReferenceData("HLTData","Gain",(TObject *) histogain,&metaData)){ |
242 | Log("Error storing 2D histos for gain as reference data"); | |
243 | delete filesources; | |
244 | return 3; | |
245 | } | |
246 | Log("Take the CH reference data. Now we will try to fit\n"); | |
e5c60cc7 | 247 | calibra->SetMinEntries(100); // If there is less than 100 entries in the histo: no fit |
248 | calibra->FitCHOnline(histogain); | |
67c25e8d | 249 | numbertotalgroup[0] = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(0)) |
250 | + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(0)); | |
e5c60cc7 | 251 | numberfit[0] = calibra->GetNumberFit(); |
252 | statisticmean[0] = calibra->GetStatisticMean(); | |
253 | numberEnt[0] = calibra->GetNumberEnt(); | |
254 | objgaindet = calibra->CreateDetObjectTree(calibra->GetGain(),0); | |
255 | objgainpad = calibra->CreatePadObjectTree(calibra->GetGain(),0,objgaindet); | |
256 | } | |
257 | ||
258 | if (histodriftvelocity) { | |
259 | calibra->SetModeCalibrationFromTObject((TObject *) histodriftvelocity,1); | |
8dfa5624 | 260 | if(!StoreReferenceData("HLTData","VdriftT0",(TObject *) histodriftvelocity,&metaData)){ |
261 | Log("Error storing 2D Profile for average pulse height as reference data"); | |
262 | delete filesources; | |
263 | return 3; | |
264 | } | |
265 | Log("Take the PH reference data. Now we will try to fit\n"); | |
e5c60cc7 | 266 | calibra->SetMinEntries(100*20); // If there is less than 2000 |
267 | calibra->FitPHOnline(histodriftvelocity); | |
67c25e8d | 268 | numbertotalgroup[1] = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(1)) |
269 | + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(1)); | |
e5c60cc7 | 270 | numberfit[1] = calibra->GetNumberFit(); |
271 | statisticmean[1] = calibra->GetStatisticMean(); | |
272 | numberEnt[1] = calibra->GetNumberEnt(); | |
273 | objdriftvelocitydet = calibra->CreateDetObjectTree(calibra->GetVdrift(),1); | |
274 | objdriftvelocitypad = calibra->CreatePadObjectTree(calibra->GetVdrift(),1,objdriftvelocitydet); | |
275 | objtime0det = calibra->CreateDetObjectTree(calibra->GetT0(),3); | |
276 | objtime0pad = calibra->CreatePadObjectTree(calibra->GetT0(),3,objtime0det); | |
277 | } | |
278 | ||
279 | if (histoprf) { | |
280 | calibra->SetModeCalibrationFromTObject((TObject *) histoprf,2); | |
8dfa5624 | 281 | if(!StoreReferenceData("HLTData","PRF",(TObject *) histoprf,&metaData)){ |
282 | Log("Error storing the 2D Profile for Pad Response Function as reference data"); | |
283 | delete filesources; | |
284 | return 3; | |
285 | } | |
286 | Log("Take the PRF reference data. Now we will try to fit\n"); | |
e5c60cc7 | 287 | calibra->SetMinEntries(100*20); // If there is less than 2000 |
288 | calibra->SetRangeFitPRF(0.5); | |
289 | calibra->FitPRFOnline(histoprf); | |
67c25e8d | 290 | numbertotalgroup[2] = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(2)) |
291 | + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(2)); | |
e5c60cc7 | 292 | numberfit[2] = calibra->GetNumberFit(); |
293 | statisticmean[2] = calibra->GetStatisticMean(); | |
294 | numberEnt[2] = calibra->GetNumberEnt(); | |
295 | objPRFpad = calibra->CreatePadObjectTree(calibra->GetPRF()); | |
296 | } | |
297 | ||
298 | } | |
299 | ||
300 | // Bilan of the fit statistic | |
8dfa5624 | 301 | Log(Form("The mean number of entries required for a fit is: %d" |
e5c60cc7 | 302 | ,(Int_t) calibra->GetMinEntries())); |
8dfa5624 | 303 | Log(Form("FOR THE CH: There is a mean statistic of: %f, with %d fits for %d groups and %d histos with entries" |
e5c60cc7 | 304 | ,statisticmean[0],numberfit[0],numbertotalgroup[0],numberEnt[0])); |
8dfa5624 | 305 | Log(Form("FOR THE PH: There is a mean statistic of: %f, with %d fits for %d groups and %d histos with entries" |
e5c60cc7 | 306 | ,statisticmean[1],numberfit[1],numbertotalgroup[1],numberEnt[1])); |
8dfa5624 | 307 | Log(Form("FOR THE PRF: There is a mean statistic of: %f, with %d fits for %d groups and %d histos with entries" |
e5c60cc7 | 308 | ,statisticmean[2],numberfit[2],numbertotalgroup[2],numberEnt[2])); |
309 | ||
67c25e8d | 310 | |
e5c60cc7 | 311 | // |
312 | // Store the coefficients in the grid OCDB if enough statistics | |
313 | // | |
314 | ||
315 | // Store the infos for the detector | |
316 | AliCDBMetaData *md1= new AliCDBMetaData(); | |
317 | md1->SetObjectClassName("AliTRDCalDet"); | |
318 | md1->SetResponsible("Raphaelle Bailhache"); | |
319 | md1->SetBeamPeriod(1); | |
320 | md1->SetAliRootVersion("01-10-06"); // root version | |
321 | md1->SetComment("The dummy values in this calibration file are for testing only"); | |
8dfa5624 | 322 | // Gain |
e5c60cc7 | 323 | if ((numbertotalgroup[0] > 0) && |
324 | (numberfit[0] >= 0.95*numberEnt[0])) { | |
8dfa5624 | 325 | if(!Store("Calib","ChamberGainFactor",(TObject *) objgaindet ,md1,0,kTRUE)){ |
326 | Log("Error storing the calibration object for the chamber gain"); | |
327 | delete filesources; | |
328 | return 4; | |
329 | } | |
330 | } | |
331 | else{ | |
332 | Log("Not enough statistics for the gain"); | |
e5c60cc7 | 333 | } |
8dfa5624 | 334 | // Vdrift and time0 |
e5c60cc7 | 335 | if ((numbertotalgroup[1] > 0) && |
336 | (numberfit[1] >= 0.95*numberEnt[1])) { | |
8dfa5624 | 337 | if(!Store("Calib","ChamberVdrift" ,(TObject *) objdriftvelocitydet,md1,0,kTRUE)){ |
338 | Log("Error storing the calibration object for the chamber vdrift"); | |
339 | delete filesources; | |
340 | return 4; | |
341 | } | |
342 | if(!Store("Calib","ChamberT0" ,(TObject *) objtime0det ,md1,0,kTRUE)){ | |
343 | Log("Error storing the calibration object for the chamber t0"); | |
344 | delete filesources; | |
345 | return 4; | |
346 | } | |
347 | } | |
348 | else{ | |
349 | Log("Not enough statistics for the average pulse height"); | |
e5c60cc7 | 350 | } |
351 | ||
352 | // Store the infos for the pads | |
353 | AliCDBMetaData *md2= new AliCDBMetaData(); | |
354 | md2->SetObjectClassName("AliTRDCalPad"); | |
355 | md2->SetResponsible("Raphaelle Bailhache"); | |
356 | md2->SetBeamPeriod(1); | |
357 | md2->SetAliRootVersion("01-10-06"); //root version | |
358 | md2->SetComment("The dummy values in this calibration file are for testing only"); | |
8dfa5624 | 359 | // Gain |
e5c60cc7 | 360 | if ((numbertotalgroup[0] > 0) && |
361 | (numberfit[0] >= 0.95*numberEnt[0])) { | |
8dfa5624 | 362 | if(!Store("Calib","LocalGainFactor" ,(TObject *) objgainpad ,md2,0,kTRUE)){ |
363 | Log("Error storing the calibration object for the local gain factor"); | |
364 | delete filesources; | |
365 | return 4; | |
366 | } | |
e5c60cc7 | 367 | } |
8dfa5624 | 368 | // Vdrift and time0 |
e5c60cc7 | 369 | if ((numbertotalgroup[1] > 0) && |
370 | (numberfit[1] >= 0.95*numberEnt[1])) { | |
8dfa5624 | 371 | if(!Store("Calib","LocalVdrift" ,(TObject *) objdriftvelocitypad,md2,0,kTRUE)){ |
372 | Log("Error storing the calibration object for the local drift velocity"); | |
373 | delete filesources; | |
374 | return 4; | |
375 | } | |
376 | if(!Store("Calib","LocalT0" ,(TObject *) objtime0pad ,md2,0,kTRUE)){ | |
377 | Log("Error storing the calibration object for the local time0"); | |
378 | delete filesources; | |
379 | return 4; | |
380 | } | |
e5c60cc7 | 381 | } |
8dfa5624 | 382 | // Pad Response Width |
e5c60cc7 | 383 | if ((numbertotalgroup[2] > 0) && |
384 | (numberfit[2] >= 0.95*numberEnt[2])) { | |
8dfa5624 | 385 | if(!Store("Calib","PRFWidth" ,(TObject *) objPRFpad ,md2,0,kTRUE)){ |
386 | Log("Error storing the calibration object for the Pad Response Function"); | |
387 | delete filesources; | |
388 | return 4; | |
389 | } | |
390 | } | |
391 | else{ | |
392 | Log("Not enough statistics for the Pad Response Function"); | |
e5c60cc7 | 393 | } |
394 | ||
395 | // End | |
396 | delete filesources; | |
397 | timer.Stop(); | |
398 | timer.Print(); | |
8dfa5624 | 399 | return 0; |
e5c60cc7 | 400 | |
401 | } |