Line data Source code
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 : // Run Types treated: //
22 : // PULSER, INJECTOR -> Store OCDB parameters //
23 : // ALL RUNS -> Store DCS reference data //
24 : // Origin: E.Crescio, Torino, crescio@to.infn.it //
25 : // F.Prino, Torino, prino@to.infn.it //
26 : // //
27 : ///////////////////////////////////////////////////////////////////
28 :
29 : #include "AliITSDDLModuleMapSDD.h"
30 : #include "AliITSPreprocessorSDD.h"
31 : #include "AliITSCalibrationSDD.h"
32 : #include "AliITSDriftSpeedSDD.h"
33 : #include "AliITSDriftSpeedArraySDD.h"
34 : #include "AliITSDCSAnalyzerSDD.h"
35 : #include "AliShuttleInterface.h"
36 : #include "AliCDBEntry.h"
37 : #include "AliCDBMetaData.h"
38 : #include "TObjArray.h"
39 : #include "AliLog.h"
40 : #include <TObjString.h>
41 : #include <TSystem.h>
42 : #include <TList.h>
43 : #include <TF1.h>
44 : #include <TH1D.h>
45 :
46 116 : const TString AliITSPreprocessorSDD::fgkNameHistoPedestals = "hpedestal";
47 116 : const TString AliITSPreprocessorSDD::fgkNameHistoNoise = "hnoise";
48 116 : ClassImp(AliITSPreprocessorSDD)
49 :
50 : //______________________________________________________________________
51 : AliITSPreprocessorSDD::AliITSPreprocessorSDD( AliShuttleInterface* shuttle):
52 0 : AliPreprocessor("SDD", shuttle)
53 0 : {
54 : // constructor
55 0 : AddRunType("PULSER");
56 0 : AddRunType("INJECTOR");
57 0 : AddRunType("PHYSICS");
58 0 : }
59 :
60 : //______________________________________________________________________
61 : UInt_t AliITSPreprocessorSDD::Process(TMap* /*dcsAliasMap*/ ){
62 :
63 :
64 : // Get DDL map from OCDB
65 0 : AliCDBEntry* entry = GetFromOCDB("Calib", "DDLMapSDD");
66 0 : if(!entry){
67 0 : Log("DDL map file not found in OCDB.");
68 0 : return 2;
69 : }
70 0 : AliITSDDLModuleMapSDD* ddlmap = (AliITSDDLModuleMapSDD*)entry->GetObject();
71 0 : if(!ddlmap){
72 0 : Log("AliITSDDLModuleMapSDD object not in file.");
73 0 : return 2;
74 : }
75 0 : ddlmap->PrintDDLMap();
76 :
77 : //preprocessing
78 0 : TString runType = GetRunType();
79 : Int_t retcode=0;
80 :
81 0 : if (runType == "PULSER"){
82 0 : Log("Process FXS files from PULSER RUN");
83 0 : retcode=ProcessPulser(ddlmap);
84 0 : }else if(runType== "INJECTOR"){
85 0 : Log("Process FXS files from INJECTOR RUN");
86 0 : retcode=ProcessInjector(ddlmap);
87 0 : }
88 : return retcode;
89 :
90 0 : }
91 : //______________________________________________________________________
92 : UInt_t AliITSPreprocessorSDD::ProcessPulser(AliITSDDLModuleMapSDD* ddlmap){
93 : // Process FXS files from PULSER run (baseline, noise, gain)
94 : // returns 0 in case of success,
95 : // 1 in case of storage error,
96 : // 2 in case of error with input files
97 0 : TObjArray calSDD(kNumberOfSDD);
98 0 : calSDD.SetOwner(kFALSE);
99 :
100 0 : Float_t baseline,rawnoise,cmn,corn,gain;
101 0 : Int_t isgoodan,i,im,is,isgoodmod,basmin,basoff;
102 0 : Int_t th,tl;
103 0 : Int_t numOfBadChannels[kNumberOfSDD];
104 :
105 0 : TList* sourceList = GetFileSources(kDAQ, "SDD_Calib");
106 0 : if (!sourceList){
107 0 : Log("Error: no sources found for SDD_Calib");
108 0 : return 2;
109 : }
110 :
111 : Int_t ind = 0;
112 0 : while (sourceList->At(ind)!=NULL) {
113 0 : TObjString* tarId = (TObjString*) sourceList->At(ind);
114 0 : TString tarName = GetFile(kDAQ, "SDD_Calib", tarId->GetString().Data());
115 0 : if(tarName.Length()==0){
116 0 : Log(Form("Baseline tar file from source %d not found.",ind));
117 0 : return 2;
118 : }
119 0 : TString command;
120 0 : command.Form("tar -xf %s",tarName.Data());
121 0 : gSystem->Exec(command);
122 0 : ind++;
123 0 : }
124 0 : delete sourceList;
125 : // Read ADC sampling frequency from fee.conf
126 0 : Int_t amSamplFreq=40;
127 : Int_t retfscf;
128 0 : FILE* feefil=fopen("fee.conf","r");
129 0 : if(feefil){
130 0 : retfscf=fscanf(feefil,"%d \n",&amSamplFreq);
131 0 : fclose(feefil);
132 0 : if(retfscf<0){
133 0 : Log("Error reading from fee.conf. AM sampling set at 40 MHz by default");
134 : }else{
135 0 : Log(Form("AM sampling frequency = %d MHz",amSamplFreq));
136 : }
137 : }else{
138 0 : Log("File fee.conf not found. AM sampling set at 40 MHz by default");
139 : }
140 :
141 0 : for(Int_t iddl=0;iddl<kNumberOfDDL;iddl++){
142 0 : for(Int_t imod=0;imod<kModulesPerDDL;imod++){
143 0 : Int_t modID=ddlmap->GetModuleNumber(iddl,imod);
144 0 : if(modID==-1) continue;
145 0 : modID-=240; // to have SDD modules numbering from 0 to 260
146 0 : AliITSCalibrationSDD *cal = new AliITSCalibrationSDD("simulated");
147 0 : if(amSamplFreq!=40) cal->SetAMAt20MHz();
148 0 : numOfBadChannels[modID]=0;
149 0 : Int_t badch[kNumberOfChannels];
150 : Bool_t sid0ok=kTRUE;
151 : Bool_t sid1ok=kTRUE;
152 0 : for(Int_t isid=0;isid<=1;isid++){
153 0 : TString inpFileName;
154 0 : inpFileName.Form("./SDDbase_ddl%02dc%02d_sid%d.data",iddl,imod,isid);
155 :
156 0 : FILE* basFil = fopen(inpFileName,"read");
157 0 : if (basFil == 0) {
158 0 : Log(Form("File %s not found.",inpFileName.Data()));
159 0 : if(isid==0){
160 : sid0ok=kFALSE;
161 0 : for(Int_t iChip=0; iChip<4; iChip++) cal->SetChipBad(iChip);
162 0 : cal->SetDeadChannels(cal->GetDeadChannels()+256);
163 0 : for(Int_t iAnode=0; iAnode<256; iAnode++) cal->SetBadChannel(iAnode,iAnode);
164 0 : }else{
165 : sid1ok=kFALSE;
166 0 : for(Int_t iChip=4; iChip<8; iChip++) cal->SetChipBad(iChip);
167 0 : cal->SetDeadChannels(cal->GetDeadChannels()+256);
168 0 : for(Int_t iAnode=0; iAnode<256; iAnode++) cal->SetBadChannel(iAnode,iAnode+256);
169 : }
170 0 : continue;
171 : }
172 :
173 0 : retfscf=fscanf(basFil,"%d %d %d\n",&im,&is,&isgoodmod);
174 0 : if(retfscf<0) isgoodmod=kFALSE;
175 0 : if(!isgoodmod){
176 0 : if(isid==0){
177 : sid0ok=kFALSE;
178 0 : for(Int_t iChip=0; iChip<4; iChip++) cal->SetChipBad(iChip);
179 0 : }else{
180 : sid1ok=kFALSE;
181 0 : for(Int_t iChip=4; iChip<8; iChip++) cal->SetChipBad(iChip);
182 : }
183 : }
184 0 : retfscf=fscanf(basFil,"%d\n",&th);
185 0 : retfscf=fscanf(basFil,"%d\n",&tl);
186 0 : cal->SetZSLowThreshold(isid,tl);
187 0 : cal->SetZSHighThreshold(isid,th);
188 0 : for(Int_t ian=0;ian<(kNumberOfChannels/2);ian++){
189 0 : retfscf=fscanf(basFil,"%d %d %f %d %d %f %f %f %f\n",&i,&isgoodan,&baseline,&basmin,&basoff,&rawnoise,&cmn,&corn,&gain);
190 : Int_t ich=ian;
191 0 : if(isid==1) ich+=256;
192 0 : if(!isgoodan){
193 0 : Int_t ibad=numOfBadChannels[modID];
194 0 : badch[ibad]=ich;
195 0 : numOfBadChannels[modID]++;
196 0 : }
197 0 : cal->SetBaseline(ich,baseline-basoff);
198 0 : cal->SetNoiseAfterElectronics(ich,rawnoise);
199 0 : cal->SetGain(ich,gain);
200 : }
201 0 : cal->SetDeadChannels(numOfBadChannels[modID]);
202 0 : for(Int_t ibad=0;ibad<numOfBadChannels[modID];ibad++){
203 0 : cal->SetBadChannel(ibad,badch[ibad]);
204 : }
205 0 : fclose(basFil);
206 0 : }
207 0 : if(!sid0ok && !sid1ok) cal->SetBad();
208 0 : Log(Form("Put calib obj for module %d (DDL %d Carlos %d)",modID,iddl,imod));
209 0 : calSDD.AddAt(cal,modID);
210 0 : }
211 : }
212 0 : AliCDBMetaData *md= new AliCDBMetaData();
213 0 : md->SetResponsible("Francesco Prino");
214 0 : md->SetBeamPeriod(0);
215 0 : md->SetComment("AliITSCalibrationSDD from PEDESTAL+PULSER runs");
216 0 : Bool_t retCode = Store("Calib","CalibSDD",&calSDD,md, 0, kTRUE);
217 0 : if(retCode) return 0;
218 0 : else return 1;
219 0 : }
220 : //______________________________________________________________________
221 : UInt_t AliITSPreprocessorSDD::ProcessInjector(AliITSDDLModuleMapSDD* ddlmap){
222 : // Process FXS files from injector events (INJECTOR or PHYSICS runs)
223 : // returns 0 in case of success,
224 : // 1 in case of storage error,
225 : // 2 in case of error with input files
226 0 : TObjArray vdrift(2*kNumberOfSDD);
227 0 : vdrift.SetOwner(kFALSE);
228 0 : Int_t evNumb,polDeg;
229 0 : UInt_t timeStamp,statusInj;
230 0 : Bool_t modSet[2*kNumberOfSDD]; // flag modules with good inj.
231 0 : for(Int_t ihyb=0; ihyb<2*kNumberOfSDD; ihyb++) modSet[ihyb]=0;
232 : Double_t nPtLay3 = 0;
233 : Double_t nPtLay4 = 0;
234 :
235 0 : Double_t param[4]; // parameters of poly fit
236 : Double_t minValP0=5.; // min value for param[0]
237 : Double_t maxValP0=8.; // max value for param[0]
238 : Double_t minValP1=0.; // min value for param[1]
239 0 : Double_t aveCoefLay3[4]={0.,0.,0.,0.}; // average param for good mod.
240 0 : Double_t aveCoefLay4[4]={0.,0.,0.,0.}; // average param for good mod.
241 0 : Double_t defCoef[4]={6.53227,0.00128941,-5.14493e-06,0}; // default values for param
242 0 : Float_t auxP;
243 :
244 0 : TList* sourceList = GetFileSources(kDAQ, "SDD_Injec");
245 0 : if (!sourceList){
246 0 : Log("Error: no sources found for SDD_Injec");
247 0 : return 2;
248 : }
249 : Int_t ind = 0;
250 0 : while (sourceList->At(ind)!=NULL) {
251 0 : TObjString* tarId = (TObjString*) sourceList->At(ind);
252 0 : TString tarName = GetFile(kDAQ, "SDD_Injec", tarId->GetString().Data());
253 0 : if(tarName.Length()==0){
254 0 : Log(Form("Injector tar file from source %d not found.",ind));
255 0 : return 2;
256 : }
257 0 : TString command;
258 0 : command.Form("tar -xf %s",tarName.Data());
259 0 : gSystem->Exec(command);
260 0 : ind++;
261 0 : }
262 0 : delete sourceList;
263 : Int_t retfscf;
264 :
265 :
266 0 : for(Int_t iddl=0;iddl<kNumberOfDDL;iddl++){
267 0 : for(Int_t imod=0;imod<kModulesPerDDL;imod++){
268 0 : Int_t modID=ddlmap->GetModuleNumber(iddl,imod);
269 0 : if(modID==-1) continue;
270 0 : modID-=240; // to have SDD modules numbering from 0 to 260
271 0 : for(Int_t isid=0;isid<=1;isid++){
272 0 : AliITSDriftSpeedArraySDD *arr=new AliITSDriftSpeedArraySDD();
273 0 : TString inpFileName;
274 0 : inpFileName.Form("./SDDinj_ddl%02dc%02d_sid%d.data",iddl,imod,isid);
275 0 : FILE* injFil = fopen(inpFileName,"read");
276 0 : if (injFil == 0) {
277 0 : Log(Form("File %s not found.",inpFileName.Data()));
278 0 : continue;
279 : }
280 0 : retfscf=fscanf(injFil,"%d",&polDeg);
281 0 : if(retfscf<0){
282 0 : Log(Form("File %s has bad format.",inpFileName.Data()));
283 0 : fclose(injFil);
284 0 : continue;
285 : }
286 0 : while (!feof(injFil)){
287 0 : retfscf=fscanf(injFil,"%d %u ",&evNumb,&timeStamp);
288 0 : if(evNumb==-99){
289 0 : statusInj=timeStamp;
290 0 : arr->SetInjectorStatus(statusInj);
291 0 : }else{
292 0 : if(feof(injFil)) break;
293 0 : for(Int_t ic=0;ic<4;ic++){
294 0 : retfscf=fscanf(injFil,"%f ",&auxP);
295 0 : param[ic]=auxP;
296 : }
297 :
298 0 : if(polDeg>=0 && polDeg<=AliITSDriftSpeedSDD::GetMaxPolDeg() &&
299 0 : param[0]>minValP0 && param[0]<maxValP0 && param[1]>minValP1){
300 0 : if(polDeg==3){
301 0 : if(modID<kNumberOfSDDLay3){
302 0 : for(Int_t ic=0;ic<4;ic++) aveCoefLay3[ic]+=param[ic];
303 0 : nPtLay3++;
304 0 : }else{
305 0 : for(Int_t ic=0;ic<4;ic++) aveCoefLay4[ic]+=param[ic];
306 0 : nPtLay4++;
307 : }
308 : }
309 0 : AliITSDriftSpeedSDD *dsp=new AliITSDriftSpeedSDD(evNumb,timeStamp,polDeg,param);
310 0 : arr->AddDriftSpeed(dsp);
311 0 : modSet[2*modID+isid]=1;
312 0 : }else{
313 0 : Log(Form("Module %d side %d not accepted, degree=%d, params=%g %g %g %g",modID+240,isid,polDeg,param[0],param[1],param[2],param[3]));
314 : }
315 : }
316 : }
317 0 : fclose(injFil);
318 0 : Log(Form("Put calib obj for hybrid %d (DDL %d Carlos %d)",2*modID+isid,iddl,imod));
319 0 : if(modSet[2*modID+isid]) vdrift.AddAt(arr,2*modID+isid);
320 0 : }
321 0 : }
322 : }
323 :
324 : // set drift speed for modules with bad injectors
325 0 : for(Int_t ic=0;ic<4;ic++){
326 0 : if(nPtLay3>0) aveCoefLay3[ic]/=nPtLay3; // mean parameters
327 0 : else aveCoefLay3[ic]=defCoef[ic]; // default parameters
328 0 : if(nPtLay4>0) aveCoefLay4[ic]/=nPtLay4; // mean parameters
329 0 : else aveCoefLay4[ic]=defCoef[ic]; // default parameters
330 : }
331 0 : AliITSDriftSpeedSDD *avdsp3=new AliITSDriftSpeedSDD(evNumb,timeStamp,3,aveCoefLay3);
332 0 : AliITSDriftSpeedSDD *avdsp4=new AliITSDriftSpeedSDD(evNumb,timeStamp,3,aveCoefLay4);
333 :
334 : // Check status of golden modules
335 : Int_t idGoldenMod=-1, idGoldenSide=-1;
336 0 : Int_t idGoldenModList[5]={319,319,321,243,243};
337 0 : Int_t idGoldenSideList[5]={0,1,0,0,1};
338 : AliITSDriftSpeedSDD* refSpeed=0x0;
339 0 : for(Int_t iGold=0; iGold<5; iGold++){
340 0 : Int_t indexG=2*(idGoldenModList[iGold]-240)+idGoldenSideList[iGold];
341 0 : if(modSet[indexG]){
342 : idGoldenMod=idGoldenModList[iGold];
343 : idGoldenSide=idGoldenSideList[iGold];
344 0 : AliITSDriftSpeedArraySDD* arrRef=(AliITSDriftSpeedArraySDD*)vdrift.At(indexG);
345 0 : refSpeed=arrRef->GetDriftSpeedObject(0);
346 : break;
347 : }
348 0 : }
349 : TList* correctionList=0x0;
350 0 : if(idGoldenMod>=240 && idGoldenSide>=0){
351 : // Get rescaling corrections from OCDB
352 0 : AliCDBEntry* entry = GetFromOCDB("Calib", "RescaleDriftSpeedSDD");
353 0 : if(!entry){
354 0 : Log("RescaleDriftSpeedSDD file not found in OCDB.");
355 : }
356 0 : TList* fullList=(TList*)entry->GetObject();
357 0 : if(!fullList){
358 0 : Log("TList object not found in file.");
359 : }
360 0 : TString listName=Form("RefMod%d_Side%d",idGoldenMod,idGoldenSide);
361 0 : correctionList=(TList*)fullList->FindObject(listName.Data());
362 0 : if(!correctionList){
363 0 : Log(Form("TList for requested module %d side %d not found",idGoldenMod,idGoldenSide));
364 : }else{
365 0 : Log(Form("Use module %d side %d as reference module",idGoldenMod,idGoldenSide));
366 0 : if(refSpeed){
367 0 : Log(Form("Drift speed params for golden module = %g %g %g %g",refSpeed->GetDriftSpeedParameter(0),refSpeed->GetDriftSpeedParameter(1),refSpeed->GetDriftSpeedParameter(2),refSpeed->GetDriftSpeedParameter(3)));
368 : }else{
369 0 : AliError("No drift speed object for golden module");
370 : }
371 : }
372 0 : }
373 :
374 0 : for(Int_t ihyb=0; ihyb<2*kNumberOfSDDLay3; ihyb++){
375 0 : AliITSDriftSpeedArraySDD *arr=new AliITSDriftSpeedArraySDD();
376 0 : if(modSet[ihyb]==0){
377 0 : Int_t iBadMod=ihyb/2+240;
378 0 : Int_t iBadSide=ihyb%2;
379 : Bool_t goldenUsed=kFALSE;
380 0 : if(correctionList && refSpeed){
381 0 : Double_t *params=RescaleDriftSpeedModule(correctionList,iBadMod,iBadSide,refSpeed);
382 0 : if(params){
383 0 : AliWarning(Form("No good injector events for mod. %d side %d --> use rescaled values from golden module",iBadMod,iBadSide));
384 0 : AliITSDriftSpeedSDD* dspres=new AliITSDriftSpeedSDD(0,refSpeed->GetEventTimestamp(),3,params);
385 0 : arr->AddDriftSpeed(dspres);
386 0 : arr->SetInjectorStatus(1);
387 : goldenUsed=kTRUE;
388 0 : delete [] params;
389 0 : }
390 0 : }
391 0 : if(!goldenUsed){
392 0 : AliWarning(Form("No good injector events for mod. %d side %d --> use average values for layer 3",iBadMod,iBadSide));
393 0 : arr->AddDriftSpeed(avdsp3);
394 0 : arr->SetInjectorStatus(0);
395 0 : }
396 0 : vdrift.AddAt(arr,ihyb);
397 0 : }
398 : }
399 :
400 0 : for(Int_t ihyb=2*kNumberOfSDDLay3; ihyb<2*kNumberOfSDD; ihyb++){
401 0 : if(modSet[ihyb]==0){
402 0 : AliWarning(Form("No good injector events for mod. %d side %d --> use average values for layer 4",ihyb/2,ihyb%2));
403 0 : AliITSDriftSpeedArraySDD *arr=new AliITSDriftSpeedArraySDD();
404 0 : arr->AddDriftSpeed(avdsp4);
405 0 : arr->SetInjectorStatus(0);
406 0 : vdrift.AddAt(arr,ihyb);
407 0 : }
408 : }
409 :
410 0 : AliCDBMetaData *md= new AliCDBMetaData();
411 0 : md->SetResponsible("Francesco Prino");
412 0 : md->SetBeamPeriod(0);
413 0 : md->SetComment("AliITSDriftSpeedSDD from injector events");
414 0 : Bool_t retCode = Store("Calib","DriftSpeedSDD",&vdrift,md,0, kTRUE);
415 0 : if(retCode) return 0;
416 0 : else return 1;
417 0 : }
418 :
419 : //______________________________________________________________________
420 : Double_t* AliITSPreprocessorSDD::RescaleDriftSpeedModule(const TList* theList,
421 : Int_t iBadMod,
422 : Int_t iBadSide,
423 : const AliITSDriftSpeedSDD* refSpeed)
424 : const
425 : {
426 : // Rescale driftSpeed for a drift region starting from values of golden module
427 :
428 0 : if(!refSpeed) return 0x0;
429 0 : TString hisName=Form("hRatioMod%d_Side%d",iBadMod,iBadSide);
430 0 : TH1D* h=(TH1D*)theList->FindObject(hisName.Data());
431 0 : if(!h) return 0x0;
432 :
433 0 : TF1* fpoly=new TF1("fpoly","pol3",0.,255.);
434 0 : for(Int_t iAnode=0; iAnode<256; iAnode++){
435 0 : Double_t vref=refSpeed->GetDriftSpeedAtAnode((Double_t)iAnode);
436 0 : Double_t vcorr=h->GetBinContent(iAnode+1)*vref;
437 0 : h->SetBinContent(iAnode+1,vcorr);
438 : }
439 0 : h->Fit(fpoly,"RNQ");
440 0 : Double_t *params=new Double_t[4];
441 0 : for(Int_t iPar=0; iPar<4; iPar++) params[iPar]=fpoly->GetParameter(iPar);
442 0 : delete fpoly;
443 : return params;
444 0 : }
445 :
446 :
447 :
|