Skip to content

Commit e0618bb

Browse files
authored
Merge pull request #222 from saganatt/event-mixing
Update event mixing documentation with slice cache and lambda binning
2 parents a654900 + 7b62dd9 commit e0618bb

File tree

2 files changed

+49
-15
lines changed

2 files changed

+49
-15
lines changed

docs/advanced-specifics/eventMixing.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,23 @@ o2::soa::combinations (CombinationIndexPolicy(tracks1, tracks2, ...))
1717
1818
which returns tuples of tracks (one track from each table of tracks).
1919
20-
There are several *CombinationIndexPolicies* available which are explained [here](../framework/framework.md#getting-combinations-pairs-triplets-). It is recommended that you will get first well acquainted with combinations before moving on to mixing.
20+
There are several *CombinationIndexPolicies* available which are explained [here](../basics-tasks/CombiningData.md). It is recommended that you will get first well acquainted with combinations before moving on to mixing.
2121
22-
## Event mixing
22+
## Mixing generator
2323
2424
`GroupedCombinationsGenerator` which generates mixed event pairs is a generalization of block combination policies. Therefore, it accepts the same parameters:
2525
2626
- binning policy
2727
- outsider
2828
- category neighbours (equivalent to the number of other collisions to mix with)
2929
30-
You can consult a detailed description of these parameters in the [block combinations section](../framework/framework.md#block--binned-combination-policies).
30+
You can consult a detailed description of these parameters in the [block combinations section](../basics-tasks/CombiningData.md#block--binned-combination-policies).
3131
3232
The `GroupedCombinationsGenerator` general constructor is defined as:
3333
3434
```cpp
3535
template <typename T1, typename GroupingPolicy, typename BP, typename G, typename... As>
36-
GroupedCombinationsGenerator(const BP& binningPolicy, int catNeighbours, const T1& outsider, G& grouping, std::tuple<T2s...>& associated)
36+
GroupedCombinationsGenerator(const BP& binningPolicy, int catNeighbours, const T1& outsider, G& grouping, std::tuple<T2s...>& associated, SliceCache* cache)
3737
```
3838

3939
This is a more general functionality which potentially could be used for other applications beyond event mixing. However, to simplify this tutorial, let's assume our `grouping` table is the table of collisions, and the `associated` are tables of structures like tracks and V0s.
@@ -43,7 +43,8 @@ This is a more general functionality which potentially could be used for other a
4343
- `T1`: type of an outsider value as well as the value itself as a parameter,
4444
- `GroupingPolicy`: type of a *BlockCombinationIndexPolicies* which specifies how collision pairs will be generated (strictly upper, upper or full block combinations)i,
4545
- `BP`: type of a binning policy applied to the block combinations of collisions as well as the policy instance,
46-
- input grouping (collisions) and associated (tracks, V0s) tables and their types.
46+
- input grouping (collisions) and associated (tracks, V0s) tables and their types
47+
- a pointer to the `SliceCache` which is used implicitly for efficient slicing of associated tables
4748

4849
To simplify the code, there are helper shortcuts defined for the most common use cases:
4950

docs/tutorials/eventMixing.md

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ Obtain mixed event tuples.
1414
Executable: o2-analysistutorial-event-mixing
1515
</div>
1616

17-
For a general introduction to combinations and event mixing, check first [here](../framework/eventMixing.md).
17+
For a general introduction to combinations and event mixing, check first [here](../advanced-specifics/eventMixing.md).
1818

19-
### MixedEvents
19+
## MixedEvents
2020

21-
Firstly, we define binning of collisions for block combinations:
21+
Firstly, we define slice cache and binning of collisions for block combinations:
2222

2323
```cpp
24+
SliceCache cache;
2425
std::vector<double> xBins{VARIABLE_WIDTH, -0.064, -0.062, -0.060, 0.066, 0.068, 0.070, 0.072};
2526
std::vector<double> yBins{VARIABLE_WIDTH, -0.320, -0.301, -0.300, 0.330, 0.340, 0.350, 0.360};
2627
using BinningType = BinningPolicy<aod::collision::PosX, aod::collision::PosY>;
@@ -32,7 +33,7 @@ BinningType binningOnPositions{{xBins, yBins}, true};
3233
Then, we define the mixing structure itself:
3334
3435
```cpp
35-
SameKindPair<aod::Collisions, aod::Tracks, BinningType> pair{binningOnPositions, 5, -1}; // indicates that 5 events should be mixed and under/overflow (-1) to be ignored
36+
SameKindPair<aod::Collisions, aod::Tracks, BinningType> pair{binningOnPositions, 5, -1, &cache}; // indicates that 5 events should be mixed and under/overflow (-1) to be ignored
3637
```
3738

3839
In this case, only table types and the binning police type need to be passed, as the rest is taken from the defaults.
@@ -53,15 +54,15 @@ for (auto& [t1, t2] : combinations(CombinationsFullIndexPolicy(tracks1, tracks2)
5354
}
5455
```
5556

56-
### MixedEventsInsideProcess
57+
## MixedEventsInsideProcess
5758

5859
This is the same task as above, with the difference that binning policy and `SameKindPair` are declared inside `process()`. This is particularly helpful when your bins are ConfigurableAxes. The standard out-of-process declaration of binning policy and corresponding mixing structure would take only default configurable values.
5960

60-
### Task with different table structures
61+
## Tasks with different table structures
6162

6263
These tasks demonstrate how mixing works with Filtered and Join.
6364

64-
### MixedEventsDynamicColumns
65+
## MixedEventsDynamicColumns
6566

6667
This is a more realistic example with mixing of collisions binned by z-vertex and multiplicity V0M. As `MultFV0M` is a dynamic column, its type is templated on the contributing column types. Therefore, the binning policy type is:
6768

@@ -71,15 +72,15 @@ using BinningType = BinningPolicy<aod::collision::PosZ, aod::mult::MultFV0M<aod:
7172

7273
The rest of the task is the same as in the basic example.
7374

74-
### Tasks with different table kinds
75+
## Tasks with different table kinds
7576

7677
These tasks demonstrate usage of `Pair`, `Triple` and `SameKindTriple` on tracks and V0s.
7778

78-
### MixedEventsWithHashTask
79+
## MixedEventsWithHashTask
7980

8081
This task shows how one can use `NoBinningPolicy` in case of bins predefined somewhere else.
8182

82-
### MixedEventsPartitionedTracks
83+
## MixedEventsPartitionedTracks
8384

8485
This is a bit more advanced example which shows how one can further partition the tracks from mixing. As the tracks tables are produced only at the generation of each mixed collision pair, `Partitions` must be declared inside the mixing loop. Additionally, each partition must be bound to a respective table -- `tracks1` or `tracks2`. Then, the corresponding partitioning condition is applied to the selected table.
8586

@@ -95,3 +96,35 @@ for (auto& [c1, tracks1, c2, tracks2] : pair) {
9596
rightPhi2.bindTable(tracks2);
9697
}
9798
```
99+
100+
## MixedEventsLambdaBinning
101+
102+
The task demonstrates how to use FlexibleBinningPolicy if binning cannot be calculated straight from the collision columns, but is obtained from other variables in a user-defined function.<br>
103+
This is naturally implemented for mixing inside `process()`, as the helper lambda function is usually defined inside `process()`. For example:
104+
105+
```cpp
106+
void process(aod::Collisions& collisions, aod::Tracks& tracks) {
107+
auto getTracksSize =
108+
[&tracks, this](aod::Collision const& col) {
109+
auto associatedTracks = tracks.sliceByCached(o2::aod::track::collisionId, col.globalIndex(), this->cache); // it's cached, so slicing/grouping happens only once
110+
return associatedTracks.size();
111+
};
112+
```
113+
114+
The binning policy:
115+
116+
```cpp
117+
using BinningType = FlexibleBinningPolicy<std::tuple<decltype(getTracksSize)>, aod::collision::PosZ, decltype(getTracksSize)>;
118+
BinningType binningWithLambda{{getTracksSize}, {axisVertex, axisMultiplicity}, true};
119+
```
120+
121+
A tuple with types of all lambda functions must be first passed in the `BinningType` definition, before the rest of arguments follow in the order of usage.<br>
122+
Similarly, in `binningWithLambda` definition, one must first pass a tuple with all lambda functions before other arguments.<br>
123+
Note that binning with respect to z-vertex is calculated from column values as before, while the lambda is used only for the multiplicity axis. You must be careful to follow the same order of columns/lambdas in the `BinningType` definition and of the corresponding axes in binning instantation.
124+
Any combination of lambda- and column-based binning is possible.
125+
126+
Finally, the mixing structure is defined like in previous examples:
127+
128+
```cpp
129+
SameKindPair<aod::Collisions, aod::Tracks, BinningType> pair{binningWithLambda, 5, -1, collisions, tracksTuple, &cache};
130+
```

0 commit comments

Comments
 (0)