]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/ITSSDDBASda.cxx
Fix warnings
[u/mrichter/AliRoot.git] / ITS / ITSSDDBASda.cxx
CommitLineData
00252d8f 1/*
2- Contact: - prino@to.infn.it
f2c71038 3- Link: - http://www.to.infn.it/~prino/alice/RawData/run11161.date
4- Run Type: - PEDESTAL_RUN
00252d8f 5- DA Type: - LDC
6- Number of events needed: 100
7- Input Files: -
979b5a5f 8- Output Files: - SDDbase_step1_ddl*c*_sid*.data SDDbase_step2_ddl*c*_sid*.data
00252d8f 9- Trigger types used:
10*/
11
12
e44f571c 13//////////////////////////////////////////////////////////////////////////////
14// Detector Algorithm for analysis of SDD baseline runs. //
15// //
16// Produces ASCII and ROOT output files with: //
17// 1. anode quality bit //
18// 1. Baseline values //
19// 2. Raw noise //
20// 3. Common mode coefficients //
21// 4. Noise corrected for common mode //
22// Files are stored locally. //
23// The next DAQ-DA step on Test Pulse run writes files to FXS //
24// //
25// Author: F. Prino (prino@to.infn.it) //
26// //
27//////////////////////////////////////////////////////////////////////////////
28
29
30
31extern "C" {
32#include "daqDA.h"
33}
34
35#include "event.h"
36#include "monitor.h"
37
38#include <stdio.h>
39#include <stdlib.h>
40
41// ROOT includes
42#include <TFile.h>
42e868a7 43#include <TSystem.h>
e44f571c 44#include <TH1F.h>
45#include <TH2F.h>
00252d8f 46#include <TROOT.h>
47#include <TPluginManager.h>
e44f571c 48
49// AliRoot includes
50#include "AliRawReaderDate.h"
51#include "AliITSOnlineSDDBase.h"
52#include "AliITSOnlineSDDCMN.h"
53#include "AliITSRawStreamSDD.h"
54/* Main routine
55 Arguments: list of DATE raw data files
56*/
57int main(int argc, char **argv) {
58
59 int status = 0;
60
00252d8f 61 // line added to solve IO problems
62 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
63 "*",
64 "TStreamerInfo",
65 "RIO",
66 "TStreamerInfo()");
e44f571c 67
68 /* log start of process */
979b5a5f 69 printf("ITS SDD BASELINE+NOISE algorithm program started\n");
e44f571c 70
71
72 /* check that we got some arguments = list of files */
73 if (argc<2) {
74 printf("Wrong number of arguments\n");
75 return -1;
76 }
77
78
5065707f 79 Int_t maxNEvents=10; // maximum number of events to be analyzed
979b5a5f 80 const Int_t kTotDDL=24;
81 const Int_t kModPerDDL=12;
82 const Int_t kSides=2;
42e868a7 83 Int_t adcSamplFreq=40;
5065707f 84 Bool_t readfeeconf=kFALSE;
85 gSystem->Exec("rm -f SDDbase_*.data");
42e868a7 86 if(gSystem->Getenv("DAQ_DETDB_LOCAL")!=NULL){
87 const char* dir=gSystem->Getenv("DAQ_DETDB_LOCAL");
88 TString filnam=Form("%s/fee.conf",dir);
89 FILE* feefil=fopen(filnam.Data(),"r");
5065707f 90 if(feefil){
91 fscanf(feefil,"%d \n",&adcSamplFreq);
92 fclose(feefil);
93 readfeeconf=kTRUE;
94 printf("ADC sampling frequency = %d MHz\n",adcSamplFreq);
95 }
42e868a7 96 }
5065707f 97 if(!readfeeconf) printf("File fee.conf not found, sampling frequency set to 40 MHz\n");
42e868a7 98
979b5a5f 99 AliITSOnlineSDDBase **base=new AliITSOnlineSDDBase*[kTotDDL*kModPerDDL*kSides];
100 AliITSOnlineSDDCMN **corr=new AliITSOnlineSDDCMN*[kTotDDL*kModPerDDL*kSides];
101 TH2F **histo=new TH2F*[kTotDDL*kModPerDDL*kSides];
e44f571c 102
103 Char_t hisnam[20];
979b5a5f 104 for(Int_t iddl=0; iddl<kTotDDL;iddl++){
105 for(Int_t imod=0; imod<kModPerDDL;imod++){
106 for(Int_t isid=0;isid<kSides;isid++){
107 Int_t index=kSides*(kModPerDDL*iddl+imod)+isid;
108 base[index]=new AliITSOnlineSDDBase(iddl,imod,isid);
42e868a7 109 if(adcSamplFreq==20) base[index]->SetLastGoodTB(126);
110 else base[index]->SetLastGoodTB(254);
979b5a5f 111 sprintf(hisnam,"h%02dc%02ds%d",iddl,imod,isid);
112 histo[index]=new TH2F(hisnam,"",256,-0.5,255.5,256,-0.5,255.5);
113 }
e44f571c 114 }
115 }
116
117 /* report progress */
3083967f 118 daqDA_progressReport(8);
e44f571c 119 Int_t iev;
5065707f 120 Int_t ievPed;
e44f571c 121 for(Int_t iStep=0;iStep<2;iStep++){
e44f571c 122 printf("Start Analysis Step %d\n",iStep);
123 iev=0;
5065707f 124 ievPed=0;
e44f571c 125 if(iStep==1){
979b5a5f 126 for(Int_t iddl=0; iddl<kTotDDL;iddl++){
127 for(Int_t imod=0; imod<kModPerDDL;imod++){
128 for(Int_t isid=0;isid<kSides;isid++){
129 Int_t index=kSides*(kModPerDDL*iddl+imod)+isid;
130 corr[index]=new AliITSOnlineSDDCMN(iddl,imod,isid);
42e868a7 131 if(adcSamplFreq==20) corr[index]->SetLastGoodTB(126);
132 else corr[index]->SetLastGoodTB(254);
979b5a5f 133 }
e44f571c 134 }
135 }
136 }
137
138 /* read the data files */
139 int n;
140 for (n=1;n<argc;n++) {
141
142 status=monitorSetDataSource( argv[n] );
143 if (status!=0) {
144 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
145 return -1;
146 }
147
148 /* report progress */
149 /* in this example, indexed on the number of files */
150 // Progress report inside the event loop as well?
3083967f 151 daqDA_progressReport(10+40*iStep*n/argc);
e44f571c 152
153 /* read the file */
154 for(;;) {
155 struct eventHeaderStruct *event;
156 eventTypeType eventT;
157
158 /* get next event */
159 status=monitorGetEventDynamic((void **)&event);
160 if (status==MON_ERR_EOF) break; /* end of monitoring file has been reached */
161 if (status!=0) {
162 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
163 return -1;
164 }
165
166 /* retry if got no event */
167 if (event==NULL) {
168 break;
169 }
170
171 iev++;
e44f571c 172
173 /* use event - here, just write event id to result file */
174 eventT=event->eventType;
175 switch (event->eventType){
176
177 /* START OF RUN */
178 case START_OF_RUN:
179 break;
180
181 /* END OF RUN */
182 case END_OF_RUN:
183 break;
184
3083967f 185 // case PHYSICS_EVENT: // comment this line for test raw data
186 // break; // comment this line for test raw data
187
e44f571c 188
189 case CALIBRATION_EVENT:
3083967f 190 break; // uncomment this line for test raw data
191 case PHYSICS_EVENT: // uncomment this line for test raw data
e44f571c 192 printf(" event number = %i \n",iev);
5065707f 193 ievPed++;
e44f571c 194 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
e44f571c 195
e44f571c 196
197 Int_t evtyp=0;
198 while(rawReader->ReadHeader()){
199 const UInt_t *subev = rawReader->GetSubEventAttributes();
200 if(subev[0]==0 && subev[1]==0 && subev[2]==0) evtyp=1;
201 }
202
203 rawReader->Reset();
979b5a5f 204 for(Int_t iddl=0; iddl<kTotDDL;iddl++){
205 for(Int_t imod=0; imod<kModPerDDL;imod++){
206 for(Int_t isid=0;isid<kSides;isid++){
207 Int_t index=kSides*(kModPerDDL*iddl+imod)+isid;
208 histo[index]->Reset();
209 }
e44f571c 210 }
211 }
212 AliITSRawStreamSDD s(rawReader);
e44f571c 213
214 while(s.Next()){
979b5a5f 215 Int_t iDDL=rawReader->GetDDLID();
216 Int_t iCarlos=s.GetCarlosId();
de075dae 217 if(s.IsCompletedModule()) continue;
218 if(s.IsCompletedDDL()) continue;
219 if(iDDL>=0 && iDDL<kTotDDL){
979b5a5f 220 Int_t index=kSides*(kModPerDDL*iDDL+iCarlos)+s.GetChannel();
e44f571c 221 histo[index]->Fill(s.GetCoord2(),s.GetCoord1(),s.GetSignal());
222 }
223 }
224 delete rawReader;
979b5a5f 225 for(Int_t iddl=0; iddl<kTotDDL;iddl++){
226 for(Int_t imod=0; imod<kModPerDDL;imod++){
227 for(Int_t isid=0;isid<kSides;isid++){
228 Int_t index=kSides*(kModPerDDL*iddl+imod)+isid;
229 if(iStep==0) base[index]->AddEvent(histo[index]);
230 if(iStep==1) corr[index]->AddEvent(histo[index]);
231 }
e44f571c 232 }
233 }
234
235 /* free resources */
236 free(event);
237 }
5065707f 238 if(ievPed>=maxNEvents) break;
e44f571c 239 }
e44f571c 240 }
979b5a5f 241
242 if(iStep==0){
243 for(Int_t iddl=0; iddl<kTotDDL;iddl++){
244 for(Int_t imod=0; imod<kModPerDDL;imod++){
245 for(Int_t isid=0;isid<kSides;isid++){
246 Int_t index=kSides*(kModPerDDL*iddl+imod)+isid;
247 base[index]->ValidateAnodes();
248 base[index]->WriteToASCII();
249 }
e44f571c 250 }
5065707f 251 }
979b5a5f 252 }
e44f571c 253 }
254
255 /* write report */
5065707f 256 printf("Run #%s, received %d calibration events\n",getenv("DATE_RUN_NUMBER"),ievPed);
e44f571c 257
258 /* report progress */
259 daqDA_progressReport(90);
260
261
262
3083967f 263 TFile *fh=new TFile("SDDbaseHistos.root","RECREATE");
979b5a5f 264 for(Int_t iddl=0; iddl<kTotDDL;iddl++){
265 for(Int_t imod=0; imod<kModPerDDL;imod++){
266 for(Int_t isid=0;isid<kSides;isid++){
267 Int_t index=kSides*(kModPerDDL*iddl+imod)+isid;
268 corr[index]->ValidateAnodes();
269 corr[index]->WriteToASCII();
270 corr[index]->WriteToROOT(fh);
271 }
e44f571c 272 }
273 }
274 fh->Close();
275
276
e44f571c 277 /* report progress */
278 daqDA_progressReport(100);
279
280
281
282 return status;
283}