Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:19:32

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