]> git.uio.no Git - u/mrichter/AliRoot.git/blob - VZERO/VZEROTUNING1da.cxx
Iteration number added into output file
[u/mrichter/AliRoot.git] / VZERO / VZEROTUNING1da.cxx
1 /*********************************************************************************
2 - Contact:    Brigitte Cheynis     b.cheynis@ipnl.in2p3.fr
3 - Link:       http
4 - Raw data test file : 
5 - Reference run number :              
6 - Run Type:   STANDALONE
7 - DA Type:    LDC
8 - Number of events needed: 500
9 - Input Files:  argument list
10 - Output Files: local file  V0_Tuning1.dat
11                 FXS file    V0_Tuning1.dat
12 - Trigger types used: PHYSICS_EVENT
13 **********************************************************************************/
14
15
16 /**********************************************************************************
17 *                                                                                 *
18 * VZERO Detector Algorithm used for tuning FEE parameters                         *
19 *                                                                                 *
20 * This program reads data on the LDC                                              *
21 * It cumulates fBB and fBG flags, populates local "./V0_Tuning1.dat"              *            
22 * file and exports it to the FES.                                                 *
23 * We have 128 channels instead of 64 as expected for V0 due to the two sets of    *
24 * charge integrators which are used by the FEE ...                                *
25 * The program reports about its processing progress.                              *
26 *                                                                                 *
27 ***********************************************************************************/
28
29 // DATE
30 #include "event.h"
31 #include "monitor.h"
32 #include "daqDA.h"
33
34 //AliRoot
35 #include <AliVZERORawStream.h>
36 #include <AliRawReaderDate.h>
37 #include <AliRawReader.h>
38 #include <AliDAQ.h>
39
40 // standard
41 #include <stdio.h>
42 #include <stdlib.h>
43
44 //ROOT
45 #include "TROOT.h"
46 #include "TPluginManager.h"
47 #include <TFile.h>
48 #include <TH1F.h>
49 #include <TMath.h>
50
51
52 /* Main routine --- Arguments: iteration number, data file */
53       
54 int main(int argc, char **argv) {
55
56 /* magic line from Cvetan */
57   gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
58                     "*",
59                     "TStreamerInfo",
60                     "RIO",
61                     "TStreamerInfo()");
62   int status;
63
64   Float_t BBFlag[128];
65   Float_t BGFlag[128];
66   for(Int_t i=0; i<128; i++) {
67       BBFlag[i] = 0.0;
68       BGFlag[i] = 0.0;
69   } 
70       
71   /* log start of process */
72   printf("VZERO DA program started - Tuning FEE parameters\n");  
73
74   /* check that we got some arguments  */
75   if (argc<2)   {
76       printf("Wrong number of arguments\n");
77       return -1;}
78
79   /* open result file to be exported to FES */
80   FILE *fp=NULL;
81   fp=fopen("./V0_Tuning1.dat","a");
82   if (fp==NULL) {
83       printf("Failed to open result file\n");
84       return -1;}
85
86   /* open log file to inform user */
87   FILE *flog=NULL;
88   flog=fopen("./V00log.txt","a");
89   if (flog==NULL) {
90       printf("Failed to open log file\n");
91       return -1;  }
92     
93   /* report progress */
94   daqDA_progressReport(10);
95
96   /* init counters on events */
97   int nevents_physics=0;
98   int nevents_total=0;
99
100   /* read the data  */
101   
102   status=monitorSetDataSource( argv[1] );
103   if (status!=0) {
104       printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
105       return -1; }
106
107   /* report progress */
108   daqDA_progressReport(50);
109
110   /* read the data file */
111   for(;;) {
112         struct eventHeaderStruct *event;
113         eventTypeType eventT;
114
115         /* get next event */
116         status=monitorGetEventDynamic((void **)&event);
117         if (status==MON_ERR_EOF) break; /* end of monitoring file has been reached */
118         if (status!=0) {
119             printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
120             return -1; }
121
122         /* retry if got no event */
123         if (event==NULL) break;
124         
125         /* decode event */
126         eventT=event->eventType;
127         
128         switch (event->eventType){
129       
130         case START_OF_RUN:
131              break;
132       
133         case END_OF_RUN:
134              printf("End Of Run detected\n");
135              break;
136       
137         case PHYSICS_EVENT:
138              nevents_physics++;
139              
140 //              fprintf(flog,"Run #%lu, event size: %lu, BC:%u, Orbit:%u, Period:%u\n",
141 //                  (unsigned long)event->eventRunNb,
142 //                  (unsigned long)event->eventSize,
143 //                  EVENT_ID_GET_BUNCH_CROSSING(event->eventId),
144 //                  EVENT_ID_GET_ORBIT(event->eventId),
145 //                  EVENT_ID_GET_PERIOD(event->eventId) );
146                  
147              AliRawReader *rawReader = new AliRawReaderDate((void*)event);
148   
149              AliVZERORawStream* rawStream  = new AliVZERORawStream(rawReader); 
150              rawStream->Next(); 
151              for(Int_t i=0; i<64; i++) {
152                 if(!rawStream->GetIntegratorFlag(i,10))
153                 {
154                    if(rawStream->GetBBFlag(i,10)) BBFlag[i]++;       // even integrator - channel 0 to 63
155                    if(rawStream->GetBGFlag(i,10)) BGFlag[i]++;       // even integrator - channel 0 to 63
156                 } 
157                 else 
158                 {                  
159                    if(rawStream->GetBBFlag(i,10)) BBFlag[i+64]++;    // odd integrator  - channel 64 to 123
160                    if(rawStream->GetBGFlag(i,10)) BGFlag[i+64]++;    // odd integrator  - channel 64 to 123
161                 }
162              }    
163              delete rawStream;
164              rawStream = 0x0;      
165              delete rawReader;
166              rawReader = 0x0;                                                                    
167         } // end of switch on event type 
168         
169         nevents_total++;
170         /* free resources */
171         free(event);
172
173   }  // loop over events
174     
175 //________________________________________________________________________
176 //  Computes mean values, dumps them into the output text file
177         
178   for(Int_t i=0; i<128; i++) {
179       BBFlag[i] = BBFlag[i]/nevents_physics;
180       BGFlag[i] = BGFlag[i]/nevents_physics;
181       fprintf(fp," %d %d %f %f\n",argc,i,BBFlag[i],BGFlag[i]);
182       fprintf(flog," %d %d %f %f\n",argc,i,BBFlag[i],BGFlag[i]);
183   } 
184   
185 //________________________________________________________________________
186    
187   /* write report */
188   fprintf(flog,"Run #%s, received %d physics events out of %d\n",getenv("DATE_RUN_NUMBER"),nevents_physics,nevents_total);
189   printf("Run #%s, received %d physics events out of %d\n",getenv("DATE_RUN_NUMBER"),nevents_physics,nevents_total);
190   
191   /* close result and log files */
192   fclose(fp);
193   fclose(flog); 
194   
195   /* report progress */
196   daqDA_progressReport(90);
197
198   /* export result file to FES */
199   status=daqDA_FES_storeFile("./V0_Tuning1.dat","V00da_results");
200   if (status)    {
201       printf("Failed to export file : %d\n",status);
202       return -1; }
203
204   /* report progress */
205   daqDA_progressReport(100);
206   
207   return status;
208 }