#include <SimCalorimetry/EcalElectronicsEmulation/interface/EcalFEtoDigi.h>
Public Member Functions | |
EcalFEtoDigi (const edm::ParameterSet &) | |
~EcalFEtoDigi () | |
Private Member Functions | |
virtual void | beginJob (const edm::EventSetup &) |
method called once each job just before starting event loop | |
EcalTriggerPrimitiveSample | create_TPSample (TCCinput, const edm::EventSetup &) |
create EcalTriggerPrimitiveSample from input data (line) | |
EcalTriggerPrimitiveSample | create_TPSampleTcp (TCCinput, const edm::EventSetup &) |
create EcalTriggerPrimitiveSample in tcp format (uncomrpessed energy) | |
EcalTrigTowerDetId | create_TTDetId (TCCinput) |
create EcalTrigTowerDetId from input data (line) | |
virtual void | endJob () |
method called once each job just after ending the event loop | |
void | getLUT (unsigned int *lut, const int towerId, const edm::EventSetup &) const |
return the LUT from eventSetup | |
virtual void | produce (edm::Event &, const edm::EventSetup &) |
method called to produce the data | |
void | readInput () |
open and read in input (flat) data file | |
int | SMidToTCCid (const int) const |
translate input supermodule id into TCC id (barrel) | |
Private Attributes | |
std::string | basename_ |
bool | debug_ |
int | fileEventOffset_ |
TCCInputData | inputdata_ [N_SM] |
std::ofstream | outfile |
bool | singlefile |
int | sm_ |
bool | useIdentityLUT_ |
Definition at line 36 of file EcalFEtoDigi.h.
EcalFEtoDigi::EcalFEtoDigi | ( | const edm::ParameterSet & | iConfig | ) | [explicit] |
Definition at line 7 of file EcalFEtoDigi.cc.
References basename_, debug_, fileEventOffset_, edm::ParameterSet::getUntrackedParameter(), singlefile, sm_, and useIdentityLUT_.
00007 { 00008 basename_ = iConfig.getUntrackedParameter<std::string>("FlatBaseName","ecal_tcc_"); 00009 sm_ = iConfig.getUntrackedParameter<int>("SuperModuleId",-1); 00010 fileEventOffset_ = iConfig.getUntrackedParameter<int>("FileEventOffset",0); 00011 useIdentityLUT_ = iConfig.getUntrackedParameter<bool>("UseIdentityLUT",false); 00012 debug_ = iConfig.getUntrackedParameter<bool>("debugPrintFlag", false); 00013 00014 singlefile = (sm_==-1)?false:true; 00015 00016 produces<EcalTrigPrimDigiCollection>(); 00017 produces<EcalTrigPrimDigiCollection >("formatTCP"); 00018 00019 }
EcalFEtoDigi::~EcalFEtoDigi | ( | ) | [inline] |
void EcalFEtoDigi::beginJob | ( | const edm::EventSetup & | setup | ) | [private, virtual] |
method called once each job just before starting event loop
check SM numbering convetion: 1-38 [or -1 flag to indicate all sm's are to be read in]
debug: open file for recreating input copy
Reimplemented from edm::EDProducer.
Definition at line 295 of file EcalFEtoDigi.cc.
References debug_, Exception, outfile, readInput(), and sm_.
00295 { 00296 00299 if(sm_!=-1 && sm_<1 || sm_>36) 00300 throw cms::Exception("EcalFEtoDigiInvalidDetId") 00301 << "EcalFEtoDigi: Adapt SM numbering convention.\n"; 00302 00304 if(debug_) 00305 outfile.open("inputcopy.txt"); 00306 00307 readInput(); 00308 00309 }
EcalTriggerPrimitiveSample EcalFEtoDigi::create_TPSample | ( | TCCinput | data, | |
const edm::EventSetup & | evtSetup | |||
) | [private] |
create EcalTriggerPrimitiveSample from input data (line)
setup look up table
compress energy 10 -> 8 bit
crate sample
Definition at line 237 of file EcalFEtoDigi.cc.
References create_TTDetId(), debug_, TCCinput::get_energy(), TCCinput::get_fg(), getLUT(), i, TCCinput::input, DetId::rawId(), and useIdentityLUT_.
Referenced by produce().
00237 { 00238 00239 int tower = create_TTDetId(data).rawId() ; 00240 int Et = data.get_energy(); 00241 bool tt_fg = data.get_fg(); 00242 //unsigned input = data.input; 00243 //int Et = input & 0x3ff; //get bits 0-9 00244 //bool tt_fg = input & 0x400; //get bit number 10 00245 00247 unsigned int lut_[1024] ; 00248 if(!useIdentityLUT_) 00249 getLUT(lut_, tower, evtSetup) ; 00250 else 00251 for(int i=0; i<1024; i++) lut_[i] = i ; //identity lut! 00252 00254 int lut_out = lut_[Et]; 00255 int ttFlag = (lut_out & 0x700) >> 8; 00256 int cEt = (lut_out & 0xff ); 00257 00259 if(debug_&&data.get_energy()!=0) 00260 printf("[EcalFEtoDigi] Creating sample; input:0x%X (Et:0x%x) cEt:0x%x fg:%d ttflag:0x%x \n", 00261 data.input, Et, cEt, tt_fg, ttFlag); 00262 00263 EcalTriggerPrimitiveSample e_sample(cEt, tt_fg, ttFlag); 00264 00265 return e_sample; 00266 }
EcalTriggerPrimitiveSample EcalFEtoDigi::create_TPSampleTcp | ( | TCCinput | data, | |
const edm::EventSetup & | evtSetup | |||
) | [private] |
create EcalTriggerPrimitiveSample in tcp format (uncomrpessed energy)
setup look up table
Definition at line 270 of file EcalFEtoDigi.cc.
References create_TTDetId(), TCCinput::get_energy(), TCCinput::get_fg(), getLUT(), i, DetId::rawId(), and useIdentityLUT_.
Referenced by produce().
00270 { 00271 00272 int tower = create_TTDetId(data).rawId() ; 00273 int Et = data.get_energy(); 00274 bool tt_fg = data.get_fg(); 00275 00277 unsigned int lut_[1024] ; 00278 if(!useIdentityLUT_) 00279 getLUT(lut_, tower, evtSetup) ; 00280 else 00281 for(int i=0; i<1024; i++) lut_[i] = i ; //identity lut! 00282 00283 int lut_out = lut_[Et]; 00284 int ttFlag = (lut_out & 0x700) >> 8; 00285 int tcpdata = ((ttFlag&0x7)<<11) | ((tt_fg & 0x1)<<10) | (Et & 0x3ff) ; 00286 00287 EcalTriggerPrimitiveSample e_sample(tcpdata); 00288 00289 return e_sample; 00290 }
EcalTrigTowerDetId EcalFEtoDigi::create_TTDetId | ( | TCCinput | data | ) | [private] |
create EcalTrigTowerDetId from input data (line)
construct the EcalTrigTowerDetId object
Definition at line 203 of file EcalFEtoDigi.cc.
References debug_, EcalBarrel, TCCinput::get_energy(), sm_, and TCCinput::tower.
Referenced by create_TPSample(), create_TPSampleTcp(), and produce().
00203 { 00204 00205 // (EcalBarrel only) 00206 static const int kTowersInPhi = 4; 00207 00208 int iTT = data.tower; 00209 int zside = (sm_>18)?-1:+1; 00210 int SMid = sm_; 00211 00212 int jtower = iTT-1; 00213 int etaTT = jtower / kTowersInPhi +1; 00214 int phiTT; 00215 if (zside < 0) 00216 phiTT = (SMid-19) * kTowersInPhi + jtower % kTowersInPhi; 00217 else 00218 phiTT = (SMid- 1) * kTowersInPhi + kTowersInPhi-(jtower % kTowersInPhi)-1; 00219 00220 phiTT ++; 00221 //needed as phi=0 (iphi=1) is at middle of lower SMs (1 and 19), need shift by 2 00222 phiTT = phiTT -2; 00223 if (phiTT <= 0) phiTT = 72+phiTT; 00224 00226 if(debug_&&data.get_energy()!=0) 00227 printf("[EcalFEtoDigi] Creating EcalTrigTowerDetId (SMid,itt)=(%d,%d)->(eta,phi)=(%d,%d) \n", SMid, iTT, etaTT, phiTT); 00228 00229 EcalTrigTowerDetId 00230 e_id( zside , EcalBarrel, etaTT, phiTT, 0); 00231 00232 return e_id; 00233 }
method called once each job just after ending the event loop
Reimplemented from edm::EDProducer.
Definition at line 314 of file EcalFEtoDigi.cc.
References outfile.
void EcalFEtoDigi::getLUT | ( | unsigned int * | lut, | |
const int | towerId, | |||
const edm::EventSetup & | evtSetup | |||
) | const [private] |
return the LUT from eventSetup
Definition at line 328 of file EcalFEtoDigi.cc.
References edm::EventSetup::get(), EcalTPGGroups::getMap(), i, and edm::ESHandle< T >::product().
Referenced by create_TPSample(), and create_TPSampleTcp().
00329 { 00330 edm::ESHandle<EcalTPGLutGroup> lutGrpHandle; 00331 evtSetup.get<EcalTPGLutGroupRcd>().get( lutGrpHandle ); 00332 const EcalTPGGroups::EcalTPGGroupsMap & lutGrpMap = lutGrpHandle.product()->getMap() ; 00333 EcalTPGGroups::EcalTPGGroupsMapItr itgrp = lutGrpMap.find(towerId) ; 00334 uint32_t lutGrp = 999 ; 00335 if (itgrp != lutGrpMap.end()) lutGrp = itgrp->second ; 00336 00337 edm::ESHandle<EcalTPGLutIdMap> lutMapHandle; 00338 evtSetup.get<EcalTPGLutIdMapRcd>().get( lutMapHandle ); 00339 const EcalTPGLutIdMap::EcalTPGLutMap & lutMap = lutMapHandle.product()->getMap() ; 00340 EcalTPGLutIdMap::EcalTPGLutMapItr itLut = lutMap.find(lutGrp) ; 00341 if (itLut != lutMap.end()) { 00342 const unsigned int * theLut = (itLut->second).getLut() ; 00343 for (unsigned int i=0 ; i<1024 ; i++) lut[i] = theLut[i] ; 00344 } 00345 }
void EcalFEtoDigi::produce | ( | edm::Event & | iEvent, | |
const edm::EventSetup & | iSetup | |||
) | [private, virtual] |
method called to produce the data
event counter
re-read input (needed in case of event-by-event input production)
create EcalTrigTowerDetId
create EcalTriggerPrimitiveDigi
create EcalTriggerPrimitiveSample
set sample
add to EcalTrigPrimDigiCollection
set sample (uncompressed format)
add to EcalTrigPrimDigiCollection (uncompressed format)
print & debug
in case no info was found for the event:need to create something
Implements edm::EDProducer.
Definition at line 23 of file EcalFEtoDigi.cc.
References begin, EcalTriggerPrimitiveDigi::compressedEt(), GenMuonPlsPt100GeV_cfg::cout, create_TPSample(), create_TPSampleTcp(), create_TTDetId(), debug_, lat::endl(), fileEventOffset_, EcalTriggerPrimitiveDigi::fineGrain(), i, EcalTriggerPrimitiveDigi::id(), EcalTrigTowerDetId::ieta(), inputdata_, EcalTrigTowerDetId::iphi(), it, N_SM, outfile, edm::Event::put(), EcalTriggerPrimitiveDigi::setSample(), EcalTriggerPrimitiveDigi::setSize(), singlefile, EcalTriggerPrimitiveDigi::size(), sm_, and EcalTriggerPrimitiveDigi::ttFlag().
00024 { 00025 00027 static int current_bx = -1; 00028 current_bx++; 00029 00031 //readInput(); 00032 00033 if(debug_) 00034 std::cout << "[EcalFEtoDigi::produce] producing event " << current_bx << std::endl; 00035 00036 std::auto_ptr<EcalTrigPrimDigiCollection> 00037 e_tpdigis (new EcalTrigPrimDigiCollection); 00038 std::auto_ptr<EcalTrigPrimDigiCollection> 00039 e_tpdigisTcp (new EcalTrigPrimDigiCollection); 00040 00041 std::vector<TCCinput>::const_iterator it; 00042 00043 for(int i=0; i<N_SM; i++) { 00044 00045 if(!singlefile) 00046 sm_=i+1; 00047 00048 for(it = inputdata_[i].begin(); it != inputdata_[i].end(); it++) { 00049 00050 if(!(*it).is_current(current_bx+fileEventOffset_)) 00051 continue; 00052 else 00053 if(debug_ && (*it).input!=0 ) 00054 std::cout << "[EcalFEtoDigi] " 00055 << "\tsupermodule:" << sm_ 00056 << "\tevent: " << current_bx 00057 << "\tbx: " << (*it).bunchCrossing 00058 << "\tvalue:0x" << std::setfill('0') << std::setw(4) 00059 << std::hex << (*it).input << std::setfill(' ') << std::dec 00060 << std::endl; 00061 00062 00064 const EcalTrigTowerDetId e_id = create_TTDetId(*it); 00065 00066 //EcalElectronicsMapping theMapping; 00067 //const EcalTrigTowerDetId e_id 00068 //= theMapping.getTrigTowerDetId(SMidToTCCid(sm_),(*it).tower); 00069 //EcalElectronicsMapping::getTrigTowerDetId(int TCCid, int iTT) 00070 00072 EcalTriggerPrimitiveDigi *e_digi = new EcalTriggerPrimitiveDigi(e_id); 00073 EcalTriggerPrimitiveDigi *e_digiTcp = new EcalTriggerPrimitiveDigi(e_id); 00074 00076 EcalTriggerPrimitiveSample e_sample = create_TPSample(*it, iSetup); 00077 EcalTriggerPrimitiveSample e_sampleTcp = create_TPSampleTcp(*it, iSetup); 00078 00080 e_digi->setSize(1); //set sampleOfInterest to 0 00081 e_digi->setSample(0,e_sample); 00082 00084 e_tpdigis->push_back(*e_digi); 00085 00087 e_digiTcp->setSize(1); //set sampleOfInterest to 0 00088 e_digiTcp->setSample(0,e_sampleTcp); 00089 00091 e_tpdigisTcp->push_back(*e_digiTcp); 00092 00093 if(debug_) 00094 outfile << (*it).tower << '\t' 00095 << (*it).bunchCrossing << '\t'<< std::setfill('0') << std::hex 00096 << "0x" << std::setw(4) << (*it).input << '\t' 00097 << "0" << std::dec << std::setfill(' ') 00098 << std::endl; 00099 00101 if(debug_ && (*it).input!=0 ) 00102 std::cout << "[EcalFEtoDigi] debug id: " << e_digi->id() << "\n\t" 00103 << std::dec 00104 << "\tieta: " << e_digi->id().ieta() 00105 << "\tiphi: " << e_digi->id().iphi() 00106 << "\tsize: " << e_digi->size() 00107 << "\tfg: " <<(e_digi->fineGrain()?1:0) 00108 << std::hex 00109 << "\tEt: 0x" << e_digi->compressedEt() 00110 << " (0x" << (*it).get_energy() << ")" 00111 << "\tttflag: 0x" << e_digi->ttFlag() 00112 << std::dec 00113 << std::endl; 00114 00115 delete e_digi; 00116 delete e_digiTcp; 00117 00118 } 00119 00120 if(singlefile) 00121 break; 00122 } 00123 00125 if(e_tpdigis->size()==0) { 00126 std::cout << "[EcalFEtoDigi] creating empty collection for the event!\n"; 00127 EcalTriggerPrimitiveDigi *e_digi = new EcalTriggerPrimitiveDigi(); 00128 e_tpdigis->push_back(*e_digi); 00129 } 00130 00131 iEvent.put(e_tpdigis); 00132 iEvent.put(e_tpdigisTcp,"formatTCP"); 00133 00134 }
void EcalFEtoDigi::readInput | ( | ) | [private] |
open and read in input (flat) data file
Definition at line 139 of file EcalFEtoDigi.cc.
References prof2calltree::back, basename_, GenMuonPlsPt100GeV_cfg::cout, debug_, dummy, lat::endl(), f, fileEventOffset_, i, inputdata_, N_SM, s, singlefile, sm_, SMidToTCCid(), and tt.
Referenced by beginJob().
00139 { 00140 00141 if(debug_) 00142 std::cout << "\n[EcalFEtoDigi::readInput] Reading input data\n"; 00143 00144 if(!singlefile) 00145 sm_=-1; 00146 for(int i=0; i<N_SM; i++) 00147 inputdata_[i].clear(); 00148 00149 std::stringstream s; 00150 int tcc; 00151 00152 for (int i=0; i<N_SM; i++) { 00153 00154 tcc = (sm_==-1)?SMidToTCCid(i+1):SMidToTCCid(sm_); 00155 00156 s.str(""); 00157 s << basename_ << tcc << ".txt"; 00158 00159 std::ifstream f(s.str().c_str()); 00160 00161 if(debug_) { 00162 std::cout << " opening " << s.str().c_str() << "..." << std::endl; 00163 if(!f.good()) 00164 std::cout << " skipped!"; 00165 std::cout << std::endl; 00166 } 00167 //if (!f.good() || f.eof()) 00168 // throw cms::Exception("BadInputFile") 00169 // << "EcalFEtoDigi: cannot open file " << s.str().c_str() << std::endl; 00170 00171 int n_bx=0; 00172 int tt; int bx; unsigned val; int dummy; 00173 00174 while(f.good()) { 00175 if(f.eof()) break; 00176 tt=0; bx=-1; val=0x0; dummy=0; 00177 f >> tt >> bx >> std::hex >> val >> std::dec >> dummy; 00178 if(bx==-1 || bx < fileEventOffset_ ) continue; 00179 if( !n_bx || (bx!=(inputdata_[i].back()).bunchCrossing) ) 00180 n_bx++; 00181 TCCinput ttdata(tt,bx,val); 00182 inputdata_[i].push_back(ttdata); 00183 00184 if(debug_&&val!=0) 00185 printf("\treading tower:%d bx:%d input:0x%x dummy:%2d\n", 00186 tt, bx, val, dummy); 00187 } 00188 00189 f.close(); 00190 00191 if(sm_!=-1) 00192 break; 00193 } 00194 00195 if(debug_) 00196 std::cout << "[EcalFEtoDigi::readInput] Done reading." << std::endl; 00197 00198 return; 00199 }
int EcalFEtoDigi::SMidToTCCid | ( | const | int | ) | const [private] |
translate input supermodule id into TCC id (barrel)
Definition at line 321 of file EcalFEtoDigi.cc.
Referenced by readInput().
std::string EcalFEtoDigi::basename_ [private] |
bool EcalFEtoDigi::debug_ [private] |
Definition at line 64 of file EcalFEtoDigi.h.
Referenced by beginJob(), create_TPSample(), create_TTDetId(), EcalFEtoDigi(), produce(), and readInput().
int EcalFEtoDigi::fileEventOffset_ [private] |
Definition at line 63 of file EcalFEtoDigi.h.
Referenced by EcalFEtoDigi(), produce(), and readInput().
TCCInputData EcalFEtoDigi::inputdata_[N_SM] [private] |
std::ofstream EcalFEtoDigi::outfile [private] |
bool EcalFEtoDigi::singlefile [private] |
Definition at line 61 of file EcalFEtoDigi.h.
Referenced by EcalFEtoDigi(), produce(), and readInput().
int EcalFEtoDigi::sm_ [private] |
Definition at line 60 of file EcalFEtoDigi.h.
Referenced by beginJob(), create_TTDetId(), EcalFEtoDigi(), produce(), and readInput().
bool EcalFEtoDigi::useIdentityLUT_ [private] |
Definition at line 59 of file EcalFEtoDigi.h.
Referenced by create_TPSample(), create_TPSampleTcp(), and EcalFEtoDigi().