CMS 3D CMS Logo

TauElementsOperators.cc
Go to the documentation of this file.
2 
3 using namespace reco;
4 using std::string;
5 
6 TauElementsOperators::TauElementsOperators(BaseTau& theBaseTau) : BaseTau_(theBaseTau),AreaMetric_recoElements_maxabsEta_(2.5){
7  IsolTracks_=theBaseTau.isolationTracks();
8 }
9 
10 double TauElementsOperators::computeConeSize(const TFormula& ConeSizeTFormula,double ConeSizeMin,double ConeSizeMax){
11  double x=BaseTau_.energy();
12  double y=BaseTau_.et();
13  double ConeSize=ConeSizeTFormula.Eval(x,y);
14  if (ConeSize<ConeSizeMin)ConeSize=ConeSizeMin;
15  if (ConeSize>ConeSizeMax)ConeSize=ConeSizeMax;
16  return ConeSize;
17 }
18 
19 double TauElementsOperators::computeConeSize(const TFormula& ConeSizeTFormula,double ConeSizeMin,double ConeSizeMax, double transverseEnergy, double energy, double jetOpeningAngle){
20  double ConeSize=ConeSizeTFormula.Eval(energy, transverseEnergy, jetOpeningAngle);
21  if (ConeSize<ConeSizeMin)ConeSize=ConeSizeMin;
22  if (ConeSize>ConeSizeMax)ConeSize=ConeSizeMax;
23  return ConeSize;
24 }
25 
26 /*
27  * DEPRECATED????
28 TFormula TauElementsOperators::computeConeSizeTFormula(const string& ConeSizeFormula,const char* errorMessage){
29  //--- check functional form
30  // given as configuration parameter for matching and signal cone sizes;
31  //
32  // The size of a cone may depend on the energy "E" and/or transverse energy "ET" of the tau-jet candidate.
33  // Any functional form that is supported by ROOT's TFormula class can be used (e.g. "3.0/E", "0.25/sqrt(ET)")
34  //
35  // replace "E" by TFormula variable "x"
36  // "ET" "y"
37  string ConeSizeFormulaStr = ConeSizeFormula;
38  replaceSubStr(ConeSizeFormulaStr,"ET","y");
39  replaceSubStr(ConeSizeFormulaStr,"E","x");
40  ConeSizeTFormula.SetName("ConeSize");
41  ConeSizeTFormula.SetTitle(ConeSizeFormulaStr.data()); // the function definition is actually stored in the "Title" data-member of the TFormula object
42  int errorFlag = ConeSizeTFormula.Compile();
43  if (errorFlag!= 0) {
44  throw cms::Exception("") << "\n unsupported functional Form for " << errorMessage << " " << ConeSizeFormula << endl
45  << "Please check that the Definition in \"" << ConeSizeTFormula.GetName() << "\" only contains the variables \"E\" or \"ET\""
46  << " and Functions that are supported by ROOT's TFormular Class." << endl;
47  }else return ConeSizeTFormula;
48 }
49 */
50 
51 
52 
53 void TauElementsOperators::replaceSubStr(string& s,const string& oldSubStr,const string& newSubStr){
54  //--- protect replacement algorithm
55  // from case that oldSubStr and newSubStr are equal
56  // (nothing to be done anyway)
57  if ( oldSubStr == newSubStr ) return;
58 
59  //--- protect replacement algorithm
60  // from case that oldSubStr contains no characters
61  // (i.e. matches everything)
62  if ( oldSubStr.empty() ) return;
63 
64  const string::size_type lengthOldSubStr = oldSubStr.size();
65  const string::size_type lengthNewSubStr = newSubStr.size();
66 
67  string::size_type positionPreviousMatch = 0;
68  string::size_type positionNextMatch = 0;
69 
70  //--- consecutively replace all occurences of oldSubStr by newSubStr;
71  // keep iterating until no occurence of oldSubStr left
72  while ( (positionNextMatch = s.find(oldSubStr, positionPreviousMatch)) != string::npos ) {
73  s.replace(positionNextMatch, lengthOldSubStr, newSubStr);
74  positionPreviousMatch = positionNextMatch + lengthNewSubStr;
75  }
76 }
77 
78 const TrackRefVector TauElementsOperators::tracksInCone(const math::XYZVector& coneAxis,const string coneMetric,const double coneSize,const double ptTrackMin) const{
79  TrackRefVector theFilteredTracks;
80  for (TrackRefVector::const_iterator iTrack=Tracks_.begin();iTrack!=Tracks_.end();++iTrack) {
81  if ((**iTrack).pt()>ptTrackMin)theFilteredTracks.push_back(*iTrack);
82  }
83  TrackRefVector theFilteredTracksInCone;
84  if (coneMetric=="DR"){
85  theFilteredTracksInCone=TracksinCone_DRmetric_(coneAxis,metricDR_,coneSize,theFilteredTracks);
86  }else if(coneMetric=="angle"){
87  theFilteredTracksInCone=TracksinCone_Anglemetric_(coneAxis,metricAngle_,coneSize,theFilteredTracks);
88  }else if(coneMetric=="area"){
89  int errorFlag = 0;
90  FixedAreaIsolationCone fixedAreaCone;
92  double coneAngle=fixedAreaCone(coneAxis.theta(),coneAxis.phi(),0,coneSize,errorFlag);
93  if (errorFlag!=0) return TrackRefVector();
94  theFilteredTracksInCone=TracksinCone_Anglemetric_(coneAxis,metricAngle_,coneAngle,theFilteredTracks);
95  }else return TrackRefVector();
96  return theFilteredTracksInCone;
97 }
98 const TrackRefVector TauElementsOperators::tracksInCone(const math::XYZVector& coneAxis,const string coneMetric,const double coneSize,const double ptTrackMin,const double tracktorefpoint_maxDZ,const double refpoint_Z, const Vertex &myPV) const{
99  TrackRefVector theFilteredTracks;
100  for (TrackRefVector::const_iterator iTrack=Tracks_.begin();iTrack!=Tracks_.end();++iTrack) {
101  if ((**iTrack).pt()>ptTrackMin && fabs((**iTrack).dz(myPV.position())-refpoint_Z)<=tracktorefpoint_maxDZ)theFilteredTracks.push_back(*iTrack);
102  }
103  TrackRefVector theFilteredTracksInCone;
104  if (coneMetric=="DR"){
105  theFilteredTracksInCone=TracksinCone_DRmetric_(coneAxis,metricDR_,coneSize,theFilteredTracks);
106  }else if(coneMetric=="angle"){
107  theFilteredTracksInCone=TracksinCone_Anglemetric_(coneAxis,metricAngle_,coneSize,theFilteredTracks);
108  }else if(coneMetric=="area"){
109  int errorFlag = 0;
110  FixedAreaIsolationCone fixedAreaCone;
112  double coneAngle=fixedAreaCone(coneAxis.theta(),coneAxis.phi(),0,coneSize,errorFlag);
113  if (errorFlag!=0) return TrackRefVector();
114  theFilteredTracksInCone=TracksinCone_Anglemetric_(coneAxis,metricAngle_,coneAngle,theFilteredTracks);
115  }else return TrackRefVector();
116  return theFilteredTracksInCone;
117 }
118 const TrackRefVector TauElementsOperators::tracksInAnnulus(const math::XYZVector& myVector,const string innercone_metric,const double innercone_size,const string outercone_metric,const double outercone_size,const double minPt)const{
119  TrackRefVector theFilteredTracks;
120  for (TrackRefVector::const_iterator iTrack=Tracks_.begin();iTrack!=Tracks_.end();++iTrack) {
121  if ((**iTrack).pt()>minPt)theFilteredTracks.push_back(*iTrack);
122  }
123  TrackRefVector theFilteredTracksInAnnulus;
124  if (outercone_metric=="DR"){
125  if (innercone_metric=="DR"){
126  theFilteredTracksInAnnulus=TracksinAnnulus_innerDRouterDRmetrics_(myVector,metricDR_,innercone_size,metricDR_,outercone_size,theFilteredTracks);
127  }else if(innercone_metric=="angle"){
128  theFilteredTracksInAnnulus=TracksinAnnulus_innerAngleouterDRmetrics_(myVector,metricAngle_,innercone_size,metricDR_,outercone_size,theFilteredTracks);
129  }else if(innercone_metric=="area"){
130  int errorFlag=0;
131  FixedAreaIsolationCone theFixedAreaSignalCone;
133  double innercone_angle=theFixedAreaSignalCone(myVector.theta(),myVector.phi(),0,innercone_size,errorFlag);
134  if (errorFlag!=0)return TrackRefVector();
135  theFilteredTracksInAnnulus=TracksinAnnulus_innerAngleouterDRmetrics_(myVector,metricAngle_,innercone_angle,metricDR_,outercone_size,theFilteredTracks);
136  }else return TrackRefVector();
137  }else if(outercone_metric=="angle"){
138  if (innercone_metric=="DR"){
139  theFilteredTracksInAnnulus=TracksinAnnulus_innerDRouterAnglemetrics_(myVector,metricDR_,innercone_size,metricAngle_,outercone_size,theFilteredTracks);
140  }else if(innercone_metric=="angle"){
141  theFilteredTracksInAnnulus=TracksinAnnulus_innerAngleouterAnglemetrics_(myVector,metricAngle_,innercone_size,metricAngle_,outercone_size,theFilteredTracks);
142  }else if(innercone_metric=="area"){
143  int errorFlag=0;
144  FixedAreaIsolationCone theFixedAreaSignalCone;
146  double innercone_angle=theFixedAreaSignalCone(myVector.theta(),myVector.phi(),0,innercone_size,errorFlag);
147  if (errorFlag!=0)return theFilteredTracksInAnnulus;
148  theFilteredTracksInAnnulus=TracksinAnnulus_innerAngleouterAnglemetrics_(myVector,metricAngle_,innercone_angle,metricAngle_,outercone_size,theFilteredTracks);
149  }else return TrackRefVector();
150  }else if(outercone_metric=="area"){
151  int errorFlag=0;
152  FixedAreaIsolationCone theFixedAreaSignalCone;
154  if (innercone_metric=="DR"){
155  // not implemented yet
156  }else if(innercone_metric=="angle"){
157  double outercone_angle=theFixedAreaSignalCone(myVector.theta(),myVector.phi(),innercone_size,outercone_size,errorFlag);
158  if (errorFlag!=0)return theFilteredTracksInAnnulus;
159  theFilteredTracksInAnnulus=TracksinAnnulus_innerAngleouterAnglemetrics_(myVector,metricAngle_,innercone_size,metricAngle_,outercone_angle,theFilteredTracks);
160  }else if(innercone_metric=="area"){
161  double innercone_angle=theFixedAreaSignalCone(myVector.theta(),myVector.phi(),0,innercone_size,errorFlag);
162  if (errorFlag!=0)return theFilteredTracksInAnnulus;
163  double outercone_angle=theFixedAreaSignalCone(myVector.theta(),myVector.phi(),innercone_angle,outercone_size,errorFlag);
164  if (errorFlag!=0)return theFilteredTracksInAnnulus;
165  theFilteredTracksInAnnulus=TracksinAnnulus_innerAngleouterAnglemetrics_(myVector,metricAngle_,innercone_angle,metricAngle_,outercone_angle,theFilteredTracks);
166  }else return TrackRefVector();
167  }
168  return theFilteredTracksInAnnulus;
169 }
170 const TrackRefVector TauElementsOperators::tracksInAnnulus(const math::XYZVector& myVector,const string innercone_metric,const double innercone_size,const string outercone_metric,const double outercone_size,const double minPt,const double tracktorefpoint_maxDZ,const double refpoint_Z, const Vertex &myPV)const{
171  TrackRefVector theFilteredTracks;
172  for (TrackRefVector::const_iterator iTrack=Tracks_.begin();iTrack!=Tracks_.end();++iTrack) {
173  if ((**iTrack).pt()>minPt && fabs((**iTrack).dz(myPV.position())-refpoint_Z)<=tracktorefpoint_maxDZ)theFilteredTracks.push_back(*iTrack);
174  }
175  TrackRefVector theFilteredTracksInAnnulus;
176  if (outercone_metric=="DR"){
177  if (innercone_metric=="DR"){
178  theFilteredTracksInAnnulus=TracksinAnnulus_innerDRouterDRmetrics_(myVector,metricDR_,innercone_size,metricDR_,outercone_size,theFilteredTracks);
179  }else if(innercone_metric=="angle"){
180  theFilteredTracksInAnnulus=TracksinAnnulus_innerAngleouterDRmetrics_(myVector,metricAngle_,innercone_size,metricDR_,outercone_size,theFilteredTracks);
181  }else if(innercone_metric=="area"){
182  int errorFlag=0;
183  FixedAreaIsolationCone theFixedAreaSignalCone;
185  double innercone_angle=theFixedAreaSignalCone(myVector.theta(),myVector.phi(),0,innercone_size,errorFlag);
186  if (errorFlag!=0)return TrackRefVector();
187  theFilteredTracksInAnnulus=TracksinAnnulus_innerAngleouterDRmetrics_(myVector,metricAngle_,innercone_angle,metricDR_,outercone_size,theFilteredTracks);
188  }else return TrackRefVector();
189  }else if(outercone_metric=="angle"){
190  if (innercone_metric=="DR"){
191  theFilteredTracksInAnnulus=TracksinAnnulus_innerDRouterAnglemetrics_(myVector,metricDR_,innercone_size,metricAngle_,outercone_size,theFilteredTracks);
192  }else if(innercone_metric=="angle"){
193  theFilteredTracksInAnnulus=TracksinAnnulus_innerAngleouterAnglemetrics_(myVector,metricAngle_,innercone_size,metricAngle_,outercone_size,theFilteredTracks);
194  }else if(innercone_metric=="area"){
195  int errorFlag=0;
196  FixedAreaIsolationCone theFixedAreaSignalCone;
198  double innercone_angle=theFixedAreaSignalCone(myVector.theta(),myVector.phi(),0,innercone_size,errorFlag);
199  if (errorFlag!=0)return theFilteredTracksInAnnulus;
200  theFilteredTracksInAnnulus=TracksinAnnulus_innerAngleouterAnglemetrics_(myVector,metricAngle_,innercone_angle,metricAngle_,outercone_size,theFilteredTracks);
201  }else return TrackRefVector();
202  }else if(outercone_metric=="area"){
203  int errorFlag=0;
204  FixedAreaIsolationCone theFixedAreaSignalCone;
206  if (innercone_metric=="DR"){
207  // not implemented yet
208  }else if(innercone_metric=="angle"){
209  double outercone_angle=theFixedAreaSignalCone(myVector.theta(),myVector.phi(),innercone_size,outercone_size,errorFlag);
210  if (errorFlag!=0)return theFilteredTracksInAnnulus;
211  theFilteredTracksInAnnulus=TracksinAnnulus_innerAngleouterAnglemetrics_(myVector,metricAngle_,innercone_size,metricAngle_,outercone_angle,theFilteredTracks);
212  }else if(innercone_metric=="area"){
213  double innercone_angle=theFixedAreaSignalCone(myVector.theta(),myVector.phi(),0,innercone_size,errorFlag);
214  if (errorFlag!=0)return theFilteredTracksInAnnulus;
215  double outercone_angle=theFixedAreaSignalCone(myVector.theta(),myVector.phi(),innercone_angle,outercone_size,errorFlag);
216  if (errorFlag!=0)return theFilteredTracksInAnnulus;
217  theFilteredTracksInAnnulus=TracksinAnnulus_innerAngleouterAnglemetrics_(myVector,metricAngle_,innercone_angle,metricAngle_,outercone_angle,theFilteredTracks);
218  }else return TrackRefVector();
219  }
220  return theFilteredTracksInAnnulus;
221 }
222 
223 const TrackRef TauElementsOperators::leadTk(string matchingConeMetric,double matchingConeSize,double ptTrackMin)const{
224  return leadTk(BaseTau_.momentum(),matchingConeMetric,matchingConeSize,ptTrackMin);
225 }
226 
227 const TrackRef TauElementsOperators::leadTk(const math::XYZVector& jetAxis,string matchingConeMetric,double matchingConeSize,double ptTrackMin)const{
228  const TrackRefVector matchingConeTracks=tracksInCone(jetAxis,matchingConeMetric,matchingConeSize,ptTrackMin);
229  if ((int)matchingConeTracks.size()==0) return TrackRef();
230  TrackRef leadingTrack;
231  double leadingTrackPt=0.;
232  for (TrackRefVector::const_iterator track=matchingConeTracks.begin();track!=matchingConeTracks.end();++track) {
233  if ((*track)->pt()>ptTrackMin && (*track)->pt()>leadingTrackPt){
234  leadingTrack=(*track);
235  leadingTrackPt=leadingTrack->pt();
236  }
237  }
238  return leadingTrack;
239 }
240 // ***
241 double TauElementsOperators::discriminatorByIsolTracksN(unsigned int isolationAnnulus_Tracksmaxn)const{
242  if ((unsigned int)IsolTracks_.size()>isolationAnnulus_Tracksmaxn)return 0.;
243  else return 1.;
244 }
246  string matchingConeMetric,double matchingConeSize,double ptLeadingTrackMin,double ptOtherTracksMin,
247  string signalConeMetric,double signalConeSize,string isolationConeMetric,double isolationConeSize,
248  unsigned int isolationAnnulus_Tracksmaxn)const{
249  const TrackRef leadingTrack=leadTk(jetAxis,matchingConeMetric,matchingConeSize,ptLeadingTrackMin);
250  if(!leadingTrack)return 0.;
251  math::XYZVector coneAxis=leadingTrack->momentum();
252  TrackRefVector isolationAnnulusTracks=tracksInAnnulus(coneAxis,signalConeMetric,signalConeSize,isolationConeMetric,isolationConeSize,ptOtherTracksMin);
253  if ((unsigned int)isolationAnnulusTracks.size()>isolationAnnulus_Tracksmaxn)return 0.;
254  else return 1.;
255 }
256 double TauElementsOperators::discriminatorByIsolTracksN(string matchingConeMetric,double matchingConeSize,double ptLeadingTrackMin,double ptOtherTracksMin,
257  string signalConeMetric,double signalConeSize,string isolationConeMetric,double isolationConeSize,
258  unsigned int isolationAnnulus_Tracksmaxn)const{
259  return discriminatorByIsolTracksN(BaseTau_.momentum(),matchingConeMetric,matchingConeSize,ptLeadingTrackMin,ptOtherTracksMin,signalConeMetric,signalConeSize,isolationConeMetric,isolationConeSize,isolationAnnulus_Tracksmaxn);
260 }
double computeConeSize(const TFormula &ConeSizeTFormula, double ConeSizeMin, double ConeSizeMax)
ElementsInAnnulusRef< math::XYZVector, Angle< math::XYZVector >, DeltaR< math::XYZVector >, reco::TrackCollection > TracksinAnnulus_innerAngleouterDRmetrics_
virtual const reco::TrackRefVector & isolationTracks() const
Definition: BaseTau.cc:30
const reco::TrackRef leadTk(std::string matchingConeMetric, double matchingConeSize, double ptTrackMin) const
ElementsInAnnulusRef< math::XYZVector, DeltaR< math::XYZVector >, DeltaR< math::XYZVector >, reco::TrackCollection > TracksinAnnulus_innerDRouterDRmetrics_
double discriminatorByIsolTracksN(unsigned int isolationAnnulus_Tracksmaxn) const
const_iterator end() const
Termination of iteration.
Definition: RefVector.h:253
DeltaR< math::XYZVector > metricDR_
edm::RefVector< TrackCollection > TrackRefVector
vector of reference to Track in the same collection
Definition: TrackFwd.h:30
uint16_t size_type
const Point & position() const
position
Definition: Vertex.h:109
const_iterator begin() const
Initialize an iterator over the RefVector.
Definition: RefVector.h:248
Vector momentum() const final
spatial momentum vector
const reco::TrackRefVector tracksInCone(const math::XYZVector &coneAxis, const std::string coneMetric, const double coneSize, const double ptTrackMin) const
ElementsInAnnulusRef< math::XYZVector, DeltaR< math::XYZVector >, Angle< math::XYZVector >, reco::TrackCollection > TracksinAnnulus_innerDRouterAnglemetrics_
reco::TrackRefVector IsolTracks_
double et() const final
transverse energy
ElementsInConeRef< math::XYZVector, DeltaR< math::XYZVector >, reco::TrackCollection > TracksinCone_DRmetric_
ElementsInAnnulusRef< math::XYZVector, Angle< math::XYZVector >, Angle< math::XYZVector >, reco::TrackCollection > TracksinAnnulus_innerAngleouterAnglemetrics_
double energy() const final
energy
void setAcceptanceLimit(double etaMaxTrackingAcceptance)
reco::TrackRefVector Tracks_
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:30
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:21
fixed size matrix
Angle< math::XYZVector > metricAngle_
void push_back(value_type const &ref)
Add a Ref<C, T> to the RefVector.
Definition: RefVector.h:69
size_type size() const
Size of the RefVector.
Definition: RefVector.h:107
ElementsInConeRef< math::XYZVector, Angle< math::XYZVector >, reco::TrackCollection > TracksinCone_Anglemetric_
void replaceSubStr(std::string &s, const std::string &oldSubStr, const std::string &newSubStr)
const reco::TrackRefVector tracksInAnnulus(const math::XYZVector &coneAxis, const std::string innerconeMetric, const double innerconeSize, const std::string outerconeMetric, const double outerconeSize, const double ptTrackMin) const