CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TCTauAlgorithm.cc
Go to the documentation of this file.
2 
7 
9 
10 #include "Math/VectorUtil.h"
11 using namespace ROOT::Math;
12 
13 using namespace reco;
14 
16  init();
17 }
18 
20  init();
21  inputConfig(iConfig);
22 }
23 
25 
27 
28  event = 0;
29  setup = 0;
30 
31  trackAssociator = new TrackDetectorAssociator();
32  trackAssociator->useDefaultPropagator();
33 
34  all = 0;
35  passed = 0;
36  prongs = -1;
37  algoComponentUsed = 0;
38 }
39 
41 
42  etCaloOverTrackMin = iConfig.getParameter<double>("EtCaloOverTrackMin");
43  etCaloOverTrackMax = iConfig.getParameter<double>("EtCaloOverTrackMax");
44  etHcalOverTrackMin = iConfig.getParameter<double>("EtHcalOverTrackMin");
45  etHcalOverTrackMax = iConfig.getParameter<double>("EtHcalOverTrackMax");
46 
47  signalCone = iConfig.getParameter<double>("SignalConeSize");
48  ecalCone = iConfig.getParameter<double>("EcalConeSize");
49 
50  EcalRecHitsEB_input= iConfig.getParameter<edm::InputTag>("EBRecHitCollection");
51  EcalRecHitsEE_input= iConfig.getParameter<edm::InputTag>("EERecHitCollection");
52  HBHERecHits_input = iConfig.getParameter<edm::InputTag>("HBHERecHitCollection");
53  HORecHits_input = iConfig.getParameter<edm::InputTag>("HORecHitCollection");
54  HFRecHits_input = iConfig.getParameter<edm::InputTag>("HFRecHitCollection");
55 
56  edm::ParameterSet pset = iConfig.getParameter<edm::ParameterSet>("TrackAssociatorParameters");
57  trackAssociatorParameters.loadParameters( pset );
58 
59  dropCaloJets = iConfig.getUntrackedParameter<bool>("DropCaloJets",false);
60  dropRejected = iConfig.getUntrackedParameter<bool>("DropRejectedJets",true);
61 }
62 
63 
65  return double(passed)/all;
66 }
67 
69  return passed;
70 }
71 
73  return all;
74 }
75 
77  return algoComponentUsed;
78 }
79 
81 
82  event = &iEvent;
83  setup = &iSetup;
84 
86  iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder",builder);
87  transientTrackBuilder = builder.product();
88 
89  // geometry initialization
91  iSetup.get<CaloGeometryRecord>().get(geometry);
92 
93 
94  EB = geometry->getSubdetectorGeometry(DetId::Ecal,EcalBarrel);
95  EE = geometry->getSubdetectorGeometry(DetId::Ecal,EcalEndcap);
96  HB = geometry->getSubdetectorGeometry(DetId::Hcal,HcalBarrel);
97  HE = geometry->getSubdetectorGeometry(DetId::Hcal,HcalEndcap);
98  HO = geometry->getSubdetectorGeometry(DetId::Hcal,HcalOuter);
99  HF = geometry->getSubdetectorGeometry(DetId::Hcal,HcalForward);
100 
101  //hits
102  iEvent.getByLabel( EcalRecHitsEB_input, EBRecHits );
103  iEvent.getByLabel( EcalRecHitsEE_input, EERecHits );
104 
105  iEvent.getByLabel( HBHERecHits_input, HBHERecHits );
106  iEvent.getByLabel( HORecHits_input, HORecHits );
107  iEvent.getByLabel( HFRecHits_input, HFRecHits );
108 }
109 
110 
112 
113  const TrackRef& leadTk = jet.leadTrack();
114 
115  const TrackRefVector associatedTracks = jet.caloTauTagInfoRef()->Tracks();
116 
117  const CaloJet* cJet = jet.caloTauTagInfoRef()->calojetRef().get();
118  CaloJet caloJet = *cJet;
119  caloJet.setP4(jet.p4());
120 
121  return recalculateEnergy(caloJet,leadTk,associatedTracks);
122 }
123 
125 
126  all++;
127 
128  math::XYZTLorentzVector p4(0,0,0,0);
129  algoComponentUsed = TCAlgoUndetermined;
130 
131  //if(!dropRejected)
132  p4 = caloJet.p4();
133 
134  if(leadTk.isNull()) return p4;
135 
136  XYZVector momentum(0,0,0);
137  int prongCounter = 0;
139  for(iTrack = associatedTracks.begin(); iTrack!= associatedTracks.end(); ++iTrack){
140  double DR = ROOT::Math::VectorUtil::DeltaR(leadTk->momentum(),(*iTrack)->momentum());
141  if(DR < signalCone) {
142  momentum+=(*iTrack)->momentum();
143  prongCounter++;
144  }
145  }
146  if(momentum.Rho() == 0) return p4;
147 
148  XYZVector ltrackEcalHitPoint = trackEcalHitPoint(*leadTk);
149 
150  if(! (ltrackEcalHitPoint.Rho() > 0 && ltrackEcalHitPoint.Rho() < 9999) ) return p4;
151 
152  std::pair<XYZVector,XYZVector> caloClusters = getClusterEnergy(caloJet,ltrackEcalHitPoint,signalCone);
153  XYZVector EcalCluster = caloClusters.first;
154  XYZVector HcalCluster = caloClusters.second;
155 
156  double eCaloOverTrack = (EcalCluster.R()+HcalCluster.R()-momentum.R())/momentum.R();
157 
158  std::pair<XYZVector,XYZVector> caloClustersPhoton = getClusterEnergy(caloJet,ltrackEcalHitPoint,ecalCone);
159  XYZVector EcalClusterPhoton = caloClustersPhoton.first;
160 
161  math::XYZTLorentzVector p4photons(0,0,0,EcalClusterPhoton.R() - EcalCluster.R());
162 
163  if( eCaloOverTrack > etCaloOverTrackMin && eCaloOverTrack < etCaloOverTrackMax ) {
164 
165  double eHcalOverTrack = (HcalCluster.R()-momentum.R())/momentum.R();
166 
167  if ( eHcalOverTrack > etHcalOverTrackMin && eHcalOverTrack < etHcalOverTrackMax ) {
168  p4.SetXYZT(EcalCluster.X() + momentum.X(),
169  EcalCluster.Y() + momentum.Y(),
170  EcalCluster.Z() + momentum.Z(),
171  EcalCluster.R() + momentum.R());
172  p4 += p4photons;
173  algoComponentUsed = TCAlgoMomentumECAL;
174  }else{
175  p4.SetXYZT(momentum.X(),
176  momentum.Y(),
177  momentum.Z(),
178  momentum.R());
179  algoComponentUsed = TCAlgoMomentum;
180  }
181  }
182  if( eCaloOverTrack > etCaloOverTrackMax ) {
183  double eHcalOverTrack = (HcalCluster.R()-momentum.R())/momentum.R();
184 
185  if ( eHcalOverTrack > etHcalOverTrackMin && eHcalOverTrack < etHcalOverTrackMax ) {
186  p4.SetXYZT(EcalCluster.X() + momentum.X(),
187  EcalCluster.Y() + momentum.Y(),
188  EcalCluster.Z() + momentum.Z(),
189  EcalCluster.R() + momentum.R());
190  p4 += p4photons;
191  algoComponentUsed = TCAlgoMomentumECAL;
192  }
193  if ( eHcalOverTrack < etHcalOverTrackMin ) {
194  if(!dropCaloJets) p4.SetXYZT(caloJet.px(),caloJet.py(),caloJet.pz(),caloJet.energy());
195  else p4.SetXYZT(0,0,0,0);
196  algoComponentUsed = TCAlgoCaloJet;
197  }
198  if ( eHcalOverTrack > etHcalOverTrackMax ) {
199  algoComponentUsed = TCAlgoHadronicJet; // reject
200  if(!dropRejected) p4.SetXYZT(caloJet.px(),caloJet.py(),caloJet.pz(),caloJet.energy());
201  else p4.SetXYZT(0,0,0,0);
202  }
203  }
204  if( eCaloOverTrack < etCaloOverTrackMin ) {
205  algoComponentUsed = TCAlgoTrackProblem; // reject
206  if(!dropRejected) p4.SetXYZT(caloJet.px(),caloJet.py(),caloJet.pz(),caloJet.energy());
207  }
208 
209  if(p4.Et() > 0) passed++;
210 
211  return p4;
212 }
213 
214 
216 
217 
218  GlobalPoint ecalHitPosition(0,0,0);
219 
220  double maxTowerEt = 0;
221  std::vector<CaloTowerPtr> towers = caloJet.getCaloConstituents();
222  for(std::vector<CaloTowerPtr>::const_iterator iTower = towers.begin();
223  iTower!= towers.end(); ++iTower){
224  if((*iTower)->et() > maxTowerEt){
225  maxTowerEt = (*iTower)->et();
226  ecalHitPosition = (*iTower)->emPosition();
227  }
228  }
229 
230 
231  XYZVector ecalHitPoint(0,0,0);
232 
233  try{
234  GlobalPoint trackEcalHitPoint = transientTrack.stateOnSurface(ecalHitPosition).globalPosition();
235 
236  ecalHitPoint.SetXYZ(trackEcalHitPoint.x(),
237  trackEcalHitPoint.y(),
238  trackEcalHitPoint.z());
239  }catch(...) {;}
240 
241  return ecalHitPoint;
242 }
243 
245 
246  const FreeTrajectoryState fts = trackAssociator->getFreeTrajectoryState(*setup,track);
247  TrackDetMatchInfo info = trackAssociator->associate(*event, *setup, fts, trackAssociatorParameters);
248  if( info.isGoodEcal != 0 ) {
249  return XYZVector(info.trkGlobPosAtEcal.x(),info.trkGlobPosAtEcal.y(),info.trkGlobPosAtEcal.z());
250  }
251  return XYZVector(0,0,0);
252 }
253 
254 std::pair<XYZVector,XYZVector> TCTauAlgorithm::getClusterEnergy(const CaloJet& caloJet,XYZVector& trackEcalHitPoint,double cone){
255 
256  XYZVector ecalCluster(0,0,0);
257  XYZVector hcalCluster(0,0,0);
258 
259  std::vector<CaloTowerPtr> towers = caloJet.getCaloConstituents();
260 
261  for(std::vector<CaloTowerPtr>::const_iterator iTower = towers.begin();
262  iTower!= towers.end(); ++iTower){
263  std::vector<XYZVector> ECALCells;
264  std::vector<XYZVector> HCALCells;
265 
266  size_t numRecHits = (**iTower).constituentsSize();
267 
268  // access CaloRecHits
269  for(size_t j = 0; j < numRecHits; j++) {
270  DetId recHitDetID = (**iTower).constituent(j);
271  //DetId::Detector detNum=recHitDetID.det();
272  if( recHitDetID.det() == DetId::Ecal ){
273  if( recHitDetID.subdetId() == 1 ){ // Ecal Barrel
274  EBDetId ecalID = recHitDetID;
275  EBRecHitCollection::const_iterator theRecHit = EBRecHits->find(ecalID);
276  if(theRecHit != EBRecHits->end()){
277  DetId id = theRecHit->detid();
278  const CaloCellGeometry* this_cell = EB->getGeometry(id);
279  double energy = theRecHit->energy();
280  ECALCells.push_back(getCellMomentum(this_cell,energy));
281  }
282  }
283  if( recHitDetID.subdetId() == 2 ){ // Ecal Endcap
284  EEDetId ecalID = recHitDetID;
285  EERecHitCollection::const_iterator theRecHit = EERecHits->find(ecalID);
286  if(theRecHit != EERecHits->end()){
287  DetId id = theRecHit->detid();
288  const CaloCellGeometry* this_cell = EE->getGeometry(id);
289  double energy = theRecHit->energy();
290  ECALCells.push_back(getCellMomentum(this_cell,energy));
291  }
292  }
293  }
294  if( recHitDetID.det() == DetId::Hcal ){
295  HcalDetId hcalID = recHitDetID;
296  if( recHitDetID.subdetId() == HcalBarrel ){
297  //int depth = hcalID.depth();
298  //if (depth==1){
299  HBHERecHitCollection::const_iterator theRecHit=HBHERecHits->find(hcalID);
300  if(theRecHit != HBHERecHits->end()){
301  DetId id = theRecHit->detid();
302  const CaloCellGeometry* this_cell = HB->getGeometry(id);
303  double energy = theRecHit->energy();
304  HCALCells.push_back(getCellMomentum(this_cell,energy));
305  }
306  //}
307  }
308  if( recHitDetID.subdetId() == HcalEndcap ){
309  //int depth = hcalID.depth();
310  //if (depth==1){
311  HBHERecHitCollection::const_iterator theRecHit=HBHERecHits->find(hcalID);
312  if(theRecHit != HBHERecHits->end()){
313  DetId id = theRecHit->detid();
314  const CaloCellGeometry* this_cell = HE->getGeometry(id);
315  double energy = theRecHit->energy();
316  HCALCells.push_back(getCellMomentum(this_cell,energy));
317  }
318  //}
319  }
320  if( recHitDetID.subdetId() == HcalOuter ){
321  HORecHitCollection::const_iterator theRecHit=HORecHits->find(hcalID);
322  if(theRecHit != HORecHits->end()){
323  DetId id = theRecHit->detid();
324  const CaloCellGeometry* this_cell = HO->getGeometry(id);
325  double energy = theRecHit->energy();
326  HCALCells.push_back(getCellMomentum(this_cell,energy));
327  }
328  }
329  if( recHitDetID.subdetId() == HcalForward ){
330  HFRecHitCollection::const_iterator theRecHit=HFRecHits->find(hcalID);
331  if(theRecHit != HFRecHits->end()){
332  DetId id = theRecHit->detid();
333  const CaloCellGeometry* this_cell = HF->getGeometry(id);
334  double energy = theRecHit->energy();
335  HCALCells.push_back(getCellMomentum(this_cell,energy));
336  }
337  }
338  }
339  }
340 
341  std::vector<XYZVector>::const_iterator i;
342  for(i = ECALCells.begin(); i != ECALCells.end(); ++i) {
343  double DR = ROOT::Math::VectorUtil::DeltaR(trackEcalHitPoint,*i);
344  if( DR < cone ) ecalCluster += *i;
345  }
346  for(i = HCALCells.begin(); i != HCALCells.end(); ++i) {
347  double DR = ROOT::Math::VectorUtil::DeltaR(trackEcalHitPoint,*i);
348  if( DR < cone ) hcalCluster += *i;
349  }
350  }
351  return std::pair<XYZVector,XYZVector> (ecalCluster,hcalCluster);
352 }
353 
355  XYZVector momentum(0,0,0);
356  if(cell){
357  GlobalPoint hitPosition = cell->getPosition();
358 
359  double phi = hitPosition.phi();
360  double theta = hitPosition.theta();
361  if(theta > 3.14159) theta = 2*3.14159 - theta;
362  double px = energy * sin(theta)*cos(phi);
363  double py = energy * sin(theta)*sin(phi);
364  double pz = energy * cos(theta);
365 
366  momentum = XYZVector(px,py,pz);
367  }
368  return momentum;
369 }
T getParameter(std::string const &) const
void eventSetup(const edm::Event &, const edm::EventSetup &)
T getUntrackedParameter(std::string const &, T const &) const
virtual reco::TrackRef leadTrack() const
Definition: BaseTau.cc:26
int i
Definition: DBlmapReader.cc:9
Jets made from CaloTowers.
Definition: CaloJet.h:30
double efficiency()
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
int init
Definition: HydjetWrapper.h:63
Geom::Phi< T > phi() const
Definition: PV3DBase.h:68
void inputConfig(const edm::ParameterSet &iConfig)
std::vector< EcalRecHit >::const_iterator const_iterator
Geom::Theta< T > theta() const
T y() const
Definition: PV3DBase.h:62
virtual void setP4(const LorentzVector &p4)
set 4-momentum
GlobalPoint globalPosition() const
const GlobalPoint & getPosition() const
Returns the position of reference for this cell.
const_iterator end() const
Termination of iteration.
Definition: RefVector.h:249
virtual std::vector< CaloTowerPtr > getCaloConstituents() const
get all constituents
Definition: CaloJet.cc:94
const_iterator begin() const
Initialize an iterator over the RefVector.
Definition: RefVector.h:244
math::XYZVector trackEcalHitPoint(const reco::TransientTrack &, const reco::CaloJet &)
Geom::Theta< T > theta() const
Definition: PV3DBase.h:74
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:30
std::pair< math::XYZVector, math::XYZVector > getClusterEnergy(const reco::CaloJet &, math::XYZVector &, double)
virtual double energy() const
energy
int iEvent
Definition: GenABIO.cc:243
bool isNull() const
Checks for null.
Definition: Ref.h:247
double p4[4]
Definition: TauolaWrapper.h:92
T z() const
Definition: PV3DBase.h:63
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
math::XYZTLorentzVector recalculateEnergy(const reco::CaloTau &)
int j
Definition: DBlmapReader.cc:9
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:39
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
math::XYZVector getCellMomentum(const CaloCellGeometry *, double &)
Definition: DetId.h:20
Transform3DPJ::Vector XYZVector
virtual double px() const
x coordinate of momentum vector
const CaloTauTagInfoRef & caloTauTagInfoRef() const
Definition: CaloTau.cc:29
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
virtual double pz() const
z coordinate of momentum vector
ESHandle< TrackerGeometry > geometry
TrajectoryStateOnSurface stateOnSurface(const GlobalPoint &point) const
math::XYZPoint trkGlobPosAtEcal
Track position at different parts of the calorimeter.
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:242
Detector det() const
get the detector field from this detid
Definition: DetId.h:37
T x() const
Definition: PV3DBase.h:61
virtual const LorentzVector & p4() const
four-momentum Lorentz vector
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
virtual double py() const
y coordinate of momentum vector
Definition: DDAxes.h:10