ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/Mods/src/SeparatePileUpMod.cc
Revision: 1.1
Committed: Fri Apr 27 21:03:35 2012 UTC (13 years ago) by ceballos
Content type: text/plain
Branch: MAIN
Log Message:
new module

File Contents

# User Rev Content
1 ceballos 1.1 // $Id: SeparatePileUpMod.cc,v 1.9 2010/07/06 08:33:16 sixie Exp $
2    
3     #include "MitPhysics/Mods/interface/SeparatePileUpMod.h"
4     #include "MitAna/DataTree/interface/PFCandidateCol.h"
5     #include "MitAna/DataTree/interface/VertexCol.h"
6     #include "MitPhysics/Init/interface/ModNames.h"
7    
8     using namespace mithep;
9    
10     ClassImp(mithep::SeparatePileUpMod)
11    
12     //------------------------------------------------------------------------------
13     SeparatePileUpMod::SeparatePileUpMod(const char *name, const char *title) :
14     BaseMod(name,title),
15     fPFCandidatesName(Names::gkPFCandidatesBrn),
16     fPFPileUpName("PFPileUp"),
17     fPFNoPileUpName("PFNoPileUp"),
18     fVertexName(ModNames::gkGoodVertexesName),
19     fPFCandidates(0),
20     fVertices(0),
21     fCheckClosestZVertex(kTRUE)
22     {
23     // Constructor.
24     }
25    
26     //------------------------------------------------------------------------------
27     void SeparatePileUpMod::Process()
28     {
29     // Process entries of the tree.
30    
31     LoadBranch(fPFCandidatesName);
32    
33     PFCandidateOArr *pfPileUp = new PFCandidateOArr;
34     pfPileUp->SetName(fPFPileUpName);
35    
36     PFCandidateOArr *pfNoPileUp = new PFCandidateOArr;
37     pfNoPileUp->SetName(fPFNoPileUpName);
38    
39     fVertices = GetObjThisEvt<VertexOArr>(fVertexName);
40    
41     for(UInt_t i = 0; i < fPFCandidates->GetEntries(); i++) {
42     const PFCandidate *pf = fPFCandidates->At(i);
43     assert(pf);
44    
45     if(pf->PFType() == PFCandidate::eHadron) {
46     if(pf->HasTrackerTrk() &&
47     fVertices->At(0)->HasTrack(pf->TrackerTrk()) &&
48     fVertices->At(0)->TrackWeight(pf->TrackerTrk()) > 0)
49     {
50     pfNoPileUp->Add(pf);
51     }
52     else {
53     Bool_t vertexFound = kFALSE;
54     const Vertex *closestVtx = 0;
55     Double_t dzmin = 10000;
56    
57     for(UInt_t j = 0; j < fVertices->GetEntries(); j++) {
58     const Vertex *vtx = fVertices->At(j);
59     assert(vtx);
60    
61     if(pf->HasTrackerTrk() &&
62     vtx->HasTrack(pf->TrackerTrk()) &&
63     vtx->TrackWeight(pf->TrackerTrk()) > 0) {
64     vertexFound = kTRUE;
65     closestVtx = vtx;
66     break;
67     }
68     Double_t dz = fabs(pf->SourceVertex().Z() - vtx->Z());
69     if(dz < dzmin) {
70     closestVtx = vtx;
71     dzmin = dz;
72     }
73     }
74    
75     if(fCheckClosestZVertex) {
76     // Fallback: if track is not associated with any vertex,
77     // associate it with the vertex closest in z
78     if(vertexFound || closestVtx != fVertices->At(0))
79     pfPileUp->Add(pf);
80     else
81     pfNoPileUp->Add(pf);
82     }
83     else {
84     if(vertexFound && closestVtx != fVertices->At(0))
85     pfPileUp->Add(pf);
86     else
87     pfNoPileUp->Add(pf); // Ridiculous but that's how it is
88     }
89     }
90     }
91     else {
92     pfNoPileUp->Add(pf);
93     }
94     } // Loop over PF candidates
95    
96     // add to event for other modules to use
97     AddObjThisEvt(pfPileUp);
98     AddObjThisEvt(pfNoPileUp);
99     }
100    
101     //------------------------------------------------------------------------------
102     void SeparatePileUpMod::SlaveBegin()
103     {
104     // Run startup code on the computer (slave) doing the actual analysis. Here,
105     // we just request the Tau collection branch.
106    
107     ReqBranch(fPFCandidatesName, fPFCandidates);
108     }