Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-03 01:57:39

0001 // -*- C++ -*-
0002 //
0003 // Package:     CommonAlignmentMonitor
0004 // Class  :     AlignmentMonitorBase
0005 //
0006 // Implementation:
0007 //     <Notes on implementation>
0008 //
0009 // Original Author:  Jim Pivarski
0010 //         Created:  Fri Mar 30 12:21:07 CDT 2007
0011 // $Id: AlignmentMonitorBase.cc,v 1.11 2010/01/06 15:23:09 mussgill Exp $
0012 //
0013 
0014 #include "Alignment/CommonAlignmentMonitor/interface/AlignmentMonitorBase.h"
0015 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0016 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0017 #include "FWCore/ServiceRegistry/interface/Service.h"
0018 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0019 
0020 AlignmentMonitorBase::AlignmentMonitorBase(const edm::ParameterSet &cfg,
0021                                            const edm::ConsumesCollector &iC,
0022                                            std::string name)
0023     : m_beamSpotTag(cfg.getUntrackedParameter<edm::InputTag>("beamSpotTag", edm::InputTag("offlineBeamSpot"))),
0024       m_iteration(0),
0025       mp_tracker(nullptr),
0026       mp_muon(nullptr),
0027       mp_store(nullptr) {
0028   edm::Service<TFileService> tFileService;
0029   m_baseDirMap[std::vector<std::string>()] = new TFileDirectory(tFileService->mkdir(name));
0030 }
0031 
0032 void AlignmentMonitorBase::beginOfJob(AlignableTracker *pTracker,
0033                                       AlignableMuon *pMuon,
0034                                       AlignmentParameterStore *pStore) {
0035   mp_tracker = pTracker;
0036   mp_muon = pMuon;
0037   mp_store = pStore;
0038 
0039   if (!pMuon)
0040     mp_navigator = new AlignableNavigator(pTracker);
0041   else if (!pTracker)
0042     mp_navigator = new AlignableNavigator(pMuon);
0043   else
0044     mp_navigator = new AlignableNavigator(pTracker, pMuon);
0045 }
0046 
0047 void AlignmentMonitorBase::startingNewLoop() {
0048   m_iteration++;
0049 
0050   for (std::map<std::vector<std::string>, TFileDirectory *>::const_iterator i = m_iterDirMap.begin();
0051        i != m_iterDirMap.end();
0052        ++i) {
0053     delete i->second;
0054   }
0055   m_iterDirMap.clear();
0056 
0057   std::ostringstream dirName;
0058   dirName << "iter" << iteration();
0059   m_iterDirMap[std::vector<std::string>()] =
0060       new TFileDirectory(m_baseDirMap[std::vector<std::string>()]->mkdir(dirName.str()));
0061 
0062   book();
0063 }
0064 
0065 void AlignmentMonitorBase::duringLoop(const edm::Event &iEvent,
0066                                       const edm::EventSetup &iSetup,
0067                                       const ConstTrajTrackPairCollection &iTrajTracks) {
0068   event(iEvent, iSetup, iTrajTracks);
0069 }
0070 
0071 void AlignmentMonitorBase::endOfLoop() { afterAlignment(); }
0072 
0073 TFileDirectory *AlignmentMonitorBase::directory(std::string dir) {
0074   std::string::size_type lastPos = dir.find_first_not_of('/', 0);
0075   std::string::size_type pos = dir.find_first_of('/', lastPos);
0076   std::vector<std::string> dirs;
0077 
0078   bool isIter = false;
0079   if (dir.substr(lastPos, pos - lastPos) == std::string("iterN")) {
0080     isIter = true;
0081     lastPos = dir.find_first_not_of('/', pos);
0082     pos = dir.find_first_of('/', lastPos);
0083   }
0084 
0085   while (std::string::npos != pos || std::string::npos != lastPos) {
0086     dirs.push_back(dir.substr(lastPos, pos - lastPos));
0087     lastPos = dir.find_first_not_of('/', pos);
0088     pos = dir.find_first_of('/', lastPos);
0089   }
0090 
0091   std::map<std::vector<std::string>, TFileDirectory *> *theMap;
0092   if (isIter)
0093     theMap = &m_iterDirMap;
0094   else
0095     theMap = &m_baseDirMap;
0096 
0097   std::vector<std::string> partial;
0098   TFileDirectory *last = (*theMap)[partial];
0099   for (unsigned int i = 0; i < dirs.size(); i++) {
0100     partial.push_back(dirs[i]);
0101     if (theMap->find(partial) == theMap->end()) {
0102       (*theMap)[partial] = new TFileDirectory(last->mkdir(dirs[i]));
0103     }
0104     last = (*theMap)[partial];
0105   }
0106   return last;
0107 }
0108 
0109 TH1F *AlignmentMonitorBase::book1D(
0110     std::string dir, std::string name, std::string title, int nchX, double lowX, double highX) {
0111   return directory(dir)->make<TH1F>(name.c_str(), title.c_str(), nchX, lowX, highX);
0112 }
0113 
0114 TProfile *AlignmentMonitorBase::bookProfile(std::string dir,
0115                                             std::string name,
0116                                             std::string title,
0117                                             int nchX,
0118                                             double lowX,
0119                                             double highX,
0120                                             int nchY,
0121                                             double lowY,
0122                                             double highY,
0123                                             const char *option) {
0124   if (lowY == highY) {
0125     return directory(dir)->make<TProfile>(name.c_str(), title.c_str(), nchX, lowX, highX, option);
0126   } else {
0127     return directory(dir)->make<TProfile>(name.c_str(), title.c_str(), nchX, lowX, highX, lowY, highY, option);
0128   }
0129 }
0130 
0131 TH2F *AlignmentMonitorBase::book2D(std::string dir,
0132                                    std::string name,
0133                                    std::string title,
0134                                    int nchX,
0135                                    double lowX,
0136                                    double highX,
0137                                    int nchY,
0138                                    double lowY,
0139                                    double highY) {
0140   return directory(dir)->make<TH2F>(name.c_str(), title.c_str(), nchX, lowX, highX, nchY, lowY, highY);
0141 }