CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
JetToDigiDump.cc
Go to the documentation of this file.
1 // JetToDigiDump.cc
2 // Description: Prints out Jets, consituent CaloTowers, constituent RecHits and associated Digis (the digis for HCAL only).
3 // The user can specify which level in the config file:
4 // DumpLevel="Jets": Printout of jets and their kinematic quantities.
5 // DumpLevel="Towers": Nested Printout of jets and their constituent CaloTowers
6 // DumpLevel="RecHits": Nested Printout of jets, constituent CaloTowers and constituent RecHits
7 // DumpLevel="Digis": Nested Printout of jets, constituent CaloTowers, RecHits and all the HCAL digis
8 // associated with the RecHit channel (no links exist to go back to actual digis used).
9 // Does simple sanity checks on energy sums at each level: jets=sum of towers, tower=sum of RecHits.
10 // Does quick and dirty estimate of the fC/GeV factor that was applied to make the RecHit from the Digis.
11 //
12 // Author: Robert M. Harris
13 // Date: 19 - October - 2006
14 //
18 //in CaloJet: #include "DataFormats/CaloTowers/interface/CaloTowerCollection.h"
19 // just for the CaloTowerPtr declaration:
20 // in CaloTowerCollection: #include "DataFormats/CaloTowers/interface/CaloTower.h"
21 // in CaloTowerCollection: #include "DataFormats/CaloTowers/interface/CaloTowerDefs.h"
34 #include <TROOT.h>
35 #include <TSystem.h>
36 #include <TFile.h>
37 #include <TCanvas.h>
38 #include <cmath>
39 using namespace edm;
40 using namespace reco;
41 using namespace std;
42 
44  : DumpLevel(cfg.getParameter<string>("DumpLevel")),
45  CaloJetAlg(cfg.getParameter<string>("CaloJetAlg")),
46  DebugLevel(cfg.getParameter<int>("DebugLevel")),
47  ShowECal(cfg.getParameter<bool>("ShowECal")) {}
48 
50  if (DumpLevel == "Jets") {
51  cout << "Dump of Jets" << endl;
52  Dump = 1;
53  } else if (DumpLevel == "Towers") {
54  cout << "Dump of Jets and constituent CaloTowers" << endl;
55  Dump = 2;
56  } else if (DumpLevel == "RecHits") {
57  cout << "Dump of Jets, constituent CaloTowers, and constituent RecHits" << endl;
58  Dump = 3;
59  } else if (DumpLevel == "Digis") {
60  cout << "Dump of Jets, constituent CaloTowers, constituent RecHits and associated Digis" << endl;
61  Dump = 4;
62  }
63  cout << "Jet Algorithm being dumped is " << CaloJetAlg << endl;
64  cout << "Debug level is " << DebugLevel << endl;
65  //Initialize some stuff
66  evtCount = 0;
67 }
68 
69 void JetToDigiDump::analyze(const Event& evt, const EventSetup& es) {
70  int jetInd;
83  // Old:
84  //Handle<edm::SortedCollection<EBDataFrame> > EBDigis;
85  //Handle<edm::SortedCollection<EBDataFrame> > EEDigis;
86 
87  //Find the CaloTowers in leading CaloJets
88  if (DebugLevel)
89  cout << "Getting caloJets" << endl;
90 
91  evt.getByLabel(CaloJetAlg, caloJets);
92  if (Dump >= 2)
93  evt.getByLabel("towerMaker", caloTowers);
94  if (Dump >= 3) {
95  if (DebugLevel)
96  cout << "Getting recHits" << endl;
97  evt.getByLabel("hbhereco", HBHERecHits);
98  evt.getByLabel("horeco", HORecHits);
99  evt.getByLabel("hfreco", HFRecHits);
100  evt.getByLabel("ecalRecHit", "EcalRecHitsEB", EBRecHits);
101  evt.getByLabel("ecalRecHit", "EcalRecHitsEE", EERecHits);
102  if (DebugLevel)
103  cout << "# of hits gotten - HBHE: " << HBHERecHits->size() << endl;
104  evt.getByLabel("hcalDigis", HBHEDigis);
105  evt.getByLabel("hcalDigis", HODigis);
106  evt.getByLabel("hcalDigis", HFDigis);
107  if (DebugLevel)
108  cout << "# of digis gotten - HBHE: " << HBHEDigis->size() << endl;
109  if (ShowECal) {
110  evt.getByLabel("ecalDigis", "ebDigis", EBDigis);
111  evt.getByLabel("ecalDigis", "eeDigis", EEDigis);
112  }
113  }
114 
115  cout << endl << "Evt: " << evtCount << ", Num Jets=" << caloJets->end() - caloJets->begin() << endl;
116  if (Dump >= 1)
117  cout << " *********************************************************" << endl;
118  jetInd = 0;
119  if (Dump >= 1)
120  for (CaloJetCollection::const_iterator jet = caloJets->begin(); jet != caloJets->end(); ++jet) {
121  //2_1_? std::vector <CaloTowerPtr> towers = jet->getCaloConstituents ();
122  //2_0_7"
123  std::vector<CaloTowerPtr> towers = jet->getCaloConstituents();
124  int nConstituents = towers.size();
125  cout << " Jet: " << jetInd << ", eta=" << jet->eta() << ", phi=" << jet->phi() << ", pt=" << jet->pt()
126  << ",E=" << jet->energy() << ", EB E=" << jet->emEnergyInEB() << " ,HB E=" << jet->hadEnergyInHB()
127  << ", HO E=" << jet->hadEnergyInHO() << " ,EE E=" << jet->emEnergyInEE() << ", HE E=" << jet->hadEnergyInHE()
128  << ", HF E=" << jet->hadEnergyInHF() + jet->emEnergyInHF() << ", Num Towers=" << nConstituents << endl;
129  if (Dump >= 2)
130  cout << " =====================================================" << endl;
131  float sumTowerE = 0.0;
132  if (Dump >= 2)
133  for (int i = 0; i < nConstituents; i++) {
135  caloTowers->find(towers[i]->id()); //Find the tower from its CaloTowerDetID
136  if (theTower == caloTowers->end()) {
137  cerr << "Bug? Can't find the tower" << endl;
138  return;
139  }
140  int ietaTower = towers[i]->id().ieta();
141  int iphiTower = towers[i]->id().iphi();
142  sumTowerE += theTower->energy();
143  size_t numRecHits = theTower->constituentsSize();
144  cout << " Tower " << i << ": ieta=" << ietaTower << ", eta=" << theTower->eta() << ", iphi=" << iphiTower
145  << ", phi=" << theTower->phi() << ", energy=" << theTower->energy() << ", EM=" << theTower->emEnergy()
146  << ", HAD=" << theTower->hadEnergy() << ", HO=" << theTower->outerEnergy()
147  << ", Num Rec Hits =" << numRecHits << endl;
148  if (Dump >= 3)
149  cout << " ------------------------------------------------" << endl;
150  float sumRecHitE = 0.0;
151  if (Dump >= 3)
152  for (size_t j = 0; j < numRecHits; j++) {
153  DetId RecHitDetID = theTower->constituent(j);
154  DetId::Detector DetNum = RecHitDetID.det();
155  if (DetNum == DetId::Hcal) {
156  //cout << "RecHit " << j << ": Detector = " << DetNum << ": Hcal " << endl;
157  HcalDetId HcalID = RecHitDetID;
158  HcalSubdetector HcalNum = HcalID.subdet();
159  if (HcalNum == HcalBarrel) {
160  HBHERecHitCollection::const_iterator theRecHit = HBHERecHits->find(HcalID);
161  sumRecHitE += theRecHit->energy();
162  HBHEDigiCollection::const_iterator theDigis = HBHEDigis->find(HcalID);
163  cout << " RecHit: " << j << ": HB, ieta=" << HcalID.ieta() << ", iphi=" << HcalID.iphi()
164  << ", depth=" << HcalID.depth() << ", energy=" << theRecHit->energy()
165  << ", time=" << theRecHit->time() << ", All Digis=" << theDigis->size()
166  << ", presamples =" << theDigis->presamples() << endl;
167  /* const HcalElectronicsId HW_ID = theDigis->elecId();
168  cout << "Digi: Index=" << HW_ID.linearIndex() << ", raw ID=" << HW_ID.rawId() << ", fiberChan=" << HW_ID.fiberChanId() << ", fiberInd=" << HW_ID.fiberIndex() \
169  << ", HTR chan=" << HW_ID.htrChanId() << ", HTR Slot=" << HW_ID.htrSlot() << ", HDR top/bot=" << HW_ID.htrTopBottom() \
170  << ", VME crate=" << HW_ID.readoutVMECrateId() << ", DCC=" << HW_ID.dccid() << ", DCC spigot=" << HW_ID.spigot() << endl;
171  */
172  float SumDigiCharge = 0.0;
173  float EstimatedPedestal = 0.0;
174  int SamplesToAdd = 4;
175  if (Dump >= 4)
176  cout << " ......................................" << endl;
177  if (Dump >= 4)
178  for (int k = 0; k < theDigis->size(); k++) {
179  const HcalQIESample QIE = theDigis->sample(k);
180  if (k >= theDigis->presamples() && k < theDigis->presamples() + SamplesToAdd)
181  SumDigiCharge += QIE.nominal_fC();
182  if (k < theDigis->presamples() - 1)
183  EstimatedPedestal += QIE.nominal_fC() * SamplesToAdd / (theDigis->presamples() - 1);
184  cout << " Digi: " << k << ", cap ID = " << QIE.capid()
185  << ": ADC Counts = " << QIE.adc() << ", nominal fC = " << QIE.nominal_fC() << endl;
186  }
187  if (Dump >= 4)
188  cout << " 4 Digi fC =" << SumDigiCharge << ", est. ped. fC=" << EstimatedPedestal
189  << ", est. GeV/fc=" << theRecHit->energy() / (SumDigiCharge - EstimatedPedestal) << endl;
190  if (Dump >= 4)
191  cout << " ......................................" << endl;
192  } else if (HcalNum == HcalEndcap) {
193  HBHERecHitCollection::const_iterator theRecHit = HBHERecHits->find(HcalID);
194  if ((abs(HcalID.ieta()) == 28 || abs(HcalID.ieta()) == 29) && HcalID.depth() == 3) {
195  sumRecHitE += theRecHit->energy() / 2; //Depth 3 split over tower 28 & 29
196  } else {
197  sumRecHitE += theRecHit->energy();
198  }
199  HBHEDigiCollection::const_iterator theDigis = HBHEDigis->find(HcalID);
200  cout << " RecHit: " << j << ": HE, ieta=" << HcalID.ieta() << ", iphi=" << HcalID.iphi()
201  << ", depth=" << HcalID.depth() << ", energy=" << theRecHit->energy()
202  << ", time=" << theRecHit->time() << ", All Digis=" << theDigis->size()
203  << ", presamples =" << theDigis->presamples() << endl;
204  float SumDigiCharge = 0.0;
205  float EstimatedPedestal = 0.0;
206  int SamplesToAdd = 4;
207  if (Dump >= 4)
208  cout << " ......................................" << endl;
209  if (Dump >= 4)
210  for (int k = 0; k < theDigis->size(); k++) {
211  const HcalQIESample QIE = theDigis->sample(k);
212  if (k >= theDigis->presamples() && k < theDigis->presamples() + SamplesToAdd)
213  SumDigiCharge += QIE.nominal_fC();
214  if (k < theDigis->presamples() - 1)
215  EstimatedPedestal += QIE.nominal_fC() * SamplesToAdd / (theDigis->presamples() - 1);
216  cout << " Digi: " << k << ", cap ID = " << QIE.capid()
217  << ": ADC Counts = " << QIE.adc() << ", nominal fC = " << QIE.nominal_fC() << endl;
218  }
219  if (Dump >= 4)
220  cout << " 4 Digi fC =" << SumDigiCharge << ", est. ped. fC=" << EstimatedPedestal
221  << ", est. GeV/fc=" << theRecHit->energy() / (SumDigiCharge - EstimatedPedestal) << endl;
222  if (Dump >= 4)
223  cout << " ......................................" << endl;
224  } else if (HcalNum == HcalOuter) {
225  HORecHitCollection::const_iterator theRecHit = HORecHits->find(HcalID);
226  sumRecHitE += theRecHit->energy();
227  HODigiCollection::const_iterator theDigis = HODigis->find(HcalID);
228  cout << " RecHit: " << j << ": HO, ieta=" << HcalID.ieta() << ", iphi=" << HcalID.iphi()
229  << ", depth=" << HcalID.depth() << ", energy=" << theRecHit->energy()
230  << ", time=" << theRecHit->time() << ", All Digis=" << theDigis->size()
231  << ", presamples =" << theDigis->presamples() << endl;
232  float SumDigiCharge = 0.0;
233  float EstimatedPedestal = 0.0;
234  int SamplesToAdd = 4;
235  if (Dump >= 4)
236  cout << " ......................................" << endl;
237  if (Dump >= 4)
238  for (int k = 0; k < theDigis->size(); k++) {
239  const HcalQIESample QIE = theDigis->sample(k);
240  if (k >= theDigis->presamples() && k < theDigis->presamples() + SamplesToAdd)
241  SumDigiCharge += QIE.nominal_fC();
242  if (k < theDigis->presamples() - 1)
243  EstimatedPedestal += QIE.nominal_fC() * SamplesToAdd / (theDigis->presamples() - 1);
244  cout << " Digi: " << k << ", cap ID = " << QIE.capid()
245  << ": ADC Counts = " << QIE.adc() << ", nominal fC = " << QIE.nominal_fC() << endl;
246  }
247  if (Dump >= 4)
248  cout << " 4 Digi fC =" << SumDigiCharge << ", est. ped. fC=" << EstimatedPedestal
249  << ", est. GeV/fc=" << theRecHit->energy() / (SumDigiCharge - EstimatedPedestal) << endl;
250  if (Dump >= 4)
251  cout << " ......................................" << endl;
252  } else if (HcalNum == HcalForward) {
253  HFRecHitCollection::const_iterator theRecHit = HFRecHits->find(HcalID);
254  sumRecHitE += theRecHit->energy();
255  HFDigiCollection::const_iterator theDigis = HFDigis->find(HcalID);
256  cout << " RecHit: " << j << ": HF, ieta=" << HcalID.ieta() << ", iphi=" << HcalID.iphi()
257  << ", depth=" << HcalID.depth() << ", energy=" << theRecHit->energy()
258  << ", time=" << theRecHit->time() << ", All Digis=" << theDigis->size()
259  << ", presamples =" << theDigis->presamples() << endl;
260  float SumDigiCharge = 0.0;
261  float EstimatedPedestal = 0.0;
262  int SamplesToAdd = 1;
263  if (Dump >= 4)
264  cout << " ......................................" << endl;
265  if (Dump >= 4)
266  for (int k = 0; k < theDigis->size(); k++) {
267  const HcalQIESample QIE = theDigis->sample(k);
268  if (k >= theDigis->presamples() && k < theDigis->presamples() + SamplesToAdd)
269  SumDigiCharge += QIE.nominal_fC();
270  if (k < theDigis->presamples() - 1)
271  EstimatedPedestal += QIE.nominal_fC() * SamplesToAdd / (theDigis->presamples() - 1);
272  cout << " Digi: " << k << ", cap ID = " << QIE.capid()
273  << ": ADC Counts = " << QIE.adc() << ", nominal fC = " << QIE.nominal_fC() << endl;
274  }
275  if (Dump >= 4)
276  cout << " 1 Digi fC =" << SumDigiCharge << ", est. ped. fC=" << EstimatedPedestal
277  << ", est. GeV/fc=" << theRecHit->energy() / (SumDigiCharge - EstimatedPedestal) << endl;
278  if (Dump >= 4)
279  cout << " ......................................" << endl;
280  }
281  }
282  if (ShowECal && DetNum == DetId::Ecal) {
283  int EcalNum = RecHitDetID.subdetId();
284  if (EcalNum == 1) {
285  EBDetId EcalID = RecHitDetID;
286  EBRecHitCollection::const_iterator theRecHit = EBRecHits->find(EcalID);
287  EBDigiCollection::const_iterator theDigis = EBDigis->find(EcalID);
288  sumRecHitE += theRecHit->energy();
289  cout << " RecHit " << j << ": EB, ieta=" << EcalID.ieta() << ", iphi=" << EcalID.iphi()
290  << ", SM=" << EcalID.ism() << ", energy=" << theRecHit->energy()
291  << ", All Digis=" << theDigis->size() << endl;
292  if (Dump >= 4)
293  cout << " ......................................" << endl;
294  if (Dump >= 4)
295  for (unsigned int k = 0; k < theDigis->size(); k++) {
296  EBDataFrame frame(*theDigis);
297  const EcalMGPASample MGPA = frame.sample(k);
298  cout << " Digi: " << k << ": ADC Sample = " << MGPA.adc()
299  << ", Gain ID = " << MGPA.gainId() << endl;
300  }
301  if (Dump >= 4)
302  cout << " ......................................" << endl;
303  } else if (EcalNum == 2) {
304  EEDetId EcalID = RecHitDetID;
305  EERecHitCollection::const_iterator theRecHit = EERecHits->find(EcalID);
306  EEDigiCollection::const_iterator theDigis = EEDigis->find(EcalID);
307  sumRecHitE += theRecHit->energy();
308  cout << " RecHit " << j << ": EE, ix=" << EcalID.ix() << ", iy=" << EcalID.iy()
309  << ", energy=" << theRecHit->energy() << ", All Digis=" << theDigis->size() << endl;
310  if (Dump >= 4)
311  cout << " ......................................" << endl;
312  if (Dump >= 4)
313  for (unsigned int k = 0; k < theDigis->size(); k++) {
314  EEDataFrame frame(*theDigis);
315  const EcalMGPASample MGPA = frame.sample(k);
316  cout << " Digi: " << k << ": ADC Sample = " << MGPA.adc()
317  << ", Gain ID = " << MGPA.gainId() << endl;
318  }
319  if (Dump >= 4)
320  cout << " ......................................" << endl;
321  }
322  }
323  }
324  if (Dump >= 3) {
325  if (abs(ietaTower) == 28 || abs(ietaTower) == 29) {
326  cout << " Splitted Sum of RecHit Energies=" << sumRecHitE
327  << ", CaloTower energy=" << theTower->energy() << endl;
328  } else {
329  cout << " Sum of RecHit Energies=" << sumRecHitE << ", CaloTower energy=" << theTower->energy()
330  << endl;
331  }
332  }
333  if (Dump >= 3)
334  cout << " ------------------------------------------------" << endl;
335  }
336  if (Dump >= 2)
337  cout << " Sum of tower energies=" << sumTowerE << ", CaloJet energy=" << jet->energy() << endl;
338  jetInd++;
339  if (Dump >= 2)
340  cout << " =====================================================" << endl;
341  }
342  evtCount++;
343  if (Dump >= 1)
344  cout << " *********************************************************" << endl;
345 }
346 
tuple cfg
Definition: looper.py:296
int ix() const
Definition: EEDetId.h:77
void analyze(const edm::Event &, const edm::EventSetup &) override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::vector< CaloTower >::const_iterator const_iterator
EcalMGPASample sample(int i) const
Definition: EcalDataFrame.h:29
void endJob() override
int gainId() const
get the gainId (2 bits)
int ism() const
get the ECAL/SM id
Definition: EBDetId.h:59
int iphi() const
get the crystal iphi
Definition: EBDetId.h:51
std::string CaloJetAlg
Definition: JetToDigiDump.h:27
constexpr HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:138
constexpr int iphi() const
get the cell iphi
Definition: HcalDetId.h:157
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
HcalSubdetector
Definition: HcalAssistant.h:31
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
constexpr int ieta() const
get the cell ieta
Definition: HcalDetId.h:155
int iy() const
Definition: EEDetId.h:83
int ieta() const
get the crystal ieta
Definition: EBDetId.h:49
constexpr double nominal_fC() const
get the nominal FC (no calibrations applied)
Definition: HcalQIESample.h:45
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:500
constexpr int adc() const
get the ADC sample
Definition: HcalQIESample.h:43
Definition: DetId.h:17
Detector
Definition: DetId.h:24
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
constexpr int capid() const
get the Capacitor id
Definition: HcalQIESample.h:47
std::string DumpLevel
Definition: JetToDigiDump.h:26
tuple cout
Definition: gather_cfg.py:144
constexpr int depth() const
get the tower depth
Definition: HcalDetId.h:164
JetToDigiDump(const edm::ParameterSet &)
void beginJob() override
int adc() const
get the ADC sample (12 bits)
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:46