]> git.uio.no Git - u/mrichter/AliRoot.git/blob - T0/T0Laserda.cxx
QA for monitoring
[u/mrichter/AliRoot.git] / T0 / T0Laserda.cxx
1 /*
2 T0 DA for online calibration
3  
4 Contact: Michal.Oledzki@cern.ch
5 Link: http://users.jyu.fi/~mioledzk/
6 Run Type: STANDALONE
7 DA Type: MON
8 Number of events needed: 400000 
9 Input Files: inLaser.dat, external parameters
10 Output Files: daLaser.root, to be exported to the DAQ FXS
11 Trigger types used: CALIBRATION_EVENT
12
13 */
14
15 #define FILE_OUT "daLaser.root"
16 #define FILE_IN "inLaser.dat"
17 #include <daqDA.h>
18 #include <event.h>
19 #include <monitor.h>
20  
21 #include <Riostream.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24
25 //AliRoot
26 #include <AliRawReaderDate.h>
27 #include <AliRawReader.h>
28 #include <AliT0RawReader.h>
29
30 //ROOT
31 #include "TROOT.h"
32 #include "TPluginManager.h"
33 #include "TFile.h"
34 #include "TKey.h"
35 #include "TH2S.h"
36 #include "TObject.h"
37 #include "TBenchmark.h"
38 #include "TRandom.h"
39 #include "TMath.h"
40 #include "TCanvas.h"
41 #include "TString.h"
42 #include "TH1.h"
43 #include "TF1.h"
44 #include "TSpectrum.h"
45 #include "TVirtualFitter.h"
46 //#include "TProfile.h"
47 int cqbx,cqby,clbx,clby,mod;
48 float cqlx,cqmx,cqly,cqmy,cllx,clmx,clly,clmy;
49 /* Main routine
50       Arguments: 
51       1- monitoring data source
52 */
53 int main(int argc, char **argv) {
54   int status;
55   
56   /* magic line */
57   gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
58                                         "*",
59                                         "TStreamerInfo",
60                                         "RIO",
61                                         "TStreamerInfo()"); 
62   
63   if(daqDA_DB_getFile(FILE_IN, FILE_IN)){
64      printf("Couldn't get input file >>inLaser.dat<< from DAQ_DB !!!\n");
65      return -1;
66   }
67   
68  
69   FILE *inp;
70   char c;
71   inp = fopen(FILE_IN, "r");  
72   if(!inp){
73         printf("Input file >>inLaser.dat<< not found !!!\n");
74         return -1;
75   }
76
77   while((c=getc(inp))!=EOF) {
78     switch(c) {
79       case 'a': {fscanf(inp, "%d", &cqbx ); break;} //N of X bins hCFD_QTC
80       case 'b': {fscanf(inp, "%f", &cqlx ); break;} //Low x hCFD_QTC
81       case 'c': {fscanf(inp, "%f", &cqmx ); break;} //High x hCFD_QTC
82       case 'd': {fscanf(inp, "%d", &cqby ); break;} //N of Y bins hCFD_QTC
83       case 'e': {fscanf(inp, "%f", &cqly ); break;} //Low y hCFD_QTC
84       case 'f': {fscanf(inp, "%f", &cqmy ); break;} //High y hCFD_QTC
85       case 'g': {fscanf(inp, "%d", &clbx ); break;} //N of X bins hCFD_LED
86       case 'h': {fscanf(inp, "%f", &cllx ); break;} //Low x hCFD_LED
87       case 'i': {fscanf(inp, "%f", &clmx ); break;} //High x hCFD_LED
88       case 'j': {fscanf(inp, "%d", &clby ); break;} //N of Y bins hCFD_LED
89       case 'k': {fscanf(inp, "%f", &clly ); break;} //Low y hCFD_LED
90       case 'l': {fscanf(inp, "%f", &clmy ); break;} //High y hCFD_LED
91       case 'm': {fscanf(inp, "%d", &mod  ); break;} //Modulo number
92     }
93   }
94   fclose(inp);
95
96   if (argc!=2) {
97     printf("Wrong number of arguments\n");
98     return -1;
99   }
100
101
102   /* define data source : this is argument 1 */  
103   status=monitorSetDataSource( argv[1] );
104   if (status!=0) {
105     printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
106     return -1;
107   }
108
109
110   /* declare monitoring program */
111   status=monitorDeclareMp( __FILE__ );
112   if (status!=0) {
113     printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
114     return -1;
115   }
116
117
118   /* define wait event timeout - 1s max */
119   monitorSetNowait();
120   monitorSetNoWaitNetworkTimeout(1000);
121   
122
123   /* log start of process */
124   printf("T0 monitoring program started\n");  
125
126   // Allocation of histograms - start
127   TH2F *hCFDvsQTC[24][10];
128   TH2F *hCFDvsLED[24][10]; 
129
130    for(Int_t ic=0; ic<24; ic++) 
131         for(Int_t im=0;im<10;im++)
132     {
133       hCFDvsQTC[ic][im] = new TH2F(Form("CFDvsQTC%d_%d",ic+1,im+1),"CFDvsQTC",cqbx,cqlx,cqmx,cqby,cqly,cqmy);
134       hCFDvsLED[ic][im] = new TH2F(Form("CFDvsLED%d_%d",ic+1,im+1),"CFDvsLED",clbx,cllx,clmx,clby,clly,clmy);
135     }
136
137   // Allocation of histograms - end
138
139   Int_t iev=0;
140   Int_t mip=0;
141   /* main loop (infinite) */
142   for(;;) {
143     struct eventHeaderStruct *event;
144     eventTypeType eventT;
145   
146     /* check shutdown condition */
147     if (daqDA_checkShutdown()) {break;}
148     
149     /* get next event (blocking call until timeout) */
150     status=monitorGetEventDynamic((void **)&event);
151     if (status==(int)MON_ERR_EOF) {
152       printf ("End of File detected\n");
153       break; /* end of monitoring file has been reached */
154     }
155     
156     if (status!=0) {
157       printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
158       break;
159     }
160
161     /* retry if got no event */
162     if (event==NULL) {
163       continue;
164     }
165  
166     /* use event - here, just write event id to result file */
167     eventT=event->eventType;
168    
169     switch (event->eventType){
170
171       case START_OF_RUN:
172         break;
173
174       case END_OF_RUN:
175         break;
176
177       case CALIBRATION_EVENT:
178 //      case PHYSICS_EVENT:
179       iev++; 
180
181       if(iev==1){
182            printf("First event - %i\n",iev);
183       }
184
185       // Initalize raw-data reading and decoding
186       AliRawReader *reader = new AliRawReaderDate((void*)event);
187           
188       // Enable the following two lines in case of real-data
189           reader->RequireHeader(kTRUE);
190       AliT0RawReader *start = new AliT0RawReader(reader, kTRUE);
191
192       // Read raw data
193       Int_t allData[106][5];
194       for(Int_t i0=0;i0<106;i0++)
195         for(Int_t j0=0;j0<5;j0++)
196                 allData[i0][j0] = 0;
197      
198        if(start->Next()){
199         for (Int_t i=0; i<106; i++) {
200          for(Int_t iHit=0;iHit<5;iHit++){
201           allData[i][iHit]= start->GetData(i,iHit);
202          }
203         }
204        }
205         else 
206          printf("No data for T0 found!!!\n");
207
208       // Fill the histograms
209
210       if(iev<10000){
211         mip=0;
212         }else 
213         if((iev%mod)==0.0){
214         mip++;
215 //      printf("mip = %d\n",mip);
216         if(mip>=9) mip=9;}
217       
218
219       for (Int_t ik = 0; ik<24; ik+=2)
220          for (Int_t iHt=0; iHt<5; iHt++){
221                  Int_t cc = ik/2;
222                 if(allData[ik+25][iHt]!=0 && allData[ik+26][iHt]!=0 && allData[cc+1][iHt]!=0){
223                  hCFDvsQTC[cc][mip]->Fill((allData[ik+25][iHt]-allData[ik+26][iHt]) , (allData[cc+1][iHt]-allData[0][0]+5000));
224                 } 
225                 if(allData[cc+13][iHt]!=0 && allData[cc+1][iHt]!=0){
226                  hCFDvsLED[cc][mip]->Fill(allData[cc+13][iHt]-allData[cc+1][iHt],allData[cc+1][iHt]-allData[0][0]+5000);
227                 }
228         }
229
230       for (Int_t ik = 24; ik<48; ik+=2)
231          for (Int_t iHt=0; iHt<5; iHt++){
232                  Int_t cc = ik/2;
233                 if(allData[ik+57][iHt]!=0 && allData[ik+58][iHt]!=0 && allData[cc+45][iHt]!=0){
234                  hCFDvsQTC[cc][mip]->Fill(allData[ik+57][iHt]-allData[ik+58][iHt],allData[cc+45][iHt]-allData[0][0]+5000);
235                 }
236                 if(allData[cc+57][iHt]!=0 && allData[cc+45][iHt]!=0){
237                  hCFDvsLED[cc][mip]->Fill(allData[cc+57][iHt]-allData[cc+45][iHt],allData[cc+45][iHt]-allData[0][0]+5000);
238                 }
239         }
240       
241      delete start;
242         start = 0x0;
243      reader->Reset();
244       // End of fill histograms
245
246     }
247
248     /* free resources */
249     free(event);
250     
251     /* exit when last event received, no need to wait for TERM signal */
252     if (eventT==END_OF_RUN) {
253       printf("EOR event detected\n");
254       printf("Number of events processed - %i\n ",iev);
255       break;
256     }
257   }
258   printf("After loop, before writing histos\n");
259   // write a file with the histograms
260   TFile *hist = new TFile(FILE_OUT,"RECREATE");
261
262   for(Int_t j=0;j<24;j++)
263    for(Int_t k=0;k<10;k++)
264     {
265      hCFDvsQTC[j][k]->Write();
266      hCFDvsLED[j][k]->Write();
267     }
268   hist->Close();
269   delete hist;
270
271   status=0;
272
273   /* export file to FXS */
274   if (daqDA_FES_storeFile(FILE_OUT, "LASER")) {
275     status=-2;
276   }
277
278   return status;
279 }
280