CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/L1Trigger/TextToDigi/plugins/RctInputTextToDigi.cc

Go to the documentation of this file.
00001 #include "RctInputTextToDigi.h"
00002 
00003 //
00004 // constructors and destructor
00005 //
00006 
00007 RctInputTextToDigi::RctInputTextToDigi(const edm::ParameterSet& iConfig) :
00008   inputFile_(iConfig.getParameter<edm::FileInPath>("inputFile")),
00009   inputStream_(inputFile_.fullPath().c_str()),
00010   nEvent_(0),
00011   oldVersion_(false),
00012   lookupTables_(new L1RCTLookupTables)
00013 {
00014   //register your products
00015   /* Examples
00016      produces<ExampleData2>();
00017      
00018      //if do put with a label
00019      produces<ExampleData2>("label");
00020   */
00021   
00022   produces<EcalTrigPrimDigiCollection>();
00023   produces<HcalTrigPrimDigiCollection>();
00024 
00025   //now do what ever other initialization is needed
00026 
00027   if ((!inputStream_.is_open())||(!inputStream_))
00028     {
00029       // not good!!
00030       std::cerr << "Input file didn't open!!" << std::endl;
00031     }
00032   //if (inputStream_.eof()) {std::cout << "Real zeroth eof! " << std::endl;}
00033 
00034 }
00035 
00036 
00037 RctInputTextToDigi::~RctInputTextToDigi()
00038 {
00039  
00040    // do anything here that needs to be done at desctruction time
00041    // (e.g. close files, deallocate resources etc.)
00042 
00043   inputStream_.close();
00044 
00045 }
00046 
00047 
00048 //
00049 // member functions
00050 //
00051 
00052 // ------------ method called to produce the data  ------------
00053 void
00054 RctInputTextToDigi::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00055 {
00056   using namespace edm;
00057 
00058   //std::cout << std::endl << std::endl << "Event number " << nEvent_ << std::endl;
00059 
00060   // This next section taken directly from 
00061   // L1Trigger/RegionalCaloTrigger/plugins/L1RCTProducer.cc rev. 1.6
00062   // Refresh configuration information every event
00063   // Hopefully doesn't take too much time
00064   ESHandle<L1RCTParameters> rctParameters;
00065   iSetup.get<L1RCTParametersRcd>().get(rctParameters);
00066   const L1RCTParameters* r = rctParameters.product();
00067   lookupTables_->setRCTParameters(r);
00068 
00069   std::auto_ptr<EcalTrigPrimDigiCollection>
00070     ecalTPs(new EcalTrigPrimDigiCollection());
00071   std::auto_ptr<HcalTrigPrimDigiCollection> 
00072     hcalTPs(new HcalTrigPrimDigiCollection());
00073   ecalTPs->reserve(56*72); 
00074   hcalTPs->reserve(56*72+18*8);  // includes HF
00075   const int nEcalSamples = 1;   // we only use 1 sample for each
00076   const int nHcalSamples = 1;
00077   
00078   int fileEventNumber; 
00079   
00080   // check to see if need to skip file header and do so before
00081   // looping through entire event
00082   
00083   std::string junk;
00084   //bool old_version = false;
00085   if (nEvent_ == 0)
00086     {
00087       //std::string junk;
00088       unsigned short junk_counter = 0;
00089       //bool old_version = false;
00090       do
00091         {
00092           if(inputStream_ >> junk) {/*std::cout << "Good: ";*/}
00093           //std::cout << "header junk was input: \"" << junk << "\"."
00094           //                 << std::endl;
00095           // for oldest version, which is same as newest version
00096           //      if((junk_counter == 11) && (junk.compare("0-32") == 0))
00097           //        {
00098           //          oldVersion_ = true;
00099           //        }
00100           if((junk_counter == 11) && (junk.compare("1-32") == 0))
00101             {
00102               oldVersion_ = true;
00103             }
00104           junk_counter++;
00105         }
00106       while (junk.compare("LUTOut") != 0);
00107       std::cout << "Skipped file header" << std::endl;
00108       if (oldVersion_) {std::cout << "oldVersion_ TRUE (tower 1-32)" << std::endl;}
00109       else {std::cout << "oldVersion_ FALSE (tower 0-31)" << std::endl;}
00110     }
00111   
00112   // can't actually read in phi and eta, file has crate card tower instead
00113   // do a while loop for event number instead??  dunno
00114   for (int i = 0; i < 72; i++)
00115     {
00116       // negative eta, iEta -28 to -1
00117       for (int j = 0; j < 56; j++)
00118         {
00119           // calc ieta, iphi coords of tower 
00120           // ieta -28 to -1 or 1 to 28, iphi 1 to 72
00121           // methods in CondFormats/L1TObjects/src/L1RCTParameters.cc
00122           
00123           unsigned short crate;
00124           unsigned short card;
00125           unsigned short tower;
00126           unsigned eAddr;
00127           unsigned hAddr;
00128           
00129           inputStream_ >> std::hex >> fileEventNumber >> crate >> card  
00130                        >> tower
00131                        >> eAddr >> hAddr >> junk >> std::dec;
00132           
00133           if (oldVersion_)
00134             {
00135               tower = tower - 1;
00136             }
00137           int encodedEtEcal = (int) (eAddr>>1);
00138           bool fineGrainEcal = (bool) (eAddr&1);
00139           int encodedEtHcal = (int) (hAddr>>1);
00140           bool fineGrainHcal = (bool) (hAddr&1);  // mip bit
00141           
00142           //std::cout << "Eventnumber " << fileEventNumber << "\tCrate " 
00143           //    << crate << "\tCard " << card << "\tTower " 
00144           //    << tower << " \teAddr " << eAddr <<"\thAddr "
00145           //    << hAddr << "\tjunk " << junk << std::endl;
00146           
00147           int iEta = lookupTables_->rctParameters()->calcIEta(crate,card,tower);
00148           int iPhi = lookupTables_->rctParameters()->calcIPhi(crate,card,tower);
00149           // transform rct iphi coords into global coords
00150           iPhi = ((72 + 18 - iPhi) % 72);
00151           if (iPhi == 0) {iPhi = 72;}
00152           unsigned absIeta = abs(iEta);
00153           int zSide = (iEta/absIeta);
00154           
00155           /*std::cout << "iEta " << iEta << "\tabsiEta " << absIeta 
00156             << "\tiPhi " << iPhi << "\tzSide " 
00157             << zSide << std::endl;
00158           */
00159           
00160           // args to detid are zside, type of tower, absieta, iphi
00161           // absieta and iphi must be between 1 and 127 inclusive
00162 
00163           EcalTriggerPrimitiveDigi 
00164             ecalDigi(EcalTrigTowerDetId(zSide, EcalTriggerTower, absIeta,
00165                                         iPhi));
00166           ecalDigi.setSize(nEcalSamples);
00167           
00168           // last arg is 3-bit trigger tower flag, which we don't use
00169           // we only use 8-bit encoded et and 1-bit fg
00170           ecalDigi.setSample(0, EcalTriggerPrimitiveSample(encodedEtEcal, 
00171                                                            fineGrainEcal, 0));
00172           //std::cout << ecalDigi << std::endl;
00173           ecalTPs->push_back(ecalDigi);
00174           
00175           HcalTriggerPrimitiveDigi
00176             hcalDigi(HcalTrigTowerDetId(iEta, iPhi));
00177           
00178           hcalDigi.setSize(nHcalSamples);
00179           
00180           // last two arg's are slb and slb channel, which we don't need
00181           hcalDigi.setSample(0, HcalTriggerPrimitiveSample(encodedEtHcal,
00182                                                            fineGrainHcal,
00183                                                            0, 0));
00184           //std::cout << hcalDigi << std::endl;
00185           hcalTPs->push_back(hcalDigi);
00186         }
00187       
00188       // also need to push_back HF digis!  
00189       // file input doesn't include HF, so need empty digis
00190       for (int i = 0; i < 18; i++)
00191         {
00192           for (int j = 0; j < 8; j++)
00193             {
00194               // HF ieta: +- 29 through 32.  HF iphi: 1,5,9,13,etc.
00195               int hfIEta = (j%4)+29;
00196               if (i < 9)
00197                 {
00198                   hfIEta = hfIEta*(-1);
00199                 }
00200               // iphi shift not implemented, but not necessary here --
00201               // everything's filled with zeros so it's symmetric anyhow
00202               int hfIPhi = (i%9)*8 + (j/4)*4 + 1;
00203               
00204               HcalTriggerPrimitiveDigi
00205                 hfDigi(HcalTrigTowerDetId(hfIEta, hfIPhi));
00206               hfDigi.setSize(1);
00207               hfDigi.setSample(0, HcalTriggerPrimitiveSample(0,0,0,0));
00208               hcalTPs->push_back(hfDigi);
00209             }
00210         }
00211     }
00212   iEvent.put(ecalTPs);
00213   iEvent.put(hcalTPs);
00214   
00215   nEvent_++;
00216   //std::cout << "Produce done" << std::endl;
00217 }
00218 
00219 // ------------ method called once each job just before starting event loop  ------------
00220 void 
00221 RctInputTextToDigi::beginJob() 
00222 {
00223   // open input file to read all events
00224   //inputStream_.open(inputFile_.fullPath().c_str());
00225   //std::cout << "beginJob entered" << std::endl;
00226 }
00227 
00228 // ------------ method called once each job just after ending the event loop  ------------
00229 void 
00230 RctInputTextToDigi::endJob() 
00231 {
00232   // close input file
00233   //inputStream_.close();
00234 }
00235 
00236 //define this as a plug-in
00237 DEFINE_FWK_MODULE(RctInputTextToDigi);