ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/Mods/src/SeparatePileUpMod.cc
Revision: 1.3
Committed: Fri May 4 20:28:33 2012 UTC (13 years ago) by ceballos
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_029c, Mit_029b, Mit_029a, Mit_028a, Mit_028, Mit_027, Mit_027a, HEAD
Changes since 1.2: +6 -3 lines
Log Message:
use of all vertexes option

File Contents

# Content
1 // $Id: SeparatePileUpMod.cc,v 1.2 2012/04/27 22:41:41 ceballos 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 fAllVertexName(Names::gkPVBrn),
19 fVertexName(ModNames::gkGoodVertexesName),
20 fPFCandidates(0),
21 fAllVertices(0),
22 fVertices(0),
23 fCheckClosestZVertex(kTRUE),
24 fUseAllVertices(kTRUE)
25 {
26 // Constructor.
27 }
28
29 //------------------------------------------------------------------------------
30 void SeparatePileUpMod::Process()
31 {
32 // Process entries of the tree.
33
34 LoadBranch(fPFCandidatesName);
35
36 PFCandidateOArr *pfPileUp = new PFCandidateOArr;
37 pfPileUp->SetName(fPFPileUpName);
38
39 PFCandidateOArr *pfNoPileUp = new PFCandidateOArr;
40 pfNoPileUp->SetName(fPFNoPileUpName);
41
42 LoadBranch(fAllVertexName);
43
44 if(fUseAllVertices == kTRUE) fVertices = fAllVertices;
45 else fVertices = GetObjThisEvt<VertexOArr>(fVertexName);
46
47 for(UInt_t i = 0; i < fPFCandidates->GetEntries(); i++) {
48 const PFCandidate *pf = fPFCandidates->At(i);
49 assert(pf);
50
51 if(pf->PFType() == PFCandidate::eHadron) {
52 if(pf->HasTrackerTrk() &&
53 fVertices->At(0)->HasTrack(pf->TrackerTrk()) &&
54 fVertices->At(0)->TrackWeight(pf->TrackerTrk()) > 0)
55 {
56 pfNoPileUp->Add(pf);
57 }
58 else {
59 Bool_t vertexFound = kFALSE;
60 const Vertex *closestVtx = 0;
61 Double_t dzmin = 10000;
62
63 for(UInt_t j = 0; j < fAllVertices->GetEntries(); j++) {
64 const Vertex *vtx = fAllVertices->At(j);
65 assert(vtx);
66
67 if(pf->HasTrackerTrk() &&
68 vtx->HasTrack(pf->TrackerTrk()) &&
69 vtx->TrackWeight(pf->TrackerTrk()) > 0) {
70 vertexFound = kTRUE;
71 closestVtx = vtx;
72 break;
73 }
74 Double_t dz = fabs(pf->SourceVertex().Z() - vtx->Z());
75 if(dz < dzmin) {
76 closestVtx = vtx;
77 dzmin = dz;
78 }
79 }
80
81 if(fCheckClosestZVertex) {
82 // Fallback: if track is not associated with any vertex,
83 // associate it with the vertex closest in z
84 if(vertexFound || closestVtx != fVertices->At(0))
85 pfPileUp->Add(pf);
86 else
87 pfNoPileUp->Add(pf);
88 }
89 else {
90 if(vertexFound && closestVtx != fVertices->At(0))
91 pfPileUp->Add(pf);
92 else
93 pfNoPileUp->Add(pf); // Ridiculous but that's how it is
94 }
95 }
96 }
97 else {
98 pfNoPileUp->Add(pf);
99 }
100 } // Loop over PF candidates
101
102 // add to event for other modules to use
103 AddObjThisEvt(pfPileUp);
104 AddObjThisEvt(pfNoPileUp);
105 }
106
107 //------------------------------------------------------------------------------
108 void SeparatePileUpMod::SlaveBegin()
109 {
110 // Run startup code on the computer (slave) doing the actual analysis. Here,
111 // we just request the Tau collection branch.
112
113 ReqBranch(fAllVertexName, fAllVertices);
114 ReqBranch(fPFCandidatesName, fPFCandidates);
115 }