ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/Morgan/src/HLTAnalyzer.cc
Revision: 1.8
Committed: Tue Oct 27 16:04:39 2009 UTC (15 years, 6 months ago) by lethuill
Content type: text/plain
Branch: MAIN
CVS Tags: all_3_3_2_01, all_3_2_5_02, HEAD
Changes since 1.7: +1 -1 lines
Error occurred while calculating annotation data.
Log Message:
Fix verbosity level

File Contents

# Content
1 #include "../interface/HLTAnalyzer.h"
2
3 using namespace std;
4
5 HLTAnalyzer::HLTAnalyzer(const edm::ParameterSet& producersNames, int verbosity) :
6 verbosity_(verbosity)
7 ,triggerNames_()
8 ,nEvents_(0)
9 ,nWasRun_(0)
10 ,nAccept_(0)
11 ,nErrors_(0)
12 ,hltWasRun_(0)
13 ,hltAccept_(0)
14 ,hltErrors_(0)
15 ,hltNames_(0)
16 {
17 triggerResultsTag_ = producersNames.getParameter<edm::InputTag> ("hltProducer");
18 allowMissingCollection_ = producersNames.getUntrackedParameter<bool>("allowMissingCollection", false);
19 }
20
21
22 bool HLTAnalyzer::init(const edm::Event& iEvent, TRootEvent* rootEvent)
23 {
24
25 try
26 {
27 edm::Handle<edm::TriggerResults> trigResults;
28 iEvent.getByLabel(triggerResultsTag_,trigResults);
29 triggerNames_.init(*trigResults);
30 }
31 catch (cms::Exception& exception)
32 {
33 if ( !allowMissingCollection_ )
34 {
35 cout << " ##### ERROR IN HLTAnalyzer::init => No TriggerResults #####"<<endl;
36 throw exception;
37 }
38 return false;
39 }
40
41 hltNames_=triggerNames_.triggerNames();
42 const unsigned int n(hltNames_.size());
43 if(verbosity_>4) cout << " Number of HLT paths = " << n << endl;
44 hltWasRun_.resize(n);
45 hltAccept_.resize(n);
46 hltErrors_.resize(n);
47 for (unsigned int i=0; i!=n; ++i)
48 {
49 if(verbosity_>4) cout << " Name of HLT path " << i << ": " << hltNames_[i] << endl;
50 hltWasRun_[i]=0;
51 hltAccept_[i]=0;
52 hltErrors_[i]=0;
53 }
54
55 return true;
56 }
57
58
59 bool HLTAnalyzer::process(const edm::Event& iEvent, TRootEvent* rootEvent)
60 {
61 nEvents_++;
62 edm::Handle<edm::TriggerResults> trigResults;
63 try
64 {
65 iEvent.getByLabel(triggerResultsTag_,trigResults);
66 if (trigResults.isValid()) {
67 if (trigResults->wasrun()) nWasRun_++;
68 const bool accept(trigResults->accept());
69 if(verbosity_>1) cout << " HLT decision: " << accept << endl;
70 rootEvent->setGlobalHLT(accept);
71 if (accept) ++nAccept_;
72 if (trigResults->error() ) nErrors_++;
73 }
74 else
75 {
76 cout << " HLT results not found!" << endl;;
77 nErrors_++;
78 return false;
79 }
80 }
81 catch (cms::Exception& exception)
82 {
83 if ( !allowMissingCollection_ )
84 {
85 cout << " ##### ERROR IN HLTAnalyzer::process => No TriggerResults #####"<<endl;
86 throw exception;
87 }
88 cout << " HLT results not found!" << endl;;
89 nErrors_++;
90 return false;
91 }
92
93 // decision for each HLT algorithm
94 const unsigned int n(hltNames_.size());
95 std::vector<Bool_t> hltDecision(n, false);
96 for (unsigned int i=0; i!=n; ++i)
97 {
98 //if(verbosity_>4) cout << " Trigger result for HLT path " << i << " = "<< (trigResults->accept(i)) << endl;
99 if (trigResults->wasrun(i)) hltWasRun_[i]++;
100 if (trigResults->error(i) ) hltErrors_[i]++;
101 if (trigResults->accept(i))
102 {
103 hltAccept_[i]++;
104 hltDecision[i]=true;
105 }
106 }
107
108 rootEvent->setTrigHLT(hltDecision);
109
110 return true;
111 }
112
113
114 void HLTAnalyzer::printStats()
115 {
116 // final printout of accumulated statistics
117 const unsigned int n(hltNames_.size());
118
119 cout << dec << endl;
120 cout << "HLTAnalyzer-Summary " << "---------- Event Summary ------------\n";
121 cout << "HLTAnalyzer-Summary"
122 << " Events total = " << nEvents_
123 << " wasrun = " << nWasRun_
124 << " passed = " << nAccept_
125 << " errors = " << nErrors_
126 << "\n";
127
128 cout << endl;
129 cout << "HLTAnalyzer-Summary " << "---------- HLTrig Summary ------------\n";
130 cout << "HLTAnalyzer-Summary "
131 << right << setw(10) << "HLT Bit#" << " "
132 << right << setw(10) << "WasRun" << " "
133 << right << setw(10) << "Passed" << " "
134 << right << setw(10) << "Errors" << " "
135 << "Name" << "\n";
136
137 for (unsigned int i=0; i!=n; ++i)
138 {
139 cout << "HLTAnalyzer-Summary "
140 << right << setw(10) << i << " "
141 << right << setw(10) << hltWasRun_[i] << " "
142 << right << setw(10) << hltAccept_[i] << " "
143 << right << setw(10) << hltErrors_[i] << " "
144 << hltNames_[i] << "\n";
145 }
146
147 cout << endl;
148 cout << "HLTAnalyzer-Summary end!" << endl;
149 cout << endl;
150
151 return;
152 }
153
154 void HLTAnalyzer::copySummary(TRootRun* runInfos)
155 {
156 if(verbosity_>4) cout << " Copying HLT Summary table in TRootRun" << endl;
157
158 runInfos->setNHLTEvents(nEvents_) ;
159 runInfos->setNHLTWasRun(nWasRun_) ;
160 runInfos->setNHLTAccept(nAccept_) ;
161 runInfos->setNHLTErrors(nErrors_) ;
162
163 runInfos->setHLTWasRun(hltWasRun_) ;
164 runInfos->setHLTAccept(hltAccept_) ;
165 runInfos->setHLTErrors(hltErrors_) ;
166 runInfos->setHLTNames(hltNames_) ;
167
168 }