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