CMS 3D CMS Logo

EcalTPGAnalyzer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Class: EcalTPGAnalyzer
4 //
5 //
6 // Original Author: Pascal Paganini
7 //
8 //
9 
10 // system include files
11 #include <memory>
12 #include <utility>
13 
14 // user include files
16 
18 
19 #include "EcalTPGAnalyzer.h"
20 
21 #include <TMath.h>
22 #include <sstream>
23 
24 using namespace edm;
26 
28  : tpCollection_(iConfig.getParameter<edm::InputTag>("TPCollection")),
29  tpEmulatorCollection_(iConfig.getParameter<edm::InputTag>("TPEmulatorCollection")),
30  digiCollectionEB_(iConfig.getParameter<edm::InputTag>("DigiCollectionEB")),
31  digiCollectionEE_(iConfig.getParameter<edm::InputTag>("DigiCollectionEE")),
32  gtRecordCollectionTag_(iConfig.getParameter<std::string>("GTRecordCollection")),
33  l1GtReadoutRecordToken_(consumes<L1GlobalTriggerReadoutRecord>(edm::InputTag(gtRecordCollectionTag_))),
34  tpToken_(consumes<EcalTrigPrimDigiCollection>(tpCollection_)),
35  tpEmulToken_(consumes<EcalTrigPrimDigiCollection>(tpEmulatorCollection_)),
36  ebDigiToken_(consumes<EBDigiCollection>(digiCollectionEB_)),
37  eeDigiToken_(consumes<EEDigiCollection>(digiCollectionEE_)),
38  eTTMapToken_(esConsumes<edm::Transition::BeginRun>()),
39  ebGeometryToken_(esConsumes<edm::Transition::BeginRun>(edm::ESInputTag("", "EcalBarrel"))),
40  eeGeometryToken_(esConsumes<edm::Transition::BeginRun>(edm::ESInputTag("", "EcalEndcap"))),
41  l1GtMaskToken_(esConsumes()),
42  allowTP_(iConfig.getParameter<bool>("ReadTriggerPrimitives")),
43  useEE_(iConfig.getParameter<bool>("UseEndCap")),
44  print_(iConfig.getParameter<bool>("Print")) {
45  // file
46  file_ = new TFile("ECALTPGtree.root", "RECREATE");
47  file_->cd();
48 
49  // tree
50  tree_ = new TTree("EcalTPGAnalysis", "EcalTPGAnalysis");
51 
52  tree_->Branch("runNb", &treeVariables_.runNb, "runNb/i"); //
53  tree_->Branch("evtNb", &treeVariables_.evtNb, "evtNb/i"); //
54  tree_->Branch("bxNb", &treeVariables_.bxNb, "bxNb/i"); //
55  tree_->Branch("orbitNb", &treeVariables_.orbitNb, "orbitNb/i"); //
56  tree_->Branch("nbOfActiveTriggers", &treeVariables_.nbOfActiveTriggers, "nbOfActiveTriggers/i"); //
57  tree_->Branch("activeTriggers", treeVariables_.activeTriggers, "activeTriggers[nbOfActiveTriggers]/I"); //
58 
59  tree_->Branch("nbOfTowers", &treeVariables_.nbOfTowers, "nbOfTowers/i"); //
60  tree_->Branch("ieta", treeVariables_.ieta, "ieta[nbOfTowers]/I"); //
61  tree_->Branch("iphi", treeVariables_.iphi, "iphi[nbOfTowers]/I"); //
62  tree_->Branch("nbOfXtals", treeVariables_.nbOfXtals, "nbOfXtals[nbOfTowers]/I"); //
63  tree_->Branch("rawTPData", treeVariables_.rawTPData, "rawTPData[nbOfTowers]/I"); //
64  tree_->Branch("rawTPEmul1", treeVariables_.rawTPEmul1, "rawTPEmul1[nbOfTowers]/I"); //
65  tree_->Branch("rawTPEmul2", treeVariables_.rawTPEmul2, "rawTPEmul2[nbOfTowers]/I"); //
66  tree_->Branch("rawTPEmul3", treeVariables_.rawTPEmul3, "rawTPEmul3[nbOfTowers]/I"); //
67  tree_->Branch("rawTPEmul4", treeVariables_.rawTPEmul4, "rawTPEmul4[nbOfTowers]/I"); //
68  tree_->Branch("rawTPEmul5", treeVariables_.rawTPEmul5, "rawTPEmul5[nbOfTowers]/I"); //
69  tree_->Branch("eRec", treeVariables_.eRec, "eRec[nbOfTowers]/F"); //
70 }
71 
73  file_->cd();
74  tree_->Write();
75  file_->Close();
76 }
77 
78 void EcalTPGAnalyzer::beginRun(edm::Run const&, edm::EventSetup const& evtSetup) {
79  // geometry
80  eTTmap_ = &evtSetup.getData(eTTMapToken_);
83 }
84 
85 void EcalTPGAnalyzer::endRun(edm::Run const&, edm::EventSetup const& evtSetup) {}
86 
88  using namespace edm;
89  using namespace std;
90 
91  if (print_)
92  std::cout << "===========" << iEvent.id() << std::endl;
93 
94  map<EcalTrigTowerDetId, towerEner> mapTower;
95  map<EcalTrigTowerDetId, towerEner>::iterator itTT;
96 
98  // get Evts info
100 
101  treeVariables_.runNb = iEvent.id().run();
102  treeVariables_.evtNb = iEvent.id().event();
103  treeVariables_.bxNb = iEvent.bunchCrossing();
104  treeVariables_.orbitNb = iEvent.orbitNumber();
105 
107  // get L1 info
109 
111  iEvent.getByToken(l1GtReadoutRecordToken_, gtRecord);
112  DecisionWord dWord = gtRecord->decisionWord(); // this will get the decision word *before* masking disabled bits
113 
114  const auto& l1GtTmAlgo = iSetup.getData(l1GtMaskToken_);
115  std::vector<unsigned int> triggerMaskAlgoTrig = l1GtTmAlgo.gtTriggerMask();
116 
117  // apply masks on algo
118  int iDaq = 0;
119  int iBit = -1;
121  for (std::vector<bool>::iterator itBit = dWord.begin(); itBit != dWord.end(); ++itBit) {
122  iBit++;
123  int maskBit = triggerMaskAlgoTrig[iBit] & (1 << iDaq);
124  if (maskBit)
125  *itBit = false;
126  if (*itBit) {
129  }
130  }
131 
133  // Get TP data
135 
137  iEvent.getByToken(tpToken_, tp);
138  if (print_)
139  std::cout << "TP collection size=" << tp.product()->size() << std::endl;
140 
141  for (unsigned int i = 0; i < tp.product()->size(); i++) {
142  EcalTriggerPrimitiveDigi d = (*(tp.product()))[i];
143  const EcalTrigTowerDetId TPtowid = d.id();
144  towerEner tE;
145  tE.iphi_ = TPtowid.iphi();
146  tE.ieta_ = TPtowid.ieta();
147  tE.tpgADC_ = d[0].raw();
148  mapTower[TPtowid] = tE;
149  }
150 
152  // Get Emulators TP
154 
156  iEvent.getByToken(tpEmulToken_, tpEmul);
157  if (print_)
158  std::cout << "TPEmulator collection size=" << tpEmul.product()->size() << std::endl;
159 
160  for (unsigned int i = 0; i < tpEmul.product()->size(); i++) {
161  EcalTriggerPrimitiveDigi d = (*(tpEmul.product()))[i];
162  const EcalTrigTowerDetId TPtowid = d.id();
163  itTT = mapTower.find(TPtowid);
164  if (itTT != mapTower.end())
165  for (int j = 0; j < 5; j++)
166  (itTT->second).tpgEmul_[j] = d[j].raw();
167  }
168 
170  // Get nb of crystals read out
172 
173  // Get EB xtal digi inputs
175  iEvent.getByToken(ebDigiToken_, digiEB);
176 
177  for (unsigned int i = 0; i < digiEB.product()->size(); i++) {
178  const EBDataFrame& df = (*(digiEB.product()))[i];
179  const EBDetId& id = df.id();
180  const EcalTrigTowerDetId towid = id.tower();
181  itTT = mapTower.find(towid);
182  if (itTT != mapTower.end())
183  (itTT->second).nbXtal_++;
184  }
185 
186  if (useEE_) {
187  // Get EE xtal digi inputs
189  iEvent.getByToken(eeDigiToken_, digiEE);
190  for (unsigned int i = 0; i < digiEE.product()->size(); i++) {
191  const EEDataFrame& df = (*(digiEE.product()))[i];
192  const EEDetId& id = df.id();
193  const EcalTrigTowerDetId towid = eTTmap_->towerOf(id);
194  itTT = mapTower.find(towid);
195  if (itTT != mapTower.end())
196  (itTT->second).nbXtal_++;
197  }
198  }
199 
201  // Get rechits
203 
204  //... to be completed
205 
207  // fill tree
209 
210  treeVariables_.nbOfTowers = mapTower.size();
211  int towerNb = 0;
212  for (itTT = mapTower.begin(); itTT != mapTower.end(); ++itTT) {
213  treeVariables_.ieta[towerNb] = (itTT->second).ieta_;
214  treeVariables_.iphi[towerNb] = (itTT->second).iphi_;
215  treeVariables_.nbOfXtals[towerNb] = (itTT->second).nbXtal_;
216  treeVariables_.rawTPData[towerNb] = (itTT->second).tpgADC_;
217  treeVariables_.rawTPEmul1[towerNb] = (itTT->second).tpgEmul_[0];
218  treeVariables_.rawTPEmul2[towerNb] = (itTT->second).tpgEmul_[1];
219  treeVariables_.rawTPEmul3[towerNb] = (itTT->second).tpgEmul_[2];
220  treeVariables_.rawTPEmul4[towerNb] = (itTT->second).tpgEmul_[3];
221  treeVariables_.rawTPEmul5[towerNb] = (itTT->second).tpgEmul_[4];
222  treeVariables_.eRec[towerNb] = (itTT->second).eRec_;
223  towerNb++;
224  }
225 
226  tree_->Fill();
227 }
const edm::ESGetToken< EcalTrigTowerConstituentsMap, IdealGeometryRecord > eTTMapToken_
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
const bool print_
std::ostream & print_(std::ostream &os, value_type const &hash)
Definition: Hash.cc:92
int ieta() const
get the tower ieta
const CaloSubdetectorGeometry * theEndcapGeometry_
size_type size() const
T const * product() const
Definition: Handle.h:70
const edm::EDGetTokenT< EcalTrigPrimDigiCollection > tpToken_
const DecisionWord & decisionWord(int bxInEventValue) const
~EcalTPGAnalyzer() override
EcalTrigTowerDetId towerOf(const DetId &id) const
Get the tower id for this det id (or null if not known)
int iEvent
Definition: GenABIO.cc:224
EcalTPGVariables treeVariables_
std::vector< bool > DecisionWord
typedefs
void analyze(edm::Event const &, edm::EventSetup const &) override
const edm::EDGetTokenT< EcalTrigPrimDigiCollection > tpEmulToken_
Transition
Definition: Transition.h:12
const edm::ESGetToken< L1GtTriggerMask, L1GtTriggerMaskAlgoTrigRcd > l1GtMaskToken_
bool getData(T &iHolder) const
Definition: EventSetup.h:122
void beginRun(edm::Run const &, edm::EventSetup const &) override
d
Definition: ztail.py:151
const CaloSubdetectorGeometry * theBarrelGeometry_
const EcalTrigTowerConstituentsMap * eTTmap_
void endRun(edm::Run const &, edm::EventSetup const &) override
const edm::ESGetToken< CaloSubdetectorGeometry, EcalEndcapGeometryRecord > eeGeometryToken_
const edm::ESGetToken< CaloSubdetectorGeometry, EcalBarrelGeometryRecord > ebGeometryToken_
const bool useEE_
const edm::EDGetTokenT< L1GlobalTriggerReadoutRecord > l1GtReadoutRecordToken_
const edm::EDGetTokenT< EEDigiCollection > eeDigiToken_
HLT enums.
const edm::EDGetTokenT< EBDigiCollection > ebDigiToken_
int iphi() const
get the tower iphi
EcalTPGAnalyzer(const edm::ParameterSet &)
Definition: Run.h:45