source: trunk/MagicSoft/Mars/mfilter/MFEvtNumber.cc@ 8427

Last change on this file since 8427 was 8419, checked in by tbretz, 17 years ago
*** empty log message ***
File size: 5.2 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 if (t->Draw("RunNumber.fVal:EvtNumber.fVal", fSelector, "goff")<0)
112 {
113 *fLog << err << "Could not retrieve event-list from tree " << fTreeName << " in file " << fFileName << " selecting " << fSelector << "... aborting." << endl;
114 return kFALSE;
115 }
116
117 const Long64_t n = t->GetSelectedRows();
118
119 if (n<=0)
120 {
121 *fLog << err << "Could not retrieve event-list from tree " << fTreeName << " in file " << fFileName << " selecting " << fSelector << "... aborting." << endl;
122 return kFALSE;
123 }
124
125 const Double_t *v1 = t->GetV1();
126 const Double_t *v2 = t->GetV2();
127
128
129 *fLog << inf << "Found " << n << " events fulfilling " << fSelector << "." << endl;
130
131 for (Long64_t i=0; i<n; i++)
132 fList.Add(Compile((ULong64_t)v1[i], (ULong64_t)v2[i]), 1);
133
134 return kTRUE;
135}
136
137// --------------------------------------------------------------------------
138//
139// Select events randomly according to the MC ("old") and required ("new")
140// energy slope.
141// Old E slope is fMcSlope
142// New E slope is set by the user (fval; fNewSlope)
143// If old and new energy slope are the same skip the selection.
144// The MC energy slope and lower and upper limits are taken from the
145// run header (requires reflector ver.>0.6 and camera ver.>0.6)
146//
147Int_t MFEvtNumber::Process()
148{
149 if (fFileName.IsNull())
150 return kTRUE;
151
152 fResult = fList.GetValue(GetEvtId()) ? kTRUE : kFALSE;
153
154 return kTRUE;
155}
156
157// --------------------------------------------------------------------------
158//
159// MFEvtNumber.FileName: filename.root
160// MFEvtNumber.TreeName: Events
161// MFEvtNumber.Selector: ThetaSquared<0.04
162//
163Int_t MFEvtNumber::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
164{
165 Bool_t rc = kFALSE;
166 if (IsEnvDefined(env, prefix, "FileName", print))
167 {
168 rc = kTRUE;
169 SetFileName(GetEnvValue(env, prefix, "FileName", fFileName));
170 }
171 if (IsEnvDefined(env, prefix, "TreeName", print))
172 {
173 rc = kTRUE;
174 SetFileName(GetEnvValue(env, prefix, "TreeName", fTreeName));
175 }
176 if (IsEnvDefined(env, prefix, "Selector", print))
177 {
178 rc = kTRUE;
179 SetSelector(GetEnvValue(env, prefix, "Selector", fSelector));
180 }
181 return rc;
182}
Note: See TracBrowser for help on using the repository browser.