2 T0 DA for online calibration
4 Contact: Michal.Oledzki@cern.ch
5 Link: http://users.jyu.fi/~mioledzk/
8 Number of events needed: 500000
9 Input Files: inPhys.dat, external parameters
10 Output Files: daPhys.root, to be exported to the DAQ FXS
11 Trigger types used: PHYSICS_EVENT
15 #define FILE_OUT "daPhys.root"
16 #define FILE_IN "inPhys.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"
43 #include "TSpectrum.h"
44 #include "TVirtualFitter.h"
46 float clx,cmx,cclx,ccmx;
50 1- monitoring data source
52 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 >>inPhys.dat<< from DAQ_DB !!!\n");
71 inp = fopen(FILE_IN, "r");
73 printf("Input file >>inPhys.dat<< not found !!!\n");
77 while((c=getc(inp))!=EOF) {
79 case 'a': {fscanf(inp, "%d", &ccbx ); break;} //N of X bins hCFD1_CFD
80 case 'b': {fscanf(inp, "%f", &cclx ); break;} //Low x hCFD1_CFD
81 case 'c': {fscanf(inp, "%f", &ccmx ); break;} //High x hCFD1_CFD
82 case 'd': {fscanf(inp, "%d", &cbx ); break;} //N of X bins hCFD
83 case 'e': {fscanf(inp, "%f", &clx ); break;} //Low x hCFD
84 case 'f': {fscanf(inp, "%f", &cmx ); break;} //High x hCFD
90 printf("Wrong number of arguments\n");
95 /* define data source : this is argument 1 */
96 status=monitorSetDataSource( argv[1] );
98 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
103 /* declare monitoring program */
104 status=monitorDeclareMp( __FILE__ );
106 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
111 /* define wait event timeout - 1s max */
113 monitorSetNoWaitNetworkTimeout(1000);
116 /* log start of process */
117 printf("T0 monitoring program started\n");
119 // Allocation of histograms - start
121 TH1F *hCFD1minCFD[24];
124 for(Int_t ic=0; ic<24; ic++) {
126 hCFD1minCFD[ic] = new TH1F(Form("CFD1-CFD%d",ic+1),"CFD-CFD",ccbx,cclx,ccmx);
127 hCFD[ic] = new TH1F(Form("CFD%i",ic+1),"CFD",cbx,clx,cmx);
130 hCFD1minCFD[ic] = new TH1F(Form("CFD1-CFD%i",ic+1),"CFD-CFD",ccbx,cclx,ccmx);
131 hCFD[ic] = new TH1F(Form("CFD%i",ic+1),"CFD",cbx,clx,cmx);
135 // Allocation of histograms - end
138 /* main loop (infinite) */
140 struct eventHeaderStruct *event;
141 eventTypeType eventT;
143 /* check shutdown condition */
144 if (daqDA_checkShutdown()) {break;}
146 /* get next event (blocking call until timeout) */
147 status=monitorGetEventDynamic((void **)&event);
148 if (status==(int)MON_ERR_EOF) {
149 printf ("End of File detected\n");
150 break; /* end of monitoring file has been reached */
154 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
158 /* retry if got no event */
165 /* use event - here, just write event id to result file */
166 eventT=event->eventType;
168 switch (event->eventType){
177 // case CALIBRATION_EVENT:
181 printf("First event - %i\n",iev);
184 // Initalize raw-data reading and decoding
185 AliRawReader *reader = new AliRawReaderDate((void*)event);
187 // Enable the following two lines in case of real-data
188 reader->RequireHeader(kTRUE);
189 AliT0RawReader *start = new AliT0RawReader(reader, kTRUE);
192 Int_t allData[105][5];
193 for(Int_t i0=0;i0<105;i0++)
194 for(Int_t j0=0;j0<5;j0++)
198 for (Int_t i=0; i<105; i++) {
199 for(Int_t iHit=0;iHit<5;iHit++){
200 allData[i][iHit]= start->GetData(i,iHit);
204 printf("No T0 data found!!\n");
206 // Fill the histograms
208 for (Int_t ik = 0; ik<24; ik++)
209 for (Int_t iHt=0; iHt<5; iHt++){
210 if(allData[ik+1][iHt]!=0 ){
212 hCFD1minCFD[ik]->Fill(allData[ik+1][iHt]-allData[1][iHt]);
213 hCFD[ik]->Fill(allData[ik+13][iHt]);
216 hCFD1minCFD[ik]->Fill(allData[ik+45][iHt]-allData[57][iHt]);
217 hCFD[ik]->Fill(allData[ik+45][iHt]);
225 // End of fill histograms
232 /* exit when last event received, no need to wait for TERM signal */
233 if (eventT==END_OF_RUN) {
234 printf("EOR event detected\n");
235 printf("Number of events processed - %i\n ",iev);
239 printf("After loop, before writing histos\n");
240 // write a file with the histograms
241 TFile *hist = new TFile(FILE_OUT,"RECREATE");
243 for(Int_t j=0;j<24;j++){
244 hCFD1minCFD[j]->Write();
252 /* export file to FXS */
253 if (daqDA_FES_storeFile(FILE_OUT, "PHYSICS")) {