2 T0 DA for online calibration
4 Contact: Michal.Oledzki@cern.ch
5 Link: http://users.jyu.fi/~mioledzk/
8 Number of events needed: 400000
9 Input Files: inLaser.dat, external parameters
10 Output Files: daLaser.root, to be exported to the DAQ FXS
11 Trigger types used: CALIBRATION_EVENT
15 #define FILE_OUT "daLaser.root"
16 #define FILE_IN "inLaser.dat"
21 #include <Riostream.h>
26 #include <AliRawReaderDate.h>
27 #include <AliRawReader.h>
28 #include <AliT0RawReader.h>
32 #include "TPluginManager.h"
37 #include "TBenchmark.h"
44 #include "TSpectrum.h"
45 #include "TVirtualFitter.h"
46 //#include "TProfile.h"
47 int cqbx,cqby,clbx,clby,cbx;
48 float cqlx,cqmx,cqly,cqmy,cllx,clmx,clly,clmy,clx,cmx;
51 1- monitoring data source
53 int main(int argc, char **argv) {
57 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
63 if(daqDA_DB_getFile(FILE_IN, FILE_IN)){
64 printf("Couldn't get input file >>inLaser.dat<< from DAQ_DB !!!\n");
71 inp = fopen(FILE_IN, "r");
73 printf("Input file >>inLaser.dat<< not found !!!\n");
77 while((c=getc(inp))!=EOF) {
79 case 'a': {fscanf(inp, "%d", &cqbx ); break;} //N of X bins hCFD_QTC
80 case 'b': {fscanf(inp, "%f", &cqlx ); break;} //Low x hCFD_QTC
81 case 'c': {fscanf(inp, "%f", &cqmx ); break;} //High x hCFD_QTC
82 case 'd': {fscanf(inp, "%d", &cqby ); break;} //N of Y bins hCFD_QTC
83 case 'e': {fscanf(inp, "%f", &cqly ); break;} //Low y hCFD_QTC
84 case 'f': {fscanf(inp, "%f", &cqmy ); break;} //High y hCFD_QTC
85 case 'g': {fscanf(inp, "%d", &clbx ); break;} //N of X bins hCFD_LED
86 case 'h': {fscanf(inp, "%f", &cllx ); break;} //Low x hCFD_LED
87 case 'i': {fscanf(inp, "%f", &clmx ); break;} //High x hCFD_LED
88 case 'j': {fscanf(inp, "%d", &clby ); break;} //N of Y bins hCFD_LED
89 case 'k': {fscanf(inp, "%f", &clly ); break;} //Low y hCFD_LED
90 case 'l': {fscanf(inp, "%f", &clmy ); break;} //High y hCFD_LED
91 case 'm': {fscanf(inp, "%d", &cbx ); break;} //N of Y bins hCFD
92 case 'n': {fscanf(inp, "%f", &clx ); break;} //Low x hCFD
93 case 'o': {fscanf(inp, "%f", &cmx ); break;} //High x hCFD
99 printf("Wrong number of arguments\n");
104 /* define data source : this is argument 1 */
105 status=monitorSetDataSource( argv[1] );
107 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
112 /* declare monitoring program */
113 status=monitorDeclareMp( __FILE__ );
115 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
120 /* define wait event timeout - 1s max */
122 monitorSetNoWaitNetworkTimeout(1000);
125 /* log start of process */
126 printf("T0 monitoring program started\n");
128 // Allocation of histograms - start
133 for(Int_t ic=0; ic<24; ic++) {
134 hCFDvsQTC[ic] = new TH2F(Form("CFD_QTC%d",ic+1),"CFD_QTC",cqbx,cqlx,cqmx,cqby,cqly,cqmy);
135 hCFDvsLED[ic] = new TH2F(Form("CFD_LED%d",ic+1),"CFD_LED",clbx,cllx,clmx,clby,clly,clmy);
137 hCFD[ic] = new TH1F(Form("T0_C_%d_CFD",ic+1),"CFD", cbx,clx,cmx);
140 hCFD[ic] = new TH1F(Form("T0_A_%d_CFD",ic-11),"CFD", cbx,clx,cmx);
144 // Allocation of histograms - end
147 /* main loop (infinite) */
149 struct eventHeaderStruct *event;
150 eventTypeType eventT;
152 /* check shutdown condition */
153 if (daqDA_checkShutdown()) {break;}
155 /* get next event (blocking call until timeout) */
156 status=monitorGetEventDynamic((void **)&event);
157 if (status==(int)MON_ERR_EOF) {
158 printf ("End of File detected\n");
159 break; /* end of monitoring file has been reached */
163 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
167 /* retry if got no event */
174 /* use event - here, just write event id to result file */
175 eventT=event->eventType;
177 switch (event->eventType){
185 case CALIBRATION_EVENT:
186 // case PHYSICS_EVENT:
190 printf("First event - %i\n",iev);
193 // Initalize raw-data reading and decoding
194 AliRawReader *reader = new AliRawReaderDate((void*)event);
196 // Enable the following two lines in case of real-data
197 reader->RequireHeader(kTRUE);
198 AliT0RawReader *start = new AliT0RawReader(reader, kTRUE);
201 Int_t allData[105][5];
202 for(Int_t i0=0;i0<105;i0++)
203 for(Int_t j0=0;j0<5;j0++)
207 for (Int_t i=0; i<105; i++) {
208 for(Int_t iHit=0;iHit<5;iHit++){
209 allData[i][iHit]= start->GetData(i,iHit);
213 printf("No T0 data found!!\n");
215 // Fill the histograms
217 for (Int_t ik = 0; ik<24; ik+=2)
218 for (Int_t iHt=0; iHt<5; iHt++){
220 if((allData[cc+1][iHt]-allData[0][0]+5000)!=0 && allData[cc+1][iHt]>0){
221 hCFD[cc]->Fill(allData[cc+1][iHt]-allData[0][0]+5000);
223 if(allData[ik+25][iHt]!=0 && allData[ik+26][iHt]!=0 && allData[cc+1][iHt]!=0){
224 hCFDvsQTC[cc]->Fill((allData[ik+25][iHt]-allData[ik+26][iHt]) , (allData[cc+1][iHt]-allData[0][0]+5000));
226 if(allData[cc+13][iHt]!=0 && allData[cc+1][iHt]!=0){
227 hCFDvsLED[cc]->Fill(allData[cc+13][iHt]-allData[cc+1][iHt],allData[cc+1][iHt]-allData[0][0]+5000);
231 for (Int_t ik = 24; ik<48; ik+=2)
232 for (Int_t iHt=0; iHt<5; iHt++){
234 if((allData[cc+45][iHt]-allData[0][0]+5000)!=0 && allData[cc+45][iHt]>0){
235 hCFD[cc]->Fill(allData[cc+45][iHt]-allData[0][0]+5000);
237 if(allData[ik+57][iHt]!=0 && allData[ik+58][iHt]!=0 && allData[cc+45][iHt]!=0){
238 hCFDvsQTC[cc]->Fill(allData[ik+57][iHt]-allData[ik+58][iHt],allData[cc+45][iHt]-allData[0][0]+5000);
240 if(allData[cc+57][iHt]!=0 && allData[cc+45][iHt]!=0){
241 hCFDvsLED[cc]->Fill(allData[cc+57][iHt]-allData[cc+45][iHt],allData[cc+45][iHt]-allData[0][0]+5000);
248 // End of fill histograms
255 /* exit when last event received, no need to wait for TERM signal */
256 if (eventT==END_OF_RUN) {
257 printf("EOR event detected\n");
258 printf("Number of events processed - %i\n ",iev);
262 printf("After loop, before writing histos\n");
263 // write a file with the histograms
264 TFile *hist = new TFile(FILE_OUT,"RECREATE");
266 for(Int_t j=0;j<24;j++){
267 hCFDvsQTC[j]->Write();
268 hCFDvsLED[j]->Write();
276 /* export file to FXS */
277 if (daqDA_FES_storeFile(FILE_OUT, "LASER")) {