Skip to content

Commit 7fdb992

Browse files
shahor02sawenzel
authored andcommitted
BunchFilling separate class, store it in RunContext
Moved bunch filling used for simulation to new o2::BunchFilling class; The digitization-flow will save the used BunchFilling in the RunContext, together with the assumed mu per BC (info may be needed by particular digitizers for QED handling)
1 parent 81277fe commit 7fdb992

File tree

13 files changed

+209
-160
lines changed

13 files changed

+209
-160
lines changed

DataFormats/common/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ O2_SETUP(NAME ${MODULE_NAME})
44

55
set(SRCS
66
src/InteractionRecord.cxx
7+
src/BunchFilling.cxx
78
)
89

910
Set(HEADERS
1011
include/${MODULE_NAME}/TimeStamp.h
1112
include/${MODULE_NAME}/EvIndex.h
1213
include/${MODULE_NAME}/InteractionRecord.h
14+
include/${MODULE_NAME}/BunchFilling.h
1315
)
1416

1517
Set(LINKDEF src/CommonDataFormatLinkDef.h)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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 pattern of filled (interacting) bunches
12+
13+
#ifndef ALICEO2_BUNCHFILLING_H
14+
#define ALICEO2_BUNCHFILLING_H
15+
16+
#include "CommonConstants/LHCConstants.h"
17+
#include <bitset>
18+
19+
namespace o2
20+
{
21+
class BunchFilling
22+
{
23+
public:
24+
int getNBunches() const { return mPattern.count(); }
25+
bool testBC(int bcID) const { return mPattern[bcID]; }
26+
void setBC(int bcID, bool active = true);
27+
void setBCTrain(int nBC, int bcSpacing, int firstBC);
28+
void setBCTrains(int nTrains, int trainSpacingInBC, int nBC, int bcSpacing, int firstBC);
29+
void print(int bcPerLine = 100) const;
30+
const auto& getPattern() const { return mPattern; }
31+
// set BC filling a la TPC TDR, 12 50ns trains of 48 BCs
32+
// but instead of uniform train spacing we add 96empty BCs after each train
33+
void setDefault()
34+
{
35+
setBCTrains(12, 96, 48, 2, 0);
36+
}
37+
38+
private:
39+
std::bitset<o2::constants::lhc::LHCMaxBunches> mPattern;
40+
41+
ClassDefNV(BunchFilling, 1);
42+
};
43+
}
44+
45+
#endif
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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+
#include "FairLogger.h"
12+
#include "CommonDataFormat/BunchFilling.h"
13+
14+
using namespace o2;
15+
16+
//_________________________________________________
17+
void BunchFilling::setBC(int bcID, bool active)
18+
{
19+
// add interacting BC slot
20+
if (bcID >= o2::constants::lhc::LHCMaxBunches) {
21+
LOG(FATAL) << "BCid is limited to " << 0 << '-' << o2::constants::lhc::LHCMaxBunches - 1
22+
<< FairLogger::endl;
23+
}
24+
mPattern.set(bcID, active);
25+
}
26+
27+
//_________________________________________________
28+
void BunchFilling::setBCTrain(int nBC, int bcSpacing, int firstBC)
29+
{
30+
// add interacting BC train with given spacing starting at given place, i.e.
31+
// train with 25ns spacing should have bcSpacing = 1
32+
for (int i = 0; i < nBC; i++) {
33+
setBC(firstBC);
34+
firstBC += bcSpacing;
35+
}
36+
}
37+
38+
//_________________________________________________
39+
void BunchFilling::setBCTrains(int nTrains, int trainSpacingInBC, int nBC, int bcSpacing, int firstBC)
40+
{
41+
// add nTrains trains of interacting BCs with bcSpacing within the train and trainSpacingInBC empty slots
42+
// between the trains
43+
for (int it = 0; it < nTrains; it++) {
44+
setBCTrain(nBC, bcSpacing, firstBC);
45+
firstBC += nBC * bcSpacing + trainSpacingInBC;
46+
}
47+
}
48+
49+
//_________________________________________________
50+
void BunchFilling::print(int bcPerLine) const
51+
{
52+
bool endlOK = false;
53+
for (int i = 0; i < o2::constants::lhc::LHCMaxBunches; i++) {
54+
printf("%c", mPattern[i] ? '+' : '-');
55+
if (((i + 1) % bcPerLine) == 0) {
56+
printf("\n");
57+
endlOK = true;
58+
} else {
59+
endlOK = false;
60+
}
61+
}
62+
if (!endlOK) {
63+
printf("\n");
64+
}
65+
}

DataFormats/common/src/CommonDataFormatLinkDef.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@
3131

3232
#pragma link C++ class o2::dataformats::EvIndex < int, int > +;
3333
#pragma link C++ class o2::InteractionRecord + ;
34+
#pragma link C++ class o2::BunchFilling + ;
3435

3536
#endif

DataFormats/simulation/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ set(SRCS
66
src/Stack.cxx
77
src/MCTrack.cxx
88
src/MCCompLabel.cxx
9+
src/RunContext.cxx
910
)
1011

1112
Set(HEADERS

DataFormats/simulation/include/SimulationDataFormat/RunContext.h

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <TChain.h>
1616
#include <TBranch.h>
1717
#include "CommonDataFormat/InteractionRecord.h"
18+
#include "CommonDataFormat/BunchFilling.h"
1819

1920
namespace o2
2021
{
@@ -40,15 +41,6 @@ class RunContext
4041
public:
4142
RunContext() : mNofEntries{ 0 }, mMaxPartNumber{ 0 }, mEventRecords(), mEventParts() {}
4243

43-
// RS Do we needs this?
44-
TBranch* getBranch(std::string_view name, int sourceid = 0) const
45-
{
46-
if (mChains[sourceid]) {
47-
return mChains[sourceid]->GetBranch(name.data());
48-
}
49-
return nullptr;
50-
}
51-
5244
int getNCollisions() const { return mNofEntries; }
5345
void setNCollisions(int n) { mNofEntries = n; }
5446

@@ -57,26 +49,33 @@ class RunContext
5749

5850
std::vector<o2::InteractionRecord>& getEventRecords() { return mEventRecords; }
5951
std::vector<std::vector<o2::steer::EventPart>>& getEventParts() { return mEventParts; }
60-
std::vector<TChain*>& getChains() { return mChains; }
6152

6253
const std::vector<o2::InteractionRecord>& getEventRecords() const { return mEventRecords; }
6354
const std::vector<std::vector<o2::steer::EventPart>>& getEventParts() const { return mEventParts; }
64-
const std::vector<TChain*>& getChains() const { return mChains; }
55+
56+
o2::BunchFilling& getBunchFilling() { return mBCFilling; }
57+
const o2::BunchFilling& getBunchFilling() const { return (const o2::BunchFilling&)mBCFilling; }
58+
59+
void setMuPerBC(float m) { mMuBC = m; }
60+
float getMuPerBC() const { return mMuBC; }
6561

6662
void printCollisionSummary() const;
6763

6864
private:
6965
int mNofEntries = 0;
7066
int mMaxPartNumber = 0; // max number of parts in any given collision
67+
float mMuBC; // probability of hadronic interaction per bunch
68+
7169
std::vector<o2::InteractionRecord> mEventRecords;
7270
// for each collision we record the constituents (which shall not exceed mMaxPartNumber)
7371
std::vector<std::vector<o2::steer::EventPart>> mEventParts;
74-
std::vector<TChain*> mChains; //! pointers to input chains
72+
73+
o2::BunchFilling mBCFilling; // patter of active BCs
7574

7675
// it would also be appropriate to record the filenames
7776
// that went into the chain
7877

79-
ClassDefNV(RunContext, 1);
78+
ClassDefNV(RunContext, 2);
8079
};
8180
}
8281
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
#include "SimulationDataFormat/RunContext.h"
12+
#include <iostream>
13+
14+
using namespace o2::steer;
15+
16+
void RunContext::printCollisionSummary() const
17+
{
18+
std::cout << "Summary of RunContext --\n";
19+
std::cout << "Number of Collisions " << mEventRecords.size() << "\n";
20+
for (int i = 0; i < mEventRecords.size(); ++i) {
21+
std::cout << "Collision " << i << " TIME " << mEventRecords[i].timeNS;
22+
for (auto& e : mEventParts[i]) {
23+
std::cout << " (" << e.sourceID << " , " << e.entryID << ")";
24+
}
25+
std::cout << "\n";
26+
}
27+
}

Steer/include/Steer/HitProcessingManager.h

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ class HitProcessingManager
4949

5050
void setGeometryFile(std::string const& geomfile) { mGeometryFile = geomfile; }
5151

52-
void setInteractionSampler();
52+
o2::steer::InteractionSampler& getInteractionSampler() { return mInteractionSampler; }
53+
5354
void sampleCollisionTimes();
5455
void sampleCollisionConstituents();
5556

@@ -92,6 +93,8 @@ inline void HitProcessingManager::sampleCollisionTimes()
9293
{
9394
mRunContext.getEventRecords().resize(mRunContext.getNCollisions());
9495
mInteractionSampler.generateCollisionTimes(mRunContext.getEventRecords());
96+
mRunContext.getBunchFilling() = mInteractionSampler.getBunchFilling();
97+
mRunContext.setMuPerBC(mInteractionSampler.getMuPerBC());
9598
}
9699

97100
inline void HitProcessingManager::sampleCollisionConstituents()
@@ -157,25 +160,6 @@ inline void HitProcessingManager::run()
157160
}
158161
}
159162

160-
template <typename HitType, typename Task_t>
161-
std::function<void(const o2::steer::RunContext&)> defaultRunFunction(Task_t& task, std::string_view brname)
162-
{
163-
// using HitType = Task_t::InputType;
164-
return [&task, brname](const o2::steer::RunContext& c) {
165-
HitType* hittype = nullptr;
166-
auto br = c.getBranch(brname.data());
167-
assert(br);
168-
br->SetAddress(&hittype);
169-
for (auto entry = 0; entry < c.getNCollisions(); ++entry) {
170-
br->GetEntry(entry);
171-
task.setData(hittype, &c);
172-
task.Exec("");
173-
}
174-
task.FinishTask();
175-
// delete hittype
176-
};
177-
}
178-
179163
inline void HitProcessingManager::registerRunFunction(RunFunct_t&& f) { mRegisteredRunFunctions.emplace_back(f); }
180164

181165
inline void HitProcessingManager::addInputFile(std::string_view simfilename)

Steer/include/Steer/InteractionSampler.h

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
#include <Rtypes.h>
1717
#include <TMath.h>
1818
#include <TRandom.h>
19-
#include <bitset>
2019
#include <vector>
2120
#include "CommonDataFormat/InteractionRecord.h"
21+
#include "CommonDataFormat/BunchFilling.h"
2222
#include "CommonConstants/LHCConstants.h"
2323

2424
namespace o2
@@ -28,56 +28,47 @@ namespace steer
2828
class InteractionSampler
2929
{
3030
public:
31-
static constexpr double Sec2NanoSec = 1.e9; // s->ns conversion
32-
33-
using BunchFilling = std::bitset<o2::constants::lhc::LHCMaxBunches>;
31+
static constexpr float Sec2NanoSec = 1.e9; // s->ns conversion
3432

3533
o2::InteractionRecord generateCollisionTime();
3634
void generateCollisionTimes(std::vector<o2::InteractionRecord>& dest);
3735

3836
void init();
3937

40-
void setInteractionRate(double rateHz) { mIntRate = rateHz; }
41-
double getInteractionRate() const { return mIntRate; }
42-
void setMuPerBC(double mu) { mMuBC = mu; }
43-
double getMuPerBC() const { return mMuBC; }
44-
void setBCTimeRMS(double tNS = 0.2) { mBCTimeRMS = tNS; }
45-
double getBCTimeRMS() const { return mBCTimeRMS; }
38+
void setInteractionRate(float rateHz) { mIntRate = rateHz; }
39+
float getInteractionRate() const { return mIntRate; }
40+
void setMuPerBC(float mu) { mMuBC = mu; }
41+
float getMuPerBC() const { return mMuBC; }
42+
void setBCTimeRMS(float tNS = 0.2) { mBCTimeRMS = tNS; }
43+
float getBCTimeRMS() const { return mBCTimeRMS; }
4644
const BunchFilling& getBunchFilling() const { return mBCFilling; }
4745
BunchFilling& getBunchFilling() { return mBCFilling; }
48-
int getNCollidingBC() const { return mBCFilling.count(); }
4946
int getBCMin() const { return mBCMin; }
5047
int getBCMax() const { return mBCMax; }
51-
bool getBC(int bcID) const { return mBCFilling.test(bcID); }
52-
void setBC(int bcID, bool active = true);
53-
void setBCTrain(int nBC, int bcSpacing, int firstBC);
54-
void setBCTrains(int nTrains, int trainSpacingInBC, int nBC, int bcSpacing, int firstBC);
55-
void setDefaultBunchFilling();
5648

5749
void print() const;
58-
void printBunchFilling(int bcPerLine = 100) const;
5950

6051
protected:
6152
int simulateInteractingBC();
6253
int genPoissonZT();
6354
void nextCollidingBC();
55+
void warnOrbitWrapped() const;
6456

6557
int mIntBCCache = 0; ///< N interactions left for current BC
6658
int mBCCurrent = 0; ///< current BC
67-
int mOrbit = 0; ///< current orbit
68-
int mPeriod = 0; ///< current period
59+
unsigned int mOrbit = 0; ///< current orbit
6960
int mBCMin = 0; ///< 1st filled BCID
7061
int mBCMax = -1; ///< last filled BCID
71-
double mIntRate = -1.; ///< total interaction rate in Hz
72-
double mBCTimeRMS = 0.2; ///< BC time spread in NANOSECONDS
73-
double mMuBC = -1.; ///< interaction probability per BC
74-
double mProbNoInteraction = 1.; ///< probability of BC w/o interaction
75-
double mMuBCZTRed = 0; ///< reduced mu for fast zero-truncated Poisson derivation
62+
float mIntRate = -1.; ///< total interaction rate in Hz
63+
float mBCTimeRMS = 0.2; ///< BC time spread in NANOSECONDS
64+
float mMuBC = -1.; ///< interaction probability per BC
65+
float mProbNoInteraction = 1.; ///< probability of BC w/o interaction
66+
float mMuBCZTRed = 0; ///< reduced mu for fast zero-truncated Poisson derivation
7667

77-
BunchFilling mBCFilling; ///< patter of active BCs
78-
std::vector<double> mTimeInBC; ///< interaction times within single BC
68+
o2::BunchFilling mBCFilling; ///< patter of active BCs
69+
std::vector<float> mTimeInBC; ///< interaction times within single BC
7970

80-
static constexpr double DefIntRate = 50e3; ///< default interaction rate
71+
static constexpr float DefIntRate = 50e3; ///< default interaction rate
8172

8273
ClassDefNV(InteractionSampler, 1);
8374
};
@@ -99,12 +90,12 @@ inline void InteractionSampler::nextCollidingBC()
9990
do {
10091
if (++mBCCurrent > mBCMax) { // did we exhaust full orbit?
10192
mBCCurrent = mBCMin;
102-
if (++mOrbit >= o2::constants::lhc::MaxNOrbits) { // did we exhaust full period?
93+
if (++mOrbit >= o2::constants::lhc::MaxNOrbits) { // wrap orbit (should not happen in run3)
94+
warnOrbitWrapped();
10395
mOrbit = 0;
104-
mPeriod++;
10596
}
10697
}
107-
} while (!mBCFilling[mBCCurrent]);
98+
} while (!mBCFilling.testBC(mBCCurrent));
10899
}
109100

110101
//_________________________________________________

0 commit comments

Comments
 (0)