Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:21:47

0001 /**
0002  *
0003  * Analyzer that writes LUTs.
0004  *
0005  *\author L. Gray (4/13/06)
0006  *
0007  */
0008 
0009 #include <fstream>
0010 #include "FWCore/Framework/interface/EDAnalyzer.h"
0011 #include "FWCore/Framework/interface/Event.h"
0012 #include "DataFormats/Common/interface/Handle.h"
0013 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0014 #include "FWCore/Framework/interface/EventSetup.h"
0015 #include "FWCore/Framework/interface/ESHandle.h"
0016 
0017 #include "Geometry/CSCGeometry/interface/CSCGeometry.h"
0018 #include "Geometry/Records/interface/MuonGeometryRecord.h"
0019 #include "DataFormats/MuonDetId/interface/CSCTriggerNumbering.h"
0020 #include "DataFormats/MuonDetId/interface/CSCDetId.h"
0021 
0022 #include "DataFormats/L1CSCTrackFinder/interface/CSCBitWidths.h"
0023 #include "L1Trigger/CSCTrackFinder/interface/CSCSectorReceiverLUT.h"
0024 
0025 #include "L1Trigger/CSCTrackFinder/test/analysis/CSCMakeSRLUT.h"
0026 
0027 CSCMakeSRLUT::CSCMakeSRLUT(edm::ParameterSet const& conf) {
0028   writeLocalPhi = conf.getUntrackedParameter<bool>("WriteLocalPhi", true);
0029   station = conf.getUntrackedParameter<int>("Station", -1);
0030   sector = conf.getUntrackedParameter<int>("Sector", -1);
0031   endcap = conf.getUntrackedParameter<int>("Endcap", -1);
0032   isTMB07 = conf.getUntrackedParameter<bool>("isTMB07", false);
0033   writeGlobalPhi = conf.getUntrackedParameter<bool>("WriteGlobalPhi", true);
0034   writeGlobalEta = conf.getUntrackedParameter<bool>("WriteGlobalEta", true);
0035   binary = conf.getUntrackedParameter<bool>("BinaryOutput", true);
0036   LUTparam = conf.getParameter<edm::ParameterSet>("lutParam");
0037 
0038   //init Sector Receiver LUTs
0039   for (int e = CSCDetId::minEndcapId(); e <= CSCDetId::maxEndcapId(); ++e)
0040     for (int se = CSCTriggerNumbering::minTriggerSectorId(); se <= CSCTriggerNumbering::maxTriggerSectorId(); ++se)
0041       for (int st = CSCDetId::minStationId(); st <= CSCDetId::maxStationId(); ++st) {
0042         if (st == 1)
0043           for (int ss = CSCTriggerNumbering::minTriggerSubSectorId();
0044                ss <= CSCTriggerNumbering::maxTriggerSubSectorId();
0045                ++ss) {
0046             mySR[e - 1][se - 1][ss - 1][st - 1] = new CSCSectorReceiverLUT(e, se, ss, st, LUTparam, isTMB07);
0047           }
0048         else {
0049           mySR[e - 1][se - 1][0][st - 1] = new CSCSectorReceiverLUT(e, se, 0, st, LUTparam, isTMB07);
0050           mySR[e - 1][se - 1][1][st - 1] = NULL;  // Save space.
0051         }
0052       }
0053 }
0054 
0055 CSCMakeSRLUT::~CSCMakeSRLUT() {
0056   for (int e = CSCDetId::minEndcapId(); e <= CSCDetId::maxEndcapId(); ++e)
0057     for (int se = CSCTriggerNumbering::minTriggerSectorId(); se <= CSCTriggerNumbering::maxTriggerSectorId(); ++se)
0058       for (int ss = CSCTriggerNumbering::minTriggerSubSectorId(); ss <= CSCTriggerNumbering::maxTriggerSubSectorId();
0059            ++ss)
0060         for (int st = CSCDetId::minStationId(); st <= CSCDetId::maxStationId(); ++st) {
0061           if (mySR[e - 1][se - 1][ss - 1][st - 1]) {
0062             delete mySR[e - 1][se - 1][ss - 1][st - 1];
0063             mySR[e - 1][se - 1][ss - 1][st - 1] = NULL;
0064           }
0065         }
0066 }
0067 
0068 void CSCMakeSRLUT::analyze(edm::Event const& e, edm::EventSetup const& iSetup) {
0069   edm::ESHandle<CSCGeometry> pDD;
0070   iSetup.get<MuonGeometryRecord>().get(pDD);
0071 
0072   if (writeLocalPhi) {
0073     std::string filename = std::string("LocalPhiLUT") + ((binary) ? std::string(".bin") : std::string(".dat"));
0074     std::ofstream LocalPhiLUT(filename.c_str());
0075     for (int i = 0; i < 1 << CSCBitWidths::kLocalPhiAddressWidth; ++i) {
0076       unsigned short thedata;
0077       try {
0078         thedata = mySR[0][0][0][0]->localPhi(i).toint();
0079       } catch (...) {
0080         thedata = 0;
0081       }
0082       if (binary)
0083         LocalPhiLUT.write(reinterpret_cast<char*>(&thedata), sizeof(unsigned short));
0084       else
0085         LocalPhiLUT << std::dec << thedata << std::endl;
0086     }
0087   }
0088 
0089   if (writeGlobalPhi) {
0090     std::string MEprefix = "GlobalPhiME";
0091     std::string MBprefix = "GlobalPhiMB";
0092     std::ofstream GlobalPhiLUT;
0093 
0094     for (int e = CSCDetId::minEndcapId(); e <= CSCDetId::maxEndcapId(); ++e)
0095       if (endcap == -1 || endcap == e)
0096         for (int se = CSCTriggerNumbering::minTriggerSectorId(); se <= CSCTriggerNumbering::maxTriggerSectorId(); ++se)
0097           if (sector == -1 || sector == se)
0098             for (int st = CSCDetId::minStationId(); st <= CSCDetId::maxStationId(); ++st)
0099               if (station == -1 || station == st)
0100                 for (int ss = CSCTriggerNumbering::minTriggerSubSectorId();
0101                      ss <= CSCTriggerNumbering::maxTriggerSubSectorId();
0102                      ++ss) {
0103                   unsigned short thedata;
0104                   if (st == 1) {
0105                     std::string fname =
0106                         MEprefix + mySR[e - 1][se - 1][ss - 1][st - 1]->encodeFileIndex() + fileSuffix();
0107                     GlobalPhiLUT.open(fname.c_str());
0108                     for (int i = 0; i < 1 << CSCBitWidths::kGlobalPhiAddressWidth; ++i) {
0109                       try {
0110                         thedata = mySR[e - 1][se - 1][ss - 1][st - 1]->globalPhiME(i).toint();
0111                       } catch (...) {
0112                         thedata = 0;
0113                       }
0114                       if (binary)
0115                         GlobalPhiLUT.write(reinterpret_cast<char*>(&thedata), sizeof(unsigned short));
0116                       else
0117                         GlobalPhiLUT << std::dec << thedata << std::endl;
0118                     }
0119                     GlobalPhiLUT.close();
0120 
0121                     // Write MB global phi LUTs
0122 
0123                     fname = MBprefix + mySR[e - 1][se - 1][ss - 1][st - 1]->encodeFileIndex() + fileSuffix();
0124                     GlobalPhiLUT.open(fname.c_str());
0125                     for (int i = 0; i < 1 << CSCBitWidths::kGlobalPhiAddressWidth; ++i) {
0126                       try {
0127                         thedata = mySR[e - 1][se - 1][ss - 1][st - 1]->globalPhiMB(i).toint();
0128                       } catch (...) {
0129                         thedata = 0;
0130                       }
0131                       if (binary)
0132                         GlobalPhiLUT.write(reinterpret_cast<char*>(&thedata), sizeof(unsigned short));
0133                       else
0134                         GlobalPhiLUT << std::dec << thedata << std::endl;
0135                     }
0136                     GlobalPhiLUT.close();
0137 
0138                   } else {
0139                     if (ss == 1) {
0140                       std::string fname = MEprefix + mySR[e - 1][se - 1][0][st - 1]->encodeFileIndex() + fileSuffix();
0141                       GlobalPhiLUT.open(fname.c_str());
0142                       for (int i = 0; i < 1 << CSCBitWidths::kGlobalPhiAddressWidth; ++i) {
0143                         try {
0144                           thedata = mySR[e - 1][se - 1][0][st - 1]->globalPhiME(i).toint();
0145                         } catch (...) {
0146                           thedata = 0;
0147                         }
0148                         if (binary)
0149                           GlobalPhiLUT.write(reinterpret_cast<char*>(&thedata), sizeof(unsigned short));
0150                         else
0151                           GlobalPhiLUT << std::dec << thedata << std::endl;
0152                       }
0153                       GlobalPhiLUT.close();
0154                     }
0155                   }
0156                 }
0157   }
0158 
0159   if (writeGlobalEta) {
0160     std::string prefix = "GlobalEtaME";
0161     std::ofstream GlobalEtaLUT;
0162 
0163     for (int e = CSCDetId::minEndcapId(); e <= CSCDetId::maxEndcapId(); ++e)
0164       if (endcap == -1 || endcap == e)
0165         for (int se = CSCTriggerNumbering::minTriggerSectorId(); se <= CSCTriggerNumbering::maxTriggerSectorId(); ++se)
0166           if (sector == -1 || sector == se)
0167             for (int st = CSCDetId::minStationId(); st <= CSCDetId::maxStationId(); ++st)
0168               if (station == -1 || station == st)
0169                 for (int ss = CSCTriggerNumbering::minTriggerSubSectorId();
0170                      ss <= CSCTriggerNumbering::maxTriggerSubSectorId();
0171                      ++ss) {
0172                   unsigned short thedata;
0173                   if (st == 1) {
0174                     std::string fname = prefix + mySR[e - 1][se - 1][ss - 1][st - 1]->encodeFileIndex() + fileSuffix();
0175                     GlobalEtaLUT.open(fname.c_str());
0176                     for (int i = 0; i < 1 << CSCBitWidths::kGlobalEtaAddressWidth; ++i) {
0177                       try {
0178                         thedata = mySR[e - 1][se - 1][ss - 1][st - 1]->globalEtaME(i).toint();
0179                       } catch (...) {
0180                         thedata = 0;
0181                       }
0182                       if (binary)
0183                         GlobalEtaLUT.write(reinterpret_cast<char*>(&thedata), sizeof(unsigned short));
0184                       else
0185                         GlobalEtaLUT << std::dec << thedata << std::endl;
0186                     }
0187                     GlobalEtaLUT.close();
0188                   } else {
0189                     if (ss == 1) {
0190                       std::string fname = prefix + mySR[e - 1][se - 1][0][st - 1]->encodeFileIndex() + fileSuffix();
0191                       GlobalEtaLUT.open(fname.c_str());
0192                       for (int i = 0; i < 1 << CSCBitWidths::kGlobalEtaAddressWidth; ++i) {
0193                         try {
0194                           thedata = mySR[e - 1][se - 1][0][st - 1]->globalEtaME(i).toint();
0195                         } catch (...) {
0196                           thedata = 0;
0197                         }
0198                         if (binary)
0199                           GlobalEtaLUT.write(reinterpret_cast<char*>(&thedata), sizeof(unsigned short));
0200                         else
0201                           GlobalEtaLUT << std::dec << thedata << std::endl;
0202                       }
0203                       GlobalEtaLUT.close();
0204                     }
0205                   }
0206                 }
0207   }
0208 }
0209 
0210 std::string CSCMakeSRLUT::fileSuffix() const {
0211   std::string fileName = "";
0212   fileName += ((binary) ? ".bin" : ".dat");
0213   return fileName;
0214 }