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