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