CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/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,
00062                                const edm::EventSetup & iSetup)
00063 {
00064   for (std::set<unsigned int>::iterator it = _objectsType.begin(); 
00065       it != _objectsType.end(); ++it)
00066   {
00067     std::vector<std::string> sources(2);
00068     sources[0] = "gen";
00069     sources[1] = "rec";
00070 
00071     const std::string objTypeStr = EVTColContainer::getTypeString(*it);
00072           
00073     for (size_t i = 0; i < sources.size(); i++) 
00074     {
00075       std::string source = sources[i];
00076       bookHist(source, objTypeStr, "Eta");
00077       bookHist(source, objTypeStr, "Phi");
00078       bookHist(source, objTypeStr, "MaxPt1");
00079       bookHist(source, objTypeStr, "MaxPt2");
00080     }
00081   }
00082 }
00083 
00084 void HLTHiggsPlotter::analyze(const bool & isPassTrigger,
00085                               const std::string & source,
00086                               const std::vector<MatchStruct> & matches)
00087 {
00088   if ( !isPassTrigger )
00089   {
00090     return;
00091   }
00092   std::map<unsigned int,int> countobjects;
00093   // Initializing the count of the used object
00094   for(std::set<unsigned int>::iterator co = _objectsType.begin();
00095       co != _objectsType.end(); ++co)
00096   {
00097     countobjects[*co] = 0;
00098   }
00099         
00100   int counttotal = 0;
00101   const int totalobjectssize2 = 2*countobjects.size();
00102   // Fill the histos if pass the trigger (just the two with higher pt)
00103   for (size_t j = 0; j < matches.size(); ++j)
00104   {
00105     // Is this object owned by this trigger? If not we are not interested...
00106     if ( _objectsType.find( matches[j].objType) == _objectsType.end() )
00107     {
00108       continue;
00109     }
00110 
00111     const unsigned int objType = matches[j].objType;
00112     const std::string objTypeStr = EVTColContainer::getTypeString(matches[j].objType);
00113                 
00114     float pt  = matches[j].pt;
00115     float eta = matches[j].eta;
00116     float phi = matches[j].phi;
00117     this->fillHist(isPassTrigger,source,objTypeStr,"Eta",eta);
00118     this->fillHist(isPassTrigger,source,objTypeStr,"Phi",phi);
00119     if ( countobjects[objType] == 0 )
00120     {
00121       this->fillHist(isPassTrigger,source,objTypeStr,"MaxPt1",pt);
00122       // Filled the high pt ...
00123       ++(countobjects[objType]);
00124       ++counttotal;
00125     }
00126     else if ( countobjects[objType] == 1 )
00127     {
00128       this->fillHist(isPassTrigger,source,objTypeStr,"MaxPt2",pt);
00129       // Filled the second high pt ...
00130       ++(countobjects[objType]);
00131       ++counttotal;
00132     }
00133     else
00134     {
00135       if ( counttotal == totalobjectssize2 ) 
00136       {
00137         break;
00138       }
00139     }                           
00140   }
00141 }
00142 
00143 
00144 void HLTHiggsPlotter::bookHist(const std::string & source, 
00145                                const std::string & objType,
00146                                const std::string & variable)
00147 {
00148   std::string sourceUpper = source; 
00149   sourceUpper[0] = std::toupper(sourceUpper[0]);
00150   std::string name = source + objType + variable + "_" + _hltPath;
00151   TH1F * h = 0;
00152 
00153   if (variable.find("MaxPt") != std::string::npos) 
00154   {
00155     std::string desc = (variable == "MaxPt1") ? "Leading" : "Next-to-Leading";
00156     std::string title = "pT of " + desc + " " + sourceUpper + " " + objType + " "
00157         "where event pass the "+ _hltPath;
00158     const size_t nBins = _parametersTurnOn.size() - 1;
00159     float * edges = new float[nBins + 1];
00160     for(size_t i = 0; i < nBins + 1; i++)
00161     {
00162       edges[i] = _parametersTurnOn[i];
00163     }
00164     h = new TH1F(name.c_str(), title.c_str(), nBins, edges);
00165     delete [] edges;
00166   }
00167   else 
00168   {
00169     std::string symbol = (variable == "Eta") ? "#eta" : "#phi";
00170     std::string title  = symbol + " of " + sourceUpper + " " + objType + " "+
00171         "where event pass the "+ _hltPath;
00172     std::vector<double> params = (variable == "Eta") ? _parametersEta : _parametersPhi;
00173 
00174     int    nBins = (int)params[0];
00175     double min   = params[1];
00176     double max   = params[2];
00177     h = new TH1F(name.c_str(), title.c_str(), nBins, min, max);
00178   }
00179   h->Sumw2();
00180   _elements[name] = _dbe->book1D(name, h);
00181   delete h;
00182 }
00183 
00184 void HLTHiggsPlotter::fillHist(const bool & passTrigger,
00185                                const std::string & source, 
00186                                const std::string & objType,
00187                                const std::string & variable,
00188                                const float & value )
00189 {
00190   std::string sourceUpper = source; 
00191   sourceUpper[0] = toupper(sourceUpper[0]);
00192   std::string name = source + objType + variable + "_" + _hltPath;
00193 
00194   _elements[name]->Fill(value);
00195 }
00196 
00197