1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 ////////////////////////////////////////////////////////////////////////////
18 // MCM configuraton handler //
20 // Author: U. Westerhoff //
22 ////////////////////////////////////////////////////////////////////////////
24 #include "AliTRDtrapConfigHandler.h"
31 #include "AliTRDtrapConfig.h"
32 #include "AliTRDgeometry.h"
33 #include "AliTRDcalibDB.h"
36 #include "TGeoMatrix.h"
41 ClassImp(AliTRDtrapConfigHandler)
43 AliTRDtrapConfigHandler::AliTRDtrapConfigHandler() :
45 , fRestrictiveMask((0x3ffff << 11) | (0x1f << 6) | 0x3f)
51 AliTRDtrapConfigHandler::~AliTRDtrapConfigHandler()
56 void AliTRDtrapConfigHandler::ResetMCMs()
59 // Reset all MCM registers and DMEM
62 AliTRDtrapConfig *cfg = AliTRDtrapConfig::Instance();
68 Int_t AliTRDtrapConfigHandler::LoadConfig()
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
74 AliTRDtrapConfig *cfg = AliTRDtrapConfig::Instance();
76 // HC header configuration bits
77 cfg->SetTrapReg(AliTRDtrapConfig::kC15CPUA, 0x2102); // zs, deh
80 cfg->SetTrapReg(AliTRDtrapConfig::kC13CPUA, 24);
83 cfg->SetTrapReg(AliTRDtrapConfig::kFPNP, 4*10);
84 cfg->SetTrapReg(AliTRDtrapConfig::kFPTC, 0);
85 cfg->SetTrapReg(AliTRDtrapConfig::kFPBY, 0); // bypassed!
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);
92 cfg->SetTrapReg(AliTRDtrapConfig::kFGTA, 20);
93 cfg->SetTrapReg(AliTRDtrapConfig::kFGTB, 2060);
94 cfg->SetTrapReg(AliTRDtrapConfig::kFGBY, 0); // bypassed!
97 cfg->SetTrapReg(AliTRDtrapConfig::kFTAL, 200);
98 cfg->SetTrapReg(AliTRDtrapConfig::kFTLL, 0);
99 cfg->SetTrapReg(AliTRDtrapConfig::kFTLS, 200);
100 cfg->SetTrapReg(AliTRDtrapConfig::kFTBY, 0);
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);
116 // ndrift (+ 5 binary digits)
117 ltuParam.SetNtimebins(20 << 5);
118 // deflection + tilt correction
119 ltuParam.SetRawOmegaTau(0.16133);
120 // deflection range table
121 ltuParam.SetRawPtMin(0.1);
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);
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
139 // ****** hit position LUT
141 // now calculate it from PRF
142 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
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
148 for (Int_t iBin = 0; iBin < 128; iBin++)
149 cfg->SetTrapReg((AliTRDtrapConfig::TrapReg_t) (AliTRDtrapConfig::kTPL00 + iBin), 0, 0, 0, 0);
151 for (Int_t iLayer = 0; iLayer < 6; iLayer++) {
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);
159 for (Int_t iBin = 0; iBin < 128; iBin++) {
160 Int_t corr = (Int_t) (gr.Eval(iBin)) - iBin;
165 for (Int_t iStack = 0; iStack < 540/6; iStack++) {
166 cfg->SetTrapReg((AliTRDtrapConfig::TrapReg_t) (AliTRDtrapConfig::kTPL00 + iBin), corr, 6*iStack + iLayer);
170 // ****** hit position LUT configuration end
173 cfg->SetTrapReg(AliTRDtrapConfig::kEBSF, 1); // 0: store filtered; 1: store unfiltered
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
182 cfg->SetTrapReg(AliTRDtrapConfig::kNES, (0x0000 << 16) | 0x1000);
188 Int_t AliTRDtrapConfigHandler::LoadConfig(TString filename)
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
198 Int_t ignoredLines=0;
203 AliTRDtrapConfig *cfg = AliTRDtrapConfig::Instance();
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()));
214 Int_t extali, addr, data;
216 // reset restrictive mask
217 fRestrictiveMask = (0x3ffff << 11) | (0x1f << 6) | 0x3f;
219 while(infile.good()) {
224 infile >> std::skipws >> cmd >> addr >> data >> extali;
226 if(cmd!=999 && extali!=-1 && addr != -1 && data!= -1 && extali!=-1) {
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 AliDebug(1, Form("checking restriction: mask=0x%08x, rocpos=0x%08x", fRestrictiveMask, rocpos));
232 if ((fRestrictiveMask & rocpos) == rocpos) {
233 AliDebug(1, Form("match: %i %i %i %i", cmd, extali, addr, data));
234 cfg->AddValues(det, cmd, extali, addr, data);
239 else if(cmd == fgkScsnLTUparam) {
240 ProcessLTUparam(extali, addr, data);
243 else if(cmd == fgkScsnCmdRestr) {
244 fRestrictiveMask = data;
245 AliDebug(1, Form("updated restrictive mask to 0x%08x", fRestrictiveMask));
248 else if((cmd == fgkScsnCmdReset) ||
249 (cmd == fgkScsnCmdRobReset)) {
253 else if (cmd == fgkScsnCmdSetHC) {
254 Int_t fullVersion = ((data & 0x7F00) >> 1) | (data & 0x7f);
256 for (Int_t iDet = 0; iDet < AliTRDgeometry::Ndet(); iDet++) {
257 Int_t smls = (AliTRDgeometry::GetSector(iDet) << 6) | (AliTRDgeometry::GetLayer(iDet) << 3) | AliTRDgeometry::GetStack(iDet);
259 for (Int_t iRob = 0; iRob < 8; iRob++) {
261 cfg->SetTrapReg(AliTRDtrapConfig::kC14CPUA, 0xc << 16, iDet, iRob, 17);
262 cfg->SetTrapReg(AliTRDtrapConfig::kC15CPUA, ((1<<29) | (fullVersion<<15) | (1<<12) | (smls<<1) | (iRob%2)), iDet, iRob, 17);
265 cfg->SetTrapReg(AliTRDtrapConfig::kC14CPUA, 0, iDet, iRob, 16);
266 cfg->SetTrapReg(AliTRDtrapConfig::kC15CPUA, ((1<<29) | (fullVersion<<15) | (1<<12) | (smls<<1) | (iRob%2)), iDet, iRob, 16);
268 // and now for the others
269 for (Int_t iMcm = 0; iMcm < 16; iMcm++) {
270 cfg->SetTrapReg(AliTRDtrapConfig::kC14CPUA, iMcm | (iRob << 4) | (3 << 16), iDet, iRob, iMcm);
271 cfg->SetTrapReg(AliTRDtrapConfig::kC15CPUA, ((1<<29) | (fullVersion<<15) | (1<<12) | (smls<<1) | (iRob%2)), iDet, iRob, iMcm);
277 else if((cmd == fgkScsnCmdRead) ||
278 (cmd == fgkScsnCmdPause) ||
279 (cmd == fgkScsnCmdPtrg) ||
280 (cmd == fgkScsnCmdHwPtrg) ||
281 (cmd == fgkScsnCmdRobPower) ||
282 (cmd == fgkScsnCmdTtcRx) ||
283 (cmd == fgkScsnCmdMcmTemp) ||
284 (cmd == fgkScsnCmdOri) ||
285 (cmd == fgkScsnCmdPM) ) {
286 AliDebug(2, Form("ignored SCSN command: %i %i %i %i", cmd, addr, data, extali));
290 AliWarning(Form("unknown SCSN command: %i %i %i %i", cmd, addr, data, extali));
297 else if(!infile.eof() && !infile.good()) {
299 infile.ignore(256, '\n');
309 AliDebug(5, Form("Ignored lines: %i, ignored cmds: %i", ignoredLines, ignoredCmds));
312 if(ignoredLines>readLines)
313 AliError(Form("More than 50 %% of the input file could not be processed. Perhaps you should check the input file %s", filename.Data()));
320 void AliTRDtrapConfigHandler::ProcessLTUparam(Int_t dest, Int_t addr, UInt_t data)
323 // Process the LTU parameters and stores them in internal class variables
324 // or transfer the stored values to AliTRDtrapConfig, depending on the dest parameter
329 case 0: // set the parameters in AliTRDtrapConfig
330 for(Int_t det=0; det<AliTRDgeometry::Ndet(); det++) {
331 ConfigureDyCorr(det);
332 ConfigureDRange(det); // deflection range
333 ConfigureNTimebins(det); // timebins in the drift region
334 ConfigurePIDcorr(det); // scaling parameters for the PID
338 case 1: // set variables
341 case 0: ltuParam.SetPtMin(data); break; // pt_min in GeV/c (*1000)
342 case 1: ltuParam.SetMagField(data); break; // B in T (*1000)
343 case 2: ltuParam.SetOmegaTau(data); break; // omega*tau
344 case 3: ltuParam.SetNtimebins(data); break;
345 // ntimbins: drift time (for 3 cm) in timebins (5 add. bin. digits)
346 case 4: ltuParam.SetScaleQ0(data); break;
347 case 5: ltuParam.SetScaleQ1(data); break;
348 case 6: ltuParam.SetLengthCorrectionEnable(data); break;
349 case 7: ltuParam.SetTiltCorrectionEnable(data); break;
354 AliError(Form("dest %i not implemented", dest));
360 void AliTRDtrapConfigHandler::ConfigureNTimebins(Int_t det)
363 // Set timebins in the drift region
365 AliTRDtrapConfig::Instance()->AddValues(det, fgkScsnCmdWrite, 127, AliTRDtrapConfig::fgkDmemAddrNdrift, ltuParam.GetNtimebins());
370 void AliTRDtrapConfigHandler::ConfigureDyCorr(Int_t det)
373 // Deflection length correction
374 // due to Lorentz angle and tilted pad correction
375 // This correction is in units of padwidth / (256*32)
378 Int_t nRobs = AliTRDgeometry::GetStack(det) == 2 ? 6 : 8;
380 for (Int_t r = 0; r < nRobs; r++) {
381 for (Int_t m = 0; m < 16; m++) {
382 Int_t dest = 1<<10 | r<<7 | m;
383 Int_t dyCorrInt = ltuParam.GetDyCorrection(det, r, m);
384 AliTRDtrapConfig::Instance()->AddValues(det, fgkScsnCmdWrite, dest, AliTRDtrapConfig::fgkDmemAddrDeflCorr, dyCorrInt);
393 void AliTRDtrapConfigHandler::ConfigureDRange(Int_t det)
396 // deflection range LUT
397 // range calculated according to B-field (in T) and pt_min (in GeV/c)
398 // if pt_min < 0.1 GeV/c the maximal allowed range for the tracklet
399 // deflection (-64..63) is used
402 Int_t nRobs = AliTRDgeometry::GetStack(det) == 2 ? 6 : 8;
407 for (Int_t r = 0; r < nRobs; r++) {
408 for (Int_t m = 0; m < 16; m++) {
409 for (Int_t c = 0; c < 18; c++) {
411 // cout << "maxdefl: " << maxDeflAngle << ", localPhi " << localPhi << endl;
412 // cout << "r " << r << ", m" << m << ", c " << c << ", min angle: " << localPhi-maxDeflAngle << ", max: " << localPhi+maxDeflAngle
413 // << ", min int: " << dyMinInt << ", max int: " << dyMaxInt << endl;
414 Int_t dest = 1<<10 | r<<7 | m;
415 Int_t lutAddr = AliTRDtrapConfig::fgkDmemAddrDeflCutStart + 2*c;
416 ltuParam.GetDyRange(det, r, m, c, dyMinInt, dyMaxInt);
417 AliTRDtrapConfig::Instance()->AddValues(det, fgkScsnCmdWrite, dest, lutAddr+0, dyMinInt);
418 AliTRDtrapConfig::Instance()->AddValues(det, fgkScsnCmdWrite, dest, lutAddr+1, dyMaxInt);
424 void AliTRDtrapConfigHandler::PrintGeoTest()
427 // Prints some information about the geometry. Only for debugging
431 // for(int sm=0; sm<6; sm++) {
432 for(int stack=0; stack<5; stack++) {
433 for(int layer=0; layer<6; layer++) {
435 Int_t det = sm*30+stack*6+layer;
436 for (Int_t r = 0; r < 6; r++) {
437 for (Int_t m = 0; m < 16; m++) {
438 for (Int_t c = 7; c < 8; c++) {
439 cout << stack << ";" << layer << ";" << r << ";" << m
440 << ";" << ltuParam.GetX(det, r, m)
441 << ";" << ltuParam.GetLocalY(det, r, m, c)
442 << ";" << ltuParam.GetLocalZ(det, r, m) << endl;
452 void AliTRDtrapConfigHandler::ConfigurePIDcorr(Int_t det)
455 // Calculate the MCM individual correction factors for the PID
456 // and transfer them to AliTRDtrapConfig
459 static const Int_t addrLUTcor0 = AliTRDtrapConfig::fgkDmemAddrLUTcor0;
460 static const Int_t addrLUTcor1 = AliTRDtrapConfig::fgkDmemAddrLUTcor1;
465 Int_t nRobs = AliTRDgeometry::GetStack(det) == 2 ? 6 : 8;
467 for (Int_t r=0; r<nRobs; r++) {
468 for(Int_t m=0; m<16; m++) {
469 Int_t dest = 1<<10 | r<<7 | m;
470 ltuParam.GetCorrectionFactors(det, r, m, 9, cor0, cor1);
471 AliTRDtrapConfig::Instance()->AddValues(det, fgkScsnCmdWrite, dest, addrLUTcor0, cor0);
472 AliTRDtrapConfig::Instance()->AddValues(det, fgkScsnCmdWrite, dest, addrLUTcor1, cor1);