48 m_l1GtDataDaqInputTag = m_parameters.getParameter <
InputTag>(
"inputTagL1GtDataDaq");
49 m_verbose = m_parameters.getUntrackedParameter<
bool> (
"verbose",
false);
50 m_refPrescaleSet = m_parameters.getParameter <
int> (
"refPrescaleSet");
51 m_lsShiftGTRates = m_parameters.getUntrackedParameter<
int> (
"lsShiftGTRates",0);
57 m_inputCategories[
"IsoEG"] = Categories.getUntrackedParameter<
bool>(
"IsoEG");
58 m_inputCategories[
"Jet"] = Categories.getUntrackedParameter<
bool>(
"Jet");
59 m_inputCategories[
"CenJet"] = Categories.getUntrackedParameter<
bool>(
"CenJet");
60 m_inputCategories[
"ForJet"] = Categories.getUntrackedParameter<
bool>(
"ForJet");
61 m_inputCategories[
"TauJet"] = Categories.getUntrackedParameter<
bool>(
"TauJet");
62 m_inputCategories[
"ETM"] = Categories.getUntrackedParameter<
bool>(
"ETM");
63 m_inputCategories[
"ETT"] = Categories.getUntrackedParameter<
bool>(
"ETT");
64 m_inputCategories[
"HTT"] = Categories.getUntrackedParameter<
bool>(
"HTT");
65 m_inputCategories[
"HTM"] = Categories.getUntrackedParameter<
bool>(
"HTM");
78 if (m_outputFile.size() != 0) {
79 cout <<
"L1T Monitoring histograms will be saved to " << m_outputFile.c_str() << endl;
83 if (disable) {m_outputFile =
"";}
85 if (dbe !=
NULL) {dbe->setCurrentFolder(
"L1T/L1TRate");}
95 if (m_verbose) {
cout <<
"[L1TRate:] Called beginJob." << endl;}
103 dbe->
rmdir(
"L1T/L1TRate");
111 if (m_verbose) {
cout <<
"[L1TRate:] Called endJob." << endl;}
113 if (m_outputFile.size() != 0 && dbe)
114 dbe->save(m_outputFile);
124 if (m_verbose) {
cout <<
"[L1TRate:] Called beginRun." << endl;}
136 dbe->setCurrentFolder(
"L1T/L1TRate");
137 m_ErrorMonitor = dbe->book1D(
"ErrorMonitor",
"ErrorMonitor",5,0,5);
138 m_ErrorMonitor->setBinLabel(1,
"WARNING_DB_CONN_FAILED");
139 m_ErrorMonitor->setBinLabel(2,
"WARNING_DB_QUERY_FAILED");
140 m_ErrorMonitor->setBinLabel(3,
"WARNING_DB_INCORRECT_NBUNCHES");
141 m_ErrorMonitor->setBinLabel(4,
"WARNING_PY_MISSING_FIT");
142 m_ErrorMonitor->setBinLabel(5,
"UNKNOWN");
149 m_selectedTriggers = myMenuHelper.
getLUSOTrigger(m_inputCategories,m_refPrescaleSet);
152 int srcAlgoXSecFit = m_parameters.getParameter<
int>(
"srcAlgoXSecFit");
153 if (srcAlgoXSecFit == 0){getXSexFitsOMDS (m_parameters);}
154 else if(srcAlgoXSecFit == 1){getXSexFitsPython(m_parameters);}
157 m_algoBit[(
algo->second).algoAlias()] = (
algo->second).algoBitNumber();
160 double minInstantLuminosity = m_parameters.getParameter<
double>(
"minInstantLuminosity");
161 double maxInstantLuminosity = m_parameters.getParameter<
double>(
"maxInstantLuminosity");
164 for(map<string,string>::const_iterator
i=m_selectedTriggers.begin() ;
i!=m_selectedTriggers.end() ;
i++){
166 TString tCategory = (*i).first;
167 TString tTrigger = (*i).second;
169 TString tErrorMessage =
"";
172 if(tTrigger !=
"Undefined" && m_templateFunctions.find(tTrigger) != m_templateFunctions.end()){
173 tTestFunction = m_templateFunctions[tTrigger];
175 else if(tTrigger ==
"Undefined"){
176 TString tFunc =
"-1";
177 tTestFunction =
new TF1(
"FitParametrization_"+tTrigger,tFunc,0,
double(m_maxNbins)-0.5);
179 else if(m_templateFunctions.find(tTrigger) == m_templateFunctions.end()){
180 TString tFunc =
"-1";
181 tTestFunction =
new TF1(
"FitParametrization_"+tTrigger,tFunc,0,
double(m_maxNbins)-0.5);
182 tErrorMessage =
" (Undefined Test Function)";
185 TString tFunc =
"-1";
186 tTestFunction =
new TF1(
"FitParametrization_"+tTrigger,tFunc,0,
double(m_maxNbins)-0.5);
189 if(tTrigger !=
"Undefined"){
192 tErrorMessage +=
" WARNING: Default Prescale = ";
196 if (tCategory ==
"Mu" && myMenuHelper.
getEtaRangeByAlias(tCategory,tTrigger) != 4294967295){
197 tErrorMessage +=
" WARNING: Eta Range = ";
200 else if(tCategory ==
"EG" && myMenuHelper.
getEtaRangeByAlias(tCategory,tTrigger) != 32639){
201 tErrorMessage +=
" WARNING: Eta Range = ";
204 else if(tCategory ==
"IsoEG" && myMenuHelper.
getEtaRangeByAlias(tCategory,tTrigger) != 32639){
205 tErrorMessage +=
" WARNING: Eta Range = ";
209 if(tCategory ==
"Mu" && myMenuHelper.
getQualityAlias(tCategory,tTrigger) != 240){
210 tErrorMessage +=
" WARNING: Quality = ";
218 dbe->setCurrentFolder(
"L1T/L1TRate/TriggerCrossSections");
219 m_xSecVsInstLumi[tTrigger] = dbe->bookProfile(tCategory,
220 "Cross Sec. vs Inst. Lumi Algo: "+tTrigger+tErrorMessage,
222 minInstantLuminosity,
223 maxInstantLuminosity,0,500);
224 m_xSecVsInstLumi[tTrigger] ->setAxisTitle(
"Instantaneous Luminosity [10^{30}cm^{-2}s^{-1}]" ,1);
225 m_xSecVsInstLumi[tTrigger] ->setAxisTitle(
"Algorithm #sigma [#mu b]" ,2);
226 m_xSecVsInstLumi[tTrigger] ->getTProfile()->GetListOfFunctions()->Add(tTestFunction);
227 m_xSecVsInstLumi[tTrigger] ->getTProfile()->SetMarkerStyle(23);
229 dbe->setCurrentFolder(
"L1T/L1TRate/Certification");
230 m_xSecObservedToExpected[tTrigger] = dbe->book1D(tCategory,
"Algo: "+tTrigger+tErrorMessage,m_maxNbins,-0.5,
double(m_maxNbins)-0.5);
231 m_xSecObservedToExpected[tTrigger] ->setAxisTitle(
"Lumi Section" ,1);
232 m_xSecObservedToExpected[tTrigger] ->setAxisTitle(
"#sigma_{obs} / #sigma_{exp}" ,2);
240 if (m_verbose) {
cout <<
"[L1TRate:] Called endRun." << endl;}
246 if (m_verbose) {
cout <<
"[L1TRate:] Called beginLuminosityBlock at LS=" << lumiBlock.
id().
luminosityBlock() << endl;}
254 if (m_verbose) {
cout <<
"[L1TRate:] Called endLuminosityBlock at LS=" << eventLS << endl;}
263 bool isDefRate,isDefLumi,isDefPrescaleIndex;
264 map<TString,double>* rates=0;
266 int prescalesIndex=0;
269 for(map<string,string>::const_iterator
i=m_selectedTriggers.begin() ;
i!=m_selectedTriggers.end() ;
i++){
270 string tTrigger = (*i).second;
271 m_xSecObservedToExpected[tTrigger]->getTH1()->Reset(
"ICE");
272 m_xSecVsInstLumi [tTrigger]->getTH1()->Reset(
"ICE");
275 for(
map<
int,map<TString,double> >::iterator
i=m_lsRates.begin() ;
i!=m_lsRates.end() ;
i++){
277 unsigned int ls = (*i).first;
278 rates = &(*i).second;
281 if(m_lsLuminosity.find(ls)==m_lsLuminosity.end()){isDefLumi=
false;}
284 lumi=m_lsLuminosity[
ls];
287 if(m_lsPrescaleIndex.find(ls)==m_lsPrescaleIndex.end()){isDefPrescaleIndex=
false;}
289 isDefPrescaleIndex=
true;
290 prescalesIndex=m_lsPrescaleIndex[
ls];
293 if(isDefRate && isDefLumi && isDefPrescaleIndex){
295 const vector<int>& currentPrescaleFactors = (*m_listsPrescaleFactors).at(prescalesIndex);
297 for(map<string,string>::const_iterator
i=m_selectedTriggers.begin() ;
i!=m_selectedTriggers.end() ;
i++){
299 string tTrigger = (*i).second;
300 TF1* tTestFunction = (TF1*) m_xSecVsInstLumi[tTrigger]->
getTProfile()->GetListOfFunctions()->First();
303 if(tTrigger !=
"Undefined"){
305 unsigned int trigBit = m_algoBit[tTrigger];
306 double trigPrescale = currentPrescaleFactors[trigBit];
307 double trigRate = (*rates)[tTrigger];
309 if(lumi!=0 && trigPrescale!=0 && trigRate!=0){
311 double AlgoXSec = (trigPrescale*trigRate)/lumi;
312 double TemplateFunctionValue = tTestFunction->Eval(lumi);
315 int ibin = m_xSecObservedToExpected[tTrigger]->getTH1()->FindBin(ls);
316 m_xSecObservedToExpected[tTrigger]->setBinContent(ibin,AlgoXSec/TemplateFunctionValue);
317 m_xSecVsInstLumi [tTrigger]->Fill(lumi,AlgoXSec);
319 if(m_verbose){
cout<<
"[L1TRate:] ls="<<ls<<
" Algo="<<tTrigger<<
" XSec="<<AlgoXSec<<
" Test="<<AlgoXSec/TemplateFunctionValue<<endl;}
323 int ibin = m_xSecObservedToExpected[tTrigger]->getTH1()->FindBin(ls);
324 m_xSecObservedToExpected[tTrigger]->setBinContent(ibin,0.000001);
325 if(m_verbose){
cout <<
"[L1TRate:] Algo="<< tTrigger<<
" XSec=Failed" << endl;}
340 iEvent.
getByLabel(m_l1GtDataDaqInputTag, gtReadoutRecordData);
341 iEvent.
getByLabel(m_scalersSource , colLScal);
342 iEvent.
getByLabel(m_scalersSource , triggerScalers);
345 int EventRun = iEvent.
id().
run();
351 Level1TriggerScalersCollection::const_iterator itL1TScalers = triggerScalers->begin();
354 int gtLS = (*itL1TScalers).lumiSegmentNr()+m_lsShiftGTRates;
357 if(m_lsRates.find(gtLS)==m_lsRates.end()){
359 if (m_verbose) {
cout <<
"[L1TRate:] Buffering GT Rates for LS=" << gtLS << endl;}
360 map<TString,double> bufferRate;
363 for(map<string,string>::const_iterator
i=m_selectedTriggers.begin() ;
i!=m_selectedTriggers.end() ;
i++){
365 string tTrigger = (*i).second;
368 if(tTrigger !=
"Undefined"){
370 unsigned int trigBit = m_algoBit[tTrigger];
373 bufferRate[tTrigger] = trigRate;
376 m_lsRates[gtLS] = bufferRate;
381 if(colLScal.
isValid() && colLScal->size()){
383 LumiScalersCollection::const_iterator itLScal = colLScal->begin();
384 unsigned int scalLS = itLScal->sectionNumber();
387 if(m_lsLuminosity.find(scalLS)==m_lsLuminosity.end()){
389 if (m_verbose) {
cout <<
"[L1TRate:] Buffering SCAL-HF Lumi for LS=" << scalLS << endl;}
390 double instLumi = itLScal->instantLumi();
391 double deadTimeNormHF = itLScal->deadTimeNormalization();
395 if(m_parameters.getUntrackedParameter<
bool>(
"useHFDeadTimeNormalization",
false)){
398 if(deadTimeNormHF==0){instLumi = 0;}
399 else {instLumi = instLumi/deadTimeNormHF;}
402 m_lsLuminosity[scalLS]=instLumi;
407 if(gtReadoutRecordData.
isValid()){
410 if(m_lsPrescaleIndex.find(eventLS)==m_lsPrescaleIndex.end()){
412 if (m_verbose) {
cout <<
"[L1TRate:] Buffering Prescale Index for LS=" << eventLS << endl;}
415 const vector<L1GtFdlWord>& gtFdlVectorData = gtReadoutRecordData->gtFdlVector();
419 for(
unsigned int i=0;
i<gtFdlVectorData.size();
i++){
420 if(gtFdlVectorData[
i].bxInEvent()==0){indexFDL=
i;
break;}
423 int CurrentPrescalesIndex = gtFdlVectorData[indexFDL].gtPrescaleFactorIndexAlgo();
424 m_lsPrescaleIndex[eventLS] = CurrentPrescalesIndex;
443 string pathCondDB = ps.
getParameter<
string>(
"pathCondDB");
447 myOMDSHelper.
connect(oracleDB,pathCondDB,conError);
449 map<string,WbMTriggerXSecFit> wbmFits;
453 wbmFits = myOMDSHelper.getWbMAlgoXsecFits(errorRetrive);
458 string eName = myOMDSHelper.enumToStringError(errorRetrive);
459 m_ErrorMonitor->Fill(eName);
463 string eName = myOMDSHelper.enumToStringError(conError);
464 m_ErrorMonitor->Fill(eName);
467 double minInstantLuminosity = m_parameters.getParameter<
double>(
"minInstantLuminosity");
468 double maxInstantLuminosity = m_parameters.getParameter<
double>(
"maxInstantLuminosity");
471 for(map<string,string>::const_iterator
a=m_selectedTriggers.begin() ;
a!=m_selectedTriggers.end() ;
a++){
473 string tTrigger = (*a).second;
476 if(tTrigger !=
"Undefined"){
478 if(wbmFits.find(tTrigger) != wbmFits.end()){
482 vector<double> tParameters;
483 tParameters.push_back(tWbMParameters.
pm1);
484 tParameters.push_back(tWbMParameters.
p0);
485 tParameters.push_back(tWbMParameters.
p1);
486 tParameters.push_back(tWbMParameters.
p2);
489 m_templateFunctions[tTrigger] =
new TF1(
"FitParametrization_"+tWbMParameters.
bitName,
491 minInstantLuminosity,maxInstantLuminosity);
492 m_templateFunctions[tTrigger] ->SetParameters(&tParameters[0]);
493 m_templateFunctions[tTrigger] ->SetLineWidth(1);
494 m_templateFunctions[tTrigger] ->SetLineColor(kRed);
496 }
else{noError =
false;}
519 std::vector<edm::ParameterSet> m_fitParameters = ps.
getParameter< vector<ParameterSet> >(
"fitParameters");
521 double minInstantLuminosity = m_parameters.getParameter<
double>(
"minInstantLuminosity");
522 double maxInstantLuminosity = m_parameters.getParameter<
double>(
"maxInstantLuminosity");
525 for(map<string,string>::const_iterator
a=m_selectedTriggers.begin() ;
a!=m_selectedTriggers.end() ;
a++){
527 string tTrigger = (*a).second;
530 if(tTrigger !=
"Undefined"){
532 bool foundFit =
false;
534 for(
unsigned int b=0 ;
b<m_fitParameters.size() ;
b++){
536 if(tTrigger == m_fitParameters[
b].getParameter<string>(
"AlgoName")){
538 TString tAlgoName = m_fitParameters[
b].getParameter<
string > (
"AlgoName");
539 TString tTemplateFunction = m_fitParameters[
b].getParameter<
string > (
"TemplateFunction");
540 vector<double> tParameters = m_fitParameters[
b].getParameter< vector<double> >(
"Parameters");
543 m_templateFunctions[tTrigger] =
new TF1(
"FitParametrization_"+tAlgoName,tTemplateFunction,
544 minInstantLuminosity,maxInstantLuminosity);
545 m_templateFunctions[tTrigger] ->SetParameters(&tParameters[0]);
546 m_templateFunctions[tTrigger] ->SetLineWidth(1);
547 m_templateFunctions[tTrigger] ->SetLineColor(kRed);
555 string eName =
"WARNING_PY_MISSING_FIT";
556 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)
void rmdir(const std::string &fullpath)
void beginRun(const edm::Run &run, const edm::EventSetup &iSetup)
DEFINE_FWK_MODULE(HiMixingModule)
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)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
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 setCurrentFolder(const std::string &fullpath)
void analyze(const edm::Event &e, const edm::EventSetup &c)