CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DiJetAnalyzer.cc
Go to the documentation of this file.
2 
5 
14 
18 
20 #include <fstream>
21 
22 
23 
24 #include "TString.h"
25 #include "TFile.h"
26 #include "TTree.h"
27 #include "TObject.h"
28 #include "TObjArray.h"
29 #include "TClonesArray.h"
30 #include "TRefArray.h"
31 #include "TLorentzVector.h"
32 
33 
34 
35 namespace cms
36 {
38 {
39  jets_=iConfig.getParameter<edm::InputTag>("jetsInput");
40  ec_=iConfig.getParameter<edm::InputTag>("ecInput");
41  hbhe_=iConfig.getParameter<edm::InputTag>("hbheInput");
42  ho_=iConfig.getParameter<edm::InputTag>("hoInput");
43  hf_=iConfig.getParameter<edm::InputTag>("hfInput");
44 
45  // get name of output file with histogramms
46  fOutputFileName = iConfig.getUntrackedParameter<std::string>("HistOutFile");
47 
48  allowMissingInputs_ = true;
49 }
50 
51 
53 {
54 
55 }
56 
57 
58 //
59 // member functions
60 //
61 
62 // ------------ method called to for each event ------------
63 void
65 {
66 
67  using namespace std;
68  using namespace edm;
69  using namespace reco;
70 
71  const double pi = 4.*atan(1.);
72 
73  // event number & run number
74  eventNumber = iEvent.id().event();
75  runNumber = iEvent.id().run();
76 
77 
78  // read jets
79  CaloJet jet1, jet2, jet3;
80  try {
82  iEvent.getByLabel(jets_,jets);
83  if(jets->size()>1){
84  jet1 = (*jets)[0];
85  jet2 = (*jets)[1];
86  if(fabs(jet1.eta())>fabs(jet2.eta())){
87  CaloJet jet = jet1;
88  jet1 = jet2;
89  jet2 = jet;
90  }
91  // if(fabs(jet1.eta())>eta_1 || (fabs(jet2.eta())-jet_R) < eta_2){ return;}
92  } else {return;}
93  tagJetP4->SetPxPyPzE(jet1.px(), jet1.py(), jet1.pz(), jet1.energy());
94  probeJetP4->SetPxPyPzE(jet2.px(), jet2.py(), jet2.pz(), jet2.energy());
95  if(jets->size()>2){
96  jet3 = (*jets)[2];
97  etVetoJet = jet3.et();
98  } else { etVetoJet = 0.;}
99  }catch (cms::Exception& e) { // can't find it!
100  if (!allowMissingInputs_) { throw e; }
101  }
102 
103 
104  double dR = 1000.;
106  iSetup.get<CaloGeometryRecord>().get(pG);
107  const CaloGeometry* geo = pG.product();
108  vector<DetId> vid = geo->getValidDetIds();
109  for(vector<DetId>::const_iterator idItr = vid.begin(); idItr != vid.end(); idItr++)
110  {
111  if( (*idItr).det() == DetId::Hcal ) {
112  GlobalPoint pos = geo->getPosition(*idItr);
113  double deta = fabs(jet2.eta() - pos.eta());
114  double dphi = fabs(jet2.phi() - pos.phi());
115  if(dphi>pi){dphi=2*pi-dphi;}
116  double dR_candidate = sqrt(deta*deta + dphi*dphi);
117  int ieta = HcalDetId(*idItr).ieta();
118  int iphi = HcalDetId(*idItr).iphi();
119  int idepth = HcalDetId(*idItr).depth();
120  if(dR_candidate < dR && idepth == 1){
121  dR = dR_candidate;
122  iEtaHit = ieta;
123  iPhiHit = iphi;
124  }
125  }
126  }
127 
128  targetE = jet1.et()/sin(jet2.theta());
129 
130  std::map<DetId,int> mapId;
131  vector<CaloTowerPtr> towers_fw = jet2.getCaloConstituents();
132  vector<CaloTowerPtr>::const_iterator towersItr;
133  for(towersItr = towers_fw.begin(); towersItr != towers_fw.end(); towersItr++){
134  size_t tower_size = (*towersItr)->constituentsSize();
135  for(size_t i=0; i<tower_size; i++){
136  DetId id = (*towersItr)->constituent(i);
137  mapId[id] = 1;
138  }
139  }
140 
141 
142  // probeJetEmFrac = 0.;
143  double emEnergy = 0.;
144  try {
146  iEvent.getByLabel(ec_,ec);
147  for(EcalRecHitCollection::const_iterator ecItr = (*ec).begin();
148  ecItr != (*ec).end(); ++ecItr)
149  {
150  DetId id = ecItr->detid();
151  if(mapId[id]==1){
152  emEnergy += ecItr->energy();
153  }
154  }
155  } catch (cms::Exception& e) { // can't find it!
156  if (!allowMissingInputs_) throw e;
157  }
158 
159  targetE += -emEnergy;
160  probeJetEmFrac = emEnergy/jet2.energy();
161 
162  int nHits = 0;
163  try {
165  iEvent.getByLabel(hbhe_, hbhe);
166  for(HBHERecHitCollection::const_iterator hbheItr=hbhe->begin();
167  hbheItr!=hbhe->end(); hbheItr++)
168  {
169  DetId id = hbheItr->detid();
170  if(mapId[id]==1){
171  TCell* cell = new TCell(id.rawId(),hbheItr->energy());
172  (*cells)[nHits] = cell;
173  nHits++;
174  }
175  }
176  } catch (cms::Exception& e) { // can't find it!
177  if (!allowMissingInputs_) throw e;
178  }
179 
180 
181  try {
183  iEvent.getByLabel(ho_, ho);
184  for(HORecHitCollection::const_iterator hoItr=ho->begin();
185  hoItr!=ho->end(); hoItr++)
186  {
187  DetId id = hoItr->detid();
188  if(mapId[id]==1){
189  TCell* cell = new TCell(id.rawId(),hoItr->energy());
190  (*cells)[nHits] = cell;
191  nHits++;
192  }
193  }
194  } catch (cms::Exception& e) { // can't find it!
195  if (!allowMissingInputs_) throw e;
196  }
197 
198  try {
200  iEvent.getByLabel(hf_, hf);
201  for(HFRecHitCollection::const_iterator hfItr=hf->begin();
202  hfItr!=hf->end(); hfItr++)
203  {
204  DetId id = hfItr->detid();
205  if(mapId[id]==1){
206  TCell* cell = new TCell(id.rawId(),hfItr->energy());
207  (*cells)[nHits] = cell;
208  nHits++;
209  }
210  }
211  } catch (cms::Exception& e) { // can't find it!
212  if (!allowMissingInputs_) throw e;
213  }
214 
215  probeJetEmFrac = emEnergy/jet2.energy();
216 
217 PxTrkHcal = 0;
218 PyTrkHcal = 0;
219 PzTrkHcal = 0;
220 
221  tree->Fill();
222 
223 }
224 
225 
226 // ------------ method called once each job just before starting event loop ------------
227 void
229 {
230 
231  hOutputFile = new TFile( fOutputFileName.c_str(), "RECREATE" ) ;
232 
233  tree = new TTree("hcalCalibTree", "Tree for IsoTrack Calibration");
234 
235  cells = new TClonesArray("TCell");
236  tagJetP4 = new TLorentzVector();
237  probeJetP4 = new TLorentzVector();
238 
239 
240  tree->Branch("eventNumber", &eventNumber, "eventNumber/i");
241  tree->Branch("runNumber", &runNumber, "runNumber/i");
242  tree->Branch("iEtaHit", &iEtaHit, "iEtaHit/I");
243  tree->Branch("iPhiHit", &iPhiHit, "iPhiHit/i");
244 
245 
246  tree->Branch("xTrkHcal", &xTrkHcal, "xTrkHcal/F");
247  tree->Branch("yTrkHcal", &yTrkHcal, "yTrkHcal/F");
248  tree->Branch("zTrkHcal", &zTrkHcal, "zTrkHcal/F");
249 
250  tree->Branch("PxTrkHcal", &PxTrkHcal, "PxTrkHcal/F");
251  tree->Branch("PyTrkHcal", &PyTrkHcal, "PyTrkHcal/F");
252  tree->Branch("PzTrkHcal", &PzTrkHcal, "PzTrkHcal/F");
253 
254  tree->Branch("cells", &cells, 64000);
255  tree->Branch("emEnergy", &emEnergy, "emEnergy/F");
256  tree->Branch("targetE", &targetE, "targetE/F");
257  tree->Branch("etVetoJet", &etVetoJet, "etVetoJet/F");
258  tree->Branch("tagJetP4", "TLorentzVector", &tagJetP4);
259  tree->Branch("probeJetP4", "TLorentzVector", &probeJetP4);
260  tree->Branch("tagJetEmFrac", &tagJetEmFrac,"tagJetEmFrac/F");
261  tree->Branch("probeJetEmFrac", &probeJetEmFrac,"probeJetEmFrac/F");
262 
263 }
264 
265 // ------------ method called once each job just after ending the event loop ------------
266 void
268 
269  hOutputFile->SetCompressionLevel(2);
270  hOutputFile->cd();
271  tree->Write();
272  hOutputFile->Close() ;
273 
274 }
275 }
RunNumber_t run() const
Definition: EventID.h:42
virtual void endJob()
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:44
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
Jets made from CaloTowers.
Definition: CaloJet.h:30
TLorentzVector * tagJetP4
Definition: DiJetAnalyzer.h:94
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
std::string fOutputFileName
Definition: DiJetAnalyzer.h:68
Geom::Phi< T > phi() const
Definition: PV3DBase.h:68
std::vector< EcalRecHit >::const_iterator const_iterator
virtual void analyze(const edm::Event &, const edm::EventSetup &)
Definition: TCell.h:15
edm::InputTag hbhe_
Definition: DiJetAnalyzer.h:61
const Double_t pi
edm::InputTag ho_
Definition: DiJetAnalyzer.h:62
virtual void beginJob()
int depth() const
get the tower depth
Definition: HcalDetId.h:42
int iEvent
Definition: GenABIO.cc:243
DiJetAnalyzer(const edm::ParameterSet &)
T sqrt(T t)
Definition: SSEVec.h:46
vector< PseudoJet > jets
int ieta() const
get the cell ieta
Definition: HcalDetId.h:38
TLorentzVector * probeJetP4
Definition: DiJetAnalyzer.h:95
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
edm::InputTag ec_
Definition: DiJetAnalyzer.h:60
int iphi() const
get the cell iphi
Definition: HcalDetId.h:40
Definition: DetId.h:20
const T & get() const
Definition: EventSetup.h:55
TClonesArray * cells
Definition: DiJetAnalyzer.h:88
std::vector< DetId > getValidDetIds() const
Get the list of all valid detector ids.
Definition: CaloGeometry.cc:90
T eta() const
Definition: PV3DBase.h:75
edm::EventID id() const
Definition: EventBase.h:56
edm::InputTag hf_
Definition: DiJetAnalyzer.h:63
edm::InputTag jets_
Definition: DiJetAnalyzer.h:59