CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
AlignmentMonitorBase.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: CommonAlignmentMonitor
4 // Class : AlignmentMonitorBase
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: Jim Pivarski
10 // Created: Fri Mar 30 12:21:07 CDT 2007
11 // $Id: AlignmentMonitorBase.cc,v 1.12 2011/10/12 22:25:58 khotilov Exp $
12 //
13 
19 
20 
22  : m_beamSpotTag(cfg.getUntrackedParameter<edm::InputTag>("beamSpotTag",edm::InputTag("offlineBeamSpot")))
23  , m_iteration(0), mp_tracker(0), mp_muon(0), mp_store(0)
24 {
25  edm::Service<TFileService> tFileService;
26  m_baseDirMap[std::vector<std::string>()] = new TFileDirectory(tFileService->mkdir(name));
27 }
28 
29 
31 {
33  mp_muon = pMuon;
34  mp_store = pStore;
35 
36  if (!pMuon) mp_navigator = new AlignableNavigator(pTracker);
37  else if (!pTracker) mp_navigator = new AlignableNavigator(pMuon);
38  else mp_navigator = new AlignableNavigator(pTracker, pMuon);
39 }
40 
41 
43 {
44  m_iteration++;
45 
46  for (std::map<std::vector<std::string>, TFileDirectory*>::const_iterator i = m_iterDirMap.begin(); i != m_iterDirMap.end(); ++i) {
47  delete i->second;
48  }
49  m_iterDirMap.clear();
50 
51  std::ostringstream dirName;
52  dirName << "iter" << iteration();
53  m_iterDirMap[std::vector<std::string>()] = new TFileDirectory(m_baseDirMap[std::vector<std::string>()]->mkdir(dirName.str()));
54 
55  book();
56 }
57 
58 
60 {
61  event(iEvent, iSetup, iTrajTracks);
62 }
63 
64 
66 {
67  afterAlignment(iSetup);
68 }
69 
70 
72 {
73  std::string::size_type lastPos = dir.find_first_not_of("/", 0);
74  std::string::size_type pos = dir.find_first_of("/", lastPos);
75  std::vector<std::string> dirs;
76 
77  bool isIter = false;
78  if (dir.substr(lastPos, pos - lastPos) == std::string("iterN")) {
79  isIter = true;
80  lastPos = dir.find_first_not_of("/", pos);
81  pos = dir.find_first_of("/", lastPos);
82  }
83 
84  while (std::string::npos != pos || std::string::npos != lastPos) {
85  dirs.push_back(dir.substr(lastPos, pos - lastPos));
86  lastPos = dir.find_first_not_of("/", pos);
87  pos = dir.find_first_of("/", lastPos);
88  }
89 
90  std::map<std::vector<std::string>, TFileDirectory*> *theMap;
91  if (isIter) theMap = &m_iterDirMap;
92  else theMap = &m_baseDirMap;
93 
94  std::vector<std::string> partial;
95  TFileDirectory *last = (*theMap)[partial];
96  for (unsigned int i = 0; i < dirs.size(); i++) {
97  partial.push_back(dirs[i]);
98  if (theMap->find(partial) == theMap->end()) {
99  (*theMap)[partial] = new TFileDirectory(last->mkdir(dirs[i]));
100  }
101  last = (*theMap)[partial];
102  }
103  return last;
104 }
105 
106 
107 TH1F *AlignmentMonitorBase::book1D(std::string dir, std::string name, std::string title, int nchX, double lowX, double highX)
108 {
109  return directory(dir)->make<TH1F>(name.c_str(), title.c_str(), nchX, lowX, highX);
110 }
111 
112 
113 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)
114 {
115  if (lowY == highY) {
116  return directory(dir)->make<TProfile>(name.c_str(), title.c_str(), nchX, lowX, highX, option);
117  }
118  else {
119  return directory(dir)->make<TProfile>(name.c_str(), title.c_str(), nchX, lowX, highX, lowY, highY, option);
120  }
121 }
122 
123 
124 TH2F *AlignmentMonitorBase::book2D(std::string dir, std::string name, std::string title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
125 {
126  return directory(dir)->make<TH2F>(name.c_str(), title.c_str(), nchX, lowX, highX, nchY, lowY, highY);
127 }
AlignableMuon * pMuon()
int i
Definition: DBlmapReader.cc:9
AlignmentParameterStore * pStore()
std::map< std::vector< std::string >, TFileDirectory * > m_baseDirMap
virtual void event(const edm::Event &iEvent, const edm::EventSetup &iSetup, const ConstTrajTrackPairCollection &iTrajTracks)
Called for each event (by &quot;run()&quot;): may be reimplemented.
TH2F * book2D(std::string dir, std::string name, std::string title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
std::map< std::vector< std::string >, TFileDirectory * > m_iterDirMap
AlignmentParameterStore * mp_store
AlignmentMonitorBase(const edm::ParameterSet &cfg, std::string name)
Constructor.
AlignableTracker * pTracker()
TProfile * bookProfile(std::string dir, std::string name, std::string title, int nchX, double lowX, double highX, int nchY=1, double lowY=0., double highY=0., const char *option="s")
uint16_t size_type
TFileDirectory * directory(std::string dir)
int iEvent
Definition: GenABIO.cc:243
std::vector< ConstTrajTrackPair > ConstTrajTrackPairCollection
TH1F * book1D(std::string dir, std::string name, std::string title, int nchX, double lowX, double highX)
AlignableTracker * mp_tracker
void beginOfJob(AlignableTracker *pTracker, AlignableMuon *pMuon, AlignmentParameterStore *pStore)
Called at beginning of job: don&#39;t reimplement.
AlignableNavigator * mp_navigator
TFileDirectory mkdir(const std::string &dir, const std::string &descr="")
create a new subdirectory
void startingNewLoop()
Called at beginning of loop: don&#39;t reimplement.
T * make() const
make new ROOT object
void endOfLoop(const edm::EventSetup &iSetup)
Called at end of loop: don&#39;t reimplement.
void duringLoop(const edm::Event &iEvent, const edm::EventSetup &iSetup, const ConstTrajTrackPairCollection &iTrajTracks)
Called for each event: don&#39;t reimplement.
virtual void afterAlignment(const edm::EventSetup &iSetup)
virtual void book()=0
Book or retrieve histograms; MUST be reimplemented.
dbl *** dir
Definition: mlp_gen.cc:35
Constructor of the full muon geometry.
Definition: AlignableMuon.h:36