]> git.uio.no Git - u/mrichter/AliRoot.git/blame - T0/T0Physda.cxx
1.The QA data created on demand according to the event species at filling time. 2...
[u/mrichter/AliRoot.git] / T0 / T0Physda.cxx
CommitLineData
6145b1a7 1/*
2T0 DA for online calibration
271b5bd3 3
6145b1a7 4Contact: Michal.Oledzki@cern.ch
5Link: http://users.jyu.fi/~mioledzk/
6Run Type: PHYSICS
7DA Type: MON
8Number of events needed: 500000
9Input Files: inPhys.dat, external parameters
10Output Files: daPhys.root, to be exported to the DAQ FXS
11Trigger types used: PHYSICS_EVENT
49976464 12------------------------------Alla
13Now trigger type changed to CALICRATION_EVENT
14to have data during test.
15SOULD 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"
6145b1a7 49int cbx, ccbx;
50float clx,cmx,cclx,ccmx;
99194e07 51
52/* Main routine
53 Arguments:
54 1- monitoring data source
55*/
56int 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
85 case 'c': {fscanf(inp, "%f", &ccmx ); break;} //High x hCFD1_CFD
86 // case 'd': {fscanf(inp, "%d", &cbx ); break;} //N of X bins hCFD
87 // case 'e': {fscanf(inp, "%f", &clx ); break;} //Low x hCFD
271b5bd3 88// case 'f': {fscanf(inp, "%f", &cmx ); break;} //High x hCFD
6145b1a7 89 }
90 }
91 fclose(inp);
92
99194e07 93 if (argc!=2) {
94 printf("Wrong number of arguments\n");
95 return -1;
96 }
b95e8d87 97
99194e07 98
99 /* define data source : this is argument 1 */
100 status=monitorSetDataSource( argv[1] );
101 if (status!=0) {
102 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
103 return -1;
104 }
b95e8d87 105
106
99194e07 107 /* declare monitoring program */
108 status=monitorDeclareMp( __FILE__ );
109 if (status!=0) {
110 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
111 return -1;
112 }
b95e8d87 113
114
99194e07 115 /* define wait event timeout - 1s max */
116 monitorSetNowait();
117 monitorSetNoWaitNetworkTimeout(1000);
118
b95e8d87 119
99194e07 120 /* log start of process */
121 printf("T0 monitoring program started\n");
b95e8d87 122
99194e07 123 // Allocation of histograms - start
124
ae4882b1 125 TH1F *hCFD1minCFD[24];
6145b1a7 126
b95e8d87 127 for(Int_t ic=0; ic<24; ic++) {
128 hCFD1minCFD[ic] = new TH1F(Form("CFD1-CFD%d",ic+1),"CFD-CFD",ccbx,cclx,ccmx);
129 }
130 TH1F *hVertex = new TH1F("hVertex","Z vertex",ccbx,cclx,ccmx);
131
132 Float_t meanShift[24];
133
99194e07 134 // Allocation of histograms - end
135
136 Int_t iev=0;
137 /* main loop (infinite) */
138 for(;;) {
139 struct eventHeaderStruct *event;
140 eventTypeType eventT;
b95e8d87 141
99194e07 142 /* check shutdown condition */
143 if (daqDA_checkShutdown()) {break;}
144
145 /* get next event (blocking call until timeout) */
146 status=monitorGetEventDynamic((void **)&event);
147 if (status==(int)MON_ERR_EOF) {
148 printf ("End of File detected\n");
149 break; /* end of monitoring file has been reached */
150 }
151
152 if (status!=0) {
153 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
154 break;
155 }
b95e8d87 156
99194e07 157 /* retry if got no event */
158 if (event==NULL) {
159 continue;
160 }
b95e8d87 161
99194e07 162 /* use event - here, just write event id to result file */
163 eventT=event->eventType;
b95e8d87 164
99194e07 165 switch (event->eventType){
b95e8d87 166
99194e07 167 case START_OF_RUN:
168 break;
b95e8d87 169
170 case END_OF_RUN:
171 break;
172
1c26d5e0 173 case PHYSICS_EVENT:
b95e8d87 174 // case CALIBRATION_EVENT:
19e2ac29 175 iev++;
b95e8d87 176
19e2ac29 177 if(iev==1){
b95e8d87 178 printf("First event - %i\n",iev);
19e2ac29 179 }
b95e8d87 180
99194e07 181 // Initalize raw-data reading and decoding
182 AliRawReader *reader = new AliRawReaderDate((void*)event);
b95e8d87 183
99194e07 184 // Enable the following two lines in case of real-data
b95e8d87 185 reader->RequireHeader(kTRUE);
99194e07 186 AliT0RawReader *start = new AliT0RawReader(reader, kTRUE);
b95e8d87 187
99194e07 188 // Read raw data
189 Int_t allData[105][5];
190 for(Int_t i0=0;i0<105;i0++)
191 for(Int_t j0=0;j0<5;j0++)
b95e8d87 192 allData[i0][j0] = 0;
193
194 if(start->Next()){
195 for (Int_t i=0; i<105; i++) {
196 for(Int_t iHit=0;iHit<5;iHit++){
197 allData[i][iHit]= start->GetData(i,iHit);
198 }
199 }
99194e07 200 }
b95e8d87 201 else
271b5bd3 202 printf("No T0 data found!!!\n");
b95e8d87 203
99194e07 204 // Fill the histograms
b95e8d87 205 Float_t besttimeA=9999999;
206 Float_t besttimeC=9999999;
207 Float_t time[24];
ae4882b1 208 for (Int_t ik = 0; ik<24; ik++)
b95e8d87 209 if(allData[ik+1][0]!=0 ){
210 if(ik<12){
211 hCFD1minCFD[ik]->Fill(allData[ik+1][0]-allData[1][0]);
212 if(iev == 20000) meanShift[ik] = hCFD1minCFD[ik]->GetMean();
213 }
214 if(ik>11){
215 hCFD1minCFD[ik]->Fill(allData[ik+45][0]-allData[57][0]);
216 if(iev == 20000)
217 meanShift[ik] = hCFD1minCFD[ik]->GetMean();
218 }
99194e07 219 }
b95e8d87 220 //fill vertex & mean time _ fast reconstruction
221 if (iev > 20000 && iev <50000)
222 {
223 for (Int_t in=0; in<12; in++)
224 {
225 time[in] = allData[in+1][0] - meanShift[in] + 5000 - allData[0][0] ;
226 time[in+12] = allData[in+56+1][0] - meanShift[in+12] + 5000 - allData[0][0];
227 }
228 for (Int_t ipmt=0; ipmt<12; ipmt++){
229 if(time[ipmt] > 1 ) {
230 if(time[ipmt]<besttimeC)
231 besttimeC=time[ipmt]; //timeC
232 }
233 }
234 for ( Int_t ipmt=12; ipmt<24; ipmt++){
235 if(time[ipmt] > 1) {
236 if(time[ipmt]<besttimeA)
237 besttimeA=time[ipmt]; //timeA
238 }
239 }
240 Float_t vertex = 0.0299792 *(besttimeC - besttimeA)*24.4/2.;
241 hVertex->Fill(vertex);
242
243 }
244 delete start;
245 start = 0x0;
246 reader->Reset();
99194e07 247 // End of fill histograms
b95e8d87 248
99194e07 249 }
b95e8d87 250
99194e07 251 /* free resources */
252 free(event);
253
254 /* exit when last event received, no need to wait for TERM signal */
255 if (eventT==END_OF_RUN) {
256 printf("EOR event detected\n");
19e2ac29 257 printf("Number of events processed - %i\n ",iev);
99194e07 258 break;
259 }
260 }
6145b1a7 261 printf("After loop, before writing histos\n");
99194e07 262 // write a file with the histograms
6145b1a7 263 TFile *hist = new TFile(FILE_OUT,"RECREATE");
99194e07 264
265 for(Int_t j=0;j<24;j++){
ae4882b1 266 hCFD1minCFD[j]->Write();
99194e07 267 }
b95e8d87 268 hVertex->Write();
99194e07 269 hist->Close();
270 delete hist;
271
6145b1a7 272 status=0;
273
274 /* export file to FXS */
387638f7 275 if (daqDA_FES_storeFile(FILE_OUT, "PHYSICS")) {
6145b1a7 276 status=-2;
277 }
278
99194e07 279 return status;
280}
281
282