]> git.uio.no Git - u/mrichter/AliRoot.git/blob - T0/T0Laserda.cxx
Remove obsolete macro
[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: T0_STANDALONE_LASER
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: PHYSICS_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,cbx;
48 float cqlx,cqmx,cqly,cqmy,cllx,clmx,clly,clmy,clx,cmx;
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   FILE *inp;
63   char c;
64   inp = fopen(FILE_IN, "r");  
65   while((c=getc(inp))!=EOF) {
66     switch(c) {
67       case 'a': {fscanf(inp, "%d", &cqbx ); break;} //N of X bins hCFD_QTC
68       case 'b': {fscanf(inp, "%f", &cqlx ); break;} //Low x hCFD_QTC
69       case 'c': {fscanf(inp, "%f", &cqmx ); break;} //High x hCFD_QTC
70       case 'd': {fscanf(inp, "%d", &cqby ); break;} //N of Y bins hCFD_QTC
71       case 'e': {fscanf(inp, "%f", &cqly ); break;} //Low y hCFD_QTC
72       case 'f': {fscanf(inp, "%f", &cqmy ); break;} //High y hCFD_QTC
73       case 'g': {fscanf(inp, "%d", &clbx ); break;} //N of X bins hCFD_LED
74       case 'h': {fscanf(inp, "%f", &cllx ); break;} //Low x hCFD_LED
75       case 'i': {fscanf(inp, "%f", &clmx ); break;} //High x hCFD_LED
76       case 'j': {fscanf(inp, "%d", &clby ); break;} //N of Y bins hCFD_LED
77       case 'k': {fscanf(inp, "%f", &clly ); break;} //Low y hCFD_LED
78       case 'l': {fscanf(inp, "%f", &clmy ); break;} //High y hCFD_LED
79       case 'm': {fscanf(inp, "%d", &cbx ); break;}  //N of Y bins hCFD 
80       case 'n': {fscanf(inp, "%f", &clx ); break;}  //Low x hCFD
81       case 'o': {fscanf(inp, "%f", &cmx ); break;}  //High x hCFD
82     }
83   }
84   fclose(inp);
85
86   if (argc!=2) {
87     printf("Wrong number of arguments\n");
88     return -1;
89   }
90
91
92   /* define data source : this is argument 1 */  
93   status=monitorSetDataSource( argv[1] );
94   if (status!=0) {
95     printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
96     return -1;
97   }
98
99
100   /* declare monitoring program */
101   status=monitorDeclareMp( __FILE__ );
102   if (status!=0) {
103     printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
104     return -1;
105   }
106
107
108   /* define wait event timeout - 1s max */
109   monitorSetNowait();
110   monitorSetNoWaitNetworkTimeout(1000);
111   
112
113   /* log start of process */
114   printf("T0 monitoring program started\n");  
115
116   // Allocation of histograms - start
117   TH1F *hCFD[24];
118   TH2F *hCFD_QTC[24];
119   TH2F *hCFD_LED[24]; 
120
121    for(Int_t ic=0; ic<24; ic++) {
122       hCFD_QTC[ic] = new TH2F(Form("CFD_QTC%d",ic+1),"CFD_QTC",cqbx,cqlx,cqmx,cqby,cqly,cqmy);
123       hCFD_LED[ic] = new TH2F(Form("CFD_LED%d",ic+1),"CFD_LED",clbx,cllx,clmx,clby,clly,clmy);
124       if(ic<12){
125         hCFD[ic] = new TH1F(Form("T0_C_%d_CFD",ic+1),"CFD", cbx,clx,cmx);       
126       }
127       else{
128         hCFD[ic] = new TH1F(Form("T0_A_%d_CFD",ic-11),"CFD", cbx,clx,cmx); 
129       }
130     }
131
132   // Allocation of histograms - end
133
134   Int_t iev=0;
135   /* main loop (infinite) */
136   for(;;) {
137     struct eventHeaderStruct *event;
138     eventTypeType eventT;
139   
140     /* check shutdown condition */
141     if (daqDA_checkShutdown()) {break;}
142     
143     /* get next event (blocking call until timeout) */
144     status=monitorGetEventDynamic((void **)&event);
145     if (status==(int)MON_ERR_EOF) {
146       printf ("End of File detected\n");
147       break; /* end of monitoring file has been reached */
148     }
149     
150     if (status!=0) {
151       printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
152       break;
153     }
154
155     /* retry if got no event */
156     if (event==NULL) {
157       continue;
158     }
159  
160     iev++; 
161
162     /* use event - here, just write event id to result file */
163     eventT=event->eventType;
164    
165     switch (event->eventType){
166
167       case START_OF_RUN:
168         break;
169
170       case END_OF_RUN:
171         break;
172
173 //      case CALIBRATION_EVENT:
174       case PHYSICS_EVENT:
175       printf(" event number = %i \n",iev);
176
177
178       // Initalize raw-data reading and decoding
179       AliRawReader *reader = new AliRawReaderDate((void*)event);
180           
181       // Enable the following two lines in case of real-data
182    //       reader->LoadEquipmentIdsMap("T0map.txt");
183     //     reader->RequireHeader(kFALSE);
184      //           reader->RequireHeader(kTRUE);
185       AliT0RawReader *start = new AliT0RawReader(reader, kTRUE);
186
187       // Read raw data
188       Int_t allData[105][5];
189       for(Int_t i0=0;i0<105;i0++)
190         for(Int_t j0=0;j0<5;j0++)
191                 allData[i0][j0] = 0;
192      
193       if(start->Next())
194       for (Int_t i=0; i<105; i++) {
195         for(Int_t iHit=0;iHit<5;iHit++){
196           allData[i][iHit]= start->GetData(i,iHit);
197         }
198       }
199         else 
200         printf("No T0 data found!!\n");
201
202       // Fill the histograms
203         
204       for (Int_t ik = 0; ik<24; ik+=2)
205          for (Int_t iHt=0; iHt<5; iHt++){
206                  Int_t cc = ik/2;
207                 if((allData[cc+1][iHt]-allData[0][0])>0){
208                  hCFD[cc]->Fill(allData[cc+1][iHt]-allData[0][0]);
209                 }
210                 if(allData[ik+25][iHt]!=0 && allData[ik+26][iHt]!=0 && allData[cc+1][iHt]!=0){
211                  hCFD_QTC[cc]->Fill((allData[ik+25][iHt]-allData[ik+26][iHt]) , (allData[cc+1][iHt]-allData[0][0]));
212                  } 
213                 if(allData[cc+13][iHt]!=0 && allData[cc+1][iHt]!=0){
214                  hCFD_LED[cc]->Fill(allData[cc+13][iHt]-allData[cc+1][iHt],allData[cc+1][iHt]-allData[0][0]);
215                  }
216         }
217
218       for (Int_t ik = 24; ik<48; ik+=2)
219          for (Int_t iHt=0; iHt<5; iHt++){
220                  Int_t cc = ik/2;
221                 if((allData[cc+45][iHt]-allData[0][0])>0){
222                  hCFD[cc]->Fill(allData[cc+45][iHt]-allData[0][0]);
223                 }
224
225                 if(allData[ik+57][iHt]!=0 && allData[ik+58][iHt]!=0){
226                 if(allData[cc+45][iHt]!=0)
227                  hCFD_QTC[cc]->Fill(allData[ik+57][iHt]-allData[ik+58][iHt],allData[cc+45][iHt]-allData[0][0]);
228                  }
229                 if(allData[cc+57][iHt]!=0 && allData[cc+45][iHt]!=0){
230                  hCFD_LED[cc]->Fill(allData[cc+57][iHt]-allData[cc+45][iHt],allData[cc+45][iHt]-allData[0][0]);
231                  }
232         }
233
234         
235      delete start;
236         start = 0x0;
237      reader->Reset();
238       // End of fill histograms
239
240     }
241
242
243
244     /* free resources */
245     free(event);
246     
247     /* exit when last event received, no need to wait for TERM signal */
248     if (eventT==END_OF_RUN) {
249       printf("EOR event detected\n");
250       break;
251     }
252   }
253   printf("After loop, before writing histos\n");
254   // write a file with the histograms
255   TFile *hist = new TFile(FILE_OUT,"RECREATE");
256
257   for(Int_t j=0;j<24;j++){
258      hCFD_QTC[j]->Write();
259      hCFD_LED[j]->Write();
260      hCFD[j]->Write();
261     }
262   hist->Close();
263   delete hist;
264
265   status=0;
266
267   /* export file to FXS */
268   if (daqDA_FES_storeFile(FILE_OUT, FILE_OUT)) {
269     status=-2;
270   }
271
272   return status;
273 }
274