CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/src/Alignment/CommonAlignmentMonitor/src/AlignmentMonitorBase.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     CommonAlignmentMonitor
00004 // Class  :     AlignmentMonitorBase
00005 // 
00006 // Implementation:
00007 //     <Notes on implementation>
00008 //
00009 // Original Author:  Jim Pivarski
00010 //         Created:  Fri Mar 30 12:21:07 CDT 2007
00011 // $Id: AlignmentMonitorBase.cc,v 1.12 2011/10/12 22:25:58 khotilov Exp $
00012 //
00013 
00014 #include "Alignment/CommonAlignmentMonitor/interface/AlignmentMonitorBase.h"
00015 #include "FWCore/ParameterSet/interface/ParameterSet.h" 
00016 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00017 #include "FWCore/ServiceRegistry/interface/Service.h"
00018 #include "CommonTools/UtilAlgos/interface/TFileService.h"
00019 
00020 
00021 AlignmentMonitorBase::AlignmentMonitorBase(const edm::ParameterSet& cfg, std::string name)
00022    : m_beamSpotTag(cfg.getUntrackedParameter<edm::InputTag>("beamSpotTag",edm::InputTag("offlineBeamSpot")))
00023    , m_iteration(0), mp_tracker(0), mp_muon(0), mp_store(0)
00024 {
00025    edm::Service<TFileService> tFileService;
00026    m_baseDirMap[std::vector<std::string>()] = new TFileDirectory(tFileService->mkdir(name));
00027 }
00028 
00029 
00030 void AlignmentMonitorBase::beginOfJob(AlignableTracker *pTracker, AlignableMuon *pMuon, AlignmentParameterStore *pStore)
00031 {
00032    mp_tracker = pTracker;
00033    mp_muon = pMuon;
00034    mp_store = pStore;
00035 
00036    if (!pMuon)          mp_navigator = new AlignableNavigator(pTracker);
00037    else if (!pTracker)  mp_navigator = new AlignableNavigator(pMuon);
00038    else                 mp_navigator = new AlignableNavigator(pTracker, pMuon);
00039 }
00040 
00041 
00042 void AlignmentMonitorBase::startingNewLoop()
00043 {
00044    m_iteration++;
00045 
00046    for (std::map<std::vector<std::string>, TFileDirectory*>::const_iterator i = m_iterDirMap.begin();  i != m_iterDirMap.end();  ++i) {
00047       delete i->second;
00048    }
00049    m_iterDirMap.clear();
00050 
00051    std::ostringstream dirName;
00052    dirName << "iter" << iteration();
00053    m_iterDirMap[std::vector<std::string>()] = new TFileDirectory(m_baseDirMap[std::vector<std::string>()]->mkdir(dirName.str()));
00054 
00055    book();
00056 }
00057 
00058 
00059 void AlignmentMonitorBase::duringLoop(const edm::Event &iEvent, const edm::EventSetup &iSetup, const ConstTrajTrackPairCollection &iTrajTracks)
00060 {
00061    event(iEvent, iSetup, iTrajTracks);
00062 }
00063 
00064 
00065 void AlignmentMonitorBase::endOfLoop(const edm::EventSetup &iSetup)
00066 {
00067    afterAlignment(iSetup);
00068 }
00069 
00070 
00071 TFileDirectory *AlignmentMonitorBase::directory(std::string dir)
00072 {
00073    std::string::size_type lastPos = dir.find_first_not_of("/", 0);
00074    std::string::size_type pos = dir.find_first_of("/", lastPos);
00075    std::vector<std::string> dirs;
00076 
00077    bool isIter = false;
00078    if (dir.substr(lastPos, pos - lastPos) == std::string("iterN")) {
00079       isIter = true;
00080       lastPos = dir.find_first_not_of("/", pos);
00081       pos = dir.find_first_of("/", lastPos);
00082    }
00083 
00084    while (std::string::npos != pos  ||  std::string::npos != lastPos) {
00085       dirs.push_back(dir.substr(lastPos, pos - lastPos));
00086       lastPos = dir.find_first_not_of("/", pos);
00087       pos = dir.find_first_of("/", lastPos);
00088    }
00089 
00090    std::map<std::vector<std::string>, TFileDirectory*> *theMap;
00091    if (isIter) theMap = &m_iterDirMap;
00092    else theMap = &m_baseDirMap;
00093 
00094    std::vector<std::string> partial;
00095    TFileDirectory *last = (*theMap)[partial];
00096    for (unsigned int i = 0;  i < dirs.size();  i++) {
00097       partial.push_back(dirs[i]);
00098       if (theMap->find(partial) == theMap->end()) {
00099          (*theMap)[partial] = new TFileDirectory(last->mkdir(dirs[i]));
00100       }
00101       last = (*theMap)[partial];
00102    }
00103    return last;
00104 }
00105 
00106 
00107 TH1F *AlignmentMonitorBase::book1D(std::string dir, std::string name, std::string title, int nchX, double lowX, double highX)
00108 {
00109    return directory(dir)->make<TH1F>(name.c_str(), title.c_str(), nchX, lowX, highX);
00110 }
00111 
00112 
00113 TProfile *AlignmentMonitorBase::bookProfile(std::string dir, std::string name, std::string title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, const char *option)
00114 {
00115    if (lowY == highY) {
00116       return directory(dir)->make<TProfile>(name.c_str(), title.c_str(), nchX, lowX, highX, option);
00117    }
00118    else {
00119       return directory(dir)->make<TProfile>(name.c_str(), title.c_str(), nchX, lowX, highX, lowY, highY, option);
00120    }
00121 }
00122 
00123 
00124 TH2F *AlignmentMonitorBase::book2D(std::string dir, std::string name, std::string title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
00125 {
00126    return directory(dir)->make<TH2F>(name.c_str(), title.c_str(), nchX, lowX, highX, nchY, lowY, highY);
00127 }