]>
Commit | Line | Data |
---|---|---|
6145b1a7 | 1 | /* |
2 | T0 DA for online calibration | |
271b5bd3 | 3 | |
6145b1a7 | 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 | |
49976464 | 12 | ------------------------------Alla |
13 | Now trigger type changed to CALICRATION_EVENT | |
14 | to have data during test. | |
15 | SOULD BE CHANGED BACK BEFORE BEAM | |
16 | ------------------------------- Alla | |
6145b1a7 | 17 | */ |
99194e07 | 18 | |
6145b1a7 | 19 | #define FILE_OUT "daPhys.root" |
20 | #define FILE_IN "inPhys.dat" | |
21 | #include <daqDA.h> | |
99194e07 | 22 | #include <event.h> |
23 | #include <monitor.h> | |
24 | ||
25 | #include <Riostream.h> | |
26 | #include <stdio.h> | |
27 | #include <stdlib.h> | |
28 | ||
29 | //AliRoot | |
30 | #include <AliRawReaderDate.h> | |
31 | #include <AliRawReader.h> | |
32 | #include <AliT0RawReader.h> | |
99194e07 | 33 | |
34 | //ROOT | |
6145b1a7 | 35 | #include "TROOT.h" |
36 | #include "TPluginManager.h" | |
99194e07 | 37 | #include "TFile.h" |
38 | #include "TKey.h" | |
39 | #include "TH2S.h" | |
40 | #include "TObject.h" | |
41 | #include "TBenchmark.h" | |
42 | #include "TRandom.h" | |
99194e07 | 43 | #include "TCanvas.h" |
44 | #include "TString.h" | |
45 | #include "TH1.h" | |
46 | #include "TF1.h" | |
47 | #include "TSpectrum.h" | |
48 | #include "TVirtualFitter.h" | |
3348cdd2 | 49 | int cbx, ccbx, npmtA, npmtC; |
6145b1a7 | 50 | float clx,cmx,cclx,ccmx; |
99194e07 | 51 | |
52 | /* Main routine | |
53 | Arguments: | |
54 | 1- monitoring data source | |
55 | */ | |
56 | int main(int argc, char **argv) { | |
57 | //int main(){ | |
58 | int status; | |
6145b1a7 | 59 | |
60 | /* magic line */ | |
61 | gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo", | |
62 | "*", | |
63 | "TStreamerInfo", | |
64 | "RIO", | |
65 | "TStreamerInfo()"); | |
b95e8d87 | 66 | |
19e2ac29 | 67 | if(daqDA_DB_getFile(FILE_IN, FILE_IN)){ |
b95e8d87 | 68 | printf("Couldn't get input file >>inPhys.dat<< from DAQ_DB !!!\n"); |
69 | return -1; | |
19e2ac29 | 70 | } |
b95e8d87 | 71 | |
99194e07 | 72 | |
6145b1a7 | 73 | FILE *inp; |
74 | char c; | |
75 | inp = fopen(FILE_IN, "r"); | |
19e2ac29 | 76 | if(!inp){ |
b95e8d87 | 77 | printf("Input file >>inPhys.dat<< not found !!!\n"); |
78 | return -1; | |
19e2ac29 | 79 | } |
b95e8d87 | 80 | |
6145b1a7 | 81 | while((c=getc(inp))!=EOF) { |
82 | switch(c) { | |
b95e8d87 | 83 | case 'a': {fscanf(inp, "%d", &ccbx ); break;} //N of X bins hCFD1_CFD |
84 | case 'b': {fscanf(inp, "%f", &cclx ); break;} //Low x hCFD1_CFD | |
3348cdd2 | 85 | case 'c': {fscanf(inp, "%f", &ccmx ); break;} //High x hCFD1_CF |
86 | case 'd': {fscanf(inp, "%d", &npmtC ); break;} //number of reference PMTC | |
87 | case 'e': {fscanf(inp, "%d", &npmtA ); break;} //number of reference PMTA | |
6145b1a7 | 88 | } |
89 | } | |
90 | fclose(inp); | |
91 | ||
99194e07 | 92 | if (argc!=2) { |
93 | printf("Wrong number of arguments\n"); | |
94 | return -1; | |
95 | } | |
b95e8d87 | 96 | |
99194e07 | 97 | |
98 | /* define data source : this is argument 1 */ | |
99 | status=monitorSetDataSource( argv[1] ); | |
100 | if (status!=0) { | |
101 | printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status)); | |
102 | return -1; | |
103 | } | |
b95e8d87 | 104 | |
105 | ||
99194e07 | 106 | /* declare monitoring program */ |
107 | status=monitorDeclareMp( __FILE__ ); | |
108 | if (status!=0) { | |
109 | printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status)); | |
110 | return -1; | |
111 | } | |
b95e8d87 | 112 | |
113 | ||
99194e07 | 114 | /* define wait event timeout - 1s max */ |
115 | monitorSetNowait(); | |
116 | monitorSetNoWaitNetworkTimeout(1000); | |
117 | ||
b95e8d87 | 118 | |
99194e07 | 119 | /* log start of process */ |
120 | printf("T0 monitoring program started\n"); | |
b95e8d87 | 121 | |
99194e07 | 122 | // Allocation of histograms - start |
123 | ||
ae4882b1 | 124 | TH1F *hCFD1minCFD[24]; |
6145b1a7 | 125 | |
b95e8d87 | 126 | for(Int_t ic=0; ic<24; ic++) { |
127 | hCFD1minCFD[ic] = new TH1F(Form("CFD1-CFD%d",ic+1),"CFD-CFD",ccbx,cclx,ccmx); | |
128 | } | |
129 | TH1F *hVertex = new TH1F("hVertex","Z vertex",ccbx,cclx,ccmx); | |
130 | ||
131 | Float_t meanShift[24]; | |
132 | ||
99194e07 | 133 | // Allocation of histograms - end |
134 | ||
135 | Int_t iev=0; | |
136 | /* main loop (infinite) */ | |
137 | for(;;) { | |
138 | struct eventHeaderStruct *event; | |
139 | eventTypeType eventT; | |
b95e8d87 | 140 | |
99194e07 | 141 | /* check shutdown condition */ |
142 | if (daqDA_checkShutdown()) {break;} | |
143 | ||
144 | /* get next event (blocking call until timeout) */ | |
145 | status=monitorGetEventDynamic((void **)&event); | |
146 | if (status==(int)MON_ERR_EOF) { | |
147 | printf ("End of File detected\n"); | |
148 | break; /* end of monitoring file has been reached */ | |
149 | } | |
150 | ||
151 | if (status!=0) { | |
152 | printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status)); | |
153 | break; | |
154 | } | |
b95e8d87 | 155 | |
99194e07 | 156 | /* retry if got no event */ |
157 | if (event==NULL) { | |
158 | continue; | |
159 | } | |
b95e8d87 | 160 | |
99194e07 | 161 | /* use event - here, just write event id to result file */ |
162 | eventT=event->eventType; | |
b95e8d87 | 163 | |
99194e07 | 164 | switch (event->eventType){ |
b95e8d87 | 165 | |
99194e07 | 166 | case START_OF_RUN: |
167 | break; | |
b95e8d87 | 168 | |
169 | case END_OF_RUN: | |
170 | break; | |
171 | ||
1c26d5e0 | 172 | case PHYSICS_EVENT: |
b95e8d87 | 173 | // case CALIBRATION_EVENT: |
19e2ac29 | 174 | iev++; |
b95e8d87 | 175 | |
19e2ac29 | 176 | if(iev==1){ |
b95e8d87 | 177 | printf("First event - %i\n",iev); |
19e2ac29 | 178 | } |
b95e8d87 | 179 | |
99194e07 | 180 | // Initalize raw-data reading and decoding |
181 | AliRawReader *reader = new AliRawReaderDate((void*)event); | |
b95e8d87 | 182 | |
99194e07 | 183 | // Enable the following two lines in case of real-data |
b95e8d87 | 184 | reader->RequireHeader(kTRUE); |
99194e07 | 185 | AliT0RawReader *start = new AliT0RawReader(reader, kTRUE); |
b95e8d87 | 186 | |
99194e07 | 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++) | |
b95e8d87 | 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 | } | |
99194e07 | 199 | } |
b95e8d87 | 200 | else |
271b5bd3 | 201 | printf("No T0 data found!!!\n"); |
b95e8d87 | 202 | |
99194e07 | 203 | // Fill the histograms |
b95e8d87 | 204 | Float_t besttimeA=9999999; |
205 | Float_t besttimeC=9999999; | |
206 | Float_t time[24]; | |
ae4882b1 | 207 | for (Int_t ik = 0; ik<24; ik++) |
b95e8d87 | 208 | if(allData[ik+1][0]!=0 ){ |
209 | if(ik<12){ | |
3348cdd2 | 210 | hCFD1minCFD[ik]->Fill(allData[ik+1][0]-allData[npmtC][0]); |
b95e8d87 | 211 | if(iev == 20000) meanShift[ik] = hCFD1minCFD[ik]->GetMean(); |
212 | } | |
213 | if(ik>11){ | |
3348cdd2 | 214 | hCFD1minCFD[ik]->Fill(allData[ik+45][0]-allData[56+npmtA][0]); |
b95e8d87 | 215 | if(iev == 20000) |
216 | meanShift[ik] = hCFD1minCFD[ik]->GetMean(); | |
217 | } | |
99194e07 | 218 | } |
b95e8d87 | 219 | //fill vertex & mean time _ fast reconstruction |
220 | if (iev > 20000 && iev <50000) | |
221 | { | |
222 | for (Int_t in=0; in<12; in++) | |
223 | { | |
224 | time[in] = allData[in+1][0] - meanShift[in] + 5000 - allData[0][0] ; | |
225 | time[in+12] = allData[in+56+1][0] - meanShift[in+12] + 5000 - allData[0][0]; | |
226 | } | |
227 | for (Int_t ipmt=0; ipmt<12; ipmt++){ | |
228 | if(time[ipmt] > 1 ) { | |
229 | if(time[ipmt]<besttimeC) | |
230 | besttimeC=time[ipmt]; //timeC | |
231 | } | |
232 | } | |
233 | for ( Int_t ipmt=12; ipmt<24; ipmt++){ | |
234 | if(time[ipmt] > 1) { | |
235 | if(time[ipmt]<besttimeA) | |
236 | besttimeA=time[ipmt]; //timeA | |
237 | } | |
238 | } | |
239 | Float_t vertex = 0.0299792 *(besttimeC - besttimeA)*24.4/2.; | |
240 | hVertex->Fill(vertex); | |
241 | ||
242 | } | |
243 | delete start; | |
244 | start = 0x0; | |
245 | reader->Reset(); | |
99194e07 | 246 | // End of fill histograms |
b95e8d87 | 247 | |
99194e07 | 248 | } |
b95e8d87 | 249 | |
99194e07 | 250 | /* free resources */ |
251 | free(event); | |
252 | ||
253 | /* exit when last event received, no need to wait for TERM signal */ | |
254 | if (eventT==END_OF_RUN) { | |
255 | printf("EOR event detected\n"); | |
19e2ac29 | 256 | printf("Number of events processed - %i\n ",iev); |
99194e07 | 257 | break; |
258 | } | |
259 | } | |
6145b1a7 | 260 | printf("After loop, before writing histos\n"); |
99194e07 | 261 | // write a file with the histograms |
6145b1a7 | 262 | TFile *hist = new TFile(FILE_OUT,"RECREATE"); |
99194e07 | 263 | |
264 | for(Int_t j=0;j<24;j++){ | |
ae4882b1 | 265 | hCFD1minCFD[j]->Write(); |
99194e07 | 266 | } |
b95e8d87 | 267 | hVertex->Write(); |
99194e07 | 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, "PHYSICS")) { |
6145b1a7 | 275 | status=-2; |
276 | } | |
277 | ||
99194e07 | 278 | return status; |
279 | } | |
280 | ||
281 |