source: branches/AddingGoogleTestEnvironment/mfilter/MFEvtNumber.cc@ 18165

Last change on this file since 18165 was 8720, checked in by tbretz, 17 years ago
*** empty log message ***
File size: 5.3 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of MARS, the MAGIC Analysis and Reconstruction
5! * Software. It is distributed to you in the hope that it can be a useful
6! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
7! * It is distributed WITHOUT ANY WARRANTY.
8! *
9! * Permission to use, copy, modify and distribute this software and its
10! * documentation for any purpose is hereby granted without fee,
11! * provided that the above copyright notice appear in all copies and
12! * that both that copyright notice and this permission notice appear
13! * in supporting documentation. It is provided "as is" without express
14! * or implied warranty.
15! *
16!
17!
18! Author(s): Thomas Bretz 3/2007 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2007
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MFEvtNumber
28//
29/////////////////////////////////////////////////////////////////////////////
30#include "MFEvtNumber.h"
31
32#include <TFile.h>
33#include <TTree.h>
34
35#include "MParList.h"
36
37#include "MLog.h"
38#include "MLogManip.h"
39
40#include "MRawRunHeader.h"
41#include "MRawEvtHeader.h"
42
43ClassImp(MFEvtNumber);
44
45using namespace std;
46
47// --------------------------------------------------------------------------
48//
49// Default Constructor
50//
51MFEvtNumber::MFEvtNumber(const char *name, const char *title):
52 fFileName(""), fTreeName("Events"), fSelector("")
53{
54 fName = name ? name : "MFEvtNumber";
55 fTitle = title ? title : "Filter to select events by run- and evt-number";
56}
57
58// --------------------------------------------------------------------------
59//
60// return the event id. It is a binary compilation of run- and evt-number
61//
62ULong_t MFEvtNumber::GetEvtId() const
63{
64 return Compile(fRun->GetRunNumber(), fEvt->GetDAQEvtNumber());
65}
66
67// --------------------------------------------------------------------------
68//
69// Preprocess
70//
71// MC slope and min/max energy are read
72// Normalization factor is computed
73//
74Int_t MFEvtNumber::PreProcess(MParList *plist)
75{
76 fResult = kTRUE;
77
78 if (fFileName.IsNull())
79 {
80 *fLog << inf << "No input file given... skipped." << endl;
81 return kSKIP;
82 }
83
84 fRun = (MRawRunHeader*)plist->FindObject("MRawRunHeader");
85 if (!fRun)
86 {
87 *fLog << err << "MRawRunHeader not found ... aborting." << endl;
88 return kFALSE;
89 }
90 fEvt = (MRawEvtHeader*)plist->FindObject("MRawEvtHeader");
91 if (!fEvt)
92 {
93 *fLog << err << "MRawEvtHeader not found ... aborting." << endl;
94 return kFALSE;
95 }
96
97 TFile file(fFileName);
98 if (file.IsZombie())
99 {
100 *fLog << err << "Cannot open file " << fFileName << "... aborting." << endl;
101 return kFALSE;
102 }
103
104 TTree *t = dynamic_cast<TTree*>(file.Get(fTreeName));
105 if (!t)
106 {
107 *fLog << err << "Tree " << fTreeName << " not found in file " << fFileName << "... aborting." << endl;
108 return kFALSE;
109 }
110
111 t->SetEstimate(t->GetEntries());
112
113 if (t->Draw("RunNumber.fVal:EvtNumber.fVal", fSelector, "goff")<0)
114 {
115 *fLog << err << "Could not retrieve event-list from tree " << fTreeName << " in file " << fFileName << " selecting " << fSelector << "... aborting." << endl;
116 return kFALSE;
117 }
118
119 const Long64_t n = t->GetSelectedRows();
120
121 if (n<=0)
122 {
123 *fLog << err << "Could not retrieve event-list from tree " << fTreeName << " in file " << fFileName << " selecting " << fSelector << "... aborting." << endl;
124 return kFALSE;
125 }
126
127 const Double_t *v1 = t->GetV1();
128 const Double_t *v2 = t->GetV2();
129
130
131 *fLog << inf << "Found " << n << " events fulfilling " << fSelector << "." << endl;
132
133 for (Long64_t i=0; i<n; i++)
134 fList.Add(Compile((ULong64_t)v1[i], (ULong64_t)v2[i]), 1);
135
136 return kTRUE;
137}
138
139// --------------------------------------------------------------------------
140//
141// Select events randomly according to the MC ("old") and required ("new")
142// energy slope.
143// Old E slope is fMcSlope
144// New E slope is set by the user (fval; fNewSlope)
145// If old and new energy slope are the same skip the selection.
146// The MC energy slope and lower and upper limits are taken from the
147// run header (requires reflector ver.>0.6 and camera ver.>0.6)
148//
149Int_t MFEvtNumber::Process()
150{
151 if (fFileName.IsNull())
152 return kTRUE;
153
154 fResult = fList.GetValue(GetEvtId()) ? kTRUE : kFALSE;
155
156 return kTRUE;
157}
158
159// --------------------------------------------------------------------------
160//
161// MFEvtNumber.FileName: filename.root
162// MFEvtNumber.TreeName: Events
163// MFEvtNumber.Selector: ThetaSquared<0.04
164//
165Int_t MFEvtNumber::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
166{
167 Bool_t rc = kFALSE;
168 if (IsEnvDefined(env, prefix, "FileName", print))
169 {
170 rc = kTRUE;
171 SetFileName(GetEnvValue(env, prefix, "FileName", fFileName));
172 }
173 if (IsEnvDefined(env, prefix, "TreeName", print))
174 {
175 rc = kTRUE;
176 SetFileName(GetEnvValue(env, prefix, "TreeName", fTreeName));
177 }
178 if (IsEnvDefined(env, prefix, "Selector", print))
179 {
180 rc = kTRUE;
181 SetSelector(GetEnvValue(env, prefix, "Selector", fSelector));
182 }
183 return rc;
184}
Note: See TracBrowser for help on using the repository browser.