ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/L1RpcTriggerAnalysis/src/AnaRpcMisc.cc
Revision: 1.7
Committed: Tue Dec 11 12:49:33 2012 UTC (12 years, 4 months ago) by konec
Content type: text/plain
Branch: MAIN
CVS Tags: Artur_11_07_2013_B, Artur_11_07_2013_A, Artur_11_07_2013, Artur_28_06_2013, HEAD
Changes since 1.6: +20 -12 lines
Error occurred while calculating annotation data.
Log Message:
*** empty log message ***

File Contents

# Content
1 #include "UserCode/L1RpcTriggerAnalysis/interface/AnaRpcMisc.h"
2 #include "TProfile.h"
3 #include "TObjArray.h"
4 #include "TH2F.h"
5 #include "TH1D.h"
6 #include "TGraphErrors.h"
7 #include "TF1.h"
8 #include "UserCode/L1RpcTriggerAnalysis/interface/EventObj.h"
9 #include "UserCode/L1RpcTriggerAnalysis/interface/MuonObj.h"
10 #include "UserCode/L1RpcTriggerAnalysis/interface/L1Obj.h"
11 #include "UserCode/L1RpcTriggerAnalysis/interface/L1ObjColl.h"
12 #include "UserCode/L1RpcTriggerAnalysis/interface/Utilities.h"
13 #include <math.h>
14 #include <vector>
15
16 template <class T> T sqr( T t) {return t*t;}
17
18
19 void AnaRpcMisc::init(TObjArray& histos)
20 {
21 hRpcMisc_UE = new TH2D("hRpcMisc_US","hRpcMisc_UnderEstimated", L1RpcEtaScale::nEtaBins, L1RpcEtaScale::etaBins, 144, 0., 2.*M_PI); histos.Add(hRpcMisc_UE);
22 hRpcMisc_OE = new TH2D("hRpcMisc_OS","hRpcMisc_OverEstimated", L1RpcEtaScale::nEtaBins, L1RpcEtaScale::etaBins, 144, 0., 2.*M_PI); histos.Add(hRpcMisc_OE);
23 hRpcMisc_EffRun = new TH1D("hRpcMisc_EffRun","Efficiency in run; efficiency; weighted numb. of runs / bin",200,0.,1.); histos.Add(hRpcMisc_EffRun);
24 hRpcMisc_Time = new TH1D("hRpcMisc_Time","RPC Trigger timing",5,-2.5,2.5); histos.Add(hRpcMisc_Time);
25 hRpcMisc_TimeAll = new TH1D("hRpcMisc_TimeAll","RPC Trigger timing",5,-2.5,2.5); histos.Add(hRpcMisc_TimeAll);
26 hRpcMisc_TimeDen = new TH1D("hRpcMisc_TimeDen","RPC Trigger timing",5,-2.5,2.5); histos.Add(hRpcMisc_TimeDen);
27 }
28
29 double AnaRpcMisc::maxPt(const std::vector<L1Obj> & l1Objs) const
30 {
31 double result = 0.;
32 for (unsigned int i=0; i<l1Objs.size(); i++) if (l1Objs[i].pt > result) result = l1Objs[i].pt;
33 return result;
34 }
35
36 void AnaRpcMisc::run(const EventObj* event, const MuonObj *muon, const L1ObjColl *l1Coll)
37 {
38 if (effRunMap.find(event->run) == effRunMap.end()) effRunMap[event->run] = std::make_pair(0,0);
39 if (purRunMap.find(event->run) == purRunMap.end()) purRunMap[event->run] = std::make_pair(0,0);
40
41 // double etaMu = fabs(muon->eta());
42 double ptMu = muon->pt();
43 if (!muon->isGlobal()) return;
44
45 L1ObjColl l1RpcColl = l1Coll->l1RpcColl();
46 std::vector<L1Obj> l1Rpcs = l1RpcColl.selectByMatched().selectByBx().getL1Objs();
47
48 if (ptMu > 50. && l1Rpcs.size()==1 && l1Rpcs[0].pt < 8.) {
49 // debug = true;
50 if (debug) std::cout <<"HERE ptMu: "<<ptMu<<" ptRPC: "<<l1Rpcs[0].pt <<" eta:"<<l1Rpcs[0].eta << std::endl;
51 hRpcMisc_UE->Fill(l1Rpcs[0].eta, l1Rpcs[0].phi);
52 // if (fabs(l1Rpcs[0].eta)>1.2) {
53 // std::cout <<"RPC_pt: "<<l1Rpcs[0].pt<<" eta: "<<l1Rpcs[0].eta<<"phi: "<<l1Rpcs[0].phi<<std::endl;
54 // std::cout <<"MU__pt:"<<muon->pt()<<" eta: "<<muon->eta()<<" phi: "<<muon->phi()<<std::endl;
55 // }
56 }
57 if (ptMu < 8. && l1Rpcs.size()==1 && l1Rpcs[0].pt > 80.) hRpcMisc_OE->Fill(l1Rpcs[0].eta, l1Rpcs[0].phi);
58
59 if (ptMu > 20.) {
60 effRunMap[event->run].second++;
61 if (l1Rpcs.size() > 0 && l1Rpcs[0].pt >= 16) effRunMap[event->run].first++;
62 }
63 if (l1Rpcs.size() > 0 && fabs(muon->eta()) < 1.6) {
64 if (ptMu > 10. && l1Rpcs[0].pt >= 10) purRunMap[event->run].first++;
65 if (ptMu < 7. && l1Rpcs[0].pt >= 10) purRunMap[event->run].second++;
66 }
67
68 //
69 // timing
70 //
71 if (ptMu > 10. && fabs(muon->eta()) < 1.6 ) {
72 std::vector<L1Obj> l1RpcsAll = l1RpcColl.getL1Objs();
73 std::vector<L1Obj> l1RpcsMatched = l1RpcColl.selectByMatched().getL1Objs();
74 for (unsigned int i=0; i<5; i++) hRpcMisc_TimeDen->Fill(i-2.);
75 for (unsigned int i=0; i<l1RpcsMatched.size(); i++) hRpcMisc_Time->Fill(l1RpcsMatched[i].bx);
76 for (unsigned int i=0; i<l1RpcsAll.size();i++) hRpcMisc_TimeAll->Fill(l1RpcsAll[i].bx);
77 // for (unsigned int i=0; i<l1RpcsMatched.size(); i++) if (l1RpcsMatched[i].bx==-2) debug = true;
78 }
79 if (debug) {
80 std::cout <<"------------"<<std::endl;
81 std::cout <<" Event: "<<(*event).id <<" Lumi: "<<(*event).lumi<< std::endl;
82 std::cout <<"MU__pt:"<<muon->pt()<<" eta: "<<muon->eta()<<" phi: "<<muon->phi()<<std::endl;
83 std::cout << l1RpcColl << std::endl;
84
85 }
86 }
87
88
89 void AnaRpcMisc::resume(TObjArray& histos)
90 {
91 // average efficiency per Run
92 TGraphErrors * hGraphRun = new TGraphErrors;
93 hGraphRun->SetName("hGraph_RunEff");
94 histos.Add(hGraphRun);
95 unsigned int nPoints = 0;
96 // for( EffRunMap::const_iterator im = effRunMap.begin(); im != effRunMap.end(); ++im) if (im->second.first != 0) ++nPoints;
97 nPoints = effRunMap.size();
98 hGraphRun->Set(nPoints);
99 unsigned int iPoint=0;
100 for( EffRunMap::const_iterator im = effRunMap.begin(); im != effRunMap.end(); ++im) {
101 float eff = 0.;
102 float effErr = 1.;
103 // if (im->second.first==0 ) continue;
104 if (im->second.second != 0) {
105 eff = float(im->second.first)/float(im->second.second);
106 float effM1 = (im->second.first > 0)? float(im->second.first-1)/float(im->second.second) : 0.;
107 effErr = sqrt( (1-effM1)*std::max((int) im->second.first,1))/im->second.second;
108 }
109 std::cout <<" RUN: "<<im->first
110 <<" Effic: "<< eff <<" ("<<im->second.first<<"/"<<im->second.second<<")"<<std::endl;
111 hRpcMisc_EffRun->Fill(eff, 1./sqr(effErr));
112 hGraphRun->SetPoint(iPoint, im->first, eff);
113 hGraphRun->SetPointError(iPoint, 0., effErr);
114 iPoint++;
115 }
116
117 TGraphErrors * hGraphPur = new TGraphErrors;
118 hGraphPur->SetName("hGraph_RunPur");
119 histos.Add(hGraphPur);
120 iPoint = 0;
121 for( PurRunMap::const_iterator im = purRunMap.begin(); im != purRunMap.end(); ++im) {
122 // if (im->second.second == 0) continue;
123 hGraphPur->Set(++iPoint);
124 double pur=0.;
125 double purErr=0.;;
126 if (im->second.second != 0) {
127 double second = double(im->second.second);
128 pur = double(im->second.first)/second;
129 double firstE = im->second.first==0 ? 1. : double(im->second.first);
130 purErr = firstE/second*sqrt(1./firstE+ 1./second);
131 }
132 std::cout<<" RUN: " << im->first <<" Good: "<<im->second.first<<" Bad: "<< im->second.second << std::endl;
133 hGraphPur->SetPoint(iPoint-1, im->first, pur);
134 hGraphPur->SetPointError(iPoint-1, 0., purErr);
135 }
136
137 }