updates in the resolution task (clusters 2 tracklets residuals)
[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// //
fdfee371 28// Authors: //
ec55623f 29// R. Bailhache (R.Bailhache@gsi.de) //
cd4fc278 30// W. Monange (w.monange@gsi.de) //
fdfee371 31// F. Kramer (kramer@ikf.uni-frankfurt.de) //
ec55623f 32// //
33////////////////////////////////////////////////////////////////////////////
e5c60cc7 34
e5c60cc7 35#include <TFile.h>
36#include <TProfile2D.h>
e5c60cc7 37#include <TStopwatch.h>
38#include <TObjString.h>
39#include <TString.h>
40#include <TList.h>
41#include <TCollection.h>
fdfee371 42#include <TSAXParser.h>
e5c60cc7 43
44#include "AliCDBMetaData.h"
e5c60cc7 45#include "AliLog.h"
46
c8ab4518 47#include "AliTRDPreprocessor.h"
3a0f6479 48#include "AliTRDSensorArray.h"
67c25e8d 49#include "AliTRDCalibraFit.h"
50#include "AliTRDCalibraMode.h"
3a0f6479 51#include "AliTRDCalibPadStatus.h"
fdfee371 52#include "AliTRDSaxHandler.h"
3a0f6479 53#include "Cal/AliTRDCalDet.h"
5029ad25 54#include "Cal/AliTRDCalPad.h"
3a0f6479 55#include "Cal/AliTRDCalPadStatus.h"
fdfee371 56#include "Cal/AliTRDCalDCS.h"
5029ad25 57#include "Cal/AliTRDCalSingleChamberStatus.h"
58#include "Cal/AliTRDCalROC.h"
59
e5c60cc7 60
e5c60cc7 61ClassImp(AliTRDPreprocessor)
62
63//______________________________________________________________________________________________
ec55623f 64AliTRDPreprocessor::AliTRDPreprocessor(AliShuttleInterface *shuttle)
c8ab4518 65 :AliPreprocessor("TRD", shuttle)
66 ,fVdriftHLT(0)
e5c60cc7 67{
68 //
69 // Constructor
70 //
71
2efb65b5 72 AddRunType("PHYSICS");
73 AddRunType("STANDALONE");
74 AddRunType("PEDESTAL");
75
e5c60cc7 76}
77
78//______________________________________________________________________________________________
79AliTRDPreprocessor::~AliTRDPreprocessor()
80{
81 //
82 // Destructor
83 //
84
85}
86
87//______________________________________________________________________________________________
88void AliTRDPreprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
89{
90 //
91 // Initialization routine for the TRD preprocessor
92 //
93
94 AliPreprocessor::Initialize(run,startTime,endTime);
95
96}
97
98//______________________________________________________________________________________________
a5e1169e 99UInt_t AliTRDPreprocessor::Process(TMap* dcsAliasMap)
e5c60cc7 100{
101 //
a5e1169e 102 // Process DCS and calibration part for HLT
103 //
104
8dd14606 105 TString runType = GetRunType();
106 Log(Form("runtype %s\n",runType.Data()));
65ffd646 107
fdfee371 108 // always process the configuration data
109/* Int_t resultDCSC = */ProcessDCSConfigData(); // for testing!
110 // if there was an error, return with its code
111// if (resultDCSC != 0) return resultDCSC; // for testing!
112
b70c68da 113 if (runType=="PEDESTAL"){
8dd14606 114 if(ExtractPedestals()) return 1;
115 return 0;
116 }
a5e1169e 117
b70c68da 118 if ((runType=="PHYSICS") || (runType=="STANDALONE")){
f5bb5557 119 // HLT if On
120 //TString runPar = GetRunParameter("HLTStatus");
8dd14606 121 //if(runPar=="1") {
f5bb5557 122 if(GetHLTStatus()) {
fdfee371 123 /*if(*/ExtractHLT()/*) return 1*/; // for testing!
f5bb5557 124 }
125 // DAQ if HLT failed
8dd14606 126 if(!fVdriftHLT) {
fdfee371 127 /*if(*/ExtractDriftVelocityDAQ()/*) return 1*/; // for testing!
8dd14606 128 }
65ffd646 129 // DCS
130 if(ProcessDCS(dcsAliasMap)) return 1;
6ace5fe2 131 }
8dd14606 132
133 return 0;
6ace5fe2 134
135}
c8ab4518 136
f5bb5557 137//______________________________________________________________________________
138Bool_t AliTRDPreprocessor::ProcessDCS()
139{
c8ab4518 140 //
141 // Default process DCS method
142 //
f5bb5557 143
144 TString runType = GetRunType();
b70c68da 145 if ((runType == "PHYSICS") || (runType == "STANDALONE")) {
c8ab4518 146 return kTRUE;
147 }
f5bb5557 148 return kFALSE;
149
150}
6ace5fe2 151
6ace5fe2 152//______________________________________________________________________________
c8ab4518 153Bool_t AliTRDPreprocessor::ProcessDCS(TMap *dcsAliasMap)
6ace5fe2 154{
c8ab4518 155 //
156 // Process DCS method
157 //
158
159 Bool_t error = kFALSE;
6ace5fe2 160
a5e1169e 161 AliCDBMetaData metaData;
162 metaData.SetBeamPeriod(0);
163 metaData.SetResponsible("Wilfried Monange/Raphaelle Bailhache");
164 metaData.SetComment("TRD calib test");
c8ab4518 165
166 Log("****** DCS ******\n");
cd4fc278 167
8dd14606 168 TObjArray * list=AliTRDSensorArray::GetList ();
cd4fc278 169
170 if (list == 0x0) {
6ace5fe2 171 Log ("Error during AliTRDSensorArray::GetList");
172 Log ("DCS will not be processing");
8dd14606 173 return kTRUE;
6ace5fe2 174 }
175
176 Int_t nEntries = list->GetEntries ();
177 Log (Form ("%d alias loaded", nEntries));
cd4fc278 178
6ace5fe2 179 Bool_t * results=new Bool_t [nEntries];
180 Int_t * nGraph=new Int_t [nEntries];
cd4fc278 181
6ace5fe2 182 for (Int_t iAlias = 0; iAlias < nEntries; iAlias++) {
cd4fc278 183
6ace5fe2 184 AliTRDSensorArray * oneTRDDCS = (AliTRDSensorArray *)list->At (iAlias);
cd4fc278 185
6ace5fe2 186 oneTRDDCS->SetStartTime (TTimeStamp (fStartTime));
187 oneTRDDCS->SetEndTime (TTimeStamp (fEndTime));
cd4fc278 188
c8ab4518 189 Log(Form("Processing DCS : \"%s\"", oneTRDDCS->GetStoreName ().Data ()));
cd4fc278 190
6ace5fe2 191 TMap * map;
192
193 map=oneTRDDCS->ExtractDCS (dcsAliasMap);
cd4fc278 194
6ace5fe2 195 nGraph [iAlias] = map->GetEntries ();
cd4fc278 196
6ace5fe2 197 if (nGraph [iAlias] == 0) {
198 Log("No TGraph for this dcsDatapointAlias : not stored");
199 results [iAlias] = kFALSE;
2ff01398 200 error = kTRUE;
6ace5fe2 201 continue;
202 }
cd4fc278 203
6ace5fe2 204 oneTRDDCS->SetGraph(map);
205 results[iAlias]=Store("Calib", oneTRDDCS->GetStoreName().Data(), oneTRDDCS, &metaData, 0, kTRUE);
206 delete map;
207
208 //results [iAlias] = StoreReferenceData("Calib", oneTRDDCS->GetStoreName ().Data (), oneTRDDCS, &metaData);
209
6ace5fe2 210 if (!results[iAlias]) {
8dd14606 211 AliError("Problem during StoreRef DCS");
212 error=kTRUE;
6ace5fe2 213 }
214
6ace5fe2 215 //BEGIN TEST (should not be removed ...)
216 /*
217 oneTRDDCS->ClearGraph();
218 oneTRDDCS->ClearFit();
219 oneTRDDCS->SetDiffCut2 (0.1);
220 map=oneTRDDCS->ExtractDCS (dcsAliasMap);
221 oneTRDDCS->SetGraph (map);
222 Store("Calib", ("cut_"+oneTRDDCS->GetStoreName()).Data(), oneTRDDCS, &metaData, 0, kTRUE);
223 delete map;
224
225
226 if(iAlias==1 || iAlias==19) continue;
227
228 oneTRDDCS->ClearGraph();
229 oneTRDDCS->ClearFit();
230 oneTRDDCS->SetDiffCut2(0);
231 map=oneTRDDCS->ExtractDCS(dcsAliasMap);
232 oneTRDDCS->MakeSplineFit(map);
233 Store("Calib", ("fit_"+oneTRDDCS->GetStoreName()).Data() , oneTRDDCS, &metaData, 0, kTRUE);
234 delete map;
235
236
237 oneTRDDCS->ClearGraph();
238 oneTRDDCS->ClearFit();
239 oneTRDDCS->SetDiffCut2 (0.1);
240 map=oneTRDDCS->ExtractDCS (dcsAliasMap);
241 oneTRDDCS->MakeSplineFit(map);
242 Store("Calib", ("cutfit_"+oneTRDDCS->GetStoreName()).Data() , oneTRDDCS, &metaData, 0, kTRUE);
243 delete map;
244 */
245 //END TEST
246
6ace5fe2 247 }
cd4fc278 248
6ace5fe2 249 Log (" Summury of DCS :\n");
250 Log (Form("%30s %10s %10s", "dcsDatapointAlias", "Stored ?", "# graph"));
251 for (Int_t iAlias = 0; iAlias < nEntries; iAlias++) {
252 AliTRDSensorArray * oneTRDDCS = (AliTRDSensorArray *)list->At (iAlias);
253 Log (Form ("%30s %10s %4d",
254 oneTRDDCS->GetStoreName ().Data (),
255 results[iAlias] ? "ok" : "X",
256 nGraph [iAlias]));
257 }
258 Log ("*********** End of DCS **********");
259
260 delete results;
261 delete nGraph;
262
8dd14606 263 return error;
c8ab4518 264
6ace5fe2 265}
266
267//______________________________________________________________________________________________
8dd14606 268Bool_t AliTRDPreprocessor::ExtractPedestals()
6ace5fe2 269{
270 //
271 // Pedestal running on LDCs at the DAQ
272 //
54c85ef7 273
274 //
275 // The reference data are stored in:
276 // PadStatus1 for sm-00-01-02-09-10-11
277 // PadStatus2 for sm-03-04-05-12-13-14
278 // PadStatus3 for sm-06-07-08-15-16-17
279 // PadStatus0 if nothing found..means problems
280 //
5029ad25 281
8dd14606 282 Bool_t error = kFALSE;
6ace5fe2 283
284 // Init a AliTRDCalibPadStatus
285 AliTRDCalibPadStatus calPedSum = AliTRDCalibPadStatus();
286
287 AliCDBMetaData metaData;
288 metaData.SetBeamPeriod(0);
289 metaData.SetResponsible("Raphaelle Bailhache");
290 metaData.SetComment("TRD calib test");
291
292 // Sum the contributions of the LDCs
293 TList * listpad = GetFileSources(kDAQ,"PADSTATUS");
8dd14606 294 if (!listpad) {
295 Log("No list found for the PEDESTRAL Run");
296 return kTRUE;
297 }
298
c8ab4518 299 // loop through all files from LDCs
8dd14606 300 UInt_t index = 0;
301 while (listpad->At(index)!=NULL) {
302 TObjString* fileNameEntry = (TObjString*) listpad->At(index);
303 if (fileNameEntry != NULL)
304 {
6ace5fe2 305 TString fileName = GetFile(kDAQ, "PADSTATUS",
306 fileNameEntry->GetString().Data());
8dd14606 307 if(fileName.Length() ==0){
6ace5fe2 308 Log(Form("Error by retrieving the file %d for the pedestal",(Int_t)index));
8dd14606 309 delete listpad;
310 return kTRUE;
cd4fc278 311 }
8dd14606 312
313 TFile *f = TFile::Open(fileName);
314 AliTRDCalibPadStatus *calPed;
315 f->GetObject("calibpadstatus",calPed);
316
317 if(calPed){
318
54c85ef7 319 Int_t ldc = 0;
289cc637 320
8dd14606 321 // analyse
289cc637 322 //calPed->AnalyseHisto();
323
324 // Add to the calPedSum
325 for (Int_t idet=0; idet<540; idet++) {
326 AliTRDCalROC *rocMean = calPed->GetCalRocMean(idet, kFALSE);
327 if ( rocMean ) {
328 calPedSum.SetCalRocMean(rocMean,idet);
54c85ef7 329 ldc = (Int_t) (idet / 30);
289cc637 330 }
331 AliTRDCalROC *rocRMS = calPed->GetCalRocRMS(idet, kFALSE);
332 if ( rocRMS ) {
333 calPedSum.SetCalRocRMS(rocRMS,idet);
334 }
e4db522f 335 AliTRDCalROC *rocMeand = calPed->GetCalRocMeand(idet, kFALSE);
336 if ( rocMeand ) {
337 calPedSum.SetCalRocMeand(rocMeand,idet);
338 }
339 AliTRDCalROC *rocRMSd = calPed->GetCalRocRMSd(idet, kFALSE);
340 if ( rocRMSd ) {
341 calPedSum.SetCalRocRMSd(rocRMSd,idet);
342 }
289cc637 343 }// det loop
344
54c85ef7 345 if((ldc==0) || (ldc==1) || (ldc==2) || (ldc==9) || (ldc==10) || (ldc==11)) ldc = 1;
346 if((ldc==3) || (ldc==4) || (ldc==5) || (ldc==12) || (ldc==13) || (ldc==14)) ldc = 2;
347 if((ldc==6) || (ldc==7) || (ldc==8) || (ldc==15) || (ldc==16) || (ldc==17)) ldc = 3;
348
8dd14606 349 // store as reference data
350 TString name("PadStatus");
54c85ef7 351 name += ldc;
8dd14606 352 if(!StoreReferenceData("DAQData",(const char *)name,(TObject *) calPed,&metaData)){
353 Log(Form("Error storing AliTRDCalibPadStatus object %d as reference data",(Int_t)index));
354 error = kTRUE;
355 }
289cc637 356
8dd14606 357 } // calPed
358 } // fileNameEntry
359 ++index;
360 }// while (list)
c8ab4518 361
8dd14606 362 Log(Form("%d elements found in the list for the pedestal",(Int_t)index));
363 if(index==0){
6ace5fe2 364 delete listpad;
8dd14606 365 return kTRUE;
6ace5fe2 366 }
c8ab4518 367
8dd14606 368 //
5029ad25 369 // Create pedestal
8dd14606 370 //
c8ab4518 371
8dd14606 372 // Create Pad Status
373 AliTRDCalPadStatus *calPadStatus = calPedSum.CreateCalPadStatus();
5029ad25 374 // Create Noise
375 //Make the AliTRDCalPad
376 AliTRDCalPad *calPad2 = calPedSum.CreateCalPad();
377 //Make the AliTRDCalDet correspondant
378 AliTRDCalDet *calDet = calPedSum.CreateCalDet();
379
380 //
381 // Take the noise and Pad status from the previous OCDB
382 //
383
384 AliTRDCalPad *calPadPrevious=0;
385 AliCDBEntry* entry = GetFromOCDB("Calib", "PadNoise");
386 if (entry) calPadPrevious = (AliTRDCalPad*)entry->GetObject();
387 if ( calPadPrevious==NULL ) {
388 Log("AliTRDPreprocsessor: No previous TRD pad noise entry available.\n");
389 calPadPrevious = new AliTRDCalPad("PadNoise", "PadNoise");
390 }
391
392 AliTRDCalPadStatus *calPadStatusPrevious=0;
393 entry = GetFromOCDB("Calib", "PadStatus");
394 if (entry) calPadStatusPrevious = (AliTRDCalPadStatus*)entry->GetObject();
395 if ( calPadStatusPrevious==NULL ) {
396 Log("AliTRDPreprocsessor: No previous TRD pad status entry available.\n");
397 calPadStatusPrevious = new AliTRDCalPadStatus("padstatus", "padstatus");
398 for (Int_t idet=0; idet<540; ++idet)
399 {
400 AliTRDCalSingleChamberStatus *calROC = calPadStatusPrevious->GetCalROC(idet);
401 for(Int_t k = 0; k < calROC->GetNchannels(); k++){
402 calROC->SetStatus(k,AliTRDCalPadStatus::kMasked);
403 }
404 }
405 }
406
407
408 // Loop over detectors for check
409 for (Int_t det=0; det<AliTRDgeometry::kNdet; ++det) {
410
411 // noise
412 AliTRDCalROC *calROCPreviousNoise = calPadPrevious->GetCalROC(det);
413 AliTRDCalROC *calROCNoise = calPad2->GetCalROC(det);
414
415 // padstatus
416 AliTRDCalSingleChamberStatus *calROCPreviousStatus = calPadStatusPrevious->GetCalROC(det);
417 AliTRDCalSingleChamberStatus *calROCStatus = calPadStatus->GetCalROC(det);
418
419
420 // loop over first half and second half chamber
421 for(Int_t half = 0; half < 2; half++){
422
423 Bool_t data = AreThereDataPedestal(calROCStatus,(Bool_t)half);
37b0cf5e 424 //printf("There are data for the detector %d the half %d: %d\n",det,half,data);
5029ad25 425 if(!data){
426 // look if data in the OCDB
427 Bool_t dataPrevious = AreThereDataPedestal(calROCPreviousStatus,(Bool_t)half);
428 // if no data at all, set to default value
429 if(!dataPrevious){
430 SetDefaultStatus(*calROCStatus,(Bool_t)half);
431 SetDefaultNoise(*calROCNoise,(Bool_t)half);
432 }
433 else{
434 // if data, set to previous value
435 SetStatus(*calROCStatus,calROCPreviousStatus,(Bool_t)half);
436 SetNoise(*calROCNoise,calROCPreviousNoise,(Bool_t)half);
437 }
438 }
439 }
440 }
441
442 //
443 // Store
444 //
445
8dd14606 446 AliCDBMetaData md3;
447 md3.SetObjectClassName("AliTRDCalPadStatus");
448 md3.SetResponsible("Raphaelle Bailhache");
449 md3.SetBeamPeriod(1);
450 md3.SetComment("TRD calib test");
451 if(!Store("Calib","PadStatus" ,(TObject *)calPadStatus, &md3, 0, kTRUE)){
452 Log("Error storing the pedestal");
453 delete listpad;
454 return kTRUE;
a5e1169e 455 }
289cc637 456
289cc637 457 AliCDBMetaData md4;
458 md4.SetObjectClassName("AliTRDCalPad");
459 md4.SetResponsible("Raphaelle Bailhache");
460 md4.SetBeamPeriod(1);
461 md4.SetComment("TRD calib test");
462 if(!Store("Calib","PadNoise" ,(TObject *)calPad2, &md4, 0, kTRUE)){
463 Log("Error storing the pedestal");
464 delete listpad;
465 return kTRUE;
466 }
5029ad25 467
289cc637 468 AliCDBMetaData md5;
469 md5.SetObjectClassName("AliTRDCalDet");
470 md5.SetResponsible("Raphaelle Bailhache");
471 md5.SetBeamPeriod(1);
472 md5.SetComment("TRD calib test");
473 if(!Store("Calib","DetNoise" ,(TObject *)calDet, &md5, 0, kTRUE)){
474 Log("Error storing the pedestal");
475 delete listpad;
476 return kTRUE;
477 }
478
8dd14606 479 delete listpad;
480 return error;
5029ad25 481
482}
483//__________________________________________________________________
484Bool_t AliTRDPreprocessor::AreThereDataPedestal(AliTRDCalSingleChamberStatus *calROCStatus, Bool_t second){
a5e1169e 485
5029ad25 486 //
487 // Data for this half chamber
488 //
489
490 Bool_t data = kFALSE;
491 Int_t nCols = calROCStatus->GetNcols();
492 Int_t nCol0 = 0;
493 Int_t nColE = (Int_t) nCols/2 - 2;
494 if(second) {
495 nCol0 = nColE + 4;
496 nColE = nCols;
497 }
498 for(Int_t col = nCol0; col < nColE; col++){
499 for(Int_t row = 0; row < calROCStatus->GetNrows(); row++){
500 //printf("ismasked %d\n",(Int_t)calROCStatus->IsMasked(col,row));
37b0cf5e 501 if(!calROCStatus->GetStatus(col,row)) {
5029ad25 502 data = kTRUE;
503 continue;
504 }
505 }
506 if(data) continue;
507 }
508
509 return data;
510
511}
512//__________________________________________________________________
513void AliTRDPreprocessor::SetDefaultStatus(AliTRDCalSingleChamberStatus &calROCStatus, Bool_t second){
514
515 //
516 // default status for this half chamber
517 //
518
519 Int_t nCols = calROCStatus.GetNcols();
520 Int_t nCol0 = 0;
521 Int_t nColE = (Int_t) nCols/2;
522 if(second) {
523 nCol0 = nColE;
524 nColE = nCols;
525 }
526 for(Int_t col = nCol0; col < nColE; col++){
527 for(Int_t row = 0; row < calROCStatus.GetNrows(); row++){
528 calROCStatus.SetStatus(col,row,0);
529 }
530 }
531}
532//__________________________________________________________________
533void AliTRDPreprocessor::SetStatus(AliTRDCalSingleChamberStatus &calROCStatus, AliTRDCalSingleChamberStatus *calROCStatusPrevious,Bool_t second){
534
535 //
536 // previous status for this half chamber
537 //
538
539 Int_t nCols = calROCStatus.GetNcols();
540 Int_t nCol0 = 0;
541 Int_t nColE = (Int_t) nCols/2;
542 if(second) {
543 nCol0 = nColE;
544 nColE = nCols;
545 }
546 for(Int_t col = nCol0; col < nColE; col++){
547 for(Int_t row = 0; row < calROCStatus.GetNrows(); row++){
548 calROCStatus.SetStatus(col,row,calROCStatusPrevious->GetStatus(col,row));
549 }
550 }
6ace5fe2 551}
5029ad25 552//__________________________________________________________________
553void AliTRDPreprocessor::SetDefaultNoise(AliTRDCalROC &calROCNoise, Bool_t second){
554
555 //
556 // default noise for this half chamber
557 //
c8ab4518 558
5029ad25 559 Int_t nCols = calROCNoise.GetNcols();
560 Int_t nCol0 = 0;
561 Int_t nColE = (Int_t) nCols/2;
562 if(second) {
563 nCol0 = nColE;
564 nColE = nCols;
565 }
566 for(Int_t col = nCol0; col < nColE; col++){
567 for(Int_t row = 0; row < calROCNoise.GetNrows(); row++){
568 calROCNoise.SetValue(col,row,0.12);
569 }
570 }
571}
572//__________________________________________________________________
573void AliTRDPreprocessor::SetNoise(AliTRDCalROC &calROCNoise, AliTRDCalROC *calROCNoisePrevious, Bool_t second){
574
575 //
576 // previous noise for this half chamber
577 //
578
579 Int_t nCols = calROCNoise.GetNcols();
580 Int_t nCol0 = 0;
581 Int_t nColE = (Int_t) nCols/2;
582 if(second) {
583 nCol0 = nColE;
584 nColE = nCols;
585 }
586 for(Int_t col = nCol0; col < nColE; col++){
587 for(Int_t row = 0; row < calROCNoise.GetNrows(); row++){
588 calROCNoise.SetValue(col,row,calROCNoisePrevious->GetValue(col,row));
589 }
590 }
591}
6ace5fe2 592//______________________________________________________________________________________________
8dd14606 593Bool_t AliTRDPreprocessor::ExtractDriftVelocityDAQ()
6ace5fe2 594{
a5e1169e 595 //
6ace5fe2 596 // Drift velocity DA running on monitoring servers at the DAQ
e5c60cc7 597 //
598
8dd14606 599 Bool_t error = kFALSE;
6ace5fe2 600
601 // Objects for HLT and DAQ zusammen
3a0f6479 602 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
6ace5fe2 603 AliCDBMetaData metaData;
604 metaData.SetBeamPeriod(0);
605 metaData.SetResponsible("Raphaelle Bailhache");
606 metaData.SetComment("TRD calib test");
3a0f6479 607 // Store the infos for the detector
6ace5fe2 608 AliCDBMetaData md1;
609 md1.SetObjectClassName("AliTRDCalDet");
610 md1.SetResponsible("Raphaelle Bailhache");
611 md1.SetBeamPeriod(0);
612 md1.SetComment("TRD calib test");
3a0f6479 613 // Store the infos for the pads
6ace5fe2 614 AliCDBMetaData md2;
615 md2.SetObjectClassName("AliTRDCalPad");
616 md2.SetResponsible("Raphaelle Bailhache");
617 md2.SetBeamPeriod(0);
618 md2.SetComment("TRD calib test");
3a0f6479 619
6ace5fe2 620 // Take the file from the DAQ file exchange server
621 TList *listdaq = GetFileSources(kDAQ,"VDRIFT");
8dd14606 622 if (!listdaq) {
6ace5fe2 623 Log("No list found for vdrift (DAQ)");
8dd14606 624 return kTRUE;
625 }
626
627 if(listdaq->GetSize() !=1){
628 Log(Form("Problem on the size of the list: %d (DAQ)",listdaq->GetSize()));
629 delete listdaq;
630 return kTRUE;
6ace5fe2 631 }
8dd14606 632
633 TObjString* fileNameEntry = (TObjString*) listdaq->At(0);
634 if(fileNameEntry != NULL){
635 TString fileName = GetFile(kDAQ, "VDRIFT",
636 fileNameEntry->GetString().Data());
637 if(fileName.Length() ==0){
638 Log("Error retrieving the file vdrift (DAQ)");
639 delete listdaq;
640 return kTRUE;
641 }
642 TFile *filedaq = TFile::Open(fileName);
643 TProfile2D *histodriftvelocity = (TProfile2D *) filedaq->Get("PH2d");
644 if (histodriftvelocity) {
645
646 // store as reference data
647 if(!StoreReferenceData("DAQData","VdriftT0",(TObject *) histodriftvelocity,&metaData)){
648 Log("Error storing 2D Profile for vdrift from the DAQ");
649 error = kTRUE;
650 }
651
652 // analyse
653
654 Log("Take the PH reference data. Now we will try to fit\n");
655 calibra->SetMinEntries(2000); // If there is less than 2000
656 calibra->AnalysePH(histodriftvelocity);
657
658 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(1))
659 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(1));
660 Int_t nbfit = calibra->GetNumberFit();
661 Int_t nbE = calibra->GetNumberEnt();
662
663 // if enough statistics store the results
664 if ((nbtg > 0) &&
665 (nbfit >= 0.95*nbE)) {
666 // create the cal objects
667 TObjArray object = calibra->GetVectorFit();
668 AliTRDCalDet *objdriftvelocitydet = calibra->CreateDetObjectVdrift(&object,kTRUE);
669 TObject *objdriftvelocitypad = calibra->CreatePadObjectVdrift();
670 object = calibra->GetVectorFit2();
671 AliTRDCalDet *objtime0det = calibra->CreateDetObjectT0(&object,kTRUE);
672 TObject *objtime0pad = calibra->CreatePadObjectT0();
673 calibra->ResetVectorFit();
674 // store
675 if(!Store("Calib","ChamberVdrift" ,(TObject *) objdriftvelocitydet,&md1,0,kTRUE)){
676 Log("Error storing the calibration object for the chamber vdrift (DAQ)");
677 error = kTRUE;
678 }
679 if(!Store("Calib","ChamberT0" ,(TObject *) objtime0det ,&md1,0,kTRUE)){
680 Log("Error storing the calibration object for the chamber t0 (DAQ)");
681 error = kTRUE;
682 }
683 if(!Store("Calib","LocalVdrift" ,(TObject *) objdriftvelocitypad,&md2,0,kTRUE)){
684 Log("Error storing the calibration object for the local drift velocity (DAQ)");
685 error = kTRUE;
686 }
687 if(!Store("Calib","LocalT0" ,(TObject *) objtime0pad ,&md2,0,kTRUE)){
688 Log("Error storing the calibration object for the local time0 (DAQ)");
689 error = kTRUE;
690 }
691 }
692 else{
693 Log("Not enough statistics for the average pulse height (DAQ)");
694 }
695 } // histo here
696 }// if fileNameEntry
697
698 delete listdaq;
699 return error;
700
6ace5fe2 701}
c8ab4518 702
6ace5fe2 703//______________________________________________________________________________________________
8dd14606 704Bool_t AliTRDPreprocessor::ExtractHLT()
6ace5fe2 705{
e5c60cc7 706 //
6ace5fe2 707 // Gain, vdrift and PRF calibration running on HLT
f5bb5557 708 // return kTRUE if NULL pointer to the list
e5c60cc7 709 //
3a0f6479 710
8dd14606 711 Bool_t error = kFALSE;
712
6ace5fe2 713 // Objects for HLT and DAQ zusammen
714 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
715 AliCDBMetaData metaData;
716 metaData.SetBeamPeriod(0);
717 metaData.SetResponsible("Raphaelle Bailhache");
718 metaData.SetComment("TRD calib test");
719 // Store the infos for the detector
720 AliCDBMetaData md1;
721 md1.SetObjectClassName("AliTRDCalDet");
722 md1.SetResponsible("Raphaelle Bailhache");
723 md1.SetBeamPeriod(0);
724 md1.SetComment("TRD calib test");
725 // Store the infos for the pads
726 AliCDBMetaData md2;
727 md2.SetObjectClassName("AliTRDCalPad");
728 md2.SetResponsible("Raphaelle Bailhache");
729 md2.SetBeamPeriod(0);
730 md2.SetComment("TRD calib test");
6ace5fe2 731
732 // Take the file from the HLT file exchange server
733 TList *listhlt = GetFileSources(kHLT,"GAINDRIFTPRF");
8dd14606 734 if (!listhlt) {
6ace5fe2 735 Log("No list found for the HLT");
8dd14606 736 return kTRUE;
737 }
738
739 if(listhlt->GetSize() != 1) {
740 Log(Form("Problem on the size of the list: %d (HLT)",listhlt->GetSize()));
741 delete listhlt;
742 return kTRUE;
6ace5fe2 743 }
3a0f6479 744
8dd14606 745 TObjString* fileNameEntry = (TObjString*) listhlt->At(0);
746 if(fileNameEntry != NULL){
747 TString fileName = GetFile(kHLT, "GAINDRIFTPRF",
748 fileNameEntry->GetString().Data());
749 if(fileName.Length() ==0){
750 Log("Error retrieving the file (HLT)");
751 delete listhlt;
752 return kTRUE;
753 }
754 // Take the file
755 TFile *filehlt = TFile::Open(fileName);
756
8dd14606 757 // gain
758 TH2I *histogain = (TH2I *) filehlt->Get("CH2d");
759 histogain->SetDirectory(0);
760 if (histogain) {
761 // store the reference data
762 if(!StoreReferenceData("HLTData","Gain",(TObject *) histogain,&metaData)){
763 Log("Error storing 2D histos for gain");
764 error = kTRUE;
765 }
766 // analyse
767 Log("Take the CH reference data. Now we will try to fit\n");
768 calibra->SetMinEntries(1000); // If there is less than 1000 entries in the histo: no fit
769 calibra->AnalyseCH(histogain);
770 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(0))
771 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(0));
772 Int_t nbfit = calibra->GetNumberFit();
773 Int_t nbE = calibra->GetNumberEnt();
774 // enough statistics
775 if ((nbtg > 0) &&
776 (nbfit >= 0.95*nbE)) {
777 // create the cal objects
778 TObjArray object = calibra->GetVectorFit();
413153cb 779 AliTRDCalDet *objgaindet = calibra->CreateDetObjectGain(&object);
8dd14606 780 TObject *objgainpad = calibra->CreatePadObjectGain();
781 // store them
782 if(!Store("Calib","ChamberGainFactor",(TObject *) objgaindet ,&md1,0,kTRUE)){
783 Log("Error storing the calibration object for the chamber gain");
784 error = kTRUE;
785 }
786 if(!Store("Calib","LocalGainFactor" ,(TObject *) objgainpad ,&md2,0,kTRUE)){
787 Log("Error storing the calibration object for the local gain factor");
788 error = kTRUE;
789 }
790 }
791 calibra->ResetVectorFit();
792 }// if histogain
793
8dd14606 794 // vdrift
795 fVdriftHLT = kFALSE;
796 TProfile2D *histodriftvelocity = (TProfile2D *) filehlt->Get("PH2d");
797 histodriftvelocity->SetDirectory(0);
798 if (histodriftvelocity) {
799 // store the reference data
800 if(!StoreReferenceData("HLTData","VdriftT0",(TObject *) histodriftvelocity,&metaData)){
801 Log("Error storing 2D Profile for average pulse height (HLT)");
802 error = kTRUE;
803 }
804 // analyse
805 Log("Take the PH reference data. Now we will try to fit\n");
806 calibra->SetMinEntries(1000*20); // If there is less than 20000
807 calibra->AnalysePH(histodriftvelocity);
808 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(1))
809 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(1));
810 Int_t nbfit = calibra->GetNumberFit();
811 Int_t nbE = calibra->GetNumberEnt();
812 // enough statistics
813 if ((nbtg > 0) &&
814 (nbfit >= 0.95*nbE)) {
815 // create the cal objects
816 TObjArray object = calibra->GetVectorFit();
817 AliTRDCalDet *objdriftvelocitydet = calibra->CreateDetObjectVdrift(&object,kTRUE);
818 TObject *objdriftvelocitypad = calibra->CreatePadObjectVdrift();
819 object = calibra->GetVectorFit2();
820 AliTRDCalDet *objtime0det = calibra->CreateDetObjectT0(&object,kTRUE);
821 TObject *objtime0pad = calibra->CreatePadObjectT0();
822 // store them
823 if(!Store("Calib","ChamberVdrift" ,(TObject *) objdriftvelocitydet,&md1,0,kTRUE)){
824 Log("Error storing the calibration object for the chamber vdrift (HLT)");
825 error = kTRUE;
826 }
827 if(!Store("Calib","ChamberT0" ,(TObject *) objtime0det ,&md1,0,kTRUE)){
828 Log("Error storing the calibration object for the chamber t0 (HLT)");
829 error = kTRUE;
830 }
831 if(!Store("Calib","LocalVdrift" ,(TObject *) objdriftvelocitypad,&md2,0,kTRUE)){
832 Log("Error storing the calibration object for the local drift velocity (HLT)");
833 error = kTRUE;
834 }
835 if(!Store("Calib","LocalT0" ,(TObject *) objtime0pad ,&md2,0,kTRUE)){
836 Log("Error storing the calibration object for the local time0 (HLT)");
837 error = kTRUE;
838 }
839 fVdriftHLT = kTRUE;
840 }
841 calibra->ResetVectorFit();
842 }// if TProfile2D
843
8dd14606 844 // prf
845 TProfile2D *histoprf = (TProfile2D *) filehlt->Get("PRF2d");
846 histoprf->SetDirectory(0);
847 if (histoprf) {
848 // store reference data
849 if(!StoreReferenceData("HLTData","PRF",(TObject *) histoprf,&metaData)){
850 Log("Error storing the 2D Profile for Pad Response Function");
851 error = kTRUE;
852 }
853 // analyse
854 Log("Take the PRF reference data. Now we will try to fit\n");
855 calibra->SetMinEntries(600); // If there is less than 20000
856 calibra->AnalysePRFMarianFit(histoprf);
857 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(2))
858 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(2));
859 Int_t nbfit = calibra->GetNumberFit();
860 Int_t nbE = calibra->GetNumberEnt();
861 // enough statistics
862 if ((nbtg > 0) &&
863 (nbfit >= 0.95*nbE)) {
864 // create cal pad objects
865 TObjArray object = calibra->GetVectorFit();
866 TObject *objPRFpad = calibra->CreatePadObjectPRF(&object);
867 // store them
868 if(!Store("Calib","PRFWidth" ,(TObject *) objPRFpad ,&md2,0,kTRUE)){
869 Log("Error storing the calibration object for the Pad Response Function");
870 error = kTRUE;
871 }
872 }
873 calibra->ResetVectorFit();
874 }// if PRF
875 }// if fileNameEntry
876
877 delete listhlt;
878 return error;
879
e5c60cc7 880}
fdfee371 881
882//_____________________________________________________________________________
883UInt_t AliTRDPreprocessor::ProcessDCSConfigData()
884{
885 //
886 // process the configuration of FEE, PTR and GTU
887 // reteive XML file from the DCS FXS
888 // parse it and store TObjArrays in the CDB
889 // return 0 for success, otherwise:
890 // 5: could not get the file from the FXS
891 // 6: ERROR in XML validation: something wrong with the file
892 // 7: ERROR while creating calibration objects in the handler
893 // 8: error while storing data in the CDB
894 // > 100: SaxHandler error code
895 //
896
897 Log("Processing the DCS config summary file.");
898
899 // get the XML file
900 const char * xmlFile = GetFile(kDCS,"CONFIGSUMMARY","");
901 if (xmlFile == NULL) {
902 return 5;
903 Log(Form("File %s not found!",xmlFile));
904 }
905
906 // create parser and parse
907 TSAXParser saxParser;
908 AliTRDSaxHandler saxHandler;
909 saxParser.ConnectToHandler("AliTRDSaxHandler", &saxHandler);
910 saxParser.ParseFile(xmlFile);
911
912 // report errors if present
913 if (saxParser.GetParseCode() == 0) {
914 Log("XML file validation OK");
915 } else {
916 Log(Form("ERROR in XML file validation. Parsecode: %s", saxParser.GetParseCode()));
917 return 6;
918 }
919 if (saxHandler.GetHandlerStatus() != 0) {
920 Log(Form("ERROR while creating calibration objects. Error code: %s", saxHandler.GetHandlerStatus()));
921 return 7;
922 }
923
924 // get the calibration object storing the data from the handler
925 AliTRDCalDCS* fCalDCSObj = saxHandler.GetCalDCSObj();
926
927 // store the DCS calib data in the CDB
928 AliCDBMetaData metaData1;
929 metaData1.SetBeamPeriod(0);
930 metaData1.SetResponsible("Frederick Kramer");
931 metaData1.SetComment("DCS configuration data in one AliTRDCalDCS object.");
932 if (!Store("Calib", "DCSCONFIG", fCalDCSObj, &metaData1, 0, kTRUE)) {
933 Log("problems while storing DCS config data object");
934 return 8;
935 }
936
937 return 0;
938}
939