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;
182 oneTRDDCS->SetGraph(map);
183 results[iAlias]=Store("Calib", oneTRDDCS->GetStoreName().Data(), oneTRDDCS, &metaData, 0, kTRUE);
186 //results [iAlias] = StoreReferenceData("Calib", oneTRDDCS->GetStoreName ().Data (), oneTRDDCS, &metaData);
189 if (!results[iAlias]) {
190 AliError("Problem during StoreRef DCS");
195 //BEGIN TEST (should not be removed ...)
197 oneTRDDCS->ClearGraph();
198 oneTRDDCS->ClearFit();
199 oneTRDDCS->SetDiffCut2 (0.1);
200 map=oneTRDDCS->ExtractDCS (dcsAliasMap);
201 oneTRDDCS->SetGraph (map);
202 Store("Calib", ("cut_"+oneTRDDCS->GetStoreName()).Data(), oneTRDDCS, &metaData, 0, kTRUE);
206 if(iAlias==1 || iAlias==19) continue;
208 oneTRDDCS->ClearGraph();
209 oneTRDDCS->ClearFit();
210 oneTRDDCS->SetDiffCut2(0);
211 map=oneTRDDCS->ExtractDCS(dcsAliasMap);
212 oneTRDDCS->MakeSplineFit(map);
213 Store("Calib", ("fit_"+oneTRDDCS->GetStoreName()).Data() , oneTRDDCS, &metaData, 0, kTRUE);
217 oneTRDDCS->ClearGraph();
218 oneTRDDCS->ClearFit();
219 oneTRDDCS->SetDiffCut2 (0.1);
220 map=oneTRDDCS->ExtractDCS (dcsAliasMap);
221 oneTRDDCS->MakeSplineFit(map);
222 Store("Calib", ("cutfit_"+oneTRDDCS->GetStoreName()).Data() , oneTRDDCS, &metaData, 0, kTRUE);
231 Log (" Summury of DCS :\n");
232 Log (Form("%30s %10s %10s", "dcsDatapointAlias", "Stored ?", "# graph"));
233 for (Int_t iAlias = 0; iAlias < nEntries; iAlias++) {
234 AliTRDSensorArray * oneTRDDCS = (AliTRDSensorArray *)list->At (iAlias);
235 Log (Form ("%30s %10s %4d",
236 oneTRDDCS->GetStoreName ().Data (),
237 results[iAlias] ? "ok" : "X",
240 Log ("*********** End of DCS **********");
248 //______________________________________________________________________________________________
249 Bool_t AliTRDPreprocessor::ExtractPedestals()
252 // Pedestal running on LDCs at the DAQ
255 Bool_t error = kFALSE;
257 // Init a AliTRDCalibPadStatus
258 AliTRDCalibPadStatus calPedSum = AliTRDCalibPadStatus();
260 AliCDBMetaData metaData;
261 metaData.SetBeamPeriod(0);
262 metaData.SetResponsible("Raphaelle Bailhache");
263 metaData.SetComment("TRD calib test");
265 // Sum the contributions of the LDCs
266 TList * listpad = GetFileSources(kDAQ,"PADSTATUS");
268 Log("No list found for the PEDESTRAL Run");
272 // loop through all files from LDCs
275 while (listpad->At(index)!=NULL) {
276 TObjString* fileNameEntry = (TObjString*) listpad->At(index);
277 if (fileNameEntry != NULL)
279 TString fileName = GetFile(kDAQ, "PADSTATUS",
280 fileNameEntry->GetString().Data());
281 if(fileName.Length() ==0){
282 Log(Form("Error by retrieving the file %d for the pedestal",(Int_t)index));
287 TFile *f = TFile::Open(fileName);
288 AliTRDCalibPadStatus *calPed;
289 f->GetObject("calibpadstatus",calPed);
296 //calPed->AnalyseHisto();
298 // Add to the calPedSum
299 for (Int_t idet=0; idet<540; idet++) {
300 AliTRDCalROC *rocMean = calPed->GetCalRocMean(idet, kFALSE);
302 calPedSum.SetCalRocMean(rocMean,idet);
303 sm = (Int_t) (idet / 30);
305 AliTRDCalROC *rocRMS = calPed->GetCalRocRMS(idet, kFALSE);
307 calPedSum.SetCalRocRMS(rocRMS,idet);
309 AliTRDCalROC *rocMeand = calPed->GetCalRocMeand(idet, kFALSE);
311 calPedSum.SetCalRocMeand(rocMeand,idet);
313 AliTRDCalROC *rocRMSd = calPed->GetCalRocRMSd(idet, kFALSE);
315 calPedSum.SetCalRocRMSd(rocRMSd,idet);
319 // store as reference data
320 TString name("PadStatus");
322 if(!StoreReferenceData("DAQData",(const char *)name,(TObject *) calPed,&metaData)){
323 Log(Form("Error storing AliTRDCalibPadStatus object %d as reference data",(Int_t)index));
331 Log(Form("%d elements found in the list for the pedestal",(Int_t)index));
337 // Store pedestal entry to OCDB
342 AliTRDCalPadStatus *calPadStatus = calPedSum.CreateCalPadStatus();
344 md3.SetObjectClassName("AliTRDCalPadStatus");
345 md3.SetResponsible("Raphaelle Bailhache");
346 md3.SetBeamPeriod(1);
347 md3.SetComment("TRD calib test");
348 if(!Store("Calib","PadStatus" ,(TObject *)calPadStatus, &md3, 0, kTRUE)){
349 Log("Error storing the pedestal");
355 //Make the AliTRDCalPad
356 AliTRDCalPad *calPad2 = calPedSum.CreateCalPad();
358 md4.SetObjectClassName("AliTRDCalPad");
359 md4.SetResponsible("Raphaelle Bailhache");
360 md4.SetBeamPeriod(1);
361 md4.SetComment("TRD calib test");
362 if(!Store("Calib","PadNoise" ,(TObject *)calPad2, &md4, 0, kTRUE)){
363 Log("Error storing the pedestal");
367 //Make the AliTRDCalDet correspondant
368 AliTRDCalDet *calDet = calPedSum.CreateCalDet();
370 md5.SetObjectClassName("AliTRDCalDet");
371 md5.SetResponsible("Raphaelle Bailhache");
372 md5.SetBeamPeriod(1);
373 md5.SetComment("TRD calib test");
374 if(!Store("Calib","DetNoise" ,(TObject *)calDet, &md5, 0, kTRUE)){
375 Log("Error storing the pedestal");
384 //______________________________________________________________________________________________
385 Bool_t AliTRDPreprocessor::ExtractDriftVelocityDAQ()
388 // Drift velocity DA running on monitoring servers at the DAQ
391 Bool_t error = kFALSE;
393 // Objects for HLT and DAQ zusammen
394 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
395 AliCDBMetaData metaData;
396 metaData.SetBeamPeriod(0);
397 metaData.SetResponsible("Raphaelle Bailhache");
398 metaData.SetComment("TRD calib test");
399 // Store the infos for the detector
401 md1.SetObjectClassName("AliTRDCalDet");
402 md1.SetResponsible("Raphaelle Bailhache");
403 md1.SetBeamPeriod(0);
404 md1.SetComment("TRD calib test");
405 // Store the infos for the pads
407 md2.SetObjectClassName("AliTRDCalPad");
408 md2.SetResponsible("Raphaelle Bailhache");
409 md2.SetBeamPeriod(0);
410 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)");
497 //______________________________________________________________________________________________
498 Bool_t AliTRDPreprocessor::ExtractHLT()
501 // Gain, vdrift and PRF calibration running on HLT
502 // return kTRUE if NULL pointer to the list
505 Bool_t error = kFALSE;
507 // Objects for HLT and DAQ zusammen
508 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
509 AliCDBMetaData metaData;
510 metaData.SetBeamPeriod(0);
511 metaData.SetResponsible("Raphaelle Bailhache");
512 metaData.SetComment("TRD calib test");
513 // Store the infos for the detector
515 md1.SetObjectClassName("AliTRDCalDet");
516 md1.SetResponsible("Raphaelle Bailhache");
517 md1.SetBeamPeriod(0);
518 md1.SetComment("TRD calib test");
519 // Store the infos for the pads
521 md2.SetObjectClassName("AliTRDCalPad");
522 md2.SetResponsible("Raphaelle Bailhache");
523 md2.SetBeamPeriod(0);
524 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);
554 TH2I *histogain = (TH2I *) filehlt->Get("CH2d");
555 histogain->SetDirectory(0);
557 // store the reference data
558 if(!StoreReferenceData("HLTData","Gain",(TObject *) histogain,&metaData)){
559 Log("Error storing 2D histos for gain");
563 Log("Take the CH reference data. Now we will try to fit\n");
564 calibra->SetMinEntries(1000); // If there is less than 1000 entries in the histo: no fit
565 calibra->AnalyseCH(histogain);
566 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(0))
567 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(0));
568 Int_t nbfit = calibra->GetNumberFit();
569 Int_t nbE = calibra->GetNumberEnt();
572 (nbfit >= 0.95*nbE)) {
573 // create the cal objects
574 TObjArray object = calibra->GetVectorFit();
575 AliTRDCalDet *objgaindet = calibra->CreateDetObjectGain(&object,calibra->GetScaleFitFactor(),kTRUE);
576 TObject *objgainpad = calibra->CreatePadObjectGain();
578 if(!Store("Calib","ChamberGainFactor",(TObject *) objgaindet ,&md1,0,kTRUE)){
579 Log("Error storing the calibration object for the chamber gain");
582 if(!Store("Calib","LocalGainFactor" ,(TObject *) objgainpad ,&md2,0,kTRUE)){
583 Log("Error storing the calibration object for the local gain factor");
587 calibra->ResetVectorFit();
594 TProfile2D *histodriftvelocity = (TProfile2D *) filehlt->Get("PH2d");
595 histodriftvelocity->SetDirectory(0);
596 if (histodriftvelocity) {
597 // store the reference data
598 if(!StoreReferenceData("HLTData","VdriftT0",(TObject *) histodriftvelocity,&metaData)){
599 Log("Error storing 2D Profile for average pulse height (HLT)");
603 Log("Take the PH reference data. Now we will try to fit\n");
604 calibra->SetMinEntries(1000*20); // If there is less than 20000
605 calibra->AnalysePH(histodriftvelocity);
606 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(1))
607 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(1));
608 Int_t nbfit = calibra->GetNumberFit();
609 Int_t nbE = calibra->GetNumberEnt();
612 (nbfit >= 0.95*nbE)) {
613 // create the cal objects
614 TObjArray object = calibra->GetVectorFit();
615 AliTRDCalDet *objdriftvelocitydet = calibra->CreateDetObjectVdrift(&object,kTRUE);
616 TObject *objdriftvelocitypad = calibra->CreatePadObjectVdrift();
617 object = calibra->GetVectorFit2();
618 AliTRDCalDet *objtime0det = calibra->CreateDetObjectT0(&object,kTRUE);
619 TObject *objtime0pad = calibra->CreatePadObjectT0();
621 if(!Store("Calib","ChamberVdrift" ,(TObject *) objdriftvelocitydet,&md1,0,kTRUE)){
622 Log("Error storing the calibration object for the chamber vdrift (HLT)");
625 if(!Store("Calib","ChamberT0" ,(TObject *) objtime0det ,&md1,0,kTRUE)){
626 Log("Error storing the calibration object for the chamber t0 (HLT)");
629 if(!Store("Calib","LocalVdrift" ,(TObject *) objdriftvelocitypad,&md2,0,kTRUE)){
630 Log("Error storing the calibration object for the local drift velocity (HLT)");
633 if(!Store("Calib","LocalT0" ,(TObject *) objtime0pad ,&md2,0,kTRUE)){
634 Log("Error storing the calibration object for the local time0 (HLT)");
639 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();