CMS 3D CMS Logo

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/CaloTowerFwd.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  {
49 }
50 
52  if(DumpLevel=="Jets")
53  {
54  cout << "Dump of Jets" << endl;
55  Dump=1;
56  }
57  else if(DumpLevel=="Towers")
58  {
59  cout << "Dump of Jets and constituent CaloTowers" << endl;
60  Dump=2;
61  }
62  else if(DumpLevel=="RecHits")
63  {
64  cout << "Dump of Jets, constituent CaloTowers, and constituent RecHits" << endl;
65  Dump=3;
66  }
67  else if(DumpLevel=="Digis")
68  {
69  cout << "Dump of Jets, constituent CaloTowers, constituent RecHits and associated Digis" << endl;
70  Dump=4;
71  }
72  cout << "Jet Algorithm being dumped is " << CaloJetAlg << endl;
73  cout<<"Debug level is " << DebugLevel << endl;
74  //Initialize some stuff
75  evtCount = 0;
76 }
77 
78 void JetToDigiDump::analyze( const Event& evt, const EventSetup& es ) {
79 
80  int jetInd;
93  // Old:
94  //Handle<edm::SortedCollection<EBDataFrame> > EBDigis;
95  //Handle<edm::SortedCollection<EBDataFrame> > EEDigis;
96 
97  //Find the CaloTowers in leading CaloJets
98  if (DebugLevel) cout<<"Getting caloJets"<<endl;
99 
100  evt.getByLabel( CaloJetAlg, caloJets );
101  if (Dump >= 2) evt.getByLabel( "towerMaker", caloTowers );
102  if (Dump >= 3) {
103  if (DebugLevel) cout<<"Getting recHits"<<endl;
104  evt.getByLabel( "hbhereco", HBHERecHits );
105  evt.getByLabel( "horeco", HORecHits );
106  evt.getByLabel( "hfreco", HFRecHits );
107  evt.getByLabel( "ecalRecHit", "EcalRecHitsEB", EBRecHits );
108  evt.getByLabel( "ecalRecHit", "EcalRecHitsEE", EERecHits );
109  if (DebugLevel) cout<<"# of hits gotten - HBHE: "<<HBHERecHits->size()<<endl;
110  evt.getByLabel( "hcalDigis", HBHEDigis );
111  evt.getByLabel( "hcalDigis", HODigis );
112  evt.getByLabel( "hcalDigis", HFDigis );
113  if (DebugLevel) cout<<"# of digis gotten - HBHE: "<<HBHEDigis->size()<<endl;
114  if (ShowECal) {
115  evt.getByLabel( "ecalDigis", "ebDigis", EBDigis );
116  evt.getByLabel( "ecalDigis", "eeDigis", EEDigis );
117  }
118  }
119 
120  cout << endl << "Evt: "<<evtCount <<", Num Jets=" <<caloJets->end() - caloJets->begin() << endl;
121  if(Dump>=1)cout <<" *********************************************************" <<endl;
122  jetInd = 0;
123  if(Dump>=1)for( CaloJetCollection::const_iterator jet = caloJets->begin(); jet != caloJets->end(); ++ jet ) {
124  //2_1_? std::vector <CaloTowerPtr> towers = jet->getCaloConstituents ();
125  //2_0_7"
126  std::vector <CaloTowerPtr> towers = jet->getCaloConstituents ();
127  int nConstituents= towers.size();
128  cout <<" Jet: "<<jetInd<<", eta="<<jet->eta()<<", phi="<<jet->phi()<<", pt="<<jet->pt()<<\
129  ",E="<<jet->energy()<<", EB E="<<jet->emEnergyInEB()<<" ,HB E="<<jet->hadEnergyInHB()<<\
130  ", HO E="<<jet->hadEnergyInHO()<<" ,EE E="<< jet->emEnergyInEE()\
131  <<", HE E="<<jet->hadEnergyInHE()<<", HF E="<<jet->hadEnergyInHF()+jet->emEnergyInHF()<<", Num Towers="<<nConstituents<<endl;
132  if(Dump>=2)cout <<" ====================================================="<<endl;
133  float sumTowerE = 0.0;
134  if(Dump>=2)for (int i = 0; i <nConstituents ; i++) {
135  CaloTowerCollection::const_iterator theTower=caloTowers->find(towers[i]->id()); //Find the tower from its CaloTowerDetID
136  if (theTower == caloTowers->end()) {cerr<<"Bug? Can't find the tower"<<endl; return;}
137  int ietaTower = towers[i]->id().ieta();
138  int iphiTower = towers[i]->id().iphi();
139  sumTowerE += theTower->energy();
140  size_t numRecHits = theTower->constituentsSize();
141  cout << " Tower " << i <<": ieta=" << ietaTower << ", eta=" << theTower->eta() <<", iphi=" << iphiTower << ", phi=" << theTower->phi() << \
142  ", energy=" << theTower->energy() << ", EM=" << theTower->emEnergy()<< ", HAD=" << theTower->hadEnergy()\
143  << ", HO=" << theTower->outerEnergy() <<", Num Rec Hits =" << numRecHits << endl;
144  if(Dump>=3)cout << " ------------------------------------------------"<<endl;
145  float sumRecHitE = 0.0;
146  if(Dump>=3)for(size_t j = 0; j <numRecHits ; j++) {
147  DetId RecHitDetID=theTower->constituent(j);
148  DetId::Detector DetNum=RecHitDetID.det();
149  if( DetNum == DetId::Hcal ){
150  //cout << "RecHit " << j << ": Detector = " << DetNum << ": Hcal " << endl;
151  HcalDetId HcalID = RecHitDetID;
152  HcalSubdetector HcalNum = HcalID.subdet();
153  if( HcalNum == HcalBarrel ){
154  HBHERecHitCollection::const_iterator theRecHit=HBHERecHits->find(HcalID);
155  sumRecHitE += theRecHit->energy();
156  HBHEDigiCollection::const_iterator theDigis=HBHEDigis->find(HcalID);
157  cout << " RecHit: " << j << ": HB, ieta=" << HcalID.ieta() << ", iphi=" << HcalID.iphi()<<
158  ", depth=" << HcalID.depth() << ", energy=" << theRecHit->energy() << ", time=" <<\
159  theRecHit->time() <<", All Digis=" << theDigis->size() << ", presamples =" <<\
160  theDigis->presamples() <<endl;
161  /* const HcalElectronicsId HW_ID = theDigis->elecId();
162  cout << "Digi: Index=" << HW_ID.linearIndex() << ", raw ID=" << HW_ID.rawId() << ", fiberChan=" << HW_ID.fiberChanId() << ", fiberInd=" << HW_ID.fiberIndex() \
163  << ", HTR chan=" << HW_ID.htrChanId() << ", HTR Slot=" << HW_ID.htrSlot() << ", HDR top/bot=" << HW_ID.htrTopBottom() \
164  << ", VME crate=" << HW_ID.readoutVMECrateId() << ", DCC=" << HW_ID.dccid() << ", DCC spigot=" << HW_ID.spigot() << endl;
165  */
166  float SumDigiCharge = 0.0;
167  float EstimatedPedestal=0.0;
168  int SamplesToAdd = 4;
169  if(Dump>=4)cout << " ......................................"<<endl;
170  if(Dump>=4)for(int k=0; k<theDigis->size(); k++){
171  const HcalQIESample QIE = theDigis->sample(k);
172  if(k>=theDigis->presamples()&&k<theDigis->presamples()+SamplesToAdd)SumDigiCharge+=QIE.nominal_fC();
173  if(k<theDigis->presamples()-1)EstimatedPedestal+=QIE.nominal_fC()*SamplesToAdd/(theDigis->presamples()-1);
174  cout << " Digi: " << k << ", cap ID = " << QIE.capid() << ": ADC Counts = " << QIE.adc() << ", nominal fC = " << QIE.nominal_fC() <<endl;
175  }
176  if(Dump>=4)cout << " 4 Digi fC ="<<SumDigiCharge<<", est. ped. fC="<<EstimatedPedestal<<", est. GeV/fc="<<theRecHit->energy()/(SumDigiCharge-EstimatedPedestal) << endl;
177  if(Dump>=4)cout << " ......................................"<<endl;
178  }
179  else if( HcalNum == HcalEndcap ){
180  HBHERecHitCollection::const_iterator theRecHit=HBHERecHits->find(HcalID);
181  if( (abs(HcalID.ieta())==28||abs(HcalID.ieta())==29)&&HcalID.depth()==3){
182  sumRecHitE += theRecHit->energy()/2; //Depth 3 split over tower 28 & 29
183  }
184  else{
185  sumRecHitE += theRecHit->energy();
186  }
187  HBHEDigiCollection::const_iterator theDigis=HBHEDigis->find(HcalID);
188  cout << " RecHit: " << j << ": HE, ieta=" << HcalID.ieta() << ", iphi=" << HcalID.iphi()<<
189  ", depth=" << HcalID.depth() << ", energy=" << theRecHit->energy() << ", time=" <<\
190  theRecHit->time() <<", All Digis=" << theDigis->size() << ", presamples =" <<\
191  theDigis->presamples() <<endl;
192  float SumDigiCharge = 0.0;
193  float EstimatedPedestal=0.0;
194  int SamplesToAdd = 4;
195  if(Dump>=4)cout << " ......................................"<<endl;
196  if(Dump>=4)for(int k=0; k<theDigis->size(); k++){
197  const HcalQIESample QIE = theDigis->sample(k);
198  if(k>=theDigis->presamples()&&k<theDigis->presamples()+SamplesToAdd)SumDigiCharge+=QIE.nominal_fC();
199  if(k<theDigis->presamples()-1)EstimatedPedestal+=QIE.nominal_fC()*SamplesToAdd/(theDigis->presamples()-1);
200  cout << " Digi: " << k << ", cap ID = " << QIE.capid() << ": ADC Counts = " << QIE.adc() << ", nominal fC = " << QIE.nominal_fC() <<endl;
201  }
202  if(Dump>=4)cout << " 4 Digi fC ="<<SumDigiCharge<<", est. ped. fC="<<EstimatedPedestal<<", est. GeV/fc="<<theRecHit->energy()/(SumDigiCharge-EstimatedPedestal) << endl;
203  if(Dump>=4)cout << " ......................................"<<endl;
204  }
205  else if( HcalNum == HcalOuter ){
206  HORecHitCollection::const_iterator theRecHit=HORecHits->find(HcalID);
207  sumRecHitE += theRecHit->energy();
208  HODigiCollection::const_iterator theDigis=HODigis->find(HcalID);
209  cout << " RecHit: " << j << ": HO, ieta=" << HcalID.ieta() << ", iphi=" << HcalID.iphi()<<
210  ", depth=" << HcalID.depth() << ", energy=" << theRecHit->energy() << ", time=" <<\
211  theRecHit->time() <<", All Digis=" << theDigis->size() << ", presamples =" <<\
212  theDigis->presamples() <<endl;
213  float SumDigiCharge = 0.0;
214  float EstimatedPedestal=0.0;
215  int SamplesToAdd = 4;
216  if(Dump>=4)cout << " ......................................"<<endl;
217  if(Dump>=4)for(int k=0; k<theDigis->size(); k++){
218  const HcalQIESample QIE = theDigis->sample(k);
219  if(k>=theDigis->presamples()&&k<theDigis->presamples()+SamplesToAdd)SumDigiCharge+=QIE.nominal_fC();
220  if(k<theDigis->presamples()-1)EstimatedPedestal+=QIE.nominal_fC()*SamplesToAdd/(theDigis->presamples()-1);
221  cout << " Digi: " << k << ", cap ID = " << QIE.capid() << ": ADC Counts = " << QIE.adc() << ", nominal fC = " << QIE.nominal_fC() <<endl;
222  }
223  if(Dump>=4)cout << " 4 Digi fC ="<<SumDigiCharge<<", est. ped. fC="<<EstimatedPedestal<<", est. GeV/fc="<<theRecHit->energy()/(SumDigiCharge-EstimatedPedestal) << endl;
224  if(Dump>=4)cout << " ......................................"<<endl;
225  }
226  else if( HcalNum == HcalForward ){
227  HFRecHitCollection::const_iterator theRecHit=HFRecHits->find(HcalID);
228  sumRecHitE += theRecHit->energy();
229  HFDigiCollection::const_iterator theDigis=HFDigis->find(HcalID);
230  cout << " RecHit: " << j << ": HF, ieta=" << HcalID.ieta() << ", iphi=" << HcalID.iphi()<<
231  ", depth=" << HcalID.depth() << ", energy=" << theRecHit->energy() << ", time=" <<\
232  theRecHit->time() <<", All Digis=" << theDigis->size() << ", presamples =" <<\
233  theDigis->presamples() <<endl;
234  float SumDigiCharge = 0.0;
235  float EstimatedPedestal=0.0;
236  int SamplesToAdd = 1;
237  if(Dump>=4)cout << " ......................................"<<endl;
238  if(Dump>=4)for(int k=0; k<theDigis->size(); k++){
239  const HcalQIESample QIE = theDigis->sample(k);
240  if(k>=theDigis->presamples()&&k<theDigis->presamples()+SamplesToAdd)SumDigiCharge+=QIE.nominal_fC();
241  if(k<theDigis->presamples()-1)EstimatedPedestal+=QIE.nominal_fC()*SamplesToAdd/(theDigis->presamples()-1);
242  cout << " Digi: " << k << ", cap ID = " << QIE.capid() << ": ADC Counts = " << QIE.adc() << ", nominal fC = " << QIE.nominal_fC() <<endl;
243  }
244  if(Dump>=4)cout << " 1 Digi fC ="<<SumDigiCharge<<", est. ped. fC="<<EstimatedPedestal<<", est. GeV/fc="<<theRecHit->energy()/(SumDigiCharge-EstimatedPedestal) << endl;
245  if(Dump>=4)cout << " ......................................"<<endl;
246  }
247  }
248  if( ShowECal && DetNum == DetId::Ecal ){
249  int EcalNum = RecHitDetID.subdetId();
250  if( EcalNum == 1 ){
251  EBDetId EcalID = RecHitDetID;
252  EBRecHitCollection::const_iterator theRecHit=EBRecHits->find(EcalID);
253  EBDigiCollection::const_iterator theDigis=EBDigis->find(EcalID);
254  sumRecHitE += theRecHit->energy();
255  cout << " RecHit " << j << ": EB, ieta=" << EcalID.ieta() << ", iphi=" << EcalID.iphi() << ", SM=" << EcalID.ism() << ", energy=" << theRecHit->energy() <<", All Digis=" << theDigis->size()<< endl;
256  if(Dump>=4)cout << " ......................................"<<endl;
257  if(Dump>=4)for(unsigned int k=0; k<theDigis->size(); k++){
258  EBDataFrame frame (*theDigis);
259  const EcalMGPASample MGPA = frame.sample(k);
260  cout << " Digi: " << k << ": ADC Sample = " << MGPA.adc() << ", Gain ID = "<< MGPA.gainId() <<endl;
261  }
262  if(Dump>=4)cout << " ......................................"<<endl;
263  }
264  else if( EcalNum == 2 ){
265  EEDetId EcalID = RecHitDetID;
266  EERecHitCollection::const_iterator theRecHit=EERecHits->find(EcalID);
267  EEDigiCollection::const_iterator theDigis=EEDigis->find(EcalID);
268  sumRecHitE += theRecHit->energy();
269  cout << " RecHit " << j << ": EE, ix=" << EcalID.ix() << ", iy=" << EcalID.iy() << ", energy=" << theRecHit->energy() << ", All Digis=" << theDigis->size()<< endl;
270  if(Dump>=4)cout << " ......................................"<<endl;
271  if(Dump>=4)for(unsigned int k=0; k<theDigis->size(); k++){
272  EEDataFrame frame (*theDigis);
273  const EcalMGPASample MGPA = frame.sample(k);
274  cout << " Digi: " << k << ": ADC Sample = " << MGPA.adc() << ", Gain ID = "<< MGPA.gainId() <<endl;
275  }
276  if(Dump>=4)cout << " ......................................"<<endl;
277  }
278  }
279  }
280  if(Dump>=3){
281  if( abs(ietaTower)==28||abs(ietaTower)==29){
282  cout << " Splitted Sum of RecHit Energies=" << sumRecHitE <<", CaloTower energy=" << theTower->energy() << endl;
283  }
284  else{
285  cout << " Sum of RecHit Energies=" << sumRecHitE <<", CaloTower energy=" << theTower->energy() << endl;
286  }
287  }
288  if(Dump>=3)cout << " ------------------------------------------------"<<endl;
289  }
290  if(Dump>=2)cout << " Sum of tower energies=" << sumTowerE << ", CaloJet energy=" << jet->energy() << endl;
291  jetInd++;
292  if(Dump>=2)cout <<" ====================================================="<<endl;
293  }
294  evtCount++;
295  if(Dump>=1)cout <<" *********************************************************" <<endl;
296 
297 }
298 
300 
301 
302 }
int ix() const
Definition: EEDetId.h:76
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:49
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
int adc() const
get the ADC sample
Definition: HcalQIESample.h:22
std::vector< CaloTower >::const_iterator const_iterator
EcalMGPASample sample(int i) const
Definition: EcalDataFrame.h:29
int gainId() const
get the gainId (2 bits)
int ism() const
get the ECAL/SM id
Definition: EBDetId.h:61
int iphi() const
get the crystal iphi
Definition: EBDetId.h:53
std::string CaloJetAlg
Definition: JetToDigiDump.h:27
const_iterator find(id_type i) const
int depth() const
get the tower depth
Definition: HcalDetId.cc:108
int ieta() const
get the cell ieta
Definition: HcalDetId.h:56
HcalSubdetector
Definition: HcalAssistant.h:31
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int iy() const
Definition: EEDetId.h:82
int ieta() const
get the crystal ieta
Definition: EBDetId.h:51
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:413
int k[5][pyjets_maxn]
const_iterator end() const
int iphi() const
get the cell iphi
Definition: HcalDetId.cc:103
Definition: DetId.h:18
int capid() const
get the Capacitor id
Definition: HcalQIESample.h:26
Detector
Definition: DetId.h:24
double nominal_fC() const
get the nominal FC (no calibrations applied)
iterator find(key_type k)
fixed size matrix
HLT enums.
size_type size() const
void analyze(const edm::Event &, const edm::EventSetup &)
std::string DumpLevel
Definition: JetToDigiDump.h:26
Detector det() const
get the detector field from this detid
Definition: DetId.h:35
JetToDigiDump(const edm::ParameterSet &)
int adc() const
get the ADC sample (12 bits)