00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "Alignment/CommonAlignmentMonitor/interface/AlignmentMonitorBase.h"
00018 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00019 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00020 #include "FWCore/ServiceRegistry/interface/Service.h"
00021 #include "PhysicsTools/UtilAlgos/interface/TFileService.h"
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 AlignmentMonitorBase::AlignmentMonitorBase(const edm::ParameterSet& cfg, std::string name)
00041 : m_iteration(0), mp_tracker(0), mp_muon(0), mp_store(0) {
00042 edm::Service<TFileService> tFileService;
00043 m_baseDirMap[std::vector<std::string>()] = new TFileDirectory(tFileService->mkdir(name));
00044 }
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062 void AlignmentMonitorBase::beginOfJob(AlignableTracker *pTracker, AlignableMuon *pMuon, AlignmentParameterStore *pStore) {
00063 mp_tracker = pTracker;
00064 mp_muon = pMuon;
00065 mp_store = pStore;
00066
00067 if (!pMuon) mp_navigator = new AlignableNavigator(pTracker);
00068 else if (!pTracker) mp_navigator = new AlignableNavigator(pMuon);
00069 else mp_navigator = new AlignableNavigator(pTracker, pMuon);
00070 }
00071
00072 void AlignmentMonitorBase::startingNewLoop() {
00073 m_iteration++;
00074
00075 for (std::map<std::vector<std::string>, TFileDirectory*>::const_iterator i = m_iterDirMap.begin(); i != m_iterDirMap.end(); ++i) {
00076 delete i->second;
00077 }
00078 m_iterDirMap.clear();
00079
00080 std::ostringstream dirName;
00081 dirName << "iter" << iteration();
00082 m_iterDirMap[std::vector<std::string>()] = new TFileDirectory(m_baseDirMap[std::vector<std::string>()]->mkdir(dirName.str()));
00083
00084 book();
00085 }
00086
00087 void AlignmentMonitorBase::duringLoop(const edm::EventSetup &iSetup, const ConstTrajTrackPairCollection &iTrajTracks) {
00088 event(iSetup, iTrajTracks);
00089 }
00090
00091 void AlignmentMonitorBase::endOfLoop(const edm::EventSetup &iSetup) {
00092 afterAlignment(iSetup);
00093 }
00094
00095 void AlignmentMonitorBase::endOfJob() {
00096 }
00097
00098 TFileDirectory *AlignmentMonitorBase::directory(std::string dir) {
00099 std::string::size_type lastPos = dir.find_first_not_of("/", 0);
00100 std::string::size_type pos = dir.find_first_of("/", lastPos);
00101 std::vector<std::string> dirs;
00102
00103 bool isIter = false;
00104 if (dir.substr(lastPos, pos - lastPos) == std::string("iterN")) {
00105 isIter = true;
00106 lastPos = dir.find_first_not_of("/", pos);
00107 pos = dir.find_first_of("/", lastPos);
00108 }
00109
00110 while (std::string::npos != pos || std::string::npos != lastPos) {
00111 dirs.push_back(dir.substr(lastPos, pos - lastPos));
00112 lastPos = dir.find_first_not_of("/", pos);
00113 pos = dir.find_first_of("/", lastPos);
00114 }
00115
00116 std::map<std::vector<std::string>, TFileDirectory*> *theMap;
00117 if (isIter) theMap = &m_iterDirMap;
00118 else theMap = &m_baseDirMap;
00119
00120 std::vector<std::string> partial;
00121 TFileDirectory *last = (*theMap)[partial];
00122 for (unsigned int i = 0; i < dirs.size(); i++) {
00123 partial.push_back(dirs[i]);
00124 if (theMap->find(partial) == theMap->end()) {
00125 (*theMap)[partial] = new TFileDirectory(last->mkdir(dirs[i]));
00126 }
00127 last = (*theMap)[partial];
00128 }
00129 return last;
00130 }
00131
00132 TH1F *AlignmentMonitorBase::book1D(std::string dir, std::string name, std::string title, int nchX, double lowX, double highX) {
00133 return directory(dir)->make<TH1F>(name.c_str(), title.c_str(), nchX, lowX, highX);
00134 }
00135
00136 TProfile *AlignmentMonitorBase::bookProfile(std::string dir, std::string name, std::string title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, char *option) {
00137 if (lowY == highY) {
00138 return directory(dir)->make<TProfile>(name.c_str(), title.c_str(), nchX, lowX, highX, option);
00139 }
00140 else {
00141 return directory(dir)->make<TProfile>(name.c_str(), title.c_str(), nchX, lowX, highX, lowY, highY, option);
00142 }
00143 }
00144
00145
00146
00147
00148
00149
00150
00151