loading libANALYSIS.so
[u/mrichter/AliRoot.git] / T0 / T0Laserda.cxx
CommitLineData
f16a53cf 1/*
2TOF DA for online calibration
3
4Contact: Michal.Oledzki@cern.ch
5Link: www.if.pw.edu.pl:/~oledzki
6Run Type: PHYSICS
7DA Type: MON
8Number of events needed: depending on the run, being run-level
9Input Files:
10Output Files: daLaser.root, to be exported to the DAQ FXS
11Trigger types used: PHYSICS_EVENT
12
13*/
99194e07 14//extern "C"
15
f16a53cf 16#define FILE_OUT "daLaser.root"
99194e07 17
f16a53cf 18#include <daqDA.h>
99194e07 19#include <event.h>
20#include <monitor.h>
21
22#include <Riostream.h>
23#include <stdio.h>
24#include <stdlib.h>
25
26//AliRoot
27#include <AliRawReaderDate.h>
28#include <AliRawReader.h>
29#include <AliT0RawReader.h>
99194e07 30
31//ROOT
32#include "TFile.h"
33#include "TKey.h"
34#include "TH2S.h"
35#include "TObject.h"
36#include "TBenchmark.h"
37#include "TRandom.h"
38#include "TMath.h"
39#include "TCanvas.h"
40#include "TString.h"
41#include "TH1.h"
42#include "TF1.h"
43#include "TSpectrum.h"
44#include "TVirtualFitter.h"
45#include "TProfile.h"
46
47/* Main routine
48 Arguments:
49 1- monitoring data source
50*/
51int main(int argc, char **argv) {
52 int status;
53
54
55 if (argc!=2) {
56 printf("Wrong number of arguments\n");
57 return -1;
58 }
59
60
61 /* define data source : this is argument 1 */
62 status=monitorSetDataSource( argv[1] );
63 if (status!=0) {
64 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
65 return -1;
66 }
67
68
69 /* declare monitoring program */
70 status=monitorDeclareMp( __FILE__ );
71 if (status!=0) {
72 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
73 return -1;
74 }
75
76
77 /* define wait event timeout - 1s max */
78 monitorSetNowait();
79 monitorSetNoWaitNetworkTimeout(1000);
80
81
82 /* log start of process */
83 printf("T0 monitoring program started\n");
84
85 // Allocation of histograms - start
86 TH1F *hCFD[24];
87 TH2F *hCFD_QTC[24]; TH2F *hCFD_LED[24];
88 Char_t buf1[10], buf2[10],buf3[10],buf4[10];
89
90 for(Int_t ic=0; ic<24; ic++) {
91 sprintf(buf1,"CFD_QTC%i",ic+1);
92 sprintf(buf2,"CFD_LED%i",ic+1);
93
94 hCFD_QTC[ic] = new TH2F(buf1,"CFD_QTC",8000,0.5,8000.5,2000,10000.5,20000.5);
95 hCFD_LED[ic] = new TH2F(buf2,"CFD_LED",1000,-500.0,500.0,100,14600.0,14700.0);
96 if(ic<12){
97 sprintf(buf3,"T0_C_%i_CFD",ic+1);
98 hCFD[ic] = new TH1F(buf3,"CFD", 30000,0., 30000.);
99 }
100 else{
101 sprintf(buf4,"T0_A_%i_CFD",ic-11);
102 hCFD[ic] = new TH1F(buf4,"CFD", 30000,0., 30000.);
103 }
104 }
105
106 // Allocation of histograms - end
107
108 Int_t iev=0;
109 /* main loop (infinite) */
110 for(;;) {
111 struct eventHeaderStruct *event;
112 eventTypeType eventT;
113
114 /* check shutdown condition */
115 if (daqDA_checkShutdown()) {break;}
116
117 /* get next event (blocking call until timeout) */
118 status=monitorGetEventDynamic((void **)&event);
119 if (status==(int)MON_ERR_EOF) {
120 printf ("End of File detected\n");
121 break; /* end of monitoring file has been reached */
122 }
123
124 if (status!=0) {
125 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
126 break;
127 }
128
129 /* retry if got no event */
130 if (event==NULL) {
131 continue;
132 }
133
134 iev++;
135
136 /* use event - here, just write event id to result file */
137 eventT=event->eventType;
138
139 switch (event->eventType){
140
141 case START_OF_RUN:
142 break;
143
144 case END_OF_RUN:
145 break;
146
147// case CALIBRATION_EVENT:
148 case PHYSICS_EVENT:
149 printf(" event number = %i \n",iev);
150
151
152 // Initalize raw-data reading and decoding
153 AliRawReader *reader = new AliRawReaderDate((void*)event);
154
155 // Enable the following two lines in case of real-data
156 // reader->LoadEquipmentIdsMap("T0map.txt");
157 // reader->RequireHeader(kFALSE);
158 // reader->RequireHeader(kTRUE);
159 AliT0RawReader *start = new AliT0RawReader(reader, kTRUE);
160
161 // Read raw data
162 Int_t allData[105][5];
163 for(Int_t i0=0;i0<105;i0++)
164 for(Int_t j0=0;j0<5;j0++)
165 allData[i0][j0] = 0;
166
167 if(start->Next())
168 for (Int_t i=0; i<105; i++) {
169 for(Int_t iHit=0;iHit<5;iHit++){
170 allData[i][iHit]= start->GetData(i,iHit);
171 }
172 }
173 else
174 printf("No T0 data found!!\n");
175
176 // Fill the histograms
177
178 for (Int_t ik = 0; ik<24; ik+=2)
179 for (Int_t iHt=0; iHt<5; iHt++){
180 Int_t cc = ik/2;
181 if((allData[cc+1][iHt]-allData[0][0])>0){
182 hCFD[cc]->Fill(allData[cc+1][iHt]-allData[0][0]);
183 }
184 if(allData[ik+25][iHt]!=0 && allData[ik+26][iHt]!=0 && allData[cc+1][iHt]!=0){
185 hCFD_QTC[cc]->Fill((allData[ik+25][iHt]-allData[ik+26][iHt]) , (allData[cc+1][iHt]-allData[0][0]));
186 }
187 if(allData[cc+13][iHt]!=0 && allData[cc+1][iHt]!=0){
188 hCFD_LED[cc]->Fill(allData[cc+13][iHt]-allData[cc+1][iHt],allData[cc+1][iHt]-allData[0][0]);
189 }
190 }
191
192 for (Int_t ik = 24; ik<48; ik+=2)
193 for (Int_t iHt=0; iHt<5; iHt++){
194 Int_t cc = ik/2;
195 if((allData[cc+45][iHt]-allData[0][0])>0){
196 hCFD[cc]->Fill(allData[cc+45][iHt]-allData[0][0]);
197 }
198
199 if(allData[ik+57][iHt]!=0 && allData[ik+58][iHt]!=0){
200 if(allData[cc+45][iHt]!=0)
201 hCFD_QTC[cc]->Fill(allData[ik+57][iHt]-allData[ik+58][iHt],allData[cc+45][iHt]-allData[0][0]);
202 }
203 if(allData[cc+57][iHt]!=0 && allData[cc+45][iHt]!=0){
204 hCFD_LED[cc]->Fill(allData[cc+57][iHt]-allData[cc+45][iHt],allData[cc+45][iHt]-allData[0][0]);
205 }
206 }
207
208
209 delete start;
210 start = 0x0;
211 reader->Reset();
212 // End of fill histograms
213
214 }
215
216
217
218 /* free resources */
219 free(event);
220
221 /* exit when last event received, no need to wait for TERM signal */
222 if (eventT==END_OF_RUN) {
223 printf("EOR event detected\n");
224 break;
225 }
226 }
227printf("After loop, before writing histos\n");
228 // write a file with the histograms
f16a53cf 229 TFile *hist = new TFile(FILE_OUT,"RECREATE");
99194e07 230
231 for(Int_t j=0;j<24;j++){
232 hCFD_QTC[j]->Write();
233 hCFD_LED[j]->Write();
234 hCFD[j]->Write();
235 }
236 hist->Close();
237 delete hist;
238
239 return status;
240}
241