ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/Mods/src/EffMod.cc
Revision: 1.2
Committed: Mon Jun 29 08:41:50 2009 UTC (15 years, 10 months ago) by loizides
Content type: text/plain
Branch: MAIN
Changes since 1.1: +18 -16 lines
Log Message:
Plot ratios if root is not in batch mode

File Contents

# User Rev Content
1 loizides 1.2 // $Id: EffMod.cc,v 1.1 2009/04/29 15:06:42 loizides Exp $
2 loizides 1.1
3     #include "MitPhysics/Mods/interface/EffMod.h"
4     #include "MitAna/DataCont/interface/BaseCollection.h"
5     #include "MitPhysics/Init/interface/ModNames.h"
6     #include "MitCommon/MathTools/interface/MathUtils.h"
7     #include <TH1D.h>
8    
9     using namespace mithep;
10    
11     ClassImp(mithep::EffMod)
12    
13     //--------------------------------------------------------------------------------------------------
14     EffMod::EffMod(const char *name, const char *title) :
15     BaseMod(name,title),
16     fCol1Name(ModNames::gkMCLeptonsName),
17     fCol2Name(ModNames::gkMergedLeptonsName),
18     fMinPt(10),
19     fMaxEta(2.4),
20     fRadius(0.1),
21     fPartType(MCParticle::kUnknown)
22     {
23     // Constructor.
24     }
25    
26    
27     //--------------------------------------------------------------------------------------------------
28     void EffMod::Process()
29     {
30     // Process entries of the tree.
31    
32     const BaseCollection *col1 = GetObjThisEvt<BaseCollection>(fCol1Name);
33     const BaseCollection *col2 = GetObjThisEvt<BaseCollection>(fCol2Name);
34    
35     UInt_t ents1 = 0;
36     if (col1)
37     ents1 = col1->GetEntries();
38    
39     UInt_t ents2 = 0;
40     if (col2)
41     ents2 = col2->GetEntries();
42    
43     Bool_t *found = new Bool_t[ents2];
44     for (UInt_t i=0; i<ents2; ++i)
45     found[i] = kFALSE;
46    
47     // find matches
48     for (UInt_t j=0; j<ents1; ++j) {
49     const Particle *p1 = dynamic_cast<const Particle*>(col1->ObjAt(j));
50     if (!p1)
51     continue;
52    
53     if (fPartType != MCParticle::kUnknown) {
54     const MCParticle *mc = dynamic_cast<const MCParticle*>(p1);
55     if (!mc || !mc->Is(fPartType))
56     continue;
57     }
58    
59     Double_t pt = p1->Pt();
60     if (pt < fMinPt)
61     continue;
62     if (p1->AbsEta() > fMaxEta)
63     continue;
64    
65     Double_t phi = p1->Phi();
66     Double_t eta = p1->Eta();
67    
68     fCol1Pt->Fill(TMath::Min(pt, 299.999));
69     fCol1Eta->Fill(eta);
70    
71     UInt_t foundInd = ents2;
72     Double_t foundD = 1e12;
73    
74     for (UInt_t i=0; i<ents2; ++i) {
75     if (found[i]) continue;
76     const Particle *p2 = dynamic_cast<const Particle*>(col2->ObjAt(i));
77     if (!p2)
78     continue;
79    
80     if(MathUtils::DeltaR(phi, eta, p2->Phi(), p2->Eta()) < fRadius) {
81     Double_t newDiff = TMath::Abs(pt - p2->Pt());
82     if (newDiff < foundD) {
83     foundInd = i;
84     foundD = newDiff;
85     }
86     }
87     }
88     if (foundInd < ents2) {
89     fCol2Pt->Fill(TMath::Min(p1->Pt(),299.999));
90     fCol2Eta->Fill(p1->Eta());
91     found[foundInd] = 1;
92     }
93     }
94    
95     // find fakes
96     for (UInt_t i=0; i<ents2; ++i) {
97     const Particle *p2 = dynamic_cast<const Particle*>(col2->ObjAt(i));
98     if (!p2)
99     continue;
100     if (found[i]) {
101     fGoodPt->Fill(TMath::Min(p2->Pt(),299.999));
102     fGoodEta->Fill(p2->Eta());
103     } else {
104     fFakePt->Fill(TMath::Min(p2->Pt(),299.999));
105     fFakeEta->Fill(p2->Eta());
106     }
107     }
108    
109     }
110    
111     //--------------------------------------------------------------------------------------------------
112     void EffMod::SlaveBegin()
113     {
114     // Create and add histograms to the output list.
115    
116     AddTH1(fCol1Pt,"hCol1Pt",";p_{T} [GeV];#",100,0,300);
117     AddTH1(fCol1Eta,"hCol1Eta",";#eta;#",50,-5,5);
118     AddTH1(fCol2Pt,"hCol2Pt",";p_{T} [GeV];#",100,0,300);
119     AddTH1(fCol2Eta,"hCol2Eta",";#eta;#",50,-5,5);
120     AddTH1(fGoodPt,"hGoodPt",";p_{T} [GeV];#",100,0,300);
121     AddTH1(fGoodEta,"hGoodEta",";#eta;#",50,-5,5);
122     AddTH1(fFakePt,"hFakePt",";p_{T} [GeV];#",100,0,300);
123     AddTH1(fFakeEta,"hFakeEta",";#eta;#",50,-5,5);
124     }
125    
126     //--------------------------------------------------------------------------------------------------
127     void EffMod::Terminate()
128     {
129     // Create and add ratio histograms to the output list.
130    
131 loizides 1.2 if (gROOT->IsBatch()) {
132     TH1D *pteff = static_cast<TH1D*>(fCol2Pt->Clone("hPtEff"));
133     pteff->Divide(fCol1Pt);
134     AddOutput(pteff);
135    
136     TH1D *etaeff = static_cast<TH1D*>(fCol2Eta->Clone("hEtaEff"));
137     etaeff->Divide(fCol1Eta);
138     AddOutput(etaeff);
139    
140     TH1D *ptfrate = static_cast<TH1D*>(fFakePt->Clone("hPtFakeRate"));
141     ptfrate->Divide(fGoodPt);
142     AddOutput(ptfrate);
143    
144     TH1D *etafrate = static_cast<TH1D*>(fFakeEta->Clone("hEtaFakeRate"));
145     etafrate->Divide(fGoodEta);
146     AddOutput(etafrate);
147     }
148 loizides 1.1 }