Go to the documentation of this file.00001
00012 #include <FWCore/Framework/interface/EDAnalyzer.h>
00013 #include <FWCore/Framework/interface/Event.h>
00014 #include <FWCore/Framework/interface/MakerMacros.h>
00015 #include <DataFormats/EcalDigi/interface/EcalDigiCollections.h>
00016 #include <DataFormats/EcalDetId/interface/EcalDetIdCollections.h>
00017
00018 #include <DataFormats/EcalDigi/interface/EcalTriggerPrimitiveDigi.h>
00019 #include <DataFormats/EcalDigi/interface/EcalTriggerPrimitiveSample.h>
00020
00021 #include "CaloOnlineTools/EcalTools/plugins/EcalPnGraphs.h"
00022 #include "CaloOnlineTools/EcalTools/interface/EcalFedMap.h"
00023
00024 #include <iostream>
00025 #include <vector>
00026 #include <map>
00027
00028 #include "TFile.h"
00029 #include "TGraph.h"
00030
00031
00032
00033 EcalPnGraphs::EcalPnGraphs(const edm::ParameterSet& ps){
00034
00035
00036 digiProducer_ = ps.getParameter<std::string>("digiProducer");
00037 fileName = ps.getUntrackedParameter<std::string >("fileName", std::string("toto") );
00038
00039 first_Pn = 0;
00040
00041 listPns = ps.getUntrackedParameter<std::vector<int> >("listPns", std::vector<int>());
00042 numPn = ps.getUntrackedParameter< int >("numPn");
00043
00044 std::vector<int> listDefaults;
00045 listDefaults.push_back(-1);
00046 feds_ = ps.getUntrackedParameter<std::vector<int> > ("requestedFeds",listDefaults);
00047 bool fedIsGiven = false;
00048
00049 std::vector<std::string> ebDefaults;
00050 ebDefaults.push_back("none");
00051 ebs_ = ps.getUntrackedParameter<std::vector<std::string> >("requestedEbs",ebDefaults);
00052 bool ebIsGiven = false;
00053
00054
00055 if ( feds_[0] != -1 ) {
00056 edm::LogInfo("EcalPnGraphs") << "FED id is given! Goining to beginJob! ";
00057 fedIsGiven = true;
00058 }else {
00059 feds_.clear();
00060 if ( ebs_[0] !="none" ) {
00061 ebIsGiven = true;
00062
00063 fedMap = new EcalFedMap();
00064 for (std::vector<std::string>::const_iterator ebItr = ebs_.begin();
00065 ebItr!= ebs_.end(); ++ebItr) {
00066 feds_.push_back(fedMap->getFedFromSlice(*ebItr));
00067 }
00068 delete fedMap;
00069 } else {
00070
00071 for ( int i=601; i<655; ++i){
00072 feds_.push_back(i);
00073 }
00074 }
00075 }
00076
00077
00078 inputIsOk = true;
00079
00080 if ( fedIsGiven ) {
00081 std::vector<int>::iterator fedIter;
00082 for (fedIter = feds_.begin(); fedIter!=feds_.end(); ++fedIter) {
00083 if ( (*fedIter) < 601 || (*fedIter) > 654) {
00084 std::cout << "[EcalPnGraphs] pn number : " << (*fedIter) << " found in listFeds. "
00085 << " Valid range is [601-654]. Returning." << std::endl;
00086 inputIsOk = false;
00087 return;
00088 }
00089 }
00090 }
00091
00092
00093 if ( listPns[0] != -1 ) {
00094 std::vector<int>::iterator intIter;
00095 for (intIter = listPns.begin(); intIter != listPns.end(); intIter++) {
00096 if ( ((*intIter) < 1) || (10 < (*intIter)) ) {
00097 std::cout << "[EcalPnGraphs] pn number : " << (*intIter) << " found in listPns. "
00098 << " Valid range is 1-10. Returning." << std::endl;
00099 inputIsOk = false;
00100 return;
00101 }
00102 if (!first_Pn ) first_Pn = (*intIter);
00103 }
00104 } else {
00105 listPns.clear();
00106 listPns.push_back(5);
00107 listPns.push_back(6);
00108 }
00109
00110
00111 for (int i=0; i<50; i++) abscissa[i] = i;
00112
00113
00114 eventCounter =0;
00115 }
00116
00117
00118
00119 EcalPnGraphs::~EcalPnGraphs(){
00120
00121
00122 }
00123
00124
00125 void EcalPnGraphs::beginJob() {
00126
00127 edm::LogInfo("EcalPhGraphs") << "entering beginJob! " ;
00128 }
00129
00130
00131 void EcalPnGraphs::analyze( const edm::Event & e, const edm::EventSetup& c){
00132
00133
00134 eventCounter++;
00135 if (!inputIsOk) return;
00136
00137 bool pnDigisFound = true;
00138
00139 edm::Handle<EcalPnDiodeDigiCollection> pn_digis;
00140 try {
00141 e.getByLabel(digiProducer_, pn_digis);
00142 pnDigisFound = true;
00143 } catch (cms::Exception& ex) {
00144 edm::LogError("EcalPnGraphs") << "PNs were not found!";
00145 }
00146
00147
00148
00149
00150 std::vector<int>::iterator pn_it;
00151 for ( pn_it = listPns.begin(); pn_it != listPns.end() ; pn_it++ )
00152 {
00153 int ipn = (*pn_it);
00154 int hpn = numPn;
00155
00156 for (int u = (-hpn) ; u<=hpn; u++){
00157 int ipn_c = ipn + u;
00158 if (ipn_c < 1 || ipn_c > 10) continue;
00159 std::vector<int>::iterator notInList = find(listAllPns.begin(), listAllPns.end(), ipn_c);
00160 if ( notInList == listAllPns.end() ) {
00161 listAllPns.push_back ( ipn_c );
00162 }
00163 }
00164 }
00165
00166
00167 for ( EcalPnDiodeDigiCollection::const_iterator pnItr = pn_digis->begin(); pnItr != pn_digis->end(); ++pnItr ) {
00168
00169 int ipn = (*pnItr).id().iPnId();
00170
00171 int ieb = EcalPnDiodeDetId((*pnItr).id()).iDCCId();
00172
00173
00174 int FEDid = ieb + 600;
00175
00176 std::vector<int>::iterator fedIter = find(feds_.begin(), feds_.end(), FEDid);
00177
00178 if ( fedIter == feds_.end() ) {
00179 edm::LogWarning("EcalPnGraphs")<< "For Event " << eventCounter << " PnDigis are not found from requested SM!. returning...";
00180 return;
00181 }
00182
00183 std::vector<int>::iterator iPnIter;
00184 iPnIter = find( listAllPns.begin() , listAllPns.end() , ipn);
00185 if (iPnIter == listAllPns.end()) continue;
00186
00187 for ( int i=0; i< (*pnItr).size() && i<50; ++i ) {
00188 ordinate[i] = (*pnItr).sample(i).adc();
00189 }
00190
00191 TGraph oneGraph(50, abscissa,ordinate);
00192 std::string title;
00193 title = "Graph_ev" + intToString( eventCounter )
00194 + "_FED" + intToString( FEDid )
00195 + "_ipn" + intToString( ipn );
00196 oneGraph.SetTitle(title.c_str());
00197 oneGraph.SetName(title.c_str());
00198 graphs.push_back(oneGraph);
00199
00200 }
00201 }
00202
00203 std::string EcalPnGraphs::intToString(int num)
00204 {
00205
00206
00207
00208
00209 std::ostringstream myStream;
00210 myStream << num << std::flush;
00211
00212 return(myStream.str());
00213 }
00214
00215
00216 void EcalPnGraphs::endJob() {
00217
00218 fileName += ( std::string("_Pn") + intToString(first_Pn) );
00219 fileName += ".graph.root";
00220
00221 root_file = new TFile( fileName.c_str() , "RECREATE" );
00222 std::vector<TGraph>::iterator gr_it;
00223 for ( gr_it = graphs.begin(); gr_it != graphs.end(); gr_it++ ) (*gr_it).Write();
00224 root_file->Close();
00225
00226 edm::LogInfo("EcalPnGraphs") << "DONE!.... " ;
00227 }
00228