Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:20:47

0001 // -*- C++ -*-
0002 //
0003 // Package:    L1TMicroGMTInputProducer
0004 // Class:      L1TMicroGMTInputProducer
0005 //
0006 /**\class L1TMicroGMTInputProducer L1TMicroGMTInputProducer.cc L1Trigger/L1TGlobalMuon/plugins/L1TMicroGMTInputProducer.cc
0007 
0008  Description: Takes txt-file input and produces barrel- / overlap- / forward TF muons
0009 
0010  Implementation:
0011      [Notes on implementation]
0012 */
0013 //
0014 // Original Author:  Joschka Philip Lingemann,40 3-B01,+41227671598,
0015 //         Created:  Thu Oct  3 10:12:30 CEST 2013
0016 // $Id$
0017 //
0018 //
0019 
0020 // system include files
0021 #include <memory>
0022 #include <fstream>
0023 
0024 // user include files
0025 #include "FWCore/Framework/interface/Frameworkfwd.h"
0026 #include "FWCore/Framework/interface/stream/EDProducer.h"
0027 
0028 #include "FWCore/Framework/interface/Event.h"
0029 #include "FWCore/Framework/interface/MakerMacros.h"
0030 
0031 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0032 #include "FWCore/Utilities/interface/Exception.h"
0033 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0034 
0035 #include "DataFormats/L1TMuon/interface/RegionalMuonCandFwd.h"
0036 #include "DataFormats/L1TMuon/interface/RegionalMuonCand.h"
0037 #include "DataFormats/L1TMuon/interface/MuonCaloSumFwd.h"
0038 #include "DataFormats/L1TMuon/interface/MuonCaloSum.h"
0039 
0040 #include <iostream>
0041 //
0042 // class declaration
0043 //
0044 using namespace l1t;
0045 
0046 class L1TMicroGMTInputProducer : public edm::stream::EDProducer<> {
0047 public:
0048   explicit L1TMicroGMTInputProducer(const edm::ParameterSet&);
0049   ~L1TMicroGMTInputProducer() override;
0050 
0051   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0052 
0053 private:
0054   void produce(edm::Event&, const edm::EventSetup&) override;
0055 
0056   void openFile();
0057   void skipHeader();
0058   int convertToInt(std::string& bitstr) const;
0059   static bool cmpProc(const RegionalMuonCand&, const RegionalMuonCand&);
0060 
0061   // ----------member data ---------------------------
0062   std::string m_fname;
0063   std::ifstream m_filestream;
0064   bool m_endOfBx;
0065   bool m_lastMuInBx;
0066   int m_currType;
0067   int m_currEvt;
0068 };
0069 
0070 //
0071 // constants, enums and typedefs
0072 //
0073 
0074 //
0075 // static data member definitions
0076 //
0077 
0078 //
0079 // constructors and destructor
0080 //
0081 L1TMicroGMTInputProducer::L1TMicroGMTInputProducer(const edm::ParameterSet& iConfig)
0082     : m_endOfBx(false), m_currType(0), m_currEvt(0) {
0083   //register your products
0084   produces<RegionalMuonCandBxCollection>("BarrelTFMuons");
0085   produces<RegionalMuonCandBxCollection>("OverlapTFMuons");
0086   produces<RegionalMuonCandBxCollection>("ForwardTFMuons");
0087   produces<MuonCaloSumBxCollection>("TriggerTowerSums");
0088 
0089   //now do what ever other initialization is needed
0090   m_fname = iConfig.getParameter<std::string>("inputFileName");
0091 
0092   openFile();
0093   skipHeader();
0094 }
0095 
0096 L1TMicroGMTInputProducer::~L1TMicroGMTInputProducer() {
0097   // do anything here that needs to be done at desctruction time
0098   // (e.g. close files, deallocate resources etc.)
0099   m_filestream.close();
0100 }
0101 
0102 //
0103 // member functions
0104 //
0105 bool L1TMicroGMTInputProducer::cmpProc(const RegionalMuonCand& mu1, const RegionalMuonCand& mu2) {
0106   return mu1.processor() < mu2.processor();
0107 }
0108 
0109 void L1TMicroGMTInputProducer::openFile() {
0110   if (!m_filestream.is_open()) {
0111     m_filestream.open(m_fname.c_str());
0112     if (!m_filestream.good()) {
0113       cms::Exception("FileOpenError") << "Failed to open input file";
0114     }
0115   }
0116 }
0117 
0118 void L1TMicroGMTInputProducer::skipHeader() {
0119   while (m_filestream.peek() == '#') {
0120     std::string tmp;
0121     getline(m_filestream, tmp);
0122   }
0123 }
0124 
0125 int L1TMicroGMTInputProducer::convertToInt(std::string& bitstr) const {
0126   int num = 0;
0127   for (size_t cntr = 0; cntr < bitstr.size(); ++cntr) {
0128     char c = bitstr[cntr];
0129     num = (num << 1) |  // Shift the current set of bits to the left one bit
0130           (c - '0');    // Add in the current bit via a bitwise-or
0131   }
0132   return num;
0133 }
0134 
0135 // ------------ method called to produce the data  ------------
0136 void L1TMicroGMTInputProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0137   using namespace edm;
0138 
0139   std::unique_ptr<RegionalMuonCandBxCollection> barrelMuons(new RegionalMuonCandBxCollection());
0140   std::unique_ptr<RegionalMuonCandBxCollection> overlapMuons(new RegionalMuonCandBxCollection());
0141   std::unique_ptr<RegionalMuonCandBxCollection> endcapMuons(new RegionalMuonCandBxCollection());
0142   std::unique_ptr<MuonCaloSumBxCollection> towerSums(new MuonCaloSumBxCollection());
0143 
0144   RegionalMuonCand mu;
0145   MuonCaloSum tSum;
0146   m_endOfBx = false;
0147   int caloCounter = 0;
0148   std::vector<int> bar{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
0149   std::vector<int> ovl_neg{0, 0, 0, 0, 0, 0};
0150   std::vector<int> ovl_pos{0, 0, 0, 0, 0, 0};
0151   std::vector<int> fwd_neg{0, 0, 0, 0, 0, 0};
0152   std::vector<int> fwd_pos{0, 0, 0, 0, 0, 0};
0153   while (!m_endOfBx && !m_filestream.eof()) {
0154     std::string lineID;
0155     m_filestream >> lineID;
0156     std::string restOfLine;
0157 
0158     if (lineID == "BAR" || lineID == "OVL-" || lineID == "FWD-" || lineID == "OVL+" || lineID == "FWD+") {
0159       int tmp;
0160       m_filestream >> tmp;  // cable no
0161       // if (lineID == "BAR") tmp += 12;
0162       // if (lineID == "OVL-") tmp = (tmp-6)+24;
0163       // if (lineID == "OVL+") tmp = tmp + 6;
0164       // if (lineID == "FWD-") tmp = (tmp-6)+30;
0165 
0166       // mu.setLink(tmp);
0167       m_filestream >> tmp;
0168       mu.setHwPt(tmp);
0169 
0170       m_filestream >> tmp;
0171 
0172       int globalPhi = int(tmp * 0.560856864654333f);  // correction from txt file producer!
0173       int globalWedgePhi = (globalPhi + 24) % 576;    // this sets CMS phi = 0 to -15 deg
0174       int globalSectorPhi = (globalPhi - 24);         // this sets CMS phi = 0 to +15 deg
0175       if (globalSectorPhi < 0) {
0176         globalSectorPhi += 576;
0177       }
0178 
0179       // int globalMuonPhi = int(tmp*0.560856864654333f); // make sure scale is correct
0180       bool skip = false;
0181       if (lineID == "BAR") {
0182         int processor = globalWedgePhi / 48 + 1;
0183         int localPhi = globalWedgePhi % 48;
0184         mu.setTFIdentifiers(processor, tftype::bmtf);
0185         mu.setHwPhi(localPhi);
0186         bar[processor - 1]++;
0187         if (bar[processor - 1] > 3)
0188           skip = true;
0189       }
0190       if (lineID == "OVL-") {
0191         int processor = globalSectorPhi / 96 + 1;
0192         int localPhi = globalSectorPhi % 96;
0193         mu.setTFIdentifiers(processor, tftype::omtf_neg);
0194         mu.setHwPhi(localPhi);
0195         ovl_neg[processor - 1]++;
0196         if (ovl_neg[processor - 1] > 3)
0197           skip = true;
0198       }
0199       if (lineID == "OVL+") {
0200         int processor = globalSectorPhi / 96 + 1;
0201         int localPhi = globalSectorPhi % 96;
0202         mu.setTFIdentifiers(processor, tftype::omtf_pos);
0203         mu.setHwPhi(localPhi);
0204         ovl_pos[processor - 1]++;
0205         if (ovl_pos[processor - 1] > 3)
0206           skip = true;
0207       }
0208       if (lineID == "FWD-") {
0209         int processor = globalSectorPhi / 96 + 1;
0210         int localPhi = globalSectorPhi % 96;
0211         mu.setTFIdentifiers(processor, tftype::emtf_neg);
0212         mu.setHwPhi(localPhi);
0213         fwd_neg[processor - 1]++;
0214         if (fwd_neg[processor - 1] > 3)
0215           skip = true;
0216       }
0217       if (lineID == "FWD+") {
0218         int processor = globalSectorPhi / 96 + 1;
0219         int localPhi = globalSectorPhi % 96;
0220         mu.setTFIdentifiers(processor, tftype::emtf_pos);
0221         mu.setHwPhi(localPhi);
0222         fwd_pos[processor - 1]++;
0223         if (fwd_pos[processor - 1] > 3)
0224           skip = true;
0225       }
0226 
0227       m_filestream >> tmp;
0228       tmp = int(tmp * 0.9090909090f);
0229       mu.setHwEta(tmp);
0230 
0231       m_filestream >> tmp;
0232       mu.setHwSign(tmp);
0233 
0234       m_filestream >> tmp;
0235       mu.setHwSignValid(tmp);
0236 
0237       m_filestream >> tmp;
0238       mu.setHwQual(tmp);
0239 
0240       if (lineID == "BAR")
0241         m_currType = 0;
0242       if (lineID == "OVL-")
0243         m_currType = 1;
0244       if (lineID == "OVL+")
0245         m_currType = 2;
0246       if (lineID == "FWD-")
0247         m_currType = 3;
0248       if (lineID == "FWD+")
0249         m_currType = 4;
0250 
0251       if (m_currType == 0 && !skip)
0252         barrelMuons->push_back(0, mu);
0253       if ((m_currType == 1 || m_currType == 2) && !skip)
0254         overlapMuons->push_back(0, mu);
0255       if ((m_currType == 3 || m_currType == 4) && !skip)
0256         endcapMuons->push_back(0, mu);
0257     }
0258 
0259     if (lineID == "EVT" && m_currEvt != 0) {
0260       m_endOfBx = true;
0261     } else if (lineID == "EVT") {
0262       m_currEvt++;
0263     }
0264 
0265     if (lineID == "CALO") {
0266       for (int i = 0; i < 28; ++i) {
0267         int ieta = i;  //caloCounter%28;
0268         int iphi = caloCounter;
0269         int et;
0270 
0271         m_filestream >> et;
0272         tSum.setEtBits(et);
0273         tSum.setEtaBits(ieta);
0274         tSum.setPhiBits(iphi);
0275         tSum.setIndex(caloCounter * 28 + i);
0276         towerSums->push_back(0, tSum);
0277       }
0278       caloCounter++;
0279     }
0280     getline(m_filestream, restOfLine);
0281     //std::cout << restOfLine;
0282   }
0283 
0284   // std::sort(barrelMuons->begin(0), barrelMuons->end(0), L1TMicroGMTInputProducer::cmpProc);
0285   // std::sort(overlapMuons->begin(0), overlapMuons->end(0), L1TMicroGMTInputProducer::cmpProc);
0286   // std::sort(endcapMuons->begin(0), endcapMuons->end(0), L1TMicroGMTInputProducer::cmpProc);
0287 
0288   iEvent.put(std::move(barrelMuons), "BarrelTFMuons");
0289   iEvent.put(std::move(overlapMuons), "OverlapTFMuons");
0290   iEvent.put(std::move(endcapMuons), "ForwardTFMuons");
0291   iEvent.put(std::move(towerSums), "TriggerTowerSums");
0292   m_currEvt++;
0293 }
0294 
0295 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0296 void L1TMicroGMTInputProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0297   //The following says we do not know what parameters are allowed so do no validation
0298   // Please change this to state exactly what you do use, even if it is no parameters
0299   edm::ParameterSetDescription desc;
0300   desc.setUnknown();
0301   descriptions.addDefault(desc);
0302 }
0303 
0304 //define this as a plug-in
0305 DEFINE_FWK_MODULE(L1TMicroGMTInputProducer);