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
27 #include "EcalTrigPrimAnalyzer.h"
28 
29 #include <TMath.h>
30 
32 
34  : recHits_(iConfig.getParameter<bool>("AnalyzeRecHits")),
35  label_(iConfig.getParameter<edm::InputTag>("inputTP")),
36  rechits_labelEB_(iConfig.getParameter<edm::InputTag>("inputRecHitsEB")),
37  rechits_labelEE_(iConfig.getParameter<edm::InputTag>("inputRecHitsEE")),
38  tpToken_(consumes<EcalTrigPrimDigiCollection>(label_)),
39  ebToken_(consumes<EcalRecHitCollection>(rechits_labelEB_)),
40  eeToken_(consumes<EcalRecHitCollection>(rechits_labelEE_)),
41  tokens_(consumesCollector()) {
42  usesResource(TFileService::kSharedResource);
43 
44  ecal_parts_.push_back("Barrel");
45  ecal_parts_.push_back("Endcap");
46 
48  tree_ = fs->make<TTree>("TPGtree", "TPGtree");
49  tree_->Branch("iphi", &iphi_, "iphi/I");
50  tree_->Branch("ieta", &ieta_, "ieta/I");
51  tree_->Branch("eRec", &eRec_, "eRec/F");
52  tree_->Branch("tpgADC", &tpgADC_, "tpgADC/I");
53  tree_->Branch("tpgGeV", &tpgGeV_, "tpgGeV/F");
54  tree_->Branch("ttf", &ttf_, "ttf/I");
55  tree_->Branch("fg", &fg_, "fg/I");
56  for (unsigned int i = 0; i < 2; ++i) {
57  ecal_et_[i] = fs->make<TH1I>(ecal_parts_[i].c_str(), "Et", 255, 0, 255);
58  char title[30];
59  sprintf(title, "%s_ttf", ecal_parts_[i].c_str());
60  ecal_tt_[i] = fs->make<TH1I>(title, "TTF", 10, 0, 10);
61  sprintf(title, "%s_fgvb", ecal_parts_[i].c_str());
62  ecal_fgvb_[i] = fs->make<TH1I>(title, "FGVB", 10, 0, 10);
63  }
64 
65  if (recHits_) {
66  hTPvsRechit_ = fs->make<TH2F>("TP_vs_RecHit", "TP vs rechit", 256, -1, 255, 255, 0, 255);
67  hTPoverRechit_ = fs->make<TH1F>("TP_over_RecHit", "TP over rechit", 500, 0, 4);
68  endcapGeomToken_ = esConsumes<CaloSubdetectorGeometry, EcalEndcapGeometryRecord>(edm::ESInputTag("", "EcalEndcap"));
69  barrelGeomToken_ = esConsumes<CaloSubdetectorGeometry, EcalBarrelGeometryRecord>(edm::ESInputTag("", "EcalBarrel"));
70  eTTmapToken_ = esConsumes<EcalTrigTowerConstituentsMap, IdealGeometryRecord>();
71  }
72 }
73 
74 //
75 // member functions
76 //
77 
78 // ------------ method called to analyze the data ------------
80  // Get input
81  const auto &tp = iEvent.get(tpToken_);
82  for (unsigned int i = 0; i < tp.size(); i++) {
83  const EcalTriggerPrimitiveDigi &d = tp[i];
84  int subdet = d.id().subDet() - 1;
85  if (subdet == 0) {
86  ecal_et_[subdet]->Fill(d.compressedEt());
87  } else {
88  if (d.id().ietaAbs() == 27 || d.id().ietaAbs() == 28) {
89  if (i % 2)
90  ecal_et_[subdet]->Fill(d.compressedEt() * 2.);
91  } else
92  ecal_et_[subdet]->Fill(d.compressedEt());
93  }
94  ecal_tt_[subdet]->Fill(d.ttFlag());
95  ecal_fgvb_[subdet]->Fill(d.fineGrain());
96  }
97  if (!recHits_)
98  return;
99 
100  // comparison with RecHits
101  const EcalRecHitCollection &rechit_EB_col = iEvent.get(ebToken_);
102  const EcalRecHitCollection &rechit_EE_col = iEvent.get(eeToken_);
103 
104  const auto &theEndcapGeometry = iSetup.getData(endcapGeomToken_);
105  const auto &theBarrelGeometry = iSetup.getData(barrelGeomToken_);
106  const auto &eTTmap = iSetup.getData(eTTmapToken_);
107 
108  std::map<EcalTrigTowerDetId, float> mapTow_Et;
109 
110  for (unsigned int i = 0; i < rechit_EB_col.size(); i++) {
111  const EBDetId &myid1 = rechit_EB_col[i].id();
112  EcalTrigTowerDetId towid1 = myid1.tower();
113  float theta = theBarrelGeometry.getGeometry(myid1)->getPosition().theta();
114  float Etsum = rechit_EB_col[i].energy() * sin(theta);
115  bool test_alreadyin = false;
116  std::map<EcalTrigTowerDetId, float>::iterator ittest = mapTow_Et.find(towid1);
117  if (ittest != mapTow_Et.end())
118  test_alreadyin = true;
119  if (test_alreadyin)
120  continue;
121  unsigned int j = i + 1;
122  bool loopend = false;
123  unsigned int count = 0;
124  while (j < rechit_EB_col.size() && !loopend) {
125  count++;
126  const EBDetId &myid2 = rechit_EB_col[j].id();
127  EcalTrigTowerDetId towid2 = myid2.tower();
128  if (towid1 == towid2) {
129  float theta = theBarrelGeometry.getGeometry(myid2)->getPosition().theta();
130  Etsum += rechit_EB_col[j].energy() * sin(theta);
131  }
132  j++;
133  if (count > 1800)
134  loopend = true;
135  }
136  mapTow_Et.insert(std::pair<EcalTrigTowerDetId, float>(towid1, Etsum));
137  }
138 
139  for (unsigned int i = 0; i < rechit_EE_col.size(); i++) {
140  const EEDetId &myid1 = rechit_EE_col[i].id();
141  EcalTrigTowerDetId towid1 = eTTmap.towerOf(myid1);
142  float theta = theEndcapGeometry.getGeometry(myid1)->getPosition().theta();
143  float Etsum = rechit_EE_col[i].energy() * sin(theta);
144  bool test_alreadyin = false;
145  std::map<EcalTrigTowerDetId, float>::iterator ittest = mapTow_Et.find(towid1);
146  if (ittest != mapTow_Et.end())
147  test_alreadyin = true;
148  if (test_alreadyin)
149  continue;
150  unsigned int j = i + 1;
151  bool loopend = false;
152  unsigned int count = 0;
153  while (j < rechit_EE_col.size() && !loopend) {
154  const EEDetId &myid2 = rechit_EE_col[j].id();
155  EcalTrigTowerDetId towid2 = eTTmap.towerOf(myid2);
156  if (towid1 == towid2) {
157  float theta = theEndcapGeometry.getGeometry(myid2)->getPosition().theta();
158  Etsum += rechit_EE_col[j].energy() * sin(theta);
159  }
160  // else loopend=true;
161  j++;
162  if (count > 500)
163  loopend = true;
164  }
165  // alreadyin_EE.push_back(towid1);
166  mapTow_Et.insert(std::pair<EcalTrigTowerDetId, float>(towid1, Etsum));
167  }
168 
169  EcalTPGScale ecalScale(tokens_, iSetup);
170  for (unsigned int i = 0; i < tp.size(); i++) {
171  const EcalTriggerPrimitiveDigi &d = tp[i];
172  const EcalTrigTowerDetId TPtowid = d.id();
173  std::map<EcalTrigTowerDetId, float>::iterator it = mapTow_Et.find(TPtowid);
174  float Et = ecalScale.getTPGInGeV(d.compressedEt(), TPtowid);
175  if (d.id().ietaAbs() == 27 || d.id().ietaAbs() == 28)
176  Et *= 2;
177  iphi_ = TPtowid.iphi();
178  ieta_ = TPtowid.ieta();
179  tpgADC_ = d.compressedEt();
180  tpgGeV_ = Et;
181  ttf_ = d.ttFlag();
182  fg_ = d.fineGrain();
183  if (it != mapTow_Et.end()) {
184  hTPvsRechit_->Fill(it->second, Et);
185  hTPoverRechit_->Fill(Et / it->second);
186  eRec_ = it->second;
187  }
188  tree_->Fill();
189  }
190 }
static const std::string kSharedResource
Definition: TFileService.h:76
const edm::EDGetTokenT< EcalTrigPrimDigiCollection > tpToken_
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
int ieta() const
get the tower ieta
size_type size() const
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
void analyze(const edm::Event &, const edm::EventSetup &) override
edm::ESGetToken< CaloSubdetectorGeometry, EcalBarrelGeometryRecord > barrelGeomToken_
int iEvent
Definition: GenABIO.cc:224
edm::ESGetToken< CaloSubdetectorGeometry, EcalEndcapGeometryRecord > endcapGeomToken_
std::vector< std::string > ecal_parts_
const edm::EDGetTokenT< EcalRecHitCollection > eeToken_
d
Definition: ztail.py:151
edm::ESGetToken< EcalTrigTowerConstituentsMap, IdealGeometryRecord > eTTmapToken_
std::vector< edm::EDGetTokenT< int > > tokens_
EcalTrigPrimAnalyzer(const edm::ParameterSet &)
EcalTPGScale::Tokens tokens_
double getTPGInGeV(const EcalTriggerPrimitiveDigi &tpDigi) const
Definition: EcalTPGScale.cc:17
HLT enums.
const edm::EDGetTokenT< EcalRecHitCollection > ebToken_
EcalTrigTowerDetId tower() const
get the HCAL/trigger iphi of this crystal
Definition: EBDetId.h:57
int iphi() const
get the tower iphi
Geom::Theta< T > theta() const