CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/Validation/EventGenerator/interface/HiggsValidation.h

Go to the documentation of this file.
00001 #ifndef HiggsValidation_H
00002 #define HiggsValidation_H
00003 
00004 /*class HiggsValidation
00005  *  
00006  *  Class to fill Event Generator dqm monitor elements; works on HepMCProduct
00007  *
00008  *  $Date: 2012/06/25 14:51:48 $
00009  *  $Revision: 1.1 $
00010  *
00011  */
00012 #include <iostream>
00013 
00014 // framework & common header files
00015 #include "FWCore/Framework/interface/EDAnalyzer.h"
00016 #include "FWCore/Framework/interface/Event.h"
00017 #include "FWCore/Framework/interface/EventSetup.h"
00018 #include "FWCore/Framework/interface/Run.h"
00019 
00020 #include "DataFormats/Common/interface/Handle.h"
00021 #include "FWCore/Framework/interface/ESHandle.h"
00022 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00023 #include "FWCore/Utilities/interface/InputTag.h"
00024 
00025 //DQM services
00026 #include "DQMServices/Core/interface/DQMStore.h"
00027 #include "FWCore/ServiceRegistry/interface/Service.h"
00028 #include "DQMServices/Core/interface/MonitorElement.h"
00029 
00030 #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
00031 //#include "DataFormats/HepMCCandidate/interface/GenParticle.h"
00032 
00033 #include "SimGeneral/HepPDTRecord/interface/ParticleDataTable.h"
00034 #include "TLorentzVector.h"
00035 
00036 #include "Validation/EventGenerator/interface/WeightManager.h"
00037 
00038 class HiggsValidation : public edm::EDAnalyzer {
00039  public:
00040   explicit HiggsValidation(const edm::ParameterSet&);
00041   virtual ~HiggsValidation();
00042   virtual void beginJob();
00043   virtual void endJob();  
00044   virtual void analyze(const edm::Event&, const edm::EventSetup&);
00045   virtual void beginRun(const edm::Run&, const edm::EventSetup&);
00046   virtual void endRun(const edm::Run&, const edm::EventSetup&);
00047   
00048  private:
00049 
00050 
00051   class MonitoredDecays {
00052   public:
00053     
00054     MonitoredDecays(const edm::ParameterSet& iConfig){
00055       fillMap();
00056       std::vector<std::string> input = iConfig.getParameter<std::vector<std::string> >("monitorDecays");
00057       for(std::vector<std::string>::const_iterator i = input.begin(); i!= input.end(); ++i){
00058         fill(*i);
00059       }
00060     }
00061 
00062     ~MonitoredDecays(){};
00063         
00064     size_t position(int pid1,int pid2){
00065       if(abs(pid1) == 14 || abs(pid1) == 16) pid1 = 12;
00066       if(abs(pid2) == 14 || abs(pid2) == 16) pid2 = 12;
00067       for(size_t i = 0; i < channels.size(); ++i){
00068         if((channels[i].first == abs(pid1) && channels[i].second == abs(pid2)) || 
00069            (channels[i].first == abs(pid2) && channels[i].second == abs(pid1))) return i+1;
00070       }
00071       return channels.size()+1;
00072     }
00073 
00074     size_t size(){return channels.size() + 2;}
00075     size_t undetermined(){return 0;}
00076     size_t stable(){return size();}
00077     std::string channel(size_t i){
00078       if(i == 0) return "?";
00079       if(i == channels.size()+1) return "Stable";
00080       return convert(channels[i-1].first)+convert(channels[i-1].second);
00081     }
00082 
00083     int convert(std::string s){
00084       if( namePidMap.count(s)){
00085         return namePidMap[s];
00086       }
00087       return 0;
00088     }
00089 
00090     std::string convert(int pid){
00091       pid = abs(pid);
00092       if(pid == 14 || pid == 16) pid = 12;
00093       for(std::map<std::string,int>::const_iterator i = namePidMap.begin(); i!= namePidMap.end(); ++i) {
00094         if(i->second == pid) return i->first;
00095       }
00096       return "not found";
00097     }
00098 
00099     unsigned int NDecayParticles(){return nparticles_;}
00100 
00101     int isDecayParticle(int pid){
00102       int idx=0;
00103       for(std::map<std::string,int>::const_iterator i = namePidMap.begin(); i!= namePidMap.end(); ++i) {
00104         if(i->second == pid) return idx;
00105         idx++;
00106       }
00107       return -1;
00108     }
00109 
00110     std::string ConvertIndex(int index){
00111       int idx=0;
00112       for(std::map<std::string,int>::const_iterator i = namePidMap.begin(); i!= namePidMap.end(); ++i) {
00113         if(idx==index) return i->first;
00114         idx++;
00115       }
00116       return "unknown";
00117     }
00118 
00119   private:
00120     void fill(std::string s){
00121       size_t pos = s.find("+");
00122       std::string particle1 = s.substr(0,pos);
00123       std::string particle2 = s.substr(pos+1,s.length()-pos);
00124       std::pair<int,int> decay;
00125       decay.first  = convert(particle1);
00126       decay.second = convert(particle2);
00127       channels.push_back(decay);
00128     }
00129     
00130     void fillMap(){
00131       namePidMap["d"]     = 1;
00132       namePidMap["u"]     = 2;
00133       namePidMap["s"]     = 3;
00134       namePidMap["c"]     = 4;
00135       namePidMap["b"]     = 5;
00136       namePidMap["t"]     = 6;
00137       namePidMap["e"]     = 11;
00138       namePidMap["nu"]    = 12;
00139       namePidMap["mu"]    = 13;
00140       namePidMap["tau"]   = 15;
00141       namePidMap["gamma"] = 22;
00142       namePidMap["Z"]     = 23;
00143       namePidMap["W"]     = 24;
00144       nparticles_=0;
00145       for(std::map<std::string,int>::const_iterator i = namePidMap.begin(); i!= namePidMap.end(); ++i){
00146         nparticles_++;
00147       }
00148     }
00149 
00150     std::map<std::string,int> namePidMap;
00151     
00152     std::vector<std::pair<int,int> > channels;
00153     unsigned int nparticles_;
00154 
00155   };
00156   
00157   int findHiggsDecayChannel(const HepMC::GenParticle*,std::vector<HepMC::GenParticle*> &decayprod);
00158   std::string convert(int);
00159   
00160   WeightManager _wmanager;
00161   
00162   edm::InputTag hepmcCollection_;
00163 
00164   int particle_id;
00165   std::string particle_name;
00166   
00167   MonitoredDecays* monitoredDecays;
00168   
00170   edm::ESHandle<HepPDT::ParticleDataTable> fPDGTable ;
00171   
00173   DQMStore *dbe;
00174 
00175   MonitorElement *nEvt;
00176   MonitorElement *HiggsDecayChannels;
00177   
00178   MonitorElement *Higgs_pt;
00179   MonitorElement *Higgs_eta;
00180   MonitorElement *Higgs_mass;
00181   
00182   std::vector<MonitorElement*> HiggsDecayProd_pt;
00183   std::vector<MonitorElement*> HiggsDecayProd_eta;
00184 
00185 };
00186 
00187 #endif