]> git.uio.no Git - u/mrichter/AliRoot.git/blame - T0/T0Laserda.cxx
bug in StepManager fixed, thanks to Andreas
[u/mrichter/AliRoot.git] / T0 / T0Laserda.cxx
CommitLineData
f16a53cf 1/*
6145b1a7 2T0 DA for online calibration
271b5bd3 3
f16a53cf 4Contact: Michal.Oledzki@cern.ch
6145b1a7 5Link: http://users.jyu.fi/~mioledzk/
49ab1618 6Run Type: STANDALONE
f16a53cf 7DA Type: MON
6145b1a7 8Number of events needed: 400000
9Input Files: inLaser.dat, external parameters
f16a53cf 10Output Files: daLaser.root, to be exported to the DAQ FXS
49ab1618 11Trigger types used: CALIBRATION_EVENT
f16a53cf 12
13*/
99194e07 14
f16a53cf 15#define FILE_OUT "daLaser.root"
6145b1a7 16#define FILE_IN "inLaser.dat"
f16a53cf 17#include <daqDA.h>
99194e07 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>
99194e07 29
30//ROOT
0acfe114 31#include "TROOT.h"
32#include "TPluginManager.h"
33#include "TFile.h"
99194e07 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"
387638f7 46//#include "TProfile.h"
271b5bd3 47int cqbx,cqby,clbx,clby,mod;
48float cqlx,cqmx,cqly,cqmy,cllx,clmx,clly,clmy;
99194e07 49/* Main routine
50 Arguments:
51 1- monitoring data source
52*/
53int main(int argc, char **argv) {
54 int status;
55
0acfe114 56 /* magic line */
57 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
58 "*",
59 "TStreamerInfo",
60 "RIO",
61 "TStreamerInfo()");
19e2ac29 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
000ccf4d 68
6145b1a7 69 FILE *inp;
70 char c;
71 inp = fopen(FILE_IN, "r");
19e2ac29 72 if(!inp){
73 printf("Input file >>inLaser.dat<< not found !!!\n");
74 return -1;
75 }
76
6145b1a7 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
271b5bd3 91 case 'm': {fscanf(inp, "%d", &mod ); break;} //Modulo number
6145b1a7 92 }
93 }
94 fclose(inp);
95
99194e07 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
271b5bd3 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);
99194e07 135 }
136
137 // Allocation of histograms - end
138
139 Int_t iev=0;
271b5bd3 140 Int_t mip=0;
99194e07 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
99194e07 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
19e2ac29 177 case CALIBRATION_EVENT:
178// case PHYSICS_EVENT:
179 iev++;
180
181 if(iev==1){
182 printf("First event - %i\n",iev);
183 }
99194e07 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
387638f7 189 reader->RequireHeader(kTRUE);
99194e07 190 AliT0RawReader *start = new AliT0RawReader(reader, kTRUE);
191
192 // Read raw data
271b5bd3 193 Int_t allData[106][5];
194 for(Int_t i0=0;i0<106;i0++)
99194e07 195 for(Int_t j0=0;j0<5;j0++)
196 allData[i0][j0] = 0;
197
271b5bd3 198 if(start->Next()){
199 for (Int_t i=0; i<106; i++) {
200 for(Int_t iHit=0;iHit<5;iHit++){
99194e07 201 allData[i][iHit]= start->GetData(i,iHit);
271b5bd3 202 }
99194e07 203 }
271b5bd3 204 }
99194e07 205 else
271b5bd3 206 printf("No data for T0 found!!!\n");
99194e07 207
208 // Fill the histograms
271b5bd3 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
99194e07 219 for (Int_t ik = 0; ik<24; ik+=2)
6e999168 220 for (Int_t iHt=0; iHt<1; iHt++){
99194e07 221 Int_t cc = ik/2;
99194e07 222 if(allData[ik+25][iHt]!=0 && allData[ik+26][iHt]!=0 && allData[cc+1][iHt]!=0){
271b5bd3 223 hCFDvsQTC[cc][mip]->Fill((allData[ik+25][iHt]-allData[ik+26][iHt]) , (allData[cc+1][iHt]-allData[0][0]+5000));
000ccf4d 224 }
99194e07 225 if(allData[cc+13][iHt]!=0 && allData[cc+1][iHt]!=0){
271b5bd3 226 hCFDvsLED[cc][mip]->Fill(allData[cc+13][iHt]-allData[cc+1][iHt],allData[cc+1][iHt]-allData[0][0]+5000);
000ccf4d 227 }
99194e07 228 }
229
230 for (Int_t ik = 24; ik<48; ik+=2)
6e999168 231 for (Int_t iHt=0; iHt<1; iHt++){
99194e07 232 Int_t cc = ik/2;
63176e52 233 if(allData[ik+57][iHt]!=0 && allData[ik+58][iHt]!=0 && allData[cc+45][iHt]!=0){
271b5bd3 234 hCFDvsQTC[cc][mip]->Fill(allData[ik+57][iHt]-allData[ik+58][iHt],allData[cc+45][iHt]-allData[0][0]+5000);
000ccf4d 235 }
99194e07 236 if(allData[cc+57][iHt]!=0 && allData[cc+45][iHt]!=0){
271b5bd3 237 hCFDvsLED[cc][mip]->Fill(allData[cc+57][iHt]-allData[cc+45][iHt],allData[cc+45][iHt]-allData[0][0]+5000);
000ccf4d 238 }
99194e07 239 }
271b5bd3 240
99194e07 241 delete start;
242 start = 0x0;
243 reader->Reset();
244 // End of fill histograms
245
246 }
247
99194e07 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");
19e2ac29 254 printf("Number of events processed - %i\n ",iev);
99194e07 255 break;
256 }
257 }
6145b1a7 258 printf("After loop, before writing histos\n");
99194e07 259 // write a file with the histograms
f16a53cf 260 TFile *hist = new TFile(FILE_OUT,"RECREATE");
99194e07 261
271b5bd3 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();
99194e07 267 }
268 hist->Close();
269 delete hist;
270
6145b1a7 271 status=0;
272
273 /* export file to FXS */
387638f7 274 if (daqDA_FES_storeFile(FILE_OUT, "LASER")) {
6145b1a7 275 status=-2;
276 }
277
99194e07 278 return status;
279}
280