Skip to content

Commit 56fe695

Browse files
authored
HMPID: cleaned up version of PR5606 + fixes (#5624)
* HMPID: cleaned up version of PR5606 * fix CI errors * add missing options * Rename WriteRawFromRootSpec to DigitsToRawSpec + and write-raw-from-root-workflow to digits-to-raw-workflow Co-authored-by: shahoian <ruben.shahoyan@cern.ch>
1 parent 9fa2b72 commit 56fe695

26 files changed

Lines changed: 1158 additions & 56 deletions

Detectors/HMPID/base/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ o2_add_library(HMPIDBase
1616
o2_target_root_dictionary(HMPIDBase
1717
HEADERS include/HMPIDBase/Param.h
1818
include/HMPIDBase/Digit.h
19+
include/HMPIDBase/Trigger.h
1920
include/HMPIDBase/Cluster.h
2021
include/HMPIDBase/Geo.h)

Detectors/HMPID/base/include/HMPIDBase/Digit.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class Digit
5050
static void Equipment2Absolute(int Equi, int Colu, int Dilo, int Chan, int* Module, int* x, int* y);
5151

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

8181
public:
8282
Digit() = default;
83-
Digit(uint16_t bc, uint32_t orbit, int pad, uint16_t charge) : mBc(bc), mOrbit(orbit), mQ(charge), mPad(pad){};
83+
Digit(uint16_t bc, uint32_t orbit, int pad, uint16_t charge);
8484
Digit(uint16_t bc, uint32_t orbit, int chamber, int photo, int x, int y, uint16_t charge);
85-
Digit(uint16_t bc, uint32_t orbit, uint16_t, int equipment, int column, int dilogic, int channel);
86-
Digit(uint16_t bc, uint32_t orbit, uint16_t, int module, int x, int y);
85+
Digit(uint16_t bc, uint32_t orbit, uint16_t charge, int equipment, int column, int dilogic, int channel);
86+
Digit(uint16_t bc, uint32_t orbit, uint16_t charge, int module, int x, int y);
8787

8888
// Getter & Setters
8989
uint16_t getCharge() const { return mQ; }
@@ -133,7 +133,13 @@ class Digit
133133
// Charge management functions
134134
static void getPadAndTotalCharge(HitType const& hit, int& chamber, int& pc, int& px, int& py, float& totalcharge);
135135
static float getFractionalContributionForPad(HitType const& hit, int somepad);
136-
void addCharge(float q) { mQ += q; }
136+
void addCharge(float q)
137+
{
138+
mQ += q;
139+
if (mQ > 0x0FFF) {
140+
mQ = 0x0FFF;
141+
}
142+
}
137143
void subCharge(float q) { mQ -= q; }
138144

139145
private:

Detectors/HMPID/base/include/HMPIDBase/Geo.h

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#define ALICEO2_HMPID_GEO_H
1919

2020
#include <TMath.h>
21-
#include <Rtypes.h>
2221

2322
namespace o2
2423
{
@@ -134,6 +133,90 @@ class Geo
134133

135134
ClassDefNV(Geo, 1);
136135
};
136+
137+
class ReadOut
138+
{
139+
public:
140+
struct LinkAddr {
141+
uint8_t Fee;
142+
uint8_t Cru;
143+
uint8_t Lnk;
144+
uint8_t Flp;
145+
};
146+
union Lnk {
147+
LinkAddr Id;
148+
uint32_t LinkUId;
149+
};
150+
static constexpr Lnk mEq[Geo::MAXEQUIPMENTS] = {{0, 0, 0, 160},
151+
{1, 0, 1, 160},
152+
{2, 0, 2, 160},
153+
{3, 0, 3, 160},
154+
{4, 1, 0, 160},
155+
{5, 1, 1, 160},
156+
{8, 1, 2, 160},
157+
{9, 1, 3, 160},
158+
{6, 2, 0, 161},
159+
{7, 2, 1, 161},
160+
{10, 2, 2, 161},
161+
{11, 3, 0, 161},
162+
{12, 3, 1, 161},
163+
{13, 3, 2, 161}};
164+
165+
static inline int FeeId(unsigned int idx) { return (idx > Geo::MAXEQUIPMENTS) ? -1 : mEq[idx].Id.Fee; };
166+
static inline int CruId(unsigned int idx) { return (idx > Geo::MAXEQUIPMENTS) ? -1 : mEq[idx].Id.Cru; };
167+
static inline int LnkId(unsigned int idx) { return (idx > Geo::MAXEQUIPMENTS) ? -1 : mEq[idx].Id.Lnk; };
168+
static inline int FlpId(unsigned int idx) { return (idx > Geo::MAXEQUIPMENTS) ? -1 : mEq[idx].Id.Flp; };
169+
static inline uint32_t UniqueId(unsigned int idx) { return (idx > Geo::MAXEQUIPMENTS) ? -1 : mEq[idx].LinkUId; };
170+
171+
static unsigned int searchIdx(int FeeId)
172+
{
173+
for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) {
174+
if (FeeId == mEq[i].Id.Fee) {
175+
return (i);
176+
}
177+
}
178+
return (-1);
179+
}
180+
static unsigned int searchIdx(int CruId, int LnkId)
181+
{
182+
for (int i = 0; i < Geo::MAXEQUIPMENTS; i++) {
183+
if (CruId == mEq[i].Id.Cru && LnkId == mEq[i].Id.Lnk) {
184+
return (i);
185+
}
186+
}
187+
return (-1);
188+
}
189+
static void getInfo(unsigned int idx, int& Fee, int& Cru, int& Lnk, int& Flp)
190+
{
191+
Cru = mEq[idx].Id.Cru;
192+
Lnk = mEq[idx].Id.Lnk;
193+
Fee = mEq[idx].Id.Fee;
194+
Flp = mEq[idx].Id.Flp;
195+
return;
196+
}
197+
198+
ClassDefNV(ReadOut, 1);
199+
};
200+
/*
201+
void ReadOut::Init()
202+
{
203+
mEq[0].Id = { 0, 0, 0, 160};
204+
mEq[1].Id = { 1, 0, 1, 160};
205+
mEq[2].Id = { 2, 0, 2, 160};
206+
mEq[3].Id = { 3, 0, 3, 160};
207+
mEq[4].Id = { 4, 1, 0, 160};
208+
mEq[5].Id = { 5, 1, 1, 160};
209+
mEq[6].Id = { 8, 1, 2, 160};
210+
mEq[7].Id = { 9, 1, 3, 160};
211+
mEq[8].Id = { 6, 2, 0, 161};
212+
mEq[9].Id = { 7, 2, 1, 161};
213+
mEq[10].Id = {10, 2, 2, 161};
214+
mEq[11].Id = {11, 3, 0, 161};
215+
mEq[12].Id = {12, 3, 1, 161};
216+
mEq[13].Id = {13, 3, 2, 161};
217+
};
218+
*/
219+
137220
} // namespace hmpid
138221
} // namespace o2
139222

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
///
12+
/// \file Trigger.h
13+
/// \author Antonio Franco - INFN Bari
14+
/// \version 1.0
15+
/// \date 2/03/2021
16+
17+
#ifndef DETECTORS_HMPID_BASE_INCLUDE_HMPIDBASE_TRIGGER_H_
18+
#define DETECTORS_HMPID_BASE_INCLUDE_HMPIDBASE_TRIGGER_H_
19+
20+
#include <vector>
21+
#include "TMath.h"
22+
#include "CommonDataFormat/TimeStamp.h"
23+
#include "CommonConstants/LHCConstants.h"
24+
25+
namespace o2
26+
{
27+
namespace hmpid
28+
{
29+
30+
/// \class Trigger
31+
/// \brief HMPID Trigger declaration
32+
class Trigger
33+
{
34+
public:
35+
// Trigger time Conversion Functions
36+
static inline uint64_t OrbitBcToEventId(uint32_t Orbit, uint16_t BC) { return ((Orbit << 12) | (0x0FFF & BC)); };
37+
static inline uint32_t EventIdToOrbit(uint64_t EventId) { return (EventId >> 12); };
38+
static inline uint16_t EventIdToBc(uint64_t EventId) { return (EventId & 0x0FFF); };
39+
static double OrbitBcToTimeNs(uint32_t Orbit, uint16_t BC) { return (BC * o2::constants::lhc::LHCBunchSpacingNS + Orbit * o2::constants::lhc::LHCOrbitNS); };
40+
static uint32_t TimeNsToOrbit(double TimeNs) { return (uint32_t)(TimeNs / o2::constants::lhc::LHCOrbitNS); };
41+
static uint16_t TimeNsToBc(double TimeNs) { return (uint16_t)(std::fmod(TimeNs, o2::constants::lhc::LHCOrbitNS) / o2::constants::lhc::LHCBunchSpacingNS); };
42+
static void TimeNsToOrbitBc(double TimeNs, uint32_t& Orbit, uint16_t& Bc)
43+
{
44+
Orbit = TimeNsToOrbit(TimeNs);
45+
Bc = TimeNsToBc(TimeNs);
46+
return;
47+
};
48+
49+
// Operators definition !
50+
friend inline bool operator<(const Trigger& l, const Trigger& r) { return OrbitBcToEventId(l.mOrbit, l.mBc) < OrbitBcToEventId(r.mOrbit, r.mBc); };
51+
friend inline bool operator==(const Trigger& l, const Trigger& r) { return OrbitBcToEventId(l.mOrbit, l.mBc) == OrbitBcToEventId(r.mOrbit, r.mBc); };
52+
friend inline bool operator>(const Trigger& l, const Trigger& r) { return r < l; };
53+
friend inline bool operator<=(const Trigger& l, const Trigger& r) { return !(l > r); };
54+
friend inline bool operator>=(const Trigger& l, const Trigger& r) { return !(l < r); };
55+
friend inline bool operator!=(const Trigger& l, const Trigger& r) { return !(l == r); };
56+
57+
// Digit ASCII format (Orbit,BunchCrossing)[LHC Time nSec]
58+
friend std::ostream& operator<<(std::ostream& os, const Trigger& d)
59+
{
60+
os << "(" << d.mOrbit << "," << d.mBc << ")[" << OrbitBcToTimeNs(d.mOrbit, d.mBc) << " ns]";
61+
return os;
62+
};
63+
64+
public:
65+
Trigger() = default;
66+
Trigger(uint16_t bc, uint32_t orbit)
67+
{
68+
mBc = bc;
69+
mOrbit = orbit;
70+
};
71+
uint32_t getOrbit() const { return mOrbit; }
72+
uint16_t getBc() const { return mBc; }
73+
uint64_t getTriggerID() const { return OrbitBcToEventId(mOrbit, mBc); }
74+
void setOrbit(uint32_t orbit)
75+
{
76+
mOrbit = orbit;
77+
return;
78+
}
79+
void setBC(uint16_t bc)
80+
{
81+
mBc = bc;
82+
return;
83+
}
84+
void setTriggerID(uint64_t trigger)
85+
{
86+
mOrbit = (trigger >> 12);
87+
mBc = (trigger & 0x0FFF);
88+
return;
89+
}
90+
91+
private:
92+
// Members
93+
uint16_t mBc = 0.;
94+
uint32_t mOrbit = 0;
95+
96+
ClassDefNV(Trigger, 2);
97+
};
98+
99+
} // namespace hmpid
100+
} // namespace o2
101+
102+
#endif /* DETECTORS_HMPID_BASE_INCLUDE_HMPIDBASE_TRIGGER_H_ */

Detectors/HMPID/base/src/Digit.cxx

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,20 @@ using namespace o2::hmpid;
3030
ClassImp(o2::hmpid::Digit);
3131

3232
// ============= Digit Class implementation =======
33+
/// Constructor : Create the Digit structure. Accepts the trigger time (Orbit,BC)
34+
/// The mapping of the digit is in the Photo Cathod coords
35+
/// (Chamber, PhotoCathod, X, Y)
36+
/// @param[in] bc : the bunch crossing [0 .. 2^12-1]
37+
/// @param[in] orbit : the orbit number [0 .. 2^32-1]
38+
/// @param[in] pad : the Digit Unique Id [0x00CPXXYY]
39+
/// @param[in] charge : the value of the charge [0 .. 2^12-1]
40+
Digit::Digit(uint16_t bc, uint32_t orbit, int pad, uint16_t charge)
41+
{
42+
mBc = bc;
43+
mOrbit = orbit;
44+
mQ = charge > 0x0FFF ? 0x0FFF : charge;
45+
mPad = pad;
46+
}
3347

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

@@ -63,7 +77,7 @@ Digit::Digit(uint16_t bc, uint32_t orbit, uint16_t charge, int equipment, int co
6377
{
6478
mBc = bc;
6579
mOrbit = orbit;
66-
mQ = charge;
80+
mQ = charge > 0x0FFF ? 0x0FFF : charge;
6781
mPad = Equipment2Pad(equipment, column, dilogic, channel);
6882
}
6983

@@ -80,7 +94,7 @@ Digit::Digit(uint16_t bc, uint32_t orbit, uint16_t charge, int module, int x, in
8094
{
8195
mBc = bc;
8296
mOrbit = orbit;
83-
mQ = charge;
97+
mQ = charge > 0x0FFF ? 0x0FFF : charge;
8498
mPad = Absolute2Pad(module, x, y);
8599
}
86100

@@ -369,7 +383,7 @@ Double_t Digit::OrbitBcToTimeNs(uint32_t Orbit, uint16_t BC)
369383
/// @return : the Orbit number [0..2^32-1]
370384
uint32_t Digit::TimeNsToOrbit(Double_t TimeNs)
371385
{
372-
return (TimeNs / o2::constants::lhc::LHCOrbitNS);
386+
return (uint32_t)(TimeNs / o2::constants::lhc::LHCOrbitNS);
373387
}
374388

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

385399
/// TimeNsToOrbitBc : Extracts the (Orbit,BC) pair from the absolute

Detectors/HMPID/base/src/HMPIDBaseLinkDef.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,7 @@
2222
#pragma link C++ class o2::hmpid::HitType + ;
2323
#pragma link C++ class vector < o2::hmpid::HitType> + ;
2424
#pragma link C++ class o2::hmpid::Geo + ;
25+
#pragma link C++ class o2::hmpid::Trigger + ;
26+
#pragma link C++ class vector < o2::hmpid::Trigger> + ;
2527

2628
#endif

0 commit comments

Comments
 (0)