#include "TFile.h"
#include "TROOT.h"
#include "TClonesArray.h"
#include "AliRun.h"
#include "AliRunLoader.h"
#include "AliTOFdigit.h"
#include "AliRawReader.h"
#include "AliTOFTrigger.h"
#include "AliTRDptrgParam.h"
#include "AliTRDptrgTLMU.h"
#include "AliLog.h"
ClassImp(AliTRDptrgTLMU)
AliTRDptrgTLMU::AliTRDptrgTLMU(AliRunLoader *rl)
: TObject(),
fRunLoader(rl),
fParam(0x0),
fOperatingMode(AliTRDptrgParam::kDigits),
fInputMask(0x0),
fCMatrices(0x0),
fMultiplicity(0x0),
fOutput(0x0)
{
for (Int_t i = 0; i < 18; i++) {
this->fTOFinputBits[i] = 0;
}
this->LoadParams();
}
AliTRDptrgTLMU::AliTRDptrgTLMU(AliRunLoader *rl, AliTRDptrgParam *param,
AliTRDptrgParam::AliTRDptrgOperatingMode_t operatingMode)
: TObject(),
fRunLoader(rl),
fParam(param),
fOperatingMode(operatingMode),
fInputMask(0x0),
fCMatrices(0x0),
fMultiplicity(0x0),
fOutput(0x0)
{
for (Int_t i = 0; i < 18; i++) {
this->fTOFinputBits[i] = 0;
}
this->LoadParams();
}
AliTRDptrgTLMU::~AliTRDptrgTLMU()
{
this->fCMatrices = 0x0;
this->fMultiplicity = 0x0;
this->fOutput = 0x0;
}
Int_t* AliTRDptrgTLMU::Simulate()
{
if (this->fOperatingMode == AliTRDptrgParam::kDigits) {
this->LoadDigits();
}
else if (this->fOperatingMode == AliTRDptrgParam::kHits) {
return 0x0;
}
UInt_t temp = 0x1;
UInt_t sm = 0x0;
for (Int_t iSM = 0; iSM < 18; iSM++) {
if (this->Or(iSM)) {
sm |= temp;
}
temp <<= 1;
}
AliDebug(4, Form("Active supermodules: 0x%x", sm));
UInt_t multiplicity = this->GetMultiplicitySum();
AliDebug(4, Form("TOF/TLMU multiplicity: %d", multiplicity));
Int_t* result = new Int_t[9];
result[0] = 8;
for (Int_t iResult = 0; iResult < 8; iResult++) {
result[iResult + 1] = 0;
if (this->fOutput[iResult][0] != -1) {
for (Int_t iLine = 0; iLine < 18; iLine++) {
AliDebug(5, Form("Entry: %d, matrix: %d, line: %d, output: 0x%x",
iResult, this->fOutput[iResult][0], iLine, sm &
this->fCMatrices[this->fOutput[iResult][0]][iLine]));
if (this->GetBitVectorMultiplicity(
sm & this->fCMatrices[this->fOutput[iResult][0]][iLine]) > 1) {
result[iResult + 1] = 1;
break;
}
}
}
if (this->fOutput[iResult][1] != -1) {
AliDebug(5, Form("Entry: %d, slice: %d", iResult,
this->fOutput[iResult][1]));
if ((this->fMultiplicity[this->fOutput[iResult][1]][0] < multiplicity) &&
(this->fMultiplicity[this->fOutput[iResult][1]][1] >= multiplicity)) {
result[iResult + 1] = 1;
}
}
AliDebug(4, Form("TLMU result[%d] = %d", iResult, result[iResult + 1]));
}
return result;
}
Int_t AliTRDptrgTLMU::LoadDigits()
{
this->GetInputBits();
return 0;
}
Bool_t AliTRDptrgTLMU::LoadParams()
{
if (this->fParam == 0x0) {
AliWarning("no parameter object assigned - using default settings!");
UInt_t* imask = 0x0;
imask = new UInt_t[18];
for (Int_t i = 0; i < 18; i++) {
imask[i] = 0xFFFFFFFF;
}
this->fInputMask = imask;
this->fCMatrices = new UInt_t*[3];
this->fCMatrices[0] = new UInt_t[18];
this->fCMatrices[1] = new UInt_t[18];
this->fCMatrices[2] = new UInt_t[18];
for (UInt_t iMatrix = 0; iMatrix < 3; iMatrix++) {
for (UInt_t iSlice = 0; iSlice < 18; iSlice++) {
if (iMatrix == 0) {
if (iSlice < 9) {
this->fCMatrices[iMatrix][iSlice] = 0x201 << iSlice;
AliDebug(5, Form("fCMatrices[%d][%d]=0x%x",iMatrix,iSlice,
this->fCMatrices[iMatrix][iSlice]));
}
}
else if (iMatrix == 1) {
if (iSlice < 8) {
this->fCMatrices[iMatrix][iSlice] = 0x381 << iSlice;
}
else if (iSlice == 8) {
this->fCMatrices[iMatrix][iSlice] = 0x30101;
}
else if (iSlice == 9) {
this->fCMatrices[iMatrix][iSlice] = 0x20203;
}
else {
this->fCMatrices[iMatrix][iSlice] = 0x407 << (iSlice - 10);
}
AliDebug(5, Form("fCMatrices[%d][%d]=0x%x",iMatrix,iSlice,
this->fCMatrices[iMatrix][iSlice]));
}
else if (iMatrix == 2) {
if (iSlice < 7 ) {
this->fCMatrices[iMatrix][iSlice] = 0xF81 << iSlice;
}
else if (iSlice == 7) {
this->fCMatrices[iMatrix][iSlice] = 0x3C081;
}
else if (iSlice == 8) {
this->fCMatrices[iMatrix][iSlice] = 0x38103;
}
else if (iSlice == 9) {
this->fCMatrices[iMatrix][iSlice] = 0x30207;
}
else if (iSlice == 10) {
this->fCMatrices[iMatrix][iSlice] = 0x2040F;
}
else {
this->fCMatrices[iMatrix][iSlice] = 0x81F << (iSlice - 11);
}
AliDebug(5, Form("fCMatrices[%d][%d]=0x%x",iMatrix,iSlice,
this->fCMatrices[iMatrix][iSlice]));
}
}
}
this->fMultiplicity = new UInt_t*[9];
for (Int_t i = 0; i < 9; i++) {
this->fMultiplicity[i] = new UInt_t[2];
}
this->fMultiplicity[0][0] = 0;
this->fMultiplicity[0][1] = 10;
this->fMultiplicity[1][0] = 10;
this->fMultiplicity[1][1] = 25;
this->fMultiplicity[2][0] = 25;
this->fMultiplicity[2][1] = 50;
this->fMultiplicity[3][0] = 50;
this->fMultiplicity[3][1] = 100;
this->fMultiplicity[4][0] = 100;
this->fMultiplicity[4][1] = 200;
this->fMultiplicity[5][0] = 200;
this->fMultiplicity[5][1] = 350;
this->fMultiplicity[6][0] = 350;
this->fMultiplicity[6][1] = 400;
this->fMultiplicity[7][0] = 400;
this->fMultiplicity[7][1] = 576;
this->fMultiplicity[8][0] = 100;
this->fMultiplicity[8][1] = 576;
this->fOutput = new Int_t*[8];
for (Int_t i = 0; i < 9; i++) {
this->fOutput[i] = new Int_t[2];
this->fOutput[i][0] = -1;
this->fOutput[i][1] = -1;
}
this->fOutput[0][0] = 0;
this->fOutput[1][0] = 1;
this->fOutput[2][0] = 2;
this->fOutput[3][1] = 0;
this->fOutput[4][1] = 1;
this->fOutput[5][1] = 2;
this->fOutput[6][1] = 3;
this->fOutput[7][1] = 8;
}
else {
this->fInputMask = this->fParam->GetTLMUInputMask();
this->fCMatrices = this->fParam->GetTLMUcmatrices();
this->fMultiplicity = this->fParam->GetTLMUmultiplicity();
this->fOutput = this->fParam->GetTLMUoutput();
}
return false;
}
void AliTRDptrgTLMU::GetInputBits() {
AliTOFTrigger *toftrig = new AliTOFTrigger();
toftrig->CreateLTMMatrix();
Bool_t** map = 0x0;
map = new Bool_t*[72];
for (Int_t i=0; i < 72; i++)
map[i] = new Bool_t[8];
for (Int_t i=0; i < 72; i++)
for (Int_t j=0; j < 8; j++)
map[i][j] = kFALSE;
toftrig->GetTRDmap(map);
AliDebug(5, "AliTOFTrigger->GetTRDmap(map):");
for (Int_t i=0; i < 72; i++) {
AliDebug(5, Form("%d %d%d%d%d%d%d%d%d", i, map[i][0], map[i][1], map[i][2],
map[i][3], map[i][4], map[i][5], map[i][6], map[i][7]));
}
for (Int_t i=0; i < 18; i++) {
this->fTOFinputBits[i] = 0;
}
Int_t supermodule = -1;
UInt_t tempA = 0x00000001;
UInt_t tempC = 0x00010000;
for (Int_t iLTM = 0; iLTM < (kNLTM / 2); iLTM++) {
if (!(iLTM % 2)) {
tempA = 0x00000001;
tempC = 0x00010000;
supermodule++;
}
for (Int_t iLTMchan = 0; iLTMchan < 8; iLTMchan++) {
if (map[iLTM][iLTMchan]) {
this->fTOFinputBits[supermodule] |= tempA;
}
if (map[iLTM + 36][iLTMchan]) {
this->fTOFinputBits[supermodule] |= tempC;
}
tempA <<= 1;
tempC <<= 1;
}
}
for (Int_t iSM = 0; iSM < 18; iSM++) {
AliDebug(5, Form("fInputTOFinputBits[%d]=0x%x", iSM,
this->fTOFinputBits[iSM]));
this->fTOFinputBits[iSM] &= this->fInputMask[iSM];
}
}
Int_t AliTRDptrgTLMU::BackToBack(Int_t iSM, Int_t range) {
Int_t counterPart = -1;
if (iSM >= 9) {
counterPart = iSM - 9;
}
else {
counterPart = iSM + 9;
}
if (this->Or(iSM)) {
Int_t result = 0;
for (Int_t i = counterPart - range; i <= counterPart + range; i++) {
if ((i >= 0) && (i < 18)) {
if (Or(i)) {
result++;
}
}
else {
if (i < 0) {
if (Or(17 - i)) {
result++;
}
}
if (i > 17) {
if (Or(i - 18)) {
result++;
}
}
}
}
AliDebug(5, Form("BackToBack of %d and %d+-%d\n: %d", iSM, counterPart,
range, result));
return result;
}
else {
AliDebug(5, Form("BackToBack unsuccessful, not hit in sm%d", iSM));
return 0;
}
}
Int_t AliTRDptrgTLMU::Coincidence(Int_t iSM1, Int_t iSM2) {
if (this->Or(iSM1) && this->Or(iSM2)) {
return 1;
}
else
return 0;
}
inline Int_t AliTRDptrgTLMU::Or(Int_t iSM) {
if ((iSM >= 0) && (iSM < 18)) {
if (this->fTOFinputBits[iSM] > 0)
return 1;
else
return 0;
}
else {
return -1;
}
}
Int_t AliTRDptrgTLMU::GetMultiplicity(Int_t iSM) {
UInt_t temp = this->fTOFinputBits[iSM];
UInt_t mask = 0x01;
Int_t multiplicity = 0;
for (int iBit = 0; iBit < 32; iBit++) {
if ((mask & temp) != 0x0) {
multiplicity++;
}
mask <<= 1;
}
AliDebug(5, Form("Multiplicity of supermodule %d: %d", iSM, multiplicity));
return multiplicity;
}
Int_t AliTRDptrgTLMU::GetMultiplicitySum() {
Int_t sum = 0;
for (Int_t i = 0; i < 18; i++) {
sum += this->GetMultiplicity(i);
}
AliDebug(5, Form("Whole multiplicity: %d", sum));
return sum;
}
UInt_t AliTRDptrgTLMU::GetBitVectorMultiplicity(UInt_t BitVector) {
UInt_t result = 0;
UInt_t temp = 0x01;
for (UInt_t iBit = 0; iBit < 32; iBit++) {
if (BitVector & temp) {
result++;
}
temp <<= 1;
}
return result;
}