]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ZDC/AliZDCPreprocessor.cxx
In AliMUONTriggerQADataMakerRec:
[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"
73bc3a3f 20#include "AliZDCEnCalib.h"
21#include "AliZDCTowerCalib.h"
0d579f58 22#include "AliZDCMBCalib.h"
64a7c78d 23
d5e687c2 24/////////////////////////////////////////////////////////////////////
25// //
73bc3a3f 26// Class implementing Shuttle ZDC pre-processor. //
27// It takes data from DCS and DAQ and writes calibration objects //
28// in the OCDB and reference values/histos in the ReferenceData. //
d5e687c2 29// //
30/////////////////////////////////////////////////////////////////////
64a7c78d 31
e83c8d88 32// ******************************************************************
33// RETURN CODES:
da2b6160 34// return 0 : everything OK
35// return 1 : no DCS input data Map
36// return 2 : error storing DCS data in RefData
37// return 3 : error storing alignment object in OCDB
38// return 4 : error in ZDCMapping.dat file retrieved from DAQ FXS (not existing|empty|corrupted)
39// return 5 : error storing mapping obj. in OCDB
40// return 6 : error storing energy calibration obj. in OCDB
41// return 7 : error storing tower inter-calibration obj. in OCDB
42// return 8 : error in ZDCEnergyCalib.dat file retrieved from DAQ FXS
43// return 9 : error in ZDCTowerCalib.dat file retrieved from DAQ FXS
44// return 10: error in ZDCPedestal.dat file retrieved from DAQ FXS
45// return 11: error storing pedestal calibration obj. in OCDB
46// return 12: error in ZDCPedHisto.root file retrieved from DAQ FXS
47// return 13: error storing pedestal histos in RefData
48// return 14: error in ZDCLaserCalib.dat file retrieved from DAQ FXS
49// return 15: error storing laser calibration obj. in OCDB
50// return 16: error in ZDCLaserHisto.root file retrieved from DAQ FXS
51// return 17: error storing laser histos in RefData
0d579f58 52// return 18: error in ZDCMBCalib.root file retrieved from DAQ FXS
53// return 19: error storing MB calibration obj. in OCDB
e83c8d88 54// ******************************************************************
55
64a7c78d 56ClassImp(AliZDCPreprocessor)
57
58//______________________________________________________________________________________________
857ece97 59AliZDCPreprocessor::AliZDCPreprocessor(AliShuttleInterface* shuttle) :
60 AliPreprocessor("ZDC", shuttle),
64a7c78d 61 fData(0)
62{
63 // constructor
b8d194f5 64 // May 2009 - run types updated according to
65 // http://alice-ecs.web.cern.ch/alice-ecs/runtypes_3.36.html
cbf06263 66 AddRunType("STANDALONE_PEDESTAL");
1ee299a5 67 AddRunType("STANDALONE_LASER");
321fe3b8 68 AddRunType("STANDALONE_COSMIC");
b8d194f5 69 AddRunType("CALIBRATION_EMD");
70 AddRunType("CALIBRATION_MB");
71 AddRunType("CALIBRATION_CENTRAL");
72 AddRunType("CALIBRATION_SEMICENTRAL");
73 AddRunType("CALIBRATION_BC");
321fe3b8 74 AddRunType("PHYSICS");
64a7c78d 75}
76
cbf06263 77
64a7c78d 78//______________________________________________________________________________________________
79AliZDCPreprocessor::~AliZDCPreprocessor()
80{
81 // destructor
82}
83
7a78280f 84
64a7c78d 85//______________________________________________________________________________________________
da2b6160 86void AliZDCPreprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
64a7c78d 87{
88 // Creates AliZDCDataDCS object
89
90 AliPreprocessor::Initialize(run, startTime, endTime);
91
57c85e6e 92 AliDebug(2,Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s \n\tStartTime DCS Query %s \n\tEndTime DCS Query %s", run,
e83c8d88 93 TTimeStamp(startTime).AsString(),
94 TTimeStamp(endTime).AsString(), ((TTimeStamp)GetStartTimeDCSQuery()).AsString(), ((TTimeStamp)GetEndTimeDCSQuery()).AsString()));
64a7c78d 95
73bc3a3f 96 fRun = run;
97 fStartTime = startTime;
98 fEndTime = endTime;
79563ba1 99
e83c8d88 100 fData = new AliZDCDataDCS(fRun, fStartTime, fEndTime, GetStartTimeDCSQuery(), GetEndTimeDCSQuery());
101}
102
103//_____________________________________________________________________________
104Bool_t AliZDCPreprocessor::ProcessDCS(){
105
106 // tells whether DCS should be processed or not
107
108 TString runType = GetRunType();
109 Log(Form("RunType %s",runType.Data()));
110
111 if (runType=="STANDALONE_COSMIC" || runType=="STANDALONE_PEDESTAL"){
112 return kFALSE;
113 }
114
115 return kTRUE;
116}
117
118//______________________________________________________________________________________________
119UInt_t AliZDCPreprocessor::ProcessDCSData(TMap* dcsAliasMap)
120{
121
122 // Fills data into a AliZDCDataDCS object
bf867209 123 if(!dcsAliasMap){
124 Log(" No DCS map found: ZDC exiting from Shuttle");
57c85e6e 125 if(fData){
126 delete fData;
127 fData = 0;
128 }
bf867209 129 return 1;
130 }
131
e83c8d88 132 Log(Form("Processing data from DCS"));
bf867209 133
e83c8d88 134 // The processing of the DCS input data is forwarded to AliZDCDataDCS
e83c8d88 135 //dcsAliasMap->Print("");
bf867209 136 Bool_t resDCSProcess = fData->ProcessData(*dcsAliasMap);
137 if(resDCSProcess==kFALSE){
138 Log(" Problems in processing DCS DP");
139 return 1;
57c85e6e 140 }
e83c8d88 141
0d579f58 142 // ------------------------------------------------------
143 // Change introduced 26/9/09 in order NOT to process the
144 // HV DP since some of them are never found in amanda DB
145 // ------------------------------------------------------
57c85e6e 146 // Store DCS data as reference
aee13a2d 147 AliCDBMetaData metadata;
e83c8d88 148 metadata.SetResponsible("Chiara Oppedisano");
57c85e6e 149 metadata.SetComment("DCS DP TMap for ZDC");
e83c8d88 150 Bool_t resDCSRef = kTRUE;
57c85e6e 151 resDCSRef = StoreReferenceData("DCS","Data", dcsAliasMap, &metadata);
e83c8d88 152
153 if(resDCSRef==kFALSE) return 2;
aee13a2d 154
e83c8d88 155 // --- Writing ZDC table positions into alignment object
156 TClonesArray *array = new TClonesArray("AliAlignObjParams",10);
157 TClonesArray &alobj = *array;
158 AliAlignObjParams a;
159 Double_t dx=0., dz=0., dpsi=0., dtheta=0., dphi=0.;
160 // Vertical table position in mm from DCS
57c85e6e 161 Double_t dyZN1 = (Double_t) (fData->GetAlignData(0)/10.);
162 Double_t dyZP1 = (Double_t) (fData->GetAlignData(1)/10.);
163 Double_t dyZN2 = (Double_t) (fData->GetAlignData(2)/10.);
164 Double_t dyZP2 = (Double_t) (fData->GetAlignData(3)/10.);
e83c8d88 165 //
166 const char *n1ZDC="ZDC/NeutronZDC_C";
167 const char *p1ZDC="ZDC/ProtonZDC_C";
168 const char *n2ZDC="ZDC/NeutronZDC_A";
169 const char *p2ZDC="ZDC/ProtonZDC_A";
170 //
171 UShort_t iIndex=0;
172 AliGeomManager::ELayerID iLayer = AliGeomManager::kInvalidLayer;
173 UShort_t volid = AliGeomManager::LayerToVolUID(iLayer,iIndex);
174 //
175 new(alobj[0]) AliAlignObjParams(n1ZDC, volid, dx, dyZN1, dz, dpsi, dtheta, dphi, kTRUE);
176 new(alobj[1]) AliAlignObjParams(p1ZDC, volid, dx, dyZP1, dz, dpsi, dtheta, dphi, kTRUE);
177 new(alobj[2]) AliAlignObjParams(n2ZDC, volid, dx, dyZN2, dz, dpsi, dtheta, dphi, kTRUE);
178 new(alobj[3]) AliAlignObjParams(p2ZDC, volid, dx, dyZP2, dz, dpsi, dtheta, dphi, kTRUE);
179
180 // save in CDB storage
181 AliCDBMetaData mdDCS;
182 mdDCS.SetResponsible("Chiara Oppedisano");
183 mdDCS.SetComment("Alignment object for ZDC");
1a1c78d4 184 Bool_t resultAl = Store("Align","Data", array, &mdDCS, 0, kFALSE);
e83c8d88 185 if(resultAl==kFALSE) return 3;
186
187 return 0;
64a7c78d 188}
189
321fe3b8 190//______________________________________________________________________________________________
da2b6160 191UInt_t AliZDCPreprocessor::ProcessChMap()
321fe3b8 192{
0d579f58 193 const int kNch=48, kNScch=32;
e83c8d88 194
3c159ed0 195 // Reading the file for mapping from FXS
da2b6160 196 TList* daqSource = GetFileSources(kDAQ, "MAPPING");
321fe3b8 197 if(!daqSource){
da2b6160 198 AliError(Form("No sources for file ZDCChMapping.dat in run %d ", fRun));
e83c8d88 199 return 4;
321fe3b8 200 }
da2b6160 201 if(daqSource->GetEntries()==0) return 4;
202 Log("\t List of DAQ sources for MAPPING id: "); daqSource->Print();
321fe3b8 203 //
204 TIter iter(daqSource);
205 TObjString* source = 0;
b8d194f5 206 Int_t isou = 0;
e83c8d88 207 Int_t readMap[kNch][6];
3c159ed0 208 //
321fe3b8 209 while((source = dynamic_cast<TObjString*> (iter.Next()))){
92508ce2 210 TString fileName = GetFile(kDAQ, "MAPPING", source->GetName());
da2b6160 211 Log(Form("\t Getting file #%d: ZDCChMapping.dat from %s\n",++isou, source->GetName()));
321fe3b8 212
213 if(fileName.Length() <= 0){
214 Log(Form("No file from source %s!", source->GetName()));
e83c8d88 215 return 4;
321fe3b8 216 }
c00e895a 217 // --- Reading file with calibration data
218 //const char* fname = fileName.Data();
219 if(fileName){
321fe3b8 220 FILE *file;
c00e895a 221 if((file = fopen(fileName,"r")) == NULL){
222 printf("Cannot open file %s \n",fileName.Data());
e83c8d88 223 return 4;
321fe3b8 224 }
c00e895a 225 Log(Form("File %s connected to process data for ADC mapping", fileName.Data()));
321fe3b8 226 //
e83c8d88 227 for(Int_t j=0; j<kNch; j++){
321fe3b8 228 for(Int_t k=0; k<6; k++){
73bc3a3f 229 int read = fscanf(file,"%d",&readMap[j][k]);
e83c8d88 230 if(read == 0) AliDebug(3," Failing in reading data from mapping file");
321fe3b8 231 }
321fe3b8 232 }
233 fclose(file);
234 }
235 else{
c00e895a 236 Log(Form("File %s not found", fileName.Data()));
e83c8d88 237 return 4;
321fe3b8 238 }
3c159ed0 239 }
3c159ed0 240
241 // Store the currently read map ONLY IF it is different
242 // from the entry in the OCDB
243 Bool_t updateOCDB = kFALSE;
244
245 AliCDBEntry *cdbEntry = GetFromOCDB("Calib","ChMap");
246 if(!cdbEntry){
73bc3a3f 247 Log(" No existing CDB entry for ADC mapping");
3c159ed0 248 updateOCDB = kTRUE;
249 }
250 else{
251 AliZDCChMap *chMap = (AliZDCChMap*) cdbEntry->GetObject();
e83c8d88 252 for(Int_t i=0; i<kNch; i++){
3c159ed0 253 if( (readMap[i][1] == chMap->GetADCModule(i))
254 && (readMap[i][2] == chMap->GetADCChannel(i))
255 && (readMap[i][4] == chMap->GetDetector(i))
256 && (readMap[i][5] == chMap->GetSector(i))){
257 updateOCDB = kFALSE;
258 }
0d579f58 259 else updateOCDB = kTRUE;
3c159ed0 260 }
261 }
0d579f58 262 //
e83c8d88 263 Bool_t resChMapStore = kTRUE;
3c159ed0 264 if(updateOCDB==kTRUE){
73bc3a3f 265 Log(" A new entry ZDC/Calib/ChMap will be created");
3c159ed0 266 //
267 // --- Initializing mapping calibration object
268 AliZDCChMap *mapCalib = new AliZDCChMap("ZDC");
269 // Writing channel map in the OCDB
e83c8d88 270 for(Int_t k=0; k<kNch; k++){
3c159ed0 271 mapCalib->SetADCModule(k,readMap[k][1]);
272 mapCalib->SetADCChannel(k,readMap[k][2]);
273 mapCalib->SetDetector(k,readMap[k][4]);
274 mapCalib->SetSector(k,readMap[k][5]);
1a1c78d4 275 // TEMPORARY!!!! Until no mapping from scaler is provided!!!!!!!
aee13a2d 276 if(k<kNScch){
277 mapCalib->SetScChannel(k, 0);
278 mapCalib->SetScDetector(k, 0);
279 mapCalib->SetScSector(k, 0);
1a1c78d4 280 }
3c159ed0 281 }
0d579f58 282 mapCalib->Print("");
321fe3b8 283 //
284 AliCDBMetaData metaData;
285 metaData.SetBeamPeriod(0);
81f09162 286 //metaData.SetResponsible("Chiara Oppedisano");
0d579f58 287 metaData.SetComment("Filling AliZDCChMap object");
321fe3b8 288 //
1a1c78d4 289 resChMapStore = Store("Calib","ChMap",mapCalib, &metaData, 0, kTRUE);
290 printf(" Mapping object stored in OCDB\n");
321fe3b8 291 }
3c159ed0 292 else{
73bc3a3f 293 Log(" ZDC/Calib/ChMap entry in OCDB is valid and won't be updated");
e83c8d88 294 resChMapStore = kTRUE;
3c159ed0 295 }
0d579f58 296
aee13a2d 297 delete daqSource; daqSource=0;
6f427255 298
e83c8d88 299 if(resChMapStore==kFALSE) return 5;
aee13a2d 300 else return 0;
321fe3b8 301
302}
303
64a7c78d 304//______________________________________________________________________________________________
e83c8d88 305UInt_t AliZDCPreprocessor::ProcessppData()
64a7c78d 306{
e83c8d88 307 Bool_t resEnCal=kTRUE, resTowCal=kTRUE;
79563ba1 308
73bc3a3f 309 // *********** Energy calibration
3c159ed0 310 // --- Cheking if there is already the entry in the OCDB
5df9f417 311 AliCDBEntry *cdbEnEntry = GetFromOCDB("Calib", "EnergyCalib");
73bc3a3f 312 if(!cdbEnEntry){
dd98e862 313 Log(Form(" ZDC/Calib/EnergyCalib entry will be created"));
3c159ed0 314 // --- Initializing calibration object
73bc3a3f 315 AliCDBMetaData metaData;
316 metaData.SetBeamPeriod(0);
317 metaData.SetResponsible("Chiara Oppedisano");
3c159ed0 318 //
73bc3a3f 319 AliZDCEnCalib *eCalib = new AliZDCEnCalib("ZDC");
3c159ed0 320 for(Int_t j=0; j<6; j++) eCalib->SetEnCalib(j,1.);
73bc3a3f 321 metaData.SetComment("AliZDCEnCalib object");
322 //eCalib->Print("");
1a1c78d4 323 resEnCal = Store("Calib", "EnergyCalib", eCalib, &metaData, 0, kTRUE);
73bc3a3f 324 }
325 else{
326 // if entry exists it is still valid (=1 for all runs!)
dd98e862 327 Log(Form(" Valid ZDC/Calib/EnergyCalib object already existing in OCDB!!!"));
73bc3a3f 328 resEnCal = kTRUE;
329 }
e83c8d88 330
331 if(resEnCal==kFALSE) return 6;
332
73bc3a3f 333 //
334 // *********** Tower inter-calibration
335 // --- Cheking if there is already the entry in the OCDB
5df9f417 336 AliCDBEntry *cdbTowEntry = GetFromOCDB("Calib", "TowerCalib");
73bc3a3f 337 if(!cdbTowEntry){
338 AliZDCTowerCalib *towCalib = new AliZDCTowerCalib("ZDC");
3c159ed0 339 for(Int_t j=0; j<5; j++){
73bc3a3f 340 towCalib->SetZN1EqualCoeff(j, 1.);
341 towCalib->SetZP1EqualCoeff(j, 1.);
342 towCalib->SetZN2EqualCoeff(j, 1.);
343 towCalib->SetZP2EqualCoeff(j, 1.);
3c159ed0 344 }
73bc3a3f 345 //towCalib->Print("");
346 //
347 AliCDBMetaData metaData;
348 metaData.SetBeamPeriod(0);
349 metaData.SetResponsible("Chiara Oppedisano");
350 metaData.SetComment("AliZDCTowerCalib object");
351 //
1a1c78d4 352 resTowCal = Store("Calib", "TowerCalib", towCalib, &metaData, 0, kTRUE);
73bc3a3f 353 }
354 else{
355 // if entry exists it is still valid (=1 for all runs!)
dd98e862 356 Log(Form(" Valid ZDC/Calib/TowerCalib object already existing in OCDB!!!"));
73bc3a3f 357 resTowCal = kTRUE;
358 }
359
e83c8d88 360 if(resTowCal==kFALSE) return 7;
361
362 return 0;
363}
364
365//______________________________________________________________________________________________
366UInt_t AliZDCPreprocessor::ProcessCalibData()
367{
da2b6160 368 TList* daqSources = GetFileSources(kDAQ, "EMDENERGYCALIB");
e83c8d88 369 if(!daqSources){
370 AliError(Form("No sources for CALIBRATION_EMD run %d !", fRun));
da2b6160 371 return 8;
e83c8d88 372 }
da2b6160 373 Log("\t List of DAQ sources for EMDENERGYCALIB id: "); daqSources->Print();
e83c8d88 374 //
375 TIter iter2(daqSources);
376 TObjString* source = 0;
377 Int_t i=0;
da2b6160 378 Bool_t resEnCal=kTRUE, resTowCal=kTRUE;
379
e83c8d88 380 while((source = dynamic_cast<TObjString*> (iter2.Next()))){
da2b6160 381 TString stringEMDFileName = GetFile(kDAQ, "EMDENERGYCALIB", source->GetName());
e83c8d88 382 if(stringEMDFileName.Length() <= 0){
383 Log(Form("No file from source %s!", source->GetName()));
da2b6160 384 return 8;
e83c8d88 385 }
da2b6160 386 const char* emdFileName = stringEMDFileName.Data();
387 Log(Form("\t Getting file #%d: %s from %s\n",++i,emdFileName,source->GetName()));
388 //
e83c8d88 389 // --- Initializing energy calibration object
390 AliZDCEnCalib *eCalib = new AliZDCEnCalib("ZDC");
da2b6160 391 // --- Reading file with calibration data
e83c8d88 392 if(emdFileName){
393 FILE *file;
394 if((file = fopen(emdFileName,"r")) == NULL){
da2b6160 395 printf("Cannot open file %s \n",emdFileName);
396 return 8;
e83c8d88 397 }
398 Log(Form("File %s connected to process data from EM dissociation events", emdFileName));
399 //
400 Float_t fitValEMD[6];
401 for(Int_t j=0; j<6; j++){
da2b6160 402 if(j<6){
403 int iread = fscanf(file,"%f",&fitValEMD[j]);
404 if(iread==0) AliDebug(3," Failing reading daa from EMD calibration data file");
405 eCalib->SetEnCalib(j,fitValEMD[j]);
406 }
e83c8d88 407 }
408 //
409 fclose(file);
410 }
411 else{
412 Log(Form("File %s not found", emdFileName));
da2b6160 413 return 8;
e83c8d88 414 }
415 //eCalib->Print("");
416 //
417 AliCDBMetaData metaData;
418 metaData.SetBeamPeriod(0);
419 metaData.SetResponsible("Chiara Oppedisano");
420 metaData.SetComment("Filling AliZDCEnCalib object");
421 //
1a1c78d4 422 resEnCal = Store("Calib","EnergyCalib",eCalib, &metaData, 0, kTRUE);
e83c8d88 423 if(resEnCal==kFALSE) return 6;
424 }
425 delete daqSources; daqSources = 0;
da2b6160 426
427 TList* daqSourcesH = GetFileSources(kDAQ, "EMDTOWERCALIB");
e83c8d88 428 if(!daqSourcesH){
429 AliError(Form("No sources for CALIBRATION_EMD run %d !", fRun));
da2b6160 430 return 9;
e83c8d88 431 }
da2b6160 432 Log("\t List of DAQ sources for EMDTOWERCALIB id: "); daqSourcesH->Print();
e83c8d88 433 //
434 TIter iter2H(daqSourcesH);
435 TObjString* sourceH = 0;
436 Int_t iH=0;
e83c8d88 437 while((sourceH = dynamic_cast<TObjString*> (iter2H.Next()))){
da2b6160 438 TString stringtowEMDFileName = GetFile(kDAQ, "EMDTOWERCALIB", sourceH->GetName());
439 if(stringtowEMDFileName.Length() <= 0){
e83c8d88 440 Log(Form("No file from source %s!", sourceH->GetName()));
da2b6160 441 return 9;
e83c8d88 442 }
da2b6160 443 const char * towEMDFileName = stringtowEMDFileName.Data();
444 Log(Form("\t Getting file #%d: %s from source %s\n",++iH,towEMDFileName,sourceH->GetName()));
e83c8d88 445 // --- Initializing energy calibration object
446 AliZDCTowerCalib *towCalib = new AliZDCTowerCalib("ZDC");
da2b6160 447 // --- Reading file with calibration data
448 if(towEMDFileName){
e83c8d88 449 FILE *file;
da2b6160 450 if((file = fopen(towEMDFileName,"r")) == NULL){
451 printf("Cannot open file %s \n",towEMDFileName);
452 return 9;
e83c8d88 453 }
e83c8d88 454 //
455 Float_t equalCoeff[4][5];
456 for(Int_t j=0; j<4; j++){
da2b6160 457 for(Int_t k=0; k<5; k++){
458 int leggi = fscanf(file,"%f",&equalCoeff[j][k]);
459 if(leggi==0) AliDebug(3," Failing reading data from EMD calibration file");
460 if(j==0) towCalib->SetZN1EqualCoeff(k, equalCoeff[j][k]);
461 else if(j==1) towCalib->SetZP1EqualCoeff(k, equalCoeff[j][k]);
462 else if(j==2) towCalib->SetZN2EqualCoeff(k, equalCoeff[j][k]);
463 else if(j==3) towCalib->SetZP2EqualCoeff(k, equalCoeff[j][k]);
464 }
e83c8d88 465 }
466 //
467 fclose(file);
468 }
469 else{
da2b6160 470 Log(Form("File %s not found", towEMDFileName));
471 return 9;
e83c8d88 472 }
473 //towCalib->Print("");
474 //
475 AliCDBMetaData metaData;
476 metaData.SetBeamPeriod(0);
477 metaData.SetResponsible("Chiara Oppedisano");
478 metaData.SetComment("Filling AliZDCTowerCalib object");
479 //
1a1c78d4 480 resTowCal = Store("Calib","TowerCalib",towCalib, &metaData, 0, kTRUE);
e83c8d88 481 if(resTowCal==kFALSE) return 7;
482 }
da2b6160 483 delete daqSourcesH; daqSourcesH = 0;
e83c8d88 484
da2b6160 485
e83c8d88 486 return 0;
487}
488
489//______________________________________________________________________________________________
490UInt_t AliZDCPreprocessor::ProcessPedestalData()
491{
73bc3a3f 492 TList* daqSources = GetFileSources(kDAQ, "PEDESTALDATA");
cb50c7c8 493 if(!daqSources){
78e8a1cc 494 Log(Form("No source for STANDALONE_PEDESTAL run %d !", fRun));
da2b6160 495 return 10;
79563ba1 496 }
da2b6160 497 if(daqSources->GetEntries()==0) return 10;
498 Log("\t List of DAQ sources for PEDESTALDATA id: "); daqSources->Print();
79563ba1 499 //
cb50c7c8 500 TIter iter(daqSources);
da2b6160 501 TObjString* source;
79563ba1 502 Int_t i=0;
da2b6160 503 Bool_t resPedCal=kTRUE, resPedHist=kTRUE;
504
cb50c7c8 505 while((source = dynamic_cast<TObjString*> (iter.Next()))){
73bc3a3f 506 TString stringPedFileName = GetFile(kDAQ, "PEDESTALDATA", source->GetName());
507 if(stringPedFileName.Length() <= 0){
da2b6160 508 Log(Form("No PEDESTALDATA file from source %s!", source->GetName()));
509 return 10;
73bc3a3f 510 }
da2b6160 511 const char* pedFileName = stringPedFileName.Data();
512 Log(Form("\t Getting file #%d: %s from %s\n",++i,pedFileName,source->GetName()));
513 //
e83c8d88 514 // --- Initializing pedestal calibration object
515 AliZDCPedestals *pedCalib = new AliZDCPedestals("ZDC");
516 // --- Reading file with pedestal calibration data
e83c8d88 517 // no. ADCch = (22 signal ch. + 2 reference PMs) * 2 gain chain = 48
518 const Int_t knZDCch = 48;
e83c8d88 519 FILE *file;
520 if((file = fopen(pedFileName,"r")) == NULL){
521 printf("Cannot open file %s \n",pedFileName);
da2b6160 522 return 10;
e83c8d88 523 }
524 Log(Form("File %s connected to process pedestal data", pedFileName));
525 Float_t pedVal[(2*knZDCch)][2];
526 for(Int_t k=0; k<(2*knZDCch); k++){
da2b6160 527 for(Int_t j=0; j<2; j++){
528 int aleggi = fscanf(file,"%f",&pedVal[k][j]);
529 if(aleggi==0) AliDebug(3," Failing reading data from pedestal file");
530 //if(j==1) printf("pedVal[%d] -> %f, %f \n",k,pedVal[k][0],pedVal[k][1]);
531 }
532 if(k<knZDCch){
533 pedCalib->SetMeanPed(k,pedVal[k][0]);
534 pedCalib->SetMeanPedWidth(k,pedVal[k][1]);
535 }
536 else if(k>=knZDCch && k<(2*knZDCch)){
537 pedCalib->SetOOTPed(k-knZDCch,pedVal[k][0]);
538 pedCalib->SetOOTPedWidth(k-knZDCch,pedVal[k][1]);
539 }
540 else if(k>=(2*knZDCch) && k<(3*knZDCch)){
541 pedCalib->SetPedCorrCoeff(k-(2*knZDCch),pedVal[k][0],pedVal[k][1]);
542 }
e83c8d88 543 }
544 fclose(file);
545 //pedCalib->Print("");
546 //
547 AliCDBMetaData metaData;
548 metaData.SetBeamPeriod(0);
549 metaData.SetResponsible("Chiara Oppedisano");
550 metaData.SetComment("Filling AliZDCPedestals object");
551 //
1a1c78d4 552 resPedCal = Store("Calib","Pedestals",pedCalib, &metaData, 0, kTRUE);
da2b6160 553 if(resPedCal==kFALSE) return 11;
64a7c78d 554 }
cb50c7c8 555 delete daqSources; daqSources = 0;
da2b6160 556
557 TList* daqSourceH = GetFileSources(kDAQ, "PEDESTALHISTOS");
73bc3a3f 558 if(!daqSourceH){
da2b6160 559 Log(Form("No source for PEDESTALHISTOS id run %d !", fRun));
560 return 12;
73bc3a3f 561 }
da2b6160 562 Log("\t List of DAQ sources for PEDESTALHISTOS id: "); daqSourceH->Print();
73bc3a3f 563 //
564 TIter iterH(daqSourceH);
565 TObjString* sourceH = 0;
566 Int_t iH=0;
567 while((sourceH = dynamic_cast<TObjString*> (iterH.Next()))){
da2b6160 568 TString stringPedFileName = GetFile(kDAQ, "PEDESTALHISTOS", sourceH->GetName());
73bc3a3f 569 if(stringPedFileName.Length() <= 0){
da2b6160 570 Log(Form("No PEDESTALHISTOS file from source %s!", sourceH->GetName()));
571 return 12;
73bc3a3f 572 }
da2b6160 573 const char* pedFileName = stringPedFileName.Data();
574 Log(Form("\t Getting file #%d: %s from %s\n",++iH, pedFileName, sourceH->GetName()));
575 resPedHist = StoreReferenceFile(pedFileName, "pedestalReference.root");
576 if(resPedHist==kFALSE) return 13;
73bc3a3f 577 }
da2b6160 578 delete daqSourceH; daqSourceH=0;
e83c8d88 579
580 return 0;
581}
582
583//______________________________________________________________________________________________
584UInt_t AliZDCPreprocessor::ProcessLaserData()
585{
73bc3a3f 586 TList* daqSources = GetFileSources(kDAQ, "LASERDATA");
1ee299a5 587 if(!daqSources){
588 AliError(Form("No sources for STANDALONE_LASER run %d !", fRun));
da2b6160 589 return 14;
1ee299a5 590 }
da2b6160 591 if(daqSources->GetEntries()==0) return 14;
592 Log("\t List of DAQ sources for LASERDATA id: "); daqSources->Print();
1ee299a5 593 //
594 TIter iter2(daqSources);
595 TObjString* source = 0;
596 Int_t i=0;
da2b6160 597 Bool_t resLaserCal=kTRUE, resLaserHist=kTRUE;
598
1ee299a5 599 while((source = dynamic_cast<TObjString*> (iter2.Next()))){
da2b6160 600 TString stringLaserFileName = GetFile(kDAQ, "LASERDATA", source->GetName());
601 if(stringLaserFileName.Length() <= 0){
73bc3a3f 602 Log(Form("No LASER file from source %s!", source->GetName()));
da2b6160 603 return 14;
73bc3a3f 604 }
da2b6160 605 const char* laserFileName = stringLaserFileName.Data();
606 Log(Form("\t Getting file #%d: %s from %s\n",++i,laserFileName,source->GetName()));
607 //
73bc3a3f 608 // --- Initializing pedestal calibration object
609 AliZDCLaserCalib *lCalib = new AliZDCLaserCalib("ZDC");
610 // --- Reading file with pedestal calibration data
73bc3a3f 611 if(laserFileName){
612 FILE *file;
613 if((file = fopen(laserFileName,"r")) == NULL){
614 printf("Cannot open file %s \n",laserFileName);
da2b6160 615 return 14;
1ee299a5 616 }
73bc3a3f 617 Log(Form("File %s connected to process data from LASER events", laserFileName));
1ee299a5 618 //
73bc3a3f 619 Float_t ivalRead[22][4];
620 for(Int_t j=0; j<22; j++){
da2b6160 621 for(Int_t k=0; k<4; k++){
622 int aleggi = fscanf(file,"%f",&ivalRead[j][k]);
623 if(aleggi==0) AliDebug(3," Failng reading data from laser file");
73bc3a3f 624 //printf(" %d %1.0f ",k, ivalRead[j][k]);
625 }
626 lCalib->SetDetector(j, (Int_t) ivalRead[j][0]);
627 lCalib->SetSector(j, (Int_t) ivalRead[j][1]);
628 lCalib->SetfPMValue(j, ivalRead[j][2]);
629 lCalib->SetfPMWidth(j, ivalRead[j][3]);
630 }
631 fclose(file);
632 }
633 else{
634 Log(Form("File %s not found", laserFileName));
da2b6160 635 return 14;
73bc3a3f 636 }
637 //lCalib->Print("");
638 //
639 AliCDBMetaData metaData;
640 metaData.SetBeamPeriod(0);
641 metaData.SetResponsible("Chiara Oppedisano");
642 metaData.SetComment("Filling AliZDCLaserCalib object");
643 //
1a1c78d4 644 resLaserCal = Store("Calib","LaserCalib",lCalib, &metaData, 0, kTRUE);
da2b6160 645 if(resLaserCal==kFALSE) return 15;
1ee299a5 646 }
73bc3a3f 647 delete daqSources; daqSources = 0;
da2b6160 648
73bc3a3f 649 TList* daqSourceH = GetFileSources(kDAQ, "LASERHISTOS");
650 if(!daqSourceH){
651 AliError(Form("No sources for STANDALONE_LASER run %d !", fRun));
da2b6160 652 return 16;
73bc3a3f 653 }
da2b6160 654 Log("\t List of DAQ sources for LASERHISTOS id: "); daqSourceH->Print();
73bc3a3f 655 //
656 TIter iter2H(daqSourceH);
657 TObjString* sourceH = 0;
658 Int_t iH=0;
659 while((sourceH = dynamic_cast<TObjString*> (iter2H.Next()))){
da2b6160 660 Log(Form("\t Getting file #%d\n",++iH));
661 TString stringLaserFileName = GetFile(kDAQ, "LASERHISTOS", sourceH->GetName());
662 if(stringLaserFileName.Length() <= 0){
73bc3a3f 663 Log(Form("No LASER file from source %s!", sourceH->GetName()));
da2b6160 664 return 16;
73bc3a3f 665 }
da2b6160 666 resLaserHist = StoreReferenceFile(stringLaserFileName.Data(), "laserReference.root");
e83c8d88 667 //
da2b6160 668 if(resLaserHist==kFALSE) return 17;
73bc3a3f 669 }
670 delete daqSourceH; daqSourceH = 0;
e83c8d88 671
672 return 0;
673}
674
0d579f58 675
676//______________________________________________________________________________________________
677UInt_t AliZDCPreprocessor::ProcessMBCalibData()
678{
679 TList* daqSources = GetFileSources(kDAQ, "MBCALIB");
680 if(!daqSources){
681 AliError(Form("No sources for CALIBRATION_MB run %d !", fRun));
682 return 18;
683 }
684 if(daqSources->GetEntries()==0) return 18;
685 Log("\t List of DAQ sources for MBCALIB id: "); daqSources->Print();
686 //
687 TIter iter2(daqSources);
688 TObjString* source = 0;
689 Int_t i=0;
690 Bool_t resMBCal=kTRUE;
691
692 while((source = dynamic_cast<TObjString*> (iter2.Next()))){
693 TString stringMBFileName = GetFile(kDAQ, "MBCALIB", source->GetName());
694 if(stringMBFileName.Length() <= 0){
695 Log(Form("No MBCALIB file from source %s!", source->GetName()));
696 return 18;
697 }
698 const char* mbFileName = stringMBFileName.Data();
699 Log(Form("\t Getting file #%d: %s from %s\n",++i,mbFileName,source->GetName()));
700 //
701 // --- Initializing calibration object
702 AliZDCMBCalib *mbCalib = new AliZDCMBCalib("ZDC");
703 // --- Reading file with calibration data
704 if(mbFileName){
705 TFile * fileHistos = TFile::Open(mbFileName);
706 Log(Form("File %s connected to process data from CALIBRATION_MB events", mbFileName));
707 //
708 fileHistos->cd();
709 TH2F *hZDCvsZEM = (TH2F*) fileHistos->Get("hZDCvsZEM");
710 TH2F *hZDCCvsZEM = (TH2F*) fileHistos->Get("hZDCCvsZEM");
711 TH2F *hZDCAvsZEM = (TH2F*) fileHistos->Get("hZDCAvsZEM");
712 //
713 mbCalib->SetZDCvsZEM(hZDCvsZEM);
714 mbCalib->SetZDCCvsZEM(hZDCCvsZEM);
715 mbCalib->SetZDCAvsZEM(hZDCAvsZEM);
716 //
717 //fileHistos->Close();
718 }
719 else{
720 Log(Form("File %s not found", mbFileName));
721 return 14;
722 }
723 //
724 AliCDBMetaData metaData;
725 metaData.SetBeamPeriod(0);
726 metaData.SetResponsible("Chiara Oppedisano");
727 metaData.SetComment("Filling AliZDCMBCalib object");
728 //
729 //mbCalib->Dump();
730 //
731 resMBCal = Store("Calib","MBCalib",mbCalib, &metaData, 0, kTRUE);
732 printf(" here 1000\n");
733 if(resMBCal==kFALSE) return 19;
734 }
735 delete daqSources; daqSources = 0;
736
737 return 0;
738}
739
e83c8d88 740//______________________________________________________________________________________________
741UInt_t AliZDCPreprocessor::Process(TMap* dcsAliasMap)
742{
743 UInt_t resDCS = 0;
744 UInt_t resChMap=0;
0d579f58 745 UInt_t resEnergyCalib=0, resPedestalCalib=0, resLaserCalib=0, resMBCalib=0;
e83c8d88 746
747 // ************************* Process DCS data ****************************
748 if(ProcessDCS()) resDCS = ProcessDCSData(dcsAliasMap);
749
750 // ********************************* From DAQ ************************************
751
752 const char* beamType = GetRunParameter("beamType");
753 TString runType = GetRunType();
da2b6160 754 printf("\t **** AliZDCPreprocessor -> beamType %s, runType %s ****\n",beamType,runType.Data());
e83c8d88 755
756 // ******************************************
0d579f58 757 // ADC channel mapping
e83c8d88 758 // ******************************************
da2b6160 759 resChMap = ProcessChMap();
e83c8d88 760
761 // ******************************************
0d579f58 762 // Calibration param. for p-p data (all = 1)
e83c8d88 763 // ******************************************
764 // NO ENERGY CALIBRATION -> coefficients set to 1.
765 // Temp -> also inter-calibration coefficients are set to 1.
da2b6160 766 if((strcmp(beamType,"p-p")==0) || (strcmp(beamType,"P-P")==0)) resEnergyCalib = ProcessppData();
e83c8d88 767
b8d194f5 768 // *****************************************************
0d579f58 769 // CALIBRATION_EMD -> Energy calibration and equalization
b8d194f5 770 // *****************************************************
0d579f58 771 if((strcmp(beamType,"A-A")==0) && (runType.CompareTo("CALIBRATION_EMD")==0))
e83c8d88 772 resEnergyCalib = ProcessCalibData();
773
774 // *****************************************************
775 // STANDALONE_PEDESTALS -> Pedestal subtraction
776 // *****************************************************
da2b6160 777 if(runType.CompareTo("STANDALONE_PEDESTAL")==0) resPedestalCalib = ProcessPedestalData();
e83c8d88 778
779 // *****************************************************
780 // STANDALONE_LASER -> Signal stability and ageing
781 // *****************************************************
0d579f58 782 else if(runType.CompareTo("STANDALONE_LASER")==0) resLaserCalib = ProcessLaserData();
783
784 // *****************************************************
785 // CALIBRATION_MB -> Signal stability and ageing
786 // *****************************************************
787 else if(runType.CompareTo("CALIBRATION_MB")==0) resMBCalib = ProcessMBCalibData();
e83c8d88 788
028eb4a1 789
e83c8d88 790 if(resDCS!=0) return resDCS;
791 else if(resChMap!=0) return resChMap;
792 else if(resEnergyCalib!=0) return resEnergyCalib;
793 else if(resPedestalCalib!=0) return resPedestalCalib;
794 else if(resLaserCalib!=0) return resLaserCalib;
0d579f58 795 else if(resMBCalib!=0) return resMBCalib;
79563ba1 796
e83c8d88 797 return 0;
cb50c7c8 798
64a7c78d 799}