CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MonitorTrackResiduals.cc
Go to the documentation of this file.
15 
17  : dqmStore_( edm::Service<DQMStore>().operator->() )
18  , conf_(iConfig), m_cacheID_(0)
19  , genTriggerEventFlag_(new GenericTriggerEventFlag(iConfig, consumesCollector(), *this))
20  , avalidator_(iConfig, consumesCollector()) {
21  ModOn = conf_.getParameter<bool>("Mod_On");
22 }
23 
26 }
27 
28 
30 }
31 
33 {
34  unsigned long long cacheID = iSetup.get<SiStripDetCablingRcd>().cacheIdentifier();
35  if (m_cacheID_ != cacheID) {
36  m_cacheID_ = cacheID;
37  this->createMEs( ibooker , iSetup);
38  }
39 }
40 
42 
43  // Initialize the GenericTriggerEventFlag
44  if ( genTriggerEventFlag_->on() ) genTriggerEventFlag_->initRun( run, iSetup );
45 }
46 
47 std::pair<std::string, int32_t> MonitorTrackResiduals::findSubdetAndLayer(uint32_t ModuleID, const TrackerTopology* tTopo) {
48  std::string subdet = "";
49  int32_t layer = 0;
50  auto id = DetId(ModuleID);
51  switch (id.subdetId()) {
52  // Pixel Barrel, Endcap
53  case 1:
54  subdet = "BPIX";
55  layer = tTopo->pxbLayer(id);
56  break;
57  case 2:
58  subdet = "FPIX";
59  layer = tTopo->pxfDisk(id) * ( tTopo->pxfSide(ModuleID)==1 ? -1 : +1);
60  break;
61  // Strip TIB, TID, TOB, TEC
62  case 3:
63  subdet = "TIB";
64  layer = tTopo->tibLayer(id);
65  break;
66  case 4:
67  subdet = "TID";
68  layer = tTopo->tidWheel(id) * ( tTopo->tecSide(ModuleID)==1 ? -1 : +1);
69  break;
70  case 5:
71  subdet = "TOB";
72  layer = tTopo->tobLayer(id);
73  break;
74  case 6:
75  subdet = "TEC";
76  layer = tTopo->tecWheel(id) * ( tTopo->tecSide(ModuleID)==1 ? -1 : +1);
77  break;
78  default:
79  // TODO: Fail loudly.
80  subdet = "UNKNOWN";
81  layer = 0;
82  }
83  return std::make_pair(subdet, layer);
84 }
85 
86 
88 
89  //Retrieve tracker topology and geometry
91  iSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
92  const TrackerTopology* const tTopo = tTopoHandle.product();
93 
95  iSetup.get<TrackerDigiGeometryRecord>().get(TG);
96 
97  Parameters = conf_.getParameter<edm::ParameterSet>("TH1ResModules");
98  int32_t i_residuals_Nbins = Parameters.getParameter<int32_t>("Nbinx");
99  double d_residual_xmin = Parameters.getParameter<double>("xmin");
100  double d_residual_xmax = Parameters.getParameter<double>("xmax");
101  Parameters = conf_.getParameter<edm::ParameterSet>("TH1NormResModules");
102  int32_t i_normres_Nbins = Parameters.getParameter<int32_t>("Nbinx");
103  double d_normres_xmin = Parameters.getParameter<double>("xmin");
104  double d_normres_xmax = Parameters.getParameter<double>("xmax");
105 
106 
107  // use SistripHistoId for producing histogram id (and title)
108  SiStripHistoId hidmanager;
109 
110  SiStripFolderOrganizer strip_organizer;
111  auto pixel_organizer = SiPixelFolderOrganizer(false);
112 
113  // Collect list of modules from Tracker Geometry
114  std::vector<uint32_t> activeDets;
115  auto ids = TG->detIds(); // or detUnitIds?
116  for (DetId id : ids) {
117  activeDets.push_back(id.rawId());
118  }
119 
120  // book histo per each detector module
121  for(auto ModuleID : activeDets)
122  {
123  auto id = DetId(ModuleID);
124 
125  // TODO: Not yet implemented for Pixel.
126  // Book module histogramms?
127  if (ModOn) {
128  switch (id.subdetId()) {
129  case 1: pixel_organizer.setModuleFolder(ibooker, ModuleID, 0); break;
130  case 2: pixel_organizer.setModuleFolder(ibooker, ModuleID, 0); break;
131  default: strip_organizer.setDetectorFolder(ModuleID,tTopo);
132  }
133  {
134  // this sounds strip specific but also works for pixel
135  std::string hid = hidmanager.createHistoId("HitResidualsX","det",ModuleID);
136  std::string normhid = hidmanager.createHistoId("NormalizedHitResidualsX","det",ModuleID);
137  auto& histos = m_ModuleResiduals[std::make_pair("", ModuleID)];
138  histos.x.base = ibooker.book1D(hid, hid, i_residuals_Nbins,d_residual_xmin,d_residual_xmax);
139  histos.x.base->setAxisTitle("(x_{pred} - x_{rec})' [cm]");
140  histos.x.normed = ibooker.book1D(normhid, normhid, i_normres_Nbins,d_normres_xmin,d_normres_xmax);
141  histos.x.normed->setAxisTitle("(x_{pred} - x_{rec})'/#sigma");
142  }{
143  std::string hid = hidmanager.createHistoId("HitResidualsY","det",ModuleID);
144  std::string normhid = hidmanager.createHistoId("NormalizedHitResidualsY","det",ModuleID);
145  auto& histos = m_ModuleResiduals[std::make_pair("", ModuleID)];
146  histos.y.base = ibooker.book1D(hid, hid, i_residuals_Nbins,d_residual_xmin,d_residual_xmax);
147  histos.y.base->setAxisTitle("(y_{pred} - y_{rec})' [cm]");
148  histos.y.normed = ibooker.book1D(normhid, normhid, i_normres_Nbins,d_normres_xmin,d_normres_xmax);
149  histos.y.normed->setAxisTitle("(y_{pred} - y_{rec})'/#sigma");
150  }
151  }
152 
153  auto subdetandlayer = findSubdetAndLayer(ModuleID, tTopo);
154  if(m_SubdetLayerResiduals.find(subdetandlayer) == m_SubdetLayerResiduals.end()) {
155  // add new histograms
156  auto& histos = m_SubdetLayerResiduals[subdetandlayer];
157  switch (id.subdetId()) {
158  // Pixel Barrel, Endcap
159  case 1: pixel_organizer.setModuleFolder(ibooker, ModuleID, 2); break;
160  case 2: pixel_organizer.setModuleFolder(ibooker, ModuleID, 6); break;
161  // All strip
162  default: strip_organizer.setLayerFolder(ModuleID,tTopo,subdetandlayer.second);
163  }
164 
165  auto xy = std::vector<std::pair<HistoPair&, const char*> >
166  { std::make_pair(std::ref(histos.x), "X"),
167  std::make_pair(std::ref(histos.y), "Y") };
168  for (auto& histopair : xy) {
169  // book histogramms on layer level, check for barrel/pixel only for correct labeling
170  auto isBarrel = subdetandlayer.first.find("B") != std::string::npos;
171  auto isPixel = subdetandlayer.first.find("X") != std::string::npos;
172  // TODO: We use a legacy name to stay compatible with other code.
173  // Check if this is necessary.
174  std::string histoname = Form("HitResiduals_%s__%s__%d%s",
175  subdetandlayer.first.c_str(),
176  isBarrel ? "Layer" : "wheel",
177  std::abs(subdetandlayer.second),
178  histopair.second[0] == 'X' ? "" : "_Y");
179  std::string histotitle = Form("HitResiduals %s on %s%s full %s %d",
180  histopair.second,
181  subdetandlayer.first.c_str(),
182  isBarrel ? "" : (subdetandlayer.second > 0 ? "+" : "-"),
183  isBarrel ? "Layer" : (isPixel ? "Disk" : "Wheel"),
184  std::abs(subdetandlayer.second));
185 
186 
187  std::string normhistoname = Form("Normalized%s", histoname.c_str());
188  std::string normhistotitle = Form("Normalized%s", histotitle.c_str());
189 
190  //std::cout << "##### Booking: " << ibooker.pwd() << " title " << histoname << std::endl;
191 
192  histopair.first.base =
193  ibooker.book1D(histoname.c_str(),histotitle.c_str(),
194  i_residuals_Nbins,d_residual_xmin,d_residual_xmax);
195  histopair.first.base->setAxisTitle("(x_{pred} - x_{rec})' [cm]");
196 
197  histopair.first.normed =
198  ibooker.book1D(normhistoname.c_str(),normhistotitle.c_str(),
199  i_normres_Nbins,d_normres_xmin,d_normres_xmax);
200  histopair.first.normed->setAxisTitle("(x_{pred} - x_{rec})'/#sigma");
201  }
202  }
203  } // end loop over activeDets
204 }
205 
206 
208 }
209 
210 
212 
213  //dqmStore_->showDirStructure();
214  bool outputMEsInRootFile = conf_.getParameter<bool>("OutputMEsInRootFile");
216  if(outputMEsInRootFile){
217  dqmStore_->save(outputFileName);
218  }
219 }
220 
221 
223 
224  // Filter out events if Trigger Filtering is requested
225  if (genTriggerEventFlag_->on()&& ! genTriggerEventFlag_->accept( iEvent, iSetup) ) return;
226 
227  //Retrieve tracker topology from geometry
228  edm::ESHandle<TrackerTopology> tTopoHandle;
229  iSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
230  const TrackerTopology* const tTopo = tTopoHandle.product();
231 
232  std::vector<TrackerValidationVariables::AVHitStruct> v_hitstruct;
233  avalidator_.fillHitQuantities(iEvent,v_hitstruct);
234  for (auto it : v_hitstruct) {
235  uint RawId = it.rawDetId;
236 
237  if (ModOn) {
238  auto& mod_histos = m_ModuleResiduals[std::make_pair("",RawId)];
239  mod_histos.x.base->Fill(it.resXprime);
240  mod_histos.x.normed->Fill(it.resXprime/it.resXprimeErr);
241  mod_histos.y.base->Fill(it.resYprime);
242  mod_histos.y.normed->Fill(it.resYprime/it.resYprimeErr);
243  }
244  auto subdetandlayer = findSubdetAndLayer(RawId, tTopo);
245  auto histos = m_SubdetLayerResiduals[subdetandlayer];
246  // fill if its error is not zero
247  if(it.resXprimeErr != 0 && histos.x.base) {
248  histos.x.base->Fill(it.resXprime);
249  histos.x.normed->Fill(it.resXprime/it.resXprimeErr);
250  }
251  if(it.resYprimeErr != 0 && histos.y.base) {
252  histos.y.base->Fill(it.resYprime);
253  histos.y.normed->Fill(it.resYprime/it.resYprimeErr);
254  }
255  }
256 }
257 
258 
259 
261 
T getParameter(std::string const &) const
virtual void analyze(const edm::Event &, const edm::EventSetup &)
unsigned int tibLayer(const DetId &id) const
void dqmBeginRun(const edm::Run &, const edm::EventSetup &)
unsigned long long m_cacheID_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
unsigned int pxfDisk(const DetId &id) const
std::pair< std::string, int32_t > findSubdetAndLayer(uint32_t ModuleID, const TrackerTopology *tTopo)
bool isBarrel(GeomDetEnumerators::SubDetector m)
unsigned int tidWheel(const DetId &id) const
void fillHitQuantities(const Trajectory *trajectory, std::vector< AVHitStruct > &v_avhitout)
Provides a code based selection for trigger and DCS information in order to have no failing filters i...
void createMEs(DQMStore::IBooker &, const edm::EventSetup &)
void setDetectorFolder(uint32_t rawdetid, const TrackerTopology *tTopo)
TrackerValidationVariables avalidator_
int iEvent
Definition: GenABIO.cc:230
vector< ParameterSet > Parameters
bool accept(const edm::Event &event, const edm::EventSetup &setup)
To be called from analyze/filter() methods.
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:115
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
virtual void endRun(const edm::Run &, const edm::EventSetup &)
virtual void beginJob(void)
unsigned int pxbLayer(const DetId &id) const
Definition: DetId.h:18
void setLayerFolder(uint32_t rawdetid, const TrackerTopology *tTopo, int32_t layer=0, bool ring_flag=0)
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
const T & get() const
Definition: EventSetup.h:56
T const * product() const
Definition: ESHandle.h:86
void save(const std::string &filename, const std::string &path="", const std::string &pattern="", const std::string &rewrite="", const uint32_t run=0, const uint32_t lumi=0, SaveReferenceTag ref=SaveWithReference, int minStatus=dqm::qstatus::STATUS_OK, const std::string &fileupdate="RECREATE", const bool resetMEsAfterWriting=false)
Definition: DQMStore.cc:2603
GenericTriggerEventFlag * genTriggerEventFlag_
bool isPixel(HitType hitType)
MonitorTrackResiduals(const edm::ParameterSet &)
unsigned int pxfSide(const DetId &id) const
void initRun(const edm::Run &run, const edm::EventSetup &setup)
To be called from beginRun() methods.
unsigned int tecWheel(const DetId &id) const
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
unsigned int tobLayer(const DetId &id) const
Definition: Run.h:43
unsigned int tecSide(const DetId &id) const