CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/HLTriggerOffline/Higgs/src/HLTHiggsPlotter.cc

Go to the documentation of this file.
00001 
00008 #include "FWCore/ServiceRegistry/interface/Service.h"
00009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00010 #include "DataFormats/Common/interface/Handle.h"
00011 #include "DataFormats/Candidate/interface/CandMatchMap.h"
00012 #include "DataFormats/MuonReco/interface/Muon.h"
00013 #include "DataFormats/MuonReco/interface/MuonFwd.h"
00014 
00015 #include "DataFormats/HLTReco/interface/TriggerEvent.h"
00016 
00017 #include "HLTriggerOffline/Higgs/interface/HLTHiggsPlotter.h"
00018 #include "HLTriggerOffline/Higgs/interface/HLTHiggsSubAnalysis.h"
00019 #include "HLTriggerOffline/Higgs/src/EVTColContainer.cc"
00020 
00021 #include "TPRegexp.h"
00022 
00023 
00024 #include<set>
00025 #include<cctype>
00026 
00027 HLTHiggsPlotter::HLTHiggsPlotter(const edm::ParameterSet & pset,
00028                 const std::string & hltPath,
00029                 const std::vector<unsigned int> & objectsType,
00030                 DQMStore * dbe) :
00031         _hltPath(hltPath),
00032         _hltProcessName(pset.getParameter<std::string>("hltProcessName")),
00033         _objectsType(std::set<unsigned int>(objectsType.begin(),objectsType.end())),
00034         _nObjects(objectsType.size()),
00035         _parametersEta(pset.getParameter<std::vector<double> >("parametersEta")),
00036         _parametersPhi(pset.getParameter<std::vector<double> >("parametersPhi")),
00037         _parametersTurnOn(pset.getParameter<std::vector<double> >("parametersTurnOn")),
00038         _dbe(dbe)
00039 {
00040         for(std::set<unsigned int>::iterator it = _objectsType.begin();
00041                         it != _objectsType.end(); ++it)
00042         {
00043                 // Some parameters extracted from the .py
00044                 std::string objStr = EVTColContainer::getTypeString( *it );
00045                 _cutMinPt[*it] = pset.getParameter<double>( std::string(objStr+"_cutMinPt").c_str() );
00046                 _cutMaxEta[*it] = pset.getParameter<double>( std::string(objStr+"_cutMaxEta").c_str() );
00047         }
00048 }
00049 
00050 HLTHiggsPlotter::~HLTHiggsPlotter()
00051 {
00052 }
00053 
00054 
00055 void HLTHiggsPlotter::beginJob() 
00056 {
00057 }
00058 
00059 
00060 
00061 void HLTHiggsPlotter::beginRun(const edm::Run & iRun, const edm::EventSetup & iSetup)
00062 {
00063         for(std::set<unsigned int>::iterator it = _objectsType.begin(); 
00064                         it != _objectsType.end(); ++it)
00065         {
00066                 std::vector<std::string> sources(2);
00067                 sources[0] = "gen";
00068                 sources[1] = "rec";
00069 
00070                 const std::string objTypeStr = EVTColContainer::getTypeString(*it);
00071           
00072                 for(size_t i = 0; i < sources.size(); i++) 
00073                 {
00074                         std::string source = sources[i];
00075                         bookHist(source, objTypeStr, "Eta");
00076                         bookHist(source, objTypeStr, "Phi");
00077                         bookHist(source, objTypeStr, "MaxPt1");
00078                         bookHist(source, objTypeStr, "MaxPt2");
00079                 }
00080         }
00081 }
00082 
00083 void HLTHiggsPlotter::analyze(const bool & isPassTrigger,const std::string & source,
00084                 const std::vector<MatchStruct> & matches)
00085 {
00086         if( ! isPassTrigger )
00087         {
00088                 return;
00089         }
00090         std::map<unsigned int,int> countobjects;
00091         // Initializing the count of the used object
00092         for(std::set<unsigned int>::iterator co = _objectsType.begin();
00093                         co != _objectsType.end(); ++co)
00094         {
00095                 countobjects[*co] = 0;
00096         }
00097         
00098         int counttotal = 0;
00099         const int totalobjectssize2 = 2*countobjects.size();
00100         // Fill the histos if pass the trigger (just the two with higher pt)
00101         for(size_t j = 0; j < matches.size(); ++j)
00102         {
00103                 // Is this object owned by this trigger? If not we are not interested...
00104                 if( _objectsType.find( matches[j].objType) == _objectsType.end() )
00105                 {
00106                          continue;
00107                 }
00108 
00109                 const unsigned int objType = matches[j].objType;
00110                 const std::string objTypeStr = EVTColContainer::getTypeString(matches[j].objType);
00111                 
00112                 float pt  = matches[j].pt;
00113                 float eta = matches[j].eta;
00114                 float phi = matches[j].phi;
00115                 this->fillHist(isPassTrigger,source,objTypeStr,"Eta",eta);
00116                 this->fillHist(isPassTrigger,source,objTypeStr,"Phi",phi);
00117                 if( countobjects[objType] == 0 )
00118                 {
00119                         this->fillHist(isPassTrigger,source,objTypeStr,"MaxPt1",pt);
00120                         // Filled the high pt ...
00121                         ++(countobjects[objType]);
00122                         ++counttotal;
00123                 }
00124                 else if( countobjects[objType] == 1 )
00125                 {
00126                         this->fillHist(isPassTrigger,source,objTypeStr,"MaxPt2",pt);
00127                         // Filled the second high pt ...
00128                         ++(countobjects[objType]);
00129                         ++counttotal;
00130                 }
00131                 else
00132                 {
00133                         if( counttotal == totalobjectssize2 ) 
00134                         {
00135                                 break;
00136                         }
00137                 }                               
00138         }
00139 }
00140 
00141 
00142 void HLTHiggsPlotter::bookHist(const std::string & source, 
00143                 const std::string & objType, const std::string & variable)
00144 {
00145         std::string sourceUpper = source; 
00146         sourceUpper[0] = std::toupper(sourceUpper[0]);
00147         std::string name = source + objType + variable + "_" + _hltPath;
00148         TH1F * h = 0;
00149 
00150         if(variable.find("MaxPt") != std::string::npos) 
00151         {
00152                 std::string desc = (variable == "MaxPt1") ? "Leading" : "Next-to-Leading";
00153                 std::string title = "pT of " + desc + " " + sourceUpper + " " + objType + " "
00154                    "where event pass the "+ _hltPath;
00155                 const size_t nBins = _parametersTurnOn.size() - 1;
00156                 float * edges = new float[nBins + 1];
00157                 for(size_t i = 0; i < nBins + 1; i++)
00158                 {
00159                         edges[i] = _parametersTurnOn[i];
00160                 }
00161                 h = new TH1F(name.c_str(), title.c_str(), nBins, edges);
00162                 delete edges;
00163         }
00164         else 
00165         {
00166                 std::string symbol = (variable == "Eta") ? "#eta" : "#phi";
00167                 std::string title  = symbol + " of " + sourceUpper + " " + objType + " "+
00168                         "where event pass the "+ _hltPath;
00169                 std::vector<double> params = (variable == "Eta") ? _parametersEta : _parametersPhi;
00170 
00171                 int    nBins = (int)params[0];
00172                 double min   = params[1];
00173                 double max   = params[2];
00174                 h = new TH1F(name.c_str(), title.c_str(), nBins, min, max);
00175         }
00176         h->Sumw2();
00177         _elements[name] = _dbe->book1D(name, h);
00178         delete h;
00179 }
00180 
00181 void HLTHiggsPlotter::fillHist(const bool & passTrigger, const std::string & source, 
00182                 const std::string & objType, const std::string & variable, const float & value )
00183 {
00184         std::string sourceUpper = source; 
00185         sourceUpper[0] = toupper(sourceUpper[0]);
00186         std::string name = source + objType + variable + "_" + _hltPath;
00187 
00188         _elements[name]->Fill(value);
00189 }
00190 
00191