CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/PhysicsTools/RecoUtils/plugins/TriggerVariables.h

Go to the documentation of this file.
00001 #include "PhysicsTools/UtilAlgos/interface/CachingVariable.h"
00002 
00003 
00004 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutRecord.h"
00005 class L1BitComputer : public VariableComputer {
00006  public:
00007   L1BitComputer(CachingVariable::CachingVariableFactoryArg arg):VariableComputer(arg){
00008     src_=edm::Service<InputTagDistributorService>()->retrieve("src",arg.iConfig);
00009     for(int i = 0;i!=128;i++){
00010       std::stringstream ss;
00011       ss<<i;
00012       declare(ss.str());
00013     }
00014 
00015     for(int i = 0;i!=64;i++){
00016       std::stringstream ss;
00017       ss<<"TechTrig_";
00018       ss<<i;
00019       declare(ss.str());
00020     }
00021 
00022 
00023   }
00024     ~L1BitComputer(){};
00025     
00026     void compute(const edm::Event & iEvent) const{
00027       edm::Handle<L1GlobalTriggerReadoutRecord> l1Handle;
00028       iEvent.getByLabel(src_, l1Handle);
00029       if (l1Handle.failedToGet()) doesNotCompute();
00030       const DecisionWord & dWord = l1Handle->decisionWord();
00031       for(int i = 0;i!=128;i++){
00032         std::stringstream ss;
00033         ss<<i;
00034         double r=dWord.at(i);
00035         assign(ss.str(),r);
00036       }
00037 
00038       const TechnicalTriggerWord & tTWord = l1Handle->technicalTriggerWord();
00039       for(int i = 0;i!=64;i++){
00040         std::stringstream ss;
00041         ss<<"TechTrig_";
00042         ss<<i;
00043         double r=tTWord.at(i);
00044         assign(ss.str(),r);
00045       }
00046 
00047       
00048       
00049     }
00050  private:
00051     edm::InputTag src_;
00052 };
00053 
00054 #include "DataFormats/Common/interface/TriggerResults.h"
00055 #include "FWCore/Common/interface/TriggerNames.h"
00056 #include "HLTrigger/HLTcore/interface/HLTConfigProvider.h"
00057 
00058 class HLTBitComputer : public VariableComputer {
00059  public:
00060   HLTBitComputer(CachingVariable::CachingVariableFactoryArg arg):VariableComputer(arg){
00061     src_=edm::Service<InputTagDistributorService>()->retrieve("src",arg.iConfig);
00062     HLTConfigProvider provider;
00063     //the function will not work anymore until a major redesign is performed. so long for HLT variables.
00064     //provider.init(src_.process());
00065     validTriggerNames_ =  provider.triggerNames();
00066     for (unsigned int iT=0;iT!=validTriggerNames_.size();++iT){
00067       TString tname(validTriggerNames_[iT]);
00068       tname.ReplaceAll("HLT_","");//remove the "HLT_" prefix
00069       declare(std::string(tname));
00070     }
00071   }
00072     ~HLTBitComputer(){}
00073     void compute(const edm::Event & iEvent) const{
00074       edm::Handle<edm::TriggerResults> trh;
00075       iEvent.getByLabel(src_,trh);
00076       if (!trh.isValid()) doesNotCompute();
00077       const edm::TriggerNames & triggerNames = iEvent.triggerNames(*trh);
00078       for (unsigned int iT=0;iT!=validTriggerNames_.size();++iT){
00079         
00080         TString tname(validTriggerNames_[iT]);
00081         tname.ReplaceAll("HLT_","");
00082         double r=trh->accept(triggerNames.triggerIndex(validTriggerNames_[iT]));
00083         assign(std::string(tname),r);
00084       }
00085       
00086     }
00087  private:
00088     edm::InputTag src_;
00089     std::vector<std::string> validTriggerNames_;
00090 };
00091 
00092 class HLTBitVariable : public CachingVariable {
00093  public:
00094   HLTBitVariable(CachingVariableFactoryArg arg ) :
00095     CachingVariable("HLTBitVariable",arg.n,arg.iConfig),
00096     src_(edm::Service<InputTagDistributorService>()->retrieve("src",arg.iConfig)),
00097     bitName_(arg.n){ arg.m[arg.n]=this;}
00098     CachingVariable::evalType eval(const edm::Event & iEvent) const{
00099       edm::Handle<edm::TriggerResults> hltHandle;
00100       iEvent.getByLabel(src_, hltHandle);
00101       if (hltHandle.failedToGet()) return std::make_pair(false,0);
00102       const edm::TriggerNames & trgNames = iEvent.triggerNames(*hltHandle);
00103       unsigned int index = trgNames.triggerIndex(bitName_);
00104       if ( index==trgNames.size() ) return std::make_pair(false,0);
00105       else return std::make_pair(true, hltHandle->accept(index));
00106 
00107     }
00108  private:
00109   edm::InputTag src_;
00110   std::string bitName_;
00111 };