CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
AnaL1CaloCleaner.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: AnaL1CaloCleaner
4 // Class: AnaL1CaloCleaner
5 //
6 
7 // system include files
8 #include <memory>
9 
10 // user include files
13 
16 
18 
21 
26 //#include "DataFormats/METReco/interface/MET.h"
28 
29 #include "TTree.h"
30 #include "TFile.h"
31 #include "Math/VectorUtil.h"
32 
33 //
34 // class declaration
35 //
36 
38 {
39 public:
40  explicit AnaL1CaloCleaner(const edm::ParameterSet&);
42 
43  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
44 private:
45  virtual void analyze(const edm::Event&, const edm::EventSetup&);
46 
55 
56  TTree* tree_;
57  Float_t pt_;
58  Float_t p_;
59  Float_t eta_;
60  Float_t phi_;
61  Float_t len_ecal_;
62  Float_t len_hcal_;
63  Float_t len_ho_;
64  Float_t dep_ecal_;
65  Float_t dep_hcal_;
66  Float_t dep_ho_;
67  Float_t l1_upara_;
68  Float_t l1_uperp_;
69  Float_t calo_upara_;
70  Float_t calo_uperp_;
71  Int_t charge_;
72 };
73 
74 //
75 // constants, enums and typedefs
76 //
77 
78 //
79 // static data member definitions
80 //
81 
83 {
84  std::map<int, std::string > detMap_;
85  std::map<int, std::map<int, std::string> > subDetMap_;
86 
87  detMap_[DetId::Hcal]="Hcal";
88  detMap_[DetId::Ecal]="Ecal";
89 
90  subDetMap_[DetId::Ecal][EcalBarrel]="EcalBarrel";
91  subDetMap_[DetId::Ecal][EcalEndcap]="EcalEndcap";
92  subDetMap_[DetId::Ecal][EcalPreshower ]="EcalPreshower";
93  subDetMap_[DetId::Ecal][EcalTriggerTower]="EcalTriggerTower";
94  subDetMap_[DetId::Ecal][EcalLaserPnDiode]="EcalLaserPnDiode";
95 
96  subDetMap_[DetId::Hcal][HcalEmpty]="HcalEmpty";
97  subDetMap_[DetId::Hcal][HcalBarrel]="HcalBarrel";
98  subDetMap_[DetId::Hcal][HcalEndcap]="HcalEndcap";
99  subDetMap_[DetId::Hcal][HcalOuter]="HcalOuter";
100  subDetMap_[DetId::Hcal][HcalForward]="HcalForward";
101  subDetMap_[DetId::Hcal][HcalTriggerTower]="HcalTriggerTower";
102  subDetMap_[DetId::Hcal][HcalOther]="HcalOther";
103 
104  return "H_"+detMap_[det.det()]+"_"+subDetMap_[det.det()][det.subdetId()];
105 }
106 
107 std::pair<double, double> compMEtProjU(const reco::Candidate::LorentzVector& zP4, double metPx, double metPy, int& errorFlag)
108 {
109  if ( zP4.pt() == 0. ) {
110  edm::LogWarning ("compMEtProjU")
111  << " Failed to compute projection, because Z0 candidate has zero Pt --> returning dummy solution !!";
112  errorFlag = 1;
113  return std::pair<double, double>(0., 0.);
114  }
115 
116  double qX = zP4.px();
117  double qY = zP4.py();
118  double qT = TMath::Sqrt(qX*qX + qY*qY);
119 
120  double uX = -metPx;//(qX + metPx);
121  double uY = -metPy;//(qY + metPy);
122 
123  double u1 = (uX*qX + uY*qY)/qT;
124  double u2 = (uX*qY - uY*qX)/qT;
125 
126  return std::pair<double, double>(u1, u2);
127 }
128 
129 //
130 // constructors and destructor
131 //
133  colCaloLengthsMinus_(iConfig.getParameter<edm::InputTag>("caloLengthsMinus")),
134  colCaloLengthsPlus_(iConfig.getParameter<edm::InputTag>("caloLengthsPlus")),
135  colCaloDepositsMinus_(iConfig.getParameter<edm::InputTag>("caloDepositsMinus")),
136  colCaloDepositsPlus_(iConfig.getParameter<edm::InputTag>("caloDepositsPlus")),
137  colL1ETM_(iConfig.getParameter<edm::InputTag>("l1ETM")),
138  colCaloMET_(iConfig.getParameter<edm::InputTag>("caloMET")),
139  colGenParticles_(iConfig.getParameter<edm::InputTag>("genParticles")),
140  colMuons_(iConfig.getParameter<edm::InputTag>("muons"))
141 {
143  tree_ = fs->make<TTree>("L1AnaTree", "L1AnaTree");
144 
145  tree_->Branch("pt", &pt_, "pt/F");
146  tree_->Branch("p", &p_, "p/F");
147  tree_->Branch("eta", &eta_, "eta/F");
148  tree_->Branch("phi", &phi_, "phi/F");
149  tree_->Branch("len_ecal", &len_ecal_, "len_ecal/F");
150  tree_->Branch("len_hcal", &len_hcal_, "len_hcal/F");
151  tree_->Branch("len_ho", &len_ho_, "len_ho/F");
152  tree_->Branch("dep_ecal", &dep_ecal_, "dep_ecal/F");
153  tree_->Branch("dep_hcal", &dep_hcal_, "dep_hcal/F");
154  tree_->Branch("dep_ho", &dep_ho_, "dep_ho/F");
155  tree_->Branch("l1_upara", &l1_upara_, "l1_upara/F");
156  tree_->Branch("l1_uperp", &l1_uperp_, "l1_uperp/F");
157  tree_->Branch("calo_upara", &calo_upara_, "calo_upara/F");
158  tree_->Branch("calo_uperp", &calo_uperp_, "calo_uperp/F");
159  tree_->Branch("charge", &charge_, "charge/I");
160 }
161 
162 void
164 {
165  // Find the (only) status-1 genlevel muon
167  iEvent.getByLabel(colGenParticles_, genHandle);
168  const reco::GenParticle* genMuon = NULL;
169  for(std::vector<reco::GenParticle>::const_iterator iter = genHandle->begin(); iter != genHandle->end(); ++iter)
170  {
171  const reco::GenParticle& gen = *iter;
172  if(TMath::Abs(gen.pdgId()) != 13) continue;
173  if(gen.status() != 1) continue;
174  if(genMuon) return; // There should only be one muon, or the whole method does not work
175  genMuon = &gen;
176  }
177 
178  // There should be at least one such muon
179  if(!genMuon) return;
180 
181  // Next, find the matching reco muon, if any
183  iEvent.getByLabel(colMuons_, muonsHandle);
184  const reco::Muon* recoMuon = NULL;
185  for(std::vector<reco::Muon>::const_iterator iter = muonsHandle->begin(); iter != muonsHandle->end(); ++iter)
186  {
187  const reco::Muon& mu = *iter;
188  if(!mu.isGlobalMuon()) continue;
189  if(ROOT::Math::VectorUtil::DeltaR(genMuon->p4(), mu.p4()) > 0.1) continue;
190  if(recoMuon && ROOT::Math::VectorUtil::DeltaR(genMuon->p4(), mu.p4()) > ROOT::Math::VectorUtil::DeltaR(genMuon->p4(), recoMuon->p4())) continue;
191  recoMuon = &mu;
192  }
193 
194  // We need a reco muon
195  if(!recoMuon) return;
196 
197  // Next, read the pathlength the muon travelled in the calorimeter
198  edm::Handle<std::map<unsigned int,float> > hLengthsMinus, hLengthsPlus;
199  edm::Handle<std::map<unsigned int,float> > hDepositsMinus, hDepositsPlus;
200  iEvent.getByLabel(colCaloLengthsMinus_, hLengthsMinus);
201  iEvent.getByLabel(colCaloLengthsPlus_, hLengthsPlus);
202  iEvent.getByLabel(colCaloDepositsMinus_, hDepositsMinus);
203  iEvent.getByLabel(colCaloDepositsPlus_, hDepositsPlus);
204  const std::map<unsigned int,float>& caloLengths = recoMuon->charge() < 0 ? *hLengthsMinus : *hLengthsPlus;
205  const std::map<unsigned int,float>& caloDeposits = recoMuon->charge() < 0 ? *hDepositsMinus : *hDepositsPlus;
206  float len_ecal = 0.0f, len_hcal = 0.0f, len_ho = 0.0f;
207  float dep_ecal = 0.0f, dep_hcal = 0.0f, dep_ho = 0.0f;
208  for(std::map<unsigned int, float>::const_iterator iter = caloLengths.begin(); iter != caloLengths.end(); ++iter)
209  {
210  const DetId det(iter->first);
211  std::map<unsigned int, float>::const_iterator dep_iter = caloDeposits.find(det);
212  const float dep = (dep_iter != caloDeposits.end()) ? dep_iter->second : 0.0f;
213 
214  //std::string name = getKey(det);
215  //std::cout << name << ": " << iter->second << std::endl;
216  // val = (hDeposits->find(entry.first))->second;
217  if(det.det() == DetId::Ecal)
218  {
219  len_ecal += iter->second;
220  dep_ecal += dep;
221  }
222  else if(det.det() == DetId::Hcal && det.subdetId() != HcalOuter)
223  {
224  len_hcal += iter->second;
225  dep_hcal += dep;
226  }
227  else if(det.det() == DetId::Hcal && det.subdetId() == HcalOuter)
228  {
229  len_ho += iter->second;
230  dep_ho += dep;
231  }
232  }
233 
234  // Compute the parallel and perpendicular projection wrt. the genmuon axis
236  iEvent.getByLabel(colL1ETM_, hl1Etm);
237  assert(hl1Etm->size() == 1);
238  int errorFlag = 0;
239  std::pair<double, double> l1_u1u2 = compMEtProjU(genMuon->p4(), (*hl1Etm)[0].px(), (*hl1Etm)[0].py(), errorFlag);
240  if(errorFlag) return;
241 
242  // Do the same with calo MET for reference
244  iEvent.getByLabel(colCaloMET_, hCaloMet);
245  assert(hCaloMet->size() == 1);
246  errorFlag = 0;
247  std::pair<double, double> calo_u1u2 = compMEtProjU(genMuon->p4(), (*hCaloMet)[0].px(), (*hCaloMet)[0].py(), errorFlag);
248  if(errorFlag) return;
249 
250  // And finally fill the tree
251  pt_ = recoMuon->pt();
252  p_ = recoMuon->p();
253  eta_ = recoMuon->eta();
254  phi_ = recoMuon->phi();
255  len_ecal_ = len_ecal;
256  len_hcal_ = len_hcal;
257  len_ho_ = len_ho;
258  dep_ecal_ = dep_ecal;
259  dep_hcal_ = dep_hcal;
260  dep_ho_ = dep_ho;
261  l1_upara_ = l1_u1u2.first;
262  l1_uperp_ = l1_u1u2.second;
263  calo_upara_ = calo_u1u2.first;
264  calo_uperp_ = calo_u1u2.second;
265  charge_ = recoMuon->charge();
266 
267  tree_->Fill();
268 }
269 
271 {
272 }
273 
274 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
275 void
277  //The following says we do not know what parameters are allowed so do no validation
278  // Please change this to state exactly what you do use, even if it is no parameters
280  desc.setUnknown();
281  descriptions.addDefault(desc);
282 }
283 
284 //define this as a plug-in
edm::InputTag colCaloDepositsMinus_
edm::InputTag colGenParticles_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
assert(m_qm.get())
bool isGlobalMuon() const
Definition: Muon.h:222
virtual double phi() const final
momentum azimuthal angle
#define NULL
Definition: scimark2.h:8
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
edm::InputTag colCaloLengthsMinus_
edm::InputTag colCaloMET_
edm::InputTag colL1ETM_
def gen
run2 Cosmic #### Run 256259 @ 0T 2015C### Run 272133 @ 3.8T 2016B###
std::string getKey(const DetId &det)
virtual int status() const final
status word
edm::InputTag colCaloDepositsPlus_
edm::InputTag colCaloLengthsPlus_
AnaL1CaloCleaner(const edm::ParameterSet &)
int iEvent
Definition: GenABIO.cc:230
void addDefault(ParameterSetDescription const &psetDescription)
virtual int charge() const final
electric charge
Definition: LeafCandidate.h:91
T Abs(T a)
Definition: MathUtil.h:49
const int mu
Definition: Constants.h:22
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
virtual void analyze(const edm::Event &, const edm::EventSetup &)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:418
std::pair< double, double > compMEtProjU(const reco::Candidate::LorentzVector &zP4, double metPx, double metPy, int &errorFlag)
Definition: DetId.h:18
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:37
virtual double p() const final
magnitude of momentum vector
virtual int pdgId() const final
PDG identifier.
virtual double eta() const final
momentum pseudorapidity
Detector det() const
get the detector field from this detid
Definition: DetId.h:35
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
virtual const LorentzVector & p4() const final
four-momentum Lorentz vector
Definition: LeafCandidate.h:99
edm::InputTag colMuons_
virtual double pt() const final
transverse momentum