Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:21:42

0001 #include "RctInputTextToDigi.h"
0002 
0003 //
0004 // constructors and destructor
0005 //
0006 
0007 RctInputTextToDigi::RctInputTextToDigi(const edm::ParameterSet &iConfig)
0008     : inputFile_(iConfig.getParameter<edm::FileInPath>("inputFile")),
0009       inputStream_(inputFile_.fullPath().c_str()),
0010       lookupTables_(new L1RCTLookupTables),
0011       paramsToken_(esConsumes()),
0012       nEvent_(0),
0013       oldVersion_(false) {
0014   // register your products
0015   /* Examples
0016      produces<ExampleData2>();
0017 
0018      //if do put with a label
0019      produces<ExampleData2>("label");
0020   */
0021 
0022   produces<EcalTrigPrimDigiCollection>();
0023   produces<HcalTrigPrimDigiCollection>();
0024 
0025   // now do what ever other initialization is needed
0026 
0027   if ((!inputStream_.is_open()) || (!inputStream_)) {
0028     // not good!!
0029     std::cerr << "Input file didn't open!!" << std::endl;
0030   }
0031   // if (inputStream_.eof()) {std::cout << "Real zeroth eof! " << std::endl;}
0032 }
0033 
0034 RctInputTextToDigi::~RctInputTextToDigi() {
0035   // do anything here that needs to be done at desctruction time
0036   // (e.g. close files, deallocate resources etc.)
0037 
0038   inputStream_.close();
0039 }
0040 
0041 //
0042 // member functions
0043 //
0044 
0045 // ------------ method called to produce the data  ------------
0046 void RctInputTextToDigi::produce(edm::Event &iEvent, const edm::EventSetup &iSetup) {
0047   using namespace edm;
0048 
0049   // std::cout << std::endl << std::endl << "Event number " << nEvent_ <<
0050   // std::endl;
0051 
0052   // This next section taken directly from
0053   // L1Trigger/RegionalCaloTrigger/plugins/L1RCTProducer.cc rev. 1.6
0054   // Refresh configuration information every event
0055   // Hopefully doesn't take too much time
0056   const L1RCTParameters *r = &iSetup.getData(paramsToken_);
0057   lookupTables_->setRCTParameters(r);
0058 
0059   std::unique_ptr<EcalTrigPrimDigiCollection> ecalTPs(new EcalTrigPrimDigiCollection());
0060   std::unique_ptr<HcalTrigPrimDigiCollection> hcalTPs(new HcalTrigPrimDigiCollection());
0061   ecalTPs->reserve(56 * 72);
0062   hcalTPs->reserve(56 * 72 + 18 * 8);  // includes HF
0063   const int nEcalSamples = 1;          // we only use 1 sample for each
0064   const int nHcalSamples = 1;
0065 
0066   int fileEventNumber;
0067 
0068   // check to see if need to skip file header and do so before
0069   // looping through entire event
0070 
0071   std::string junk;
0072   // bool old_version = false;
0073   if (nEvent_ == 0) {
0074     // std::string junk;
0075     unsigned short junk_counter = 0;
0076     // bool old_version = false;
0077     do {
0078       if (inputStream_ >> junk) { /*std::cout << "Good: ";*/
0079       }
0080       // std::cout << "header junk was input: \"" << junk << "\"."
0081       //             << std::endl;
0082       // for oldest version, which is same as newest version
0083       //      if((junk_counter == 11) && (junk.compare("0-32") == 0))
0084       //        {
0085       //          oldVersion_ = true;
0086       //        }
0087       if ((junk_counter == 11) && (junk == "1-32")) {
0088         oldVersion_ = true;
0089       }
0090       junk_counter++;
0091     } while (junk != "LUTOut");
0092     std::cout << "Skipped file header" << std::endl;
0093     if (oldVersion_) {
0094       std::cout << "oldVersion_ TRUE (tower 1-32)" << std::endl;
0095     } else {
0096       std::cout << "oldVersion_ FALSE (tower 0-31)" << std::endl;
0097     }
0098   }
0099 
0100   // can't actually read in phi and eta, file has crate card tower instead
0101   // do a while loop for event number instead??  dunno
0102   for (int i = 0; i < 72; i++) {
0103     // negative eta, iEta -28 to -1
0104     for (int j = 0; j < 56; j++) {
0105       // calc ieta, iphi coords of tower
0106       // ieta -28 to -1 or 1 to 28, iphi 1 to 72
0107       // methods in CondFormats/L1TObjects/src/L1RCTParameters.cc
0108 
0109       unsigned short crate;
0110       unsigned short card;
0111       unsigned short tower;
0112       unsigned eAddr;
0113       unsigned hAddr;
0114 
0115       inputStream_ >> std::hex >> fileEventNumber >> crate >> card >> tower >> eAddr >> hAddr >> junk >> std::dec;
0116 
0117       if (oldVersion_) {
0118         tower = tower - 1;
0119       }
0120       int encodedEtEcal = (int)(eAddr >> 1);
0121       bool fineGrainEcal = (bool)(eAddr & 1);
0122       int encodedEtHcal = (int)(hAddr >> 1);
0123       bool fineGrainHcal = (bool)(hAddr & 1);  // mip bit
0124 
0125       // std::cout << "Eventnumber " << fileEventNumber << "\tCrate "
0126       //    << crate << "\tCard " << card << "\tTower "
0127       //    << tower << " \teAddr " << eAddr <<"\thAddr "
0128       //    << hAddr << "\tjunk " << junk << std::endl;
0129 
0130       int iEta = lookupTables_->rctParameters()->calcIEta(crate, card, tower);
0131       int iPhi = lookupTables_->rctParameters()->calcIPhi(crate, card, tower);
0132       // transform rct iphi coords into global coords
0133       iPhi = ((72 + 18 - iPhi) % 72);
0134       if (iPhi == 0) {
0135         iPhi = 72;
0136       }
0137       unsigned absIeta = abs(iEta);
0138       int zSide = (iEta / absIeta);
0139 
0140       /*std::cout << "iEta " << iEta << "\tabsiEta " << absIeta
0141         << "\tiPhi " << iPhi << "\tzSide "
0142         << zSide << std::endl;
0143       */
0144 
0145       // args to detid are zside, type of tower, absieta, iphi
0146       // absieta and iphi must be between 1 and 127 inclusive
0147 
0148       EcalTriggerPrimitiveDigi ecalDigi(EcalTrigTowerDetId(zSide, EcalTriggerTower, absIeta, iPhi));
0149       ecalDigi.setSize(nEcalSamples);
0150 
0151       // last arg is 3-bit trigger tower flag, which we don't use
0152       // we only use 8-bit encoded et and 1-bit fg
0153       ecalDigi.setSample(0, EcalTriggerPrimitiveSample(encodedEtEcal, fineGrainEcal, 0));
0154       // std::cout << ecalDigi << std::endl;
0155       ecalTPs->push_back(ecalDigi);
0156 
0157       HcalTriggerPrimitiveDigi hcalDigi(HcalTrigTowerDetId(iEta, iPhi));
0158 
0159       hcalDigi.setSize(nHcalSamples);
0160 
0161       // last two arg's are slb and slb channel, which we don't need
0162       hcalDigi.setSample(0, HcalTriggerPrimitiveSample(encodedEtHcal, fineGrainHcal, 0, 0));
0163       // std::cout << hcalDigi << std::endl;
0164       hcalTPs->push_back(hcalDigi);
0165     }
0166 
0167     // also need to push_back HF digis!
0168     // file input doesn't include HF, so need empty digis
0169     for (int i = 0; i < 18; i++) {
0170       for (int j = 0; j < 8; j++) {
0171         // HF ieta: +- 29 through 32.  HF iphi: 1,5,9,13,etc.
0172         int hfIEta = (j % 4) + 29;
0173         if (i < 9) {
0174           hfIEta = hfIEta * (-1);
0175         }
0176         // iphi shift not implemented, but not necessary here --
0177         // everything's filled with zeros so it's symmetric anyhow
0178         int hfIPhi = (i % 9) * 8 + (j / 4) * 4 + 1;
0179 
0180         HcalTriggerPrimitiveDigi hfDigi(HcalTrigTowerDetId(hfIEta, hfIPhi));
0181         hfDigi.setSize(1);
0182         hfDigi.setSample(0, HcalTriggerPrimitiveSample(0, false, 0, 0));
0183         hcalTPs->push_back(hfDigi);
0184       }
0185     }
0186   }
0187   iEvent.put(std::move(ecalTPs));
0188   iEvent.put(std::move(hcalTPs));
0189 
0190   nEvent_++;
0191   // std::cout << "Produce done" << std::endl;
0192 }
0193 
0194 // ------------ method called once each job just before starting event loop
0195 // ------------
0196 void RctInputTextToDigi::beginJob() {
0197   // open input file to read all events
0198   // inputStream_.open(inputFile_.fullPath().c_str());
0199   // std::cout << "beginJob entered" << std::endl;
0200 }
0201 
0202 // ------------ method called once each job just after ending the event loop
0203 // ------------
0204 void RctInputTextToDigi::endJob() {
0205   // close input file
0206   // inputStream_.close();
0207 }
0208 
0209 // define this as a plug-in
0210 DEFINE_FWK_MODULE(RctInputTextToDigi);