]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ZDC/AliZDCPreprocessor.cxx
Adding TDC histos
[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{
82dffa48 193 const int kNModules=10, kNch=48, kNScch=32, kNtdcch=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;
82dffa48 207 Int_t modMap[kNModules][3], adcMap[kNch][6], scMap[kNScch][6], tdcMap[kNtdcch][4];
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 //
608444fb 227 for(Int_t j=0; j<kNch; j++){
228 for(Int_t k=0; k<6; k++){
229 int read = fscanf(file,"%d",&adcMap[j][k]);
198f612a 230 if(read == 0) AliDebug(3," Failing in reading data from mapping file");
231 }
232 }
608444fb 233 for(Int_t j=kNch; j<kNch+kNScch; j++){
198f612a 234 for(Int_t k=0; k<6; k++){
608444fb 235 int read = fscanf(file,"%d",&scMap[j-kNch][k]);
198f612a 236 if(read == 0) AliDebug(3," Failing in reading data from mapping file");
237 }
238 }
82dffa48 239 for(Int_t j=kNch+kNScch; j<kNch+kNScch+kNtdcch; j++){
240 for(Int_t k=0; k<4; k++){
241 int read = fscanf(file,"%d",&tdcMap[j-kNch-kNScch][k]);
242 if(read == 0) AliDebug(3," Failing in reading data from mapping file");
243 }
244 }
245 for(Int_t j=kNch+kNScch+kNtdcch; j<kNch+kNScch+kNtdcch+kNModules; j++){
608444fb 246 for(Int_t k=0; k<3; k++){
82dffa48 247 int read = fscanf(file,"%d",&modMap[j-kNch-kNScch-kNtdcch][k]);
e83c8d88 248 if(read == 0) AliDebug(3," Failing in reading data from mapping file");
321fe3b8 249 }
321fe3b8 250 }
251 fclose(file);
252 }
253 else{
c00e895a 254 Log(Form("File %s not found", fileName.Data()));
e83c8d88 255 return 4;
321fe3b8 256 }
3c159ed0 257 }
3c159ed0 258
259 // Store the currently read map ONLY IF it is different
260 // from the entry in the OCDB
82dffa48 261 Bool_t adcMapUpdated=kFALSE, scMapUpdated=kFALSE, tdcMapUpdated=kFALSE;
3c159ed0 262 Bool_t updateOCDB = kFALSE;
263
264 AliCDBEntry *cdbEntry = GetFromOCDB("Calib","ChMap");
265 if(!cdbEntry){
73bc3a3f 266 Log(" No existing CDB entry for ADC mapping");
3c159ed0 267 updateOCDB = kTRUE;
268 }
269 else{
270 AliZDCChMap *chMap = (AliZDCChMap*) cdbEntry->GetObject();
e83c8d88 271 for(Int_t i=0; i<kNch; i++){
ba3ffd74 272 if( (adcMap[i][1] != chMap->GetADCModule(i))
273 || (adcMap[i][2] != chMap->GetADCChannel(i))
216a94dd 274 || (adcMap[i][3] != chMap->GetADCSignalCode(i))
ba3ffd74 275 || (adcMap[i][4] != chMap->GetDetector(i))
276 || (adcMap[i][5] != chMap->GetSector(i)))
277 adcMapUpdated = kTRUE;
198f612a 278 }
279 for(Int_t i=0; i<kNScch; i++){
ba3ffd74 280 if( (scMap[i][2] != chMap->GetScChannel(i))
216a94dd 281 || (scMap[i][3] != chMap->GetScSignalCode(i)) )
ba3ffd74 282 scMapUpdated = kTRUE;
3c159ed0 283 }
82dffa48 284 for(Int_t i=0; i<kNtdcch; i++){
285 if( (tdcMap[i][2] != chMap->GetTDCChannel(i))
286 || (tdcMap[i][3] != chMap->GetTDCSignalCode(i)))
287 tdcMapUpdated = kTRUE;
288 }
3c159ed0 289 }
82dffa48 290 if(adcMapUpdated || scMapUpdated || tdcMapUpdated) updateOCDB = kTRUE;
0d579f58 291 //
e83c8d88 292 Bool_t resChMapStore = kTRUE;
3c159ed0 293 if(updateOCDB==kTRUE){
73bc3a3f 294 Log(" A new entry ZDC/Calib/ChMap will be created");
3c159ed0 295 //
296 // --- Initializing mapping calibration object
297 AliZDCChMap *mapCalib = new AliZDCChMap("ZDC");
298 // Writing channel map in the OCDB
198f612a 299 for(Int_t k=0; k<kNModules; k++){
300 mapCalib->SetModuleMap(k, modMap[k][0], modMap[k][1], modMap[k][2]);
301 }
e83c8d88 302 for(Int_t k=0; k<kNch; k++){
198f612a 303 mapCalib->SetADCModule(k,adcMap[k][1]);
304 mapCalib->SetADCChannel(k,adcMap[k][2]);
82dffa48 305 mapCalib->SetADCSignalCode(k,adcMap[k][3]);
198f612a 306 mapCalib->SetDetector(k,adcMap[k][4]);
307 mapCalib->SetSector(k,adcMap[k][5]);
308 }
309 for(Int_t k=0; k<kNScch; k++){
7d1d8256 310 mapCalib->SetScChannel(k, scMap[k][2]);
82dffa48 311 mapCalib->SetScSignalCode(k, scMap[k][3]);
7d1d8256 312 mapCalib->SetScDetector(k, scMap[k][4]);
313 mapCalib->SetScSector(k, scMap[k][5]);
3c159ed0 314 }
82dffa48 315 for(Int_t k=0; k<kNtdcch; k++){
316 mapCalib->SetTDCChannel(k, tdcMap[k][2]);
317 mapCalib->SetTDCSignalCode(k, tdcMap[k][3]);
318 }
198f612a 319 //
216a94dd 320 //mapCalib->Print("");
321fe3b8 321 //
322 AliCDBMetaData metaData;
323 metaData.SetBeamPeriod(0);
198f612a 324 metaData.SetResponsible("Chiara Oppedisano");
82dffa48 325 metaData.SetComment("AliZDCChMap object created by ZDC preprocessor");
321fe3b8 326 //
1a1c78d4 327 resChMapStore = Store("Calib","ChMap",mapCalib, &metaData, 0, kTRUE);
328 printf(" Mapping object stored in OCDB\n");
321fe3b8 329 }
3c159ed0 330 else{
73bc3a3f 331 Log(" ZDC/Calib/ChMap entry in OCDB is valid and won't be updated");
e83c8d88 332 resChMapStore = kTRUE;
3c159ed0 333 }
0d579f58 334
aee13a2d 335 delete daqSource; daqSource=0;
6f427255 336
e83c8d88 337 if(resChMapStore==kFALSE) return 5;
aee13a2d 338 else return 0;
321fe3b8 339
340}
341
64a7c78d 342//______________________________________________________________________________________________
e83c8d88 343UInt_t AliZDCPreprocessor::ProcessppData()
64a7c78d 344{
e83c8d88 345 Bool_t resEnCal=kTRUE, resTowCal=kTRUE;
79563ba1 346
73bc3a3f 347 // *********** Energy calibration
3c159ed0 348 // --- Cheking if there is already the entry in the OCDB
5df9f417 349 AliCDBEntry *cdbEnEntry = GetFromOCDB("Calib", "EnergyCalib");
73bc3a3f 350 if(!cdbEnEntry){
dd98e862 351 Log(Form(" ZDC/Calib/EnergyCalib entry will be created"));
3c159ed0 352 // --- Initializing calibration object
73bc3a3f 353 AliCDBMetaData metaData;
354 metaData.SetBeamPeriod(0);
355 metaData.SetResponsible("Chiara Oppedisano");
3c159ed0 356 //
73bc3a3f 357 AliZDCEnCalib *eCalib = new AliZDCEnCalib("ZDC");
3c159ed0 358 for(Int_t j=0; j<6; j++) eCalib->SetEnCalib(j,1.);
73bc3a3f 359 metaData.SetComment("AliZDCEnCalib object");
360 //eCalib->Print("");
1a1c78d4 361 resEnCal = Store("Calib", "EnergyCalib", eCalib, &metaData, 0, kTRUE);
73bc3a3f 362 }
363 else{
364 // if entry exists it is still valid (=1 for all runs!)
dd98e862 365 Log(Form(" Valid ZDC/Calib/EnergyCalib object already existing in OCDB!!!"));
73bc3a3f 366 resEnCal = kTRUE;
367 }
e83c8d88 368
369 if(resEnCal==kFALSE) return 6;
370
73bc3a3f 371 //
372 // *********** Tower inter-calibration
373 // --- Cheking if there is already the entry in the OCDB
5df9f417 374 AliCDBEntry *cdbTowEntry = GetFromOCDB("Calib", "TowerCalib");
73bc3a3f 375 if(!cdbTowEntry){
376 AliZDCTowerCalib *towCalib = new AliZDCTowerCalib("ZDC");
3c159ed0 377 for(Int_t j=0; j<5; j++){
73bc3a3f 378 towCalib->SetZN1EqualCoeff(j, 1.);
379 towCalib->SetZP1EqualCoeff(j, 1.);
380 towCalib->SetZN2EqualCoeff(j, 1.);
381 towCalib->SetZP2EqualCoeff(j, 1.);
3c159ed0 382 }
73bc3a3f 383 //towCalib->Print("");
384 //
385 AliCDBMetaData metaData;
386 metaData.SetBeamPeriod(0);
387 metaData.SetResponsible("Chiara Oppedisano");
388 metaData.SetComment("AliZDCTowerCalib object");
389 //
1a1c78d4 390 resTowCal = Store("Calib", "TowerCalib", towCalib, &metaData, 0, kTRUE);
73bc3a3f 391 }
392 else{
393 // if entry exists it is still valid (=1 for all runs!)
dd98e862 394 Log(Form(" Valid ZDC/Calib/TowerCalib object already existing in OCDB!!!"));
73bc3a3f 395 resTowCal = kTRUE;
396 }
397
e83c8d88 398 if(resTowCal==kFALSE) return 7;
399
400 return 0;
401}
402
403//______________________________________________________________________________________________
2c62f191 404UInt_t AliZDCPreprocessor::ProcessCalibData(Float_t beamEnergy)
e83c8d88 405{
da2b6160 406 TList* daqSources = GetFileSources(kDAQ, "EMDENERGYCALIB");
e83c8d88 407 if(!daqSources){
408 AliError(Form("No sources for CALIBRATION_EMD run %d !", fRun));
da2b6160 409 return 8;
e83c8d88 410 }
da2b6160 411 Log("\t List of DAQ sources for EMDENERGYCALIB id: "); daqSources->Print();
e83c8d88 412 //
413 TIter iter2(daqSources);
414 TObjString* source = 0;
415 Int_t i=0;
da2b6160 416 Bool_t resEnCal=kTRUE, resTowCal=kTRUE;
417
e83c8d88 418 while((source = dynamic_cast<TObjString*> (iter2.Next()))){
da2b6160 419 TString stringEMDFileName = GetFile(kDAQ, "EMDENERGYCALIB", source->GetName());
e83c8d88 420 if(stringEMDFileName.Length() <= 0){
421 Log(Form("No file from source %s!", source->GetName()));
da2b6160 422 return 8;
e83c8d88 423 }
da2b6160 424 const char* emdFileName = stringEMDFileName.Data();
425 Log(Form("\t Getting file #%d: %s from %s\n",++i,emdFileName,source->GetName()));
426 //
e83c8d88 427 // --- Initializing energy calibration object
428 AliZDCEnCalib *eCalib = new AliZDCEnCalib("ZDC");
da2b6160 429 // --- Reading file with calibration data
e83c8d88 430 if(emdFileName){
431 FILE *file;
432 if((file = fopen(emdFileName,"r")) == NULL){
da2b6160 433 printf("Cannot open file %s \n",emdFileName);
434 return 8;
e83c8d88 435 }
436 Log(Form("File %s connected to process data from EM dissociation events", emdFileName));
437 //
438 Float_t fitValEMD[6];
439 for(Int_t j=0; j<6; j++){
da2b6160 440 if(j<6){
441 int iread = fscanf(file,"%f",&fitValEMD[j]);
442 if(iread==0) AliDebug(3," Failing reading daa from EMD calibration data file");
2c62f191 443 eCalib->SetEnCalib(j, beamEnergy/fitValEMD[j]);
da2b6160 444 }
e83c8d88 445 }
446 //
447 fclose(file);
448 }
449 else{
450 Log(Form("File %s not found", emdFileName));
da2b6160 451 return 8;
e83c8d88 452 }
453 //eCalib->Print("");
454 //
455 AliCDBMetaData metaData;
456 metaData.SetBeamPeriod(0);
457 metaData.SetResponsible("Chiara Oppedisano");
458 metaData.SetComment("Filling AliZDCEnCalib object");
459 //
1a1c78d4 460 resEnCal = Store("Calib","EnergyCalib",eCalib, &metaData, 0, kTRUE);
e83c8d88 461 if(resEnCal==kFALSE) return 6;
462 }
463 delete daqSources; daqSources = 0;
da2b6160 464
465 TList* daqSourcesH = GetFileSources(kDAQ, "EMDTOWERCALIB");
e83c8d88 466 if(!daqSourcesH){
467 AliError(Form("No sources for CALIBRATION_EMD run %d !", fRun));
da2b6160 468 return 9;
e83c8d88 469 }
da2b6160 470 Log("\t List of DAQ sources for EMDTOWERCALIB id: "); daqSourcesH->Print();
e83c8d88 471 //
472 TIter iter2H(daqSourcesH);
473 TObjString* sourceH = 0;
474 Int_t iH=0;
e83c8d88 475 while((sourceH = dynamic_cast<TObjString*> (iter2H.Next()))){
da2b6160 476 TString stringtowEMDFileName = GetFile(kDAQ, "EMDTOWERCALIB", sourceH->GetName());
477 if(stringtowEMDFileName.Length() <= 0){
e83c8d88 478 Log(Form("No file from source %s!", sourceH->GetName()));
da2b6160 479 return 9;
e83c8d88 480 }
da2b6160 481 const char * towEMDFileName = stringtowEMDFileName.Data();
482 Log(Form("\t Getting file #%d: %s from source %s\n",++iH,towEMDFileName,sourceH->GetName()));
e83c8d88 483 // --- Initializing energy calibration object
484 AliZDCTowerCalib *towCalib = new AliZDCTowerCalib("ZDC");
da2b6160 485 // --- Reading file with calibration data
486 if(towEMDFileName){
e83c8d88 487 FILE *file;
da2b6160 488 if((file = fopen(towEMDFileName,"r")) == NULL){
489 printf("Cannot open file %s \n",towEMDFileName);
490 return 9;
e83c8d88 491 }
e83c8d88 492 //
493 Float_t equalCoeff[4][5];
494 for(Int_t j=0; j<4; j++){
da2b6160 495 for(Int_t k=0; k<5; k++){
496 int leggi = fscanf(file,"%f",&equalCoeff[j][k]);
497 if(leggi==0) AliDebug(3," Failing reading data from EMD calibration file");
498 if(j==0) towCalib->SetZN1EqualCoeff(k, equalCoeff[j][k]);
499 else if(j==1) towCalib->SetZP1EqualCoeff(k, equalCoeff[j][k]);
500 else if(j==2) towCalib->SetZN2EqualCoeff(k, equalCoeff[j][k]);
501 else if(j==3) towCalib->SetZP2EqualCoeff(k, equalCoeff[j][k]);
502 }
e83c8d88 503 }
504 //
505 fclose(file);
506 }
507 else{
da2b6160 508 Log(Form("File %s not found", towEMDFileName));
509 return 9;
e83c8d88 510 }
511 //towCalib->Print("");
512 //
513 AliCDBMetaData metaData;
514 metaData.SetBeamPeriod(0);
515 metaData.SetResponsible("Chiara Oppedisano");
516 metaData.SetComment("Filling AliZDCTowerCalib object");
517 //
1a1c78d4 518 resTowCal = Store("Calib","TowerCalib",towCalib, &metaData, 0, kTRUE);
e83c8d88 519 if(resTowCal==kFALSE) return 7;
520 }
da2b6160 521 delete daqSourcesH; daqSourcesH = 0;
e83c8d88 522
da2b6160 523
e83c8d88 524 return 0;
525}
526
527//______________________________________________________________________________________________
528UInt_t AliZDCPreprocessor::ProcessPedestalData()
529{
73bc3a3f 530 TList* daqSources = GetFileSources(kDAQ, "PEDESTALDATA");
cb50c7c8 531 if(!daqSources){
78e8a1cc 532 Log(Form("No source for STANDALONE_PEDESTAL run %d !", fRun));
da2b6160 533 return 10;
79563ba1 534 }
da2b6160 535 if(daqSources->GetEntries()==0) return 10;
536 Log("\t List of DAQ sources for PEDESTALDATA id: "); daqSources->Print();
79563ba1 537 //
cb50c7c8 538 TIter iter(daqSources);
da2b6160 539 TObjString* source;
79563ba1 540 Int_t i=0;
da2b6160 541 Bool_t resPedCal=kTRUE, resPedHist=kTRUE;
542
cb50c7c8 543 while((source = dynamic_cast<TObjString*> (iter.Next()))){
73bc3a3f 544 TString stringPedFileName = GetFile(kDAQ, "PEDESTALDATA", source->GetName());
545 if(stringPedFileName.Length() <= 0){
da2b6160 546 Log(Form("No PEDESTALDATA file from source %s!", source->GetName()));
547 return 10;
73bc3a3f 548 }
da2b6160 549 const char* pedFileName = stringPedFileName.Data();
550 Log(Form("\t Getting file #%d: %s from %s\n",++i,pedFileName,source->GetName()));
551 //
e83c8d88 552 // --- Initializing pedestal calibration object
553 AliZDCPedestals *pedCalib = new AliZDCPedestals("ZDC");
554 // --- Reading file with pedestal calibration data
e83c8d88 555 // no. ADCch = (22 signal ch. + 2 reference PMs) * 2 gain chain = 48
556 const Int_t knZDCch = 48;
e83c8d88 557 FILE *file;
558 if((file = fopen(pedFileName,"r")) == NULL){
559 printf("Cannot open file %s \n",pedFileName);
da2b6160 560 return 10;
e83c8d88 561 }
562 Log(Form("File %s connected to process pedestal data", pedFileName));
796c8b58 563 Float_t pedVal[(3*knZDCch)][2];
e83c8d88 564 for(Int_t k=0; k<(2*knZDCch); k++){
da2b6160 565 for(Int_t j=0; j<2; j++){
566 int aleggi = fscanf(file,"%f",&pedVal[k][j]);
567 if(aleggi==0) AliDebug(3," Failing reading data from pedestal file");
568 //if(j==1) printf("pedVal[%d] -> %f, %f \n",k,pedVal[k][0],pedVal[k][1]);
569 }
570 if(k<knZDCch){
571 pedCalib->SetMeanPed(k,pedVal[k][0]);
572 pedCalib->SetMeanPedWidth(k,pedVal[k][1]);
573 }
574 else if(k>=knZDCch && k<(2*knZDCch)){
575 pedCalib->SetOOTPed(k-knZDCch,pedVal[k][0]);
576 pedCalib->SetOOTPedWidth(k-knZDCch,pedVal[k][1]);
577 }
578 else if(k>=(2*knZDCch) && k<(3*knZDCch)){
579 pedCalib->SetPedCorrCoeff(k-(2*knZDCch),pedVal[k][0],pedVal[k][1]);
580 }
e83c8d88 581 }
582 fclose(file);
583 //pedCalib->Print("");
584 //
585 AliCDBMetaData metaData;
586 metaData.SetBeamPeriod(0);
587 metaData.SetResponsible("Chiara Oppedisano");
588 metaData.SetComment("Filling AliZDCPedestals object");
589 //
1a1c78d4 590 resPedCal = Store("Calib","Pedestals",pedCalib, &metaData, 0, kTRUE);
da2b6160 591 if(resPedCal==kFALSE) return 11;
64a7c78d 592 }
cb50c7c8 593 delete daqSources; daqSources = 0;
da2b6160 594
595 TList* daqSourceH = GetFileSources(kDAQ, "PEDESTALHISTOS");
73bc3a3f 596 if(!daqSourceH){
da2b6160 597 Log(Form("No source for PEDESTALHISTOS id run %d !", fRun));
598 return 12;
73bc3a3f 599 }
da2b6160 600 Log("\t List of DAQ sources for PEDESTALHISTOS id: "); daqSourceH->Print();
73bc3a3f 601 //
602 TIter iterH(daqSourceH);
603 TObjString* sourceH = 0;
604 Int_t iH=0;
605 while((sourceH = dynamic_cast<TObjString*> (iterH.Next()))){
da2b6160 606 TString stringPedFileName = GetFile(kDAQ, "PEDESTALHISTOS", sourceH->GetName());
73bc3a3f 607 if(stringPedFileName.Length() <= 0){
da2b6160 608 Log(Form("No PEDESTALHISTOS file from source %s!", sourceH->GetName()));
609 return 12;
73bc3a3f 610 }
da2b6160 611 const char* pedFileName = stringPedFileName.Data();
612 Log(Form("\t Getting file #%d: %s from %s\n",++iH, pedFileName, sourceH->GetName()));
613 resPedHist = StoreReferenceFile(pedFileName, "pedestalReference.root");
614 if(resPedHist==kFALSE) return 13;
73bc3a3f 615 }
da2b6160 616 delete daqSourceH; daqSourceH=0;
e83c8d88 617
618 return 0;
619}
620
621//______________________________________________________________________________________________
622UInt_t AliZDCPreprocessor::ProcessLaserData()
623{
73bc3a3f 624 TList* daqSources = GetFileSources(kDAQ, "LASERDATA");
1ee299a5 625 if(!daqSources){
626 AliError(Form("No sources for STANDALONE_LASER run %d !", fRun));
da2b6160 627 return 14;
1ee299a5 628 }
da2b6160 629 if(daqSources->GetEntries()==0) return 14;
630 Log("\t List of DAQ sources for LASERDATA id: "); daqSources->Print();
1ee299a5 631 //
632 TIter iter2(daqSources);
633 TObjString* source = 0;
634 Int_t i=0;
da2b6160 635 Bool_t resLaserCal=kTRUE, resLaserHist=kTRUE;
636
1ee299a5 637 while((source = dynamic_cast<TObjString*> (iter2.Next()))){
da2b6160 638 TString stringLaserFileName = GetFile(kDAQ, "LASERDATA", source->GetName());
639 if(stringLaserFileName.Length() <= 0){
73bc3a3f 640 Log(Form("No LASER file from source %s!", source->GetName()));
da2b6160 641 return 14;
73bc3a3f 642 }
da2b6160 643 const char* laserFileName = stringLaserFileName.Data();
644 Log(Form("\t Getting file #%d: %s from %s\n",++i,laserFileName,source->GetName()));
645 //
73bc3a3f 646 // --- Initializing pedestal calibration object
647 AliZDCLaserCalib *lCalib = new AliZDCLaserCalib("ZDC");
648 // --- Reading file with pedestal calibration data
73bc3a3f 649 if(laserFileName){
650 FILE *file;
651 if((file = fopen(laserFileName,"r")) == NULL){
652 printf("Cannot open file %s \n",laserFileName);
da2b6160 653 return 14;
1ee299a5 654 }
73bc3a3f 655 Log(Form("File %s connected to process data from LASER events", laserFileName));
1ee299a5 656 //
73bc3a3f 657 Float_t ivalRead[22][4];
658 for(Int_t j=0; j<22; j++){
da2b6160 659 for(Int_t k=0; k<4; k++){
660 int aleggi = fscanf(file,"%f",&ivalRead[j][k]);
661 if(aleggi==0) AliDebug(3," Failng reading data from laser file");
73bc3a3f 662 //printf(" %d %1.0f ",k, ivalRead[j][k]);
663 }
664 lCalib->SetDetector(j, (Int_t) ivalRead[j][0]);
665 lCalib->SetSector(j, (Int_t) ivalRead[j][1]);
666 lCalib->SetfPMValue(j, ivalRead[j][2]);
667 lCalib->SetfPMWidth(j, ivalRead[j][3]);
668 }
669 fclose(file);
670 }
671 else{
672 Log(Form("File %s not found", laserFileName));
da2b6160 673 return 14;
73bc3a3f 674 }
675 //lCalib->Print("");
676 //
677 AliCDBMetaData metaData;
678 metaData.SetBeamPeriod(0);
679 metaData.SetResponsible("Chiara Oppedisano");
680 metaData.SetComment("Filling AliZDCLaserCalib object");
681 //
1a1c78d4 682 resLaserCal = Store("Calib","LaserCalib",lCalib, &metaData, 0, kTRUE);
da2b6160 683 if(resLaserCal==kFALSE) return 15;
1ee299a5 684 }
73bc3a3f 685 delete daqSources; daqSources = 0;
da2b6160 686
73bc3a3f 687 TList* daqSourceH = GetFileSources(kDAQ, "LASERHISTOS");
688 if(!daqSourceH){
689 AliError(Form("No sources for STANDALONE_LASER run %d !", fRun));
da2b6160 690 return 16;
73bc3a3f 691 }
da2b6160 692 Log("\t List of DAQ sources for LASERHISTOS id: "); daqSourceH->Print();
73bc3a3f 693 //
694 TIter iter2H(daqSourceH);
695 TObjString* sourceH = 0;
696 Int_t iH=0;
697 while((sourceH = dynamic_cast<TObjString*> (iter2H.Next()))){
da2b6160 698 Log(Form("\t Getting file #%d\n",++iH));
699 TString stringLaserFileName = GetFile(kDAQ, "LASERHISTOS", sourceH->GetName());
700 if(stringLaserFileName.Length() <= 0){
73bc3a3f 701 Log(Form("No LASER file from source %s!", sourceH->GetName()));
da2b6160 702 return 16;
73bc3a3f 703 }
da2b6160 704 resLaserHist = StoreReferenceFile(stringLaserFileName.Data(), "laserReference.root");
e83c8d88 705 //
da2b6160 706 if(resLaserHist==kFALSE) return 17;
73bc3a3f 707 }
708 delete daqSourceH; daqSourceH = 0;
e83c8d88 709
710 return 0;
711}
712
0d579f58 713
714//______________________________________________________________________________________________
715UInt_t AliZDCPreprocessor::ProcessMBCalibData()
716{
717 TList* daqSources = GetFileSources(kDAQ, "MBCALIB");
718 if(!daqSources){
719 AliError(Form("No sources for CALIBRATION_MB run %d !", fRun));
720 return 18;
721 }
722 if(daqSources->GetEntries()==0) return 18;
723 Log("\t List of DAQ sources for MBCALIB id: "); daqSources->Print();
724 //
725 TIter iter2(daqSources);
726 TObjString* source = 0;
727 Int_t i=0;
728 Bool_t resMBCal=kTRUE;
729
730 while((source = dynamic_cast<TObjString*> (iter2.Next()))){
731 TString stringMBFileName = GetFile(kDAQ, "MBCALIB", source->GetName());
732 if(stringMBFileName.Length() <= 0){
733 Log(Form("No MBCALIB file from source %s!", source->GetName()));
734 return 18;
735 }
736 const char* mbFileName = stringMBFileName.Data();
737 Log(Form("\t Getting file #%d: %s from %s\n",++i,mbFileName,source->GetName()));
738 //
739 // --- Initializing calibration object
740 AliZDCMBCalib *mbCalib = new AliZDCMBCalib("ZDC");
741 // --- Reading file with calibration data
742 if(mbFileName){
743 TFile * fileHistos = TFile::Open(mbFileName);
744 Log(Form("File %s connected to process data from CALIBRATION_MB events", mbFileName));
745 //
746 fileHistos->cd();
747 TH2F *hZDCvsZEM = (TH2F*) fileHistos->Get("hZDCvsZEM");
748 TH2F *hZDCCvsZEM = (TH2F*) fileHistos->Get("hZDCCvsZEM");
749 TH2F *hZDCAvsZEM = (TH2F*) fileHistos->Get("hZDCAvsZEM");
750 //
751 mbCalib->SetZDCvsZEM(hZDCvsZEM);
752 mbCalib->SetZDCCvsZEM(hZDCCvsZEM);
753 mbCalib->SetZDCAvsZEM(hZDCAvsZEM);
754 //
755 //fileHistos->Close();
756 }
757 else{
758 Log(Form("File %s not found", mbFileName));
759 return 14;
760 }
761 //
762 AliCDBMetaData metaData;
763 metaData.SetBeamPeriod(0);
764 metaData.SetResponsible("Chiara Oppedisano");
765 metaData.SetComment("Filling AliZDCMBCalib object");
766 //
767 //mbCalib->Dump();
768 //
769 resMBCal = Store("Calib","MBCalib",mbCalib, &metaData, 0, kTRUE);
770 printf(" here 1000\n");
771 if(resMBCal==kFALSE) return 19;
772 }
773 delete daqSources; daqSources = 0;
774
775 return 0;
776}
777
e83c8d88 778//______________________________________________________________________________________________
779UInt_t AliZDCPreprocessor::Process(TMap* dcsAliasMap)
780{
781 UInt_t resDCS = 0;
782 UInt_t resChMap=0;
0d579f58 783 UInt_t resEnergyCalib=0, resPedestalCalib=0, resLaserCalib=0, resMBCalib=0;
e83c8d88 784
785 // ************************* Process DCS data ****************************
786 if(ProcessDCS()) resDCS = ProcessDCSData(dcsAliasMap);
787
788 // ********************************* From DAQ ************************************
789
790 const char* beamType = GetRunParameter("beamType");
791 TString runType = GetRunType();
2c62f191 792 Float_t beamEnergy = (Float_t)(((TString)GetRunParameter("beamEnergy")).Atof());
793 printf("\t **** AliZDCPreprocessor -> runType %s, beamType %s, beamEnergy %1.0f ****\n",
794 runType.Data(),beamType,beamEnergy);
e83c8d88 795
796 // ******************************************
0d579f58 797 // ADC channel mapping
e83c8d88 798 // ******************************************
da2b6160 799 resChMap = ProcessChMap();
e83c8d88 800
801 // ******************************************
0d579f58 802 // Calibration param. for p-p data (all = 1)
e83c8d88 803 // ******************************************
804 // NO ENERGY CALIBRATION -> coefficients set to 1.
805 // Temp -> also inter-calibration coefficients are set to 1.
da2b6160 806 if((strcmp(beamType,"p-p")==0) || (strcmp(beamType,"P-P")==0)) resEnergyCalib = ProcessppData();
e83c8d88 807
b8d194f5 808 // *****************************************************
0d579f58 809 // CALIBRATION_EMD -> Energy calibration and equalization
b8d194f5 810 // *****************************************************
0d579f58 811 if((strcmp(beamType,"A-A")==0) && (runType.CompareTo("CALIBRATION_EMD")==0))
2c62f191 812 resEnergyCalib = ProcessCalibData(beamEnergy);
e83c8d88 813
814 // *****************************************************
815 // STANDALONE_PEDESTALS -> Pedestal subtraction
816 // *****************************************************
da2b6160 817 if(runType.CompareTo("STANDALONE_PEDESTAL")==0) resPedestalCalib = ProcessPedestalData();
e83c8d88 818
819 // *****************************************************
820 // STANDALONE_LASER -> Signal stability and ageing
821 // *****************************************************
0d579f58 822 else if(runType.CompareTo("STANDALONE_LASER")==0) resLaserCalib = ProcessLaserData();
823
824 // *****************************************************
825 // CALIBRATION_MB -> Signal stability and ageing
826 // *****************************************************
827 else if(runType.CompareTo("CALIBRATION_MB")==0) resMBCalib = ProcessMBCalibData();
e83c8d88 828
028eb4a1 829
e83c8d88 830 if(resDCS!=0) return resDCS;
831 else if(resChMap!=0) return resChMap;
832 else if(resEnergyCalib!=0) return resEnergyCalib;
833 else if(resPedestalCalib!=0) return resPedestalCalib;
834 else if(resLaserCalib!=0) return resLaserCalib;
0d579f58 835 else if(resMBCalib!=0) return resMBCalib;
79563ba1 836
e83c8d88 837 return 0;
cb50c7c8 838
64a7c78d 839}