1 |
mocchiut |
1.1 |
//############################################################################################################################################################# |
2 |
|
|
// |
3 |
|
|
// filter.c # by Emiliano Mocchiutti (2005/11/25) |
4 |
|
|
// |
5 |
|
|
//############################################################################################################################################################# |
6 |
|
|
// |
7 |
|
|
// Template for the event selection using the EventViewer. The function must be called "filter" while the filename where the function is defined can be anyone. |
8 |
|
|
// |
9 |
|
|
//############################################################################################################################################################# |
10 |
|
|
// |
11 |
|
|
// The idea of the event selection is the following: |
12 |
|
|
// 1) you must know which kind of data the EventViewer program is using (for example tracker level0, level1 or level2 data?) |
13 |
|
|
// 2) depending on the available data you can define your selection. |
14 |
|
|
// 3) information about data used can be found in the structure "level" which contains the following variables: |
15 |
|
|
// typedef struct Levels { |
16 |
|
|
// Int_t calo; // if equal to 0 calorimeter level 0 , if equal to 1 calorimeter level 1 data. |
17 |
|
|
// Int_t calol2; // for the moment this is always 0 |
18 |
|
|
// Int_t tof; // tof/trigger level 1 or level 0 data |
19 |
|
|
// Int_t track; // tracker level 1 or level 0 data |
20 |
|
|
// Int_t track2; // if set to one there are tracker level2 data |
21 |
|
|
// Int_t s4; // S4 level 1 or level0 data |
22 |
|
|
// Int_t ac; // AC level 1 or level0 data |
23 |
|
|
// Int_t nd; // always 0 for the moment |
24 |
|
|
// } level; |
25 |
|
|
// evno is the event number to be processed. |
26 |
|
|
// All data coming from yoda are stored in the tree called "otr", tree "ttr" contains only level2 tracker data. |
27 |
|
|
// 4) to learn how to change things look at examples below. |
28 |
|
|
// 5) to stop the eventviewer this function must return 1 as value, when returning 0 means go on searching. |
29 |
|
|
// 6) is it possible to combine information from different detectors. |
30 |
|
|
// |
31 |
|
|
|
32 |
|
|
int filter(Int_t evno, TTree *otr, TTree *ttr, Levels & level){ |
33 |
|
|
// |
34 |
|
|
// example n. 1 |
35 |
|
|
// select events where the energy deposit in S4 is greater than 0.7 MIP |
36 |
|
|
// |
37 |
|
|
Bool_t S4 = true; |
38 |
|
|
// |
39 |
|
|
// check the data level |
40 |
|
|
// |
41 |
|
|
if ( level.s4 == 0 ) { |
42 |
|
|
S4 = false; |
43 |
|
|
// |
44 |
|
|
// determine in which branch we can find S4 data in the tree otr. |
45 |
|
|
// |
46 |
|
|
pamela::S4::S4Event *s4 = 0; |
47 |
|
|
otr->SetBranchAddress("S4.Event", &s4); |
48 |
|
|
otr->GetEntry(evno); |
49 |
|
|
// |
50 |
|
|
// if we have level0 data we must calibrate the data to make a selection in MIP. |
51 |
|
|
// |
52 |
|
|
Float_t s4data = ((float)s4->S4_DATA -32.) * 0.29; |
53 |
|
|
// |
54 |
|
|
// if the condition is satisfied S4 is true. |
55 |
|
|
// |
56 |
|
|
if ( s4data>0.7 ) S4 = true; |
57 |
|
|
}; |
58 |
|
|
|
59 |
|
|
// |
60 |
|
|
// example n. 2 |
61 |
|
|
// select events with one or more tracks |
62 |
|
|
// |
63 |
|
|
Bool_t TRACKER = true; |
64 |
|
|
// |
65 |
|
|
// check we have tracker LEVEL2 data |
66 |
|
|
// |
67 |
|
|
if ( level.track2 == 1 ){ |
68 |
|
|
TRACKER = false; |
69 |
|
|
// |
70 |
|
|
// access tracker level2 data, store variables in the structure trk. |
71 |
|
|
// |
72 |
|
|
struct Tracklev2 trk; |
73 |
|
|
settrklev2(ttr,trk); |
74 |
|
|
// |
75 |
|
|
// get entry, here we are assuming we have syncronized data. |
76 |
|
|
// |
77 |
|
|
ttr->GetEntry(evno); |
78 |
|
|
// |
79 |
|
|
if ( trk.ntrk > 0 ){ |
80 |
|
|
// |
81 |
|
|
TRACKER = true; |
82 |
|
|
// |
83 |
|
|
// example of how to calculate rigidity from deflection and select negative particles with rigidity less than 1 GV: |
84 |
|
|
// |
85 |
|
|
// Float_t rig = 0.; |
86 |
|
|
// |
87 |
|
|
// notice that in the structure trk columns and rows of matrixes are inverted respect to the fortran style al[0][4] is deflection for the first track |
88 |
|
|
// al[1][4] would be deflection for the second track, etc. |
89 |
|
|
// |
90 |
|
|
// if ( trk.al[0][4] != 0. ) rig = 1./trk.al[0][4]; |
91 |
|
|
// if ( abs(rig) < 1. ) TRACKER = true; |
92 |
|
|
}; |
93 |
|
|
}; |
94 |
|
|
|
95 |
|
|
// |
96 |
|
|
// example n. 3 |
97 |
|
|
// select events with 6 hist in the X-view of the tracker and 6 hit in the Y-view of the tracker |
98 |
|
|
// |
99 |
|
|
Bool_t TRACKER2 = true; |
100 |
|
|
// |
101 |
|
|
if ( level.track == 0 ){ |
102 |
|
|
TRACKER2 = false; |
103 |
|
|
Int_t fnclx = 0; |
104 |
|
|
Int_t fncly = 0; |
105 |
|
|
pamela::tracker::TrackerEvent *trk = 0; |
106 |
|
|
otr->SetBranchAddress("Tracker.Event", &trk); |
107 |
|
|
otr->GetEntry(evno); |
108 |
|
|
for (Int_t l = 0; l<12; l++){ |
109 |
|
|
Int_t planeno = trk->DSPnumber[l]-1; |
110 |
|
|
if ( planeno < 0 || planeno > 11 ) planeno = 0; |
111 |
|
|
if ( planeno >= 0 ) { |
112 |
|
|
if ( (planeno+1)%2 ){ |
113 |
|
|
for (Int_t m = 0; m<3; m++){ |
114 |
|
|
if ( trk->signcluster[l][m] != 0. ){ |
115 |
|
|
fncly++; |
116 |
|
|
}; |
117 |
|
|
}; |
118 |
|
|
} else { |
119 |
|
|
for (Int_t m = 0; m<3; m++){ |
120 |
|
|
if ( trk->signcluster[l][m] != 0. ){ |
121 |
|
|
fnclx++; |
122 |
|
|
}; |
123 |
|
|
}; |
124 |
|
|
}; |
125 |
|
|
}; |
126 |
|
|
}; |
127 |
|
|
if ( fnclx == 6 && fncly == 6 ) TRACKER2 = true; |
128 |
|
|
}; |
129 |
|
|
|
130 |
|
|
// |
131 |
|
|
// example n. 4 |
132 |
|
|
// select events with qtot greater than 100 and nstrip greater than 100 in the calorimeter (interacting particles) |
133 |
|
|
// |
134 |
|
|
Bool_t CALO = true; |
135 |
|
|
// |
136 |
|
|
// check if we have calorimeter level1 data |
137 |
|
|
// |
138 |
|
|
if ( level.calo == 1 ){ |
139 |
|
|
CALO = false; |
140 |
|
|
CalorimeterLevel1 *calo = new CalorimeterLevel1(); |
141 |
|
|
otr->SetBranchAddress("CaloLevel1.Event", &calo); |
142 |
|
|
otr->GetEntry(evno); |
143 |
|
|
if ( calo->qtot > 100 && calo->nstrip > 100) CALO = true; |
144 |
|
|
}; |
145 |
|
|
|
146 |
|
|
// |
147 |
|
|
// example n. 5 |
148 |
|
|
// select calorimeter selftrigger events |
149 |
|
|
// |
150 |
|
|
Bool_t TRIGGER = true; |
151 |
|
|
if ( level.tof == 0 || level.tof == 1 ){ |
152 |
|
|
// |
153 |
|
|
Bool_t TRIGGER = false; |
154 |
|
|
// |
155 |
|
|
// define where to find in the tree otr the Trigger.Event branch |
156 |
|
|
// |
157 |
|
|
pamela::trigger::TriggerEvent *trig = 0; |
158 |
|
|
otr->SetBranchAddress("Trigger.Event", &trig); |
159 |
|
|
// |
160 |
|
|
// get the entry number "evno" passed by the main EventViewer program |
161 |
|
|
// |
162 |
|
|
otr->GetEntry(evno); |
163 |
|
|
// |
164 |
|
|
// check the first element of the variable patterntrig which tell us if this one is a calorimeter trigger |
165 |
|
|
// |
166 |
|
|
if ( trig->patterntrig[0] ) { |
167 |
|
|
// |
168 |
|
|
// set the boolean variable TRIGGER to true. Instead of setting this variable it is possible to return(1) here. |
169 |
|
|
// |
170 |
|
|
TRIGGER = true; |
171 |
|
|
}; |
172 |
|
|
// |
173 |
|
|
// example if one want to select S4/pulser triggers |
174 |
|
|
// |
175 |
|
|
//if ( trig->patterntrig[1] & (1<<0) ) TRIGGER = true; |
176 |
|
|
}; |
177 |
|
|
|
178 |
|
|
// |
179 |
|
|
// example n. 6 |
180 |
|
|
// select events with AC hits |
181 |
|
|
// |
182 |
|
|
Bool_t AC = true; |
183 |
|
|
// |
184 |
|
|
// in the case of level0 data |
185 |
|
|
// |
186 |
|
|
if ( level.ac == 0){ |
187 |
|
|
AC = false; |
188 |
|
|
pamela::anticounter::AnticounterEvent *ace = 0; |
189 |
|
|
otr->SetBranchAddress("Anticounter.Event", &ace); |
190 |
|
|
otr->GetEntry(evno); |
191 |
|
|
Int_t hitmapA = 0; |
192 |
|
|
Int_t hitmapB = 0; |
193 |
|
|
// |
194 |
|
|
// hitmap variable contain the information |
195 |
|
|
// |
196 |
|
|
hitmapA = ace->hitmap[0]; |
197 |
|
|
hitmapB = ace->hitmap[1]; |
198 |
|
|
if ( hitmapA || hitmapB ) AC = true; |
199 |
|
|
}; |
200 |
|
|
// |
201 |
|
|
// in the case of level1 data |
202 |
|
|
// |
203 |
|
|
if ( level.ac == 1){ |
204 |
|
|
AC = false; |
205 |
|
|
AnticounterLevel1 *ace = new AnticounterLevel1(); |
206 |
|
|
otr->SetBranchAddress("AcLevel1.Event", &ace); |
207 |
|
|
otr->GetEntry(evno); |
208 |
|
|
Int_t hitmapA = 0; |
209 |
|
|
Int_t hitmapB = 0; |
210 |
|
|
hitmapA = ace->hitmap[0]; |
211 |
|
|
hitmapB = ace->hitmap[1]; |
212 |
|
|
if ( hitmapA || hitmapB ) AC = true; |
213 |
|
|
}; |
214 |
|
|
|
215 |
|
|
// |
216 |
|
|
// example n. 7 |
217 |
|
|
// select events in which we have at least one AC hit outside the trigger time window (we need level1 data) |
218 |
|
|
// |
219 |
|
|
Bool_t AC2 = true; |
220 |
|
|
if ( level.ac == 1){ |
221 |
|
|
AC2 = false; |
222 |
|
|
AnticounterLevel1 *ace = new AnticounterLevel1(); |
223 |
|
|
otr->SetBranchAddress("AcLevel1.Event", &ace); |
224 |
|
|
otr->GetEntry(evno); |
225 |
|
|
Int_t hitstatusA = 0; |
226 |
|
|
Int_t hitstatusB = 0; |
227 |
|
|
Int_t hitmapA = 0; |
228 |
|
|
Int_t hitmapB = 0; |
229 |
|
|
hitmapA = ace->hitmap[0]; |
230 |
|
|
hitmapB = ace->hitmap[1]; |
231 |
|
|
hitstatusA = ace->hitstatus[0]; |
232 |
|
|
hitstatusB = ace->hitstatus[1]; |
233 |
|
|
Int_t deltaA = hitstatusA - hitmapA; |
234 |
|
|
Int_t deltaB = hitstatusB - hitmapB; |
235 |
|
|
if ( deltaA || deltaB ) AC2 = true; |
236 |
|
|
}; |
237 |
|
|
|
238 |
|
|
|
239 |
|
|
// |
240 |
|
|
// example n. 8 |
241 |
|
|
// select events with one or more detected neutrons: |
242 |
|
|
// |
243 |
|
|
Bool_t ND = true; |
244 |
|
|
if ( level.nd == 0){ |
245 |
|
|
ND = false; |
246 |
|
|
Int_t tmpSize; |
247 |
|
|
Int_t nTrig = 0; |
248 |
|
|
pamela::neutron::NeutronEvent *ne = 0; |
249 |
|
|
pamela::neutron::NeutronRecord *nr = 0; |
250 |
|
|
otr->SetBranchAddress("Neutron.Event", &ne); |
251 |
|
|
otr->GetEntry(evno); |
252 |
|
|
tmpSize = ne->Records->GetEntries(); |
253 |
|
|
for (Int_t j = 0; j < tmpSize; j++){ |
254 |
|
|
nr = (pamela::neutron::NeutronRecord*)ne->Records->At(j); |
255 |
|
|
nTrig += (int)nr->trigPhysics; |
256 |
|
|
}; |
257 |
|
|
if ( nTrig > 0 ) ND = true; |
258 |
|
|
}; |
259 |
|
|
|
260 |
|
|
// |
261 |
|
|
// Here we can use the boolean variables and decide if the event passed the selecion or not. |
262 |
|
|
// |
263 |
|
|
// if the event pass the selection return one, zero otherwise. |
264 |
|
|
// |
265 |
|
|
|
266 |
|
|
// |
267 |
|
|
// Some examples: |
268 |
|
|
// |
269 |
|
|
|
270 |
|
|
// A - select only calorimeter selftrigger events |
271 |
|
|
// |
272 |
|
|
// if ( TRIGGER ) return(1); |
273 |
|
|
|
274 |
|
|
// B - select calorimeter self-trigger events with at least one fitted track: |
275 |
|
|
// |
276 |
|
|
// if ( TRIGGER && TRACKER ) return(1); |
277 |
|
|
|
278 |
|
|
// C - select events with at least one track (default behaviour so it is uncommented) |
279 |
|
|
// |
280 |
|
|
if ( TRACKER ) return(1); |
281 |
|
|
|
282 |
|
|
// D - select interacting events in the calorimeter |
283 |
|
|
// |
284 |
|
|
// if ( CALO ) return(1); |
285 |
|
|
|
286 |
|
|
|
287 |
|
|
// E - select events with hit in the anticounters |
288 |
|
|
// |
289 |
|
|
// if ( AC ) return(1); |
290 |
|
|
|
291 |
|
|
// F - select events with energy release in S4 greater than 0.7 MIPs, at least one track, no hit in the anticounters and at least one neutron detected: |
292 |
|
|
// |
293 |
|
|
// if ( S4 && TRACKER && !AC && ND ) return(1); |
294 |
|
|
|
295 |
|
|
// |
296 |
|
|
// if nothing match, return 0. |
297 |
|
|
// |
298 |
|
|
return(0); |
299 |
|
|
}; |