CMS 3D CMS Logo

AlignmentMonitorTemplate.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: CommonAlignmentProducer
4 // Class : AlignmentMonitorTemplate
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: Jim Pivarski
10 // Created: Thu Mar 29 13:59:56 CDT 2007
11 // $Id: AlignmentMonitorTemplate.cc,v 1.6 2010/02/25 00:27:56 wmtan Exp $
12 //
13 
14 // system include files
16 #include "TH1.h"
17 #include "TObject.h"
18 // #include "PluginManager/ModuleDef.h"
21 
22 // user include files
23 
24 //
25 // class definition
26 //
27 
29 public:
30  AlignmentMonitorTemplate(const edm::ParameterSet& cfg) : AlignmentMonitorBase(cfg, "AlignmentMonitorTemplate"){};
32 
33  void book() override;
34  void event(const edm::Event& iEvent,
35  const edm::EventSetup& iSetup,
36  const ConstTrajTrackPairCollection& iTrajTracks) override;
37  void afterAlignment() override;
38 
39 private:
41  std::map<Alignable*, TH1F*> m_residuals;
42 };
43 
44 //
45 // constants, enums and typedefs
46 //
47 
48 //
49 // static data member definitions
50 //
51 
52 //
53 // member functions
54 //
55 
57  m_hist = book1D("/", "hist", "hist", 10, 0.5, 10.5); // there's only one of these per job
58  m_ihist = book1D("/iterN/", "ihist", "ihist", 10, 0, 1); // there's a new one of these for each iteration
59  // "/iterN/" is a special directory name, in which the "N" gets replaced by the current iteration number.
60 
61  m_otherdir = book1D("/otherdir/", "hist", "this is a histogram in another directory", 10, 0.5, 10.5);
62  m_otherdir2 =
63  book1D("/iterN/otherdir/", "hist", "here's one in another directory inside the iterN directories", 10, 0.5, 10.5);
64 
65  // This is a procedure that makes one histogram for each selected alignable, and puts them in the iterN directory.
66  // This is not a constant-time lookup. If you need something faster, see AlignmentMonitorMuonHIP, which has a
67  // dynamically-allocated array of TH1F*s.
68  const auto& alignables = pStore()->alignables();
69  for (const auto& it : alignables) {
70  char name[256], title[256];
71  snprintf(name, sizeof(name), "xresid%d", it->geomDetId().rawId());
72  snprintf(title, sizeof(title), "x track-hit for DetId %d", it->geomDetId().rawId());
73 
74  m_residuals[it] = book1D("/iterN/", name, title, 100, -5., 5.);
75  }
76 
77  // Important: you create TObject pointers with the "new" operator, but YOU don't delete them. They're deleted by the
78  // base class, which knows when they are no longer needed (based on whether they are in the /iterN/ directory or not).
79 
80  // For more detail, see the twiki page:
81  // https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideAlignmentMonitors for creating a plugin like this one
82  // https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideAlignmentAlgorithms#Monitoring for configuring it
83 }
84 
86  const edm::EventSetup& iSetup,
88  m_hist->Fill(iteration()); // get the number of events per iteration
89  m_ihist->Fill(0.5); // get the number of events in this iteration in the central bin
90 
91  TrajectoryStateCombiner tsoscomb;
92 
93  // This is a procedure that loops over tracks/hits, calculates residuals, and fills the appropriate histogram.
94  for (ConstTrajTrackPairCollection::const_iterator it = tracks.begin(); it != tracks.end(); ++it) {
95  const Trajectory* traj = it->first;
96  // const reco::Track* track = it->second;
97  // If your tracks are refit using the producer in RecoTracker, you'll get updated reco::Track objects with
98  // each iteration, and it makes sense to make plots using these.
99  // If your tracks are refit using TrackingTools/TrackRefitter, only the Trajectories will be updated.
100  // We're working on that. I'll try to remember to change this comment when the update is ready.
101 
102  std::vector<TrajectoryMeasurement> measurements = traj->measurements();
103  for (std::vector<TrajectoryMeasurement>::const_iterator im = measurements.begin(); im != measurements.end(); ++im) {
104  const TrajectoryMeasurement meas = *im;
105  const TransientTrackingRecHit* hit = &(*meas.recHit());
106  const DetId id = hit->geographicalId();
107 
108  if (hit->isValid() && pNavigator()->detAndSubdetInMap(id)) {
109  // Combine the forward-propagated state with the backward-propagated state to get a minimally-biased residual.
110  // This is the same procedure that is used to calculate residuals in the HIP algorithm
112 
113  // Search for our histogram using the Alignable* -> TH1F* map
114  // The "alignable = alignable->mother()" part ascends the alignable tree, because hits are on the lowest-level
115  // while our histograms may be associated with higher-level Alignables.
116  Alignable* alignable = pNavigator()->alignableFromDetId(id);
117  std::map<Alignable*, TH1F*>::const_iterator search = m_residuals.find(alignable);
118  while (search == m_residuals.end() && (alignable = alignable->mother()))
119  search = m_residuals.find(alignable);
120 
121  if (search != m_residuals.end()) {
122  search->second->Fill(tsosc.localPosition().x() - hit->localPosition().x());
123  }
124  } // end if hit is valid
125  } // end loop over hits
126  } // end loop over tracks/trajectories
127 }
128 
130  m_otherdir->Fill(
131  iteration()); // this one will only get one fill per iteration, because it's called in afterAlignment()
132 }
133 
134 //
135 // constructors and destructor
136 //
137 
138 // AlignmentMonitorTemplate::AlignmentMonitorTemplate(const AlignmentMonitorTemplate& rhs)
139 // {
140 // // do actual copying here;
141 // }
142 
143 //
144 // assignment operators
145 //
146 // const AlignmentMonitorTemplate& AlignmentMonitorTemplate::operator=(const AlignmentMonitorTemplate& rhs)
147 // {
148 // //An exception safe implementation is
149 // AlignmentMonitorTemplate temp(rhs);
150 // swap(rhs);
151 //
152 // return *this;
153 // }
154 
155 //
156 // const member functions
157 //
158 
159 //
160 // static member functions
161 //
162 
163 //
164 // SEAL definitions
165 //
166 
167 //
168 // DEFINE_SEAL_PLUGIN(AlignmentMonitorPluginFactory, AlignmentMonitorTemplate, "AlignmentMonitorTemplate");
TrajectoryStateCombiner.h
AlignableNavigator::detAndSubdetInMap
bool detAndSubdetInMap(const DetId &detid) const
Given a DetId, returns true if DetIds with this detector and subdetector id are in the map (not neces...
Definition: AlignableNavigator.cc:193
AlignmentMonitorTemplate
Definition: AlignmentMonitorTemplate.cc:28
runGCPTkAlMap.title
string title
Definition: runGCPTkAlMap.py:94
AlignmentParameterStore::alignables
const align::Alignables & alignables(void) const
get all alignables
Definition: AlignmentParameterStore.h:47
AlignmentMonitorTemplate::m_residuals
std::map< Alignable *, TH1F * > m_residuals
Definition: AlignmentMonitorTemplate.cc:41
PV3DBase::x
T x() const
Definition: PV3DBase.h:59
AlignmentMonitorTemplate::AlignmentMonitorTemplate
AlignmentMonitorTemplate(const edm::ParameterSet &cfg)
Definition: AlignmentMonitorTemplate.cc:30
Alignable
Definition: Alignable.h:27
AlignmentMonitorBase::pStore
AlignmentParameterStore * pStore()
Definition: AlignmentMonitorBase.h:113
AlignmentMonitorTemplate::m_hist
TH1F * m_hist
Definition: AlignmentMonitorTemplate.cc:40
AlignmentMonitorTemplate::book
void book() override
Book or retrieve histograms; MUST be reimplemented.
Definition: AlignmentMonitorTemplate.cc:56
AlignmentMonitorPluginFactory
AlignmentMonitorTemplate::m_otherdir
TH1F * m_otherdir
Definition: AlignmentMonitorTemplate.cc:40
AlignmentMonitorBase::pNavigator
AlignableNavigator * pNavigator()
Definition: AlignmentMonitorBase.h:114
hit::x
double x
Definition: SiStripHitEffFromCalibTree.cc:89
AlignmentMonitorTemplate::event
void event(const edm::Event &iEvent, const edm::EventSetup &iSetup, const ConstTrajTrackPairCollection &iTrajTracks) override
Called for each event (by "run()"): may be reimplemented.
Definition: AlignmentMonitorTemplate.cc:85
DetId
Definition: DetId.h:17
TrajectoryStateOnSurface
Definition: TrajectoryStateOnSurface.h:16
TrajectoryMeasurement::backwardPredictedState
TrajectoryStateOnSurface const & backwardPredictedState() const
Access to backward predicted state (from smoother)
Definition: TrajectoryMeasurement.h:179
TrajectoryMeasurement::forwardPredictedState
TrajectoryStateOnSurface const & forwardPredictedState() const
Access to forward predicted state (from fitter or builder)
Definition: TrajectoryMeasurement.h:177
cond::persistency::search
std::vector< T >::const_iterator search(const cond::Time_t &val, const std::vector< T > &container)
Definition: IOVProxy.cc:21
DEFINE_EDM_PLUGIN
#define DEFINE_EDM_PLUGIN(factory, type, name)
Definition: PluginFactory.h:124
AlignmentMonitorPluginFactory.h
TrajectoryStateCombiner
Definition: TrajectoryStateCombiner.h:13
TrajectoryStateOnSurface::localPosition
LocalPoint localPosition() const
Definition: TrajectoryStateOnSurface.h:74
edm::ParameterSet
Definition: ParameterSet.h:47
tracks
const uint32_t *__restrict__ const HitContainer *__restrict__ TkSoA *__restrict__ tracks
Definition: CAHitNtupletGeneratorKernelsImpl.h:159
AlignmentMonitorBase.h
AlignmentMonitorBase
Definition: AlignmentMonitorBase.h:42
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::EventSetup
Definition: EventSetup.h:58
AlignmentMonitorTemplate::m_ihist
TH1F * m_ihist
Definition: AlignmentMonitorTemplate.cc:40
Trajectory::measurements
DataContainer const & measurements() const
Definition: Trajectory.h:178
looper.cfg
cfg
Definition: looper.py:297
TrackingRecHit
Definition: TrackingRecHit.h:21
AlignmentMonitorBase::book1D
TH1F * book1D(std::string dir, std::string name, std::string title, int nchX, double lowX, double highX)
Definition: AlignmentMonitorBase.cc:107
TrajectoryMeasurement::recHit
ConstRecHitPointer const & recHit() const
Definition: TrajectoryMeasurement.h:190
AlignmentMonitorBase::iteration
int iteration()
Definition: AlignmentMonitorBase.h:110
AlignableNavigator::alignableFromDetId
AlignableDetOrUnitPtr alignableFromDetId(const DetId &detid)
Returns AlignableDetOrUnitPtr corresponding to given DetId.
Definition: AlignableNavigator.cc:91
Trajectory
Definition: Trajectory.h:38
TrajectoryStateCombiner::combine
TSOS combine(const TSOS &pTsos1, const TSOS &pTsos2) const
Definition: TrajectoryStateCombiner.cc:6
AlignmentMonitorTemplate::~AlignmentMonitorTemplate
~AlignmentMonitorTemplate() override
Definition: AlignmentMonitorTemplate.cc:31
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
AlignmentMonitorBase::ConstTrajTrackPairCollection
std::vector< ConstTrajTrackPair > ConstTrajTrackPairCollection
Definition: AlignmentMonitorBase.h:45
AlignmentMonitorTemplate::afterAlignment
void afterAlignment() override
Definition: AlignmentMonitorTemplate.cc:129
AlignmentMonitorTemplate::m_otherdir2
TH1F * m_otherdir2
Definition: AlignmentMonitorTemplate.cc:40
edm::Event
Definition: Event.h:73
TrajectoryMeasurement
Definition: TrajectoryMeasurement.h:25
hit
Definition: SiStripHitEffFromCalibTree.cc:88
Alignable::mother
Alignable * mother() const
Return pointer to container alignable (if any)
Definition: Alignable.h:91