X-Git-Url: http://git.uio.no/git/?a=blobdiff_plain;f=HMPID%2FHMPIDda.cxx;h=ab8be123e7095264f67ed4e61ff5b1d26c455abb;hb=a6e0ebfecb0f40425d846df3110255aecf0a2c4b;hp=7eed96d37a6c222b08ebccc7206b91d0fd2f049e;hpb=6f14ad738e861e4397d61e58e0e8197583131be2;p=u%2Fmrichter%2FAliRoot.git diff --git a/HMPID/HMPIDda.cxx b/HMPID/HMPIDda.cxx index 7eed96d37a6..ab8be123e70 100644 --- a/HMPID/HMPIDda.cxx +++ b/HMPID/HMPIDda.cxx @@ -1,9 +1,18 @@ /* -********************************************************* -Author: * -this file provides the detector algorithm for HMPID. * -********************************************************* + +HMPID DA for online calibration + +Contact: Levente.Molnar@ba.infn.it, Giacomo.Volpe@ba.infn.it +Link: http://richpc1.ba.infn.it/~levente/Files4Public/ValidateHmpidDA/ +Run Type: PEDESTAL -- but we select on the PHYSICS_EVENTS in th HMPIDda.cxx +DA Type: LDC +Number of events needed: 1000 events +Input Files: Raw pedestal file, EXTERNAL config file: HmpidSigmaCut.txt on both HMPID LDCs +Output Files: 14 txt files including pedestal values +Trigger types used: PEDESTAL RUN (selecting on PHYSICS_EVENT) + */ + extern "C" { #include } @@ -12,28 +21,39 @@ extern "C" { #include "monitor.h" #include +#include "fstream.h" #include #include //AliRoot -//#include "AliHMPIDRawStream.h" +#include "AliHMPIDRawStream.h" +#include "AliHMPIDCalib.h" #include "AliRawReaderDate.h" #include "AliBitPacking.h" -#include "TMath.h" //ROOT +#include "TROOT.h" #include "TFile.h" -#include "TKey.h" -#include "TH2S.h" +#include "TSystem.h" +#include "TString.h" #include "TObject.h" -#include "TBenchmark.h" -#include "TMath.h" -#include "TRandom.h" +#include "TPluginManager.h" + int main(int argc, char **argv){ int status; + const Char_t *hmpConfigFile = "HmpDaqDaConfig.txt"; + const Int_t ddlOffset = 1536; + TString hmpIn; + TString feeIn; + + + /* log start of process */ + printf("HMPID DA program started\n"); + gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo","*","TStreamerInfo","RIO","TStreamerInfo()"); + /* check that we got some arguments = list of files */ if (argc<2) { printf("Wrong number of arguments\n"); @@ -41,43 +61,43 @@ int main(int argc, char **argv){ } /* copy locally a file from daq detector config db */ - status=daqDA_DB_getFile("myconfig","./myconfig.txt"); - if (status) { - printf("Failed to get config file : %d\n",status); - return -1; - } - /* and possibly use it */ - - /* open result file */ - FILE *fp=NULL; - fp=fopen("./result.txt","a"); - if (fp==NULL) { - printf("Failed to open file\n"); - return -1; - } + hmpIn=Form("./%s",hmpConfigFile); + status=daqDA_DB_getFile(hmpConfigFile,hmpIn.Data()); + if (status) { printf("Failed to get HMPID config file status: %d\n",status); return -1; } /* report progress */ daqDA_progressReport(10); + + + /* define wait event timeout - 1s max */ + monitorSetNowait(); + monitorSetNoWaitNetworkTimeout(1000); - /* init some counters */ - //int nevents_physics=0; - //int nevents_total=0; - - Float_t SummQ[14][48][11][25], Mean[14][48][11][25], SummQ2[14][48][11][25], Sigma[14][48][11][25]; - - Int_t iEvtNcal=0; - - ofstream out; - - for(Int_t ddl=0;ddl<=13;ddl++) for(Int_t row=1;row<=24;row++) for(Int_t dil=1;dil<=10;dil++) for(Int_t adr=0;adr<=47;adr++) - - { - SummQ[ddl][adr][dil][row]=0; SummQ2[ddl][adr][dil][row]=0; Mean[ddl][adr][dil][row]=0; Sigma[ddl][adr][dil][row]=0; - } - - int n; - for (n=1;nSetSigCutFromFile(hmpIn); + + /* ONLY set this option to kTRUE if you want to create the ADC dsitributions for all 161280 pads!!!!*/ + /* kTRUE is not suggested for production mode b/c of the memory consumption! */ + pCal->SetWriteHistoPads(kFALSE); //use this option for default production useage!!! + //pCal->SetWriteHistoPads(kTRUE); //only for expert debug + //pCal->SetWriteHistoPads(kTRUE,kTRUE,13); //DO NOT USE THIS OPTION! + + + /* init event counter */ + Int_t firstEvt=0; + Int_t iEvtNcal=firstEvt; //Start from 1 not 0! + ULong_t runNum=0; + ULong_t ldcId=0; + + int n; + for (n=1;neventType; - if (eventT==CALIBRATION_EVENT) { - - iEvtNcal++; - - AliRawReader *pRR = new AliRawReaderDate((void*)event); - - pRR->Select("HMPID");//select only one DDL files - - UInt_t RawDataWord=0; - - while(pRR->ReadNextInt(RawDataWord)) //raw records loop (in selected DDL files) - { - Int_t ddl = pRR->GetDDLID(); - - Int_t a = AliBitPacking::UnpackWord(RawDataWord,12,17); assert(0<=a&&a<=47); // 1098 7654 3210 9876 5432 1098 7654 3210 DILOGIC address (0..47) - Int_t d = AliBitPacking::UnpackWord(RawDataWord,18,21); assert(1<=d&&d<=10); // 3322 2222 2222 1111 1111 1000 0000 0000 DILOGIC number (1..10) - Int_t r = AliBitPacking::UnpackWord(RawDataWord,22,26); assert(1<=r&&r<=24); // Row number (1..24) - - Int_t q = AliBitPacking::UnpackWord(RawDataWord, 0,11); assert(0<=q&&q<=4095); // 0000 0rrr rrdd ddaa aaaa qqqq qqqq qqqq Qdc (0..4095) - - SummQ[ddl][a][d][r]+=q; - - SummQ2[ddl][a][d][r]+=(q*q); - - }//raw records loop - - delete pRR; - + if (eventT==PHYSICS_EVENT || eventT==CALIBRATION_EVENT ) { //updated: 18/02/2008 based on http://alice-ecs.web.cern.ch/alice-ecs/runtypes_3.16.html + runNum=(unsigned long)event->eventRunNb; //assuming that only one run is processed at a time + ldcId=(unsigned long)event->eventLdcId; + if(iEvtNcal==firstEvt && pCal->GetWritePads()==kTRUE) + { + if(pCal->GetLargePads()==kFALSE) pCal->InitFile((Int_t)ldcId); //The number for iEvtNcal should be the same as for the first value + else pCal->InitFile((Int_t)runNum); //The number for iEvtNcal should be the same as for the first value + } + + iEvtNcal++; + AliRawReader *reader = new AliRawReaderDate((void*)event); + AliHMPIDRawStream stream(reader);stream.SetTurbo(kTRUE); //raw data decoding without error checks SetTurbo(kTRUE) + while(stream.Next()) + { + for(Int_t iPad=0;iPadFillPedestal(stream.GetPadArray()[iPad],stream.GetChargeArray()[iPad]); + } //pads + }//while -- loop on det load in one event + + for(Int_t iddl=0;iddlFillDDLCnt(iddl,stream.GetnDDLInStream()[iddl],stream.GetnDDLOutStream()[iddl]); + for(Int_t ierr=0; ierr < stream.GetNErrors(); ierr++) { + pCal->FillErrors(iddl,ierr,stream.GetErrors(iddl,ierr)); + } + }//err + + pCal->SetRunParams(runNum,stream.GetTimeStamp(),stream.GetLDCNumber()); //Get the last TimeStam read and the LDC ID + stream.Delete(); }// if CALIBRATION_EVENT /* exit when last event received, no need to wait for TERM signal */ @@ -148,52 +177,47 @@ int main(int argc, char **argv){ } // events loop - free(event); - } - -} - /* close result file */ - fclose(fp); + free(event); + } - /* report progress */ - daqDA_progressReport(90); + }//arg + + /* write report */ + printf("HMPID DA processed RUN #%s on LDC#%d, with %d calibration events\n",getenv("DATE_RUN_NUMBER"),ldcId,iEvtNcal); - /* store the result file on FES */ - status=daqDA_FES_storeFile("./result.txt","DAcase1_results"); - if (status) { - printf("Failed to export file : %d\n",status); + if (!iEvtNcal) { + printf("No calibration events have been read. Exiting\n"); return -1; } + /* report progress */ + daqDA_progressReport(90); + + for(Int_t nDDL=0; nDDL < AliHMPIDRawStream::kNDDL; nDDL++) { + feeIn=Form("thr%d.dat",ddlOffset+nDDL); + /* Calculate pedestal for the given ddl, if there is no ddl go t next */ + if(pCal->CalcPedestal(nDDL,Form("HmpidPedDdl%02i.txt",nDDL),Form("%s",feeIn.Data()),iEvtNcal)) { + status=daqDA_DB_storeFile(feeIn.Data(),feeIn.Data()); //store a single threshold file for a DDL in DAQ DB + if (status) { printf("Failed to store file %s in DAQ DB, status: %d\n",feeIn.Data(),status); } + status=daqDA_FES_storeFile(Form("HmpidPedDdl%02i.txt",nDDL),Form("HmpidPedDdl%02i.txt",nDDL)); //store a single pedestal file for a DDL + if (status) { printf("Failed to export file on FES: %d\n",status); } + }//pedestals and thresholds + if(pCal->WriteErrors(nDDL,Form("HmpidErrorsDdl%02i.txt",nDDL),iEvtNcal)) { + status=daqDA_FES_storeFile(Form("HmpidErrorsDdl%02i.txt",nDDL),Form("HmpidErrorsDdl%02i.txt",nDDL)); + if (status) { printf("Failed to export file : %d\n",status); } + }//errors + /* to create pedestal file as Paolo uncomment the line */ + //if(!pCal->CalcPedestalPaolo(nDDL,Form("%sHmpidPedDdl%02i.txt",sDaOut.Data(),nDDL),iEvtNcal)) continue; + }//nDDL + + if(pCal->GetWritePads()==kTRUE) pCal->CloseFile(); + delete pCal; + if (status) return -1; + /* report progress */ daqDA_progressReport(100); - + + return status; - - for(Int_t ddl=0;ddl<=13;ddl++){ - - out.open(Form("HmpidPedDdl%02i.txt",ddl)); - - for(Int_t row=1;row<=24;row++) - - for(Int_t dil=1;dil<=10;dil++) - - for(Int_t adr=0;adr<=47;adr++){ - - Mean[ddl][adr][dil][row] = SummQ[ddl][adr][dil][row]/iEvtNcal; - - Sigma[ddl][adr][dil][row] = TMath::Sqrt(SummQ2[ddl][adr][dil][row]/iEvtNcal - (SummQ[ddl][adr][dil][row]/iEvtNcal)*(SummQ[ddl][adr][dil][row]/iEvtNcal)); - - Int_t inhard=((Int_t(Mean[ddl][adr][dil][row]))<<9)+Int_t(Mean[ddl][adr][dil][row]+3*Sigma[ddl][adr][dil][row]); - - out << Form("%2i %2i %2i %5.2f %5.2f %x\n",row,dil,adr,Mean[ddl][adr][dil][row],Sigma[ddl][adr][dil][row],inhard); - - } - } } -//} - - - -