Skip to content

Commit e523405

Browse files
authored
Merge 6e4b06d into sapling-pr-archive-ktf
2 parents 73e94b5 + 6e4b06d commit e523405

File tree

27 files changed

+1077
-13
lines changed

27 files changed

+1077
-13
lines changed

DataFormats/Detectors/TRD/include/DataFormatsTRD/Digit.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class Digit
5959
Digit(int det, int row, int pad, ArrayADC adc, int phase = 0);
6060
Digit(int det, int row, int pad); // add adc data and pretrigger phase in a separate step
6161
Digit(int det, int rob, int mcm, int channel, ArrayADC adc, int phase = 0);
62-
Digit(int det, int rob, int mcm, int channel); // add adc data in a seperate step
62+
Digit(int det, int rob, int mcm, int channel, int phase = 0); // add adc data
6363

6464
// Copy
6565
Digit(const Digit&) = default;
@@ -74,9 +74,11 @@ class Digit
7474
void setDetector(int det) { mDetector = ((mDetector & 0xf000) | (det & 0xfff)); }
7575
void setADC(ArrayADC const& adc) { mADC = adc; }
7676
void setADC(const gsl::span<ADC_t>& adc) { std::copy(adc.begin(), adc.end(), mADC.begin()); }
77-
void setPreTrigPhase(int phase) { mDetector = (((phase & 0xf) << 12) | (mDetector & 0xfff)); }
77+
// set the trigger phase make sure it is mapped to 2 bits as it can only have 4 valid numbers shifted 0,3,6,9 or 1,4,7,10 etc.
78+
void setPreTrigPhase(int phase);
7879
// Get methods
7980
int getDetector() const { return mDetector & 0xfff; }
81+
int getDetectorInFull() const { return mDetector; } // return the entire mDetector 16 bits, so far only for CTF encoding.
8082
int getHCId() const { return (mDetector & 0xfff) * 2 + (mROB % 2); }
8183
int getPadRow() const { return HelperMethods::getPadRowFromMCM(mROB, mMCM); }
8284
int getPadCol() const { return HelperMethods::getPadColFromADC(mROB, mMCM, mChannel); }

DataFormats/Detectors/TRD/include/DataFormatsTRD/PHData.h

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,66 @@ class PHData
6161

6262
ClassDefNV(PHData, 1);
6363
};
64+
65+
/*
66+
This data type is used to send around the information required to fill PH plots per chamber
67+
68+
|19|18|17|16|15|14|13|12|11|10|09|08|07|06|05|04|03|02|01|00|
69+
-------------------------------------------------------------
70+
|type |nNeighb | time bin | detector number |
71+
-------------------------------------------------------------
72+
*/
73+
/*
74+
This data type is used to send around the information required to fill PH plots per chamber
75+
76+
|15|14|13|12|11|10|09|08|07|06|05|04|03|02|01|00|
77+
------------------------------------------------
78+
| ADC sum for all neigbours |
79+
------------------------------------------------
80+
*/
81+
82+
class PHDataHD
83+
{
84+
public:
85+
enum Origin : uint8_t {
86+
ITSTPCTRD,
87+
TPCTRD,
88+
TRACKLET,
89+
OTHER
90+
};
91+
92+
PHDataHD() = default;
93+
PHDataHD(int adc, int det, int tb, int nb, int type) { set(adc, det, tb, nb, type); }
94+
95+
void set(int adc, int det, int tb, int nb, int type)
96+
{
97+
mDetector = det;
98+
mTimeBin = tb;
99+
mType = type;
100+
mNNeighbours = nb;
101+
mADC = adc;
102+
}
103+
104+
// the ADC sum for given time bin for up to three neighbours
105+
int getADC() const { return mADC; }
106+
// the TRD detector number
107+
int getDetector() const { return mDetector; }
108+
// the given time bin
109+
int getTimebin() const { return mTimeBin; }
110+
// number of neighbouring digits for which the ADC is accumulated
111+
int getNNeighbours() const { return mNNeighbours; }
112+
// the origin of this point: digit on ITS-TPC-TRD track, ... (see enum Origin above)
113+
int getType() const { return mType; }
114+
115+
private:
116+
uint16_t mDetector{0};
117+
uint8_t mTimeBin{0};
118+
uint8_t mType{0};
119+
uint8_t mNNeighbours{0};
120+
uint16_t mADC{0};
121+
122+
ClassDefNV(PHDataHD, 1);
123+
};
64124
} // namespace o2::trd
65125

66126
#endif // ALICEO2_TRD_PHDATA_H_

DataFormats/Detectors/TRD/src/DataFormatsTRDLinkDef.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#pragma link C++ class o2::trd::ChannelInfo + ;
4444
#pragma link C++ class o2::trd::ChannelInfoContainer + ;
4545
#pragma link C++ struct o2::trd::PHData + ;
46+
#pragma link C++ struct o2::trd::PHDataHD + ;
4647
#pragma link C++ class o2::trd::TRDDataCountersPerTimeFrame + ;
4748
#pragma link C++ class o2::trd::DataCountersPerTrigger + ;
4849
#pragma link C++ class std::vector < o2::trd::Tracklet64> + ;
@@ -56,6 +57,7 @@
5657
#pragma link C++ class std::vector < o2::trd::GainCalibHistos> + ;
5758
#pragma link C++ class std::vector < o2::trd::T0FitHistos> + ;
5859
#pragma link C++ class std::vector < o2::trd::PHData> + ;
60+
#pragma link C++ class std::vector < o2::trd::PHDataHD> + ;
5961
#pragma link C++ class std::vector < o2::trd::KrCluster> + ;
6062
#pragma link C++ class std::vector < o2::trd::KrClusterTriggerRecord> + ;
6163
#pragma link C++ class std::vector < o2::trd::DataCountersPerTrigger> + ;

DataFormats/Detectors/TRD/src/Digit.cxx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "DataFormatsTRD/Digit.h"
1313
#include <iostream>
1414
#include <algorithm>
15+
#include "fairlogger/Logger.h"
1516

1617
namespace o2::trd
1718
{
@@ -46,12 +47,18 @@ Digit::Digit(int det, int rob, int mcm, int channel, ArrayADC adc, int pretrigph
4647
setPreTrigPhase(pretrigphase);
4748
}
4849

49-
Digit::Digit(int det, int rob, int mcm, int channel) // add adc data in a seperate step
50+
Digit::Digit(int det, int rob, int mcm, int channel, int pretrigphase) // add adc data in a seperate step
5051
{
5152
setDetector(det);
5253
setROB(rob);
5354
setMCM(mcm);
5455
setChannel(channel);
56+
setPreTrigPhase(pretrigphase);
57+
}
58+
59+
void Digit::setPreTrigPhase(int phase)
60+
{
61+
mDetector = ((((phase) & 0x3) << 12) | (mDetector & 0xfff));
5562
}
5663

5764
bool Digit::isSharedDigit() const

DataFormats/Parameters/include/DataFormatsParameters/AggregatedRunInfo.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ namespace o2::parameters
2323
{
2424

2525
class GRPECSObject;
26+
class GRPLHCIFData;
2627

2728
/// Composite struct where one may collect important global properties of data "runs"
2829
/// aggregated from various sources (GRPECS, RunInformation CCDB entries, etc.).
@@ -39,8 +40,9 @@ struct AggregatedRunInfo {
3940

4041
// we may have pointers to actual data source objects GRPECS, ...
4142
const o2::parameters::GRPECSObject* grpECS = nullptr; // pointer to GRPECSobject (fetched during struct building)
43+
const o2::parameters::GRPLHCIFData* grpLHC = nullptr;
4244

43-
static AggregatedRunInfo buildAggregatedRunInfo(int runnumber, long sorMS, long eorMS, long orbitResetMUS, const o2::parameters::GRPECSObject* grpecs, const std::vector<Long64_t>* ctfFirstRunOrbitVec);
45+
static AggregatedRunInfo buildAggregatedRunInfo(int runnumber, long sorMS, long eorMS, long orbitResetMUS, const o2::parameters::GRPECSObject* grpecs, const std::vector<Long64_t>* ctfFirstRunOrbitVec, const o2::parameters::GRPLHCIFData* grplhcif = nullptr);
4446

4547
// fills and returns AggregatedRunInfo for a given data run number.
4648
static AggregatedRunInfo buildAggregatedRunInfo_DATA(o2::ccdb::CCDBManagerInstance& ccdb, int runnumber);

DataFormats/Parameters/src/AggregatedRunInfo.cxx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "DataFormatsParameters/AggregatedRunInfo.h"
1616
#include "CCDB/BasicCCDBManager.h"
1717
#include "DataFormatsParameters/GRPECSObject.h"
18+
#include "DataFormatsParameters/GRPLHCIFData.h"
1819
#include "CommonConstants/LHCConstants.h"
1920
#include "Framework/Logger.h"
2021
#include <map>
@@ -42,14 +43,15 @@ o2::parameters::AggregatedRunInfo AggregatedRunInfo::buildAggregatedRunInfo_DATA
4243
std::map<std::string, std::string> metadata;
4344
metadata["runNumber"] = Form("%d", runnumber);
4445
auto grpecs = ccdb.getSpecific<o2::parameters::GRPECSObject>("GLO/Config/GRPECS", run_mid_timestamp, metadata);
46+
auto grplhcif = ccdb.getSpecific<o2::parameters::GRPLHCIFData>("GLO/Config/GRPLHCIF", run_mid_timestamp); // no run metadata here
4547
bool oldFatalState = ccdb.getFatalWhenNull();
4648
ccdb.setFatalWhenNull(false);
4749
auto ctp_first_run_orbit = ccdb.getForTimeStamp<std::vector<Long64_t>>("CTP/Calib/FirstRunOrbit", run_mid_timestamp);
4850
ccdb.setFatalWhenNull(oldFatalState);
49-
return buildAggregatedRunInfo(runnumber, sor, eor, tsOrbitReset, grpecs, ctp_first_run_orbit);
51+
return buildAggregatedRunInfo(runnumber, sor, eor, tsOrbitReset, grpecs, ctp_first_run_orbit, grplhcif);
5052
}
5153

52-
o2::parameters::AggregatedRunInfo AggregatedRunInfo::buildAggregatedRunInfo(int runnumber, long sorMS, long eorMS, long orbitResetMUS, const o2::parameters::GRPECSObject* grpecs, const std::vector<Long64_t>* ctfFirstRunOrbitVec)
54+
o2::parameters::AggregatedRunInfo AggregatedRunInfo::buildAggregatedRunInfo(int runnumber, long sorMS, long eorMS, long orbitResetMUS, const o2::parameters::GRPECSObject* grpecs, const std::vector<Long64_t>* ctfFirstRunOrbitVec, const o2::parameters::GRPLHCIFData* grplhcif)
5355
{
5456
auto nOrbitsPerTF = grpecs->getNHBFPerTF();
5557
// calculate SOR/EOR orbits
@@ -81,7 +83,7 @@ o2::parameters::AggregatedRunInfo AggregatedRunInfo::buildAggregatedRunInfo(int
8183
orbitSOR = (orbitSOR / nOrbitsPerTF + 1) * nOrbitsPerTF;
8284
}
8385
}
84-
return AggregatedRunInfo{runnumber, sorMS, eorMS, nOrbitsPerTF, orbitResetMUS, orbitSOR, orbitEOR, grpecs};
86+
return AggregatedRunInfo{runnumber, sorMS, eorMS, nOrbitsPerTF, orbitResetMUS, orbitSOR, orbitEOR, grpecs, grplhcif};
8587
}
8688

8789
namespace

DataFormats/simulation/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ o2_target_root_dictionary(
5555
# * src/SimulationDataLinkDef.h
5656
# * and not src/SimulationDataFormatLinkDef.h
5757

58+
o2_add_test(InteractionSampler
59+
SOURCES test/testInteractionSampler.cxx
60+
COMPONENT_NAME SimulationDataFormat
61+
PUBLIC_LINK_LIBRARIES O2::SimulationDataFormat)
62+
5863
o2_add_test(BasicHits
5964
SOURCES test/testBasicHits.cxx
6065
COMPONENT_NAME SimulationDataFormat

DataFormats/simulation/include/SimulationDataFormat/InteractionSampler.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "CommonDataFormat/BunchFilling.h"
2323
#include "CommonConstants/LHCConstants.h"
2424
#include "MathUtils/RandomRing.h"
25+
#include <TH1F.h>
2526

2627
namespace o2
2728
{
@@ -130,6 +131,30 @@ class FixedSkipBC_InteractionSampler : public InteractionSampler
130131
ClassDef(FixedSkipBC_InteractionSampler, 1);
131132
};
132133

134+
// A version of the interaction sampler which can sample according to non-uniform mu(bc) as
135+
// observed during data taking.
136+
class NonUniformMuInteractionSampler : public InteractionSampler
137+
{
138+
public:
139+
NonUniformMuInteractionSampler() : InteractionSampler() { mBCIntensityScales.resize(o2::constants::lhc::LHCMaxBunches, 1); }
140+
bool setBCIntensityScales(const std::vector<float>& scales_from_vector);
141+
bool setBCIntensityScales(const TH1F& scales_from_histo); // initialize scales
142+
143+
// helper function to determine the scales from a histogram (count from event selection analysis)
144+
std::vector<float> determineBCIntensityScalesFromHistogram(const TH1F& scales_from_histo);
145+
146+
const std::vector<float>& getBCIntensityScales() const { return mBCIntensityScales; }
147+
148+
protected:
149+
int simulateInteractingBC() override;
150+
int getBCJump() const;
151+
152+
private:
153+
// non-uniformity
154+
std::vector<float> mBCIntensityScales;
155+
ClassDef(NonUniformMuInteractionSampler, 1);
156+
};
157+
133158
} // namespace steer
134159
} // namespace o2
135160

DataFormats/simulation/src/InteractionSampler.cxx

Lines changed: 96 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ const o2::InteractionTimeRecord& InteractionSampler::generateCollisionTime()
115115
int InteractionSampler::simulateInteractingBC()
116116
{
117117
// Returns number of collisions assigned to selected BC
118-
119118
nextCollidingBC(mBCJumpGenerator.getNextValue());
119+
120120
// once BC is decided, enforce at least one interaction
121121
int ncoll = mNCollBCGenerator.getNextValue();
122122

@@ -162,3 +162,98 @@ void InteractionSampler::setBunchFilling(const std::string& bcFillingFile)
162162
mBCFilling = *bc;
163163
delete bc;
164164
}
165+
166+
// ________________________________________________
167+
bool NonUniformMuInteractionSampler::setBCIntensityScales(const std::vector<float>& scales_from_vector)
168+
{
169+
// Sets the intensity scales per bunch crossing index
170+
// The length of this vector needs to be compatible with the bunch filling chosen
171+
mBCIntensityScales = scales_from_vector;
172+
173+
if (scales_from_vector.size() != mInteractingBCs.size()) {
174+
LOG(error) << "Scaling factors and bunch filling scheme are not compatible. Not doing anything";
175+
return false;
176+
}
177+
178+
float sum = 0.;
179+
for (auto v : mBCIntensityScales) {
180+
sum += std::abs(v);
181+
}
182+
if (sum == 0) {
183+
LOGP(warn, "total intensity is 0, assuming uniform");
184+
for (auto& v : mBCIntensityScales) {
185+
v = 1.f;
186+
}
187+
} else { // normalize
188+
float norm = mBCIntensityScales.size() / sum;
189+
for (auto& v : mBCIntensityScales) {
190+
v = std::abs(v) * norm;
191+
}
192+
}
193+
return false;
194+
}
195+
196+
// ________________________________________________
197+
198+
bool NonUniformMuInteractionSampler::setBCIntensityScales(const TH1F& hist)
199+
{
200+
return setBCIntensityScales(determineBCIntensityScalesFromHistogram(hist));
201+
}
202+
203+
std::vector<float> NonUniformMuInteractionSampler::determineBCIntensityScalesFromHistogram(const TH1F& hist)
204+
{
205+
std::vector<float> scales;
206+
// we go through the BCs and query the count from histogram
207+
for (auto bc : mInteractingBCs) {
208+
scales.push_back(hist.GetBinContent(bc + 1));
209+
}
210+
return scales;
211+
}
212+
213+
int NonUniformMuInteractionSampler::getBCJump() const
214+
{
215+
auto muFunc = [this](int bc_position) {
216+
return mBCIntensityScales[bc_position % mInteractingBCs.size()] * mMuBC;
217+
};
218+
219+
double U = gRandom->Rndm(); // uniform (0,1)
220+
double T = -std::log(1.0 - U); // threshold
221+
double sumMu = 0.0;
222+
int offset = 0;
223+
auto bcStart = mCurrBCIdx; // the current bc
224+
225+
while (sumMu < T) {
226+
auto mu_here = muFunc(bcStart + offset); // mu at next BC
227+
sumMu += mu_here;
228+
if (sumMu >= T) {
229+
break; // found BC with at least one collision
230+
}
231+
++offset;
232+
}
233+
return offset;
234+
}
235+
236+
int NonUniformMuInteractionSampler::simulateInteractingBC()
237+
{
238+
nextCollidingBC(getBCJump());
239+
240+
auto muFunc = [this](int bc_position) {
241+
return mBCIntensityScales[bc_position % mInteractingBCs.size()] * mMuBC;
242+
};
243+
244+
// now sample number of collisions in chosenBC, conditioned >=1:
245+
double mu_chosen = muFunc(mCurrBCIdx); // or does it need to be mCurrBCIdx
246+
int ncoll = 0;
247+
do {
248+
ncoll = gRandom->Poisson(mu_chosen);
249+
} while (ncoll == 0);
250+
251+
// assign random time withing a bunch
252+
for (int i = ncoll; i--;) {
253+
mTimeInBC.push_back(mCollTimeGenerator.getNextValue());
254+
}
255+
if (ncoll > 1) { // sort in DECREASING time order (we are reading vector from the end)
256+
std::sort(mTimeInBC.begin(), mTimeInBC.end(), [](const float a, const float b) { return a > b; });
257+
}
258+
return ncoll;
259+
}

DataFormats/simulation/src/SimulationDataLinkDef.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#pragma link C++ class o2::steer::InteractionSampler + ;
2727
#pragma link C++ class o2::steer::FixedSkipBC_InteractionSampler + ;
28+
#pragma link C++ class o2::steer::NonUniformMuInteractionSampler + ;
2829
#pragma link C++ class o2::sim::StackParam + ;
2930
#pragma link C++ class o2::conf::ConfigurableParamHelper < o2::sim::StackParam> + ;
3031
#pragma link C++ class o2::MCTrackT < double> + ;

0 commit comments

Comments
 (0)