CMS 3D CMS Logo

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