Reading muon trigger scalers with the DA of the muon trigger and transfer
[u/mrichter/AliRoot.git] / T0 / DA / T0Laserda.cxx
CommitLineData
f16a53cf 1/*
6145b1a7 2T0 DA for online calibration
271b5bd3 3
8fb3757b 4Contact: Alla.Maevskaya@cern.ch
5Run Type: AMPLITUDE_CALIBRATION
f16a53cf 6DA Type: MON
8fb3757b 7Number of events needed: 5000
6145b1a7 8Input Files: inLaser.dat, external parameters
f16a53cf 9Output Files: daLaser.root, to be exported to the DAQ FXS
49ab1618 10Trigger types used: CALIBRATION_EVENT
f16a53cf 11
12*/
99194e07 13
f16a53cf 14#define FILE_OUT "daLaser.root"
6145b1a7 15#define FILE_IN "inLaser.dat"
f16a53cf 16#include <daqDA.h>
99194e07 17#include <event.h>
18#include <monitor.h>
19
20#include <Riostream.h>
21#include <stdio.h>
22#include <stdlib.h>
23
24//AliRoot
25#include <AliRawReaderDate.h>
26#include <AliRawReader.h>
27#include <AliT0RawReader.h>
99194e07 28
29//ROOT
0acfe114 30#include "TROOT.h"
31#include "TPluginManager.h"
32#include "TFile.h"
99194e07 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"
933d9707 45//AMORE
46//
47#ifdef ALI_AMORE
48#include <AmoreDA.h>
49#endif
50
51
52float lcfd, hcfd;
99194e07 53/* Main routine
54 Arguments:
55 1- monitoring data source
56*/
57int main(int argc, char **argv) {
58 int status;
59
0acfe114 60 /* magic line */
61 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
62 "*",
63 "TStreamerInfo",
64 "RIO",
65 "TStreamerInfo()");
19e2ac29 66
933d9707 67 Int_t nEntries = daqDA_ECS_getTotalIteration(); // usually = 11 = Nb of calibration runs
68 cout<<" nEntries "<<nEntries<<endl;
69 Int_t nInit=1; // = 0 all DAC values ; = 1 DAC=0 excluded (default=1)
70 // Reading current iteration
71 Int_t nIndex = daqDA_ECS_getCurrentIteration();
72 if(nIndex<0 || nIndex>nEntries) {printf("\n Failed: nIndex = %d\n",nIndex); return -1 ;}
19e2ac29 73
933d9707 74
75// decode the input line
76 if (argc!=2) {
77 printf("Wrong number of arguments\n");
78 return -1;
19e2ac29 79 }
933d9707 80
19e2ac29 81
933d9707 82 Float_t mipsin[20];
83 if(daqDA_DB_getFile(FILE_IN, FILE_IN)){
84 printf("Couldn't get input file >>inLaser.dat<< from DAQ_DB !!!\n");
85 return -1;
6145b1a7 86 }
6145b1a7 87
933d9707 88 ifstream filein(FILE_IN,ios::in);
89 Int_t k=0;
90 while (k<nEntries ) {
91 filein >>mipsin[k] ;
92 cout<<" "<<mipsin[k]<<endl;
93 k++; }
94 filein>>lcfd;
95 filein>>hcfd;
96 filein.close();
97
98
99
100 /*
99194e07 101 if (argc!=2) {
102 printf("Wrong number of arguments\n");
103 return -1;
104 }
933d9707 105 */
106
107 // Char_t inputFile[256]="";
99194e07 108
109
110 /* define data source : this is argument 1 */
111 status=monitorSetDataSource( argv[1] );
112 if (status!=0) {
113 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
114 return -1;
115 }
116
117
118 /* declare monitoring program */
119 status=monitorDeclareMp( __FILE__ );
120 if (status!=0) {
121 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
122 return -1;
123 }
124
125
126 /* define wait event timeout - 1s max */
127 monitorSetNowait();
128 monitorSetNoWaitNetworkTimeout(1000);
129
130
131 /* log start of process */
132 printf("T0 monitoring program started\n");
933d9707 133
99194e07 134 // Allocation of histograms - start
933d9707 135
136 TH1F *hQTC[24]; TH1F *hLED[24]; TH1F *hCFD[24];
137 printf(" CFD low limit %f high %f",lcfd, hcfd);
138
139 for(Int_t ic=0; ic<24; ic++)
271b5bd3 140 {
0bf44cd7 141 hQTC[ic] = new TH1F(Form("hQTC%d_%d",ic+1,nIndex),"QTC",1000, 500, 10000);
142 hLED[ic] = new TH1F(Form("hLED%d_%d",ic+1,nIndex),"LED",125,200,700);
933d9707 143 hCFD[ic] = new TH1F(Form("hCFD%d_%d",ic+1,nIndex),"CFD", Int_t ((hcfd-lcfd)/2), lcfd, hcfd);
99194e07 144 }
933d9707 145
99194e07 146 // Allocation of histograms - end
933d9707 147
148 // Reading current iteration
149
99194e07 150 Int_t iev=0;
933d9707 151
99194e07 152 /* main loop (infinite) */
153 for(;;) {
154 struct eventHeaderStruct *event;
155 eventTypeType eventT;
933d9707 156
99194e07 157 /* check shutdown condition */
158 if (daqDA_checkShutdown()) {break;}
159
160 /* get next event (blocking call until timeout) */
161 status=monitorGetEventDynamic((void **)&event);
162 if (status==(int)MON_ERR_EOF) {
163 printf ("End of File detected\n");
164 break; /* end of monitoring file has been reached */
165 }
166
167 if (status!=0) {
168 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
169 break;
170 }
933d9707 171
99194e07 172 /* retry if got no event */
173 if (event==NULL) {
174 continue;
175 }
933d9707 176
99194e07 177 /* use event - here, just write event id to result file */
178 eventT=event->eventType;
933d9707 179
99194e07 180 switch (event->eventType){
933d9707 181
182 case START_OF_RUN:
183 break;
184
185 case END_OF_RUN:
186 break;
187
188 case CALIBRATION_EVENT:
189 // case PHYSICS_EVENT:
19e2ac29 190 iev++;
933d9707 191
192 if(iev==1) printf("First event %i\n",iev);
193
194
99194e07 195 // Initalize raw-data reading and decoding
196 AliRawReader *reader = new AliRawReaderDate((void*)event);
933d9707 197
99194e07 198 // Enable the following two lines in case of real-data
933d9707 199 reader->RequireHeader(kTRUE);
99194e07 200 AliT0RawReader *start = new AliT0RawReader(reader, kTRUE);
201
202 // Read raw data
271b5bd3 203 Int_t allData[106][5];
204 for(Int_t i0=0;i0<106;i0++)
99194e07 205 for(Int_t j0=0;j0<5;j0++)
206 allData[i0][j0] = 0;
933d9707 207
208 if(start->Next()){
271b5bd3 209 for (Int_t i=0; i<106; i++) {
933d9707 210 for(Int_t iHit=0;iHit<5;iHit++){
211 allData[i][iHit]= start->GetData(i,iHit);
212 }
99194e07 213 }
933d9707 214 }
215 else
216 printf("No data for T0 found!!!\n");
217
218
99194e07 219 // Fill the histograms
271b5bd3 220
99194e07 221 for (Int_t ik = 0; ik<24; ik+=2)
933d9707 222 {
223 Int_t cc = ik/2;
224 if(allData[ik+25][0]>0 && allData[ik+26][0]>0)
225 hQTC[cc]->Fill((allData[ik+25][0]-allData[ik+26][0]));
226 if(allData[cc+13][0]>0 && allData[cc+1][0]>0)
227 hLED[cc]->Fill(allData[cc+13][0]-allData[cc+1][0]);
228 if(allData[cc+1][0] > 0) hCFD[cc]->Fill(allData[cc+1][0]);
229 // printf("%i %i CFD %i LED_CFD %i\n",
230 // ik,cc,allData[cc+1][0],allData[cc+1][0]);
231
232 }
233
234
99194e07 235 for (Int_t ik = 24; ik<48; ik+=2)
933d9707 236 {
237 Int_t cc = ik/2;
238 if(allData[ik+57][0]>0 && allData[ik+58][0]>0 && allData[cc+45][0]>0)
239 hQTC[cc]->Fill(allData[ik+57][0]-allData[ik+58][0]);
240
241 if(allData[cc+57][0]>0 && allData[cc+45][0]>0)
242 hLED[cc]->Fill(allData[cc+57][0]-allData[cc+45][0]);
243 if(allData[cc+45][0] > 0) hCFD[cc]->Fill(allData[cc+45][0]);
244 // printf("%i %i CFD %i LED_CFD %i\n",
245 // ik,cc,allData[cc+45][0],allData[cc+45][0]);
246
99194e07 247 }
271b5bd3 248
933d9707 249 delete start;
250 start = 0x0;
2a9a5b36 251 delete reader;
252 reader= 0x0;
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");
faf85e90 269 TH1F* hAmp = new TH1F("hAmpLaser"," Laser amplitude ", 1000, 0.5, 20.5);
0bf44cd7 270 for(Int_t i=0; i<nIndex; i++) hAmp->Fill(mipsin[i]);
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