]> git.uio.no Git - u/mrichter/AliRoot.git/blob - VZERO/VZEROINTEGRATIONGATETUNINGda.cxx
Changes in QA to be able to process separately different triggers (Ruben)
[u/mrichter/AliRoot.git] / VZERO / VZEROINTEGRATIONGATETUNINGda.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:   INTEGRATION_GATE_TUNING (not defined yet)
7 - DA Type:    LDC
8 - Number of events needed: 500
9 - Input Files:  argument list
10 - Output Files: local file  V0_IntegrationGateTuning.dat
11                 FXS file    V0_IntegrationGateTuning.dat
12 - Trigger types used: PHYSICS_EVENT
13 **********************************************************************************/
14
15
16 /**********************************************************************************
17 *                                                                                 *
18 * VZERO Detector Algorithm used for tuning Integration Gates                      *
19 *                                                                                 *
20 * This program reads data on the LDC                                              *
21 * It cumulates mean ADC responses ,  populates local                              *
22 *                                   "./V0_IntegrationGateTuning.dat"  file        * 
23 * and exports it to the FES.                                                      *
24 * We have 128 channels instead of 64 as expected for V0 due to the two sets of    *
25 * charge integrators which are used by the FEE ...                                *
26 * The program reports about its processing progress.                              *
27 *                                                                                 *
28 ***********************************************************************************/
29
30 // DATE
31 #include "event.h"
32 #include "monitor.h"
33 #include "daqDA.h"
34
35 //AliRoot
36 #include <AliVZERORawStream.h>
37 #include <AliRawReaderDate.h>
38 #include <AliRawReader.h>
39 #include <AliDAQ.h>
40
41 // standard
42 #include <stdio.h>
43 #include <stdlib.h>
44
45 //ROOT
46 #include "TROOT.h"
47 #include "TPluginManager.h"
48 #include <TFile.h>
49 #include <TH1F.h>
50 #include <TMath.h>
51
52
53 /* Main routine --- Arguments: list of DATE raw data files */
54       
55 int main(int argc, char **argv) {
56
57 /* magic line from Cvetan */
58   gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
59                     "*",
60                     "TStreamerInfo",
61                     "RIO",
62                     "TStreamerInfo()");
63
64   int status;
65   status = daqDA_DB_getFile("V00da_results","./V0_Pedestals.dat");
66   if (status) {
67       printf("Failed to get Pedestal file (V0_Pedestals.dat) from DAQ DB, status=%d\n", status);
68       return -1;   
69   }
70   
71   Float_t MeanPed[128], SigPed[128], fdump;
72   
73   /* open the pedestal file and retrieve pedestal mean and sigma */
74   FILE *fpPed = fopen("V0_Pedestals.dat","r");
75   for(int i=0;i<128;i++){
76       fscanf(fpPed,"%f %f %f %f \n",&MeanPed[i],&SigPed[i],&fdump,&fdump);
77 //      printf("%.3f %.3f \n",MeanPed[i],SigPed[i]);
78   }
79   fclose(fpPed);
80
81 //______________________________________________________________________________
82 // Get running parameters from V00_ChannelDelayTuning_DA.config file
83
84   Int_t    kNbEventSkipped;   // = 100;   number of events skipped - to be tuned
85   Float_t  kSigmaCut;         // = 3.0;   number of sigmas for threshold cut - to be tuned
86   
87   status = daqDA_DB_getFile("V00_ChannelDelayTuning_DA.config","./V00_ChannelDelayTuning_DA.config");
88   if (status) {
89       printf("Failed to get config file (V00_ChannelDelayTuning_DA.config) from DAQ DB, status=%d\n", status);
90       return -1;   
91   }
92   /* open the config file and retrieve running parameters */
93   FILE *fpConfig = fopen("V00_ChannelDelayTuning_DA.config","r");
94   fscanf(fpConfig,"%f %d",&kSigmaCut,&kNbEventSkipped);
95   fclose(fpConfig);
96   
97   printf("Number of events skipped = %d ; Number of sigmas for threshold cut = %f\n",kNbEventSkipped,kSigmaCut);
98 //______________________________________________________________________________
99
100   Float_t ChargeEoI  = 0.0;
101   Bool_t  Integrator = 0;
102   Int_t   NHit[128];
103   Float_t ADC_Mean[128];
104   for(Int_t i=0; i<128; i++) {
105       ADC_Mean[i] = 0.0;
106       NHit[i]     = 0;
107   } 
108        
109   /* log start of process */
110   printf("VZERO Integration_Gate_Tuning DA program started - Tuning Integration Gates\n");  
111
112   /* check that we got some arguments = list of files */
113   if (argc<2)   {
114       printf("Wrong number of arguments\n");
115       return -1;}
116                
117   /* open result file to be exported to FES */
118   FILE *fp=NULL;
119   fp=fopen("./V0_IntegrationGateTuning.dat","a");
120   if (fp==NULL) {
121       printf("Failed to open result file\n");
122       return -1;}
123
124   /* open log file to inform user */
125   FILE *flog=NULL;
126   flog=fopen("./V00log.txt","a");
127   if (flog==NULL) {
128       printf("Failed to open log file\n");
129       return -1;  }
130     
131   /* report progress */
132   daqDA_progressReport(10);
133
134   /* init counters on events */
135   int nevents_physics=0;
136   int nevents_total=0;
137   int iteration;
138   sscanf(argv[1],"%d",&iteration);
139   
140   /* read the n data files */
141   for (int n=2; n<argc; n++) {
142   
143   /* read the data  */
144     status=monitorSetDataSource( argv[n] );
145   if (status!=0) {
146       printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
147       return -1; }
148
149   /* report progress */
150   daqDA_progressReport(10+50*n/argc);
151    
152   /* read the data file */
153     for(;;) {
154         struct eventHeaderStruct *event;
155         eventTypeType eventT;
156
157         /* get next event */
158         status=monitorGetEventDynamic((void **)&event);
159         if (status==MON_ERR_EOF) break; /* end of monitoring file has been reached */
160         if (status!=0) {
161             printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
162             return -1; }
163
164         /* retry if got no event */
165         if (event==NULL) break;
166         
167         /* decode event */
168         eventT=event->eventType;
169         
170         switch (event->eventType){
171       
172         case START_OF_RUN:
173              break;
174       
175         case END_OF_RUN:
176              printf("End Of Run detected\n");
177              break;
178       
179         case PHYSICS_EVENT:
180              nevents_physics++;
181                          
182              AliRawReader *rawReader = new AliRawReaderDate((void*)event);
183   
184              AliVZERORawStream* rawStream  = new AliVZERORawStream(rawReader); 
185              rawStream->Next(); 
186              for(Int_t i=0; i<64; i++) {
187                  // Look for the maximum in the LHC clock train instead of central clock 10
188                  ChargeEoI     = 0.0;
189                  Int_t iClock  =   0;
190                  for(size_t iEvent=0; iEvent<21; iEvent++){
191                      if((float)rawStream->GetPedestal(i,iEvent)>ChargeEoI) 
192                         {ChargeEoI = (float)rawStream->GetPedestal(i,iEvent);
193                         iClock     = iEvent;}
194                  }           
195                  Integrator = rawStream->GetIntegratorFlag(i,iClock);
196                  ChargeEoI  =  ChargeEoI - MeanPed[i + 64*Integrator];
197                  Float_t Threshold = kSigmaCut * SigPed[i + 64*Integrator];
198
199                  if(ChargeEoI  > Threshold) {                              
200                     ADC_Mean[i+64*Integrator] = ADC_Mean[i+64*Integrator]+ChargeEoI; 
201                     NHit[i+64*Integrator]+=1;
202                  }
203              }    
204              delete rawStream;
205              rawStream = 0x0;      
206              delete rawReader;
207              rawReader = 0x0;                                                                    
208         } // end of switch on event type 
209         
210         nevents_total++;
211         /* free resources */
212         free(event);
213
214     }    // end of loop over events
215   }      // end of loop over data files 
216
217 //________________________________________________________________________
218 //  Computes mean values, dumps them into the output text file
219         
220   for(Int_t i=0; i<128; i++) {
221       if(NHit[i]>0) 
222          ADC_Mean[i]=ADC_Mean[i]/(float)NHit[i];
223       else       
224          ADC_Mean[i]=0.0;        
225       fprintf(fp," %d %d %f\n",iteration,i,ADC_Mean[i]);
226       fprintf(flog,"it %d ch %d NHit %d ADCMean %f\n",iteration,i,NHit[i],ADC_Mean[i]);
227   } 
228   
229 //________________________________________________________________________
230    
231   /* write report */
232   fprintf(flog,"Run #%s, received %d physics events out of %d\n",getenv("DATE_RUN_NUMBER"),nevents_physics,nevents_total);
233   printf("Run #%s, received %d physics events out of %d\n",getenv("DATE_RUN_NUMBER"),nevents_physics,nevents_total);
234   
235   /* close result and log files */
236   fclose(fp);
237   fclose(flog); 
238   
239   /* report progress */
240   daqDA_progressReport(90);
241
242   /* export result file to FES */
243   status=daqDA_FES_storeFile("./V0_IntegrationGateTuning.dat","V00da_IntegrationGateTuning.dat");
244   if (status)    {
245       printf("Failed to export file : %d\n",status);
246       return -1; }
247
248   /* report progress */
249   daqDA_progressReport(100);
250   
251   return status;
252 }