CMS 3D CMS Logo

EcalTrigPrimAnalyzer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Class: EcalTrigPrimAnalyzer
4 //
10 //
11 //
12 // Original Author: Ursula Berthon, Stephanie Baffioni, Pascal Paganini
13 // Created: Thu Jul 4 11:38:38 CEST 2005
14 //
15 //
16 
17 // system include files
18 #include <memory>
19 #include <utility>
20 
21 // user include files
25 
30 
35 
40 
42 
43 #include "EcalTrigPrimAnalyzer.h"
44 
45 #include <TMath.h>
46 
47 using namespace edm;
49 
51 
52 {
53  ecal_parts_.push_back("Barrel");
54  ecal_parts_.push_back("Endcap");
55 
56  histfile_ = new TFile("histos.root", "RECREATE");
57  tree_ = new TTree("TPGtree", "TPGtree");
58  tree_->Branch("iphi", &iphi_, "iphi/I");
59  tree_->Branch("ieta", &ieta_, "ieta/I");
60  tree_->Branch("eRec", &eRec_, "eRec/F");
61  tree_->Branch("tpgADC", &tpgADC_, "tpgADC/I");
62  tree_->Branch("tpgGeV", &tpgGeV_, "tpgGeV/F");
63  tree_->Branch("ttf", &ttf_, "ttf/I");
64  tree_->Branch("fg", &fg_, "fg/I");
65  for (unsigned int i = 0; i < 2; ++i) {
66  ecal_et_[i] = new TH1I(ecal_parts_[i].c_str(), "Et", 255, 0, 255);
67  char title[30];
68  sprintf(title, "%s_ttf", ecal_parts_[i].c_str());
69  ecal_tt_[i] = new TH1I(title, "TTF", 10, 0, 10);
70  sprintf(title, "%s_fgvb", ecal_parts_[i].c_str());
71  ecal_fgvb_[i] = new TH1I(title, "FGVB", 10, 0, 10);
72  }
73 
74  recHits_ = iConfig.getParameter<bool>("AnalyzeRecHits");
75  label_ = iConfig.getParameter<edm::InputTag>("inputTP");
76  if (recHits_) {
77  hTPvsRechit_ = new TH2F("TP_vs_RecHit", "TP vs rechit", 256, -1, 255, 255, 0, 255);
78  hTPoverRechit_ = new TH1F("TP_over_RecHit", "TP over rechit", 500, 0, 4);
79  rechits_labelEB_ = iConfig.getParameter<edm::InputTag>("inputRecHitsEB");
80  rechits_labelEE_ = iConfig.getParameter<edm::InputTag>("inputRecHitsEE");
81  }
82 }
83 
85  // do anything here that needs to be done at desctruction time
86  // (e.g. close files, deallocate resources etc.)
87 
88  histfile_->Write();
89  histfile_->Close();
90 }
91 
92 //
93 // member functions
94 //
95 
96 // ------------ method called to analyze the data ------------
98  using namespace edm;
99  using namespace std;
100 
101  // Get input
103  iEvent.getByLabel(label_, tp);
104  for (unsigned int i = 0; i < tp.product()->size(); i++) {
105  EcalTriggerPrimitiveDigi d = (*(tp.product()))[i];
106  int subdet = d.id().subDet() - 1;
107  if (subdet == 0) {
108  ecal_et_[subdet]->Fill(d.compressedEt());
109  } else {
110  if (d.id().ietaAbs() == 27 || d.id().ietaAbs() == 28) {
111  if (i % 2)
112  ecal_et_[subdet]->Fill(d.compressedEt() * 2.);
113  } else
114  ecal_et_[subdet]->Fill(d.compressedEt());
115  }
116  ecal_tt_[subdet]->Fill(d.ttFlag());
117  ecal_fgvb_[subdet]->Fill(d.fineGrain());
118  }
119  if (!recHits_)
120  return;
121 
122  // comparison with RecHits
123  edm::Handle<EcalRecHitCollection> rechit_EB_col;
124  iEvent.getByLabel(rechits_labelEB_, rechit_EB_col);
125 
126  edm::Handle<EcalRecHitCollection> rechit_EE_col;
127  iEvent.getByLabel(rechits_labelEE_, rechit_EE_col);
128 
129  edm::ESHandle<CaloGeometry> theGeometry;
130  edm::ESHandle<CaloSubdetectorGeometry> theBarrelGeometry_handle;
131  edm::ESHandle<CaloSubdetectorGeometry> theEndcapGeometry_handle;
132  iSetup.get<CaloGeometryRecord>().get(theGeometry);
133  iSetup.get<EcalEndcapGeometryRecord>().get("EcalEndcap", theEndcapGeometry_handle);
134  iSetup.get<EcalBarrelGeometryRecord>().get("EcalBarrel", theBarrelGeometry_handle);
135 
136  const CaloSubdetectorGeometry *theEndcapGeometry = theEndcapGeometry_handle.product();
137  const CaloSubdetectorGeometry *theBarrelGeometry = theBarrelGeometry_handle.product();
139  iSetup.get<IdealGeometryRecord>().get(eTTmap_);
140 
141  map<EcalTrigTowerDetId, float> mapTow_Et;
142 
143  for (unsigned int i = 0; i < rechit_EB_col.product()->size(); i++) {
144  const EBDetId &myid1 = (*rechit_EB_col.product())[i].id();
145  EcalTrigTowerDetId towid1 = myid1.tower();
146  float theta = theBarrelGeometry->getGeometry(myid1)->getPosition().theta();
147  float Etsum = ((*rechit_EB_col.product())[i].energy()) * sin(theta);
148  bool test_alreadyin = false;
149  map<EcalTrigTowerDetId, float>::iterator ittest = mapTow_Et.find(towid1);
150  if (ittest != mapTow_Et.end())
151  test_alreadyin = true;
152  if (test_alreadyin)
153  continue;
154  unsigned int j = i + 1;
155  bool loopend = false;
156  unsigned int count = 0;
157  while (j < rechit_EB_col.product()->size() && !loopend) {
158  count++;
159  const EBDetId &myid2 = (*rechit_EB_col.product())[j].id();
160  EcalTrigTowerDetId towid2 = myid2.tower();
161  if (towid1 == towid2) {
162  float theta = theBarrelGeometry->getGeometry(myid2)->getPosition().theta();
163  Etsum += (*rechit_EB_col.product())[j].energy() * sin(theta);
164  }
165  j++;
166  if (count > 1800)
167  loopend = true;
168  }
169  mapTow_Et.insert(pair<EcalTrigTowerDetId, float>(towid1, Etsum));
170  }
171 
172  for (unsigned int i = 0; i < rechit_EE_col.product()->size(); i++) {
173  const EEDetId &myid1 = (*rechit_EE_col.product())[i].id();
174  EcalTrigTowerDetId towid1 = (*eTTmap_).towerOf(myid1);
175  float theta = theEndcapGeometry->getGeometry(myid1)->getPosition().theta();
176  float Etsum = (*rechit_EE_col.product())[i].energy() * sin(theta);
177  bool test_alreadyin = false;
178  map<EcalTrigTowerDetId, float>::iterator ittest = mapTow_Et.find(towid1);
179  if (ittest != mapTow_Et.end())
180  test_alreadyin = true;
181  if (test_alreadyin)
182  continue;
183  unsigned int j = i + 1;
184  bool loopend = false;
185  unsigned int count = 0;
186  while (j < rechit_EE_col.product()->size() && !loopend) {
187  const EEDetId &myid2 = (*rechit_EE_col.product())[j].id();
188  EcalTrigTowerDetId towid2 = (*eTTmap_).towerOf(myid2);
189  if (towid1 == towid2) {
190  float theta = theEndcapGeometry->getGeometry(myid2)->getPosition().theta();
191  Etsum += (*rechit_EE_col.product())[j].energy() * sin(theta);
192  }
193  // else loopend=true;
194  j++;
195  if (count > 500)
196  loopend = true;
197  }
198  // alreadyin_EE.push_back(towid1);
199  mapTow_Et.insert(pair<EcalTrigTowerDetId, float>(towid1, Etsum));
200  }
201 
202  EcalTPGScale ecalScale;
203  ecalScale.setEventSetup(iSetup);
204  for (unsigned int i = 0; i < tp.product()->size(); i++) {
205  EcalTriggerPrimitiveDigi d = (*(tp.product()))[i];
206  const EcalTrigTowerDetId TPtowid = d.id();
207  map<EcalTrigTowerDetId, float>::iterator it = mapTow_Et.find(TPtowid);
208  float Et = ecalScale.getTPGInGeV(d.compressedEt(), TPtowid);
209  if (d.id().ietaAbs() == 27 || d.id().ietaAbs() == 28)
210  Et *= 2;
211  iphi_ = TPtowid.iphi();
212  ieta_ = TPtowid.ieta();
213  tpgADC_ = d.compressedEt();
214  tpgGeV_ = Et;
215  ttf_ = d.ttFlag();
216  fg_ = d.fineGrain();
217  if (it != mapTow_Et.end()) {
218  hTPvsRechit_->Fill(it->second, Et);
219  hTPoverRechit_->Fill(Et / it->second);
220  eRec_ = it->second;
221  }
222  tree_->Fill();
223  }
224 }
225 
227  for (unsigned int i = 0; i < 2; ++i) {
228  ecal_et_[i]->Write();
229  ecal_tt_[i]->Write();
230  ecal_fgvb_[i]->Write();
231  }
232  if (recHits_) {
233  hTPvsRechit_->Write();
234  hTPoverRechit_->Write();
235  }
236 }
EcalTPGScale::getTPGInGeV
double getTPGInGeV(const EcalTriggerPrimitiveDigi &tpDigi)
Definition: EcalTPGScale.cc:18
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
mps_fire.i
i
Definition: mps_fire.py:355
EcalTrigTowerDetId::iphi
int iphi() const
get the tower iphi
Definition: EcalTrigTowerDetId.h:52
EcalTPGScale
Definition: EcalTPGScale.h:8
edm::Handle::product
T const * product() const
Definition: Handle.h:70
ESHandle.h
CaloGeometryRecord
Definition: CaloGeometryRecord.h:30
EBDetId
Definition: EBDetId.h:17
edm
HLT enums.
Definition: AlignableModifier.h:19
EcalEndcapGeometryRecord
Definition: EcalEndcapGeometryRecord.h:23
EcalTrigPrimAnalyzer::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: EcalTrigPrimAnalyzer.cc:97
edm::SortedCollection::size
size_type size() const
Definition: SortedCollection.h:215
EDAnalyzer.h
EcalTPGScale::setEventSetup
void setEventSetup(const edm::EventSetup &evtSetup)
Definition: EcalTPGScale.cc:16
EcalTrigTowerDetId
Definition: EcalTrigTowerDetId.h:14
EcalTrigPrimAnalyzer::endJob
void endJob() override
Definition: EcalTrigPrimAnalyzer.cc:226
edm::Handle
Definition: AssociativeIterator.h:50
EcalBarrelGeometryRecord
Definition: EcalBarrelGeometryRecord.h:23
EcalRecHitCollections.h
EcalTriggerPrimitiveDigi.h
funct::sin
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
MakerMacros.h
EcalTrigPrimAnalyzer::~EcalTrigPrimAnalyzer
~EcalTrigPrimAnalyzer() override
Definition: EcalTrigPrimAnalyzer.cc:84
EBDetId::tower
EcalTrigTowerDetId tower() const
get the HCAL/trigger iphi of this crystal
Definition: EBDetId.h:57
edm::EventSetup::get
T get() const
Definition: EventSetup.h:73
EcalDigiCollections.h
edm::ESHandle< CaloGeometry >
theta
Geom::Theta< T > theta() const
Definition: Basic3DVectorLD.h:150
HCALHighEnergyHPDFilter_cfi.energy
energy
Definition: HCALHighEnergyHPDFilter_cfi.py:5
cmsswSequenceInfo.tp
tp
Definition: cmsswSequenceInfo.py:17
EEDetId
Definition: EEDetId.h:14
CaloGeometryRecord.h
CaloSubdetectorGeometry.h
edm::ParameterSet
Definition: ParameterSet.h:36
Event.h
KineDebug3::count
void count()
Definition: KinematicConstrainedVertexUpdatorT.h:21
edm::get
T const & get(Event const &event, InputTag const &tag) noexcept(false)
Definition: Event.h:669
iEvent
int iEvent
Definition: GenABIO.cc:224
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:57
EcalTrigTowerDetId::ieta
int ieta() const
get the tower ieta
Definition: EcalTrigTowerDetId.h:44
EcalRecHit.h
overlapproblemtsosanalyzer_cfi.title
title
Definition: overlapproblemtsosanalyzer_cfi.py:7
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
CaloCellGeometry.h
EcalTrigTowerConstituentsMap.h
std
Definition: JetResolutionObject.h:76
EcalTrigPrimAnalyzer.h
EcalTriggerPrimitiveDigi
Definition: EcalTriggerPrimitiveDigi.h:16
CaloGeometry.h
EcalTrigPrimAnalyzer::EcalTrigPrimAnalyzer
EcalTrigPrimAnalyzer(const edm::ParameterSet &)
Definition: EcalTrigPrimAnalyzer.cc:50
EventSetup.h
CaloSubdetectorGeometry
Definition: CaloSubdetectorGeometry.h:22
ztail.d
d
Definition: ztail.py:151
ParameterSet.h
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
edm::Event
Definition: Event.h:73
edm::InputTag
Definition: InputTag.h:15
IdealGeometryRecord
Definition: IdealGeometryRecord.h:27
EcalTPGScale.h