/[PAMELA software]/PamCut/PamCutBase/PamCutBase.h
ViewVC logotype

Contents of /PamCut/PamCutBase/PamCutBase.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (show annotations) (download)
Tue Oct 27 10:24:01 2009 UTC (15 years, 1 month ago) by pam-fi
Branch: MAIN
Changes since 1.4: +20 -7 lines
File MIME type: text/plain
New ownership feature added.

1 /*
2 * PamCutBase.h
3 *
4 * Created on: 6-feb-2009
5 * Author: Nicola Mori
6 */
7
8 /*! \file PamCutBase.h PamCut and PamCutCollection classes definitions. */
9
10 #ifndef PAMCUTBASE_H_
11 #define PAMCUTBASE_H_
12
13 #include <PamLevel2.h>
14 #include "../CommonDefs.h"
15
16 using namespace std;
17
18 /*! @brief An abstract class to apply cuts to Pamela data.
19 *
20 * This class provides a basic interface for a cut object to apply to PamLevel2 data.
21 */
22 class PamCut {
23 public:
24
25 /*! @brief Constructor.
26 * @param cutName The cut's name.
27 */
28 PamCut(const char *cutName) :
29 _cutName(cutName), _nEv(0), _nGood(0) {
30 }
31
32 /*! @brief Destructor. */
33 virtual ~PamCut() {
34 }
35
36 /*! @brief The basic event check.
37 *
38 * This routine applies the cut to the currently selected event, eg., to the event selected
39 * by the last PamLevel2::GetEntry() call performed by the object pointed by event. Note that
40 * OnGood() is not called by this method.
41 *
42 * @param event The event to analyze.
43 * @return #CUTOK if the event satisfy the cut, other return values are implementation-specific.
44 */
45
46 virtual int Check(PamLevel2 *event) = 0;
47
48 /*! @brief Applies the cut to the current event.
49 *
50 * This routine applies the cut to the currently selected event, eg., it calls Check() and if the
51 * event satisfy the selection it consequently call OnGood(), otherwise it calls OnBad()(this is
52 * the only difference with Check()).
53 *
54 * @param event The event to analyze.
55 * @return same return values as Check()
56 */
57 virtual int ApplyCut(PamLevel2 *event);
58
59 /*! @brief Applies the cut to a range of events.
60 *
61 * This method resets the counters calling Reset() and then calls ApplyCut(PamLevel2 *event) for all
62 * the events in PamLevel2 argument inside the specified range. After checking all the events, it calls
63 * the private method _Finalize(), on which the tasks to be performed after the selection can be defined.
64 *
65 * @param events Pointer to PamLevel2 object which contains the events.
66 * @param firstEvent The first event to analyze. Possible values range from 0 to \#events - 1.
67 * @param lastEvent The last event to analyze.
68 */
69 virtual void Process(PamLevel2 *events, ULong_t firstEvent, ULong_t lastEvent);
70
71 /*! @brief Post-selection tasks.
72 *
73 * Here the post-selection actions (histogram filling, parameter calculation etc.) can be defined.
74 * This routine is automatically called after a good event has been selected by
75 * ApplyCut().
76 * @param event The event which satisfy the cut.
77 */
78 virtual void OnGood(PamLevel2 *event) {
79 }
80
81 /*! @brief Post-selection tasks.
82 *
83 * The post-selection tasks for bad events (ie., not satisfying the cut) can be defined here.
84 *
85 * @see OnGood
86 * @param event The event which don't satisfy the cut.
87 * @param selectionResult The return value of the Check() routine.
88 */
89 virtual void OnBad(PamLevel2 *event, int selectionResult) {
90 }
91
92 /*! @brief Returns the number of checked events.
93 *
94 * @return The number of checked events.
95 */
96 virtual UInt_t GetNEv() {
97 return _nEv;
98 }
99 /*! @brief Returns the number of good events.
100 *
101 * This counter keeps track of how many events have fulfilled the
102 * conditions specified in Check.
103 *
104 * @return The number of good events.
105 */
106 virtual UInt_t GetNGood() {
107 return _nGood;
108 }
109
110 /*! @brief The pre-analysis task definition.
111 *
112 * This method is automatically called by Process() before the event selection;
113 * override this in derived classes to perform pre-analysis tasks like opening files and so on.
114 * In this base class implementation it only resets the counters for examined and good events.
115 * The parameter PamLevel2 *events may serve to initialize the analysis (even if in this base class
116 * implementation it is unused), so the interface includes it.
117 *
118 * @param events The PamLevel2 pointer to the events that will be analyzed.
119 *
120 * @see GetNEv(), GetNGood().
121 */
122 virtual void Setup(PamLevel2 *events);
123
124 /*! @brief The post-analysis task definition.
125 *
126 * This method is automatically called by Process() after the event selection has been
127 * performed; override this in derived classes to perform post-analysis tasks like writing
128 * histograms, closing files and so on.
129 */
130 virtual void Finalize() {
131 }
132
133 /*! @brief Returns the cut name.
134 *
135 * @return The cut name.
136 */
137 const char* GetName() const;
138
139 /*! @brief Changes the cut's name
140 *
141 * @param newName The new name.
142 */
143 void SetName(const char *newName);
144
145 /*! @brief The assignment operator.
146 * This operator defines how to copy a PamCut object into another. In current implementation,
147 * it only copies the cut's name of the RHS on the LHS.
148 *
149 * @param rightValue The RHS.
150 * @return The new value for LHS.
151 */
152 PamCut& operator=(const PamCut &rightValue);
153
154 private:
155
156 const char *_cutName;
157
158 protected:
159
160 UInt_t _nEv; ///< The number of analyzed events.
161 UInt_t _nGood; ///< The number of good events.
162 };
163
164 /*! @brief A class which applies a set of cuts to Pamela data.
165 *
166 * This is a multi-cut class, which inherits from PamCut. Indeed, a multi-cut can be seen as a cut composed
167 * by various simpler cuts; hence the interface of PamCut is also functional for PamCutCollection. The
168 * ApplyCut(PamLevel2 *event) method is overridden so as all the cuts that compose the PamCutCollection are applied to the
169 * events in the same order they are added to the collection. Instead, Process(PamLevel2 *events, ULong_t firstEvent, ULong_t lastEvent)
170 * is NOT overridden, since it performs the same task as the one in the base class: it is sufficient to override
171 * Check(PamLevel2 *event) to replace the single-cut evaluation with a multi-cut evaluation.
172 */
173 class PamCutCollection: public PamCut {
174 public:
175
176 /*! @brief Constructor.
177 * The collection can own the cuts, according to the value of the "owns" parameter.
178 * If set to true, the collection will take in charge the duty of destroying cuts and
179 * freeing their memory; users then should not set owns to true and explicitly call
180 * delete for the cuts in the collection. If instead owns is set to false, no destruction
181 * is performed by the collection; in this case, the user should issue the eventual
182 * delete calls.
183 *
184 * @param collectionName The collection's name.
185 * @param owns If true, the collection will own the cuts, ie., it will
186 * destroy them in its destructor.
187 */
188 PamCutCollection(const char *collectionName, bool owns = true) :
189 PamCut(collectionName), _owns(owns) {
190 }
191
192 /*! @brief Destructor. */
193 ~PamCutCollection();
194
195 /*! @brief Adds a cut to the cut collection
196 * This routine adds a cut to the collection. These are stored in a vector in the same order
197 * they are inserted (the first cut would be element 0, the second cut element 1 and so on).
198 * All the references to a "cut number" or "cut index" will refer to this numbering scheme.
199 *
200 * @param cut The pointer to a PamCut-derived object to add to the collection.
201 */
202 void AddCut(PamCut *cut);
203
204 /*! @brief The basic selection.
205 *
206 * Like in the mother class, this method performs a basic check on the current event: it calls
207 * Check() for each cut previously added with AddCut(), exiting if one of them is not satisfied.
208 *
209 * @param event The event to analyze.
210 * @return the index of the failed cut (range: [0, \#cuts-1], see AddCut()); #CUTOK if the event
211 * satisfies all the cuts.
212 */
213 int Check(PamLevel2 *event);
214
215 /*! @brief Applies the cuts to the current event.
216 *
217 * This routine works pretty much like the redefinition of Check(), calling ApplyCut() (instead of
218 * Check() )for each cut. If a cut fails, it calls OnBad(), passing the index of the failed cut as
219 * the selectionResult argument. If all the cuts are successful, it calls OnGood().
220 *
221 * @param event The event to analyze.
222 * @return same return values as Check().
223 */
224 int ApplyCut(PamLevel2 *event);
225
226 /*! @brief Returns a pointer to the iCut-th cut.
227 *
228 * The return value of this method is a pointer to a PamCut object; hence, to use the specific method of
229 * derived cuts it must be cast to the proper cut class.
230 *
231 * @param iCut The cut number, defined as the insertion order (from 0 to \#cuts-1, see AddCut()).
232 * @return pointer to the iCut-th cut; NULL if the specified cut cannot be found or if no cuts are present.
233 * */
234 PamCut *GetCut(unsigned int iCut);
235
236 /*! @brief Searches for a cut by name.
237 *
238 * The return value of this method is a pointer to a PamCut object; hence, to use the specific method of
239 * derived cuts it must be cast to the proper cut class.
240 *
241 * @param cutName The name of the cut to search for.
242 * @return pointer to the iCut-th cut; NULL if the specified cut cannot be found or if no cuts are present.
243 * */
244 PamCut *GetCut(const char *cutName);
245
246 /*! @brief The number of cuts contained in the collection.
247 *
248 * @return The number of cuts
249 */
250 unsigned int GetSize();
251
252 /*! @brief The pre-analysis task definition.
253 *
254 * This override of the Setup() method calls Setup() for the base class PamCut, and subsequently for each cut
255 * contained in the collection, in the same order the cuts were added to the collection.
256 *
257 * @param events The PamLevel2 pointer to the events that will be analyzed. Unused, but required by the interface.
258 */
259 void Setup(PamLevel2 *events);
260
261 /*! @brief The post-analysis task definition.
262 *
263 * This override of the Finalize() method calls PamCut::Finalize() and then the Finalize() method of each cut
264 * contained in the collection, in the same order.
265 */
266 void Finalize();
267
268 /*! @brief Assignment operator redefinition.
269 * The assignment operator replaces the content of the LHS with that of RHS. The net effect would be that
270 * the cuts contained in the LHS are exactly the same that are in the RHS. In particular, this means that
271 * any modification to one of the cuts will propagate both to the LHS and RHS collections. Also the cut
272 * name will be copied, since the implementation invokes PamCut::operator=.
273 *
274 * @param rightValue The RHS.
275 * @return The new value for LHS.
276 */
277 PamCutCollection& operator=(const PamCutCollection &rightValue);
278
279 protected:
280 /*! @brief A vector containing pointers to PamCut objects */
281 std::vector<PamCut*> _cuts;
282
283 /*! @brief A flag signaling if the collection owns the cuts (ie., if the collection
284 * will destroy the cuts.
285 */
286 bool _owns;
287 };
288
289 #endif /* PAMCUTBASE_H_ */

  ViewVC Help
Powered by ViewVC 1.1.23