Go to the documentation of this file.00001
00013 #include <FWCore/Framework/interface/EDAnalyzer.h>
00014 #include <FWCore/Framework/interface/Event.h>
00015 #include <FWCore/Framework/interface/MakerMacros.h>
00016 #include <FWCore/Framework/interface/ESHandle.h>
00017 #include <FWCore/MessageLogger/interface/MessageLogger.h>
00018
00019 #include "CaloOnlineTools/EcalTools/plugins/EcalDigiDisplay.h"
00020 #include "CaloOnlineTools/EcalTools/interface/EcalFedMap.h"
00021 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
00022 #include "DataFormats/EcalDetId/interface/EcalDetIdCollections.h"
00023 #include "DataFormats/EcalRawData/interface/EcalRawDataCollections.h"
00024 #include "DataFormats/EcalRawData/interface/EcalDCCHeaderBlock.h"
00025
00026 #include "DataFormats/EcalDigi/interface/EcalTriggerPrimitiveDigi.h"
00027 #include "DataFormats/EcalDigi/interface/EcalTriggerPrimitiveSample.h"
00028
00029 #include <iostream>
00030 #include <vector>
00031 #include <set>
00032 #include <map>
00033
00034
00035 EcalDigiDisplay::EcalDigiDisplay(const edm::ParameterSet& ps) {
00036
00037
00038 ebDigiCollection_ = ps.getParameter<std::string>("ebDigiCollection");
00039 eeDigiCollection_ = ps.getParameter<std::string>("eeDigiCollection");
00040 digiProducer_ = ps.getParameter<std::string>("digiProducer");
00041
00042 requestedFeds_ = ps.getUntrackedParameter<std::vector<int> >("requestedFeds");
00043 requestedEbs_ = ps.getUntrackedParameter<std::vector<std::string> >("requestedEbs");
00044
00045 cryDigi = ps.getUntrackedParameter<bool>("cryDigi");
00046 ttDigi = ps.getUntrackedParameter<bool>("ttDigi");
00047 pnDigi = ps.getUntrackedParameter<bool>("pnDigi");
00048
00049 mode = ps.getUntrackedParameter<int>("mode");
00050 listChannels = ps.getUntrackedParameter<std::vector<int> >("listChannels");
00051 listTowers = ps.getUntrackedParameter<std::vector<int> >("listTowers");
00052 listPns = ps.getUntrackedParameter<std::vector<int> >("listPns");
00053
00054 std::vector<int> listDefaults;
00055 listDefaults.push_back(-1);
00056 requestedFeds_ = ps.getUntrackedParameter<std::vector<int> >("requestedFeds",listDefaults);
00057 bool fedIsGiven = false;
00058
00059 std::vector<std::string> ebDefaults;
00060 ebDefaults.push_back("none");
00061 requestedEbs_ = ps.getUntrackedParameter<std::vector<std::string> >("requestedEbs",ebDefaults);
00062 bool ebIsGiven = false;
00063
00064 if ( requestedFeds_[0] != -1 ) {
00065 edm::LogInfo("EcalDigiDisplay") << "FED id is given! Goining to beginRun! ";
00066 fedIsGiven = true;
00067 }else {
00068 if ( requestedEbs_[0] !="none" ) {
00069 ebIsGiven = true;
00070
00071 requestedFeds_.clear();
00072 fedMap = new EcalFedMap();
00073 for (std::vector<std::string>::const_iterator ebItr = requestedEbs_.begin();
00074 ebItr!= requestedEbs_.end(); ++ebItr) {
00075 requestedFeds_.push_back(fedMap->getFedFromSlice(*ebItr));
00076 }
00077 delete fedMap;
00078 } else {
00079
00080 for ( int i=601; i<655; ++i){
00081 requestedFeds_.push_back(i);
00082 }
00083 }
00084 }
00085
00086
00087 listChannels = ps.getUntrackedParameter<std::vector<int> >("listChannels",listDefaults);
00088
00089 listTowers = ps.getUntrackedParameter<std::vector<int> >("listTowers", listDefaults);
00090
00091
00092 std::vector<int>::iterator fedIter;
00093 std::vector<int>::iterator intIter;
00094 inputIsOk = true;
00095
00096 if ( fedIsGiven ) {
00097 for ( fedIter = requestedFeds_.begin(); fedIter!=requestedFeds_.end(); ++fedIter) {
00098 if ( (*fedIter) < 601 || (*fedIter) > 655 ) {
00099 edm::LogError("EcalDigiDisplay") << " FED value: " << (*fedIter) << " found in requetsedFeds. "
00100 << " Valid range is 601-654. Returning.";
00101 inputIsOk = false;
00102 return;
00103 }
00104 }
00105 }
00106 bool barrelSM = false;
00107
00108 for (fedIter = requestedFeds_.begin(); fedIter!=requestedFeds_.end(); ++fedIter) {
00109 if ( (*fedIter) > 609 && (*fedIter) < 646 && inputIsOk )
00110 barrelSM = true;
00111 }
00112
00113 if ( barrelSM ) {
00114 if ( cryDigi ) {
00115
00116 for (intIter = listChannels.begin(); intIter != listChannels.end(); intIter++) {
00117 if ( ((*intIter) < 1) || (1700 < (*intIter)) ) {
00118 edm::LogError("EcalDigiDisplay") << " ic value: " << (*intIter) << " found in listChannels. "
00119 << " Valid range is 1-1700. Returning.";
00120 inputIsOk = false;
00121 return;
00122 }
00123 }
00124 }
00125
00126 if ( ttDigi ) {
00127 for (intIter = listTowers.begin(); intIter != listTowers.end(); intIter++) {
00128
00129 if ( ((*intIter) < 1) || (70 < (*intIter)) ) {
00130 edm::LogError("EcalDigiDisplay") << " TT value: " << (*intIter) << " found in listTowers. "
00131 << " Valid range for EB SM is 1-70. Returning.";
00132 inputIsOk = false;
00133 return;
00134 }
00135 }
00136 }
00137 }else
00138 if (ttDigi) {
00139
00140 for (intIter = listTowers.begin(); intIter != listTowers.end(); intIter++) {
00141 if ( (*intIter) > 34 ) {
00142 edm::LogError("EcalDigiDisplay") << " TT value: " << (*intIter) << " found in listTowers. "
00143 << " Valid range for EE DCC is 1-34. Returning.";
00144 inputIsOk = false;
00145 return;
00146 }
00147 }
00148 }
00149
00150
00151 listPns = ps.getUntrackedParameter<std::vector<int> >("listPns",listDefaults);
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161 if ( pnDigi ) {
00162 for (intIter = listPns.begin(); intIter != listPns.end(); intIter++) {
00163 if ( ((*intIter) < 1) || (10 < (*intIter)) ) {
00164 edm::LogError("EcalDigiDisplay") << " Pn number : " << (*intIter) << " found in listPns. "
00165 << " Valid range is 1-10. Returning.";
00166 inputIsOk = false;
00167 return;
00168 }
00169 }
00170 }
00171 }
00172
00173 EcalDigiDisplay::~EcalDigiDisplay() {
00174
00175
00176 }
00177
00178
00179 void EcalDigiDisplay::beginRun(edm::Run const &, edm::EventSetup const& c) {
00180
00181 edm::LogInfo("EcalDigiDisplay") << "entering beginRun! ";
00182
00183 edm::ESHandle<EcalElectronicsMapping> elecHandle;
00184 c.get<EcalMappingRcd>().get(elecHandle);
00185 ecalElectronicsMap_ = elecHandle.product();
00186 }
00187
00188
00189 void EcalDigiDisplay::analyze( edm::Event const & e, edm::EventSetup const & c) {
00190
00191
00192 if (!inputIsOk) return;
00193
00194
00195 edm::Handle<EcalRawDataCollection> dccHeader;
00196 try {
00197 e.getByLabel(digiProducer_,dccHeader);
00198 } catch (cms::Exception& ex) {
00199 edm::LogError("EcalDigiUnpackerModule") << "Can't get DCC Headers!";
00200 }
00201
00202
00203 bool ebDigisFound = false;
00204 bool eeDigisFound = false;
00205 bool pnDigisFound = false;
00206
00207 edm::Handle<EBDigiCollection> eb_digis;
00208 try {
00209 e.getByLabel(digiProducer_,ebDigiCollection_, eb_digis);
00210 if ( eb_digis->size() != 0 )
00211 ebDigisFound = true;
00212 } catch (cms::Exception& ex) {
00213 edm::LogError("EcalDigiUnpackerModule") << "EB Digis were not found!";
00214 }
00215
00216
00217 edm::Handle<EEDigiCollection> ee_digis;
00218 try {
00219 e.getByLabel(digiProducer_,eeDigiCollection_, ee_digis);
00220 if ( ee_digis->size() != 0 )
00221 eeDigisFound = true;
00222 } catch (cms::Exception& ex) {
00223 edm::LogError("EcalDigiUnpackerModule") << "EE Digis were not found!";
00224 }
00225
00226
00227 edm::Handle<EcalPnDiodeDigiCollection> pn_digis;
00228 try {
00229 e.getByLabel(digiProducer_, pn_digis);
00230 if ( pn_digis->size() != 0)
00231 pnDigisFound = true;
00232 } catch (cms::Exception& ex) {
00233 edm::LogError("EcalDigiUnpackerModule") << "PNs were not found!";
00234 }
00235
00236
00237
00238
00239 if ( cryDigi || ttDigi ) {
00240 if ( ebDigisFound )
00241 readEBDigis(eb_digis, mode);
00242 if ( eeDigisFound )
00243 readEEDigis(ee_digis, mode);
00244 if ( !(ebDigisFound || eeDigisFound) ) {
00245 edm::LogWarning("EcalDigiUnpackerModule") << "No Digis were found! Returning..";
00246 return;
00247 }
00248 }
00249 if ( pnDigi ) {
00250 if (pnDigisFound )
00251 readPNDigis(pn_digis, mode);
00252 }
00253 }
00254
00256
00258
00259 void EcalDigiDisplay::readEBDigis (edm::Handle<EBDigiCollection> digis, int Mode) {
00260
00261 for ( EBDigiCollection::const_iterator digiItr= digis->begin();digiItr != digis->end();
00262 ++digiItr ) {
00263
00264 EBDetId detId = EBDetId((*digiItr).id());
00265 EcalElectronicsId elecId = ecalElectronicsMap_->getElectronicsId(detId);
00266
00267 int FEDid = elecId.dccId() + 600;
00268 std::vector<int>::iterator fedIter = find(requestedFeds_.begin(), requestedFeds_.end(), FEDid);
00269 if (fedIter == requestedFeds_.end()) continue;
00270
00271 int ic = EBDetId((*digiItr).id()).ic();
00272 int tt = EBDetId((*digiItr).id()).tower().iTT();
00273
00274
00275 if ( Mode ==1 ) {
00276 edm::LogInfo("EcalDigiDisplay") << "\n\n^^^^^^^^^^^^^^^^^^ [EcalDigiDisplay] digi cry collection size " << digis->size();
00277 edm::LogInfo("EcalDigiDisplay") << " [EcalDigiDisplay] dumping first " << listChannels[0] << " crystals\n";
00278
00279 if( ic > listChannels[0]) continue;
00280 } else if ( Mode==2 ) {
00281
00282 std::vector<int>::iterator icIterCh;
00283 std::vector<int>::iterator icIterTt;
00284 icIterCh = find(listChannels.begin(), listChannels.end(), ic);
00285 icIterTt = find(listTowers.begin(), listTowers.end(), tt);
00286 if (icIterCh == listChannels.end() && icIterTt == listTowers.end() ) continue;
00287 edm::LogInfo("EcalDigiDisplay") << "\n\n^^^^^^^^^^^^^^^^^^ [EcalDigiDisplay] digi cry collection size " << digis->size();
00288 } else {
00289 edm::LogInfo("EcalDigiDisplay") << "[EcalDigiDisplay] parameter mode set to: " << Mode
00290 << ". Only mode 1 and 2 are allowed. Returning...";
00291 inputIsOk = false;
00292 return;
00293 }
00294 std::cout << "FEDID: " << FEDid << std::endl;
00295 std::cout << "Tower: " << EBDetId((*digiItr).id()).tower().iTT()
00296 <<" ic-cry: "
00297 << EBDetId((*digiItr).id()).ic() << " i-phi: "
00298 << EBDetId((*digiItr).id()).iphi() << " j-eta: "
00299 << EBDetId((*digiItr).id()).ieta() << std::endl;
00300
00301 for ( unsigned int i=0; i< (*digiItr).size() ; ++i ) {
00302 EBDataFrame df( *digiItr );
00303 if (!(i%3) ) std::cout << "\n\t";
00304 std::cout << "sId: " << (i+1) << " " << df.sample(i) << "\t";
00305 }
00306 std::cout << " " << std::endl;
00307 }
00308 }
00309
00310
00311 void EcalDigiDisplay::readEEDigis (edm::Handle<EEDigiCollection> digis, int Mode) {
00312
00313
00314 if ( Mode!=2 ) {
00315 std::cout << "For Endcap mode needs to be set to 2" << std::endl;
00316 return;
00317 }
00318
00319 for ( EEDigiCollection::const_iterator digiItr= digis->begin();digiItr != digis->end();
00320 ++digiItr ) {
00321
00322
00323 EEDetId detId = EEDetId((*digiItr).id());
00324 EcalElectronicsId elecId = ecalElectronicsMap_->getElectronicsId(detId);
00325
00326 int FEDid = elecId.dccId() + 600;
00327 std::vector<int>::iterator fedIter = find(requestedFeds_.begin(), requestedFeds_.end(), FEDid);
00328 if (fedIter == requestedFeds_.end()) continue;
00329
00330 edm::LogInfo("EcalDigiDisplay") << "\n\n^^^^^^^^^^^^^^^^^^ [EcalDigiDisplay] digi cry collection size " << digis->size();
00331
00332 int crystalId = 10000 * FEDid + 100 * elecId.towerId() + 5 * (elecId.stripId()-1)+elecId.xtalId();
00333 int chId = elecId.towerId();
00334
00335 std::vector<int>::iterator icIterCh;
00336 std::vector<int>::iterator icIterTt;
00337 icIterCh = find(listChannels.begin(), listChannels.end(), crystalId);
00338 icIterTt = find(listTowers.begin(), listTowers.end(), chId);
00339 if ( icIterCh == listChannels.end() && icIterTt == listTowers.end() ) continue;
00340
00341 std::cout << "FEDID: " << FEDid << std::endl;
00342 std::cout << "Tower: " << elecId.towerId()
00343 << "crystalId: "
00344 << crystalId << " i-x: "
00345 << EEDetId((*digiItr).id()).ix() << " j-y: "
00346 << EEDetId((*digiItr).id()).iy() << std::endl;
00347
00348
00349 for ( unsigned int i=0; i< (*digiItr).size() ; ++i ) {
00350 EEDataFrame df( *digiItr );
00351 if (!(i%3) ) std::cout << "\n\t";
00352 std::cout << "sId: " << (i+1) << " " << df.sample(i) << "\t";
00353 }
00354 std::cout << " " << std::endl;
00355 }
00356 }
00357
00358 void EcalDigiDisplay::readPNDigis(edm::Handle<EcalPnDiodeDigiCollection> PNs, int Mode) {
00359
00360 int pnDigiCounter = 0;
00361
00362
00363 for ( EcalPnDiodeDigiCollection::const_iterator pnItr = PNs->begin(); pnItr != PNs->end(); ++pnItr ) {
00364 EcalPnDiodeDetId pnDetId = EcalPnDiodeDetId((*pnItr).id());
00365
00366 int FEDid = pnDetId.iDCCId() + 600;
00367 std::vector<int>::iterator fedIter = find(requestedFeds_.begin(), requestedFeds_.end(), FEDid);
00368 if (fedIter == requestedFeds_.end()) continue;
00369 int pnNum = (*pnItr).id().iPnId();
00370
00371 if ( Mode == 1) {
00372 edm::LogInfo("EcalDigiDisplay") << "\n\n^^^^^^^^^^^^^^^^^^ EcalDigiDisplay digi PN collection. Size: " << PNs->size();
00373 edm::LogInfo("EcalDigiDisplay") << " [EcalDigiDisplay] dumping first " << listPns[0] << " PNs ";
00374
00375 if ( (pnDigiCounter++) >= listPns[0] ) break;
00376 } else if ( Mode == 2) {
00377 edm::LogInfo("EcalDigiDisplay") << "\n\n^^^^^^^^^^^^^^^^^^ EcalDigiDisplay digi PN collection. Size: " << PNs->size();
00378
00379
00380 std::vector<int>::iterator pnIter;
00381 pnIter = find(listPns.begin(), listPns.end(), pnNum);
00382 if (pnIter == listPns.end()) continue;
00383 } else {
00384 edm::LogError("EcalDigiDisplay")<< "[EcalDigiDisplay] parameter mode set to: " << Mode
00385 << ". Only mode 1 and 2 are allowed. Returning...";
00386 inputIsOk = false;
00387 return;
00388 }
00389
00390 std::cout << "DCCID: " << pnDetId.iDCCId() << std::endl;
00391 std::cout << "\nPN num: " << (*pnItr).id().iPnId();
00392 for ( int samId=0; samId < (*pnItr).size() ; samId++ ) {
00393 if (!(samId%3) ) std::cout << "\n\t";
00394 std::cout << "sId: " << (samId+1) << " "
00395 << (*pnItr).sample(samId)
00396 << "\t";
00397 }
00398 }
00399 }
00400
00401
00402 void EcalDigiDisplay::endJob() {
00403
00404 edm::LogInfo("EcalDigiDisplay") << "DONE!.... " ;
00405 }
00406
00407