Adding the interface to AMORE.
[u/mrichter/AliRoot.git] / ITS / AliITSPreprocessorSDD.cxx
CommitLineData
979b5a5f 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 **************************************************************************/
e56160b8 15
20f3f947 16/* $Id$ */
5a9fd7dd 17
979b5a5f 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
e56160b8 26#include "AliITSPreprocessorSDD.h"
27#include "AliITSCalibrationSDD.h"
18da6e54 28#include "AliITSDriftSpeedSDD.h"
29#include "AliITSDriftSpeedArraySDD.h"
cfaccd71 30#include "AliITSDCSAnalyzerSDD.h"
e56160b8 31#include "AliShuttleInterface.h"
979b5a5f 32#include "AliCDBEntry.h"
e56160b8 33#include "AliCDBMetaData.h"
34#include "TObjArray.h"
e56160b8 35#include "AliLog.h"
dfb8947f 36#include <TObjString.h>
37#include <TSystem.h>
38#include <TList.h>
e56160b8 39
7537d03c 40const TString AliITSPreprocessorSDD::fgkNameHistoPedestals = "hpedestal";
41const TString AliITSPreprocessorSDD::fgkNameHistoNoise = "hnoise";
e56160b8 42ClassImp(AliITSPreprocessorSDD)
43
15b67cdc 44//______________________________________________________________________
45AliITSPreprocessorSDD::AliITSPreprocessorSDD( AliShuttleInterface* shuttle):
46 AliPreprocessor("SDD", shuttle)
47{
48 // constructor
49 AddRunType("PULSER");
50 AddRunType("INJECTOR");
51 AddRunType("PHYSICS");
52}
e56160b8 53
317e638f 54//______________________________________________________________________
cfaccd71 55UInt_t AliITSPreprocessorSDD::Process(TMap* dcsAliasMap){
e56160b8 56
979b5a5f 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 }
e56160b8 68
979b5a5f 69 //preprocessing
18da6e54 70 TString runType = GetRunType();
461c9263 71 Int_t retcode=0;
c2bd28b6 72
ad2585ed 73 if (runType == "PULSER"){
317e638f 74 retcode=ProcessPulser(ddlmap);
75 }else if(runType== "INJECTOR"){
76 retcode=ProcessInjector(ddlmap);
317e638f 77 }
461c9263 78 if(retcode!=0) return retcode;
79
80 Bool_t retcodedcs =ProcessDCSDataPoints(dcsAliasMap);
81 if(retcodedcs) return 0;
82 else return 1;
83
317e638f 84}
85//______________________________________________________________________
461c9263 86UInt_t AliITSPreprocessorSDD::ProcessPulser(AliITSDDLModuleMapSDD* ddlmap){
317e638f 87 // Process FXS files from PULSER run (baseline, noise, gain)
461c9263 88 // returns 0 in case of success,
89 // 1 in case of storage error,
90 // 2 in case of error with input files
317e638f 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;
e7610d19 97 Int_t th,tl;
317e638f 98 Int_t numOfBadChannels[kNumberOfSDD];
18da6e54 99
317e638f 100 TList* sourceList = GetFileSources(kDAQ, "SDD_Calib");
101 if (!sourceList){
102 Log("Error: no sources found for SDD_Calib");
103 return 2;
104 }
dfb8947f 105
317e638f 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;
18da6e54 113 }
317e638f 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");
9f963593 126 cal->SetUseCorrectionMaps(0,0); // temporary disabling of maps
317e638f 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);
20f3f947 138 if(!isgoodmod) cal->SetBad();
e7610d19 139 fscanf(basFil,"%d\n",&th);
140 fscanf(basFil,"%d\n",&tl);
20f3f947 141 cal->SetZSLowThreshold(isid,tl);
142 cal->SetZSHighThreshold(isid,th);
317e638f 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]++;
979b5a5f 151 }
20f3f947 152 cal->SetBaseline(ich,baseline-basoff);
317e638f 153 cal->SetNoiseAfterElectronics(ich,rawnoise);
154 cal->SetGain(ich,gain);
979b5a5f 155 }
317e638f 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);
c2bd28b6 161 }
317e638f 162 calSDD.AddAt(cal,modID);
e56160b8 163 }
317e638f 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);
461c9263 170 if(retCode) return 0;
171 else return 1;
317e638f 172}
173//______________________________________________________________________
461c9263 174UInt_t AliITSPreprocessorSDD::ProcessInjector(AliITSDDLModuleMapSDD* ddlmap){
317e638f 175 // Process FXS files from injector events (INJECTOR or PHYSICS runs)
461c9263 176 // returns 0 in case of success,
177 // 1 in case of storage error,
178 // 2 in case of error with input files
317e638f 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;
9f963593 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;
e56160b8 195
317e638f 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));
18da6e54 207 return 2;
208 }
317e638f 209 sprintf(command,"tar -xf %s",tarName.Data());
210 gSystem->Exec(command);
211 ind++;
212 }
213 delete sourceList;
9f963593 214
215
317e638f 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++){
9f963593 222 modSet[2*modID+isid]=0;
317e638f 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);
979b5a5f 230 vdrift.AddAt(arr,2*modID+isid);
317e638f 231 continue;
232 }
233 fscanf(injFil,"%d",&polDeg);
234 while (!feof(injFil)){
9f963593 235 fscanf(injFil,"%d %d ",&evNumb,&timeStamp);
317e638f 236 if(feof(injFil)) break;
9f963593 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 }
18da6e54 249 }
9f963593 250 if(modSet[2*modID+isid]) vdrift.AddAt(arr,2*modID+isid);
18da6e54 251 }
252 }
cfaccd71 253 }
9f963593 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
317e638f 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);
461c9263 277 if(retCode) return 0;
278 else return 1;
317e638f 279}
280//______________________________________________________________________
281Bool_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;
e56160b8 297}