41 |
|
|
42 |
|
#include "DataFormats/TrackReco/interface/Track.h" |
43 |
|
#include "DataFormats/TrackReco/interface/TrackFwd.h" |
44 |
< |
#include "UserCode/PVStudy/interface/TrackSorter.h" |
44 |
> |
#include "DataFormats/VertexReco/interface/Vertex.h" |
45 |
> |
#include <DataFormats/VertexReco/interface/VertexFwd.h> |
46 |
|
|
47 |
+ |
#include "UserCode/PVStudy/interface/TrackSorter.h" |
48 |
|
#include "TrackingTools/TransientTrack/interface/TransientTrackBuilder.h" |
49 |
< |
#include "TrackingTools/Records/interface/TransientTrackRecord.h" |
50 |
< |
#include "TrackingTools/TransientTrack/interface/TransientTrack.h" |
51 |
< |
#include "MagneticField/Records/interface/IdealMagneticFieldRecord.h" |
49 |
> |
#include "TrackingTools/Records/interface/TransientTrackRecord.h" |
50 |
> |
#include "TrackingTools/TransientTrack/interface/TransientTrack.h" |
51 |
> |
#include "MagneticField/Records/interface/IdealMagneticFieldRecord.h" |
52 |
> |
|
53 |
> |
#include "PhysicsTools/UtilAlgos/interface/TFileService.h" |
54 |
|
|
55 |
|
TrackSplitterProducer::TrackSplitterProducer(const edm::ParameterSet & iConfig) |
56 |
|
: theTrackFilter(iConfig.getParameter<edm::ParameterSet>("TkFilterParameters")) |
59 |
|
debug_ = iConfig.getParameter<bool> ("Debug"); |
60 |
|
TrackCollectionTag_ = iConfig.getParameter<edm::InputTag>("TrackCollectionTag"); |
61 |
|
bsSrc = iConfig.getParameter< edm::InputTag >("beamSpot"); |
62 |
+ |
vertexCollectionTag_ = iConfig.getUntrackedParameter<edm::InputTag>("vertexCollection"); |
63 |
+ |
min_pvtx_zsep_ = iConfig.getParameter<double> ("minPvtxZsep"); |
64 |
+ |
pixelVertexCollectionTag_ = iConfig.getParameter<edm::InputTag>("pixelVertexCollectionTag"); |
65 |
+ |
trkFilterZcut_ = iConfig.getParameter<double> ("trkFilterZcut"); |
66 |
|
|
67 |
|
produces<TrackCollection>("SplittedTracks1"); |
68 |
< |
produces<TrackCollection>("SplittedTracks2"); |
68 |
> |
produces<TrackCollection>("SplittedTracks2"); |
69 |
|
} |
70 |
|
|
71 |
|
|
75 |
|
using namespace reco; |
76 |
|
using namespace std; |
77 |
|
|
78 |
< |
Handle< TrackCollection> trackCollectionHandle; |
78 |
> |
if(debug_) |
79 |
> |
cout<<"Starting TrackSplitterProducer::produce()..."<<endl; |
80 |
> |
|
81 |
> |
|
82 |
> |
//======================================================= |
83 |
> |
// PVTX accessors |
84 |
> |
//======================================================= |
85 |
> |
//vertexCollection |
86 |
> |
static const reco::VertexCollection s_empty_vertexColl; |
87 |
> |
const reco::VertexCollection *vertexColl = &s_empty_vertexColl; |
88 |
> |
edm::Handle<reco::VertexCollection> vertexCollectionHandle; |
89 |
> |
iEvent.getByLabel(vertexCollectionTag_, vertexCollectionHandle); |
90 |
> |
if( iEvent.getByLabel(vertexCollectionTag_, vertexCollectionHandle)) { |
91 |
> |
vertexColl = vertexCollectionHandle.product(); |
92 |
> |
} else { |
93 |
> |
cout << "vertexCollection cannot be found -> using empty collection of same type." <<endl; |
94 |
> |
} |
95 |
> |
|
96 |
> |
if (vertexColl->size() == 0) return; |
97 |
> |
// The event must have a valid leading vertex with proper fit (!isFake()) |
98 |
> |
if (vertexColl->begin()->isFake() || !(vertexColl->begin()->isValid())) return; |
99 |
> |
|
100 |
> |
// == Apply event pre-selection based on if the leading pvtx has nearby pvtx within max_zsep |
101 |
> |
// zsep is the mininum separation of the secondary pvtxs to the leading one |
102 |
> |
if(vertexColl->size()>1) { |
103 |
> |
double zsep = 9999.0; |
104 |
> |
for(reco::VertexCollection::const_iterator v=vertexColl->begin() + 1 ; |
105 |
> |
v!=vertexColl->end(); ++v) { |
106 |
> |
if(v->isValid() && ! v->isFake()) { |
107 |
> |
// zsep |
108 |
> |
if(fabs(v->z()- vertexColl->begin()->z())< zsep) |
109 |
> |
zsep = fabs(v->z()- vertexColl->begin()->z()); |
110 |
> |
} |
111 |
> |
} |
112 |
> |
if( zsep < min_pvtx_zsep_ ) return; |
113 |
> |
} |
114 |
> |
|
115 |
> |
//======================================================= |
116 |
> |
// Track accessors |
117 |
> |
//======================================================= |
118 |
> |
|
119 |
> |
edm::Handle<reco::TrackCollection> trackCollectionHandle; |
120 |
|
iEvent.getByLabel(TrackCollectionTag_, trackCollectionHandle); |
121 |
|
|
122 |
+ |
|
123 |
+ |
//======================================================= |
124 |
+ |
// BeamSpot accessors |
125 |
+ |
//======================================================= |
126 |
+ |
|
127 |
|
edm::Handle<reco::BeamSpot> recoBeamSpotHandle; |
128 |
|
iEvent.getByLabel(bsSrc,recoBeamSpotHandle); |
129 |
|
reco::BeamSpot bs = *recoBeamSpotHandle; |
134 |
|
TrackSorter trksorter; |
135 |
|
TrackCollection sortedTrackColl = trksorter.sortedList(*(trackCollectionHandle.product())); |
136 |
|
|
83 |
– |
|
137 |
|
// Filter the track for PV |
138 |
|
std::vector<reco::Track> filtedTrackColl; |
139 |
|
edm::ESHandle<TransientTrackBuilder> theB; |
140 |
|
iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder",theB); |
141 |
|
|
142 |
+ |
//Get pixelVertices |
143 |
+ |
static const reco::VertexCollection s_empty_pixelVertexColl; |
144 |
+ |
const reco::VertexCollection *pixelVertexColl = &s_empty_pixelVertexColl; |
145 |
+ |
edm::Handle<reco::VertexCollection> pixelVertexCollectionHandle; |
146 |
+ |
iEvent.getByLabel(pixelVertexCollectionTag_, pixelVertexCollectionHandle); |
147 |
+ |
if( iEvent.getByLabel(pixelVertexCollectionTag_, pixelVertexCollectionHandle)) { |
148 |
+ |
pixelVertexColl = pixelVertexCollectionHandle.product(); |
149 |
+ |
} else { |
150 |
+ |
cout << "pixelVertexCollection cannot be found. -> using empty collection of same type." <<endl; |
151 |
+ |
} |
152 |
+ |
|
153 |
+ |
if(debug_) |
154 |
+ |
cout<<"Getting pixelVertices: size() = "<< pixelVertexColl->size() <<endl; |
155 |
+ |
|
156 |
+ |
if(pixelVertexColl->size() == 0 ) return; |
157 |
|
|
158 |
+ |
//Get the z and sigma z of the first vertex of pixelVertexColl |
159 |
+ |
double z_pixelpvtx = pixelVertexColl->begin()->z(); |
160 |
+ |
double zerr_pixelpvtx = pixelVertexColl->begin()->zError(); |
161 |
+ |
if(debug_) { |
162 |
+ |
std::cout<<"TrackSplitterProducer pixelVertex z = "<<z_pixelpvtx<<" +/- "<<zerr_pixelpvtx<<std::endl; |
163 |
+ |
// Fill the track->dz() in the PV difference from first pixelpvtx |
164 |
+ |
std::cout<<"Looping through "<< pixelVertexColl->begin()->tracksSize() <<" pixelTracks"<<endl; |
165 |
+ |
for(reco::Vertex::trackRef_iterator t = (pixelVertexColl->begin())->tracks_begin(); |
166 |
+ |
t!= (pixelVertexColl->begin())->tracks_end(); t++) { |
167 |
+ |
// illegal charge |
168 |
+ |
if ( (**t).charge() < -1 || (**t).charge() > 1 ) { |
169 |
+ |
// h["trkPtPV"]->Fill(0.); |
170 |
+ |
} |
171 |
+ |
else |
172 |
+ |
std::cout<<"pixelTrack dz() = "<<(**t).dz()<<" +/- "<<(**t).dzError()<<endl; |
173 |
+ |
} |
174 |
+ |
} |
175 |
+ |
|
176 |
+ |
|
177 |
+ |
// Loop over generalTracks and apply trkFilter |
178 |
|
for(TrackCollection::const_iterator track = sortedTrackColl.begin(); track!= sortedTrackColl.end(); ++track) |
179 |
|
{ |
180 |
|
TransientTrack t_track = (*theB).build(*track); |
181 |
|
t_track.setBeamSpot(bs); |
182 |
< |
if (theTrackFilter(t_track)) filtedTrackColl.push_back(Track (*track)); |
182 |
> |
//Filter tracks based on default track filter by offlinePrimaryVertices |
183 |
> |
if (theTrackFilter(t_track)) { |
184 |
> |
//Filter tracks based on the z provided by pixelVertices |
185 |
> |
if (fabs((track->dz() - z_pixelpvtx)) < trkFilterZcut_ *track->dzError()) |
186 |
> |
filtedTrackColl.push_back(Track (*track)); |
187 |
> |
else { |
188 |
> |
if(debug_) { |
189 |
> |
cout<<"WARNING: track dz is not within "<< trkFilterZcut_ << " cm." <<endl; |
190 |
> |
cout<<" track->dz = "<<track->dz()<<" +/- "<<track->dzError() |
191 |
> |
<<" track->dz - z_pixelpvtx = " << track->dz()-z_pixelpvtx<<endl; |
192 |
> |
} |
193 |
> |
} |
194 |
> |
} |
195 |
|
} |
196 |
|
|
197 |
+ |
|
198 |
|
// create the two splitted trackCollections |
199 |
|
splittedTColl1_ = std::auto_ptr<TrackCollection> (new TrackCollection ); |
200 |
|
splittedTColl2_ = std::auto_ptr<TrackCollection> (new TrackCollection ); |
205 |
|
if(debug_) |
206 |
|
cout<<"TrackSplitterProducer looping over "<< filtedTrackColl.size()<< "tracks." << endl; |
207 |
|
|
107 |
– |
//for(TrackCollection::const_iterator track = sortedTrackColl.begin(); track!= sortedTrackColl.end(); ++track, ++i) |
208 |
|
for(TrackCollection::const_iterator track = filtedTrackColl.begin(); track!= filtedTrackColl.end(); ++track, ++i) |
209 |
|
{ |
210 |
< |
if(debug_) |
211 |
< |
cout<< "Track "<<i<<" : pT = "<<track->pt()<<endl; |
210 |
> |
if(debug_) { |
211 |
> |
cout<< "Track "<<i<<" : pT = "<<track->pt() |
212 |
> |
<<"; dz = "<< track->dz() <<" +/- "<< track->dzError() <<endl; |
213 |
> |
} |
214 |
|
|
215 |
|
//Iterate every other track |
216 |
|
if (track != (filtedTrackColl.end() -1) ) { |