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) {
46 TH1F::AddDirectory(0);
47 // --- Histograms for ADC pedestals
48 // [22 signal channels x 2 gain chains + 2 reference PTMs]
50 TH1F *hPed[44], *hPedOutOfTime[44];
53 char namhist1[50], namhist2[50], namhist3[50];
54 for(Int_t j=0; j<44; j++){
56 sprintf(namhist1,"PedZN1_%d",j);
57 sprintf(namhist2,"PedZN1OutOfTime_%d",j);
58 sprintf(namhist3,"PedCorrZN1_%d",j);
60 else if(j>=10 && j<20){
61 sprintf(namhist1,"PedZP1_%d",j-10);
62 sprintf(namhist2,"PedZP1OutOfTime_%d",j-10);
63 sprintf(namhist3,"PedCorrZP1_%d",j-10);
65 else if(j>=20 && j<24){
66 sprintf(namhist1,"PedZEM_%d",j-20);
67 sprintf(namhist2,"PedZEMOutOfTime_%d",j-20);
68 sprintf(namhist3,"PedCorrZEM_%d",j-20);
70 else if(j>=24 && j<33){
71 sprintf(namhist1,"PedZN2_%d",j-24);
72 sprintf(namhist2,"PedZN2OutOfTime_%d",j-24);
73 sprintf(namhist3,"PedCorrZN2_%d",j-24);
75 else if(j>=33 && j<43){
76 sprintf(namhist1,"PedZP2_%d",j-33);
77 sprintf(namhist2,"PedZP2OutOfTime_%d",j-33);
78 sprintf(namhist3,"PedCorrZP2_%d",j-33);
80 hPed[j] = new TH1F(namhist1, namhist1, 100,0., 200.);
81 hPedOutOfTime[j] = new TH1F(namhist2, namhist2, 100,0., 200.);
82 hPedCorr[j] = new TH2F(namhist3,namhist3,100,0.,200.,100,0.,200.);
88 printf("Wrong number of arguments\n");
93 /* open result file */
95 fp=fopen("./result.txt","a");
97 printf("Failed to open file\n");
102 /* define data source : this is argument 1 */
103 status = monitorSetDataSource( argv[1] );
105 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
110 /* declare monitoring program */
111 status = monitorDeclareMp( __FILE__ );
113 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
118 /* define wait event timeout - 1s max */
120 monitorSetNoWaitNetworkTimeout(1000);
123 /* log start of process */
124 printf("ZDC PEDESTAL monitoring program started\n");
126 /* init some counters */
127 int nevents_physics=0;
130 struct equipmentStruct *equipment;
137 struct eventHeaderStruct *event;
138 eventTypeType eventT;
141 /* main loop (infinite) */
144 /* check shutdown condition */
145 if (daqDA_checkShutdown()) {break;}
147 /* get next event (blocking call until timeout) */
148 status=monitorGetEventDynamic((void **)&event);
149 if (status==MON_ERR_EOF) {
150 printf ("End of File detected\n");
151 break; /* end of monitoring file has been reached */
155 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
159 /* retry if got no event */
166 /* use event - here, just write event id to result file */
167 eventT=event->eventType;
169 if(eventT==PHYSICS_EVENT){
170 //fprintf(fp,"Run #%lu, event size: %lu, BC:%u, Orbit:%u, Period:%u\n",
172 // Initalize raw-data reading and decoding
173 AliRawReader *reader = new AliRawReaderDate((void*)event);
174 const AliRawDataHeader* header = reader->GetDataHeader();
176 UChar_t message = header->GetL1TriggerMessage();
177 if(message & 0x40000){ // DEDICATED PEDESTAL RUN
178 printf("\t L1 message -> PEDESTAL raw data\n");
182 printf("\t L1 message -> NO PEDESTAL raw data found\n");
186 //Commented until we won't have Raw Data Header...
188 //printf("\t ERROR! No Raw Data Header found!!!\n");
193 AliZDCRawStream *rawStreamZDC = new AliZDCRawStream(reader);
195 if (!rawStreamZDC->Next()) printf(" \t No raw data found!! \n");
197 Int_t RawADC[44], RawADCoot[44];
198 for(Int_t j=0; j<44; j++){
202 while(rawStreamZDC->Next()){
204 if(rawStreamZDC->IsADCDataWord()){
205 if(rawStreamZDC->GetSector(0)==1 || rawStreamZDC->GetSector(0)==2){ // *** ZN1, ZP1
206 index = 10*(rawStreamZDC->GetSector(0)-1)+rawStreamZDC->GetSector(1)+5*rawStreamZDC->GetADCGain();
208 else if(rawStreamZDC->GetSector(0)==3){ // *** ZEM
209 index = 10*(rawStreamZDC->GetSector(0)-1)+(rawStreamZDC->GetSector(1)-1)+2*rawStreamZDC->GetADCGain();
211 else if(rawStreamZDC->GetSector(0)==4 || rawStreamZDC->GetSector(0)==5){ // *** ZN2, ZP2
212 index = 10*(rawStreamZDC->GetSector(0)-2)+rawStreamZDC->GetSector(1)+5*rawStreamZDC->GetADCGain()+4;
215 hPed[index]->Fill(rawStreamZDC->GetADCValue());
216 RawADC[counter] = rawStreamZDC->GetADCValue();
219 hPedOutOfTime[index]->Fill(rawStreamZDC->GetADCValue());
220 RawADCoot[counter-44] = rawStreamZDC->GetADCValue();
225 if(counter == 88){ // Last ADC channel
226 for(Int_t k=0; k<44; k++){
227 hPedCorr[k]->Fill(RawADCoot[k], RawADC[k]);
242 /* exit when last event received, no need to wait for TERM signal */
243 if (eventT==END_OF_RUN) {
244 printf("EOR event detected\n");
249 /* Analysis of the histograms */
252 fileShuttle = fopen("ZDCPedestal.dat","w");
254 Float_t MeanPed[44], MeanPedWidth[44],
255 MeanPedOOT[44], MeanPedWidthOOT[44],
256 CorrCoeff0[44], CorrCoeff1[44];
257 // --- Out-of-time pedestals
259 for(Int_t i=0; i<44; i++){
260 hPed[i]->Fit("gaus","Q");
261 ADCfunc[i] = hPed[i]->GetFunction("gaus");
262 MeanPed[i] = ADCfunc[i]->GetParameter(1);
263 MeanPedWidth[i] = ADCfunc[i]->GetParameter(2);
264 fprintf(fileShuttle,"\t%f\t%f\n",MeanPed[i],MeanPedWidth[i]);
265 //printf("\t MeanPed[%d] = %f\n",i, MeanPed[i]);
267 // --- Out-of-time pedestals
269 for(Int_t i=0; i<44; i++){
270 hPedOutOfTime[i]->Fit("gaus","Q");
271 ADCootfunc[i] = hPedOutOfTime[i]->GetFunction("gaus");
272 MeanPedOOT[i] = ADCootfunc[i]->GetParameter(1);
273 MeanPedWidthOOT[i] = ADCootfunc[i]->GetParameter(2);
274 fprintf(fileShuttle,"\t%f\t%f\n",MeanPedOOT[i],MeanPedWidthOOT[i]);
275 //printf("\t MeanPedOOT[%d] = %f\n",i, MeanPedOOT[i]);
278 // --- Fit of correlations
279 TProfile* hPedCorrProf[44];
282 for(int i=0;i<44;i++) {
283 sprintf(namhist4,"ADCvsOOT%d_Prof",i);
284 hPedCorrProf[i] = hPedCorr[i]->ProfileX(namhist4,-1,-1,"S");
285 hPedCorrProf[i]->SetName(namhist4);
286 hPedCorrProf[i]->Fit("pol1","Q");
287 ffunc[i] = hPedCorrProf[i]->GetFunction("pol1");
288 CorrCoeff0[i] = ffunc[i]->GetParameter(0);
289 CorrCoeff1[i] = ffunc[i]->GetParameter(1);
290 fprintf(fileShuttle,"\t%f\t%f\n",CorrCoeff0[i],CorrCoeff1[i]);
291 //printf("\t CorrCoeff0[%d] = %f, CorrCoeff1[%d] = %f\n",i, CorrCoeff0[i], i, CorrCoeff1[i]);
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 */