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() :
46 , fRestrictiveMask((0x3ffff << 11) | (0x1f << 6) | 0x3f)
52 AliTRDtrapConfigHandler::~AliTRDtrapConfigHandler()
57 void AliTRDtrapConfigHandler::ResetMCMs()
60 // Reset all MCM registers and DMEM
63 AliTRDtrapConfig *cfg = AliTRDtrapConfig::Instance();
69 Int_t AliTRDtrapConfigHandler::LoadConfig()
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
75 AliTRDtrapConfig *cfg = AliTRDtrapConfig::Instance();
77 // HC header configuration bits
78 cfg->SetTrapReg(AliTRDtrapConfig::kC15CPUA, 0x2102); // zs, deh
81 cfg->SetTrapReg(AliTRDtrapConfig::kC13CPUA, 24);
84 cfg->SetTrapReg(AliTRDtrapConfig::kFPNP, 4*10);
85 cfg->SetTrapReg(AliTRDtrapConfig::kFPTC, 0);
86 cfg->SetTrapReg(AliTRDtrapConfig::kFPBY, 0); // bypassed!
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);
93 cfg->SetTrapReg(AliTRDtrapConfig::kFGTA, 20);
94 cfg->SetTrapReg(AliTRDtrapConfig::kFGTB, 2060);
95 cfg->SetTrapReg(AliTRDtrapConfig::kFGBY, 0); // bypassed!
98 cfg->SetTrapReg(AliTRDtrapConfig::kFTAL, 200);
99 cfg->SetTrapReg(AliTRDtrapConfig::kFTLL, 0);
100 cfg->SetTrapReg(AliTRDtrapConfig::kFTLS, 200);
101 cfg->SetTrapReg(AliTRDtrapConfig::kFTBY, 0);
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);
117 // ndrift (+ 5 binary digits)
118 ltuParam.SetNtimebins(20 << 5);
119 ConfigureNTimebins();
121 // deflection + tilt correction
122 ltuParam.SetRawOmegaTau(0.16133);
125 // deflection range table
126 ltuParam.SetRawPtMin(0.1);
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]);
139 // now calculate it from PRF
140 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
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
146 for (Int_t iBin = 0; iBin < 128; iBin++)
147 cfg->SetTrapReg((AliTRDtrapConfig::TrapReg_t) (AliTRDtrapConfig::kTPL00 + iBin), 0, 0, 0, 0);
149 for (Int_t iLayer = 0; iLayer < 6; iLayer++) {
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);
157 for (Int_t iBin = 0; iBin < 128; iBin++) {
158 Int_t corr = gr.Eval(iBin) - iBin;
163 for (Int_t iStack = 0; iStack < 540/6; iStack++) {
164 cfg->SetTrapReg((AliTRDtrapConfig::TrapReg_t) (AliTRDtrapConfig::kTPL00 + iBin), corr, 6*iStack + iLayer);
170 cfg->SetTrapReg(AliTRDtrapConfig::kEBSF, 1); // 0: store filtered; 1: store unfiltered
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
179 cfg->SetTrapReg(AliTRDtrapConfig::kNES, (0x0000 << 16) | 0x1000);
184 Int_t AliTRDtrapConfigHandler::LoadConfig(TString filename, Int_t det)
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
196 Int_t ignoredLines=0;
201 AliTRDtrapConfig *cfg = AliTRDtrapConfig::Instance();
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()));
212 Int_t extali, addr, data;
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);
221 while(infile.good()) {
226 infile >> std::skipws >> cmd >> addr >> data >> extali;
227 // std::cout << "no: " << no << ", cmd " << cmd << ", extali " << extali << ", addr " << addr << ", data " << data << endl;
229 if(cmd!=999 && extali!=-1 && addr != -1 && data!= -1 && extali!=-1) {
230 if(cmd==fgkScsnCmdWrite) {
231 if ((fRestrictiveMask & rocpos) == rocpos)
232 cfg->AddValues(det, cmd, extali, addr, data);
234 else if(cmd == fgkScsnCmdRestr)
235 fRestrictiveMask = data;
236 else if(cmd == fgkScsnLTUparam)
237 ProcessLTUparam(extali, addr, data);
243 else if(!infile.eof() && !infile.good()) {
245 infile.ignore(256, '\n');
255 AliDebug(5, Form("Ignored lines: %i, ignored cmds: %i", ignoredLines, ignoredCmds));
258 if(ignoredLines>readLines)
259 AliError(Form("More than 50 %% of the input file could not be processed. Perhaps you should check the input file %s", filename.Data()));
266 void AliTRDtrapConfigHandler::ProcessLTUparam(Int_t dest, Int_t addr, UInt_t data)
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
275 case 0: // set the parameters in AliTRDtrapConfig
277 ConfigureDRange(); // deflection range
278 ConfigureNTimebins(); // timebins in the drift region
279 ConfigurePIDcorr(); // scaling parameters for the PID
282 case 1: // set variables
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;
289 // ntimbins: drift time (for 3 cm) in timebins (5 add. bin. digits)
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;
298 AliError(Form("dest %i not implemented", dest));
304 void AliTRDtrapConfigHandler::ConfigureNTimebins()
307 // Set timebins in the drift region
309 AliTRDtrapConfig::Instance()->AddValues(fDet, fgkScsnCmdWrite, 127, AliTRDtrapConfig::fgkDmemAddrNdrift, ltuParam.GetNtimebins());
314 void AliTRDtrapConfigHandler::ConfigureDyCorr()
317 // Deflection length correction
318 // due to Lorentz angle and tilted pad correction
319 // This correction is in units of padwidth / (256*32)
322 Int_t nRobs = AliTRDgeometry::GetStack(fDet) == 2 ? 6 : 8;
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);
337 void AliTRDtrapConfigHandler::ConfigureDRange()
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
346 Int_t nRobs = AliTRDgeometry::GetStack(fDet) == 2 ? 6 : 8;
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++) {
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);
368 void AliTRDtrapConfigHandler::PrintGeoTest()
371 // Prints some information about the geometry. Only for debugging
375 // for(int sm=0; sm<6; sm++) {
376 for(int stack=0; stack<5; stack++) {
377 for(int layer=0; layer<6; layer++) {
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++) {
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;
396 void AliTRDtrapConfigHandler::ConfigurePIDcorr()
399 // Calculate the MCM individual correction factors for the PID
400 // and transfer them to AliTRDtrapConfig
403 static const Int_t addrLUTcor0 = AliTRDtrapConfig::fgkDmemAddrLUTcor0;
404 static const Int_t addrLUTcor1 = AliTRDtrapConfig::fgkDmemAddrLUTcor1;
409 Int_t nRobs = AliTRDgeometry::GetStack(fDet) == 2 ? 6 : 8;
411 for (Int_t r=0; r<nRobs; r++) {
412 for(Int_t m=0; m<16; m++) {
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);