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
1 change: 1 addition & 0 deletions Detectors/HMPID/base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ o2_add_library(HMPIDBase
o2_target_root_dictionary(HMPIDBase
HEADERS include/HMPIDBase/Param.h
include/HMPIDBase/Digit.h
include/HMPIDBase/Trigger.h
include/HMPIDBase/Cluster.h
include/HMPIDBase/Geo.h)
16 changes: 11 additions & 5 deletions Detectors/HMPID/base/include/HMPIDBase/Digit.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Digit
static void Equipment2Absolute(int Equi, int Colu, int Dilo, int Chan, int* Module, int* x, int* y);

// Trigger time Conversion Functions
static inline uint64_t OrbitBcToEventId(uint32_t Orbit, uint16_t BC) { return ((Orbit << 12) || BC); };
static inline uint64_t OrbitBcToEventId(uint32_t Orbit, uint16_t BC) { return ((Orbit << 12) | (0x0FFF & BC)); };
static inline uint32_t EventIdToOrbit(uint64_t EventId) { return (EventId >> 12); };
static inline uint16_t EventIdToBc(uint64_t EventId) { return (EventId & 0x0FFF); };
static double OrbitBcToTimeNs(uint32_t Orbit, uint16_t BC);
Expand Down Expand Up @@ -80,10 +80,10 @@ class Digit

public:
Digit() = default;
Digit(uint16_t bc, uint32_t orbit, int pad, uint16_t charge) : mBc(bc), mOrbit(orbit), mQ(charge), mPad(pad){};
Digit(uint16_t bc, uint32_t orbit, int pad, uint16_t charge);
Digit(uint16_t bc, uint32_t orbit, int chamber, int photo, int x, int y, uint16_t charge);
Digit(uint16_t bc, uint32_t orbit, uint16_t, int equipment, int column, int dilogic, int channel);
Digit(uint16_t bc, uint32_t orbit, uint16_t, int module, int x, int y);
Digit(uint16_t bc, uint32_t orbit, uint16_t charge, int equipment, int column, int dilogic, int channel);
Digit(uint16_t bc, uint32_t orbit, uint16_t charge, int module, int x, int y);

// Getter & Setters
uint16_t getCharge() const { return mQ; }
Expand Down Expand Up @@ -133,7 +133,13 @@ class Digit
// Charge management functions
static void getPadAndTotalCharge(HitType const& hit, int& chamber, int& pc, int& px, int& py, float& totalcharge);
static float getFractionalContributionForPad(HitType const& hit, int somepad);
void addCharge(float q) { mQ += q; }
void addCharge(float q)
{
mQ += q;
if (mQ > 0x0FFF) {
mQ = 0x0FFF;
}
}
void subCharge(float q) { mQ -= q; }

private:
Expand Down
85 changes: 84 additions & 1 deletion Detectors/HMPID/base/include/HMPIDBase/Geo.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#define ALICEO2_HMPID_GEO_H

#include <TMath.h>
#include <Rtypes.h>

namespace o2
{
Expand Down Expand Up @@ -134,6 +133,90 @@ class Geo

ClassDefNV(Geo, 1);
};

class ReadOut
{
public:
struct LinkAddr {
uint8_t Fee;
uint8_t Cru;
uint8_t Lnk;
uint8_t Flp;
};
union Lnk {
LinkAddr Id;
uint32_t LinkUId;
};
static constexpr Lnk mEq[Geo::MAXEQUIPMENTS] = {{0, 0, 0, 160},
{1, 0, 1, 160},
{2, 0, 2, 160},
{3, 0, 3, 160},
{4, 1, 0, 160},
{5, 1, 1, 160},
{8, 1, 2, 160},
{9, 1, 3, 160},
{6, 2, 0, 161},
{7, 2, 1, 161},
{10, 2, 2, 161},
{11, 3, 0, 161},
{12, 3, 1, 161},
{13, 3, 2, 161}};

static inline int FeeId(unsigned int idx) { return (idx > Geo::MAXEQUIPMENTS) ? -1 : mEq[idx].Id.Fee; };
static inline int CruId(unsigned int idx) { return (idx > Geo::MAXEQUIPMENTS) ? -1 : mEq[idx].Id.Cru; };
static inline int LnkId(unsigned int idx) { return (idx > Geo::MAXEQUIPMENTS) ? -1 : mEq[idx].Id.Lnk; };
static inline int FlpId(unsigned int idx) { return (idx > Geo::MAXEQUIPMENTS) ? -1 : mEq[idx].Id.Flp; };
static inline uint32_t UniqueId(unsigned int idx) { return (idx > Geo::MAXEQUIPMENTS) ? -1 : mEq[idx].LinkUId; };

static unsigned int searchIdx(int FeeId)
{
for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) {
if (FeeId == mEq[i].Id.Fee) {
return (i);
}
}
return (-1);
}
static unsigned int searchIdx(int CruId, int LnkId)
{
for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) {
if (CruId == mEq[i].Id.Cru && LnkId == mEq[i].Id.Lnk) {
return (i);
}
}
return (-1);
}
static void getInfo(unsigned int idx, int& Fee, int& Cru, int& Lnk, int& Flp)
{
Cru = mEq[idx].Id.Cru;
Lnk = mEq[idx].Id.Lnk;
Fee = mEq[idx].Id.Fee;
Flp = mEq[idx].Id.Flp;
return;
}

ClassDefNV(ReadOut, 1);
};
/*
void ReadOut::Init()
{
mEq[0].Id = { 0, 0, 0, 160};
mEq[1].Id = { 1, 0, 1, 160};
mEq[2].Id = { 2, 0, 2, 160};
mEq[3].Id = { 3, 0, 3, 160};
mEq[4].Id = { 4, 1, 0, 160};
mEq[5].Id = { 5, 1, 1, 160};
mEq[6].Id = { 8, 1, 2, 160};
mEq[7].Id = { 9, 1, 3, 160};
mEq[8].Id = { 6, 2, 0, 161};
mEq[9].Id = { 7, 2, 1, 161};
mEq[10].Id = {10, 2, 2, 161};
mEq[11].Id = {11, 3, 0, 161};
mEq[12].Id = {12, 3, 1, 161};
mEq[13].Id = {13, 3, 2, 161};
};
*/

} // namespace hmpid
} // namespace o2

Expand Down
102 changes: 102 additions & 0 deletions Detectors/HMPID/base/include/HMPIDBase/Trigger.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// Copyright CERN and copyright holders of ALICE O2. This software is
// distributed under the terms of the GNU General Public License v3 (GPL
// Version 3), copied verbatim in the file "COPYING".
//
// See http://alice-o2.web.cern.ch/license for full licensing information.
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

///
/// \file Trigger.h
/// \author Antonio Franco - INFN Bari
/// \version 1.0
/// \date 2/03/2021

#ifndef DETECTORS_HMPID_BASE_INCLUDE_HMPIDBASE_TRIGGER_H_
#define DETECTORS_HMPID_BASE_INCLUDE_HMPIDBASE_TRIGGER_H_

#include <vector>
#include "TMath.h"
#include "CommonDataFormat/TimeStamp.h"
#include "CommonConstants/LHCConstants.h"

namespace o2
{
namespace hmpid
{

/// \class Trigger
/// \brief HMPID Trigger declaration
class Trigger
{
public:
// Trigger time Conversion Functions
static inline uint64_t OrbitBcToEventId(uint32_t Orbit, uint16_t BC) { return ((Orbit << 12) | (0x0FFF & BC)); };
static inline uint32_t EventIdToOrbit(uint64_t EventId) { return (EventId >> 12); };
static inline uint16_t EventIdToBc(uint64_t EventId) { return (EventId & 0x0FFF); };
static double OrbitBcToTimeNs(uint32_t Orbit, uint16_t BC) { return (BC * o2::constants::lhc::LHCBunchSpacingNS + Orbit * o2::constants::lhc::LHCOrbitNS); };
static uint32_t TimeNsToOrbit(double TimeNs) { return (uint32_t)(TimeNs / o2::constants::lhc::LHCOrbitNS); };
static uint16_t TimeNsToBc(double TimeNs) { return (uint16_t)(std::fmod(TimeNs, o2::constants::lhc::LHCOrbitNS) / o2::constants::lhc::LHCBunchSpacingNS); };
static void TimeNsToOrbitBc(double TimeNs, uint32_t& Orbit, uint16_t& Bc)
{
Orbit = TimeNsToOrbit(TimeNs);
Bc = TimeNsToBc(TimeNs);
return;
};

// Operators definition !
friend inline bool operator<(const Trigger& l, const Trigger& r) { return OrbitBcToEventId(l.mOrbit, l.mBc) < OrbitBcToEventId(r.mOrbit, r.mBc); };
friend inline bool operator==(const Trigger& l, const Trigger& r) { return OrbitBcToEventId(l.mOrbit, l.mBc) == OrbitBcToEventId(r.mOrbit, r.mBc); };
friend inline bool operator>(const Trigger& l, const Trigger& r) { return r < l; };
friend inline bool operator<=(const Trigger& l, const Trigger& r) { return !(l > r); };
friend inline bool operator>=(const Trigger& l, const Trigger& r) { return !(l < r); };
friend inline bool operator!=(const Trigger& l, const Trigger& r) { return !(l == r); };

// Digit ASCII format (Orbit,BunchCrossing)[LHC Time nSec]
friend std::ostream& operator<<(std::ostream& os, const Trigger& d)
{
os << "(" << d.mOrbit << "," << d.mBc << ")[" << OrbitBcToTimeNs(d.mOrbit, d.mBc) << " ns]";
return os;
};

public:
Trigger() = default;
Trigger(uint16_t bc, uint32_t orbit)
{
mBc = bc;
mOrbit = orbit;
};
uint32_t getOrbit() const { return mOrbit; }
uint16_t getBc() const { return mBc; }
uint64_t getTriggerID() const { return OrbitBcToEventId(mOrbit, mBc); }
void setOrbit(uint32_t orbit)
{
mOrbit = orbit;
return;
}
void setBC(uint16_t bc)
{
mBc = bc;
return;
}
void setTriggerID(uint64_t trigger)
{
mOrbit = (trigger >> 12);
mBc = (trigger & 0x0FFF);
return;
}

private:
// Members
uint16_t mBc = 0.;
uint32_t mOrbit = 0;

ClassDefNV(Trigger, 2);
};

} // namespace hmpid
} // namespace o2

#endif /* DETECTORS_HMPID_BASE_INCLUDE_HMPIDBASE_TRIGGER_H_ */
24 changes: 19 additions & 5 deletions Detectors/HMPID/base/src/Digit.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,20 @@ using namespace o2::hmpid;
ClassImp(o2::hmpid::Digit);

// ============= Digit Class implementation =======
/// Constructor : Create the Digit structure. Accepts the trigger time (Orbit,BC)
/// The mapping of the digit is in the Photo Cathod coords
/// (Chamber, PhotoCathod, X, Y)
/// @param[in] bc : the bunch crossing [0 .. 2^12-1]
/// @param[in] orbit : the orbit number [0 .. 2^32-1]
/// @param[in] pad : the Digit Unique Id [0x00CPXXYY]
/// @param[in] charge : the value of the charge [0 .. 2^12-1]
Digit::Digit(uint16_t bc, uint32_t orbit, int pad, uint16_t charge)
{
mBc = bc;
mOrbit = orbit;
mQ = charge > 0x0FFF ? 0x0FFF : charge;
mPad = pad;
}

/// Constructor : Create the Digit structure. Accepts the trigger time (Orbit,BC)
/// The mapping of the digit is in the Photo Cathod coords
Expand All @@ -45,7 +59,7 @@ Digit::Digit(uint16_t bc, uint32_t orbit, int chamber, int photo, int x, int y,
{
mBc = bc;
mOrbit = orbit;
mQ = charge;
mQ = charge > 0x0FFF ? 0x0FFF : charge;
mPad = Abs(chamber, photo, x, y);
}

Expand All @@ -63,7 +77,7 @@ Digit::Digit(uint16_t bc, uint32_t orbit, uint16_t charge, int equipment, int co
{
mBc = bc;
mOrbit = orbit;
mQ = charge;
mQ = charge > 0x0FFF ? 0x0FFF : charge;
mPad = Equipment2Pad(equipment, column, dilogic, channel);
}

Expand All @@ -80,7 +94,7 @@ Digit::Digit(uint16_t bc, uint32_t orbit, uint16_t charge, int module, int x, in
{
mBc = bc;
mOrbit = orbit;
mQ = charge;
mQ = charge > 0x0FFF ? 0x0FFF : charge;
mPad = Absolute2Pad(module, x, y);
}

Expand Down Expand Up @@ -369,7 +383,7 @@ Double_t Digit::OrbitBcToTimeNs(uint32_t Orbit, uint16_t BC)
/// @return : the Orbit number [0..2^32-1]
uint32_t Digit::TimeNsToOrbit(Double_t TimeNs)
{
return (TimeNs / o2::constants::lhc::LHCOrbitNS);
return (uint32_t)(TimeNs / o2::constants::lhc::LHCOrbitNS);
}

/// TimeNsToBc : Extracts the Bunch Crossing number from the absolute
Expand All @@ -379,7 +393,7 @@ uint32_t Digit::TimeNsToOrbit(Double_t TimeNs)
/// @return : the Bunch Crossing number [0..2^12-1]
uint16_t Digit::TimeNsToBc(Double_t TimeNs)
{
return (std::fmod(TimeNs, o2::constants::lhc::LHCOrbitNS) / o2::constants::lhc::LHCBunchSpacingNS);
return (uint16_t)(std::fmod(TimeNs, o2::constants::lhc::LHCOrbitNS) / o2::constants::lhc::LHCBunchSpacingNS);
}

/// TimeNsToOrbitBc : Extracts the (Orbit,BC) pair from the absolute
Expand Down
2 changes: 2 additions & 0 deletions Detectors/HMPID/base/src/HMPIDBaseLinkDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@
#pragma link C++ class o2::hmpid::HitType + ;
#pragma link C++ class vector < o2::hmpid::HitType> + ;
#pragma link C++ class o2::hmpid::Geo + ;
#pragma link C++ class o2::hmpid::Trigger + ;
#pragma link C++ class vector < o2::hmpid::Trigger> + ;

#endif
Loading