CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/src/HLTrigger/HLTanalyzers/src/HLTInfo.cc

Go to the documentation of this file.
00001 #include <iostream>
00002 #include <sstream>
00003 #include <istream>
00004 #include <fstream>
00005 #include <iomanip>
00006 #include <string>
00007 #include <cmath>
00008 #include <functional>
00009 #include <stdlib.h>
00010 #include <string.h>
00011 
00012 #include "HLTrigger/HLTanalyzers/interface/HLTInfo.h"
00013 #include "FWCore/Common/interface/TriggerNames.h"
00014 
00015 // L1 related
00016 #include "L1Trigger/GlobalTriggerAnalyzer/interface/L1GtUtils.h"
00017 #include "CondFormats/L1TObjects/interface/L1GtTriggerMenu.h"
00018 #include "CondFormats/DataRecord/interface/L1GtTriggerMenuRcd.h"
00019 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutSetupFwd.h"
00020 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutSetup.h"
00021 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutRecord.h"
00022 
00023 
00024 HLTInfo::HLTInfo() {
00025 
00026   //set parameter defaults 
00027   _Debug=false;
00028   _OR_BXes=false;
00029   UnpackBxInEvent=1;
00030 }
00031 
00032 void HLTInfo::beginRun(const edm::Run& run, const edm::EventSetup& c){ 
00033 
00034 
00035   bool changed(true);
00036   if (hltConfig_.init(run,c,processName_,changed)) {
00037     // if init returns TRUE, initialisation has succeeded!
00038     if (changed) {
00039       // The HLT config has actually changed wrt the previous Run, hence rebook your
00040       // histograms or do anything else dependent on the revised HLT config
00041       std::cout << "Initalizing HLTConfigProvider"  << std::endl;
00042     }
00043   } else {
00044     // if init returns FALSE, initialisation has NOT succeeded, which indicates a problem
00045     // with the file and/or code and needs to be investigated!
00046     std::cout << " HLT config extraction failure with process name " << processName_ << std::endl;
00047     // In this case, all access methods will return empty values!
00048   }
00049 
00050 }
00051 
00052 /*  Setup the analysis to put the branch-variables into the tree. */
00053 void HLTInfo::setup(const edm::ParameterSet& pSet, TTree* HltTree) {
00054 
00055 
00056   processName_ = pSet.getParameter<std::string>("HLTProcessName") ;
00057 
00058   edm::ParameterSet myHltParams = pSet.getParameter<edm::ParameterSet>("RunParameters") ;
00059   std::vector<std::string> parameterNames = myHltParams.getParameterNames() ;
00060   
00061   for ( std::vector<std::string>::iterator iParam = parameterNames.begin();
00062         iParam != parameterNames.end(); iParam++ ){
00063     if ( (*iParam) == "Debug" ) _Debug =  myHltParams.getParameter<bool>( *iParam );
00064   }
00065 
00066   dummyBranches_ = pSet.getUntrackedParameter<std::vector<std::string> >("dummyBranches",std::vector<std::string>(0));
00067 
00068   HltEvtCnt = 0;
00069   const int kMaxTrigFlag = 10000;
00070   trigflag = new int[kMaxTrigFlag];
00071   trigPrescl = new int[kMaxTrigFlag];
00072   L1EvtCnt = 0;
00073   const int kMaxL1Flag = 10000;
00074   l1flag = new int[kMaxL1Flag];
00075   l1flag5Bx = new int[kMaxTrigFlag];
00076   l1Prescl = new int[kMaxL1Flag];
00077   l1techflag = new int[kMaxL1Flag];
00078   l1techflag5Bx = new int[kMaxTrigFlag];
00079   l1techPrescl = new int[kMaxTrigFlag];
00080   const int kMaxHLTPart = 10000;
00081   hltppt = new float[kMaxHLTPart];
00082   hltpeta = new float[kMaxHLTPart];
00083   const int kMaxL1ExtEmI = 10000;
00084   l1extiemet = new float[kMaxL1ExtEmI];
00085   l1extieme = new float[kMaxL1ExtEmI];
00086   l1extiemeta = new float[kMaxL1ExtEmI];
00087   l1extiemphi = new float[kMaxL1ExtEmI];
00088   const int kMaxL1ExtEmN = 10000;
00089   l1extnemet = new float[kMaxL1ExtEmN];
00090   l1extneme = new float[kMaxL1ExtEmN];
00091   l1extnemeta = new float[kMaxL1ExtEmN];
00092   l1extnemphi = new float[kMaxL1ExtEmN];
00093   const int kMaxL1ExtMu = 10000;
00094   l1extmupt = new float[kMaxL1ExtMu];
00095   l1extmue = new float[kMaxL1ExtMu];
00096   l1extmueta = new float[kMaxL1ExtMu];
00097   l1extmuphi = new float[kMaxL1ExtMu];
00098   l1extmuiso = new int[kMaxL1ExtMu];
00099   l1extmumip = new int[kMaxL1ExtMu];
00100   l1extmufor = new int[kMaxL1ExtMu];
00101   l1extmurpc = new int[kMaxL1ExtMu];
00102   l1extmuqul = new int[kMaxL1ExtMu];
00103   l1extmuchg = new int[kMaxL1ExtMu];
00104   const int kMaxL1ExtJtC = 10000;
00105   l1extjtcet = new float[kMaxL1ExtJtC];
00106   l1extjtce = new float[kMaxL1ExtJtC];
00107   l1extjtceta = new float[kMaxL1ExtJtC];
00108   l1extjtcphi = new float[kMaxL1ExtJtC];
00109   const int kMaxL1ExtJtF = 10000;
00110   l1extjtfet = new float[kMaxL1ExtJtF];
00111   l1extjtfe = new float[kMaxL1ExtJtF];
00112   l1extjtfeta = new float[kMaxL1ExtJtF];
00113   l1extjtfphi = new float[kMaxL1ExtJtF];
00114   const int kMaxL1ExtTau = 10000;
00115   l1exttauet = new float[kMaxL1ExtTau];
00116   l1exttaue = new float[kMaxL1ExtTau];
00117   l1exttaueta = new float[kMaxL1ExtTau];
00118   l1exttauphi = new float[kMaxL1ExtTau];
00119 
00120   algoBitToName = new TString[128];
00121   techBitToName = new TString[128];
00122 
00123   HltTree->Branch("NL1IsolEm",&nl1extiem,"NL1IsolEm/I");
00124   HltTree->Branch("L1IsolEmEt",l1extiemet,"L1IsolEmEt[NL1IsolEm]/F");
00125   HltTree->Branch("L1IsolEmE",l1extieme,"L1IsolEmE[NL1IsolEm]/F");
00126   HltTree->Branch("L1IsolEmEta",l1extiemeta,"L1IsolEmEta[NL1IsolEm]/F");
00127   HltTree->Branch("L1IsolEmPhi",l1extiemphi,"L1IsolEmPhi[NL1IsolEm]/F");
00128   HltTree->Branch("NL1NIsolEm",&nl1extnem,"NL1NIsolEm/I");
00129   HltTree->Branch("L1NIsolEmEt",l1extnemet,"L1NIsolEmEt[NL1NIsolEm]/F");
00130   HltTree->Branch("L1NIsolEmE",l1extneme,"L1NIsolEmE[NL1NIsolEm]/F");
00131   HltTree->Branch("L1NIsolEmEta",l1extnemeta,"L1NIsolEmEta[NL1NIsolEm]/F");
00132   HltTree->Branch("L1NIsolEmPhi",l1extnemphi,"L1NIsolEmPhi[NL1NIsolEm]/F");
00133   HltTree->Branch("NL1Mu",&nl1extmu,"NL1Mu/I");
00134   HltTree->Branch("L1MuPt",l1extmupt,"L1MuPt[NL1Mu]/F");
00135   HltTree->Branch("L1MuE",l1extmue,"L1MuE[NL1Mu]/F");
00136   HltTree->Branch("L1MuEta",l1extmueta,"L1MuEta[NL1Mu]/F");
00137   HltTree->Branch("L1MuPhi",l1extmuphi,"L1MuPhi[NL1Mu]/F");
00138   HltTree->Branch("L1MuIsol",l1extmuiso,"L1MuIsol[NL1Mu]/I");
00139   HltTree->Branch("L1MuMip",l1extmumip,"L1MuMip[NL1Mu]/I");
00140   HltTree->Branch("L1MuFor",l1extmufor,"L1MuFor[NL1Mu]/I");
00141   HltTree->Branch("L1MuRPC",l1extmurpc,"L1MuRPC[NL1Mu]/I");
00142   HltTree->Branch("L1MuQal",l1extmuqul,"L1MuQal[NL1Mu]/I");
00143   HltTree->Branch("L1MuChg",l1extmuchg,"L1MuChg[NL1Mu]/I");
00144   HltTree->Branch("NL1CenJet",&nl1extjetc,"NL1CenJet/I");
00145   HltTree->Branch("L1CenJetEt",l1extjtcet,"L1CenJetEt[NL1CenJet]/F");
00146   HltTree->Branch("L1CenJetE",l1extjtce,"L1CenJetE[NL1CenJet]/F");
00147   HltTree->Branch("L1CenJetEta",l1extjtceta,"L1CenJetEta[NL1CenJet]/F");
00148   HltTree->Branch("L1CenJetPhi",l1extjtcphi,"L1CenJetPhi[NL1CenJet]/F");
00149   HltTree->Branch("NL1ForJet",&nl1extjetf,"NL1ForJet/I");
00150   HltTree->Branch("L1ForJetEt",l1extjtfet,"L1ForJetEt[NL1ForJet]/F");
00151   HltTree->Branch("L1ForJetE",l1extjtfe,"L1ForJetE[NL1ForJet]/F");
00152   HltTree->Branch("L1ForJetEta",l1extjtfeta,"L1ForJetEta[NL1ForJet]/F");
00153   HltTree->Branch("L1ForJetPhi",l1extjtfphi,"L1ForJetPhi[NL1ForJet]/F");
00154   HltTree->Branch("NL1Tau",&nl1exttau,"NL1Tau/I");
00155   HltTree->Branch("L1TauEt",l1exttauet,"L1TauEt[NL1Tau]/F");
00156   HltTree->Branch("L1TauE",l1exttaue,"L1TauE[NL1Tau]/F");
00157   HltTree->Branch("L1TauEta",l1exttaueta,"L1TauEta[NL1Tau]/F");
00158   HltTree->Branch("L1TauPhi",l1exttauphi,"L1TauPhi[NL1Tau]/F");
00159   HltTree->Branch("L1Met",&met,"L1Met/F");
00160   HltTree->Branch("L1MetPhi",&metphi,"L1MetPhi/F");
00161   HltTree->Branch("L1EtTot",&ettot,"L1EtTot/F");
00162   HltTree->Branch("L1Mht",&mht,"L1Mht/F");
00163   HltTree->Branch("L1MhtPhi",&mhtphi,"L1MhtPhi/F");
00164   HltTree->Branch("L1EtHad",&ethad,"L1EtHad/F");
00165 
00166   // L1GctJetCounts
00167   HltTree->Branch("L1HfRing1EtSumPositiveEta",&l1hfRing1EtSumPositiveEta,"L1HfRing1EtSumPositiveEta/I");
00168   HltTree->Branch("L1HfRing2EtSumPositiveEta",&l1hfRing2EtSumPositiveEta,"L1HfRing2EtSumPositiveEta/I");
00169   HltTree->Branch("L1HfRing1EtSumNegativeEta",&l1hfRing1EtSumNegativeEta,"L1HfRing1EtSumNegativeEta/I");
00170   HltTree->Branch("L1HfRing2EtSumNegativeEta",&l1hfRing2EtSumNegativeEta,"L1HfRing2EtSumNegativeEta/I");
00171   HltTree->Branch("L1HfTowerCountPositiveEtaRing1",&l1hfTowerCountPositiveEtaRing1,"L1HfTowerCountPositiveEtaRing1/I");
00172   HltTree->Branch("L1HfTowerCountNegativeEtaRing1",&l1hfTowerCountNegativeEtaRing1,"L1HfTowerCountNegativeEtaRing1/I");
00173   HltTree->Branch("L1HfTowerCountPositiveEtaRing2",&l1hfTowerCountPositiveEtaRing2,"L1HfTowerCountPositiveEtaRing2/I");
00174   HltTree->Branch("L1HfTowerCountNegativeEtaRing2",&l1hfTowerCountNegativeEtaRing2,"L1HfTowerCountNegativeEtaRing2/I");
00175 
00176 }
00177 
00178 /* **Analyze the event** */
00179 void HLTInfo::analyze(const edm::Handle<edm::TriggerResults>                 & hltresults,
00180                       const edm::Handle<l1extra::L1EmParticleCollection>     & L1ExtEmIsol,
00181                       const edm::Handle<l1extra::L1EmParticleCollection>     & L1ExtEmNIsol,
00182                       const edm::Handle<l1extra::L1MuonParticleCollection>   & L1ExtMu,
00183                       const edm::Handle<l1extra::L1JetParticleCollection>    & L1ExtJetC,
00184                       const edm::Handle<l1extra::L1JetParticleCollection>    & L1ExtJetF,
00185                       const edm::Handle<l1extra::L1JetParticleCollection>    & L1ExtTau,
00186                       const edm::Handle<l1extra::L1EtMissParticleCollection> & L1ExtMet,
00187                       const edm::Handle<l1extra::L1EtMissParticleCollection> & L1ExtMht,
00188                       const edm::Handle<L1GlobalTriggerReadoutRecord>        & L1GTRR,
00189                       const edm::Handle<L1GctHFBitCountsCollection>          & gctBitCounts,
00190                       const edm::Handle<L1GctHFRingEtSumsCollection>         & gctRingSums,
00191                       edm::EventSetup const& eventSetup,
00192                       edm::Event const& iEvent,
00193                       TTree* HltTree) {
00194 
00195 //   std::cout << " Beginning HLTInfo " << std::endl;
00196 
00197 
00199   if (hltresults.isValid()) {
00200     int ntrigs = hltresults->size();
00201     if (ntrigs==0){std::cout << "%HLTInfo -- No trigger name given in TriggerResults of the input " << std::endl;}
00202 
00203     edm::TriggerNames const& triggerNames = iEvent.triggerNames(*hltresults);
00204 
00205     // 1st event : Book as many branches as trigger paths provided in the input...
00206     if (HltEvtCnt==0){
00207       for (int itrig = 0; itrig != ntrigs; ++itrig) {
00208         TString trigName = triggerNames.triggerName(itrig);
00209         HltTree->Branch(trigName,trigflag+itrig,trigName+"/I");
00210         HltTree->Branch(trigName+"_Prescl",trigPrescl+itrig,trigName+"_Prescl/I");
00211       }
00212 
00213       int itdum = ntrigs;
00214       for (unsigned int idum = 0; idum < dummyBranches_.size(); ++idum) {
00215         TString trigName(dummyBranches_[idum].data());
00216         bool addThisBranch = 1;
00217         for (int itrig = 0; itrig != ntrigs; ++itrig) {
00218           TString realTrigName = triggerNames.triggerName(itrig);
00219           if(trigName == realTrigName) addThisBranch = 0;
00220         }
00221         if(addThisBranch){
00222           HltTree->Branch(trigName,trigflag+itdum,trigName+"/I");
00223           HltTree->Branch(trigName+"_Prescl",trigPrescl+itdum,trigName+"_Prescl/I");
00224           trigflag[itdum] = 0;
00225           trigPrescl[itdum] = 0;
00226           ++itdum;
00227         }
00228       }
00229 
00230       HltEvtCnt++;
00231     }
00232     // ...Fill the corresponding accepts in branch-variables
00233 
00234     //std::cout << "Number of prescale sets: " << hltConfig_.prescaleSize() << std::endl;
00235     //std::cout << "Number of HLT paths: " << hltConfig_.size() << std::endl;
00236     //int presclSet = hltConfig_.prescaleSet(iEvent, eventSetup);
00237     //std::cout<<"\tPrescale set number: "<< presclSet <<std::endl; 
00238 
00239     for (int itrig = 0; itrig != ntrigs; ++itrig){
00240 
00241       std::string trigName=triggerNames.triggerName(itrig);
00242       bool accept = hltresults->accept(itrig);
00243 
00244       trigPrescl[itrig] = hltConfig_.prescaleValue(iEvent, eventSetup, trigName);
00245 
00246 
00247       if (accept){trigflag[itrig] = 1;}
00248       else {trigflag[itrig] = 0;}
00249 
00250       if (_Debug){
00251         if (_Debug) std::cout << "%HLTInfo --  Number of HLT Triggers: " << ntrigs << std::endl;
00252         std::cout << "%HLTInfo --  HLTTrigger(" << itrig << "): " << trigName << " = " << accept << std::endl;
00253       }
00254     }
00255   }
00256   else { if (_Debug) std::cout << "%HLTInfo -- No Trigger Result" << std::endl;}
00257 
00259 
00260   const int maxL1EmIsol = 4;
00261   for (int i=0; i!=maxL1EmIsol; ++i){
00262     l1extiemet[i] = -999.;
00263     l1extieme[i] = -999.;
00264     l1extiemeta[i] = -999.;
00265     l1extiemphi[i] = -999.;
00266   }
00267   if (L1ExtEmIsol.isValid()) {
00268     nl1extiem = maxL1EmIsol;
00269     l1extra::L1EmParticleCollection myl1iems;
00270     myl1iems = * L1ExtEmIsol;
00271     std::sort(myl1iems.begin(),myl1iems.end(),EtGreater());
00272     int il1exem = 0;
00273     for (l1extra::L1EmParticleCollection::const_iterator emItr = myl1iems.begin(); emItr != myl1iems.end(); ++emItr) {
00274       l1extiemet[il1exem] = emItr->et();
00275       l1extieme[il1exem] = emItr->energy();
00276       l1extiemeta[il1exem] = emItr->eta();
00277       l1extiemphi[il1exem] = emItr->phi();
00278       il1exem++;
00279     }
00280   }
00281   else {
00282     nl1extiem = 0;
00283     if (_Debug) std::cout << "%HLTInfo -- No Isolated L1 EM object" << std::endl;
00284   }
00285 
00286   const int maxL1EmNIsol = 4;
00287   for (int i=0; i!=maxL1EmNIsol; ++i){
00288     l1extnemet[i] = -999.;
00289     l1extneme[i] = -999.;
00290     l1extnemeta[i] = -999.;
00291     l1extnemphi[i] = -999.;
00292   }
00293   if (L1ExtEmNIsol.isValid()) {
00294     nl1extnem = maxL1EmNIsol;
00295     l1extra::L1EmParticleCollection myl1nems;
00296     myl1nems = * L1ExtEmNIsol;
00297     std::sort(myl1nems.begin(),myl1nems.end(),EtGreater());
00298     int il1exem = 0;
00299     for (l1extra::L1EmParticleCollection::const_iterator emItr = myl1nems.begin(); emItr != myl1nems.end(); ++emItr) {
00300       l1extnemet[il1exem] = emItr->et();
00301       l1extneme[il1exem] = emItr->energy();
00302       l1extnemeta[il1exem] = emItr->eta();
00303       l1extnemphi[il1exem] = emItr->phi();
00304       il1exem++;
00305     }
00306   }
00307   else {
00308     nl1extnem = 0;
00309     if (_Debug) std::cout << "%HLTInfo -- No Non-Isolated L1 EM object" << std::endl;
00310   }
00311 
00312   const int maxL1Mu = 4;
00313   for (int i=0; i!=maxL1Mu; ++i){
00314     l1extmupt[i] = -999.;
00315     l1extmue[i] = -999.;
00316     l1extmueta[i] = -999.;
00317     l1extmuphi[i] = -999.;
00318     l1extmuiso[i] = -999;
00319     l1extmumip[i] = -999;
00320     l1extmufor[i] = -999;
00321     l1extmurpc[i] = -999;
00322     l1extmuqul[i] = -999;
00323     l1extmuchg[i] = -999;
00324   }
00325   if (L1ExtMu.isValid()) {
00326     nl1extmu = maxL1Mu;
00327     l1extra::L1MuonParticleCollection myl1mus;
00328     myl1mus = * L1ExtMu;
00329     std::sort(myl1mus.begin(),myl1mus.end(),PtGreater());
00330     int il1exmu = 0;
00331     for (l1extra::L1MuonParticleCollection::const_iterator muItr = myl1mus.begin(); muItr != myl1mus.end(); ++muItr) {
00332       l1extmupt[il1exmu] = muItr->pt();
00333       l1extmue[il1exmu] = muItr->energy();
00334       l1extmueta[il1exmu] = muItr->eta();
00335       l1extmuphi[il1exmu] = muItr->phi();
00336       l1extmuiso[il1exmu] = muItr->isIsolated(); // = 1 for Isolated ?
00337       l1extmumip[il1exmu] = muItr->isMip(); // = 1 for Mip ?
00338       l1extmufor[il1exmu] = muItr->isForward();
00339       l1extmurpc[il1exmu] = muItr->isRPC();
00340       l1extmuchg[il1exmu] = muItr->charge();
00341       L1MuGMTExtendedCand gmtCand = muItr->gmtMuonCand();
00342       l1extmuqul[il1exmu] = gmtCand.quality(); // Muon quality as defined in the GT
00343       il1exmu++;
00344     }
00345   }
00346   else {
00347     nl1extmu = 0;
00348     if (_Debug) std::cout << "%HLTInfo -- No L1 MU object" << std::endl;
00349   }
00350 
00351   const int maxL1CenJet = 4;
00352   for (int i=0; i!=maxL1CenJet; ++i){
00353     l1extjtcet[i] = -999.;
00354     l1extjtce[i] = -999.;
00355     l1extjtceta[i] = -999.;
00356     l1extjtcphi[i] = -999.;
00357   }
00358   if (L1ExtJetC.isValid()) {
00359     nl1extjetc = maxL1CenJet;
00360     l1extra::L1JetParticleCollection myl1jetsc;
00361     myl1jetsc = * L1ExtJetC;
00362     std::sort(myl1jetsc.begin(),myl1jetsc.end(),EtGreater());
00363     int il1exjt = 0;
00364     for (l1extra::L1JetParticleCollection::const_iterator jtItr = myl1jetsc.begin(); jtItr != myl1jetsc.end(); ++jtItr) {
00365       l1extjtcet[il1exjt] = jtItr->et();
00366       l1extjtce[il1exjt] = jtItr->energy();
00367       l1extjtceta[il1exjt] = jtItr->eta();
00368       l1extjtcphi[il1exjt] = jtItr->phi();
00369       il1exjt++;
00370     }
00371   }
00372   else {
00373     nl1extjetc = 0;
00374     if (_Debug) std::cout << "%HLTInfo -- No L1 Central JET object" << std::endl;
00375   }
00376 
00377   const int maxL1ForJet = 4;
00378   for (int i=0; i!=maxL1ForJet; ++i){
00379     l1extjtfet[i] = -999.;
00380     l1extjtfe[i] = -999.;
00381     l1extjtfeta[i] = -999.;
00382     l1extjtfphi[i] = -999.;
00383   }
00384   if (L1ExtJetF.isValid()) {
00385     nl1extjetf = maxL1ForJet;
00386     l1extra::L1JetParticleCollection myl1jetsf;
00387     myl1jetsf = * L1ExtJetF;
00388     std::sort(myl1jetsf.begin(),myl1jetsf.end(),EtGreater());
00389     int il1exjt = 0;
00390     for (l1extra::L1JetParticleCollection::const_iterator jtItr = myl1jetsf.begin(); jtItr != myl1jetsf.end(); ++jtItr) {
00391       l1extjtfet[il1exjt] = jtItr->et();
00392       l1extjtfe[il1exjt] = jtItr->energy();
00393       l1extjtfeta[il1exjt] = jtItr->eta();
00394       l1extjtfphi[il1exjt] = jtItr->phi();
00395       il1exjt++;
00396     }
00397   }
00398   else {
00399     nl1extjetf = 0;
00400     if (_Debug) std::cout << "%HLTInfo -- No L1 Forward JET object" << std::endl;
00401   }
00402 
00403   const int maxL1TauJet = 4;
00404   for (int i=0; i!=maxL1TauJet; ++i){
00405     l1exttauet[i] = -999.;
00406     l1exttaue[i] = -999.;
00407     l1exttaueta[i] = -999.;
00408     l1exttauphi[i] = -999.;
00409   }
00410   if (L1ExtTau.isValid()) {
00411     nl1exttau = maxL1TauJet;
00412     l1extra::L1JetParticleCollection myl1taus;
00413     myl1taus = * L1ExtTau;
00414     std::sort(myl1taus.begin(),myl1taus.end(),EtGreater());
00415     int il1extau = 0;
00416     for (l1extra::L1JetParticleCollection::const_iterator tauItr = myl1taus.begin(); tauItr != myl1taus.end(); ++tauItr) {
00417       l1exttauet[il1extau] = tauItr->et();
00418       l1exttaue[il1extau] = tauItr->energy();
00419       l1exttaueta[il1extau] = tauItr->eta();
00420       l1exttauphi[il1extau] = tauItr->phi();
00421       il1extau++;
00422     }
00423   }
00424   else {
00425     nl1exttau = 0;
00426     if (_Debug) std::cout << "%HLTInfo -- No L1 TAU object" << std::endl;
00427   }
00428 
00429   if (L1ExtMet.isValid()) {
00430     met    = L1ExtMet->begin()->etMiss();
00431     metphi = L1ExtMet->begin()->phi();
00432     ettot  = L1ExtMet->begin()->etTotal();
00433   }
00434   else {
00435     if (_Debug) std::cout << "%HLTInfo -- No L1 MET object" << std::endl;
00436   }
00437 
00438   if (L1ExtMht.isValid()) {
00439     mht    = L1ExtMht->begin()->etMiss();
00440     mhtphi = L1ExtMht->begin()->phi();
00441     ethad  = L1ExtMht->begin()->etTotal();
00442   }
00443   else {
00444     if (_Debug) std::cout << "%HLTInfo -- No L1 MHT object" << std::endl;
00445   }
00446 
00447   //==============L1 information=======================================
00448 
00449   // L1 Triggers from Menu
00450 
00451   m_l1GtUtils.retrieveL1EventSetup(eventSetup);
00452   edm::ESHandle<L1GtTriggerMenu> menuRcd;
00453   eventSetup.get<L1GtTriggerMenuRcd>().get(menuRcd) ;
00454   const L1GtTriggerMenu* menu = menuRcd.product();
00455 
00456   int iErrorCode = -1;
00457   L1GtUtils::TriggerCategory trigCategory = L1GtUtils::AlgorithmTrigger;
00458   const int pfSetIndexAlgorithmTrigger = m_l1GtUtils.prescaleFactorSetIndex(
00459              iEvent, trigCategory, iErrorCode);
00460   if (iErrorCode == 0) {
00461     if (_Debug) std::cout << "%Prescale set index: " << pfSetIndexAlgorithmTrigger  << std::endl;
00462   }else{
00463     std::cout << "%Could not extract Prescale set index from event record. Error code: " << iErrorCode << std::endl;
00464   }
00465 
00466   // 1st event : Book as many branches as trigger paths provided in the input...
00467   if (L1GTRR.isValid()) {  
00468 
00469     DecisionWord gtDecisionWord = L1GTRR->decisionWord();
00470     const unsigned int numberTriggerBits(gtDecisionWord.size());
00471     const TechnicalTriggerWord&  technicalTriggerWordBeforeMask = L1GTRR->technicalTriggerWord();
00472     const unsigned int numberTechnicalTriggerBits(technicalTriggerWordBeforeMask.size());
00473 
00474     // 1st event : Book as many branches as trigger paths provided in the input...
00475     if (L1EvtCnt==0){
00476 
00477  
00478       //ccla determine if more than 1 bx was unpacked in event; add OR all bx's if so
00479       const edm::Provenance& prov = iEvent.getProvenance(L1GTRR.id());
00480       //const string& procName = prov.processName();
00481       edm::ParameterSetID setId = prov.psetID();
00482       //std::cout << "procName:" << procName << std::endl;
00483       //std::cout << "provinfo:" << prov << std::endl;
00484       //std::cout << "setid:" << setId << std::endl;
00485       edm::ParameterSet pSet=getParameterSet(setId);
00486       //std::cout << "pset:" << pSet << std::endl;
00487       if (pSet.exists("UnpackBxInEvent")){
00488         UnpackBxInEvent = pSet.getParameter<int>("UnpackBxInEvent");
00489       }
00490       if (_Debug) std::cout << "Number of beam crossings unpacked by GT: " << UnpackBxInEvent << std::endl;
00491       if (UnpackBxInEvent == 5) _OR_BXes = true;
00492 
00493       // get L1 menu from event setup
00494       for (CItAlgo algo = menu->gtAlgorithmMap().begin(); algo!=menu->gtAlgorithmMap().end(); ++algo) {
00495         if (_Debug) std::cout << "Name: " << (algo->second).algoName() << " Alias: " << (algo->second).algoAlias() << std::endl;
00496         int itrig = (algo->second).algoBitNumber();
00497         algoBitToName[itrig] = TString( (algo->second).algoName() );
00498         HltTree->Branch(algoBitToName[itrig],l1flag+itrig,algoBitToName[itrig]+"/I");
00499         HltTree->Branch(algoBitToName[itrig]+"_Prescl",l1Prescl+itrig,algoBitToName[itrig]+"_Prescl/I");
00500         if (_OR_BXes)
00501           HltTree->Branch(algoBitToName[itrig]+"_5bx",l1flag5Bx+itrig,algoBitToName[itrig]+"_5bx/I");
00502       }
00503 
00504       // Book branches for tech bits
00505       for (CItAlgo techTrig = menu->gtTechnicalTriggerMap().begin(); techTrig != menu->gtTechnicalTriggerMap().end(); ++techTrig) {
00506         int itrig = (techTrig->second).algoBitNumber();
00507         techBitToName[itrig] = TString( (techTrig->second).algoName() );
00508         if (_Debug) std::cout << "tech bit " << itrig << ": " << techBitToName[itrig] << " " << std::endl;
00509         HltTree->Branch(techBitToName[itrig],l1techflag+itrig,techBitToName[itrig]+"/I");
00510         HltTree->Branch(techBitToName[itrig]+"_Prescl",l1techPrescl+itrig,techBitToName[itrig]+"_Prescl/I");
00511         if (_OR_BXes)
00512           HltTree->Branch(techBitToName[itrig]+"_5bx",l1techflag5Bx+itrig,techBitToName[itrig]+"_5bx/I");
00513       }
00514     }
00515 
00516     std::string triggerAlgTechTrig = "PhysicsAlgorithms";
00517     for (unsigned int iBit = 0; iBit < numberTriggerBits; ++iBit) {     
00518       // ...Fill the corresponding accepts in branch-variables
00519       l1flag[iBit] = gtDecisionWord[iBit];
00520 
00521       std::string l1triggername= std::string (algoBitToName[iBit]);
00522       l1Prescl[iBit] = m_l1GtUtils.prescaleFactor(iEvent, 
00523                                                l1triggername,
00524                                                iErrorCode);
00525       
00526       if (_Debug) std::cout << "L1 TD: "<<iBit<<" "<<algoBitToName[iBit]<<" "
00527                             << gtDecisionWord[iBit]<<" "
00528                             << l1Prescl[iBit] << std::endl;
00529 
00530     }
00531 
00532     triggerAlgTechTrig = "TechnicalTriggers";
00533     for (unsigned int iBit = 0; iBit < numberTechnicalTriggerBits; ++iBit) {
00534       l1techflag[iBit] = (int) technicalTriggerWordBeforeMask.at(iBit);
00535 
00536       std::string l1triggername= std::string (techBitToName[iBit]);
00537       l1techPrescl[iBit] = m_l1GtUtils.prescaleFactor(iEvent, 
00538                                                l1triggername,
00539                                                iErrorCode);
00540 
00541       if (_Debug) std::cout << "L1 TD: "<<iBit<<" "<<techBitToName[iBit]<<" "
00542                             << l1techflag[iBit]<<" "
00543                             << l1Prescl[iBit] << std::endl;
00544 
00545     }
00546 
00547     if (_OR_BXes){
00548       // look at all 5 bx window in case gt timing is off
00549       // get Field Decision Logic
00550       std::vector<DecisionWord> m_gtDecisionWord5Bx;
00551       std::vector<TechnicalTriggerWord> m_gtTechDecisionWord5Bx;
00552       std::vector<int> m_ibxn;
00553 
00554       const std::vector<L1GtFdlWord> &m_gtFdlWord(L1GTRR->gtFdlVector());
00555       for (std::vector<L1GtFdlWord>::const_iterator itBx = m_gtFdlWord.begin();
00556            itBx != m_gtFdlWord.end(); ++itBx) {
00557         if (_Debug && L1EvtCnt==0) std::cout << "bx: " << (*itBx).bxInEvent() << " ";
00558         m_gtDecisionWord5Bx.push_back((*itBx).gtDecisionWord());
00559         m_gtTechDecisionWord5Bx.push_back((*itBx).gtTechnicalTriggerWord());
00560       }
00561       // --- Fill algo bits ---
00562       for (unsigned int iBit = 0; iBit < numberTriggerBits; ++iBit) {     
00563         // ...Fill the corresponding accepts in branch-variables
00564         if (_Debug) std::cout << std::endl << " L1 TD: "<<iBit<<" "<<algoBitToName[iBit]<<" ";
00565         int result=0;
00566         int bitword=0; 
00567         for (unsigned int jbx=0; jbx<m_gtDecisionWord5Bx.size(); ++jbx) {
00568           if (_Debug) std::cout << m_gtDecisionWord5Bx[jbx][iBit]<< " ";
00569           result += m_gtDecisionWord5Bx[jbx][iBit];
00570           if (m_gtDecisionWord5Bx[jbx][iBit]>0) bitword |= 1 << jbx;
00571         }
00572         if (_Debug && result>1) {std::cout << "5BxOr=" << result << "  Bitword= "<< bitword <<std::endl;
00573           std::cout << "Unpacking: " ;
00574           for (int i = 0; i<UnpackBxInEvent ; ++i){
00575             bool bitOn=bitword & (1 << i);
00576             std::cout << bitOn << " ";
00577           }
00578           std::cout << "\n";
00579         }
00580         l1flag5Bx[iBit] = bitword;
00581       }
00582       // --- Fill tech bits ---
00583       for (unsigned int iBit = 0; iBit < m_gtTechDecisionWord5Bx[2].size(); ++iBit) {     
00584         // ...Fill the corresponding accepts in branch-variables
00585         if (_Debug) std::cout << std::endl << " L1 TD: "<<iBit<<" "<<techBitToName[iBit]<<" ";
00586         int result=0;
00587         int bitword=0;       
00588         for (unsigned int jbx=0; jbx<m_gtTechDecisionWord5Bx.size(); ++jbx) {
00589           if (_Debug) std::cout << m_gtTechDecisionWord5Bx[jbx][iBit]<< " ";
00590           result += m_gtTechDecisionWord5Bx[jbx][iBit];
00591           if (m_gtTechDecisionWord5Bx[jbx][iBit]>0) bitword |= 1 << jbx;
00592         }
00593         if (_Debug && result>1) {std::cout << "5BxOr=" << result << "  Bitword= "<< bitword  << std::endl;
00594           std::cout << "Unpacking: " ;
00595           for (int i = 0; i<UnpackBxInEvent ; ++i){
00596             bool bitOn=bitword & (1 << i);
00597             std::cout << bitOn << " ";
00598           }
00599           std::cout << "\n";
00600         }
00601         l1techflag5Bx[iBit] = bitword;
00602       }
00603     } // end of OR_BX
00604 
00605     L1EvtCnt++;
00606   }
00607   else {
00608     if (_Debug) std::cout << "%HLTInfo -- No L1 GT ReadoutRecord " << std::endl;
00609   }
00610 
00611   //
00612   // LSB for feature bits = 0.125 GeV.
00613   // The default LSB for the ring sums is 0.5 GeV.
00614   
00615   if (gctBitCounts.isValid()) {
00616     L1GctHFBitCountsCollection::const_iterator bitCountItr;
00617     for (bitCountItr=gctBitCounts->begin(); bitCountItr!=gctBitCounts->end(); ++bitCountItr) { 
00618       if (bitCountItr->bx()==0){ // select in-time beam crossing
00619         l1hfTowerCountPositiveEtaRing1=bitCountItr->bitCount(0);
00620         l1hfTowerCountNegativeEtaRing1=bitCountItr->bitCount(1);
00621         l1hfTowerCountPositiveEtaRing2=bitCountItr->bitCount(2);
00622         l1hfTowerCountNegativeEtaRing2=bitCountItr->bitCount(3);
00623       }
00624     }
00625   } else {
00626     if (_Debug) std::cout << "%HLTInfo -- No L1 Gct HF BitCounts" << std::endl;
00627   }
00628 
00629   if (gctRingSums.isValid()) {
00630     L1GctHFRingEtSumsCollection::const_iterator ringSumsItr;
00631     for (ringSumsItr=gctRingSums->begin(); ringSumsItr!=gctRingSums->end(); ++ringSumsItr) { 
00632       if (ringSumsItr->bx()==0){ // select in-time beam crossing
00633         l1hfRing1EtSumPositiveEta=ringSumsItr->etSum(0);
00634         l1hfRing1EtSumNegativeEta=ringSumsItr->etSum(1);
00635         l1hfRing2EtSumPositiveEta=ringSumsItr->etSum(2);
00636         l1hfRing2EtSumNegativeEta=ringSumsItr->etSum(3);
00637       }
00638     }
00639   } else {
00640     if (_Debug) std::cout << "%HLTInfo -- No L1 Gct HF RingSums" << std::endl;
00641   }
00642 
00643   if (_Debug) std::cout << "%HLTInfo -- Done with routine" << std::endl;
00644 }