|
| 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 Digit.h |
| 13 | +/// \author Antonio Franco - INFN Bari |
| 14 | +/// \version 1.0 |
| 15 | +/// \date 15/02/2021 |
| 16 | + |
| 17 | +// History |
| 18 | +// 10/03/2021 Complete review |
| 19 | + |
| 20 | +#ifndef DETECTORS_HMPID_BASE_INCLUDE_HMPIDDATAFORMAT_DIGIT_H_ |
| 21 | +#define DETECTORS_HMPID_BASE_INCLUDE_HMPIDDATAFORMAT_DIGIT_H_ |
| 22 | + |
| 23 | +#include <iosfwd> |
| 24 | +#include <vector> |
| 25 | +#include "DataFormatsHMP/Hit.h" // for hit |
| 26 | +#include "HMPIDBase/Param.h" // for param |
| 27 | + |
| 28 | +namespace o2 |
| 29 | +{ |
| 30 | +namespace hmpid |
| 31 | +{ |
| 32 | +/// \class Digit |
| 33 | +/// \brief HMPID Digit declaration |
| 34 | +class Digit |
| 35 | +{ |
| 36 | + public: |
| 37 | + // Coordinates Conversion Functions |
| 38 | + static inline uint32_t abs(int ch, int pc, int x, int y) { return ch << 24 | pc << 16 | x << 8 | y; } |
| 39 | + static inline int ddl2C(int ddl) { return ddl >> 1; } //ddl -> chamber |
| 40 | + static inline int a2C(uint32_t pad) { return (pad & 0xFF000000) >> 24; } //abs pad -> chamber |
| 41 | + static inline int a2P(uint32_t pad) { return (pad & 0x00FF0000) >> 16; } //abs pad -> pc |
| 42 | + static inline int a2X(uint32_t pad) { return (pad & 0x0000FF00) >> 8; } //abs pad -> pad X |
| 43 | + static inline int a2Y(uint32_t pad) { return (pad & 0x000000FF); } //abs pad -> pad Y |
| 44 | + static inline uint32_t photo2Pad(int ch, int pc, int x, int y) { return abs(ch, pc, x, y); } |
| 45 | + static uint32_t equipment2Pad(int Equi, int Colu, int Dilo, int Chan); |
| 46 | + static uint32_t absolute2Pad(int Module, int x, int y); |
| 47 | + static void pad2Equipment(uint32_t pad, int* Equi, int* Colu, int* Dilo, int* Chan); |
| 48 | + static void pad2Absolute(uint32_t pad, int* Module, int* x, int* y); |
| 49 | + static void pad2Photo(uint32_t pad, uint8_t* chamber, uint8_t* photo, uint8_t* x, uint8_t* y); |
| 50 | + static void absolute2Equipment(int Module, int x, int y, int* Equi, int* Colu, int* Dilo, int* Chan); |
| 51 | + static void equipment2Absolute(int Equi, int Colu, int Dilo, int Chan, int* Module, int* x, int* y); |
| 52 | + |
| 53 | + // Trigger time Conversion Functions |
| 54 | + // static inline uint64_t orbitBcToEventId(uint32_t Orbit, uint16_t BC) { return ((Orbit << 12) | (0x0FFF & BC)); }; |
| 55 | + // static inline uint32_t eventIdToOrbit(uint64_t EventId) { return (EventId >> 12); }; |
| 56 | + // static inline uint16_t EventIdToBc(uint64_t EventId) { return (EventId & 0x0FFF); }; |
| 57 | + // static double OrbitBcToTimeNs(uint32_t Orbit, uint16_t BC); |
| 58 | + // static uint32_t TimeNsToOrbit(double TimeNs); |
| 59 | + // static uint16_t TimeNsToBc(double TimeNs); |
| 60 | + // static void TimeNsToOrbitBc(double TimeNs, uint32_t& Orbit, uint16_t& Bc); |
| 61 | + |
| 62 | + // Operators definition ! |
| 63 | + friend inline bool operator<(const Digit& l, const Digit& r) { return l.getPadID() < r.getPadID(); }; |
| 64 | + friend inline bool operator==(const Digit& l, const Digit& r) { return l.getPadID() == r.getPadID(); }; |
| 65 | + friend inline bool operator>(const Digit& l, const Digit& r) { return r < l; }; |
| 66 | + friend inline bool operator<=(const Digit& l, const Digit& r) { return !(l > r); }; |
| 67 | + friend inline bool operator>=(const Digit& l, const Digit& r) { return !(l < r); }; |
| 68 | + friend inline bool operator!=(const Digit& l, const Digit& r) { return !(l == r); }; |
| 69 | + |
| 70 | + friend std::ostream& operator<<(std::ostream& os, const Digit& d); |
| 71 | + |
| 72 | + public: |
| 73 | + Digit() = default; |
| 74 | + Digit(int pad, uint16_t charge); |
| 75 | + Digit(int chamber, int photo, int x, int y, uint16_t charge); |
| 76 | + Digit(uint16_t charge, int equipment, int column, int dilogic, int channel); |
| 77 | + Digit(uint16_t charge, int module, int x, int y); |
| 78 | + |
| 79 | + // Getter & Setters |
| 80 | + uint16_t getCharge() const { return mQ; } |
| 81 | + void setCharge(uint16_t Q) |
| 82 | + { |
| 83 | + mQ = Q; |
| 84 | + return; |
| 85 | + }; |
| 86 | + int getPadID() const { return mCh << 24 | mPh << 16 | mX << 8 | mY; } |
| 87 | + void setPadID(uint32_t pad) |
| 88 | + { |
| 89 | + mCh = pad >> 24; |
| 90 | + mPh = (pad & 0x00FF0000) >> 16; |
| 91 | + mX = (pad & 0x0000FF00) >> 8; |
| 92 | + mY = (pad & 0x000000FF); |
| 93 | + return; |
| 94 | + }; |
| 95 | + |
| 96 | + bool isValid() { return (mCh == 0xFF ? true : false); }; |
| 97 | + void setInvalid() |
| 98 | + { |
| 99 | + mCh = 0xFF; |
| 100 | + return; |
| 101 | + }; |
| 102 | + |
| 103 | + // // convenience wrapper function for conversion to x-y pad coordinates |
| 104 | + // int getPx() const { return A2X(mPad); } |
| 105 | + // int getPy() const { return A2Y(mPad); } |
| 106 | + // int getPhC() const { return A2P(mPad); } |
| 107 | + // int getCh() const { return A2C(mPad); } |
| 108 | + |
| 109 | + // Charge management functions |
| 110 | + static void getPadAndTotalCharge(o2::hmpid::HitType const& hit, int& chamber, int& pc, int& px, int& py, float& totalcharge); |
| 111 | + static float getFractionalContributionForPad(o2::hmpid::HitType const& hit, int somepad); |
| 112 | + void addCharge(float q) |
| 113 | + { |
| 114 | + mQ += q; |
| 115 | + if (mQ > 0x0FFF) { |
| 116 | + mQ = 0x0FFF; |
| 117 | + } |
| 118 | + } |
| 119 | + void subCharge(float q) { mQ -= q; } |
| 120 | + |
| 121 | + public: |
| 122 | + // Members |
| 123 | + uint16_t mQ = 0; |
| 124 | + uint8_t mCh = 0; // 0xFF indicates invalid digit |
| 125 | + uint8_t mPh = 0; |
| 126 | + uint8_t mX = 0; |
| 127 | + uint8_t mY = 0; |
| 128 | + |
| 129 | + // The Pad Unique Id, code a pad inside one HMPID chamber. |
| 130 | + // Bit Map : 0000.0000.cccc.pppp.xxxx.xxxx.yyyy.yyyy |
| 131 | + // cccc := chamber [0..6] |
| 132 | + // pppp := photo cathode [0..5] |
| 133 | + // xxxx.xxxx := horizontal displacement [0..79] |
| 134 | + // yyyy.yyyy := vertical displacement [0..47] |
| 135 | + //uint32_t mPad = 0; // 0xFFFFFFFF indicates invalid digit |
| 136 | + |
| 137 | + // Get the Geometric center of the pad |
| 138 | + static float lorsX(int pad) { return Param::lorsX(a2P(pad), a2X(pad)); } //center of the pad x, [cm] |
| 139 | + static float lorsY(int pad) { return Param::lorsY(a2P(pad), a2Y(pad)); } //center of the pad y, [cm] |
| 140 | + |
| 141 | + // determines the total charge created by a hit |
| 142 | + // might modify the localX, localY coordiates associated to the hit |
| 143 | + static Double_t qdcTot(Double_t e, Double_t time, Int_t pc, Int_t px, Int_t py, Double_t& localX, Double_t& localY); |
| 144 | + static Double_t intPartMathiX(Double_t x, Int_t pad); |
| 145 | + static Double_t intPartMathiY(Double_t y, Int_t pad); |
| 146 | + static Double_t inMathieson(Double_t localX, Double_t localY, int pad); |
| 147 | + |
| 148 | + ClassDefNV(Digit, 2); |
| 149 | +}; |
| 150 | + |
| 151 | +} // namespace hmpid |
| 152 | +} // namespace o2 |
| 153 | + |
| 154 | +#endif /* DETECTORS_HMPID_BASE_INCLUDE_HMPIDDATAFORMAT_DIGIT_H_ */ |
0 commit comments