CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SignCaloSpecificAlgo.cc
Go to the documentation of this file.
12 
13 #include <string>
14 using namespace reco;
15 using namespace std;
16 // -*- C++ -*-
17 //
18 // Package: METAlgorithms
19 // Class: SigInputObj
20 //
35 //
36 // Original Author: Kyle Story, Freya Blekman (Cornell University)
37 // Created: Fri Apr 18 11:58:33 CEST 2008
38 // $Id: SignCaloSpecificAlgo.cc,v 1.8 2009/10/22 16:50:45 fblekman Exp $
39 //
40 //
41 
43  significance_(0.),
44  matrix_(2,2)
45 {
46  matrix_(0,0)=matrix_(1,0)=matrix_(0,1)=matrix_(1,1)=0.;
47 }
49 {
50 }
51 
52 void SignCaloSpecificAlgo::usePreviousSignif(const std::vector<double> &values)
53 {
54  if(values.size()!=4)
55  return;
56  matrix_(0,0)=values[0];
57  matrix_(0,1)=values[1];
58  matrix_(1,0)=values[2];
59  matrix_(1,1)=values[3];
60  return;
61 }
63 //
64 // Convert a list of calo towers to objects that can be passed to the significance algo:
65 
66 std::vector<metsig::SigInputObj>
67 SignCaloSpecificAlgo::makeVectorOutOfCaloTowers(edm::Handle<edm::View<reco::Candidate> > towers, const::metsig::SignAlgoResolutions& resolutions, bool noHF, double globalThreshold)
68 {
69 
70  edm::View<Candidate>::const_iterator towerCand = towers->begin();
71  std::vector<metsig::SigInputObj> signInputVec;
72  //iterate over all CaloTowers and record information
73  for( ; towerCand != towers->end(); towerCand++ ) {
74  const Candidate *candidate = &(*towerCand);
75  if(candidate){
76  const CaloTower * calotower = dynamic_cast<const CaloTower*> (candidate);
77  if(calotower){
78  double sign_tower_et = calotower->et();
79  if(sign_tower_et<globalThreshold)
80  continue;
81  bool wasused=false;
82  double sign_tower_phi = calotower->phi();
83  double sign_tower_sigma_et = 0;
84  double sign_tower_sigma_phi = 0;
85  std::string sign_tower_type = "";
86 
87  bool hadIsDone = false;
88  bool emIsDone = false;
89  int cell = calotower->constituentsSize();
90 
91  while ( --cell >= 0 && (!hadIsDone || !emIsDone) )
92  {
93  DetId id = calotower->constituent( cell );
94  if( !hadIsDone && id.det() == DetId::Hcal )
95  {
96  HcalSubdetector subdet = HcalDetId(id).subdet();
97  if(subdet == HcalBarrel){
98  sign_tower_type = "hadcalotower";
99  sign_tower_et = calotower->hadEt();
100  sign_tower_sigma_et = resolutions.eval(metsig::caloHB,metsig::ET,sign_tower_et,calotower->phi(),calotower->eta());
101  sign_tower_sigma_phi = resolutions.eval(metsig::caloHB,metsig::PHI,sign_tower_et,calotower->phi(),calotower->eta());
102  }
103  else if(subdet==HcalOuter){
104  sign_tower_type = "hadcalotower";
105  sign_tower_et = calotower->outerEt();
106  sign_tower_sigma_et = resolutions.eval(metsig::caloHO,metsig::ET,sign_tower_et,calotower->phi(),calotower->eta());
107  sign_tower_sigma_phi = resolutions.eval(metsig::caloHO,metsig::PHI,sign_tower_et,calotower->phi(),calotower->eta());
108  }
109  else if(subdet==HcalEndcap){
110  sign_tower_type = "hadcalotower";
111  sign_tower_et = calotower->hadEt();
112  sign_tower_sigma_et = resolutions.eval(metsig::caloHE,metsig::ET,sign_tower_et,calotower->phi(),calotower->eta());
113  sign_tower_sigma_phi = resolutions.eval(metsig::caloHE,metsig::PHI,sign_tower_et,calotower->phi(),calotower->eta());
114  }
115  else if(subdet == HcalForward){
116  sign_tower_type = "hadcalotower";
117  sign_tower_et = calotower->et();
118  sign_tower_sigma_et = resolutions.eval(metsig::caloHF,metsig::ET,sign_tower_et,calotower->phi(),calotower->eta());
119  sign_tower_sigma_phi = resolutions.eval(metsig::caloHF,metsig::PHI,sign_tower_et,calotower->phi(),calotower->eta());
120  }
121  else{
122  edm::LogWarning("SignCaloSpecificAlgo") << " HCAL tower cell not assigned to an HCAL subdetector!!!" << std::endl;
123  }
124  // and book!
125  metsig::SigInputObj temp(sign_tower_type,sign_tower_et,sign_tower_phi,sign_tower_sigma_et,sign_tower_sigma_phi);
126  if(!noHF || subdet !=HcalForward)
127  signInputVec.push_back(temp);
128 
129  wasused=1;
130  hadIsDone = true;
131  }
132  else if( !emIsDone && id.det() == DetId::Ecal )
133  {
134  EcalSubdetector subdet = EcalSubdetector( id.subdetId() );
135 
136  if(subdet == EcalBarrel){
137  sign_tower_type = "emcalotower";
138  sign_tower_et = calotower->emEt();
139  sign_tower_sigma_et = resolutions.eval(metsig::caloEB,metsig::ET,sign_tower_et,calotower->phi(),calotower->eta());
140  sign_tower_sigma_phi = resolutions.eval(metsig::caloEB,metsig::PHI,sign_tower_et,calotower->phi(),calotower->eta());
141  }
142  else if(subdet == EcalEndcap ){
143  sign_tower_type = "emcalotower";
144  sign_tower_et = calotower->emEt();
145  sign_tower_sigma_et = resolutions.eval(metsig::caloEE,metsig::ET,sign_tower_et,calotower->phi(),calotower->eta());
146  sign_tower_sigma_phi = resolutions.eval(metsig::caloEE,metsig::PHI,sign_tower_et,calotower->phi(),calotower->eta());
147 
148  }
149  else{
150  edm::LogWarning("SignCaloSpecificAlgo") << " ECAL tower cell not assigned to an ECAL subdetector!!!" << std::endl;
151  }
152  metsig::SigInputObj temp(sign_tower_type,sign_tower_et,sign_tower_phi,sign_tower_sigma_et,sign_tower_sigma_phi);
153  signInputVec.push_back(temp);
154  wasused=1;
155  emIsDone = true;
156  }
157  }
158  if(wasused==0)
159  edm::LogWarning("SignCaloSpecificAlgo") << "found non-assigned cell, " << std::endl;
160  }
161  }
162  }
163  return signInputVec;
164 }
166 //
167 // Basic MET algorithm. gets towers, does sum. Very similar to standard MET.
169 {
170 
171  //retreive calo tower information from candidates
172  //start with the first element of the candidate list
173 
174 
175 
176  // use this container to calculate the significance. SigInputObj are objects that contain both directional and uncertainty information and are used as input to the significance calculation
177 
178  std::vector<metsig::SigInputObj> signInputVec = makeVectorOutOfCaloTowers(towers, resolutions, noHF, globalThreshold);
179 
180  // now run the significance algorithm.
181 
182  double sign_calo_met_total=0;
183  double sign_calo_met_phi=0;
184  double sign_calo_met_set=0;
185  metsig::significanceAlgo signifalgo;
186  // check the caloMET, if significance was already run continue with the matrix that is stored..
187  signifalgo.addSignifMatrix(matrix_);
188  signifalgo.addObjects(signInputVec);
189  matrix_=signifalgo.getSignifMatrix();
190  significance_ = signifalgo.significance( sign_calo_met_total, sign_calo_met_phi, sign_calo_met_set);
191  // cleanup everything:
192  signInputVec.clear();
193  // and return
194 }
195 
196 //-------------------------------------------------------------------------
const void addObjects(const std::vector< metsig::SigInputObj > &EventVec)
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
std::vector< metsig::SigInputObj > makeVectorOutOfCaloTowers(edm::Handle< edm::View< reco::Candidate > > towers, const metsig::SignAlgoResolutions &resolutions, bool noHF, double globalthreshold)
size_t constituentsSize() const
Definition: CaloTower.h:74
HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:32
DetId constituent(size_t i) const
Definition: CaloTower.h:75
double hadEt() const
Definition: CaloTower.h:85
const double significance(double &met_r, double &met_phi, double &met_set)
double outerEt() const
Definition: CaloTower.h:86
virtual double eta() const
momentum pseudorapidity
void usePreviousSignif(const std::vector< double > &values)
void calculateBaseCaloMET(edm::Handle< edm::View< reco::Candidate > > towers, CommonMETData met, const metsig::SignAlgoResolutions &resolutions, bool noHF, double globalthreshold)
TMatrixD getSignifMatrix() const
HcalSubdetector
Definition: HcalAssistant.h:32
Structure containing data common to all types of MET.
Definition: CommonMETData.h:22
const void addSignifMatrix(const TMatrixD &input)
Definition: DetId.h:20
double et(double vtxZ) const
Definition: CaloTower.h:101
const_iterator end() const
EcalSubdetector
virtual double phi() const
momentum azimuthal angle
double emEt() const
Definition: CaloTower.h:84