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 ////////////////////////////////////////////////////////////////////////////
34 #include "AliTRDPreprocessor.h"
37 #include <TProfile2D.h>
38 #include <TStopwatch.h>
39 #include <TObjString.h>
42 #include <TCollection.h>
44 #include "AliCDBMetaData.h"
47 #include "AliTRDSensorArray.h"
48 #include "AliTRDCalibraFit.h"
49 #include "AliTRDCalibraMode.h"
50 #include "AliTRDCalibPadStatus.h"
51 #include "Cal/AliTRDCalDet.h"
52 #include "Cal/AliTRDCalPadStatus.h"
54 ClassImp(AliTRDPreprocessor)
56 //______________________________________________________________________________________________
57 AliTRDPreprocessor::AliTRDPreprocessor(AliShuttleInterface *shuttle)
58 :AliPreprocessor("TRD", shuttle),
67 //______________________________________________________________________________________________
68 AliTRDPreprocessor::~AliTRDPreprocessor()
76 //______________________________________________________________________________________________
77 void AliTRDPreprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
80 // Initialization routine for the TRD preprocessor
83 AliPreprocessor::Initialize(run,startTime,endTime);
87 //______________________________________________________________________________________________
88 UInt_t AliTRDPreprocessor::Process(TMap* dcsAliasMap)
91 // Process DCS and calibration part for HLT
94 TString runType = GetRunType();
95 Log(Form("runtype %s\n",runType.Data()));
97 if (runType=="PEDESTAL_RUN"){
98 if(ExtractPedestals()) return 1;
104 if (runType=="PHYSICS"){
106 if(ProcessDCS(dcsAliasMap)) return 1;
108 //TString runPar = GetRunParameter("HLTStatus");
111 if(ExtractHLT()) return 1;
115 if(ExtractDriftVelocityDAQ()) return 1;
122 //______________________________________________________________________________
123 Bool_t AliTRDPreprocessor::ProcessDCS()
126 TString runType = GetRunType();
127 if(runType == "PHYSICS") return kTRUE;
133 //______________________________________________________________________________
134 Bool_t AliTRDPreprocessor::ProcessDCS(TMap * dcsAliasMap)
138 AliCDBMetaData metaData;
139 metaData.SetBeamPeriod(0);
140 metaData.SetResponsible("Wilfried Monange/Raphaelle Bailhache");
141 metaData.SetComment("TRD calib test");
144 Log ("****** DCS ******\n");
146 TObjArray * list=AliTRDSensorArray::GetList ();
149 Log ("Error during AliTRDSensorArray::GetList");
150 Log ("DCS will not be processing");
154 Int_t nEntries = list->GetEntries ();
155 Log (Form ("%d alias loaded", nEntries));
157 Bool_t * results=new Bool_t [nEntries];
158 Int_t * nGraph=new Int_t [nEntries];
160 for (Int_t iAlias = 0; iAlias < nEntries; iAlias++) {
162 AliTRDSensorArray * oneTRDDCS = (AliTRDSensorArray *)list->At (iAlias);
164 oneTRDDCS->SetStartTime (TTimeStamp (fStartTime));
165 oneTRDDCS->SetEndTime (TTimeStamp (fEndTime));
167 Log (Form("Processing DCS : \"%s\"", oneTRDDCS->GetStoreName ().Data ()));
171 map=oneTRDDCS->ExtractDCS (dcsAliasMap);
173 nGraph [iAlias] = map->GetEntries ();
175 if (nGraph [iAlias] == 0) {
176 Log("No TGraph for this dcsDatapointAlias : not stored");
177 results [iAlias] = kFALSE;
181 oneTRDDCS->SetGraph(map);
182 results[iAlias]=Store("Calib", oneTRDDCS->GetStoreName().Data(), oneTRDDCS, &metaData, 0, kTRUE);
185 //results [iAlias] = StoreReferenceData("Calib", oneTRDDCS->GetStoreName ().Data (), oneTRDDCS, &metaData);
188 if (!results[iAlias]) {
189 AliError("Problem during StoreRef DCS");
194 //BEGIN TEST (should not be removed ...)
196 oneTRDDCS->ClearGraph();
197 oneTRDDCS->ClearFit();
198 oneTRDDCS->SetDiffCut2 (0.1);
199 map=oneTRDDCS->ExtractDCS (dcsAliasMap);
200 oneTRDDCS->SetGraph (map);
201 Store("Calib", ("cut_"+oneTRDDCS->GetStoreName()).Data(), oneTRDDCS, &metaData, 0, kTRUE);
205 if(iAlias==1 || iAlias==19) continue;
207 oneTRDDCS->ClearGraph();
208 oneTRDDCS->ClearFit();
209 oneTRDDCS->SetDiffCut2(0);
210 map=oneTRDDCS->ExtractDCS(dcsAliasMap);
211 oneTRDDCS->MakeSplineFit(map);
212 Store("Calib", ("fit_"+oneTRDDCS->GetStoreName()).Data() , oneTRDDCS, &metaData, 0, kTRUE);
216 oneTRDDCS->ClearGraph();
217 oneTRDDCS->ClearFit();
218 oneTRDDCS->SetDiffCut2 (0.1);
219 map=oneTRDDCS->ExtractDCS (dcsAliasMap);
220 oneTRDDCS->MakeSplineFit(map);
221 Store("Calib", ("cutfit_"+oneTRDDCS->GetStoreName()).Data() , oneTRDDCS, &metaData, 0, kTRUE);
230 Log (" Summury of DCS :\n");
231 Log (Form("%30s %10s %10s", "dcsDatapointAlias", "Stored ?", "# graph"));
232 for (Int_t iAlias = 0; iAlias < nEntries; iAlias++) {
233 AliTRDSensorArray * oneTRDDCS = (AliTRDSensorArray *)list->At (iAlias);
234 Log (Form ("%30s %10s %4d",
235 oneTRDDCS->GetStoreName ().Data (),
236 results[iAlias] ? "ok" : "X",
239 Log ("*********** End of DCS **********");
247 //______________________________________________________________________________________________
248 Bool_t AliTRDPreprocessor::ExtractPedestals()
251 // Pedestal running on LDCs at the DAQ
254 Bool_t error = kFALSE;
256 // Init a AliTRDCalibPadStatus
257 AliTRDCalibPadStatus calPedSum = AliTRDCalibPadStatus();
259 AliCDBMetaData metaData;
260 metaData.SetBeamPeriod(0);
261 metaData.SetResponsible("Raphaelle Bailhache");
262 metaData.SetComment("TRD calib test");
264 // Sum the contributions of the LDCs
265 TList * listpad = GetFileSources(kDAQ,"PADSTATUS");
267 Log("No list found for the PEDESTRAL Run");
271 // loop through all files from LDCs
274 while (listpad->At(index)!=NULL) {
275 TObjString* fileNameEntry = (TObjString*) listpad->At(index);
276 if (fileNameEntry != NULL)
278 TString fileName = GetFile(kDAQ, "PADSTATUS",
279 fileNameEntry->GetString().Data());
280 if(fileName.Length() ==0){
281 Log(Form("Error by retrieving the file %d for the pedestal",(Int_t)index));
286 TFile *f = TFile::Open(fileName);
287 AliTRDCalibPadStatus *calPed;
288 f->GetObject("calibpadstatus",calPed);
295 //calPed->AnalyseHisto();
297 // Add to the calPedSum
298 for (Int_t idet=0; idet<540; idet++) {
299 AliTRDCalROC *rocMean = calPed->GetCalRocMean(idet, kFALSE);
301 calPedSum.SetCalRocMean(rocMean,idet);
302 sm = (Int_t) (idet / 30);
304 AliTRDCalROC *rocRMS = calPed->GetCalRocRMS(idet, kFALSE);
306 calPedSum.SetCalRocRMS(rocRMS,idet);
310 // store as reference data
311 TString name("PadStatus");
313 if(!StoreReferenceData("DAQData",(const char *)name,(TObject *) calPed,&metaData)){
314 Log(Form("Error storing AliTRDCalibPadStatus object %d as reference data",(Int_t)index));
322 Log(Form("%d elements found in the list for the pedestal",(Int_t)index));
328 // Store pedestal entry to OCDB
333 AliTRDCalPadStatus *calPadStatus = calPedSum.CreateCalPadStatus();
335 md3.SetObjectClassName("AliTRDCalPadStatus");
336 md3.SetResponsible("Raphaelle Bailhache");
337 md3.SetBeamPeriod(1);
338 md3.SetComment("TRD calib test");
339 if(!Store("Calib","PadStatus" ,(TObject *)calPadStatus, &md3, 0, kTRUE)){
340 Log("Error storing the pedestal");
346 //Make the AliTRDCalPad
347 AliTRDCalPad *calPad2 = calPedSum.CreateCalPad();
349 md4.SetObjectClassName("AliTRDCalPad");
350 md4.SetResponsible("Raphaelle Bailhache");
351 md4.SetBeamPeriod(1);
352 md4.SetComment("TRD calib test");
353 if(!Store("Calib","PadNoise" ,(TObject *)calPad2, &md4, 0, kTRUE)){
354 Log("Error storing the pedestal");
358 //Make the AliTRDCalDet correspondant
359 AliTRDCalDet *calDet = calPedSum.CreateCalDet();
361 md5.SetObjectClassName("AliTRDCalDet");
362 md5.SetResponsible("Raphaelle Bailhache");
363 md5.SetBeamPeriod(1);
364 md5.SetComment("TRD calib test");
365 if(!Store("Calib","DetNoise" ,(TObject *)calDet, &md5, 0, kTRUE)){
366 Log("Error storing the pedestal");
375 //______________________________________________________________________________________________
376 Bool_t AliTRDPreprocessor::ExtractDriftVelocityDAQ()
379 // Drift velocity DA running on monitoring servers at the DAQ
382 Bool_t error = kFALSE;
384 // Objects for HLT and DAQ zusammen
385 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
386 AliCDBMetaData metaData;
387 metaData.SetBeamPeriod(0);
388 metaData.SetResponsible("Raphaelle Bailhache");
389 metaData.SetComment("TRD calib test");
390 // Store the infos for the detector
392 md1.SetObjectClassName("AliTRDCalDet");
393 md1.SetResponsible("Raphaelle Bailhache");
394 md1.SetBeamPeriod(0);
395 md1.SetComment("TRD calib test");
396 // Store the infos for the pads
398 md2.SetObjectClassName("AliTRDCalPad");
399 md2.SetResponsible("Raphaelle Bailhache");
400 md2.SetBeamPeriod(0);
401 md2.SetComment("TRD calib test");
406 // Take the file from the DAQ file exchange server
407 TList *listdaq = GetFileSources(kDAQ,"VDRIFT");
409 Log("No list found for vdrift (DAQ)");
413 if(listdaq->GetSize() !=1){
414 Log(Form("Problem on the size of the list: %d (DAQ)",listdaq->GetSize()));
419 TObjString* fileNameEntry = (TObjString*) listdaq->At(0);
420 if(fileNameEntry != NULL){
421 TString fileName = GetFile(kDAQ, "VDRIFT",
422 fileNameEntry->GetString().Data());
423 if(fileName.Length() ==0){
424 Log("Error retrieving the file vdrift (DAQ)");
428 TFile *filedaq = TFile::Open(fileName);
429 TProfile2D *histodriftvelocity = (TProfile2D *) filedaq->Get("PH2d");
430 if (histodriftvelocity) {
432 // store as reference data
433 if(!StoreReferenceData("DAQData","VdriftT0",(TObject *) histodriftvelocity,&metaData)){
434 Log("Error storing 2D Profile for vdrift from the DAQ");
440 Log("Take the PH reference data. Now we will try to fit\n");
441 calibra->SetMinEntries(2000); // If there is less than 2000
442 calibra->AnalysePH(histodriftvelocity);
444 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(1))
445 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(1));
446 Int_t nbfit = calibra->GetNumberFit();
447 Int_t nbE = calibra->GetNumberEnt();
449 // if enough statistics store the results
451 (nbfit >= 0.95*nbE)) {
452 // create the cal objects
453 TObjArray object = calibra->GetVectorFit();
454 AliTRDCalDet *objdriftvelocitydet = calibra->CreateDetObjectVdrift(&object,kTRUE);
455 TObject *objdriftvelocitypad = calibra->CreatePadObjectVdrift();
456 object = calibra->GetVectorFit2();
457 AliTRDCalDet *objtime0det = calibra->CreateDetObjectT0(&object,kTRUE);
458 TObject *objtime0pad = calibra->CreatePadObjectT0();
459 calibra->ResetVectorFit();
461 if(!Store("Calib","ChamberVdrift" ,(TObject *) objdriftvelocitydet,&md1,0,kTRUE)){
462 Log("Error storing the calibration object for the chamber vdrift (DAQ)");
465 if(!Store("Calib","ChamberT0" ,(TObject *) objtime0det ,&md1,0,kTRUE)){
466 Log("Error storing the calibration object for the chamber t0 (DAQ)");
469 if(!Store("Calib","LocalVdrift" ,(TObject *) objdriftvelocitypad,&md2,0,kTRUE)){
470 Log("Error storing the calibration object for the local drift velocity (DAQ)");
473 if(!Store("Calib","LocalT0" ,(TObject *) objtime0pad ,&md2,0,kTRUE)){
474 Log("Error storing the calibration object for the local time0 (DAQ)");
479 Log("Not enough statistics for the average pulse height (DAQ)");
488 //______________________________________________________________________________________________
489 Bool_t AliTRDPreprocessor::ExtractHLT()
492 // Gain, vdrift and PRF calibration running on HLT
493 // return kTRUE if NULL pointer to the list
496 Bool_t error = kFALSE;
498 // Objects for HLT and DAQ zusammen
499 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
500 AliCDBMetaData metaData;
501 metaData.SetBeamPeriod(0);
502 metaData.SetResponsible("Raphaelle Bailhache");
503 metaData.SetComment("TRD calib test");
504 // Store the infos for the detector
506 md1.SetObjectClassName("AliTRDCalDet");
507 md1.SetResponsible("Raphaelle Bailhache");
508 md1.SetBeamPeriod(0);
509 md1.SetComment("TRD calib test");
510 // Store the infos for the pads
512 md2.SetObjectClassName("AliTRDCalPad");
513 md2.SetResponsible("Raphaelle Bailhache");
514 md2.SetBeamPeriod(0);
515 md2.SetComment("TRD calib test");
518 // Take the file from the HLT file exchange server
519 TList *listhlt = GetFileSources(kHLT,"GAINDRIFTPRF");
521 Log("No list found for the HLT");
525 if(listhlt->GetSize() != 1) {
526 Log(Form("Problem on the size of the list: %d (HLT)",listhlt->GetSize()));
531 TObjString* fileNameEntry = (TObjString*) listhlt->At(0);
532 if(fileNameEntry != NULL){
533 TString fileName = GetFile(kHLT, "GAINDRIFTPRF",
534 fileNameEntry->GetString().Data());
535 if(fileName.Length() ==0){
536 Log("Error retrieving the file (HLT)");
541 TFile *filehlt = TFile::Open(fileName);
545 TH2I *histogain = (TH2I *) filehlt->Get("CH2d");
546 histogain->SetDirectory(0);
548 // store the reference data
549 if(!StoreReferenceData("HLTData","Gain",(TObject *) histogain,&metaData)){
550 Log("Error storing 2D histos for gain");
554 Log("Take the CH reference data. Now we will try to fit\n");
555 calibra->SetMinEntries(1000); // If there is less than 1000 entries in the histo: no fit
556 calibra->AnalyseCH(histogain);
557 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(0))
558 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(0));
559 Int_t nbfit = calibra->GetNumberFit();
560 Int_t nbE = calibra->GetNumberEnt();
563 (nbfit >= 0.95*nbE)) {
564 // create the cal objects
565 TObjArray object = calibra->GetVectorFit();
566 AliTRDCalDet *objgaindet = calibra->CreateDetObjectGain(&object,calibra->GetScaleFitFactor(),kTRUE);
567 TObject *objgainpad = calibra->CreatePadObjectGain();
569 if(!Store("Calib","ChamberGainFactor",(TObject *) objgaindet ,&md1,0,kTRUE)){
570 Log("Error storing the calibration object for the chamber gain");
573 if(!Store("Calib","LocalGainFactor" ,(TObject *) objgainpad ,&md2,0,kTRUE)){
574 Log("Error storing the calibration object for the local gain factor");
578 calibra->ResetVectorFit();
585 TProfile2D *histodriftvelocity = (TProfile2D *) filehlt->Get("PH2d");
586 histodriftvelocity->SetDirectory(0);
587 if (histodriftvelocity) {
588 // store the reference data
589 if(!StoreReferenceData("HLTData","VdriftT0",(TObject *) histodriftvelocity,&metaData)){
590 Log("Error storing 2D Profile for average pulse height (HLT)");
594 Log("Take the PH reference data. Now we will try to fit\n");
595 calibra->SetMinEntries(1000*20); // If there is less than 20000
596 calibra->AnalysePH(histodriftvelocity);
597 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(1))
598 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(1));
599 Int_t nbfit = calibra->GetNumberFit();
600 Int_t nbE = calibra->GetNumberEnt();
603 (nbfit >= 0.95*nbE)) {
604 // create the cal objects
605 TObjArray object = calibra->GetVectorFit();
606 AliTRDCalDet *objdriftvelocitydet = calibra->CreateDetObjectVdrift(&object,kTRUE);
607 TObject *objdriftvelocitypad = calibra->CreatePadObjectVdrift();
608 object = calibra->GetVectorFit2();
609 AliTRDCalDet *objtime0det = calibra->CreateDetObjectT0(&object,kTRUE);
610 TObject *objtime0pad = calibra->CreatePadObjectT0();
612 if(!Store("Calib","ChamberVdrift" ,(TObject *) objdriftvelocitydet,&md1,0,kTRUE)){
613 Log("Error storing the calibration object for the chamber vdrift (HLT)");
616 if(!Store("Calib","ChamberT0" ,(TObject *) objtime0det ,&md1,0,kTRUE)){
617 Log("Error storing the calibration object for the chamber t0 (HLT)");
620 if(!Store("Calib","LocalVdrift" ,(TObject *) objdriftvelocitypad,&md2,0,kTRUE)){
621 Log("Error storing the calibration object for the local drift velocity (HLT)");
624 if(!Store("Calib","LocalT0" ,(TObject *) objtime0pad ,&md2,0,kTRUE)){
625 Log("Error storing the calibration object for the local time0 (HLT)");
630 calibra->ResetVectorFit();
635 TProfile2D *histoprf = (TProfile2D *) filehlt->Get("PRF2d");
636 histoprf->SetDirectory(0);
638 // store reference data
639 if(!StoreReferenceData("HLTData","PRF",(TObject *) histoprf,&metaData)){
640 Log("Error storing the 2D Profile for Pad Response Function");
644 Log("Take the PRF reference data. Now we will try to fit\n");
645 calibra->SetMinEntries(600); // If there is less than 20000
646 calibra->AnalysePRFMarianFit(histoprf);
647 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(2))
648 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(2));
649 Int_t nbfit = calibra->GetNumberFit();
650 Int_t nbE = calibra->GetNumberEnt();
653 (nbfit >= 0.95*nbE)) {
654 // create cal pad objects
655 TObjArray object = calibra->GetVectorFit();
656 TObject *objPRFpad = calibra->CreatePadObjectPRF(&object);
658 if(!Store("Calib","PRFWidth" ,(TObject *) objPRFpad ,&md2,0,kTRUE)){
659 Log("Error storing the calibration object for the Pad Response Function");
663 calibra->ResetVectorFit();