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