]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TOF/AliTOFPreprocessor.cxx
Removing the fake copy constructors and assignment operator, moving their declaration...
[u/mrichter/AliRoot.git] / TOF / AliTOFPreprocessor.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
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  **************************************************************************/
15
16 /* $Id$ */
17
18 #include <Riostream.h>
19 #include <stdio.h>
20 #include <stdlib.h>
21
22 #include <TFile.h>
23 #include <TH1.h>
24 #include <TH1F.h>
25 #include <TH1S.h>
26 #include <TH2S.h>
27 #include <TMath.h>
28 #include <TObjArray.h>
29 #include <TObjString.h>
30 #include <TTimeStamp.h>
31
32 #include "AliCDBMetaData.h"
33 #include "AliLog.h"
34 #include "AliTOFCalOnline.h"
35 #include "AliTOFChannelOnline.h"
36 #include "AliTOFDataDCS.h"
37 #include "AliTOFGeometryV5.h"
38 #include "AliTOFPreprocessor.h"
39
40 class TF1;
41 class AliDCSValue;
42 class AliTOFGeometry;
43
44 // TOF preprocessor class.
45 // It takes data from DCS and passes them to the class AliTOFDataDCS, which
46 // processes them. The result is then written to the CDB.
47 // analogously, it takes data form DAQ (both at Run level and inclusive - 
48 // of all the runs - level, processes them, and stores both Reference Data
49 // and Online Calibration files in the CDB. 
50
51
52 ClassImp(AliTOFPreprocessor)
53
54 const Int_t AliTOFPreprocessor::fgkBinRangeAve    = 13; // number of bins where to calculate the mean 
55 const Double_t AliTOFPreprocessor::fgkThrPar    = 0.013; // parameter used to trigger the calculation of the delay
56
57 //_____________________________________________________________________________
58
59 AliTOFPreprocessor::AliTOFPreprocessor(AliShuttleInterface* shuttle) :
60   AliPreprocessor("TOF", shuttle),
61   fData(0),
62   fh2(0),
63   fCal(0),
64   fTOFGeometry(0)
65 {
66   // constructor
67 }
68
69 //_____________________________________________________________________________
70
71 AliTOFPreprocessor::~AliTOFPreprocessor()
72 {
73   // destructor
74   delete fData;
75   fData = 0;
76   delete fh2;
77   fh2 = 0;
78   delete fCal;
79   fCal = 0;
80   delete fTOFGeometry;
81   fTOFGeometry = 0;
82 }
83
84 //______________________________________________________________________________
85 void AliTOFPreprocessor::Initialize(Int_t run, UInt_t startTime,
86         UInt_t endTime)
87 {
88   // Creates AliTOFDataDCS object
89
90   AliPreprocessor::Initialize(run, startTime, endTime);
91
92         AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run,
93                 TTimeStamp(startTime).AsString(),
94                 TTimeStamp(endTime).AsString()));
95
96         fData = new AliTOFDataDCS(fRun, fStartTime, fEndTime);
97         fh2 = 0x0;
98         fTOFGeometry = new AliTOFGeometryV5();
99         fCal = new AliTOFCalOnline(fTOFGeometry);
100         fCal->CreateArray();
101 }
102
103 //_____________________________________________________________________________
104
105 UInt_t AliTOFPreprocessor::Process(TMap* dcsAliasMap)
106 {
107   // Fills data into a AliTOFDataDCS object
108
109   TH1::AddDirectory(0);
110   UInt_t resultDCS=0;
111   UInt_t resultDAQ=0;
112   UInt_t resultDAQRef=0;
113   UInt_t result=0;
114
115   // processing DCS
116
117   if (!dcsAliasMap){
118     Log("No DCS map found");
119   }
120   else {
121   // The processing of the DCS input data is forwarded to AliTOFDataDCS
122     fData->ProcessData(*dcsAliasMap);
123     AliCDBMetaData metaDataDCS;
124     metaDataDCS.SetBeamPeriod(0);
125     metaDataDCS.SetResponsible("Chiara Zampolli");
126     metaDataDCS.SetComment("This preprocessor fills an AliTOFDataDCS object.");     resultDCS = Store("Calib","DCSData",fData, &metaDataDCS);
127     //    result+=resultDCS;
128     if (!resultDCS){
129       Log("Some problems occurred while storing DCS data processing results");
130       return 0;
131     }
132   }
133
134   // processing DAQ
135
136   TFile * daqFile=0x0;
137
138   //retrieving data at Run level
139   TList* list = GetFileSources(kDAQ, "RUNLevel");
140   if (list)
141     {
142       AliInfo("The following sources produced files with the id RUNLevel");
143       list->Print();
144       for (Int_t jj=0;jj<list->GetEntries();jj++){
145         TObjString * str = dynamic_cast<TObjString*> (list->At(jj));
146         AliInfo(Form("found source %s", str->String().Data()));
147         // file to be stored run per run
148         TString fileNameRun = GetFile(kDAQ, "RUNLevel", str->GetName());
149         if (fileNameRun.Length()>0){
150           AliInfo(Form("Got the file %s, now we can store the Reference Data for the current Run.", fileNameRun.Data()));
151           daqFile = new TFile(fileNameRun.Data(),"READ");
152           fh2 = (TH2S*) daqFile->Get("htof");
153           AliCDBMetaData metaDataHisto;
154           metaDataHisto.SetBeamPeriod(0);
155           metaDataHisto.SetResponsible("Chiara Zampolli");
156           metaDataHisto.SetComment("This preprocessor stores the array of histos object as Reference Data.");
157           resultDAQRef = StoreReferenceData("Calib","DAQData",fh2, &metaDataHisto);
158           //      result+=resultDAQRef*2;
159           if (!resultDAQRef){
160             Log("some problems occurred::No Reference Data stored, still going on (please check!)");
161           }
162           daqFile->Close();
163           delete daqFile;
164         }
165
166         else{
167           Log("The input data file from DAQ (run-level) was not found, still going on with Cumulative data file (please check!) "); 
168         } 
169       }
170     }
171   else{
172     Log("The input data file list from DAQ (run-level) was not found, still going on with Cumulative data file (please check!) "); 
173   }
174
175   //Total files, with summed histos
176
177   TList* listTot = GetFileSources(kDAQ, "DELAYS");
178   if (listTot)
179     {
180       AliInfo("The following sources produced files with the id DELAYS");
181       listTot->Print();
182       for (Int_t jj=0;jj<listTot->GetEntries();jj++){
183         TObjString * str = dynamic_cast<TObjString*> (listTot->At(jj));
184         AliInfo(Form("found source %s", str->String().Data()));
185
186         // file with summed histos, to extract calib params
187         TString fileName = GetFile(kDAQ, "DELAYS", str->GetName());
188         if (fileName.Length()>0){
189           AliInfo(Form("Got the file %s, now we can extract some values.", fileName.Data()));
190
191           daqFile = new TFile(fileName.Data(),"READ");
192           fh2 = (TH2S*) daqFile->Get("htoftot");
193           if (!fh2){
194             Log("some problems occurred:: No histo retrieved, TOF exiting from Shuttle");
195             delete daqFile;
196             return 0;
197           }
198           else {
199             static const Int_t size=fh2->GetNbinsX();
200             static const Int_t nbins=fh2->GetNbinsY();
201             static const Double_t xbinmin=fh2->GetYaxis()->GetBinLowEdge(1);
202             Int_t npads = fCal->NPads();
203             if (size != npads){
204               Log(" number of bins along x different from number of pads, found only a subset of the histograms, TOF exiting from Shuttle");
205               delete daqFile;
206               return 0;
207             }
208             for (Int_t ich=0;ich<size;ich++){
209               TH1S *h1 = new TH1S("h1","h1",nbins,xbinmin-0.5,nbins*1.+xbinmin-0.5);
210               for (Int_t ibin=0;ibin<nbins;ibin++){
211                 h1->SetBinContent(ibin+1,fh2->GetBinContent(ich+1,ibin+1));
212               }
213               Bool_t found=kFALSE; 
214               Float_t minContent=h1->Integral()*fgkThrPar; 
215               Int_t nbinsX = h1->GetNbinsX();
216               Int_t startBin=1;
217               for (Int_t j=1; j<=nbinsX; j++){
218                 if ((
219                      h1->GetBinContent(j) +     
220                      h1->GetBinContent(j+1)+
221                      h1->GetBinContent(j+2)+ 
222                      h1->GetBinContent(j+3))>minContent){
223                   found=kTRUE;
224                   startBin=j;
225                   break;
226                 }
227               }
228               if(!found) AliInfo(Form("WARNING!!! no start of fit found for histo # %i",ich));
229               // Now calculate the mean over the interval. 
230               Double_t mean = 0;
231               Double_t sumw2 = 0;
232               Double_t nent = 0;
233               for(Int_t k=0;k<fgkBinRangeAve;k++){
234                 mean=mean+h1->GetBinCenter(startBin+k)*h1->GetBinContent(startBin+k);                 
235                 nent=nent+h1->GetBinContent(startBin+k);                 
236                 sumw2=sumw2+(h1->GetBinCenter(startBin+k))*(h1->GetBinCenter(startBin+k))*(h1->GetBinContent(startBin+k));
237               }
238               mean= mean/nent; //<x>
239               sumw2=sumw2/nent; //<x^2>
240               Double_t rmsmean= 0;
241               rmsmean = TMath::Sqrt((sumw2-mean*mean)/nent);
242               if (ich<npads) {
243                 AliTOFChannelOnline * ch = fCal->GetChannel(ich);
244                 ch->SetDelay(mean);
245               }
246             delete h1;
247             h1=0x0;
248             }
249           }
250           daqFile->Close();
251           delete daqFile;
252           AliCDBMetaData metaData;
253           metaData.SetBeamPeriod(0);
254           metaData.SetResponsible("Chiara Zampolli");
255           metaData.SetComment("This preprocessor fills an AliTOFCal object.");
256           resultDAQ = Store("Calib","OnlineDelay",fCal, &metaData);
257           if(!resultDAQ){
258             Log("Some problems occurred while storing DAQ data processing results");
259             return 0;
260           }
261         }
262         else{
263           Log("The Cumulative data file from DAQ does not exist, TOF exiting from Shuttle"); 
264           return 0;
265         }
266       }
267     }
268   else{
269     Log("Problem: no list for Cumulative data file from DAQ was found, TOF exiting from Shuttle");
270     return 0;
271   }
272
273   //  delete list;
274   // list = 0;
275   // delete listTot;
276   // listTot = 0;
277   daqFile=0;
278
279   if(resultDCS ==2|| resultDAQ ==2) {
280     result=2;
281   }
282   else{ 
283     result=1;
284   }
285
286   return result;
287 }
288
289