Skip to content

Commit

Permalink
DaVinci algorithms. (#21)
Browse files Browse the repository at this point in the history
* Skeleton for FilterInTrees

* Written FilterInTrees lesson

* Addressed Alex's comments

* Fixing build decays too

* First commit of fixing errors

* Make Travis happy

* Make PEP8 happy

* Finalized debug section
  • Loading branch information
Albert Puig authored and alexpearce committed May 18, 2016
1 parent 720544a commit b43f28a
Show file tree
Hide file tree
Showing 7 changed files with 334 additions and 4 deletions.
2 changes: 1 addition & 1 deletion 01-building-decays.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Then, we can build a combiner as
from Configurables import CombineParticles
d0 = CombineParticles(
'Combine_D0',
DecayDescriptor='([D0 -> pi- K+]CC)',
DecayDescriptor='[D0 -> pi- K+]cc',
DaughtersCuts=d0_daughters,
CombinationCut=d0_comb,
MotherCut=d0_mother
Expand Down
227 changes: 227 additions & 0 deletions 07-fixing-errors.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion 17-switch-mass-hypo.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
layout: page
title: First steps in LHCb
title: Seconds steps in LHCb
subtitle: Replace a mass hypothesis
minutes: 10
---
Expand Down
86 changes: 86 additions & 0 deletions 18-filter-in-trees.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
---
layout: page
title: Second steps in LHCb
subtitle: Reuse particles from a decay tree
minutes: 10
---

> ## Learning Objectives {.objectives}
>
> * Learn how to extract particles from a decay tree
> * Build a new particle from the extracted particles
Sometimes we want to extract a portion of the decay tree in order to build a different decay.
To do that, we need to put the particles we're interested in in a new container so they can afterwards be used as inputs to a `CombineParticles` instance (as we saw in [the selection framework lesson](https://lhcb.github.io/second-analysis-steps/01-building-decays.html)).
To achieve this we can use the `FilterInTrees` algorithm, a simple variation of `FilterDesktop` ([doxygen](https://lhcb-release-area.web.cern.ch/LHCb-release-area/DOC/hlt/latest_doxygen/de/d8e/class_filter_in_trees.html)).

Let's start from the example in [the selection framework lesson](https://lhcb.github.io/second-analysis-steps/01-building-decays.html) and let's check that the $\pi^-$ child of the $D^0$ does not come from a $\rho\to\pi^+\pi^-$.
To do that, we have to extract the $\pi^-$ from `([D0 -> pi+ K-]CC)` and combine it with all pions in `Phys/StdAllNoPIDsPions/Particles`.

Using `FilterInTrees` is done in the same way we would use `FilterDesktop`:

```python
from Configurables import FilterInTrees
from PhysSelPython.Wrappers import Selection, DataOnDemand

decay_tree_location = '/Event/AllStreams/Phys/D2hhCompleteEventPromptDst2D2RSLine/Particles'
d0_from_dst = FilterInTrees('d0_from_dst_filter', Code="DECTREE('[Charm -> pi+ K-]CC')")
d0_from_dst_sel = Selection("d0_from_dst_sel",
Algorithm=d0_from_dst,
RequiredSelections=[AutomaticData(Location=decay_tree_location)])
pions_from_d0 = FilterInTrees('pions_from_d0_filter',Code="('pi+' == ABSID)")
pions_from_d0_sel = Selection("pions_from_d0_sel",
Algorithm=pions_from_d0,
RequiredSelections=[d0_from_dst_sel])
```

The output of `pions_from_d0_sel` is a container with all the pions coming from the $D^0$.

> ## Question {.callout}
> Do you see why we couldn't use something simple like
> ```python
pions_from_d0 = FilterInTrees('pions_from_d0_filter', Code="'pi+' == ABSID")
```
> ?
Note how we had to do the process in two steps in order to avoid getting the soft pion from the $D^*$.
Sometimes this makes things quite difficult, but almost all problems can be solved with a smart use of the `DECTREE` container in an intermediate step.

> ## Selecting the soft pion {.challenge}
> Can you find of a way of selecting the soft pion?
> Hint: use the `FilterDecays` algorithm, in which you specify a decay descriptor as `Code`, marking the desired particle(s).
The final step is easy, very similar to [building your own decay](https://lhcb.github.io/second-analysis-steps/01-building-decays.html):

```python
from Configurables import CombineParticles
from PhysSelPython.Wrappers import Selection, DataOnDemand

Pions = DataOnDemand('Phys/StdAllNoPIDsPions/Particles')
rho = CombineParticles('rho_particles',
DecayDescriptor=['rho(770)0 -> pi+ pi-'],
CombinationCut="ADAMASS('rho(770)0') < 300*MeV",
MotherCut='(VFASPF(VCHI2/VDOF)< 9)')
rho_sel = Selection('rho_sel',
Algorithm=rho,
RequiredSelections=[pions_from_d0_sel, Pions])
```

Unfortunately, the `CombineParticles` example we just wrote is not exactly what we meant, since it will actually build $\rho$ from all pions it gets as input, not using one from our `pions_from_d0` selection and one from `'Phys/StdAllNoPIDsPions/Particles'`.
How to solve this?
We have to get creative and use the tools at hand:
for example, we could use `SubstitutePID` from the previous lesson to change the PID of the pions in the `pions_from_d0` selection to kaon and build `[rho(770)0 -> K+ pi-]CC` and then change again the PID of the kaon to a pion.
Of course, if we were reconstructing $K^{*}(892)^{0} \to K^{-}\pi^{+}$ with `Phys/StdAllLooseKaons/Particles` instead, for example, we would already have everything we need since the ambiguity wouldn't exist.

> ## An interesting detail {.callout}
> One can use `FilterInTrees` and `FilterDecays` to select several particles at once and obtain a flattened list.
> For example, if we had a Stripping line that builds `[B- -> (^D0 -> ^K- ^pi+) ^pi-]cc` and we wanted to combine the $D^0$ and $\pi^-$ with an external $\pi^0$ to build `[B- -> D0 pi- pi0]cc`, we could do
> ```python
flatlist = FilterInTrees ("FlatList", Code="('D0' == ABSID) | ('pi-' == ABSID)")
from Configurables import CombineParticles
add_pi0 = CombineParticles("MakeB",
DecayDescriptor = "[B- -> D0 pi- pi0]cc",
...
Inputs=[flatlist, resolvedPi0])
```
> `flatlist` contains both $D^0$ and $\pi^-$, which are then used to build the $B$.
2 changes: 1 addition & 1 deletion code/06-building-decays/build_decays.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
)

d0 = CombineParticles('Combine_D0',
DecayDescriptor='([D0 -> pi- K+]CC)',
DecayDescriptor='[D0 -> pi- K+]cc',
DaughtersCuts=d0_daughters,
CombinationCut=d0_comb,
MotherCut=d0_mother)
Expand Down
16 changes: 16 additions & 0 deletions code/06-building-decays/davinci.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from Configurables import DaVinci, IoHelper

DaVinci().InputType = 'DST'
DaVinci().TupleFile = 'DVntuple.root'
DaVinci().PrintFreq = 1000
DaVinci().DataType = '2012'
DaVinci().Simulation = True
# Only ask for luminosity information when not using simulated data
DaVinci().Lumi = not DaVinci().Simulation
DaVinci().EvtMax = 1000

# Use the local input data
IOHelper().inputFiles([('root://eoslhcb.cern.ch//eos/lhcb/user/a/apearce/'
'Starterkit/Nov2015/'
'00035742_00000001_1.allstreams.dst')],
clear=True)
3 changes: 2 additions & 1 deletion index.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ developed][second-ana-repo], or you can [send an email to

1. [Using git to develop LHCb software](02-lb-git.html)
1. [Building your own decay](01-building-decays.html)
1. [What to do when something fails](07-fixing-errors.html)
1. [Run a different stripping line on simulated data](14-rerun-stripping.html)
1. [Using git to develop LHCb software](02-lb-git.html)
1. [Replace a mass hypothesis](17-switch-mass-hypo.html)
1. [Reuse particles from a decay tree](18-filter-in-trees.html)
1. [HLT intro](18-hlt-intro.html)
1. [TisTos DIY](18-tistos-diy.html)

Expand Down

0 comments on commit b43f28a

Please sign in to comment.