2 - Contact: - prino@to.infn.it
3 - Link: - alien:///alice/data/2009/LHC09c_SDD/000079094/raw/09000079094024.10.root
4 - Run Type: - PEDESTAL_RUN
6 - Number of events needed: > 10
8 - Output Files: - SDDbase_step1_ddl*c*_sid*.data SDDbase_step2_ddl*c*_sid*.data
13 //////////////////////////////////////////////////////////////////////////////
14 // Detector Algorithm for analysis of SDD baseline runs. //
16 // Produces ASCII and ROOT output files with: //
17 // 1. anode quality bit //
18 // 1. Baseline values //
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 //
25 // Author: F. Prino (prino@to.infn.it) //
27 //////////////////////////////////////////////////////////////////////////////
47 #include <TPluginManager.h>
48 #include <TObjArray.h>
49 #include <TObjString.h>
53 #include "AliRawReaderDate.h"
54 #include "AliITSOnlineSDDBase.h"
55 #include "AliITSOnlineSDDCMN.h"
56 #include "AliITSRawStreamSDD.h"
57 #include "AliITSRawStreamSDDCompressed.h"
64 Arguments: list of DATE raw data files
66 int main(int argc, char **argv) {
67 // main - Arguments: list of DATE raw data files
70 // line added to solve IO problems
71 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
77 /* log start of process */
78 printf("ITS SDD BASELINE+NOISE algorithm program started\n");
81 /* check that we got some arguments = list of files */
83 printf("Wrong number of arguments\n");
88 Int_t maxNEvents=10; // maximum number of events to be analyzed
89 const Int_t kTotDDL=24;
90 const Int_t kModPerDDL=12;
92 UInt_t amSamplFreq=40;
94 gSystem->Exec("rm -f SDDbase_*.data");
95 gSystem->Exec("rm -f SDDbase_step2_LDC.tar");
97 AliITSOnlineSDDBase **base=new AliITSOnlineSDDBase*[kTotDDL*kModPerDDL*kSides];
98 AliITSOnlineSDDCMN **corr=new AliITSOnlineSDDCMN*[kTotDDL*kModPerDDL*kSides];
99 TH2F **histo=new TH2F*[kTotDDL*kModPerDDL*kSides];
100 Bool_t isFilled[kTotDDL*kModPerDDL*kSides];
101 Bool_t writtenoutput=kFALSE;
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);
116 /* report progress */
117 daqDA_progressReport(8);
122 Int_t nEvToBeSkipped=5;
124 for(Int_t iStep=0;iStep<2;iStep++){
125 printf("Start Analysis Step %d\n",iStep);
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);
141 /* read the data files */
143 for (n=1;n<argc;n++) {
145 status=monitorSetDataSource( argv[n] );
147 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
151 /* report progress */
152 /* in this example, indexed on the number of files */
153 // Progress report inside the event loop as well?
154 daqDA_progressReport(10+40*iStep*n/argc);
158 struct eventHeaderStruct *event;
159 eventTypeType eventT;
162 status=monitorGetEventDynamic((void **)&event);
163 if (status==MON_ERR_EOF) break; /* end of monitoring file has been reached */
165 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
169 /* retry if got no event */
176 /* use event - here, just write event id to result file */
177 eventT=event->eventType;
178 switch (event->eventType){
188 // case PHYSICS_EVENT: // comment this line for test raw data
189 // break; // comment this line for test raw data
192 case CALIBRATION_EVENT:
193 break; // uncomment this line for test raw data
194 case PHYSICS_EVENT: // uncomment this line for test raw data
195 printf(" Event number = %i ",iev);
197 if(ievPed<=nEvToBeSkipped){
198 printf(" -> SKIP\n");
201 printf(" -> Analyze\n");
203 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
205 UChar_t cdhAttr=AliITSRawStreamSDD::ReadBlockAttributes(rawReader);
206 amSamplFreq=AliITSRawStreamSDD::ReadAMSamplFreqFromCDH(cdhAttr);
207 AliITSRawStream* s=AliITSRawStreamSDD::CreateRawStreamSDD(rawReader,cdhAttr);
209 printf("Use %s raw stream, sampling frequency %d MHz\n",s->ClassName(),amSamplFreq);
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();
224 Int_t iDDL=rawReader->GetDDLID();
225 Int_t iCarlos=s->GetCarlosId();
226 if(s->IsCompletedModule()) continue;
227 if(s->IsCompletedDDL()) continue;
228 if(iDDL>=0 && iDDL<kTotDDL){
229 Int_t index=kSides*(kModPerDDL*iDDL+iCarlos)+s->GetChannel();
230 histo[index]->Fill(s->GetCoord2(),s->GetCoord1(),s->GetSignal());
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;
241 if(amSamplFreq==20) base[index]->SetLastGoodTB(126);
242 else base[index]->SetLastGoodTB(254);
243 base[index]->AddEvent(histo[index]);
246 if(amSamplFreq==20) corr[index]->SetLastGoodTB(126);
247 else corr[index]->SetLastGoodTB(254);
248 corr[index]->AddEvent(histo[index]);
257 if(ievUsed>=maxNEvents) break;
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();
276 TObjString timeinfo(Form("%02d%02d%02d%02d%02d%02d",time.GetYear()-2000,time.GetMonth(),time.GetDay(),time.GetHour(),time.GetMinute(),time.GetSecond()));
277 printf("Run #%s, received %d calibration events, time %s\n",getenv("DATE_RUN_NUMBER"),ievUsed,timeinfo.GetString().Data());
279 /* report progress */
280 daqDA_progressReport(90);
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();
289 Char_t filnam[100],command[150];
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();
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());
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);
311 amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender);
312 Int_t statusamore =0;
313 statusamore += amoreDA.Send("TimeInfoPedestal",&timeinfo);
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);
320 printf("Warning: Failed to write Arrays in the AMORE database\n");
322 printf("amoreDA.Send() OK\n");
324 printf("Warning: SDDBAS DA not compiled with AMORE support\n");
328 TFile *fh=new TFile("SDDbaseHistos.root","RECREATE");
330 noiseHistos->Write();
332 corrnHistos->Write();
333 statusHistos->Write();
336 /* report progress */
337 daqDA_progressReport(100);