Skip to content

Commit aac1514

Browse files
shahor02sawenzel
authored andcommitted
Moved sim/MCInteractionRecord to common/InteractionRecord
To be used also for reconstructed objects. Modified calculations to rely on common LHC constants
1 parent 4f390fc commit aac1514

13 files changed

Lines changed: 117 additions & 75 deletions

File tree

Common/Constants/include/CommonConstants/LHCConstants.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ namespace lhc
2323
{
2424
// LHC Beam1 and Beam2 definitions
2525
enum BeamDirection : int { BeamClockWise, BeamAntiClockWise, NBeamDirections };
26+
static constexpr int LHCMaxBunches = 3564; // max N bunches
27+
static constexpr double LHCRFFreq = 400.789e6; // LHC RF frequency in Hz
28+
static constexpr double LHCBunchSpacingNS = 10 * 1.e9 / LHCRFFreq; // bunch spacing in ns (10 RFbuckets)
29+
static constexpr double LHCOrbitNS = LHCMaxBunches * LHCBunchSpacingNS; // orbit duration in ns
30+
static constexpr double LHCRevFreq = 1.e9 / LHCOrbitNS; // revolution frequency
31+
32+
// ALICE conventions
33+
static constexpr int MaxNOrbits = 0x1 << 24; // above this (~24min) period is incremented
34+
static constexpr int OrbitMask = MaxNOrbits - 1;
35+
static constexpr int MaxNPeriods = 0x1 << 28;
36+
static constexpr int PreioidMask = MaxNPeriods - 1;
37+
static constexpr double PeriodDurationNS = MaxNOrbits * LHCOrbitNS;
2638
}
2739
}
2840
}

DataFormats/common/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ set(MODULE_NAME "CommonDataFormat")
33
O2_SETUP(NAME ${MODULE_NAME})
44

55
set(SRCS
6+
src/InteractionRecord.cxx
67
)
78

89
Set(HEADERS
910
include/${MODULE_NAME}/TimeStamp.h
1011
include/${MODULE_NAME}/EvIndex.h
12+
include/${MODULE_NAME}/InteractionRecord.h
1113
)
1214

1315
Set(LINKDEF src/CommonDataFormatLinkDef.h)
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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+
/// @brief Interaction record encoding BC, orbit, time
12+
13+
#ifndef ALICEO2_INTERACTIONRECORD_H
14+
#define ALICEO2_INTERACTIONRECORD_H
15+
16+
#include <Rtypes.h>
17+
#include <iosfwd>
18+
#include <cmath>
19+
#include "CommonConstants/LHCConstants.h"
20+
21+
namespace o2
22+
{
23+
struct InteractionRecord {
24+
double timeNS = 0.; ///< time in NANOSECONDS from start of run (period=0, orbit=0)
25+
int bc = 0; ///< bunch crossing ID of interaction
26+
int orbit = 0; ///< LHC orbit
27+
int period = 0; ///< LHC period since beginning of run (if >0 -> time precision loss)
28+
29+
InteractionRecord() = default;
30+
31+
InteractionRecord(double tNS)
32+
{
33+
setFromNS(tNS);
34+
}
35+
36+
InteractionRecord(int b, int orb, int per = 0) : bc(b), orbit(orb), period(per)
37+
{
38+
timeNS = bc2ns(bc, orbit, period);
39+
}
40+
41+
void setFromNS(double ns)
42+
{
43+
timeNS = ns;
44+
bc = ns2bc(ns, orbit, period);
45+
}
46+
47+
static double bc2ns(int bc, int orbit, int period)
48+
{
49+
double t = bc * o2::constants::lhc::LHCBunchSpacingNS + orbit * o2::constants::lhc::LHCOrbitNS;
50+
return period ? t + o2::constants::lhc::PeriodDurationNS : t;
51+
}
52+
53+
static int ns2bc(double ns, int& orb, int& per)
54+
{
55+
per = ns / o2::constants::lhc::PeriodDurationNS;
56+
if (per) {
57+
ns -= per * o2::constants::lhc::PeriodDurationNS;
58+
}
59+
orb = ns / o2::constants::lhc::LHCOrbitNS;
60+
ns -= orb * o2::constants::lhc::LHCOrbitNS;
61+
return std::round(ns / o2::constants::lhc::LHCBunchSpacingNS);
62+
}
63+
64+
void print() const;
65+
66+
ClassDefNV(InteractionRecord, 1);
67+
};
68+
}
69+
70+
#endif

DataFormats/common/src/CommonDataFormatLinkDef.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,6 @@
3030
#pragma link C++ class o2::dataformats::TimeStampWithError < int, int > +;
3131

3232
#pragma link C++ class o2::dataformats::EvIndex < int, int > +;
33+
#pragma link C++ class o2::InteractionRecord + ;
3334

3435
#endif

DataFormats/simulation/src/MCInteractionRecord.cxx renamed to DataFormats/common/src/InteractionRecord.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
// In applying this license CERN does not waive the privileges and immunities
88
// granted to it by virtue of its status as an Intergovernmental Organization
99
// or submit itself to any jurisdiction.
10-
#include "SimulationDataFormat/MCInteractionRecord.h"
10+
#include "CommonDataFormat/InteractionRecord.h"
1111
#include <iostream>
1212

1313
namespace o2
1414
{
15-
void MCInteractionRecord::print()
15+
void InteractionRecord::print() const
1616
{
1717
std::cout << "BCid: " << bc << " Orbit: " << orbit << " Period: " << period << " T(ns): " << timeNS << std::endl;
1818
}

DataFormats/simulation/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ set(SRCS
66
src/Stack.cxx
77
src/MCTrack.cxx
88
src/MCCompLabel.cxx
9-
src/MCInteractionRecord.cxx
109
)
1110

1211
Set(HEADERS
@@ -15,7 +14,6 @@ Set(HEADERS
1514
include/${MODULE_NAME}/BaseHits.h
1615
include/${MODULE_NAME}/MCTruthContainer.h
1716
include/${MODULE_NAME}/MCCompLabel.h
18-
include/${MODULE_NAME}/MCInteractionRecord.h
1917
include/${MODULE_NAME}/TrackReference.h
2018
include/${MODULE_NAME}/PrimaryChunk.h
2119
)

DataFormats/simulation/include/SimulationDataFormat/MCInteractionRecord.h

Lines changed: 0 additions & 39 deletions
This file was deleted.

DataFormats/simulation/src/SimulationDataLinkDef.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#pragma link C++ class std::vector < o2::MCTrackT < double >> +;
3131
#pragma link C++ class std::vector < o2::MCTrackT < float >> +;
3232
#pragma link C++ class o2::MCCompLabel + ;
33-
#pragma link C++ class o2::MCInteractionRecord + ;
3433

3534
#pragma link C++ class o2::BaseHit + ;
3635
#pragma link C++ class o2::BasicXYZEHit < float, float > +;

Steer/include/Steer/HitProcessingManager.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class RunContext
5858
void setMaxNumberParts(int maxp) { mMaxPartNumber = maxp; }
5959
int getMaxNumberParts() const { return mMaxPartNumber; }
6060

61-
const std::vector<o2::MCInteractionRecord>& getEventRecords() const { return mEventRecords; }
61+
const std::vector<o2::InteractionRecord>& getEventRecords() const { return mEventRecords; }
6262
const std::vector<std::vector<EventPart>>& getEventParts() const { return mEventParts; }
6363
const std::vector<TChain*>& getChains() const { return mChains; }
6464

@@ -67,7 +67,7 @@ class RunContext
6767
private:
6868
int mNofEntries = 0;
6969
int mMaxPartNumber = 0; // max number of parts in any given collision
70-
std::vector<o2::MCInteractionRecord> mEventRecords;
70+
std::vector<o2::InteractionRecord> mEventRecords;
7171
// for each collision we record the constituents (which shall not exceed mMaxPartNumber)
7272
std::vector<std::vector<EventPart>> mEventParts;
7373
std::vector<TChain*> mChains; //! pointers to input chains

Steer/include/Steer/InteractionSampler.h

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
#include <TRandom.h>
1919
#include <bitset>
2020
#include <vector>
21-
#include "SimulationDataFormat/MCInteractionRecord.h"
21+
#include "CommonDataFormat/InteractionRecord.h"
22+
#include "CommonConstants/LHCConstants.h"
2223

2324
namespace o2
2425
{
@@ -28,20 +29,11 @@ class InteractionSampler
2829
{
2930
public:
3031
static constexpr double Sec2NanoSec = 1.e9; // s->ns conversion
31-
static constexpr double LHCRevFreq = 11245.5; // LHC revolution frequenct in Hz
32-
static constexpr int LHCBCSlots = 3564; // Max N BC slots on LHC (including abort gap)
33-
static constexpr int MaxNOrbits = 0x1 << 24; // above this (~24min) period is incremented
34-
static constexpr int MaxNPeriods = 0x1 << 28; // above this period is incremented
35-
//
36-
static constexpr double OrbitDuration = Sec2NanoSec / LHCRevFreq; // min spacing between BCs in ns
37-
static constexpr double PeriodDuration =
38-
OrbitDuration * MaxNOrbits; // duration of period in ns (Prec.loss for periods>1)
39-
static constexpr double BCSpacingLHC = OrbitDuration / LHCBCSlots; // min spacing between BCs in ns
4032

41-
using BunchFilling = std::bitset<LHCBCSlots>;
33+
using BunchFilling = std::bitset<o2::constants::lhc::LHCMaxBunches>;
4234

43-
o2::MCInteractionRecord generateCollisionTime();
44-
void generateCollisionTimes(std::vector<o2::MCInteractionRecord>& dest);
35+
o2::InteractionRecord generateCollisionTime();
36+
void generateCollisionTimes(std::vector<o2::InteractionRecord>& dest);
4537

4638
void init();
4739

@@ -91,7 +83,7 @@ class InteractionSampler
9183
};
9284

9385
//_________________________________________________
94-
inline void InteractionSampler::generateCollisionTimes(std::vector<o2::MCInteractionRecord>& dest)
86+
inline void InteractionSampler::generateCollisionTimes(std::vector<o2::InteractionRecord>& dest)
9587
{
9688
// fill vector with interaction records
9789
dest.clear();
@@ -107,7 +99,7 @@ inline void InteractionSampler::nextCollidingBC()
10799
do {
108100
if (++mBCCurrent > mBCMax) { // did we exhaust full orbit?
109101
mBCCurrent = mBCMin;
110-
if (++mOrbit >= MaxNOrbits) { // did we exhaust full period?
102+
if (++mOrbit >= o2::constants::lhc::MaxNOrbits) { // did we exhaust full period?
111103
mOrbit = 0;
112104
mPeriod++;
113105
}

0 commit comments

Comments
 (0)