CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/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   if (useDebugTpgScales)
00088     {
00089       // use old-style scales
00090       edm::ESHandle<CaloTPGTranscoder> transcoder;
00091       eventSetup.get<CaloTPGRecord>().get(transcoder);
00092       const CaloTPGTranscoder* h_tpg = transcoder.product();
00093 
00094       EcalTPGScale* e_tpg = new EcalTPGScale();
00095       e_tpg->setEventSetup(eventSetup);
00096 
00097       L1CaloEcalScale* ecalScale = new L1CaloEcalScale();
00098       L1CaloHcalScale* hcalScale = new L1CaloHcalScale();
00099 
00100       // create input scales, werner's code
00101       // ECAL
00102       std::cout << "ECAL Pos " << L1CaloEcalScale::nBinRank << std::endl ;
00103       for( unsigned short ieta = 1 ; ieta <= L1CaloEcalScale::nBinEta; ++ieta )
00104         {
00105           for( unsigned short irank = 0 ; irank < L1CaloEcalScale::nBinRank; ++irank )
00106             {
00107               std::cout << ieta << " " << irank ;
00108               EcalSubdetector subdet = ( ieta <= 17 ) ? EcalBarrel : EcalEndcap ;
00109               double etGeVPos =
00110                 e_tpg->getTPGInGeV
00111                 ( irank, EcalTrigTowerDetId(1, // +ve eta
00112                                             subdet,
00113                                             ieta,
00114                                             1 )); // dummy phi value
00115               ecalScale->setBin( irank, ieta, 1, etGeVPos ) ;
00116               std::cout << etGeVPos << ", " ;
00117             }
00118           std::cout << std::endl ;
00119         }
00120       std::cout << std::endl ;
00121 
00122       std::cout << "ECAL Neg" << std::endl ;
00123       for( unsigned short ieta = 1 ; ieta <= L1CaloEcalScale::nBinEta; ++ieta )
00124         {
00125           for( unsigned short irank = 0 ; irank < L1CaloEcalScale::nBinRank; ++irank )
00126             {
00127               EcalSubdetector subdet = ( ieta <= 17 ) ? EcalBarrel : EcalEndcap ;
00128 
00129               std::cout << ieta << " " << irank ;
00130               double etGeVNeg =
00131                 e_tpg->getTPGInGeV
00132                 ( irank,
00133                   EcalTrigTowerDetId(-1, // -ve eta
00134                                      subdet,
00135                                      ieta,
00136                                      2 )); // dummy phi value
00137               ecalScale->setBin( irank, ieta, -1, etGeVNeg ) ;
00138               std::cout << etGeVNeg << ", " ;
00139             }
00140           std::cout << std::endl ;
00141         }
00142       std::cout << std::endl ;
00143 
00144       // HCAL
00145       std::cout << "HCAL" << std::endl ;
00146       for( unsigned short ieta = 1 ; ieta <= L1CaloHcalScale::nBinEta; ++ieta )
00147         {
00148           for( unsigned short irank = 0 ; irank < L1CaloHcalScale::nBinRank; ++irank )
00149             {
00150               double etGeV = h_tpg->hcaletValue( ieta, irank ) ;
00151 
00152               hcalScale->setBin( irank, ieta, 1, etGeV ) ;
00153               hcalScale->setBin( irank, ieta, -1, etGeV ) ;
00154               std::cout << etGeV << ", " ;
00155               std::cout << std::endl ;
00156             }
00157           std::cout << std::endl ;
00158         }
00159 
00160       // set the input scales
00161       rctLookupTables->setEcalScale(ecalScale);
00162       rctLookupTables->setHcalScale(hcalScale);
00163       
00164       delete e_tpg;
00165       
00166     }
00167   else
00168     {
00169       edm::ESHandle<L1CaloHcalScale> hcalScale;
00170       eventSetup.get<L1CaloHcalScaleRcd>().get(hcalScale);
00171       const L1CaloHcalScale* h = hcalScale.product();
00172       edm::ESHandle<L1CaloEcalScale> ecalScale;
00173       eventSetup.get<L1CaloEcalScaleRcd>().get(ecalScale);
00174       const L1CaloEcalScale* e = ecalScale.product();
00175 
00176       rctLookupTables->setHcalScale(h);
00177       rctLookupTables->setEcalScale(e);
00178 
00179     }
00180 
00181   edm::Handle<EcalTrigPrimDigiCollection> ecal;
00182   edm::Handle<HcalTrigPrimDigiCollection> hcal;
00183   event.getByLabel(ecalDigisLabel, ecal); 
00184   event.getByLabel(hcalDigisLabel, hcal); 
00185   EcalTrigPrimDigiCollection ecalColl;
00186   HcalTrigPrimDigiCollection hcalColl;
00187   if (ecal.isValid()) { ecalColl = *ecal; }
00188   if (hcal.isValid()) { hcalColl = *hcal; }
00189   rct->digiInput(ecalColl, hcalColl);
00190   static int nEvents = 0;
00191   if(nEvents == 0)
00192     {
00193       ofs
00194         << "Crate = 0-17" << std::endl
00195         << "Card = 0-7 within the crate" << std::endl
00196         << "Tower = 0-31 covers 4 x 8 covered by the card" << std::endl
00197         << "EMAddr(0:8) = EMFGBit(0:0)+CompressedEMET(1:8)" << std::endl
00198         << "HDAddr(0:8) = HDFGBit(0:0)+CompressedHDET(1:8) - note: HDFGBit(0:0) is not part of the hardware LUT address" << std::endl
00199         << "LutOut(0:17)= LinearEMET(0:6)+HoEFGVetoBit(7:7)+LinearJetET(8:16)+ActivityBit(17:17)" << std::endl
00200         << "Event" << "\t"
00201         << "Crate" << "\t"
00202         << "Card" << "\t"
00203         << "Tower" << "\t"
00204         << "EMAddr" << "\t"
00205         << "HDAddr" << "\t"
00206         << "LUTOut"
00207         << std::endl;
00208     }
00209   if(nEvents < 64)
00210     {
00211       for(unsigned short iCrate = 0; iCrate < 18; iCrate++)
00212         {
00213           for(unsigned short iCard = 0; iCard < 7; iCard++)
00214             {
00215               // tower numbered from 0-31
00216               for(unsigned short iTower = 0; iTower < 32; iTower++)
00217                 {
00218                   unsigned short ecal = rct->ecalCompressedET(iCrate, iCard, iTower);
00219                   unsigned short hcal = rct->hcalCompressedET(iCrate, iCard, iTower);
00220                   unsigned short fgbit = rct->ecalFineGrainBit(iCrate, iCard, iTower);
00221                   unsigned short mubit = rct->hcalFineGrainBit(iCrate, iCard, iTower);
00222                   unsigned long lutOutput = rctLookupTables->lookup(ecal, hcal, fgbit, iCrate, iCard, iTower);
00223                   ofs
00224                     << std::hex 
00225                     << nEvents << "\t"
00226                     << iCrate << "\t"
00227                     << iCard << "\t"
00228                     << iTower << "\t"
00229                     << ecal * 2 + fgbit << "\t"
00230                     << hcal * 2 + mubit << "\t"
00231                     << lutOutput
00232                     << std::dec 
00233                     << std::endl;
00234                 }
00235             }
00236         }
00237     }
00238   nEvents++;
00239 }