-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedm-tutorial.twiki
191 lines (124 loc) · 7.87 KB
/
edm-tutorial.twiki
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
---+ FCC Event Data Model
%TOC{title="Contents"}%
---++ Overview
The FCC event data model is based on simple C++ classes called POD structs (Plain Old Data structures). A POD struct can be thought of as a basic C struct.
This page presents the following packages:
* albers-core: a standalone library containing the tools necessary to define an EDM based on PODs, and to write and read events based on this EDM.
* fcc-edm: the official FCC event data model, based on albers-core
* analysis-cpp: example analysis code showing how to read FCC EDM events.
*Create an FCC directory on your computer (either lxplus6 or a mac), and keep track of this directory:*
<pre>
mkdir FCC
cd FCC
export FCC=$PWD
</pre>
---++ Albers
Albers is a standalone library used to:
* define complex event data models in a simple way
* write and read edm events.
---+++ Installation
The code of Albers is available on [[https://github.com/HEP-FCC/albers-core][HEP-FCC/albers-core.git]].
Clone this repository in your FCC directory:
<pre>
cd $FCC
git clone [email protected]:HEP-FCC/albers-core.git
cd albers-core
</pre>
And follow the instructions in the [[https://github.com/HEP-FCC/albers-core/blob/tutorial/README.md][README.md]]. Make sure the tests work before proceeding to the next sections.
---+++ PODs, handles, collections
Albers comes with a very simple test EDM, described in [[https://github.com/HEP-FCC/albers-core/blob/tutorial/examples/example_edm.yaml][example_edm.yaml]]. A code generation script takes this yaml file in input to produce all classes in the [[https://github.com/HEP-FCC/albers-core/tree/tutorial/datamodel/datamodel][datamodel/datamodel/]] directory.
For each datatype in the yaml file, three classes are generated:
* the POD itself, e.g. [[https://github.com/HEP-FCC/albers-core/blob/tutorial/datamodel/datamodel/Particle.h][Particle.h]].
* a Handle to the POD, e.g. [[https://github.com/HEP-FCC/albers-core/blob/tutorial/datamodel/datamodel/ParticleHandle.h][ParticleHandle.h]].
* a collection of Handles, e.g. [[https://github.com/HEP-FCC/albers-core/blob/tutorial/datamodel/datamodel/ParticleCollection.h][ParticleCollection.h]].
PODs are used as simple structs, for example:
<pre>
Particle ptc;
ptc.P4 = LorentzVector(pt, eta, phi, m);
ptc.ID = 25
ptc.Status = 3
std::cout << ptc.Status << std::endl;
</pre>
A Handle contains a pointer to an existing POD. If you have a handle, you can get a readable reference to the corresponding POD by doing:
<pre>
const Particle& ptc = ptchandle.read();
std::cout << ptc.Status << std::endl;
ptc.Status = 1; // ERROR! CANNOT MODIFY THE POD
</pre>
In case you wish to modify a POD, you can instead do:
<pre>
Particle& ptc = ptchandle.mod();
ptc.Status = 1; // That works :-)
std::cout << ptc.Status << std::endl;
</pre>
Handles can be stored in a POD, as a reference to another POD.
They are also used to manipulate to manipulate PODs stored in the event.
%T% if you are not allowed to modify a POD, the compiler will let you know.
%T% *if your goal is just to read a POD, call read(). Only call mod() when you need to modify the POD.*
The [[https://github.com/HEP-FCC/albers-core/blob/tutorial/examples/example_edm.yaml][yaml file]] also contains "components". Components are PODs that can be used as building blocks in other PODs. For each component, the code generation script only produces the POD class, meaning that components cannot be pointed to by a Handle, and cannot be stored in a Collection.
---+++ Exercise 1: Writing a collection
Modify [[https://github.com/HEP-FCC/albers-core/blob/tutorial/examples/write.cc][write.cc]] to write a second collection in the event, containing Particles.
*As usual, compile and run your code, and check the output.*
Tips:
* Get inspiration from the code writing to the EventInfo collection. The only difference here is that you are going to store several Particles in your particle collection. Just write two particles
* Create handles to the particles in a similar way as for the EventInfo. Mofidy the Particle POD corresponding to the handle, setting its attributes to dummy values of your choice.
* To check the output, open the resulting root file, and look at the events TTree.
---+++ Exercise 2: Modifying the EDM
Modify [[https://github.com/HEP-FCC/albers-core/blob/tutorial/examples/example_edm.yaml][example_edm.yaml]] to add a new datatype of your own.
Run the code generator:
<pre>
python $ALBERS/../python/albers_class_generator.py examples/example_edm.yaml datamodel datamodel
</pre>
Check that the classes for your new datatype have been created in =datamodel/datamodel/=.
Compile.
Modify [[https://github.com/HEP-FCC/albers-core/blob/tutorial/examples/write.cc][write.cc]] to write another collection in the event, containing objects of your new datatype.
Compile again, run, and check the output root file.
---++ The FCC event data model
fcc-edm is a library based on Albers, defining the FCC event data model.
---+++ Installation
The code of is available on [[https://github.com/HEP-FCC/fcc-edm][HEP-FCC/fcc-edm.git]].
Clone this repository in your FCC directory:
<pre>
cd $FCC
git clone [email protected]:HEP-FCC/fcc-edm.git
cd fcc-edm
</pre>
And follow the instructions in the [[https://github.com/HEP-FCC/fcc-edm/blob/tutorial/README.md][README.md]]. Make sure the tests work before proceeding to the next sections.
---+++ Exercise 1
The file [[https://github.com/HEP-FCC/fcc-edm/blob/tutorial/edm_1.yaml][edm_1.yaml]] describes the whole FCC data model.
Read this file, and make sure you understand all data types. In particular, you should be able to make the difference between a POD that refers to another POD (through a Handle) and a POD that contains another POD (a component).
---+++ Exercise 2
Can you find a missing datatype or a missing attribute in an existing POD?
If yes, you are very welcome to contribute!
* add it to the yaml file
* run the code generator
* compile and run the tests
* contact Colin to discuss your changes
---++ Event analysis in C++
analysis-cpp is a package based on fcc-edm and albers. It demonstrates how to read EDM events in the analysis code. The package allows you to build:
* a C++ executable
* a C++ shared library that you can load in root to drive event processing and analysis interactively.
---+++ Installation
The code of is available on [[https://github.com/HEP-FCC/analysis-cpp.git][HEP-FCC/analysis-cpp.git]].
Clone this repository in your FCC directory:
<pre>
cd $FCC
git clone [email protected]:HEP-FCC/analysis-cpp.git
cd analysis-cpp
</pre>
And follow the instructions in the [[https://github.com/HEP-FCC/analysis-cpp/blob/tutorial/README.md][README.md]]. Make sure the tests work before proceeding to the next sections.
---+++ Exercise 1
Modify the =MyAnalysis= class in [[https://github.com/HEP-FCC/analysis-cpp/blob/tutorial/example-lib][example-lib]] to:
* read the GenParticle collection as well
* select the GenParticleHandles that are not used in any jet
* create a new histogram to plot the pT of these particles
Then draw this histogram in the [[https://github.com/HEP-FCC/analysis-cpp/blob/tutorial/example-lib/test_macro.C][example-lib/test-macro.C]] and run the macro.
---+++ Exercise 2
Taking [[https://github.com/HEP-FCC/analysis-cpp/blob/tutorial/example-lib][example-lib]] as an example, modify the analysis-cpp package in such a way that a new analysis library with a new analysis class is built. The code should be located in =another-lib= and the resulting library should be called =libmyotheranalysis.so= (or =.dylib= if you're on a mac).
Test your new library in a root macro.
---+++ Example 3
This one is not for the faint of heart.
Taking analysis-cpp as an example, create a new package called =analysis2-cpp=. Instead of reading FCC EDM events, the code in this package should read directly the simple example EDM distributed with Albers.
---++ Event analysis in python
See FccSoftwareHeppy
-- Main.ColinBernet - 2014-12-15