41 m_scalersSource_colLScal = consumes<LumiScalersCollection> (m_parameters.getParameter<
InputTag>(
"inputTagScalersResults"));
42 m_scalersSource_triggerScalers = consumes<Level1TriggerScalersCollection> (m_parameters.getParameter<
InputTag>(
"inputTagScalersResults"));
43 m_l1GtDataDaqInputTag = consumes<L1GlobalTriggerReadoutRecord> (m_parameters.getParameter<
InputTag>(
"inputTagL1GtDataDaq"));
44 m_verbose = m_parameters.getUntrackedParameter<
bool> (
"verbose",
false);
45 m_refPrescaleSet = m_parameters.getParameter <
int> (
"refPrescaleSet");
46 m_lsShiftGTRates = m_parameters.getUntrackedParameter<
int> (
"lsShiftGTRates",0);
52 m_inputCategories[
"IsoEG"] = Categories.getUntrackedParameter<
bool>(
"IsoEG");
53 m_inputCategories[
"Jet"] = Categories.getUntrackedParameter<
bool>(
"Jet");
54 m_inputCategories[
"CenJet"] = Categories.getUntrackedParameter<
bool>(
"CenJet");
55 m_inputCategories[
"ForJet"] = Categories.getUntrackedParameter<
bool>(
"ForJet");
56 m_inputCategories[
"TauJet"] = Categories.getUntrackedParameter<
bool>(
"TauJet");
57 m_inputCategories[
"ETM"] = Categories.getUntrackedParameter<
bool>(
"ETM");
58 m_inputCategories[
"ETT"] = Categories.getUntrackedParameter<
bool>(
"ETT");
59 m_inputCategories[
"HTT"] = Categories.getUntrackedParameter<
bool>(
"HTT");
60 m_inputCategories[
"HTM"] = Categories.getUntrackedParameter<
bool>(
"HTM");
73 if (m_outputFile.size() != 0) {
74 cout <<
"L1T Monitoring histograms will be saved to " << m_outputFile.c_str() << endl;
78 if (disable) {m_outputFile =
"";}
80 if (dbe !=
NULL) {dbe->setCurrentFolder(
"L1T/L1TRate");}
90 if (m_verbose) {
cout <<
"[L1TRate:] Called beginJob." << endl;}
97 dbe->setCurrentFolder(
"L1T/L1TRate");
98 dbe->rmdir(
"L1T/L1TRate");
106 if (m_verbose) {
cout <<
"[L1TRate:] Called endJob." << endl;}
108 if (m_outputFile.size() != 0 && dbe)
109 dbe->save(m_outputFile);
119 if (m_verbose) {
cout <<
"[L1TRate:] Called beginRun." << endl;}
131 dbe->setCurrentFolder(
"L1T/L1TRate");
132 m_ErrorMonitor = dbe->book1D(
"ErrorMonitor",
"ErrorMonitor",5,0,5);
133 m_ErrorMonitor->setBinLabel(1,
"WARNING_DB_CONN_FAILED");
134 m_ErrorMonitor->setBinLabel(2,
"WARNING_DB_QUERY_FAILED");
135 m_ErrorMonitor->setBinLabel(3,
"WARNING_DB_INCORRECT_NBUNCHES");
136 m_ErrorMonitor->setBinLabel(4,
"WARNING_PY_MISSING_FIT");
137 m_ErrorMonitor->setBinLabel(5,
"UNKNOWN");
144 m_selectedTriggers = myMenuHelper.
getLUSOTrigger(m_inputCategories,m_refPrescaleSet);
147 int srcAlgoXSecFit = m_parameters.getParameter<
int>(
"srcAlgoXSecFit");
148 if (srcAlgoXSecFit == 0){getXSexFitsOMDS (m_parameters);}
149 else if(srcAlgoXSecFit == 1){getXSexFitsPython(m_parameters);}
152 m_algoBit[(algo->second).algoAlias()] = (algo->second).algoBitNumber();
155 double minInstantLuminosity = m_parameters.getParameter<
double>(
"minInstantLuminosity");
156 double maxInstantLuminosity = m_parameters.getParameter<
double>(
"maxInstantLuminosity");
159 for(map<string,string>::const_iterator
i=m_selectedTriggers.begin() ;
i!=m_selectedTriggers.end() ;
i++){
161 TString tCategory = (*i).first;
162 TString tTrigger = (*i).second;
164 TString tErrorMessage =
"";
167 if(tTrigger !=
"Undefined" && m_templateFunctions.find(tTrigger) != m_templateFunctions.end()){
168 tTestFunction = m_templateFunctions[tTrigger];
170 else if(tTrigger ==
"Undefined"){
171 TString tFunc =
"-1";
172 tTestFunction =
new TF1(
"FitParametrization_"+tTrigger,tFunc,0,
double(m_maxNbins)-0.5);
174 else if(m_templateFunctions.find(tTrigger) == m_templateFunctions.end()){
175 TString tFunc =
"-1";
176 tTestFunction =
new TF1(
"FitParametrization_"+tTrigger,tFunc,0,
double(m_maxNbins)-0.5);
177 tErrorMessage =
" (Undefined Test Function)";
180 TString tFunc =
"-1";
181 tTestFunction =
new TF1(
"FitParametrization_"+tTrigger,tFunc,0,
double(m_maxNbins)-0.5);
184 if(tTrigger !=
"Undefined"){
187 tErrorMessage +=
" WARNING: Default Prescale = ";
191 if (tCategory ==
"Mu" && myMenuHelper.
getEtaRangeByAlias(tCategory,tTrigger) != 4294967295){
192 tErrorMessage +=
" WARNING: Eta Range = ";
195 else if(tCategory ==
"EG" && myMenuHelper.
getEtaRangeByAlias(tCategory,tTrigger) != 32639){
196 tErrorMessage +=
" WARNING: Eta Range = ";
199 else if(tCategory ==
"IsoEG" && myMenuHelper.
getEtaRangeByAlias(tCategory,tTrigger) != 32639){
200 tErrorMessage +=
" WARNING: Eta Range = ";
204 if(tCategory ==
"Mu" && myMenuHelper.
getQualityAlias(tCategory,tTrigger) != 240){
205 tErrorMessage +=
" WARNING: Quality = ";
213 dbe->setCurrentFolder(
"L1T/L1TRate/TriggerCrossSections");
214 m_xSecVsInstLumi[tTrigger] = dbe->bookProfile(tCategory,
215 "Cross Sec. vs Inst. Lumi Algo: "+tTrigger+tErrorMessage,
217 minInstantLuminosity,
218 maxInstantLuminosity,0,500);
219 m_xSecVsInstLumi[tTrigger] ->setAxisTitle(
"Instantaneous Luminosity [10^{30}cm^{-2}s^{-1}]" ,1);
220 m_xSecVsInstLumi[tTrigger] ->setAxisTitle(
"Algorithm #sigma [#mu b]" ,2);
221 m_xSecVsInstLumi[tTrigger] ->getTProfile()->GetListOfFunctions()->Add(tTestFunction);
222 m_xSecVsInstLumi[tTrigger] ->getTProfile()->SetMarkerStyle(23);
224 dbe->setCurrentFolder(
"L1T/L1TRate/Certification");
225 m_xSecObservedToExpected[tTrigger] = dbe->book1D(tCategory,
"Algo: "+tTrigger+tErrorMessage,m_maxNbins,-0.5,
double(m_maxNbins)-0.5);
226 m_xSecObservedToExpected[tTrigger] ->setAxisTitle(
"Lumi Section" ,1);
227 m_xSecObservedToExpected[tTrigger] ->setAxisTitle(
"#sigma_{obs} / #sigma_{exp}" ,2);
235 if (m_verbose) {
cout <<
"[L1TRate:] Called endRun." << endl;}
241 if (m_verbose) {
cout <<
"[L1TRate:] Called beginLuminosityBlock at LS=" << lumiBlock.
id().
luminosityBlock() << endl;}
249 if (m_verbose) {
cout <<
"[L1TRate:] Called endLuminosityBlock at LS=" << eventLS << endl;}
258 bool isDefRate,isDefLumi,isDefPrescaleIndex;
259 map<TString,double>* rates=0;
261 int prescalesIndex=0;
264 for(map<string,string>::const_iterator
i=m_selectedTriggers.begin() ;
i!=m_selectedTriggers.end() ;
i++){
265 string tTrigger = (*i).second;
266 m_xSecObservedToExpected[tTrigger]->getTH1()->Reset(
"ICE");
267 m_xSecVsInstLumi [tTrigger]->getTH1()->Reset(
"ICE");
270 for(
map<
int,map<TString,double> >::iterator
i=m_lsRates.begin() ;
i!=m_lsRates.end() ;
i++){
272 unsigned int ls = (*i).first;
273 rates = &(*i).second;
276 if(m_lsLuminosity.find(ls)==m_lsLuminosity.end()){isDefLumi=
false;}
279 lumi=m_lsLuminosity[
ls];
282 if(m_lsPrescaleIndex.find(ls)==m_lsPrescaleIndex.end()){isDefPrescaleIndex=
false;}
284 isDefPrescaleIndex=
true;
285 prescalesIndex=m_lsPrescaleIndex[
ls];
288 if(isDefRate && isDefLumi && isDefPrescaleIndex){
290 const vector<int>& currentPrescaleFactors = (*m_listsPrescaleFactors).at(prescalesIndex);
292 for(map<string,string>::const_iterator
i=m_selectedTriggers.begin() ;
i!=m_selectedTriggers.end() ;
i++){
294 string tTrigger = (*i).second;
295 TF1* tTestFunction = (TF1*) m_xSecVsInstLumi[tTrigger]->
getTProfile()->GetListOfFunctions()->First();
298 if(tTrigger !=
"Undefined"){
300 unsigned int trigBit = m_algoBit[tTrigger];
301 double trigPrescale = currentPrescaleFactors[trigBit];
302 double trigRate = (*rates)[tTrigger];
304 if(lumi!=0 && trigPrescale!=0 && trigRate!=0){
306 double AlgoXSec = (trigPrescale*trigRate)/lumi;
307 double TemplateFunctionValue = tTestFunction->Eval(lumi);
310 int ibin = m_xSecObservedToExpected[tTrigger]->getTH1()->FindBin(ls);
311 m_xSecObservedToExpected[tTrigger]->setBinContent(ibin,AlgoXSec/TemplateFunctionValue);
312 m_xSecVsInstLumi [tTrigger]->Fill(lumi,AlgoXSec);
314 if(m_verbose){
cout<<
"[L1TRate:] ls="<<ls<<
" Algo="<<tTrigger<<
" XSec="<<AlgoXSec<<
" Test="<<AlgoXSec/TemplateFunctionValue<<endl;}
318 int ibin = m_xSecObservedToExpected[tTrigger]->getTH1()->FindBin(ls);
319 m_xSecObservedToExpected[tTrigger]->setBinContent(ibin,0.000001);
320 if(m_verbose){
cout <<
"[L1TRate:] Algo="<< tTrigger<<
" XSec=Failed" << endl;}
335 iEvent.
getByToken(m_l1GtDataDaqInputTag, gtReadoutRecordData);
336 iEvent.
getByToken(m_scalersSource_colLScal, colLScal);
337 iEvent.
getByToken(m_scalersSource_triggerScalers, triggerScalers);
340 int EventRun = iEvent.
id().
run();
346 Level1TriggerScalersCollection::const_iterator itL1TScalers = triggerScalers->begin();
349 int gtLS = (*itL1TScalers).lumiSegmentNr()+m_lsShiftGTRates;
352 if(m_lsRates.find(gtLS)==m_lsRates.end()){
354 if (m_verbose) {
cout <<
"[L1TRate:] Buffering GT Rates for LS=" << gtLS << endl;}
355 map<TString,double> bufferRate;
358 for(map<string,string>::const_iterator
i=m_selectedTriggers.begin() ;
i!=m_selectedTriggers.end() ;
i++){
360 string tTrigger = (*i).second;
363 if(tTrigger !=
"Undefined"){
365 unsigned int trigBit = m_algoBit[tTrigger];
368 bufferRate[tTrigger] = trigRate;
371 m_lsRates[gtLS] = bufferRate;
376 if(colLScal.
isValid() && colLScal->size()){
378 LumiScalersCollection::const_iterator itLScal = colLScal->begin();
379 unsigned int scalLS = itLScal->sectionNumber();
382 if(m_lsLuminosity.find(scalLS)==m_lsLuminosity.end()){
384 if (m_verbose) {
cout <<
"[L1TRate:] Buffering SCAL-HF Lumi for LS=" << scalLS << endl;}
385 double instLumi = itLScal->instantLumi();
386 double deadTimeNormHF = itLScal->deadTimeNormalization();
390 if(m_parameters.getUntrackedParameter<
bool>(
"useHFDeadTimeNormalization",
false)){
393 if(deadTimeNormHF==0){instLumi = 0;}
394 else {instLumi = instLumi/deadTimeNormHF;}
397 m_lsLuminosity[scalLS]=instLumi;
402 if(gtReadoutRecordData.
isValid()){
405 if(m_lsPrescaleIndex.find(eventLS)==m_lsPrescaleIndex.end()){
407 if (m_verbose) {
cout <<
"[L1TRate:] Buffering Prescale Index for LS=" << eventLS << endl;}
410 const vector<L1GtFdlWord>& gtFdlVectorData = gtReadoutRecordData->gtFdlVector();
414 for(
unsigned int i=0;
i<gtFdlVectorData.size();
i++){
415 if(gtFdlVectorData[
i].bxInEvent()==0){indexFDL=
i;
break;}
418 int CurrentPrescalesIndex = gtFdlVectorData[indexFDL].gtPrescaleFactorIndexAlgo();
419 m_lsPrescaleIndex[eventLS] = CurrentPrescalesIndex;
438 string pathCondDB = ps.
getParameter<
string>(
"pathCondDB");
442 myOMDSHelper.
connect(oracleDB,pathCondDB,conError);
444 map<string,WbMTriggerXSecFit> wbmFits;
448 wbmFits = myOMDSHelper.getWbMAlgoXsecFits(errorRetrive);
453 string eName = myOMDSHelper.enumToStringError(errorRetrive);
454 m_ErrorMonitor->Fill(eName);
458 string eName = myOMDSHelper.enumToStringError(conError);
459 m_ErrorMonitor->Fill(eName);
462 double minInstantLuminosity = m_parameters.getParameter<
double>(
"minInstantLuminosity");
463 double maxInstantLuminosity = m_parameters.getParameter<
double>(
"maxInstantLuminosity");
466 for(map<string,string>::const_iterator
a=m_selectedTriggers.begin() ;
a!=m_selectedTriggers.end() ;
a++){
468 string tTrigger = (*a).second;
471 if(tTrigger !=
"Undefined"){
473 if(wbmFits.find(tTrigger) != wbmFits.end()){
477 vector<double> tParameters;
478 tParameters.push_back(tWbMParameters.
pm1);
479 tParameters.push_back(tWbMParameters.
p0);
480 tParameters.push_back(tWbMParameters.
p1);
481 tParameters.push_back(tWbMParameters.
p2);
484 m_templateFunctions[tTrigger] =
new TF1(
"FitParametrization_"+tWbMParameters.
bitName,
486 minInstantLuminosity,maxInstantLuminosity);
487 m_templateFunctions[tTrigger] ->SetParameters(&tParameters[0]);
488 m_templateFunctions[tTrigger] ->SetLineWidth(1);
489 m_templateFunctions[tTrigger] ->SetLineColor(kRed);
491 }
else{noError =
false;}
514 std::vector<edm::ParameterSet> m_fitParameters = ps.
getParameter< vector<ParameterSet> >(
"fitParameters");
516 double minInstantLuminosity = m_parameters.getParameter<
double>(
"minInstantLuminosity");
517 double maxInstantLuminosity = m_parameters.getParameter<
double>(
"maxInstantLuminosity");
520 for(map<string,string>::const_iterator
a=m_selectedTriggers.begin() ;
a!=m_selectedTriggers.end() ;
a++){
522 string tTrigger = (*a).second;
525 if(tTrigger !=
"Undefined"){
527 bool foundFit =
false;
529 for(
unsigned int b=0 ;
b<m_fitParameters.size() ;
b++){
531 if(tTrigger == m_fitParameters[
b].getParameter<string>(
"AlgoName")){
533 TString tAlgoName = m_fitParameters[
b].getParameter<
string > (
"AlgoName");
534 TString tTemplateFunction = m_fitParameters[
b].getParameter<
string > (
"TemplateFunction");
535 vector<double> tParameters = m_fitParameters[
b].getParameter< vector<double> >(
"Parameters");
538 m_templateFunctions[tTrigger] =
new TF1(
"FitParametrization_"+tAlgoName,tTemplateFunction,
539 minInstantLuminosity,maxInstantLuminosity);
540 m_templateFunctions[tTrigger] ->SetParameters(&tParameters[0]);
541 m_templateFunctions[tTrigger] ->SetLineWidth(1);
542 m_templateFunctions[tTrigger] ->SetLineColor(kRed);
550 string eName =
"WARNING_PY_MISSING_FIT";
551 m_ErrorMonitor->Fill(eName);
LuminosityBlockID id() const
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
TProfile * getTProfile(std::string name, std::string process, std::string rootfolder, DQMStore *dbe_, bool verb, bool clone)
bool connect(std::string iOracleDB, std::string iPathCondDB, int &error)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
#define DEFINE_FWK_MODULE(type)
void beginRun(const edm::Run &run, const edm::EventSetup &iSetup)
LuminosityBlockNumber_t luminosityBlock() const
std::vector< double > gtAlgoCountsRate() const
bool getXSexFitsPython(const edm::ParameterSet &ps)
L1TRate(const edm::ParameterSet &ps)
bool getXSexFitsOMDS(const edm::ParameterSet &ps)
void endRun(const edm::Run &run, const edm::EventSetup &iSetup)
const std::vector< std::vector< int > > & gtPrescaleFactors() const
get the prescale factors by reference
T const * product() const
LuminosityBlockNumber_t luminosityBlock() const
virtual void beginLuminosityBlock(edm::LuminosityBlock const &lumiBlock, edm::EventSetup const &c)
virtual void endLuminosityBlock(edm::LuminosityBlock const &lumiBlock, edm::EventSetup const &c)
void analyze(const edm::Event &e, const edm::EventSetup &c)