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)
66 //______________________________________________________________________________________________
67 AliTRDPreprocessor::~AliTRDPreprocessor()
75 //______________________________________________________________________________________________
76 void AliTRDPreprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
79 // Initialization routine for the TRD preprocessor
82 AliPreprocessor::Initialize(run,startTime,endTime);
86 //______________________________________________________________________________________________
87 UInt_t AliTRDPreprocessor::Process(TMap* dcsAliasMap)
90 // Process DCS and calibration part for HLT
93 TString runType = GetRunType();
94 Log(Form("runtype %s\n",runType.Data()));
96 if (runType=="PEDESTAL_RUN"){
97 if(ExtractPedestals()) return 1;
101 if (runType=="PHYSICS"){
103 if(ProcessDCS(dcsAliasMap)) return 1;
105 //TString runPar = GetRunParameter("HLTStatus");
108 if(ExtractHLT()) return 1;
112 if(ExtractDriftVelocityDAQ()) return 1;
120 //______________________________________________________________________________
121 Bool_t AliTRDPreprocessor::ProcessDCS()
124 // Default process DCS method
127 TString runType = GetRunType();
128 if (runType == "PHYSICS") {
135 //______________________________________________________________________________
136 Bool_t AliTRDPreprocessor::ProcessDCS(TMap *dcsAliasMap)
139 // Process DCS method
142 Bool_t error = kFALSE;
144 AliCDBMetaData metaData;
145 metaData.SetBeamPeriod(0);
146 metaData.SetResponsible("Wilfried Monange/Raphaelle Bailhache");
147 metaData.SetComment("TRD calib test");
149 Log("****** DCS ******\n");
151 TObjArray * list=AliTRDSensorArray::GetList ();
154 Log ("Error during AliTRDSensorArray::GetList");
155 Log ("DCS will not be processing");
159 Int_t nEntries = list->GetEntries ();
160 Log (Form ("%d alias loaded", nEntries));
162 Bool_t * results=new Bool_t [nEntries];
163 Int_t * nGraph=new Int_t [nEntries];
165 for (Int_t iAlias = 0; iAlias < nEntries; iAlias++) {
167 AliTRDSensorArray * oneTRDDCS = (AliTRDSensorArray *)list->At (iAlias);
169 oneTRDDCS->SetStartTime (TTimeStamp (fStartTime));
170 oneTRDDCS->SetEndTime (TTimeStamp (fEndTime));
172 Log(Form("Processing DCS : \"%s\"", oneTRDDCS->GetStoreName ().Data ()));
176 map=oneTRDDCS->ExtractDCS (dcsAliasMap);
178 nGraph [iAlias] = map->GetEntries ();
180 if (nGraph [iAlias] == 0) {
181 Log("No TGraph for this dcsDatapointAlias : not stored");
182 results [iAlias] = kFALSE;
187 oneTRDDCS->SetGraph(map);
188 results[iAlias]=Store("Calib", oneTRDDCS->GetStoreName().Data(), oneTRDDCS, &metaData, 0, kTRUE);
191 //results [iAlias] = StoreReferenceData("Calib", oneTRDDCS->GetStoreName ().Data (), oneTRDDCS, &metaData);
193 if (!results[iAlias]) {
194 AliError("Problem during StoreRef DCS");
198 //BEGIN TEST (should not be removed ...)
200 oneTRDDCS->ClearGraph();
201 oneTRDDCS->ClearFit();
202 oneTRDDCS->SetDiffCut2 (0.1);
203 map=oneTRDDCS->ExtractDCS (dcsAliasMap);
204 oneTRDDCS->SetGraph (map);
205 Store("Calib", ("cut_"+oneTRDDCS->GetStoreName()).Data(), oneTRDDCS, &metaData, 0, kTRUE);
209 if(iAlias==1 || iAlias==19) continue;
211 oneTRDDCS->ClearGraph();
212 oneTRDDCS->ClearFit();
213 oneTRDDCS->SetDiffCut2(0);
214 map=oneTRDDCS->ExtractDCS(dcsAliasMap);
215 oneTRDDCS->MakeSplineFit(map);
216 Store("Calib", ("fit_"+oneTRDDCS->GetStoreName()).Data() , oneTRDDCS, &metaData, 0, kTRUE);
220 oneTRDDCS->ClearGraph();
221 oneTRDDCS->ClearFit();
222 oneTRDDCS->SetDiffCut2 (0.1);
223 map=oneTRDDCS->ExtractDCS (dcsAliasMap);
224 oneTRDDCS->MakeSplineFit(map);
225 Store("Calib", ("cutfit_"+oneTRDDCS->GetStoreName()).Data() , oneTRDDCS, &metaData, 0, kTRUE);
232 Log (" Summury of DCS :\n");
233 Log (Form("%30s %10s %10s", "dcsDatapointAlias", "Stored ?", "# graph"));
234 for (Int_t iAlias = 0; iAlias < nEntries; iAlias++) {
235 AliTRDSensorArray * oneTRDDCS = (AliTRDSensorArray *)list->At (iAlias);
236 Log (Form ("%30s %10s %4d",
237 oneTRDDCS->GetStoreName ().Data (),
238 results[iAlias] ? "ok" : "X",
241 Log ("*********** End of DCS **********");
250 //______________________________________________________________________________________________
251 Bool_t AliTRDPreprocessor::ExtractPedestals()
254 // Pedestal running on LDCs at the DAQ
257 Bool_t error = kFALSE;
259 // Init a AliTRDCalibPadStatus
260 AliTRDCalibPadStatus calPedSum = AliTRDCalibPadStatus();
262 AliCDBMetaData metaData;
263 metaData.SetBeamPeriod(0);
264 metaData.SetResponsible("Raphaelle Bailhache");
265 metaData.SetComment("TRD calib test");
267 // Sum the contributions of the LDCs
268 TList * listpad = GetFileSources(kDAQ,"PADSTATUS");
270 Log("No list found for the PEDESTRAL Run");
274 // loop through all files from LDCs
276 while (listpad->At(index)!=NULL) {
277 TObjString* fileNameEntry = (TObjString*) listpad->At(index);
278 if (fileNameEntry != NULL)
280 TString fileName = GetFile(kDAQ, "PADSTATUS",
281 fileNameEntry->GetString().Data());
282 if(fileName.Length() ==0){
283 Log(Form("Error by retrieving the file %d for the pedestal",(Int_t)index));
288 TFile *f = TFile::Open(fileName);
289 AliTRDCalibPadStatus *calPed;
290 f->GetObject("calibpadstatus",calPed);
297 //calPed->AnalyseHisto();
299 // Add to the calPedSum
300 for (Int_t idet=0; idet<540; idet++) {
301 AliTRDCalROC *rocMean = calPed->GetCalRocMean(idet, kFALSE);
303 calPedSum.SetCalRocMean(rocMean,idet);
304 sm = (Int_t) (idet / 30);
306 AliTRDCalROC *rocRMS = calPed->GetCalRocRMS(idet, kFALSE);
308 calPedSum.SetCalRocRMS(rocRMS,idet);
310 AliTRDCalROC *rocMeand = calPed->GetCalRocMeand(idet, kFALSE);
312 calPedSum.SetCalRocMeand(rocMeand,idet);
314 AliTRDCalROC *rocRMSd = calPed->GetCalRocRMSd(idet, kFALSE);
316 calPedSum.SetCalRocRMSd(rocRMSd,idet);
320 // store as reference data
321 TString name("PadStatus");
323 if(!StoreReferenceData("DAQData",(const char *)name,(TObject *) calPed,&metaData)){
324 Log(Form("Error storing AliTRDCalibPadStatus object %d as reference data",(Int_t)index));
333 Log(Form("%d elements found in the list for the pedestal",(Int_t)index));
340 // Store pedestal entry to OCDB
344 AliTRDCalPadStatus *calPadStatus = calPedSum.CreateCalPadStatus();
346 md3.SetObjectClassName("AliTRDCalPadStatus");
347 md3.SetResponsible("Raphaelle Bailhache");
348 md3.SetBeamPeriod(1);
349 md3.SetComment("TRD calib test");
350 if(!Store("Calib","PadStatus" ,(TObject *)calPadStatus, &md3, 0, kTRUE)){
351 Log("Error storing the pedestal");
357 //Make the AliTRDCalPad
358 AliTRDCalPad *calPad2 = calPedSum.CreateCalPad();
360 md4.SetObjectClassName("AliTRDCalPad");
361 md4.SetResponsible("Raphaelle Bailhache");
362 md4.SetBeamPeriod(1);
363 md4.SetComment("TRD calib test");
364 if(!Store("Calib","PadNoise" ,(TObject *)calPad2, &md4, 0, kTRUE)){
365 Log("Error storing the pedestal");
369 //Make the AliTRDCalDet correspondant
370 AliTRDCalDet *calDet = calPedSum.CreateCalDet();
372 md5.SetObjectClassName("AliTRDCalDet");
373 md5.SetResponsible("Raphaelle Bailhache");
374 md5.SetBeamPeriod(1);
375 md5.SetComment("TRD calib test");
376 if(!Store("Calib","DetNoise" ,(TObject *)calDet, &md5, 0, kTRUE)){
377 Log("Error storing the pedestal");
387 //______________________________________________________________________________________________
388 Bool_t AliTRDPreprocessor::ExtractDriftVelocityDAQ()
391 // Drift velocity DA running on monitoring servers at the DAQ
394 Bool_t error = kFALSE;
396 // Objects for HLT and DAQ zusammen
397 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
398 AliCDBMetaData metaData;
399 metaData.SetBeamPeriod(0);
400 metaData.SetResponsible("Raphaelle Bailhache");
401 metaData.SetComment("TRD calib test");
402 // Store the infos for the detector
404 md1.SetObjectClassName("AliTRDCalDet");
405 md1.SetResponsible("Raphaelle Bailhache");
406 md1.SetBeamPeriod(0);
407 md1.SetComment("TRD calib test");
408 // Store the infos for the pads
410 md2.SetObjectClassName("AliTRDCalPad");
411 md2.SetResponsible("Raphaelle Bailhache");
412 md2.SetBeamPeriod(0);
413 md2.SetComment("TRD calib test");
415 // Take the file from the DAQ file exchange server
416 TList *listdaq = GetFileSources(kDAQ,"VDRIFT");
418 Log("No list found for vdrift (DAQ)");
422 if(listdaq->GetSize() !=1){
423 Log(Form("Problem on the size of the list: %d (DAQ)",listdaq->GetSize()));
428 TObjString* fileNameEntry = (TObjString*) listdaq->At(0);
429 if(fileNameEntry != NULL){
430 TString fileName = GetFile(kDAQ, "VDRIFT",
431 fileNameEntry->GetString().Data());
432 if(fileName.Length() ==0){
433 Log("Error retrieving the file vdrift (DAQ)");
437 TFile *filedaq = TFile::Open(fileName);
438 TProfile2D *histodriftvelocity = (TProfile2D *) filedaq->Get("PH2d");
439 if (histodriftvelocity) {
441 // store as reference data
442 if(!StoreReferenceData("DAQData","VdriftT0",(TObject *) histodriftvelocity,&metaData)){
443 Log("Error storing 2D Profile for vdrift from the DAQ");
449 Log("Take the PH reference data. Now we will try to fit\n");
450 calibra->SetMinEntries(2000); // If there is less than 2000
451 calibra->AnalysePH(histodriftvelocity);
453 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(1))
454 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(1));
455 Int_t nbfit = calibra->GetNumberFit();
456 Int_t nbE = calibra->GetNumberEnt();
458 // if enough statistics store the results
460 (nbfit >= 0.95*nbE)) {
461 // create the cal objects
462 TObjArray object = calibra->GetVectorFit();
463 AliTRDCalDet *objdriftvelocitydet = calibra->CreateDetObjectVdrift(&object,kTRUE);
464 TObject *objdriftvelocitypad = calibra->CreatePadObjectVdrift();
465 object = calibra->GetVectorFit2();
466 AliTRDCalDet *objtime0det = calibra->CreateDetObjectT0(&object,kTRUE);
467 TObject *objtime0pad = calibra->CreatePadObjectT0();
468 calibra->ResetVectorFit();
470 if(!Store("Calib","ChamberVdrift" ,(TObject *) objdriftvelocitydet,&md1,0,kTRUE)){
471 Log("Error storing the calibration object for the chamber vdrift (DAQ)");
474 if(!Store("Calib","ChamberT0" ,(TObject *) objtime0det ,&md1,0,kTRUE)){
475 Log("Error storing the calibration object for the chamber t0 (DAQ)");
478 if(!Store("Calib","LocalVdrift" ,(TObject *) objdriftvelocitypad,&md2,0,kTRUE)){
479 Log("Error storing the calibration object for the local drift velocity (DAQ)");
482 if(!Store("Calib","LocalT0" ,(TObject *) objtime0pad ,&md2,0,kTRUE)){
483 Log("Error storing the calibration object for the local time0 (DAQ)");
488 Log("Not enough statistics for the average pulse height (DAQ)");
498 //______________________________________________________________________________________________
499 Bool_t AliTRDPreprocessor::ExtractHLT()
502 // Gain, vdrift and PRF calibration running on HLT
503 // return kTRUE if NULL pointer to the list
506 Bool_t error = kFALSE;
508 // Objects for HLT and DAQ zusammen
509 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
510 AliCDBMetaData metaData;
511 metaData.SetBeamPeriod(0);
512 metaData.SetResponsible("Raphaelle Bailhache");
513 metaData.SetComment("TRD calib test");
514 // Store the infos for the detector
516 md1.SetObjectClassName("AliTRDCalDet");
517 md1.SetResponsible("Raphaelle Bailhache");
518 md1.SetBeamPeriod(0);
519 md1.SetComment("TRD calib test");
520 // Store the infos for the pads
522 md2.SetObjectClassName("AliTRDCalPad");
523 md2.SetResponsible("Raphaelle Bailhache");
524 md2.SetBeamPeriod(0);
525 md2.SetComment("TRD calib test");
527 // Take the file from the HLT file exchange server
528 TList *listhlt = GetFileSources(kHLT,"GAINDRIFTPRF");
530 Log("No list found for the HLT");
534 if(listhlt->GetSize() != 1) {
535 Log(Form("Problem on the size of the list: %d (HLT)",listhlt->GetSize()));
540 TObjString* fileNameEntry = (TObjString*) listhlt->At(0);
541 if(fileNameEntry != NULL){
542 TString fileName = GetFile(kHLT, "GAINDRIFTPRF",
543 fileNameEntry->GetString().Data());
544 if(fileName.Length() ==0){
545 Log("Error retrieving the file (HLT)");
550 TFile *filehlt = TFile::Open(fileName);
553 TH2I *histogain = (TH2I *) filehlt->Get("CH2d");
554 histogain->SetDirectory(0);
556 // store the reference data
557 if(!StoreReferenceData("HLTData","Gain",(TObject *) histogain,&metaData)){
558 Log("Error storing 2D histos for gain");
562 Log("Take the CH reference data. Now we will try to fit\n");
563 calibra->SetMinEntries(1000); // If there is less than 1000 entries in the histo: no fit
564 calibra->AnalyseCH(histogain);
565 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(0))
566 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(0));
567 Int_t nbfit = calibra->GetNumberFit();
568 Int_t nbE = calibra->GetNumberEnt();
571 (nbfit >= 0.95*nbE)) {
572 // create the cal objects
573 TObjArray object = calibra->GetVectorFit();
574 AliTRDCalDet *objgaindet = calibra->CreateDetObjectGain(&object,calibra->GetScaleFitFactor(),kTRUE);
575 TObject *objgainpad = calibra->CreatePadObjectGain();
577 if(!Store("Calib","ChamberGainFactor",(TObject *) objgaindet ,&md1,0,kTRUE)){
578 Log("Error storing the calibration object for the chamber gain");
581 if(!Store("Calib","LocalGainFactor" ,(TObject *) objgainpad ,&md2,0,kTRUE)){
582 Log("Error storing the calibration object for the local gain factor");
586 calibra->ResetVectorFit();
591 TProfile2D *histodriftvelocity = (TProfile2D *) filehlt->Get("PH2d");
592 histodriftvelocity->SetDirectory(0);
593 if (histodriftvelocity) {
594 // store the reference data
595 if(!StoreReferenceData("HLTData","VdriftT0",(TObject *) histodriftvelocity,&metaData)){
596 Log("Error storing 2D Profile for average pulse height (HLT)");
600 Log("Take the PH reference data. Now we will try to fit\n");
601 calibra->SetMinEntries(1000*20); // If there is less than 20000
602 calibra->AnalysePH(histodriftvelocity);
603 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(1))
604 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(1));
605 Int_t nbfit = calibra->GetNumberFit();
606 Int_t nbE = calibra->GetNumberEnt();
609 (nbfit >= 0.95*nbE)) {
610 // create the cal objects
611 TObjArray object = calibra->GetVectorFit();
612 AliTRDCalDet *objdriftvelocitydet = calibra->CreateDetObjectVdrift(&object,kTRUE);
613 TObject *objdriftvelocitypad = calibra->CreatePadObjectVdrift();
614 object = calibra->GetVectorFit2();
615 AliTRDCalDet *objtime0det = calibra->CreateDetObjectT0(&object,kTRUE);
616 TObject *objtime0pad = calibra->CreatePadObjectT0();
618 if(!Store("Calib","ChamberVdrift" ,(TObject *) objdriftvelocitydet,&md1,0,kTRUE)){
619 Log("Error storing the calibration object for the chamber vdrift (HLT)");
622 if(!Store("Calib","ChamberT0" ,(TObject *) objtime0det ,&md1,0,kTRUE)){
623 Log("Error storing the calibration object for the chamber t0 (HLT)");
626 if(!Store("Calib","LocalVdrift" ,(TObject *) objdriftvelocitypad,&md2,0,kTRUE)){
627 Log("Error storing the calibration object for the local drift velocity (HLT)");
630 if(!Store("Calib","LocalT0" ,(TObject *) objtime0pad ,&md2,0,kTRUE)){
631 Log("Error storing the calibration object for the local time0 (HLT)");
636 calibra->ResetVectorFit();
640 TProfile2D *histoprf = (TProfile2D *) filehlt->Get("PRF2d");
641 histoprf->SetDirectory(0);
643 // store reference data
644 if(!StoreReferenceData("HLTData","PRF",(TObject *) histoprf,&metaData)){
645 Log("Error storing the 2D Profile for Pad Response Function");
649 Log("Take the PRF reference data. Now we will try to fit\n");
650 calibra->SetMinEntries(600); // If there is less than 20000
651 calibra->AnalysePRFMarianFit(histoprf);
652 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(2))
653 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(2));
654 Int_t nbfit = calibra->GetNumberFit();
655 Int_t nbE = calibra->GetNumberEnt();
658 (nbfit >= 0.95*nbE)) {
659 // create cal pad objects
660 TObjArray object = calibra->GetVectorFit();
661 TObject *objPRFpad = calibra->CreatePadObjectPRF(&object);
663 if(!Store("Calib","PRFWidth" ,(TObject *) objPRFpad ,&md2,0,kTRUE)){
664 Log("Error storing the calibration object for the Pad Response Function");
668 calibra->ResetVectorFit();