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 #include <Riostream.h>
28 #include <TObjArray.h>
29 #include <TObjString.h>
30 #include <TTimeStamp.h>
32 #include "AliCDBMetaData.h"
34 #include "AliTOFChannelOnline.h"
35 #include "AliTOFDataDCS.h"
36 #include "AliTOFGeometry.h"
37 #include "AliTOFPreprocessor.h"
43 // TOF preprocessor class.
44 // It takes data from DCS and passes them to the class AliTOFDataDCS, which
45 // processes them. The result is then written to the CDB.
46 // analogously, it takes data form DAQ (both at Run level and inclusive -
47 // of all the runs - level, processes them, and stores both Reference Data
48 // and Online Calibration files in the CDB.
51 ClassImp(AliTOFPreprocessor)
53 const Int_t AliTOFPreprocessor::fgkBinRangeAve = 13; // number of bins where to calculate the mean
54 const Double_t AliTOFPreprocessor::fgkThrPar = 0.013; // parameter used to trigger the calculation of the delay
56 //_____________________________________________________________________________
58 AliTOFPreprocessor::AliTOFPreprocessor(AliShuttleInterface* shuttle) :
59 AliPreprocessor("TOF", shuttle),
70 //_____________________________________________________________________________
72 AliTOFPreprocessor::~AliTOFPreprocessor()
90 //______________________________________________________________________________
91 void AliTOFPreprocessor::Initialize(Int_t run, UInt_t startTime,
94 // Creates AliTOFDataDCS object
96 AliPreprocessor::Initialize(run, startTime, endTime);
98 AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run,
99 TTimeStamp(startTime).AsString(),
100 TTimeStamp(endTime).AsString()));
102 fData = new AliTOFDataDCS(fRun, fStartTime, fEndTime);
104 fNChannels = AliTOFGeometry::NSectors()*(2*(AliTOFGeometry::NStripC()+AliTOFGeometry::NStripB())+AliTOFGeometry::NStripA())*AliTOFGeometry::NpadZ()*AliTOFGeometry::NpadX();
105 fCal = new TObjArray(fNChannels);
107 for (Int_t ich = 0; ich<fNChannels; ich ++){
108 AliTOFChannelOnline * calChOnline = new AliTOFChannelOnline();
109 fCal->AddAt(calChOnline,ich);
113 //_____________________________________________________________________________
115 UInt_t AliTOFPreprocessor::Process(TMap* dcsAliasMap)
117 // Fills data into a AliTOFDataDCS object
120 // return=1 : no DCS input data Map
121 // return=2 : no DCS input data processing
122 // return=3 : no DCS processed data was stored in Ref Data
123 // return=4 : no DAQ input for Ref Data
124 // return=5 : failed to store Ref Data
125 // return=6 : failed to retrieve DAQ data for calibration
126 // return=7 : problems in histos in the input DAQ file
127 // return=8 : failed to store Online Delays
129 TH1::AddDirectory(0);
131 Bool_t resultDCSMap=kFALSE;
132 Bool_t resultDCSStore=kFALSE;
133 Bool_t resultDAQ=kFALSE;
134 Bool_t resultDAQRef=kFALSE;
139 Log("No DCS map found: TOF exiting from Shuttle");
140 return 1;// return error Code for DCS input data not found
143 // The processing of the DCS input data is forwarded to AliTOFDataDCS
144 resultDCSMap=fData->ProcessData(*dcsAliasMap);
146 Log("Some problems occurred while processing DCS data, TOF exiting from Shuttle");
147 return 2;// return error Code for processed DCS data not stored
150 AliCDBMetaData metaDataDCS;
151 metaDataDCS.SetBeamPeriod(0);
152 metaDataDCS.SetResponsible("Chiara Zampolli");
153 metaDataDCS.SetComment("This preprocessor fills an AliTOFDataDCS object.");
154 AliInfo("Storing DCS Data");
155 resultDCSStore = StoreReferenceData("Calib","DCSData",fData, &metaDataDCS);
156 if (!resultDCSStore){
157 Log("Some problems occurred while storing DCS data results in Reference Data, TOF exiting from Shuttle");
158 return 3;// return error Code for processed DCS data not stored
170 //retrieving data at Run level
171 TList* list = GetFileSources(kDAQ, "RUNLevel");
174 AliInfo("The following sources produced files with the id RUNLevel");
176 for (Int_t jj=0;jj<list->GetEntries();jj++){
177 TObjString * str = dynamic_cast<TObjString*> (list->At(jj));
178 AliInfo(Form("found source %s", str->String().Data()));
179 // file to be stored run per run
180 TString fileNameRun = GetFile(kDAQ, "RUNLevel", str->GetName());
181 if (fileNameRun.Length()>0){
182 AliInfo(Form("Got the file %s, now we can store the Reference Data for the current Run.", fileNameRun.Data()));
183 daqFile = new TFile(fileNameRun.Data(),"READ");
184 fh2 = (TH2S*) daqFile->Get("htof");
185 AliCDBMetaData metaDataHisto;
186 metaDataHisto.SetBeamPeriod(0);
187 metaDataHisto.SetResponsible("Chiara Zampolli");
188 metaDataHisto.SetComment("This preprocessor stores the array of histos object as Reference Data.");
189 AliInfo("Storing Reference Data");
190 resultDAQRef = StoreReferenceData("Calib","DAQData",fh2, &metaDataHisto);
192 Log("some problems occurred::No Reference Data stored, TOF exiting from Shuttle");
193 return 5;//return error code for failure in storing Ref Data
200 Log("The input data file from DAQ (run-level) was not found, TOF exiting from Shuttle ");
201 return 4;//return error code for failure in retrieving Ref Data
206 Log("The input data file list from DAQ (run-level) was not found, TOF exiting from Shuttle ");
207 return 4;//return error code for failure in retrieving Ref Data
212 //Total files, with cumulative histos
214 TList* listTot = GetFileSources(kDAQ, "DELAYS");
217 AliInfo("The following sources produced files with the id DELAYS");
219 for (Int_t jj=0;jj<listTot->GetEntries();jj++){
220 TObjString * str = dynamic_cast<TObjString*> (listTot->At(jj));
221 AliInfo(Form("found source %s", str->String().Data()));
223 // file with summed histos, to extract calib params
224 TString fileName = GetFile(kDAQ, "DELAYS", str->GetName());
225 if (fileName.Length()>0){
226 AliInfo(Form("Got the file %s, now we can extract some values.", fileName.Data()));
228 daqFile = new TFile(fileName.Data(),"READ");
230 fh2 = (TH2S*) daqFile->Get("htoftot");
232 Log("some problems occurred:: No histo retrieved, TOF exiting from Shuttle");
234 return 7; //return error code for histograms not existing/junky
237 static const Int_t kSize=fh2->GetNbinsX();
238 static const Int_t kNBins=fh2->GetNbinsY();
239 static const Double_t kXBinmin=fh2->GetYaxis()->GetBinLowEdge(1);
240 if (kSize != fNChannels){
241 Log(" number of bins along x different from number of pads, found only a subset of the histograms, TOF exiting from Shuttle");
243 return 7; //return error code for histograms not existing/junky
245 for (Int_t ich=0;ich<kSize;ich++){
246 TH1S *h1 = new TH1S("h1","h1",kNBins,kXBinmin-0.5,kNBins*1.+kXBinmin-0.5);
247 for (Int_t ibin=0;ibin<kNBins;ibin++){
248 h1->SetBinContent(ibin+1,fh2->GetBinContent(ich+1,ibin+1));
251 Float_t minContent=h1->Integral()*fgkThrPar;
252 Int_t nbinsX = h1->GetNbinsX();
254 for (Int_t j=1; j<=nbinsX; j++){
256 h1->GetBinContent(j) +
257 h1->GetBinContent(j+1)+
258 h1->GetBinContent(j+2)+
259 h1->GetBinContent(j+3))>minContent){
265 if(!found) AliInfo(Form("WARNING!!! no start of fit found for histo # %i",ich));
266 // Now calculate the mean over the interval.
270 for(Int_t k=0;k<fgkBinRangeAve;k++){
271 mean=mean+h1->GetBinCenter(startBin+k)*h1->GetBinContent(startBin+k);
272 nent=nent+h1->GetBinContent(startBin+k);
273 sumw2=sumw2+(h1->GetBinCenter(startBin+k))*(h1->GetBinCenter(startBin+k))*(h1->GetBinContent(startBin+k));
275 mean= mean/nent; //<x>
276 sumw2=sumw2/nent; //<x^2>
278 rmsmean = TMath::Sqrt((sumw2-mean*mean)/nent);
279 if (ich<fNChannels) {
280 AliTOFChannelOnline * ch = (AliTOFChannelOnline *)fCal->At(ich);
281 ch->SetDelay((Double_t)mean*AliTOFGeometry::TdcBinWidth()*1.E-3); // delay in ns
289 AliCDBMetaData metaData;
290 metaData.SetBeamPeriod(0);
291 metaData.SetResponsible("Chiara Zampolli");
292 metaData.SetComment("This preprocessor fills an AliTOFCal object.");
293 AliInfo("Storing Calibration Data");
294 resultDAQ = Store("Calib","ParOnline",fCal, &metaData);
296 Log("Some problems occurred while storing DAQ data processing results");
297 return 8;//return error code for problems in storing DAQ data
301 Log("The Cumulative data file from DAQ does not exist, TOF exiting from Shuttle");
302 return 6;//return error code for problems in retrieving DAQ data
307 Log("Problem: no list for Cumulative data file from DAQ was found, TOF exiting from Shuttle");
308 return 6; //return error code for problems in retrieving DAQ data