CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ggPFTracks.cc
Go to the documentation of this file.
2 //Class by Rishi Patel rpatel@cern.ch for Single Leg (high pt leg of Conversion
3 //For Vertex Selection, also has functions to do pointing using conversion pairs//that are stored with PFPhotons/PFElectrons
4 
6  edm::Handle<BeamSpot>& beamSpotHandle
7  ):
8  beamSpotHandle_(beamSpotHandle),//pass beamspot
9  isConv_(false)
10 {
11 
12 }
13 
15 //Fills a Vector of Conversion Tracks (single legs, or track pairs from a PFPhoton) and also Conversion Objects
17  reco::Photon phot,
18  vector<edm::RefToBase<reco::Track> > &Tracks,
20  vector<edm::RefToBase<reco::Track> > &SLTracks,
21  reco::ConversionRefVector &SLconversions
22  ){
23  Tracks.clear();
24  conversions.clear();
25  SLTracks.clear();
26  SLconversions.clear();
27  conversions=phot.conversions();
28  //loop over conversion paris
29  for(unsigned int c=0; c<conversions.size(); ++c){
30  const std::vector<edm::RefToBase<reco::Track> > tracks = conversions[c]->tracks();
31  for (unsigned int t=0; t<tracks.size(); t++){
32  Tracks.push_back(tracks[t]);
33  }
34  }
35 
36  reco::ConversionRefVector SLConversions=phot.conversionsOneLeg();
37 
38  for(unsigned int SLc=0; SLc<SLConversions.size(); ++SLc){
39  const std::vector<edm::RefToBase<reco::Track> > tracks = SLConversions[SLc]->tracks();
40  SLconversions.push_back(SLConversions[SLc]);
41 
42  for (unsigned int t=0; t<tracks.size(); t++){
43  SLTracks.push_back(tracks[t]);
44  }
45  }
46  if(SLConversions.size()>0 || conversions.size()>0)isConv_=true;
47 }
48 //This function does SuperCluster Pointing using Single Legs and Conversion pairs
49 //There is a bool that is flagged when it uses SLconv exclusively
50 std::pair<float,float> ggPFTracks::BeamLineInt(
52  vector<edm::RefToBase<reco::Track> > &Tracks,
54  vector<edm::RefToBase<reco::Track> > &SLTracks,
55  reco::ConversionRefVector &SLconversions
56  ){
57  std::pair<float,float> Zint(0,0);
58  TVector3 beamspot(beamSpotHandle_->position().x(),beamSpotHandle_->position().y(),
59  beamSpotHandle_->position().z());
60  TVector3 SCPos(sc->position().x()-beamspot[0], sc->position().y()-beamspot[1], sc->position().z()-beamspot[2]);
61  //find min Conversion radius for track pairs if they exist.
62  float convRMin=130;
63  float SLConvRMin=130;
64  int c_index=-1; int SLc_index=-1;
65  if(conversions.size()>0)
66  {
67  for(unsigned int c=0; c<conversions.size(); ++c){
68  float convR=sqrt(conversions[c]->conversionVertex().x()* conversions[c]->conversionVertex().x() + conversions[c]->conversionVertex().y()* conversions[c]->conversionVertex().y());
69  if(convRMin>convR){
70  convRMin=convR;
71  c_index=c;
72  }
73  }
74  }
75 
76  if(SLconversions.size()>0){
77  for(unsigned int SLc=0; SLc<SLconversions.size(); ++SLc){
78  std::vector<math::XYZPointF> innerPos=SLconversions[SLc]->tracksInnerPosition();
79  for (unsigned int t=0; t<innerPos.size(); t++){
80  float convR=sqrt( innerPos[t].X()* innerPos[t].X() + innerPos[t].Y()* innerPos[t].Y());
81 
82  if(SLConvRMin>convR){
83  SLc_index=SLc;
84  SLConvRMin=convR;
85 
86  }
87  }
88  }
89  }
90  TVector3 TkPos(beamspot[0],beamspot[1],beamspot[2]);
91  //take the smaller Radius:
92  if(convRMin<SLConvRMin && c_index>-1){
93  //point using Conversion Vertex
94  TkPos.SetXYZ(conversions[c_index]->conversionVertex().x()-beamspot[0],
95  conversions[c_index]->conversionVertex().y()-beamspot[1],
96  conversions[c_index]->conversionVertex().z()-beamspot[2] );
97  }
98  if(SLConvRMin<convRMin && SLc_index>-1){
99  reco::Vertex conv=SLconversions[SLc_index]->conversionVertex();
100  TkPos.SetXYZ(conv.x()-beamspot[0],
101  conv.y()-beamspot[1],
102  conv.z()-beamspot[2] );
103  }
104  //Intersection fromt the two points:
105  float R1=sqrt(SCPos.X()* SCPos.X() + SCPos.Y()*SCPos.Y());
106  float R2=sqrt(TkPos.X()* TkPos.X() + TkPos.Y()*TkPos.Y());
107  float Z1=SCPos.Z();
108  float Z2=TkPos.Z();
109  float slope=(Z1-Z2)/(R1-R2);
110  Zint.first=Z2 - R2*slope;
111  //determine error based on Tracking Region for conversion pairs:
112  float sigmaPix=0.06;
113  float sigmaTib=0.67;
114  float sigmaTob=2.04;
115  float sigmaFwd1=0.18;
116  float sigmaFwd2=0.61;
117  float sigmaFwd3=0.99;
118  //error of SL tracks of Conversion based on EB/EE and R>39 R<39 (4 cat)
119  float EBLR=0.24;
120  float EBHR=0.478;
121  float EELR=0.416;
122  float EEHR=0.888;
123  if(sc->eta()<1.4442){//Barrel
124  //if conversion
125  if(convRMin<SLConvRMin && c_index>-1){//3 tracking regions
126  if(convRMin<=15)Zint.second=sigmaPix;
127  else if(convRMin>15 && convRMin<=60)Zint.second=sigmaTib;
128  else Zint.second=sigmaTob;
129  }
130  //if SL
131  if(SLConvRMin<convRMin && SLc_index>-1){//2 tracking regions
132  if(SLConvRMin<39)Zint.second=EBLR;
133  else Zint.second=EBHR;
134  }
135  }
136  else{
137  //if conversion
138  if(convRMin<SLConvRMin && c_index>-1){//3 foreward tracking regions
139  float convz=conversions[c_index]->conversionVertex().z();
140  if(convz<=50)Zint.second=sigmaFwd1;
141  else if(convz>50 && convz<=60)Zint.second=sigmaFwd2;
142  else Zint.second=sigmaFwd3;
143  }
144  //if SL
145  if(SLConvRMin<convRMin && SLc_index>-1){//2 tracking regions based on R
146  if(SLConvRMin<39)Zint.second=EELR;
147  else Zint.second=EEHR;
148  }
149  }
150  return Zint;//return intersection at beamline and error in the pointing based on tracking region
151 }
152 //This Function does the track Projection (using innermost hit and inner momentum of the Single Track, NOTE: Can also use for GSF tracks
153 std::pair<float,float> ggPFTracks::TrackProj(
154  bool isEb,
155  reco::GsfTrackRef gsf,
156  vector<edm::RefToBase<reco::Track> > &SLTracks,
157  reco::ConversionRefVector &SLconversions
158  ){
159  std::pair<float,float> ZProj(0,0);
160 
161  if(gsf.isNonnull()){//if there is a gsf track then use this for track projection Plenty of inner hits
162  ZProj=gsfTrackProj(gsf);
163  return ZProj;
164  }
165 
166  float minR=210;
167  int SLind=-1;
168  if(SLconversions.size()>0){//find track with min Radius (starts earliest)
169  for(unsigned int SLc=0; SLc<SLconversions.size(); ++SLc){
170  reco::Vertex conv=SLconversions[SLc]->conversionVertex();
171  float convR=sqrt( conv.x() * conv.x() + conv.y() * conv.y());
172  if(convR<minR){
173  minR=convR;
174  SLind=SLc;
175  }
176  }
177  reco::Vertex conv=SLconversions[SLind]->conversionVertex();
178  const std::vector<edm::RefToBase<reco::Track> > tracks = SLconversions[SLind]->tracks();
179  float theta =tracks[0]->theta();
180  float tkz=conv.z();
181  float tkR=sqrt( conv.x() * conv.x() + conv.y() * conv.y());
182  float thetErr=tracks[0]->thetaError();
183  float Z=tkz-tkR/tan(theta);//track projection
184  float Zerr=((-1*(cos(theta)*cos(theta))/(sin(theta)* sin(theta))-1)*tkR*thetErr); //projection error based on theta err of track theta derivative of the Zproj
185  //for early tracks theta error is very small so just hard code an error
186  //that is measured by looking at the track Proj resolutin in MC
187  if(tkR<39 && isEb)Zerr=0.234;
188  if(tkR<39 && !isEb)Zerr=0.341;
189  ZProj.first=Z; ZProj.second=Zerr;
190  return ZProj;
191  }
192  return ZProj;
193 }
194 
195 //this function combines the results from the Track Projection and SC pointing
196 //can also use conversion pairs and gsf tracks, even when there is no Single leg
197 std::pair<float,float> ggPFTracks::gsfTrackProj(
199  ){
200  //if there is a gsf track then use this for track projection Plenty of inner hits
201 
202  float theta =gsf->innerMomentum().theta();
203 
204  float tkz=gsf->innerPosition().Z();
205  float tkR=sqrt(gsf->innerPosition().X()* gsf->innerPosition().X()+ gsf->innerPosition().Y()* gsf->innerPosition().Y());
206  float thetErr=gsf->thetaError();
207  float Z=tkz-tkR/tan(theta);
208  float Zerr=((-1*(cos(theta)*cos(theta))/(sin(theta)* sin(theta))-1)*tkR*thetErr);
209  std::pair<float,float> ZProj(0,0);
210  ZProj.first=Z; ZProj.second=Zerr;
211  return ZProj;
212 
213 }
214 
215 std::pair<float,float> ggPFTracks::gsfElectronProj(
217  ){
218  //if there is a gsf electron then use this for track projection Plenty of inner hits
219 
220  float theta =gsf.trackMomentumAtVtx().theta();
221 
222  float tkz=gsf.trackPositionAtVtx().Z();
223  float tkR=sqrt(gsf.trackPositionAtVtx().X()* gsf.trackPositionAtVtx().X()+ gsf.trackPositionAtVtx().Y()* gsf.trackPositionAtVtx().Y());
224  float thetErr=gsf.gsfTrack()->thetaError();
225  float Z=tkz-tkR/tan(theta);
226  float Zerr=((-1*(cos(theta)*cos(theta))/(sin(theta)* sin(theta))-1)*tkR*thetErr);
227  std::pair<float,float> ZProj(0,0);
228  ZProj.first=Z; ZProj.second=Zerr;
229  return ZProj;
230 
231 }
232 
233 std::pair<float,float> ggPFTracks::CombZVtx(
235  reco::GsfTrackRef gsf,
236  vector<edm::RefToBase<reco::Track> > &Tracks,
238  vector<edm::RefToBase<reco::Track> > &SLTracks,
239  reco::ConversionRefVector &SLconversions
240 
241  ){
242  std::pair<float, float> combZ(0,0);
243  bool isEb;
244  TVector3 beamspot(beamSpotHandle_->position().x(),beamSpotHandle_->position().y(),
245  beamSpotHandle_->position().z());
246  if(fabs(sc->eta())<1.4442)isEb=true;
247  else isEb=false;
248  std::pair< float,float> SCZ=BeamLineInt(sc, Tracks, conversions,SLTracks, SLconversions);
249  std::pair<float, float> TkPjZ=TrackProj(isEb,gsf,SLTracks, SLconversions);
250  //errors in the two methods
251  float sigZProj=TkPjZ.second;
252  float sigSCPoint=SCZ.second;
253 
254  if(gsf.isNonnull()){combZ=TkPjZ; return combZ;}//for gsf Tracks just return track Proj
255  //weighted avg of the two methods, where weights are based on the error
256  float Z=((SCZ.first/(sigSCPoint*sigSCPoint))+ (TkPjZ.first/( sigZProj* sigZProj)))/(1/(sigSCPoint * sigSCPoint)+ 1/(sigZProj * sigZProj));
257  //total error sum of the two errors in quadrature
258  float sigZ=sqrt((sigSCPoint * sigSCPoint)+ (sigZProj * sigZProj));
259  combZ.first=Z; combZ.second=sigZ;
260  return combZ;
261 }
262 //this function combines the results from the Track Projection and SC pointing
263 //simpler version of the above function, but returns bspot Z when there is no SL
264 std::pair<float, float> ggPFTracks::SLCombZVtx(
265  reco::Photon phot,
266  bool &hasSL
267  ){
268  std::pair<float, float> combZ(0,0);
269  TVector3 beamspot(beamSpotHandle_->position().x(),beamSpotHandle_->position().y(),
270  beamSpotHandle_->position().z());
271  bool isEb=phot.isEB();
272  //only want to use SL so the conversion pair variables will be dummy for the get function
273  vector<edm::RefToBase<reco::Track> >convTracks;
274  reco::ConversionRefVector pairConv;
275 
276  reco::ConversionRefVector SLConversions;
277  vector<edm::RefToBase<reco::Track> >SLTracks;
278  reco::GsfTrackRef gsfdummy;
279  getPFConvTracks(phot,convTracks,pairConv ,SLTracks,SLConversions);
280 
281  if(SLConversions.size()>0){
282  hasSL=true;
283  vector<edm::RefToBase<reco::Track> >dummy;
284  reco::ConversionRefVector pairdummy;
285  std::pair<float, float> TkPjZ=TrackProj(isEb,gsfdummy,SLTracks, SLConversions);
286  std::pair< float,float> SCZ=BeamLineInt(phot.superCluster(), dummy,pairdummy,SLTracks, SLConversions);
287  //errors in the two methods
288  float sigZProj=TkPjZ.second;
289  float sigSCPoint=SCZ.second;
290  //weighted avg of the two methods, where weights are based on the error
291  float Z=((SCZ.first/(sigSCPoint*sigSCPoint))+ (TkPjZ.first/(sigZProj * sigZProj)))/(1/(sigSCPoint*sigSCPoint)+ 1/(sigZProj * sigZProj));
292  //total error sum of the two errors in quadrature
293  float sigZ=sqrt((sigSCPoint*sigSCPoint)+ (sigZProj * sigZProj));
294  combZ.first=Z; combZ.second=sigZ;
295  }
296  else if(pairConv.size()>0){//else use Conversion pairs if available
297  std::pair< float,float> SCZ=BeamLineInt(phot.superCluster(),convTracks, pairConv, SLTracks, SLConversions);
298  combZ.first=SCZ.first;
299  combZ.second=SCZ.second;
300  hasSL=false;
301  }
302  else{//returns beamspot
303  combZ.first=beamspot.Z();
304  combZ.second=0;
305  hasSL=false;
306  }
307  return combZ;
308 }
const double Z[kNumberCalorimeter]
Handle< BeamSpot > beamSpotHandle_
Definition: ggPFTracks.h:65
tuple convTracks
Definition: convBrem_cff.py:35
virtual void getPFConvTracks(reco::Photon phot, vector< edm::RefToBase< reco::Track > > &Tracks, reco::ConversionRefVector &conversions, vector< edm::RefToBase< reco::Track > > &SLTracks, reco::ConversionRefVector &SLconversions)
Definition: ggPFTracks.cc:16
static HepMC::IO_HEPEVT conv
reco::ConversionRefVector conversionsOneLeg() const
vector of references to one leg Conversion&#39;s
Definition: Photon.h:68
double y() const
y coordinate
Definition: Vertex.h:97
static const double slope[3]
math::XYZVectorF trackMomentumAtVtx() const
Definition: GsfElectron.h:272
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Geom::Theta< T > theta() const
#define X(str)
Definition: MuonsGrabber.cc:49
virtual ~ggPFTracks()
Definition: ggPFTracks.cc:14
reco::SuperClusterRef superCluster() const
Ref to SuperCluster.
Definition: Photon.cc:59
std::pair< float, float > SLCombZVtx(reco::Photon phot, bool &hasSL)
Definition: ggPFTracks.cc:264
std::pair< float, float > BeamLineInt(reco::SuperClusterRef sc, vector< edm::RefToBase< reco::Track > > &Tracks, reco::ConversionRefVector &conversions, vector< edm::RefToBase< reco::Track > > &SLTracks, reco::ConversionRefVector &SLconversions)
Definition: ggPFTracks.cc:50
double double double z
ggPFTracks(edm::Handle< BeamSpot > &beamSpotHandle)
Definition: ggPFTracks.cc:5
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:250
reco::ConversionRefVector conversions() const
vector of references to Conversion&#39;s
Definition: Photon.h:62
std::pair< float, float > CombZVtx(reco::SuperClusterRef sc, reco::GsfTrackRef gsf, vector< edm::RefToBase< reco::Track > > &Tracks, reco::ConversionRefVector &conversions, vector< edm::RefToBase< reco::Track > > &SLTracks, reco::ConversionRefVector &SLconversions)
Definition: ggPFTracks.cc:233
T sqrt(T t)
Definition: SSEVec.h:46
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
double z() const
y coordinate
Definition: Vertex.h:99
std::pair< float, float > gsfTrackProj(reco::GsfTrackRef gsf)
Definition: ggPFTracks.cc:197
std::pair< float, float > gsfElectronProj(reco::GsfElectron gsf)
Definition: ggPFTracks.cc:215
double x() const
x coordinate
Definition: Vertex.h:95
void clear()
Clear the vector.
Definition: RefVector.h:133
tuple tracks
Definition: testEve_cfg.py:39
std::pair< float, float > TrackProj(bool isEb, reco::GsfTrackRef gsf, vector< edm::RefToBase< reco::Track > > &SLTracks, reco::ConversionRefVector &SLconversions)
Definition: ggPFTracks.cc:153
bool isConv_
Definition: ggPFTracks.h:66
bool isEB() const
Definition: Photon.h:118
math::XYZPointF trackPositionAtVtx() const
Definition: GsfElectron.h:270
void push_back(value_type const &ref)
Add a Ref&lt;C, T&gt; to the RefVector.
Definition: RefVector.h:64
size_type size() const
Size of the RefVector.
Definition: RefVector.h:89
Definition: DDAxes.h:10
virtual GsfTrackRef gsfTrack() const
reference to a GsfTrack
Definition: GsfElectron.h:169