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