]> git.uio.no Git - u/mrichter/AliRoot.git/blame - T0/T0Laserda.cxx
Compilation warning fixed.
[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"
933d9707 46//AMORE
47//
48#ifdef ALI_AMORE
49#include <AmoreDA.h>
50#endif
51
52
53float lcfd, hcfd;
99194e07 54/* Main routine
55 Arguments:
56 1- monitoring data source
57*/
58int main(int argc, char **argv) {
59 int status;
60
0acfe114 61 /* magic line */
62 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
63 "*",
64 "TStreamerInfo",
65 "RIO",
66 "TStreamerInfo()");
19e2ac29 67
933d9707 68 Int_t nEntries = daqDA_ECS_getTotalIteration(); // usually = 11 = Nb of calibration runs
69 cout<<" nEntries "<<nEntries<<endl;
70 Int_t nInit=1; // = 0 all DAC values ; = 1 DAC=0 excluded (default=1)
71 // Reading current iteration
72 Int_t nIndex = daqDA_ECS_getCurrentIteration();
73 if(nIndex<0 || nIndex>nEntries) {printf("\n Failed: nIndex = %d\n",nIndex); return -1 ;}
19e2ac29 74
933d9707 75
76// decode the input line
77 if (argc!=2) {
78 printf("Wrong number of arguments\n");
79 return -1;
19e2ac29 80 }
933d9707 81
19e2ac29 82
933d9707 83 Float_t mipsin[20];
84 if(daqDA_DB_getFile(FILE_IN, FILE_IN)){
85 printf("Couldn't get input file >>inLaser.dat<< from DAQ_DB !!!\n");
86 return -1;
6145b1a7 87 }
6145b1a7 88
933d9707 89 ifstream filein(FILE_IN,ios::in);
90 Int_t k=0;
91 while (k<nEntries ) {
92 filein >>mipsin[k] ;
93 cout<<" "<<mipsin[k]<<endl;
94 k++; }
95 filein>>lcfd;
96 filein>>hcfd;
97 filein.close();
98
99
100
101 /*
99194e07 102 if (argc!=2) {
103 printf("Wrong number of arguments\n");
104 return -1;
105 }
933d9707 106 */
107
108 // Char_t inputFile[256]="";
99194e07 109
110
111 /* define data source : this is argument 1 */
112 status=monitorSetDataSource( argv[1] );
113 if (status!=0) {
114 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
115 return -1;
116 }
117
118
119 /* declare monitoring program */
120 status=monitorDeclareMp( __FILE__ );
121 if (status!=0) {
122 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
123 return -1;
124 }
125
126
127 /* define wait event timeout - 1s max */
128 monitorSetNowait();
129 monitorSetNoWaitNetworkTimeout(1000);
130
131
132 /* log start of process */
133 printf("T0 monitoring program started\n");
933d9707 134
99194e07 135 // Allocation of histograms - start
933d9707 136
137 TH1F *hQTC[24]; TH1F *hLED[24]; TH1F *hCFD[24];
138 printf(" CFD low limit %f high %f",lcfd, hcfd);
139
140 for(Int_t ic=0; ic<24; ic++)
271b5bd3 141 {
933d9707 142 hQTC[ic] = new TH1F(Form("hQTC%d_%d",ic+1,nIndex),"QTC",1000, 500, 4500);
143 hLED[ic] = new TH1F(Form("hLED%d_%d",ic+1,nIndex),"LED",300,300,600);
144 hCFD[ic] = new TH1F(Form("hCFD%d_%d",ic+1,nIndex),"CFD", Int_t ((hcfd-lcfd)/2), lcfd, hcfd);
99194e07 145 }
933d9707 146
99194e07 147 // Allocation of histograms - end
933d9707 148
149 // Reading current iteration
150
99194e07 151 Int_t iev=0;
933d9707 152
99194e07 153 /* main loop (infinite) */
154 for(;;) {
155 struct eventHeaderStruct *event;
156 eventTypeType eventT;
933d9707 157
99194e07 158 /* check shutdown condition */
159 if (daqDA_checkShutdown()) {break;}
160
161 /* get next event (blocking call until timeout) */
162 status=monitorGetEventDynamic((void **)&event);
163 if (status==(int)MON_ERR_EOF) {
164 printf ("End of File detected\n");
165 break; /* end of monitoring file has been reached */
166 }
167
168 if (status!=0) {
169 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
170 break;
171 }
933d9707 172
99194e07 173 /* retry if got no event */
174 if (event==NULL) {
175 continue;
176 }
933d9707 177
99194e07 178 /* use event - here, just write event id to result file */
179 eventT=event->eventType;
933d9707 180
99194e07 181 switch (event->eventType){
933d9707 182
183 case START_OF_RUN:
184 break;
185
186 case END_OF_RUN:
187 break;
188
189 case CALIBRATION_EVENT:
190 // case PHYSICS_EVENT:
19e2ac29 191 iev++;
933d9707 192
193 if(iev==1) printf("First event %i\n",iev);
194
195
99194e07 196 // Initalize raw-data reading and decoding
197 AliRawReader *reader = new AliRawReaderDate((void*)event);
933d9707 198
99194e07 199 // Enable the following two lines in case of real-data
933d9707 200 reader->RequireHeader(kTRUE);
99194e07 201 AliT0RawReader *start = new AliT0RawReader(reader, kTRUE);
202
203 // Read raw data
271b5bd3 204 Int_t allData[106][5];
205 for(Int_t i0=0;i0<106;i0++)
99194e07 206 for(Int_t j0=0;j0<5;j0++)
207 allData[i0][j0] = 0;
933d9707 208
209 if(start->Next()){
271b5bd3 210 for (Int_t i=0; i<106; i++) {
933d9707 211 for(Int_t iHit=0;iHit<5;iHit++){
212 allData[i][iHit]= start->GetData(i,iHit);
213 }
99194e07 214 }
933d9707 215 }
216 else
217 printf("No data for T0 found!!!\n");
218
219
99194e07 220 // Fill the histograms
271b5bd3 221
99194e07 222 for (Int_t ik = 0; ik<24; ik+=2)
933d9707 223 {
224 Int_t cc = ik/2;
225 if(allData[ik+25][0]>0 && allData[ik+26][0]>0)
226 hQTC[cc]->Fill((allData[ik+25][0]-allData[ik+26][0]));
227 if(allData[cc+13][0]>0 && allData[cc+1][0]>0)
228 hLED[cc]->Fill(allData[cc+13][0]-allData[cc+1][0]);
229 if(allData[cc+1][0] > 0) hCFD[cc]->Fill(allData[cc+1][0]);
230 // printf("%i %i CFD %i LED_CFD %i\n",
231 // ik,cc,allData[cc+1][0],allData[cc+1][0]);
232
233 }
234
235
99194e07 236 for (Int_t ik = 24; ik<48; ik+=2)
933d9707 237 {
238 Int_t cc = ik/2;
239 if(allData[ik+57][0]>0 && allData[ik+58][0]>0 && allData[cc+45][0]>0)
240 hQTC[cc]->Fill(allData[ik+57][0]-allData[ik+58][0]);
241
242 if(allData[cc+57][0]>0 && allData[cc+45][0]>0)
243 hLED[cc]->Fill(allData[cc+57][0]-allData[cc+45][0]);
244 if(allData[cc+45][0] > 0) hCFD[cc]->Fill(allData[cc+45][0]);
245 // printf("%i %i CFD %i LED_CFD %i\n",
246 // ik,cc,allData[cc+45][0],allData[cc+45][0]);
247
99194e07 248 }
271b5bd3 249
933d9707 250 delete start;
251 start = 0x0;
252 reader->Reset();
99194e07 253 // End of fill histograms
254
255 }
933d9707 256
99194e07 257 /* free resources */
258 free(event);
259
260 /* exit when last event received, no need to wait for TERM signal */
261 if (eventT==END_OF_RUN) {
262 printf("EOR event detected\n");
19e2ac29 263 printf("Number of events processed - %i\n ",iev);
99194e07 264 break;
265 }
266 }
933d9707 267
6145b1a7 268 printf("After loop, before writing histos\n");
933d9707 269 TH1F* hAmp = new TH1F("hAmpLaser"," Laser amplitude ", 1000, 0.5, 10.5);
270 for(Int_t k=0; k<nEntries; k++) hAmp->Fill(mipsin[k]);
99194e07 271 // write a file with the histograms
933d9707 272 TFile *hist=0;
273 if(nIndex == 1 )
274 hist = new TFile(FILE_OUT,"RECREATE");
275 else
276 hist = new TFile(FILE_OUT,"UPDATE");
277 hist->cd();
278
271b5bd3 279 for(Int_t j=0;j<24;j++)
271b5bd3 280 {
933d9707 281 if(hQTC[j]->GetEntries()>0) hQTC[j]->Write();
282 if(hLED[j]->GetEntries()>0) hLED[j]->Write();
283 if(hCFD[j]->GetEntries()>0) hCFD[j]->Write();
99194e07 284 }
933d9707 285 hAmp->Write();
286
99194e07 287 hist->Close();
288 delete hist;
933d9707 289
6145b1a7 290 status=0;
933d9707 291
6145b1a7 292 /* export file to FXS */
933d9707 293 if (daqDA_FES_storeFile(FILE_OUT, "AMPLITUDE_CALIBRATION")) {
6145b1a7 294 status=-2;
295 }
933d9707 296
99194e07 297 return status;
298}
299