Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:23:10

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 beginRun(const edm::Run&, edm::EventSetup const&) override;
0057   void endRun(const edm::Run&, edm::EventSetup const&) override;
0058   void beginLuminosityBlock(const edm::LuminosityBlock&, edm::EventSetup const&) override;
0059   void endLuminosityBlock(const edm::LuminosityBlock&, edm::EventSetup const&) override;
0060 
0061   void openFile();
0062   void skipHeader();
0063   int convertToInt(std::string& bitstr) const;
0064   static bool cmpProc(const RegionalMuonCand&, const RegionalMuonCand&);
0065 
0066   // ----------member data ---------------------------
0067   std::string m_fname;
0068   std::ifstream m_filestream;
0069   bool m_endOfBx;
0070   bool m_lastMuInBx;
0071   int m_currType;
0072   int m_currEvt;
0073 };
0074 
0075 //
0076 // constants, enums and typedefs
0077 //
0078 
0079 //
0080 // static data member definitions
0081 //
0082 
0083 //
0084 // constructors and destructor
0085 //
0086 L1TMicroGMTInputProducer::L1TMicroGMTInputProducer(const edm::ParameterSet& iConfig)
0087     : m_endOfBx(false), m_currType(0), m_currEvt(0) {
0088   //register your products
0089   produces<RegionalMuonCandBxCollection>("BarrelTFMuons");
0090   produces<RegionalMuonCandBxCollection>("OverlapTFMuons");
0091   produces<RegionalMuonCandBxCollection>("ForwardTFMuons");
0092   produces<MuonCaloSumBxCollection>("TriggerTowerSums");
0093 
0094   //now do what ever other initialization is needed
0095   m_fname = iConfig.getParameter<std::string>("inputFileName");
0096 
0097   openFile();
0098   skipHeader();
0099 }
0100 
0101 L1TMicroGMTInputProducer::~L1TMicroGMTInputProducer() {
0102   // do anything here that needs to be done at desctruction time
0103   // (e.g. close files, deallocate resources etc.)
0104   m_filestream.close();
0105 }
0106 
0107 //
0108 // member functions
0109 //
0110 bool L1TMicroGMTInputProducer::cmpProc(const RegionalMuonCand& mu1, const RegionalMuonCand& mu2) {
0111   return mu1.processor() < mu2.processor();
0112 }
0113 
0114 void L1TMicroGMTInputProducer::openFile() {
0115   if (!m_filestream.is_open()) {
0116     m_filestream.open(m_fname.c_str());
0117     if (!m_filestream.good()) {
0118       cms::Exception("FileOpenError") << "Failed to open input file";
0119     }
0120   }
0121 }
0122 
0123 void L1TMicroGMTInputProducer::skipHeader() {
0124   while (m_filestream.peek() == '#') {
0125     std::string tmp;
0126     getline(m_filestream, tmp);
0127   }
0128 }
0129 
0130 int L1TMicroGMTInputProducer::convertToInt(std::string& bitstr) const {
0131   int num = 0;
0132   for (size_t cntr = 0; cntr < bitstr.size(); ++cntr) {
0133     char c = bitstr[cntr];
0134     num = (num << 1) |  // Shift the current set of bits to the left one bit
0135           (c - '0');    // Add in the current bit via a bitwise-or
0136   }
0137   return num;
0138 }
0139 
0140 // ------------ method called to produce the data  ------------
0141 void L1TMicroGMTInputProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0142   using namespace edm;
0143 
0144   std::unique_ptr<RegionalMuonCandBxCollection> barrelMuons(new RegionalMuonCandBxCollection());
0145   std::unique_ptr<RegionalMuonCandBxCollection> overlapMuons(new RegionalMuonCandBxCollection());
0146   std::unique_ptr<RegionalMuonCandBxCollection> endcapMuons(new RegionalMuonCandBxCollection());
0147   std::unique_ptr<MuonCaloSumBxCollection> towerSums(new MuonCaloSumBxCollection());
0148 
0149   RegionalMuonCand mu;
0150   MuonCaloSum tSum;
0151   m_endOfBx = false;
0152   int caloCounter = 0;
0153   std::vector<int> bar{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
0154   std::vector<int> ovl_neg{0, 0, 0, 0, 0, 0};
0155   std::vector<int> ovl_pos{0, 0, 0, 0, 0, 0};
0156   std::vector<int> fwd_neg{0, 0, 0, 0, 0, 0};
0157   std::vector<int> fwd_pos{0, 0, 0, 0, 0, 0};
0158   while (!m_endOfBx && !m_filestream.eof()) {
0159     std::string lineID;
0160     m_filestream >> lineID;
0161     std::string restOfLine;
0162 
0163     if (lineID == "BAR" || lineID == "OVL-" || lineID == "FWD-" || lineID == "OVL+" || lineID == "FWD+") {
0164       int tmp;
0165       m_filestream >> tmp;  // cable no
0166       // if (lineID == "BAR") tmp += 12;
0167       // if (lineID == "OVL-") tmp = (tmp-6)+24;
0168       // if (lineID == "OVL+") tmp = tmp + 6;
0169       // if (lineID == "FWD-") tmp = (tmp-6)+30;
0170 
0171       // mu.setLink(tmp);
0172       m_filestream >> tmp;
0173       mu.setHwPt(tmp);
0174 
0175       m_filestream >> tmp;
0176 
0177       int globalPhi = int(tmp * 0.560856864654333f);  // correction from txt file producer!
0178       int globalWedgePhi = (globalPhi + 24) % 576;    // this sets CMS phi = 0 to -15 deg
0179       int globalSectorPhi = (globalPhi - 24);         // this sets CMS phi = 0 to +15 deg
0180       if (globalSectorPhi < 0) {
0181         globalSectorPhi += 576;
0182       }
0183 
0184       // int globalMuonPhi = int(tmp*0.560856864654333f); // make sure scale is correct
0185       bool skip = false;
0186       if (lineID == "BAR") {
0187         int processor = globalWedgePhi / 48 + 1;
0188         int localPhi = globalWedgePhi % 48;
0189         mu.setTFIdentifiers(processor, tftype::bmtf);
0190         mu.setHwPhi(localPhi);
0191         bar[processor - 1]++;
0192         if (bar[processor - 1] > 3)
0193           skip = true;
0194       }
0195       if (lineID == "OVL-") {
0196         int processor = globalSectorPhi / 96 + 1;
0197         int localPhi = globalSectorPhi % 96;
0198         mu.setTFIdentifiers(processor, tftype::omtf_neg);
0199         mu.setHwPhi(localPhi);
0200         ovl_neg[processor - 1]++;
0201         if (ovl_neg[processor - 1] > 3)
0202           skip = true;
0203       }
0204       if (lineID == "OVL+") {
0205         int processor = globalSectorPhi / 96 + 1;
0206         int localPhi = globalSectorPhi % 96;
0207         mu.setTFIdentifiers(processor, tftype::omtf_pos);
0208         mu.setHwPhi(localPhi);
0209         ovl_pos[processor - 1]++;
0210         if (ovl_pos[processor - 1] > 3)
0211           skip = true;
0212       }
0213       if (lineID == "FWD-") {
0214         int processor = globalSectorPhi / 96 + 1;
0215         int localPhi = globalSectorPhi % 96;
0216         mu.setTFIdentifiers(processor, tftype::emtf_neg);
0217         mu.setHwPhi(localPhi);
0218         fwd_neg[processor - 1]++;
0219         if (fwd_neg[processor - 1] > 3)
0220           skip = true;
0221       }
0222       if (lineID == "FWD+") {
0223         int processor = globalSectorPhi / 96 + 1;
0224         int localPhi = globalSectorPhi % 96;
0225         mu.setTFIdentifiers(processor, tftype::emtf_pos);
0226         mu.setHwPhi(localPhi);
0227         fwd_pos[processor - 1]++;
0228         if (fwd_pos[processor - 1] > 3)
0229           skip = true;
0230       }
0231 
0232       m_filestream >> tmp;
0233       tmp = int(tmp * 0.9090909090f);
0234       mu.setHwEta(tmp);
0235 
0236       m_filestream >> tmp;
0237       mu.setHwSign(tmp);
0238 
0239       m_filestream >> tmp;
0240       mu.setHwSignValid(tmp);
0241 
0242       m_filestream >> tmp;
0243       mu.setHwQual(tmp);
0244 
0245       if (lineID == "BAR")
0246         m_currType = 0;
0247       if (lineID == "OVL-")
0248         m_currType = 1;
0249       if (lineID == "OVL+")
0250         m_currType = 2;
0251       if (lineID == "FWD-")
0252         m_currType = 3;
0253       if (lineID == "FWD+")
0254         m_currType = 4;
0255 
0256       if (m_currType == 0 && !skip)
0257         barrelMuons->push_back(0, mu);
0258       if ((m_currType == 1 || m_currType == 2) && !skip)
0259         overlapMuons->push_back(0, mu);
0260       if ((m_currType == 3 || m_currType == 4) && !skip)
0261         endcapMuons->push_back(0, mu);
0262     }
0263 
0264     if (lineID == "EVT" && m_currEvt != 0) {
0265       m_endOfBx = true;
0266     } else if (lineID == "EVT") {
0267       m_currEvt++;
0268     }
0269 
0270     if (lineID == "CALO") {
0271       for (int i = 0; i < 28; ++i) {
0272         int ieta = i;  //caloCounter%28;
0273         int iphi = caloCounter;
0274         int et;
0275 
0276         m_filestream >> et;
0277         tSum.setEtBits(et);
0278         tSum.setEtaBits(ieta);
0279         tSum.setPhiBits(iphi);
0280         tSum.setIndex(caloCounter * 28 + i);
0281         towerSums->push_back(0, tSum);
0282       }
0283       caloCounter++;
0284     }
0285     getline(m_filestream, restOfLine);
0286     //std::cout << restOfLine;
0287   }
0288 
0289   // std::sort(barrelMuons->begin(0), barrelMuons->end(0), L1TMicroGMTInputProducer::cmpProc);
0290   // std::sort(overlapMuons->begin(0), overlapMuons->end(0), L1TMicroGMTInputProducer::cmpProc);
0291   // std::sort(endcapMuons->begin(0), endcapMuons->end(0), L1TMicroGMTInputProducer::cmpProc);
0292 
0293   iEvent.put(std::move(barrelMuons), "BarrelTFMuons");
0294   iEvent.put(std::move(overlapMuons), "OverlapTFMuons");
0295   iEvent.put(std::move(endcapMuons), "ForwardTFMuons");
0296   iEvent.put(std::move(towerSums), "TriggerTowerSums");
0297   m_currEvt++;
0298 }
0299 
0300 // ------------ method called when starting to processes a run  ------------
0301 void L1TMicroGMTInputProducer::beginRun(const edm::Run&, edm::EventSetup const&) {}
0302 
0303 // ------------ method called when ending the processing of a run  ------------
0304 void L1TMicroGMTInputProducer::endRun(const edm::Run&, edm::EventSetup const&) {}
0305 
0306 // ------------ method called when starting to processes a luminosity block  ------------
0307 void L1TMicroGMTInputProducer::beginLuminosityBlock(const edm::LuminosityBlock&, edm::EventSetup const&) {}
0308 
0309 // ------------ method called when ending the processing of a luminosity block  ------------
0310 void L1TMicroGMTInputProducer::endLuminosityBlock(const edm::LuminosityBlock&, edm::EventSetup const&) {}
0311 
0312 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0313 void L1TMicroGMTInputProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0314   //The following says we do not know what parameters are allowed so do no validation
0315   // Please change this to state exactly what you do use, even if it is no parameters
0316   edm::ParameterSetDescription desc;
0317   desc.setUnknown();
0318   descriptions.addDefault(desc);
0319 }
0320 
0321 //define this as a plug-in
0322 DEFINE_FWK_MODULE(L1TMicroGMTInputProducer);