]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ZDC/AliZDCPreprocessor.cxx
Calibration strategy updated: mapping + LASER data
[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 "AliZDCChMap.h"
18 #include "AliZDCPedestals.h"
19 #include "AliZDCLaserCalib.h"
20 #include "AliZDCCalib.h"
21
22 /////////////////////////////////////////////////////////////////////
23 //                                                                 //
24 // Class implementing ZDC pre-processor.                           //
25 // It takes data from DCS and passes it to the class AliZDCDataDCS //
26 // The class is then written to the CDB.                           //
27 //                                                                 //
28 /////////////////////////////////////////////////////////////////////
29
30 ClassImp(AliZDCPreprocessor)
31
32 //______________________________________________________________________________________________
33 AliZDCPreprocessor::AliZDCPreprocessor(AliShuttleInterface* shuttle) :
34   AliPreprocessor("ZDC", shuttle),
35   fData(0)
36 {
37   // constructor
38   AddRunType("STANDALONE_PEDESTAL");
39   AddRunType("STANDALONE_LASER");
40   AddRunType("STANDALONE_EMD");
41   AddRunType("ALL");
42 }
43
44
45 //______________________________________________________________________________________________
46 AliZDCPreprocessor::~AliZDCPreprocessor()
47 {
48   // destructor
49 }
50
51
52 //______________________________________________________________________________________________
53 void AliZDCPreprocessor::Initialize(Int_t run, UInt_t startTime,
54         UInt_t endTime)
55 {
56   // Creates AliZDCDataDCS object
57
58   AliPreprocessor::Initialize(run, startTime, endTime);
59
60         Log(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run,
61                 TTimeStamp(startTime).AsString(),
62                 TTimeStamp(endTime).AsString()));
63
64         fRun = run;
65         fStartTime = startTime;
66         fEndTime = endTime;
67
68         fData = new AliZDCDataDCS(fRun, fStartTime, fEndTime);
69 }
70
71 //______________________________________________________________________________________________
72 UInt_t AliZDCPreprocessor::Process(TMap* dcsAliasMap)
73 {
74   // *************** From DCS ******************
75   // Fills data into a AliZDCDataDCS object
76   if(!dcsAliasMap) return 1;
77
78   // The processing of the DCS input data is forwarded to AliZDCDataDCS
79   Float_t dcsValues[28]; // DCSAliases=28
80   fData->SetCalibData(dcsValues);
81   fData->ProcessData(*dcsAliasMap);
82   // Store DCS data for reference
83   AliCDBMetaData metadata;
84   metadata.SetResponsible("Chiara Oppedisano");
85   metadata.SetComment("DCS data for ZDC");
86   Bool_t resDCSRef = kTRUE;
87   resDCSRef = StoreReferenceData("DCS","Data",fData,&metadata);
88   //dcsAliasMap->Print("");
89   //
90   // --- Writing ZDC table positions into alignment object
91   TClonesArray *array = new TClonesArray("AliAlignObjParams",10);
92   TClonesArray &alobj = *array;
93   AliAlignObjParams a;
94   Double_t dx=0., dz=0., dpsi=0., dtheta=0., dphi=0.;
95   // Vertical table position in mm from DCS
96   Double_t dyZN1 = (Double_t) (dcsValues[0]/10.);
97   Double_t dyZP1 = (Double_t) (dcsValues[1]/10.);
98   Double_t dyZN2 = (Double_t) (dcsValues[2]/10.);
99   Double_t dyZP2 = (Double_t) (dcsValues[3]/10.);
100   const char *n1ZDC="ZDC/NeutronZDC1";
101   const char *p1ZDC="ZDC/ProtonZDC1";
102   const char *n2ZDC="ZDC/NeutronZDC2";
103   const char *p2ZDC="ZDC/ProtonZDC2";
104   UShort_t iIndex=0;
105   AliGeomManager::ELayerID iLayer = AliGeomManager::kInvalidLayer;
106   UShort_t volid = AliGeomManager::LayerToVolUID(iLayer,iIndex);
107   //
108   new(alobj[0]) AliAlignObjParams(n1ZDC, volid, dx, dyZN1, dz, dpsi, dtheta, dphi, kTRUE);
109   new(alobj[1]) AliAlignObjParams(p1ZDC, volid, dx, dyZP1, dz, dpsi, dtheta, dphi, kTRUE);
110   new(alobj[2]) AliAlignObjParams(n2ZDC, volid, dx, dyZN2, dz, dpsi, dtheta, dphi, kTRUE);
111   new(alobj[3]) AliAlignObjParams(p2ZDC, volid, dx, dyZP2, dz, dpsi, dtheta, dphi, kTRUE);
112   // save in CDB storage
113   AliCDBMetaData md;
114   md.SetResponsible("Chiara Oppedisano");
115   md.SetComment("Alignment object for ZDC");
116   Bool_t resultAl = kTRUE;
117   resultAl = Store("Align","Data", array, &md, 0, 0);
118   
119 // *************** From DAQ ******************
120 Bool_t resChMap=kTRUE, resPedCal=kTRUE, resLaserCal=kTRUE, resECal=kTRUE;
121 // 
122 const char* beamType = GetRunParameter("beamType");
123 TString runType = GetRunType();
124 printf("\n\t AliZDCPreprocessor -> beamType %s\n",beamType);
125 printf("\t AliZDCPreprocessor -> runType  %s\n\n",runType.Data());
126
127 // ******************************************
128 //   ZDC ADC channel mapping
129 // ******************************************
130 TList* daqAllSources = GetFileSources(kDAQ, "ALL");
131 if(!daqAllSources){
132   AliError(Form("No sources run %d !", fRun));
133   return 1;
134 }
135 Log("\t List of sources "); daqAllSources->Print();
136 //
137 TIter iterAll(daqAllSources);
138 TObjString* sourceAll = 0;
139 Int_t iAll=0;
140 while((sourceAll = dynamic_cast<TObjString*> (iterAll.Next()))){
141      Log(Form("\n\t Getting file #%d\n",++iAll));
142      TString fileName = GetFile(kDAQ, "ALL", sourceAll->GetName());
143      if(fileName.Length() <= 0){
144        Log(Form("No file from source %s!", sourceAll->GetName()));
145        return 1;
146      }
147      // --- Initializing pedestal calibration object
148      AliZDCChMap *mapCalib = new AliZDCChMap("ZDC");
149      // --- Reading file with pedestal calibration data
150      const char* fname = fileName.Data();
151      if(fname){
152        FILE *fileAll;
153        if((fileAll = fopen(fname,"r")) == NULL){
154          printf("Cannot open file %s \n",fname);
155          return 1;
156        }
157        Log(Form("File %s connected to process data for ADC mapping", fname));
158        //
159        Int_t chMap[48][6]; 
160        for(Int_t j=0; j<48; j++){         
161            for(Int_t k=0; k<6; k++){
162              fscanf(fileAll,"%d",&chMap[j][k]);
163            }
164            mapCalib->SetADCModule(j,chMap[j][1]);
165            mapCalib->SetADCChannel(j,chMap[j][2]);
166            mapCalib->SetDetector(j,chMap[j][4]);
167            mapCalib->SetSector(j,chMap[j][5]);
168        }
169        fclose(fileAll);
170      }
171      else{
172        Log(Form("File %s not found", fname));
173        return 1;
174      }
175      //mapCalib->Print("");
176     // 
177     AliCDBMetaData metaData;
178     metaData.SetBeamPeriod(0);
179     metaData.SetResponsible("Chiara Oppedisano");
180     metaData.SetComment("Filling AliZDCChMap object");  
181     //
182     resChMap = Store("Calib","ChMap",mapCalib, &metaData, 0, 1);
183 }
184
185 // 
186 if(strcmp(beamType,"p-p")==0){
187
188    // --- Initializing pedestal calibration object
189    AliZDCCalib *eCalib = new AliZDCCalib("ZDC");
190    //
191    for(Int_t j=0; j<6; j++) eCalib->SetEnCalib(j,1.);
192    for(Int_t j=0; j<5; j++){  
193         eCalib->SetZN1EqualCoeff(j, 1.);
194         eCalib->SetZP1EqualCoeff(j, 1.);
195         eCalib->SetZN2EqualCoeff(j, 1.);
196         eCalib->SetZP2EqualCoeff(j, 1.);  
197    }
198    //eCalib->Print("");
199    // 
200    AliCDBMetaData metaData;
201    metaData.SetBeamPeriod(0);
202    metaData.SetResponsible("Chiara Oppedisano");
203    metaData.SetComment("AliZDCCalib object");  
204    //
205    resECal = Store("Calib","EMDCalib",eCalib, &metaData, 0, 1);
206 }
207 // 
208 // *****************************************************
209 // [a] PEDESTALS -> Pedestal subtraction
210 // *****************************************************
211 // 
212 if(runType=="STANDALONE_PEDESTAL"){
213   TList* daqSources = GetFileSources(kDAQ, "PEDESTALS");
214   if(!daqSources){
215     Log(Form("No source for STANDALONE_PEDESTAL run %d !", fRun));
216     return 1;
217   }
218   Log("\t List of sources for STANDALONE_PEDESTAL");
219   daqSources->Print();
220   //
221   TIter iter(daqSources);
222   TObjString* source = 0;
223   Int_t i=0;
224   while((source = dynamic_cast<TObjString*> (iter.Next()))){
225        Log(Form("\n\t Getting file #%d\n",++i));
226        TString stringPedFileName = GetFile(kDAQ, "PEDESTALS", source->GetName());
227        if(stringPedFileName.Length() <= 0){
228           Log(Form("No PEDESTAL file from source %s!", source->GetName()));
229           return 1;
230        }
231        // --- Initializing pedestal calibration object
232        AliZDCPedestals *pedCalib = new AliZDCPedestals("ZDC");
233        // --- Reading file with pedestal calibration data
234        const char* pedFileName = stringPedFileName.Data();
235        // no. ADCch = (22 signal ch. + 2 reference PMs) * 2 gain chain = 48
236        const Int_t knZDCch = 48;
237        if(pedFileName){
238          FILE *file;
239          if((file = fopen(pedFileName,"r")) == NULL){
240            printf("Cannot open file %s \n",pedFileName);
241            return 1;
242          }
243          Log(Form("File %s connected to process pedestal data", pedFileName));
244          Float_t pedVal[(3*knZDCch)][3];
245          for(Int_t k=0; k<(3*knZDCch); k++){
246             for(Int_t j=0; j<3; j++){
247                fscanf(file,"%f",&pedVal[k][j]);
248                //if(j==1) printf("pedVal[%d] -> %f, %f \n",k,pedVal[k][0],pedVal[k][1]);
249             }
250             if(k<knZDCch){
251               pedCalib->SetMeanPed(k,pedVal[k][1]);
252               pedCalib->SetMeanPedWidth(i,pedVal[k][2]);
253             }
254             else if(k>=knZDCch && k<(2*knZDCch)){
255               pedCalib->SetOOTPed(k-knZDCch,pedVal[k][1]);
256               pedCalib->SetOOTPedWidth(k-knZDCch,pedVal[k][2]);
257             }
258             else if(k>=(2*knZDCch) && k<(3*knZDCch)){
259               pedCalib->SetPedCorrCoeff(k-(2*knZDCch),pedVal[k][1],pedVal[k][2]);
260             }
261          }
262          fclose(file);
263        }
264        else{
265           Log(Form("File %s not found", pedFileName));
266           return 1;
267        }
268        //
269       //pedCalib->Print("");
270       // 
271       AliCDBMetaData metaData;
272       metaData.SetBeamPeriod(0);
273       metaData.SetResponsible("Chiara Oppedisano");
274       metaData.SetComment("Filling AliZDCPedestals object");  
275       //
276       resPedCal = Store("Calib","Pedestals",pedCalib, &metaData, 0, 1);
277   }
278   delete daqSources; daqSources = 0;
279 }
280 // *****************************************************
281 // [b] STANDALONE_LASER EVENTS -> Signal stability
282 // *****************************************************
283 else if(runType=="STANDALONE_LASER"){
284   TList* daqSources = GetFileSources(kDAQ, "LASER");
285   if(!daqSources){
286     AliError(Form("No sources for STANDALONE_LASER run %d !", fRun));
287     return 1;
288   }
289   Log("\t List of sources for STANDALONE_LASER");
290   daqSources->Print();
291   //
292   TIter iter2(daqSources);
293   TObjString* source = 0;
294   Int_t i=0;
295   while((source = dynamic_cast<TObjString*> (iter2.Next()))){
296        Log(Form("\n\t Getting file #%d\n",++i));
297        TString stringLASERFileName = GetFile(kDAQ, "LASER", source->GetName());
298        if(stringLASERFileName.Length() <= 0){
299          Log(Form("No LASER file from source %s!", source->GetName()));
300          return 1;
301        }
302        // --- Initializing pedestal calibration object
303        AliZDCLaserCalib *lCalib = new AliZDCLaserCalib("ZDC");
304        // --- Reading file with pedestal calibration data
305        const char* laserFileName = stringLASERFileName.Data();
306        if(laserFileName){
307          FILE *file;
308          if((file = fopen(laserFileName,"r")) == NULL){
309            printf("Cannot open file %s \n",laserFileName);
310            return 1;
311          }
312          Log(Form("File %s connected to process data from LASER events", laserFileName));
313          //
314          Float_t ivalRef[2], ivalRead[2][4]; 
315          for(Int_t j=0; j<3; j++){
316            if(j==0){
317              for(Int_t k=0; k<2; k++){
318                fscanf(file,"%f",&ivalRef[k]);
319                printf(" %1.0f  ",ivalRef[k]);
320                lCalib->SetReferenceValue(k,ivalRef[k]);     
321              }
322            }
323            else{
324              for(Int_t k=0; k<4; k++){
325                fscanf(file,"%f",&ivalRead[j-1][k]);
326                printf(" %d %1.0f  ",k, ivalRead[j-1][k]);
327              }
328              lCalib->SetSector(j-1, ivalRead[j-1][0]);
329              lCalib->SetGain(j-1, ivalRead[j-1][1]);
330              lCalib->SetfPMRefValue(j-1, ivalRead[j-1][2]);
331              lCalib->SetfPMRefWidth(j-1, ivalRead[j-1][3]);
332            }
333            printf("\n");
334          }
335          fclose(file);
336        }
337        else{
338          Log(Form("File %s not found", laserFileName));
339          return 1;
340        }
341        //lCalib->Print("");
342        // 
343        AliCDBMetaData metaData;
344        metaData.SetBeamPeriod(0);
345        metaData.SetResponsible("Chiara Oppedisano");
346        metaData.SetComment("Filling AliZDCLaserCalib object");  
347        //
348        resLaserCal = Store("Calib","LaserCalib",lCalib, &metaData, 0, 1);
349   }
350   
351 }
352 // *****************************************************
353 // [c] EMD EVENTS -> Energy calibration and equalization
354 // *****************************************************
355 else if(runType=="STANDALONE_EMD"){
356   TList* daqSources = GetFileSources(kDAQ, "EMDCALIB");
357   if(!daqSources){
358     AliError(Form("No sources for STANDALONE_EMD run %d !", fRun));
359     return 1;
360   }
361   Log("\t List of sources for STANDALONE_EMD");
362   daqSources->Print();
363   //
364   TIter iter2(daqSources);
365   TObjString* source = 0;
366   Int_t i=0;
367   while((source = dynamic_cast<TObjString*> (iter2.Next()))){
368        Log(Form("\n\t Getting file #%d\n",++i));
369        TString stringEMDFileName = GetFile(kDAQ, "EMDCALIB", source->GetName());
370        if(stringEMDFileName.Length() <= 0){
371          Log(Form("No EMDCALIB file from source %s!", source->GetName()));
372          return 1;
373        }
374        // --- Initializing pedestal calibration object
375        AliZDCCalib *eCalib = new AliZDCCalib("ZDC");
376        // --- Reading file with pedestal calibration data
377        const char* emdFileName = stringEMDFileName.Data();
378        if(emdFileName){
379          FILE *file;
380          if((file = fopen(emdFileName,"r")) == NULL){
381            printf("Cannot open file %s \n",emdFileName);
382            return 1;
383          }
384          Log(Form("File %s connected to process data from EM dissociation events", emdFileName));
385          //
386          Float_t fitValEMD[6]; Float_t equalCoeff[5][4];
387          Float_t calibVal[4];
388          for(Int_t j=0; j<10; j++){         
389            if(j<6){
390              fscanf(file,"%f",&fitValEMD[j]);
391              if(j<4){
392                calibVal[j] = 2.76/fitValEMD[j];
393                eCalib->SetEnCalib(j,calibVal[j]);
394              }
395              else eCalib->SetEnCalib(j,fitValEMD[j]);
396            }
397            else{
398              for(Int_t k=0; k<5; k++){
399                 fscanf(file,"%f",&equalCoeff[j][k]);
400                 if(j==6)      eCalib->SetZN1EqualCoeff(k, equalCoeff[j][k]);
401                 else if(j==7) eCalib->SetZP1EqualCoeff(k, equalCoeff[j][k]);
402                 else if(j==8) eCalib->SetZN2EqualCoeff(k, equalCoeff[j][k]);
403                 else if(j==9) eCalib->SetZP2EqualCoeff(k, equalCoeff[j][k]);  
404              }
405            }
406          }
407          fclose(file);
408        }
409        else{
410          Log(Form("File %s not found", emdFileName));
411          return 1;
412        }
413        //eCalib->Print("");
414       // 
415       AliCDBMetaData metaData;
416       metaData.SetBeamPeriod(0);
417       metaData.SetResponsible("Chiara Oppedisano");
418       metaData.SetComment("Filling AliZDCCalib object");  
419       //
420       resECal = Store("Calib","EMDCalib",eCalib, &metaData, 0, 1);
421   }
422 }
423 else {
424   Log(Form("Nothing to do: run type is %s", runType.Data()));
425   return 0;
426
427
428   // note that the parameters are returned as character strings!
429   const char* nEvents = GetRunParameter("totalEvents");
430   if(nEvents) Log(Form("Number of events for run %d: %s",fRun, nEvents));
431   else Log(Form("Number of events not put in logbook!"));
432  
433   UInt_t result = 0;
434   if(resDCSRef==kFALSE || resultAl==kFALSE || resPedCal==kFALSE ||
435      resLaserCal==kFALSE || resECal==kFALSE || resChMap==kFALSE){
436     if(resDCSRef == kFALSE)        result = 1;
437     else if(resultAl == kFALSE)    result = 2;
438     else if(resChMap == kFALSE)    result = 3;
439     else if(resPedCal == kFALSE)   result = 4;
440     else if(resLaserCal == kFALSE) result = 5;
441     else if(resECal == kFALSE)     result = 6;
442   }
443   
444   return result;
445   
446 }