5 This program connects to the DAQ data source passed as argument
6 and populates local "./result.txt" file with the ids of events received
9 The program exits when being asked to shut down (daqDA_checkshutdown)
12 Messages on stdout are exported to DAQ log system.
14 DA for ZDC standalon pedestal runs
15 contact: Chiara.Oppedisano@cern.ch
20 #include <Riostream.h>
36 #include <AliRawReaderDate.h>
37 #include <AliZDCRawStream.h>
42 1- monitoring data source
44 int main(int argc, char **argv) {
47 // --- Preparing histos for EM dissociation spectra
50 TH1F* histoEMDCorr[4];
52 char namhistr[50], namhistc[50];
53 for(Int_t i=0; i<4; i++) {
55 sprintf(namhistr,"ZN%d-EMDRaw",i+1);
56 sprintf(namhistc,"ZN%d-EMDCorr",i+1);
59 sprintf(namhistr,"ZP%d-EMDRaw",i);
60 sprintf(namhistc,"ZP%d-EMDCorr",i);
63 sprintf(namhistr,"ZN%d-EMDRaw",i);
64 sprintf(namhistc,"ZN%d-EMDCorr",i);
67 sprintf(namhistr,"ZP%d-EMDRaw",i-1);
68 sprintf(namhistc,"ZP%d-EMDCorr",i-1);
70 histoEMDRaw[i] = new TH1F(namhistr,namhistr,100,0.,4000.);
71 histoEMDCorr[i] = new TH1F(namhistc,namhistc,100,0.,4000.);
77 printf("Wrong number of arguments\n");
82 /* open result file */
84 fp=fopen("./result.txt","a");
86 printf("Failed to open file\n");
91 /* define data source : this is argument 1 */
92 status = monitorSetDataSource( argv[1] );
94 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
99 /* declare monitoring program */
100 status = monitorDeclareMp( __FILE__ );
102 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
107 /* define wait event timeout - 1s max */
109 monitorSetNoWaitNetworkTimeout(1000);
112 /* log start of process */
113 printf("ZDC PEDESTAL monitoring program started\n");
115 /* init some counters */
116 int nevents_physics=0;
119 struct equipmentStruct *equipment;
125 struct eventHeaderStruct *event;
126 eventTypeType eventT;
129 /* main loop (infinite) */
132 /* check shutdown condition */
133 if (daqDA_checkShutdown()) {break;}
135 /* get next event (blocking call until timeout) */
136 status=monitorGetEventDynamic((void **)&event);
137 if (status==MON_ERR_EOF) {
138 printf ("End of File detected\n");
139 break; /* end of monitoring file has been reached */
143 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
147 /* retry if got no event */
154 /* use event - here, just write event id to result file */
155 eventT=event->eventType;
157 if(eventT==PHYSICS_EVENT){
159 // *** To analyze EMD events you MUST have a pedestal data file!!!
160 // *** -> check if a pedestal run has been analyzied
162 filePed=fopen("./ZDCPedestal.dat","r");
164 printf("\t ERROR!!! You MUST have a ZDCPedestal.dat file!!!\n");
167 // 132 = 44 in-time + 44 out-of-time + 44 correlations
168 Float_t readValues[2][132], MeanPed[44], MeanPedWidth[44],
169 MeanPedOOT[44], MeanPedWidthOOT[44],
170 CorrCoeff0[44], CorrCoeff1[44];
172 for(int jj=0; jj<132; jj++){
173 for(int ii=0; ii<2; ii++){
174 fscanf(filePed,"%f",&readValues[ii][jj]);
177 MeanPed[jj] = readValues[0][jj];
178 MeanPedWidth[jj] = readValues[1][jj];
180 else if(jj>44 && jj<88){
181 MeanPedOOT[jj-44] = readValues[0][jj];
182 MeanPedWidthOOT[jj-44] = readValues[1][jj];
185 CorrCoeff0[jj-88] = readValues[0][jj];
186 CorrCoeff1[jj-88] = readValues[1][jj];;
191 // Initalize raw-data reading and decoding
192 AliRawReader *reader = new AliRawReaderDate((void*)event);
193 const AliRawDataHeader* header = reader->GetDataHeader();
195 UChar_t message = header->GetL1TriggerMessage();
198 printf("\t ATTENTION! No Raw Data Header found!!!\n");
202 AliZDCRawStream *rawStreamZDC = new AliZDCRawStream(reader);
204 if (!rawStreamZDC->Next()) printf(" \t No raw data found!! ");
206 Float_t ZDCRawADC[4], ZDCCorrADC[4], ZDCCorrADCSum[4];
207 for(Int_t g=0; g<4; g++){
208 ZDCCorrADCSum[g] = 0.;
212 while(rawStreamZDC->Next()){
213 if(rawStreamZDC->IsADCDataWord()){
214 Int_t StartIndex[4] = {5,15,29,39};
216 if(rawStreamZDC->GetSector(0) == 1 || rawStreamZDC->GetSector(0) == 2)
217 DetIndex = rawStreamZDC->GetSector(0)-1;
218 else if(rawStreamZDC->GetSector(0) == 4 || rawStreamZDC->GetSector(0) == 5)
219 DetIndex = rawStreamZDC->GetSector(0)-2;
221 if(rawStreamZDC->GetADCGain() == 1){ //EMD -> LR ADC
223 ZDCRawADC[DetIndex] += (Float_t) rawStreamZDC->GetADCValue();
224 Int_t PedIndex = StartIndex[DetIndex]+rawStreamZDC->GetSector(1);
225 // Mean pedestal subtraction
226 Float_t Pedestal = MeanPed[PedIndex];
227 // Pedestal subtraction from correlation with out-of-time signals
228 //Float_t Pedestal = ;
230 ZDCCorrADC[DetIndex] = (rawStreamZDC->GetADCValue()) - Pedestal;
231 ZDCCorrADCSum[DetIndex] += ZDCCorrADC[DetIndex];
239 for(Int_t j=0; j<4; j++){
240 histoEMDRaw[j]->Fill(ZDCRawADC[j]);
241 histoEMDCorr[j]->Fill(ZDCCorrADCSum[j]);
251 /* exit when last event received, no need to wait for TERM signal */
252 if (eventT==END_OF_RUN) {
253 printf("EOR event detected\n");
258 /* Analysis of the histograms */
261 fileShuttle = fopen("ZDCEMD.dat","w");
266 Float_t MeanFitVal[4];
268 for(Int_t k=0; k<4; k++){
269 BinMax[k] = histoEMDCorr[k]->GetMaximumBin();
270 YMax[k] = (histoEMDCorr[k]->GetXaxis())->GetXmax();
271 NBinsx[k] = (histoEMDCorr[k]->GetXaxis())->GetNbins();
272 //printf("\n\t Det%d -> BinMax = %d, ChXMax = %f\n", k+1, BinMax[k], BinMax[k]*YMax[k]/NBinsx[k]);
273 histoEMDCorr[k]->Fit("gaus","Q","",BinMax[k]*YMax[k]/NBinsx[k]*0.7,BinMax[k]*YMax[k]/NBinsx[k]*1.25);
274 fitfun[k] = histoEMDCorr[k]->GetFunction("gaus");
275 MeanFitVal[k] = (Float_t) (fitfun[k]->GetParameter(1));
276 //printf("\n\t Mean Value from gaussian fit = %f\n", MeanFitVal[k]);
279 Float_t CalibCoeff[6];
280 /*for(Int_t j=0; j<6; j++){
281 if(j<4) CalibCoeff[j] = 2.76/MeanFitVal[j];
282 else CalibCoeff[j] = 1.;
283 fprintf(fileShuttle,"\t%f\n",CalibCoeff[j]);
286 // --- For the moment we have sim data only for ZN1!!!
287 for(Int_t j=0; j<6; j++){
288 if(j==0 || j==1) CalibCoeff[j] = 2.76/MeanFitVal[j];
289 else if(j>0 && j<4) CalibCoeff[j] = CalibCoeff[0];
290 else CalibCoeff[j] = 1.;
291 fprintf(fileShuttle,"\t%f\n",CalibCoeff[j]);
298 fprintf(fp,"Run #%s, received %d physics events out of %d\n",getenv("DATE_RUN_NUMBER"),nevents_physics,nevents_total);
300 /* close result file */