CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/L1Trigger/RegionalCaloTrigger/plugins/L1RCTSaveInput.cc

Go to the documentation of this file.
00001 #include <memory>
00002 #include <string>
00003 #include <iostream>
00004 #include <fstream>
00005 using std::ostream;
00006 using std::cout;
00007 using std::cerr;
00008 using std::endl;
00009 
00010 #include <iomanip>
00011 
00012 #include "FWCore/Framework/interface/Frameworkfwd.h"
00013 #include "FWCore/Framework/interface/EDAnalyzer.h"
00014 #include "FWCore/Framework/interface/Event.h"
00015 #include "FWCore/Framework/interface/MakerMacros.h"
00016 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00017 
00018 #include "L1Trigger/RegionalCaloTrigger/interface/L1RCTSaveInput.h"
00019 
00020 #include "DataFormats/L1CaloTrigger/interface/L1CaloCollections.h"
00021 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
00022 #include "DataFormats/HcalDigi/interface/HcalDigiCollections.h"
00023 
00024 #include "CondFormats/L1TObjects/interface/L1CaloHcalScale.h"
00025 #include "CondFormats/DataRecord/interface/L1CaloHcalScaleRcd.h"
00026 #include "CondFormats/L1TObjects/interface/L1CaloEcalScale.h"
00027 #include "CondFormats/DataRecord/interface/L1CaloEcalScaleRcd.h"
00028 
00029 // also include old-style scales -- same as L1RCTProducer?
00030 #include "CalibFormats/CaloTPG/interface/CaloTPGTranscoder.h"
00031 #include "CalibFormats/CaloTPG/interface/CaloTPGRecord.h"
00032 #include "CalibCalorimetry/EcalTPGTools/interface/EcalTPGScale.h"
00033 
00034 #include "CondFormats/L1TObjects/interface/L1CaloEtScale.h"
00035 #include "CondFormats/DataRecord/interface/L1EmEtScaleRcd.h"
00036 
00037 #include "CondFormats/L1TObjects/interface/L1RCTParameters.h"
00038 #include "CondFormats/DataRecord/interface/L1RCTParametersRcd.h"
00039 #include "CondFormats/L1TObjects/interface/L1RCTChannelMask.h"
00040 #include "CondFormats/DataRecord/interface/L1RCTChannelMaskRcd.h"
00041 
00042 #include "L1Trigger/RegionalCaloTrigger/interface/L1RCT.h"
00043 #include "L1Trigger/RegionalCaloTrigger/interface/L1RCTLookupTables.h" 
00044 
00045 L1RCTSaveInput::L1RCTSaveInput(const edm::ParameterSet& conf) :
00046   fileName(conf.getUntrackedParameter<std::string>("rctTestInputFile")),
00047   rctLookupTables(new L1RCTLookupTables),
00048   rct(new L1RCT(rctLookupTables)),
00049   useEcal(conf.getParameter<bool>("useEcal")),
00050   useHcal(conf.getParameter<bool>("useHcal")),
00051   ecalDigisLabel(conf.getParameter<edm::InputTag>("ecalDigisLabel")),
00052   hcalDigisLabel(conf.getParameter<edm::InputTag>("hcalDigisLabel")),
00053   useDebugTpgScales(conf.getParameter<bool>("useDebugTpgScales"))
00054 {
00055   ofs.open(fileName.c_str(), std::ios::app);
00056   if(!ofs)
00057     {
00058       std::cerr << "Could not create " << fileName << std::endl;
00059       exit(1);
00060     }
00061 }
00062 
00063 L1RCTSaveInput::~L1RCTSaveInput()
00064 {
00065   if(rct != 0) delete rct;
00066   if(rctLookupTables != 0) delete rctLookupTables;
00067 }
00068 
00069 void
00070 L1RCTSaveInput::analyze(const edm::Event& event,
00071                         const edm::EventSetup& eventSetup)
00072 {
00073   edm::ESHandle<L1RCTParameters> rctParameters;
00074   eventSetup.get<L1RCTParametersRcd>().get(rctParameters);
00075   const L1RCTParameters* r = rctParameters.product();
00076   edm::ESHandle<L1RCTChannelMask> channelMask;
00077   eventSetup.get<L1RCTChannelMaskRcd>().get(channelMask);
00078   const L1RCTChannelMask* c = channelMask.product();
00079   edm::ESHandle<L1CaloEtScale> emScale;
00080   eventSetup.get<L1EmEtScaleRcd>().get(emScale);
00081   const L1CaloEtScale* s = emScale.product();
00082 
00083   rctLookupTables->setRCTParameters(r);
00084   rctLookupTables->setChannelMask(c);
00085   rctLookupTables->setL1CaloEtScale(s);
00086 
00087   // use dummies to get delete right when creating new scales from old
00088   L1CaloEcalScale* dummyE(0);
00089   L1CaloHcalScale* dummyH(0);
00090 
00091   if (useDebugTpgScales)
00092     {
00093       // use old-style scales
00094       edm::ESHandle<CaloTPGTranscoder> transcoder;
00095       eventSetup.get<CaloTPGRecord>().get(transcoder);
00096       const CaloTPGTranscoder* h_tpg = transcoder.product();
00097 
00098       EcalTPGScale* e_tpg = new EcalTPGScale();
00099       e_tpg->setEventSetup(eventSetup);
00100 
00101       L1CaloEcalScale* ecalScale = new L1CaloEcalScale();
00102       L1CaloHcalScale* hcalScale = new L1CaloHcalScale();
00103 
00104       // create input scales, werner's code
00105       // ECAL
00106       std::cout << "ECAL Pos " << L1CaloEcalScale::nBinRank << std::endl ;
00107       for( unsigned short ieta = 1 ; ieta <= L1CaloEcalScale::nBinEta; ++ieta )
00108         {
00109           for( unsigned short irank = 0 ; irank < L1CaloEcalScale::nBinRank; ++irank )
00110             {
00111               std::cout << ieta << " " << irank ;
00112               EcalSubdetector subdet = ( ieta <= 17 ) ? EcalBarrel : EcalEndcap ;
00113               double etGeVPos =
00114                 e_tpg->getTPGInGeV
00115                 ( irank, EcalTrigTowerDetId(1, // +ve eta
00116                                             subdet,
00117                                             ieta,
00118                                             1 )); // dummy phi value
00119               ecalScale->setBin( irank, ieta, 1, etGeVPos ) ;
00120               std::cout << etGeVPos << ", " ;
00121             }
00122           std::cout << std::endl ;
00123         }
00124       std::cout << std::endl ;
00125 
00126       std::cout << "ECAL Neg" << std::endl ;
00127       for( unsigned short ieta = 1 ; ieta <= L1CaloEcalScale::nBinEta; ++ieta )
00128         {
00129           for( unsigned short irank = 0 ; irank < L1CaloEcalScale::nBinRank; ++irank )
00130             {
00131               EcalSubdetector subdet = ( ieta <= 17 ) ? EcalBarrel : EcalEndcap ;
00132 
00133               std::cout << ieta << " " << irank ;
00134               double etGeVNeg =
00135                 e_tpg->getTPGInGeV
00136                 ( irank,
00137                   EcalTrigTowerDetId(-1, // -ve eta
00138                                      subdet,
00139                                      ieta,
00140                                      2 )); // dummy phi value
00141               ecalScale->setBin( irank, ieta, -1, etGeVNeg ) ;
00142               std::cout << etGeVNeg << ", " ;
00143             }
00144           std::cout << std::endl ;
00145         }
00146       std::cout << std::endl ;
00147 
00148       // HCAL
00149       std::cout << "HCAL" << std::endl ;
00150       for( unsigned short ieta = 1 ; ieta <= L1CaloHcalScale::nBinEta; ++ieta )
00151         {
00152           for( unsigned short irank = 0 ; irank < L1CaloHcalScale::nBinRank; ++irank )
00153             {
00154               double etGeV = h_tpg->hcaletValue( ieta, irank ) ;
00155 
00156               hcalScale->setBin( irank, ieta, 1, etGeV ) ;
00157               hcalScale->setBin( irank, ieta, -1, etGeV ) ;
00158               std::cout << etGeV << ", " ;
00159               std::cout << std::endl ;
00160             }
00161           std::cout << std::endl ;
00162         }
00163 
00164       // set the input scales
00165       rctLookupTables->setEcalScale(ecalScale);
00166       rctLookupTables->setHcalScale(hcalScale);
00167       
00168       dummyE = ecalScale;
00169       dummyH = hcalScale;
00170       
00171       delete e_tpg;
00172       
00173     }
00174   else
00175     {
00176       edm::ESHandle<L1CaloHcalScale> hcalScale;
00177       eventSetup.get<L1CaloHcalScaleRcd>().get(hcalScale);
00178       const L1CaloHcalScale* h = hcalScale.product();
00179       edm::ESHandle<L1CaloEcalScale> ecalScale;
00180       eventSetup.get<L1CaloEcalScaleRcd>().get(ecalScale);
00181       const L1CaloEcalScale* e = ecalScale.product();
00182 
00183       rctLookupTables->setHcalScale(h);
00184       rctLookupTables->setEcalScale(e);
00185 
00186     }
00187 
00188   edm::Handle<EcalTrigPrimDigiCollection> ecal;
00189   edm::Handle<HcalTrigPrimDigiCollection> hcal;
00190   event.getByLabel(ecalDigisLabel, ecal); 
00191   event.getByLabel(hcalDigisLabel, hcal); 
00192   EcalTrigPrimDigiCollection ecalColl;
00193   HcalTrigPrimDigiCollection hcalColl;
00194   if (ecal.isValid()) { ecalColl = *ecal; }
00195   if (hcal.isValid()) { hcalColl = *hcal; }
00196   rct->digiInput(ecalColl, hcalColl);
00197   static int nEvents = 0;
00198   if(nEvents == 0)
00199     {
00200       ofs
00201         << "Crate = 0-17" << std::endl
00202         << "Card = 0-7 within the crate" << std::endl
00203         << "Tower = 0-31 covers 4 x 8 covered by the card" << std::endl
00204         << "EMAddr(0:8) = EMFGBit(0:0)+CompressedEMET(1:8)" << std::endl
00205         << "HDAddr(0:8) = HDFGBit(0:0)+CompressedHDET(1:8) - note: HDFGBit(0:0) is not part of the hardware LUT address" << std::endl
00206         << "LutOut(0:17)= LinearEMET(0:6)+HoEFGVetoBit(7:7)+LinearJetET(8:16)+ActivityBit(17:17)" << std::endl
00207         << "Event" << "\t"
00208         << "Crate" << "\t"
00209         << "Card" << "\t"
00210         << "Tower" << "\t"
00211         << "EMAddr" << "\t"
00212         << "HDAddr" << "\t"
00213         << "LUTOut"
00214         << std::endl;
00215     }
00216   if(nEvents < 64)
00217     {
00218       for(unsigned short iCrate = 0; iCrate < 18; iCrate++)
00219         {
00220           for(unsigned short iCard = 0; iCard < 7; iCard++)
00221             {
00222               // tower numbered from 0-31
00223               for(unsigned short iTower = 0; iTower < 32; iTower++)
00224                 {
00225                   unsigned short ecal = rct->ecalCompressedET(iCrate, iCard, iTower);
00226                   unsigned short hcal = rct->hcalCompressedET(iCrate, iCard, iTower);
00227                   unsigned short fgbit = rct->ecalFineGrainBit(iCrate, iCard, iTower);
00228                   unsigned short mubit = rct->hcalFineGrainBit(iCrate, iCard, iTower);
00229                   unsigned long lutOutput = rctLookupTables->lookup(ecal, hcal, fgbit, iCrate, iCard, iTower);
00230                   ofs
00231                     << std::hex 
00232                     << nEvents << "\t"
00233                     << iCrate << "\t"
00234                     << iCard << "\t"
00235                     << iTower << "\t"
00236                     << ecal * 2 + fgbit << "\t"
00237                     << hcal * 2 + mubit << "\t"
00238                     << lutOutput
00239                     << std::dec 
00240                     << std::endl;
00241                 }
00242             }
00243         }
00244     }
00245   nEvents++;
00246 }