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