2 T0 DA for online calibration
3 Contact: AllaMaevskaya@cern.ch
6 Number of events needed: 10000
7 Input Files: inPhys.dat, external parameters, T0/Calib/Slewing_Walk
8 Output Files: daPhys.root, to be exported to the DAQ FXS
9 Trigger types used: PHYSICS_EVENT
10 ------------------------------Alla
11 Now trigger type changed to CALICRATION_EVENT
12 to have data during test.
13 SOULD BE CHANGED BACK BEFORE BEAM
14 ------------------------------- Alla
17 #define FILE_OUT "daPhys.root"
18 #define FILE_IN "inPhys.dat"
23 #include <Riostream.h>
28 #include <AliRawReaderDate.h>
29 #include <AliRawReader.h>
30 #include <AliT0RawReader.h>
31 #include <AliT0CalibWalk.h>
32 #include <AliCDBManager.h>
33 #include <AliCDBEntry.h>
36 #include "TPluginManager.h"
40 #include "TBenchmark.h"
48 1- monitoring data source
50 int main(int argc, char **argv) {
55 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
61 if(daqDA_DB_getFile(FILE_IN, FILE_IN)){
62 printf("Couldn't get input file >>inPhys.dat<< from DAQ_DB !!!\n");
69 inp = fopen(FILE_IN, "r");
71 printf("Input file >>inPhys.dat<< not found !!!\n");
74 int kcbx, kt0bx, knpmtA, knpmtC;
75 float kclx,kcmx, kt0lx, kt0hx;
77 while((c=getc(inp))!=EOF) {
79 case 'a': {fscanf(inp, "%d", &kcbx ); break;} //N of X bins hCFD1_CFD
80 case 'b': {fscanf(inp, "%f", &kclx ); break;} //Low x hCFD1_CFD
81 case 'c': {fscanf(inp, "%f", &kcmx ); break;} //High x hCFD1_CF
82 case 'd': {fscanf(inp, "%d", &knpmtC ); break;} //number of reference PMTC
83 case 'e': {fscanf(inp, "%d", &knpmtA ); break;} //number of reference PMTA
84 case 'f': {fscanf(inp, "%d", &kt0bx ); break;} //N of X bins hT0
85 case 'g': {fscanf(inp, "%f", &kt0lx ); break;} //Low x hT0
86 case 'k': {fscanf(inp, "%f", &kt0hx ); break;} //High x hT0
92 printf("Wrong number of arguments\n");
97 /* define data source : this is argument 1 */
98 status=monitorSetDataSource( argv[1] );
100 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
105 /* declare monitoring program */
106 status=monitorDeclareMp( __FILE__ );
108 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
113 /* define wait event timeout - 1s max */
115 monitorSetNoWaitNetworkTimeout(1000);
118 /* log start of process */
119 printf("T0 monitoring program started\n");
122 if (getenv("DATE_RUN_NUMBER")==0) {
123 printf("DATE_RUN_NUMBER not properly set.\n");
126 int runNr = atoi(getenv("DATE_RUN_NUMBER"));
128 // Get the necessary OCDB files from the DAQ detector DB
129 if (gSystem->AccessPathName("localOCDB/T0/Calib/Slewing_Walk/",kFileExists)) {
130 if (gSystem->mkdir("localOCDB/T0/Calib/Slewing_Walk/",kTRUE) != 0) {
131 printf("Failed to create directory: localOCDB/T0/Calib/Slewing_Walk/");
136 status = daqDA_DB_getFile("T0/Calib/Slewing_Walk","localOCDB/T0/Calib/Slewing_Walk/Run0_999999999_v0_s0.root");
138 printf("Failed to get geometry file (GRP/Geometry/Data) from DAQdetDB, status=%d\n", status);
141 TGraph *gr[24]; TGraph *gramp[24];
142 AliCDBManager *man = AliCDBManager::Instance();
143 man->SetDefaultStorage("local://localOCDB");
145 AliCDBEntry *entry = AliCDBManager::Instance()->Get("T0/Calib/Slewing_Walk");
147 AliT0CalibWalk *fParam = (AliT0CalibWalk*)entry->GetObject();
148 for (Int_t i=0; i<24; i++) {
149 gr[i] = fParam->GetWalk(i);
150 gramp[i] = fParam->GetQTC(i);
153 Int_t chargeQT0[24], chargeQT1[24];
154 Float_t adc ,walk, amp;
156 // Allocation of histograms - start
158 TH1F *hCFD1minCFD[24];
161 for(Int_t ic=0; ic<24; ic++) {
162 hCFD1minCFD[ic] = new TH1F(Form("CFD1minCFD%d",ic+1),"CFD-CFD",kcbx,kclx,kcmx);
163 hCFD[ic] = new TH1F(Form("CFD%d",ic+1),"CFD",kt0bx,kt0lx,kt0hx);
165 TH1F *hVertex = new TH1F("hVertex","T0 time",kt0bx,kt0lx,kt0hx);
167 // Allocation of histograms - end
171 /* main loop (infinite) */
173 struct eventHeaderStruct *event;
174 eventTypeType eventT;
176 /* check shutdown condition */
177 if (daqDA_checkShutdown()) {break;}
179 /* get next event (blocking call until timeout) */
180 status=monitorGetEventDynamic((void **)&event);
181 if (status==(int)MON_ERR_EOF) {
182 printf ("End of File detected\n");
183 break; /* end of monitoring file has been reached */
187 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
191 /* retry if got no event */
196 /* use event - here, just write event id to result file */
197 eventT=event->eventType;
199 switch (event->eventType){
208 // case CALIBRATION_EVENT:
212 printf("First event - %i\n",iev);
215 // Initalize raw-data reading and decoding
216 AliRawReader *reader = new AliRawReaderDate((void*)event);
218 // Enable the following two lines in case of real-data
219 reader->RequireHeader(kTRUE);
220 AliT0RawReader *start = new AliT0RawReader(reader, kTRUE);
223 Int_t allData[110][5];
224 for(Int_t i0=0;i0<107;i0++)
225 for(Int_t j0=0;j0<5;j0++)
229 for (Int_t i=0; i<107; i++) {
230 for(Int_t iHit=0;iHit<5;iHit++){
231 allData[i][iHit]= start->GetData(i,iHit);
236 // Fill the histograms
237 walk = adc = amp = -999;
238 for (Int_t in=0; in<12; in++)
240 chargeQT0[in]=allData[2*in+25][0];
241 chargeQT1[in]=allData[2*in+26][0];
243 for (Int_t in=12; in<24; in++)
245 chargeQT0[in]=allData[2*in+57][0];
246 chargeQT1[in]=allData[2*in+58][0];
248 Float_t besttimeA=9999999;
249 Float_t besttimeC=9999999;
251 Float_t meanShift[24];
252 for (Int_t ik = 0; ik<24; ik++)
254 if( ( chargeQT0[ik] - chargeQT1[ik])>0) {
255 adc = chargeQT0[ik] - chargeQT1[ik];
256 // cout<<ik <<" "<<adc<<endl;
259 amp = gramp[ik]->Eval(Double_t(adc));
260 if(amp < 0.8) continue;
262 walk = Int_t(gr[ik]->Eval(Double_t(adc) ) );
264 if(ik<12 && allData[ik+1][0]>0 && allData[knpmtC][0]>0 ){
265 hCFD1minCFD[ik]->Fill(allData[ik+1][0]-allData[knpmtC][0]);
266 if( walk >-100) hCFD[ik]->Fill(allData[ik+1][0] - walk);
267 // cout<<ik<<" "<<allData[ik+1][0]<<" adc "<<adc<<" walk "<<walk<<endl;
270 if(ik>11 && allData[ik+45][0]>0 && allData[56+knpmtA][0]>0 )
272 hCFD1minCFD[ik]->Fill(allData[ik+45][0]-allData[56+knpmtA][0]);
273 if( walk >-100) hCFD[ik]->Fill(allData[ik+45][0] - walk);
274 // cout<<ik<<" "<<allData[ik+1][0]<<" adc "<<adc<<" walk "<<walk<<endl;
277 meanShift[ik] = hCFD1minCFD[ik]->GetMean();
278 if(ik==knpmtC || ik==(56+knpmtA)) meanShift[ik]=0;
281 //fill mean time _ fast reconstruction
284 for (Int_t in=0; in<12; in++)
286 time[in] = allData[in+1][0] - meanShift[in] ;
287 time[in+12] = allData[in+56+1][0] ;
289 for (Int_t ipmt=0; ipmt<12; ipmt++){
290 if(time[ipmt] > 1 ) {
291 if(time[ipmt]<besttimeC)
292 besttimeC=time[ipmt]; //timeC
295 for ( Int_t ipmt=12; ipmt<24; ipmt++){
297 if(time[ipmt]<besttimeA)
298 besttimeA=time[ipmt]; //timeA
301 if(besttimeA<9999999 &&besttimeC< 9999999) {
302 Float_t t0 =0.001* 24.4 * Float_t( besttimeA+besttimeC)/2.;
311 // End of fill histograms
318 /* exit when last event received, no need to wait for TERM signal */
319 if (eventT==END_OF_RUN) {
320 printf("EOR event detected\n");
321 printf("Number of events processed - %i\n ",iev);
325 printf("After loop, before writing histos\n");
326 // write a file with the histograms
328 TFile hist(FILE_OUT,"RECREATE");
330 for(Int_t j=0;j<24;j++){
331 hCFD1minCFD[j]->SetDirectory(&hist);
332 hCFD1minCFD[j]->Write();
342 /* export file to FXS */
343 if (daqDA_FES_storeFile(FILE_OUT, "PHYSICS")) {