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
Log Message:
Fix verbosity level

File Contents

# User Rev Content
1 lethuill 1.5 #include "../interface/HLTAnalyzer.h"
2 mlethuil 1.1
3     using namespace std;
4    
5 lethuill 1.7 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 mlethuil 1.1 {
17 lethuill 1.7 triggerResultsTag_ = producersNames.getParameter<edm::InputTag> ("hltProducer");
18     allowMissingCollection_ = producersNames.getUntrackedParameter<bool>("allowMissingCollection", false);
19 mlethuil 1.1 }
20    
21 lethuill 1.7
22     bool HLTAnalyzer::init(const edm::Event& iEvent, TRootEvent* rootEvent)
23 mlethuil 1.1 {
24 lethuill 1.7
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 mlethuil 1.1 }
57    
58    
59 lethuill 1.7 bool HLTAnalyzer::process(const edm::Event& iEvent, TRootEvent* rootEvent)
60 mlethuil 1.1 {
61 lethuill 1.7 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 lethuill 1.8 if(verbosity_>1) cout << " HLT decision: " << accept << endl;
70 lethuill 1.7 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 mlethuil 1.1
113    
114 lethuill 1.7 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 mlethuil 1.1 }
153    
154     void HLTAnalyzer::copySummary(TRootRun* runInfos)
155     {
156 lethuill 1.7 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 mlethuil 1.1 }