]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HMPID/HMPIDda.cxx
Updated version of the HMPID DA. To be checked on real data by the experts and then...
[u/mrichter/AliRoot.git] / HMPID / HMPIDda.cxx
1 /*
2 *********************************************************
3 Author:                                                 *
4 this file provides the detector algorithm for HMPID.    *
5 *********************************************************
6 */
7 extern "C" {
8 #include <daqDA.h>
9 }
10
11 #include "event.h"
12 #include "monitor.h"
13
14 #include <Riostream.h>
15 #include <stdio.h>
16 #include <stdlib.h>
17
18 //AliRoot
19 //#include "AliHMPIDRawStream.h"
20 #include "AliRawReaderDate.h"
21 #include "AliBitPacking.h"
22 #include "TMath.h"
23
24 //ROOT
25 #include "TFile.h"
26 #include "TKey.h"
27 #include "TH2S.h"
28 #include "TObject.h"
29 #include "TBenchmark.h"
30 #include "TMath.h"
31 #include "TRandom.h"
32
33 int main(int argc, char **argv){ 
34
35   int status;
36
37   /* log start of process */
38   printf("HMPID DA program started\n");  
39
40   /* check that we got some arguments = list of files */
41   if (argc<2) {
42     printf("Wrong number of arguments\n");
43     return -1;
44   }
45
46   /* copy locally a file from daq detector config db
47   status=daqDA_DB_getFile("myconfig","./myconfig.txt");
48   if (status) {
49     printf("Failed to get config file : %d\n",status);
50     return -1;
51   }
52   and possibly use it */
53
54   /* report progress */
55   daqDA_progressReport(10);
56
57
58   /* init some counters */
59   Float_t SummQ[14][48][11][25], SummQ2[14][48][11][25];
60   Bool_t  isDDLOn[14];
61   for(Int_t ddl=0;ddl<=13;ddl++) {
62     isDDLOn[ddl] = kFALSE;
63     for(Int_t row=1;row<=24;row++)
64       for(Int_t dil=1;dil<=10;dil++)
65         for(Int_t adr=0;adr<=47;adr++)
66           {
67             SummQ[ddl][adr][dil][row]=0;
68             SummQ2[ddl][adr][dil][row]=0;
69           }
70   }
71
72   /* init event counter */
73   Int_t iEvtNcal=0;
74
75   int n;
76   for (n=1;n<argc;n++) {
77
78     status=monitorSetDataSource( argv[n] );
79     if (status!=0) {
80       printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
81       return -1;
82     }
83
84     /* report progress */
85     /* in this example, indexed on the number of files */
86     daqDA_progressReport(10+80*n/argc);
87
88     for(;;) { // infinite loop 
89       struct eventHeaderStruct *event;
90       eventTypeType eventT;
91
92       /* get next event */
93       status=monitorGetEventDynamic((void **)&event);
94       if (status==MON_ERR_EOF) break; /* end of monitoring file has been reached */
95       if (status!=0) {
96         printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
97         return -1;
98       }
99
100       /* retry if got no event */
101       if (event==NULL) {
102         break;
103       }
104
105       /* use event - here, just write event id to result file */
106       eventT=event->eventType;
107
108       if (eventT==CALIBRATION_EVENT) {
109         
110         iEvtNcal++;
111
112         AliRawReader *pRR = new AliRawReaderDate((void*)event);
113         
114         pRR->Select("HMPID");//select only one DDL files 
115       
116         UInt_t RawDataWord=0;
117       
118         while(pRR->ReadNextInt(RawDataWord)) //raw records loop (in selected DDL files)
119           {                 
120             Int_t ddl = pRR->GetDDLID();       
121
122             Int_t a = AliBitPacking::UnpackWord(RawDataWord,12,17); assert(0<=a&&a<=47);   // 1098 7654 3210 9876 5432 1098 7654 3210 DILOGIC address (0..47)
123             Int_t d = AliBitPacking::UnpackWord(RawDataWord,18,21); assert(1<=d&&d<=10);   // 3322 2222 2222 1111 1111 1000 0000 0000 DILOGIC number  (1..10)      
124             Int_t r = AliBitPacking::UnpackWord(RawDataWord,22,26); assert(1<=r&&r<=24);   // Row number (1..24)
125           
126             Int_t q = AliBitPacking::UnpackWord(RawDataWord, 0,11); assert(0<=q&&q<=4095); // 0000 0rrr rrdd ddaa aaaa qqqq qqqq qqqq Qdc        (0..4095)
127
128             SummQ[ddl][a][d][r]+=q;
129             SummQ2[ddl][a][d][r]+=(q*q);
130             isDDLOn[ddl] = kTRUE;
131           }//raw records loop
132         
133         delete pRR;
134
135       }// if CALIBRATION_EVENT
136
137       /* exit when last event received, no need to wait for TERM signal */
138       if (eventT==END_OF_RUN) {
139         printf("EOR event detected\n");
140         break;    
141     
142       } // events loop   
143
144       free(event);
145     }
146
147   }
148
149   /* write report */
150   printf("Run #%s, received %d calibration events\n",getenv("DATE_RUN_NUMBER"),iEvtNcal);
151
152   if (!iEvtNcal) {
153     printf("No calibration events have been read. Exiting\n");
154     return -1;
155   }
156
157   /* report progress */
158   daqDA_progressReport(90);
159
160   for(Int_t ddl=0; ddl < 14; ddl++) {
161     if (!isDDLOn[ddl]) continue;
162
163     ofstream out;
164     out.open(Form("./HmpidPedDdl%02i.txt",ddl));
165
166     for(Int_t row=1; row < 25; row++)
167       for(Int_t dil=1; dil < 11; dil++)
168         for(Int_t adr=0; adr < 48; adr++) {
169
170           Float_t mean = SummQ[ddl][adr][dil][row]/iEvtNcal;
171           Float_t sigma = TMath::Sqrt(SummQ2[ddl][adr][dil][row]/iEvtNcal - (SummQ[ddl][adr][dil][row]/iEvtNcal)*(SummQ[ddl][adr][dil][row]/iEvtNcal));
172           Int_t inhard=((Int_t(mean))<<9)+Int_t(mean+3*sigma);
173
174           out << Form("%2i %2i %2i %5.2f %5.2f %x\n",row,dil,adr,mean,sigma,inhard);
175         }
176
177     /* store the result file on FES */
178     status=daqDA_FES_storeFile(Form("./HmpidPedDdl%02i.txt",ddl),Form("HMPID_DA_Pedestals_ddl=%02i",ddl));
179     if (status) {
180       printf("Failed to export file : %d\n",status);
181       return -1;
182     }
183   }
184
185
186   /* report progress */
187   daqDA_progressReport(100);
188
189   return status;
190 }