ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/Morgan/src/LeptonAnalyzer.cc
Revision: 1.6
Committed: Wed Oct 28 16:06:54 2009 UTC (15 years, 6 months ago) by lethuill
Content type: text/plain
Branch: MAIN
CVS Tags: all_3_3_2_01, HEAD
Changes since 1.5: +1 -13 lines
Log Message:
Use primary vertex instead of beam spot in d0 and dz calculation

File Contents

# Content
1 #include "../interface/LeptonAnalyzer.h"
2
3 using namespace std;
4 using namespace reco;
5 using namespace edm;
6
7 LeptonAnalyzer::LeptonAnalyzer(const edm::ParameterSet& producersNames, const edm::ParameterSet& myConfig, int verbosity):verbosity_(verbosity),initOK_(false),dummyVertex_(false),trackBuilder_(),primaryVertex_(0),vertexPoint_(0)
8 {
9 allowMissingCollection_ = producersNames.getUntrackedParameter<bool>("allowMissingCollection", false);
10 dataType_ = producersNames.getUntrackedParameter<string>("dataType","unknown");
11 doPrimaryVertex_ = myConfig.getUntrackedParameter<bool>("doPrimaryVertex");
12 doBeamSpot_ = myConfig.getUntrackedParameter<bool>("doBeamSpot");
13 vertexProducer_ = producersNames.getParameter<edm::InputTag>("primaryVertexProducer");
14 }
15
16
17 LeptonAnalyzer::~LeptonAnalyzer()
18 {
19 if (dummyVertex_) delete primaryVertex_;
20 if (vertexPoint_ != 0) delete vertexPoint_;
21 }
22
23
24 void LeptonAnalyzer::initIPCalculator(const edm::Event& iEvent, const edm::EventSetup& iSetup, TRootEvent* rootEvent, TRootBeamSpot* rootBeamSpot)
25 {
26
27 // Get the track builder
28 try
29 {
30 iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder",trackBuilder_);
31 }
32 catch (cms::Exception& exception)
33 {
34 if ( !allowMissingCollection_ )
35 {
36 cout << " ##### ERROR IN LeptonAnalyzer::initIPCalculator => Track builder is missing in EventSetup #####"<<endl;
37 throw exception;
38 }
39 if(verbosity_>1) cout << " ===> No Track builder, skip IP3D calculation" << endl;
40 initOK_ = false;
41 }
42
43 // Get primary vertex collection
44 unsigned int nVertices = 0;
45 edm::Handle< reco::VertexCollection > recoVertices;
46 try
47 {
48 iEvent.getByLabel(vertexProducer_, recoVertices);
49 nVertices = recoVertices->size();
50 }
51 catch (cms::Exception& exception)
52 {
53 if ( !allowMissingCollection_ )
54 {
55 cout << " ##### ERROR IN LeptonAnalyzer::initIPCalculator => Vertex collection is missing #####"<<endl;
56 throw exception;
57 }
58 if(verbosity_>1) cout << " ===> No Vertex collection, skip IP3D calculation" << endl;
59 initOK_ = false;
60 }
61
62
63 if ( nVertices==0 )
64 {
65 // FIXME - Take beamspot instead ?
66 cout << "***** ERROR in LeptonAnalyzer::initIPCalculator() - No reco::Vertex for this event - Will use dummy vertex *****" << endl;
67 reco::Vertex::Point point(0,0,0);
68 reco::Vertex::Error error;
69 error(0,0) = 0.0015*0.0015;
70 error(1,1) = 0.0015*0.0015;
71 error(2,2) = 15.*15.;
72 primaryVertex_ = new reco::Vertex(point,error,1,1,1);
73 dummyVertex_ = true;
74 }
75 else if ( rootEvent->primaryVertexIndex()>=int(recoVertices->size()) )
76 {
77 cout << "***** ERROR in LeptonAnalyzer::initIPCalculator() - Selected primary vertex not found in reco::Vertex collection - Will use first reco::Vertex *****" << endl;
78 primaryVertex_ = & ((*recoVertices)[0]);
79 }
80 else if ( rootEvent->primaryVertexIndex()<0 )
81 {
82 cout << "***** ERROR in LeptonAnalyzer::initIPCalculator() - No Primary vertex was selected in reco::Vertex collection - Will use first reco::Vertex *****" << endl;
83 primaryVertex_ = & ((*recoVertices)[0]);
84 }
85 else
86 {
87 primaryVertex_ = & ((*recoVertices)[rootEvent->primaryVertexIndex()]);
88 }
89
90 vertexPoint_ = new GlobalPoint(primaryVertex_->position().x(),primaryVertex_->position().y(),primaryVertex_->position().z());
91
92 initOK_ = true;
93 }
94
95
96 float LeptonAnalyzer::ip3DSignificance(const reco::TransientTrack& track)
97 {
98 float significance = -9999.;
99 if ( initOK_ )
100 {
101 const TrajectoryStateOnSurface tsos = track.stateOnSurface(*vertexPoint_);
102 if (!tsos.isValid())
103 {
104 significance = -8888.;
105 }
106 else
107 {
108 std::pair<bool,Measurement1D> muIPpair;
109 muIPpair = IPTools::signedImpactParameter3D(tsos, tsos.globalDirection(), *primaryVertex_);
110
111 if (muIPpair.first)
112 {
113 significance = muIPpair.second.significance();
114 }
115 else
116 {
117 significance = -7777.;
118 }
119 }
120 }
121 return significance;
122 }