]>
Commit | Line | Data |
---|---|---|
00252d8f | 1 | /* |
2 | - Contact: - prino@to.infn.it | |
4a9f3efb | 3 | - Link: - alien:///alice/data/2009/LHC09c_SDD/000079094/raw/09000079094024.10.root |
f2c71038 | 4 | - Run Type: - PEDESTAL_RUN |
00252d8f | 5 | - DA Type: - LDC |
e5b2f7f2 | 6 | - Number of events needed: > 10 |
00252d8f | 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 | ||
31 | extern "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> | |
e5b2f7f2 | 48 | #include <TObjArray.h> |
49 | #include <TObjString.h> | |
50 | #include <TDatime.h> | |
e44f571c | 51 | |
52 | // AliRoot includes | |
53 | #include "AliRawReaderDate.h" | |
54 | #include "AliITSOnlineSDDBase.h" | |
55 | #include "AliITSOnlineSDDCMN.h" | |
56 | #include "AliITSRawStreamSDD.h" | |
a8cd2ab2 | 57 | #include "AliITSRawStreamSDDCompressed.h" |
e5b2f7f2 | 58 | |
59 | #ifdef ALI_AMORE | |
60 | #include <AmoreDA.h> | |
61 | #endif | |
62 | ||
e44f571c | 63 | /* Main routine |
64 | Arguments: list of DATE raw data files | |
65 | */ | |
66 | int main(int argc, char **argv) { | |
f510fd70 | 67 | // main - Arguments: list of DATE raw data files |
e44f571c | 68 | int status = 0; |
69 | ||
00252d8f | 70 | // line added to solve IO problems |
71 | gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo", | |
72 | "*", | |
73 | "TStreamerInfo", | |
74 | "RIO", | |
75 | "TStreamerInfo()"); | |
e44f571c | 76 | |
77 | /* log start of process */ | |
979b5a5f | 78 | printf("ITS SDD BASELINE+NOISE algorithm program started\n"); |
e44f571c | 79 | |
80 | ||
81 | /* check that we got some arguments = list of files */ | |
82 | if (argc<2) { | |
83 | printf("Wrong number of arguments\n"); | |
84 | return -1; | |
85 | } | |
86 | ||
87 | ||
5065707f | 88 | Int_t maxNEvents=10; // maximum number of events to be analyzed |
979b5a5f | 89 | const Int_t kTotDDL=24; |
90 | const Int_t kModPerDDL=12; | |
91 | const Int_t kSides=2; | |
040d0012 | 92 | UInt_t amSamplFreq=40; |
93 | ||
5065707f | 94 | gSystem->Exec("rm -f SDDbase_*.data"); |
456ec396 | 95 | gSystem->Exec("rm -f SDDbase_step2_LDC.tar"); |
42e868a7 | 96 | |
979b5a5f | 97 | AliITSOnlineSDDBase **base=new AliITSOnlineSDDBase*[kTotDDL*kModPerDDL*kSides]; |
98 | AliITSOnlineSDDCMN **corr=new AliITSOnlineSDDCMN*[kTotDDL*kModPerDDL*kSides]; | |
99 | TH2F **histo=new TH2F*[kTotDDL*kModPerDDL*kSides]; | |
456ec396 | 100 | Bool_t isFilled[kTotDDL*kModPerDDL*kSides]; |
040d0012 | 101 | Bool_t writtenoutput=kFALSE; |
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); | |
109 | sprintf(hisnam,"h%02dc%02ds%d",iddl,imod,isid); | |
110 | histo[index]=new TH2F(hisnam,"",256,-0.5,255.5,256,-0.5,255.5); | |
456ec396 | 111 | isFilled[index]=0; |
979b5a5f | 112 | } |
e44f571c | 113 | } |
114 | } | |
115 | ||
116 | /* report progress */ | |
3083967f | 117 | daqDA_progressReport(8); |
f2201323 | 118 | |
e44f571c | 119 | Int_t iev; |
5065707f | 120 | Int_t ievPed; |
f2201323 | 121 | Int_t ievUsed; |
122 | Int_t nEvToBeSkipped=5; | |
123 | ||
e44f571c | 124 | for(Int_t iStep=0;iStep<2;iStep++){ |
e44f571c | 125 | printf("Start Analysis Step %d\n",iStep); |
126 | iev=0; | |
5065707f | 127 | ievPed=0; |
f2201323 | 128 | ievUsed=0; |
e44f571c | 129 | if(iStep==1){ |
979b5a5f | 130 | for(Int_t iddl=0; iddl<kTotDDL;iddl++){ |
131 | for(Int_t imod=0; imod<kModPerDDL;imod++){ | |
132 | for(Int_t isid=0;isid<kSides;isid++){ | |
133 | Int_t index=kSides*(kModPerDDL*iddl+imod)+isid; | |
134 | corr[index]=new AliITSOnlineSDDCMN(iddl,imod,isid); | |
456ec396 | 135 | isFilled[index]=0; |
979b5a5f | 136 | } |
e44f571c | 137 | } |
138 | } | |
139 | } | |
140 | ||
141 | /* read the data files */ | |
142 | int n; | |
143 | for (n=1;n<argc;n++) { | |
144 | ||
145 | status=monitorSetDataSource( argv[n] ); | |
146 | if (status!=0) { | |
147 | printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status)); | |
148 | return -1; | |
149 | } | |
150 | ||
151 | /* report progress */ | |
152 | /* in this example, indexed on the number of files */ | |
153 | // Progress report inside the event loop as well? | |
3083967f | 154 | daqDA_progressReport(10+40*iStep*n/argc); |
e44f571c | 155 | |
156 | /* read the file */ | |
157 | for(;;) { | |
158 | struct eventHeaderStruct *event; | |
159 | eventTypeType eventT; | |
160 | ||
161 | /* get next event */ | |
162 | status=monitorGetEventDynamic((void **)&event); | |
163 | if (status==MON_ERR_EOF) break; /* end of monitoring file has been reached */ | |
164 | if (status!=0) { | |
165 | printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status)); | |
166 | return -1; | |
167 | } | |
168 | ||
169 | /* retry if got no event */ | |
170 | if (event==NULL) { | |
171 | break; | |
172 | } | |
173 | ||
174 | iev++; | |
e44f571c | 175 | |
176 | /* use event - here, just write event id to result file */ | |
177 | eventT=event->eventType; | |
178 | switch (event->eventType){ | |
179 | ||
180 | /* START OF RUN */ | |
181 | case START_OF_RUN: | |
182 | break; | |
183 | ||
184 | /* END OF RUN */ | |
185 | case END_OF_RUN: | |
186 | break; | |
187 | ||
3083967f | 188 | // case PHYSICS_EVENT: // comment this line for test raw data |
189 | // break; // comment this line for test raw data | |
190 | ||
e44f571c | 191 | |
192 | case CALIBRATION_EVENT: | |
3083967f | 193 | break; // uncomment this line for test raw data |
194 | case PHYSICS_EVENT: // uncomment this line for test raw data | |
f2201323 | 195 | printf(" Event number = %i ",iev); |
196 | ievPed++; | |
197 | if(ievPed<=nEvToBeSkipped){ | |
198 | printf(" -> SKIP\n"); | |
199 | break; | |
200 | } | |
201 | printf(" -> Analyze\n"); | |
202 | ievUsed++; | |
e44f571c | 203 | AliRawReader *rawReader = new AliRawReaderDate((void*)event); |
040d0012 | 204 | rawReader->Reset(); |
205 | UChar_t cdhAttr=AliITSRawStreamSDD::ReadBlockAttributes(rawReader); | |
206 | amSamplFreq=AliITSRawStreamSDD::ReadAMSamplFreqFromCDH(cdhAttr); | |
207 | AliITSRawStream* s=AliITSRawStreamSDD::CreateRawStreamSDD(rawReader,cdhAttr); | |
208 | if(!writtenoutput){ | |
209 | printf("Use %s raw stream, sampling frequency %d MHz\n",s->ClassName(),amSamplFreq); | |
210 | writtenoutput=kTRUE; | |
e44f571c | 211 | } |
212 | ||
040d0012 | 213 | |
979b5a5f | 214 | for(Int_t iddl=0; iddl<kTotDDL;iddl++){ |
215 | for(Int_t imod=0; imod<kModPerDDL;imod++){ | |
216 | for(Int_t isid=0;isid<kSides;isid++){ | |
217 | Int_t index=kSides*(kModPerDDL*iddl+imod)+isid; | |
218 | histo[index]->Reset(); | |
219 | } | |
e44f571c | 220 | } |
221 | } | |
e44f571c | 222 | |
a8cd2ab2 | 223 | while(s->Next()){ |
979b5a5f | 224 | Int_t iDDL=rawReader->GetDDLID(); |
a8cd2ab2 | 225 | Int_t iCarlos=s->GetCarlosId(); |
226 | if(s->IsCompletedModule()) continue; | |
227 | if(s->IsCompletedDDL()) continue; | |
de075dae | 228 | if(iDDL>=0 && iDDL<kTotDDL){ |
a8cd2ab2 | 229 | Int_t index=kSides*(kModPerDDL*iDDL+iCarlos)+s->GetChannel(); |
230 | histo[index]->Fill(s->GetCoord2(),s->GetCoord1(),s->GetSignal()); | |
456ec396 | 231 | isFilled[index]=1; |
e44f571c | 232 | } |
233 | } | |
a8cd2ab2 | 234 | delete s; |
e44f571c | 235 | delete rawReader; |
979b5a5f | 236 | for(Int_t iddl=0; iddl<kTotDDL;iddl++){ |
237 | for(Int_t imod=0; imod<kModPerDDL;imod++){ | |
238 | for(Int_t isid=0;isid<kSides;isid++){ | |
239 | Int_t index=kSides*(kModPerDDL*iddl+imod)+isid; | |
040d0012 | 240 | if(iStep==0){ |
241 | if(amSamplFreq==20) base[index]->SetLastGoodTB(126); | |
242 | else base[index]->SetLastGoodTB(254); | |
243 | base[index]->AddEvent(histo[index]); | |
244 | } | |
245 | if(iStep==1){ | |
246 | if(amSamplFreq==20) corr[index]->SetLastGoodTB(126); | |
247 | else corr[index]->SetLastGoodTB(254); | |
248 | corr[index]->AddEvent(histo[index]); | |
249 | } | |
979b5a5f | 250 | } |
e44f571c | 251 | } |
252 | } | |
253 | ||
254 | /* free resources */ | |
255 | free(event); | |
256 | } | |
f2201323 | 257 | if(ievUsed>=maxNEvents) break; |
e44f571c | 258 | } |
e44f571c | 259 | } |
979b5a5f | 260 | |
261 | if(iStep==0){ | |
262 | for(Int_t iddl=0; iddl<kTotDDL;iddl++){ | |
263 | for(Int_t imod=0; imod<kModPerDDL;imod++){ | |
264 | for(Int_t isid=0;isid<kSides;isid++){ | |
265 | Int_t index=kSides*(kModPerDDL*iddl+imod)+isid; | |
266 | base[index]->ValidateAnodes(); | |
267 | base[index]->WriteToASCII(); | |
268 | } | |
e44f571c | 269 | } |
5065707f | 270 | } |
979b5a5f | 271 | } |
e44f571c | 272 | } |
273 | ||
274 | /* write report */ | |
e5b2f7f2 | 275 | TDatime time; |
276 | TObjString timeinfo(Form("%02d%02d%02d%02d%02d%02d",time.GetYear()-2000,time.GetMonth(),time.GetDay(),time.GetHour(),time.GetMinute(),time.GetSecond())); | |
f2201323 | 277 | printf("Run #%s, received %d calibration events, time %s\n",getenv("DATE_RUN_NUMBER"),ievUsed,timeinfo.GetString().Data()); |
e44f571c | 278 | |
279 | /* report progress */ | |
280 | daqDA_progressReport(90); | |
281 | ||
e5b2f7f2 | 282 | TObjArray* basHistos=new TObjArray(); |
283 | TObjArray* noiseHistos=new TObjArray(); | |
284 | TObjArray* cmnHistos=new TObjArray(); | |
285 | TObjArray* corrnHistos=new TObjArray(); | |
286 | TObjArray* statusHistos=new TObjArray(); | |
e44f571c | 287 | |
288 | ||
456ec396 | 289 | Char_t filnam[100],command[150]; |
979b5a5f | 290 | for(Int_t iddl=0; iddl<kTotDDL;iddl++){ |
291 | for(Int_t imod=0; imod<kModPerDDL;imod++){ | |
292 | for(Int_t isid=0;isid<kSides;isid++){ | |
293 | Int_t index=kSides*(kModPerDDL*iddl+imod)+isid; | |
294 | corr[index]->ValidateAnodes(); | |
295 | corr[index]->WriteToASCII(); | |
456ec396 | 296 | if(isFilled[index]){ |
e5b2f7f2 | 297 | basHistos->AddLast(corr[index]->GetBaselineAnodeHisto()); |
298 | noiseHistos->AddLast(corr[index]->GetRawNoiseAnodeHisto()); | |
299 | cmnHistos->AddLast(corr[index]->GetCMNCoefAnodeHisto()); | |
300 | corrnHistos->AddLast(corr[index]->GetCorrNoiseAnodeHisto()); | |
301 | statusHistos->AddLast(corr[index]->GetStatusAnodeHisto()); | |
456ec396 | 302 | sprintf(filnam,"SDDbase_step2_ddl%02dc%02d_sid%d.data",iddl,imod,isid); |
303 | sprintf(command,"tar -rf SDDbase_step2_LDC.tar %s",filnam); | |
304 | gSystem->Exec(command); | |
305 | } | |
979b5a5f | 306 | } |
e44f571c | 307 | } |
308 | } | |
e44f571c | 309 | |
e5b2f7f2 | 310 | #ifdef ALI_AMORE |
311 | amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender); | |
9ce3c336 | 312 | Int_t statusamore =0; |
7f601ef8 | 313 | statusamore += amoreDA.Send("TimeInfoPedestal",&timeinfo); |
9ce3c336 | 314 | statusamore += amoreDA.Send("Baselines",basHistos); |
315 | statusamore += amoreDA.Send("RawNoise",noiseHistos); | |
316 | statusamore += amoreDA.Send("CommonMode",cmnHistos); | |
317 | statusamore += amoreDA.Send("CorrectedNoise",corrnHistos); | |
318 | statusamore += amoreDA.Send("NoisyChannels",statusHistos); | |
319 | if ( statusamore ) | |
e5b2f7f2 | 320 | printf("Warning: Failed to write Arrays in the AMORE database\n"); |
321 | else | |
322 | printf("amoreDA.Send() OK\n"); | |
323 | #else | |
324 | printf("Warning: SDDBAS DA not compiled with AMORE support\n"); | |
325 | #endif | |
326 | ||
327 | ||
328 | TFile *fh=new TFile("SDDbaseHistos.root","RECREATE"); | |
329 | basHistos->Write(); | |
330 | noiseHistos->Write(); | |
331 | cmnHistos->Write(); | |
332 | corrnHistos->Write(); | |
333 | statusHistos->Write(); | |
334 | fh->Close(); | |
e44f571c | 335 | |
e44f571c | 336 | /* report progress */ |
337 | daqDA_progressReport(100); | |
338 | ||
339 | ||
340 | ||
341 | return status; | |
342 | } |