/*********************************************************************************
- Contact: Brigitte Cheynis b.cheynis@ipnl.in2p3.fr
-- Link: /afs/cern.ch/user/c/cheynis/public/run546.dat
+- Link: http
+- Raw data test file :
+- Reference run number :
- Run Type: PHYSICS
-- DA Type: LDC
-- Number of events needed: >=100
-- Input Files: raw_data_file_on_LDC
-- Output Files: local files V00Log.txt, VZERO_Histos.root, V0_Ped_Width_Gain.dat
- FXS file V0_Ped_Width_Gain.dat
-- Trigger types used:
+- DA Type: MON
+- Number of events needed: >=500
+- Input Files: argument list
+- Output Files: local files VZERO_Histos.root, V0_Pedestals.dat (Online mapping)
+ FXS file V0_Ped_Width_Gain.dat (Offline mapping)
+- Trigger types used: PHYSICS_EVENT
**********************************************************************************/
-
/**********************************************************************************
* *
* VZERO Detector Algorithm used for extracting calibration parameters *
* *
-* This program reads the DDL data file passed as argument using the monitoring *
-* library. *
+* This program connects to the DAQ data source passed as argument. *
* It computes calibration parameters, populates local "./V0_Ped_Width_Gain.dat" *
-* file and exports it to the FES. *
+* file, exports it to the FES, and stores it into DAQ DB *
+* The program exits when being asked to shut down (daqDA_checkshutdown) *
+* or on End of Run event. *
* We have 128 channels instead of 64 as expected for V0 due to the two sets of *
* charge integrators which are used by the FEE ... *
-* The program reports about its processing progress. *
* *
***********************************************************************************/
#include <TH1F.h>
#include <TMath.h>
+Int_t GetOfflineChannel(Int_t channel);
-/* Main routine --- Arguments: list of DATE raw data files */
+/* Main routine --- Arguments: monitoring data source */
int main(int argc, char **argv) {
+/* magic line from Cvetan */
+ gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
+ "*",
+ "TStreamerInfo",
+ "RIO",
+ "TStreamerInfo()");
int status;
+ if (argc!=2) {
+ printf("Wrong number of arguments\n");
+ return -1;
+ }
+
+ // Online values (using FEE channel numbering),
+ // stored into local V0_Pedestals.dat:
+ Double_t adcMean[128];
+ Double_t adcSigma[128];
+ Double_t pedMean[128];
+ Double_t pedSigma[128];
+ // Offline values(same but ordered as in aliroot for offliners)
+ // stored into V0_Ped_Width_Gain.dat:
+ Double_t adcMeanOff[128];
+ Double_t adcSigmaOff[128];
+ Double_t pedMeanOff[128];
+ Double_t pedSigmaOff[128];
+
+//___________________________________________________
+// Get cuts from V00DA.config file
- printf(" argc = %d, argv = %s \n",argc, &(**argv));
+ Int_t kClockMin; // = 16; LHC Clock Min for pedestal calculation
+ Int_t kClockMax; // = 19; LHC Clock Max for pedestal calculation
+ Int_t kLowCut; // = 60; low cut on signal distribution - to be tuned
+ Int_t kHighCut; // = 50; high cut on pedestal distribution - to be tuned
+ Int_t kClockMinRef; // = 16; LHC Clock Min for Flag checking
+ Int_t kClockMaxRef; // = 20; LHC Clock Max for Flag checking
+ Float_t kChi2Max; // = 1. Maximum chi2
- Int_t kHighCut = 50; // high cut on pedestal distribution - to be tuned
- Int_t kLowCut = 30; // low cut on signal distribution - to be tuned
- Double_t ADCmean[128];
- Double_t PEDmean[128];
- Double_t PEDsigma[128];
+ status = daqDA_DB_getFile("V00DA.config","./V00DA.config");
+ if (status) {
+ printf("Failed to get Config file (V00DA.config) from DAQ DB, status=%d\n", status);
+ printf("Take default values of parameters for pedestal calculation \n");
+ kClockMin = 16;
+ kClockMax = 19;
+ kLowCut = 60;
+ kHighCut = 50;
+ kClockMinRef = 16;
+ kClockMaxRef = 20;
+ kChi2Max = 1.;
+ } else {
+ /* open the config file and retrieve cuts */
+ FILE *fpConfig = fopen("V00DA.config","r");
+ int res = fscanf(fpConfig,"%d %d %d %d %d %d %f",&kClockMin,&kClockMax,&kLowCut,&kHighCut,&kClockMinRef,&kClockMaxRef,&kChi2Max);
+ if(res!=7) {
+ printf("Failed to get values from Config file (V00DA.config): wrong file format - 4 integers are expected - \n");
+ kClockMin = 16;
+ kClockMax = 19;
+ kLowCut = 60;
+ kHighCut = 50;
+ kClockMinRef = 16;
+ kClockMaxRef = 20;
+ kChi2Max = 1.;
+ }
+ fclose(fpConfig);
+ }
+ printf("LHC Clock Min for pedestal calculation = %d; LHC Clock Max for pedestal calculation = %d; LowCut on signal = %d ; HighCut on pedestal = %d\n",
+ kClockMin, kClockMax, kLowCut, kHighCut);
+
//___________________________________________________
// Book HISTOGRAMS - dynamics of p-p collisions -
- char ADCname[6];
- char PEDname[6];
+ char adcName[6];
+ char pedName[6];
TH1F *hADCname[128];
TH1F *hPEDname[128];
char texte[12];
for (Int_t i=0; i<128; i++) {
- sprintf(ADCname,"hADC%d",i);
+ sprintf(adcName,"hADC%d",i);
sprintf(texte,"ADC cell%d",i);
- hADCname[i] = new TH1F(ADCname,texte,1024,0,1023);
- sprintf(PEDname,"hPED%d",i);
+ hADCname[i] = new TH1F(adcName,texte,1024,-0.5, 1023.5);
+ sprintf(pedName,"hPED%d",i);
sprintf(texte,"PED cell%d",i);
- hPEDname[i] = new TH1F(PEDname,texte,1024,0,1023);}
+ hPEDname[i] = new TH1F(pedName,texte,1024,-0.5, 1023.5);
+ }
//___________________________________________________
-
-
- /* log start of process */
- printf("VZERO DA program started\n");
- /* check that we got some arguments = list of files */
- if (argc<2) {
- printf("Wrong number of arguments\n");
+ /* open result file to be exported to FES */
+ FILE *fpLocal=NULL;
+ fpLocal=fopen("./V0_Pedestals.dat","w");
+ if (fpLocal==NULL) {
+ printf("Failed to open local result file\n");
return -1;}
-
+
/* open result file to be exported to FES */
FILE *fp=NULL;
- fp=fopen("./V0_Ped_Width_Gain.dat","a");
+ fp=fopen("./V0_Ped_Width_Gain.dat","w");
if (fp==NULL) {
printf("Failed to open result file\n");
return -1;}
- /* open log file to inform user */
- FILE *flog=NULL;
- flog=fopen("./V00log.txt","a");
- if (flog==NULL) {
- printf("Failed to open log file\n");
- return -1; }
-
- /* report progress */
- daqDA_progressReport(10);
+ /* define data source : this is argument 1 */
+ 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);
+
/* init counters on events */
- int nevents_physics=0;
- int nevents_total=0;
+ int neventsPhysics=0;
+ int neventsTotal=0;
- /* read the data files, considering n files */
-
- int n;
-
- for (n=1;n<argc;n++) {
-
- status=monitorSetDataSource( argv[n] );
- if (status!=0) {
- printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
- return -1; }
-
- /* report progress - here indexed on the number of files */
- daqDA_progressReport(10+80*n/argc);
-
- /* read the data file */
- for(;;) {
- struct eventHeaderStruct *event;
- eventTypeType eventT;
-
- /* get next event */
- status=monitorGetEventDynamic((void **)&event);
- if (status==MON_ERR_EOF) break; /* end of monitoring file has been reached */
- if (status!=0) {
- printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
- return -1; }
-
- /* retry if got no event */
- if (event==NULL) break;
-
- /* decode event */
- eventT=event->eventType;
+ /* loop on events (infinite) */
+ for(;;) {
+ struct eventHeaderStruct *event;
+ eventTypeType eventT;
+
+ /* check shutdown condition */
+ if (daqDA_checkShutdown()) {break;}
+
+ /* get next event (blocking call until timeout) */
+ status=monitorGetEventDynamic((void **)&event);
+ if (status==MON_ERR_EOF) {
+ printf ("End of File detected\n");
+ break; /* end of monitoring file has been reached */
+ }
+
+ if (status!=0) {
+ printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
+ break;
+ }
+
+ /* retry if got no event */
+ if (event==NULL) continue;
+
+ /* decode event */
+ eventT=event->eventType;
- switch (event->eventType){
+ switch (event->eventType){
- case START_OF_RUN:
- break;
+ case START_OF_RUN:
+ break;
- case END_OF_RUN:
- printf("End Of Run detected\n");
- break;
+ case END_OF_RUN:
+ printf("End Of Run detected\n");
+ break;
- case PHYSICS_EVENT:
- nevents_physics++;
-
- fprintf(flog,"Run #%lu, event size: %lu, BC:%u, Orbit:%u, Period:%u\n",
- (unsigned long)event->eventRunNb,
- (unsigned long)event->eventSize,
- EVENT_ID_GET_BUNCH_CROSSING(event->eventId),
- EVENT_ID_GET_ORBIT(event->eventId),
- EVENT_ID_GET_PERIOD(event->eventId) );
-
- AliRawReader *rawReader = new AliRawReaderDate((void*)event);
+ case PHYSICS_EVENT:
+ neventsPhysics++;
+
+ AliRawReader *rawReader = new AliRawReaderDate((void*)event);
- AliVZERORawStream* rawStream = new AliVZERORawStream(rawReader);
- rawStream->Next();
- for(Int_t i=0; i<64; i++) {
- if(!rawStream->GetIntegratorFlag(i,10))
- hADCname[i]->Fill(float(rawStream->GetADC(i))); // even integrator - fills 0 to 63
- else
- hADCname[i+64]->Fill(float(rawStream->GetADC(i))); // odd integrator - fills 64 to 123
- for(Int_t j=0; j<21; j++) {
- if(j==10) continue;
- if(!rawStream->GetIntegratorFlag(i,j))
- { hPEDname[i]->Fill(float(rawStream->GetPedestal(i,j))); } // even integrator
- else
- { hPEDname[i+64]->Fill(float(rawStream->GetPedestal(i,j))); } // odd integrator
- }
- }
- delete rawStream;
- rawStream = 0x0;
- delete rawReader;
- rawReader = 0x0;
- } // end of switch on event type
+ AliVZERORawStream* rawStream = new AliVZERORawStream(rawReader);
+ if (rawStream->Next()) {
+ for(Int_t i=0; i<64; i++) {
+ Int_t nFlag = 0;
+ for(Int_t j=kClockMinRef; j <= kClockMaxRef; j++) { // Check flags on clock range used for pedestal calculation
+ if((rawStream->GetBBFlag(i,j)) || (rawStream->GetBGFlag(i,j))) nFlag++;
+ }
+ if(nFlag == 0){ // Fill 64*2 pedestal histograms - 2 integrators -
+ Float_t sum[2] = {0.,0.};
+ Float_t sumwi[2] = {0.,0.};
+ for(Int_t j=kClockMin;j <= kClockMax;j++){
+ Int_t integrator = rawStream->GetIntegratorFlag(i,j);
+ Float_t pedestal = (float)(rawStream->GetPedestal(i,j));
+ sum[integrator] += pedestal;
+ sumwi[integrator] += 1.;
+ }
+ Float_t mean[2] = {0.,0.};
+ Float_t chi2[2] = {0.,0.};
+
+ for(int ii=0;ii<2;ii++) if(sumwi[ii]>1.e-6) mean[ii] = sum[ii] / sumwi[ii];
+
+ for(Int_t j=kClockMin;j <= kClockMax;j++){
+ Int_t integrator = rawStream->GetIntegratorFlag(i,j);
+ Float_t pedestal = (float)(rawStream->GetPedestal(i,j));
+ chi2[integrator] += (mean[integrator] - pedestal) * (mean[integrator] - pedestal);
+ }
+ if(chi2[0]<kChi2Max && chi2[1]<kChi2Max) {
+ for(int ii=0;ii<2;ii++){
+ if(mean[ii] >1.e-6) hPEDname[i + 64*ii]->Fill(mean[ii]);
+ }
+ }
+
+ }
+ if((rawStream->GetBBFlag(i,10)) || (rawStream->GetBGFlag(i,10))){ // Charge
+ Int_t integrator = rawStream->GetIntegratorFlag(i,10);
+ Float_t charge = (float)(rawStream->GetADC(i)); // Fill 64*2 ADCmax histograms
+ hADCname[i + 64 * integrator]->Fill(charge);
+ }
+ } // End loop over channels
+ } // End : if rawstream
+ delete rawStream;
+ rawStream = 0x0;
+ delete rawReader;
+ rawReader = 0x0;
+ } // end of switch on event type
+
+ neventsTotal++;
+ /* free resources */
+ free(event);
- nevents_total++;
- /* free resources */
- free(event);
+ /* exit when last event received, no need to wait for TERM signal */
+ if (eventT==END_OF_RUN) {
+ printf("End Of Run event detected\n");
+ break;
+ }
- } // loop over events
+ } // loop over events
+
+ printf("%d physics events processed\n",neventsPhysics);
- } // loop over data files
-//________________________________________________________________________
-// Computes mean values, dumps them into the output text file
+//___________________________________________________________________________
+// Computes mean values, converts FEE channels into Offline AliRoot channels
+// and dumps the ordered values into the output text file for SHUTTLE
for(Int_t i=0; i<128; i++) {
hPEDname[i]->GetXaxis()->SetRange(0,kHighCut);
- PEDmean[i] = hPEDname[i]->GetMean();
- PEDsigma[i] = hPEDname[i]->GetRMS();
- hADCname[i]->GetXaxis()->SetRange(kLowCut,1023);
- ADCmean[i] = hADCname[i]->GetMean() ;
- fprintf(fp," %.3f %.3f %.3f\n",PEDmean[i],PEDsigma[i],ADCmean[i]);
- }
-
+ pedMean[i] = hPEDname[i]->GetMean();
+ pedSigma[i] = hPEDname[i]->GetRMS();
+ hADCname[i]->GetXaxis()->SetRange(kLowCut,1024);
+ adcMean[i] = hADCname[i]->GetMean();
+ adcSigma[i] = hADCname[i]->GetRMS();
+// printf(" i = %d, %.3f %.3f %.3f %.3f\n",i,pedMean[i],pedSigma[i],adcMean[i],adcSigma[i]);
+ fprintf(fpLocal," %.3f %.3f %.3f %.3f\n",pedMean[i],pedSigma[i],
+ adcMean[i],adcSigma[i]);
+ if (i < 64) {
+ Int_t j = GetOfflineChannel(i);
+ pedMeanOff[j] = pedMean[i];
+ pedSigmaOff[j] = pedSigma[i];
+ adcMeanOff[j] = adcMean[i];
+ adcSigmaOff[j] = adcSigma[i]; }
+ else{
+ Int_t j = GetOfflineChannel(i-64);
+ pedMeanOff[j+64] = pedMean[i];
+ pedSigmaOff[j+64] = pedSigma[i];
+ adcMeanOff[j+64] = adcMean[i];
+ adcSigmaOff[j+64] = adcSigma[i];
+ }
+ }
+
+ for(Int_t j=0; j<128; j++) {
+// printf(" j = %d, %.3f %.3f %.3f %.3f\n",j,pedMeanOff[j],pedSigmaOff[j],
+// adcMeanOff[j],adcSigmaOff[j]);
+ fprintf(fp," %.3f %.3f %.3f %.3f\n",pedMeanOff[j],pedSigmaOff[j],
+ adcMeanOff[j],adcSigmaOff[j]);
+ }
+
//________________________________________________________________________
// Write root file with histos for users further check - just in case -
TFile *histoFile = new TFile("VZERO_histos.root","RECREATE");
for (Int_t i=0; i<128; i++) {
- hADCname[i]->GetXaxis()->SetRange(0,1023);
+ hADCname[i]->GetXaxis()->SetRange(0,1024);
hADCname[i]->Write();
hPEDname[i]->Write(); }
//________________________________________________________________________
- /* write report */
- fprintf(flog,"Run #%s, received %d physics events out of %d\n",getenv("DATE_RUN_NUMBER"),nevents_physics,nevents_total);
- printf("Run #%s, received %d physics events out of %d\n",getenv("DATE_RUN_NUMBER"),nevents_physics,nevents_total);
-
- /* close result and log files */
+ /* close local result file and FXS result file*/
+ fclose(fpLocal);
fclose(fp);
- fclose(flog);
-
- /* report progress */
- daqDA_progressReport(90);
-
-
+
/* export result file to FES */
status=daqDA_FES_storeFile("./V0_Ped_Width_Gain.dat","V00da_results");
if (status) {
printf("Failed to export file : %d\n",status);
return -1; }
- /* report progress */
- daqDA_progressReport(100);
-
+ /* store result file into Online DB */
+ status=daqDA_DB_storeFile("./V0_Pedestals.dat","V00da_results");
+ if (status) {
+ printf("Failed to store file into Online DB: %d\n",status);
+ return -1; }
+
return status;
}
+
+ Int_t GetOfflineChannel(Int_t channel) {
+
+// Channel mapping Online - Offline:
+
+ Int_t fOfflineChannel[64] = {39, 38, 37, 36, 35, 34, 33, 32,
+ 47, 46, 45, 44, 43, 42, 41, 40,
+ 55, 54, 53, 52, 51, 50, 49, 48,
+ 63, 62, 61, 60, 59, 58, 57, 56,
+ 7, 6, 5, 4, 3, 2, 1, 0,
+ 15, 14, 13, 12, 11, 10, 9, 8,
+ 23, 22, 21, 20, 19, 18, 17, 16,
+ 31, 30, 29, 28, 27, 26, 25, 24};
+ return fOfflineChannel[channel];
+}