CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiStripMonitorTrack.cc
Go to the documentation of this file.
2 
6 
19 
21 
23 #include "TMath.h"
24 
26  conf_(conf),
27  tracksCollection_in_EventTree(true),
28  firstEvent(-1),
29  genTriggerEventFlag_(new GenericTriggerEventFlag(conf, consumesCollector(), *this))
30 {
31  Cluster_src_ = conf.getParameter<edm::InputTag>("Cluster_src");
32  Mod_On_ = conf.getParameter<bool>("Mod_On");
33  Trend_On_ = conf.getParameter<bool>("Trend_On");
34  TkHistoMap_On_ = conf.getParameter<bool>("TkHistoMap_On");
35 
36  TrackProducer_ = conf_.getParameter<std::string>("TrackProducer");
37  TrackLabel_ = conf_.getParameter<std::string>("TrackLabel");
38 
39  topFolderName_ = conf_.getParameter<std::string>("TopFolderName");
40 
41  clusterToken_ = consumes<edmNew::DetSetVector<SiStripCluster> >(Cluster_src_);
42  trackToken_ = consumes<reco::TrackCollection>(edm::InputTag(TrackProducer_,TrackLabel_) );
43  trackTrajToken_ = consumes<TrajTrackAssociationCollection>(edm::InputTag(TrackProducer_,TrackLabel_) );
44 
45  // cluster quality conditions
46  edm::ParameterSet cluster_condition = conf_.getParameter<edm::ParameterSet>("ClusterConditions");
47  applyClusterQuality_ = cluster_condition.getParameter<bool>("On");
48  sToNLowerLimit_ = cluster_condition.getParameter<double>("minStoN");
49  sToNUpperLimit_ = cluster_condition.getParameter<double>("maxStoN");
50  widthLowerLimit_ = cluster_condition.getParameter<double>("minWidth");
51  widthUpperLimit_ = cluster_condition.getParameter<double>("maxWidth");
52 
53 
54  // Create DCS Status
55  bool checkDCS = conf_.getParameter<bool>("UseDCSFiltering");
56  if (checkDCS) dcsStatus_ = new SiStripDCSStatus(consumesCollector());
57  else dcsStatus_ = 0;
58 }
59 
60 //------------------------------------------------------------------------
62  if (dcsStatus_) delete dcsStatus_;
64 }
65 
66 //------------------------------------------------------------------------
68 {
69  //get geom
71  LogDebug("SiStripMonitorTrack") << "[SiStripMonitorTrack::beginRun] There are "<<tkgeom_->detUnits().size() <<" detectors instantiated in the geometry" << std::endl;
73 
74 
75  // Initialize the GenericTriggerEventFlag
77 }
78 
79 //------------------------------------------------------------------------
81 {
82  //Retrieve tracker topology from geometry
84  es.get<TrackerTopologyRcd>().get(tTopoHandle);
85  const TrackerTopology* const tTopo = tTopoHandle.product();
86  book(ibooker , tTopo);
87 }
88 
89 // ------------ method called to produce the data ------------
91 {
92  // Filter out events if DCS checking is requested
93  if (dcsStatus_ && !dcsStatus_->getStatus(e,es)) return;
94 
95  // Filter out events if Trigger Filtering is requested
96  if (genTriggerEventFlag_->on()&& ! genTriggerEventFlag_->accept( e, es) ) return;
97 
98  //initialization of global quantities
99  LogDebug("SiStripMonitorTrack") << "[SiStripMonitorTrack::analyse] " << "Run " << e.id().run() << " Event " << e.id().event() << std::endl;
100  eventNb = e.id().event();
101  vPSiStripCluster.clear();
102 
103  iLumisection = e.orbitNumber()/262144.0;
104 
105  // initialise # of clusters
106  for (std::map<std::string, SubDetMEs>::iterator iSubDet = SubDetMEsMap.begin();
107  iSubDet != SubDetMEsMap.end(); iSubDet++) {
108  iSubDet->second.totNClustersOnTrack = 0;
109  iSubDet->second.totNClustersOffTrack = 0;
110  }
111 
112  //Perform track study
113  trackStudy(e, es);
114 
115  //Perform Cluster Study (irrespectively to tracks)
116 
117  AllClusters(e, es); //analyzes the off Track Clusters
118 
119  //Summary Counts of clusters
120  std::map<std::string, MonitorElement*>::iterator iME;
121  std::map<std::string, LayerMEs>::iterator iLayerME;
122 
123  if (Trend_On_) {
124  // for (std::map<std::string, SubDetMEs>::iterator iSubDet = SubDetMEsMap.begin(), iterEnd=SubDetMEsMaps.end();
125  // iSubDet != iterEnd; ++iSubDet) {
126  for (auto const &iSubDet : SubDetMEsMap) {
127  SubDetMEs subdet_mes = iSubDet.second;
128  if (subdet_mes.totNClustersOnTrack > 0) {
129  fillME(subdet_mes.nClustersOnTrack, subdet_mes.totNClustersOnTrack);
130  }
131  fillME(subdet_mes.nClustersOffTrack, subdet_mes.totNClustersOffTrack);
134  }
135  } else {
136  for (auto const &iSubDet : SubDetMEsMap) {
137  SubDetMEs subdet_mes = iSubDet.second;
138  if (subdet_mes.totNClustersOnTrack > 0) {
139  fillME(subdet_mes.nClustersOnTrack, subdet_mes.totNClustersOnTrack);
140  }
141  fillME(subdet_mes.nClustersOffTrack, subdet_mes.totNClustersOffTrack);
142  }
143  }
144 }
145 
146 //------------------------------------------------------------------------
148 {
149 
150  SiStripFolderOrganizer folder_organizer;
151  folder_organizer.setSiStripFolderName(topFolderName_);
152  //******** TkHistoMaps
153  if (TkHistoMap_On_) {
154  tkhisto_StoNCorrOnTrack = new TkHistoMap(ibooker , topFolderName_ ,"TkHMap_StoNCorrOnTrack", 0.0,true);
155  tkhisto_NumOnTrack = new TkHistoMap(ibooker , topFolderName_, "TkHMap_NumberOfOnTrackCluster", 0.0,true);
156  tkhisto_NumOffTrack = new TkHistoMap(ibooker , topFolderName_, "TkHMap_NumberOfOfffTrackCluster",0.0,true);
157  }
158  //******** TkHistoMaps
159 
160  std::vector<uint32_t> vdetId_;
161  SiStripDetCabling_->addActiveDetectorsRawIds(vdetId_);
162  const char* tec = "TEC";
163  const char* tid = "TID";
164  //Histos for each detector, layer and module
165  SiStripHistoId hidmanager;
166 
167  if(Mod_On_) {
168  for (std::vector<uint32_t>::const_iterator detid_iter=vdetId_.begin(),detid_end=vdetId_.end();detid_iter!=detid_end;++detid_iter){ //loop on all the active detid
169  uint32_t detid = *detid_iter;
170 
171  if (detid < 1){
172  edm::LogError("SiStripMonitorTrack")<< "[" <<__PRETTY_FUNCTION__ << "] invalid detid " << detid<< std::endl;
173  continue;
174  }
175 
176 
177  //std::string name;
178 
179  // book Layer and RING plots
180  std::pair<std::string,int32_t> det_layer_pair = folder_organizer.GetSubDetAndLayer(detid,tTopo,false);
181  /*
182  std::string thickness;
183  std::pair<std::string,int32_t> det_layer_pair_test = folder_organizer.GetSubDetAndLayerThickness(detid,tTopo,thickness);
184  std::cout << "[SiStripMonitorTrack::book] det_layer_pair " << det_layer_pair.first << " " << det_layer_pair.second << " " << thickness << std::endl;
185  */
186 
187  std::string layer_id = hidmanager.getSubdetid(detid, tTopo, false);
188 
189  std::map<std::string, LayerMEs>::iterator iLayerME = LayerMEsMap.find(layer_id);
190  if(iLayerME==LayerMEsMap.end()){
191  folder_organizer.setLayerFolder(detid, tTopo, det_layer_pair.second, false);
192  bookLayerMEs(ibooker , detid, layer_id);
193  }
194 
195  const char* subdet = det_layer_pair.first.c_str();
196  if ( std::strstr(subdet, tec) != NULL || std::strstr(subdet, tid) != NULL ) {
197  std::string ring_id = hidmanager.getSubdetid(detid, tTopo, true);
198  std::map<std::string, RingMEs>::iterator iRingME = RingMEsMap.find(ring_id);
199  if(iRingME==RingMEsMap.end()){
200  std::pair<std::string,int32_t> det_ring_pair = folder_organizer.GetSubDetAndLayer(detid,tTopo,true);
201  folder_organizer.setLayerFolder(detid, tTopo, det_ring_pair.second, true);
202  bookRingMEs(ibooker , detid, ring_id);
203  }
204  }
205 
206  // book sub-detector plots
207  std::pair<std::string,std::string> sdet_pair = folder_organizer.getSubDetFolderAndTag(detid, tTopo);
208  if (SubDetMEsMap.find(sdet_pair.second) == SubDetMEsMap.end()){
209  ibooker.setCurrentFolder(sdet_pair.first);
210  bookSubDetMEs(ibooker , sdet_pair.second);
211  }
212  // book module plots
213  folder_organizer.setDetectorFolder(detid,tTopo);
214  bookModMEs(ibooker , *detid_iter);
215  }//end loop on detectors detid
216  } else {
217  for (std::vector<uint32_t>::const_iterator detid_iter=vdetId_.begin(),detid_end=vdetId_.end();detid_iter!=detid_end;++detid_iter){ //loop on all the active detid
218  uint32_t detid = *detid_iter;
219 
220  if (detid < 1){
221  edm::LogError("SiStripMonitorTrack")<< "[" <<__PRETTY_FUNCTION__ << "] invalid detid " << detid<< std::endl;
222  continue;
223  }
224 
225 
226  //std::string name;
227 
228  // book Layer and RING plots
229  std::pair<std::string,int32_t> det_layer_pair = folder_organizer.GetSubDetAndLayer(detid,tTopo,false);
230  /*
231  std::string thickness;
232  std::pair<std::string,int32_t> det_layer_pair_test = folder_organizer.GetSubDetAndLayerThickness(detid,tTopo,thickness);
233  std::cout << "[SiStripMonitorTrack::book] det_layer_pair " << det_layer_pair.first << " " << det_layer_pair.second << " " << thickness << std::endl;
234  */
235 
236  std::string layer_id = hidmanager.getSubdetid(detid, tTopo, false);
237 
238  std::map<std::string, LayerMEs>::iterator iLayerME = LayerMEsMap.find(layer_id);
239  if(iLayerME==LayerMEsMap.end()){
240  folder_organizer.setLayerFolder(detid, tTopo, det_layer_pair.second, false);
241  bookLayerMEs(ibooker , detid, layer_id);
242  }
243 
244  const char* subdet = det_layer_pair.first.c_str();
245  if ( std::strstr(subdet, tec) != NULL || std::strstr(subdet, tid) != NULL ) {
246  std::string ring_id = hidmanager.getSubdetid(detid, tTopo, true);
247  std::map<std::string, RingMEs>::iterator iRingME = RingMEsMap.find(ring_id);
248  if(iRingME==RingMEsMap.end()){
249  std::pair<std::string,int32_t> det_ring_pair = folder_organizer.GetSubDetAndLayer(detid,tTopo,true);
250  folder_organizer.setLayerFolder(detid, tTopo, det_ring_pair.second, true);
251  bookRingMEs(ibooker , detid, ring_id);
252  }
253  }
254 
255  // book sub-detector plots
256  std::pair<std::string,std::string> sdet_pair = folder_organizer.getSubDetFolderAndTag(detid, tTopo);
257  if (SubDetMEsMap.find(sdet_pair.second) == SubDetMEsMap.end()){
258  ibooker.setCurrentFolder(sdet_pair.first);
259  bookSubDetMEs(ibooker , sdet_pair.second);
260  }
261  }//end loop on detectors detid
262  }
263 }
264 
265 //--------------------------------------------------------------------------------
266 void SiStripMonitorTrack::bookModMEs(DQMStore::IBooker & ibooker , const uint32_t id)//Histograms at MODULE level
267 {
268  std::string name = "det";
269  SiStripHistoId hidmanager;
270  std::string hid = hidmanager.createHistoId("",name,id);
271  std::map<std::string, ModMEs>::iterator iModME = ModMEsMap.find(hid);
272  if(iModME==ModMEsMap.end()){
273  ModMEs theModMEs;
274  theModMEs.ClusterStoNCorr = 0;
275  theModMEs.ClusterCharge = 0;
276  theModMEs.ClusterChargeCorr = 0;
277  theModMEs.ClusterWidth = 0;
278  theModMEs.ClusterPos = 0;
279  theModMEs.ClusterPGV = 0;
280  theModMEs.ClusterChargePerCMfromTrack = 0;
281  theModMEs.ClusterChargePerCMfromOrigin = 0;
282 
283  // Cluster Width
284  theModMEs.ClusterWidth=bookME1D(ibooker , "TH1ClusterWidth", hidmanager.createHistoId("ClusterWidth_OnTrack",name,id).c_str());
285  ibooker.tag(theModMEs.ClusterWidth,id);
286  // Cluster Charge
287  theModMEs.ClusterCharge=bookME1D(ibooker , "TH1ClusterCharge", hidmanager.createHistoId("ClusterCharge_OnTrack",name,id).c_str());
288  ibooker.tag(theModMEs.ClusterCharge,id);
289  // Cluster Charge Corrected
290  theModMEs.ClusterChargeCorr=bookME1D(ibooker , "TH1ClusterChargeCorr", hidmanager.createHistoId("ClusterChargeCorr_OnTrack",name,id).c_str());
291  ibooker.tag(theModMEs.ClusterChargeCorr,id);
292  // Cluster StoN Corrected
293  theModMEs.ClusterStoNCorr=bookME1D(ibooker , "TH1ClusterStoNCorrMod", hidmanager.createHistoId("ClusterStoNCorr_OnTrack",name,id).c_str());
294  ibooker.tag(theModMEs.ClusterStoNCorr,id);
295  // Cluster Position
296  short total_nr_strips = SiStripDetCabling_->nApvPairs(id) * 2 * 128;
297  theModMEs.ClusterPos=ibooker.book1D(hidmanager.createHistoId("ClusterPosition_OnTrack",name,id).c_str(),hidmanager.createHistoId("ClusterPosition_OnTrack",name,id).c_str(),total_nr_strips,0.5,total_nr_strips+0.5);
298  ibooker.tag(theModMEs.ClusterPos,id);
299  // Cluster PGV
300  theModMEs.ClusterPGV=bookMEProfile(ibooker , "TProfileClusterPGV", hidmanager.createHistoId("PGV_OnTrack",name,id).c_str());
301  ibooker.tag(theModMEs.ClusterPGV,id);
302  // Cluster Charge per cm
303  theModMEs.ClusterChargePerCMfromTrack = bookME1D(ibooker , "TH1ClusterChargePerCM", hidmanager.createHistoId("ClusterChargePerCMfromTrack",name,id).c_str());
304  ibooker.tag(theModMEs.ClusterChargePerCMfromTrack,id);
305 
306  theModMEs.ClusterChargePerCMfromOrigin = bookME1D(ibooker , "TH1ClusterChargePerCM", hidmanager.createHistoId("ClusterChargePerCMfromOrigin",name,id).c_str());
307  ibooker.tag(theModMEs.ClusterChargePerCMfromOrigin,id);
308 
309  ModMEsMap[hid]=theModMEs;
310  }
311 }
312 
314 
315  MonitorElement* me = NULL;
316  bool view = false;
317  view = (conf_.getParameter<edm::ParameterSet>(histoParameters.c_str())).getParameter<bool>(viewParameter.c_str());
318  if ( id.find("TEC") == std::string::npos && id.find("TID") == std::string::npos ) {
319  me = bookME1D(ibooker , histoParameters.c_str(), histoName.c_str());
320  } else {
321  if (view) {
322  // histoName = histoName + "__" + thickness;
323  me = bookME1D(ibooker , histoParameters.c_str(), histoName.c_str());
324  }
325  }
326  return me;
327 }
328 
329 //
330 // -- Book Layer Level Histograms and Trend plots
331 //
332 //------------------------------------------------------------------------
333 void SiStripMonitorTrack::bookLayerMEs(DQMStore::IBooker & ibooker , const uint32_t mod_id, std::string& layer_id)
334 {
335  std::string name = "layer";
336  std::string view = "layerView";
337  std::string hname;
338  std::string hpar;
339  SiStripHistoId hidmanager;
340 
341  LayerMEs theLayerMEs;
342  theLayerMEs.ClusterStoNCorrOnTrack = 0;
343  theLayerMEs.ClusterChargeCorrOnTrack = 0;
344  theLayerMEs.ClusterChargeOnTrack = 0;
345  theLayerMEs.ClusterChargeOffTrack = 0;
346  theLayerMEs.ClusterNoiseOnTrack = 0;
347  theLayerMEs.ClusterNoiseOffTrack = 0;
348  theLayerMEs.ClusterWidthOnTrack = 0;
349  theLayerMEs.ClusterWidthOffTrack = 0;
350  theLayerMEs.ClusterPosOnTrack = 0;
351  theLayerMEs.ClusterPosOffTrack = 0;
352  theLayerMEs.ClusterChargePerCMfromTrack = 0;
353  theLayerMEs.ClusterChargePerCMfromOriginOnTrack = 0;
354  theLayerMEs.ClusterChargePerCMfromOriginOffTrack = 0;
355 
356  // Signal/Noise (w/ cluster charge corrected)
357  hname = hidmanager.createHistoLayer("Summary_ClusterStoNCorr",name,layer_id,"OnTrack");
358  hpar = "TH1ClusterStoNCorr";
359  theLayerMEs.ClusterStoNCorrOnTrack = handleBookMEs(ibooker,view,layer_id,hpar,hname);
360 
361  // Cluster Charge Corrected
362  hname = hidmanager.createHistoLayer("Summary_ClusterChargeCorr",name,layer_id,"OnTrack");
363  hpar = "TH1ClusterChargeCorr";
364  theLayerMEs.ClusterChargeCorrOnTrack = handleBookMEs(ibooker,view,layer_id,hpar,hname);
365 
366  // Cluster Charge (On and Off Track)
367  hname = hidmanager.createHistoLayer("Summary_ClusterCharge",name,layer_id,"OnTrack");
368  hpar = "TH1ClusterCharge";
369  theLayerMEs.ClusterChargeOnTrack = handleBookMEs(ibooker,view,layer_id,hpar,hname);
370 
371  hname = hidmanager.createHistoLayer("Summary_ClusterCharge",name,layer_id,"OffTrack");
372  hpar = "TH1ClusterCharge";
373  theLayerMEs.ClusterChargeOffTrack = handleBookMEs(ibooker,view,layer_id,hpar,hname);
374 
375  // Cluster Noise (On and Off Track)
376  hname = hidmanager.createHistoLayer("Summary_ClusterNoise",name,layer_id,"OnTrack");
377  hpar = "TH1ClusterNoise";
378  theLayerMEs.ClusterNoiseOnTrack = handleBookMEs(ibooker,view,layer_id,hpar,hname);
379 
380  hname = hidmanager.createHistoLayer("Summary_ClusterNoise",name,layer_id,"OffTrack");
381  hpar = "TH1ClusterNoise";
382  theLayerMEs.ClusterNoiseOffTrack = handleBookMEs(ibooker,view,layer_id,hpar,hname);
383 
384  // Cluster Width (On and Off Track)
385  hname = hidmanager.createHistoLayer("Summary_ClusterWidth",name,layer_id,"OnTrack");
386  hpar = "TH1ClusterWidth";
387  theLayerMEs.ClusterWidthOnTrack = handleBookMEs(ibooker,view,layer_id,hpar,hname);
388 
389  hname = hidmanager.createHistoLayer("Summary_ClusterWidth",name,layer_id,"OffTrack");
390  hpar = "TH1ClusterWidth";
391  theLayerMEs.ClusterWidthOffTrack = handleBookMEs(ibooker,view,layer_id,hpar,hname);
392 
393  //Cluster Position
394  short total_nr_strips = SiStripDetCabling_->nApvPairs(mod_id) * 2 * 128;
395  if (layer_id.find("TEC") != std::string::npos) total_nr_strips = 3 * 2 * 128;
396 
397  hname = hidmanager.createHistoLayer("Summary_ClusterPosition",name,layer_id,"OnTrack");
398  theLayerMEs.ClusterPosOnTrack = ibooker.book1D(hname, hname, total_nr_strips, 0.5,total_nr_strips+0.5);
399 
400  hname = hidmanager.createHistoLayer("Summary_ClusterPosition",name,layer_id,"OffTrack");
401  theLayerMEs.ClusterPosOffTrack = ibooker.book1D(hname, hname, total_nr_strips, 0.5,total_nr_strips+0.5);
402 
403  // dQ/dx
404  hname = hidmanager.createHistoLayer("Summary_ClusterChargePerCMfromTrack",name,layer_id,"");
405  hpar = "TH1ClusterChargePerCM";
406  theLayerMEs.ClusterChargePerCMfromTrack = handleBookMEs(ibooker,view,layer_id,hpar,hname);
407 
408  hname = hidmanager.createHistoLayer("Summary_ClusterChargePerCMfromOrigin",name,layer_id,"OnTrack");
409  hpar = "TH1ClusterChargePerCM";
410  theLayerMEs.ClusterChargePerCMfromOriginOnTrack = handleBookMEs(ibooker,view,layer_id,hpar,hname);
411 
412  hname = hidmanager.createHistoLayer("Summary_ClusterChargePerCMfromOrigin",name,layer_id,"OffTrack");
413  hpar = "TH1ClusterChargePerCM";
414  theLayerMEs.ClusterChargePerCMfromOriginOffTrack = handleBookMEs(ibooker,view,layer_id,hpar,hname);
415 
416  //bookeeping
417  LayerMEsMap[layer_id]=theLayerMEs;
418 
419 }
420 
422 {
423 
424  std::string name = "ring";
425  std::string view = "ringView";
426  std::string hname;
427  std::string hpar;
428  SiStripHistoId hidmanager;
429 
430  RingMEs theRingMEs;
431  theRingMEs.ClusterStoNCorrOnTrack = 0;
432  theRingMEs.ClusterChargeCorrOnTrack = 0;
433  theRingMEs.ClusterChargeOnTrack = 0;
434  theRingMEs.ClusterChargeOffTrack = 0;
435  theRingMEs.ClusterNoiseOnTrack = 0;
436  theRingMEs.ClusterNoiseOffTrack = 0;
437  theRingMEs.ClusterWidthOnTrack = 0;
438  theRingMEs.ClusterWidthOffTrack = 0;
439  theRingMEs.ClusterChargePerCMfromTrack = 0;
442 
443  hname = hidmanager.createHistoLayer("Summary_ClusterStoNCorr",name,ring_id,"OnTrack");
444  hpar = "TH1ClusterStoNCorr";
445  theRingMEs.ClusterStoNCorrOnTrack = handleBookMEs(ibooker,view,ring_id,hpar,hname);
446 
447  // Cluster Charge Corrected
448  hname = hidmanager.createHistoLayer("Summary_ClusterChargeCorr",name,ring_id,"OnTrack");
449  hpar = "TH1ClusterChargeCorr";
450  theRingMEs.ClusterChargeCorrOnTrack = handleBookMEs(ibooker,view,ring_id,hpar,hname);
451 
452  // Cluster Charge (On and Off Track)
453  hname = hidmanager.createHistoLayer("Summary_ClusterCharge",name,ring_id,"OnTrack");
454  hpar = "TH1ClusterCharge";
455  theRingMEs.ClusterChargeOnTrack = handleBookMEs(ibooker,view,ring_id,hpar,hname);
456 
457  hname = hidmanager.createHistoLayer("Summary_ClusterCharge",name,ring_id,"OffTrack");
458  hpar = "TH1ClusterCharge";
459  theRingMEs.ClusterChargeOffTrack = handleBookMEs(ibooker,view,ring_id,hpar,hname);
460 
461  // Cluster Noise (On and Off Track)
462  hname = hidmanager.createHistoLayer("Summary_ClusterNoise",name,ring_id,"OnTrack");
463  hpar = "TH1ClusterNoise";
464  theRingMEs.ClusterNoiseOnTrack = handleBookMEs(ibooker,view,ring_id,hpar,hname);
465 
466  hname = hidmanager.createHistoLayer("Summary_ClusterNoise",name,ring_id,"OffTrack");
467  hpar = "TH1ClusterNoise";
468  theRingMEs.ClusterNoiseOffTrack = handleBookMEs(ibooker,view,ring_id,hpar,hname);
469 
470  // Cluster Width (On and Off Track)
471  hname = hidmanager.createHistoLayer("Summary_ClusterWidth",name,ring_id,"OnTrack");
472  hpar = "TH1ClusterWidth";
473  theRingMEs.ClusterWidthOnTrack = handleBookMEs(ibooker,view,ring_id,hpar,hname);
474 
475  hname = hidmanager.createHistoLayer("Summary_ClusterWidth",name,ring_id,"OffTrack");
476  hpar = "TH1ClusterWidth";
477  theRingMEs.ClusterWidthOffTrack = handleBookMEs(ibooker,view,ring_id,hpar,hname);
478 
479  // dQ/dx
480  hname = hidmanager.createHistoLayer("Summary_ClusterChargePerCMfromTrack",name,ring_id,"");
481  hpar = "TH1ClusterChargePerCM";
482  theRingMEs.ClusterChargePerCMfromTrack = handleBookMEs(ibooker,view,ring_id,hpar,hname);
483 
484  hname = hidmanager.createHistoLayer("Summary_ClusterChargePerCMfromOrigin",name,ring_id,"OnTrack");
485  hpar = "TH1ClusterChargePerCM";
486  theRingMEs.ClusterChargePerCMfromOriginOnTrack = handleBookMEs(ibooker,view,ring_id,hpar,hname);
487 
488  hname = hidmanager.createHistoLayer("Summary_ClusterChargePerCMfromOrigin",name,ring_id,"OffTrack");
489  hpar = "TH1ClusterChargePerCM";
490  theRingMEs.ClusterChargePerCMfromOriginOffTrack = handleBookMEs(ibooker,view,ring_id,hpar,hname);
491 
492  //bookeeping
493  RingMEsMap[ring_id]=theRingMEs;
494 
495 }
496 //------------------------------------------------------------------------
497 //
498 // -- Book Histograms at Sub-Detector Level
499 //
501 
503  subdet_tag = "__" + name;
504  std::string completeName;
505  std::string axisName;
506 
507  SubDetMEs theSubDetMEs;
508  theSubDetMEs.totNClustersOnTrack = 0;
509  theSubDetMEs.totNClustersOffTrack = 0;
510  theSubDetMEs.nClustersOnTrack = 0;
511  theSubDetMEs.nClustersTrendOnTrack = 0;
512  theSubDetMEs.nClustersOffTrack = 0;
513  theSubDetMEs.nClustersTrendOffTrack = 0;
514  theSubDetMEs.ClusterStoNCorrOnTrack = 0;
515  theSubDetMEs.ClusterChargeOnTrack = 0;
516  theSubDetMEs.ClusterChargeOffTrack = 0;
517  theSubDetMEs.ClusterStoNOffTrack = 0;
518  theSubDetMEs.ClusterChargePerCMfromTrack = 0;
519  theSubDetMEs.ClusterChargePerCMfromOriginOnTrack = 0;
520  theSubDetMEs.ClusterChargePerCMfromOriginOffTrack = 0;
521 
522  // TotalNumber of Cluster OnTrack
523  completeName = "Summary_TotalNumberOfClusters_OnTrack" + subdet_tag;
524  axisName = "Number of on-track clusters in " + name;
525  theSubDetMEs.nClustersOnTrack = bookME1D(ibooker , "TH1nClustersOn", completeName.c_str());
526  theSubDetMEs.nClustersOnTrack->setAxisTitle(axisName.c_str());
527  theSubDetMEs.nClustersOnTrack->getTH1()->StatOverflows(kTRUE);
528 
529  // TotalNumber of Cluster OffTrack
530  completeName = "Summary_TotalNumberOfClusters_OffTrack" + subdet_tag;
531  axisName = "Number of off-track clusters in " + name;
532  theSubDetMEs.nClustersOffTrack = bookME1D(ibooker , "TH1nClustersOff", completeName.c_str());
533  theSubDetMEs.nClustersOffTrack->setAxisTitle(axisName.c_str());
534  theSubDetMEs.nClustersOffTrack->getTH1()->StatOverflows(kTRUE);
535 
536  // Cluster StoN On Track
537  completeName = "Summary_ClusterStoNCorr_OnTrack" + subdet_tag;
538  theSubDetMEs.ClusterStoNCorrOnTrack = bookME1D(ibooker , "TH1ClusterStoNCorr", completeName.c_str());
539 
540  // Cluster Charge On Track
541  completeName = "Summary_ClusterCharge_OnTrack" + subdet_tag;
542  theSubDetMEs.ClusterChargeOnTrack=bookME1D(ibooker , "TH1ClusterCharge", completeName.c_str());
543 
544  // Cluster Charge Off Track
545  completeName = "Summary_ClusterCharge_OffTrack" + subdet_tag;
546  theSubDetMEs.ClusterChargeOffTrack=bookME1D(ibooker , "TH1ClusterCharge", completeName.c_str());
547 
548  // Cluster Charge StoN Off Track
549  completeName = "Summary_ClusterStoN_OffTrack" + subdet_tag;
550  theSubDetMEs.ClusterStoNOffTrack = bookME1D(ibooker , "TH1ClusterStoN", completeName.c_str());
551 
552  // cluster charge per cm on track
553  completeName = "Summary_ClusterChargePerCMfromTrack" + subdet_tag;
554  theSubDetMEs.ClusterChargePerCMfromTrack=bookME1D(ibooker , "TH1ClusterChargePerCM", completeName.c_str());
555 
556  // cluster charge per cm on track
557  completeName = "Summary_ClusterChargePerCMfromOrigin_OnTrack" + subdet_tag;
558  theSubDetMEs.ClusterChargePerCMfromOriginOnTrack=bookME1D(ibooker , "TH1ClusterChargePerCM", completeName.c_str());
559 
560  // cluster charge per cm off track
561  completeName = "Summary_ClusterChargePerCMfromOrigin_OffTrack" + subdet_tag;
562  theSubDetMEs.ClusterChargePerCMfromOriginOffTrack=bookME1D(ibooker , "TH1ClusterChargePerCM", completeName.c_str());
563 
564  if(Trend_On_){
565  // TotalNumber of Cluster
566  completeName = "Trend_TotalNumberOfClusters_OnTrack" + subdet_tag;
567  theSubDetMEs.nClustersTrendOnTrack = bookMETrend(ibooker , completeName.c_str());
568  completeName = "Trend_TotalNumberOfClusters_OffTrack" + subdet_tag;
569  theSubDetMEs.nClustersTrendOffTrack = bookMETrend(ibooker , completeName.c_str());
570  }
571 
572  //bookeeping
573  SubDetMEsMap[name]=theSubDetMEs;
574 
575 }
576 //--------------------------------------------------------------------------------
577 
578 inline MonitorElement* SiStripMonitorTrack::bookME1D(DQMStore::IBooker & ibooker , const char* ParameterSetLabel, const char* HistoName)
579 {
580  Parameters = conf_.getParameter<edm::ParameterSet>(ParameterSetLabel);
581  return ibooker.book1D(HistoName,HistoName,
582  Parameters.getParameter<int32_t>("Nbinx"),
583  Parameters.getParameter<double>("xmin"),
584  Parameters.getParameter<double>("xmax")
585  );
586 }
587 
588 //--------------------------------------------------------------------------------
589 inline MonitorElement* SiStripMonitorTrack::bookME2D(DQMStore::IBooker & ibooker , const char* ParameterSetLabel, const char* HistoName)
590 {
591  Parameters = conf_.getParameter<edm::ParameterSet>(ParameterSetLabel);
592  return ibooker.book2D(HistoName,HistoName,
593  Parameters.getParameter<int32_t>("Nbinx"),
594  Parameters.getParameter<double>("xmin"),
595  Parameters.getParameter<double>("xmax"),
596  Parameters.getParameter<int32_t>("Nbiny"),
597  Parameters.getParameter<double>("ymin"),
598  Parameters.getParameter<double>("ymax")
599  );
600 }
601 
602 //--------------------------------------------------------------------------------
603 inline MonitorElement* SiStripMonitorTrack::bookME3D(DQMStore::IBooker & ibooker , const char* ParameterSetLabel, const char* HistoName)
604 {
605  Parameters = conf_.getParameter<edm::ParameterSet>(ParameterSetLabel);
606  return ibooker.book3D(HistoName,HistoName,
607  Parameters.getParameter<int32_t>("Nbinx"),
608  Parameters.getParameter<double>("xmin"),
609  Parameters.getParameter<double>("xmax"),
610  Parameters.getParameter<int32_t>("Nbiny"),
611  Parameters.getParameter<double>("ymin"),
612  Parameters.getParameter<double>("ymax"),
613  Parameters.getParameter<int32_t>("Nbinz"),
614  Parameters.getParameter<double>("zmin"),
615  Parameters.getParameter<double>("zmax")
616  );
617 }
618 
619 //--------------------------------------------------------------------------------
620 inline MonitorElement* SiStripMonitorTrack::bookMEProfile(DQMStore::IBooker & ibooker , const char* ParameterSetLabel, const char* HistoName)
621 {
622  Parameters = conf_.getParameter<edm::ParameterSet>(ParameterSetLabel);
623  return ibooker.bookProfile(HistoName,HistoName,
624  Parameters.getParameter<int32_t>("Nbinx"),
625  Parameters.getParameter<double>("xmin"),
626  Parameters.getParameter<double>("xmax"),
627  Parameters.getParameter<int32_t>("Nbiny"),
628  Parameters.getParameter<double>("ymin"),
629  Parameters.getParameter<double>("ymax"),
630  "" );
631 }
632 
633 //--------------------------------------------------------------------------------
635 {
636  edm::ParameterSet ParametersTrend = conf_.getParameter<edm::ParameterSet>("Trending");
637  MonitorElement* me = ibooker.bookProfile(HistoName,HistoName,
638  ParametersTrend.getParameter<int32_t>("Nbins"),
639  ParametersTrend.getParameter<double>("xmin"),
640  ParametersTrend.getParameter<double>("xmax"),
641  0 , 0 , "" );
642  if (me->kind() == MonitorElement::DQM_KIND_TPROFILE) me->getTH1()->SetCanExtend(TH1::kAllAxes);
643 
644  if(!me) return me;
645  me->setAxisTitle("Lumisection",1);
646  return me;
647 }
648 
649 //------------------------------------------------------------------------------------------
650 void SiStripMonitorTrack::trajectoryStudy(const edm::Ref<std::vector<Trajectory> > traj, const edm::EventSetup& es) {
651  const std::vector<TrajectoryMeasurement> & measurements = traj->measurements();
652  for(std::vector<TrajectoryMeasurement>::const_iterator traj_mes_iterator= measurements.begin(), traj_mes_end=measurements.end();
653  traj_mes_iterator!=traj_mes_end;++traj_mes_iterator){//loop on measurements
654  //trajectory local direction and position on detector
655  LocalVector statedirection;
656 
657  TrajectoryStateOnSurface updatedtsos=traj_mes_iterator->updatedState();
658  ConstRecHitPointer ttrh=traj_mes_iterator->recHit();
659 
660  if (!ttrh->isValid()) continue;
661 
662  const ProjectedSiStripRecHit2D* projhit = dynamic_cast<const ProjectedSiStripRecHit2D*>( ttrh->hit() );
663  const SiStripMatchedRecHit2D* matchedhit = dynamic_cast<const SiStripMatchedRecHit2D*>( ttrh->hit() );
664  const SiStripRecHit2D* hit2D = dynamic_cast<const SiStripRecHit2D*>( ttrh->hit() );
665  const SiStripRecHit1D* hit1D = dynamic_cast<const SiStripRecHit1D*>( ttrh->hit() );
666 
667  // RecHitType type=Single;
668 
669  if(matchedhit){
670  LogTrace("SiStripMonitorTrack")<<"\nMatched recHit found"<< std::endl;
671  // type=Matched;
672 
673  const GluedGeomDet * gdet=static_cast<const GluedGeomDet *>(tkgeom_->idToDet(matchedhit->geographicalId()));
674  GlobalVector gtrkdirup=gdet->toGlobal(updatedtsos.localMomentum());
675  //mono side
676  const GeomDetUnit * monodet=gdet->monoDet();
677  statedirection=monodet->toLocal(gtrkdirup);
678  SiStripRecHit2D m = matchedhit->monoHit();
679  // if(statedirection.mag() != 0) RecHitInfo<SiStripRecHit2D>(&m,statedirection,trackref,es);
680  if(statedirection.mag()) RecHitInfo<SiStripRecHit2D>(&m,statedirection,es);
681  //stereo side
682  const GeomDetUnit * stereodet=gdet->stereoDet();
683  statedirection=stereodet->toLocal(gtrkdirup);
684  SiStripRecHit2D s = matchedhit->stereoHit();
685  // if(statedirection.mag() != 0) RecHitInfo<SiStripRecHit2D>(&s,statedirection,trackref,es);
686  if(statedirection.mag()) RecHitInfo<SiStripRecHit2D>(&s,statedirection,es);
687  }
688  else if(projhit){
689  LogTrace("SiStripMonitorTrack")<<"\nProjected recHit found"<< std::endl;
690  // type=Projected;
691  const GluedGeomDet * gdet=static_cast<const GluedGeomDet *>(tkgeom_->idToDet(projhit->geographicalId()));
692 
693  GlobalVector gtrkdirup=gdet->toGlobal(updatedtsos.localMomentum());
694  const SiStripRecHit2D originalhit=projhit->originalHit();
695  const GeomDetUnit * det;
696  if(!StripSubdetector(originalhit.geographicalId().rawId()).stereo()){
697  //mono side
698  LogTrace("SiStripMonitorTrack")<<"\nProjected recHit found MONO"<< std::endl;
699  det=gdet->monoDet();
700  statedirection=det->toLocal(gtrkdirup);
701  if(statedirection.mag()) RecHitInfo<SiStripRecHit2D>(&(originalhit),statedirection,es);
702  }
703  else{
704  LogTrace("SiStripMonitorTrack")<<"\nProjected recHit found STEREO"<< std::endl;
705  //stereo side
706  det=gdet->stereoDet();
707  statedirection=det->toLocal(gtrkdirup);
708  if(statedirection.mag()) RecHitInfo<SiStripRecHit2D>(&(originalhit),statedirection,es);
709  }
710  }else if (hit2D){
711  statedirection=updatedtsos.localMomentum();
712  if(statedirection.mag()) RecHitInfo<SiStripRecHit2D>(hit2D,statedirection,es);
713  } else if (hit1D) {
714  statedirection=updatedtsos.localMomentum();
715  if(statedirection.mag()) RecHitInfo<SiStripRecHit1D>(hit1D,statedirection,es);
716  } else {
717  LogDebug ("SiStripMonitorTrack")
718  << " LocalMomentum: "<<statedirection
719  << "\nLocal x-z plane angle: "<<atan2(statedirection.x(),statedirection.z());
720  }
721 
722  }
723 
724 }
725 //------------------------------------------------------------------------
727  const ProjectedSiStripRecHit2D* projhit,
728  const SiStripMatchedRecHit2D* matchedhit,
729  const SiStripRecHit2D* hit2D,
730  const SiStripRecHit1D* hit1D,
731  LocalVector localMomentum
732  ) {
733  LocalVector statedirection;
734  if(matchedhit){ // type=Matched;
735  LogTrace("SiStripMonitorTrack")<<"\nMatched recHit found"<< std::endl;
736 
737  const GluedGeomDet * gdet=static_cast<const GluedGeomDet *>(tkgeom_->idToDet(matchedhit->geographicalId()));
738 
739  GlobalVector gtrkdirup=gdet->toGlobal(localMomentum);
740 
741  //mono side
742  const GeomDetUnit * monodet=gdet->monoDet();
743  statedirection=monodet->toLocal(gtrkdirup);
744  SiStripRecHit2D m = matchedhit->monoHit();
745  if(statedirection.mag()) RecHitInfo<SiStripRecHit2D>(&m,statedirection,es);
746 
747  //stereo side
748  const GeomDetUnit * stereodet=gdet->stereoDet();
749  statedirection=stereodet->toLocal(gtrkdirup);
750  SiStripRecHit2D s = matchedhit->stereoHit();
751  if(statedirection.mag()) RecHitInfo<SiStripRecHit2D>(&s,statedirection,es);
752  }
753  else if(projhit){ // type=Projected;
754  LogTrace("SiStripMonitorTrack")<<"\nProjected recHit found"<< std::endl;
755 
756  const GluedGeomDet * gdet=static_cast<const GluedGeomDet *>(tkgeom_->idToDet(projhit->geographicalId()));
757 
758  GlobalVector gtrkdirup=gdet->toGlobal(localMomentum);
759  const SiStripRecHit2D originalhit=projhit->originalHit();
760 
761  const GeomDetUnit * det;
762  if(!StripSubdetector(originalhit.geographicalId().rawId()).stereo()){
763  //mono side
764  LogTrace("SiStripMonitorTrack")<<"\nProjected recHit found MONO"<< std::endl;
765  det=gdet->monoDet();
766  statedirection=det->toLocal(gtrkdirup);
767  if(statedirection.mag()) RecHitInfo<SiStripRecHit2D>(&(originalhit),statedirection,es);
768  }
769  else{
770  LogTrace("SiStripMonitorTrack")<<"\nProjected recHit found STEREO"<< std::endl;
771  //stereo side
772  det=gdet->stereoDet();
773  statedirection=det->toLocal(gtrkdirup);
774  if(statedirection.mag()) RecHitInfo<SiStripRecHit2D>(&(originalhit),statedirection,es);
775  }
776  } else if (hit2D){ // type=2D
777  statedirection=localMomentum;
778  if(statedirection.mag()) RecHitInfo<SiStripRecHit2D>(hit2D,statedirection,es);
779  } else if (hit1D) { // type=1D
780  statedirection=localMomentum;
781  if(statedirection.mag()) RecHitInfo<SiStripRecHit1D>(hit1D,statedirection,es);
782  } else {
783  LogDebug ("SiStripMonitorTrack")
784  << " LocalMomentum: "<<statedirection
785  << "\nLocal x-z plane angle: "<<atan2(statedirection.x(),statedirection.z());
786  }
787 
788 }
789 //------------------------------------------------------------------------
791 
792 using namespace std;
793 using namespace edm;
794 using namespace reco;
795 
796  // trajectory input
797  edm::Handle<TrajTrackAssociationCollection> TItkAssociatorCollection;
798  ev.getByToken(trackTrajToken_, TItkAssociatorCollection);
799  if( TItkAssociatorCollection.isValid()){
800  trackStudyFromTrajectory(TItkAssociatorCollection,es);
801  } else {
802  edm::LogError("SiStripMonitorTrack")<<"Association not found ... try w/ track collection"<<std::endl;
803 
804  // edm::Handle<std::vector<Trajectory> > trajectories;
805  // ev.getByToken(trajectoryToken_, trajectories);
806 
807  // track input
808  edm::Handle<reco::TrackCollection > trackCollectionHandle;
809  ev.getByToken(trackToken_, trackCollectionHandle);//takes the track collection
810  if (trackCollectionHandle.isValid()){
811  trackStudyFromTrack(trackCollectionHandle,es);
812  } else {
813  edm::LogError("SiStripMonitorTrack")<<"also Track Collection is not valid !! " << TrackLabel_<<std::endl;
814  return;
815  }
816  }
817 }
818 //------------------------------------------------------------------------
820 
821  // edm::ESHandle<TransientTrackBuilder> builder;
822  // es.get<TransientTrackRecord>().get("TransientTrackBuilder",builder);
823  // const TransientTrackBuilder* transientTrackBuilder = builder.product();
824 
825  reco::TrackCollection trackCollection = *trackCollectionHandle;
826  for (reco::TrackCollection::const_iterator track = trackCollection.begin(), etrack = trackCollection.end();
827  track!=etrack; ++track) {
828 
829  // const reco::TransientTrack transientTrack = transientTrackBuilder->build(track);
830 
831 
832  for (trackingRecHit_iterator hit = track->recHitsBegin(), ehit = track->recHitsEnd();
833  hit!=ehit; ++hit) {
834  if (!(*hit)->isValid()) continue;
835  DetId detID = (*hit)->geographicalId();
836  if (detID.det() != DetId::Tracker) continue;
837  const TrackingRecHit* theHit = (*hit);
838  const ProjectedSiStripRecHit2D* projhit = dynamic_cast<const ProjectedSiStripRecHit2D*>( (theHit) );
839  const SiStripMatchedRecHit2D* matchedhit = dynamic_cast<const SiStripMatchedRecHit2D*> ( (theHit) );
840  const SiStripRecHit2D* hit2D = dynamic_cast<const SiStripRecHit2D*> ( (theHit) );
841  const SiStripRecHit1D* hit1D = dynamic_cast<const SiStripRecHit1D*> ( (theHit) );
842 
843  // GlobalPoint globalPoint = hit->globalPosition();
844  // reco::TrajectoryStateOnSurface stateOnSurface = transientTrack->stateOnSurface(globalPoint);
845 
846  LocalVector localMomentum;
847  hitStudy(es,projhit,matchedhit,hit2D,hit1D,localMomentum);
848  }
849 
850  // hit pattern of the track
851  // const reco::HitPattern & hitsPattern = track->hitPattern();
852  // loop over the hits of the track
853  // for (int i=0; i<hitsPattern.numberOfHits(); i++) {
854  // for (int i=0; i<hitsPattern.numberOfHits(reco::HitPattern::TRACK_HITS); i++) {
855  // uint32_t hit = hitsPattern.getHitPattern(reco::HitPattern::TRACK_HITS,i);
856 
857  // if the hit is valid and in pixel barrel, print out the layer
858  // if (hitsPattern.validHitFilter(hit) && hitsPattern.pixelBarrelHitFilter(hit))
859 
860  // if (!hitsPattern.validHitFilter(hit)) continue;
861 // if (hitsPattern.pixelHitFilter(hit)) std::cout << "pixel" << std::endl; // pixel
862 // if (hitsPattern.pixelBarrelHitFilter(hit)) std::cout << "pixel barrel" << std::endl; // pixel barrel
863 // if (hitsPattern.pixelEndcapHitFilter(hit)) std::cout << "pixel endcap" << std::endl; // pixel endcap
864 // if (hitsPattern.stripHitFilter(hit)) std::cout << "strip" << std::endl; // strip
865 // if (hitsPattern.stripTIBHitFilter(hit)) std::cout << "TIB" << std::endl; // strip TIB
866 // if (hitsPattern.stripTIDHitFilter(hit)) std::cout << "TID" << std::endl; // strip TID
867 // if (hitsPattern.stripTOBHitFilter(hit)) std::cout << "TOB" << std::endl; // strip TOB
868 // if (hitsPattern.stripTECHitFilter(hit)) std::cout << "TEC" << std::endl; // strip TEC
869 // if (hitsPattern.muonDTHitFilter(hit)) std::cout << "DT" << std::endl; // muon DT
870 // if (hitsPattern.muonCSCHitFilter(hit)) std::cout << "CSC" << std::endl; // muon CSC
871 // if (hitsPattern.muonRPCHitFilter(hit)) std::cout << "RPC" << std::endl; // muon RPC
872 //
873 // // expert level: printout the hit in 10-bit binary format
874 // std::cout << "hit in 10-bit binary format = ";
875 // for (int j=9; j>=0; j--) {
876 // int bit = (hit >> j) & 0x1;
877 // std::cout << bit;
878 // }
879 // std::cout << std::endl;
880  // }
881  }
882 }
883 //------------------------------------------------------------------------
885  //Perform track study
886  int i=0;
887  for(TrajTrackAssociationCollection::const_iterator it = TItkAssociatorCollection->begin();it != TItkAssociatorCollection->end(); ++it){
888  const edm::Ref<std::vector<Trajectory> > traj_iterator = it->key;
889 
890  // Trajectory Map, extract Trajectory for this track
891  //reco::TrackRef trackref = it->val;
892  LogDebug("SiStripMonitorTrack")
893  << "Track number "<< ++i << std::endl;
894  // << "\n\tmomentum: " << trackref->momentum()
895  // << "\n\tPT: " << trackref->pt()
896  // << "\n\tvertex: " << trackref->vertex()
897  // << "\n\timpact parameter: " << trackref->d0()
898  // << "\n\tcharge: " << trackref->charge()
899  // << "\n\tnormalizedChi2: " << trackref->normalizedChi2()
900  // <<"\n\tFrom EXTRA : "
901  // <<"\n\t\touter PT "<< trackref->outerPt()<<std::endl;
902 
903  // trajectoryStudy(traj_iterator,trackref,es);
904  trajectoryStudy(traj_iterator,es);
905 
906  }
907 }
908 //------------------------------------------------------------------------
909 template <class T> void SiStripMonitorTrack::RecHitInfo(const T* tkrecHit, LocalVector LV, const edm::EventSetup& es){
910 
911  if(!tkrecHit->isValid()){
912  LogTrace("SiStripMonitorTrack") <<"\t\t Invalid Hit " << std::endl;
913  return;
914  }
915 
916  const uint32_t& detid = tkrecHit->geographicalId().rawId();
917 
918  LogTrace("SiStripMonitorTrack")
919  <<"\n\t\tRecHit on det "<<detid
920  <<"\n\t\tRecHit in LP "<<tkrecHit->localPosition()
921  <<"\n\t\tRecHit in GP "<<tkgeom_->idToDet(tkrecHit->geographicalId())->surface().toGlobal(tkrecHit->localPosition())
922  <<"\n\t\tRecHit trackLocal vector "<<LV.x() << " " << LV.y() << " " << LV.z() <<std::endl;
923 
924 
925  //Retrieve tracker topology from geometry
926  edm::ESHandle<TrackerTopology> tTopoHandle;
927  es.get<TrackerTopologyRcd>().get(tTopoHandle);
928  const TrackerTopology* const tTopo = tTopoHandle.product();
929 
930  //Get SiStripCluster from SiStripRecHit
931  if ( tkrecHit != NULL ){
932  const SiStripCluster* SiStripCluster_ = &*(tkrecHit->cluster());
933  SiStripClusterInfo SiStripClusterInfo_(*SiStripCluster_,es,detid);
934 
935  const Det2MEs MEs = findMEs(tTopo, detid);
936  if (clusterInfos(&SiStripClusterInfo_,detid, OnTrack, LV, MEs))
937  {
938  vPSiStripCluster.insert(SiStripCluster_);
939  }
940  }
941  else
942  {
943  edm::LogError("SiStripMonitorTrack") << "NULL hit" << std::endl;
944  }
945  }
946 
947 //------------------------------------------------------------------------
949 {
950 
951  //Retrieve tracker topology from geometry
952  edm::ESHandle<TrackerTopology> tTopoHandle;
953  es.get<TrackerTopologyRcd>().get(tTopoHandle);
954  const TrackerTopology* const tTopo = tTopoHandle.product();
955 
957  ev.getByToken( clusterToken_, siStripClusterHandle);
958  if (siStripClusterHandle.isValid()){
959  //Loop on Dets
960  for (edmNew::DetSetVector<SiStripCluster>::const_iterator DSViter=siStripClusterHandle->begin(), DSVEnd=siStripClusterHandle->end();
961  DSViter!=DSVEnd; ++DSViter) {
962 
963  uint32_t detid=DSViter->id();
964  const Det2MEs MEs = findMEs(tTopo, detid);
965 
966  LogDebug("SiStripMonitorTrack") << "on detid "<< detid << " N Cluster= " << DSViter->size();
967 
968  //Loop on Clusters
969  for(edmNew::DetSet<SiStripCluster>::const_iterator ClusIter = DSViter->begin(), ClusEnd = DSViter->end();
970  ClusIter!=ClusEnd; ++ClusIter) {
971 
972  if (vPSiStripCluster.find(&*ClusIter) == vPSiStripCluster.end()) {
973  SiStripClusterInfo SiStripClusterInfo_(*ClusIter,es,detid);
974  clusterInfos(&SiStripClusterInfo_,detid,OffTrack,LV,MEs);
975  }
976  }
977  }
978  } else {
979  edm::LogError("SiStripMonitorTrack")<< "ClusterCollection is not valid!!" << std::endl;
980  return;
981  }
982 }
983 
984 //------------------------------------------------------------------------
986  SiStripHistoId hidmanager1;
987 
988  std::string layer_id = hidmanager1.getSubdetid(detid, tTopo, false);
989  std::string ring_id = hidmanager1.getSubdetid(detid, tTopo, true);
990  std::string sdet_tag = folderOrganizer_.getSubDetFolderAndTag(detid, tTopo).second;
991 
992  Det2MEs me;
993  me.iLayer = nullptr;
994  me.iRing = nullptr;
995  me.iSubdet = nullptr;
996 
997  std::map<std::string, LayerMEs>::iterator iLayer = LayerMEsMap.find(layer_id);
998  if (iLayer != LayerMEsMap.end()) {
999  me.iLayer = &(iLayer->second);
1000  }
1001 
1002  std::map<std::string, RingMEs>::iterator iRing = RingMEsMap.find(ring_id);
1003  if (iRing != RingMEsMap.end()) {
1004  me.iRing = &(iRing->second);
1005  }
1006 
1007  std::map<std::string, SubDetMEs>::iterator iSubdet = SubDetMEsMap.find(sdet_tag);
1008  if (iSubdet != SubDetMEsMap.end()) {
1009  me.iSubdet = &(iSubdet->second);
1010  }
1011 
1012  return me;
1013 }
1014 
1015 //------------------------------------------------------------------------
1017 bool SiStripMonitorTrack::clusterInfos(SiStripClusterInfo* cluster, const uint32_t detid, enum ClusterFlags flag, const LocalVector LV, const Det2MEs& MEs)
1018 {
1019 
1020  if (cluster==NULL) return false;
1021  // if one imposes a cut on the clusters, apply it
1022  if( (applyClusterQuality_) &&
1023  (cluster->signalOverNoise() < sToNLowerLimit_ ||
1024  cluster->signalOverNoise() > sToNUpperLimit_ ||
1025  cluster->width() < widthLowerLimit_ ||
1026  cluster->width() > widthUpperLimit_) ) return false;
1027  // start of the analysis
1028 
1029  float cosRZ = -2;
1030  LogDebug("SiStripMonitorTrack")<< "\n\tLV " << LV.x() << " " << LV.y() << " " << LV.z() << " " << LV.mag() << std::endl;
1031  if (LV.mag()){
1032  cosRZ= fabs(LV.z())/LV.mag();
1033  LogDebug("SiStripMonitorTrack")<< "\n\t cosRZ " << cosRZ << std::endl;
1034  }
1035 
1036  // Filling SubDet/Layer Plots (on Track + off Track)
1037  float StoN = cluster->signalOverNoise();
1038  float noise = cluster->noiseRescaledByGain();
1039  uint16_t charge = cluster->charge();
1040  uint16_t width = cluster->width();
1041  float position = cluster->baryStrip();
1042 
1043  // new dE/dx (chargePerCM)
1044  // https://indico.cern.ch/event/342236/session/5/contribution/10/material/slides/0.pdf
1045  float dQdx_fromTrack = siStripClusterTools::chargePerCM(detid, *cluster, LV);
1046  // from straigth line origin-sensor centre
1047  const StripGeomDetUnit* DetUnit = static_cast<const StripGeomDetUnit*>(tkgeom_->idToDetUnit(DetId(detid)));
1048  LocalPoint locVtx = DetUnit->toLocal(GlobalPoint(0.0, 0.0, 0.0));
1049  LocalVector locDir(locVtx.x(), locVtx.y(), locVtx.z());
1050  float dQdx_fromOrigin = siStripClusterTools::chargePerCM(detid, *cluster, locDir);
1051 
1052  if(flag==OnTrack){
1053  if (MEs.iSubdet != nullptr) MEs.iSubdet->totNClustersOnTrack++;
1054  // layerMEs
1055  if (MEs.iLayer != nullptr) {
1056  if(noise > 0.0) fillME(MEs.iLayer->ClusterStoNCorrOnTrack, StoN*cosRZ);
1057  if(noise == 0.0) LogDebug("SiStripMonitorTrack") << "Module " << detid << " in Event " << eventNb << " noise " << cluster->noiseRescaledByGain() << std::endl;
1058  fillME(MEs.iLayer->ClusterChargeCorrOnTrack, charge*cosRZ);
1059  fillME(MEs.iLayer->ClusterChargeOnTrack, charge);
1060  fillME(MEs.iLayer->ClusterNoiseOnTrack, noise);
1061  fillME(MEs.iLayer->ClusterWidthOnTrack, width);
1062  fillME(MEs.iLayer->ClusterPosOnTrack, position);
1063  fillME(MEs.iLayer->ClusterChargePerCMfromTrack, dQdx_fromTrack);
1064  fillME(MEs.iLayer->ClusterChargePerCMfromOriginOnTrack, dQdx_fromOrigin);
1065  }
1066  // ringMEs
1067  if (MEs.iRing != nullptr) {
1068  if(noise > 0.0) fillME(MEs.iRing->ClusterStoNCorrOnTrack, StoN*cosRZ);
1069  if(noise == 0.0) LogDebug("SiStripMonitorTrack") << "Module " << detid << " in Event " << eventNb << " noise " << cluster->noiseRescaledByGain() << std::endl;
1070  fillME(MEs.iRing->ClusterChargeCorrOnTrack, charge*cosRZ);
1071  fillME(MEs.iRing->ClusterChargeOnTrack, charge);
1072  fillME(MEs.iRing->ClusterNoiseOnTrack, noise);
1073  fillME(MEs.iRing->ClusterWidthOnTrack, width);
1074  fillME(MEs.iRing->ClusterChargePerCMfromTrack, dQdx_fromTrack);
1075  fillME(MEs.iRing->ClusterChargePerCMfromOriginOnTrack, dQdx_fromOrigin);
1076  }
1077  // subdetMEs
1078  if(MEs.iSubdet != nullptr){
1079  fillME(MEs.iSubdet->ClusterChargeOnTrack,charge);
1080  if(noise > 0.0) fillME(MEs.iSubdet->ClusterStoNCorrOnTrack,StoN*cosRZ);
1081  fillME(MEs.iSubdet->ClusterChargePerCMfromTrack,dQdx_fromTrack);
1082  fillME(MEs.iSubdet->ClusterChargePerCMfromOriginOnTrack,dQdx_fromOrigin);
1083  }
1084  //******** TkHistoMaps
1085  if (TkHistoMap_On_) {
1086  uint32_t adet=cluster->detId();
1087  tkhisto_NumOnTrack->add(adet,1.);
1088  if(noise > 0.0) tkhisto_StoNCorrOnTrack->fill(adet,cluster->signalOverNoise()*cosRZ);
1089  if(noise == 0.0)
1090  LogDebug("SiStripMonitorTrack") << "Module " << detid << " in Event " << eventNb << " noise " << noise << std::endl;
1091  }
1092  // Module plots filled only for onTrack Clusters
1093  if(Mod_On_){
1094  SiStripHistoId hidmanager2;
1095  std::string name = hidmanager2.createHistoId("","det",detid);
1096  //fillModMEs
1097  std::map<std::string, ModMEs>::iterator iModME = ModMEsMap.find(name);
1098  if(iModME!=ModMEsMap.end()){
1099  if(noise > 0.0) fillME(iModME->second.ClusterStoNCorr ,StoN*cosRZ);
1100  if(noise == 0.0) LogDebug("SiStripMonitorTrack") << "Module " << name << " in Event " << eventNb << " noise " << noise << std::endl;
1101  fillME(iModME->second.ClusterCharge,charge);
1102 
1103  fillME(iModME->second.ClusterChargeCorr,charge*cosRZ);
1104 
1105  fillME(iModME->second.ClusterWidth ,width);
1106  fillME(iModME->second.ClusterPos ,position);
1107 
1108  fillME(iModME->second.ClusterChargePerCMfromTrack, dQdx_fromTrack);
1109  fillME(iModME->second.ClusterChargePerCMfromOrigin, dQdx_fromOrigin);
1110 
1111  //fill the PGV histo
1112  float PGVmax = cluster->maxCharge();
1113  int PGVposCounter = cluster->maxIndex();
1114  for (int i= int(conf_.getParameter<edm::ParameterSet>("TProfileClusterPGV").getParameter<double>("xmin"));i<PGVposCounter;++i)
1115  fillME(iModME->second.ClusterPGV, i,0.);
1116  for (auto it=cluster->stripCharges().begin();it<cluster->stripCharges().end();++it) {
1117  fillME(iModME->second.ClusterPGV, PGVposCounter++,(*it)/PGVmax);
1118  }
1119  for (int i= PGVposCounter;i<int(conf_.getParameter<edm::ParameterSet>("TProfileClusterPGV").getParameter<double>("xmax"));++i)
1120  fillME(iModME->second.ClusterPGV, i,0.);
1121  //end fill the PGV histo
1122  }
1123  }
1124  } else {
1125  if (flag == OffTrack) {
1126  if (MEs.iSubdet != nullptr) MEs.iSubdet->totNClustersOffTrack++;
1127  //******** TkHistoMaps
1128  if (TkHistoMap_On_) {
1129  uint32_t adet=cluster->detId();
1130  tkhisto_NumOffTrack->add(adet,1.);
1131  if(charge > 250){
1132  LogDebug("SiStripMonitorTrack") << "Module firing " << detid << " in Event " << eventNb << std::endl;
1133  }
1134  }
1135  }
1136  // layerMEs
1137  if (MEs.iLayer != nullptr) {
1138  fillME(MEs.iLayer->ClusterChargeOffTrack, charge);
1139  fillME(MEs.iLayer->ClusterNoiseOffTrack, noise);
1140  fillME(MEs.iLayer->ClusterWidthOffTrack, width);
1141  fillME(MEs.iLayer->ClusterPosOffTrack, position);
1142  fillME(MEs.iLayer->ClusterChargePerCMfromOriginOffTrack, dQdx_fromOrigin);
1143  }
1144  // ringMEs
1145  if (MEs.iRing != nullptr) {
1146  fillME(MEs.iRing->ClusterChargeOffTrack, charge);
1147  fillME(MEs.iRing->ClusterNoiseOffTrack, noise);
1148  fillME(MEs.iRing->ClusterWidthOffTrack, width);
1149  fillME(MEs.iRing->ClusterChargePerCMfromOriginOffTrack, dQdx_fromOrigin);
1150  }
1151  // subdetMEs
1152  if(MEs.iSubdet != nullptr){
1153  fillME(MEs.iSubdet->ClusterChargeOffTrack,charge);
1154  if(noise > 0.0) fillME(MEs.iSubdet->ClusterStoNOffTrack,StoN);
1155  fillME(MEs.iSubdet->ClusterChargePerCMfromOriginOffTrack,dQdx_fromOrigin);
1156  }
1157  }
1158  return true;
1159 }
1160 //--------------------------------------------------------------------------------
#define LogDebug(id)
RunNumber_t run() const
Definition: EventID.h:39
uint8_t maxCharge() const
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:41
Det2MEs findMEs(const TrackerTopology *tTopo, const uint32_t detid)
int i
Definition: DBlmapReader.cc:9
MonitorElement * ClusterChargePerCMfromTrack
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
TkHistoMap * tkhisto_NumOffTrack
SiStripMonitorTrack(const edm::ParameterSet &)
void setSiStripFolderName(std::string name)
virtual void analyze(const edm::Event &, const edm::EventSetup &)
void trackStudy(const edm::Event &ev, const edm::EventSetup &es)
void trackStudyFromTrack(edm::Handle< reco::TrackCollection > trackCollectionHandle, const edm::EventSetup &es)
edm::EDGetTokenT< reco::TrackCollection > trackToken_
void trackStudyFromTrajectory(edm::Handle< TrajTrackAssociationCollection > TItkAssociatorCollection, const edm::EventSetup &es)
const GeomDetUnit * monoDet() const
Definition: GluedGeomDet.h:20
void fillME(MonitorElement *ME, float value1)
std::pair< const std::string, const char * > getSubDetFolderAndTag(const uint32_t &detid, const TrackerTopology *tTopo)
SiStripDCSStatus * dcsStatus_
MonitorElement * bookProfile(Args &&...args)
Definition: DQMStore.h:157
void hitStudy(const edm::EventSetup &es, const ProjectedSiStripRecHit2D *projhit, const SiStripMatchedRecHit2D *matchedhit, const SiStripRecHit2D *hit2D, const SiStripRecHit1D *hit1D, LocalVector localMomentum)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
float noiseRescaledByGain() const
void book(DQMStore::IBooker &, const TrackerTopology *tTopo)
void AllClusters(const edm::Event &ev, const edm::EventSetup &es)
std::map< std::string, RingMEs > RingMEsMap
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:52
float chargePerCM(DetId detid, Iter a, Iter b)
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
float baryStrip() const
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
edm::ParameterSet conf_
T y() const
Definition: PV3DBase.h:63
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
Definition: GeomDet.h:67
std::pair< std::string, int32_t > GetSubDetAndLayer(const uint32_t &detid, const TrackerTopology *tTopo, bool ring_flag=0)
MonitorElement * bookME1D(DQMStore::IBooker &, const char *, const char *)
#define NULL
Definition: scimark2.h:8
MonitorElement * ClusterChargePerCMfromTrack
bool ev
MonitorElement * ClusterChargeCorrOnTrack
Provides a code based selection for trigger and DCS information in order to have no failing filters i...
data_type const * const_iterator
Definition: DetSetNew.h:30
key_type key() const
Accessor for product key.
Definition: Ref.h:264
edm::ESHandle< SiStripDetCabling > SiStripDetCabling_
void bookLayerMEs(DQMStore::IBooker &, const uint32_t, std::string &)
uint16_t maxIndex() const
void trajectoryStudy(const edm::Ref< std::vector< Trajectory > > traj, const edm::EventSetup &es)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
MonitorElement * ClusterChargePerCMfromOriginOffTrack
auto stripCharges() const -> decltype(cluster() ->amplitudes())
void setDetectorFolder(uint32_t rawdetid, const TrackerTopology *tTopo)
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
LocalVector localMomentum() const
edm::ESHandle< TrackerGeometry > tkgeom_
bool getStatus(edm::Event const &e, edm::EventSetup const &eSetup)
edmNew::DetSet< SiStripCluster >::const_iterator ClusIter
math::XYZTLorentzVectorD LV
float signalOverNoise() const
T mag() const
Definition: PV3DBase.h:67
vector< ParameterSet > Parameters
edm::EventNumber_t eventNb
TrackingRecHit::ConstRecHitPointer ConstRecHitPointer
uint16_t charge() const
std::unordered_set< const SiStripCluster * > vPSiStripCluster
std::map< std::string, SubDetMEs > SubDetMEsMap
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
void fill(uint32_t &detid, float value)
Definition: TkHistoMap.cc:180
bool accept(const edm::Event &event, const edm::EventSetup &setup)
To be called from analyze/filter() methods.
const std::string subdet_tag("SubDet")
T z() const
Definition: PV3DBase.h:64
MonitorElement * bookME2D(DQMStore::IBooker &, const char *, const char *)
uint16_t width() const
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:115
void tag(MonitorElement *, unsigned int)
Definition: DQMStore.cc:286
TH1 * getTH1(void) const
void bookSubDetMEs(DQMStore::IBooker &, std::string &name)
MonitorElement * bookME3D(DQMStore::IBooker &, const char *, const char *)
int orbitNumber() const
Definition: EventBase.h:67
MonitorElement * ClusterChargePerCMfromOrigin
MonitorElement * ClusterChargePerCMfromOriginOffTrack
SiStripFolderOrganizer folderOrganizer_
std::string getSubdetid(uint32_t id, const TrackerTopology *tTopo, bool flag_ring)
MonitorElement * ClusterChargePerCMfromTrack
bool isValid() const
Definition: HandleBase.h:75
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
#define LogTrace(id)
tuple conf
Definition: dbtoconf.py:185
SiStripRecHit2D originalHit() const
Definition: DetId.h:18
edm::EDGetTokenT< TrajTrackAssociationCollection > trackTrajToken_
void bookModMEs(DQMStore::IBooker &, const uint32_t)
void setLayerFolder(uint32_t rawdetid, const TrackerTopology *tTopo, int32_t layer=0, bool ring_flag=0)
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:274
SiStripRecHit2D stereoHit() const
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:133
std::string createHistoId(std::string description, std::string id_type, uint32_t component_id)
MonitorElement * ClusterChargePerCMfromTrack
const T & get() const
Definition: EventSetup.h:56
T const * product() const
Definition: ESHandle.h:86
void dqmBeginRun(const edm::Run &run, const edm::EventSetup &es)
std::map< std::string, ModMEs > ModMEsMap
MonitorElement * bookMETrend(DQMStore::IBooker &, const char *)
std::string HistoName
TkHistoMap * tkhisto_NumOnTrack
SiStripRecHit2D monoHit() const
uint32_t detId() const
GenericTriggerEventFlag * genTriggerEventFlag_
void RecHitInfo(const T *tkrecHit, LocalVector LV, const edm::EventSetup &)
MonitorElement * ClusterChargePerCMfromOriginOnTrack
edm::EventID id() const
Definition: EventBase.h:60
MonitorElement * handleBookMEs(DQMStore::IBooker &, std::string &, std::string &, std::string &, std::string &)
static int position[264][3]
Definition: ReadPGInfo.cc:509
MonitorElement * bookMEProfile(DQMStore::IBooker &, const char *, const char *)
TkHistoMap * tkhisto_StoNCorrOnTrack
DetId geographicalId() const
void initRun(const edm::Run &run, const edm::EventSetup &setup)
To be called from beginRun() methods.
MonitorElement * ClusterChargePerCMfromOriginOnTrack
bool clusterInfos(SiStripClusterInfo *cluster, const uint32_t detid, enum ClusterFlags flags, LocalVector LV, const Det2MEs &MEs)
std::string createHistoLayer(std::string description, std::string id_type, std::string path, std::string flag)
Detector det() const
get the detector field from this detid
Definition: DetId.h:35
MonitorElement * book3D(Args &&...args)
Definition: DQMStore.h:151
long double T
T x() const
Definition: PV3DBase.h:62
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
void bookRingMEs(DQMStore::IBooker &, const uint32_t, std::string &)
MonitorElement * ClusterChargePerCMfromOriginOnTrack
void add(uint32_t &detid, float value)
Definition: TkHistoMap.cc:213
const GeomDetUnit * stereoDet() const
Definition: GluedGeomDet.h:21
TrackingRecHitCollection::base::const_iterator trackingRecHit_iterator
iterator over a vector of reference to TrackingRecHit in the same collection
Definition: Run.h:43
edm::EDGetTokenT< edmNew::DetSetVector< SiStripCluster > > clusterToken_
std::map< std::string, LayerMEs > LayerMEsMap
MonitorElement * ClusterChargePerCMfromOriginOffTrack