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;
106 if(ProcessDCS(dcsAliasMap)) return 1;
109 // Process the calibration data for the HLT and DAQ part
112 if (runType=="PHYSICS"){
113 //TString runPar = GetRunParameter("HLTStatus")
115 if(ExtractHLT()) return 1;
116 //if (fResult > 0) return fResult;
119 if(ExtractDriftVelocityDAQ()) return 1;
127 //______________________________________________________________________________
128 Bool_t AliTRDPreprocessor::ProcessDCS(TMap * dcsAliasMap)
132 AliCDBMetaData metaData;
133 metaData.SetBeamPeriod(0);
134 metaData.SetResponsible("Wilfried Monange/Raphaelle Bailhache");
135 metaData.SetComment("TRD calib test");
138 Log ("****** DCS ******\n");
140 TObjArray * list=AliTRDSensorArray::GetList ();
143 Log ("Error during AliTRDSensorArray::GetList");
144 Log ("DCS will not be processing");
148 Int_t nEntries = list->GetEntries ();
149 Log (Form ("%d alias loaded", nEntries));
151 Bool_t * results=new Bool_t [nEntries];
152 Int_t * nGraph=new Int_t [nEntries];
154 for (Int_t iAlias = 0; iAlias < nEntries; iAlias++) {
156 AliTRDSensorArray * oneTRDDCS = (AliTRDSensorArray *)list->At (iAlias);
158 oneTRDDCS->SetStartTime (TTimeStamp (fStartTime));
159 oneTRDDCS->SetEndTime (TTimeStamp (fEndTime));
161 Log (Form("Processing DCS : \"%s\"", oneTRDDCS->GetStoreName ().Data ()));
165 map=oneTRDDCS->ExtractDCS (dcsAliasMap);
167 nGraph [iAlias] = map->GetEntries ();
169 if (nGraph [iAlias] == 0) {
170 Log("No TGraph for this dcsDatapointAlias : not stored");
171 results [iAlias] = kFALSE;
175 oneTRDDCS->SetGraph(map);
176 results[iAlias]=Store("Calib", oneTRDDCS->GetStoreName().Data(), oneTRDDCS, &metaData, 0, kTRUE);
179 //results [iAlias] = StoreReferenceData("Calib", oneTRDDCS->GetStoreName ().Data (), oneTRDDCS, &metaData);
182 if (!results[iAlias]) {
183 AliError("Problem during StoreRef DCS");
188 //BEGIN TEST (should not be removed ...)
190 oneTRDDCS->ClearGraph();
191 oneTRDDCS->ClearFit();
192 oneTRDDCS->SetDiffCut2 (0.1);
193 map=oneTRDDCS->ExtractDCS (dcsAliasMap);
194 oneTRDDCS->SetGraph (map);
195 Store("Calib", ("cut_"+oneTRDDCS->GetStoreName()).Data(), oneTRDDCS, &metaData, 0, kTRUE);
199 if(iAlias==1 || iAlias==19) continue;
201 oneTRDDCS->ClearGraph();
202 oneTRDDCS->ClearFit();
203 oneTRDDCS->SetDiffCut2(0);
204 map=oneTRDDCS->ExtractDCS(dcsAliasMap);
205 oneTRDDCS->MakeSplineFit(map);
206 Store("Calib", ("fit_"+oneTRDDCS->GetStoreName()).Data() , oneTRDDCS, &metaData, 0, kTRUE);
210 oneTRDDCS->ClearGraph();
211 oneTRDDCS->ClearFit();
212 oneTRDDCS->SetDiffCut2 (0.1);
213 map=oneTRDDCS->ExtractDCS (dcsAliasMap);
214 oneTRDDCS->MakeSplineFit(map);
215 Store("Calib", ("cutfit_"+oneTRDDCS->GetStoreName()).Data() , oneTRDDCS, &metaData, 0, kTRUE);
224 Log (" Summury of DCS :\n");
225 Log (Form("%30s %10s %10s", "dcsDatapointAlias", "Stored ?", "# graph"));
226 for (Int_t iAlias = 0; iAlias < nEntries; iAlias++) {
227 AliTRDSensorArray * oneTRDDCS = (AliTRDSensorArray *)list->At (iAlias);
228 Log (Form ("%30s %10s %4d",
229 oneTRDDCS->GetStoreName ().Data (),
230 results[iAlias] ? "ok" : "X",
233 Log ("*********** End of DCS **********");
241 //______________________________________________________________________________________________
242 Bool_t AliTRDPreprocessor::ExtractPedestals()
245 // Pedestal running on LDCs at the DAQ
248 Bool_t error = kFALSE;
250 // Init a AliTRDCalibPadStatus
251 AliTRDCalibPadStatus calPedSum = AliTRDCalibPadStatus();
253 AliCDBMetaData metaData;
254 metaData.SetBeamPeriod(0);
255 metaData.SetResponsible("Raphaelle Bailhache");
256 metaData.SetComment("TRD calib test");
258 // Sum the contributions of the LDCs
259 TList * listpad = GetFileSources(kDAQ,"PADSTATUS");
261 Log("No list found for the PEDESTRAL Run");
265 // loop through all files from LDCs
268 while (listpad->At(index)!=NULL) {
269 TObjString* fileNameEntry = (TObjString*) listpad->At(index);
270 if (fileNameEntry != NULL)
272 TString fileName = GetFile(kDAQ, "PADSTATUS",
273 fileNameEntry->GetString().Data());
274 if(fileName.Length() ==0){
275 Log(Form("Error by retrieving the file %d for the pedestal",(Int_t)index));
280 TFile *f = TFile::Open(fileName);
281 AliTRDCalibPadStatus *calPed;
282 f->GetObject("calibpadstatus",calPed);
289 //calPed->AnalyseHisto();
291 // Add to the calPedSum
292 for (Int_t idet=0; idet<540; idet++) {
293 AliTRDCalROC *rocMean = calPed->GetCalRocMean(idet, kFALSE);
295 calPedSum.SetCalRocMean(rocMean,idet);
296 sm = (Int_t) (idet / 30);
298 AliTRDCalROC *rocRMS = calPed->GetCalRocRMS(idet, kFALSE);
300 calPedSum.SetCalRocRMS(rocRMS,idet);
304 // store as reference data
305 TString name("PadStatus");
307 if(!StoreReferenceData("DAQData",(const char *)name,(TObject *) calPed,&metaData)){
308 Log(Form("Error storing AliTRDCalibPadStatus object %d as reference data",(Int_t)index));
316 Log(Form("%d elements found in the list for the pedestal",(Int_t)index));
322 // Store pedestal entry to OCDB
327 AliTRDCalPadStatus *calPadStatus = calPedSum.CreateCalPadStatus();
329 md3.SetObjectClassName("AliTRDCalPadStatus");
330 md3.SetResponsible("Raphaelle Bailhache");
331 md3.SetBeamPeriod(1);
332 md3.SetComment("TRD calib test");
333 if(!Store("Calib","PadStatus" ,(TObject *)calPadStatus, &md3, 0, kTRUE)){
334 Log("Error storing the pedestal");
340 //Make the AliTRDCalPad
341 AliTRDCalPad *calPad2 = calPedSum.CreateCalPad();
343 md4.SetObjectClassName("AliTRDCalPad");
344 md4.SetResponsible("Raphaelle Bailhache");
345 md4.SetBeamPeriod(1);
346 md4.SetComment("TRD calib test");
347 if(!Store("Calib","PadNoise" ,(TObject *)calPad2, &md4, 0, kTRUE)){
348 Log("Error storing the pedestal");
352 //Make the AliTRDCalDet correspondant
353 AliTRDCalDet *calDet = calPedSum.CreateCalDet();
355 md5.SetObjectClassName("AliTRDCalDet");
356 md5.SetResponsible("Raphaelle Bailhache");
357 md5.SetBeamPeriod(1);
358 md5.SetComment("TRD calib test");
359 if(!Store("Calib","DetNoise" ,(TObject *)calDet, &md5, 0, kTRUE)){
360 Log("Error storing the pedestal");
369 //______________________________________________________________________________________________
370 Bool_t AliTRDPreprocessor::ExtractDriftVelocityDAQ()
373 // Drift velocity DA running on monitoring servers at the DAQ
376 Bool_t error = kFALSE;
378 // Objects for HLT and DAQ zusammen
379 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
380 AliCDBMetaData metaData;
381 metaData.SetBeamPeriod(0);
382 metaData.SetResponsible("Raphaelle Bailhache");
383 metaData.SetComment("TRD calib test");
384 // Store the infos for the detector
386 md1.SetObjectClassName("AliTRDCalDet");
387 md1.SetResponsible("Raphaelle Bailhache");
388 md1.SetBeamPeriod(0);
389 md1.SetComment("TRD calib test");
390 // Store the infos for the pads
392 md2.SetObjectClassName("AliTRDCalPad");
393 md2.SetResponsible("Raphaelle Bailhache");
394 md2.SetBeamPeriod(0);
395 md2.SetComment("TRD calib test");
400 // Take the file from the DAQ file exchange server
401 TList *listdaq = GetFileSources(kDAQ,"VDRIFT");
403 Log("No list found for vdrift (DAQ)");
407 if(listdaq->GetSize() !=1){
408 Log(Form("Problem on the size of the list: %d (DAQ)",listdaq->GetSize()));
413 TObjString* fileNameEntry = (TObjString*) listdaq->At(0);
414 if(fileNameEntry != NULL){
415 TString fileName = GetFile(kDAQ, "VDRIFT",
416 fileNameEntry->GetString().Data());
417 if(fileName.Length() ==0){
418 Log("Error retrieving the file vdrift (DAQ)");
422 TFile *filedaq = TFile::Open(fileName);
423 TProfile2D *histodriftvelocity = (TProfile2D *) filedaq->Get("PH2d");
424 if (histodriftvelocity) {
426 // store as reference data
427 if(!StoreReferenceData("DAQData","VdriftT0",(TObject *) histodriftvelocity,&metaData)){
428 Log("Error storing 2D Profile for vdrift from the DAQ");
434 Log("Take the PH reference data. Now we will try to fit\n");
435 calibra->SetMinEntries(2000); // If there is less than 2000
436 calibra->AnalysePH(histodriftvelocity);
438 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(1))
439 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(1));
440 Int_t nbfit = calibra->GetNumberFit();
441 Int_t nbE = calibra->GetNumberEnt();
443 // if enough statistics store the results
445 (nbfit >= 0.95*nbE)) {
446 // create the cal objects
447 TObjArray object = calibra->GetVectorFit();
448 AliTRDCalDet *objdriftvelocitydet = calibra->CreateDetObjectVdrift(&object,kTRUE);
449 TObject *objdriftvelocitypad = calibra->CreatePadObjectVdrift();
450 object = calibra->GetVectorFit2();
451 AliTRDCalDet *objtime0det = calibra->CreateDetObjectT0(&object,kTRUE);
452 TObject *objtime0pad = calibra->CreatePadObjectT0();
453 calibra->ResetVectorFit();
455 if(!Store("Calib","ChamberVdrift" ,(TObject *) objdriftvelocitydet,&md1,0,kTRUE)){
456 Log("Error storing the calibration object for the chamber vdrift (DAQ)");
459 if(!Store("Calib","ChamberT0" ,(TObject *) objtime0det ,&md1,0,kTRUE)){
460 Log("Error storing the calibration object for the chamber t0 (DAQ)");
463 if(!Store("Calib","LocalVdrift" ,(TObject *) objdriftvelocitypad,&md2,0,kTRUE)){
464 Log("Error storing the calibration object for the local drift velocity (DAQ)");
467 if(!Store("Calib","LocalT0" ,(TObject *) objtime0pad ,&md2,0,kTRUE)){
468 Log("Error storing the calibration object for the local time0 (DAQ)");
473 Log("Not enough statistics for the average pulse height (DAQ)");
482 //______________________________________________________________________________________________
483 Bool_t AliTRDPreprocessor::ExtractHLT()
486 // Gain, vdrift and PRF calibration running on HLT
487 // return kFALSE if NULL pointer to the list
490 Bool_t error = kFALSE;
492 // Objects for HLT and DAQ zusammen
493 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
494 AliCDBMetaData metaData;
495 metaData.SetBeamPeriod(0);
496 metaData.SetResponsible("Raphaelle Bailhache");
497 metaData.SetComment("TRD calib test");
498 // Store the infos for the detector
500 md1.SetObjectClassName("AliTRDCalDet");
501 md1.SetResponsible("Raphaelle Bailhache");
502 md1.SetBeamPeriod(0);
503 md1.SetComment("TRD calib test");
504 // Store the infos for the pads
506 md2.SetObjectClassName("AliTRDCalPad");
507 md2.SetResponsible("Raphaelle Bailhache");
508 md2.SetBeamPeriod(0);
509 md2.SetComment("TRD calib test");
512 // Take the file from the HLT file exchange server
513 TList *listhlt = GetFileSources(kHLT,"GAINDRIFTPRF");
515 Log("No list found for the HLT");
519 if(listhlt->GetSize() != 1) {
520 Log(Form("Problem on the size of the list: %d (HLT)",listhlt->GetSize()));
525 TObjString* fileNameEntry = (TObjString*) listhlt->At(0);
526 if(fileNameEntry != NULL){
527 TString fileName = GetFile(kHLT, "GAINDRIFTPRF",
528 fileNameEntry->GetString().Data());
529 if(fileName.Length() ==0){
530 Log("Error retrieving the file (HLT)");
535 TFile *filehlt = TFile::Open(fileName);
539 TH2I *histogain = (TH2I *) filehlt->Get("CH2d");
540 histogain->SetDirectory(0);
542 // store the reference data
543 if(!StoreReferenceData("HLTData","Gain",(TObject *) histogain,&metaData)){
544 Log("Error storing 2D histos for gain");
548 Log("Take the CH reference data. Now we will try to fit\n");
549 calibra->SetMinEntries(1000); // If there is less than 1000 entries in the histo: no fit
550 calibra->AnalyseCH(histogain);
551 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(0))
552 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(0));
553 Int_t nbfit = calibra->GetNumberFit();
554 Int_t nbE = calibra->GetNumberEnt();
557 (nbfit >= 0.95*nbE)) {
558 // create the cal objects
559 TObjArray object = calibra->GetVectorFit();
560 AliTRDCalDet *objgaindet = calibra->CreateDetObjectGain(&object,calibra->GetScaleFitFactor(),kTRUE);
561 TObject *objgainpad = calibra->CreatePadObjectGain();
563 if(!Store("Calib","ChamberGainFactor",(TObject *) objgaindet ,&md1,0,kTRUE)){
564 Log("Error storing the calibration object for the chamber gain");
567 if(!Store("Calib","LocalGainFactor" ,(TObject *) objgainpad ,&md2,0,kTRUE)){
568 Log("Error storing the calibration object for the local gain factor");
572 calibra->ResetVectorFit();
579 TProfile2D *histodriftvelocity = (TProfile2D *) filehlt->Get("PH2d");
580 histodriftvelocity->SetDirectory(0);
581 if (histodriftvelocity) {
582 // store the reference data
583 if(!StoreReferenceData("HLTData","VdriftT0",(TObject *) histodriftvelocity,&metaData)){
584 Log("Error storing 2D Profile for average pulse height (HLT)");
588 Log("Take the PH reference data. Now we will try to fit\n");
589 calibra->SetMinEntries(1000*20); // If there is less than 20000
590 calibra->AnalysePH(histodriftvelocity);
591 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(1))
592 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(1));
593 Int_t nbfit = calibra->GetNumberFit();
594 Int_t nbE = calibra->GetNumberEnt();
597 (nbfit >= 0.95*nbE)) {
598 // create the cal objects
599 TObjArray object = calibra->GetVectorFit();
600 AliTRDCalDet *objdriftvelocitydet = calibra->CreateDetObjectVdrift(&object,kTRUE);
601 TObject *objdriftvelocitypad = calibra->CreatePadObjectVdrift();
602 object = calibra->GetVectorFit2();
603 AliTRDCalDet *objtime0det = calibra->CreateDetObjectT0(&object,kTRUE);
604 TObject *objtime0pad = calibra->CreatePadObjectT0();
606 if(!Store("Calib","ChamberVdrift" ,(TObject *) objdriftvelocitydet,&md1,0,kTRUE)){
607 Log("Error storing the calibration object for the chamber vdrift (HLT)");
610 if(!Store("Calib","ChamberT0" ,(TObject *) objtime0det ,&md1,0,kTRUE)){
611 Log("Error storing the calibration object for the chamber t0 (HLT)");
614 if(!Store("Calib","LocalVdrift" ,(TObject *) objdriftvelocitypad,&md2,0,kTRUE)){
615 Log("Error storing the calibration object for the local drift velocity (HLT)");
618 if(!Store("Calib","LocalT0" ,(TObject *) objtime0pad ,&md2,0,kTRUE)){
619 Log("Error storing the calibration object for the local time0 (HLT)");
624 calibra->ResetVectorFit();
629 TProfile2D *histoprf = (TProfile2D *) filehlt->Get("PRF2d");
630 histoprf->SetDirectory(0);
632 // store reference data
633 if(!StoreReferenceData("HLTData","PRF",(TObject *) histoprf,&metaData)){
634 Log("Error storing the 2D Profile for Pad Response Function");
638 Log("Take the PRF reference data. Now we will try to fit\n");
639 calibra->SetMinEntries(600); // If there is less than 20000
640 calibra->AnalysePRFMarianFit(histoprf);
641 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(2))
642 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(2));
643 Int_t nbfit = calibra->GetNumberFit();
644 Int_t nbE = calibra->GetNumberEnt();
647 (nbfit >= 0.95*nbE)) {
648 // create cal pad objects
649 TObjArray object = calibra->GetVectorFit();
650 TObject *objPRFpad = calibra->CreatePadObjectPRF(&object);
652 if(!Store("Calib","PRFWidth" ,(TObject *) objPRFpad ,&md2,0,kTRUE)){
653 Log("Error storing the calibration object for the Pad Response Function");
657 calibra->ResetVectorFit();