]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ZDC/AliZDCPreprocessor.cxx
Initialisation.
[u/mrichter/AliRoot.git] / ZDC / AliZDCPreprocessor.cxx
1 // --- ROOT system
2 #include <TFile.h>
3 #include <TClonesArray.h>
4 #include <TList.h>
5 #include <TObjString.h>
6 #include <TTimeStamp.h>
7
8 #include "AliZDCPreprocessor.h"
9 #include "AliCDBManager.h"
10 #include "AliCDBEntry.h"
11 #include "AliCDBMetaData.h"
12 #include "AliDCSValue.h"
13 #include "AliAlignObj.h"
14 #include "AliAlignObjParams.h"
15 #include "AliLog.h"
16 #include "AliZDCDataDCS.h"
17 #include "AliZDCPedestals.h"
18 #include "AliZDCCalib.h"
19 #include "AliZDCRecParam.h"
20
21 /////////////////////////////////////////////////////////////////////
22 //                                                                 //
23 // Class implementing ZDC pre-processor.                           //
24 // It takes data from DCS and passes it to the class AliZDCDataDCS //
25 // The class is then written to the CDB.                           //
26 //                                                                 //
27 /////////////////////////////////////////////////////////////////////
28
29 ClassImp(AliZDCPreprocessor)
30
31 //______________________________________________________________________________________________
32 AliZDCPreprocessor::AliZDCPreprocessor(AliShuttleInterface* shuttle) :
33   AliPreprocessor("ZDC", shuttle),
34   fData(0)
35 {
36   // constructor
37 }
38
39 //______________________________________________________________________________________________
40 AliZDCPreprocessor::~AliZDCPreprocessor()
41 {
42   // destructor
43 }
44
45
46 //______________________________________________________________________________________________
47 void AliZDCPreprocessor::Initialize(Int_t run, UInt_t startTime,
48         UInt_t endTime)
49 {
50   // Creates AliZDCDataDCS object
51
52   AliPreprocessor::Initialize(run, startTime, endTime);
53
54         Log(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run,
55                 TTimeStamp(startTime).AsString(),
56                 TTimeStamp(endTime).AsString()));
57
58         fRun = run;
59         fStartTime = startTime;
60         fEndTime = endTime;
61
62         fData = new AliZDCDataDCS(fRun, fStartTime, fEndTime);
63 }
64
65 //______________________________________________________________________________________________
66 UInt_t AliZDCPreprocessor::Process(TMap* dcsAliasMap)
67 {
68   // *************** From DCS ******************
69   // Fills data into a AliZDCDataDCS object
70   if(!dcsAliasMap) return 1;
71
72   // The processing of the DCS input data is forwarded to AliZDCDataDCS
73   Float_t dcsValues[28]; // DCSAliases=28
74   fData->ProcessData(*dcsAliasMap, dcsValues);
75   //dcsAliasMap->Print("");
76   //
77   // --- Writing ZDC table positions into alignment object
78   TClonesArray *array = new TClonesArray("AliAlignObjParams",10);
79   TClonesArray &alobj = *array;
80   AliAlignObjParams a;
81   Double_t dx=0., dz=0., dpsi=0., dtheta=0., dphi=0.;
82   // Vertical table position in mm from DCS
83   Double_t dyZN1 = (Double_t) (dcsValues[0]/10.);
84   Double_t dyZP1 = (Double_t) (dcsValues[1]/10.);
85   Double_t dyZN2 = (Double_t) (dcsValues[2]/10.);
86   Double_t dyZP2 = (Double_t) (dcsValues[3]/10.);
87   const char *n1ZDC="ZDC/NeutronZDC1";
88   const char *p1ZDC="ZDC/ProtonZDC1";
89   const char *n2ZDC="ZDC/NeutronZDC2";
90   const char *p2ZDC="ZDC/ProtonZDC2";
91   UShort_t iIndex=0;
92   AliGeomManager::ELayerID iLayer = AliGeomManager::kInvalidLayer;
93   UShort_t volid = AliGeomManager::LayerToVolUID(iLayer,iIndex);
94   //
95   new(alobj[0]) AliAlignObjParams(n1ZDC, volid, dx, dyZN1, dz, dpsi, dtheta, dphi, kTRUE);
96   new(alobj[1]) AliAlignObjParams(p1ZDC, volid, dx, dyZP1, dz, dpsi, dtheta, dphi, kTRUE);
97   new(alobj[2]) AliAlignObjParams(n2ZDC, volid, dx, dyZN2, dz, dpsi, dtheta, dphi, kTRUE);
98   new(alobj[3]) AliAlignObjParams(p2ZDC, volid, dx, dyZP2, dz, dpsi, dtheta, dphi, kTRUE);
99   // save in CDB storage
100   AliCDBMetaData md;
101   md.SetResponsible("Chiara Oppedisano");
102   md.SetComment("Alignment object for ZDC");
103   Bool_t resultAl = kTRUE;
104   resultAl = Store("Align","Data", array, &md, 0, 0);
105   
106 // *************** From DAQ ******************
107 Bool_t resPedCal = kTRUE, resECal = kTRUE, resRecPar = kTRUE;
108 // *****************************************************
109 // [a] PEDESTALS -> Pedestal subtraction
110 // *****************************************************
111 TString runType = GetRunType();
112 printf("\n\t AliZDCPreprocessor -> runType detected %s\n\n",runType.Data());
113 if(runType == "PEDESTAL_RUN"){
114   TList* daqSources = GetFileSources(kDAQ, "PEDESTALS");
115   if(!daqSources){
116     Log(Form("No source for PEDESTALS run %d !", fRun));
117     return 1;
118   }
119   Log("\t List of sources for PEDESTALS");
120   daqSources->Print();
121   //
122   TIter iter(daqSources);
123   TObjString* source = 0;
124   Int_t i=0;
125   while((source = dynamic_cast<TObjString*> (iter.Next()))){
126        Log(Form("\n\t Getting file #%d\n",++i));
127        TString stringPedFileName = GetFile(kDAQ, "PEDESTALS", source->GetName());
128        if(stringPedFileName.Length() <= 0){
129           Log(Form("No PEDESTAL file from source %s!", source->GetName()));
130           return 1;
131        }
132        // --- Initializing pedestal calibration object
133        AliZDCPedestals *pedCalib = new AliZDCPedestals("ZDC");
134        // --- Reading file with pedestal calibration data
135        const char* pedFileName = stringPedFileName.Data();
136        // no. ADCch = (22 signal ch. + 2 reference PMs) * 2 gain chain = 48
137        const Int_t knZDCch = 48;
138        if(pedFileName){
139          FILE *file;
140          if((file = fopen(pedFileName,"r")) == NULL){
141            printf("Cannot open file %s \n",pedFileName);
142            return 1;
143          }
144          Log(Form("File %s connected to process pedestal data", pedFileName));
145          Float_t pedVal[(3*knZDCch)][2];
146          for(Int_t i=0; i<(3*knZDCch); i++){
147             for(Int_t j=0; j<2; j++){
148                fscanf(file,"%f",&pedVal[i][j]);
149                //if(j==1) printf("pedVal[%d] -> %f, %f \n",i,pedVal[i][0],pedVal[i][1]);
150             }
151             if(i<knZDCch){
152               pedCalib->SetMeanPed(i,pedVal[i][0]);
153               pedCalib->SetMeanPedWidth(i,pedVal[i][1]);
154             }
155             else if(i>=knZDCch && i<(2*knZDCch)){
156               pedCalib->SetOOTPed(i-knZDCch,pedVal[i][0]);
157               pedCalib->SetOOTPedWidth(i-knZDCch,pedVal[i][1]);
158             }
159             else if(i>=(2*knZDCch) && i<(3*knZDCch)){
160               pedCalib->SetPedCorrCoeff(i-(2*knZDCch),pedVal[i][0],pedVal[i][1]);
161             }
162          }
163        }
164        else{
165           Log(Form("File %s not found", pedFileName));
166           return 1;
167        }
168        //
169       //pedCalib->Print("");
170       // 
171       AliCDBMetaData metaData;
172       metaData.SetBeamPeriod(0);
173       metaData.SetResponsible("Chiara");
174       metaData.SetComment("Filling AliZDCPedestals object");  
175       //
176       resPedCal = Store("Calib","Pedestals",pedCalib, &metaData, 0, 1);
177   }
178   delete daqSources; daqSources = 0;
179 }
180 // *****************************************************
181 // [b] EMD EVENTS -> Energy calibration and equalization
182 // *****************************************************
183 else if(runType == "PULSER_RUN"){
184   TList* daqSources = GetFileSources(kDAQ, "EMDCALIB");
185   if(!daqSources){
186     AliError(Form("No sources for PULSER_RUN run %d !", fRun));
187     return 1;
188   }
189   Log("\t List of sources for PULSER_RUN");
190   daqSources->Print();
191   //
192   TIter iter2(daqSources);
193   TObjString* source = 0;
194   Int_t j=0;
195   while((source = dynamic_cast<TObjString*> (iter2.Next()))){
196        Log(Form("\n\t Getting file #%d\n",++j));
197        TString stringEMDFileName = GetFile(kDAQ, "EMDCALIB", source->GetName());
198        if(stringEMDFileName.Length() <= 0){
199          Log(Form("No EMDCALIB file from source %s!", source->GetName()));
200          return 1;
201        }
202        // --- Initializing pedestal calibration object
203        AliZDCCalib *eCalib = new AliZDCCalib("ZDC");
204        // --- Reading file with pedestal calibration data
205        const char* emdFileName = stringEMDFileName.Data();
206        if(emdFileName){
207          FILE *file;
208          if((file = fopen(emdFileName,"r")) == NULL){
209            printf("Cannot open file %s \n",emdFileName);
210            return 1;
211          }
212          Log(Form("File %s connected to process data from EM dissociation events", emdFileName));
213          //
214          Float_t fitValEMD[6]; Float_t equalCoeff[5][4];
215          Float_t calibVal[4];
216          for(Int_t j=0; j<10; j++){         
217            if(j<6){
218              fscanf(file,"%f",&fitValEMD[j]);
219              if(j<4){
220                calibVal[j] = fitValEMD[j]/2.76;
221                eCalib->SetEnCalib(j,calibVal[j]);
222              }
223              else eCalib->SetEnCalib(j,fitValEMD[j]);
224            }
225            else{
226              for(Int_t k=0; k<5; k++){
227                 fscanf(file,"%f",&equalCoeff[j][k]);
228                 if(j==6) eCalib->SetZN1EqualCoeff(k, equalCoeff[j][k]);
229                 else if(j==7) eCalib->SetZP1EqualCoeff(k, equalCoeff[j][k]);
230                 else if(j==8) eCalib->SetZN2EqualCoeff(k, equalCoeff[j][k]);
231                 else if(j==9) eCalib->SetZP2EqualCoeff(k, equalCoeff[j][k]);  
232              }
233            }
234          }
235        }
236        else{
237          Log(Form("File %s not found", emdFileName));
238          return 1;
239        }
240        //calibdata->Print("");
241       // 
242       AliCDBMetaData metaData;
243       metaData.SetBeamPeriod(0);
244       metaData.SetResponsible("Chiara");
245       metaData.SetComment("Filling AliZDCCalib object");  
246       //
247       resECal = Store("Calib","Calib",eCalib, &metaData, 0, 1);
248   }
249 }
250 // ********************************************************
251 // [c] PHYSICS RUNS -> Parameters needed for reconstruction
252 // ********************************************************
253 else if(runType == "PHYSICS"){
254   TList* daqSources = GetFileSources(kDAQ, "PHYSICS");
255   if(!daqSources){
256     AliError(Form("No sources for PHYSICS run %d !", fRun));
257     return 1;
258   }
259   Log("\t List of sources for PHYSICS");
260   daqSources->Print();
261   //
262   TIter iter2(daqSources);
263   TObjString* source = 0;
264   Int_t j=0;
265   while((source = dynamic_cast<TObjString*> (iter2.Next()))){
266        Log(Form("\n\t Getting file #%d\n",++j));
267        TString stringPHYSFileName = GetFile(kDAQ, "PHYSICS", source->GetName());
268        if(stringPHYSFileName.Length() <= 0){
269          Log(Form("No PHYSICS file from source %s!", source->GetName()));
270          return 1;
271        }
272        // --- Initializing pedestal calibration object
273        AliZDCRecParam *recCalib = new AliZDCRecParam("ZDC");
274        // --- Reading file with pedestal calibration data
275        const char* physFileName = stringPHYSFileName.Data();
276        if(physFileName){
277          FILE *file;
278          if((file = fopen(physFileName,"r")) == NULL){
279            printf("Cannot open file %s \n",physFileName);
280            return 1;
281          }
282          Log(Form("File %s connected to process data from PHYSICS runs", physFileName));
283          //
284          Float_t physRecParam[10]; 
285          for(Int_t j=0; j<10; j++) fscanf(file,"%f",&physRecParam[j]);
286          recCalib->SetZEMEndValue(physRecParam[0]);
287          recCalib->SetZEMCutFraction(physRecParam[1]);
288          recCalib->SetDZEMSup(physRecParam[2]);
289          recCalib->SetDZEMInf(physRecParam[3]);
290          recCalib->SetEZN1MaxValue(physRecParam[4]);
291          recCalib->SetEZP1MaxValue(physRecParam[5]);
292          recCalib->SetEZDC1MaxValue(physRecParam[6]);
293          recCalib->SetEZN2MaxValue(physRecParam[7]);
294          recCalib->SetEZP2MaxValue(physRecParam[8]);
295          recCalib->SetEZDC2MaxValue(physRecParam[9]);
296        }
297        else{
298          Log(Form("File %s not found", physFileName));
299          return 1;
300        }
301        //calibdata->Print("");
302       // 
303       AliCDBMetaData metaData;
304       metaData.SetBeamPeriod(0);
305       metaData.SetResponsible("Chiara");
306       metaData.SetComment("Filling AliZDCCalib object");  
307       //
308       resRecPar = Store("Calib","RecParam",recCalib, &metaData, 0, 1);
309   }
310
311 else {
312   Log(Form("Nothing to do: run type is %s", runType.Data()));
313   return 0;
314
315
316   // note that the parameters are returned as character strings!
317   const char* nEvents = GetRunParameter("totalEvents");
318   if(nEvents) Log(Form("Number of events for run %d: %s",fRun, nEvents));
319   else Log(Form("Number of events not put in logbook!"));
320  
321   UInt_t result = 0;
322   if(resultAl==kFALSE || resPedCal==kFALSE || resECal==kFALSE || resRecPar==kFALSE){
323     if(resultAl == kFALSE) result = 1;
324     else if(resPedCal == kFALSE) result = 2;
325     else if(resECal == kFALSE)   result = 3;
326     else if(resRecPar == kFALSE) result = 4;
327   }
328   
329   return result;
330   
331 }