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);
287 calPed->AnalyseHisto();
289 // store as reference data
290 TString name("PadStatus");
291 name += (Int_t)index;
292 if(!StoreReferenceData("DAQData",(const char *)name,(TObject *) calPed,&metaData)){
293 Log(Form("Error storing AliTRDCalibPadStatus object %d as reference data",(Int_t)index));
298 // Add to the calPedSum
299 for (Int_t idet=0; idet<540; idet++) {
300 AliTRDCalROC *rocMean = calPed->GetCalRocMean(idet, kFALSE);
301 if ( rocMean ) calPedSum.SetCalRocMean(rocMean,idet);
302 AliTRDCalROC *rocRMS = calPed->GetCalRocRMS(idet, kFALSE);
303 if ( rocRMS ) calPedSum.SetCalRocRMS(rocRMS,idet);
309 Log(Form("%d elements found in the list for the pedestal",(Int_t)index));
315 // Store pedestal entry to OCDB
320 AliTRDCalPadStatus *calPadStatus = calPedSum.CreateCalPadStatus();
322 md3.SetObjectClassName("AliTRDCalPadStatus");
323 md3.SetResponsible("Raphaelle Bailhache");
324 md3.SetBeamPeriod(1);
325 md3.SetComment("TRD calib test");
326 if(!Store("Calib","PadStatus" ,(TObject *)calPadStatus, &md3, 0, kTRUE)){
327 Log("Error storing the pedestal");
336 //______________________________________________________________________________________________
337 Bool_t AliTRDPreprocessor::ExtractDriftVelocityDAQ()
340 // Drift velocity DA running on monitoring servers at the DAQ
343 Bool_t error = kFALSE;
345 // Objects for HLT and DAQ zusammen
346 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
347 AliCDBMetaData metaData;
348 metaData.SetBeamPeriod(0);
349 metaData.SetResponsible("Raphaelle Bailhache");
350 metaData.SetComment("TRD calib test");
351 // Store the infos for the detector
353 md1.SetObjectClassName("AliTRDCalDet");
354 md1.SetResponsible("Raphaelle Bailhache");
355 md1.SetBeamPeriod(0);
356 md1.SetComment("TRD calib test");
357 // Store the infos for the pads
359 md2.SetObjectClassName("AliTRDCalPad");
360 md2.SetResponsible("Raphaelle Bailhache");
361 md2.SetBeamPeriod(0);
362 md2.SetComment("TRD calib test");
367 // Take the file from the DAQ file exchange server
368 TList *listdaq = GetFileSources(kDAQ,"VDRIFT");
370 Log("No list found for vdrift (DAQ)");
374 if(listdaq->GetSize() !=1){
375 Log(Form("Problem on the size of the list: %d (DAQ)",listdaq->GetSize()));
380 TObjString* fileNameEntry = (TObjString*) listdaq->At(0);
381 if(fileNameEntry != NULL){
382 TString fileName = GetFile(kDAQ, "VDRIFT",
383 fileNameEntry->GetString().Data());
384 if(fileName.Length() ==0){
385 Log("Error retrieving the file vdrift (DAQ)");
389 TFile *filedaq = TFile::Open(fileName);
390 TProfile2D *histodriftvelocity = (TProfile2D *) filedaq->Get("PH2d");
391 if (histodriftvelocity) {
393 // store as reference data
394 if(!StoreReferenceData("DAQData","VdriftT0",(TObject *) histodriftvelocity,&metaData)){
395 Log("Error storing 2D Profile for vdrift from the DAQ");
401 Log("Take the PH reference data. Now we will try to fit\n");
402 calibra->SetMinEntries(2000); // If there is less than 2000
403 calibra->AnalysePH(histodriftvelocity);
405 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(1))
406 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(1));
407 Int_t nbfit = calibra->GetNumberFit();
408 Int_t nbE = calibra->GetNumberEnt();
410 // if enough statistics store the results
412 (nbfit >= 0.95*nbE)) {
413 // create the cal objects
414 TObjArray object = calibra->GetVectorFit();
415 AliTRDCalDet *objdriftvelocitydet = calibra->CreateDetObjectVdrift(&object,kTRUE);
416 TObject *objdriftvelocitypad = calibra->CreatePadObjectVdrift();
417 object = calibra->GetVectorFit2();
418 AliTRDCalDet *objtime0det = calibra->CreateDetObjectT0(&object,kTRUE);
419 TObject *objtime0pad = calibra->CreatePadObjectT0();
420 calibra->ResetVectorFit();
422 if(!Store("Calib","ChamberVdrift" ,(TObject *) objdriftvelocitydet,&md1,0,kTRUE)){
423 Log("Error storing the calibration object for the chamber vdrift (DAQ)");
426 if(!Store("Calib","ChamberT0" ,(TObject *) objtime0det ,&md1,0,kTRUE)){
427 Log("Error storing the calibration object for the chamber t0 (DAQ)");
430 if(!Store("Calib","LocalVdrift" ,(TObject *) objdriftvelocitypad,&md2,0,kTRUE)){
431 Log("Error storing the calibration object for the local drift velocity (DAQ)");
434 if(!Store("Calib","LocalT0" ,(TObject *) objtime0pad ,&md2,0,kTRUE)){
435 Log("Error storing the calibration object for the local time0 (DAQ)");
440 Log("Not enough statistics for the average pulse height (DAQ)");
449 //______________________________________________________________________________________________
450 Bool_t AliTRDPreprocessor::ExtractHLT()
453 // Gain, vdrift and PRF calibration running on HLT
454 // return kFALSE if NULL pointer to the list
457 Bool_t error = kFALSE;
459 // Objects for HLT and DAQ zusammen
460 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
461 AliCDBMetaData metaData;
462 metaData.SetBeamPeriod(0);
463 metaData.SetResponsible("Raphaelle Bailhache");
464 metaData.SetComment("TRD calib test");
465 // Store the infos for the detector
467 md1.SetObjectClassName("AliTRDCalDet");
468 md1.SetResponsible("Raphaelle Bailhache");
469 md1.SetBeamPeriod(0);
470 md1.SetComment("TRD calib test");
471 // Store the infos for the pads
473 md2.SetObjectClassName("AliTRDCalPad");
474 md2.SetResponsible("Raphaelle Bailhache");
475 md2.SetBeamPeriod(0);
476 md2.SetComment("TRD calib test");
479 // Take the file from the HLT file exchange server
480 TList *listhlt = GetFileSources(kHLT,"GAINDRIFTPRF");
482 Log("No list found for the HLT");
486 if(listhlt->GetSize() != 1) {
487 Log(Form("Problem on the size of the list: %d (HLT)",listhlt->GetSize()));
492 TObjString* fileNameEntry = (TObjString*) listhlt->At(0);
493 if(fileNameEntry != NULL){
494 TString fileName = GetFile(kHLT, "GAINDRIFTPRF",
495 fileNameEntry->GetString().Data());
496 if(fileName.Length() ==0){
497 Log("Error retrieving the file (HLT)");
502 TFile *filehlt = TFile::Open(fileName);
506 TH2I *histogain = (TH2I *) filehlt->Get("CH2d");
507 histogain->SetDirectory(0);
509 // store the reference data
510 if(!StoreReferenceData("HLTData","Gain",(TObject *) histogain,&metaData)){
511 Log("Error storing 2D histos for gain");
515 Log("Take the CH reference data. Now we will try to fit\n");
516 calibra->SetMinEntries(1000); // If there is less than 1000 entries in the histo: no fit
517 calibra->AnalyseCH(histogain);
518 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(0))
519 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(0));
520 Int_t nbfit = calibra->GetNumberFit();
521 Int_t nbE = calibra->GetNumberEnt();
524 (nbfit >= 0.95*nbE)) {
525 // create the cal objects
526 TObjArray object = calibra->GetVectorFit();
527 AliTRDCalDet *objgaindet = calibra->CreateDetObjectGain(&object,calibra->GetScaleFitFactor(),kTRUE);
528 TObject *objgainpad = calibra->CreatePadObjectGain();
530 if(!Store("Calib","ChamberGainFactor",(TObject *) objgaindet ,&md1,0,kTRUE)){
531 Log("Error storing the calibration object for the chamber gain");
534 if(!Store("Calib","LocalGainFactor" ,(TObject *) objgainpad ,&md2,0,kTRUE)){
535 Log("Error storing the calibration object for the local gain factor");
539 calibra->ResetVectorFit();
546 TProfile2D *histodriftvelocity = (TProfile2D *) filehlt->Get("PH2d");
547 histodriftvelocity->SetDirectory(0);
548 if (histodriftvelocity) {
549 // store the reference data
550 if(!StoreReferenceData("HLTData","VdriftT0",(TObject *) histodriftvelocity,&metaData)){
551 Log("Error storing 2D Profile for average pulse height (HLT)");
555 Log("Take the PH reference data. Now we will try to fit\n");
556 calibra->SetMinEntries(1000*20); // If there is less than 20000
557 calibra->AnalysePH(histodriftvelocity);
558 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(1))
559 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(1));
560 Int_t nbfit = calibra->GetNumberFit();
561 Int_t nbE = calibra->GetNumberEnt();
564 (nbfit >= 0.95*nbE)) {
565 // create the cal objects
566 TObjArray object = calibra->GetVectorFit();
567 AliTRDCalDet *objdriftvelocitydet = calibra->CreateDetObjectVdrift(&object,kTRUE);
568 TObject *objdriftvelocitypad = calibra->CreatePadObjectVdrift();
569 object = calibra->GetVectorFit2();
570 AliTRDCalDet *objtime0det = calibra->CreateDetObjectT0(&object,kTRUE);
571 TObject *objtime0pad = calibra->CreatePadObjectT0();
573 if(!Store("Calib","ChamberVdrift" ,(TObject *) objdriftvelocitydet,&md1,0,kTRUE)){
574 Log("Error storing the calibration object for the chamber vdrift (HLT)");
577 if(!Store("Calib","ChamberT0" ,(TObject *) objtime0det ,&md1,0,kTRUE)){
578 Log("Error storing the calibration object for the chamber t0 (HLT)");
581 if(!Store("Calib","LocalVdrift" ,(TObject *) objdriftvelocitypad,&md2,0,kTRUE)){
582 Log("Error storing the calibration object for the local drift velocity (HLT)");
585 if(!Store("Calib","LocalT0" ,(TObject *) objtime0pad ,&md2,0,kTRUE)){
586 Log("Error storing the calibration object for the local time0 (HLT)");
591 calibra->ResetVectorFit();
596 TProfile2D *histoprf = (TProfile2D *) filehlt->Get("PRF2d");
597 histoprf->SetDirectory(0);
599 // store reference data
600 if(!StoreReferenceData("HLTData","PRF",(TObject *) histoprf,&metaData)){
601 Log("Error storing the 2D Profile for Pad Response Function");
605 Log("Take the PRF reference data. Now we will try to fit\n");
606 calibra->SetMinEntries(600); // If there is less than 20000
607 calibra->AnalysePRFMarianFit(histoprf);
608 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(2))
609 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(2));
610 Int_t nbfit = calibra->GetNumberFit();
611 Int_t nbE = calibra->GetNumberEnt();
614 (nbfit >= 0.95*nbE)) {
615 // create cal pad objects
616 TObjArray object = calibra->GetVectorFit();
617 TObject *objPRFpad = calibra->CreatePadObjectPRF(&object);
619 if(!Store("Calib","PRFWidth" ,(TObject *) objPRFpad ,&md2,0,kTRUE)){
620 Log("Error storing the calibration object for the Pad Response Function");
624 calibra->ResetVectorFit();