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