]>
Commit | Line | Data |
---|---|---|
6145b1a7 | 1 | /* |
2 | T0 DA for online calibration | |
3 | ||
4 | Contact: Michal.Oledzki@cern.ch | |
5 | Link: http://users.jyu.fi/~mioledzk/ | |
6 | Run Type: PHYSICS | |
7 | DA Type: MON | |
8 | Number of events needed: 500000 | |
9 | Input Files: inPhys.dat, external parameters | |
10 | Output Files: daPhys.root, to be exported to the DAQ FXS | |
11 | Trigger types used: PHYSICS_EVENT | |
99194e07 | 12 | |
6145b1a7 | 13 | */ |
99194e07 | 14 | |
6145b1a7 | 15 | #define FILE_OUT "daPhys.root" |
16 | #define FILE_IN "inPhys.dat" | |
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 | |
6145b1a7 | 31 | #include "TROOT.h" |
32 | #include "TPluginManager.h" | |
99194e07 | 33 | #include "TFile.h" |
34 | #include "TKey.h" | |
35 | #include "TH2S.h" | |
36 | #include "TObject.h" | |
37 | #include "TBenchmark.h" | |
38 | #include "TRandom.h" | |
99194e07 | 39 | #include "TCanvas.h" |
40 | #include "TString.h" | |
41 | #include "TH1.h" | |
42 | #include "TF1.h" | |
43 | #include "TSpectrum.h" | |
44 | #include "TVirtualFitter.h" | |
6145b1a7 | 45 | int cbx, ccbx; |
46 | float clx,cmx,cclx,ccmx; | |
99194e07 | 47 | |
48 | /* Main routine | |
49 | Arguments: | |
50 | 1- monitoring data source | |
51 | */ | |
52 | int main(int argc, char **argv) { | |
53 | //int main(){ | |
54 | int status; | |
6145b1a7 | 55 | |
56 | /* magic line */ | |
57 | gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo", | |
58 | "*", | |
59 | "TStreamerInfo", | |
60 | "RIO", | |
61 | "TStreamerInfo()"); | |
99194e07 | 62 | |
6145b1a7 | 63 | FILE *inp; |
64 | char c; | |
65 | inp = fopen(FILE_IN, "r"); | |
66 | while((c=getc(inp))!=EOF) { | |
67 | switch(c) { | |
68 | case 'a': {fscanf(inp, "%d", &ccbx ); break;} //N of X bins hCFD1_CFD | |
69 | case 'b': {fscanf(inp, "%f", &cclx ); break;} //Low x hCFD1_CFD | |
70 | case 'c': {fscanf(inp, "%f", &ccmx ); break;} //High x hCFD1_CFD | |
71 | case 'd': {fscanf(inp, "%d", &cbx ); break;} //N of X bins hCFD | |
72 | case 'e': {fscanf(inp, "%f", &clx ); break;} //Low x hCFD | |
73 | case 'f': {fscanf(inp, "%f", &cmx ); break;} //High x hCFD | |
74 | } | |
75 | } | |
76 | fclose(inp); | |
77 | ||
99194e07 | 78 | if (argc!=2) { |
79 | printf("Wrong number of arguments\n"); | |
80 | return -1; | |
81 | } | |
82 | ||
83 | ||
84 | /* define data source : this is argument 1 */ | |
85 | status=monitorSetDataSource( argv[1] ); | |
86 | if (status!=0) { | |
87 | printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status)); | |
88 | return -1; | |
89 | } | |
90 | ||
91 | ||
92 | /* declare monitoring program */ | |
93 | status=monitorDeclareMp( __FILE__ ); | |
94 | if (status!=0) { | |
95 | printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status)); | |
96 | return -1; | |
97 | } | |
98 | ||
99 | ||
100 | /* define wait event timeout - 1s max */ | |
101 | monitorSetNowait(); | |
102 | monitorSetNoWaitNetworkTimeout(1000); | |
103 | ||
104 | ||
105 | /* log start of process */ | |
106 | printf("T0 monitoring program started\n"); | |
107 | ||
108 | // Allocation of histograms - start | |
109 | ||
110 | TH1F *hCFD1_CFD[24]; | |
111 | TH1F *hCFD[24]; | |
6145b1a7 | 112 | |
99194e07 | 113 | for(Int_t ic=0; ic<24; ic++) { |
114 | if(ic<12) { | |
6145b1a7 | 115 | hCFD1_CFD[ic] = new TH1F(Form("CFD1-CFD%d",ic+1),"CFD-CFD",ccbx,cclx,ccmx); |
116 | hCFD[ic] = new TH1F(Form("CFD%i",ic+1),"CFD",cbx,clx,cmx); | |
99194e07 | 117 | } |
118 | if(ic>11){ | |
6145b1a7 | 119 | hCFD1_CFD[ic] = new TH1F(Form("CFD13-CFD%i",ic+1),"CFD-CFD",ccbx,cclx,ccmx); |
120 | hCFD[ic] = new TH1F(Form("CFD%i",ic+1),"CFD",cbx,clx,cmx); | |
99194e07 | 121 | } |
122 | } | |
123 | ||
124 | // Allocation of histograms - end | |
125 | ||
126 | Int_t iev=0; | |
127 | /* main loop (infinite) */ | |
128 | for(;;) { | |
129 | struct eventHeaderStruct *event; | |
130 | eventTypeType eventT; | |
131 | ||
132 | /* check shutdown condition */ | |
133 | if (daqDA_checkShutdown()) {break;} | |
134 | ||
135 | /* get next event (blocking call until timeout) */ | |
136 | status=monitorGetEventDynamic((void **)&event); | |
137 | if (status==(int)MON_ERR_EOF) { | |
138 | printf ("End of File detected\n"); | |
139 | break; /* end of monitoring file has been reached */ | |
140 | } | |
141 | ||
142 | if (status!=0) { | |
143 | printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status)); | |
144 | break; | |
145 | } | |
146 | ||
147 | /* retry if got no event */ | |
148 | if (event==NULL) { | |
149 | continue; | |
150 | } | |
151 | ||
152 | iev++; | |
153 | ||
154 | /* use event - here, just write event id to result file */ | |
155 | eventT=event->eventType; | |
156 | ||
157 | switch (event->eventType){ | |
158 | ||
159 | case START_OF_RUN: | |
160 | break; | |
161 | ||
162 | case END_OF_RUN: | |
163 | break; | |
164 | ||
165 | case PHYSICS_EVENT: | |
166 | printf(" event number = %i \n",iev); | |
167 | ||
168 | ||
169 | // Initalize raw-data reading and decoding | |
170 | AliRawReader *reader = new AliRawReaderDate((void*)event); | |
171 | ||
172 | // Enable the following two lines in case of real-data | |
173 | // reader->LoadEquipmentIdsMap("T0map.txt"); | |
174 | // reader->RequireHeader(kFALSE); | |
175 | // reader->RequireHeader(kTRUE); | |
176 | AliT0RawReader *start = new AliT0RawReader(reader, kTRUE); | |
177 | ||
178 | // Read raw data | |
179 | Int_t allData[105][5]; | |
180 | for(Int_t i0=0;i0<105;i0++) | |
181 | for(Int_t j0=0;j0<5;j0++) | |
182 | allData[i0][j0] = 0; | |
183 | ||
184 | ||
185 | if(start->Next()) | |
186 | for (Int_t i=0; i<105; i++) { | |
187 | for(Int_t iHit=0;iHit<5;iHit++){ | |
188 | allData[i][iHit]= start->GetData(i,iHit); | |
189 | } | |
190 | } | |
191 | else | |
192 | printf("No T0 data found!!\n"); | |
193 | ||
194 | // Fill the histograms | |
195 | ||
196 | for (Int_t ik = 0; ik<24; ik+=2) | |
197 | for (Int_t iHt=0; iHt<5; iHt++){ | |
198 | Int_t cc = ik/2; | |
199 | if(allData[cc+1][iHt]!=0 ){ | |
200 | hCFD1_CFD[cc]->Fill(allData[cc+1][iHt]-allData[1][iHt]); | |
201 | hCFD[cc]->Fill(allData[cc+13][iHt]); | |
202 | } | |
203 | } | |
204 | ||
205 | for (Int_t ik = 24; ik<48; ik+=2) | |
206 | for (Int_t iHt=0; iHt<5; iHt++){ | |
207 | Int_t cc = ik/2; | |
208 | if(allData[cc+45][iHt]!=0 ){ | |
209 | hCFD1_CFD[cc]->Fill(allData[cc+45][iHt]-allData[57][iHt]); | |
210 | hCFD[cc]->Fill(allData[cc+45][iHt]); | |
211 | } | |
212 | } | |
213 | ||
214 | delete start; | |
215 | start = 0x0; | |
216 | reader->Reset(); | |
217 | // End of fill histograms | |
218 | ||
219 | } | |
220 | ||
221 | ||
222 | ||
223 | /* free resources */ | |
224 | free(event); | |
225 | ||
226 | /* exit when last event received, no need to wait for TERM signal */ | |
227 | if (eventT==END_OF_RUN) { | |
228 | printf("EOR event detected\n"); | |
229 | break; | |
230 | } | |
231 | } | |
6145b1a7 | 232 | printf("After loop, before writing histos\n"); |
99194e07 | 233 | // write a file with the histograms |
6145b1a7 | 234 | TFile *hist = new TFile(FILE_OUT,"RECREATE"); |
99194e07 | 235 | |
236 | for(Int_t j=0;j<24;j++){ | |
237 | hCFD1_CFD[j]->Write(); | |
238 | hCFD[j]->Write(); | |
239 | } | |
240 | hist->Close(); | |
241 | delete hist; | |
242 | ||
6145b1a7 | 243 | status=0; |
244 | ||
245 | /* export file to FXS */ | |
246 | if (daqDA_FES_storeFile(FILE_OUT, FILE_OUT)) { | |
247 | status=-2; | |
248 | } | |
249 | ||
99194e07 | 250 | return status; |
251 | } | |
252 | ||
253 |