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 //
24 // It alsotakes DCS data, does spline fits //
25 // and stores both reference data and spline fits results //
29 // R. Bailhache (R.Bailhache@gsi.de) //
30 // W. Monange (w.monange@gsi.de) //
32 ////////////////////////////////////////////////////////////////////////////
35 #include <TProfile2D.h>
36 #include <TStopwatch.h>
37 #include <TObjString.h>
40 #include <TCollection.h>
42 #include "AliCDBMetaData.h"
45 #include "AliTRDPreprocessor.h"
46 #include "AliTRDSensorArray.h"
47 #include "AliTRDCalibraFit.h"
48 #include "AliTRDCalibraMode.h"
49 #include "AliTRDCalibPadStatus.h"
50 #include "Cal/AliTRDCalDet.h"
51 #include "Cal/AliTRDCalPadStatus.h"
53 ClassImp(AliTRDPreprocessor)
55 //______________________________________________________________________________________________
56 AliTRDPreprocessor::AliTRDPreprocessor(AliShuttleInterface *shuttle)
57 :AliPreprocessor("TRD", shuttle)
64 AddRunType("PHYSICS");
65 AddRunType("STANDALONE");
66 AddRunType("PEDESTAL");
70 //______________________________________________________________________________________________
71 AliTRDPreprocessor::~AliTRDPreprocessor()
79 //______________________________________________________________________________________________
80 void AliTRDPreprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
83 // Initialization routine for the TRD preprocessor
86 AliPreprocessor::Initialize(run,startTime,endTime);
90 //______________________________________________________________________________________________
91 UInt_t AliTRDPreprocessor::Process(TMap* dcsAliasMap)
94 // Process DCS and calibration part for HLT
97 TString runType = GetRunType();
98 Log(Form("runtype %s\n",runType.Data()));
100 if (runType=="PEDESTAL"){
101 if(ExtractPedestals()) return 1;
105 if ((runType=="PHYSICS") || (runType=="STANDALONE")){
107 if(ProcessDCS(dcsAliasMap)) return 1;
109 //TString runPar = GetRunParameter("HLTStatus");
112 if(ExtractHLT()) return 1;
116 if(ExtractDriftVelocityDAQ()) return 1;
124 //______________________________________________________________________________
125 Bool_t AliTRDPreprocessor::ProcessDCS()
128 // Default process DCS method
131 TString runType = GetRunType();
132 if ((runType == "PHYSICS") || (runType == "STANDALONE")) {
139 //______________________________________________________________________________
140 Bool_t AliTRDPreprocessor::ProcessDCS(TMap *dcsAliasMap)
143 // Process DCS method
146 Bool_t error = kFALSE;
148 AliCDBMetaData metaData;
149 metaData.SetBeamPeriod(0);
150 metaData.SetResponsible("Wilfried Monange/Raphaelle Bailhache");
151 metaData.SetComment("TRD calib test");
153 Log("****** DCS ******\n");
155 TObjArray * list=AliTRDSensorArray::GetList ();
158 Log ("Error during AliTRDSensorArray::GetList");
159 Log ("DCS will not be processing");
163 Int_t nEntries = list->GetEntries ();
164 Log (Form ("%d alias loaded", nEntries));
166 Bool_t * results=new Bool_t [nEntries];
167 Int_t * nGraph=new Int_t [nEntries];
169 for (Int_t iAlias = 0; iAlias < nEntries; iAlias++) {
171 AliTRDSensorArray * oneTRDDCS = (AliTRDSensorArray *)list->At (iAlias);
173 oneTRDDCS->SetStartTime (TTimeStamp (fStartTime));
174 oneTRDDCS->SetEndTime (TTimeStamp (fEndTime));
176 Log(Form("Processing DCS : \"%s\"", oneTRDDCS->GetStoreName ().Data ()));
180 map=oneTRDDCS->ExtractDCS (dcsAliasMap);
182 nGraph [iAlias] = map->GetEntries ();
184 if (nGraph [iAlias] == 0) {
185 Log("No TGraph for this dcsDatapointAlias : not stored");
186 results [iAlias] = kFALSE;
191 oneTRDDCS->SetGraph(map);
192 results[iAlias]=Store("Calib", oneTRDDCS->GetStoreName().Data(), oneTRDDCS, &metaData, 0, kTRUE);
195 //results [iAlias] = StoreReferenceData("Calib", oneTRDDCS->GetStoreName ().Data (), oneTRDDCS, &metaData);
197 if (!results[iAlias]) {
198 AliError("Problem during StoreRef DCS");
202 //BEGIN TEST (should not be removed ...)
204 oneTRDDCS->ClearGraph();
205 oneTRDDCS->ClearFit();
206 oneTRDDCS->SetDiffCut2 (0.1);
207 map=oneTRDDCS->ExtractDCS (dcsAliasMap);
208 oneTRDDCS->SetGraph (map);
209 Store("Calib", ("cut_"+oneTRDDCS->GetStoreName()).Data(), oneTRDDCS, &metaData, 0, kTRUE);
213 if(iAlias==1 || iAlias==19) continue;
215 oneTRDDCS->ClearGraph();
216 oneTRDDCS->ClearFit();
217 oneTRDDCS->SetDiffCut2(0);
218 map=oneTRDDCS->ExtractDCS(dcsAliasMap);
219 oneTRDDCS->MakeSplineFit(map);
220 Store("Calib", ("fit_"+oneTRDDCS->GetStoreName()).Data() , oneTRDDCS, &metaData, 0, kTRUE);
224 oneTRDDCS->ClearGraph();
225 oneTRDDCS->ClearFit();
226 oneTRDDCS->SetDiffCut2 (0.1);
227 map=oneTRDDCS->ExtractDCS (dcsAliasMap);
228 oneTRDDCS->MakeSplineFit(map);
229 Store("Calib", ("cutfit_"+oneTRDDCS->GetStoreName()).Data() , oneTRDDCS, &metaData, 0, kTRUE);
236 Log (" Summury of DCS :\n");
237 Log (Form("%30s %10s %10s", "dcsDatapointAlias", "Stored ?", "# graph"));
238 for (Int_t iAlias = 0; iAlias < nEntries; iAlias++) {
239 AliTRDSensorArray * oneTRDDCS = (AliTRDSensorArray *)list->At (iAlias);
240 Log (Form ("%30s %10s %4d",
241 oneTRDDCS->GetStoreName ().Data (),
242 results[iAlias] ? "ok" : "X",
245 Log ("*********** End of DCS **********");
254 //______________________________________________________________________________________________
255 Bool_t AliTRDPreprocessor::ExtractPedestals()
258 // Pedestal running on LDCs at the DAQ
261 Bool_t error = kFALSE;
263 // Init a AliTRDCalibPadStatus
264 AliTRDCalibPadStatus calPedSum = AliTRDCalibPadStatus();
266 AliCDBMetaData metaData;
267 metaData.SetBeamPeriod(0);
268 metaData.SetResponsible("Raphaelle Bailhache");
269 metaData.SetComment("TRD calib test");
271 // Sum the contributions of the LDCs
272 TList * listpad = GetFileSources(kDAQ,"PADSTATUS");
274 Log("No list found for the PEDESTRAL Run");
278 // loop through all files from LDCs
280 while (listpad->At(index)!=NULL) {
281 TObjString* fileNameEntry = (TObjString*) listpad->At(index);
282 if (fileNameEntry != NULL)
284 TString fileName = GetFile(kDAQ, "PADSTATUS",
285 fileNameEntry->GetString().Data());
286 if(fileName.Length() ==0){
287 Log(Form("Error by retrieving the file %d for the pedestal",(Int_t)index));
292 TFile *f = TFile::Open(fileName);
293 AliTRDCalibPadStatus *calPed;
294 f->GetObject("calibpadstatus",calPed);
301 //calPed->AnalyseHisto();
303 // Add to the calPedSum
304 for (Int_t idet=0; idet<540; idet++) {
305 AliTRDCalROC *rocMean = calPed->GetCalRocMean(idet, kFALSE);
307 calPedSum.SetCalRocMean(rocMean,idet);
308 sm = (Int_t) (idet / 30);
310 AliTRDCalROC *rocRMS = calPed->GetCalRocRMS(idet, kFALSE);
312 calPedSum.SetCalRocRMS(rocRMS,idet);
314 AliTRDCalROC *rocMeand = calPed->GetCalRocMeand(idet, kFALSE);
316 calPedSum.SetCalRocMeand(rocMeand,idet);
318 AliTRDCalROC *rocRMSd = calPed->GetCalRocRMSd(idet, kFALSE);
320 calPedSum.SetCalRocRMSd(rocRMSd,idet);
324 // store as reference data
325 TString name("PadStatus");
327 if(!StoreReferenceData("DAQData",(const char *)name,(TObject *) calPed,&metaData)){
328 Log(Form("Error storing AliTRDCalibPadStatus object %d as reference data",(Int_t)index));
337 Log(Form("%d elements found in the list for the pedestal",(Int_t)index));
344 // Store pedestal entry to OCDB
348 AliTRDCalPadStatus *calPadStatus = calPedSum.CreateCalPadStatus();
350 md3.SetObjectClassName("AliTRDCalPadStatus");
351 md3.SetResponsible("Raphaelle Bailhache");
352 md3.SetBeamPeriod(1);
353 md3.SetComment("TRD calib test");
354 if(!Store("Calib","PadStatus" ,(TObject *)calPadStatus, &md3, 0, kTRUE)){
355 Log("Error storing the pedestal");
361 //Make the AliTRDCalPad
362 AliTRDCalPad *calPad2 = calPedSum.CreateCalPad();
364 md4.SetObjectClassName("AliTRDCalPad");
365 md4.SetResponsible("Raphaelle Bailhache");
366 md4.SetBeamPeriod(1);
367 md4.SetComment("TRD calib test");
368 if(!Store("Calib","PadNoise" ,(TObject *)calPad2, &md4, 0, kTRUE)){
369 Log("Error storing the pedestal");
373 //Make the AliTRDCalDet correspondant
374 AliTRDCalDet *calDet = calPedSum.CreateCalDet();
376 md5.SetObjectClassName("AliTRDCalDet");
377 md5.SetResponsible("Raphaelle Bailhache");
378 md5.SetBeamPeriod(1);
379 md5.SetComment("TRD calib test");
380 if(!Store("Calib","DetNoise" ,(TObject *)calDet, &md5, 0, kTRUE)){
381 Log("Error storing the pedestal");
391 //______________________________________________________________________________________________
392 Bool_t AliTRDPreprocessor::ExtractDriftVelocityDAQ()
395 // Drift velocity DA running on monitoring servers at the DAQ
398 Bool_t error = kFALSE;
400 // Objects for HLT and DAQ zusammen
401 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
402 AliCDBMetaData metaData;
403 metaData.SetBeamPeriod(0);
404 metaData.SetResponsible("Raphaelle Bailhache");
405 metaData.SetComment("TRD calib test");
406 // Store the infos for the detector
408 md1.SetObjectClassName("AliTRDCalDet");
409 md1.SetResponsible("Raphaelle Bailhache");
410 md1.SetBeamPeriod(0);
411 md1.SetComment("TRD calib test");
412 // Store the infos for the pads
414 md2.SetObjectClassName("AliTRDCalPad");
415 md2.SetResponsible("Raphaelle Bailhache");
416 md2.SetBeamPeriod(0);
417 md2.SetComment("TRD calib test");
419 // Take the file from the DAQ file exchange server
420 TList *listdaq = GetFileSources(kDAQ,"VDRIFT");
422 Log("No list found for vdrift (DAQ)");
426 if(listdaq->GetSize() !=1){
427 Log(Form("Problem on the size of the list: %d (DAQ)",listdaq->GetSize()));
432 TObjString* fileNameEntry = (TObjString*) listdaq->At(0);
433 if(fileNameEntry != NULL){
434 TString fileName = GetFile(kDAQ, "VDRIFT",
435 fileNameEntry->GetString().Data());
436 if(fileName.Length() ==0){
437 Log("Error retrieving the file vdrift (DAQ)");
441 TFile *filedaq = TFile::Open(fileName);
442 TProfile2D *histodriftvelocity = (TProfile2D *) filedaq->Get("PH2d");
443 if (histodriftvelocity) {
445 // store as reference data
446 if(!StoreReferenceData("DAQData","VdriftT0",(TObject *) histodriftvelocity,&metaData)){
447 Log("Error storing 2D Profile for vdrift from the DAQ");
453 Log("Take the PH reference data. Now we will try to fit\n");
454 calibra->SetMinEntries(2000); // If there is less than 2000
455 calibra->AnalysePH(histodriftvelocity);
457 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(1))
458 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(1));
459 Int_t nbfit = calibra->GetNumberFit();
460 Int_t nbE = calibra->GetNumberEnt();
462 // if enough statistics store the results
464 (nbfit >= 0.95*nbE)) {
465 // create the cal objects
466 TObjArray object = calibra->GetVectorFit();
467 AliTRDCalDet *objdriftvelocitydet = calibra->CreateDetObjectVdrift(&object,kTRUE);
468 TObject *objdriftvelocitypad = calibra->CreatePadObjectVdrift();
469 object = calibra->GetVectorFit2();
470 AliTRDCalDet *objtime0det = calibra->CreateDetObjectT0(&object,kTRUE);
471 TObject *objtime0pad = calibra->CreatePadObjectT0();
472 calibra->ResetVectorFit();
474 if(!Store("Calib","ChamberVdrift" ,(TObject *) objdriftvelocitydet,&md1,0,kTRUE)){
475 Log("Error storing the calibration object for the chamber vdrift (DAQ)");
478 if(!Store("Calib","ChamberT0" ,(TObject *) objtime0det ,&md1,0,kTRUE)){
479 Log("Error storing the calibration object for the chamber t0 (DAQ)");
482 if(!Store("Calib","LocalVdrift" ,(TObject *) objdriftvelocitypad,&md2,0,kTRUE)){
483 Log("Error storing the calibration object for the local drift velocity (DAQ)");
486 if(!Store("Calib","LocalT0" ,(TObject *) objtime0pad ,&md2,0,kTRUE)){
487 Log("Error storing the calibration object for the local time0 (DAQ)");
492 Log("Not enough statistics for the average pulse height (DAQ)");
502 //______________________________________________________________________________________________
503 Bool_t AliTRDPreprocessor::ExtractHLT()
506 // Gain, vdrift and PRF calibration running on HLT
507 // return kTRUE if NULL pointer to the list
510 Bool_t error = kFALSE;
512 // Objects for HLT and DAQ zusammen
513 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
514 AliCDBMetaData metaData;
515 metaData.SetBeamPeriod(0);
516 metaData.SetResponsible("Raphaelle Bailhache");
517 metaData.SetComment("TRD calib test");
518 // Store the infos for the detector
520 md1.SetObjectClassName("AliTRDCalDet");
521 md1.SetResponsible("Raphaelle Bailhache");
522 md1.SetBeamPeriod(0);
523 md1.SetComment("TRD calib test");
524 // Store the infos for the pads
526 md2.SetObjectClassName("AliTRDCalPad");
527 md2.SetResponsible("Raphaelle Bailhache");
528 md2.SetBeamPeriod(0);
529 md2.SetComment("TRD calib test");
531 // Take the file from the HLT file exchange server
532 TList *listhlt = GetFileSources(kHLT,"GAINDRIFTPRF");
534 Log("No list found for the HLT");
538 if(listhlt->GetSize() != 1) {
539 Log(Form("Problem on the size of the list: %d (HLT)",listhlt->GetSize()));
544 TObjString* fileNameEntry = (TObjString*) listhlt->At(0);
545 if(fileNameEntry != NULL){
546 TString fileName = GetFile(kHLT, "GAINDRIFTPRF",
547 fileNameEntry->GetString().Data());
548 if(fileName.Length() ==0){
549 Log("Error retrieving the file (HLT)");
554 TFile *filehlt = TFile::Open(fileName);
557 TH2I *histogain = (TH2I *) filehlt->Get("CH2d");
558 histogain->SetDirectory(0);
560 // store the reference data
561 if(!StoreReferenceData("HLTData","Gain",(TObject *) histogain,&metaData)){
562 Log("Error storing 2D histos for gain");
566 Log("Take the CH reference data. Now we will try to fit\n");
567 calibra->SetMinEntries(1000); // If there is less than 1000 entries in the histo: no fit
568 calibra->AnalyseCH(histogain);
569 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(0))
570 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(0));
571 Int_t nbfit = calibra->GetNumberFit();
572 Int_t nbE = calibra->GetNumberEnt();
575 (nbfit >= 0.95*nbE)) {
576 // create the cal objects
577 TObjArray object = calibra->GetVectorFit();
578 AliTRDCalDet *objgaindet = calibra->CreateDetObjectGain(&object);
579 TObject *objgainpad = calibra->CreatePadObjectGain();
581 if(!Store("Calib","ChamberGainFactor",(TObject *) objgaindet ,&md1,0,kTRUE)){
582 Log("Error storing the calibration object for the chamber gain");
585 if(!Store("Calib","LocalGainFactor" ,(TObject *) objgainpad ,&md2,0,kTRUE)){
586 Log("Error storing the calibration object for the local gain factor");
590 calibra->ResetVectorFit();
595 TProfile2D *histodriftvelocity = (TProfile2D *) filehlt->Get("PH2d");
596 histodriftvelocity->SetDirectory(0);
597 if (histodriftvelocity) {
598 // store the reference data
599 if(!StoreReferenceData("HLTData","VdriftT0",(TObject *) histodriftvelocity,&metaData)){
600 Log("Error storing 2D Profile for average pulse height (HLT)");
604 Log("Take the PH reference data. Now we will try to fit\n");
605 calibra->SetMinEntries(1000*20); // If there is less than 20000
606 calibra->AnalysePH(histodriftvelocity);
607 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(1))
608 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(1));
609 Int_t nbfit = calibra->GetNumberFit();
610 Int_t nbE = calibra->GetNumberEnt();
613 (nbfit >= 0.95*nbE)) {
614 // create the cal objects
615 TObjArray object = calibra->GetVectorFit();
616 AliTRDCalDet *objdriftvelocitydet = calibra->CreateDetObjectVdrift(&object,kTRUE);
617 TObject *objdriftvelocitypad = calibra->CreatePadObjectVdrift();
618 object = calibra->GetVectorFit2();
619 AliTRDCalDet *objtime0det = calibra->CreateDetObjectT0(&object,kTRUE);
620 TObject *objtime0pad = calibra->CreatePadObjectT0();
622 if(!Store("Calib","ChamberVdrift" ,(TObject *) objdriftvelocitydet,&md1,0,kTRUE)){
623 Log("Error storing the calibration object for the chamber vdrift (HLT)");
626 if(!Store("Calib","ChamberT0" ,(TObject *) objtime0det ,&md1,0,kTRUE)){
627 Log("Error storing the calibration object for the chamber t0 (HLT)");
630 if(!Store("Calib","LocalVdrift" ,(TObject *) objdriftvelocitypad,&md2,0,kTRUE)){
631 Log("Error storing the calibration object for the local drift velocity (HLT)");
634 if(!Store("Calib","LocalT0" ,(TObject *) objtime0pad ,&md2,0,kTRUE)){
635 Log("Error storing the calibration object for the local time0 (HLT)");
640 calibra->ResetVectorFit();
644 TProfile2D *histoprf = (TProfile2D *) filehlt->Get("PRF2d");
645 histoprf->SetDirectory(0);
647 // store reference data
648 if(!StoreReferenceData("HLTData","PRF",(TObject *) histoprf,&metaData)){
649 Log("Error storing the 2D Profile for Pad Response Function");
653 Log("Take the PRF reference data. Now we will try to fit\n");
654 calibra->SetMinEntries(600); // If there is less than 20000
655 calibra->AnalysePRFMarianFit(histoprf);
656 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(2))
657 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(2));
658 Int_t nbfit = calibra->GetNumberFit();
659 Int_t nbE = calibra->GetNumberEnt();
662 (nbfit >= 0.95*nbE)) {
663 // create cal pad objects
664 TObjArray object = calibra->GetVectorFit();
665 TObject *objPRFpad = calibra->CreatePadObjectPRF(&object);
667 if(!Store("Calib","PRFWidth" ,(TObject *) objPRFpad ,&md2,0,kTRUE)){
668 Log("Error storing the calibration object for the Pad Response Function");
672 calibra->ResetVectorFit();