37 m_scalersSource = consumes<Level1TriggerScalersCollection>(pset.
getParameter <
InputTag>(
"inputTagScalersResults"));
38 m_l1GtDataDaqInputTag = consumes<L1GlobalTriggerReadoutRecord>(pset.
getParameter <
InputTag>(
"inputTagL1GtDataDaq"));
39 m_l1GtEvmSource = consumes<L1GlobalTriggerEvmReadoutRecord>(pset.
getParameter <
InputTag>(
"inputTagtEvmSource"));
43 m_monitorBits = pset.
getParameter< vector<ParameterSet> >(
"MonitorBits");
45 for(
unsigned i=0;
i<m_monitorBits.size();
i++){
48 if(m_monitorBits[
i].getParameter<bool>(
"bitType")){
50 int bit = m_monitorBits[
i].getParameter<
int>(
"bitNumber");
51 int offset = m_monitorBits[
i].getParameter<
int>(
"bitOffset");
52 m_selAlgoBit.push_back( pair<int,int>(bit,offset) );
56 int bit = m_monitorBits[
i].getParameter<
int>(
"bitNumber");
57 int offset = m_monitorBits[
i].getParameter<
int>(
"bitOffset");
58 m_selTechBit.push_back( pair<int,int>(bit,offset) );
62 m_monitorRates = pset.
getParameter< vector<ParameterSet> >(
"MonitorRates");
79 if (m_verbose){
cout <<
"[L1TBPTX] Called beginJob." << endl;}
87 dbe->
rmdir(
"L1T/L1TBPTX");
96 if (m_verbose){
cout <<
"[L1TBPTX] Called endJob." << endl;}
98 if (m_outputFile.size() != 0 && dbe)
99 dbe->save(m_outputFile);
110 if (m_verbose){
cout <<
"[L1TBPTX] Called beginRun." << endl;}
126 m_algoBit_Alias[(algo->second).algoBitNumber()] = (algo->second).algoAlias();
130 m_techBit_Alias[(algo->second).algoBitNumber()] = (algo->second).algoName();
134 dbe->setCurrentFolder(
"L1T/L1TBPTX");
135 m_ErrorMonitor = dbe->book1D(
"ErrorMonitor",
"ErrorMonitor",7,0,7);
136 m_ErrorMonitor->setBinLabel(
UNKNOWN ,
"UNKNOWN");
137 m_ErrorMonitor->setBinLabel(WARNING_DB_CONN_FAILED ,
"WARNING_DB_CONN_FAILED");
138 m_ErrorMonitor->setBinLabel(WARNING_DB_QUERY_FAILED ,
"WARNING_DB_QUERY_FAILED");
139 m_ErrorMonitor->setBinLabel(WARNING_DB_INCORRECT_NBUNCHES,
"WARNING_DB_INCORRECT_NBUNCHES");
140 m_ErrorMonitor->setBinLabel(ERROR_UNABLE_RETRIVE_PRODUCT ,
"ERROR_UNABLE_RETRIVE_PRODUCT");
141 m_ErrorMonitor->setBinLabel(ERROR_TRIGGERALIAS_NOTVALID ,
"ERROR_TRIGGERALIAS_NOTVALID");
142 m_ErrorMonitor->setBinLabel(ERROR_LSBLOCK_NOTVALID ,
"ERROR_LSBLOCK_NOTVALID");
144 for(
unsigned i=0;
i<m_monitorBits.size();
i++){
146 bool isAlgo = m_monitorBits[
i].getParameter<
bool> (
"bitType");
147 TString testName = m_monitorBits[
i].getParameter<
string>(
"testName");
148 int bit = m_monitorBits[
i].getParameter<
int> (
"bitNumber");
150 TString meTitle =
"";
151 dbe->setCurrentFolder(
"L1T/L1TBPTX/Efficiency/");
153 meTitle=
"Algo ";meTitle+=bit; meTitle+=
" - "; meTitle+=m_algoBit_Alias[bit]; meTitle+=
" Efficiency";
154 m_meAlgoEfficiency[bit] = dbe->book1D(testName,meTitle,maxNbins,-0.5,
double(maxNbins)-0.5);
155 m_meAlgoEfficiency[bit]->setAxisTitle(
"Lumi Section" ,1);
158 meTitle=
"Tech "; meTitle+=bit; meTitle+=
" - "; meTitle+=m_techBit_Alias[bit]; meTitle+=
" Efficiency";
159 m_meTechEfficiency[bit] = dbe->book1D(testName,meTitle,maxNbins,-0.5,
double(maxNbins)-0.5);
160 m_meTechEfficiency[bit]->setAxisTitle(
"Lumi Section" ,1);
164 dbe->setCurrentFolder(
"L1T/L1TBPTX/MissFire/");
166 meTitle=
"Algo "; meTitle+=bit; meTitle+=
" - "; meTitle+=m_algoBit_Alias[bit]; meTitle+=
"(1 - Miss Fire Rate)";
167 m_meAlgoMissFire[bit] = dbe->book1D(testName,meTitle,maxNbins,-0.5,
double(maxNbins)-0.5);
168 m_meAlgoMissFire[bit]->setAxisTitle(
"Lumi Section" ,1);
169 m_meAlgoMissFire[bit]->setAxisTitle(
"1 - Miss Fire Rate",2);
172 meTitle=
"Tech "; meTitle+=bit; meTitle+=
" - "; meTitle+=m_techBit_Alias[bit]; meTitle+=
"(1 - Miss Fire Rate)";
173 m_meTechMissFire[bit] = dbe->book1D(testName,meTitle,maxNbins,-0.5,
double(maxNbins)-0.5);
174 m_meTechMissFire[bit]->setAxisTitle(
"Lumi Section" ,1);
175 m_meTechMissFire[bit]->setAxisTitle(
"1 - Miss Fire Rate",2);
179 for(
unsigned i=0;
i<m_monitorRates.size();
i++){
181 TString testName = m_monitorRates[
i].getParameter<
string>(
"testName");
182 bool isAlgo = m_monitorRates[
i].getParameter<
bool> (
"bitType");
183 int bit = m_monitorRates[
i].getParameter<
int> (
"bitNumber");
185 pair<bool,int> refME = pair<bool,int>(isAlgo,bit);
187 TString meTitle =
"";
188 dbe->setCurrentFolder(
"L1T/L1TBPTX/Rate/");
190 meTitle=
"Algo "+bit; meTitle+=
" - "; meTitle+=m_algoBit_Alias[bit]; meTitle+=
" Rate";
191 m_meRate[refME] = dbe->book1D(testName,meTitle,maxNbins,-0.5,
double(maxNbins)-0.5);
192 m_meRate[refME]->setAxisTitle(
"Lumi Section" ,1);
193 m_meRate[refME]->setAxisTitle(
"Rate (unprescaled) [Hz]",2);
196 meTitle=
"Tech "+bit; meTitle+=
" - "; meTitle+=m_techBit_Alias[bit]; meTitle+=
" Rate";
197 m_meRate[refME] = dbe->book1D(testName,meTitle,maxNbins,-0.5,
double(maxNbins)-0.5);
198 m_meRate[refME]->setAxisTitle(
"Lumi Section" ,1);
199 m_meRate[refME]->setAxisTitle(
"Rate (unprescaled) [Hz]",2);
234 if (m_verbose){
cout <<
"[L1TBPTX] Called beginLuminosityBlock." << endl;}
240 m_currentLSValid =
true;
242 for(
unsigned i=0;
i<m_monitorBits.size();
i++){
244 TString triggerName =
"";
245 if(m_monitorBits[
i].getParameter<bool>(
"bitType")){
246 triggerName =
"algo_"+m_monitorBits[
i].getParameter<
int>(
"bitNumber");
248 triggerName =
"tech_"+m_monitorBits[
i].getParameter<
int>(
"bitNumber");
251 m_effNumerator [triggerName] = 0;
252 m_effDenominator [triggerName] = 0;
253 m_missFireNumerator [triggerName] = 0;
254 m_missFireDenominator[triggerName] = 0;
269 if(m_verbose){
cout <<
"[L1TBPTX] Called endLuminosityBlock." << endl;}
272 if(m_currentLSValid && m_beamConfig.isValid()){
274 for(
unsigned i=0;
i<m_monitorBits.size();
i++){
276 bool isAlgo = m_monitorBits[
i].getParameter<
bool> (
"bitType");
277 TString testName = m_monitorBits[
i].getParameter<
string>(
"testName");
278 int bit = m_monitorBits[
i].getParameter<
int> (
"bitNumber");
281 if(isAlgo){triggerName =
"algo_"+bit;}
282 else {triggerName =
"tech_"+bit;}
286 if(m_effDenominator[triggerName]!=0) {valEff = (double)m_effNumerator[triggerName]/m_effDenominator[triggerName];}
288 if(m_missFireDenominator[triggerName]!=0){valMiss = (double)m_missFireNumerator[triggerName]/m_missFireDenominator[triggerName];}
292 int bin = m_meAlgoEfficiency[bit]->getTH1()->FindBin(m_currentLS);
293 m_meAlgoEfficiency[bit]->setBinContent(bin,valEff);
294 m_meAlgoMissFire[bit] ->setBinContent(bin,1-valMiss);
297 int bin = m_meTechEfficiency[bit]->getTH1()->FindBin(m_currentLS);
298 m_meTechEfficiency[bit]->setBinContent(bin,valEff);
299 m_meTechMissFire[bit] ->setBinContent(bin,1-valMiss);
311 if(m_currentLSValid){
313 const vector<int>& currentPFAlgo = (*m_prescaleFactorsAlgoTrig).at(m_currentPrescalesIndex);
314 const vector<int>& currentPFTech = (*m_prescaleFactorsTechTrig).at(m_currentPrescalesIndex);
316 for(
unsigned i=0;
i<m_monitorRates.size();
i++){
318 bool isAlgo = m_monitorRates[
i].getParameter<
bool> (
"bitType");
319 int bit = m_monitorRates[
i].getParameter<
int> (
"bitNumber");
321 pair<bool,int> refME = pair<bool,int>(isAlgo,bit);
324 int bin = m_meRate[refME]->getTH1()->FindBin(m_currentGTLS);
325 int trigPS = currentPFAlgo[bit];
326 double trigRate = (double) trigPS*m_l1Rate[refME];
327 m_meRate[refME]->setBinContent(bin,trigRate);
330 int bin = m_meRate[refME]->getTH1()->FindBin(m_currentGTLS);
331 int trigPS = currentPFTech[bit];
332 double trigRate = (double) trigPS*m_l1Rate[refME];
333 m_meRate[refME]->setBinContent(bin,trigRate);
342 if(m_verbose){
cout <<
"[L1TBPTX] Called endRun." << endl;}
350 if(m_verbose){
cout <<
"[L1TBPTX] Called analyze." << endl;}
353 if(m_currentLSValid){
355 if(m_verbose){
cout <<
"[L1TBPTX] -> m_currentLSValid=" << m_currentLSValid << endl;}
359 iEvent.
getByToken(m_l1GtEvmSource, gtEvmReadoutRecord);
362 if(gtEvmReadoutRecord.
isValid()){
364 const L1GtfeExtWord& gtfeEvmWord = gtEvmReadoutRecord->gtfeWord();
365 unsigned int lhcBeamMode = gtfeEvmWord.
beamMode();
367 if(m_verbose){
cout <<
"[L1TBPTX] Beam mode: "<< lhcBeamMode << endl;}
369 if(lhcBeamMode==RAMP || lhcBeamMode==FLATTOP || lhcBeamMode==SQUEEZE || lhcBeamMode==ADJUST || lhcBeamMode==STABLE){
373 if(m_verbose){
cout <<
"[L1TBPTX] No valid bunch structure yet retrived. Attemptting to retrive..." << endl;}
383 if(m_beamConfig.nCollidingBunches<=0){
385 m_currentLSValid=
false;
389 else{m_currentLSValid=
false;}
392 int eCount = m_ErrorMonitor->getTH1()->GetBinContent(ERROR_UNABLE_RETRIVE_PRODUCT);
394 m_ErrorMonitor->getTH1()->SetBinContent(ERROR_UNABLE_RETRIVE_PRODUCT,eCount);
401 if(m_currentLSValid && m_beamConfig.isValid()){
403 if(m_verbose){
cout <<
"Current event in valid LS and beam config" << endl;}
407 iEvent.
getByToken(m_l1GtDataDaqInputTag, gtReadoutRecordData);
409 if(gtReadoutRecordData.
isValid()){
411 const vector<L1GtFdlWord>& gtFdlVectorData = gtReadoutRecordData->gtFdlVector();
415 for(
unsigned int i=0;
i<gtFdlVectorData.size();
i++){
416 if(gtFdlVectorData[
i].bxInEvent()==0){eventFDL=
i;
break;}
419 m_currentPrescalesIndex = gtFdlVectorData[eventFDL].gtPrescaleFactorIndexAlgo();
421 for(
unsigned i=0;
i<m_monitorBits.size();
i++){
423 TString triggerName =
"";
424 bool isAlgo = m_monitorBits[
i].getParameter<
bool>(
"bitType");
425 int bit = m_monitorBits[
i].getParameter<
int> (
"bitNumber");
426 int offset = m_monitorBits[
i].getParameter<
int> (
"bitOffset");
428 if(isAlgo){triggerName =
"algo_"+bit;}
429 else {triggerName =
"tech_"+bit;}
434 if(offset<0){evBxStart+=-1*
offset;}
435 if(offset>0){evBxEnd +=-1*
offset;}
437 for(
unsigned a=0;
a<gtFdlVectorData.size();
a++){
439 int testBx = gtFdlVectorData[
a].localBxNr()-
offset;
440 bool lhcBxFilled = m_beamConfig.beam1[testBx] && m_beamConfig.beam2[testBx];
441 bool algoFired =
false;
444 if(gtFdlVectorData[
a].gtDecisionWord()[bit]){algoFired=
true;}
448 if(gtFdlVectorData[
a].gtTechnicalTriggerWord()[bit]){algoFired=
true;}
451 if(lhcBxFilled) {m_effDenominator[triggerName]++;}
452 if(lhcBxFilled && algoFired){m_effNumerator [triggerName]++;}
454 if(algoFired) {m_missFireNumerator[triggerName]++;}
455 if(algoFired && !lhcBxFilled){m_missFireNumerator[triggerName]++;}
466 iEvent.
getByToken(m_scalersSource,triggerScalers);
470 Level1TriggerScalersCollection::const_iterator itL1TScalers = triggerScalers->begin();
473 m_currentGTLS= (*itL1TScalers).lumiSegmentNr();
475 for(
unsigned i=0;
i<m_monitorRates.size();
i++){
477 bool isAlgo = m_monitorRates[
i].getParameter<
bool>(
"bitType");
478 int bit = m_monitorRates[
i].getParameter<
int> (
"bitNumber");
480 pair<bool,int> refTrig = pair<bool,int>(isAlgo,bit);
483 else {m_l1Rate[refTrig] = trigRates.gtTechCountsRate()[bit];}
496 if(m_verbose){
cout <<
"[L1TBPTX] Called getBeamConfOMDS()" << endl;}
499 string oracleDB = m_parameters.getParameter<
string>(
"oracleDB");
500 string pathCondDB = m_parameters.getParameter<
string>(
"pathCondDB");
505 myOMDSHelper.connect(oracleDB,pathCondDB,conError);
509 if(m_verbose){
cout <<
"[L1TBPTX] Connected to DB with no error." << endl;}
512 m_beamConfig = myOMDSHelper.getBeamConfiguration(m_lhcFill,errorRetrive);
516 cout <<
"[L1TBPTX] Retriving LHC Bunch Structure: NO_ERROR" << endl;
517 cout <<
"[L1TSync] -> LHC Bunch Structure valid=" << m_beamConfig.m_valid <<
" nBunches=" << m_beamConfig.nCollidingBunches << endl;
521 if(m_verbose){
cout <<
"[L1TBPTX] Retriving LHC Bunch Structure: WARNING_DB_QUERY_FAILED" << endl;}
523 int eCount = m_ErrorMonitor->getTH1()->GetBinContent(WARNING_DB_QUERY_FAILED);
525 m_ErrorMonitor->getTH1()->SetBinContent(WARNING_DB_QUERY_FAILED,eCount);
528 if(m_verbose){
cout <<
"[L1TBPTX] Retriving LHC Bunch Structure: WARNING_DB_INCORRECT_NBUNCHES" << endl;}
530 int eCount = m_ErrorMonitor->getTH1()->GetBinContent(WARNING_DB_INCORRECT_NBUNCHES);
532 m_ErrorMonitor->getTH1()->SetBinContent(WARNING_DB_INCORRECT_NBUNCHES,eCount);
535 if(m_verbose){
cout <<
"[L1TBPTX] Retriving LHC Bunch Structure: UNKNOWN" << endl;}
536 int eCount = m_ErrorMonitor->getTH1()->GetBinContent(
UNKNOWN);
538 m_ErrorMonitor->getTH1()->SetBinContent(
UNKNOWN,eCount);
543 if(m_verbose){
cout <<
"[L1TBPTX] Connection to DB: WARNING_DB_CONN_FAILED" << endl;}
544 int eCount = m_ErrorMonitor->getTH1()->GetBinContent(WARNING_DB_CONN_FAILED);
546 m_ErrorMonitor->getTH1()->SetBinContent(WARNING_DB_CONN_FAILED,eCount);
549 if(m_verbose){
cout <<
"[L1TBPTX] Connection to DB: UNKNOWN" << endl;}
550 int eCount = m_ErrorMonitor->getTH1()->GetBinContent(
UNKNOWN);
552 m_ErrorMonitor->getTH1()->SetBinContent(
UNKNOWN,eCount);
LuminosityBlockID id() const
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
void analyze(const edm::Event &e, const edm::EventSetup &c)
void doFractionInSync(bool iForce=false, bool iBad=false)
virtual void endLuminosityBlock(edm::LuminosityBlock const &lumiBlock, edm::EventSetup const &c)
void rmdir(const std::string &fullpath)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
virtual void beginLuminosityBlock(edm::LuminosityBlock const &lumiBlock, edm::EventSetup const &c)
0: Unidentified isolated particle
L1TBPTX(const edm::ParameterSet &ps)
DEFINE_FWK_MODULE(HiMixingModule)
std::vector< double > gtAlgoCountsRate() const
unsigned int offset(bool)
void certifyLSBlock(std::string iTrigger, int iInitLs, int iEndLs, float iValue)
const std::vector< std::vector< int > > & gtPrescaleFactors() const
get the prescale factors by reference
void endRun(const edm::Run &run, const edm::EventSetup &iSetup)
const cms_uint32_t lhcFillNumber() const
T const * product() const
LuminosityBlockNumber_t luminosityBlock() const
void beginRun(const edm::Run &run, const edm::EventSetup &iSetup)
BeginRun.
const cms_uint16_t beamMode() const
void setCurrentFolder(const std::string &fullpath)