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>
29 #include <AliT0CalibAmp.h>
33 #include "TPluginManager.h"
38 #include "TBenchmark.h"
45 #include "TSpectrum.h"
46 #include "TVirtualFitter.h"
57 1- monitoring data source
59 int main(int argc, char **argv) {
63 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
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 ;}
77 // decode the input line
79 printf("Wrong number of arguments\n");
85 if(daqDA_DB_getFile(FILE_IN, FILE_IN)){
86 printf("Couldn't get input file >>inLaser.dat<< from DAQ_DB !!!\n");
90 ifstream filein(FILE_IN,ios::in);
94 cout<<" "<<mipsin[k]<<endl;
104 printf("Wrong number of arguments\n");
109 // Char_t inputFile[256]="";
112 /* define data source : this is argument 1 */
113 status=monitorSetDataSource( argv[1] );
115 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
120 /* declare monitoring program */
121 status=monitorDeclareMp( __FILE__ );
123 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
128 /* define wait event timeout - 1s max */
130 monitorSetNoWaitNetworkTimeout(1000);
133 /* log start of process */
134 printf("T0 monitoring program started\n");
136 // Allocation of histograms - start
138 TH1F *hQTC[24]; TH1F *hLED[24]; TH1F *hCFD[24];
139 printf(" CFD low limit %f high %f",lcfd, hcfd);
141 for(Int_t ic=0; ic<24; ic++)
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);
148 // Allocation of histograms - end
150 // Reading current iteration
154 /* main loop (infinite) */
156 struct eventHeaderStruct *event;
157 eventTypeType eventT;
159 /* check shutdown condition */
160 if (daqDA_checkShutdown()) {break;}
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 */
170 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
174 /* retry if got no event */
179 /* use event - here, just write event id to result file */
180 eventT=event->eventType;
182 switch (event->eventType){
190 case CALIBRATION_EVENT:
191 // case PHYSICS_EVENT:
194 if(iev==1) printf("First event %i\n",iev);
197 // Initalize raw-data reading and decoding
198 AliRawReader *reader = new AliRawReaderDate((void*)event);
200 // Enable the following two lines in case of real-data
201 reader->RequireHeader(kTRUE);
202 AliT0RawReader *start = new AliT0RawReader(reader, kTRUE);
205 Int_t allData[106][5];
206 for(Int_t i0=0;i0<106;i0++)
207 for(Int_t j0=0;j0<5;j0++)
211 for (Int_t i=0; i<106; i++) {
212 for(Int_t iHit=0;iHit<5;iHit++){
213 allData[i][iHit]= start->GetData(i,iHit);
218 printf("No data for T0 found!!!\n");
221 // Fill the histograms
223 for (Int_t ik = 0; ik<24; 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]);
237 for (Int_t ik = 24; ik<48; 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]);
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]);
254 // End of fill histograms
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");
264 printf("Number of events processed - %i\n ",iev);
269 printf("After loop, before writing histos\n");
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]);
272 // write a file with the histograms
275 hist = new TFile(FILE_OUT,"RECREATE");
277 hist = new TFile(FILE_OUT,"UPDATE");
280 for(Int_t j=0;j<24;j++)
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();
293 /* export file to FXS */
294 if (daqDA_FES_storeFile(FILE_OUT, "AMPLITUDE_CALIBRATION")) {