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 **************************************************************************/
19 //#include <Riostream.h>
28 #include <TObjArray.h>
29 #include <TObjString.h>
30 #include <TTimeStamp.h>
32 #include "AliCDBMetaData.h"
33 #include "AliCDBEntry.h"
35 #include "AliTOFChannelOnlineArray.h"
36 #include "AliTOFChannelOnlineStatusArray.h"
37 #include "AliTOFDataDCS.h"
38 #include "AliTOFDCSmaps.h"
39 #include "AliTOFLvHvDataPoints.h"
40 #include "AliTOFGeometry.h"
41 #include "AliTOFPreprocessor.h"
42 #include "AliTOFFEEReader.h"
43 #include "AliTOFRawStream.h"
44 #include "AliTOFCableLengthMap.h"
45 #include "AliTOFcalibHisto.h"
46 #include "AliTOFFEEDump.h"
48 #include "AliTOFDeltaBCOffset.h"
49 #include "AliTOFCTPLatency.h"
50 #include "AliTOFRunParams.h"
51 #include "AliTOFT0FillOnlineCalib.h"
52 #include "AliTOFHitField.h"
53 #include "AliTOFChannelOffline.h"
55 #include "TGeoManager.h"
56 #include "AliGeomManager.h"
57 #include "AliTOFReadoutInfo.h"
59 // TOF preprocessor class.
60 // It takes data from DCS and passes them to the class AliTOFDataDCS, which
61 // processes them. The result is then written to the CDB.
62 // Analogously, it takes data form DAQ (both at Run level and inclusive -
63 // of all the runs - level, processes them, and stores both Reference Data
64 // and Online Calibration files in the CDB.
65 // Processing of Pulser/Noise Run data and of TOF FEE DCS map included also.
69 // return=1 : no DCS input data Map
70 // return=2 : no DCS input data processing
71 // return=3 : no DCS processed data was stored in Ref Data
72 // return=4 : no DAQ input for Ref Data
73 // return=5 : failed to store DAQ Ref Data
74 // return=6 : failed to retrieve DAQ data for calibration
75 // return=7 : problems in processing histos in the input DAQ file
76 // return=8 : failed to store Online Delays
77 // return=9 : failed to store Reference Data for Pulser
78 // return=10: failed to retrieve Pulser data
79 // return=11: failed to store Pulser map in OCDB
80 // return=12: failed to store Reference Data for Noise
81 // return=13: failed to retrieve Noise data
82 // return=14: failed to store Noise map in OCDB
83 // return=15: failed to retrieve FEE data from FXS
84 // return=16: failed to retrieve FEE data from OCDB
85 // return=17: failed to store FEE data in OCDB
86 // return=18: failed to store FEE reference data in OCDB
87 // return=20: failed in retrieving status variable
88 // return=100 : no DCS input data Map (HV and LV status)
89 // return=200 : no DCS input data processing (HV and LV status)
90 // return=300 : no DCS processed data was stored in Ref Data (HV and LV status)
92 ClassImp(AliTOFPreprocessor)
94 const Int_t AliTOFPreprocessor::fgkBinRangeAve = 13; // number of bins where to calculate the mean
95 const Double_t AliTOFPreprocessor::fgkIntegralThr = 100; // min number of entries to perform computation of delay per channel
96 const Double_t AliTOFPreprocessor::fgkThrPar = 0.013; // parameter used to trigger the calculation of the delay
98 //_____________________________________________________________________________
100 AliTOFPreprocessor::AliTOFPreprocessor(AliShuttleInterface* shuttle) :
101 AliPreprocessor("TOF", shuttle),
106 fStoreRefData(kTRUE),
111 fIsStatusMapChanged(0)
114 AddRunType("PHYSICS");
115 AddRunType("PULSER");
120 //_____________________________________________________________________________
122 AliTOFPreprocessor::~AliTOFPreprocessor()
127 //______________________________________________________________________________
128 void AliTOFPreprocessor::Initialize(Int_t run, UInt_t startTime,
131 // Creates AliTOFDataDCS object
133 AliPreprocessor::Initialize(run, startTime, endTime);
135 AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s \n\tStartTime DCS Query %s \n\tEndTime DCS Query %s", run,
136 TTimeStamp(startTime).AsString(),
137 TTimeStamp(endTime).AsString(), ((TTimeStamp)GetStartTimeDCSQuery()).AsString(), ((TTimeStamp)GetEndTimeDCSQuery()).AsString()));
139 fData = new AliTOFDataDCS(fRun, fStartTime, fEndTime, GetStartTimeDCSQuery(), GetEndTimeDCSQuery());
140 fHVLVmaps = new AliTOFLvHvDataPoints(fRun, fStartTime, fEndTime, GetStartTimeDCSQuery(), GetEndTimeDCSQuery());
141 fNChannels = AliTOFGeometry::NSectors()*(2*(AliTOFGeometry::NStripC()+AliTOFGeometry::NStripB())+AliTOFGeometry::NStripA())*AliTOFGeometry::NpadZ()*AliTOFGeometry::NpadX();
143 //_____________________________________________________________________________
144 Bool_t AliTOFPreprocessor::ProcessDCS(){
146 // check whether DCS should be processed or not...
148 TString runType = GetRunType();
149 Log(Form("RunType %s",runType.Data()));
151 if (runType != "PHYSICS"){
157 //_____________________________________________________________________________
159 UInt_t AliTOFPreprocessor::ProcessDCSDataPoints(TMap *dcsAliasMap)
161 // Fills data into a AliTOFDataDCS object
164 Log("Processing DCS DP");
165 TH1::AddDirectory(0);
167 Bool_t resultDCSMap=kFALSE;
168 Bool_t resultDCSStore=kFALSE;
173 Log("No DCS map found: TOF exiting from Shuttle");
178 return 1;// return error Code for DCS input data not found
183 Log("No DCSdata map initialized: TOF exiting from Shuttle");
184 return 0;// return error Code for DCS data map not initialized
187 fData->SetFDRFlag(fFDRFlag);
189 // The processing of the DCS input data is forwarded to AliTOFDataDCS
190 resultDCSMap=fData->ProcessData(*dcsAliasMap);
192 Log("Some problems occurred while processing DCS data, TOF exiting from Shuttle");
197 return 2;// return error Code for processed DCS data not stored
200 AliCDBMetaData metaDataDCS;
201 metaDataDCS.SetBeamPeriod(0);
202 metaDataDCS.SetResponsible("Chiara Zampolli");
203 metaDataDCS.SetComment("This preprocessor fills an AliTOFDataDCS object.");
204 AliInfo("Storing DCS Data");
205 resultDCSStore = StoreReferenceData("Calib","DCSData",fData, &metaDataDCS);
206 if (!resultDCSStore){
207 Log("Some problems occurred while storing DCS data results in Reference Data, TOF exiting from Shuttle");
212 return 3;// return error Code for processed DCS data not stored
225 //_____________________________________________________________________________
227 UInt_t AliTOFPreprocessor::ProcessHVandLVdps(TMap *dcsAliasMap)
230 //Fills data into a AliTOFLvHvDataPoints object
231 // Merges fStatus object with LV and HV status at SOR
232 // Updates fStatus object with LV and HV status
233 // at EOR in case of correct end of run
234 // at last but two value in case of end-of-run caused by TOF detector.
237 Log("Processing HV and LV DCS DPs");
238 TH1::AddDirectory(0);
240 Bool_t resultDCSMap=kFALSE;
242 // processing DCS HV and LV data points
245 Log("No DCS map found: TOF exiting from Shuttle");
250 return 100;// return error Code for DCS input data not found
255 Log("No HVLVdata map initialized: TOF exiting from Shuttle");
256 return 200;// return error Code for HVLV data map not initialized
259 fHVLVmaps->SetFDRFlag(fFDRFlag);
261 // The processing of the DCS input data is forwarded to AliTOFDataDCS
263 resultDCSMap = fHVLVmaps->ProcessData(*dcsAliasMap);
265 Log("Some problems occurred while processing DCS data, TOF exiting from Shuttle");
270 return 200;// return error Code for processed DCS data not stored
274 // check with plots. Start...
276 TH1F *hROsor = new TH1F("hROsor","RO status map at SOR",91*96*18,-0.5,91*96*18-0.5);
277 for (Int_t ii=1; ii<=91*96*18; ii++) hROsor->SetBinContent(ii,-1);
278 for (Int_t ii=0; ii<91*96*18; ii++) {
279 if (fStatus->GetHWStatus(ii)==AliTOFChannelOnlineStatusArray::kTOFHWBad)
280 hROsor->SetBinContent(ii+1,0);
281 else if (fStatus->GetHWStatus(ii)==AliTOFChannelOnlineStatusArray::kTOFHWOk)
282 hROsor->SetBinContent(ii+1,1);
285 TH1F *hROandHVandLVsor = new TH1F("hROandHVandLVsor","RO.and.HV.andLV status map at SOR",91*96*18,-0.5,91*96*18-0.5);
286 for (Int_t ii=1; ii<=91*96*18; ii++) hROandHVandLVsor->SetBinContent(ii,-1);
287 TH1F *hROandHVandLVeor = new TH1F("hROandHVandLVeor","RO.and.HV.andLV status map at EOR",91*96*18,-0.5,91*96*18-0.5);
288 for (Int_t ii=1; ii<=91*96*18; ii++) hROandHVandLVeor->SetBinContent(ii,-1);
291 AliTOFDCSmaps * lvANDhvMap = (AliTOFDCSmaps*)fHVLVmaps->GetHVandLVmapAtSOR(); // Get LV.and.HV status map at SOR
292 for (Int_t index=0; index<fNChannels; index++) {
293 if ( ( lvANDhvMap->GetCellValue(index)==0 &&
294 fStatus->GetHWStatus(index) != AliTOFChannelOnlineStatusArray::kTOFHWBad ) ||
295 ( lvANDhvMap->GetCellValue(index)==1 &&
296 fStatus->GetHWStatus(index) != AliTOFChannelOnlineStatusArray::kTOFHWOk ) ) {
297 fStatus->SetHWStatus(index, AliTOFChannelOnlineStatusArray::kTOFHWBad);
298 fIsStatusMapChanged=kTRUE;
302 // check with plots. Start...
304 for (Int_t ii=0; ii<91*96*18; ii++) {
305 if (fStatus->GetHWStatus(ii)==AliTOFChannelOnlineStatusArray::kTOFHWBad)
306 hROandHVandLVsor->SetBinContent(ii+1,0);
307 else if (fStatus->GetHWStatus(ii)==AliTOFChannelOnlineStatusArray::kTOFHWOk)
308 hROandHVandLVsor->SetBinContent(ii+1,1);
312 lvANDhvMap = (AliTOFDCSmaps*)fHVLVmaps->GetHVandLVmapAtEOR(); // Get LV.and.HV status map at EOR
313 for (Int_t index=0; index<fNChannels; index++) {
314 if ( ( lvANDhvMap->GetCellValue(index)==0 &&
315 fStatus->GetHWStatus(index)!=AliTOFChannelOnlineStatusArray::kTOFHWBad ) ||
316 ( lvANDhvMap->GetCellValue(index)==1 &&
317 fStatus->GetHWStatus(index) != AliTOFChannelOnlineStatusArray::kTOFHWOk ) ) {
318 fStatus->SetHWStatus(index, AliTOFChannelOnlineStatusArray::kTOFHWBad);
319 fIsStatusMapChanged=kTRUE;
323 // check with plots. Start...
325 for (Int_t ii=0; ii<91*96*18; ii++) {
326 if (fStatus->GetHWStatus(ii)==AliTOFChannelOnlineStatusArray::kTOFHWBad)
327 hROandHVandLVeor->SetBinContent(ii+1,0);
328 else if (fStatus->GetHWStatus(ii)==AliTOFChannelOnlineStatusArray::kTOFHWOk)
329 hROandHVandLVeor->SetBinContent(ii+1,1);
332 TCanvas *canvas = new TCanvas("canvas","",10,10,1000,1000);
333 canvas->SetFillColor(0);
336 hROsor->SetLineWidth(2);
339 hROandHVandLVsor->SetLineWidth(2);
340 hROandHVandLVsor->Draw();
342 hROandHVandLVeor->SetLineWidth(2);
343 hROandHVandLVeor->Draw();
352 /* check whether we don't need to update OCDB.
353 * in this case we can return without errors. */
355 if (!fIsStatusMapChanged) {
356 AliInfo("TOF HW status config has not changed. Do not overwrite stored file.");
357 return 0; // return ok
360 TString runType = GetRunType();
361 if (runType != "PHYSICS") {
362 AliInfo(Form("Run Type = %s, waiting to store status map",GetRunType()));
363 return 0; // return ok
366 // update the OCDB with the current FEE.and.HV.and.LV
367 // since even a little difference has been detected.
369 AliCDBMetaData metaData;
370 metaData.SetBeamPeriod(0);
371 metaData.SetResponsible("Roberto Preghenella");
372 metaData.SetComment("This preprocessor fills an AliTOFChannelOnlineStatusArray object from FEE.and.HV.and.LV data.");
373 AliInfo("Storing Status data from current run. Collected RO.and.HV.and.LV infos @ EOR");
374 // store TOF channel status
375 if (!Store("Calib", "Status", fStatus, &metaData, 0, kTRUE)) {
377 Log("problems while storing RO.and.HV.and.LV Status data object");
386 return 17; // return error code for problems while TOF channel status
389 // everything fine. return
404 //_____________________________________________________________________________
406 UInt_t AliTOFPreprocessor::ProcessOnlineDelays()
408 // Processing data from DAQ for online calibration
410 Bool_t updateOCDB = kFALSE;
411 Log("Processing DAQ delays");
413 // reading configuration map
414 TString compDelays = "kFALSE";
415 Int_t deltaStartingRun = fRun;
416 Int_t startingRun = fRun-deltaStartingRun;
417 Int_t binRangeAve = fgkBinRangeAve;
418 Double_t integralThr = fgkIntegralThr;
419 Double_t thrPar = fgkThrPar;
421 AliCDBEntry *cdbEntry = GetFromOCDB("Calib","Config");
423 Log(Form("No Configuration entry found in CDB, using default values: ComputingDelays = %s, StartingRun = %i",compDelays.Data(), startingRun));
426 TMap *configMap = (TMap*)cdbEntry->GetObject();
428 Log(Form("No map found in Config entry in CDB, using default values: ComputingDelays = %s, StartingRun = %i",compDelays.Data(), startingRun));
431 TObjString *strDelays = (TObjString*)configMap->GetValue("ComputingDelays");
433 compDelays = (TString) strDelays->GetString();
436 Log(Form("No ComputingDelays value found in Map from Config entry in CDB, using default value: ComputingDelays = %s",compDelays.Data()));
438 TObjString *strRun = (TObjString*)configMap->GetValue("StartingRun");
440 TString tmpstr = strRun->GetString();
441 startingRun = tmpstr.Atoi();
442 deltaStartingRun = fRun - startingRun;
445 Log(Form("No StartingRun value found in Map from Config entry in CDB, using default value: StartingRun = %i",startingRun));
447 TObjString *strBinRangeAve = (TObjString*)configMap->GetValue("BinRangeAve");
448 if (strBinRangeAve) {
449 TString tmpstr = strBinRangeAve->GetString();
450 binRangeAve = tmpstr.Atoi();
453 Log(Form("No BinRangeAve value found in Map from Config entry in CDB, using default value: BinRangeAve = %i",binRangeAve));
455 TObjString *strIntegralThr = (TObjString*)configMap->GetValue("IntegralThr");
456 if (strIntegralThr) {
457 TString tmpstr = strIntegralThr->GetString();
458 integralThr = tmpstr.Atof();
461 Log(Form("No IntegralThr value found in Map from Config entry in CDB, using default value: IntegralThr = %f",integralThr));
463 TObjString *strThrPar = (TObjString*)configMap->GetValue("ThrPar");
465 TString tmpstr = strThrPar->GetString();
466 thrPar = tmpstr.Atof();
469 Log(Form("No ThrPar value found in Map from Config entry in CDB, using default value: ThrPar = %f",thrPar));
473 if (compDelays == "kTRUE") fFDRFlag = kFALSE;
474 else fFDRFlag = kTRUE;
479 Log(Form("ComputingDelays = %s, StartingRun = %i",compDelays.Data(),startingRun));
481 /* init array with current calibration, if any */
482 fCal = new AliTOFChannelOnlineArray(fNChannels);
483 AliTOFChannelOnlineArray *curCal = NULL;
485 AliCDBEntry *cdbEntry2 = GetFromOCDB("Calib","ParOnlineDelay");
486 if (!cdbEntry2 || !cdbEntry2->GetObject()) {
487 /* no CDB entry found. set update flag */
488 Log(" ************ WARNING ************");
489 Log("No CDB ParOnlineDelay entry found, creating a new one!");
490 Log(" *********************************");
494 Log("Found previous ParOnlineDelay entry. Using it to init calibration");
495 curCal = (AliTOFChannelOnlineArray *)cdbEntry2->GetObject();
496 for (Int_t i = 0; i < fNChannels; i++)
497 fCal->SetDelay(i, curCal->GetDelay(i));
501 TH1::AddDirectory(0);
503 Bool_t resultDAQRef=kFALSE;
504 Bool_t resultTOFPP=kFALSE;
511 //retrieving data at Run level
512 TList* list = GetFileSources(kDAQ, "RUNLevel");
513 if (list !=0x0 && list->GetEntries()!=0)
515 AliInfo("The following sources produced files with the id RUNLevel");
517 for (Int_t jj=0;jj<list->GetEntries();jj++){
518 TObjString * str = dynamic_cast<TObjString*> (list->At(jj));
520 AliError("dynamic_cast returned NULL");
523 AliInfo(Form("found source %s", str->String().Data()));
524 // file to be stored run per run
525 TString fileNameRun = GetFile(kDAQ, "RUNLevel", str->GetName());
526 if (fileNameRun.Length()>0){
527 AliInfo(Form("Got the file %s, now we can store the Reference Data for the current Run.", fileNameRun.Data()));
528 daqFile = new TFile(fileNameRun.Data(),"READ");
529 h2 = (TH2S*) daqFile->Get("htof");
530 AliCDBMetaData metaDataHisto;
531 metaDataHisto.SetBeamPeriod(0);
532 metaDataHisto.SetResponsible("Chiara Zampolli");
533 metaDataHisto.SetComment("This preprocessor stores the array of histos object as Reference Data.");
534 AliInfo("Storing Reference Data");
535 resultDAQRef = StoreReferenceData("Calib","DAQData",h2, &metaDataHisto);
537 Log("some problems occurred::No Reference Data stored, TOF exiting from Shuttle");
542 return 5;//return error code for failure in storing Ref Data
549 Log("The input data file from DAQ (run-level) was not found, TOF exiting from Shuttle ");
553 return 4;//return error code for failure in retrieving Ref Data
559 Log("The input data file list from DAQ (run-level) was not found, TOF exiting from Shuttle ");
562 return 4;//return error code for failure in retrieving Ref Data
567 //Total files, with cumulative histos
569 TList* listTot = GetFileSources(kDAQ, "DELAYS");
570 if (listTot !=0x0 && listTot->GetEntries()!=0)
572 AliInfo("The following sources produced files with the id DELAYS");
574 for (Int_t jj=0;jj<listTot->GetEntries();jj++){
575 TObjString * str = dynamic_cast<TObjString*> (listTot->At(jj));
577 AliError("dynamic_cast returned NULL");
580 AliInfo(Form("found source %s", str->String().Data()));
582 // file with summed histos, to extract calib params
583 TString fileName = GetFile(kDAQ, "DELAYS", str->GetName());
584 if (fileName.Length()>0){
585 AliInfo(Form("Got the file %s, now we can extract some values.", fileName.Data()));
587 daqFile = new TFile(fileName.Data(),"READ");
589 h2 = (TH2S*) daqFile->Get("htoftot");
591 Log("some problems occurred:: No histo retrieved, TOF exiting from Shuttle");
596 return 7; //return error code for histograms not existing/junky
599 static const Int_t kSize=h2->GetNbinsX();
600 static const Int_t kNBins=h2->GetNbinsY();
601 static const Double_t kXBinmin=h2->GetYaxis()->GetBinLowEdge(1);
602 if (kSize != fNChannels){
603 Log(" number of bins along x different from number of pads, found only a subset of the histograms, TOF exiting from Shuttle");
609 return 7; //return error code for histograms not existing/junky
611 Int_t nNotStatistics = 0; // number of channel with not enough statistics
613 /* FDR flag set. do not compute delays, use nominal cable delays */
616 Log(" Not computing delays according to flag set in Config entry in OCDB!");
617 FillWithCosmicCalibration(fCal);
619 /* check whether the new calibration is different from the previous one */
620 if (curCal) { /* well, check also whether we have a previous calibration */
621 for (Int_t i = 0; i < fNChannels; i++) {
622 if (fCal->GetDelay(i) != curCal->GetDelay(i)) {
628 else /* otherwise update OCDB */
633 else { // computing delays if not in FDR runs
635 updateOCDB = kTRUE; /* always update OCDB when computing delays */
637 for (Int_t ich=0;ich<kSize;ich++){
638 /* check whether channel has been read out during current run.
639 * if the status is bad it means it has not been read out.
640 * in this case skip channel in order to not affect the mean */
641 if (fStatus->GetHWStatus(ich) == AliTOFChannelOnlineStatusArray::kTOFHWBad){
642 AliDebug(2,Form(" Channel %i found bad according to FEEmap, (HW status = %i), skipping from delay computing",ich, (Int_t)fStatus->GetHWStatus(ich)));
645 AliDebug(2,Form(" Channel %i found ok according to FEEmap, starting delay computing",ich));
646 TH1S *h1 = new TH1S("h1","h1",kNBins,kXBinmin-0.5,kNBins*1.+kXBinmin-0.5);
647 for (Int_t ibin=0;ibin<kNBins;ibin++){
648 h1->SetBinContent(ibin+1,h2->GetBinContent(ich+1,ibin+1));
650 if(h1->Integral()<integralThr) {
652 Log(Form(" Not enough statistics for bin %i, skipping this channel",ich)); // printing message only if not in FDR runs
658 Float_t minContent=h1->Integral()*thrPar;
659 Int_t nbinsX = h1->GetNbinsX();
661 for (Int_t j=1; j<=nbinsX; j++){
663 h1->GetBinContent(j) +
664 h1->GetBinContent(j+1)+
665 h1->GetBinContent(j+2)+
666 h1->GetBinContent(j+3))>minContent){
672 if(!found) AliInfo(Form("WARNING!!! no start of fit found for histo # %i",ich));
673 // Now calculate the mean over the interval.
677 for(Int_t k=0;k<binRangeAve;k++){
678 mean=mean+h1->GetBinCenter(startBin+k)*h1->GetBinContent(startBin+k);
679 nent=nent+h1->GetBinContent(startBin+k);
680 sumw2=sumw2+(h1->GetBinCenter(startBin+k))*(h1->GetBinCenter(startBin+k))*(h1->GetBinContent(startBin+k));
682 mean= mean/nent; //<x>
683 sumw2=sumw2/nent; //<x^2>
685 rmsmean = TMath::Sqrt((sumw2-mean*mean)/nent);
686 if (ich<fNChannels) {
687 Float_t delay = mean*AliTOFGeometry::TdcBinWidth()*1.E-3; // delay in ns
688 fCal->SetDelay(ich,delay); // delay in ns
689 AliDebug(2,Form("Setting delay %f (ns) for channel %i",delay,ich));
695 if (nNotStatistics!=0) Log(Form("Too little statistics for %d channels!",nNotStatistics));
702 Log("The Cumulative data file from DAQ does not exist, TOF exiting from Shuttle");
706 return 6;//return error code for problems in retrieving DAQ data
712 Log("Problem: no list for Cumulative data file from DAQ was found, TOF exiting from Shuttle");
715 return 6; //return error code for problems in retrieving DAQ data
718 /* check whether we don't need to update OCDB.
719 * in this case we can return without errors and
720 * the current FEE is stored in the fStatus object. */
722 AliInfo("update OCDB flag not set. Do not overwrite stored file.");
723 return 0; /* return ok */
727 AliCDBMetaData metaData;
728 metaData.SetBeamPeriod(0);
729 metaData.SetResponsible("Chiara Zampolli");
730 metaData.SetComment("This preprocessor fills an AliTOFChannelOnlineArray object for online calibration - delays.");
731 AliInfo("Storing Calibration Data");
732 resultTOFPP = Store("Calib","ParOnlineDelay",fCal, &metaData,deltaStartingRun,kTRUE);
734 Log("Some problems occurred while storing online object resulting from DAQ data processing");
737 return 8;//return error code for problems in storing DAQ data
748 //_____________________________________________________________________________
751 AliTOFPreprocessor::ProcessT0Fill()
753 // Processing data from DAQ for T0-fill measurement
755 Log("Processing T0-fill");
758 /* instance and setup CDB manager */
759 AliCDBManager *cdb = AliCDBManager::Instance();
761 if (!gGeoManager) AliGeomManager::LoadGeometry();
764 /* get params from OCDB */
765 AliCDBEntry *cdbe = NULL;
768 * check UseLHCClockPhase flag in RunParams.
769 * if set do nothing and return successfully
771 cdbe = GetFromOCDB("Calib", "RunParams");
773 Log("cannot get \"RunParams\" entry from OCDB");
776 AliTOFRunParams *runparams = (AliTOFRunParams *)cdbe->GetObject();
777 if (runparams->GetUseLHCClockPhase()) {
778 Log("UseLHCClockPhase flag is set in RunParams: online T0-fill not computed");
783 * at this stage status object is not on OCDB yet
784 * since it will be stored later. nevertheless we
785 * should have the array in memory since it has been
786 * already setup by ProcessFEF.
789 /* check status and latency window available */
790 if (!fStatus || !fLatencyWindow){
791 AliError("No valid fStatus or fLatencyWindow found, some errors must have occurred!!");
795 /* get offline calibration from OCDB */
796 cdbe = GetFromOCDB("Calib", "ParOffline");
798 Log("cannot get \"ParOffline\" entry from OCDB");
801 TObjArray *offlineArray = (TObjArray *)cdbe->GetObject();
802 AliTOFChannelOffline *channelOffline;
804 Log("cannot get \"ParOffline\" object from CDB entry");
807 Log("got \"ParOffline\" object");
809 /* get deltaBC offset from OCDB */
810 cdbe = GetFromOCDB("Calib", "DeltaBCOffset");
812 Log("cannot get \"DeltaBCOffset\" entry from OCDB");
815 AliTOFDeltaBCOffset *deltaBCOffsetObject = (AliTOFDeltaBCOffset *)cdbe->GetObject();
816 if (!deltaBCOffsetObject) {
817 Log("cannot get \"DeltaBCOffset\" object from CDB entry");
820 Int_t deltaBCOffset = deltaBCOffsetObject->GetDeltaBCOffset();
821 Log(Form("got \"DeltaBCOffset\" object: deltaBCOffset=%d (BC bins)", deltaBCOffset));
823 /* get CTP latency from OCDB */
824 cdbe = GetFromOCDB("Calib", "CTPLatency");
826 Log("cannot get \"CTPLatency\" entry from OCDB");
829 AliTOFCTPLatency *ctpLatencyObject = (AliTOFCTPLatency *)cdbe->GetObject();
830 if (!ctpLatencyObject) {
831 Log("cannot get \"CTPLatency\" object from CDB entry");
834 Float_t ctpLatency = ctpLatencyObject->GetCTPLatency();
835 Log(Form("got \"CTPLatency\" object: ctpLatency=%f (ps)", ctpLatency));
837 /* get file sources from FXS */
838 TList *fileList = GetFileSources(kDAQ, "HITS");
839 if (!fileList || fileList->GetEntries() == 0) {
840 Log("cannot get DAQ source file list or empty list");
843 Log(Form("got DAQ source file list: %d files", fileList->GetEntries()));
846 /* create tree chain using file sources */
847 TChain chain("hitTree");
848 for (Int_t ifile = 0; ifile < fileList->GetEntries(); ifile++) {
849 TObjString *str = (TObjString *)fileList->At(ifile);
850 TString filename = GetFile(kDAQ, "HITS", str->GetName());
852 Log(Form("file added to input chain: source=%s, filename=%s", str->String().Data(), filename.Data()));
854 Int_t nhits = chain.GetEntries();
855 Log(Form("input chain ready: %d hits", nhits));
857 /* setup input chain */
858 AliTOFHitField *hit = new AliTOFHitField();
859 chain.SetBranchAddress("hit", &hit);
861 /* create calib histo and geometry */
862 AliTOFcalibHisto calibHisto;
863 calibHisto.LoadCalibHisto();
864 AliTOFGeometry tofGeo;
867 Float_t c = TMath::C() * 1.e2 / 1.e12; /* cm/ps */
868 Float_t c_1 = 1. / c;
870 Int_t index, timebin, totbin, deltaBC, l0l1latency, det[5];
871 Float_t timeps, totns, corrps, length, timeexp, timezero, pos[3], latencyWindow;
874 TH1F *hT0Fill = new TH1F("hT0Fill", "T0 fill;t - t_{exp}^{(c)} (ps);", 2000, -24400., 24400.);
877 for (Int_t ihit = 0; ihit < nhits; ihit++) {
880 chain.GetEntry(ihit);
883 index = hit->GetIndex();
884 timebin = hit->GetTimeBin();
885 totbin = hit->GetTOTBin();
886 deltaBC = hit->GetDeltaBC();
887 l0l1latency = hit->GetL0L1Latency();
888 latencyWindow = fLatencyWindow[index] * 1.e3;
890 /* convert time in ps and tot in ns */
891 timeps = timebin * AliTOFGeometry::TdcBinWidth();
892 totns = totbin * AliTOFGeometry::ToTBinWidth() * 1.e-3;
893 /* get calibration correction in ps */
896 channelOffline = (AliTOFChannelOffline *)offlineArray->At(index);
897 if (totns < AliTOFGeometry::SlewTOTMin()) totns = AliTOFGeometry::SlewTOTMin();
898 if (totns > AliTOFGeometry::SlewTOTMax()) totns = AliTOFGeometry::SlewTOTMax();
900 for (Int_t ipar = 0; ipar < 6; ipar++) corrps += channelOffline->GetSlewPar(ipar) * TMath::Power(totns, ipar);
902 /* perform time correction */
903 // timeps = timeps + (deltaBC - deltaBCOffset) * AliTOFGeometry::BunchCrossingBinWidth() + l0l1latency * AliTOFGeometry::BunchCrossingBinWidth() + ctpLatency - latencyWindow - corrps; /* deltaBC correction removed for the time being */
904 timeps = timeps + l0l1latency * AliTOFGeometry::BunchCrossingBinWidth() + ctpLatency - latencyWindow - corrps;
905 /* compute length and expected time */
906 tofGeo.GetVolumeIndices(index, det);
907 tofGeo.GetPosPar(det, pos);
909 for (Int_t i = 0; i < 3; i++) length += pos[i] * pos[i];
910 length = TMath::Sqrt(length);
911 timeexp = length * c_1;
912 /* compute time zero */
913 timezero = timeps - timeexp;
916 hT0Fill->Fill(timezero);
919 /* rebin until maximum bin has required minimum entries */
920 Int_t maxBin = hT0Fill->GetMaximumBin();
921 Float_t maxBinContent = hT0Fill->GetBinContent(maxBin);
922 Float_t binWidth = hT0Fill->GetBinWidth(maxBin);
923 while (maxBinContent < 400 && binWidth < 90.) {
925 maxBin = hT0Fill->GetMaximumBin();
926 maxBinContent = hT0Fill->GetBinContent(maxBin);
927 binWidth = hT0Fill->GetBinWidth(maxBin);
929 Float_t maxBinCenter = hT0Fill->GetBinCenter(maxBin);
931 /* rough fit of the edge */
932 TF1 *gaus = (TF1 *)gROOT->GetFunction("gaus");
933 gaus->SetParameter(1, maxBinCenter);
934 Float_t fitMin = maxBinCenter - 1000.; /* fit from 1 ns before max */
935 Float_t fitMax = maxBinCenter + 1000.; /* fit until 1 ns above max */
936 hT0Fill->Fit("gaus", "q0", "", fitMin, fitMax);
937 /* better fit of the edge */
939 for (Int_t istep = 0; istep < 10; istep++) {
940 mean = gaus->GetParameter(1);
941 sigma = gaus->GetParameter(2);
942 fitMin = mean - 3. * sigma;
944 hT0Fill->Fit("gaus", "q0", "", fitMin, fitMax);
947 mean = gaus->GetParameter(1);
948 sigma = gaus->GetParameter(2);
949 Float_t meane = gaus->GetParError(1);
950 Float_t sigmae = gaus->GetParError(2);
951 Log(Form("edge fit: mean = %f +- %f ps", mean, meane));
952 Log(Form("edge fit: sigma = %f +- %f ps", sigma, sigmae));
955 Log("error on mean is large: store default T0-fill value (0 ps)");
959 Log("error on sigma is large: store default TOFreso value (200 ps)");
963 /* scratch values from the fit and use max bin center as t0-fill */
966 Log(Form("do not care about fitted value, just use max bin as t0-fill: %f ps", mean));
968 /* create RunParams object */
969 UInt_t timestamp[1] = {0};
970 Float_t t0[1] = {mean};
971 Float_t tofReso[1] = {sigma};
972 Float_t t0Spread[1] = {-1.};
973 AliTOFRunParams *runParamsObject = new AliTOFRunParams(1);
974 runParamsObject->SetTimestamp(timestamp);
975 runParamsObject->SetT0(t0);
976 runParamsObject->SetTOFResolution(tofReso);
977 runParamsObject->SetT0Spread(t0Spread);
978 runParamsObject->SetUseLHCClockPhase(kFALSE);
980 /* store reference data */
982 AliCDBMetaData metaDataHisto;
983 metaDataHisto.SetBeamPeriod(0);
984 metaDataHisto.SetResponsible("Roberto Preghenella");
985 metaDataHisto.SetComment("online T0-fill histogram");
986 if (!StoreReferenceData("Calib","T0Fill", hT0Fill, &metaDataHisto)) {
987 Log("error while storing reference data");
990 delete runParamsObject;
993 Log("reference data successfully stored");
996 AliCDBMetaData metaData;
997 metaData.SetBeamPeriod(0);
998 metaData.SetResponsible("Roberto Preghenella");
999 metaData.SetComment("online RunParams measurement");
1000 if (!Store("Calib", "RunParams", runParamsObject, &metaData, 0, kFALSE)) {
1001 Log("error while storing RunParams object");
1004 delete runParamsObject;
1007 Log("RunParams object successfully stored");
1011 delete runParamsObject;
1016 //_____________________________________________________________________________
1019 AliTOFPreprocessor::ProcessNoiseCalibTrg()
1021 // Processing data from DAQ using calibration triggers for noise measurement
1023 Log("Processing Noise (calibration trigger)");
1025 /* check status and matching window available */
1026 if (!fStatus || !fMatchingWindow){
1027 AliError("No valid fStatus or fMatchingWindow found, some errors must have occurred!!");
1031 Float_t noiseThr = 1000.; // setting default threshold for noise to 1000 Hz
1032 // reading config map
1033 AliCDBEntry *cdbEntry = GetFromOCDB("Calib","ConfigNoise");
1034 if (!cdbEntry) Log(Form("No Configuration entry found in CDB, using default values: NoiseThr = %f",noiseThr));
1036 TMap *configMap = (TMap*)cdbEntry->GetObject();
1037 if (!configMap) Log(Form("No map found in Config entry in CDB, using default values: NoiseThr = %f", noiseThr));
1039 TObjString *strNoiseThr = (TObjString*)configMap->GetValue("NoiseThr");
1041 TString tmpstr = strNoiseThr->GetString();
1042 noiseThr = tmpstr.Atoi();
1044 else Log(Form("No NoiseThr value found in Map from ConfigNoise entry in CDB, using default value: NoiseThr = %f",noiseThr));
1048 /* get file sources from FXS */
1049 TList *fileList = GetFileSources(kDAQ, "CALIB");
1050 if (!fileList || fileList->GetEntries() == 0) {
1051 Log("cannot get DAQ source file list or empty list");
1054 Log(Form("got DAQ source file list: %d files", fileList->GetEntries()));
1057 /* open input file (only one expected) */
1058 TObjString *str = (TObjString *)fileList->At(0);
1059 TString filename = GetFile(kDAQ, "CALIB", str->GetName());
1060 Log(Form("opening input file: source=%s, filename=%s", str->String().Data(), filename.Data()));
1061 TFile *filein = TFile::Open(filename.Data());
1062 if (!filein || !filein->IsOpen()) {
1063 Log("cannot open input file");
1067 /* get histo from input file */
1068 TH1F *hCalibHit = (TH1F *)filein->Get("hCalibHit");
1070 Log("cannot get \"hCalibHit\" histo");
1074 /* create and set noise rate histo and check rate */
1075 TH1F *hNoiseRate = new TH1F("hNoiseRate", ";index;rate (Hz)", fNChannels, 0., fNChannels);
1076 Float_t rate, rate_err;
1077 for (Int_t ich = 0; ich < fNChannels; ich++) {
1078 /* check channel enabled */
1079 if (fStatus->GetHWStatus(ich) == AliTOFChannelOnlineStatusArray::kTOFHWBad) continue;
1080 /* set noise rate histo */
1081 rate = hCalibHit->GetBinContent(ich + 1);
1082 rate_err = hCalibHit->GetBinError(ich + 1);
1083 rate /= fMatchingWindow[ich] * 1.e-9;
1084 rate_err /= fMatchingWindow[ich] * 1.e-9;
1085 hNoiseRate->SetBinContent(ich + 1, rate);
1086 hNoiseRate->SetBinError(ich + 1, rate_err);
1088 if (rate_err == 0.) continue;
1089 /* check noise rate and set noise flags */
1090 if ((rate - 3. * rate_err) > noiseThr) {
1091 Log(Form("channel %d detected as noisy: rate = (%f +- %f) Hz", ich, rate, rate_err));
1092 if (fStatus->GetNoiseStatus(ich) == AliTOFChannelOnlineStatusArray::kTOFNoiseOk) {
1093 Log(Form("channel %d noise status changed from Ok to Bad", ich));
1094 fStatus->SetNoiseStatus(ich, AliTOFChannelOnlineStatusArray::kTOFNoiseBad);
1095 fIsStatusMapChanged = kTRUE;
1097 else Log(Form("channel %d noise status unchanged", ich));
1099 else if ((rate + 3. * rate_err) < noiseThr) {
1100 if (fStatus->GetNoiseStatus(ich) == AliTOFChannelOnlineStatusArray::kTOFNoiseBad) {
1101 Log(Form("channel %d noise status changed from Bad to Ok", ich));
1102 fStatus->SetNoiseStatus(ich, AliTOFChannelOnlineStatusArray::kTOFNoiseOk);
1103 fIsStatusMapChanged = kTRUE;
1108 /* store reference data */
1110 AliCDBMetaData metaDataHisto;
1111 metaDataHisto.SetBeamPeriod(0);
1112 metaDataHisto.SetResponsible("Roberto Preghenella");
1113 metaDataHisto.SetComment("calibration trigger noise rate histogram");
1114 if (!StoreReferenceData("Calib","CalibNoise", hNoiseRate, &metaDataHisto)) {
1115 Log("error while storing reference data");
1120 Log("reference data successfully stored");
1128 //_____________________________________________________________________________
1131 AliTOFPreprocessor::ProcessReadout()
1133 // Processing data from DAQ to compute reaodut efficiency
1135 Log("Processing Readout");
1137 /* get file sources from FXS */
1138 TList *fileList = GetFileSources(kDAQ, "READOUT");
1139 if (!fileList || fileList->GetEntries() == 0) {
1140 Log("cannot get DAQ source file list or empty list");
1143 Log(Form("got DAQ source file list: %d files", fileList->GetEntries()));
1146 /* open input file (only one expected) */
1147 TObjString *str = (TObjString *)fileList->At(0);
1148 TString filename = GetFile(kDAQ, "READOUT", str->GetName());
1149 Log(Form("opening input file: source=%s, filename=%s", str->String().Data(), filename.Data()));
1150 TFile *filein = TFile::Open(filename.Data());
1151 if (!filein || !filein->IsOpen()) {
1152 Log("cannot open input file");
1156 /* get histo from input file */
1157 TH1F *hChainEfficiency = (TH1F *)filein->Get("hChainEfficiency");
1158 if (!hChainEfficiency) {
1159 Log("cannot get \"hChainEfficiency\" histo");
1163 /* fill channel efficiency histo */
1165 /* temporarly disable warnings */
1166 AliLog::EType_t logLevel = (AliLog::EType_t)AliLog::GetGlobalLogLevel();
1167 AliLog::SetGlobalLogLevel(AliLog::kError);
1169 TH1F *hChannelEfficiency = new TH1F("hChannelEfficiency", "Channel readout efficiency;index;efficiency", fNChannels, 0., fNChannels);
1170 Int_t chainIndex, det[5], dummy, index;
1171 Float_t effi, effi_err;
1172 /* loop over DDLs */
1173 for (Int_t iddl = 0; iddl < 72; iddl++) {
1174 /* loop over TRMs */
1175 for (Int_t itrm = 0; itrm < 10; itrm++) {
1176 /* loop over chains */
1177 for (Int_t ichain = 0; ichain < 2; ichain++) {
1178 chainIndex = ichain + 2 * itrm + 20 * iddl;
1179 effi = hChainEfficiency->GetBinContent(chainIndex + 1);
1180 effi_err = hChainEfficiency->GetBinError(chainIndex + 1);
1181 /* loop over TDCs */
1182 for (Int_t itdc = 0; itdc < 15; itdc++) {
1183 /* loop over channels */
1184 for (Int_t ichannel = 0; ichannel < 8; ichannel++) {
1186 /* get channel index */
1187 AliTOFRawStream::EquipmentId2VolumeId(iddl, itrm + 3, ichain, itdc, ichannel, det);
1191 /* check valid index */
1192 if (det[0] < 0 || det[0] > 17 ||
1193 det[1] < 0 || det[1] > 5 ||
1194 det[2] < 0 || det[2] > 18 ||
1195 det[3] < 0 || det[3] > 1 ||
1196 det[4] < 0 || det[4] > 47) continue;
1197 index = AliTOFGeometry::GetIndex(det);
1199 /* set channel efficiency */
1200 hChannelEfficiency->SetBinContent(index + 1, effi);
1201 hChannelEfficiency->SetBinError(index + 1, effi_err);
1209 /* re-enable warnings */
1210 AliLog::SetGlobalLogLevel(logLevel);
1212 /* store reference data */
1214 /* setup TOF readout info object */
1215 AliTOFReadoutInfo readoutInfo;
1216 readoutInfo.SetChainEfficiency((TH1F *)filein->Get("hChainEfficiency"));
1217 readoutInfo.SetTRMData((TH1F *)filein->Get("hTRMData"));
1218 readoutInfo.SetTRMEmptyEvent((TH1F *)filein->Get("hTRMEmptyEvent"));
1219 readoutInfo.SetTRMBadEventCounter((TH1F *)filein->Get("hTRMBadEventCounter"));
1220 readoutInfo.SetTRMBadCRC((TH1F *)filein->Get("hTRMBadCRC"));
1221 readoutInfo.SetChainData((TH1F *)filein->Get("hChainData"));
1222 readoutInfo.SetChainBadStatus((TH1F *)filein->Get("hChainBadStatus"));
1223 readoutInfo.SetChainBadEventCounter((TH1F *)filein->Get("hChainBadEventCounter"));
1224 readoutInfo.SetTDCError((TH1F *)filein->Get("hTDCError"));
1225 readoutInfo.SetTDCErrorFlags((TH2F *)filein->Get("hTDCErrorFlags"));
1227 AliCDBMetaData metaDataHisto;
1228 metaDataHisto.SetBeamPeriod(0);
1229 metaDataHisto.SetResponsible("Roberto Preghenella");
1230 metaDataHisto.SetComment("readout info data");
1231 if (!StoreReferenceData("Calib","ReadoutInfo", &readoutInfo, &metaDataHisto)) {
1232 Log("error while storing reference data");
1236 Log("reference data successfully stored");
1239 AliCDBMetaData metaData;
1240 metaData.SetBeamPeriod(0);
1241 metaData.SetResponsible("Roberto Preghenella");
1242 metaData.SetComment("online ReadoutEfficiency measurement");
1243 if (!Store("Calib", "ReadoutEfficiency", hChannelEfficiency, &metaData, 0, kFALSE)) {
1244 Log("error while storing ReadoutEfficiency object");
1245 delete hChannelEfficiency;
1249 Log("ReadoutEfficiency object successfully stored");
1251 delete hChannelEfficiency;
1256 //_____________________________________________________________________________
1258 UInt_t AliTOFPreprocessor::ProcessPulserData()
1260 // Processing Pulser Run data for TOF channel status
1262 Log("Processing Pulser");
1265 AliError("No valid fStatus found, some errors must have occurred!!");
1269 TH1::AddDirectory(0);
1271 Bool_t resultPulserRef=kFALSE;
1272 Bool_t resultPulser=kFALSE;
1274 static const Int_t kSize = AliTOFGeometry::NPadXSector()*AliTOFGeometry::NSectors();
1275 TH1S * htofPulser = new TH1S("hTOFpulser","histo with signals on TOF during pulser", kSize,-0.5,kSize-0.5);
1276 for (Int_t ibin =1;ibin<=kSize;ibin++){
1277 htofPulser->SetBinContent(ibin,-1);
1280 // processing pulser
1282 TFile * daqFile=0x0;
1285 //retrieving Pulser data
1286 TList* listPulser = GetFileSources(kDAQ, "PULSER");
1287 if (listPulser !=0x0 && listPulser->GetEntries()!=0)
1289 AliInfo("The following sources produced files with the id PULSER");
1290 listPulser->Print();
1292 for (Int_t jj=0;jj<listPulser->GetEntries();jj++){
1293 Int_t nPulserSource = 0;
1294 TObjString * str = dynamic_cast<TObjString*> (listPulser->At(jj));
1296 AliError("dynamic_cast returned NULL");
1299 AliInfo(Form("found source %s", str->String().Data()));
1300 // file to be stored run per run
1301 TString fileNamePulser = GetFile(kDAQ, "PULSER", str->GetName());
1302 if (fileNamePulser.Length()>0){
1303 // storing refernce data
1304 AliInfo(Form("Got the file %s, now we can process pulser data.", fileNamePulser.Data()));
1305 daqFile = new TFile(fileNamePulser.Data(),"READ");
1306 h1 = (TH1S*) daqFile->Get("hTOFpulser");
1307 for (Int_t ibin=0;ibin<kSize;ibin++){
1308 if ((h1->GetBinContent(ibin+1))!=-1){
1309 if ((htofPulser->GetBinContent(ibin+1))==-1){
1310 htofPulser->SetBinContent(ibin+1,h1->GetBinContent(ibin+1));
1313 Log(Form("Something strange occurred during Pulser run, channel %i already read by another LDC, please check!",ibin));
1318 // elaborating infos
1321 Int_t nreadNotEmpty=0;
1322 for (Int_t ientry=1;ientry<=h1->GetNbinsX();ientry++){
1324 AliDebug(3,Form(" channel %i pulser status before pulser = %i, with global status = %i",ientry,(Int_t)fStatus->GetPulserStatus(ientry),(Int_t)fStatus->GetStatus(ientry)));
1325 /* check whether channel has been read out during current run.
1326 * if the status is bad it means it has not been read out.
1327 * in this case skip channel in order to not affect the mean */
1328 if (fStatus->GetHWStatus(ientry-1) == AliTOFChannelOnlineStatusArray::kTOFHWBad)
1332 if (h1->GetBinContent(ientry)==-1) continue;
1334 if (h1->GetBinContent(ientry)>0) {
1336 AliDebug(2,Form(" channel %i is ok with entry = %f; so far %i channels added ",ientry-1,h1->GetBinContent(ientry),nreadNotEmpty));
1338 mean+=h1->GetBinContent(ientry);
1344 AliDebug(2,Form(" nread = %i , nreadNotEmpty = %i, mean = %f",nread,nreadNotEmpty,mean));
1345 for (Int_t ich =0;ich<fNChannels;ich++){
1346 if (h1->GetBinContent(ich+1)==-1) continue;
1347 AliDebug(3,Form(" channel %i pulser status before pulser = %i",ich,(Int_t)fStatus->GetPulserStatus(ich)));
1349 /* check whether channel has been read out during current run.
1350 * if the status is bad it means it has not been read out.
1351 * in this case skip channel in order to leave its status
1353 if (fStatus->GetHWStatus(ich) == AliTOFChannelOnlineStatusArray::kTOFHWBad)
1356 if (h1->GetBinContent(ich+1)<0.05*mean){
1357 fStatus->SetPulserStatus(ich,AliTOFChannelOnlineStatusArray::kTOFPulserBad); // bad status for pulser
1358 AliDebug(2,Form( " channel %i pulser status after pulser = %i (bad, content = %f), with global status = %i",ich,(Int_t)fStatus->GetPulserStatus(ich),h1->GetBinContent(ich+1),(Int_t)fStatus->GetStatus(ich)));
1361 fStatus->SetPulserStatus(ich,AliTOFChannelOnlineStatusArray::kTOFPulserOk); // good status for pulser
1362 AliDebug(2,Form( " channel %i pulser status after pulser = %i (good), with global status = %i",ich,(Int_t)fStatus->GetPulserStatus(ich),(Int_t)fStatus->GetStatus(ich)));
1367 Log("No channels read!! No action taken, keeping old status");
1376 Log("The input data file from DAQ (pulser) was not found, TOF exiting from Shuttle ");
1384 return 10;//return error code for failure in retrieving Ref Data
1386 AliDebug(2,Form(" Number of channels processed during pulser run from source %i = %i",jj, nPulserSource));
1388 AliDebug(2,Form(" Number of channels processed during pulser run = %i",nPulser));
1393 Log("The input data file list from DAQ (pulser) was not found, TOF exiting from Shuttle ");
1400 return 10;//return error code for failure in retrieving Ref Data
1405 AliCDBMetaData metaData;
1406 metaData.SetBeamPeriod(0);
1407 metaData.SetResponsible("Chiara Zampolli");
1408 metaData.SetComment("This preprocessor fills an AliTOFChannelOnlineStatusArray object after a Pulser run.");
1409 AliInfo("Storing Calibration Data from Pulser Run");
1410 resultPulser = Store("Calib","Status",fStatus, &metaData,0,kTRUE);
1412 Log("Some problems occurred while storing online object resulting from Pulser data processing");
1419 return 11;//return error code for problems in storing Pulser data
1424 AliCDBMetaData metaDataHisto;
1425 metaDataHisto.SetBeamPeriod(0);
1426 metaDataHisto.SetResponsible("Chiara Zampolli");
1427 metaDataHisto.SetComment("This preprocessor stores the Ref data from a pulser run.");
1428 AliInfo("Storing Reference Data");
1429 resultPulserRef = StoreReferenceData("Calib","PulserData",htofPulser, &metaDataHisto);
1430 if (!resultPulserRef){
1431 Log("some problems occurred::No Reference Data for pulser stored, TOF exiting from Shuttle");
1438 return 9;//return error code for failure in storing Ref Data
1454 //_____________________________________________________________________________
1456 UInt_t AliTOFPreprocessor::ProcessNoiseData()
1459 // Processing Noise Run data for TOF channel status
1461 Log("Processing Noise");
1464 AliError("No valid fStatus found, some errors must have occurred!!");
1468 Float_t noiseThr = 1; // setting default threshold for noise to 1 Hz
1469 // reading config map
1470 AliCDBEntry *cdbEntry = GetFromOCDB("Calib","ConfigNoise");
1472 Log(Form("No Configuration entry found in CDB, using default values: NoiseThr = %f",noiseThr));
1475 TMap *configMap = (TMap*)cdbEntry->GetObject();
1477 Log(Form("No map found in Config entry in CDB, using default values: NoiseThr = %f", noiseThr));
1480 TObjString *strNoiseThr = (TObjString*)configMap->GetValue("NoiseThr");
1482 TString tmpstr = strNoiseThr->GetString();
1483 noiseThr = tmpstr.Atoi();
1486 Log(Form("No NoiseThr value found in Map from ConfigNoise entry in CDB, using default value: NoiseThr = %f",noiseThr));
1494 TH1::AddDirectory(0);
1496 Bool_t resultNoiseRef=kFALSE;
1497 Bool_t resultNoise=kFALSE;
1499 static const Int_t kSize = AliTOFGeometry::NPadXSector()*AliTOFGeometry::NSectors();
1500 TH1F * htofNoise = new TH1F("hTOFnoise","histo with signals on TOF during noise", kSize,-0.5,kSize-0.5);
1501 for (Int_t ibin =1;ibin<=kSize;ibin++){
1502 htofNoise->SetBinContent(ibin,-1);
1507 TFile * daqFile=0x0;
1512 Int_t nNoisyChannels = 0;
1513 Int_t nNotNoisyChannels = 0;
1514 Int_t nChannelsFromDA = 0;
1515 Int_t nMatchingWindowNullNonZero = 0;
1516 Int_t nMatchingWindowNullEqualZero = 0;
1518 // retrieving Noise data
1519 TList* listNoise = GetFileSources(kDAQ, "NOISE");
1520 if (listNoise !=0x0 && listNoise->GetEntries()!=0)
1522 AliInfo("The following sources produced files with the id NOISE");
1524 for (Int_t jj=0;jj<listNoise->GetEntries();jj++){
1525 Int_t nNoiseSource = 0;
1526 TObjString * str = dynamic_cast<TObjString*> (listNoise->At(jj));
1528 AliError("dynamic_cast returned NULL");
1531 AliInfo(Form("found source %s", str->String().Data()));
1532 // file to be stored run per run
1533 TString fileNameNoise = GetFile(kDAQ, "NOISE", str->GetName());
1534 if (fileNameNoise.Length()>0){
1535 // storing reference data
1536 AliInfo(Form("Got the file %s, now we can process noise data.", fileNameNoise.Data()));
1537 daqFile = new TFile(fileNameNoise.Data(),"READ");
1538 h1 = (TH1F*) daqFile->Get("hTOFnoise");
1539 for (Int_t ibin=0;ibin<kSize;ibin++){
1540 if ((h1->GetBinContent(ibin+1))!=-1){
1542 // checking the matching window for current channel
1543 if (fMatchingWindow[ibin] == 0){
1544 Log(Form("Matching window for channel %i null, but the channel was read by the LDC! skipping channel, BUT Please check!",ibin));
1545 if ((h1->GetBinContent(ibin+1))!=0) nMatchingWindowNullNonZero++;
1546 if ((h1->GetBinContent(ibin+1))==0) nMatchingWindowNullEqualZero++;
1549 if ((htofNoise->GetBinContent(ibin+1))==-1){
1550 htofNoise->SetBinContent(ibin+1,h1->GetBinContent(ibin+1)/(fMatchingWindow[ibin]*1.E-9));
1551 if ((h1->GetBinContent(ibin+1))!= 0) AliDebug(2,Form("Channel = %i, Matching window = %i, Content = %f", ibin, fMatchingWindow[ibin], htofNoise->GetBinContent(ibin+1)));
1554 Log(Form("Something strange occurred during Noise run, channel %i already read by another LDC, please check!",ibin));
1559 Log(Form(" Number of channels processed during noise run from source %i = %i",jj, nNoiseSource));
1568 Log("The input data file from DAQ (noise) was not found, TOF exiting from Shuttle ");
1577 if (fMatchingWindow){
1578 delete [] fMatchingWindow;
1579 fMatchingWindow = 0;
1581 return 13;//return error code for failure in retrieving Ref Data
1587 Log("The input data file list from DAQ (noise) was not found, TOF exiting from Shuttle ");
1594 if (fMatchingWindow){
1595 delete [] fMatchingWindow;
1596 fMatchingWindow = 0;
1598 return 13;//return error code for failure in retrieving Ref Data
1601 // elaborating infos to set NOISE status
1602 for (Int_t ich =0;ich<fNChannels;ich++){
1603 if (htofNoise->GetBinContent(ich+1)== -1) continue;
1607 AliDebug(3,Form(" channel %i noise status before noise = %i, with global status = %i",ich,(Int_t)fStatus->GetNoiseStatus(ich),(Int_t)fStatus->GetStatus(ich)));
1608 //AliDebug(2,Form( " channel %i status before noise = %i",ich,(Int_t)fStatus->GetNoiseStatus(ich)));
1610 /* check whether channel has been read out during current run.
1611 * if the status is bad it means it has not been read out.
1612 * in this case skip channel in order to leave its status
1615 if ((fStatus->GetHWStatus(ich)) == AliTOFChannelOnlineStatusArray::kTOFHWBad)
1619 if (htofNoise->GetBinContent(ich+1) >= noiseThr){
1620 fStatus->SetNoiseStatus(ich,AliTOFChannelOnlineStatusArray::kTOFNoiseBad); // bad status for noise
1621 AliDebug(3,Form( " channel %i noise status after noise = %i, with global status = %i",ich,(Int_t)fStatus->GetNoiseStatus(ich),(Int_t)fStatus->GetStatus(ich)));
1625 fStatus->SetNoiseStatus(ich,AliTOFChannelOnlineStatusArray::kTOFNoiseOk); // good status for noise
1626 AliDebug(3,Form(" channel %i noise status after noise = %i, with global status = %i",ich,(Int_t)fStatus->GetNoiseStatus(ich),(Int_t)fStatus->GetStatus(ich)));
1627 nNotNoisyChannels++;
1631 Log(Form(" Number of channels processed by DA during noise run, independetly from TOFFEE = %i",nChannelsFromDA));
1632 Log(Form(" Number of channels processed during noise run (that were ON according to TOFFEE) = %i",nNoise));
1633 Log(Form(" Number of noisy channels found during noise run = %i",nNoisyChannels));
1634 Log(Form(" Number of not noisy channels found during noise run = %i",nNotNoisyChannels));
1635 Log(Form(" Number of channels with matching window NULL (so skipped), but Non Zero content = %i",nMatchingWindowNullNonZero));
1636 Log(Form(" Number of channels with matching window NULL (so skipped), and Zero content = %i",nMatchingWindowNullEqualZero));
1644 AliCDBMetaData metaData;
1645 metaData.SetBeamPeriod(0);
1646 metaData.SetResponsible("Chiara Zampolli");
1647 metaData.SetComment("This preprocessor fills an AliTOFChannelOnlineStatusArray object after a Noise run.");
1648 AliInfo("Storing Calibration Data from Noise Run");
1649 resultNoise = Store("Calib","Status",fStatus, &metaData,0,kTRUE);
1651 Log("Some problems occurred while storing online object resulting from Noise data processing");
1658 if (fMatchingWindow){
1659 delete [] fMatchingWindow;
1660 fMatchingWindow = 0;
1662 return 14;//return error code for problems in storing Noise data
1667 AliCDBMetaData metaDataHisto;
1668 metaDataHisto.SetBeamPeriod(0);
1669 metaDataHisto.SetResponsible("Chiara Zampolli");
1670 metaDataHisto.SetComment("This preprocessor stores the Ref data from a noise run. ");
1671 AliInfo("Storing Reference Data");
1672 resultNoiseRef = StoreReferenceData("Calib","NoiseData",htofNoise, &metaDataHisto);
1673 if (!resultNoiseRef){
1674 Log("some problems occurred::No Reference Data for noise stored");
1681 if (fMatchingWindow){
1682 delete [] fMatchingWindow;
1683 fMatchingWindow = 0;
1685 return 12;//return error code for failure in storing Ref Data
1697 if (fMatchingWindow){
1698 delete [] fMatchingWindow;
1699 fMatchingWindow = 0;
1704 //_____________________________________________________________________________
1706 UInt_t AliTOFPreprocessor::ProcessFEEData()
1708 // Processing Pulser Run data for TOF channel status
1709 // dummy for the time being
1711 Log("Processing FEE");
1713 //Bool_t updateOCDB = kFALSE;
1714 AliTOFFEEReader feeReader;
1716 TH1C hCurrentFEE("hCurrentFEE","histo with current FEE channel status", fNChannels, 0, fNChannels);
1718 /* load current TOF FEE(dump) from DCS FXS,
1719 * setup TOFFEEdump object */
1721 const char * toffeeFileName = GetFile(kDCS,"TofFeeMap","");
1722 AliInfo(Form("toffee file name = %s", toffeeFileName));
1723 if (toffeeFileName == NULL) {
1726 AliTOFFEEDump feedump;
1727 feedump.ReadFromFile(toffeeFileName);
1729 /* load current TOF FEE(light) config from DCS FXS, parse,
1730 * fill current FEE histogram and set FEE status */
1732 const char * nameFile = GetFile(kDCS,"TofFeeLightMap","");
1733 AliInfo(Form("toffeeLight file name = %s",nameFile));
1734 if (nameFile == NULL) {
1737 feeReader.LoadFEElightConfig(nameFile);
1738 Int_t parseFee = feeReader.ParseFEElightConfig();
1739 AliDebug(2,Form("%i enabled channels found in FEElight configuration",parseFee));
1740 /* load stored TOF FEE from OCDB and compare it with current FEE.
1741 * if stored FEE is different from current FEE set update flag.
1742 * if there is no stored FEE in OCDB set update flag */
1744 fMatchingWindow = new Int_t[fNChannels];
1745 fLatencyWindow = new Int_t[fNChannels];
1747 AliCDBEntry *cdbEntry = GetFromOCDB("Calib","Status");
1749 /* no CDB entry found. set update flag */
1750 Log(" ************ WARNING ************");
1751 Log("No CDB Status entry found, creating a new one!");
1752 Log(" *********************************");
1753 fStatus = new AliTOFChannelOnlineStatusArray(fNChannels);
1754 //updateOCDB = kTRUE;
1755 fIsStatusMapChanged = kTRUE;
1758 if (cdbEntry) cdbEntry->SetOwner(kFALSE);
1759 /* CDB entry OK. loop over channels */
1760 fStatus = (AliTOFChannelOnlineStatusArray*) cdbEntry->GetObject();
1763 /* cehck whether status object has latency window data */
1764 if (!fStatus->HasLatencyWindow()) {
1765 /* create new status object and update OCDB */
1766 Log(" ************ WARNING ************");
1767 Log("CDB Status entry found but has no latency window data, creating a new one!");
1768 Log(" *********************************");
1770 fStatus = new AliTOFChannelOnlineStatusArray(fNChannels);
1771 //updateOCDB = kTRUE;
1772 fIsStatusMapChanged = kTRUE;
1775 for (Int_t iChannel = 0; iChannel < fNChannels; iChannel++){
1776 //AliDebug(2,Form("********** channel %i",iChannel));
1777 /* compare current FEE channel status with stored one
1778 * if different set update flag and break loop */
1779 //AliDebug(2,Form( " channel %i status before FEE = %i",iChannel,(Int_t)fStatus->GetHWStatus(iChannel)));
1780 fMatchingWindow[iChannel] = feeReader.GetMatchingWindow(iChannel);
1781 fLatencyWindow[iChannel] = feeReader.GetLatencyWindow(iChannel);
1782 if (feeReader.IsChannelEnabled(iChannel)) {
1783 hCurrentFEE.SetBinContent(iChannel + 1, 1);
1784 if (fStatus->GetHWStatus(iChannel)!=AliTOFChannelOnlineStatusArray::kTOFHWOk){
1785 //updateOCDB = kTRUE;
1786 fIsStatusMapChanged = kTRUE;
1787 fStatus->SetHWStatus(iChannel,AliTOFChannelOnlineStatusArray::kTOFHWOk);
1788 AliDebug(3,Form( " changed into enabled: channel %i status after FEE = %i",iChannel,(Int_t)fStatus->GetHWStatus(iChannel)));
1790 if (fStatus->GetLatencyWindow(iChannel)!=fLatencyWindow[iChannel]){
1791 //updateOCDB = kTRUE;
1792 fIsStatusMapChanged = kTRUE;
1793 fStatus->SetLatencyWindow(iChannel,fLatencyWindow[iChannel]);
1794 AliDebug(3,Form( " changed latency window: channel %i latency window after FEE = %i",iChannel,fStatus->GetLatencyWindow(iChannel)));
1798 if (fStatus->GetHWStatus(iChannel)!=AliTOFChannelOnlineStatusArray::kTOFHWBad){
1799 //updateOCDB = kTRUE;
1800 fIsStatusMapChanged = kTRUE;
1801 fStatus->SetHWStatus(iChannel,AliTOFChannelOnlineStatusArray::kTOFHWBad);
1802 AliDebug(3,Form( " changed into disabled: channel %i status after FEE = %i",iChannel,(Int_t)fStatus->GetHWStatus(iChannel)));
1808 /* check whether we don't have to store reference data.
1809 * in this case we return without errors. */
1810 if (fStoreRefData) {
1811 /* store reference data */
1812 AliCDBMetaData metaDataHisto;
1813 metaDataHisto.SetBeamPeriod(0);
1814 metaDataHisto.SetResponsible("Roberto Preghenella");
1815 metaDataHisto.SetComment("This preprocessor stores the FEE Ref data of the current run.");
1816 AliInfo("Storing FEE reference data");
1817 /* store FEE reference data */
1818 if (!StoreReferenceData("Calib", "FEEData", &hCurrentFEE, &metaDataHisto)) {
1820 Log("problems while storing FEE reference data");
1825 return 18; /* error return code for problems while storing FEE reference data */
1828 /* store TOF FEE dump reference data */
1829 AliCDBMetaData metaDatadump;
1830 metaDatadump.SetBeamPeriod(0);
1831 metaDatadump.SetResponsible("Roberto Preghenella");
1832 metaDatadump.SetComment("This preprocessor stores the TOF FEE dump Ref data of the current run.");
1833 AliInfo("Storing TOF FEE dump reference data");
1834 /* store FEE reference data */
1835 if (!StoreReferenceData("Calib", "FEEDump", &feedump, &metaDatadump)) {
1837 Log("problems while storing TOF FEE dump reference data");
1838 return 18; /* error return code for problems while storing FEE reference data */
1846 //_____________________________________________________________________________
1848 UInt_t AliTOFPreprocessor::Process(TMap *dcsAliasMap)
1851 // Main AliTOFPreprocessor method called by SHUTTLE
1854 TString runType = GetRunType();
1855 Log(Form("RunType %s",runType.Data()));
1859 /* always process FEE data */
1860 Int_t iresultFEE = ProcessFEEData();
1861 if (iresultFEE != 0)
1864 if (runType == "PULSER") {
1865 Int_t iresultPulser = ProcessPulserData();
1866 return iresultPulser;
1869 if (runType == "NOISE") { // for the time being associating noise runs with pedestal runs; proper run type to be defined
1870 Int_t iresultNoise = ProcessNoiseData();
1871 return iresultNoise;
1874 if (runType == "PHYSICS") {
1875 // Int_t iresultDAQ = ProcessOnlineDelays();
1876 Int_t iresultDAQ = ProcessT0Fill();
1877 Int_t iresultNoiseCalib = ProcessNoiseCalibTrg();
1878 Int_t iresultReadout = ProcessReadout();
1879 Int_t iresultDCS = ProcessDCSDataPoints(dcsAliasMap);
1880 Int_t iResultHVandLVdps = ProcessHVandLVdps(dcsAliasMap);
1881 return iresultDAQ+iresultNoiseCalib+iresultDCS+iResultHVandLVdps+iresultReadout;
1889 //_____________________________________________________________________________
1892 AliTOFPreprocessor::FillWithCosmicCalibration(AliTOFChannelOnlineArray *cal)
1895 * fill with cosmic calibration
1898 Log(" Using cosmic-ray calibration.");
1900 AliTOFcalibHisto calibHisto;
1901 calibHisto.SetFullCorrectionFlag(AliTOFcalibHisto::kTimeSlewingCorr, kFALSE);
1902 Log(Form(" loading calibration histograms from %s", calibHisto.GetCalibHistoFileName()));
1903 Log(Form(" loading calibration parameters from %s", calibHisto.GetCalibParFileName()));
1904 calibHisto.LoadCalibPar();
1906 /* loop over channel index */
1907 for (Int_t iIndex = 0; iIndex < fNChannels; iIndex++) {
1908 cal->SetDelay(iIndex, calibHisto.GetFullCorrection(iIndex));
1913 //_____________________________________________________________________________
1916 AliTOFPreprocessor::FillWithCableLengthMap(AliTOFChannelOnlineArray *cal)
1919 * fill with cosmic calibration
1922 Log(" Using cable-length map.");
1923 AliTOFRawStream tofrs;
1924 Int_t det[5], dummy, index;
1925 Float_t cableTimeShift;
1927 /* temporarly disable warnings */
1928 AliLog::EType_t logLevel = (AliLog::EType_t)AliLog::GetGlobalLogLevel();
1929 AliLog::SetGlobalLogLevel(AliLog::kError);
1931 /* loop over EO indeces */
1932 for (Int_t iddl = 0; iddl < 72; iddl++)
1933 for (Int_t islot = 3; islot <= 12; islot++)
1934 for (Int_t ichain = 0; ichain < 2; ichain++)
1935 for (Int_t itdc = 0; itdc < 15; itdc++)
1936 for (Int_t ichannel = 0; ichannel < 8; ichannel++) {
1939 tofrs.EquipmentId2VolumeId(iddl, islot, ichain, itdc, ichannel, det);
1941 /* swap det[3] and det[4] indeces (needed to obtain correct channel index) */
1946 /* check DO index */
1947 if (det[0] < 0 || det[0] > 17 ||
1948 det[1] < 0 || det[1] > 4 ||
1949 det[2] < 0 || det[2] > 18 ||
1950 det[3] < 0 || det[3] > 1 ||
1951 det[4] < 0 || det[4] > 47)
1954 /* get channel index */
1955 index = AliTOFGeometry::GetIndex(det);
1956 if (index < 0) continue;
1958 /* get cable time shift */
1959 cableTimeShift = AliTOFCableLengthMap::GetCableTimeShift(iddl, islot, ichain, itdc);
1962 if (index<fNChannels) {
1963 cal->SetDelay(index,cableTimeShift); // delay in ns
1964 AliDebug(2,Form("Setting delay %f (ns) for channel %i",cableTimeShift,index));
1967 } /* loop over EO indeces */
1969 /* re-enable warnings */
1970 AliLog::SetGlobalLogLevel(logLevel);