]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/AliTRDtrapConfigHandler.cxx
correct for omission
[u/mrichter/AliRoot.git] / TRD / AliTRDtrapConfigHandler.cxx
CommitLineData
5ac2e3b1 1/**************************************************************************
2 * Copyright(c) 1998-1999, 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////////////////////////////////////////////////////////////////////////////
17// //
18// MCM configuraton handler //
19// //
20// Author: U. Westerhoff //
21// //
22////////////////////////////////////////////////////////////////////////////
23
5ac2e3b1 24#include "AliTRDtrapConfigHandler.h"
25
26#include <iostream>
27#include <iomanip>
28
5ac2e3b1 29#include "AliLog.h"
30
5e86ff99 31#include "AliTRDtrapConfig.h"
5ac2e3b1 32#include "AliTRDgeometry.h"
5e86ff99 33#include "AliTRDcalibDB.h"
5ac2e3b1 34
35#include "TMath.h"
36#include "TGeoMatrix.h"
5e86ff99 37#include "TGraph.h"
5ac2e3b1 38
39using namespace std;
40
41ClassImp(AliTRDtrapConfigHandler)
42
5ac2e3b1 43AliTRDtrapConfigHandler::AliTRDtrapConfigHandler() :
5e86ff99 44 ltuParam()
5ac2e3b1 45 , fDet(0)
5e86ff99 46 , fRestrictiveMask((0x3ffff << 11) | (0x1f << 6) | 0x3f)
5ac2e3b1 47{
5e86ff99 48
5ac2e3b1 49}
50
51
52AliTRDtrapConfigHandler::~AliTRDtrapConfigHandler()
53{
5e86ff99 54
5ac2e3b1 55}
56
57void AliTRDtrapConfigHandler::ResetMCMs()
58{
59 //
60 // Reset all MCM registers and DMEM
61 //
62
63 AliTRDtrapConfig *cfg = AliTRDtrapConfig::Instance();
64 cfg->ResetRegs();
65 cfg->ResetDmem();
66}
67
68
5e86ff99 69Int_t AliTRDtrapConfigHandler::LoadConfig()
70{
71 // load a default configuration which is suitable for simulation
72 // for a detailed description of the registers see the TRAP manual
73 // if you want to resimulate tracklets on real data use the appropriate config instead
74
75 AliTRDtrapConfig *cfg = AliTRDtrapConfig::Instance();
76
77 // HC header configuration bits
78 cfg->SetTrapReg(AliTRDtrapConfig::kC15CPUA, 0x2102); // zs, deh
79
80 // no. of timebins
81 cfg->SetTrapReg(AliTRDtrapConfig::kC13CPUA, 24);
82
83 // pedestal filter
84 cfg->SetTrapReg(AliTRDtrapConfig::kFPNP, 4*10);
85 cfg->SetTrapReg(AliTRDtrapConfig::kFPTC, 0);
86 cfg->SetTrapReg(AliTRDtrapConfig::kFPBY, 0); // bypassed!
87
88 // gain filter
89 for (Int_t adc = 0; adc < 20; adc++) {
90 cfg->SetTrapReg(AliTRDtrapConfig::TrapReg_t(AliTRDtrapConfig::kFGA0+adc), 40);
91 cfg->SetTrapReg(AliTRDtrapConfig::TrapReg_t(AliTRDtrapConfig::kFGF0+adc), 15);
92 }
93 cfg->SetTrapReg(AliTRDtrapConfig::kFGTA, 20);
94 cfg->SetTrapReg(AliTRDtrapConfig::kFGTB, 2060);
95 cfg->SetTrapReg(AliTRDtrapConfig::kFGBY, 0); // bypassed!
96
97 // tail cancellation
98 cfg->SetTrapReg(AliTRDtrapConfig::kFTAL, 200);
99 cfg->SetTrapReg(AliTRDtrapConfig::kFTLL, 0);
100 cfg->SetTrapReg(AliTRDtrapConfig::kFTLS, 200);
101 cfg->SetTrapReg(AliTRDtrapConfig::kFTBY, 0);
102
103 // tracklet calculation
104 cfg->SetTrapReg(AliTRDtrapConfig::kTPQS0, 5);
105 cfg->SetTrapReg(AliTRDtrapConfig::kTPQE0, 10);
106 cfg->SetTrapReg(AliTRDtrapConfig::kTPQS1, 11);
107 cfg->SetTrapReg(AliTRDtrapConfig::kTPQE1, 20);
108 cfg->SetTrapReg(AliTRDtrapConfig::kTPFS, 5);
109 cfg->SetTrapReg(AliTRDtrapConfig::kTPFE, 20);
110 cfg->SetTrapReg(AliTRDtrapConfig::kTPVBY, 0);
111 cfg->SetTrapReg(AliTRDtrapConfig::kTPVT, 10);
112 cfg->SetTrapReg(AliTRDtrapConfig::kTPHT, 150);
113 cfg->SetTrapReg(AliTRDtrapConfig::kTPFP, 40);
114 cfg->SetTrapReg(AliTRDtrapConfig::kTPCL, 1);
115 cfg->SetTrapReg(AliTRDtrapConfig::kTPCT, 10);
116
117 // ndrift (+ 5 binary digits)
118 ltuParam.SetNtimebins(20 << 5);
119 ConfigureNTimebins();
120
121 // deflection + tilt correction
122 ltuParam.SetRawOmegaTau(0.16133);
123 ConfigureDyCorr();
124
125 // deflection range table
126 ltuParam.SetRawPtMin(0.1);
127 ConfigureDRange();
128
129 // hit position LUT
130 // reset values
131 const UShort_t lutPos[128] = {
132 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15,
133 16, 16, 16, 17, 17, 18, 18, 19, 19, 19, 20, 20, 20, 21, 21, 22, 22, 22, 23, 23, 23, 24, 24, 24, 24, 25, 25, 25, 26, 26, 26, 26,
134 27, 27, 27, 27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 27, 27, 27, 27, 26,
135 26, 26, 26, 25, 25, 25, 24, 24, 23, 23, 22, 22, 21, 21, 20, 20, 19, 18, 18, 17, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 7};
136 for (Int_t iCOG = 0; iCOG < 128; iCOG++)
137 cfg->SetTrapReg((AliTRDtrapConfig::TrapReg_t) (AliTRDtrapConfig::kTPL00 + iCOG), lutPos[iCOG]);
138
139 // now calculate it from PRF
140 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
141
142 Double_t padResponse[3]; // pad response left, central, right
143 Double_t padResponseR[3]; // pad response left, central, right
144 Double_t padResponseL[3]; // pad response left, central, right
145
146 for (Int_t iBin = 0; iBin < 128; iBin++)
147 cfg->SetTrapReg((AliTRDtrapConfig::TrapReg_t) (AliTRDtrapConfig::kTPL00 + iBin), 0, 0, 0, 0);
148
149 for (Int_t iLayer = 0; iLayer < 6; iLayer++) {
150 TGraph gr(128);
151 for (Int_t iBin = 0; iBin < 256*0.5; iBin++) {
152 cal->PadResponse(1., iBin*1./256., iLayer, padResponse);
153 cal->PadResponse(1., iBin*1./256.-1., iLayer, padResponseR);
154 cal->PadResponse(1., iBin*1./256.+1., iLayer, padResponseL);
155 gr.SetPoint(iBin, (0.5 * (padResponseR[1] - padResponseL[1])/padResponse[1] * 256), iBin);
156 }
157 for (Int_t iBin = 0; iBin < 128; iBin++) {
67c58c26 158 Int_t corr = (Int_t) (gr.Eval(iBin)) - iBin;
5e86ff99 159 if (corr < 0)
160 corr = 0;
161 else if (corr > 31)
162 corr = 31;
163 for (Int_t iStack = 0; iStack < 540/6; iStack++) {
164 cfg->SetTrapReg((AliTRDtrapConfig::TrapReg_t) (AliTRDtrapConfig::kTPL00 + iBin), corr, 6*iStack + iLayer);
165 }
166 }
167 }
168
169 // event buffer
170 cfg->SetTrapReg(AliTRDtrapConfig::kEBSF, 1); // 0: store filtered; 1: store unfiltered
171
172 // zs applied to data stored in event buffer (sel. by EBSF)
173 cfg->SetTrapReg(AliTRDtrapConfig::kEBIS, 15 << 2); // single indicator threshold (plus two digits)
174 cfg->SetTrapReg(AliTRDtrapConfig::kEBIT, 30 << 2); // sum indicator threshold (plus two digits)
175 cfg->SetTrapReg(AliTRDtrapConfig::kEBIL, 0xf0); // lookup table
176 cfg->SetTrapReg(AliTRDtrapConfig::kEBIN, 0); // neighbour sensitivity
177
178 // raw data
179 cfg->SetTrapReg(AliTRDtrapConfig::kNES, (0x0000 << 16) | 0x1000);
180
181 return 0;
182}
183
5ac2e3b1 184Int_t AliTRDtrapConfigHandler::LoadConfig(TString filename, Int_t det)
185{
186 //
187 // load a TRAP configuration from a file
188 // The file format is the format created by the standalone
189 // command coder scc / show_cfdat but without the running number
190 // scc /show_cfdat adds as the first column
191 // which are two tools to inspect/export configurations from wingDB
192 //
193
194
195 fDet = det;
196 Int_t ignoredLines=0;
197 Int_t ignoredCmds=0;
198 Int_t readLines=0;
199
200
201 AliTRDtrapConfig *cfg = AliTRDtrapConfig::Instance();
202
203 AliDebug(5, Form("Processing file %s", filename.Data()));
204 std::ifstream infile;
205 infile.open(filename.Data(), std::ifstream::in);
206 if (!infile.is_open()) {
207 AliError(Form("Can not open MCM configuration file %s", filename.Data()));
208 return kFALSE;
209 }
210
211 UInt_t cmd;
212 Int_t extali, addr, data;
213
5e86ff99 214 // reset restrictive mask
215 fRestrictiveMask = (0x3ffff << 11) | (0x1f << 6) | 0x3f;
216 Int_t sec = AliTRDgeometry::GetSector(fDet);
217 Int_t stack = AliTRDgeometry::GetStack(fDet);
218 Int_t layer = AliTRDgeometry::GetLayer(fDet);
219 UInt_t rocpos = (1 << (sec+11)) | (1 << (stack+6)) | (1 << layer);
220
5ac2e3b1 221 while(infile.good()) {
222 cmd=999;
223 extali=-1;
224 addr=-1;
225 data=-1;
226 infile >> std::skipws >> cmd >> addr >> data >> extali;
227 // std::cout << "no: " << no << ", cmd " << cmd << ", extali " << extali << ", addr " << addr << ", data " << data << endl;
228
229 if(cmd!=999 && extali!=-1 && addr != -1 && data!= -1 && extali!=-1) {
5e86ff99 230 if(cmd==fgkScsnCmdWrite) {
231 if ((fRestrictiveMask & rocpos) == rocpos)
5ac2e3b1 232 cfg->AddValues(det, cmd, extali, addr, data);
5e86ff99 233 }
234 else if(cmd == fgkScsnCmdRestr)
235 fRestrictiveMask = data;
5ac2e3b1 236 else if(cmd == fgkScsnLTUparam)
237 ProcessLTUparam(extali, addr, data);
238 else
239 ignoredCmds++;
240
241 readLines++;
242 }
243 else if(!infile.eof() && !infile.good()) {
244 infile.clear();
245 infile.ignore(256, '\n');
246 ignoredLines++;
247 }
248
249 if(!infile.eof())
250 infile.clear();
251 }
252
253 infile.close();
254
255 AliDebug(5, Form("Ignored lines: %i, ignored cmds: %i", ignoredLines, ignoredCmds));
256
257
258 if(ignoredLines>readLines)
ff792017 259 AliError(Form("More than 50 %% of the input file could not be processed. Perhaps you should check the input file %s", filename.Data()));
5ac2e3b1 260
261
262 return kTRUE;
263}
264
265
5ac2e3b1 266void AliTRDtrapConfigHandler::ProcessLTUparam(Int_t dest, Int_t addr, UInt_t data)
267{
268 //
269 // Process the LTU parameters and stores them in internal class variables
270 // or transfer the stored values to AliTRDtrapConfig, depending on the dest parameter
271 //
272
273 switch (dest) {
274
275 case 0: // set the parameters in AliTRDtrapConfig
276 ConfigureDyCorr();
277 ConfigureDRange(); // deflection range
278 ConfigureNTimebins(); // timebins in the drift region
279 ConfigurePIDcorr(); // scaling parameters for the PID
280 break;
281
282 case 1: // set variables
283 switch (addr) {
284
5e86ff99 285 case 0: ltuParam.SetPtMin(data); break; // pt_min in GeV/c (*1000)
286 case 1: ltuParam.SetMagField(data); break; // B in T (*1000)
287 case 2: ltuParam.SetOmegaTau(data); break; // omega*tau
288 case 3: ltuParam.SetNtimebins(data); break;
5ac2e3b1 289 // ntimbins: drift time (for 3 cm) in timebins (5 add. bin. digits)
5e86ff99 290 case 4: ltuParam.SetScaleQ0(data); break;
291 case 5: ltuParam.SetScaleQ1(data); break;
292 case 6: ltuParam.SetLengthCorrectionEnable(data); break;
293 case 7: ltuParam.SetTiltCorrectionEnable(data); break;
5ac2e3b1 294 }
295 break;
296
297 default:
298 AliError(Form("dest %i not implemented", dest));
299 }
300
301}
302
303
304void AliTRDtrapConfigHandler::ConfigureNTimebins()
305{
306 //
307 // Set timebins in the drift region
308 //
5e86ff99 309 AliTRDtrapConfig::Instance()->AddValues(fDet, fgkScsnCmdWrite, 127, AliTRDtrapConfig::fgkDmemAddrNdrift, ltuParam.GetNtimebins());
5ac2e3b1 310}
311
312
313
314void AliTRDtrapConfigHandler::ConfigureDyCorr()
315{
316 //
317 // Deflection length correction
318 // due to Lorentz angle and tilted pad correction
319 // This correction is in units of padwidth / (256*32)
320 //
321
5e86ff99 322 Int_t nRobs = AliTRDgeometry::GetStack(fDet) == 2 ? 6 : 8;
323
324 for (Int_t r = 0; r < nRobs; r++) {
325 for (Int_t m = 0; m < 16; m++) {
326 Int_t dest = 1<<10 | r<<7 | m;
327 Int_t dyCorrInt = ltuParam.GetDyCorrection(fDet, r, m);
328 AliTRDtrapConfig::Instance()->AddValues(fDet, fgkScsnCmdWrite, dest, AliTRDtrapConfig::fgkDmemAddrDeflCorr, dyCorrInt);
5ac2e3b1 329 }
5e86ff99 330 }
5ac2e3b1 331}
332
333
334
335
336
337void AliTRDtrapConfigHandler::ConfigureDRange()
338{
339 //
340 // deflection range LUT
341 // range calculated according to B-field (in T) and pt_min (in GeV/c)
342 // if pt_min < 0.1 GeV/c the maximal allowed range for the tracklet
343 // deflection (-64..63) is used
344 //
345
5e86ff99 346 Int_t nRobs = AliTRDgeometry::GetStack(fDet) == 2 ? 6 : 8;
5ac2e3b1 347
5e86ff99 348 Int_t dyMinInt;
349 Int_t dyMaxInt;
5ac2e3b1 350
351 for (Int_t r = 0; r < nRobs; r++) {
352 for (Int_t m = 0; m < 16; m++) {
353 for (Int_t c = 0; c < 18; c++) {
354
5e86ff99 355 // cout << "maxdefl: " << maxDeflAngle << ", localPhi " << localPhi << endl;
356 // cout << "r " << r << ", m" << m << ", c " << c << ", min angle: " << localPhi-maxDeflAngle << ", max: " << localPhi+maxDeflAngle
357 // << ", min int: " << dyMinInt << ", max int: " << dyMaxInt << endl;
358 Int_t dest = 1<<10 | r<<7 | m;
359 Int_t lutAddr = AliTRDtrapConfig::fgkDmemAddrDeflCutStart + 2*c;
360 ltuParam.GetDyRange(fDet, r, m, c, dyMinInt, dyMaxInt);
361 AliTRDtrapConfig::Instance()->AddValues(fDet, fgkScsnCmdWrite, dest, lutAddr+0, dyMinInt);
362 AliTRDtrapConfig::Instance()->AddValues(fDet, fgkScsnCmdWrite, dest, lutAddr+1, dyMaxInt);
5ac2e3b1 363 }
364 }
365 }
366}
367
368void AliTRDtrapConfigHandler::PrintGeoTest()
369{
370 //
371 // Prints some information about the geometry. Only for debugging
372 //
373
5ac2e3b1 374 int sm=0;
375 // for(int sm=0; sm<6; sm++) {
376 for(int stack=0; stack<5; stack++) {
377 for(int layer=0; layer<6; layer++) {
378
379 fDet = sm*30+stack*6+layer;
380 for (Int_t r = 0; r < 6; r++) {
381 for (Int_t m = 0; m < 16; m++) {
382 for (Int_t c = 7; c < 8; c++) {
5e86ff99 383 cout << stack << ";" << layer << ";" << r << ";" << m
384 << ";" << ltuParam.GetX(fDet, r, m)
385 << ";" << ltuParam.GetLocalY(fDet, r, m, c)
386 << ";" << ltuParam.GetLocalZ(fDet, r, m) << endl;
5ac2e3b1 387 }
388 }
389 }
390 }
391 }
392 // }
393}
394
395
5ac2e3b1 396void AliTRDtrapConfigHandler::ConfigurePIDcorr()
397{
398 //
399 // Calculate the MCM individual correction factors for the PID
400 // and transfer them to AliTRDtrapConfig
401 //
402
403 static const Int_t addrLUTcor0 = AliTRDtrapConfig::fgkDmemAddrLUTcor0;
404 static const Int_t addrLUTcor1 = AliTRDtrapConfig::fgkDmemAddrLUTcor1;
405
406 UInt_t cor0;
407 UInt_t cor1;
408
5e86ff99 409 Int_t nRobs = AliTRDgeometry::GetStack(fDet) == 2 ? 6 : 8;
5ac2e3b1 410
411 for (Int_t r=0; r<nRobs; r++) {
412 for(Int_t m=0; m<16; m++) {
5e86ff99 413 Int_t dest = 1<<10 | r<<7 | m;
414 ltuParam.GetCorrectionFactors(fDet, r, m, 0, cor0, cor1);
415 AliTRDtrapConfig::Instance()->AddValues(fDet, fgkScsnCmdWrite, dest, addrLUTcor0, cor0);
416 AliTRDtrapConfig::Instance()->AddValues(fDet, fgkScsnCmdWrite, dest, addrLUTcor1, cor1);
417 }
418 }
5ac2e3b1 419}