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