00001 #include <memory>
00002 #include <iostream>
00003 #include <sstream>
00004 #include <string>
00005 #include <stdio.h>
00006 #include <sys/time.h>
00007
00008 #include "TNamed.h"
00009 #include "TH1F.h"
00010
00011 #include "FWCore/Framework/interface/Frameworkfwd.h"
00012 #include "FWCore/Framework/interface/EDAnalyzer.h"
00013 #include "FWCore/Framework/interface/Event.h"
00014 #include "FWCore/Framework/interface/MakerMacros.h"
00015 #include "FWCore/Framework/interface/ESHandle.h"
00016 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00017 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00018
00019 #include "DataFormats/Provenance/interface/EventID.h"
00020 #include "DataFormats/Provenance/interface/RunID.h"
00021 #include "DataFormats/Provenance/interface/Timestamp.h"
00022
00023 #include "DataFormats/Common/interface/Handle.h"
00024 #include "DataFormats/TrackCandidate/interface/TrackCandidateCollection.h"
00025 #include "Geometry/TrackerGeometryBuilder/interface/PixelGeomDetUnit.h"
00026 #include "RecoTracker/TransientTrackingRecHit/interface/TkTransientTrackingRecHitBuilder.h"
00027 #include "TrackingTools/PatternTools/interface/TrajectoryFitter.h"
00028 #include "TrackingTools/Records/interface/TransientRecHitRecord.h"
00029 #include "TrackingTools/Records/interface/TrackingComponentsRecord.h"
00030 #include "TrackingTools/TrackFitters/interface/TrajectoryStateCombiner.h"
00031 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateTransform.h"
00032
00033 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
00034 #include "CondFormats/SiPixelObjects/interface/SiPixelPerformanceSummary.h"
00035
00036 #include "DQMServices/Core/interface/DQMStore.h"
00037 #include "DQMServices/Core/interface/MonitorElement.h"
00038
00039 #include "DQM/SiPixelCommon/interface/SiPixelHistogramId.h"
00040 #include "DQM/SiPixelHistoricInfoClient/interface/SiPixelHistoricInfoEDAClient.h"
00041
00042
00043 using namespace std;
00044 using namespace cgicc;
00045 using namespace xcept;
00046
00047
00048 SiPixelHistoricInfoEDAClient::SiPixelHistoricInfoEDAClient(const edm::ParameterSet& parameterSet) {
00049 parameterSet_ = parameterSet;
00050 dbe_ = edm::Service<DQMStore>().operator->();
00051 dbe_->setVerbose(0);
00052 }
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080 SiPixelHistoricInfoEDAClient::~SiPixelHistoricInfoEDAClient() {}
00081
00082
00083 void SiPixelHistoricInfoEDAClient::beginJob(const edm::EventSetup& eventSetup) {
00084 nEvents = 0;
00085 }
00086
00087
00088 void SiPixelHistoricInfoEDAClient::beginRun(const edm::Run& run, const edm::EventSetup& eventSetup) {
00089 performanceSummary_ = new SiPixelPerformanceSummary();
00090 performanceSummary_->clear();
00091 performanceSummary_->setRunNumber(run.run());
00092 firstEventInRun = true;
00093 }
00094
00095
00096 void SiPixelHistoricInfoEDAClient::analyze(const edm::Event& event, const edm::EventSetup& eventSetup) {
00097 if (firstEventInRun) {
00098 firstEventInRun = false;
00099 performanceSummary_->setTimeValue(event.time().value());
00100 }
00101 nEvents++;
00102 }
00103
00104
00105 void SiPixelHistoricInfoEDAClient::endRun(const edm::Run& run, const edm::EventSetup& eventSetup) {
00106 firstEventInRun = false;
00107 std::cout << "SiPixelHistoricInfoEDAClient::endRun() number of events = "<< nEvents << std::endl;
00108
00109 retrievePointersToModuleMEs(eventSetup);
00110 fillSummaryObjects(run);
00111 performanceSummary_->print();
00112 writetoDB(run);
00113
00114 if (parameterSet_.getUntrackedParameter<bool>("writeHisto", true)) {
00115 std::string outputDir = parameterSet_.getUntrackedParameter<std::string>("outputDir",".");
00116 std::ostringstream endRunOutputFile;
00117 endRunOutputFile << outputDir << "/SiPixelHistoricInfoEDAClient_" << run.run() <<".root";
00118 dbe_->save(endRunOutputFile.str());
00119 }
00120 }
00121
00122
00123 void SiPixelHistoricInfoEDAClient::endJob() {
00124 if (parameterSet_.getUntrackedParameter<bool>("writeHisto", true)) {
00125 std::string outputDir = parameterSet_.getUntrackedParameter<std::string>("outputDir",".");
00126 std::ostringstream endJobOutputFile;
00127 endJobOutputFile << outputDir << "/SiPixelHistoricInfoEDAClient_endJob.root";
00128 dbe_->save(endJobOutputFile.str());
00129 }
00130 }
00131
00132
00133 void SiPixelHistoricInfoEDAClient::retrievePointersToModuleMEs(const edm::EventSetup& eventSetup) {
00134 std::vector<string> listOfMEsWithFullPath;
00135 dbe_->getContents(listOfMEsWithFullPath);
00136
00137 for (std::vector<string>::const_iterator ime=listOfMEsWithFullPath.begin();
00138 ime!=listOfMEsWithFullPath.end(); ime++) {
00139 uint32_t pathLength = (*ime).find(":",0);
00140 string thePath = (*ime).substr(0, pathLength);
00141 string allHists = (*ime).substr(pathLength+1);
00142
00143 if (thePath.find("Pixel",0)!=string::npos && thePath.find("Module",0)!=string::npos) {
00144 uint histnameLength;
00145 do {
00146 histnameLength = allHists.find(",",0);
00147 string theHist;
00148 if (histnameLength!=string::npos) {
00149 theHist = allHists.substr(0, histnameLength);
00150 allHists.erase(0, histnameLength+1);
00151 }
00152 else theHist = allHists;
00153
00154 string fullPathHist = thePath + "/" + theHist;
00155 MonitorElement* theMEpointer = dbe_->get(fullPathHist);
00156
00157 SiPixelHistogramId hisIDmanager;
00158 string hisID;
00159 uint32_t localMEdetID;
00160 if (theMEpointer) {
00161 hisID = theMEpointer->getName();
00162 localMEdetID = hisIDmanager.getRawId(hisID);
00163
00164 if (ClientPointersToModuleMEs.find(localMEdetID)==ClientPointersToModuleMEs.end()) {
00165 std::vector<MonitorElement*> newMEvector;
00166 newMEvector.push_back(theMEpointer);
00167 ClientPointersToModuleMEs.insert(std::make_pair(localMEdetID, newMEvector));
00168 }
00169 else ((ClientPointersToModuleMEs.find(localMEdetID))->second).push_back(theMEpointer);
00170 }
00171 }
00172 while (histnameLength!=string::npos);
00173 }
00174 }
00175 }
00176
00177
00178 void SiPixelHistoricInfoEDAClient::fillSummaryObjects(const edm::Run& run) const {
00179 for (std::map< uint32_t, std::vector<MonitorElement*> >::const_iterator iMEvec=ClientPointersToModuleMEs.begin();
00180 iMEvec!=ClientPointersToModuleMEs.end(); iMEvec++) {
00181 uint32_t localMEdetID = iMEvec->first;
00182 std::vector<MonitorElement*> theMEvector = iMEvec->second;
00183
00184 for (std::vector<MonitorElement*>::const_iterator iMEpntr = theMEvector.begin();
00185 iMEpntr!=theMEvector.end(); iMEpntr++) {
00186 std::string theMEname = (*iMEpntr)->getName();
00187
00188
00189 if (theMEname.find("ndigis_siPixelDigis")!=std::string::npos) {
00190 performanceSummary_->setNumberOfDigis(localMEdetID, (*iMEpntr)->getMean(), (*iMEpntr)->getRMS());
00191 if (parameterSet_.getUntrackedParameter<bool>("debug", true)) {
00192 std::cout << "sipixel performance summary table set with the number of digi's "<< (*iMEpntr)->getMean()
00193 << " +- "<< (*iMEpntr)->getRMS()
00194 <<" for det ID "<< localMEdetID << std::endl;
00195 }
00196 }
00197
00198
00199
00200 }
00201 }
00202 }
00203
00204
00205 void SiPixelHistoricInfoEDAClient::writetoDB(const edm::Run& run) const {
00206 unsigned int thisRun = run.run();
00207 std::cout << std::endl << "SiPixelHistoricInfoEDAClient::writetoDB() run = "<< thisRun << std::endl;
00208
00209 edm::Service<cond::service::PoolDBOutputService> mydbservice;
00210 if (mydbservice.isAvailable()) {
00211 if (mydbservice->isNewTagRequest("SiPixelPerformanceSummaryRcd")) {
00212 mydbservice->createNewIOV<SiPixelPerformanceSummary>(performanceSummary_,
00213 mydbservice->beginOfTime(),
00214 mydbservice->endOfTime(),
00215 "SiPixelPerformanceSummaryRcd");
00216 }
00217 else {
00218 mydbservice->appendSinceTime<SiPixelPerformanceSummary>(performanceSummary_,
00219 mydbservice->currentTime(),
00220 "SiPixelPerformanceSummaryRcd");
00221 }
00222 }
00223 else edm::LogError("writetoDB") << "service unavailable" << std::endl;
00224
00225 std::cout << "SiPixelHistoricInfoEDAClient::writetoDB() finished. "<< std::endl;
00226 }
00227
00228
00229 void SiPixelHistoricInfoEDAClient::writetoDB(edm::EventID eventID, edm::Timestamp EventTime) const {
00230 unsigned int thisRun = eventID.run();
00231 unsigned int thisEvent = eventID.event();
00232 unsigned long long thisTime = EventTime.value();
00233 std::cout << std::endl << "SiPixelHistoricInfoEDAClient::writetoDB() run = "<< thisRun
00234 <<" event = "<< thisEvent
00235 <<" time = "<< thisTime << std::endl;
00236
00237 edm::Service<cond::service::PoolDBOutputService> mydbservice;
00238 if (mydbservice.isAvailable()) {
00239 if (mydbservice->isNewTagRequest("SiPixelPerformanceSummaryRcd")) {
00240 mydbservice->createNewIOV<SiPixelPerformanceSummary>(performanceSummary_,
00241 mydbservice->beginOfTime(),
00242 mydbservice->endOfTime(),
00243 "SiPixelPerformanceSummaryRcd");
00244 }
00245 else {
00246 mydbservice->appendSinceTime<SiPixelPerformanceSummary>(performanceSummary_,
00247 mydbservice->currentTime(),
00248 "SiPixelPerformanceSummaryRcd");
00249 }
00250 }
00251 else edm::LogError("writetoDB") << "service unavailable" << std::endl;
00252 }
00253
00254
00255 void SiPixelHistoricInfoEDAClient::savetoFile(std::string filename) const {
00256 dbe_->save(filename);
00257 }
00258
00259
00260 float SiPixelHistoricInfoEDAClient::calculatePercentOver(MonitorElement* me) const {
00261 TH1F* hist = me->getTH1F();
00262 unsigned int nBins = hist->GetNbinsX();
00263 unsigned int upperBin = hist->FindBin(hist->GetMean()+3*hist->GetRMS());
00264 float percentage=0.0;
00265 if ((upperBin-nBins)<1) {
00266 percentage = hist->Integral(upperBin,nBins)/hist->Integral();
00267 return percentage;
00268 }
00269 return -99.9;
00270 }
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327