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