CMS 3D CMS Logo

EcalEBTrigPrimAnalyzer.cc
Go to the documentation of this file.
1 // system include files
2 #include <memory>
3 #include <utility>
4 
5 // user include files
9 
14 
16 
19 
21 
24 
25 //#include "CalibCalorimetry/EcalTPGTools/interface/EcalEBTPGScale.h"
26 
27 #include "EcalEBTrigPrimAnalyzer.h"
28 
29 #include <TMath.h>
30 
31 using namespace edm;
33 
35  : tokens_(consumesCollector())
36 
37 {
38  ecal_parts_.push_back("Barrel");
39 
40  histfile_ = new TFile("histos.root", "RECREATE");
41  tree_ = new TTree("TPGtree", "TPGtree");
42  tree_->Branch("tpIphi", &tpIphi_, "tpIphi/I");
43  tree_->Branch("tpIeta", &tpIeta_, "tpIeta/I");
44  tree_->Branch("rhIphi", &rhIphi_, "rhIphi/I");
45  tree_->Branch("rhIeta", &rhIeta_, "rhIeta/I");
46  tree_->Branch("eRec", &eRec_, "eRec/F");
47  tree_->Branch("tpgADC", &tpgADC_, "tpgADC/I");
48  tree_->Branch("tpgGeV", &tpgGeV_, "tpgGeV/F");
49  tree_->Branch("ttf", &ttf_, "ttf/I");
50  tree_->Branch("fg", &fg_, "fg/I");
51  for (unsigned int i = 0; i < ecal_parts_.size(); ++i) {
52  char title[30];
53  sprintf(title, "%s_Et", ecal_parts_[i].c_str());
54  ecal_et_[i] = new TH1I(title, "Et", 255, 0, 255);
55  sprintf(title, "%s_ttf", ecal_parts_[i].c_str());
56  ecal_tt_[i] = new TH1I(title, "TTF", 10, 0, 10);
57  sprintf(title, "%s_fgvb", ecal_parts_[i].c_str());
58  ecal_fgvb_[i] = new TH1I(title, "FGVB", 10, 0, 10);
59  }
60  eTTmapToken_ = esConsumes<EcalTrigTowerConstituentsMap, IdealGeometryRecord>();
61  recHits_ = iConfig.getParameter<bool>("AnalyzeRecHits");
62  debug_ = iConfig.getParameter<bool>("Debug");
63  rechits_labelEB_ = consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("inputRecHitsEB"));
64  primToken_ = consumes<EcalEBTrigPrimDigiCollection>(iConfig.getParameter<edm::InputTag>("inputTP"));
65  barrelGeomToken_ = esConsumes<CaloSubdetectorGeometry, EcalBarrelGeometryRecord>(edm::ESInputTag("", "EcalBarrel"));
66  tokenEBdigi_ = consumes<EBDigiCollection>(iConfig.getParameter<edm::InputTag>("barrelEcalDigis"));
67  nEvents_ = 0;
68 
69  hTPvsTow_eta_ = new TH2F("TP_vs_Tow_eta", "TP vs Tow eta ; #eta(tow); #eta(tp)", 50, -2.5, 2.5, 50, -2.5, 2.5);
70  hAllTPperEvt_ = new TH1F("AllTPperEvt", "TP per Event; N_{TP}; ", 100, 0., 20000.);
71  hTPperEvt_ = new TH1F("TPperEvt", "N_{TP} per Event; N_{TP}; ", 100, 0., 500.);
72  hTP_iphiVsieta_ = new TH2F("TP_iphiVsieta", "TP i#phi vs i#eta ; i#eta(tp); i#phi(tp)", 10, 70, 80, 10, 340, 350);
74  new TH2F("TP_iphiVsieta_fullrange", "TP i#phi vs i#eta ; i#eta(tp); i#phi(tp)", 200, -100, 100, 350, 0, 350);
75 
76  if (recHits_) {
78  new TH2F("TP_vs_Tow_ieta", "TP vs Tow ieta ; i#eta(tow); i#eta(tp)", 200, -100, 100, 200, -100, 100);
79 
80  hTPvsRechit_ = new TH2F("TP_vs_RecHit", "TP vs rechit Et;E_{T}(rh) (GeV);E_{T}(tp) (GeV)", 100, 0, 50, 100, 0, 50);
81  hDeltaEt_ = new TH1F("DeltaEt", "[Et(rh)-Et(TP)]/Et(rh); [E_{T}(rh)-E_{T}(tp)]/E_{T}(rh); Counts", 200, -1, 1);
82  hTPoverRechit_ = new TH1F("TP_over_RecHit", "Et(TP/rechit); E_{T}(tp)/E_{T}(rh); Counts", 200, 0, 2);
83  hRechitEt_ = new TH1F("RecHitEt", "E_{T};E_{T}(rh) (GeV);Counts", 100, 0, 50);
84  hTPEt_ = new TH1F("TPEt", "E_{T}{tp);E_{T}(rh) (GeV);Count", 100, 0, 50);
85  hRatioEt_ = new TH1F("RatioTPoverRH", "Et", 100, 0, 50);
86  hAllRechitEt_ = new TH1F("AllRecHit", "Et", 100, 0, 50);
87 
88  hRH_iphiVsieta_ = new TH2F("RH_iphiVsieta", "RH i#phi vs i#eta ; i#eta(rh); i#phi(rh)", 10, 70, 80, 10, 340, 350);
90  new TH2F("RH_iphiVsieta_fullrange", "RH i#phi vs i#eta ; i#eta(rh); i#phi(rh)", 200, -100, 100, 350, 0, 350);
91  }
92 }
93 
95  // do anything here that needs to be done at desctruction time
96  // (e.g. close files, deallocate resources etc.)
97 
98  histfile_->Write();
99  histfile_->Close();
100 }
101 
103 
104 //
105 // member functions
106 //
107 
108 // ------------ method called to analyze the data ------------
110  using namespace edm;
111  using namespace std;
112  nEvents_++;
113 
114  if (nEvents_ == 1)
115  this->init(iSetup);
116 
117  // Get input
119  iEvent.getByToken(primToken_, tp);
120  //
121  /*
122  edm::Handle<EBDigiCollection> barrelDigiHandle;
123  const EBDigiCollection *ebdigi=NULL;
124  iEvent.getByToken(tokenEBdigi_,barrelDigiHandle);
125  ebdigi=barrelDigiHandle.product();
126  */
127 
128  for (unsigned int i = 0; i < tp.product()->size(); i++) {
129  EcalEBTriggerPrimitiveDigi d = (*(tp.product()))[i];
130  int subdet = 0;
131  if (subdet == 0) {
132  ecal_et_[subdet]->Fill(d.encodedEt());
133  }
134  }
135 
136  // if (!recHits_) return;
137 
138  edm::Handle<EcalRecHitCollection> rechit_EB_col;
139  if (recHits_) {
140  // get the RecHits
141  iEvent.getByToken(rechits_labelEB_, rechit_EB_col);
142  }
143 
144  edm::ESHandle<CaloSubdetectorGeometry> theBarrelGeometry_handle = iSetup.getHandle(barrelGeomToken_);
145  const CaloSubdetectorGeometry* theBarrelGeometry = theBarrelGeometry_handle.product();
146 
147  if (debug_) {
148  std::cout << " TP analyzer =================> Treating event " << iEvent.id() << " Number of TPs "
149  << tp.product()->size() << std::endl;
150  if (recHits_)
151  std::cout << " Number of EB rechits " << rechit_EB_col.product()->size() << std::endl;
152  }
153  hAllTPperEvt_->Fill(float(tp.product()->size()));
154 
155  //if ( iEvent.id().event() != 648) return;
156 
157  //EcalEBTPGScale ecalScale ;
158  EcalTPGScale ecalScale(tokens_, iSetup);
159 
160  // for(unsigned int iDigi = 0; iDigi < ebdigi->size() ; ++iDigi) {
161  // EBDataFrame myFrame((*ebdigi)[iDigi]);
162  // const EBDetId & myId = myFrame.id();
163 
164  int nTP = 0;
165  for (unsigned int i = 0; i < tp.product()->size(); i++) {
166  EcalEBTriggerPrimitiveDigi d = (*(tp.product()))[i];
167  const EBDetId TPid = d.id();
168  // if ( myId != TPid ) continue;
169 
170  /*
171  int index=getIndex(ebdigi,coarser);
172  std::cout << " Same xTal " << myId << " " << TPid << " coarser " << coarser << " index " << index << std::endl;
173  double Et = ecalScale.getTPGInGeV(d.encodedEt(), coarser) ;
174  */
175  //this works if the energy is compressed into 8 bits float Et=d.compressedEt()/2.; // 2ADC counts/GeV
176  float Et = d.encodedEt() / 8.; // 8 ADCcounts/GeV
177  if (Et <= 5)
178  continue;
179  //if ( Et<= 0 ) continue;
180  nTP++;
181 
182  std::cout << " TP digi size " << d.size() << std::endl;
183  for (int iBx = 0; iBx < d.size(); iBx++) {
184  std::cout << " TP samples " << d.sample(iBx) << std::endl;
185  }
186 
187  // EcalTrigTowerDetId coarser=(*eTTmap_).towerOf(myId);
188  // does not work float etaTow = theBarrelGeometry->getGeometry(coarser)->getPosition().theta();
189  // float etaTP = theBarrelGeometry->getGeometry(TPid)->getPosition().eta();
190  // does not work hTPvsTow_eta_->Fill ( etaTow, etaTP );
191  // hTPvsTow_ieta_->Fill ( coarser.ieta(), TPid.ieta() );
192 
193  tpIphi_ = TPid.iphi();
194  tpIeta_ = TPid.ieta();
195  tpgADC_ = d.encodedEt();
196  tpgGeV_ = Et;
197 
198  hTP_iphiVsieta_->Fill(TPid.ieta(), TPid.iphi(), Et);
199  hTP_iphiVsieta_fullrange_->Fill(TPid.ieta(), TPid.iphi(), Et);
200 
201  if (recHits_) {
202  for (unsigned int j = 0; j < rechit_EB_col.product()->size(); j++) {
203  const EBDetId& myid1 = (*rechit_EB_col.product())[j].id();
204  float theta = theBarrelGeometry->getGeometry(myid1)->getPosition().theta();
205  float rhEt = ((*rechit_EB_col.product())[j].energy()) * sin(theta);
206  if (myid1 == TPid) {
207  if (debug_)
208  std::cout << " Analyzer same cristal " << myid1 << " " << TPid << std::endl;
209  // if ( rhEt < 1.5 && Et > 10 ) {
210  // std::cout << " TP analyzer =================> Treating event "<<iEvent.id()<< ", Number of EB rechits "<< rechit_EB_col.product()->size() << " Number of TPs " << tp.product()->size() << std::endl;
211  //std::cout << " TP compressed et " << d.encodedEt() << " Et in GeV " << Et << " RH Et " << rhEt << " Et/rhEt " << Et/rhEt << std::endl;
212  //}
213 
214  //std::cout << " TP out " << d << std::endl;
215 
216  // for (int isam=0;isam< d.size();++isam) {
217  // std::cout << " d[isam].raw() " << d[isam].raw() << std::endl;
218  //}
219 
220  rhIphi_ = myid1.iphi();
221  rhIeta_ = myid1.ieta();
222  hRH_iphiVsieta_->Fill(myid1.ieta(), myid1.iphi(), rhEt);
223  hRH_iphiVsieta_fullrange_->Fill(myid1.ieta(), myid1.iphi(), rhEt);
224 
225  hTPvsRechit_->Fill(rhEt, Et);
226  hTPoverRechit_->Fill(Et / rhEt);
227  hDeltaEt_->Fill((rhEt - Et) / rhEt);
228  if (debug_)
229  std::cout << " TP compressed et " << d.encodedEt() << " Et in GeV " << Et << " RH Et " << rhEt
230  << " Et/rhEt " << Et / rhEt << std::endl;
231  hRechitEt_->Fill(rhEt);
232  hTPEt_->Fill(Et);
233  if (rhEt < 1000000)
234  eRec_ = rhEt;
235  tree_->Fill();
236  }
237 
238  } // end loop of recHits
239  } // if recHits
240 
241  } // end loop over TP collection
242 
243  // } // end loop over digi collection
244 
245  hTPperEvt_->Fill(float(nTP));
246 
247  if (recHits_) {
248  hRatioEt_->Divide(hTPEt_, hRechitEt_);
249  for (unsigned int j = 0; j < rechit_EB_col.product()->size(); j++) {
250  const EBDetId& myid1 = (*rechit_EB_col.product())[j].id();
251  float theta = theBarrelGeometry->getGeometry(myid1)->getPosition().theta();
252  float rhEt = ((*rechit_EB_col.product())[j].energy()) * sin(theta);
253  if (rhEt > 0)
254  hAllRechitEt_->Fill(rhEt);
255  }
256  }
257 }
258 
260  for (unsigned int i = 0; i < ecal_parts_.size(); ++i) {
261  ecal_et_[i]->Write();
262  ecal_tt_[i]->Write();
263  ecal_fgvb_[i]->Write();
264  }
265 
266  hAllTPperEvt_->Write();
267  hTPperEvt_->Write();
268 
269  if (recHits_) {
270  hTPvsTow_ieta_->Write();
271  hTPvsTow_eta_->Write();
272  hTPvsRechit_->Write();
273  hTPoverRechit_->Write();
274  hAllRechitEt_->Write();
275  hRechitEt_->Write();
276  hDeltaEt_->Write();
277  hTPEt_->Write();
278  hRatioEt_->Write();
279  hTP_iphiVsieta_->Write();
280  hRH_iphiVsieta_->Write();
281  hTP_iphiVsieta_fullrange_->Write();
282  hRH_iphiVsieta_fullrange_->Write();
283  }
284 }
EcalEBTrigPrimAnalyzer::tpgADC_
int tpgADC_
Definition: EcalEBTrigPrimAnalyzer.h:66
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
EcalEBTrigPrimAnalyzer::eTTmapToken_
edm::ESGetToken< EcalTrigTowerConstituentsMap, IdealGeometryRecord > eTTmapToken_
Definition: EcalEBTrigPrimAnalyzer.h:77
EcalEBTrigPrimAnalyzer::histfile_
TFile * histfile_
Definition: EcalEBTrigPrimAnalyzer.h:47
EcalEBTrigPrimAnalyzer::hTPvsTow_ieta_
TH2F * hTPvsTow_ieta_
Definition: EcalEBTrigPrimAnalyzer.h:57
runGCPTkAlMap.title
string title
Definition: runGCPTkAlMap.py:94
EBDetId::ieta
int ieta() const
get the crystal ieta
Definition: EBDetId.h:49
mps_fire.i
i
Definition: mps_fire.py:428
edm::ESInputTag
Definition: ESInputTag.h:87
EcalEBTrigPrimAnalyzer::EcalEBTrigPrimAnalyzer
EcalEBTrigPrimAnalyzer(const edm::ParameterSet &)
Definition: EcalEBTrigPrimAnalyzer.cc:34
EcalTPGScale
Definition: EcalTPGScale.h:16
edm::Handle::product
T const * product() const
Definition: Handle.h:70
EcalEBTrigPrimAnalyzer::hTPoverRechit_
TH1F * hTPoverRechit_
Definition: EcalEBTrigPrimAnalyzer.h:51
ESHandle.h
EcalEBTrigPrimAnalyzer::rhIphi_
int rhIphi_
Definition: EcalEBTrigPrimAnalyzer.h:67
EBDetId
Definition: EBDetId.h:17
edm
HLT enums.
Definition: AlignableModifier.h:19
gather_cfg.cout
cout
Definition: gather_cfg.py:144
EcalEBTrigPrimAnalyzer::tpIeta_
int tpIeta_
Definition: EcalEBTrigPrimAnalyzer.h:66
EcalEBTrigPrimAnalyzer::nEvents_
int nEvents_
Definition: EcalEBTrigPrimAnalyzer.h:38
edm::SortedCollection::size
size_type size() const
Definition: SortedCollection.h:215
EcalEBTrigPrimAnalyzer::hTP_iphiVsieta_
TH2F * hTP_iphiVsieta_
Definition: EcalEBTrigPrimAnalyzer.h:59
EDAnalyzer.h
EcalEBTrigPrimAnalyzer::init
void init(const edm::EventSetup &)
Definition: EcalEBTrigPrimAnalyzer.cc:102
edm::Handle
Definition: AssociativeIterator.h:50
EcalRecHitCollections.h
EcalEBTrigPrimAnalyzer::hAllRechitEt_
TH1F * hAllRechitEt_
Definition: EcalEBTrigPrimAnalyzer.h:53
EcalEBTrigPrimAnalyzer::ecal_fgvb_
TH1I * ecal_fgvb_[2]
Definition: EcalEBTrigPrimAnalyzer.h:45
EcalEBTrigPrimAnalyzer::rhIeta_
int rhIeta_
Definition: EcalEBTrigPrimAnalyzer.h:67
funct::sin
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
EcalEBTrigPrimAnalyzer::hTPEt_
TH1F * hTPEt_
Definition: EcalEBTrigPrimAnalyzer.h:55
EcalEBTrigPrimAnalyzer::ttf_
int ttf_
Definition: EcalEBTrigPrimAnalyzer.h:66
EcalEBTrigPrimAnalyzer::hRatioEt_
TH1F * hRatioEt_
Definition: EcalEBTrigPrimAnalyzer.h:56
MakerMacros.h
EcalEBTrigPrimAnalyzer::recHits_
bool recHits_
Definition: EcalEBTrigPrimAnalyzer.h:74
EcalEBTrigPrimAnalyzer::eTTmap_
edm::ESHandle< EcalTrigTowerConstituentsMap > eTTmap_
Definition: EcalEBTrigPrimAnalyzer.h:76
EcalEBTrigPrimAnalyzer::ecal_parts_
std::vector< std::string > ecal_parts_
Definition: EcalEBTrigPrimAnalyzer.h:42
EcalEBTrigPrimAnalyzer::hRH_iphiVsieta_fullrange_
TH2F * hRH_iphiVsieta_fullrange_
Definition: EcalEBTrigPrimAnalyzer.h:62
EcalDigiCollections.h
EcalEBTrigPrimAnalyzer::tree_
TTree * tree_
Definition: EcalEBTrigPrimAnalyzer.h:64
edm::ESHandle< CaloSubdetectorGeometry >
tokens_
std::vector< edm::EDGetTokenT< int > > tokens_
Definition: TimeStudyModules.cc:75
EcalEBTrigPrimAnalyzer::hTPvsRechit_
TH2F * hTPvsRechit_
Definition: EcalEBTrigPrimAnalyzer.h:50
theta
Geom::Theta< T > theta() const
Definition: Basic3DVectorLD.h:150
EcalEBTrigPrimAnalyzer::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: EcalEBTrigPrimAnalyzer.cc:109
HCALHighEnergyHPDFilter_cfi.energy
energy
Definition: HCALHighEnergyHPDFilter_cfi.py:5
EcalRecHit.h
EcalEBTrigPrimAnalyzer::hDeltaEt_
TH1F * hDeltaEt_
Definition: EcalEBTrigPrimAnalyzer.h:52
cmsswSequenceInfo.tp
tp
Definition: cmsswSequenceInfo.py:17
EcalEBTrigPrimAnalyzer::tpIphi_
int tpIphi_
Definition: EcalEBTrigPrimAnalyzer.h:66
EcalEBTrigPrimAnalyzer::hRH_iphiVsieta_
TH2F * hRH_iphiVsieta_
Definition: EcalEBTrigPrimAnalyzer.h:60
CaloGeometryRecord.h
EcalEBTrigPrimAnalyzer::primToken_
edm::EDGetTokenT< EcalEBTrigPrimDigiCollection > primToken_
Definition: EcalEBTrigPrimAnalyzer.h:71
EcalEBTrigPrimAnalyzer::fg_
int fg_
Definition: EcalEBTrigPrimAnalyzer.h:66
EcalEBTrigPrimAnalyzer::hRechitEt_
TH1F * hRechitEt_
Definition: EcalEBTrigPrimAnalyzer.h:54
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
EcalEBTrigPrimAnalyzer::rechits_labelEB_
edm::EDGetTokenT< EcalRecHitCollection > rechits_labelEB_
Definition: EcalEBTrigPrimAnalyzer.h:72
EcalEBTrigPrimAnalyzer::hAllTPperEvt_
TH1F * hAllTPperEvt_
Definition: EcalEBTrigPrimAnalyzer.h:48
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::EventSetup::getHandle
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:155
CaloSubdetectorGeometry::getGeometry
virtual std::shared_ptr< const CaloCellGeometry > getGeometry(const DetId &id) const
Get the cell geometry of a given detector id. Should return false if not found.
Definition: CaloSubdetectorGeometry.cc:36
edm::EventSetup
Definition: EventSetup.h:58
EcalEBTrigPrimAnalyzer::eRec_
float eRec_
Definition: EcalEBTrigPrimAnalyzer.h:68
EcalEBTrigPrimAnalyzer::tokens_
EcalTPGScale::Tokens tokens_
Definition: EcalEBTrigPrimAnalyzer.h:79
CaloCellGeometry.h
EcalTrigTowerConstituentsMap.h
EcalEBTrigPrimAnalyzer::barrelGeomToken_
edm::ESGetToken< CaloSubdetectorGeometry, EcalBarrelGeometryRecord > barrelGeomToken_
Definition: EcalEBTrigPrimAnalyzer.h:78
EcalEBTriggerPrimitiveDigi
Definition: EcalEBTriggerPrimitiveDigi.h:15
std
Definition: JetResolutionObject.h:76
EcalEBTrigPrimAnalyzer.h
EcalEBTrigPrimAnalyzer::tpgGeV_
float tpgGeV_
Definition: EcalEBTrigPrimAnalyzer.h:68
EcalEBTrigPrimAnalyzer::hTPvsTow_eta_
TH2F * hTPvsTow_eta_
Definition: EcalEBTrigPrimAnalyzer.h:58
CaloGeometry.h
EcalEBTrigPrimAnalyzer::ecal_et_
TH1I * ecal_et_[2]
Definition: EcalEBTrigPrimAnalyzer.h:43
EventSetup.h
CaloSubdetectorGeometry
Definition: CaloSubdetectorGeometry.h:22
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
EBDetId::iphi
int iphi() const
get the crystal iphi
Definition: EBDetId.h:51
ztail.d
d
Definition: ztail.py:151
EcalEBTrigPrimAnalyzer::debug_
bool debug_
Definition: EcalEBTrigPrimAnalyzer.h:75
ParameterSet.h
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
EcalEBTrigPrimAnalyzer::hTPperEvt_
TH1F * hTPperEvt_
Definition: EcalEBTrigPrimAnalyzer.h:49
edm::Event
Definition: Event.h:73
EcalEBTrigPrimAnalyzer::tokenEBdigi_
edm::EDGetTokenT< EBDigiCollection > tokenEBdigi_
Definition: EcalEBTrigPrimAnalyzer.h:73
EcalEBTrigPrimAnalyzer::endJob
void endJob() override
Definition: EcalEBTrigPrimAnalyzer.cc:259
EcalEBTrigPrimAnalyzer::hTP_iphiVsieta_fullrange_
TH2F * hTP_iphiVsieta_fullrange_
Definition: EcalEBTrigPrimAnalyzer.h:61
edm::InputTag
Definition: InputTag.h:15
EcalEBTrigPrimAnalyzer::~EcalEBTrigPrimAnalyzer
~EcalEBTrigPrimAnalyzer() override
Definition: EcalEBTrigPrimAnalyzer.cc:94
EcalEBTrigPrimAnalyzer::ecal_tt_
TH1I * ecal_tt_[2]
Definition: EcalEBTrigPrimAnalyzer.h:44