3 This program reads the DAQ data files passed as argument using the monitoring library.
5 It computes the average event size and populates local "./result.txt" file with the
8 The program reports about its processing progress.
10 Messages on stdout are exported to DAQ log system.
12 DA for ZDC standalone pedestal runs
14 Contact: Chiara.Oppedisano@to.infn.it
16 Run Type: STANDALONE_EMD_RUN
18 Number of events needed: at least ~5*10^3
19 Input Files: ZDCPedestal.dat
20 Output Files: ZDCEMDCalib.dat, ZDCChMapping.dat
21 Trigger Types Used: Standalone Trigger
24 #define PEDDATA_FILE "ZDCPedestal.dat"
27 #include <Riostream.h>
28 #include <Riostream.h>
45 #include <AliRawReaderDate.h>
46 #include <AliRawEventHeaderBase.h>
47 #include <AliZDCRawStream.h>
52 1- monitoring data source
54 int main(int argc, char **argv) {
56 TFitter *minuitFit = new TFitter(4);
57 TVirtualFitter::SetFitter(minuitFit);
61 /* log start of process */
62 printf("ZDC EMD program started\n");
64 /* check that we got some arguments = list of files */
66 printf("Wrong number of arguments\n");
71 // --- Preparing histos for EM dissociation spectra
74 TH1F* histoEMDCorr[4];
76 char namhistr[50], namhistc[50];
77 for(Int_t i=0; i<4; i++) {
79 sprintf(namhistr,"ZN%d-EMDRaw",i+1);
80 sprintf(namhistc,"ZN%d-EMDCorr",i+1);
83 sprintf(namhistr,"ZP%d-EMDRaw",i);
84 sprintf(namhistc,"ZP%d-EMDCorr",i);
87 sprintf(namhistr,"ZN%d-EMDRaw",i);
88 sprintf(namhistc,"ZN%d-EMDCorr",i);
91 sprintf(namhistr,"ZP%d-EMDRaw",i-1);
92 sprintf(namhistc,"ZP%d-EMDCorr",i-1);
94 histoEMDRaw[i] = new TH1F(namhistr,namhistr,100,0.,4000.);
95 histoEMDCorr[i] = new TH1F(namhistc,namhistc,100,0.,4000.);
98 /* open result file */
100 fp=fopen("./result.txt","a");
102 printf("Failed to open file\n");
106 FILE *mapFile4Shuttle;
107 const char *mapfName = "ZDCChMapping.dat";
108 // *** To analyze LASER events you MUST have a pedestal data file!!!
109 // *** -> check if a pedestal run has been analyzied
111 read = daqDA_FES_storeFile(PEDDATA_FILE,"ZDCPEDESTAL_data");
113 printf("\t ERROR!!! ZDCPedestal.dat file NOT FOUND in DAQ db!!!\n");
116 else printf("\t ZDCPedestal.dat file retrieved from DAQ db\n");
118 FILE *filePed = fopen(PEDDATA_FILE,"r");
120 printf("\t ERROR!!! Can't open ZDCPedestal.dat file!!!\n");
124 // 144 = 48 in-time + 48 out-of-time + 48 correlations
125 Float_t readValues[2][144], MeanPed[44], MeanPedWidth[44],
126 MeanPedOOT[44], MeanPedWidthOOT[44];
127 // ***************************************************
128 // Unless we have a narrow correlation to fit we
129 // don't fit and store in-time vs. out-of-time
130 // histograms -> mean pedstal subtracted!!!!!!
131 // ***************************************************
132 //Float_t CorrCoeff0[44], CorrCoeff1[44];
134 for(int jj=0; jj<144; jj++){
135 for(int ii=0; ii<2; ii++){
136 fscanf(filePed,"%f",&readValues[ii][jj]);
139 MeanPed[jj] = readValues[0][jj];
140 MeanPedWidth[jj] = readValues[1][jj];
141 //printf("\t MeanPed[%d] = %1.1f\n",jj, MeanPed[jj]);
143 else if(jj>48 && jj<96){
144 MeanPedOOT[jj-48] = readValues[0][jj];
145 MeanPedWidthOOT[jj-48] = readValues[1][jj];
148 CorrCoeff0[jj-96] = readValues[0][jj];
149 CorrCoeff1[jj-96] = readValues[1][jj];;
154 /* report progress */
155 daqDA_progressReport(10);
158 /* init some counters */
159 int nevents_physics=0;
162 /* read the data files */
166 status=monitorSetDataSource( argv[n] );
168 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
172 /* report progress */
173 /* in this example, indexed on the number of files */
174 daqDA_progressReport(10+80*n/argc);
178 struct eventHeaderStruct *event;
179 eventTypeType eventT;
182 status=monitorGetEventDynamic((void **)&event);
183 if(status==MON_ERR_EOF) break; /* end of monitoring file has been reached */
185 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
189 /* retry if got no event */
194 // Initalize raw-data reading and decoding
195 AliRawReader *reader = new AliRawReaderDate((void*)event);
196 reader->Select("ZDC");
197 // --- Reading event header
198 //UInt_t evtype = reader->GetType();
199 //printf("\n\t ZDCEMDda -> ev. type %d\n",evtype);
200 //printf("\t ZDCEMDda -> run # %d\n",reader->GetRunNumber());
202 AliZDCRawStream *rawStreamZDC = new AliZDCRawStream(reader);
205 /* use event - here, just write event id to result file */
206 eventT=event->eventType;
208 Int_t ich=0, adcMod[48], adcCh[48], sigCode[48], det[48], sec[48];
209 if(eventT==START_OF_DATA){
211 if(!rawStreamZDC->Next()) printf(" \t No raw data found!! \n");
213 while(rawStreamZDC->Next()){
214 if(rawStreamZDC->IsChMapping()){
215 adcMod[ich] = rawStreamZDC->GetADCModFromMap(ich);
216 adcCh[ich] = rawStreamZDC->GetADCChFromMap(ich);
217 sigCode[ich] = rawStreamZDC->GetADCSignFromMap(ich);
218 det[ich] = rawStreamZDC->GetDetectorFromMap(ich);
219 sec[ich] = rawStreamZDC->GetTowerFromMap(ich);
224 // --------------------------------------------------------
225 // --- Writing ascii data file for the Shuttle preprocessor
226 mapFile4Shuttle = fopen(mapfName,"w");
227 for(Int_t i=0; i<ich; i++){
228 fprintf(mapFile4Shuttle,"\t%d\t%d\t%d\t%d\t%d\t%d\n",i,
229 adcMod[i],adcCh[i],sigCode[i],det[i],sec[i]);
231 //printf("ZDCPEDESTALDA.cxx -> ch.%d mod %d, ch %d, code %d det %d, sec %d\n",
232 // i,adcMod[i],adcCh[i],sigCode[i],det[i],sec[i]);
234 fclose(mapFile4Shuttle);
237 if(eventT==PHYSICS_EVENT){
238 // --- Reading data header
239 reader->ReadHeader();
240 const AliRawDataHeader* header = reader->GetDataHeader();
242 UChar_t message = header->GetAttributes();
243 if(message & 0x70){ // DEDICATED EMD RUN
244 //printf("\t STANDALONE_EMD_RUN raw data found\n");
248 printf("\t NO STANDALONE_EMD_RUN raw data found\n");
253 printf("\t ATTENTION! No Raw Data Header found!!!\n");
257 if (!rawStreamZDC->Next()) printf(" \t No raw data found!! ");
259 // ----- Setting ch. mapping -----
260 for(Int_t jk=0; jk<48; jk++){
261 rawStreamZDC->SetMapADCMod(jk, adcMod[jk]);
262 rawStreamZDC->SetMapADCCh(jk, adcCh[jk]);
263 rawStreamZDC->SetMapADCSig(jk, sigCode[jk]);
264 rawStreamZDC->SetMapDet(jk, det[jk]);
265 rawStreamZDC->SetMapTow(jk, sec[jk]);
268 Float_t ZDCRawADC[4], ZDCCorrADC[4], ZDCCorrADCSum[4];
269 for(Int_t g=0; g<4; g++){
270 ZDCCorrADCSum[g] = 0.;
274 while(rawStreamZDC->Next()){
275 if(rawStreamZDC->IsADCDataWord()){
276 Int_t DetIndex=999, PedIndex=999;
277 if(rawStreamZDC->GetSector(0) == 1 || rawStreamZDC->GetSector(0) == 2){
278 DetIndex = rawStreamZDC->GetSector(0)-1;
279 PedIndex = (rawStreamZDC->GetSector(0)+1)+4*rawStreamZDC->GetSector(1);
281 else if(rawStreamZDC->GetSector(0) == 4 || rawStreamZDC->GetSector(0) == 5){
282 DetIndex = rawStreamZDC->GetSector(0)-2;
283 PedIndex = (rawStreamZDC->GetSector(0)-2)+4*rawStreamZDC->GetSector(1)+24;
286 if(rawStreamZDC->GetADCGain() == 1){ //EMD -> LR ADC
288 ZDCRawADC[DetIndex] += (Float_t) rawStreamZDC->GetADCValue();
289 // Mean pedestal subtraction
290 Float_t Pedestal = MeanPed[PedIndex];
291 // Pedestal subtraction from correlation with out-of-time signals
292 //Float_t Pedestal = CorrCoeff0[PedIndex]+CorrCoeff1[PedIndex]*MeanPedOOT[PedIndex];
294 ZDCCorrADC[DetIndex] = (rawStreamZDC->GetADCValue()) - Pedestal;
295 ZDCCorrADCSum[DetIndex] += ZDCCorrADC[DetIndex];
297 /*printf("\t det %d quad %d res %d pedInd %d ADCCorr %d ZDCCorrADCSum[%d] = %d\n",
298 rawStreamZDC->GetSector(0),rawStreamZDC->GetSector(1),
299 rawStreamZDC->GetADCGain(),PedIndex,
300 (Int_t) (rawStreamZDC->GetADCValue() - Pedestal), DetIndex,
301 (Int_t) ZDCCorrADCSum[DetIndex]);
310 for(Int_t j=0; j<4; j++){
311 histoEMDRaw[j]->Fill(ZDCRawADC[j]);
312 histoEMDCorr[j]->Fill(ZDCCorrADCSum[j]);
321 /* exit when last event received, no need to wait for TERM signal */
322 if (eventT==END_OF_RUN) {
323 printf("EOR event detected\n");
330 /* Analysis of the histograms */
333 const char *fName = "ZDCPedestal.dat";
334 fileShuttle = fopen(fName,"w");
339 Float_t MeanFitVal[4];
341 for(Int_t k=0; k<4; k++){
342 BinMax[k] = histoEMDCorr[k]->GetMaximumBin();
343 YMax[k] = (histoEMDCorr[k]->GetXaxis())->GetXmax();
344 NBinsx[k] = (histoEMDCorr[k]->GetXaxis())->GetNbins();
345 // printf("\n\t Det%d -> BinMax = %d, ChXMax = %f\n", k+1, BinMax[k], BinMax[k]*YMax[k]/NBinsx[k]);
346 histoEMDCorr[k]->Fit("gaus","Q","",BinMax[k]*YMax[k]/NBinsx[k]*0.7,BinMax[k]*YMax[k]/NBinsx[k]*1.25);
347 fitfun[k] = histoEMDCorr[k]->GetFunction("gaus");
348 MeanFitVal[k] = (Float_t) (fitfun[k]->GetParameter(1));
349 //printf("\n\t Mean Value from gaussian fit = %f\n", MeanFitVal[k]);
352 Float_t CalibCoeff[6];
353 /*for(Int_t j=0; j<6; j++){
354 if(j<4) CalibCoeff[j] = MeanFitVal[j];
355 else CalibCoeff[j] = 1.;
356 fprintf(fileShuttle,"\t%f\n",CalibCoeff[j]);
359 // --- For the moment we have sim data only for ZN1!!!
360 for(Int_t j=0; j<6; j++){
361 if(j==0) CalibCoeff[j] = MeanFitVal[j];
362 else if(j>0 && j<4) CalibCoeff[j] = CalibCoeff[0];
363 else CalibCoeff[j] = 1.;
364 fprintf(fileShuttle,"\t%f\n",CalibCoeff[j]);
369 for(Int_t ij=0; ij<4; ij++){
370 delete histoEMDRaw[ij];
371 delete histoEMDCorr[ij];
375 TVirtualFitter::SetFitter(0);
378 fprintf(fp,"Run #%s, received %d physics events out of %d\n",getenv("DATE_RUN_NUMBER"),nevents_physics,nevents_total);
380 /* close result file */
383 /* report progress */
384 daqDA_progressReport(90);
386 /* store the result file on FES */
387 status = daqDA_FES_storeFile(mapfName,"ZDCCHMAPPING_data");
389 printf("Failed to export file : %d\n",status);
393 status = daqDA_FES_storeFile(fName,"ZDCEMD_data");
395 printf("Failed to export file : %d\n",status);
399 /* report progress */
400 daqDA_progressReport(100);