]>
Commit | Line | Data |
---|---|---|
1 | /************************************************************************** | |
2 | * Copyright(c) 2007-2009, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
7 | * Permission to use, copy, modify and distribute this software and its * | |
8 | * documentation strictly for non-commercial purposes is hereby granted * | |
9 | * without fee, provided that the above copyright notice appears in all * | |
10 | * copies and that both the copyright notice and this permission notice * | |
11 | * appear in the supporting documentation. The authors make no claims * | |
12 | * about the suitability of this software for any purpose. It is * | |
13 | * provided "as is" without express or implied warranty. * | |
14 | **************************************************************************/ | |
15 | ||
16 | /* $Id$ */ | |
17 | ||
18 | /////////////////////////////////////////////////////////////////// | |
19 | // // | |
20 | // Implementation of the class for SDD preprocessing // | |
21 | // Origin: E.Crescio, Torino, crescio@to.infn.it // | |
22 | // F.Prino, Torino, prino@to.infn.it // | |
23 | // // | |
24 | /////////////////////////////////////////////////////////////////// | |
25 | ||
26 | #include "AliITSPreprocessorSDD.h" | |
27 | #include "AliITSCalibrationSDD.h" | |
28 | #include "AliITSDriftSpeedSDD.h" | |
29 | #include "AliITSDriftSpeedArraySDD.h" | |
30 | #include "AliITSDCSAnalyzerSDD.h" | |
31 | #include "AliShuttleInterface.h" | |
32 | #include "AliCDBEntry.h" | |
33 | #include "AliCDBMetaData.h" | |
34 | #include "TObjArray.h" | |
35 | #include "AliLog.h" | |
36 | #include <TObjString.h> | |
37 | #include <TSystem.h> | |
38 | #include <TList.h> | |
39 | ||
40 | const TString AliITSPreprocessorSDD::fgkNameHistoPedestals = "hpedestal"; | |
41 | const TString AliITSPreprocessorSDD::fgkNameHistoNoise = "hnoise"; | |
42 | ClassImp(AliITSPreprocessorSDD) | |
43 | ||
44 | //______________________________________________________________________ | |
45 | AliITSPreprocessorSDD::AliITSPreprocessorSDD( AliShuttleInterface* shuttle): | |
46 | AliPreprocessor("SDD", shuttle) | |
47 | { | |
48 | // constructor | |
49 | AddRunType("PULSER"); | |
50 | AddRunType("INJECTOR"); | |
51 | AddRunType("PHYSICS"); | |
52 | } | |
53 | ||
54 | //______________________________________________________________________ | |
55 | UInt_t AliITSPreprocessorSDD::Process(TMap* dcsAliasMap){ | |
56 | ||
57 | // Get DDL map from OCDB | |
58 | AliCDBEntry* entry = GetFromOCDB("Calib", "DDLMapSDD"); | |
59 | if(!entry){ | |
60 | Log("DDL map file not found in OCDB."); | |
61 | return 2; | |
62 | } | |
63 | AliITSDDLModuleMapSDD* ddlmap = (AliITSDDLModuleMapSDD*)entry->GetObject(); | |
64 | if(!ddlmap){ | |
65 | Log("AliITSDDLModuleMapSDD object not in file."); | |
66 | return 2; | |
67 | } | |
68 | ||
69 | //preprocessing | |
70 | TString runType = GetRunType(); | |
71 | Int_t retcode=0; | |
72 | ||
73 | if (runType == "PULSER"){ | |
74 | retcode=ProcessPulser(ddlmap); | |
75 | }else if(runType== "INJECTOR"){ | |
76 | retcode=ProcessInjector(ddlmap); | |
77 | } | |
78 | if(retcode!=0) return retcode; | |
79 | ||
80 | Bool_t retcodedcs =ProcessDCSDataPoints(dcsAliasMap); | |
81 | if(retcodedcs) return 0; | |
82 | else return 1; | |
83 | ||
84 | } | |
85 | //______________________________________________________________________ | |
86 | UInt_t AliITSPreprocessorSDD::ProcessPulser(AliITSDDLModuleMapSDD* ddlmap){ | |
87 | // Process FXS files from PULSER run (baseline, noise, gain) | |
88 | // returns 0 in case of success, | |
89 | // 1 in case of storage error, | |
90 | // 2 in case of error with input files | |
91 | TObjArray calSDD(kNumberOfSDD); | |
92 | calSDD.SetOwner(kFALSE); | |
93 | Char_t command[100]; | |
94 | Char_t inpFileName[100]; | |
95 | Float_t baseline,rawnoise,cmn,corn,gain; | |
96 | Int_t isgoodan,i,im,is,isgoodmod,basmin,basoff; | |
97 | Int_t th,tl; | |
98 | Int_t numOfBadChannels[kNumberOfSDD]; | |
99 | ||
100 | TList* sourceList = GetFileSources(kDAQ, "SDD_Calib"); | |
101 | if (!sourceList){ | |
102 | Log("Error: no sources found for SDD_Calib"); | |
103 | return 2; | |
104 | } | |
105 | ||
106 | Int_t ind = 0; | |
107 | while (sourceList->At(ind)!=NULL) { | |
108 | TObjString* tarId = (TObjString*) sourceList->At(ind); | |
109 | TString tarName = GetFile(kDAQ, "SDD_Calib", tarId->GetString().Data()); | |
110 | if(tarName.Length()==0){ | |
111 | Log(Form("Baseline tar file from source %d not found.",ind)); | |
112 | return 2; | |
113 | } | |
114 | sprintf(command,"tar -xf %s",tarName.Data()); | |
115 | gSystem->Exec(command); | |
116 | ind++; | |
117 | } | |
118 | delete sourceList; | |
119 | ||
120 | for(Int_t iddl=0;iddl<kNumberOfDDL;iddl++){ | |
121 | for(Int_t imod=0;imod<kModulesPerDDL;imod++){ | |
122 | Int_t modID=ddlmap->GetModuleNumber(iddl,imod); | |
123 | if(modID==-1) continue; | |
124 | modID-=240; // to have SDD modules numbering from 0 to 260 | |
125 | AliITSCalibrationSDD *cal = new AliITSCalibrationSDD("simulated"); | |
126 | cal->SetUseCorrectionMaps(0,0); // temporary disabling of maps | |
127 | numOfBadChannels[modID]=0; | |
128 | Int_t badch[kNumberOfChannels]; | |
129 | for(Int_t isid=0;isid<=1;isid++){ | |
130 | sprintf(inpFileName,"./SDDbase_ddl%02dc%02d_sid%d.data",iddl,imod,isid); | |
131 | FILE* basFil = fopen(inpFileName,"read"); | |
132 | if (basFil == 0) { | |
133 | Log(Form("File %s not found.",inpFileName)); | |
134 | cal->SetBad(); | |
135 | continue; | |
136 | } | |
137 | fscanf(basFil,"%d %d %d\n",&im,&is,&isgoodmod); | |
138 | if(!isgoodmod) cal->SetBad(); | |
139 | fscanf(basFil,"%d\n",&th); | |
140 | fscanf(basFil,"%d\n",&tl); | |
141 | cal->SetZSLowThreshold(isid,tl); | |
142 | cal->SetZSHighThreshold(isid,th); | |
143 | for(Int_t ian=0;ian<(kNumberOfChannels/2);ian++){ | |
144 | fscanf(basFil,"%d %d %f %d %d %f %f %f %f\n",&i,&isgoodan,&baseline,&basmin,&basoff,&rawnoise,&cmn,&corn,&gain); | |
145 | Int_t ich=ian; | |
146 | if(isid==1) ich+=256; | |
147 | if(!isgoodan){ | |
148 | Int_t ibad=numOfBadChannels[modID]; | |
149 | badch[ibad]=ich; | |
150 | numOfBadChannels[modID]++; | |
151 | } | |
152 | cal->SetBaseline(ich,baseline-basoff); | |
153 | cal->SetNoiseAfterElectronics(ich,rawnoise); | |
154 | cal->SetGain(ich,gain); | |
155 | } | |
156 | cal->SetDeadChannels(numOfBadChannels[modID]); | |
157 | for(Int_t ibad=0;ibad<numOfBadChannels[modID];ibad++){ | |
158 | cal->SetBadChannel(ibad,badch[ibad]); | |
159 | } | |
160 | fclose(basFil); | |
161 | } | |
162 | calSDD.AddAt(cal,modID); | |
163 | } | |
164 | } | |
165 | AliCDBMetaData *md= new AliCDBMetaData(); | |
166 | md->SetResponsible("Francesco Prino"); | |
167 | md->SetBeamPeriod(0); | |
168 | md->SetComment("AliITSCalibrationSDD from PEDESTAL+PULSER runs"); | |
169 | Bool_t retCode = Store("Calib","CalibSDD",&calSDD,md, 0, kTRUE); | |
170 | if(retCode) return 0; | |
171 | else return 1; | |
172 | } | |
173 | //______________________________________________________________________ | |
174 | UInt_t AliITSPreprocessorSDD::ProcessInjector(AliITSDDLModuleMapSDD* ddlmap){ | |
175 | // Process FXS files from injector events (INJECTOR or PHYSICS runs) | |
176 | // returns 0 in case of success, | |
177 | // 1 in case of storage error, | |
178 | // 2 in case of error with input files | |
179 | TObjArray vdrift(2*kNumberOfSDD); | |
180 | vdrift.SetOwner(kFALSE); | |
181 | Char_t command[100]; | |
182 | Char_t inpFileName[100]; | |
183 | Int_t evNumb,polDeg; | |
184 | UInt_t timeStamp; | |
185 | Bool_t modSet[2*kNumberOfSDD]; // flag modules with good inj. | |
186 | Double_t nPt = 0; | |
187 | ||
188 | Double_t param[4]; // parameters of poly fit | |
189 | Double_t minValP0=4.; // min value for param[0] | |
190 | Double_t maxValP0=9.; // max value for param[0] | |
191 | Double_t minValP1=0.; // min value for param[1] | |
192 | Double_t aveCoef[4]={0.,0.,0.,0.}; // average param for good mod. | |
193 | Double_t defCoef[4]={6.53227,0.00128941,-5.14493e-06,0}; // default values for param | |
194 | Float_t auxP; | |
195 | ||
196 | TList* sourceList = GetFileSources(kDAQ, "SDD_Injec"); | |
197 | if (!sourceList){ | |
198 | Log("Error: no sources found for SDD_Injec"); | |
199 | return 2; | |
200 | } | |
201 | Int_t ind = 0; | |
202 | while (sourceList->At(ind)!=NULL) { | |
203 | TObjString* tarId = (TObjString*) sourceList->At(ind); | |
204 | TString tarName = GetFile(kDAQ, "SDD_Injec", tarId->GetString().Data()); | |
205 | if(tarName.Length()==0){ | |
206 | Log(Form("Injector tar file from source %d not found.",ind)); | |
207 | return 2; | |
208 | } | |
209 | sprintf(command,"tar -xf %s",tarName.Data()); | |
210 | gSystem->Exec(command); | |
211 | ind++; | |
212 | } | |
213 | delete sourceList; | |
214 | ||
215 | ||
216 | for(Int_t iddl=0;iddl<kNumberOfDDL;iddl++){ | |
217 | for(Int_t imod=0;imod<kModulesPerDDL;imod++){ | |
218 | Int_t modID=ddlmap->GetModuleNumber(iddl,imod); | |
219 | if(modID==-1) continue; | |
220 | modID-=240; // to have SDD modules numbering from 0 to 260 | |
221 | for(Int_t isid=0;isid<=1;isid++){ | |
222 | modSet[2*modID+isid]=0; | |
223 | AliITSDriftSpeedArraySDD *arr=new AliITSDriftSpeedArraySDD(); | |
224 | sprintf(inpFileName,"./SDDinj_ddl%02dc%02d_sid%d.data",iddl,imod,isid); | |
225 | FILE* injFil = fopen(inpFileName,"read"); | |
226 | if (injFil == 0) { | |
227 | Log(Form("File %s not found.",inpFileName)); | |
228 | AliITSDriftSpeedSDD *dsp=new AliITSDriftSpeedSDD(); | |
229 | arr->AddDriftSpeed(dsp); | |
230 | vdrift.AddAt(arr,2*modID+isid); | |
231 | continue; | |
232 | } | |
233 | fscanf(injFil,"%d",&polDeg); | |
234 | while (!feof(injFil)){ | |
235 | fscanf(injFil,"%d %d ",&evNumb,&timeStamp); | |
236 | if(feof(injFil)) break; | |
237 | for(Int_t ic=0;ic<4;ic++){ | |
238 | fscanf(injFil,"%f ",&auxP); | |
239 | param[ic]=auxP; | |
240 | } | |
241 | ||
242 | if(param[0]>minValP0 && param[0]<maxValP0 && param[1]>minValP1){ | |
243 | for(Int_t ic=0;ic<4;ic++) aveCoef[ic]+=param[ic]; | |
244 | nPt++; | |
245 | AliITSDriftSpeedSDD *dsp=new AliITSDriftSpeedSDD(evNumb,timeStamp,polDeg,param); | |
246 | arr->AddDriftSpeed(dsp); | |
247 | modSet[2*modID+isid]=1; | |
248 | } | |
249 | } | |
250 | if(modSet[2*modID+isid]) vdrift.AddAt(arr,2*modID+isid); | |
251 | } | |
252 | } | |
253 | } | |
254 | ||
255 | // set drift speed for modules with bad injectors | |
256 | for(Int_t ic=0;ic<4;ic++){ | |
257 | if(nPt>0) aveCoef[ic]/=nPt; // mean parameters | |
258 | else aveCoef[ic]=defCoef[ic]; // default parameters | |
259 | } | |
260 | AliITSDriftSpeedSDD *avdsp=new AliITSDriftSpeedSDD(evNumb,timeStamp,polDeg,aveCoef); | |
261 | ||
262 | for(Int_t ihyb=0; ihyb<2*kNumberOfSDD; ihyb++){ | |
263 | if(modSet[ihyb]==0){ | |
264 | AliWarning(Form("No good injector events for mod. %d --> use average values",ihyb/2)); | |
265 | AliITSDriftSpeedArraySDD *arr=new AliITSDriftSpeedArraySDD(); | |
266 | arr->AddDriftSpeed(avdsp); | |
267 | vdrift.AddAt(arr,ihyb); | |
268 | } | |
269 | } | |
270 | ||
271 | ||
272 | AliCDBMetaData *md= new AliCDBMetaData(); | |
273 | md->SetResponsible("Francesco Prino"); | |
274 | md->SetBeamPeriod(0); | |
275 | md->SetComment("AliITSDriftSpeedSDD from injector events"); | |
276 | Bool_t retCode = Store("Calib","DriftSpeedSDD",&vdrift,md,0, kTRUE); | |
277 | if(retCode) return 0; | |
278 | else return 1; | |
279 | } | |
280 | //______________________________________________________________________ | |
281 | Bool_t AliITSPreprocessorSDD::ProcessDCSDataPoints(TMap* dcsAliasMap){ | |
282 | // Process DCS data | |
283 | AliITSDCSAnalyzerSDD *dcs=new AliITSDCSAnalyzerSDD(); | |
284 | dcs->AnalyzeData(dcsAliasMap); | |
285 | TObjArray refDCS(kNumberOfSDD); | |
286 | refDCS.SetOwner(kFALSE); | |
287 | for(Int_t imod=0;imod<kNumberOfSDD;imod++){ | |
288 | AliITSDCSDataSDD *dcsdata=dcs->GetDCSData(imod); | |
289 | refDCS.Add(dcsdata); | |
290 | } | |
291 | AliCDBMetaData *md= new AliCDBMetaData(); | |
292 | md->SetResponsible("Francesco Prino"); | |
293 | md->SetBeamPeriod(0); | |
294 | md->SetComment("AliITSDCSDataSDD objects from DCS DB"); | |
295 | Bool_t retCode = StoreReferenceData("DCS","DataSDD",&refDCS,md); | |
296 | return retCode; | |
297 | } |