X-Git-Url: http://git.uio.no/git/?a=blobdiff_plain;f=ZDC%2FAliZDCPreprocessor.cxx;h=9ef09c65eb87474ba1cb201d67816ea750e40ace;hb=d631e5e72d8149fa9f221862675131332ff0e886;hp=5f622b9b7b5d00e29cf8593ac1d8c71b7367d20c;hpb=f49b80e729e7cb663030f67937904a7d6bb20aea;p=u%2Fmrichter%2FAliRoot.git diff --git a/ZDC/AliZDCPreprocessor.cxx b/ZDC/AliZDCPreprocessor.cxx index 5f622b9b7b5..9ef09c65eb8 100644 --- a/ZDC/AliZDCPreprocessor.cxx +++ b/ZDC/AliZDCPreprocessor.cxx @@ -17,16 +17,42 @@ #include "AliZDCChMap.h" #include "AliZDCPedestals.h" #include "AliZDCLaserCalib.h" -#include "AliZDCCalib.h" +#include "AliZDCEnCalib.h" +#include "AliZDCTowerCalib.h" +#include "AliZDCMBCalib.h" ///////////////////////////////////////////////////////////////////// // // -// Class implementing ZDC pre-processor. // -// It takes data from DCS and passes it to the class AliZDCDataDCS // -// The class is then written to the CDB. // +// Class implementing Shuttle ZDC pre-processor. // +// It takes data from DCS and DAQ and writes calibration objects // +// in the OCDB and reference values/histos in the ReferenceData. // // // ///////////////////////////////////////////////////////////////////// +// ****************************************************************** +// RETURN CODES: +// return 0 : everything OK +// return 1 : no DCS input data Map +// return 2 : error storing DCS data in RefData +// return 3 : error storing alignment object in OCDB +// return 4 : error in ZDCMapping.dat file retrieved from DAQ FXS (not existing|empty|corrupted) +// return 5 : error storing mapping obj. in OCDB +// return 6 : error storing energy calibration obj. in OCDB +// return 7 : error storing tower inter-calibration obj. in OCDB +// return 8 : error in ZDCEnergyCalib.dat file retrieved from DAQ FXS +// return 9 : error in ZDCTowerCalib.dat file retrieved from DAQ FXS +// return 10: error in ZDCPedestal.dat file retrieved from DAQ FXS +// return 11: error storing pedestal calibration obj. in OCDB +// return 12: error in ZDCPedHisto.root file retrieved from DAQ FXS +// return 13: error storing pedestal histos in RefData +// return 14: error in ZDCLaserCalib.dat file retrieved from DAQ FXS +// return 15: error storing laser calibration obj. in OCDB +// return 16: error in ZDCLaserHisto.root file retrieved from DAQ FXS +// return 17: error storing laser histos in RefData +// return 18: error in ZDCMBCalib.root file retrieved from DAQ FXS +// return 19: error storing MB calibration obj. in OCDB +// ****************************************************************** + ClassImp(AliZDCPreprocessor) //______________________________________________________________________________________________ @@ -35,11 +61,16 @@ AliZDCPreprocessor::AliZDCPreprocessor(AliShuttleInterface* shuttle) : fData(0) { // constructor + // May 2009 - run types updated according to + // http://alice-ecs.web.cern.ch/alice-ecs/runtypes_3.36.html AddRunType("STANDALONE_PEDESTAL"); AddRunType("STANDALONE_LASER"); - AddRunType("STANDALONE_EMD"); AddRunType("STANDALONE_COSMIC"); - AddRunType("STANDALONE_BC"); + AddRunType("CALIBRATION_EMD"); + AddRunType("CALIBRATION_MB"); + AddRunType("CALIBRATION_CENTRAL"); + AddRunType("CALIBRATION_SEMICENTRAL"); + AddRunType("CALIBRATION_BC"); AddRunType("PHYSICS"); } @@ -52,48 +83,136 @@ AliZDCPreprocessor::~AliZDCPreprocessor() //______________________________________________________________________________________________ -void AliZDCPreprocessor::Initialize(Int_t run, UInt_t startTime, - UInt_t endTime) +void AliZDCPreprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime) { // Creates AliZDCDataDCS object AliPreprocessor::Initialize(run, startTime, endTime); - Log(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run, + AliDebug(2,Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s \n\tStartTime DCS Query %s \n\tEndTime DCS Query %s", run, TTimeStamp(startTime).AsString(), - TTimeStamp(endTime).AsString())); + TTimeStamp(endTime).AsString(), ((TTimeStamp)GetStartTimeDCSQuery()).AsString(), ((TTimeStamp)GetEndTimeDCSQuery()).AsString())); + + fRun = run; + fStartTime = startTime; + fEndTime = endTime; + + fData = new AliZDCDataDCS(fRun, fStartTime, fEndTime, GetStartTimeDCSQuery(), GetEndTimeDCSQuery()); +} + +//_____________________________________________________________________________ +Bool_t AliZDCPreprocessor::ProcessDCS(){ + + // tells whether DCS should be processed or not + + TString runType = GetRunType(); + Log(Form("RunType %s",runType.Data())); + + if (runType=="STANDALONE_COSMIC" || runType=="STANDALONE_PEDESTAL"){ + return kFALSE; + } + + return kTRUE; +} + +//______________________________________________________________________________________________ +UInt_t AliZDCPreprocessor::ProcessDCSData(TMap* dcsAliasMap) +{ + + // Fills data into a AliZDCDataDCS object + if(!dcsAliasMap){ + Log(" No DCS map found: ZDC exiting from Shuttle"); + if(fData){ + delete fData; + fData = 0; + } + return 1; + } - fRun = run; - fStartTime = startTime; - fEndTime = endTime; + Log(Form("Processing data from DCS")); + + // The processing of the DCS input data is forwarded to AliZDCDataDCS + //dcsAliasMap->Print(""); + Bool_t resDCSProcess = fData->ProcessData(*dcsAliasMap); + if(resDCSProcess==kFALSE){ + Log(" Problems in processing DCS DP"); + return 1; + } + + // ------------------------------------------------------ + // Change introduced 26/9/09 in order NOT to process the + // HV DP since some of them are never found in amanda DB + // ------------------------------------------------------ + // Store DCS data as reference + AliCDBMetaData metadata; + metadata.SetResponsible("Chiara Oppedisano"); + metadata.SetComment("DCS DP TMap for ZDC"); + Bool_t resDCSRef = kTRUE; + resDCSRef = StoreReferenceData("DCS","Data", dcsAliasMap, &metadata); + + if(resDCSRef==kFALSE) return 2; - fData = new AliZDCDataDCS(fRun, fStartTime, fEndTime); + // --- Writing ZDC table positions into alignment object + TClonesArray *array = new TClonesArray("AliAlignObjParams",10); + TClonesArray &alobj = *array; + AliAlignObjParams a; + Double_t dx=0., dz=0., dpsi=0., dtheta=0., dphi=0.; + // Vertical table position in mm from DCS + Double_t dyZN1 = (Double_t) (fData->GetAlignData(0)/10.); + Double_t dyZP1 = (Double_t) (fData->GetAlignData(1)/10.); + Double_t dyZN2 = (Double_t) (fData->GetAlignData(2)/10.); + Double_t dyZP2 = (Double_t) (fData->GetAlignData(3)/10.); + // + const char *n1ZDC="ZDC/NeutronZDC_C"; + const char *p1ZDC="ZDC/ProtonZDC_C"; + const char *n2ZDC="ZDC/NeutronZDC_A"; + const char *p2ZDC="ZDC/ProtonZDC_A"; + // + UShort_t iIndex=0; + AliGeomManager::ELayerID iLayer = AliGeomManager::kInvalidLayer; + UShort_t volid = AliGeomManager::LayerToVolUID(iLayer,iIndex); + // + new(alobj[0]) AliAlignObjParams(n1ZDC, volid, dx, dyZN1, dz, dpsi, dtheta, dphi, kTRUE); + new(alobj[1]) AliAlignObjParams(p1ZDC, volid, dx, dyZP1, dz, dpsi, dtheta, dphi, kTRUE); + new(alobj[2]) AliAlignObjParams(n2ZDC, volid, dx, dyZN2, dz, dpsi, dtheta, dphi, kTRUE); + new(alobj[3]) AliAlignObjParams(p2ZDC, volid, dx, dyZP2, dz, dpsi, dtheta, dphi, kTRUE); + + // save in CDB storage + AliCDBMetaData mdDCS; + mdDCS.SetResponsible("Chiara Oppedisano"); + mdDCS.SetComment("Alignment object for ZDC"); + Bool_t resultAl = Store("Align","Data", array, &mdDCS, 0, kFALSE); + if(resultAl==kFALSE) return 3; + + return 0; } //______________________________________________________________________________________________ -UInt_t AliZDCPreprocessor::ProcessChMap(TString runType) +UInt_t AliZDCPreprocessor::ProcessChMap() { + const int kNch=48, kNScch=32; + // Reading the file for mapping from FXS - TList* daqSource = GetFileSources(kDAQ, runType.Data()); + TList* daqSource = GetFileSources(kDAQ, "MAPPING"); if(!daqSource){ - AliError(Form("No sources run %d for run type %s!", fRun, runType.Data())); - return 1; + AliError(Form("No sources for file ZDCChMapping.dat in run %d ", fRun)); + return 4; } - Log("\t List of sources "); daqSource->Print(); + if(daqSource->GetEntries()==0) return 4; + Log("\t List of DAQ sources for MAPPING id: "); daqSource->Print(); // TIter iter(daqSource); TObjString* source = 0; - Int_t isou=0; - Int_t res=999; - Int_t readMap[48][6]; + Int_t isou = 0; + Int_t readMap[kNch][6]; // while((source = dynamic_cast (iter.Next()))){ - Log(Form("\n\t Getting file #%d\n",++isou)); - TString fileName = "ZDCChMapping.dat"; + TString fileName = GetFile(kDAQ, "MAPPING", source->GetName()); + Log(Form("\t Getting file #%d: ZDCChMapping.dat from %s\n",++isou, source->GetName())); if(fileName.Length() <= 0){ Log(Form("No file from source %s!", source->GetName())); - return 1; + return 4; } // --- Reading file with calibration data //const char* fname = fileName.Data(); @@ -101,23 +220,23 @@ UInt_t AliZDCPreprocessor::ProcessChMap(TString runType) FILE *file; if((file = fopen(fileName,"r")) == NULL){ printf("Cannot open file %s \n",fileName.Data()); - return 1; + return 4; } Log(Form("File %s connected to process data for ADC mapping", fileName.Data())); // - for(Int_t j=0; j<48; j++){ + for(Int_t j=0; j WARNING! No CDB entry for ch. mapping\n"); + Log(" No existing CDB entry for ADC mapping"); updateOCDB = kTRUE; } else{ AliZDCChMap *chMap = (AliZDCChMap*) cdbEntry->GetObject(); - for(Int_t i=0; i<48; i++){ + for(Int_t i=0; iGetADCModule(i)) && (readMap[i][2] == chMap->GetADCChannel(i)) && (readMap[i][4] == chMap->GetDetector(i)) @@ -141,356 +260,540 @@ UInt_t AliZDCPreprocessor::ProcessChMap(TString runType) } } // + Bool_t resChMapStore = kTRUE; if(updateOCDB==kTRUE){ - Log("\t AliZDCPreprocessor -> A new entry ZDC/Calib/ChMap will be created"); + Log(" A new entry ZDC/Calib/ChMap will be created"); // // --- Initializing mapping calibration object AliZDCChMap *mapCalib = new AliZDCChMap("ZDC"); // Writing channel map in the OCDB - for(Int_t k=0; k<48; k++){ + for(Int_t k=0; kSetADCModule(k,readMap[k][1]); mapCalib->SetADCChannel(k,readMap[k][2]); mapCalib->SetDetector(k,readMap[k][4]); mapCalib->SetSector(k,readMap[k][5]); + // TEMPORARY!!!! Until no mapping from scaler is provided!!!!!!! + if(kSetScChannel(k, 0); + mapCalib->SetScDetector(k, 0); + mapCalib->SetScSector(k, 0); + } } - //mapCalib->Print(""); + mapCalib->Print(""); // AliCDBMetaData metaData; metaData.SetBeamPeriod(0); - metaData.SetResponsible("Chiara Oppedisano"); + //metaData.SetResponsible("Chiara Oppedisano"); metaData.SetComment("Filling AliZDCChMap object"); // - res = Store("Calib","ChMap",mapCalib, &metaData, 0, 1); + resChMapStore = Store("Calib","ChMap",mapCalib, &metaData, 0, kTRUE); + printf(" Mapping object stored in OCDB\n"); } else{ - Log("\t AliZDCPreprocessor -> ZDC/Calib/ChMap entry in OCDB is valid and won't be updated\n"); - res = kTRUE; + Log(" ZDC/Calib/ChMap entry in OCDB is valid and won't be updated"); + resChMapStore = kTRUE; } - - return res; + delete daqSource; daqSource=0; + + if(resChMapStore==kFALSE) return 5; + else return 0; } //______________________________________________________________________________________________ -UInt_t AliZDCPreprocessor::Process(TMap* dcsAliasMap) +UInt_t AliZDCPreprocessor::ProcessppData() { - // *************** From DCS ****************** - // Fills data into a AliZDCDataDCS object - if(!dcsAliasMap) return 1; - printf("Processing data from DCS\n"); - - // The processing of the DCS input data is forwarded to AliZDCDataDCS - Float_t dcsValues[28]; // DCSAliases=28 - fData->SetCalibData(dcsValues); - fData->ProcessData(*dcsAliasMap); - // Store DCS data for reference - AliCDBMetaData metadata; - metadata.SetResponsible("Chiara Oppedisano"); - metadata.SetComment("DCS data for ZDC"); - Bool_t resDCSRef = kTRUE; - resDCSRef = StoreReferenceData("DCS","Data",fData,&metadata); - dcsAliasMap->Print(""); - - // --- Writing ZDC table positions into alignment object - TClonesArray *array = new TClonesArray("AliAlignObjParams",10); - TClonesArray &alobj = *array; - AliAlignObjParams a; - Double_t dx=0., dz=0., dpsi=0., dtheta=0., dphi=0.; - // Vertical table position in mm from DCS - Double_t dyZN1 = (Double_t) (dcsValues[0]/10.); - Double_t dyZP1 = (Double_t) (dcsValues[1]/10.); - Double_t dyZN2 = (Double_t) (dcsValues[2]/10.); - Double_t dyZP2 = (Double_t) (dcsValues[3]/10.); - // - - const char *n1ZDC="ZDC/NeutronZDC_C"; - const char *p1ZDC="ZDC/ProtonZDC_C"; - const char *n2ZDC="ZDC/NeutronZDC_A"; - const char *p2ZDC="ZDC/ProtonZDC_A"; - // - UShort_t iIndex=0; - AliGeomManager::ELayerID iLayer = AliGeomManager::kInvalidLayer; - UShort_t volid = AliGeomManager::LayerToVolUID(iLayer,iIndex); - // - new(alobj[0]) AliAlignObjParams(n1ZDC, volid, dx, dyZN1, dz, dpsi, dtheta, dphi, kTRUE); - new(alobj[1]) AliAlignObjParams(p1ZDC, volid, dx, dyZP1, dz, dpsi, dtheta, dphi, kTRUE); - new(alobj[2]) AliAlignObjParams(n2ZDC, volid, dx, dyZN2, dz, dpsi, dtheta, dphi, kTRUE); - new(alobj[3]) AliAlignObjParams(p2ZDC, volid, dx, dyZP2, dz, dpsi, dtheta, dphi, kTRUE); - - // save in CDB storage - AliCDBMetaData md; - md.SetResponsible("Chiara Oppedisano"); - md.SetComment("Alignment object for ZDC"); - Bool_t resultAl = kTRUE; - resultAl = Store("Align","Data", array, &md, 0, 0); + Bool_t resEnCal=kTRUE, resTowCal=kTRUE; -// *************** From DAQ ****************** -Bool_t resChMap=kTRUE, resPedCal=kTRUE, resLaserCal=kTRUE, resECal=kTRUE; -// -const char* beamType = GetRunParameter("beamType"); -TString runType = GetRunType(); -printf("\n\t AliZDCPreprocessor -> beamType %s\n",beamType); -printf("\t AliZDCPreprocessor -> runType %s\n\n",runType.Data()); - -if(strcmp(beamType,"p-p")==0){ - + // *********** Energy calibration // --- Cheking if there is already the entry in the OCDB - AliCDBEntry *cdbEntry = GetFromOCDB("Calib", "EMDCalib"); - if(!cdbEntry){ - printf("\t AliZDCPreprocessor -> ZDC/Calib/EMDCalib entry will be created\n"); + AliCDBEntry *cdbEnEntry = GetFromOCDB("Calib", "EnergyCalib"); + if(!cdbEnEntry){ + Log(Form(" ZDC/Calib/EnergyCalib entry will be created")); // --- Initializing calibration object - AliZDCCalib *eCalib = new AliZDCCalib("ZDC"); + AliCDBMetaData metaData; + metaData.SetBeamPeriod(0); + metaData.SetResponsible("Chiara Oppedisano"); // + AliZDCEnCalib *eCalib = new AliZDCEnCalib("ZDC"); for(Int_t j=0; j<6; j++) eCalib->SetEnCalib(j,1.); + metaData.SetComment("AliZDCEnCalib object"); + //eCalib->Print(""); + resEnCal = Store("Calib", "EnergyCalib", eCalib, &metaData, 0, kTRUE); + } + else{ + // if entry exists it is still valid (=1 for all runs!) + Log(Form(" Valid ZDC/Calib/EnergyCalib object already existing in OCDB!!!")); + resEnCal = kTRUE; + } + + if(resEnCal==kFALSE) return 6; + + // + // *********** Tower inter-calibration + // --- Cheking if there is already the entry in the OCDB + AliCDBEntry *cdbTowEntry = GetFromOCDB("Calib", "TowerCalib"); + if(!cdbTowEntry){ + AliZDCTowerCalib *towCalib = new AliZDCTowerCalib("ZDC"); for(Int_t j=0; j<5; j++){ - eCalib->SetZN1EqualCoeff(j, 1.); - eCalib->SetZP1EqualCoeff(j, 1.); - eCalib->SetZN2EqualCoeff(j, 1.); - eCalib->SetZP2EqualCoeff(j, 1.); + towCalib->SetZN1EqualCoeff(j, 1.); + towCalib->SetZP1EqualCoeff(j, 1.); + towCalib->SetZN2EqualCoeff(j, 1.); + towCalib->SetZP2EqualCoeff(j, 1.); } - //eCalib->Print(""); + //towCalib->Print(""); // AliCDBMetaData metaData; metaData.SetBeamPeriod(0); metaData.SetResponsible("Chiara Oppedisano"); - metaData.SetComment("AliZDCCalib object"); + metaData.SetComment("AliZDCTowerCalib object"); // - resECal = Store("Calib","EMDCalib",eCalib, &metaData, 0, 1); + resTowCal = Store("Calib", "TowerCalib", towCalib, &metaData, 0, kTRUE); } - else{ - printf("\t AliZDCPreprocessor -> ZDC/Calib/EMDCalib object already existing in OCDB!!!\n"); - resECal = kTRUE; + else{ + // if entry exists it is still valid (=1 for all runs!) + Log(Form(" Valid ZDC/Calib/TowerCalib object already existing in OCDB!!!")); + resTowCal = kTRUE; } + + if(resTowCal==kFALSE) return 7; + + return 0; } -// ****************************************** -// ZDC ADC channel mapping -// ****************************************** -resChMap = ProcessChMap(runType); -// -// ***************************************************** -// [a] PEDESTALS -> Pedestal subtraction -// ***************************************************** -// -if(runType=="STANDALONE_PEDESTAL"){ - TList* daqSources = GetFileSources(kDAQ, "PEDESTALS"); + +//______________________________________________________________________________________________ +UInt_t AliZDCPreprocessor::ProcessCalibData() +{ + TList* daqSources = GetFileSources(kDAQ, "EMDENERGYCALIB"); if(!daqSources){ - Log(Form("No source for STANDALONE_PEDESTAL run %d !", fRun)); - return 1; + AliError(Form("No sources for CALIBRATION_EMD run %d !", fRun)); + return 8; } - Log("\t List of sources for STANDALONE_PEDESTAL"); - daqSources->Print(); + Log("\t List of DAQ sources for EMDENERGYCALIB id: "); daqSources->Print(); // - TIter iter(daqSources); + TIter iter2(daqSources); TObjString* source = 0; Int_t i=0; - while((source = dynamic_cast (iter.Next()))){ - Log(Form("\n\t Getting file #%d\n",++i)); - TString stringPedFileName = GetFile(kDAQ, "PEDESTALS", source->GetName()); - if(stringPedFileName.Length() <= 0){ - Log(Form("No PEDESTAL file from source %s!", source->GetName())); - return 1; - } - // --- Initializing pedestal calibration object - AliZDCPedestals *pedCalib = new AliZDCPedestals("ZDC"); - // --- Reading file with pedestal calibration data - const char* pedFileName = stringPedFileName.Data(); - // no. ADCch = (22 signal ch. + 2 reference PMs) * 2 gain chain = 48 - const Int_t knZDCch = 48; - if(pedFileName){ - FILE *file; - if((file = fopen(pedFileName,"r")) == NULL){ - printf("Cannot open file %s \n",pedFileName); - return 1; - } - Log(Form("File %s connected to process pedestal data", pedFileName)); - Float_t pedVal[(2*knZDCch)][2]; - for(Int_t k=0; k<(2*knZDCch); k++){ - for(Int_t j=0; j<2; j++){ - fscanf(file,"%f",&pedVal[k][j]); - //if(j==1) printf("pedVal[%d] -> %f, %f \n",k,pedVal[k][0],pedVal[k][1]); - } - if(kSetMeanPed(k,pedVal[k][0]); - pedCalib->SetMeanPedWidth(i,pedVal[k][1]); - } - else if(k>=knZDCch && k<(2*knZDCch)){ - pedCalib->SetOOTPed(k-knZDCch,pedVal[k][0]); - pedCalib->SetOOTPedWidth(k-knZDCch,pedVal[k][1]); - } - else if(k>=(2*knZDCch) && k<(3*knZDCch)){ - pedCalib->SetPedCorrCoeff(k-(2*knZDCch),pedVal[k][0],pedVal[k][1]); - } + Bool_t resEnCal=kTRUE, resTowCal=kTRUE; + + while((source = dynamic_cast (iter2.Next()))){ + TString stringEMDFileName = GetFile(kDAQ, "EMDENERGYCALIB", source->GetName()); + if(stringEMDFileName.Length() <= 0){ + Log(Form("No file from source %s!", source->GetName())); + return 8; + } + const char* emdFileName = stringEMDFileName.Data(); + Log(Form("\t Getting file #%d: %s from %s\n",++i,emdFileName,source->GetName())); + // + // --- Initializing energy calibration object + AliZDCEnCalib *eCalib = new AliZDCEnCalib("ZDC"); + // --- Reading file with calibration data + if(emdFileName){ + FILE *file; + if((file = fopen(emdFileName,"r")) == NULL){ + printf("Cannot open file %s \n",emdFileName); + return 8; + } + Log(Form("File %s connected to process data from EM dissociation events", emdFileName)); + // + Float_t fitValEMD[6]; + for(Int_t j=0; j<6; j++){ + if(j<6){ + int iread = fscanf(file,"%f",&fitValEMD[j]); + if(iread==0) AliDebug(3," Failing reading daa from EMD calibration data file"); + eCalib->SetEnCalib(j,fitValEMD[j]); + } + } + // + fclose(file); + } + else{ + Log(Form("File %s not found", emdFileName)); + return 8; + } + //eCalib->Print(""); + // + AliCDBMetaData metaData; + metaData.SetBeamPeriod(0); + metaData.SetResponsible("Chiara Oppedisano"); + metaData.SetComment("Filling AliZDCEnCalib object"); + // + resEnCal = Store("Calib","EnergyCalib",eCalib, &metaData, 0, kTRUE); + if(resEnCal==kFALSE) return 6; + } + delete daqSources; daqSources = 0; + + TList* daqSourcesH = GetFileSources(kDAQ, "EMDTOWERCALIB"); + if(!daqSourcesH){ + AliError(Form("No sources for CALIBRATION_EMD run %d !", fRun)); + return 9; + } + Log("\t List of DAQ sources for EMDTOWERCALIB id: "); daqSourcesH->Print(); + // + TIter iter2H(daqSourcesH); + TObjString* sourceH = 0; + Int_t iH=0; + while((sourceH = dynamic_cast (iter2H.Next()))){ + TString stringtowEMDFileName = GetFile(kDAQ, "EMDTOWERCALIB", sourceH->GetName()); + if(stringtowEMDFileName.Length() <= 0){ + Log(Form("No file from source %s!", sourceH->GetName())); + return 9; + } + const char * towEMDFileName = stringtowEMDFileName.Data(); + Log(Form("\t Getting file #%d: %s from source %s\n",++iH,towEMDFileName,sourceH->GetName())); + // --- Initializing energy calibration object + AliZDCTowerCalib *towCalib = new AliZDCTowerCalib("ZDC"); + // --- Reading file with calibration data + if(towEMDFileName){ + FILE *file; + if((file = fopen(towEMDFileName,"r")) == NULL){ + printf("Cannot open file %s \n",towEMDFileName); + return 9; + } + // + Float_t equalCoeff[4][5]; + for(Int_t j=0; j<4; j++){ + for(Int_t k=0; k<5; k++){ + int leggi = fscanf(file,"%f",&equalCoeff[j][k]); + if(leggi==0) AliDebug(3," Failing reading data from EMD calibration file"); + if(j==0) towCalib->SetZN1EqualCoeff(k, equalCoeff[j][k]); + else if(j==1) towCalib->SetZP1EqualCoeff(k, equalCoeff[j][k]); + else if(j==2) towCalib->SetZN2EqualCoeff(k, equalCoeff[j][k]); + else if(j==3) towCalib->SetZP2EqualCoeff(k, equalCoeff[j][k]); } - fclose(file); - } - else{ - Log(Form("File %s not found", pedFileName)); - return 1; - } - // - //pedCalib->Print(""); - // - AliCDBMetaData metaData; - metaData.SetBeamPeriod(0); - metaData.SetResponsible("Chiara Oppedisano"); - metaData.SetComment("Filling AliZDCPedestals object"); + } // - resPedCal = Store("Calib","Pedestals",pedCalib, &metaData, 0, 1); + fclose(file); + } + else{ + Log(Form("File %s not found", towEMDFileName)); + return 9; + } + //towCalib->Print(""); + // + AliCDBMetaData metaData; + metaData.SetBeamPeriod(0); + metaData.SetResponsible("Chiara Oppedisano"); + metaData.SetComment("Filling AliZDCTowerCalib object"); + // + resTowCal = Store("Calib","TowerCalib",towCalib, &metaData, 0, kTRUE); + if(resTowCal==kFALSE) return 7; + } + delete daqSourcesH; daqSourcesH = 0; + + + return 0; +} + +//______________________________________________________________________________________________ +UInt_t AliZDCPreprocessor::ProcessPedestalData() +{ + TList* daqSources = GetFileSources(kDAQ, "PEDESTALDATA"); + if(!daqSources){ + Log(Form("No source for STANDALONE_PEDESTAL run %d !", fRun)); + return 10; + } + if(daqSources->GetEntries()==0) return 10; + Log("\t List of DAQ sources for PEDESTALDATA id: "); daqSources->Print(); + // + TIter iter(daqSources); + TObjString* source; + Int_t i=0; + Bool_t resPedCal=kTRUE, resPedHist=kTRUE; + + while((source = dynamic_cast (iter.Next()))){ + TString stringPedFileName = GetFile(kDAQ, "PEDESTALDATA", source->GetName()); + if(stringPedFileName.Length() <= 0){ + Log(Form("No PEDESTALDATA file from source %s!", source->GetName())); + return 10; + } + const char* pedFileName = stringPedFileName.Data(); + Log(Form("\t Getting file #%d: %s from %s\n",++i,pedFileName,source->GetName())); + // + // --- Initializing pedestal calibration object + AliZDCPedestals *pedCalib = new AliZDCPedestals("ZDC"); + // --- Reading file with pedestal calibration data + // no. ADCch = (22 signal ch. + 2 reference PMs) * 2 gain chain = 48 + const Int_t knZDCch = 48; + FILE *file; + if((file = fopen(pedFileName,"r")) == NULL){ + printf("Cannot open file %s \n",pedFileName); + return 10; + } + Log(Form("File %s connected to process pedestal data", pedFileName)); + Float_t pedVal[(2*knZDCch)][2]; + for(Int_t k=0; k<(2*knZDCch); k++){ + for(Int_t j=0; j<2; j++){ + int aleggi = fscanf(file,"%f",&pedVal[k][j]); + if(aleggi==0) AliDebug(3," Failing reading data from pedestal file"); + //if(j==1) printf("pedVal[%d] -> %f, %f \n",k,pedVal[k][0],pedVal[k][1]); + } + if(kSetMeanPed(k,pedVal[k][0]); + pedCalib->SetMeanPedWidth(k,pedVal[k][1]); + } + else if(k>=knZDCch && k<(2*knZDCch)){ + pedCalib->SetOOTPed(k-knZDCch,pedVal[k][0]); + pedCalib->SetOOTPedWidth(k-knZDCch,pedVal[k][1]); + } + else if(k>=(2*knZDCch) && k<(3*knZDCch)){ + pedCalib->SetPedCorrCoeff(k-(2*knZDCch),pedVal[k][0],pedVal[k][1]); + } + } + fclose(file); + //pedCalib->Print(""); + // + AliCDBMetaData metaData; + metaData.SetBeamPeriod(0); + metaData.SetResponsible("Chiara Oppedisano"); + metaData.SetComment("Filling AliZDCPedestals object"); + // + resPedCal = Store("Calib","Pedestals",pedCalib, &metaData, 0, kTRUE); + if(resPedCal==kFALSE) return 11; } delete daqSources; daqSources = 0; + + TList* daqSourceH = GetFileSources(kDAQ, "PEDESTALHISTOS"); + if(!daqSourceH){ + Log(Form("No source for PEDESTALHISTOS id run %d !", fRun)); + return 12; + } + Log("\t List of DAQ sources for PEDESTALHISTOS id: "); daqSourceH->Print(); + // + TIter iterH(daqSourceH); + TObjString* sourceH = 0; + Int_t iH=0; + while((sourceH = dynamic_cast (iterH.Next()))){ + TString stringPedFileName = GetFile(kDAQ, "PEDESTALHISTOS", sourceH->GetName()); + if(stringPedFileName.Length() <= 0){ + Log(Form("No PEDESTALHISTOS file from source %s!", sourceH->GetName())); + return 12; + } + const char* pedFileName = stringPedFileName.Data(); + Log(Form("\t Getting file #%d: %s from %s\n",++iH, pedFileName, sourceH->GetName())); + resPedHist = StoreReferenceFile(pedFileName, "pedestalReference.root"); + if(resPedHist==kFALSE) return 13; + } + delete daqSourceH; daqSourceH=0; + + return 0; } -// ***************************************************** -// [b] STANDALONE_LASER EVENTS -> Signal stability -// ***************************************************** -else if(runType=="STANDALONE_LASER"){ - TList* daqSources = GetFileSources(kDAQ, "LASER"); + +//______________________________________________________________________________________________ +UInt_t AliZDCPreprocessor::ProcessLaserData() +{ + TList* daqSources = GetFileSources(kDAQ, "LASERDATA"); if(!daqSources){ AliError(Form("No sources for STANDALONE_LASER run %d !", fRun)); - return 1; + return 14; } - Log("\t List of sources for STANDALONE_LASER"); - daqSources->Print(); + if(daqSources->GetEntries()==0) return 14; + Log("\t List of DAQ sources for LASERDATA id: "); daqSources->Print(); // TIter iter2(daqSources); TObjString* source = 0; Int_t i=0; + Bool_t resLaserCal=kTRUE, resLaserHist=kTRUE; + while((source = dynamic_cast (iter2.Next()))){ - Log(Form("\n\t Getting file #%d\n",++i)); - TString stringLASERFileName = GetFile(kDAQ, "LASER", source->GetName()); - if(stringLASERFileName.Length() <= 0){ - Log(Form("No LASER file from source %s!", source->GetName())); - return 1; - } - // --- Initializing pedestal calibration object - AliZDCLaserCalib *lCalib = new AliZDCLaserCalib("ZDC"); - // --- Reading file with pedestal calibration data - const char* laserFileName = stringLASERFileName.Data(); - if(laserFileName){ - FILE *file; - if((file = fopen(laserFileName,"r")) == NULL){ - printf("Cannot open file %s \n",laserFileName); - return 1; - } - Log(Form("File %s connected to process data from LASER events", laserFileName)); - // - Float_t ivalRead[22][4]; - for(Int_t j=0; j<22; j++){ - for(Int_t k=0; k<4; k++){ - fscanf(file,"%f",&ivalRead[j][k]); - //printf(" %d %1.0f ",k, ivalRead[j][k]); - } - lCalib->SetDetector(j, (Int_t) ivalRead[j][0]); - lCalib->SetSector(j, (Int_t) ivalRead[j][1]); - lCalib->SetfPMValue(j, ivalRead[j][2]); - lCalib->SetfPMWidth(j, ivalRead[j][3]); - } - fclose(file); - } - else{ - Log(Form("File %s not found", laserFileName)); - return 1; + TString stringLaserFileName = GetFile(kDAQ, "LASERDATA", source->GetName()); + if(stringLaserFileName.Length() <= 0){ + Log(Form("No LASER file from source %s!", source->GetName())); + return 14; + } + const char* laserFileName = stringLaserFileName.Data(); + Log(Form("\t Getting file #%d: %s from %s\n",++i,laserFileName,source->GetName())); + // + // --- Initializing pedestal calibration object + AliZDCLaserCalib *lCalib = new AliZDCLaserCalib("ZDC"); + // --- Reading file with pedestal calibration data + if(laserFileName){ + FILE *file; + if((file = fopen(laserFileName,"r")) == NULL){ + printf("Cannot open file %s \n",laserFileName); + return 14; } - //lCalib->Print(""); - // - AliCDBMetaData metaData; - metaData.SetBeamPeriod(0); - metaData.SetResponsible("Chiara Oppedisano"); - metaData.SetComment("Filling AliZDCLaserCalib object"); + Log(Form("File %s connected to process data from LASER events", laserFileName)); // - resLaserCal = Store("Calib","LaserCalib",lCalib, &metaData, 0, 1); + Float_t ivalRead[22][4]; + for(Int_t j=0; j<22; j++){ + for(Int_t k=0; k<4; k++){ + int aleggi = fscanf(file,"%f",&ivalRead[j][k]); + if(aleggi==0) AliDebug(3," Failng reading data from laser file"); + //printf(" %d %1.0f ",k, ivalRead[j][k]); + } + lCalib->SetDetector(j, (Int_t) ivalRead[j][0]); + lCalib->SetSector(j, (Int_t) ivalRead[j][1]); + lCalib->SetfPMValue(j, ivalRead[j][2]); + lCalib->SetfPMWidth(j, ivalRead[j][3]); + } + fclose(file); + } + else{ + Log(Form("File %s not found", laserFileName)); + return 14; + } + //lCalib->Print(""); + // + AliCDBMetaData metaData; + metaData.SetBeamPeriod(0); + metaData.SetResponsible("Chiara Oppedisano"); + metaData.SetComment("Filling AliZDCLaserCalib object"); + // + resLaserCal = Store("Calib","LaserCalib",lCalib, &metaData, 0, kTRUE); + if(resLaserCal==kFALSE) return 15; + } + delete daqSources; daqSources = 0; + + TList* daqSourceH = GetFileSources(kDAQ, "LASERHISTOS"); + if(!daqSourceH){ + AliError(Form("No sources for STANDALONE_LASER run %d !", fRun)); + return 16; + } + Log("\t List of DAQ sources for LASERHISTOS id: "); daqSourceH->Print(); + // + TIter iter2H(daqSourceH); + TObjString* sourceH = 0; + Int_t iH=0; + while((sourceH = dynamic_cast (iter2H.Next()))){ + Log(Form("\t Getting file #%d\n",++iH)); + TString stringLaserFileName = GetFile(kDAQ, "LASERHISTOS", sourceH->GetName()); + if(stringLaserFileName.Length() <= 0){ + Log(Form("No LASER file from source %s!", sourceH->GetName())); + return 16; + } + resLaserHist = StoreReferenceFile(stringLaserFileName.Data(), "laserReference.root"); + // + if(resLaserHist==kFALSE) return 17; } + delete daqSourceH; daqSourceH = 0; + return 0; } -// ***************************************************** -// [c] EMD EVENTS -> Energy calibration and equalization -// ***************************************************** -else if(runType=="STANDALONE_EMD" && strcmp(beamType,"Pb-Pb")==0){ - TList* daqSources = GetFileSources(kDAQ, "EMDCALIB"); + + +//______________________________________________________________________________________________ +UInt_t AliZDCPreprocessor::ProcessMBCalibData() +{ + TList* daqSources = GetFileSources(kDAQ, "MBCALIB"); if(!daqSources){ - AliError(Form("No sources for STANDALONE_EMD run %d !", fRun)); - return 1; + AliError(Form("No sources for CALIBRATION_MB run %d !", fRun)); + return 18; } - Log("\t List of sources for STANDALONE_EMD"); - daqSources->Print(); + if(daqSources->GetEntries()==0) return 18; + Log("\t List of DAQ sources for MBCALIB id: "); daqSources->Print(); // TIter iter2(daqSources); TObjString* source = 0; Int_t i=0; + Bool_t resMBCal=kTRUE; + while((source = dynamic_cast (iter2.Next()))){ - Log(Form("\n\t Getting file #%d\n",++i)); - TString stringEMDFileName = GetFile(kDAQ, "EMDCALIB", source->GetName()); - if(stringEMDFileName.Length() <= 0){ - Log(Form("No EMDCALIB file from source %s!", source->GetName())); - return 1; - } - // --- Initializing pedestal calibration object - AliZDCCalib *eCalib = new AliZDCCalib("ZDC"); - // --- Reading file with pedestal calibration data - const char* emdFileName = stringEMDFileName.Data(); - if(emdFileName){ - FILE *file; - if((file = fopen(emdFileName,"r")) == NULL){ - printf("Cannot open file %s \n",emdFileName); - return 1; - } - Log(Form("File %s connected to process data from EM dissociation events", emdFileName)); - // - Float_t fitValEMD[6]; Float_t equalCoeff[4][5]; - Float_t calibVal[4]; - for(Int_t j=0; j<10; j++){ - if(j<6){ - fscanf(file,"%f",&fitValEMD[j]); - if(j<4){ - calibVal[j] = 2.76/fitValEMD[j]; - eCalib->SetEnCalib(j,calibVal[j]); - } - else eCalib->SetEnCalib(j,fitValEMD[j]); - } - else{ - for(Int_t k=0; k<5; k++){ - fscanf(file,"%f",&equalCoeff[j][k]); - if(j==6) eCalib->SetZN1EqualCoeff(k, equalCoeff[j][k]); - else if(j==7) eCalib->SetZP1EqualCoeff(k, equalCoeff[j][k]); - else if(j==8) eCalib->SetZN2EqualCoeff(k, equalCoeff[j][k]); - else if(j==9) eCalib->SetZP2EqualCoeff(k, equalCoeff[j][k]); - } - } - } - fclose(file); - } - else{ - Log(Form("File %s not found", emdFileName)); - return 1; - } - //eCalib->Print(""); - // - AliCDBMetaData metaData; - metaData.SetBeamPeriod(0); - metaData.SetResponsible("Chiara Oppedisano"); - metaData.SetComment("Filling AliZDCCalib object"); - // - resECal = Store("Calib","EMDCalib",eCalib, &metaData, 0, 1); + TString stringMBFileName = GetFile(kDAQ, "MBCALIB", source->GetName()); + if(stringMBFileName.Length() <= 0){ + Log(Form("No MBCALIB file from source %s!", source->GetName())); + return 18; + } + const char* mbFileName = stringMBFileName.Data(); + Log(Form("\t Getting file #%d: %s from %s\n",++i,mbFileName,source->GetName())); + // + // --- Initializing calibration object + AliZDCMBCalib *mbCalib = new AliZDCMBCalib("ZDC"); + // --- Reading file with calibration data + if(mbFileName){ + TFile * fileHistos = TFile::Open(mbFileName); + Log(Form("File %s connected to process data from CALIBRATION_MB events", mbFileName)); + // + fileHistos->cd(); + TH2F *hZDCvsZEM = (TH2F*) fileHistos->Get("hZDCvsZEM"); + TH2F *hZDCCvsZEM = (TH2F*) fileHistos->Get("hZDCCvsZEM"); + TH2F *hZDCAvsZEM = (TH2F*) fileHistos->Get("hZDCAvsZEM"); + // + mbCalib->SetZDCvsZEM(hZDCvsZEM); + mbCalib->SetZDCCvsZEM(hZDCCvsZEM); + mbCalib->SetZDCAvsZEM(hZDCAvsZEM); + // + //fileHistos->Close(); + } + else{ + Log(Form("File %s not found", mbFileName)); + return 14; + } + // + AliCDBMetaData metaData; + metaData.SetBeamPeriod(0); + metaData.SetResponsible("Chiara Oppedisano"); + metaData.SetComment("Filling AliZDCMBCalib object"); + // + //mbCalib->Dump(); + // + resMBCal = Store("Calib","MBCalib",mbCalib, &metaData, 0, kTRUE); + printf(" here 1000\n"); + if(resMBCal==kFALSE) return 19; } + delete daqSources; daqSources = 0; + + return 0; } +//______________________________________________________________________________________________ +UInt_t AliZDCPreprocessor::Process(TMap* dcsAliasMap) +{ + UInt_t resDCS = 0; + UInt_t resChMap=0; + UInt_t resEnergyCalib=0, resPedestalCalib=0, resLaserCalib=0, resMBCalib=0; - // note that the parameters are returned as character strings! - const char* nEvents = GetRunParameter("totalEvents"); - if(nEvents) Log(Form("Number of events for run %d: %s",fRun, nEvents)); - else Log(Form("Number of events not put in logbook!")); - - UInt_t result = 0; - if(resDCSRef==kFALSE || resultAl==kFALSE || resPedCal==kFALSE || - resLaserCal==kFALSE || resECal==kFALSE || resChMap==kFALSE){ - if(resDCSRef == kFALSE) result = 1; - else if(resultAl == kFALSE) result = 2; - else if(resChMap == kFALSE) result = 3; - else if(resPedCal == kFALSE) result = 4; - else if(resLaserCal == kFALSE) result = 5; - else if(resECal == kFALSE) result = 6; - } + // ************************* Process DCS data **************************** + if(ProcessDCS()) resDCS = ProcessDCSData(dcsAliasMap); - return result; + // ********************************* From DAQ ************************************ + + const char* beamType = GetRunParameter("beamType"); + TString runType = GetRunType(); + printf("\t **** AliZDCPreprocessor -> beamType %s, runType %s ****\n",beamType,runType.Data()); + + // ****************************************** + // ADC channel mapping + // ****************************************** + resChMap = ProcessChMap(); + + // ****************************************** + // Calibration param. for p-p data (all = 1) + // ****************************************** + // NO ENERGY CALIBRATION -> coefficients set to 1. + // Temp -> also inter-calibration coefficients are set to 1. + if((strcmp(beamType,"p-p")==0) || (strcmp(beamType,"P-P")==0)) resEnergyCalib = ProcessppData(); + + // ***************************************************** + // CALIBRATION_EMD -> Energy calibration and equalization + // ***************************************************** + if((strcmp(beamType,"A-A")==0) && (runType.CompareTo("CALIBRATION_EMD")==0)) + resEnergyCalib = ProcessCalibData(); + + // ***************************************************** + // STANDALONE_PEDESTALS -> Pedestal subtraction + // ***************************************************** + if(runType.CompareTo("STANDALONE_PEDESTAL")==0) resPedestalCalib = ProcessPedestalData(); + + // ***************************************************** + // STANDALONE_LASER -> Signal stability and ageing + // ***************************************************** + else if(runType.CompareTo("STANDALONE_LASER")==0) resLaserCalib = ProcessLaserData(); + + // ***************************************************** + // CALIBRATION_MB -> Signal stability and ageing + // ***************************************************** + else if(runType.CompareTo("CALIBRATION_MB")==0) resMBCalib = ProcessMBCalibData(); + + + if(resDCS!=0) return resDCS; + else if(resChMap!=0) return resChMap; + else if(resEnergyCalib!=0) return resEnergyCalib; + else if(resPedestalCalib!=0) return resPedestalCalib; + else if(resLaserCalib!=0) return resLaserCalib; + else if(resMBCalib!=0) return resMBCalib; + + return 0; }