Go to the documentation of this file.00001
00002 #include "RctDigiToRctText.h"
00003 #include <iomanip>
00004
00005 using std::setw;
00006 using std::setfill;
00007 using std::hex;
00008 using std::dec;
00009 using std::endl;
00010
00011
00012 RctDigiToRctText::RctDigiToRctText(const edm::ParameterSet& iConfig) :
00013 m_rctInputLabel(iConfig.getParameter<edm::InputTag>("RctInputLabel")),
00014 m_textFileName(iConfig.getParameter<std::string>("TextFileName")),
00015 m_hexUpperCase(iConfig.getParameter<bool>("HexUpperCase")) {
00016
00018 for (unsigned i=0; i<NUM_RCT_CRATES; i++){
00019 std::stringstream fileStream;
00020 fileStream << m_textFileName << std::setw(2) << std::setfill('0') << i << ".txt";
00021 std::string fileName(fileStream.str());
00022 m_file[i].open(fileName.c_str(),std::ios::out);
00023
00024 if(!m_file[i].good()) {
00025 throw cms::Exception("RctDigiToRctTextTextFileOpenError")
00026 << "RctDigiToRctText::RctDigiToRctText : "
00027 << " couldn't create the file " << fileName << std::endl;
00028 }
00029 }
00030
00032 fdebug.open("rctdigitorcttext_debug.txt", std::ios::out);
00033
00034 }
00035
00036
00037 RctDigiToRctText::~RctDigiToRctText() {
00039 for (unsigned i=0; i<NUM_RCT_CRATES; i++)
00040 m_file[i].close();
00041 fdebug.close();
00042 }
00043
00044
00045 void
00046 RctDigiToRctText::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
00047
00049 static int nevt = -1;
00050 nevt++;
00051
00053 edm::Handle<L1CaloEmCollection> em;
00054 edm::Handle<L1CaloRegionCollection> rgn;
00055 iEvent.getByLabel(m_rctInputLabel, em);
00056 iEvent.getByLabel(m_rctInputLabel, rgn);
00057
00059 bool ldebug = false;
00060 bool debug_NOTEMPTY[18]={0};
00061 for(int i=0; i<18; i++) debug_NOTEMPTY[i]=false;
00062 std::stringstream dstrm;
00063
00064
00066
00067 unsigned long int CAND[18][8];
00068 int n_iso [18]={0};
00069 int n_niso[18]={0};
00070 bool iso;
00071 int id;
00072
00073 for(L1CaloEmCollection::const_iterator iem=em->begin(); iem!=em->end(); iem++){
00074
00075 int crate = iem->rctCrate();
00076 iso = iem->isolated();
00077 unsigned data = iem->raw();
00078
00079 id = iso ? n_iso[crate]++ : 4 + n_niso[crate]++;
00080
00081 CAND[crate][id] = data;
00082
00084 if(crate>17 || id > 7)
00085 throw cms::Exception("RctDigiToRctTextElectronIndexOutBounds")
00086 << "out of bounds indices crate:" << crate << "id:" << id << std::endl;
00087 if(ldebug&&data!=0)
00088 debug_NOTEMPTY[crate] = true;
00089 dstrm.str("");
00090 dstrm << "electron "
00091 << " bx:" << nevt
00092 << " crate:" << crate
00093 << " iso:" << iso
00094 << " raw:" << data
00095 << " \t cand:" << *iem;
00096 if(debug_NOTEMPTY[crate]) fdebug << dstrm.str() << std::endl;
00097 }
00098
00099
00101
00102 unsigned short MIPbits [18][7][2] = {{{0}}};
00103 unsigned short QIEbits [18][7][2] = {{{0}}};
00104 unsigned short RC [18][7][2] = {{{0}}};
00105 unsigned short RCof [18][7][2] = {{{0}}};
00106 unsigned short RCtau [18][7][2] = {{{0}}};
00107 unsigned short HF [18][4][2] = {{{0}}};
00108
00109 for (L1CaloRegionCollection::const_iterator irgn=rgn->begin(); irgn!=rgn->end(); irgn++){
00110
00111 int crate = irgn->rctCrate();
00112 int card = irgn->rctCard();
00113 int rgnidx= irgn->rctRegionIndex();
00114
00115 dstrm.str("");
00116 if (!irgn->id().isHf()){
00117 RC [crate][card][rgnidx]=irgn->et();
00118 RCof [crate][card][rgnidx]=irgn->overFlow();
00119 RCtau [crate][card][rgnidx]=irgn->tauVeto();
00120 MIPbits[crate][card][rgnidx]=irgn->mip();
00121 QIEbits[crate][card][rgnidx]=irgn->quiet();
00122
00123 dstrm << hex
00124 << "Et=" << irgn->et()
00125 << " OverFlow=" << irgn->overFlow()
00126 << " tauVeto=" << irgn->tauVeto()
00127 << " mip=" << irgn->mip()
00128 << " quiet=" << irgn->quiet()
00129 << " Card=" << irgn->rctCard()
00130 << " Region=" << irgn->rctRegionIndex()
00131 << " Crate=" << irgn->rctCrate()
00132 << dec;
00133 if(ldebug) LogDebug("Regions") << dstrm.str();
00134 } else {
00135 HF [crate][irgn->id().rctEta()-7][irgn->id().rctPhi()]=irgn->et();
00136
00137 dstrm << hex
00138 << "Et=" << irgn->et()
00139 << " FGrain=" << irgn->fineGrain()
00140 << " Eta=" << irgn->id().rctEta()
00141 << " Phi=" << irgn->id().rctPhi()
00142 << " Crate=" << irgn->rctCrate()
00143 << dec;
00144 if(ldebug) LogDebug("HFRegions") << dstrm.str();
00145 }
00146
00147
00148 if(ldebug &&irgn->et()!=0) debug_NOTEMPTY[crate] = true;
00149 if(debug_NOTEMPTY[crate]) {
00150 fdebug << "region"
00151 << " bx:" << nevt
00152 << " crate:" << crate
00153 << "\t";
00154 fdebug << dstrm.str() << std::endl;
00155 }
00156 }
00157
00158
00159 std::stringstream sstrm;
00160 if(m_hexUpperCase)
00161 sstrm << std::uppercase;
00162 else
00163 sstrm.unsetf(std::ios::uppercase);
00164
00165
00167
00168 for (unsigned crate=0; crate<NUM_RCT_CRATES; crate++){
00169
00170 sstrm.str("");
00171 sstrm << "Crossing " << nevt << std::endl;
00172
00173 for(int j=0; j<8; j++) {
00174 sstrm << setw(3) << setfill('0') << hex << (CAND[crate][j] & 0x3ff);
00175 if(j<7) sstrm << " ";
00176 }
00177 sstrm << setfill(' ') << dec;
00178 m_file[crate] << sstrm.str() << std::endl;
00179
00180
00181 if(debug_NOTEMPTY[crate]) fdebug << sstrm.str() << std::endl;
00182 if(ldebug) LogDebug("Electrons") << sstrm.str() << std::endl;
00183
00184 }
00185
00186
00188
00189 for (unsigned crate=0; crate<NUM_RCT_CRATES; crate++){
00190
00192 sstrm.str("");
00193 for (int card=0; card<7; card++){
00194 for (int j=0; j<2; j++){
00195 sstrm << " " << MIPbits[crate][card][j];
00196 }
00197 }
00198 m_file[crate] << sstrm.str() << std::endl;
00199 if(debug_NOTEMPTY[crate]) fdebug << sstrm.str() << std::endl;
00200
00202 sstrm.str("");
00203 for (int card=0; card<7; card++){
00204 for (int j=0; j<2; j++){
00205 sstrm << " " << QIEbits[crate][card][j];
00206 }
00207 }
00208 m_file[crate] << sstrm.str() << std::endl;
00209 if(debug_NOTEMPTY[crate]) fdebug << sstrm.str() << std::endl;
00210
00212 sstrm.str("");
00213 for (int card=0; card<7; card++){
00214 for (int j=0; j<2; j++){
00215 unsigned long int tmp;
00216 unsigned et = RC [crate][card][j];
00217 unsigned ovf = RCof [crate][card][j];
00218 unsigned tau = RCtau[crate][card][j];
00219
00220 tmp = ((tau & 0x1) << 11) | ((ovf &0x1)<<10) | ((et & 0x3ff));
00221 sstrm << " " << setw(3) << setfill('0') << hex << tmp;
00222
00223 }
00224 }
00225 m_file[crate] << sstrm.str() << std::endl;
00226 if(debug_NOTEMPTY[crate]) fdebug << sstrm.str() << std::endl << std::endl;
00227
00228
00230 sstrm.str("");
00231 for (int ip=0; ip<2; ip++){
00232 for (int ie=0; ie<4; ie++){
00233 unsigned et = HF[crate][ie][ip] & 0xff;
00234 sstrm << " " << setw(2) << setfill('0') << hex << et;
00235 }
00236 }
00237 m_file[crate] << sstrm.str() << std::endl;
00238 if(debug_NOTEMPTY[crate]) fdebug << sstrm.str() << std::endl;
00239 sstrm << setfill(' ') << dec;
00240
00241 }
00242
00243
00245 for (unsigned i=0; i<NUM_RCT_CRATES; i++)
00246 m_file[i] << std::flush;
00247
00248 fdebug << std::flush;
00249
00250 }