7 This program reads the DAQ data files passed as argument using the monitoring library.
9 It computes the average event size and populates local "./result.txt" file with the
12 The program reports about its processing progress.
14 Messages on stdout are exported to DAQ log system.
16 DA for ZDC standalone pedestal runs
18 Contact: Chiara.Oppedisano@to.infn.it
19 Link: /afs/cern.ch/user/c/chiarao/public/RawPed.date
20 Run Type: STANDALONE_PEDESTAL_RUN
22 Number of events needed: no constraint (tipically ~10^3)
24 Output Files: ZDCPedestal.dat
25 Trigger Types Used: Standalone Trigger
31 #include <Riostream.h>
47 #include <AliRawReaderDate.h>
48 #include <AliZDCRawStream.h>
52 Arguments: list of DATE raw data files
54 int main(int argc, char **argv) {
58 /* log start of process */
59 printf("ZDC PEDESTAL monitoring program started\n");
61 /* check that we got some arguments = list of files */
63 printf("Wrong number of arguments\n");
67 // --- Histograms for ADC pedestals
68 // [22 signal channels + 2 reference PTMs] x 2 gain chains
70 TH1F::AddDirectory(0);
71 int const kNChannels = 24;
72 TH1F *hPedhg[kNChannels], *hPedOutOfTimehg[kNChannels];
73 TH2F *hPedCorrhg[kNChannels];
74 TH1F *hPedlg[kNChannels], *hPedOutOfTimelg[kNChannels];
75 TH2F *hPedCorrlg[kNChannels];
77 char namhist1hg[50], namhist2hg[50], namhist3hg[50];
78 char namhist1lg[50], namhist2lg[50], namhist3lg[50];
79 for(Int_t j=0; j<kNChannels; j++){
81 sprintf(namhist1hg,"PedZN1hg_%d",j);
82 sprintf(namhist2hg,"PedZN1hgOutOfTime_%d",j);
83 sprintf(namhist3hg,"PedCorrZN1hg_%d",j);
85 sprintf(namhist1lg,"PedZN1lg_%d",j);
86 sprintf(namhist2lg,"PedZN1lgOutOfTime_%d",j);
87 sprintf(namhist3lg,"PedCorrZN1lg_%d",j);
89 else if(j>=5 && j<10){ // ZP1
90 sprintf(namhist1hg,"PedZP1hg_%d",j-5);
91 sprintf(namhist2hg,"PedZP1hgOutOfTime_%d",j-5);
92 sprintf(namhist3hg,"PedCorrZP1hg_%d",j-5);
94 sprintf(namhist1lg,"PedZP1lg_%d",j-5);
95 sprintf(namhist2lg,"PedZP1lgOutOfTime_%d",j-5);
96 sprintf(namhist3lg,"PedCorrZP1lg_%d",j-5);
98 else if(j>=10 && j<12){ // ZEM
99 sprintf(namhist1hg,"PedZEMhg_%d",j-10);
100 sprintf(namhist2hg,"PedZEMhgOutOfTime_%d",j-10);
101 sprintf(namhist3hg,"PedCorrZEMhg_%d",j-10);
103 sprintf(namhist1lg,"PedZEMlg_%d",j-10);
104 sprintf(namhist2lg,"PedZEMlgOutOfTime_%d",j-10);
105 sprintf(namhist3lg,"PedCorrZEMlg_%d",j-10);
107 else if(j>=12 && j<17){ // ZN2
108 sprintf(namhist1hg,"PedZN2hg_%d",j-12);
109 sprintf(namhist2hg,"PedZN2hgOutOfTime_%d",j-12);
110 sprintf(namhist3hg,"PedCorrZN2hg_%d",j-12);
112 sprintf(namhist1lg,"PedZN2lg_%d",j-12);
113 sprintf(namhist2lg,"PedZN2lgOutOfTime_%d",j-12);
114 sprintf(namhist3lg,"PedCorrZN2lg_%d",j-12);
116 else if(j>=17 && j<22){ // ZP2
117 sprintf(namhist1hg,"PedZP2hg_%d",j-17);
118 sprintf(namhist2hg,"PedZP2hgOutOfTime_%d",j-17);
119 sprintf(namhist3hg,"PedCorrZP2hg_%d",j-17);
121 sprintf(namhist1lg,"PedZP2lg_%d",j-17);
122 sprintf(namhist2lg,"PedZP2lgOutOfTime_%d",j-17);
123 sprintf(namhist3lg,"PedCorrZP2lg_%d",j-17);
125 else if(j>=22 && j<24){ //Reference PMs
126 sprintf(namhist1hg,"PedRefhg_%d",j-22);
127 sprintf(namhist2hg,"PedRefhgOutOfTime_%d",j-22);
128 sprintf(namhist3hg,"PedCorrRefhg_%d",j-22);
130 sprintf(namhist1lg,"PedReflg_%d",j-22);
131 sprintf(namhist2lg,"PedReflgOutOfTime_%d",j-22);
132 sprintf(namhist3lg,"PedCorrReflg_%d",j-22);
134 // --- High gain chain histos
135 hPedhg[j] = new TH1F(namhist1hg, namhist1hg, 100,0., 200.);
136 hPedOutOfTimehg[j] = new TH1F(namhist2hg, namhist2hg, 100,0., 200.);
137 hPedCorrhg[j] = new TH2F(namhist3hg,namhist3hg,100,0.,200.,100,0.,200.);
138 // --- Low gain chain histos
139 hPedlg[j] = new TH1F(namhist1lg, namhist1lg, 100,0., 600.);
140 hPedOutOfTimelg[j] = new TH1F(namhist2lg, namhist2lg, 100,0., 600.);
141 hPedCorrlg[j] = new TH2F(namhist3lg,namhist3lg,100,0.,600.,100,0.,600.);
145 /* open result file */
147 fp=fopen("./result.txt","a");
149 printf("Failed to open file\n");
154 /* report progress */
155 daqDA_progressReport(10);
158 /* init some counters */
159 int nevents_physics=0;
162 /* read the data files */
164 for (n=1;n<argc;n++) {
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 */
195 /* use event - here, just write event id to result file */
196 eventT=event->eventType;
198 if(eventT==PHYSICS_EVENT){
199 fprintf(fp,"Run #%lu, event size: %lu, BC:%u, Orbit:%u, Period:%u\n",
200 (unsigned long)event->eventRunNb,
201 (unsigned long)event->eventSize,
202 EVENT_ID_GET_BUNCH_CROSSING(event->eventId),
203 EVENT_ID_GET_ORBIT(event->eventId),
204 EVENT_ID_GET_PERIOD(event->eventId));
206 // Initalize raw-data reading and decoding
207 AliRawReader *reader = new AliRawReaderDate((void*)event);
208 const AliRawDataHeader* header = reader->GetDataHeader();
210 UChar_t message = header->GetAttributes();
211 if(message & 0x20){ // DEDICATED PEDESTAL RUN
212 printf("\t STANDALONE_PEDESTAL_RUN raw data found\n");
216 printf("\t NO STANDALONE_PEDESTAL_RUN raw data found\n");
220 //Commented until we won't have true Raw Data Header...
222 // printf("\t ATTENTION! No Raw Data Header found!!!\n");
226 AliZDCRawStream *rawStreamZDC = new AliZDCRawStream(reader);
228 if (!rawStreamZDC->Next()) printf(" \t No raw data found!! \n");
230 Int_t RawADChg[kNChannels], RawADCoothg[kNChannels];
231 Int_t RawADClg[kNChannels], RawADCootlg[kNChannels];
232 for(Int_t j=0; j<kNChannels; j++){
233 RawADChg[j]=0; RawADCoothg[j]=0;
234 RawADClg[j]=0; RawADCootlg[j]=0;
236 while(rawStreamZDC->Next()){
238 if(rawStreamZDC->IsADCDataWord()){
239 if(rawStreamZDC->GetSector(1)!=5){ // Physics signals
240 if(rawStreamZDC->GetSector(0)==1) index = rawStreamZDC->GetSector(1); // *** ZNC
241 else if(rawStreamZDC->GetSector(0)==2) index = rawStreamZDC->GetSector(1)+5; // *** ZPC
242 else if(rawStreamZDC->GetSector(0)==3) index = rawStreamZDC->GetSector(1)+9; // *** ZEM
243 else if(rawStreamZDC->GetSector(0)==4) index = rawStreamZDC->GetSector(1)+12; // *** ZNA
244 else if(rawStreamZDC->GetSector(0)==5) index = rawStreamZDC->GetSector(1)+17; // *** ZPA
246 else{ // Reference PMs
247 index = (rawStreamZDC->GetSector(0)-1)/3+22;
250 /*printf("\t counter %d index %d det %d quad %d res %d ADC %d\n", counter, index,
251 rawStreamZDC->GetSector(0), rawStreamZDC->GetSector(1),
252 rawStreamZDC->GetADCGain(), rawStreamZDC->GetADCValue());
255 if(counter<2*kNChannels){ // --- In-time pedestals (1st 48 raw data)
256 if(rawStreamZDC->GetADCGain()==0){
257 hPedhg[index]->Fill(rawStreamZDC->GetADCValue());
258 RawADChg[index] = rawStreamZDC->GetADCValue();
261 hPedlg[index]->Fill(rawStreamZDC->GetADCValue());
262 RawADClg[index] = rawStreamZDC->GetADCValue();
265 else{ // --- Out-of-time pedestals
266 if(rawStreamZDC->GetADCGain()==0){
267 hPedOutOfTimehg[index]->Fill(rawStreamZDC->GetADCValue());
268 RawADCoothg[index] = rawStreamZDC->GetADCValue();
271 hPedOutOfTimelg[index]->Fill(rawStreamZDC->GetADCValue());
272 RawADCootlg[index] = rawStreamZDC->GetADCValue();
278 if(counter == 4*kNChannels){ // Last ADC channel -> Filling correlation histos
279 for(Int_t k=0; k<kNChannels; k++){
280 hPedCorrhg[k]->Fill(RawADCoothg[k], RawADChg[k]);
281 hPedCorrlg[k]->Fill(RawADCootlg[k], RawADClg[k]);
291 }//(if PHYSICS_EVENT)
300 /* Analysis of the histograms */
303 const char *fName = "ZDCPedestal.dat";
304 fileShuttle = fopen(fName,"w");
306 Float_t MeanPed[2*kNChannels], MeanPedWidth[2*kNChannels],
307 MeanPedOOT[2*kNChannels], MeanPedWidthOOT[2*kNChannels],
308 CorrCoeff0[2*kNChannels], CorrCoeff1[2*kNChannels];
309 // --- In-time pedestals
310 TF1 *ADCfunchg[kNChannels];
311 for(Int_t i=0; i<kNChannels; i++){
312 hPedhg[i]->Fit("gaus","Q");
313 ADCfunchg[i] = hPedhg[i]->GetFunction("gaus");
314 MeanPed[i] = ADCfunchg[i]->GetParameter(1);
315 MeanPedWidth[i] = ADCfunchg[i]->GetParameter(2);
316 fprintf(fileShuttle,"\t%d\t%f\t%f\n",i,MeanPed[i],MeanPedWidth[i]);
317 //printf("\t MeanPed[%d] = %f\n",i, MeanPed[i]);
319 TF1 *ADCfunclg[kNChannels];
320 for(Int_t i=0; i<kNChannels; i++){
321 hPedlg[i]->Fit("gaus","Q");
322 ADCfunclg[i] = hPedlg[i]->GetFunction("gaus");
323 MeanPed[i+kNChannels] = ADCfunclg[i]->GetParameter(1);
324 MeanPedWidth[i+kNChannels] = ADCfunclg[i]->GetParameter(2);
325 fprintf(fileShuttle,"\t%d\t%f\t%f\n",i+kNChannels,MeanPed[i+kNChannels],MeanPedWidth[i+kNChannels]);
326 //printf("\t MeanPed[%d] = %f\n",i+kNChannels, MeanPed[i+kNChannels]);
328 // --- Out-of-time pedestals
329 TF1 *ADCootfunchg[kNChannels];
330 for(Int_t i=0; i<kNChannels; i++){
331 hPedOutOfTimehg[i]->Fit("gaus","Q");
332 ADCootfunchg[i] = hPedOutOfTimehg[i]->GetFunction("gaus");
333 MeanPedOOT[i] = ADCootfunchg[i]->GetParameter(1);
334 MeanPedWidthOOT[i] = ADCootfunchg[i]->GetParameter(2);
335 fprintf(fileShuttle,"\t%d\t%f\t%f\n",i,MeanPedOOT[i],MeanPedWidthOOT[i]);
336 //printf("\t MeanPedOOT[%d] = %f\n",i, MeanPedOOT[i]);
338 TF1 *ADCootfunclg[kNChannels];
339 for(Int_t i=0; i<kNChannels; i++){
340 hPedOutOfTimelg[i]->Fit("gaus","Q");
341 ADCootfunclg[i] = hPedOutOfTimelg[i]->GetFunction("gaus");
342 MeanPedOOT[i+kNChannels] = ADCootfunclg[i]->GetParameter(1);
343 MeanPedWidthOOT[i+kNChannels] = ADCootfunclg[i]->GetParameter(2);
344 fprintf(fileShuttle,"\t%d\t%f\t%f\n",i+kNChannels,MeanPedOOT[i+kNChannels],MeanPedWidthOOT[i+kNChannels]);
345 //printf("\t MeanPedOOT[%d] = %f\n",i+kNChannels, MeanPedOOT[i+kNChannels]);
349 TProfile *hPedCorrProfhg[kNChannels], *hPedCorrProflg[kNChannels];
350 TF1 *ffunchg[kNChannels], *ffunclg[kNChannels];
352 for(int i=0;i<kNChannels;i++) {
353 sprintf(namhist4,"ADCHRvsOOT%d_Prof",i);
354 hPedCorrProfhg[i] = hPedCorrhg[i]->ProfileX(namhist4,-1,-1,"S");
355 hPedCorrProfhg[i]->SetName(namhist4);
356 hPedCorrProfhg[i]->Fit("pol1","Q");
357 ffunchg[i] = hPedCorrProfhg[i]->GetFunction("pol1");
358 CorrCoeff0[i] = ffunchg[i]->GetParameter(0);
359 CorrCoeff1[i] = ffunchg[i]->GetParameter(1);
360 fprintf(fileShuttle,"\t%d\t%f\t%f\n",i,CorrCoeff0[i],CorrCoeff1[i]);
361 //printf("\t CorrCoeff0[%d] = %f, CorrCoeff1[%d] = %f\n",i, CorrCoeff0[i], i, CorrCoeff1[i]);
363 for(int i=0;i<kNChannels;i++) {
364 sprintf(namhist4,"ADCLRvsOOT%d_Prof",i);
365 hPedCorrProflg[i] = hPedCorrlg[i]->ProfileX(namhist4,-1,-1,"S");
366 hPedCorrProflg[i]->SetName(namhist4);
367 hPedCorrProflg[i]->Fit("pol1","Q");
368 ffunclg[i] = hPedCorrProflg[i]->GetFunction("pol1");
369 CorrCoeff0[i+kNChannels] = ffunclg[i]->GetParameter(0);
370 CorrCoeff1[i+kNChannels] = ffunclg[i]->GetParameter(1);
371 fprintf(fileShuttle,"\t%d\t%f\t%f\n",i+kNChannels,CorrCoeff0[i+kNChannels],CorrCoeff1[i+kNChannels]);
372 //printf("\t CorrCoeff0[%d] = %f, CorrCoeff1[%d] = %f\n",
373 // i+kNChannels, CorrCoeff0[i+kNChannels], i+kNChannels, CorrCoeff1[i+kNChannels]);
378 for(Int_t j=0; j<kNChannels; j++){
380 delete hPedOutOfTimehg[j];
381 delete hPedCorrhg[j];
383 delete hPedOutOfTimelg[j];
384 delete hPedCorrlg[j];
388 fprintf(fp,"Run #%s, received %d physics events out of %d\n",getenv("DATE_RUN_NUMBER"),nevents_physics,nevents_total);
390 /* close result file */
393 /* report progress */
394 daqDA_progressReport(90);
396 /* store the result file on FES */
397 status = daqDA_FES_storeFile(fName,"ZDCPEDESTAL_data");
399 printf("Failed to export file : %d\n",status);
403 /* report progress */
404 daqDA_progressReport(100);