]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HMPID/HMPIDda.cxx
First version of the HMPID online calibration algorithm. It performs the pedestal...
[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   /* check that we got some arguments = list of files */
38   if (argc<2) {
39     printf("Wrong number of arguments\n");
40     return -1;
41   }
42
43   /* copy locally a file from daq detector config db */
44   status=daqDA_DB_getFile("myconfig","./myconfig.txt");
45   if (status) {
46     printf("Failed to get config file : %d\n",status);
47     return -1;
48   }
49   /* and possibly use it */
50
51   /* open result file */
52   FILE *fp=NULL;
53   fp=fopen("./result.txt","a");
54   if (fp==NULL) {
55     printf("Failed to open file\n");
56     return -1;
57   }
58
59   /* report progress */
60   daqDA_progressReport(10);
61
62
63   /* init some counters */
64   //int nevents_physics=0;
65   //int nevents_total=0;
66
67     Float_t SummQ[14][48][11][25], Mean[14][48][11][25], SummQ2[14][48][11][25], Sigma[14][48][11][25];
68
69   Int_t iEvtNcal=0;
70
71   ofstream out;
72
73   for(Int_t ddl=0;ddl<=13;ddl++) for(Int_t row=1;row<=24;row++) for(Int_t dil=1;dil<=10;dil++) for(Int_t adr=0;adr<=47;adr++)
74
75     {
76       SummQ[ddl][adr][dil][row]=0; SummQ2[ddl][adr][dil][row]=0; Mean[ddl][adr][dil][row]=0; Sigma[ddl][adr][dil][row]=0;
77     }
78
79     int n;
80     for (n=1;n<argc;n++) {
81
82     status=monitorSetDataSource( argv[n] );
83     if (status!=0) {
84       printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
85       return -1;
86     }
87
88     /* report progress */
89     /* in this example, indexed on the number of files */
90     daqDA_progressReport(10+80*n/argc);
91
92   for(;;) // infinite loop 
93
94     {
95       struct eventHeaderStruct *event;
96       eventTypeType eventT;
97
98       /* get next event */
99       status=monitorGetEventDynamic((void **)&event);
100       if (status==MON_ERR_EOF) break; /* end of monitoring file has been reached */
101       if (status!=0) {
102         printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
103         return -1;
104       }
105
106       /* retry if got no event */
107       if (event==NULL) {
108         break;
109       }
110
111       /* use event - here, just write event id to result file */
112       eventT=event->eventType;
113
114       if (eventT==CALIBRATION_EVENT) {
115         
116         iEvtNcal++;
117
118         AliRawReader *pRR = new AliRawReaderDate((void*)event);
119         
120         pRR->Select("HMPID");//select only one DDL files 
121       
122         UInt_t RawDataWord=0;
123       
124         while(pRR->ReadNextInt(RawDataWord)) //raw records loop (in selected DDL files)
125           {                 
126             Int_t ddl = pRR->GetDDLID();       
127
128             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)
129             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)      
130             Int_t r = AliBitPacking::UnpackWord(RawDataWord,22,26); assert(1<=r&&r<=24);   // Row number (1..24)
131           
132             Int_t q = AliBitPacking::UnpackWord(RawDataWord, 0,11); assert(0<=q&&q<=4095); // 0000 0rrr rrdd ddaa aaaa qqqq qqqq qqqq Qdc        (0..4095)
133
134             SummQ[ddl][a][d][r]+=q;
135  
136             SummQ2[ddl][a][d][r]+=(q*q);
137           
138           }//raw records loop
139         
140         delete pRR;
141
142       }// if CALIBRATION_EVENT
143
144       /* exit when last event received, no need to wait for TERM signal */
145       if (eventT==END_OF_RUN) {
146         printf("EOR event detected\n");
147         break;    
148     
149       } // events loop   
150
151      free(event);
152  }
153  
154
155   /* close result file */
156   fclose(fp);
157
158   /* report progress */
159   daqDA_progressReport(90);
160
161   /* store the result file on FES */
162   status=daqDA_FES_storeFile("./result.txt","DAcase1_results");
163   if (status) {
164     printf("Failed to export file : %d\n",status);
165     return -1;
166   }
167
168   /* report progress */
169   daqDA_progressReport(100);
170
171   return status;
172
173       for(Int_t ddl=0;ddl<=13;ddl++){
174
175         out.open(Form("HmpidPedDdl%02i.txt",ddl));
176
177         for(Int_t row=1;row<=24;row++)
178
179           for(Int_t dil=1;dil<=10;dil++)
180
181             for(Int_t adr=0;adr<=47;adr++){
182
183               Mean[ddl][adr][dil][row] = SummQ[ddl][adr][dil][row]/iEvtNcal;
184
185               Sigma[ddl][adr][dil][row] = TMath::Sqrt(SummQ2[ddl][adr][dil][row]/iEvtNcal - (SummQ[ddl][adr][dil][row]/iEvtNcal)*(SummQ[ddl][adr][dil][row]/iEvtNcal));
186
187                 Int_t inhard=((Int_t(Mean[ddl][adr][dil][row]))<<9)+Int_t(Mean[ddl][adr][dil][row]+3*Sigma[ddl][adr][dil][row]);
188
189                 out << Form("%2i %2i %2i %5.2f %5.2f %x\n",row,dil,adr,Mean[ddl][adr][dil][row],Sigma[ddl][adr][dil][row],inhard);
190
191             }
192       }
193 }
194
195 //}
196
197
198
199