27 m_scalersSource_LSCollection = consumes<LumiScalersCollection> (m_parameters.getParameter<
InputTag>(
"inputTagScalersResults"));
28 m_scalersSource_L1TSCollection = consumes<Level1TriggerScalersCollection>(m_parameters.getParameter<
InputTag>(
"inputTagScalersResults"));
29 m_l1GtDataDaqInputTag = consumes<L1GlobalTriggerReadoutRecord> (m_parameters.getParameter<
InputTag>(
"inputTagL1GtDataDaq"));
30 m_verbose = m_parameters.getUntrackedParameter<
bool>(
"verbose",
false);
31 m_refPrescaleSet = m_parameters.getParameter <
int> (
"refPrescaleSet");
32 m_lsShiftGTRates = m_parameters.getUntrackedParameter<
int> (
"lsShiftGTRates",0);
38 m_inputCategories[
"IsoEG"] = Categories.getUntrackedParameter<
bool>(
"IsoEG");
39 m_inputCategories[
"Jet"] = Categories.getUntrackedParameter<
bool>(
"Jet");
40 m_inputCategories[
"CenJet"] = Categories.getUntrackedParameter<
bool>(
"CenJet");
41 m_inputCategories[
"ForJet"] = Categories.getUntrackedParameter<
bool>(
"ForJet");
42 m_inputCategories[
"TauJet"] = Categories.getUntrackedParameter<
bool>(
"TauJet");
43 m_inputCategories[
"ETM"] = Categories.getUntrackedParameter<
bool>(
"ETM");
44 m_inputCategories[
"ETT"] = Categories.getUntrackedParameter<
bool>(
"ETT");
45 m_inputCategories[
"HTT"] = Categories.getUntrackedParameter<
bool>(
"HTT");
46 m_inputCategories[
"HTM"] = Categories.getUntrackedParameter<
bool>(
"HTM");
50 cout <<
"[L1TRate_Offline:] ____________ Storage initialization ____________ " << endl;
51 cout <<
"[L1TRate_Offline:] Setting up dbe folder: L1T/L1TRate" << endl;
63 if (m_verbose) {
cout <<
"[L1TRate_Offline:] Called beginRun." << endl;}
76 m_ErrorMonitor = ibooker.
book1D(
"ErrorMonitor",
"ErrorMonitor",2,0,2);
78 m_ErrorMonitor->setBinLabel(WARNING_PY_MISSING_FIT,
"WARNING_PY_MISSING_FIT");
80 if (m_verbose) {
cout <<
"[L1TRate_Offline:] m_ErrorMonitor: " << m_ErrorMonitor << endl;}
87 m_selectedTriggers = myMenuHelper.
getLUSOTrigger(m_inputCategories,m_refPrescaleSet);
90 getXSexFitsPython(m_parameters);
93 m_algoBit[(
algo->second).algoAlias()] = (
algo->second).algoBitNumber();
96 double minInstantLuminosity = m_parameters.getParameter<
double>(
"minInstantLuminosity");
97 double maxInstantLuminosity = m_parameters.getParameter<
double>(
"maxInstantLuminosity");
100 for(map<string,string>::const_iterator
i=m_selectedTriggers.begin() ;
i!=m_selectedTriggers.end() ;
i++){
102 TString tCategory = (*i).first;
103 TString tTrigger = (*i).second;
105 TString tErrorMessage =
"";
108 if(tTrigger !=
"Undefined" && m_templateFunctions.find(tTrigger) != m_templateFunctions.end()){
109 tTestFunction = m_templateFunctions[tTrigger];
111 else if(tTrigger ==
"Undefined"){
112 TString tFunc =
"-1";
113 tTestFunction =
new TF1(
"FitParametrization_"+tTrigger,tFunc,0,
double(m_maxNbins)-0.5);
115 else if(m_templateFunctions.find(tTrigger) == m_templateFunctions.end()){
116 TString tFunc =
"-1";
117 tTestFunction =
new TF1(
"FitParametrization_"+tTrigger,tFunc,0,
double(m_maxNbins)-0.5);
118 tErrorMessage =
" (Undefined Test Function)";
121 TString tFunc =
"-1";
122 tTestFunction =
new TF1(
"FitParametrization_"+tTrigger,tFunc,0,
double(m_maxNbins)-0.5);
125 if(tTrigger !=
"Undefined"){
128 tErrorMessage +=
" WARNING: Default Prescale = ";
132 if (tCategory ==
"Mu" && myMenuHelper.
getEtaRangeByAlias(tCategory,tTrigger) != 4294967295){
133 tErrorMessage +=
" WARNING: Eta Range = ";
136 else if(tCategory ==
"EG" && myMenuHelper.
getEtaRangeByAlias(tCategory,tTrigger) != 32639){
137 tErrorMessage +=
" WARNING: Eta Range = ";
140 else if(tCategory ==
"IsoEG" && myMenuHelper.
getEtaRangeByAlias(tCategory,tTrigger) != 32639){
141 tErrorMessage +=
" WARNING: Eta Range = ";
145 if(tCategory ==
"Mu" && myMenuHelper.
getQualityAlias(tCategory,tTrigger) != 240){
146 tErrorMessage +=
" WARNING: Quality = ";
153 m_xSecObservedVsDelivLumi[tTrigger] = ibooker.
bookProfile(tCategory,
154 "Cross Sec. vs Deliv. Lumi: "+tTrigger+tErrorMessage,
156 minInstantLuminosity,
157 maxInstantLuminosity,0,500);
158 m_xSecObservedVsDelivLumi[tTrigger] ->
setAxisTitle(
"Delivered Luminosity [10^{30}cm^{-2}s^{-1}]" ,1);
159 m_xSecObservedVsDelivLumi[tTrigger] ->setAxisTitle(
"Algorithm #sigma [#mu b]" ,2);
162 m_xSecObservedVsRecorLumi[tTrigger] = ibooker.
bookProfile(tCategory,
163 "Cross Sec. vs Recor. Lumi: "+tTrigger+tErrorMessage,
165 minInstantLuminosity,
166 maxInstantLuminosity,0,500);
167 m_xSecObservedVsRecorLumi[tTrigger] ->
setAxisTitle(
"Recorded Luminosity [10^{30}cm^{-2}s^{-1}]" ,1);
168 m_xSecObservedVsRecorLumi[tTrigger] ->setAxisTitle(
"Algorithm #sigma [#mu b]" ,2);
171 m_CountsVsLS[tTrigger] = ibooker.
bookProfile(tCategory,
172 "Cross Sec. vs Inst. Lumi Algo: "+tTrigger+tErrorMessage,
174 minInstantLuminosity,
175 maxInstantLuminosity,0,500);
176 m_CountsVsLS[tTrigger] ->
setAxisTitle(
"Instantaneous Luminosity [10^{30}cm^{-2}s^{-1}]" ,1);
177 m_CountsVsLS[tTrigger] ->setAxisTitle(
"Algorithm #sigma [#mu b]" ,2);
178 m_CountsVsLS[tTrigger] ->getTProfile()->GetListOfFunctions()->Add(tTestFunction);
179 m_CountsVsLS[tTrigger] ->getTProfile()->SetMarkerStyle(23);
181 m_algoFit[tTrigger] = (TF1*) tTestFunction->Clone(
"Fit_"+tTrigger);
184 m_xSecObservedVsLS[tTrigger] = ibooker.
book1D(tCategory,
"Algo: "+tTrigger+tErrorMessage,m_maxNbins,-0.5,
double(m_maxNbins)-0.5);
185 m_xSecObservedVsLS[tTrigger] ->
setAxisTitle(
"Lumi Section" ,1);
186 m_xSecObservedVsLS[tTrigger] ->setAxisTitle(
"#sigma_{obs}" ,2);
189 m_DelivLumiVsLS[tTrigger] = ibooker.
book1D(tCategory,
"Algo: "+tTrigger+tErrorMessage,m_maxNbins,-0.5,
double(m_maxNbins)-0.5);
190 m_DelivLumiVsLS[tTrigger] ->
setAxisTitle(
"Lumi Section" ,1);
191 m_DelivLumiVsLS[tTrigger] ->setAxisTitle(
"Deliv. Lumi" ,2);
194 m_RecorLumiVsLS[tTrigger] = ibooker.
book1D(tCategory,
"Algo: "+tTrigger+tErrorMessage,m_maxNbins,-0.5,
double(m_maxNbins)-0.5);
195 m_RecorLumiVsLS[tTrigger] ->
setAxisTitle(
"Lumi Section" ,1);
196 m_RecorLumiVsLS[tTrigger] ->setAxisTitle(
"Recor. Lumi" ,2);
199 m_xSecObservedToExpected[tTrigger] = ibooker.
book1D(tCategory,
"Algo: "+tTrigger+tErrorMessage,m_maxNbins,-0.5,
double(m_maxNbins)-0.5);
200 m_xSecObservedToExpected[tTrigger] ->
setAxisTitle(
"Lumi Section" ,1);
201 m_xSecObservedToExpected[tTrigger] ->setAxisTitle(
"#sigma_{obs} / #sigma_{exp}" ,2);
213 if (m_verbose) {
cout <<
"[L1TRate_Offline:] Called beginLuminosityBlock at LS=" << lumiBlock.
id().
luminosityBlock() << endl;}
221 if (m_verbose) {
cout <<
"[L1TRate_Offline:] Called endLuminosityBlock at LS=" << eventLS << endl;}
231 bool isDefLumi,isDefPrescaleIndex;
235 int prescalesIndex=0;
238 map<TString,double>* counts=0;
241 for(map<string,string>::const_iterator
i=m_selectedTriggers.begin() ;
i!=m_selectedTriggers.end() ;
i++){
242 string tTrigger = (*i).second;
244 m_CountsVsLS [tTrigger]->getTH1()->Reset(
"ICE");
245 m_xSecObservedToExpected[tTrigger]->getTH1()->Reset(
"ICE");
247 m_xSecObservedVsLS [tTrigger]->getTH1()->Reset(
"ICE");
248 m_DelivLumiVsLS [tTrigger]->getTH1()->Reset(
"ICE");
249 m_RecorLumiVsLS [tTrigger]->getTH1()->Reset(
"ICE");
251 m_xSecObservedVsDelivLumi[tTrigger]->getTH1()->Reset(
"ICE");
252 m_xSecObservedVsRecorLumi[tTrigger]->getTH1()->Reset(
"ICE");
257 for(
map<
int,map<TString,double> >::iterator
j=m_lsRates.begin() ;
j!=m_lsRates.end() ;
j++){
259 unsigned int lsOffline = (*j).first;
260 counts = &(*j).second;
263 unsigned int lsPreInd;
265 if(m_lsLuminosity.find(lsOffline)==m_lsLuminosity.end()){isDefLumi=
false;}
268 lumi=m_lsLuminosity[lsOffline];
269 deadtime=m_lsDeadTime[lsOffline];
272 lsPreInd = lsOffline + 1;
274 if(m_lsPrescaleIndex.find(lsPreInd)==m_lsPrescaleIndex.end()){isDefPrescaleIndex=
false;}
276 isDefPrescaleIndex=
true;
277 prescalesIndex=m_lsPrescaleIndex[lsPreInd];
280 if(isDefCount && isDefLumi && isDefPrescaleIndex){
282 const vector<int>& currentPrescaleFactors = (*m_listsPrescaleFactors).at(prescalesIndex);
284 for(map<string,string>::const_iterator
j=m_selectedTriggers.begin() ;
j!=m_selectedTriggers.end() ;
j++){
286 string tTrigger = (*j).second;
287 double trigCount = (*counts)[tTrigger];
290 TF1* tTestFunction = m_algoFit[tTrigger];
294 if(tTrigger !=
"Undefined"){
296 unsigned int trigBit = m_algoBit[tTrigger];
297 double trigPrescale = currentPrescaleFactors[trigBit];
299 if(lumi!=0 && trigCount!=0 && trigPrescale!=0){
301 double RecLumi = lumi*(1. - deadtime/100.);
303 double AlgoXSec = (trigPrescale*trigCount)/RecLumi;
304 double TemplateFunctionValue = tTestFunction->Eval(lumi);
311 m_xSecObservedVsRecorLumi[tTrigger]->Fill(RecLumi,AlgoXSec);
313 m_CountsVsLS [tTrigger]->Fill(lumi,AlgoXSec);
315 int ibin = m_xSecObservedToExpected[tTrigger]->getTH1()->FindBin(lsOffline);
316 m_xSecObservedToExpected[tTrigger]->setBinContent(ibin,AlgoXSec/TemplateFunctionValue);
318 m_DelivLumiVsLS[tTrigger]->setBinContent(ibin,lumi);
319 m_RecorLumiVsLS[tTrigger]->setBinContent(ibin,RecLumi);
321 m_xSecObservedVsLS[tTrigger]->setBinContent(ibin,AlgoXSec);
327 m_xSecObservedVsRecorLumi[tTrigger]->Fill(0.000001,0.000001);
329 m_CountsVsLS [tTrigger]->Fill(0.000001,0.000001);
331 int ibin = m_xSecObservedToExpected[tTrigger]->getTH1()->FindBin(lsOffline);
332 m_xSecObservedToExpected[tTrigger]->setBinContent(ibin,0.000001);
334 m_DelivLumiVsLS[tTrigger]->setBinContent(ibin,0.000001);
335 m_RecorLumiVsLS[tTrigger]->setBinContent(ibin,0.000001);
337 m_xSecObservedVsLS[tTrigger]->setBinContent(ibin,0.000001);
353 iEvent.
getByToken(m_l1GtDataDaqInputTag , gtReadoutRecordData);
354 iEvent.
getByToken(m_scalersSource_LSCollection , colLScal);
355 iEvent.
getByToken(m_scalersSource_L1TSCollection , triggerScalers);
358 int EventRun = iEvent.
id().
run();
362 if(triggerScalers.
isValid() && triggerScalers->size()){
364 Level1TriggerScalersCollection::const_iterator itL1TScalers = triggerScalers->begin();
373 const std::vector<unsigned int> gtAlgoCounts = itL1TScalers->gtAlgoCounts();
380 int gtLS = (*itL1TScalers).lumiSegmentNr()+m_lsShiftGTRates;
383 if(m_lsRates.find(gtLS)==m_lsRates.end()){
385 map<TString,double> bufferCount;
388 for(map<string,string>::const_iterator
i=m_selectedTriggers.begin();
i!=m_selectedTriggers.end() ;
i++){
390 string tTrigger = (*i).second;
393 if(tTrigger !=
"Undefined"){
395 unsigned int trigBit = m_algoBit[tTrigger];
396 double trigCount = gtAlgoCounts[trigBit];
398 bufferCount[tTrigger] = trigCount;
402 m_lsRates[gtLS] = bufferCount;
403 m_lsDeadTime[gtLS] = deadtime;
409 if(colLScal.
isValid() && colLScal->size()){
411 LumiScalersCollection::const_iterator itLScal = colLScal->begin();
412 unsigned int scalLS = itLScal->sectionNumber();
415 if(m_lsLuminosity.find(scalLS)==m_lsLuminosity.end()){
417 if (m_verbose) {
cout <<
"[L1TRate_Offline:] Buffering SCAL-HF Lumi for LS=" << scalLS << endl;}
418 double instLumi = itLScal->instantLumi();
419 double deadTimeNormHF = itLScal->deadTimeNormalization();
439 if(m_parameters.getUntrackedParameter<
bool>(
"useHFDeadTimeNormalization",
false)){
442 if(deadTimeNormHF==0){instLumi = 0;}
443 else {instLumi = instLumi/deadTimeNormHF;}
446 m_lsLuminosity[scalLS]=instLumi;
451 if(gtReadoutRecordData.
isValid()){
454 if(m_lsPrescaleIndex.find(eventLS)==m_lsPrescaleIndex.end()){
456 if (m_verbose) {
cout <<
"[L1TRate_Offline:] Buffering Prescale Index for LS=" << eventLS << endl;}
459 const vector<L1GtFdlWord>& gtFdlVectorData = gtReadoutRecordData->gtFdlVector();
463 for(
unsigned int i=0;
i<gtFdlVectorData.size();
i++){
464 if(gtFdlVectorData[
i].bxInEvent()==0){indexFDL=
i;
break;}
467 if(gtFdlVectorData.size() != 0)
469 int CurrentPrescalesIndex = gtFdlVectorData[indexFDL].gtPrescaleFactorIndexAlgo();
470 m_lsPrescaleIndex[eventLS] = CurrentPrescalesIndex;
493 std::vector<edm::ParameterSet> m_fitParameters = ps.
getParameter< vector<ParameterSet> >(
"fitParameters");
495 double minInstantLuminosity = m_parameters.getParameter<
double>(
"minInstantLuminosity");
496 double maxInstantLuminosity = m_parameters.getParameter<
double>(
"maxInstantLuminosity");
499 for(map<string,string>::const_iterator
a=m_selectedTriggers.begin() ;
a!=m_selectedTriggers.end() ;
a++){
501 string tTrigger = (*a).second;
504 if(tTrigger !=
"Undefined"){
506 bool foundFit =
false;
508 for(
unsigned int b=0 ;
b<m_fitParameters.size() ;
b++){
510 if(tTrigger == m_fitParameters[
b].getParameter<string>(
"AlgoName")){
512 TString tAlgoName = m_fitParameters[
b].getParameter<
string > (
"AlgoName");
513 TString tTemplateFunction = m_fitParameters[
b].getParameter<
string > (
"TemplateFunction");
514 vector<double> tParameters = m_fitParameters[
b].getParameter< vector<double> >(
"Parameters");
517 m_templateFunctions[tTrigger] =
new TF1(
"FitParametrization_"+tAlgoName,tTemplateFunction,
518 minInstantLuminosity,maxInstantLuminosity);
519 m_templateFunctions[tTrigger] ->SetParameters(&tParameters[0]);
520 m_templateFunctions[tTrigger] ->SetLineWidth(1);
521 m_templateFunctions[tTrigger] ->SetLineColor(kRed);
531 int eCount = m_ErrorMonitor->getTH1()->GetBinContent(WARNING_PY_MISSING_FIT);
533 m_ErrorMonitor->getTH1()->SetBinContent(WARNING_PY_MISSING_FIT,eCount);
virtual void beginLuminosityBlock(edm::LuminosityBlock const &lumiBlock, edm::EventSetup const &c)
LuminosityBlockID id() const
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
virtual void dqmBeginRun(edm::Run const &, edm::EventSetup const &)
MonitorElement * bookProfile(Args &&...args)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
#define DEFINE_FWK_MODULE(type)
0: Unidentified isolated particle
virtual void endLuminosityBlock(edm::LuminosityBlock const &lumiBlock, edm::EventSetup const &c)
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)
LuminosityBlockNumber_t luminosityBlock() const
bool getXSexFitsPython(const edm::ParameterSet &ps)
virtual ~L1TRate_Offline()
L1TRate_Offline(const edm::ParameterSet &ps)
void analyze(const edm::Event &e, const edm::EventSetup &c)
MonitorElement * book1D(Args &&...args)
void setCurrentFolder(const std::string &fullpath)
const std::vector< std::vector< int > > & gtPrescaleFactors() const
get the prescale factors by reference
T const * product() const
LuminosityBlockNumber_t luminosityBlock() const
double deadtimePercent() const
virtual void bookHistograms(DQMStore::IBooker &ibooker, const edm::Run &run, const edm::EventSetup &iSetup) override
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)