00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "DQMOffline/L1Trigger/interface/L1TRate_Offline.h"
00012
00013 #include "DQMOffline/L1Trigger/interface/L1TMenuHelper.h"
00014
00015 #include "DQMServices/Core/interface/DQMStore.h"
00016
00017 #include "DataFormats/Scalers/interface/LumiScalers.h"
00018 #include "DataFormats/Scalers/interface/Level1TriggerRates.h"
00019 #include "DataFormats/Scalers/interface/Level1TriggerScalers.h"
00020 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutRecord.h"
00021 #include "DataFormats/Common/interface/ConditionsInEdm.h"
00022 #include "DataFormats/Luminosity/interface/LumiDetails.h"
00023 #include "DataFormats/Luminosity/interface/LumiSummary.h"
00024
00025 #include "CondFormats/L1TObjects/interface/L1GtTriggerMenu.h"
00026 #include "CondFormats/L1TObjects/interface/L1GtTriggerMenuFwd.h"
00027 #include "CondFormats/L1TObjects/interface/L1GtPrescaleFactors.h"
00028 #include "CondFormats/L1TObjects/interface/L1GtTriggerMask.h"
00029 #include "CondFormats/DataRecord/interface/L1GtTriggerMaskAlgoTrigRcd.h"
00030 #include "CondFormats/DataRecord/interface/L1GtTriggerMenuRcd.h"
00031 #include "CondFormats/DataRecord/interface/L1GtPrescaleFactorsAlgoTrigRcd.h"
00032
00033 #include "DataFormats/Histograms/interface/MEtoEDMFormat.h"
00034
00035 #include "TList.h"
00036
00037 using namespace edm;
00038 using namespace std;
00039
00040
00041 L1TRate_Offline::L1TRate_Offline(const ParameterSet & ps){
00042
00043 m_maxNbins = 2500;
00044 m_parameters = ps;
00045
00046
00047 m_scalersSource = m_parameters.getParameter <InputTag>("inputTagScalersResults");
00048 m_l1GtDataDaqInputTag = m_parameters.getParameter <InputTag>("inputTagL1GtDataDaq");
00049 m_verbose = m_parameters.getUntrackedParameter<bool> ("verbose",false);
00050 m_refPrescaleSet = m_parameters.getParameter <int> ("refPrescaleSet");
00051 m_lsShiftGTRates = m_parameters.getUntrackedParameter<int> ("lsShiftGTRates",0);
00052
00053
00054 ParameterSet Categories = ps.getParameter<ParameterSet>("categories");
00055 m_inputCategories["Mu"] = Categories.getUntrackedParameter<bool>("Mu");
00056 m_inputCategories["EG"] = Categories.getUntrackedParameter<bool>("EG");
00057 m_inputCategories["IsoEG"] = Categories.getUntrackedParameter<bool>("IsoEG");
00058 m_inputCategories["Jet"] = Categories.getUntrackedParameter<bool>("Jet");
00059 m_inputCategories["CenJet"] = Categories.getUntrackedParameter<bool>("CenJet");
00060 m_inputCategories["ForJet"] = Categories.getUntrackedParameter<bool>("ForJet");
00061 m_inputCategories["TauJet"] = Categories.getUntrackedParameter<bool>("TauJet");
00062 m_inputCategories["ETM"] = Categories.getUntrackedParameter<bool>("ETM");
00063 m_inputCategories["ETT"] = Categories.getUntrackedParameter<bool>("ETT");
00064 m_inputCategories["HTT"] = Categories.getUntrackedParameter<bool>("HTT");
00065 m_inputCategories["HTM"] = Categories.getUntrackedParameter<bool>("HTM");
00066
00067
00068 if (m_verbose) {
00069 cout << "[L1TRate_Offline:] ____________ Storage inicialization ____________ " << endl;
00070 cout << "[L1TRate_Offline:] Setting up dbe folder: L1T/L1TRate_Offline" << endl;
00071 }
00072
00073 dbe = Service < DQMStore > ().operator->();
00074 dbe->setVerbose(0);
00075 dbe->setCurrentFolder("L1T/L1TRate_Offline");
00076
00077
00078 if (m_verbose) {cout << "[L1TRate_Offline:] Pointer for DQM Store: " << dbe << endl;}
00079 }
00080
00081
00082 L1TRate_Offline::~L1TRate_Offline(){}
00083
00084
00085 void L1TRate_Offline::beginJob(void){
00086
00087 if (m_verbose) {cout << "[L1TRate_Offline:] Called beginJob." << endl;}
00088
00089
00090 DQMStore *dbe = 0;
00091 dbe = Service < DQMStore > ().operator->();
00092
00093 if (dbe) {
00094 dbe->setCurrentFolder("L1T/L1TRate_Offline");
00095 dbe->rmdir("L1T/L1TRate_Offline");
00096 }
00097
00098 }
00099
00100
00101 void L1TRate_Offline::endJob(void){
00102
00103 if (m_verbose) {cout << "[L1TRate_Offline:] Called endJob." << endl;}
00104
00105 if (m_outputFile.size() != 0 && dbe)
00106 dbe->save(m_outputFile);
00107
00108 return;
00109
00110 }
00111
00112
00113
00114
00115 void L1TRate_Offline::beginRun(const edm::Run& run, const edm::EventSetup& iSetup){
00116
00117 if (m_verbose) {cout << "[L1TRate_Offline:] Called beginRun." << endl;}
00118
00119 ESHandle<L1GtTriggerMenu> menuRcd;
00120 ESHandle<L1GtPrescaleFactors> l1GtPfAlgo;
00121
00122 iSetup.get<L1GtTriggerMenuRcd>() .get(menuRcd);
00123 iSetup.get<L1GtPrescaleFactorsAlgoTrigRcd>().get(l1GtPfAlgo);
00124
00125 const L1GtTriggerMenu* menu = menuRcd .product();
00126 const L1GtPrescaleFactors* m_l1GtPfAlgo = l1GtPfAlgo.product();
00127
00128
00129 dbe->setCurrentFolder("L1T/L1TRate_Offline");
00130 m_ErrorMonitor = dbe->book1D("ErrorMonitor", "ErrorMonitor",2,0,2);
00131 m_ErrorMonitor->setBinLabel(UNKNOWN ,"UNKNOWN");
00132 m_ErrorMonitor->setBinLabel(WARNING_PY_MISSING_FIT,"WARNING_PY_MISSING_FIT");
00133
00134 cout << "[L1TRate_Offline:] m_ErrorMonitor: " << m_ErrorMonitor << endl;
00135
00136
00137 m_listsPrescaleFactors = &(m_l1GtPfAlgo->gtPrescaleFactors());
00138
00139
00140 L1TMenuHelper myMenuHelper = L1TMenuHelper(iSetup);
00141 m_selectedTriggers = myMenuHelper.getLUSOTrigger(m_inputCategories,m_refPrescaleSet);
00142
00143
00144 getXSexFitsPython(m_parameters);
00145
00146 for (CItAlgo algo = menu->gtAlgorithmMap().begin(); algo!=menu->gtAlgorithmMap().end(); ++algo){
00147 m_algoBit[(algo->second).algoAlias()] = (algo->second).algoBitNumber();
00148 }
00149
00150 double minInstantLuminosity = m_parameters.getParameter<double>("minInstantLuminosity");
00151 double maxInstantLuminosity = m_parameters.getParameter<double>("maxInstantLuminosity");
00152
00153
00154 for(map<string,string>::const_iterator i=m_selectedTriggers.begin() ; i!=m_selectedTriggers.end() ; i++){
00155
00156 TString tCategory = (*i).first;
00157 TString tTrigger = (*i).second;
00158
00159 TString tErrorMessage = "";
00160 TF1* tTestFunction;
00161
00162 if(tTrigger != "Undefined" && m_templateFunctions.find(tTrigger) != m_templateFunctions.end()){
00163 tTestFunction = m_templateFunctions[tTrigger];
00164 }
00165 else if(tTrigger == "Undefined"){
00166 TString tFunc = "-1";
00167 tTestFunction = new TF1("FitParametrization_"+tTrigger,tFunc,0,double(m_maxNbins)-0.5);
00168 }
00169 else if(m_templateFunctions.find(tTrigger) == m_templateFunctions.end()){
00170 TString tFunc = "-1";
00171 tTestFunction = new TF1("FitParametrization_"+tTrigger,tFunc,0,double(m_maxNbins)-0.5);
00172 tErrorMessage = " (Undefined Test Function)";
00173 }
00174 else{
00175 TString tFunc = "-1";
00176 tTestFunction = new TF1("FitParametrization_"+tTrigger,tFunc,0,double(m_maxNbins)-0.5);
00177 }
00178
00179 if(tTrigger != "Undefined"){
00180
00181 if(myMenuHelper.getPrescaleByAlias(tCategory,tTrigger) != 1){
00182 tErrorMessage += " WARNING: Default Prescale = ";
00183 tErrorMessage += myMenuHelper.getPrescaleByAlias(tCategory,tTrigger);
00184 }
00185
00186 if (tCategory == "Mu" && myMenuHelper.getEtaRangeByAlias(tCategory,tTrigger) != 4294967295){
00187 tErrorMessage += " WARNING: Eta Range = ";
00188 tErrorMessage += myMenuHelper.getEtaRangeByAlias(tCategory,tTrigger);
00189 }
00190 else if(tCategory == "EG" && myMenuHelper.getEtaRangeByAlias(tCategory,tTrigger) != 32639){
00191 tErrorMessage += " WARNING: Eta Range = ";
00192 tErrorMessage += myMenuHelper.getEtaRangeByAlias(tCategory,tTrigger);
00193 }
00194 else if(tCategory == "IsoEG" && myMenuHelper.getEtaRangeByAlias(tCategory,tTrigger) != 32639){
00195 tErrorMessage += " WARNING: Eta Range = ";
00196 tErrorMessage += myMenuHelper.getEtaRangeByAlias(tCategory,tTrigger);
00197 }
00198
00199 if(tCategory == "Mu" && myMenuHelper.getQualityAlias(tCategory,tTrigger) != 240){
00200 tErrorMessage += " WARNING: Quality = ";
00201 tErrorMessage += myMenuHelper.getQualityAlias(tCategory,tTrigger);
00202 }
00203
00204 }
00205
00206 dbe->setCurrentFolder("L1T/L1TRate_Offline/TriggerCounts");
00207 m_CountsVsLS[tTrigger] = dbe->bookProfile(tCategory,
00208 "Cross Sec. vs Inst. Lumi Algo: "+tTrigger+tErrorMessage,
00209 m_maxNbins,
00210 minInstantLuminosity,
00211 maxInstantLuminosity,0,500);
00212 m_CountsVsLS[tTrigger] ->setAxisTitle("Instantaneous Luminosity [10^{30}cm^{-2}s^{-1}]" ,1);
00213 m_CountsVsLS[tTrigger] ->setAxisTitle("Algorithm #sigma [#mu b]" ,2);
00214 m_CountsVsLS[tTrigger] ->getTProfile()->GetListOfFunctions()->Add(tTestFunction);
00215 m_CountsVsLS[tTrigger] ->getTProfile()->SetMarkerStyle(23);
00216
00217 m_algoFit[tTrigger] = (TF1*) tTestFunction->Clone("Fit_"+tTrigger);
00218
00219 dbe->setCurrentFolder("L1T/L1TRate_Offline/Ratio");
00220 m_xSecObservedToExpected[tTrigger] = dbe->book1D(tCategory, "Algo: "+tTrigger+tErrorMessage,m_maxNbins,-0.5,double(m_maxNbins)-0.5);
00221 m_xSecObservedToExpected[tTrigger] ->setAxisTitle("Lumi Section" ,1);
00222 m_xSecObservedToExpected[tTrigger] ->setAxisTitle("#sigma_{obs} / #sigma_{exp}" ,2);
00223
00224
00225 }
00226
00227 }
00228
00229
00230 void L1TRate_Offline::endRun(const edm::Run& run, const edm::EventSetup& iSetup){
00231
00232 if (m_verbose) {cout << "[L1TRate_Offline:] Called endRun." << endl;}
00233 }
00234
00235
00236 void L1TRate_Offline::beginLuminosityBlock(LuminosityBlock const& lumiBlock, EventSetup const& c) {
00237
00238 if (m_verbose) {cout << "[L1TRate_Offline:] Called beginLuminosityBlock at LS=" << lumiBlock.id().luminosityBlock() << endl;}
00239
00240 }
00241
00242
00243 void L1TRate_Offline::endLuminosityBlock(LuminosityBlock const& lumiBlock, EventSetup const& c) {
00244
00245 int eventLS = lumiBlock.id().luminosityBlock();
00246 if (m_verbose) {cout << "[L1TRate_Offline:] Called endLuminosityBlock at LS=" << eventLS << endl;}
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256 bool isDefLumi,isDefPrescaleIndex;
00257
00258 double lumi=0;
00259 int prescalesIndex=0;
00260
00261 bool isDefCount;
00262 map<TString,double>* counts=0;
00263
00264
00265 for(map<string,string>::const_iterator i=m_selectedTriggers.begin() ; i!=m_selectedTriggers.end() ; i++){
00266 string tTrigger = (*i).second;
00267 m_CountsVsLS [tTrigger]->getTH1()->Reset("ICE");
00268 m_xSecObservedToExpected[tTrigger]->getTH1()->Reset("ICE");
00269
00270 }
00271
00272
00273 for(map<int,map<TString,double> >::iterator j=m_lsRates.begin() ; j!=m_lsRates.end() ; j++){
00274
00275 unsigned int lsOffline = (*j).first;
00276 counts = &(*j).second;
00277 isDefCount=true;
00278
00279 unsigned int lsPreInd;
00280
00281 if(m_lsLuminosity.find(lsOffline)==m_lsLuminosity.end()){isDefLumi=false;}
00282 else{
00283 isDefLumi=true;
00284 lumi=m_lsLuminosity[lsOffline];
00285 }
00286
00287 lsPreInd = lsOffline + 1;
00288
00289 if(m_lsPrescaleIndex.find(lsPreInd)==m_lsPrescaleIndex.end()){isDefPrescaleIndex=false;}
00290 else{
00291 isDefPrescaleIndex=true;
00292 prescalesIndex=m_lsPrescaleIndex[lsPreInd];
00293 }
00294
00295 if(isDefCount && isDefLumi && isDefPrescaleIndex){
00296
00297
00298
00299 for(map<string,string>::const_iterator j=m_selectedTriggers.begin() ; j!=m_selectedTriggers.end() ; j++){
00300
00301 string tTrigger = (*j).second;
00302 double trigCount = (*counts)[tTrigger];
00303
00304
00305 TF1* tTestFunction = m_algoFit[tTrigger];
00306
00307
00308
00309 if(tTrigger != "Undefined"){
00310
00311
00312 if(lumi!=0 && trigCount!=0 && prescalesIndex!=0){
00313
00314 double AlgoXSec = (prescalesIndex*trigCount)/lumi;
00315 double TemplateFunctionValue = tTestFunction->Eval(lumi);
00316
00317
00318 m_CountsVsLS [tTrigger]->Fill(lumi,AlgoXSec);
00319
00320 int ibin = m_xSecObservedToExpected[tTrigger]->getTH1()->FindBin(lsOffline);
00321 m_xSecObservedToExpected[tTrigger]->setBinContent(ibin,AlgoXSec/TemplateFunctionValue);
00322
00323
00324 }
00325 else {
00326 m_CountsVsLS [tTrigger]->Fill(0.000001,0.000001);
00327
00328 int ibin = m_xSecObservedToExpected[tTrigger]->getTH1()->FindBin(lsOffline);
00329 m_xSecObservedToExpected[tTrigger]->setBinContent(ibin,0.000001);
00330 }
00331 }
00332 }
00333 }
00334 }
00335 }
00336
00337
00338
00339 void L1TRate_Offline::analyze(const Event & iEvent, const EventSetup & eventSetup){
00340
00341 edm::Handle<L1GlobalTriggerReadoutRecord> gtReadoutRecordData;
00342 edm::Handle<Level1TriggerScalersCollection> triggerScalers;
00343 edm::Handle<LumiScalersCollection> colLScal;
00344
00345 iEvent.getByLabel(m_l1GtDataDaqInputTag, gtReadoutRecordData);
00346 iEvent.getByLabel(m_scalersSource , colLScal);
00347 iEvent.getByLabel(m_scalersSource , triggerScalers);
00348
00349
00350
00351 unsigned int eventLS = iEvent.id().luminosityBlock();
00352
00353
00354 if(triggerScalers.isValid() && triggerScalers->size()){
00355
00356 Level1TriggerScalersCollection::const_iterator itL1TScalers = triggerScalers->begin();
00357
00358
00359
00360 const std::vector<unsigned int> gtAlgoCounts = itL1TScalers->gtAlgoCounts();
00361
00362 int gtLS = (*itL1TScalers).lumiSegmentNr()+m_lsShiftGTRates;
00363
00364
00365 if(m_lsRates.find(gtLS)==m_lsRates.end()){
00366
00367 map<TString,double> bufferCount;
00368
00369
00370 for(map<string,string>::const_iterator i=m_selectedTriggers.begin(); i!=m_selectedTriggers.end() ; i++){
00371
00372 string tTrigger = (*i).second;
00373
00374
00375 if(tTrigger != "Undefined"){
00376
00377 unsigned int trigBit = m_algoBit[tTrigger];
00378 double trigCount = gtAlgoCounts[trigBit];
00379
00380 bufferCount[tTrigger] = trigCount;
00381
00382 }
00383 }
00384 m_lsRates[gtLS] = bufferCount;
00385 }
00386 }
00387
00388
00389
00390 if(colLScal.isValid() && colLScal->size()){
00391
00392 LumiScalersCollection::const_iterator itLScal = colLScal->begin();
00393 unsigned int scalLS = itLScal->sectionNumber();
00394
00395
00396 if(m_lsLuminosity.find(scalLS)==m_lsLuminosity.end()){
00397
00398 if (m_verbose) {cout << "[L1TRate_Offline:] Buffering SCAL-HF Lumi for LS=" << scalLS << endl;}
00399 double instLumi = itLScal->instantLumi();
00400 double deadTimeNormHF = itLScal->deadTimeNormalization();
00401
00402
00403
00404 if(m_parameters.getUntrackedParameter<bool>("useHFDeadTimeNormalization",false)){
00405
00406
00407 if(deadTimeNormHF==0){instLumi = 0;}
00408 else {instLumi = instLumi/deadTimeNormHF;}
00409 }
00410
00411 m_lsLuminosity[scalLS]=instLumi;
00412 }
00413 }
00414
00415
00416 if(gtReadoutRecordData.isValid()){
00417
00418
00419 if(m_lsPrescaleIndex.find(eventLS)==m_lsPrescaleIndex.end()){
00420
00421 if (m_verbose) {cout << "[L1TRate_Offline:] Buffering Prescale Index for LS=" << eventLS << endl;}
00422
00423
00424 const vector<L1GtFdlWord>& gtFdlVectorData = gtReadoutRecordData->gtFdlVector();
00425
00426
00427 int indexFDL=0;
00428 for(unsigned int i=0; i<gtFdlVectorData.size(); i++){
00429 if(gtFdlVectorData[i].bxInEvent()==0){indexFDL=i; break;}
00430 }
00431
00432 int CurrentPrescalesIndex = gtFdlVectorData[indexFDL].gtPrescaleFactorIndexAlgo();
00433 m_lsPrescaleIndex[eventLS] = CurrentPrescalesIndex;
00434
00435 }
00436
00437 }
00438
00439
00440 }
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451 bool L1TRate_Offline::getXSexFitsPython(const edm::ParameterSet& ps){
00452
00453
00454 bool noError = true;
00455
00456
00457 std::vector<edm::ParameterSet> m_fitParameters = ps.getParameter< vector<ParameterSet> >("fitParameters");
00458
00459 double minInstantLuminosity = m_parameters.getParameter<double>("minInstantLuminosity");
00460 double maxInstantLuminosity = m_parameters.getParameter<double>("maxInstantLuminosity");
00461
00462
00463 for(map<string,string>::const_iterator a=m_selectedTriggers.begin() ; a!=m_selectedTriggers.end() ; a++){
00464
00465 string tTrigger = (*a).second;
00466
00467
00468 if(tTrigger != "Undefined"){
00469
00470 bool foundFit = false;
00471
00472 for(unsigned int b=0 ; b<m_fitParameters.size() ; b++){
00473
00474 if(tTrigger == m_fitParameters[b].getParameter<string>("AlgoName")){
00475
00476 TString tAlgoName = m_fitParameters[b].getParameter< string > ("AlgoName");
00477 TString tTemplateFunction = m_fitParameters[b].getParameter< string > ("TemplateFunction");
00478 vector<double> tParameters = m_fitParameters[b].getParameter< vector<double> >("Parameters");
00479
00480
00481 m_templateFunctions[tTrigger] = new TF1("FitParametrization_"+tAlgoName,tTemplateFunction,
00482 minInstantLuminosity,maxInstantLuminosity);
00483 m_templateFunctions[tTrigger] ->SetParameters(&tParameters[0]);
00484 m_templateFunctions[tTrigger] ->SetLineWidth(1);
00485 m_templateFunctions[tTrigger] ->SetLineColor(kRed);
00486
00487 foundFit = true;
00488 break;
00489 }
00490
00491 if(!foundFit){
00492
00493 noError = false;
00494
00495 int eCount = m_ErrorMonitor->getTH1()->GetBinContent(WARNING_PY_MISSING_FIT);
00496 eCount++;
00497 m_ErrorMonitor->getTH1()->SetBinContent(WARNING_PY_MISSING_FIT,eCount);
00498
00499 }
00500 }
00501 }
00502 }
00503
00504 return noError;
00505
00506 }
00507
00508
00509
00510
00511 DEFINE_FWK_MODULE(L1TRate_Offline);