Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ constexpr int NSECTOR = 18; // the number of sectors
constexpr int NSTACK = 5; // the number of stacks per sector
constexpr int NLAYER = 6; // the number of layers
constexpr int NCHAMBERPERSEC = 30; // the number of chambers per sector
constexpr int NHCPERSEC = 60; // the number of half-chambers per sector
constexpr int MAXCHAMBER = 540; // the maximum number of installed chambers
constexpr int MAXHALFCHAMBER = 1080; // the maximum number of installed half-chambers
constexpr int NCHAMBER = 521; // the number of chambers actually installed
constexpr int NHALFCRU = 72; // the number of half cru (link bundles)
constexpr int NLINKSPERHALFCRU = 15; // the number of links per half cru or cru end point.
constexpr int NRU = 36; // the number of CRU we have
constexpr int NLINKSPERCRU = 30; // the number of links per CRU (two CRUs serve one supermodule)
constexpr int NCRU = 36; // the number of CRU we have
constexpr int NFLP = 12; // the number of FLP we have.
constexpr int NCRUPERFLP = 3; // the number of CRU per FLP
constexpr int TRDLINKID = 15; // hard coded link id, specific to TRD
Expand Down Expand Up @@ -77,6 +79,7 @@ constexpr int CRUPADDING32 = 0xeeeeeeee; // padding word used in the cru.
constexpr int CHANNELNRNOTRKLT = 23; // this marks channels in the ADC mask which don't contribute to a tracklet
constexpr int NOTRACKLETFIT = 31; // this value is assigned to the fit pointer in case no tracklet is available
constexpr int TRACKLETENDMARKER = 0x10001000; // marker for the end of tracklets in raw data, 2 of these.
constexpr int PADDINGWORD = 0xeeeeeeee; // half-CRU links will be padded with this words to get an even number of 256bit words
constexpr int DIGITENDMARKER = 0x0; // marker for the end of digits in raw data, 2 of these
constexpr int MAXDATAPERLINK32 = 13824; // max number of 32 bit words per link ((21x12+2+4)*64) 64 mcm, 21 channels, 10 words per channel 2 header words(DigitMCMHeader DigitMCMADCmask) 4 words for tracklets.
constexpr int MAXDATAPERLINK256 = 1728; // max number of linkwords per cru link. (256bit words)
Expand Down
72 changes: 39 additions & 33 deletions DataFormats/Detectors/TRD/include/DataFormatsTRD/HelperMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,53 +94,59 @@ struct HelperMethods {
return (layer + stack * constants::NLAYER + sector * constants::NLAYER * constants::NSTACK);
}

static int getORIinSuperModule(int detector, int readoutboard)
static int getORIinSuperModule(int hcid)
{
//given a detector and readoutboard
// given a half chamber ID compute the link ID from [0..59]
// where link ID [0..29] is for A-side CRU and [30..59] for C-side CRU
int ori = -1;
int trdstack = HelperMethods::getStack(detector);
int trdlayer = HelperMethods::getLayer(detector);
int side = HelperMethods::getROBSide(readoutboard);
//TODO ccdb lookup of detector/stack/layer/side for link id.
bool aside = false;
if (trdstack == 0 || trdstack == 1) {
aside = true; //aside
} else {
if (trdstack != 2) {
aside = false; //cside
} else {
if (side == 0) {
aside = true; //stack
} else {
aside = false; //stack2, halfchamber 1
}
}
int stack = getStack(hcid / 2);
int layer = getLayer(hcid / 2);
int side = (hcid % 2 == 0) ? 0 : 1;
bool isAside = false;
if (stack < 2 || (stack == 2 && side == 0)) {
isAside = true;
}
if (aside) {
ori = trdstack * 12 + (5 - trdlayer + side * 5) + trdlayer / 6 + side; // <- that is correct for A side at least for now, probably not for very long LUT as that will come form CCDB ni anycase.
if (isAside) {
ori = stack * constants::NLAYER * 2 + side * constants::NLAYER + 5 - layer;
} else {
//cside
int newside = side;
if (trdstack == 2) {
newside = 0; // the last part of C side CRU is a special case.
// C-side
ori = (4 - stack) * constants::NLAYER * 2 + side * constants::NLAYER + 5 - layer;
if (stack == 2) {
ori -= constants::NLAYER;
}
ori = (4 - trdstack) * 12 + (5 - trdlayer + newside * 5) + trdlayer / 6 + newside;
ori += 30; // 30 to offset if from the a side link , 69 links in total
ori += constants::NLINKSPERCRU;
}
//see TDP for explanation of mapping TODO should probably come from CCDB
// TODO: put mapping into TDP and prepare for alternative mapping (CCDB?)
return ori;
}

static int getHCIDFromLinkID(int link)
{
// link = halfcrulink [0..14] + halfcru [0..71] * constants::NLINKSPERHALFCRU (15) -> [0..1079]

int sector = link / constants::NHCPERSEC;
int linkSector = link % constants::NHCPERSEC; // [0..59]
int linkCRU = linkSector % constants::NLINKSPERCRU; // [0..29]
int stack = linkCRU / (constants::NLAYER * 2);
int layer = 5 - (linkCRU % constants::NLAYER);
int side = (linkCRU / constants::NLAYER) % 2;
if (linkSector >= constants::NLINKSPERCRU) {
// C-side
stack = 4 - stack;
if (stack == 2) {
side = 1;
}
}
return sector * constants::NHCPERSEC + stack * constants::NLAYER * 2 + layer * 2 + side;
}

static int getLinkIDfromHCID(int hcid)
{
//return a number in range [0:29] for the link related to this hcid with in its respective CRU
//lower 15 is endpoint 0 and upper 15 is endpoint 1
//a side has 30, c side has 30 to give 60 links for a supermodule
int detector = hcid / 2;
int supermodule = hcid / 60;
int chamberside = hcid % 2; // 0 for side 0, 1 for side 1;
// now offset for supermodule (+60*supermodule);
return HelperMethods::getORIinSuperModule(detector, chamberside) + 60 * supermodule; // it takes readoutboard but only cares if its odd or even hence side here.
int sector = hcid / constants::NHCPERSEC;
return getORIinSuperModule(hcid) + constants::NHCPERSEC * sector;
}

inline static void swapByteOrder(unsigned int& word)
Expand Down
12 changes: 1 addition & 11 deletions DataFormats/Detectors/TRD/include/DataFormatsTRD/RawData.h
Original file line number Diff line number Diff line change
Expand Up @@ -427,18 +427,13 @@ uint32_t getlinkdatasize(const HalfCRUHeader& cruhead, const uint32_t link);
uint32_t getlinkerrorflags(const HalfCRUHeader& cruheader, std::array<uint32_t, 15>& linkerrorflags);
uint32_t getlinkdatasizes(const HalfCRUHeader& cruheader, std::array<uint32_t, 15>& linksizes);
uint32_t getQFromRaw(const o2::trd::TrackletMCMHeader* header, const o2::trd::TrackletMCMData* data, int pidindex, int trackletindex);
uint32_t getHCIDFromTrackletHCHeader(const TrackletHCHeader& header);
uint32_t getHCIDFromTrackletHCHeader(const uint32_t& headerword);
std::ostream& operator<<(std::ostream& stream, const TrackletHCHeader& halfchamberheader);
std::ostream& operator<<(std::ostream& stream, const TrackletMCMHeader& mcmhead);
std::ostream& operator<<(std::ostream& stream, const TrackletMCMData& tracklet);
void printTrackletMCMData(o2::trd::TrackletMCMData& tracklet);
void printTrackletMCMHeader(o2::trd::TrackletMCMHeader& mcmhead);
void printHalfChamber(o2::trd::TrackletHCHeader& halfchamber);
void dumpHalfChamber(o2::trd::TrackletHCHeader& halfchamber);
void printHalfCRUHeader(o2::trd::HalfCRUHeader& halfcru);
void dumpHalfCRUHeader(o2::trd::HalfCRUHeader& halfcru);
void clearHalfCRUHeader(o2::trd::HalfCRUHeader& halfcru);
std::ostream& operator<<(std::ostream& stream, const HalfCRUHeader& halfcru);
bool trackletMCMHeaderSanityCheck(o2::trd::TrackletMCMHeader& header);
bool trackletHCHeaderSanityCheck(o2::trd::TrackletHCHeader& header);
Expand All @@ -452,13 +447,10 @@ void printDigitHCHeader(o2::trd::DigitHCHeader& header, uint32_t headers[3]);

//functions updated/checked/new for new raw reader.
//above methods left for cross checking what changes have occured.
void constructTrackletHCHeader(TrackletHCHeader& header, int sector, int stack, int layer, int side, int chipclock, int format);
void constructTrackletHCHeaderd(TrackletHCHeader& header, int detector, int rob, int chipclock, int format);
void constructTrackletHCHeader(TrackletHCHeader& header, int hcid, int chipclock, int format);
uint16_t constructTRDFeeID(int supermodule, int side, int endpoint);
uint32_t setHalfCRUHeaderFirstWord(HalfCRUHeader& cruhead, int crurdhversion, int bunchcrossing, int stopbits, int endpoint, int eventtype, int feeid, int cruid);
void setHalfCRUHeaderLinkSizeAndFlags(HalfCRUHeader& cruhead, int link, int size, int errors);
void constructTrackletMCMData(TrackletMCMData& trackletword, const int format, const uint slope, const uint pos, const uint q0, const uint q1, const uint q2);
void constructTrackletMCMData(TrackletMCMData& trackletword, const Tracklet64& tracklet);
DigitMCMADCMask constructBlankADCMask();

uint32_t getHalfCRULinkInfo(const HalfCRUHeader& cruhead, const uint32_t link, const bool data);
Expand All @@ -468,7 +460,6 @@ void getHalfCRULinkErrorFlags(const HalfCRUHeader& cruheader, std::array<uint32_
void getHalfCRULinkDataSizes(const HalfCRUHeader& cruheader, std::array<uint32_t, 15>& linksizes);
uint32_t getChargeFromRawHeaders(const o2::trd::TrackletHCHeader& hcheader, const o2::trd::TrackletMCMHeader* header, const std::array<o2::trd::TrackletMCMData, 3>& data, int pidindex, int trackletindex);
uint32_t getHCIDFromTrackletHCHeader(const TrackletHCHeader& header);
uint32_t getHCIDFromTrackletHCHeader(const uint32_t& headerword);
std::ostream& operator<<(std::ostream& stream, const TrackletHCHeader& halfchamberheader);
std::ostream& operator<<(std::ostream& stream, const TrackletMCMHeader& tracklmcmhead);
std::ostream& operator<<(std::ostream& stream, const TrackletMCMData& trackletmcmdata);
Expand Down Expand Up @@ -502,7 +493,6 @@ int getDigitHCHeaderWordType(uint32_t word);
void printDigitHCHeaders(o2::trd::DigitHCHeader& header, uint32_t headers[3], int index, int offset, bool good);
void printDigitHCHeader(o2::trd::DigitHCHeader& header, uint32_t headers[3]);
int getNumberOfTrackletsFromHeader(o2::trd::TrackletMCMHeader* header, bool verbose = false);
void setNumberOfTrackletsInHeader(o2::trd::TrackletMCMHeader& header, int numberoftracklets);
int getNextMCMADCfromBP(uint32_t& bp, int channel);

inline bool isTrackletHCHeader(uint32_t& header) { return (((header >> 12) & 0x1) == 0x1); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ enum OptionBits {
TRDIgnoreDigitHCHeaderBit,
TRDIgnoreTrackletHCHeaderBit,
TRDEnableRootOutputBit,
TRDFixSM1617Bit,
TRDIgnore2StageTrigger,
TRDGenerateStats,
TRDM1Debug
Expand Down
78 changes: 11 additions & 67 deletions DataFormats/Detectors/TRD/src/RawData.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,13 @@ std::ostream& operator<<(std::ostream& stream, const HalfCRUHeader& halfcru)

//Tracklet HC Header

void constructTrackletHCHeader(TrackletHCHeader& header, int sector, int stack, int layer, int side, int chipclock, int format)
void constructTrackletHCHeader(TrackletHCHeader& header, int hcid, int chipclock, int format)
{
int detector = hcid / 2;
int sector = (detector % (constants::NLAYER * constants::NSTACK));
int stack = (detector % constants::NLAYER);
int layer = ((detector % (constants::NLAYER * constants::NSTACK)) / constants::NLAYER);
int side = hcid % 2;
header.word = 0;
header.format = format;
header.supermodule = ~sector;
Expand All @@ -161,27 +166,11 @@ void constructTrackletHCHeader(TrackletHCHeader& header, int sector, int stack,
header.one = 1;
}

void constructTrackletHCHeaderd(TrackletHCHeader& header, int detector, int rob, int chipclock, int format)
{
int sector = (detector % (constants::NLAYER * constants::NSTACK));
int stack = (detector % constants::NLAYER);
int layer = ((detector % (constants::NLAYER * constants::NSTACK)) / constants::NLAYER);
int side = rob % 2;
constructTrackletHCHeader(header, sector, stack, layer, side, chipclock, format);
}

uint32_t getHCIDFromTrackletHCHeader(const TrackletHCHeader& header)
{
return header.layer * 2 + header.stack * constants::NLAYER * 2 + header.supermodule * constants::NLAYER * constants::NSTACK * 2 + header.side;
}

uint32_t getHCIDFromTrackletHCHeader(const uint32_t& headerword)
{
TrackletHCHeader header;
header.word = headerword;
return header.layer * 2 + header.stack * constants::NLAYER * 2 + header.supermodule * constants::NLAYER * constants::NSTACK * 2 + header.side;
}

uint32_t getChargeFromRawHeaders(const o2::trd::TrackletHCHeader& hcheader, const o2::trd::TrackletMCMHeader* header, const std::array<o2::trd::TrackletMCMData, 3>& data, int pidindex, int trackletindex)
{
uint32_t pid = 0;
Expand Down Expand Up @@ -219,14 +208,14 @@ uint32_t getChargeFromRawHeaders(const o2::trd::TrackletHCHeader& hcheader, cons
}
lowPID = data[trackletindex].pid;
//lowPID is 6 bits Q0 and 6 bits of Q1
int pidword = (highPID << 12) + lowPID; // the entire original 20 bit pid in the trap chips
uint32_t pidword = (highPID << 12) | lowPID; // the entire original 20 bit pid in the trap chips
int dynamicq = hcheader.format & 0x1; // last bit of format (lsb) defines the version of tracklet charge calculation
uint32_t pidoffset = ((pidword >> 18) & 0x3); //<<6; // used for dynamic ranged charge windows, may or may not be used below.
//pidword is here to make this code more readible and less error prone.
switch (pidindex) {
case 2: //Q2
if (!dynamicq) {
pid = (pidword >> 13) & 0x7f; // 7 bits at the top of all of pid (MSB)
pid = (pidword >> 14) & 0x3f; // 6 bits at the top of all of pid (MSB)
} else {
pid = (pidword >> 12) & 0x3f; // 6 bits of Q2 and a shift
pid |= pidoffset << 6;
Expand All @@ -235,7 +224,7 @@ uint32_t getChargeFromRawHeaders(const o2::trd::TrackletHCHeader& hcheader, cons
break;
case 1: //Q1
if (!dynamicq) {
pid = (pidword >> 6) & 0x7f; // 7 bits Q1 above the 6 bits of Q0
pid = (pidword >> 7) & 0x7f; // 7 bits Q1 above the 7 bits of Q0
} else {
pid = (pidword >> 6) & 0x3f; // 6 bits of Q1 and a shift
pid |= pidoffset << 6;
Expand All @@ -244,7 +233,7 @@ uint32_t getChargeFromRawHeaders(const o2::trd::TrackletHCHeader& hcheader, cons
break;
case 0: //Q0
if (!dynamicq) {
pid = pidword & 0x3f; // 6 least significant bits
pid = pidword & 0x7f; // 7 least significant bits
} else {
pid = pidword & 0x3f; // 6 bits of Q0
pid |= pidoffset << 6;
Expand Down Expand Up @@ -273,28 +262,6 @@ uint16_t constructTRDFeeID(int supermodule, int side, int endpoint)
return feeid.word;
}

void constructTrackletMCMData(TrackletMCMData& trackletword, const int format, const uint slope, const uint pos, const uint q0, const uint q1, const uint q2)
{
trackletword.word = 0;
// create a tracklet word as it would be sent from the FEE
// slope and position have the 8-th bit flipped each
trackletword.slope = slope ^ 0x80;
trackletword.pos = pos ^ 0x80;
trackletword.checkbit = 0;
if (format & 0x1) {
//length of q1 and q2 are 6 with a 2 bit offset sitting in the header.
trackletword.pid = (q0 & 0x3f) | ((q1 & 0x3f) << 6);
} else {
//q2 sits with upper 1 bit of q1 in the header pid word, hence the 0x3f so 6 bits of q1 are used here, shifted up above the 6 bits of q0.
trackletword.pid = (int)(q0 & 0x3f) | ((q1 & 0x3f) << 6);
}
}

void constructTrackletMCMData(TrackletMCMData& trackletword, const Tracklet64& tracklet)
{
constructTrackletMCMData(trackletword, tracklet.getFormat(), tracklet.getSlope(), tracklet.getPosition(), tracklet.getQ0(), tracklet.getQ1(), tracklet.getQ2());
}

DigitMCMADCMask constructBlankADCMask()
{
//set the default values for the mask.
Expand All @@ -303,6 +270,7 @@ DigitMCMADCMask constructBlankADCMask()
mask.c = 0x1f;
mask.n = 0x1;
mask.j = 0xc;
mask.adcmask = 0;
// actual mask will beset somewhere else, the above values are *always* that.
return mask;
}
Expand Down Expand Up @@ -668,30 +636,6 @@ int getNumberOfTrackletsFromHeader(o2::trd::TrackletMCMHeader* header, bool verb
return headertrackletcount;
}

void setNumberOfTrackletsInHeader(o2::trd::TrackletMCMHeader& header, int numberoftracklets)
{
//header.word |= 0xff<< (1+numberoftracklets*8);
switch (numberoftracklets) {
case 0:
LOG(error) << "tracklet header but no tracklets???";
header.pid0 = 0xff;
header.pid1 = 0xff;
header.pid2 = 0xff;
break;
case 1:
header.pid1 = 0xff;
header.pid2 = 0xff;
break;
case 2:
header.pid2 = 0xff;
break;
case 3:
break;
default:
LOG(error) << "we have more than 3 tracklets for an mcm in " << __func__ << ". This should never happen: tracklet count=" << numberoftracklets;
}
}

int getNextMCMADCfromBP(uint32_t& bp, int channel)
{
//given a bitpattern (adcmask) find next channel with in the mask starting from the current channel.
Expand Down
3 changes: 0 additions & 3 deletions Detectors/TRD/base/include/TRDBase/FeeParam.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ class FeeParam
static int getORI(int detector, int readoutboard);
static void unpackORI(int link, int side, int& stack, int& layer, int& halfchamberside);
// void createORILookUpTable();
static int getORIinSuperModule(int detector, int readoutboard);
static int getLinkIDfromHCID(int hcid);
static int getHCIDfromORI(int ori, int readoutboard); // TODO we need more info than just ori, for now readoutboard is there ... might change

// tracklet simulation
bool getTracklet() const { return mTracklet; }
Expand Down
28 changes: 0 additions & 28 deletions Detectors/TRD/base/src/FeeParam.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -406,34 +406,6 @@ void FeeParam::unpackORI(int link, int side, int& stack, int& layer, int& halfch
}
}

int FeeParam::getORI(int detector, int readoutboard)
{
/// LOG(info) << "getORI : " << detector << " :: " << readoutboard << " -- " << getORIinSM(detector, readoutboard) << " " << getORIinSM(detector, readoutboard) + NCHAMBERPERSEC * 2 * detector;
return getORIinSuperModule(detector, readoutboard) + NCHAMBER * 2 * detector; // 60 ORI per supermodule
}

int FeeParam::getORIinSuperModule(int detector, int readoutboard)
{
return HelperMethods::getORIinSuperModule(detector, readoutboard);
}

int FeeParam::getLinkIDfromHCID(int hcid)
{
return HelperMethods::getLinkIDfromHCID(hcid);
//return a number in range [0:29] for the link related to this hcid with in its respective CRU
//lower 15 is endpoint 0 and upper 15 is endpoint 1
//a side has 30, c side has 30 to give 60 links for a supermodule
}

int FeeParam::getHCIDfromORI(int ori, int readoutboard)
{
// ori = 60*SM+offset[0-29 A, 30-59 C]
// from the offset, we can derive the stack/layer/side combination giving the decector.
//TODO do we need this, currently I dont, others might? come back if need be.
//
return 1;
}

short FeeParam::chipmaskToMCMlist(unsigned int cmA, unsigned int cmB, unsigned short linkpair, int* mcmList, int listSize)
{
// Converts the chipmask to a list of MCMs
Expand Down
16 changes: 12 additions & 4 deletions Detectors/TRD/reconstruction/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,21 @@ Reconstruction is made up of different parts. There are things that run on the f

- Generate raw data from montecarlo:
```
o2-sim -n 200 -g pythia8 --skipModules ZDC
o2-sim-digitizer-workflow -b
o2-trd-trap2raw -d trddigits.root -t trdtracklets.root -l halfcru -o ./ -x -r 6 -e
o2-sim -n 200 -g pythia8pp --skipModules ZDC
o2-sim-digitizer-workflow -b --onlyDet TRD
o2-trd-trap2raw -o raw/TRD --file-per cru |& tee trdraw.log
```

- Parse raw data :

In order to simply read the generated raw data and extract the digits and tracklets you can do the following. Remember to first rename the original digits and tracklets files in order not to overwrite them. This way you can compare afterwards that you in fact read back the same data that you have put in.

```
mv trddigits.root trddigitsOrig.root
mv trdtracklets.root trdtrackletsOrig.root
o2-raw-file-reader-workflow --detect-tf0 --delay 100 --max-tf 0 --input-conf raw/TRD/TRDraw.cfg | o2-trd-datareader -b | o2-trd-digittracklet-writer --run |& tee trdrec.log
```

You will need the datadistribution installed as well which has an O2 dependency.

```
Expand Down Expand Up @@ -54,4 +63,3 @@ o2-dpl-raw-proxy --session default -b --dataspec "A:TRD/RAWDATA" --channel-confi
```
StfSender --id stfs --session default --transport shmem --stand-alone --input-channel-name=from-dpl --channel-config "name=from-dpl,type=pull,method=connect,address=ipc:///tmp/dpl-to-stfs,rateLogging=1,transport=shmem"
```

Loading