CMS 3D CMS Logo

DumpScObjects.cc
Go to the documentation of this file.
2 
3 #include <fstream>
4 #include <iomanip>
5 #include <memory>
6 #include <string>
7 #include <cmath>
8 
18 
24 
25 using namespace l1ScoutingRun3;
26 
27 // ----------------------------- CLASS DECLARATION ----------------------------
29 public:
30  // constructor and destructor
31  explicit DumpScObjects(const edm::ParameterSet&);
32  ~DumpScObjects() override{};
33 
34  // method for analyzing the events
35  void analyze(const edm::Event&, const edm::EventSetup&) override;
36 
37 private:
38  // dump contenct of BX
39  void printBx(unsigned bx);
40 
41  // the tokens to access the data
47 
53 
54  // the min and max BX to be analyzed
55  unsigned minBx_;
56  unsigned maxBx_;
57 
58  // select collection to be printed
60  bool checkJets_;
62  bool checkTaus_;
64 
65  // dump a specific (ORBIT, BX RANGE)
67  unsigned orbitNum_;
68  unsigned searchStartBx_;
69  unsigned searchStopBx_;
70 
71  // utils
73 };
74 // -----------------------------------------------------------------------------
75 
76 // -------------------------------- constructor -------------------------------
77 
79  : minBx_(iConfig.getUntrackedParameter<unsigned>("minBx", 0)),
80  maxBx_(iConfig.getUntrackedParameter<unsigned>("maxBx", 3564)),
81 
82  checkMuons_(iConfig.getUntrackedParameter<bool>("checkMuons", true)),
83  checkJets_(iConfig.getUntrackedParameter<bool>("checkJets", true)),
84  checkEGammas_(iConfig.getUntrackedParameter<bool>("checkEGammas", true)),
85  checkTaus_(iConfig.getUntrackedParameter<bool>("checkTaus", true)),
86  checkEtSums_(iConfig.getUntrackedParameter<bool>("checkEtSums", true)),
87 
88  searchEvent_(iConfig.getUntrackedParameter<bool>("searchEvent", false)),
89  orbitNum_(iConfig.getUntrackedParameter<unsigned>("orbitNumber", 0)),
90  searchStartBx_(iConfig.getUntrackedParameter<unsigned>("searchStartBx", 0)),
91  searchStopBx_(iConfig.getUntrackedParameter<unsigned>("searchStopBx", 0)),
92 
93  skipEmptyBx_(iConfig.getUntrackedParameter<bool>("skipEmptyBx", true)) {
94  if (checkMuons_)
95  gmtMuonsToken_ = consumes<MuonOrbitCollection>(iConfig.getParameter<edm::InputTag>("gmtMuonsTag"));
96  if (checkJets_)
97  caloJetsToken_ = consumes<JetOrbitCollection>(iConfig.getParameter<edm::InputTag>("caloJetsTag"));
98  if (checkEGammas_)
99  caloEGammasToken_ = consumes<EGammaOrbitCollection>(iConfig.getParameter<edm::InputTag>("caloEGammasTag"));
100  if (checkTaus_)
101  caloTausToken_ = consumes<TauOrbitCollection>(iConfig.getParameter<edm::InputTag>("caloTausTag"));
102  if (checkEtSums_)
103  caloEtSumsToken_ = consumes<BxSumsOrbitCollection>(iConfig.getParameter<edm::InputTag>("caloEtSumsTag"));
104 }
105 // -----------------------------------------------------------------------------
106 
107 // ----------------------- method called for each orbit -----------------------
109  if (checkMuons_)
110  iEvent.getByToken(gmtMuonsToken_, muonHandle_);
111  if (checkJets_)
112  iEvent.getByToken(caloJetsToken_, jetHandle_);
113  if (checkEGammas_)
115  if (checkTaus_)
116  iEvent.getByToken(caloTausToken_, tauHandle_);
117  if (checkEtSums_)
118  iEvent.getByToken(caloEtSumsToken_, etSumHandle_);
119 
120  // get the orbit number
121  unsigned currOrbit = iEvent.id().event();
122 
123  // if we are looking for a specific orbit
124  if (searchEvent_) {
125  if (currOrbit != orbitNum_)
126  return;
127 
128  // found the orbit
129  for (unsigned bx = searchStartBx_; bx <= searchStopBx_; bx++) {
130  printBx(bx);
131  }
132  } else {
133  if (skipEmptyBx_) {
134  // create a set of non empty BXs
135  std::set<unsigned> uniqueBx;
136 
137  if (checkMuons_) {
138  for (const unsigned& bx : muonHandle_->getFilledBxs()) {
139  if ((bx >= minBx_) || (bx <= maxBx_))
140  uniqueBx.insert(bx);
141  }
142  }
143  if (checkJets_) {
144  for (const unsigned& bx : jetHandle_->getFilledBxs()) {
145  if ((bx >= minBx_) || (bx <= maxBx_))
146  uniqueBx.insert(bx);
147  }
148  }
149  if (checkEGammas_) {
150  for (const unsigned& bx : eGammaHandle_->getFilledBxs()) {
151  if ((bx >= minBx_) || (bx <= maxBx_))
152  uniqueBx.insert(bx);
153  }
154  }
155  if (checkTaus_) {
156  for (const unsigned& bx : tauHandle_->getFilledBxs()) {
157  if ((bx >= minBx_) || (bx <= maxBx_))
158  uniqueBx.insert(bx);
159  }
160  }
161  if (checkEtSums_) {
162  for (const unsigned& bx : etSumHandle_->getFilledBxs()) {
163  if ((bx >= minBx_) || (bx <= maxBx_))
164  uniqueBx.insert(bx);
165  }
166  }
167 
168  // process bx
169  for (const unsigned& bx : uniqueBx) {
170  printBx(bx);
171  }
172 
173  } else {
174  // dump all objects
175  for (unsigned bx = minBx_; bx <= maxBx_; bx++) {
176  printBx(bx);
177  }
178  }
179  }
180 }
181 // -----------------------------------------------------------------------------
182 
183 void DumpScObjects::printBx(unsigned bx) {
184  std::cout << "BX = " << bx << " ****" << std::endl;
185 
186  if (checkMuons_ && muonHandle_.isValid()) {
187  int i = 0;
188  const auto& muons = muonHandle_->bxIterator(bx);
189  for (const auto& muon : muons) {
190  std::cout << "--- Muon " << i << " ---\n";
191  printMuon(muon);
192  i++;
193  }
194  }
195 
196  if (checkJets_ && jetHandle_.isValid()) {
197  int i = 0;
198  const auto& jets = jetHandle_->bxIterator(bx);
199  for (const auto& jet : jets) {
200  std::cout << "--- Jet " << i << " ---\n";
201  printJet(jet);
202  i++;
203  }
204  }
205 
206  if (checkEGammas_ && jetHandle_.isValid()) {
207  int i = 0;
208  const auto& eGammas = eGammaHandle_->bxIterator(bx);
209  for (const auto& egamma : eGammas) {
210  std::cout << "--- E/Gamma " << i << " ---\n";
212  i++;
213  }
214  }
215 
216  if (checkTaus_ && tauHandle_.isValid()) {
217  int i = 0;
218  const auto& taus = tauHandle_->bxIterator(bx);
219  for (const auto& tau : taus) {
220  std::cout << "--- Tau " << i << " ---\n";
221  printTau(tau);
222  i++;
223  }
224  }
225 
226  if (checkEtSums_ && etSumHandle_.isValid()) {
227  const auto& sums = etSumHandle_->bxIterator(bx);
228  for (const auto& sum : sums) {
229  std::cout << "--- Calo Sums ---\n";
230  printBxSums(sum);
231  }
232  }
233 }
234 
std::vector< unsigned > getFilledBxs() const
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
edm::Handle< EGammaOrbitCollection > eGammaHandle_
void printBx(unsigned bx)
unsigned searchStartBx_
edm::EDGetTokenT< MuonOrbitCollection > gmtMuonsToken_
void printMuon(const Muon &muon, std::ostream &outs=std::cout)
void printJet(const Jet &jet, std::ostream &outs=std::cout)
edm::EDGetTokenT< EGammaOrbitCollection > caloEGammasToken_
DumpScObjects(const edm::ParameterSet &)
void printEGamma(const EGamma &eGamma, std::ostream &outs=std::cout)
muons
the two sets of parameters below are mutually exclusive, depending if RECO or ALCARECO is used the us...
Definition: DiMuonV_cfg.py:214
void printBxSums(const BxSums &sums, std::ostream &outs=std::cout)
example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
edm::EDGetTokenT< TauOrbitCollection > caloTausToken_
int iEvent
Definition: GenABIO.cc:224
~DumpScObjects() override
edm::EDGetTokenT< JetOrbitCollection > caloJetsToken_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::Span< const_iterator > bxIterator(unsigned bx) const
edm::Handle< JetOrbitCollection > jetHandle_
void printTau(const Tau &tau, std::ostream &outs=std::cout)
bool isValid() const
Definition: HandleBase.h:70
unsigned searchStopBx_
edm::EDGetTokenT< BxSumsOrbitCollection > caloEtSumsToken_
unsigned maxBx_
edm::Handle< BxSumsOrbitCollection > etSumHandle_
unsigned minBx_
unsigned orbitNum_
edm::Handle< TauOrbitCollection > tauHandle_
void analyze(const edm::Event &, const edm::EventSetup &) override
edm::Handle< MuonOrbitCollection > muonHandle_