CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
L1TRPCTF.cc
Go to the documentation of this file.
1 /*
2  * \file L1TRPCTF.cc
3  *
4  * \author J. Berryhill
5  *
6  */
9 
13 
14 #include <sstream>
15 using namespace std;
16 using namespace edm;
17 
19  : rpctfSource_(consumes<L1MuGMTReadoutCollection>(ps.getParameter<InputTag>("rpctfSource"))),
20  // digiSource_( ps.getParameter< InputTag >("rpctfRPCDigiSource") ),
21  // m_rpcDigiFine(false),
22  // m_useRpcDigi(true),
23  m_lastUsedBxInBxdiff(0),
24  output_dir_(ps.getUntrackedParameter<string>("output_dir"))
25 // m_rpcDigiWithBX0(0),
26 // m_rpcDigiWithBXnon0(0)
27 
28 {
29  // verbosity switch
30  verbose_ = ps.getUntrackedParameter<bool>("verbose", false);
31 
32  if (verbose_)
33  cout << "L1TRPCTF: constructor...." << endl;
34 }
35 
37 
39  nev_ = 0;
40  nevRPC_ = 0;
41 
42  ostringstream oDir;
43  oDir << output_dir_ << "/CrateSynchroHistograms/";
44  ibooker.setCurrentFolder(oDir.str());
45  for (unsigned int i = 0; i < 12; i++) {
46  ostringstream o;
47  o << "RPCTF_crate_" << i << "_synchro";
48  rpctfcratesynchro[i] = ibooker.book2D(o.str(), o.str(), 5, -2.5, 2.5, 33, -16.5, 16.5);
49  for (int bx = -2; bx < 3; ++bx) {
50  ostringstream b;
51  b << "BX=" << bx;
52  rpctfcratesynchro[i]->setBinLabel(bx + 3, b.str(), 1);
53  }
54  rpctfcratesynchro[i]->setAxisTitle("Tower", 2);
55  }
56  ibooker.setCurrentFolder(output_dir_);
57 
58  rpctfetavalue[1] = ibooker.book1D("RPCTF_eta_value_bx0", "RPCTF eta value bx=0", 33, -16.5, 16.5);
59  rpctfetavalue[2] = ibooker.book1D("RPCTF_eta_value_bx+", "RPCTF eta value bx>0", 33, -16.5, 16.5);
60  rpctfetavalue[0] = ibooker.book1D("RPCTF_eta_value_bx-", "RPCTF eta value bx<0", 33, -16.5, 16.5);
61 
62  rpctfphivalue[1] = ibooker.book1D("RPCTF_phi_value_bx0", "RPCTF phi value bx=0", 144, -0.5, 143.5);
63  rpctfphivalue[2] = ibooker.book1D("RPCTF_phi_value_bx+", "RPCTF phi value bx>0", 144, -0.5, 143.5);
64  rpctfphivalue[0] = ibooker.book1D("RPCTF_phi_value_bx-", "RPCTF phi value bx<0", 144, -0.5, 143.5);
65 
66  rpctfptvalue[1] = ibooker.book1D("RPCTF_pt_value_bx0", "RPCTF pt value bx=0", 160, -0.5, 159.5);
67  rpctfptvalue[2] = ibooker.book1D("RPCTF_pt_value_bx+", "RPCTF pt value bx>0", 160, -0.5, 159.5);
68  rpctfptvalue[0] = ibooker.book1D("RPCTF_pt_value_bx-", "RPCTF pt value bx<0", 160, -0.5, 159.5);
69 
70  rpctfchargevalue[1] = ibooker.book1D("RPCTF_charge_value_bx0", "RPCTF charge value bx=0", 3, -1.5, 1.5);
71  rpctfchargevalue[2] = ibooker.book1D("RPCTF_charge_value_bx+", "RPCTF charge value bx>0", 3, -1.5, 1.5);
72  rpctfchargevalue[0] = ibooker.book1D("RPCTF_charge_value_bx-", "RPCTF charge value bx<01", 3, -1.5, 1.5);
73 
74  rpctfquality[1] = ibooker.book1D("RPCTF_quality", "RPCTF quality bx=0", 6, -0.5, 5.5);
75  rpctfquality[2] = ibooker.book1D("RPCTF_quality_bx+", "RPCTF quality bx>0", 6, -0.5, 5.5);
76  rpctfquality[0] = ibooker.book1D("RPCTF_quality_bx-", "RPCTF quality bx<0", 6, -0.5, 5.5);
77 
78  rpctfntrack_b[1] = ibooker.book1D("RPCTF_ntrack_brl_bx0", "RPCTF number of tracks - barrel, bx=0", 5, -0.5, 4.5);
79  rpctfntrack_b[2] = ibooker.book1D("RPCTF_ntrack_brl_bx+", "RPCTF number of tracks - barrel, bx>0", 5, -0.5, 4.5);
80  rpctfntrack_b[0] = ibooker.book1D("RPCTF_ntrack_brl_bx-", "RPCTF number of tracks - barrel, bx<0", 5, -0.5, 4.5);
81 
82  rpctfntrack_e[1] = ibooker.book1D("RPCTF_ntrack_fwd_bx0", "RPCTF number of tracks - endcap, bx=0", 5, -0.5, 4.5);
83  rpctfntrack_e[2] = ibooker.book1D("RPCTF_ntrack_fwd_bx+", "RPCTF number of tracks - endcap, bx>0", 5, -0.5, 4.5);
84  rpctfntrack_e[0] = ibooker.book1D("RPCTF_ntrack_fwd_bx-", "RPCTF number of tracks - endcap, bx<0", 5, -0.5, 4.5);
85 
86  m_qualVsEta[1] = ibooker.book2D("RPCTF_quality_vs_eta_bx0",
87  "RPCTF quality vs eta, bx=0",
88  33,
89  -16.5,
90  16.5,
91  6,
92  -0.5,
93  5.5); // Currently only 0...3 quals are possible
94  m_qualVsEta[2] = ibooker.book2D("RPCTF_quality_vs_eta_bx+",
95  "RPCTF quality vs eta, bx>0",
96  33,
97  -16.5,
98  16.5,
99  6,
100  -0.5,
101  5.5); // Currently only 0...3 quals are possible
102  m_qualVsEta[0] = ibooker.book2D("RPCTF_quality_vs_eta_bx-",
103  "RPCTF quality vs eta, bx<0",
104  33,
105  -16.5,
106  16.5,
107  6,
108  -0.5,
109  5.5); // Currently only 0...3 quals are possible
110 
111  m_muonsEtaPhi[1] =
112  ibooker.book2D("RPCTF_muons_eta_phi_bx0", "RPCTF occupancy(eta,phi), bx=0", 33, -16.5, 16.5, 144, -0.5, 143.5);
113  m_muonsEtaPhi[2] =
114  ibooker.book2D("RPCTF_muons_eta_phi_bx+", "RPCTF occupancy(eta,phi), bx>0", 33, -16.5, 16.5, 144, -0.5, 143.5);
115  m_muonsEtaPhi[0] =
116  ibooker.book2D("RPCTF_muons_eta_phi_bx-", "RPCTF occupancy(eta,phi), bx<0", 33, -16.5, 16.5, 144, -0.5, 143.5);
117 
118  rpctfbx = ibooker.book1D("RPCTF_bx", "RPCTF bx distribiution", 7, -3.5, 3.5);
119 
120  //axis labels
121  for (int l = 0; l < 3; ++l) {
122  m_muonsEtaPhi[l]->setAxisTitle("tower", 1);
123  m_qualVsEta[l]->setAxisTitle("tower");
124  rpctfetavalue[l]->setAxisTitle("tower");
125 
126  m_muonsEtaPhi[l]->setAxisTitle("phi", 2);
127  rpctfphivalue[l]->setAxisTitle("phi");
128  }
129 
130  // set phi bin labels
131  for (int i = 0; i < 12; ++i) {
132  //float lPhi = (30./360)*i*2*3.14;
133  int lPhi = 30 * i;
134  int lBin = int((30. / 360) * i * 144) + 1;
135  std::stringstream ss;
136  ss << "phi=" << lPhi;
137  for (int l = 0; l < 3; ++l) {
138  rpctfphivalue[l]->setBinLabel(lBin, ss.str());
139  m_muonsEtaPhi[l]->setBinLabel(lBin, ss.str(), 2);
140  }
141  }
142 
143  /*
144  // set TC numbers on phi axis
145  for (int tc = 0; tc < 12 ; ++tc ){
146  int lBin = (tc*12+3+1)%144;
147  std::stringstream ss;
148  ss << "TC" <<tc;
149  for (int l = 0; l<3; ++l){
150  rpctfphivalue[l]->setBinLabel(lBin,ss.str());
151  m_muonsEtaPhi[l]->setBinLabel(lBin,ss.str(), 2);
152  }
153  }*/
154 
155  // set eta bin labels
156  for (int i = -16; i < 17; ++i) {
157  std::stringstream ss;
158  ss << i;
159  for (int l = 0; l < 3; ++l) {
160  rpctfetavalue[l]->setBinLabel(i + 17, ss.str());
161  m_muonsEtaPhi[l]->setBinLabel(i + 17, ss.str(), 1);
162  m_qualVsEta[l]->setBinLabel(i + 17, ss.str());
163  }
164  }
165 
166  m_bxDiff = ibooker.book1D("RPCTF_bx_diff", "RPCTrigger - bx difference", 12000, -.5, 11999.5);
167 }
168 
169 void L1TRPCTF::analyze(const Event& e, const EventSetup& c) {
170  nev_++;
171  if (verbose_)
172  cout << "L1TRPCTF: analyze...." << endl;
173 
175  e.getByToken(rpctfSource_, pCollection);
176 
177  if (!pCollection.isValid()) {
178  edm::LogInfo("DataNotFound") << "can't find L1MuGMTReadoutCollection";
179  return;
180  }
181 
182  L1MuGMTReadoutCollection const* gmtrc = pCollection.product();
183  vector<L1MuGMTReadoutRecord> gmt_records = gmtrc->getRecords();
184  vector<L1MuGMTReadoutRecord>::const_iterator RRItr;
185 
186  std::vector<int> nrpctftrack_b(3, 0);
187  std::vector<int> nrpctftrack_e(3, 0);
188 
189  vector<L1TRPCTF::BxDelays> all_bxdelays;
190 
191  for (RRItr = gmt_records.begin(); RRItr != gmt_records.end(); RRItr++) {
192  if (verbose_)
193  cout << "Readout Record " << RRItr->getBxInEvent() << endl;
194 
195  vector<vector<L1MuRegionalCand> > brlAndFwdCands;
196  brlAndFwdCands.push_back(RRItr->getBrlRPCCands());
197  brlAndFwdCands.push_back(RRItr->getFwdRPCCands());
198 
199  int beIndex = 0;
200  vector<vector<L1MuRegionalCand> >::iterator RPCTFCands = brlAndFwdCands.begin();
201  for (; RPCTFCands != brlAndFwdCands.end(); ++RPCTFCands) {
202  for (vector<L1MuRegionalCand>::const_iterator ECItr = RPCTFCands->begin(); ECItr != RPCTFCands->end(); ++ECItr) {
203  int bxindex = 1; // bx == 0
204  if (ECItr->bx() > 0)
205  bxindex = 2;
206  if (ECItr->bx() < 0)
207  bxindex = 0;
208 
209  if (!ECItr->empty()) {
210  if (beIndex == 0)
211  ++nrpctftrack_b[bxindex];
212  if (beIndex == 1)
213  ++nrpctftrack_e[bxindex];
214 
215  if (verbose_)
216  cout << "RPCTFCand bx " << ECItr->bx() << endl;
217 
218  int tower = ECItr->eta_packed();
219  if (tower > 16) {
220  tower = -((~tower & 63) + 1);
221  }
222 
223  rpctfbx->Fill(ECItr->bx());
224 
225  rpctfetavalue[bxindex]->Fill(tower);
226  if (verbose_)
227  cout << "\tRPCTFCand eta value " << ECItr->etaValue() << endl;
228 
229  rpctfphivalue[bxindex]->Fill(ECItr->phi_packed());
230  if (verbose_)
231  cout << "\tRPCTFCand phi value " << ECItr->phiValue() << endl;
232 
233  rpctfptvalue[bxindex]->Fill(ECItr->ptValue());
234  if (verbose_)
235  cout << "\tRPCTFCand pt value " << ECItr->ptValue() << endl;
236 
237  rpctfchargevalue[bxindex]->Fill(ECItr->chargeValue());
238  if (verbose_)
239  cout << "\tRPCTFCand charge value " << ECItr->chargeValue() << endl;
240 
241  rpctfquality[bxindex]->Fill(ECItr->quality());
242  if (verbose_)
243  cout << "\tRPCTFCand quality " << ECItr->quality() << endl;
244 
245  m_qualVsEta[bxindex]->Fill(tower, ECItr->quality());
246  m_muonsEtaPhi[bxindex]->Fill(tower, ECItr->phi_packed());
247 
248  BxDelays bx_del;
249  bx_del.bx = ECItr->bx();
250  bx_del.eta_t = tower;
251  bx_del.phi_p = ECItr->phi_packed();
252  all_bxdelays.push_back(bx_del);
253 
254  } // if !empty
255  } // end candidates iteration
256  ++beIndex;
257  } // end brl/endcap iteration
258  } // end GMT records iteration
259 
260  for (int bxI = 0; bxI < 3; ++bxI) {
261  rpctfntrack_b[bxI]->Fill(nrpctftrack_b[bxI]);
262  rpctfntrack_e[bxI]->Fill(nrpctftrack_e[bxI]);
263  }
264 
265  for (unsigned int i = 0; i < all_bxdelays.size(); i++) {
266  int sector = ((all_bxdelays[i].phi_p + 142) % 144) / 12;
267  if (sector > 11 || sector < 0)
268  continue;
269  int eta_tower = all_bxdelays[i].eta_t;
270  for (unsigned int j = 0; j < all_bxdelays.size(); j++) {
271  if (i == j)
272  continue;
273  int sector2 = ((all_bxdelays[j].phi_p + 142) % 144) / 12;
274 
275  int distance_cut = 1;
276  int distance = ((sector + 12) - sector2) % 12;
277  distance = min(distance, 11 - distance);
278  if (distance < distance_cut)
279  continue;
280 
281  int bxDiff = all_bxdelays[i].bx - all_bxdelays[j].bx;
282  rpctfcratesynchro[sector]->Fill(bxDiff, eta_tower);
283  }
284  }
285 
286  while (m_globBX.begin() != m_globBX.end()) {
287  long long int diff = *m_globBX.begin() - m_lastUsedBxInBxdiff; // first entry will go to overflow bin, ignore
288  m_bxDiff->Fill(diff);
289  m_lastUsedBxInBxdiff = *m_globBX.begin();
290  m_globBX.erase(m_globBX.begin());
291  }
292 
293  if (verbose_)
294  cout << "L1TRPCTF: end job...." << endl;
295  LogInfo("EndJob") << "analyzed " << nev_ << " events";
296 }
std::set< unsigned long long int > m_globBX
Definition: L1TRPCTF.h:75
MonitorElement * rpctfcratesynchro[12]
Definition: L1TRPCTF.h:73
T getUntrackedParameter(std::string const &, T const &) const
const edm::EventSetup & c
MonitorElement * rpctfchargevalue[3]
Definition: L1TRPCTF.h:63
MonitorElement * rpctfetavalue[3]
Definition: L1TRPCTF.h:60
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
MonitorElement * rpctfptvalue[3]
Definition: L1TRPCTF.h:62
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
~L1TRPCTF() override
Definition: L1TRPCTF.cc:36
void bookHistograms(DQMStore::IBooker &ibooker, const edm::Run &, const edm::EventSetup &) override
Definition: L1TRPCTF.cc:38
void Fill(long long x)
MonitorElement * rpctfquality[3]
Definition: L1TRPCTF.h:64
MonitorElement * rpctfphivalue[3]
Definition: L1TRPCTF.h:61
int nev_
Definition: L1TRPCTF.h:79
T min(T a, T b)
Definition: MathUtil.h:58
MonitorElement * m_bxDiff
Definition: L1TRPCTF.h:72
bool isValid() const
Definition: HandleBase.h:70
virtual void setBinLabel(int bin, const std::string &label, int axis=1)
set bin label for x, y or z axis (axis=1, 2, 3 respectively)
MonitorElement * m_muonsEtaPhi[3]
Definition: L1TRPCTF.h:69
MonitorElement * m_qualVsEta[3]
Definition: L1TRPCTF.h:68
std::string output_dir_
Definition: L1TRPCTF.h:84
Log< level::Info, false > LogInfo
L1TRPCTF(const edm::ParameterSet &ps)
Definition: L1TRPCTF.cc:18
T const * product() const
Definition: Handle.h:70
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:177
long long int m_lastUsedBxInBxdiff
Definition: L1TRPCTF.h:83
double b
Definition: hdecay.h:118
MonitorElement * rpctfntrack_e[3]
Definition: L1TRPCTF.h:66
std::vector< L1MuGMTReadoutRecord > const & getRecords() const
MonitorElement * rpctfbx
Definition: L1TRPCTF.h:67
MonitorElement * rpctfntrack_b[3]
Definition: L1TRPCTF.h:65
void analyze(const edm::Event &e, const edm::EventSetup &c) override
Definition: L1TRPCTF.cc:169
int nevRPC_
Definition: L1TRPCTF.h:80
bool verbose_
Definition: L1TRPCTF.h:81
tuple cout
Definition: gather_cfg.py:144
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
Definition: Run.h:45
edm::EDGetTokenT< L1MuGMTReadoutCollection > rpctfSource_
Definition: L1TRPCTF.h:77
virtual void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)