CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CaloRecoTauTagInfoAlgorithm.cc
Go to the documentation of this file.
3 
4 using namespace reco;
5 
7  // parameters of the considered rec. Tracks (catched through a JetTracksAssociation object) :
8  tkminPt_ = parameters.getParameter<double>("tkminPt");
9  tkminPixelHitsn_ = parameters.getParameter<int>("tkminPixelHitsn");
10  tkminTrackerHitsn_ = parameters.getParameter<int>("tkminTrackerHitsn");
11  tkmaxipt_ = parameters.getParameter<double>("tkmaxipt");
12  tkmaxChi2_ = parameters.getParameter<double>("tkmaxChi2");
13  //
14  UsePVconstraint_ = parameters.getParameter<bool>("UsePVconstraint");
15  tkPVmaxDZ_ = parameters.getParameter<double>("tkPVmaxDZ");
16  //
17  UseTrackQuality_ = parameters.getParameter<bool>("UseTrackQuality");
18  if (UseTrackQuality_) {
19  tkQuality_ = reco::TrackBase::qualityByName(parameters.getParameter<std::string>("tkQuality"));
20  }
21  // parameters of the considered EcalRecHits
22  BarrelBasicClusters_ = parameters.getParameter<edm::InputTag>("BarrelBasicClustersSource");
23  EndcapBasicClusters_ = parameters.getParameter<edm::InputTag>("EndcapBasicClustersSource");
24  // parameters of the considered neutral ECAL BasicClusters
25  ECALBasicClustersAroundCaloJet_DRConeSize_ = parameters.getParameter<double>("ECALBasicClustersAroundCaloJet_DRConeSize");
26  ECALBasicClusterminE_ = parameters.getParameter<double>("ECALBasicClusterminE");
27  ECALBasicClusterpropagTrack_matchingDRConeSize_ = parameters.getParameter<double>("ECALBasicClusterpropagTrack_matchingDRConeSize");
28 }
29 
30 CaloTauTagInfo CaloRecoTauTagInfoAlgorithm::buildCaloTauTagInfo(edm::Event& theEvent,const edm::EventSetup& theEventSetup,const CaloJetRef& theCaloJet,const TrackRefVector& theTracks,const Vertex& thePV){
31  CaloTauTagInfo resultExtended;
32  resultExtended.setcalojetRef(theCaloJet);
33 
34  TrackRefVector theFilteredTracks;
35  if (UsePVconstraint_) theFilteredTracks=TauTagTools::filteredTracks(theTracks,tkminPt_,tkminPixelHitsn_,tkminTrackerHitsn_,tkmaxipt_,tkmaxChi2_,tkPVmaxDZ_,thePV, thePV.z());
36  else theFilteredTracks=TauTagTools::filteredTracks(theTracks,tkminPt_,tkminPixelHitsn_,tkminTrackerHitsn_,tkmaxipt_,tkmaxChi2_,thePV);
37  if (UseTrackQuality_) theFilteredTracks = filterTracksByQualityBit(theFilteredTracks,tkQuality_);
38  resultExtended.setTracks(theFilteredTracks);
39 
40  //resultExtended.setpositionAndEnergyECALRecHits(getPositionAndEnergyEcalRecHits(theEvent,theEventSetup,theCaloJet));
41 
42  std::vector<BasicClusterRef> theNeutralEcalBasicClusters=getNeutralEcalBasicClusters(theEvent,theEventSetup,theCaloJet,theFilteredTracks,ECALBasicClustersAroundCaloJet_DRConeSize_,ECALBasicClusterminE_,ECALBasicClusterpropagTrack_matchingDRConeSize_);
43  resultExtended.setneutralECALBasicClusters(theNeutralEcalBasicClusters);
44 
45  return resultExtended;
46 }
47 CaloTauTagInfo CaloRecoTauTagInfoAlgorithm::buildCaloTauTagInfo(edm::Event& theEvent,const edm::EventSetup& theEventSetup,const JetBaseRef& theJet,const TrackRefVector& theTracks,const Vertex& thePV){
48  CaloTauTagInfo resultExtended;
49  resultExtended.setJetRef(theJet);
50 
51  TrackRefVector theFilteredTracks;
52  if (UsePVconstraint_) theFilteredTracks=TauTagTools::filteredTracks(theTracks,tkminPt_,tkminPixelHitsn_,tkminTrackerHitsn_,tkmaxipt_,tkmaxChi2_,tkPVmaxDZ_,thePV, thePV.z());
53  else theFilteredTracks=TauTagTools::filteredTracks(theTracks,tkminPt_,tkminPixelHitsn_,tkminTrackerHitsn_,tkmaxipt_,tkmaxChi2_,thePV);
54  if (UseTrackQuality_) theFilteredTracks = filterTracksByQualityBit(theFilteredTracks,tkQuality_);
55  resultExtended.setTracks(theFilteredTracks);
56 
57  //resultExtended.setpositionAndEnergyECALRecHits(getPositionAndEnergyEcalRecHits(theEvent,theEventSetup,theCaloJet));
58 
59  //reco::JPTJetRef const theJPTJetRef = theJet.castTo<reco::JPTJetRef>();
60  //reco::CaloJetRef const theCaloJet = (theJPTJetRef->getCaloJetRef()).castTo<reco::CaloJetRef>();
61  reco::CaloJetRef const theCaloJet = resultExtended.calojetRef();
62  std::vector<BasicClusterRef> theNeutralEcalBasicClusters=getNeutralEcalBasicClusters(theEvent,theEventSetup,theCaloJet,theFilteredTracks,ECALBasicClustersAroundCaloJet_DRConeSize_,ECALBasicClusterminE_,ECALBasicClusterpropagTrack_matchingDRConeSize_);
63  resultExtended.setneutralECALBasicClusters(theNeutralEcalBasicClusters);
64 
65  return resultExtended;
66 }
67 /*
68 std::vector<std::pair<math::XYZPoint,float> > CaloRecoTauTagInfoAlgorithm::getPositionAndEnergyEcalRecHits(edm::Event& theEvent,const edm::EventSetup& theEventSetup,const CaloJetRef& theCaloJet){
69  std::vector<std::pair<math::XYZPoint,float> > thePositionAndEnergyEcalRecHits;
70  std::vector<CaloTowerPtr> theCaloTowers=theCaloJet->getCaloConstituents();
71  ESHandle<CaloGeometry> theCaloGeometry;
72  theEventSetup.get<CaloGeometryRecord>().get(theCaloGeometry);
73  const CaloSubdetectorGeometry* theCaloSubdetectorGeometry;
74  edm::Handle<EBRecHitCollection> EBRecHits;
75  edm::Handle<EERecHitCollection> EERecHits;
76  edm::Handle<ESRecHitCollection> ESRecHits;
77  theEvent.getByLabel(EBRecHitsLabel_,EBRecHits);
78  theEvent.getByLabel(EERecHitsLabel_,EERecHits);
79  theEvent.getByLabel(ESRecHitsLabel_,ESRecHits);
80  for(std::vector<CaloTowerPtr>::const_iterator i_Tower=theCaloTowers.begin();i_Tower!=theCaloTowers.end();i_Tower++){
81  size_t numRecHits = (**i_Tower).constituentsSize();
82  for(size_t j=0;j<numRecHits;j++) {
83  DetId RecHitDetID=(**i_Tower).constituent(j);
84 
85 
86  DetId::Detector DetNum=RecHitDetID.det();
87  if(DetNum==DetId::Ecal){
88  if((EcalSubdetector)RecHitDetID.subdetId()==EcalBarrel){
89  theCaloSubdetectorGeometry = theCaloGeometry->getSubdetectorGeometry(DetId::Ecal,EcalBarrel);
90  EBDetId EcalID=RecHitDetID;
91  EBRecHitCollection::const_iterator theRecHit=EBRecHits->find(EcalID);
92  const CaloCellGeometry* theRecHitCell=theCaloSubdetectorGeometry->getGeometry(RecHitDetID);
93  math::XYZPoint theRecHitCell_XYZPoint(theRecHitCell->getPosition().x(),theRecHitCell->getPosition().y(),theRecHitCell->getPosition().z());
94  pair<math::XYZPoint,float> thePositionAndEnergyEcalRecHit(theRecHitCell_XYZPoint,theRecHit->energy());
95  thePositionAndEnergyEcalRecHits.push_back(thePositionAndEnergyEcalRecHit);
96  }else if((EcalSubdetector)RecHitDetID.subdetId()==EcalEndcap){
97  theCaloSubdetectorGeometry = theCaloGeometry->getSubdetectorGeometry(DetId::Ecal,EcalEndcap);
98  EEDetId EcalID = RecHitDetID;
99  EERecHitCollection::const_iterator theRecHit=EERecHits->find(EcalID);
100  const CaloCellGeometry* theRecHitCell=theCaloSubdetectorGeometry->getGeometry(RecHitDetID);
101  math::XYZPoint theRecHitCell_XYZPoint(theRecHitCell->getPosition().x(),theRecHitCell->getPosition().y(),theRecHitCell->getPosition().z());
102  pair<math::XYZPoint,float> thePositionAndEnergyEcalRecHit(theRecHitCell_XYZPoint,theRecHit->energy());
103  thePositionAndEnergyEcalRecHits.push_back(thePositionAndEnergyEcalRecHit);
104  }else if((EcalSubdetector)RecHitDetID.subdetId()==EcalPreshower){
105  theCaloSubdetectorGeometry = theCaloGeometry->getSubdetectorGeometry(DetId::Ecal,EcalPreshower);
106  ESDetId EcalID = RecHitDetID;
107  ESRecHitCollection::const_iterator theRecHit=ESRecHits->find(EcalID);
108  const CaloCellGeometry* theRecHitCell=theCaloSubdetectorGeometry->getGeometry(RecHitDetID);
109  math::XYZPoint theRecHitCell_XYZPoint(theRecHitCell->getPosition().x(),theRecHitCell->getPosition().y(),theRecHitCell->getPosition().z());
110  pair<math::XYZPoint,float> thePositionAndEnergyEcalRecHit(theRecHitCell_XYZPoint,theRecHit->energy());
111  thePositionAndEnergyEcalRecHits.push_back(thePositionAndEnergyEcalRecHit);
112  }
113  }
114  }
115  }
116  return thePositionAndEnergyEcalRecHits;
117 }
118 */
119 
120 std::vector<DetId> CaloRecoTauTagInfoAlgorithm::getVectorDetId(const CaloJetRef& theCaloJet){
121  std::vector<CaloTowerPtr> theCaloTowers=theCaloJet->getCaloConstituents();
122  std::vector<DetId> myDetIds;
123  myDetIds.clear();
124 
125  for(std::vector<CaloTowerPtr>::const_iterator i_Tower=theCaloTowers.begin();i_Tower!=theCaloTowers.end();i_Tower++){
126  size_t numRecHits = (**i_Tower).constituentsSize();
127  for(size_t j=0;j<numRecHits;j++) {
128  DetId RecHitDetID=(**i_Tower).constituent(j);
129 
130  myDetIds.push_back(RecHitDetID);
131  }
132  }
133  return myDetIds;
134 }
135 
136 
137 std::vector<BasicClusterRef> CaloRecoTauTagInfoAlgorithm::getNeutralEcalBasicClusters(edm::Event& theEvent,const edm::EventSetup& theEventSetup,const CaloJetRef& theCaloJet,const TrackRefVector& theTracks,float theECALBasicClustersAroundCaloJet_DRConeSize,float theECALBasicClusterminE,float theECALBasicClusterpropagTrack_matchingDRConeSize){
138  std::vector<math::XYZPoint> thepropagTracksECALSurfContactPoints;
140  theEventSetup.get<IdealMagneticFieldRecord>().get(theMF);
141  const MagneticField* theMagField=theMF.product();
142  for(TrackRefVector::const_iterator i_Track=theTracks.begin();i_Track!=theTracks.end();i_Track++){
143  math::XYZPoint thepropagTrackECALSurfContactPoint=TauTagTools::propagTrackECALSurfContactPoint(theMagField,*i_Track);
144  if(thepropagTrackECALSurfContactPoint.R()!=0.) thepropagTracksECALSurfContactPoints.push_back(thepropagTrackECALSurfContactPoint);
145  }
146 
147  math::XYZPoint aCaloJetFakePosition((*theCaloJet).px(),(*theCaloJet).py(),(*theCaloJet).pz());
148 
149  std::vector<BasicClusterRef> theBasicClusters;
150 
151  edm::Handle<BasicClusterCollection> theBarrelBCCollection;
152  // theEvent.getByLabel("islandBasicClusters","islandBarrelBasicClusters",theBarrelBCCollection);
153  theEvent.getByLabel(BarrelBasicClusters_,theBarrelBCCollection);
154  for(unsigned int i_BC=0;i_BC!=theBarrelBCCollection->size();i_BC++) {
155  BasicClusterRef theBasicClusterRef(theBarrelBCCollection,i_BC);
156  if (theBasicClusterRef.isNull()) continue;
157  if (ROOT::Math::VectorUtil::DeltaR(aCaloJetFakePosition,(*theBasicClusterRef).position())<=theECALBasicClustersAroundCaloJet_DRConeSize && (*theBasicClusterRef).energy()>=theECALBasicClusterminE) theBasicClusters.push_back(theBasicClusterRef);
158  }
159  edm::Handle<BasicClusterCollection> theEndcapBCCollection;
160  // theEvent.getByLabel("islandBasicClusters","islandEndcapBasicClusters",theEndcapBCCollection);
161  theEvent.getByLabel(EndcapBasicClusters_,theEndcapBCCollection);
162  for(unsigned int j_BC=0;j_BC!=theEndcapBCCollection->size();j_BC++) {
163  BasicClusterRef theBasicClusterRef(theEndcapBCCollection,j_BC);
164  if (theBasicClusterRef.isNull()) continue;
165  if (ROOT::Math::VectorUtil::DeltaR(aCaloJetFakePosition,(*theBasicClusterRef).position())<=theECALBasicClustersAroundCaloJet_DRConeSize && (*theBasicClusterRef).energy()>=theECALBasicClusterminE) theBasicClusters.push_back(theBasicClusterRef);
166  }
167 
168  std::vector<BasicClusterRef> theNeutralBasicClusters=theBasicClusters;
169  std::vector<BasicClusterRef>::iterator kmatchedBasicCluster;
170  for (std::vector<math::XYZPoint>::iterator ipropagTrackECALSurfContactPoint=thepropagTracksECALSurfContactPoints.begin();ipropagTrackECALSurfContactPoint!=thepropagTracksECALSurfContactPoints.end();ipropagTrackECALSurfContactPoint++) {
171  double theMatchedEcalBasicClusterpropagTrack_minDR=theECALBasicClusterpropagTrack_matchingDRConeSize;
172  bool Track_matchedwithEcalBasicCluster=false;
173  for (std::vector<BasicClusterRef>::iterator jBasicCluster=theNeutralBasicClusters.begin();jBasicCluster!=theNeutralBasicClusters.end();jBasicCluster++) {
174  if(ROOT::Math::VectorUtil::DeltaR((*ipropagTrackECALSurfContactPoint),(**jBasicCluster).position())<theMatchedEcalBasicClusterpropagTrack_minDR){
175  Track_matchedwithEcalBasicCluster=true;
176  theMatchedEcalBasicClusterpropagTrack_minDR=ROOT::Math::VectorUtil::DeltaR((*ipropagTrackECALSurfContactPoint),(**jBasicCluster).position());
177  kmatchedBasicCluster=jBasicCluster;
178  }
179  }
180  if(Track_matchedwithEcalBasicCluster) kmatchedBasicCluster=theNeutralBasicClusters.erase(kmatchedBasicCluster);
181  }
182  return theNeutralBasicClusters;
183 }
184 
186 {
188  for (TrackRefVector::const_iterator iTrack = tracks.begin(); iTrack != tracks.end(); iTrack++) {
189  if ((*iTrack)->quality(quality)) filteredTracks.push_back(*iTrack);
190  }
191  return filteredTracks;
192 }
T getParameter(std::string const &) const
dictionary parameters
Definition: Parameters.py:2
void setTracks(const TrackRefVector &)
const CaloJetRef & calojetRef() const
TrackQuality
track quality
Definition: TrackBase.h:149
reco::CaloTauTagInfo buildCaloTauTagInfo(edm::Event &, const edm::EventSetup &, const reco::CaloJetRef &, const reco::TrackRefVector &, const reco::Vertex &)
reco::TrackRefVector filteredTracks(reco::TrackRefVector theInitialTracks, double tkminPt, int tkminPixelHitsn, int tkminTrackerHitsn, double tkmaxipt, double tkmaxChi2, reco::Vertex pV)
Definition: TauTagTools.cc:77
math::XYZPoint propagTrackECALSurfContactPoint(const MagneticField *, reco::TrackRef)
Definition: TauTagTools.cc:184
void setJetRef(const JetBaseRef)
const_iterator end() const
Termination of iteration.
Definition: RefVector.h:255
const_iterator begin() const
Initialize an iterator over the RefVector.
Definition: RefVector.h:250
int j
Definition: DBlmapReader.cc:9
double z() const
y coordinate
Definition: Vertex.h:112
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:420
bool isNull() const
Checks for null.
Definition: Ref.h:249
void setcalojetRef(const CaloJetRef)
Definition: DetId.h:18
std::vector< reco::BasicClusterRef > getNeutralEcalBasicClusters(edm::Event &, const edm::EventSetup &theEventSetup, const reco::CaloJetRef &, const reco::TrackRefVector &, float theECALBasicClustersAroundCaloJet_DRConeSize, float theECALBasicClusterminE, float theECALBasicClusterpropagTrack_matchingDRConeSize)
static TrackQuality qualityByName(const std::string &name)
Definition: TrackBase.cc:123
tuple tracks
Definition: testEve_cfg.py:39
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
const T & get() const
Definition: EventSetup.h:56
T const * product() const
Definition: ESHandle.h:86
reco::TrackRefVector filterTracksByQualityBit(const reco::TrackRefVector &tracks, reco::TrackBase::TrackQuality quality) const
std::vector< DetId > getVectorDetId(const reco::CaloJetRef &)
void push_back(value_type const &ref)
Add a Ref&lt;C, T&gt; to the RefVector.
Definition: RefVector.h:62
void setneutralECALBasicClusters(const std::vector< BasicClusterRef > &)