CMS 3D CMS Logo

CastorTTRecord.cc
Go to the documentation of this file.
2 
13 
15  CastorDigiColl_ = consumes<CastorDigiCollection>(ps.getParameter<edm::InputTag>("CastorDigiCollection"));
16  CastorSignalTS_ = ps.getParameter<unsigned int>("CastorSignalTS");
17 
18  ttpBits_ = ps.getParameter<std::vector<unsigned int>>("ttpBits");
19  TrigNames_ = ps.getParameter<std::vector<std::string>>("TriggerBitNames");
20  TrigThresholds_ = ps.getParameter<std::vector<double>>("TriggerThresholds");
21 
22  reweighted_gain = 1.0;
23 
24  produces<L1GtTechnicalTriggerRecord>();
25 }
26 
28 
30  // std::cerr << "**** RUNNING THROUGH CastorTTRecord::produce" << std::endl;
31 
32  std::vector<L1GtTechnicalTrigger> vecTT(ttpBits_.size());
33 
34  // Get Inputs
35  edm::Handle<CastorDigiCollection> CastorDigiColl;
36  e.getByToken(CastorDigiColl_, CastorDigiColl);
37 
38  if (!CastorDigiColl.failedToGet()) {
39  double cas_efC[16][14];
40  getEnergy_fC(cas_efC, CastorDigiColl, e, eventSetup);
41 
42  std::vector<bool> decision(ttpBits_.size());
43 
44  getTriggerDecisions(decision, cas_efC);
45 
46  for (unsigned int i = 0; i < ttpBits_.size(); i++) {
47  // if( decision.at(i) ) std::cerr << "**** Something Triggered" <<
48  // std::endl; std::cout << "Run CastorTTRecord::produce. TriggerBit = " <<
49  // ttpBits_.at(i) << "; TriggerName = " << TrigNames_.at(i) << "; Decision
50  // = " << decision[i] << std::endl;
51  vecTT.at(i) = L1GtTechnicalTrigger(TrigNames_.at(i), ttpBits_.at(i), 0, decision.at(i));
52  }
53 
54  } else {
55  vecTT.clear();
56  }
57 
58  // Put output into event
59  std::unique_ptr<L1GtTechnicalTriggerRecord> output(new L1GtTechnicalTriggerRecord());
60  output->setGtTechnicalTrigger(vecTT);
61  e.put(std::move(output));
62 }
63 
64 void CastorTTRecord::getEnergy_fC(double energy[16][14],
65  edm::Handle<CastorDigiCollection> &CastorDigiColl,
66  edm::Event &e,
67  const edm::EventSetup &eventSetup) {
68  // std::cerr << "**** RUNNING THROUGH CastorTTRecord::getEnergy_fC" <<
69  // std::endl;
70 
71  // Get Conditions
73  eventSetup.get<CastorDbRecord>().get(conditions);
74  const CastorQIEShape *shape = conditions->getCastorShape(); // this one is generic
75 
76  for (int isec = 0; isec < 16; isec++)
77  for (int imod = 0; imod < 14; imod++)
78  energy[isec][imod] = 0;
79 
80  // Loop over digis
82  for (idigi = CastorDigiColl->begin(); idigi != CastorDigiColl->end(); idigi++) {
83  const CastorDataFrame &digi = (*idigi);
84  HcalCastorDetId cell = digi.id();
85 
86  // Get Castor Coder
87  const CastorQIECoder *channelCoder = conditions->getCastorCoder(cell);
88  CastorCoderDb coder(*channelCoder, *shape);
89 
90  // Get Castor Calibration
91  const CastorCalibrations &calibrations = conditions->getCastorCalibrations(cell);
92 
93  // convert adc to fC
94  CaloSamples tool;
95  coder.adc2fC(digi, tool);
96 
97  // pedestal substraction
98  int capid = digi[CastorSignalTS_].capid();
99  double fC = tool[CastorSignalTS_] - calibrations.pedestal(capid);
100 
101  // to correct threshold levels in fC for different gains
102  reweighted_gain = calibrations.gain(capid) / 0.015;
103 
104  energy[digi.id().sector() - 1][digi.id().module() - 1] = fC;
105  }
106 }
107 
108 void CastorTTRecord::getTriggerDecisions(std::vector<bool> &decision, double energy[16][14]) const {
109  // std::cerr << "**** RUNNING THROUGH CastorTTRecord::getTriggerDecisions" <<
110  // std::endl;
111 
112  // check if number of bits is at least four
113  if (decision.size() < 4)
114  return;
115 
116  std::vector<bool> tdpo[8]; // TriggerDecisionsPerOctant
117  getTriggerDecisionsPerOctant(tdpo, energy);
118 
119  // preset trigger decisions
120  decision.at(0) = true;
121  decision.at(1) = false;
122  decision.at(2) = false;
123  decision.at(3) = false;
124 
125  // canceld for low pt jet
126  // bool EM_decision = false;
127  // bool HAD_decision = false;
128  // loop over castor octants
129  for (int ioct = 0; ioct < 8; ioct++) {
130  int next_oct = (ioct + 1) % 8;
131  int prev_oct = (ioct + 8 - 1) % 8;
132 
133  // gap Trigger
134  if (!tdpo[ioct].at(0))
135  decision.at(0) = false;
136  if (!tdpo[ioct].at(1))
137  decision.at(0) = false;
138 
139  // jet Trigger
140  if (tdpo[ioct].at(2))
141  decision.at(1) = true;
142 
143  // electron
144  // canceld for low pt jet
145  // if( tdpo[ioct].at(3) ) EM_decision = true;
146  // if( tdpo[ioct].at(4) ) HAD_decision = true;
147 
148  // iso muon
149  if (tdpo[ioct].at(5)) {
150  // was one of the other sectors
151  // in the octant empty ?
152  if (tdpo[ioct].at(0)) {
153  if (tdpo[prev_oct].at(1) && tdpo[next_oct].at(0) && tdpo[next_oct].at(1))
154  decision.at(3) = true;
155  } else if (tdpo[ioct].at(1)) {
156  if (tdpo[prev_oct].at(0) && tdpo[prev_oct].at(1) && tdpo[next_oct].at(0))
157  decision.at(3) = true;
158  }
159  // when not no iso muon
160  }
161 
162  // low pt jet Trigger
163  if (tdpo[ioct].at(6))
164  decision.at(2) = true;
165  }
166 
167  // for EM Trigger whole castor not hadronic and somewhere EM
168  // canceld for low pt jet
169  // decision.at(2) = EM_decision && !HAD_decision;
170 }
171 
172 void CastorTTRecord::getTriggerDecisionsPerOctant(std::vector<bool> tdpo[8], double energy[16][14]) const {
173  // std::cerr << "**** RUNNING THROUGH
174  // CastorTTRecord::getTriggerDecisionsPerOctant" << std::endl;
175 
176  // loop over octatants
177  for (int ioct = 0; ioct < 8; ioct++) {
178  // six bits from HTR card
179  // 0. first sector empty
180  // 1. second sector empty
181  // 2. jet any sector
182  // 3. EM any sector
183  // 4. HAD any sector
184  // 5. muon any sector
185  // add instead of EM Trigger (not bit 6 in real)
186  // 6. low pt jet any sector
187  tdpo[ioct].resize(7);
188 
189  for (int ibit = 0; ibit < 7; ibit++)
190  tdpo[ioct].at(ibit) = false;
191 
192  // loop over castor sectors in octant
193  for (int ioctsec = 0; ioctsec < 2; ioctsec++) {
194  // absolute sector number
195  int isec = 2 * ioct + ioctsec;
196 
197  // init module sums for every sector
198  double fCsum_mod = 0;
199  double fCsum_em = 0, fCsum_ha = 0;
200  double fCsum_jet_had = 0;
201  double fCsum_col[3] = {0, 0, 0};
202 
203  // loop over modules
204  for (int imod = 0; imod < 14; imod++) {
205  // total sum
206  fCsum_mod += energy[isec][imod];
207 
208  // EM & HAD sum
209  if (imod < 2)
210  fCsum_em += energy[isec][imod];
211  if (imod > 2 && imod < 12)
212  fCsum_ha += energy[isec][imod];
213 
214  // sum over three sector parts
215  if (imod < 4)
216  fCsum_col[0] += energy[isec][imod];
217  else if (imod < 8)
218  fCsum_col[1] += energy[isec][imod];
219  else if (imod < 12)
220  fCsum_col[2] += energy[isec][imod];
221 
222  // HAD sum for jet trigger v2
223  if (imod > 1 && imod < 5)
224  fCsum_jet_had += energy[isec][imod];
225  }
226 
227  // gap Trigger
228  if (fCsum_mod < TrigThresholds_.at(0)) {
229  if (ioctsec == 0)
230  tdpo[ioct].at(0) = true;
231  else if (ioctsec == 1)
232  tdpo[ioct].at(1) = true;
233  }
234 
235  // jet Trigger
236  // with gain correction
237  /* old version of jet trigger ( deprecated because of saturation )
238  if( fCsum_mod > TrigThresholds_.at(1) / reweighted_gain )
239  tdpo[ioct].at(2) = true;
240  */
241  if (fCsum_jet_had > TrigThresholds_.at(1) / reweighted_gain)
242  // additional high threshold near saturation for EM part
243  if (energy[isec][0] > 26000 / reweighted_gain && energy[isec][1] > 26000 / reweighted_gain)
244  tdpo[ioct].at(2) = true;
245 
246  // low pt jet Trigger
247  if (fCsum_mod > TrigThresholds_.at(5) / reweighted_gain)
248  tdpo[ioct].at(6) = true;
249 
250  // egamma Trigger
251  // with gain correction only in the EM threshold
252  if (fCsum_em > TrigThresholds_.at(2) / reweighted_gain)
253  tdpo[ioct].at(3) = true;
254  if (fCsum_ha > TrigThresholds_.at(3))
255  tdpo[ioct].at(4) = true;
256 
257  // muon Trigger
258  int countColumns = 0;
259  for (int icol = 0; icol < 3; icol++)
260  if (fCsum_col[icol] > TrigThresholds_.at(4))
261  countColumns++;
262  if (countColumns >= 2)
263  tdpo[ioct].at(5) = true;
264  }
265  }
266 }
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
int sector() const
get the sector (1-16)
std::vector< unsigned int > ttpBits_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
CastorTTRecord(const edm::ParameterSet &ps)
unsigned int CastorSignalTS_
std::vector< std::string > TrigNames_
std::vector< T >::const_iterator const_iterator
const CastorCalibrations & getCastorCalibrations(const HcalGenericDetId &fId) const
int module() const
get the module (1-2 for EM, 1-12 for HAD)
void produce(edm::Event &e, const edm::EventSetup &c) override
std::vector< double > TrigThresholds_
const CastorQIEShape * getCastorShape() const
void getTriggerDecisionsPerOctant(std::vector< bool > tdps[16], double energy[16][14]) const
double pedestal(int fCapId) const
get pedestal for capid=0..3
const_iterator end() const
double gain(int fCapId) const
get gain for capid=0..3
void getTriggerDecisions(std::vector< bool > &decision, double energy[16][14]) const
void adc2fC(const CastorDataFrame &df, CaloSamples &lf) const override
T get() const
Definition: EventSetup.h:71
edm::EDGetTokenT< CastorDigiCollection > CastorDigiColl_
~CastorTTRecord() override
const HcalCastorDetId & id() const
void getEnergy_fC(double energy[16][14], edm::Handle< CastorDigiCollection > &CastorDigiColl, edm::Event &e, const edm::EventSetup &c)
double reweighted_gain
def move(src, dest)
Definition: eostools.py:511
const_iterator begin() const
const CastorQIECoder * getCastorCoder(const HcalGenericDetId &fId) const