From 0916ba7818bf06e408813b57331a1030bb6b0e29 Mon Sep 17 00:00:00 2001 From: sevdokim Date: Wed, 11 Feb 2015 19:28:20 +0100 Subject: [PATCH] PHOS: CPV PED DA added --- PHOS/DA/CMakeLists.txt | 2 + PHOS/DA/PHOSCPVPEDda.cxx | 172 ++++++++++++++++ PHOS/PHOSbase/AliPHOSCpvPedProducer.cxx | 263 ++++++++++++++++++++++++ PHOS/PHOSbase/AliPHOSCpvPedProducer.h | 64 ++++++ PHOS/PHOSbase/CMakeLists.txt | 1 + PHOS/PHOSbase/PHOSbaseLinkDef.h | 1 + 6 files changed, 503 insertions(+) create mode 100644 PHOS/DA/PHOSCPVPEDda.cxx create mode 100644 PHOS/PHOSbase/AliPHOSCpvPedProducer.cxx create mode 100644 PHOS/PHOSbase/AliPHOSCpvPedProducer.h diff --git a/PHOS/DA/CMakeLists.txt b/PHOS/DA/CMakeLists.txt index f1aa71e1c64..4469a37644a 100644 --- a/PHOS/DA/CMakeLists.txt +++ b/PHOS/DA/CMakeLists.txt @@ -40,3 +40,5 @@ generateDA("PHOS" "LED" "${STATIC_DEPENDENCIES}") set(STATIC_DEPENDENCIES RAWDatabase-static RAWDatarec-static STEERBase-static) generateDA("PHOS" "PED" "${STATIC_DEPENDENCIES}") +set(STATIC_DEPENDENCIES PHOSbase-static RAWDatabase-static RAWDatarec-static STEERBase-static) +generateDA("PHOS" "CPVPED" "${STATIC_DEPENDENCIES}") diff --git a/PHOS/DA/PHOSCPVPEDda.cxx b/PHOS/DA/PHOSCPVPEDda.cxx new file mode 100644 index 00000000000..1dc2d57d5f9 --- /dev/null +++ b/PHOS/DA/PHOSCPVPEDda.cxx @@ -0,0 +1,172 @@ +/* +CPV PED DA for processing pedestal runs and producing pedestal tables for loading to CPV FEE. + +Contact: Sergey Evdokimov +Link: https://twiki.cern.ch/twiki/bin/view/ALICE/CPVda +Reference run: 211758 (/afs/cern.ch/user/s/sevdokim/public/CPV_run211758_pedestal.raw) +Run Type: PHYSICS +DA Type: PED +Number of events needed: 2000 events +Input files: raw data file +Output files: thr?_??.dat CpvPeds.root +Trigger types used: PHYSICS_EVENT +*/ + +#include "event.h" +#include "monitor.h" +#include "daqDA.h" + +#include +#include +#include +#include + +//AliRoot +#include "AliPHOSCpvRawStream.h" +#include "AliPHOSCpvPedProducer.h" +#include "AliPHOSCpvParam.h" +#include "AliRawReaderDate.h" +#include "AliBitPacking.h" +#include "TMath.h" + +//ROOT +#include "TROOT.h" +#include "TPluginManager.h" +#include "TSAXParser.h" +#include "TTree.h" + +#include "TString.h" +#include "TFile.h" +#include "TSystem.h" +#include "TKey.h" +#include "TH2S.h" +#include "TH2F.h" +#include "TObject.h" +#include "TBenchmark.h" +#include "TMath.h" +#include "TRandom.h" + + +int main( int argc, char **argv ) +{ + gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo", + "*", + "TStreamerInfo", + "RIO", + "TStreamerInfo()"); + Int_t status,print; + Int_t sigcut=3; + Bool_t turbo = kTRUE; + + if (argc!=2) { + printf("Wrong number of arguments\n"); + return -1; + } + + // log start of process + printf("Cpv DA program started\n"); + + /* report progress */ + daqDA_progressReport(0); + + status=monitorSetDataSource( argv[1] ); + if (status!=0) { + printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status)); + return -1; + } + + /* declare monitoring program */ + status=monitorDeclareMp( __FILE__ ); + if (status!=0) { + printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status)); + return -1; + } + + /* define wait event timeout - 1s max */ + monitorSetNowait(); + monitorSetNoWaitNetworkTimeout(1000); + + /* report progress */ + daqDA_progressReport(5); + + + // init event counter + Int_t iPhysEvnt=0; + Int_t iTotEvnt =0; + + AliPHOSCpvPedProducer * pedProducer = new AliPHOSCpvPedProducer(sigcut); + + // Reader + AliRawReader * reader; + + /* report progress */ + daqDA_progressReport(10); + + /* main loop (infinite) */ + for(;;) { // infinite loop + struct eventHeaderStruct *event; + eventTypeType eventT; + + /* check shutdown condition */ + if (daqDA_checkShutdown()) {break;} + + // get next event + status=monitorGetEventDynamic((void **)&event); + if (status==MON_ERR_EOF) { // end of monitoring file has been reached + printf("End of monitoring file has been reached! \n"); + break; + } + + if (status!=0) { + printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status)); + break; + } + + // retry if got no event + if (event==NULL) continue; + + // use event - here, just write event id to result file + eventT=event->eventType; + if (eventT==PHYSICS_EVENT) { //we use PHYSICS_EVENT for pedestal not CALIBRATION_EVENT??? + iTotEvnt++; + reader = new AliRawReaderDate((void*)event); + pedProducer->LoadNewEvent(reader); + if(pedProducer->FillPedestal()) iPhysEvnt++; + delete reader; + } // if PHYSICS_EVENT + + free(event); + + /* exit when last event received, no need to wait for TERM signal */ + if (eventT==END_OF_RUN) { + printf("EOR event detected\n"); + break; + } + } + + Printf(" Received %d events, %d good events",iTotEvnt,iPhysEvnt); + /* report progress */ + daqDA_progressReport(80); + + for(int iDDL = 0; iDDL CalcPedestal(iDDL)){ + pedProducer -> WritePedFiles(iDDL); + //for (int iCC = 0; iCCWriteAllHistsToFile("CpvPeds.root"); + status = daqDA_DB_storeFile("CpvPeds.root","CpvPeds.root"); + if(status) printf("Failed to store CpvPeds.root in DAQ DB!\n"); + + /* report progress */ + daqDA_progressReport(95); + + + return status; +} diff --git a/PHOS/PHOSbase/AliPHOSCpvPedProducer.cxx b/PHOS/PHOSbase/AliPHOSCpvPedProducer.cxx new file mode 100644 index 00000000000..9f9d1e43c19 --- /dev/null +++ b/PHOS/PHOSbase/AliPHOSCpvPedProducer.cxx @@ -0,0 +1,263 @@ +#include "AliPHOSCpvPedProducer.h" +#include "AliPHOSCpvParam.h" +#include "AliPHOSCpvRawStream.h" +#include +#include +#include +#include +#include +#include +#include +#include + +#include "TFile.h" + +using namespace std; + +using std::ifstream; +using std::ofstream; +ClassImp(AliPHOSCpvPedProducer) ; + +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +AliPHOSCpvPedProducer::AliPHOSCpvPedProducer(Int_t sigcut): + TObject(), + fSigCut(sigcut), + fTurbo(kTRUE), + fhErrors(0), + fRawStream(0) +{ + // + //constructor + // + CreateErrHist(); +} //constructor +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +AliPHOSCpvPedProducer::~AliPHOSCpvPedProducer() +{ + // + //destructor + // + for(Int_t iDDL=0; iDDLSetTurbo(fTurbo); +} +//-------------------------------------------------------------------------------------- +Bool_t AliPHOSCpvPedProducer::LoadNewEvent(AliRawReader *& rawReader) +{ + if(fRawStream) delete fRawStream; + fRawStream = new AliPHOSCpvRawStream(rawReader); + if(fRawStream) { + fRawStream->SetTurbo(fTurbo); + return kTRUE; + } + fhErrors->Fill(0); + return kFALSE; +} +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +Bool_t AliPHOSCpvPedProducer::FillPedestal(Int_t abspad,Float_t q) +{ + // + //Called from the CpvdaFillPedestal() and fills the pedestal values + //Arguments: absolute pad number as from AliPHOSCpvParam and q-charge + // + if(q<0) { + AliError("Negative charge is read!!!!!!"); + return kFALSE; + } + if(AliPHOSCpvParam::IsValidAbs(abspad) && q>0) { + Int_t iDDL=AliPHOSCpvParam::A2DDL(abspad), + iX=AliPHOSCpvParam::A2X(abspad), + iY=AliPHOSCpvParam::A2Y(abspad); + if(!fPedMeanMap[iDDL]) CreateDDLHistos(iDDL); + fPadAdc [iDDL][iX][iY] -> Fill(q); + return kTRUE; + } + return kFALSE; +}//FillPedestal(int,float) +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +Bool_t AliPHOSCpvPedProducer::FillPedestal() +{ + // + //Called from the Cpvda + // + while(fRawStream->Next()){ + for(Int_t iPad=0;iPadGetNPads();iPad++) { + Int_t charge = fRawStream->GetChargeArray()[iPad]; + Int_t aPad = fRawStream -> GetPadArray()[iPad]; + if(charge){ + if(!AliPHOSCpvParam::IsValidAbs(aPad)) continue; + if(!FillPedestal(aPad, (Float_t)charge)) return kFALSE; + } + } + } + return kTRUE; +}//FillPedestal(TClonesArray*) +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +Bool_t AliPHOSCpvPedProducer::CalcPedestal(Int_t iDDL) +{ + // + //Calculate pedestal for each pad + //Arguments: nDDL-DDL number, nEv - number of the read events + //Retutns: kTRUE/kFALSE + // + //cout<<"Now we are going to calculate pedestals"<cd(); + for(Int_t iDDL=0; iDDLWrite(); + // } + // } + //Printf("iDDL = %d\n", iDDL); + if ( fPedMeanMap[iDDL]) + rootF->WriteObject(fPedMeanMap[iDDL], Form("PedMeanMap%d",iDDL)); + if ( fPedSigMap[iDDL]) + rootF->WriteObject(fPedSigMap [iDDL], Form("fPedSigMap%d",iDDL)); + if ( f1DPedMean[iDDL]) + rootF->WriteObject(f1DPedMean [iDDL], Form("f1DPedMean%d",iDDL)); + if ( f1DPedSigma[iDDL]) + rootF->WriteObject(f1DPedSigma[iDDL], Form("f1DPedSig%d",iDDL)); + //printf("Write here something \n"); + } + //if(fhErrors) fhErrors -> Write(); + + for(Int_t iDDL=0; iDDLWrite(); + + rootF->Close(); +} //WriteAllHistsToFile() +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +void AliPHOSCpvPedProducer::WritePedFiles(Int_t iDDL) const +{ + // + // Write pedestal files to load them to RCB card + // One file per each column controler + // + + // accordance to RCB format, pedestals must be written in blocks of 64 lines (not AliPHOSCpvParam::kNPadAdd!) + Int_t block = 64; + + //cout<<"pedestal files now will be created!"<< endl; + + if(!fPedMeanMap[iDDL]) { + Printf("No pedestals found for DDL %d !\n"); + return; + } + + for(Int_t iCC=0; iCCGetMean(); + sig[g3][pad] = (Int_t) fPadAdc[iDDL][iX][iY]->GetRMS (); + //cout<< "ped is " << fPadAdc[iDDL][iX][iY]->GetMean()< fMaxThr) + write = (fMaxThr<<9) + 0; + else + write = ((ped[i3g][pad]+fSigCut * sig[i3g][pad])<<9) + fSigCut * sig[i3g][pad]; + + fprintf(pedFile, "0x%05x\n", write); + } + } + fclose(pedFile); + } // iCC +} // WritePedFiles(iDDL) +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +void AliPHOSCpvPedProducer::CreateErrHist() +{ + Int_t nErrors = AliPHOSCpvRawStream::GetNErrors(); + const char * errNames[nErrors]; + for(Int_t i=0; iGetXaxis(); + x->SetBinLabel(1, "Can't get event"); + for(Int_t i=0; iSetBinLabel(i+2,errNames[i]); + } +} +//-------------------------------------------------------------------------------------- +void AliPHOSCpvPedProducer::CreateDDLHistos(Int_t iDDL) +{ + // creating histograms + fPedMeanMap[iDDL] = new TH2F(Form("hPedMeanMap%d",iDDL),"2D mean pedestal map" ,AliPHOSCpvParam::kPadPcX,0.,AliPHOSCpvParam::kPadPcX,AliPHOSCpvParam::kPadPcY,0.,AliPHOSCpvParam::kPadPcY); + fPedSigMap [iDDL] = new TH2F(Form("hPedSigMap%d" ,iDDL),"2D pedestal sigma map",AliPHOSCpvParam::kPadPcX,0.,AliPHOSCpvParam::kPadPcX,AliPHOSCpvParam::kPadPcY,0.,AliPHOSCpvParam::kPadPcY); + f1DPedMean [iDDL] = new TH1F(Form("h1DPedMean%d" ,iDDL),"1D mean pedestal map" ,5000,0,5000); + f1DPedSigma[iDDL] = new TH1F(Form("h1DPedSigma%d",iDDL),"1D pedestal sigma map",100 ,0,100 ); + + // initialization of arrays + int adr; + for(Int_t iX=0; iX +#include +#include +#include +#include +#include +#include "AliPHOSCpvParam.h" +#include "AliPHOSCpvRawStream.h" +#include + +class TFile; +class AliPHOSCpvPedProducer: public TObject { + + +public: + AliPHOSCpvPedProducer(Int_t sigcut = 3); + virtual ~AliPHOSCpvPedProducer(); + void SetSigCut(Int_t sigcut = 3) {fSigCut = sigcut;} //set n. of pedestal distribution sigmas used to create zero suppresion table + Bool_t LoadNewEvent(AliRawReader *& rawReader); // returns true, if ok + void SetTurbo(Bool_t turbo); // if turbo==true then do read without error checking + Bool_t GetTurbo() const {return fTurbo;} + + Bool_t FillPedestal(Int_t pad,Float_t q); // pad - absolute pad number; q - charge of the pad + Bool_t FillPedestal(); // analyse event and fill pedestals + Bool_t CalcPedestal(Int_t iDDL); // analyse pedestals when all events processed for indicated DDL + + TH2F* GetPedMeanMap(Int_t iDDL) const {return fPedMeanMap[iDDL];} //Get the pedestal mean map for a DDL to send to AMORE + TH2F* GetPedSigMap(Int_t iDDL) const {return fPedSigMap[iDDL];} //Get the pedestal sigma map for a DDL to send to AMORE + TH1F* GetPedMean(Int_t iChFee) const {return f1DPedMean[iChFee];} //Get the pedestal mean map for a FEE channel to send to AMORE + TH1F* GetPedSigma(Int_t iChFee) const {return f1DPedSigma[iChFee];}//Get the pedestal Sigma map for a FEE channel to send to AMORE + void WritePedFiles(Int_t iDDL) const; // write pedestals to load(?) to RCB for indicated DDL + void WriteAllHistsToFile(const char* name) const; // create and write a new root file with hists + + void SetErrorsHist(TH1I * pHist) {fhErrors = new TH1I(*pHist);} //Set the histogram of errors, taken from AliPHOSCpvRawDigiProdicer + static Int_t GetMaxThr() {return fMaxThr;} // Get maximal threshold + +protected: + void CreateErrHist(); // initialize histogram of errors + void CreateDDLHistos(Int_t iDDL); // initialize histograms for pedestal calculation and representation + + TH1F *fPadAdc[AliPHOSCpvParam::kNDDL][AliPHOSCpvParam::kPadPcX][AliPHOSCpvParam::kPadPcY]; //Charge distribution for pads + Int_t fSigCut; //n. of pedestal distribution sigmas used to create zero suppresion table + static const Int_t fMaxThr = 511; //maximal threshold (9 bits all with 1) + Bool_t fTurbo; // if true, then read without error checking + + TH2F *fPedMeanMap[AliPHOSCpvParam::kNDDL]; //2D mean pedestal map to export to AMORE + TH2F *fPedSigMap [AliPHOSCpvParam::kNDDL]; //2D pedestal sigma map to export to AMORE + TH1F *f1DPedMean [AliPHOSCpvParam::kNDDL]; //1D mean pedestal map to export to AMORE + TH1F *f1DPedSigma[AliPHOSCpvParam::kNDDL]; //1D pedestal sigma map to export to AMORE + TH1I *fhErrors; //histogram of errors from AliPHOSCpvRawDigiProducer + AliPHOSCpvRawStream * fRawStream; //! Raw data stream +private: + ClassDef(AliPHOSCpvPedProducer,1); //Cpv calibration and pedestal class +}; +#endif diff --git a/PHOS/PHOSbase/CMakeLists.txt b/PHOS/PHOSbase/CMakeLists.txt index 311329a7e7e..03782a4df47 100644 --- a/PHOS/PHOSbase/CMakeLists.txt +++ b/PHOS/PHOSbase/CMakeLists.txt @@ -41,6 +41,7 @@ set(SRCS AliPHOSCpvRecPoint.cxx AliPHOSCpv3GConnection.cxx AliPHOSCpvParam.cxx + AliPHOSCpvPedProducer.cxx AliPHOSCpvRawDigiProducer.cxx AliPHOSCpvRawStream.cxx AliPHOSDigit.cxx diff --git a/PHOS/PHOSbase/PHOSbaseLinkDef.h b/PHOS/PHOSbase/PHOSbaseLinkDef.h index 611df561beb..ad0f4dfbd22 100644 --- a/PHOS/PHOSbase/PHOSbaseLinkDef.h +++ b/PHOS/PHOSbase/PHOSbaseLinkDef.h @@ -60,5 +60,6 @@ #pragma link C++ class AliPHOSCpvRawStream+; #pragma link C++ class AliPHOSCpvParam+; #pragma link C++ class AliPHOSCpv3GConnection+; +#pragma link C++ class AliPHOSCpvPedProducer+; #endif -- 2.43.5