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
18 
22 
25 
31 
41 
42 #include "EcalTPGAnalyzer.h"
43 
44 #include <TMath.h>
45 #include <sstream>
46 
47 using namespace edm;
49 
51  tpCollection_ = iConfig.getParameter<edm::InputTag>("TPCollection");
52  tpEmulatorCollection_ = iConfig.getParameter<edm::InputTag>("TPEmulatorCollection");
53  digiCollectionEB_ = iConfig.getParameter<edm::InputTag>("DigiCollectionEB");
54  digiCollectionEE_ = iConfig.getParameter<edm::InputTag>("DigiCollectionEE");
55  gtRecordCollectionTag_ = iConfig.getParameter<std::string>("GTRecordCollection");
56 
57  allowTP_ = iConfig.getParameter<bool>("ReadTriggerPrimitives");
58  useEE_ = iConfig.getParameter<bool>("UseEndCap");
59  print_ = iConfig.getParameter<bool>("Print");
60 
61  // file
62  file_ = new TFile("ECALTPGtree.root", "RECREATE");
63  file_->cd();
64 
65  // tree
66  tree_ = new TTree("EcalTPGAnalysis", "EcalTPGAnalysis");
67 
68  tree_->Branch("runNb", &treeVariables_.runNb, "runNb/i"); //
69  tree_->Branch("evtNb", &treeVariables_.evtNb, "evtNb/i"); //
70  tree_->Branch("bxNb", &treeVariables_.bxNb, "bxNb/i"); //
71  tree_->Branch("orbitNb", &treeVariables_.orbitNb, "orbitNb/i"); //
72  tree_->Branch("nbOfActiveTriggers", &treeVariables_.nbOfActiveTriggers, "nbOfActiveTriggers/i"); //
73  tree_->Branch("activeTriggers", treeVariables_.activeTriggers, "activeTriggers[nbOfActiveTriggers]/I"); //
74 
75  tree_->Branch("nbOfTowers", &treeVariables_.nbOfTowers, "nbOfTowers/i"); //
76  tree_->Branch("ieta", treeVariables_.ieta, "ieta[nbOfTowers]/I"); //
77  tree_->Branch("iphi", treeVariables_.iphi, "iphi[nbOfTowers]/I"); //
78  tree_->Branch("nbOfXtals", treeVariables_.nbOfXtals, "nbOfXtals[nbOfTowers]/I"); //
79  tree_->Branch("rawTPData", treeVariables_.rawTPData, "rawTPData[nbOfTowers]/I"); //
80  tree_->Branch("rawTPEmul1", treeVariables_.rawTPEmul1, "rawTPEmul1[nbOfTowers]/I"); //
81  tree_->Branch("rawTPEmul2", treeVariables_.rawTPEmul2, "rawTPEmul2[nbOfTowers]/I"); //
82  tree_->Branch("rawTPEmul3", treeVariables_.rawTPEmul3, "rawTPEmul3[nbOfTowers]/I"); //
83  tree_->Branch("rawTPEmul4", treeVariables_.rawTPEmul4, "rawTPEmul4[nbOfTowers]/I"); //
84  tree_->Branch("rawTPEmul5", treeVariables_.rawTPEmul5, "rawTPEmul5[nbOfTowers]/I"); //
85  tree_->Branch("eRec", treeVariables_.eRec, "eRec[nbOfTowers]/F"); //
86 }
87 
89  file_->cd();
90  tree_->Write();
91  file_->Close();
92 }
93 
94 void EcalTPGAnalyzer::beginRun(edm::Run const&, edm::EventSetup const& evtSetup) {
95  // geometry
96  ESHandle<CaloGeometry> theGeometry;
97  ESHandle<CaloSubdetectorGeometry> theEndcapGeometry_handle, theBarrelGeometry_handle;
98 
99  evtSetup.get<CaloGeometryRecord>().get(theGeometry);
100  evtSetup.get<EcalEndcapGeometryRecord>().get("EcalEndcap", theEndcapGeometry_handle);
101  evtSetup.get<EcalBarrelGeometryRecord>().get("EcalBarrel", theBarrelGeometry_handle);
102 
103  evtSetup.get<IdealGeometryRecord>().get(eTTmap_);
104  theEndcapGeometry_ = &(*theEndcapGeometry_handle);
105  theBarrelGeometry_ = &(*theBarrelGeometry_handle);
106 }
107 
109  using namespace edm;
110  using namespace std;
111 
112  if (print_)
113  std::cout << "===========" << iEvent.id() << std::endl;
114 
115  map<EcalTrigTowerDetId, towerEner> mapTower;
116  map<EcalTrigTowerDetId, towerEner>::iterator itTT;
117 
119  // get Evts info
121 
122  treeVariables_.runNb = iEvent.id().run();
123  treeVariables_.evtNb = iEvent.id().event();
124  treeVariables_.bxNb = iEvent.bunchCrossing();
125  treeVariables_.orbitNb = iEvent.orbitNumber();
126 
128  // get L1 info
130 
132  iEvent.getByLabel(edm::InputTag(gtRecordCollectionTag_), gtRecord);
133  DecisionWord dWord = gtRecord->decisionWord(); // this will get the decision word *before* masking disabled bits
134 
136  iSetup.get<L1GtTriggerMaskAlgoTrigRcd>().get(l1GtTmAlgo);
137  std::vector<unsigned int> triggerMaskAlgoTrig = l1GtTmAlgo.product()->gtTriggerMask();
138 
139  // apply masks on algo
140  int iDaq = 0;
141  int iBit = -1;
142  treeVariables_.nbOfActiveTriggers = 0;
143  for (std::vector<bool>::iterator itBit = dWord.begin(); itBit != dWord.end(); ++itBit) {
144  iBit++;
145  int maskBit = triggerMaskAlgoTrig[iBit] & (1 << iDaq);
146  if (maskBit)
147  *itBit = false;
148  if (*itBit) {
149  treeVariables_.activeTriggers[treeVariables_.nbOfActiveTriggers] = iBit;
150  treeVariables_.nbOfActiveTriggers++;
151  }
152  }
153 
155  // Get TP data
157 
159  iEvent.getByLabel(tpCollection_, tp);
160  if (print_)
161  std::cout << "TP collection size=" << tp.product()->size() << std::endl;
162 
163  for (unsigned int i = 0; i < tp.product()->size(); i++) {
164  EcalTriggerPrimitiveDigi d = (*(tp.product()))[i];
165  const EcalTrigTowerDetId TPtowid = d.id();
166  towerEner tE;
167  tE.iphi_ = TPtowid.iphi();
168  tE.ieta_ = TPtowid.ieta();
169  tE.tpgADC_ = d[0].raw();
170  mapTower[TPtowid] = tE;
171  }
172 
174  // Get Emulators TP
176 
178  iEvent.getByLabel(tpEmulatorCollection_, tpEmul);
179  if (print_)
180  std::cout << "TPEmulator collection size=" << tpEmul.product()->size() << std::endl;
181 
182  for (unsigned int i = 0; i < tpEmul.product()->size(); i++) {
183  EcalTriggerPrimitiveDigi d = (*(tpEmul.product()))[i];
184  const EcalTrigTowerDetId TPtowid = d.id();
185  itTT = mapTower.find(TPtowid);
186  if (itTT != mapTower.end())
187  for (int j = 0; j < 5; j++)
188  (itTT->second).tpgEmul_[j] = d[j].raw();
189  }
190 
192  // Get nb of crystals read out
194 
195  // Get EB xtal digi inputs
197  iEvent.getByLabel(digiCollectionEB_, digiEB);
198 
199  for (unsigned int i = 0; i < digiEB.product()->size(); i++) {
200  const EBDataFrame& df = (*(digiEB.product()))[i];
201  const EBDetId& id = df.id();
202  const EcalTrigTowerDetId towid = id.tower();
203  itTT = mapTower.find(towid);
204  if (itTT != mapTower.end())
205  (itTT->second).nbXtal_++;
206  }
207 
208  if (useEE_) {
209  // Get EE xtal digi inputs
211  iEvent.getByLabel(digiCollectionEE_, digiEE);
212  for (unsigned int i = 0; i < digiEE.product()->size(); i++) {
213  const EEDataFrame& df = (*(digiEE.product()))[i];
214  const EEDetId& id = df.id();
215  const EcalTrigTowerDetId towid = (*eTTmap_).towerOf(id);
216  itTT = mapTower.find(towid);
217  if (itTT != mapTower.end())
218  (itTT->second).nbXtal_++;
219  }
220  }
221 
223  // Get rechits
225 
226  //... to be completed
227 
229  // fill tree
231 
232  treeVariables_.nbOfTowers = mapTower.size();
233  int towerNb = 0;
234  for (itTT = mapTower.begin(); itTT != mapTower.end(); ++itTT) {
235  treeVariables_.ieta[towerNb] = (itTT->second).ieta_;
236  treeVariables_.iphi[towerNb] = (itTT->second).iphi_;
237  treeVariables_.nbOfXtals[towerNb] = (itTT->second).nbXtal_;
238  treeVariables_.rawTPData[towerNb] = (itTT->second).tpgADC_;
239  treeVariables_.rawTPEmul1[towerNb] = (itTT->second).tpgEmul_[0];
240  treeVariables_.rawTPEmul2[towerNb] = (itTT->second).tpgEmul_[1];
241  treeVariables_.rawTPEmul3[towerNb] = (itTT->second).tpgEmul_[2];
242  treeVariables_.rawTPEmul4[towerNb] = (itTT->second).tpgEmul_[3];
243  treeVariables_.rawTPEmul5[towerNb] = (itTT->second).tpgEmul_[4];
244  treeVariables_.eRec[towerNb] = (itTT->second).eRec_;
245  towerNb++;
246  }
247 
248  tree_->Fill();
249 }
RunNumber_t run() const
Definition: EventID.h:39
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:41
key_type id() const
Definition: EBDataFrame.h:31
std::ostream & print_(std::ostream &os, value_type const &hash)
Definition: Hash.cc:106
int bunchCrossing() const
Definition: EventBase.h:64
~EcalTPGAnalyzer() override
int ieta() const
get the tower ieta
int iEvent
Definition: GenABIO.cc:224
const std::vector< unsigned int > & gtTriggerMask() const
get the trigger mask
std::vector< bool > DecisionWord
typedefs
void analyze(edm::Event const &, edm::EventSetup const &) override
int orbitNumber() const
Definition: EventBase.h:65
void beginRun(edm::Run const &, edm::EventSetup const &) override
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:480
const DecisionWord & decisionWord(int bxInEventValue) const
key_type id() const
Definition: EEDataFrame.h:28
int iphi() const
get the tower iphi
const EcalTrigTowerDetId & id() const
T const * product() const
Definition: Handle.h:74
edm::EventID id() const
Definition: EventBase.h:59
HLT enums.
size_type size() const
T get() const
Definition: EventSetup.h:71
T const * product() const
Definition: ESHandle.h:86
EcalTPGAnalyzer(const edm::ParameterSet &)
Definition: Run.h:45