CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiPixelTrackResidualSource.cc
Go to the documentation of this file.
1 // Package: SiPixelMonitorTrack
2 // Class: SiPixelTrackResidualSource
3 //
4 // class SiPixelTrackResidualSource SiPixelTrackResidualSource.cc
5 // DQM/SiPixelMonitorTrack/src/SiPixelTrackResidualSource.cc
6 //
7 // Description: SiPixel hit-to-track residual data quality monitoring modules
8 // Implementation: prototype -> improved -> never final - end of the 1st step
9 //
10 // Original Author: Shan-Huei Chuang
11 // Created: Fri Mar 23 18:41:42 CET 2007
12 // Updated by Lukas Wehrli (plots for clusters on/off track added)
13 // $Id: SiPixelTrackResidualSource.cc,v 1.27 2013/01/03 23:50:05 wmtan Exp $
14 
15 
16 #include <iostream>
17 #include <map>
18 #include <string>
19 #include <vector>
20 #include <utility>
21 
24 
27 
31 
33 
36 
38 
44 
48 
49 //Claudia new libraries
59 
60 using namespace std;
61 using namespace edm;
62 
63 
65  pSet_(pSet),
66  modOn( pSet.getUntrackedParameter<bool>("modOn",true) ),
67  reducedSet( pSet.getUntrackedParameter<bool>("reducedSet",true) ),
68  ladOn( pSet.getUntrackedParameter<bool>("ladOn",false) ),
69  layOn( pSet.getUntrackedParameter<bool>("layOn",false) ),
70  phiOn( pSet.getUntrackedParameter<bool>("phiOn",false) ),
71  ringOn( pSet.getUntrackedParameter<bool>("ringOn",false) ),
72  bladeOn( pSet.getUntrackedParameter<bool>("bladeOn",false) ),
73  diskOn( pSet.getUntrackedParameter<bool>("diskOn",false) )
74 
75 {
76  pSet_ = pSet;
77  debug_ = pSet_.getUntrackedParameter<bool>("debug", false);
80  tracksrc_ = pSet_.getParameter<edm::InputTag>("trajectoryInput");
82  ttrhbuilder_ = pSet_.getParameter<std::string>("TTRHBuilder");
83  ptminres_= pSet.getUntrackedParameter<double>("PtMinRes",4.0) ;
84 
85  LogInfo("PixelDQM") << "SiPixelTrackResidualSource constructor" << endl;
86  LogInfo ("PixelDQM") << "Mod/Lad/Lay/Phi " << modOn << "/" << ladOn << "/"
87  << layOn << "/" << phiOn << std::endl;
88  LogInfo ("PixelDQM") << "Blade/Disk/Ring" << bladeOn << "/" << diskOn << "/"
89  << ringOn << std::endl;
90 }
91 
92 
94  LogInfo("PixelDQM") << "SiPixelTrackResidualSource destructor" << endl;
95 
96  std::map<uint32_t,SiPixelTrackResidualModule*>::iterator struct_iter;
97  for (struct_iter = theSiPixelStructure.begin() ; struct_iter != theSiPixelStructure.end() ; struct_iter++){
98  delete struct_iter->second;
99  struct_iter->second = 0;
100  }
101 }
102 
104  LogInfo("PixelDQM") << "SiPixelTrackResidualSource beginJob()" << endl;
105  firstRun = true;
106  NTotal=0;
107  NLowProb=0;
108 }
109 
110 
112  LogInfo("PixelDQM") << "SiPixelTrackResidualSource beginRun()" << endl;
113 
114  if(firstRun){
115  // retrieve TrackerGeometry for pixel dets
117  iSetup.get<TrackerDigiGeometryRecord>().get(TG);
118  if (debug_) LogVerbatim("PixelDQM") << "TrackerGeometry "<< &(*TG) <<" size is "<< TG->dets().size() << endl;
119 
120  // build theSiPixelStructure with the pixel barrel and endcap dets from TrackerGeometry
121  for (TrackerGeometry::DetContainer::const_iterator pxb = TG->detsPXB().begin();
122  pxb!=TG->detsPXB().end(); pxb++) {
123  if (dynamic_cast<PixelGeomDetUnit*>((*pxb))!=0) {
124  SiPixelTrackResidualModule* module = new SiPixelTrackResidualModule((*pxb)->geographicalId().rawId());
125  theSiPixelStructure.insert(pair<uint32_t, SiPixelTrackResidualModule*>((*pxb)->geographicalId().rawId(), module));
126  }
127  }
128  for (TrackerGeometry::DetContainer::const_iterator pxf = TG->detsPXF().begin();
129  pxf!=TG->detsPXF().end(); pxf++) {
130  if (dynamic_cast<PixelGeomDetUnit*>((*pxf))!=0) {
131  SiPixelTrackResidualModule* module = new SiPixelTrackResidualModule((*pxf)->geographicalId().rawId());
132  theSiPixelStructure.insert(pair<uint32_t, SiPixelTrackResidualModule*>((*pxf)->geographicalId().rawId(), module));
133  }
134  }
135  LogInfo("PixelDQM") << "SiPixelStructure size is " << theSiPixelStructure.size() << endl;
136 
137  // book residual histograms in theSiPixelFolder - one (x,y) pair of histograms per det
138  SiPixelFolderOrganizer theSiPixelFolder;
139  for (std::map<uint32_t, SiPixelTrackResidualModule*>::iterator pxd = theSiPixelStructure.begin();
140  pxd!=theSiPixelStructure.end(); pxd++) {
141 
142  if(modOn){
143  if (theSiPixelFolder.setModuleFolder((*pxd).first)) (*pxd).second->book(pSet_,reducedSet);
144  else throw cms::Exception("LogicError") << "SiPixelTrackResidualSource Folder Creation Failed! ";
145  }
146  if(ladOn){
147  if (theSiPixelFolder.setModuleFolder((*pxd).first,1)) {
148 
149  (*pxd).second->book(pSet_,reducedSet,1);
150  }
151  else throw cms::Exception("LogicError") << "SiPixelTrackResidualSource ladder Folder Creation Failed! ";
152  }
153  if(layOn){
154  if (theSiPixelFolder.setModuleFolder((*pxd).first,2)) (*pxd).second->book(pSet_,reducedSet,2);
155  else throw cms::Exception("LogicError") << "SiPixelTrackResidualSource layer Folder Creation Failed! ";
156  }
157  if(phiOn){
158  if (theSiPixelFolder.setModuleFolder((*pxd).first,3)) (*pxd).second->book(pSet_,reducedSet,3);
159  else throw cms::Exception("LogicError") << "SiPixelTrackResidualSource phi Folder Creation Failed! ";
160  }
161  if(bladeOn){
162  if (theSiPixelFolder.setModuleFolder((*pxd).first,4)) (*pxd).second->book(pSet_,reducedSet,4);
163  else throw cms::Exception("LogicError") << "SiPixelTrackResidualSource Blade Folder Creation Failed! ";
164  }
165  if(diskOn){
166  if (theSiPixelFolder.setModuleFolder((*pxd).first,5)) (*pxd).second->book(pSet_,reducedSet,5);
167  else throw cms::Exception("LogicError") << "SiPixelTrackResidualSource Disk Folder Creation Failed! ";
168  }
169  if(ringOn){
170  if (theSiPixelFolder.setModuleFolder((*pxd).first,6)) (*pxd).second->book(pSet_,reducedSet,6);
171  else throw cms::Exception("LogicError") << "SiPixelTrackResidualSource Ring Folder Creation Failed! ";
172  }
173  }
174 
175 
176 // edm::InputTag tracksrc = pSet_.getParameter<edm::InputTag>("trajectoryInput");
177 // edm::InputTag clustersrc = pSet_.getParameter<edm::InputTag>("clustersrc");
178 
179  //number of tracks
180  dbe_->setCurrentFolder("Pixel/Tracks");
181  meNofTracks_ = dbe_->book1D("ntracks_" + tracksrc_.label(),"Number of Tracks",4,0,4);
182  meNofTracks_->setAxisTitle("Number of Tracks",1);
183  meNofTracks_->setBinLabel(1,"All");
184  meNofTracks_->setBinLabel(2,"Pixel");
185  meNofTracks_->setBinLabel(3,"BPix");
186  meNofTracks_->setBinLabel(4,"FPix");
187 
188  //number of tracks in pixel fiducial volume
189  dbe_->setCurrentFolder("Pixel/Tracks");
190  meNofTracksInPixVol_ = dbe_->book1D("ntracksInPixVol_" + tracksrc_.label(),"Number of Tracks crossing Pixel fiducial Volume",2,0,2);
191  meNofTracksInPixVol_->setAxisTitle("Number of Tracks",1);
192  meNofTracksInPixVol_->setBinLabel(1,"With Hits");
193  meNofTracksInPixVol_->setBinLabel(2,"Without Hits");
194 
195  //number of clusters (associated to track / not associated)
196  dbe_->setCurrentFolder("Pixel/Clusters/OnTrack");
197  meNofClustersOnTrack_ = dbe_->book1D("nclusters_" + clustersrc_.label() + "_tot","Number of Clusters (on track)",3,0,3);
198  meNofClustersOnTrack_->setAxisTitle("Number of Clusters on Track",1);
202  dbe_->setCurrentFolder("Pixel/Clusters/OffTrack");
203  meNofClustersNotOnTrack_ = dbe_->book1D("nclusters_" + clustersrc_.label() + "_tot","Number of Clusters (off track)",3,0,3);
204  meNofClustersNotOnTrack_->setAxisTitle("Number of Clusters off Track",1);
208 
209  //cluster charge and size
210  //charge
211  //on track
212  dbe_->setCurrentFolder("Pixel/Clusters/OnTrack");
213  meClChargeOnTrack_all = dbe_->book1D("charge_" + clustersrc_.label(),"Charge (on track)",500,0.,500.);
214  meClChargeOnTrack_all->setAxisTitle("Charge size (in ke)",1);
215  meClChargeOnTrack_bpix = dbe_->book1D("charge_" + clustersrc_.label() + "_Barrel","Charge (on track, barrel)",500,0.,500.);
216  meClChargeOnTrack_bpix->setAxisTitle("Charge size (in ke)",1);
217  meClChargeOnTrack_fpix = dbe_->book1D("charge_" + clustersrc_.label() + "_Endcap","Charge (on track, endcap)",500,0.,500.);
218  meClChargeOnTrack_fpix->setAxisTitle("Charge size (in ke)",1);
219  meClChargeOnTrack_layer1 = dbe_->book1D("charge_" + clustersrc_.label() + "_Layer_1","Charge (on track, layer1)",500,0.,500.);
220  meClChargeOnTrack_layer1->setAxisTitle("Charge size (in ke)",1);
221  meClChargeOnTrack_layer2 = dbe_->book1D("charge_" + clustersrc_.label() + "_Layer_2","Charge (on track, layer2)",500,0.,500.);
222  meClChargeOnTrack_layer2->setAxisTitle("Charge size (in ke)",1);
223  meClChargeOnTrack_layer3 = dbe_->book1D("charge_" + clustersrc_.label() + "_Layer_3","Charge (on track, layer3)",500,0.,500.);
224  meClChargeOnTrack_layer3->setAxisTitle("Charge size (in ke)",1);
225  meClChargeOnTrack_diskp1 = dbe_->book1D("charge_" + clustersrc_.label() + "_Disk_p1","Charge (on track, diskp1)",500,0.,500.);
226  meClChargeOnTrack_diskp1->setAxisTitle("Charge size (in ke)",1);
227  meClChargeOnTrack_diskp2 = dbe_->book1D("charge_" + clustersrc_.label() + "_Disk_p2","Charge (on track, diskp2)",500,0.,500.);
228  meClChargeOnTrack_diskp2->setAxisTitle("Charge size (in ke)",1);
229  meClChargeOnTrack_diskm1 = dbe_->book1D("charge_" + clustersrc_.label() + "_Disk_m1","Charge (on track, diskm1)",500,0.,500.);
230  meClChargeOnTrack_diskm1->setAxisTitle("Charge size (in ke)",1);
231  meClChargeOnTrack_diskm2 = dbe_->book1D("charge_" + clustersrc_.label() + "_Disk_m2","Charge (on track, diskm2)",500,0.,500.);
232  meClChargeOnTrack_diskm2->setAxisTitle("Charge size (in ke)",1);
233  //off track
234  dbe_->setCurrentFolder("Pixel/Clusters/OffTrack");
235  meClChargeNotOnTrack_all = dbe_->book1D("charge_" + clustersrc_.label(),"Charge (off track)",500,0.,500.);
236  meClChargeNotOnTrack_all->setAxisTitle("Charge size (in ke)",1);
237  meClChargeNotOnTrack_bpix = dbe_->book1D("charge_" + clustersrc_.label() + "_Barrel","Charge (off track, barrel)",500,0.,500.);
238  meClChargeNotOnTrack_bpix->setAxisTitle("Charge size (in ke)",1);
239  meClChargeNotOnTrack_fpix = dbe_->book1D("charge_" + clustersrc_.label() + "_Endcap","Charge (off track, endcap)",500,0.,500.);
240  meClChargeNotOnTrack_fpix->setAxisTitle("Charge size (in ke)",1);
241  meClChargeNotOnTrack_layer1 = dbe_->book1D("charge_" + clustersrc_.label() + "_Layer_1","Charge (off track, layer1)",500,0.,500.);
242  meClChargeNotOnTrack_layer1->setAxisTitle("Charge size (in ke)",1);
243  meClChargeNotOnTrack_layer2 = dbe_->book1D("charge_" + clustersrc_.label() + "_Layer_2","Charge (off track, layer2)",500,0.,500.);
244  meClChargeNotOnTrack_layer2->setAxisTitle("Charge size (in ke)",1);
245  meClChargeNotOnTrack_layer3 = dbe_->book1D("charge_" + clustersrc_.label() + "_Layer_3","Charge (off track, layer3)",500,0.,500.);
246  meClChargeNotOnTrack_layer3->setAxisTitle("Charge size (in ke)",1);
247  meClChargeNotOnTrack_diskp1 = dbe_->book1D("charge_" + clustersrc_.label() + "_Disk_p1","Charge (off track, diskp1)",500,0.,500.);
248  meClChargeNotOnTrack_diskp1->setAxisTitle("Charge size (in ke)",1);
249  meClChargeNotOnTrack_diskp2 = dbe_->book1D("charge_" + clustersrc_.label() + "_Disk_p2","Charge (off track, diskp2)",500,0.,500.);
250  meClChargeNotOnTrack_diskp2->setAxisTitle("Charge size (in ke)",1);
251  meClChargeNotOnTrack_diskm1 = dbe_->book1D("charge_" + clustersrc_.label() + "_Disk_m1","Charge (off track, diskm1)",500,0.,500.);
252  meClChargeNotOnTrack_diskm1->setAxisTitle("Charge size (in ke)",1);
253  meClChargeNotOnTrack_diskm2 = dbe_->book1D("charge_" + clustersrc_.label() + "_Disk_m2","Charge (off track, diskm2)",500,0.,500.);
254  meClChargeNotOnTrack_diskm2->setAxisTitle("Charge size (in ke)",1);
255 
256  //size
257  //on track
258  dbe_->setCurrentFolder("Pixel/Clusters/OnTrack");
259  meClSizeOnTrack_all = dbe_->book1D("size_" + clustersrc_.label(),"Size (on track)",100,0.,100.);
260  meClSizeOnTrack_all->setAxisTitle("Cluster size (in pixels)",1);
261  meClSizeOnTrack_bpix = dbe_->book1D("size_" + clustersrc_.label() + "_Barrel","Size (on track, barrel)",100,0.,100.);
262  meClSizeOnTrack_bpix->setAxisTitle("Cluster size (in pixels)",1);
263  meClSizeOnTrack_fpix = dbe_->book1D("size_" + clustersrc_.label() + "_Endcap","Size (on track, endcap)",100,0.,100.);
264  meClSizeOnTrack_fpix->setAxisTitle("Cluster size (in pixels)",1);
265  meClSizeOnTrack_layer1 = dbe_->book1D("size_" + clustersrc_.label() + "_Layer_1","Size (on track, layer1)",100,0.,100.);
266  meClSizeOnTrack_layer1->setAxisTitle("Cluster size (in pixels)",1);
267  meClSizeOnTrack_layer2 = dbe_->book1D("size_" + clustersrc_.label() + "_Layer_2","Size (on track, layer2)",100,0.,100.);
268  meClSizeOnTrack_layer2->setAxisTitle("Cluster size (in pixels)",1);
269  meClSizeOnTrack_layer3 = dbe_->book1D("size_" + clustersrc_.label() + "_Layer_3","Size (on track, layer3)",100,0.,100.);
270  meClSizeOnTrack_layer3->setAxisTitle("Cluster size (in pixels)",1);
271  meClSizeOnTrack_diskp1 = dbe_->book1D("size_" + clustersrc_.label() + "_Disk_p1","Size (on track, diskp1)",100,0.,100.);
272  meClSizeOnTrack_diskp1->setAxisTitle("Cluster size (in pixels)",1);
273  meClSizeOnTrack_diskp2 = dbe_->book1D("size_" + clustersrc_.label() + "_Disk_p2","Size (on track, diskp2)",100,0.,100.);
274  meClSizeOnTrack_diskp2->setAxisTitle("Cluster size (in pixels)",1);
275  meClSizeOnTrack_diskm1 = dbe_->book1D("size_" + clustersrc_.label() + "_Disk_m1","Size (on track, diskm1)",100,0.,100.);
276  meClSizeOnTrack_diskm1->setAxisTitle("Cluster size (in pixels)",1);
277  meClSizeOnTrack_diskm2 = dbe_->book1D("size_" + clustersrc_.label() + "_Disk_m2","Size (on track, diskm2)",100,0.,100.);
278  meClSizeOnTrack_diskm2->setAxisTitle("Cluster size (in pixels)",1);
279  meClSizeXOnTrack_all = dbe_->book1D("sizeX_" + clustersrc_.label(),"SizeX (on track)",100,0.,100.);
280  meClSizeXOnTrack_all->setAxisTitle("Cluster sizeX (in pixels)",1);
281  meClSizeXOnTrack_bpix = dbe_->book1D("sizeX_" + clustersrc_.label() + "_Barrel","SizeX (on track, barrel)",100,0.,100.);
282  meClSizeXOnTrack_bpix->setAxisTitle("Cluster sizeX (in pixels)",1);
283  meClSizeXOnTrack_fpix = dbe_->book1D("sizeX_" + clustersrc_.label() + "_Endcap","SizeX (on track, endcap)",100,0.,100.);
284  meClSizeXOnTrack_fpix->setAxisTitle("Cluster sizeX (in pixels)",1);
285  meClSizeXOnTrack_layer1 = dbe_->book1D("sizeX_" + clustersrc_.label() + "_Layer_1","SizeX (on track, layer1)",100,0.,100.);
286  meClSizeXOnTrack_layer1->setAxisTitle("Cluster size (in pixels)",1);
287  meClSizeXOnTrack_layer2 = dbe_->book1D("sizeX_" + clustersrc_.label() + "_Layer_2","SizeX (on track, layer2)",100,0.,100.);
288  meClSizeXOnTrack_layer2->setAxisTitle("Cluster size (in pixels)",1);
289  meClSizeXOnTrack_layer3 = dbe_->book1D("sizeX_" + clustersrc_.label() + "_Layer_3","SizeX (on track, layer3)",100,0.,100.);
290  meClSizeXOnTrack_layer3->setAxisTitle("Cluster size (in pixels)",1);
291  meClSizeXOnTrack_diskp1 = dbe_->book1D("sizeX_" + clustersrc_.label() + "_Disk_p1","SizeX (on track, diskp1)",100,0.,100.);
292  meClSizeXOnTrack_diskp1->setAxisTitle("Cluster size (in pixels)",1);
293  meClSizeXOnTrack_diskp2 = dbe_->book1D("sizeX_" + clustersrc_.label() + "_Disk_p2","SizeX (on track, diskp2)",100,0.,100.);
294  meClSizeXOnTrack_diskp2->setAxisTitle("Cluster size (in pixels)",1);
295  meClSizeXOnTrack_diskm1 = dbe_->book1D("sizeX_" + clustersrc_.label() + "_Disk_m1","SizeX (on track, diskm1)",100,0.,100.);
296  meClSizeXOnTrack_diskm1->setAxisTitle("Cluster size (in pixels)",1);
297  meClSizeXOnTrack_diskm2 = dbe_->book1D("sizeX_" + clustersrc_.label() + "_Disk_m2","SizeX (on track, diskm2)",100,0.,100.);
298  meClSizeXOnTrack_diskm2->setAxisTitle("Cluster size (in pixels)",1);
299  meClSizeYOnTrack_all = dbe_->book1D("sizeY_" + clustersrc_.label(),"SizeY (on track)",100,0.,100.);
300  meClSizeYOnTrack_all->setAxisTitle("Cluster sizeY (in pixels)",1);
301  meClSizeYOnTrack_bpix = dbe_->book1D("sizeY_" + clustersrc_.label() + "_Barrel","SizeY (on track, barrel)",100,0.,100.);
302  meClSizeYOnTrack_bpix->setAxisTitle("Cluster sizeY (in pixels)",1);
303  meClSizeYOnTrack_fpix = dbe_->book1D("sizeY_" + clustersrc_.label() + "_Endcap","SizeY (on track, endcap)",100,0.,100.);
304  meClSizeYOnTrack_fpix->setAxisTitle("Cluster sizeY (in pixels)",1);
305  meClSizeYOnTrack_layer1 = dbe_->book1D("sizeY_" + clustersrc_.label() + "_Layer_1","SizeY (on track, layer1)",100,0.,100.);
306  meClSizeYOnTrack_layer1->setAxisTitle("Cluster size (in pixels)",1);
307  meClSizeYOnTrack_layer2 = dbe_->book1D("sizeY_" + clustersrc_.label() + "_Layer_2","SizeY (on track, layer2)",100,0.,100.);
308  meClSizeYOnTrack_layer2->setAxisTitle("Cluster size (in pixels)",1);
309  meClSizeYOnTrack_layer3 = dbe_->book1D("sizeY_" + clustersrc_.label() + "_Layer_3","SizeY (on track, layer3)",100,0.,100.);
310  meClSizeYOnTrack_layer3->setAxisTitle("Cluster size (in pixels)",1);
311  meClSizeYOnTrack_diskp1 = dbe_->book1D("sizeY_" + clustersrc_.label() + "_Disk_p1","SizeY (on track, diskp1)",100,0.,100.);
312  meClSizeYOnTrack_diskp1->setAxisTitle("Cluster size (in pixels)",1);
313  meClSizeYOnTrack_diskp2 = dbe_->book1D("sizeY_" + clustersrc_.label() + "_Disk_p2","SizeY (on track, diskp2)",100,0.,100.);
314  meClSizeYOnTrack_diskp2->setAxisTitle("Cluster size (in pixels)",1);
315  meClSizeYOnTrack_diskm1 = dbe_->book1D("sizeY_" + clustersrc_.label() + "_Disk_m1","SizeY (on track, diskm1)",100,0.,100.);
316  meClSizeYOnTrack_diskm1->setAxisTitle("Cluster size (in pixels)",1);
317  meClSizeYOnTrack_diskm2 = dbe_->book1D("sizeY_" + clustersrc_.label() + "_Disk_m2","SizeY (on track, diskm2)",100,0.,100.);
318  meClSizeYOnTrack_diskm2->setAxisTitle("Cluster size (in pixels)",1);
319  //off track
320  dbe_->setCurrentFolder("Pixel/Clusters/OffTrack");
321  meClSizeNotOnTrack_all = dbe_->book1D("size_" + clustersrc_.label(),"Size (off track)",100,0.,100.);
322  meClSizeNotOnTrack_all->setAxisTitle("Cluster size (in pixels)",1);
323  meClSizeNotOnTrack_bpix = dbe_->book1D("size_" + clustersrc_.label() + "_Barrel","Size (off track, barrel)",100,0.,100.);
324  meClSizeNotOnTrack_bpix->setAxisTitle("Cluster size (in pixels)",1);
325  meClSizeNotOnTrack_fpix = dbe_->book1D("size_" + clustersrc_.label() + "_Endcap","Size (off track, endcap)",100,0.,100.);
326  meClSizeNotOnTrack_fpix->setAxisTitle("Cluster size (in pixels)",1);
327  meClSizeNotOnTrack_layer1 = dbe_->book1D("size_" + clustersrc_.label() + "_Layer_1","Size (off track, layer1)",100,0.,100.);
328  meClSizeNotOnTrack_layer1->setAxisTitle("Cluster size (in pixels)",1);
329  meClSizeNotOnTrack_layer2 = dbe_->book1D("size_" + clustersrc_.label() + "_Layer_2","Size (off track, layer2)",100,0.,100.);
330  meClSizeNotOnTrack_layer2->setAxisTitle("Cluster size (in pixels)",1);
331  meClSizeNotOnTrack_layer3 = dbe_->book1D("size_" + clustersrc_.label() + "_Layer_3","Size (off track, layer3)",100,0.,100.);
332  meClSizeNotOnTrack_layer3->setAxisTitle("Cluster size (in pixels)",1);
333  meClSizeNotOnTrack_diskp1 = dbe_->book1D("size_" + clustersrc_.label() + "_Disk_p1","Size (off track, diskp1)",100,0.,100.);
334  meClSizeNotOnTrack_diskp1->setAxisTitle("Cluster size (in pixels)",1);
335  meClSizeNotOnTrack_diskp2 = dbe_->book1D("size_" + clustersrc_.label() + "_Disk_p2","Size (off track, diskp2)",100,0.,100.);
336  meClSizeNotOnTrack_diskp2->setAxisTitle("Cluster size (in pixels)",1);
337  meClSizeNotOnTrack_diskm1 = dbe_->book1D("size_" + clustersrc_.label() + "_Disk_m1","Size (off track, diskm1)",100,0.,100.);
338  meClSizeNotOnTrack_diskm1->setAxisTitle("Cluster size (in pixels)",1);
339  meClSizeNotOnTrack_diskm2 = dbe_->book1D("size_" + clustersrc_.label() + "_Disk_m2","Size (off track, diskm2)",100,0.,100.);
340  meClSizeNotOnTrack_diskm2->setAxisTitle("Cluster size (in pixels)",1);
341  meClSizeXNotOnTrack_all = dbe_->book1D("sizeX_" + clustersrc_.label(),"SizeX (off track)",100,0.,100.);
342  meClSizeXNotOnTrack_all->setAxisTitle("Cluster sizeX (in pixels)",1);
343  meClSizeXNotOnTrack_bpix = dbe_->book1D("sizeX_" + clustersrc_.label() + "_Barrel","SizeX (off track, barrel)",100,0.,100.);
344  meClSizeXNotOnTrack_bpix->setAxisTitle("Cluster sizeX (in pixels)",1);
345  meClSizeXNotOnTrack_fpix = dbe_->book1D("sizeX_" + clustersrc_.label() + "_Endcap","SizeX (off track, endcap)",100,0.,100.);
346  meClSizeXNotOnTrack_fpix->setAxisTitle("Cluster sizeX (in pixels)",1);
347  meClSizeXNotOnTrack_layer1 = dbe_->book1D("sizeX_" + clustersrc_.label() + "_Layer_1","SizeX (off track, layer1)",100,0.,100.);
348  meClSizeXNotOnTrack_layer1->setAxisTitle("Cluster size (in pixels)",1);
349  meClSizeXNotOnTrack_layer2 = dbe_->book1D("sizeX_" + clustersrc_.label() + "_Layer_2","SizeX (off track, layer2)",100,0.,100.);
350  meClSizeXNotOnTrack_layer2->setAxisTitle("Cluster size (in pixels)",1);
351  meClSizeXNotOnTrack_layer3 = dbe_->book1D("sizeX_" + clustersrc_.label() + "_Layer_3","SizeX (off track, layer3)",100,0.,100.);
352  meClSizeXNotOnTrack_layer3->setAxisTitle("Cluster size (in pixels)",1);
353  meClSizeXNotOnTrack_diskp1 = dbe_->book1D("sizeX_" + clustersrc_.label() + "_Disk_p1","SizeX (off track, diskp1)",100,0.,100.);
354  meClSizeXNotOnTrack_diskp1->setAxisTitle("Cluster size (in pixels)",1);
355  meClSizeXNotOnTrack_diskp2 = dbe_->book1D("sizeX_" + clustersrc_.label() + "_Disk_p2","SizeX (off track, diskp2)",100,0.,100.);
356  meClSizeXNotOnTrack_diskp2->setAxisTitle("Cluster size (in pixels)",1);
357  meClSizeXNotOnTrack_diskm1 = dbe_->book1D("sizeX_" + clustersrc_.label() + "_Disk_m1","SizeX (off track, diskm1)",100,0.,100.);
358  meClSizeXNotOnTrack_diskm1->setAxisTitle("Cluster size (in pixels)",1);
359  meClSizeXNotOnTrack_diskm2 = dbe_->book1D("sizeX_" + clustersrc_.label() + "_Disk_m2","SizeX (off track, diskm2)",100,0.,100.);
360  meClSizeXNotOnTrack_diskm2->setAxisTitle("Cluster size (in pixels)",1);
361  meClSizeYNotOnTrack_all = dbe_->book1D("sizeY_" + clustersrc_.label(),"SizeY (off track)",100,0.,100.);
362  meClSizeYNotOnTrack_all->setAxisTitle("Cluster sizeY (in pixels)",1);
363  meClSizeYNotOnTrack_bpix = dbe_->book1D("sizeY_" + clustersrc_.label() + "_Barrel","SizeY (off track, barrel)",100,0.,100.);
364  meClSizeYNotOnTrack_bpix->setAxisTitle("Cluster sizeY (in pixels)",1);
365  meClSizeYNotOnTrack_fpix = dbe_->book1D("sizeY_" + clustersrc_.label() + "_Endcap","SizeY (off track, endcap)",100,0.,100.);
366  meClSizeYNotOnTrack_fpix->setAxisTitle("Cluster sizeY (in pixels)",1);
367  meClSizeYNotOnTrack_layer1 = dbe_->book1D("sizeY_" + clustersrc_.label() + "_Layer_1","SizeY (off track, layer1)",100,0.,100.);
368  meClSizeYNotOnTrack_layer1->setAxisTitle("Cluster size (in pixels)",1);
369  meClSizeYNotOnTrack_layer2 = dbe_->book1D("sizeY_" + clustersrc_.label() + "_Layer_2","SizeY (off track, layer2)",100,0.,100.);
370  meClSizeYNotOnTrack_layer2->setAxisTitle("Cluster size (in pixels)",1);
371  meClSizeYNotOnTrack_layer3 = dbe_->book1D("sizeY_" + clustersrc_.label() + "_Layer_3","SizeY (off track, layer3)",100,0.,100.);
372  meClSizeYNotOnTrack_layer3->setAxisTitle("Cluster size (in pixels)",1);
373  meClSizeYNotOnTrack_diskp1 = dbe_->book1D("sizeY_" + clustersrc_.label() + "_Disk_p1","SizeY (off track, diskp1)",100,0.,100.);
374  meClSizeYNotOnTrack_diskp1->setAxisTitle("Cluster size (in pixels)",1);
375  meClSizeYNotOnTrack_diskp2 = dbe_->book1D("sizeY_" + clustersrc_.label() + "_Disk_p2","SizeY (off track, diskp2)",100,0.,100.);
376  meClSizeYNotOnTrack_diskp2->setAxisTitle("Cluster size (in pixels)",1);
377  meClSizeYNotOnTrack_diskm1 = dbe_->book1D("sizeY_" + clustersrc_.label() + "_Disk_m1","SizeY (off track, diskm1)",100,0.,100.);
378  meClSizeYNotOnTrack_diskm1->setAxisTitle("Cluster size (in pixels)",1);
379  meClSizeYNotOnTrack_diskm2 = dbe_->book1D("sizeY_" + clustersrc_.label() + "_Disk_m2","SizeY (off track, diskm2)",100,0.,100.);
380  meClSizeYNotOnTrack_diskm2->setAxisTitle("Cluster size (in pixels)",1);
381 
382 
383  //cluster global position
384  //on track
385  dbe_->setCurrentFolder("Pixel/Clusters/OnTrack");
386  //bpix
387  meClPosLayer1OnTrack = dbe_->book2D("position_" + clustersrc_.label() + "_Layer_1","Clusters Layer1 (on track)",200,-30.,30.,128,-3.2,3.2);
388  meClPosLayer1OnTrack->setAxisTitle("Global Z (cm)",1);
389  meClPosLayer1OnTrack->setAxisTitle("Global #phi",2);
390  meClPosLayer2OnTrack = dbe_->book2D("position_" + clustersrc_.label() + "_Layer_2","Clusters Layer2 (on track)",200,-30.,30.,128,-3.2,3.2);
391  meClPosLayer2OnTrack->setAxisTitle("Global Z (cm)",1);
392  meClPosLayer2OnTrack->setAxisTitle("Global #phi",2);
393  meClPosLayer3OnTrack = dbe_->book2D("position_" + clustersrc_.label() + "_Layer_3","Clusters Layer3 (on track)",200,-30.,30.,128,-3.2,3.2);
394  meClPosLayer3OnTrack->setAxisTitle("Global Z (cm)",1);
395  meClPosLayer3OnTrack->setAxisTitle("Global #phi",2);
396  //fpix
397  meClPosDisk1pzOnTrack = dbe_->book2D("position_" + clustersrc_.label() + "_pz_Disk_1","Clusters +Z Disk1 (on track)",80,-20.,20.,80,-20.,20.);
398  meClPosDisk1pzOnTrack->setAxisTitle("Global X (cm)",1);
399  meClPosDisk1pzOnTrack->setAxisTitle("Global Y (cm)",2);
400  meClPosDisk2pzOnTrack = dbe_->book2D("position_" + clustersrc_.label() + "_pz_Disk_2","Clusters +Z Disk2 (on track)",80,-20.,20.,80,-20.,20.);
401  meClPosDisk2pzOnTrack->setAxisTitle("Global X (cm)",1);
402  meClPosDisk2pzOnTrack->setAxisTitle("Global Y (cm)",2);
403  meClPosDisk1mzOnTrack = dbe_->book2D("position_" + clustersrc_.label() + "_mz_Disk_1","Clusters -Z Disk1 (on track)",80,-20.,20.,80,-20.,20.);
404  meClPosDisk1mzOnTrack->setAxisTitle("Global X (cm)",1);
405  meClPosDisk1mzOnTrack->setAxisTitle("Global Y (cm)",2);
406  meClPosDisk2mzOnTrack = dbe_->book2D("position_" + clustersrc_.label() + "_mz_Disk_2","Clusters -Z Disk2 (on track)",80,-20.,20.,80,-20.,20.);
407  meClPosDisk2mzOnTrack->setAxisTitle("Global X (cm)",1);
408  meClPosDisk2mzOnTrack->setAxisTitle("Global Y (cm)",2);
409 
410  meNClustersOnTrack_all = dbe_->book1D("nclusters_" + clustersrc_.label(),"Number of Clusters (on Track)",50,0.,50.);
411  meNClustersOnTrack_all->setAxisTitle("Number of Clusters",1);
412  meNClustersOnTrack_bpix = dbe_->book1D("nclusters_" + clustersrc_.label() + "_Barrel","Number of Clusters (on track, barrel)",50,0.,50.);
413  meNClustersOnTrack_bpix->setAxisTitle("Number of Clusters",1);
414  meNClustersOnTrack_fpix = dbe_->book1D("nclusters_" + clustersrc_.label() + "_Endcap","Number of Clusters (on track, endcap)",50,0.,50.);
415  meNClustersOnTrack_fpix->setAxisTitle("Number of Clusters",1);
416  meNClustersOnTrack_layer1 = dbe_->book1D("nclusters_" + clustersrc_.label() + "_Layer_1","Number of Clusters (on track, layer1)",50,0.,50.);
417  meNClustersOnTrack_layer1->setAxisTitle("Number of Clusters",1);
418  meNClustersOnTrack_layer2 = dbe_->book1D("nclusters_" + clustersrc_.label() + "_Layer_2","Number of Clusters (on track, layer2)",50,0.,50.);
419  meNClustersOnTrack_layer2->setAxisTitle("Number of Clusters",1);
420  meNClustersOnTrack_layer3 = dbe_->book1D("nclusters_" + clustersrc_.label() + "_Layer_3","Number of Clusters (on track, layer3)",50,0.,50.);
421  meNClustersOnTrack_layer3->setAxisTitle("Number of Clusters",1);
422  meNClustersOnTrack_diskp1 = dbe_->book1D("nclusters_" + clustersrc_.label() + "_Disk_p1","Number of Clusters (on track, diskp1)",50,0.,50.);
423  meNClustersOnTrack_diskp1->setAxisTitle("Number of Clusters",1);
424  meNClustersOnTrack_diskp2 = dbe_->book1D("nclusters_" + clustersrc_.label() + "_Disk_p2","Number of Clusters (on track, diskp2)",50,0.,50.);
425  meNClustersOnTrack_diskp2->setAxisTitle("Number of Clusters",1);
426  meNClustersOnTrack_diskm1 = dbe_->book1D("nclusters_" + clustersrc_.label() + "_Disk_m1","Number of Clusters (on track, diskm1)",50,0.,50.);
427  meNClustersOnTrack_diskm1->setAxisTitle("Number of Clusters",1);
428  meNClustersOnTrack_diskm2 = dbe_->book1D("nclusters_" + clustersrc_.label() + "_Disk_m2","Number of Clusters (on track, diskm2)",50,0.,50.);
429  meNClustersOnTrack_diskm2->setAxisTitle("Number of Clusters",1);
430 
431  //not on track
432  dbe_->setCurrentFolder("Pixel/Clusters/OffTrack");
433  //bpix
434  meClPosLayer1NotOnTrack = dbe_->book2D("position_" + clustersrc_.label() + "_Layer_1","Clusters Layer1 (off track)",200,-30.,30.,128,-3.2,3.2);
435  meClPosLayer1NotOnTrack->setAxisTitle("Global Z (cm)",1);
436  meClPosLayer1NotOnTrack->setAxisTitle("Global #phi",2);
437  meClPosLayer2NotOnTrack = dbe_->book2D("position_" + clustersrc_.label() + "_Layer_2","Clusters Layer2 (off track)",200,-30.,30.,128,-3.2,3.2);
438  meClPosLayer2NotOnTrack->setAxisTitle("Global Z (cm)",1);
439  meClPosLayer2NotOnTrack->setAxisTitle("Global #phi",2);
440  meClPosLayer3NotOnTrack = dbe_->book2D("position_" + clustersrc_.label() + "_Layer_3","Clusters Layer3 (off track)",200,-30.,30.,128,-3.2,3.2);
441  meClPosLayer3NotOnTrack->setAxisTitle("Global Z (cm)",1);
442  meClPosLayer3NotOnTrack->setAxisTitle("Global #phi",2);
443  //fpix
444  meClPosDisk1pzNotOnTrack = dbe_->book2D("position_" + clustersrc_.label() + "_pz_Disk_1","Clusters +Z Disk1 (off track)",80,-20.,20.,80,-20.,20.);
445  meClPosDisk1pzNotOnTrack->setAxisTitle("Global X (cm)",1);
446  meClPosDisk1pzNotOnTrack->setAxisTitle("Global Y (cm)",2);
447  meClPosDisk2pzNotOnTrack = dbe_->book2D("position_" + clustersrc_.label() + "_pz_Disk_2","Clusters +Z Disk2 (off track)",80,-20.,20.,80,-20.,20.);
448  meClPosDisk2pzNotOnTrack->setAxisTitle("Global X (cm)",1);
449  meClPosDisk2pzNotOnTrack->setAxisTitle("Global Y (cm)",2);
450  meClPosDisk1mzNotOnTrack = dbe_->book2D("position_" + clustersrc_.label() + "_mz_Disk_1","Clusters -Z Disk1 (off track)",80,-20.,20.,80,-20.,20.);
451  meClPosDisk1mzNotOnTrack->setAxisTitle("Global X (cm)",1);
452  meClPosDisk1mzNotOnTrack->setAxisTitle("Global Y (cm)",2);
453  meClPosDisk2mzNotOnTrack = dbe_->book2D("position_" + clustersrc_.label() + "_mz_Disk_2","Clusters -Z Disk2 (off track)",80,-20.,20.,80,-20.,20.);
454  meClPosDisk2mzNotOnTrack->setAxisTitle("Global X (cm)",1);
455  meClPosDisk2mzNotOnTrack->setAxisTitle("Global Y (cm)",2);
456 
457  meNClustersNotOnTrack_all = dbe_->book1D("nclusters_" + clustersrc_.label(),"Number of Clusters (off Track)",50,0.,50.);
458  meNClustersNotOnTrack_all->setAxisTitle("Number of Clusters",1);
459  meNClustersNotOnTrack_bpix = dbe_->book1D("nclusters_" + clustersrc_.label() + "_Barrel","Number of Clusters (off track, barrel)",50,0.,50.);
460  meNClustersNotOnTrack_bpix->setAxisTitle("Number of Clusters",1);
461  meNClustersNotOnTrack_fpix = dbe_->book1D("nclusters_" + clustersrc_.label() + "_Endcap","Number of Clusters (off track, endcap)",50,0.,50.);
462  meNClustersNotOnTrack_fpix->setAxisTitle("Number of Clusters",1);
463  meNClustersNotOnTrack_layer1 = dbe_->book1D("nclusters_" + clustersrc_.label() + "_Layer_1","Number of Clusters (off track, layer1)",50,0.,50.);
464  meNClustersNotOnTrack_layer1->setAxisTitle("Number of Clusters",1);
465  meNClustersNotOnTrack_layer2 = dbe_->book1D("nclusters_" + clustersrc_.label() + "_Layer_2","Number of Clusters (off track, layer2)",50,0.,50.);
466  meNClustersNotOnTrack_layer2->setAxisTitle("Number of Clusters",1);
467  meNClustersNotOnTrack_layer3 = dbe_->book1D("nclusters_" + clustersrc_.label() + "_Layer_3","Number of Clusters (off track, layer3)",50,0.,50.);
468  meNClustersNotOnTrack_layer3->setAxisTitle("Number of Clusters",1);
469  meNClustersNotOnTrack_diskp1 = dbe_->book1D("nclusters_" + clustersrc_.label() + "_Disk_p1","Number of Clusters (off track, diskp1)",50,0.,50.);
470  meNClustersNotOnTrack_diskp1->setAxisTitle("Number of Clusters",1);
471  meNClustersNotOnTrack_diskp2 = dbe_->book1D("nclusters_" + clustersrc_.label() + "_Disk_p2","Number of Clusters (off track, diskp2)",50,0.,50.);
472  meNClustersNotOnTrack_diskp2->setAxisTitle("Number of Clusters",1);
473  meNClustersNotOnTrack_diskm1 = dbe_->book1D("nclusters_" + clustersrc_.label() + "_Disk_m1","Number of Clusters (off track, diskm1)",50,0.,50.);
474  meNClustersNotOnTrack_diskm1->setAxisTitle("Number of Clusters",1);
475  meNClustersNotOnTrack_diskm2 = dbe_->book1D("nclusters_" + clustersrc_.label() + "_Disk_m2","Number of Clusters (off track, diskm2)",50,0.,50.);
476  meNClustersNotOnTrack_diskm2->setAxisTitle("Number of Clusters",1);
477 
478  //HitProbability
479  //on track
480  dbe_->setCurrentFolder("Pixel/Clusters/OnTrack");
481  meHitProbability = dbe_->book1D("FractionLowProb","Fraction of hits with low probability;FractionLowProb;#HitsOnTrack",100,0.,1.);
482 
483  if (debug_) {
484  // book summary residual histograms in a debugging folder - one (x,y) pair of histograms per subdetector
485  dbe_->setCurrentFolder("debugging");
486  char hisID[80];
487  for (int s=0; s<3; s++) {
488  sprintf(hisID,"residual_x_subdet_%i",s);
489  meSubdetResidualX[s] = dbe_->book1D(hisID,"Pixel Hit-to-Track Residual in X",500,-5.,5.);
490 
491  sprintf(hisID,"residual_y_subdet_%i",s);
492  meSubdetResidualY[s] = dbe_->book1D(hisID,"Pixel Hit-to-Track Residual in Y",500,-5.,5.);
493  }
494  }
495 
496  firstRun = false;
497  }
498 }
499 
500 
502  LogInfo("PixelDQM") << "SiPixelTrackResidualSource endJob()";
503 
504  // save the residual histograms to an output root file
505  bool saveFile = pSet_.getUntrackedParameter<bool>("saveFile", true);
506  if (saveFile) {
508  LogInfo("PixelDQM") << " - saving histograms to "<< outputFile.data();
509  dbe_->save(outputFile);
510  }
511  LogInfo("PixelDQM") << endl; // dbe_->showDirStructure();
512 }
513 
514 
516  //Retrieve tracker topology from geometry
517  edm::ESHandle<TrackerTopology> tTopoHandle;
518  iSetup.get<IdealGeometryRecord>().get(tTopoHandle);
519  const TrackerTopology* const tTopo = tTopoHandle.product();
520 
521 
522 
523  // retrieve TrackerGeometry again and MagneticField for use in transforming
524  // a TrackCandidate's P(ersistent)TrajectoryStateoOnDet (PTSoD) to a TrajectoryStateOnSurface (TSoS)
526  iSetup.get<TrackerDigiGeometryRecord>().get(TG);
527  const TrackerGeometry* theTrackerGeometry = TG.product();
528 
529  //analytic triplet method to calculate the track residuals in the pixe barrel detector
530 
531  //--------------------------------------------------------------------
532  // beam spot:
533  //
535  iEvent.getByLabel( "offlineBeamSpot", rbs );
536  math::XYZPoint bsP = math::XYZPoint(0,0,0);
537  if( !rbs.failedToGet() && rbs.isValid() )
538  {
539  bsP = math::XYZPoint( rbs->x0(), rbs->y0(), rbs->z0() );
540  }
541 
542  //--------------------------------------------------------------------
543  // primary vertices:
544  //
546  iEvent.getByLabel("offlinePrimaryVertices", vertices );
547 
548  if( vertices.failedToGet() ) return;
549  if( !vertices.isValid() ) return;
550 
551  math::XYZPoint vtxN = math::XYZPoint(0,0,0);
552  math::XYZPoint vtxP = math::XYZPoint(0,0,0);
553 
554  double bestNdof = 0;
555  double maxSumPt = 0;
556  reco::Vertex bestPvx;
557  for(reco::VertexCollection::const_iterator iVertex = vertices->begin();
558  iVertex != vertices->end(); ++iVertex ) {
559  if( iVertex->ndof() > bestNdof ) {
560  bestNdof = iVertex->ndof();
561  vtxN = math::XYZPoint( iVertex->x(), iVertex->y(), iVertex->z() );
562  }//ndof
563  if( iVertex->p4().pt() > maxSumPt ) {
564  maxSumPt = iVertex->p4().pt();
565  vtxP = math::XYZPoint( iVertex->x(), iVertex->y(), iVertex->z() );
566  bestPvx = *iVertex;
567  }//sumpt
568 
569  }//vertex
570 
571  if( maxSumPt < 1 ) return;
572 
573  if( maxSumPt < 1 ) vtxP = vtxN;
574 
575  //---------------------------------------------
576  //get Tracks
577  //
579  iEvent.getByLabel( "generalTracks", TracksForRes );
580  //
581  // transient track builder, needs B-field from data base (global tag in .py)
582  //
584  iSetup.get<TransientTrackRecord>().get( "TransientTrackBuilder", theB );
585 
586  //get the TransienTrackingRecHitBuilder needed for extracting the global position of the hits in the pixel
587  edm::ESHandle<TransientTrackingRecHitBuilder> theTrackerRecHitBuilder;
588  iSetup.get<TransientRecHitRecord>().get(ttrhbuilder_,theTrackerRecHitBuilder);
589 
590  //check that tracks are valid
591  if( TracksForRes.failedToGet() ) return;
592  if( !TracksForRes.isValid() ) return;
593 
594  //get tracker geometry
596  iSetup.get<TrackerDigiGeometryRecord>().get(pDD);
597 
598  if( !pDD.isValid() ) {
599  cout << "Unable to find TrackerDigiGeometry. Return\n";
600  return;
601  }
602 
603  int kk = -1;
604  //----------------------------------------------------------------------------
605  // Residuals:
606  //
607  for( reco::TrackCollection::const_iterator iTrack = TracksForRes->begin();
608  iTrack != TracksForRes->end(); ++iTrack ) {
609  //count
610  kk++;
611  //Calculate minimal track pt before curling
612  // cpt = cqRB = 0.3*R[m]*B[T] = 1.14*R[m] for B=3.8T
613  // D = 2R = 2*pt/1.14
614  // calo: D = 1.3 m => pt = 0.74 GeV/c
615  double pt = iTrack->pt();
616  if( pt < 0.75 ) continue;// curls up
617  if( abs( iTrack->dxy(vtxP) ) > 5*iTrack->dxyError() ) continue; // not prompt
618 
619  double charge = iTrack->charge();
620 
621  reco::TransientTrack tTrack = theB->build(*iTrack);
622  //get curvature of the track, needed for the residuals
623  double kap = tTrack.initialFreeState().transverseCurvature();
624  //needed for the TransienTrackingRecHitBuilder
626  if( iTrack->extra().isNonnull() &&iTrack->extra().isAvailable() ){
627 
628  double x1 = 0;
629  double y1 = 0;
630  double z1 = 0;
631  double x2 = 0;
632  double y2 = 0;
633  double z2 = 0;
634  double x3 = 0;
635  double y3 = 0;
636  double z3 = 0;
637  int n1 = 0;
638  int n2 = 0;
639  int n3 = 0;
640 
641  //for saving the pixel barrel hits
642  vector<TransientTrackingRecHit::RecHitPointer> GoodPixBarrelHits;
643  //looping through the RecHits of the track
644  for( trackingRecHit_iterator irecHit = iTrack->recHitsBegin();
645  irecHit != iTrack->recHitsEnd(); ++irecHit){
646 
647  if( (*irecHit)->isValid() ){
648  DetId detId = (*irecHit)->geographicalId();
649  // enum Detector { Tracker=1, Muon=2, Ecal=3, Hcal=4, Calo=5 };
650  if( detId.det() != 1 ){
651  if(debug_){
652  cout << "rec hit ID = " << detId.det() << " not in tracker!?!?\n";
653  }
654  continue;
655  }
656  uint32_t subDet = detId.subdetId();
657 
658  // enum SubDetector{ PixelBarrel=1, PixelEndcap=2 };
659  // enum SubDetector{ TIB=3, TID=4, TOB=5, TEC=6 };
660 
661  TransientTrackingRecHit::RecHitPointer trecHit = theTrackerRecHitBuilder->build( &*(*irecHit), initialTSOS);
662 
663 
664  double gX = trecHit->globalPosition().x();
665  double gY = trecHit->globalPosition().y();
666  double gZ = trecHit->globalPosition().z();
667 
668 
669  if( subDet == PixelSubdetector::PixelBarrel ) {
670 
671  int ilay = tTopo->pxbLayer(detId);
672 
673  if( ilay == 1 ){
674  n1++;
675  x1 = gX;
676  y1 = gY;
677  z1 = gZ;
678 
679  GoodPixBarrelHits.push_back((trecHit));
680  }//PXB1
681  if( ilay == 2 ){
682 
683  n2++;
684  x2 = gX;
685  y2 = gY;
686  z2 = gZ;
687 
688  GoodPixBarrelHits.push_back((trecHit));
689 
690  }//PXB2
691  if( ilay == 3 ){
692 
693  n3++;
694  x3 = gX;
695  y3 = gY;
696  z3 = gZ;
697  GoodPixBarrelHits.push_back((trecHit));
698  }
699  }//PXB
700 
701 
702  }//valid
703  }//loop rechits
704 
705  //CS extra plots
706 
707 
708  if( n1+n2+n3 == 3 && n1*n2*n3 > 0) {
709  for( unsigned int i = 0; i < GoodPixBarrelHits.size(); i++){
710 
711  if( GoodPixBarrelHits[i]->isValid() ){
712  DetId detId = GoodPixBarrelHits[i]->geographicalId().rawId();
713  int ilay = tTopo->pxbLayer(detId);
714  if(pt > ptminres_){
715 
716  double dca2 = 0.0, dz2=0.0;
717  double ptsig = pt;
718  if(charge<0.) ptsig = -pt;
719  //Filling the histograms in modules
720 
721  MeasurementPoint Test;
722  MeasurementPoint Test2;
723  Test=MeasurementPoint(0,0);
724  Test2=MeasurementPoint(0,0);
725  Measurement2DVector residual;
726 
727  if( ilay == 1 ){
728 
729  triplets(x2,y2,z2,x1,y1,z1,x3,y3,z3,ptsig,dca2,dz2, kap);
730 
731  Test=MeasurementPoint(dca2*1E4,dz2*1E4);
732  residual=Test-Test2;
733  }
734 
735  if( ilay == 2 ){
736 
737  triplets(x1,y1,z1,x2,y2,z2,x3,y3,z3,ptsig,dca2,dz2, kap);
738 
739  Test=MeasurementPoint(dca2*1E4,dz2*1E4);
740  residual=Test-Test2;
741 
742  }
743 
744  if( ilay == 3 ){
745 
746  triplets(x1,y1,z1,x3,y3,z3,x2,y2,z2,ptsig,dca2,dz2, kap);
747 
748  Test=MeasurementPoint(dca2*1E4,dz2*1E4);
749  residual=Test-Test2;
750  }
751  // fill the residual histograms
752 
753  std::map<uint32_t, SiPixelTrackResidualModule*>::iterator pxd = theSiPixelStructure.find(detId);
754  if (pxd!=theSiPixelStructure.end()) (*pxd).second->fill(residual, reducedSet, modOn, ladOn, layOn, phiOn, bladeOn, diskOn, ringOn);
755  }//three hits
756  }//is valid
757  }//rechits loop
758  }//pt 4
759  }
760 
761 
762  }//-----Tracks
764  //get trajectories
765  edm::Handle<std::vector<Trajectory> > trajCollectionHandle;
766  iEvent.getByLabel(tracksrc_,trajCollectionHandle);
767  const std::vector<Trajectory> trajColl = *(trajCollectionHandle.product());
768 
769  //get tracks
770  edm::Handle<std::vector<reco::Track> > trackCollectionHandle;
771  iEvent.getByLabel(tracksrc_,trackCollectionHandle);
772  const std::vector<reco::Track> trackColl = *(trackCollectionHandle.product());
773 
774  //get the map
776  iEvent.getByLabel(tracksrc_,match);
777  const TrajTrackAssociationCollection ttac = *(match.product());
778 
779  // get clusters
781  iEvent.getByLabel( clustersrc_, clusterColl );
782  const edmNew::DetSetVector<SiPixelCluster> clustColl = *(clusterColl.product());
783 
784  if(debug_){
785  std::cout << "Trajectories\t : " << trajColl.size() << std::endl;
786  std::cout << "recoTracks \t : " << trackColl.size() << std::endl;
787  std::cout << "Map entries \t : " << ttac.size() << std::endl;
788  }
789 
790  std::set<SiPixelCluster> clusterSet;
791  TrajectoryStateCombiner tsoscomb;
792  int tracks=0, pixeltracks=0, bpixtracks=0, fpixtracks=0;
793  int trackclusters=0, barreltrackclusters=0, endcaptrackclusters=0;
794  int otherclusters=0, barrelotherclusters=0, endcapotherclusters=0;
795 
796  //Loop over map entries
797  for(TrajTrackAssociationCollection::const_iterator it = ttac.begin();it != ttac.end(); ++it){
798  const edm::Ref<std::vector<Trajectory> > traj_iterator = it->key;
799  // Trajectory Map, extract Trajectory for this track
800  reco::TrackRef trackref = it->val;
801  tracks++;
802 
803  bool isBpixtrack = false, isFpixtrack = false, crossesPixVol=false;
804 
805  //find out whether track crosses pixel fiducial volume (for cosmic tracks)
806 
807  double d0 = (*trackref).d0(), dz = (*trackref).dz();
808 
809  if(abs(d0)<15 && abs(dz)<50) crossesPixVol = true;
810 
811  std::vector<TrajectoryMeasurement> tmeasColl =traj_iterator->measurements();
812  std::vector<TrajectoryMeasurement>::const_iterator tmeasIt;
813  //loop on measurements to find out whether there are bpix and/or fpix hits
814  for(tmeasIt = tmeasColl.begin();tmeasIt!=tmeasColl.end();tmeasIt++){
815  if(! tmeasIt->updatedState().isValid()) continue;
816  TransientTrackingRecHit::ConstRecHitPointer testhit = tmeasIt->recHit();
817  if(! testhit->isValid() || testhit->geographicalId().det() != DetId::Tracker) continue;
818  uint testSubDetID = (testhit->geographicalId().subdetId());
819  if(testSubDetID==PixelSubdetector::PixelBarrel) isBpixtrack = true;
820  if(testSubDetID==PixelSubdetector::PixelEndcap) isFpixtrack = true;
821  }//end loop on measurements
822  if(isBpixtrack) {
823  bpixtracks++;
824  if(debug_) std::cout << "bpixtrack\n";
825  }
826  if(isFpixtrack) {
827  fpixtracks++;
828  if(debug_) std::cout << "fpixtrack\n";
829  }
830  if(isBpixtrack || isFpixtrack){
831  pixeltracks++;
832 
833  if(crossesPixVol) meNofTracksInPixVol_->Fill(0,1);
834 
835  std::vector<TrajectoryMeasurement> tmeasColl = traj_iterator->measurements();
836  for(std::vector<TrajectoryMeasurement>::const_iterator tmeasIt = tmeasColl.begin(); tmeasIt!=tmeasColl.end(); tmeasIt++){
837  if(! tmeasIt->updatedState().isValid()) continue;
838 
839  TrajectoryStateOnSurface tsos = tsoscomb( tmeasIt->forwardPredictedState(), tmeasIt->backwardPredictedState() );
841  if(! hit->isValid() || hit->geographicalId().det() != DetId::Tracker ) {
842  continue;
843  } else {
844 
845 // //residual
846  const DetId & hit_detId = hit->geographicalId();
847  //uint IntRawDetID = (hit_detId.rawId());
848  uint IntSubDetID = (hit_detId.subdetId());
849 
850  if(IntSubDetID == 0 ) continue; // don't look at SiStrip hits!
851 
852  // get the enclosed persistent hit
853  const TrackingRecHit *persistentHit = hit->hit();
854  // check if it's not null, and if it's a valid pixel hit
855  if ((persistentHit != 0) && (typeid(*persistentHit) == typeid(SiPixelRecHit))) {
856  // tell the C++ compiler that the hit is a pixel hit
857  const SiPixelRecHit* pixhit = static_cast<const SiPixelRecHit*>( hit->hit() );
858  //Hit probability:
859  float hit_prob = -1.;
860  if(pixhit->hasFilledProb()){
861  hit_prob = pixhit->clusterProbability(0);
862  //std::cout<<"HITPROB= "<<hit_prob<<std::endl;
863  if(hit_prob<pow(10.,-15.)) NLowProb++;
864  NTotal++;
865  if(NTotal>0) meHitProbability->Fill(float(NLowProb/NTotal));
866  }
867 
868  // get the edm::Ref to the cluster
869  edm::Ref<edmNew::DetSetVector<SiPixelCluster>, SiPixelCluster> const& clust = (*pixhit).cluster();
870  // check if the ref is not null
871  if (clust.isNonnull()) {
872 
873  //define tracker and pixel geometry and topology
874  const TrackerGeometry& theTracker(*theTrackerGeometry);
875  const PixelGeomDetUnit* theGeomDet = static_cast<const PixelGeomDetUnit*> (theTracker.idToDet(hit_detId) );
876  //test if PixelGeomDetUnit exists
877  if(theGeomDet == 0) {
878  if(debug_) std::cout << "NO THEGEOMDET\n";
879  continue;
880  }
881 
882  const PixelTopology * topol = &(theGeomDet->specificTopology());
883  //fill histograms for clusters on tracks
884  //correct SiPixelTrackResidualModule
885  std::map<uint32_t, SiPixelTrackResidualModule*>::iterator pxd = theSiPixelStructure.find((*hit).geographicalId().rawId());
886 
887  //CHARGE CORRECTION (for track impact angle)
888  // calculate alpha and beta from cluster position
890  LocalVector localDir = ltp.momentum()/ltp.momentum().mag();
891 
892  float clust_alpha = atan2(localDir.z(), localDir.x());
893  float clust_beta = atan2(localDir.z(), localDir.y());
894  double corrCharge = clust->charge() * sqrt( 1.0 / ( 1.0/pow( tan(clust_alpha), 2 ) +
895  1.0/pow( tan(clust_beta ), 2 ) +
896  1.0 )
897  )/1000.;
898 
899  if (pxd!=theSiPixelStructure.end()) (*pxd).second->fill((*clust), true, corrCharge, reducedSet, modOn, ladOn, layOn, phiOn, bladeOn, diskOn, ringOn);
900 
901 
902  trackclusters++;
903  //CORR CHARGE
904  meClChargeOnTrack_all->Fill(corrCharge);
905  meClSizeOnTrack_all->Fill((*clust).size());
906  meClSizeXOnTrack_all->Fill((*clust).sizeX());
907  meClSizeYOnTrack_all->Fill((*clust).sizeY());
908  clusterSet.insert(*clust);
909 
910  //find cluster global position (rphi, z)
911  // get cluster center of gravity (of charge)
912  float xcenter = clust->x();
913  float ycenter = clust->y();
914  // get the cluster position in local coordinates (cm)
915  LocalPoint clustlp = topol->localPosition( MeasurementPoint(xcenter, ycenter) );
916  // get the cluster position in global coordinates (cm)
917  GlobalPoint clustgp = theGeomDet->surface().toGlobal( clustlp );
918 
919  //find location of hit (barrel or endcap, same for cluster)
920  bool barrel = DetId((*hit).geographicalId()).subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel);
921  bool endcap = DetId((*hit).geographicalId()).subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap);
922  if(barrel) {
923  barreltrackclusters++;
924  //CORR CHARGE
925  meClChargeOnTrack_bpix->Fill(corrCharge);
926  meClSizeOnTrack_bpix->Fill((*clust).size());
927  meClSizeXOnTrack_bpix->Fill((*clust).sizeX());
928  meClSizeYOnTrack_bpix->Fill((*clust).sizeY());
929  uint32_t DBlayer = PixelBarrelName(DetId((*hit).geographicalId())).layerName();
930  float phi = clustgp.phi();
931  float z = clustgp.z();
932  switch(DBlayer){
933  case 1: {
934  meClPosLayer1OnTrack->Fill(z,phi);
935  meClChargeOnTrack_layer1->Fill(corrCharge);
936  meClSizeOnTrack_layer1->Fill((*clust).size());
937  meClSizeXOnTrack_layer1->Fill((*clust).sizeX());
938  meClSizeYOnTrack_layer1->Fill((*clust).sizeY());
939  break;
940  }
941  case 2: {
942  meClPosLayer2OnTrack->Fill(z,phi);
943  meClChargeOnTrack_layer2->Fill(corrCharge);
944  meClSizeOnTrack_layer2->Fill((*clust).size());
945  meClSizeXOnTrack_layer2->Fill((*clust).sizeX());
946  meClSizeYOnTrack_layer2->Fill((*clust).sizeY());
947  break;
948  }
949  case 3: {
950  meClPosLayer3OnTrack->Fill(z,phi);
951  meClChargeOnTrack_layer3->Fill(corrCharge);
952  meClSizeOnTrack_layer3->Fill((*clust).size());
953  meClSizeXOnTrack_layer3->Fill((*clust).sizeX());
954  meClSizeYOnTrack_layer3->Fill((*clust).sizeY());
955  break;
956  }
957 
958  }
959 
960  }
961  if(endcap) {
962  endcaptrackclusters++;
963  //CORR CHARGE
964  meClChargeOnTrack_fpix->Fill(corrCharge);
965  meClSizeOnTrack_fpix->Fill((*clust).size());
966  meClSizeXOnTrack_fpix->Fill((*clust).sizeX());
967  meClSizeYOnTrack_fpix->Fill((*clust).sizeY());
968  uint32_t DBdisk = PixelEndcapName(DetId((*hit).geographicalId())).diskName();
969  float x = clustgp.x();
970  float y = clustgp.y();
971  float z = clustgp.z();
972  if(z>0){
973  if(DBdisk==1) {
975  meClChargeOnTrack_diskp1->Fill(corrCharge);
976  meClSizeOnTrack_diskp1->Fill((*clust).size());
977  meClSizeXOnTrack_diskp1->Fill((*clust).sizeX());
978  meClSizeYOnTrack_diskp1->Fill((*clust).sizeY());
979  }
980  if(DBdisk==2) {
982  meClChargeOnTrack_diskp2->Fill(corrCharge);
983  meClSizeOnTrack_diskp2->Fill((*clust).size());
984  meClSizeXOnTrack_diskp2->Fill((*clust).sizeX());
985  meClSizeYOnTrack_diskp2->Fill((*clust).sizeY());
986  }
987  }
988  else{
989  if(DBdisk==1) {
991  meClChargeOnTrack_diskm1->Fill(corrCharge);
992  meClSizeOnTrack_diskm1->Fill((*clust).size());
993  meClSizeXOnTrack_diskm1->Fill((*clust).sizeX());
994  meClSizeYOnTrack_diskm1->Fill((*clust).sizeY());
995  }
996  if(DBdisk==2) {
998  meClChargeOnTrack_diskm2->Fill(corrCharge);
999  meClSizeOnTrack_diskm2->Fill((*clust).size());
1000  meClSizeXOnTrack_diskm2->Fill((*clust).sizeX());
1001  meClSizeYOnTrack_diskm2->Fill((*clust).sizeY());
1002  }
1003  }
1004  }
1005 
1006  }//end if (cluster exists)
1007 
1008  }//end if (persistent hit exists and is pixel hit)
1009 
1010  }//end of else
1011 
1012 
1013  }//end for (all traj measurements of pixeltrack)
1014  }//end if (is pixeltrack)
1015  else {
1016  if(debug_) std::cout << "no pixeltrack:\n";
1017  if(crossesPixVol) meNofTracksInPixVol_->Fill(1,1);
1018  }
1019 
1020  }//end loop on map entries
1021 
1022  //find clusters that are NOT on track
1023  //edmNew::DetSet<SiPixelCluster>::const_iterator di;
1024  if(debug_) std::cout << "clusters not on track: (size " << clustColl.size() << ") ";
1025 
1026  for(TrackerGeometry::DetContainer::const_iterator it = TG->dets().begin(); it != TG->dets().end(); it++){
1027  //if(dynamic_cast<PixelGeomDetUnit*>((*it))!=0){
1028  DetId detId = (*it)->geographicalId();
1029  if(detId>=302055684 && detId<=352477708){ // make sure it's a Pixel module WITHOUT using dynamic_cast!
1030  int nofclOnTrack = 0, nofclOffTrack=0;
1031  uint32_t DBlayer=10, DBdisk=10;
1032  float z=0.;
1033  //set layer/disk
1034  if(DetId(detId).subdetId() == 1) { // Barrel module
1035  DBlayer = PixelBarrelName(DetId(detId)).layerName();
1036  }
1037  if(DetId(detId).subdetId() == 2){ // Endcap module
1038  DBdisk = PixelEndcapName(DetId(detId )).diskName();
1039  }
1041  if( isearch != clustColl.end() ) { // Not an empty iterator
1043  for(di=isearch->begin(); di!=isearch->end(); di++){
1044  unsigned int temp = clusterSet.size();
1045  clusterSet.insert(*di);
1046  //check if cluster is off track
1047  if(clusterSet.size()>temp) {
1048  otherclusters++;
1049  nofclOffTrack++;
1050  //fill histograms for clusters off tracks
1051  //correct SiPixelTrackResidualModule
1052  std::map<uint32_t, SiPixelTrackResidualModule*>::iterator pxd = theSiPixelStructure.find((*it)->geographicalId().rawId());
1053 
1054  if (pxd!=theSiPixelStructure.end()) (*pxd).second->fill((*di), false, -1., reducedSet, modOn, ladOn, layOn, phiOn, bladeOn, diskOn, ringOn);
1055 
1056 
1057 
1058  meClSizeNotOnTrack_all->Fill((*di).size());
1059  meClSizeXNotOnTrack_all->Fill((*di).sizeX());
1060  meClSizeYNotOnTrack_all->Fill((*di).sizeY());
1061  meClChargeNotOnTrack_all->Fill((*di).charge()/1000);
1062 
1064  //find cluster global position (rphi, z) get cluster
1065  //define tracker and pixel geometry and topology
1066  const TrackerGeometry& theTracker(*theTrackerGeometry);
1067  const PixelGeomDetUnit* theGeomDet = static_cast<const PixelGeomDetUnit*> (theTracker.idToDet(detId) );
1068  //test if PixelGeomDetUnit exists
1069  if(theGeomDet == 0) {
1070  if(debug_) std::cout << "NO THEGEOMDET\n";
1071  continue;
1072  }
1073  const PixelTopology * topol = &(theGeomDet->specificTopology());
1074 
1075  //center of gravity (of charge)
1076  float xcenter = di->x();
1077  float ycenter = di->y();
1078  // get the cluster position in local coordinates (cm)
1079  LocalPoint clustlp = topol->localPosition( MeasurementPoint(xcenter, ycenter) );
1080  // get the cluster position in global coordinates (cm)
1081  GlobalPoint clustgp = theGeomDet->surface().toGlobal( clustlp );
1082 
1084 
1085  //barrel
1086  if(DetId(detId).subdetId() == 1) {
1087  meClSizeNotOnTrack_bpix->Fill((*di).size());
1088  meClSizeXNotOnTrack_bpix->Fill((*di).sizeX());
1089  meClSizeYNotOnTrack_bpix->Fill((*di).sizeY());
1090  meClChargeNotOnTrack_bpix->Fill((*di).charge()/1000);
1091  barrelotherclusters++;
1092  //DBlayer = PixelBarrelName(DetId(detId)).layerName();
1093  float phi = clustgp.phi();
1094  //float r = clustgp.perp();
1095  z = clustgp.z();
1096  switch(DBlayer){
1097  case 1: {
1098  meClPosLayer1NotOnTrack->Fill(z,phi);
1099  meClSizeNotOnTrack_layer1->Fill((*di).size());
1100  meClSizeXNotOnTrack_layer1->Fill((*di).sizeX());
1101  meClSizeYNotOnTrack_layer1->Fill((*di).sizeY());
1102  meClChargeNotOnTrack_layer1->Fill((*di).charge()/1000);
1103  break;
1104  }
1105  case 2: {
1106  meClPosLayer2NotOnTrack->Fill(z,phi);
1107  meClSizeNotOnTrack_layer2->Fill((*di).size());
1108  meClSizeXNotOnTrack_layer2->Fill((*di).sizeX());
1109  meClSizeYNotOnTrack_layer2->Fill((*di).sizeY());
1110  meClChargeNotOnTrack_layer2->Fill((*di).charge()/1000);
1111  break;
1112  }
1113  case 3: {
1114  meClPosLayer3NotOnTrack->Fill(z,phi);
1115  meClSizeNotOnTrack_layer3->Fill((*di).size());
1116  meClSizeXNotOnTrack_layer3->Fill((*di).sizeX());
1117  meClSizeYNotOnTrack_layer3->Fill((*di).sizeY());
1118  meClChargeNotOnTrack_layer3->Fill((*di).charge()/1000);
1119  break;
1120  }
1121 
1122  }
1123  }
1124  //endcap
1125  if(DetId(detId).subdetId() == 2) {
1126  meClSizeNotOnTrack_fpix->Fill((*di).size());
1127  meClSizeXNotOnTrack_fpix->Fill((*di).sizeX());
1128  meClSizeYNotOnTrack_fpix->Fill((*di).sizeY());
1129  meClChargeNotOnTrack_fpix->Fill((*di).charge()/1000);
1130  endcapotherclusters++;
1131  //DBdisk = PixelEndcapName(DetId(detId )).diskName();
1132  float x = clustgp.x();
1133  float y = clustgp.y();
1134  z = clustgp.z();
1135  if(z>0){
1136  if(DBdisk==1) {
1138  meClSizeNotOnTrack_diskp1->Fill((*di).size());
1139  meClSizeXNotOnTrack_diskp1->Fill((*di).sizeX());
1140  meClSizeYNotOnTrack_diskp1->Fill((*di).sizeY());
1141  meClChargeNotOnTrack_diskp1->Fill((*di).charge()/1000);
1142  }
1143  if(DBdisk==2) {
1145  meClSizeNotOnTrack_diskp2->Fill((*di).size());
1146  meClSizeXNotOnTrack_diskp2->Fill((*di).sizeX());
1147  meClSizeYNotOnTrack_diskp2->Fill((*di).sizeY());
1148  meClChargeNotOnTrack_diskp2->Fill((*di).charge()/1000);
1149  }
1150  }
1151  else{
1152  if(DBdisk==1) {
1154  meClSizeNotOnTrack_diskm1->Fill((*di).size());
1155  meClSizeXNotOnTrack_diskm1->Fill((*di).sizeX());
1156  meClSizeYNotOnTrack_diskm1->Fill((*di).sizeY());
1157  meClChargeNotOnTrack_diskm1->Fill((*di).charge()/1000);
1158  }
1159  if(DBdisk==2) {
1161  meClSizeNotOnTrack_diskm2->Fill((*di).size());
1162  meClSizeXNotOnTrack_diskm2->Fill((*di).sizeX());
1163  meClSizeYNotOnTrack_diskm2->Fill((*di).sizeY());
1164  meClChargeNotOnTrack_diskm2->Fill((*di).charge()/1000);
1165  }
1166  }
1167 
1168  }
1169  }// end "if cluster off track"
1170  else {
1171  nofclOnTrack++;
1172  if(z == 0 && DBdisk != 10){
1173  //find cluster global position (rphi, z) get cluster
1174  //define tracker and pixel geometry and topology
1175  const TrackerGeometry& theTracker(*theTrackerGeometry);
1176  const PixelGeomDetUnit* theGeomDet = static_cast<const PixelGeomDetUnit*> (theTracker.idToDet(detId) );
1177  //test if PixelGeomDetUnit exists
1178  if(theGeomDet == 0) {
1179  if(debug_) std::cout << "NO THEGEOMDET\n";
1180  continue;
1181  }
1182  const PixelTopology * topol = &(theGeomDet->specificTopology());
1183  //center of gravity (of charge)
1184  float xcenter = di->x();
1185  float ycenter = di->y();
1186  // get the cluster position in local coordinates (cm)
1187  LocalPoint clustlp = topol->localPosition( MeasurementPoint(xcenter, ycenter) );
1188  // get the cluster position in global coordinates (cm)
1189  GlobalPoint clustgp = theGeomDet->surface().toGlobal( clustlp );
1190  z = clustgp.z();
1191  }
1192  }
1193  }
1194  }
1195  //++ fill the number of clusters on a module
1196  std::map<uint32_t, SiPixelTrackResidualModule*>::iterator pxd = theSiPixelStructure.find((*it)->geographicalId().rawId());
1197  if (pxd!=theSiPixelStructure.end()) (*pxd).second->nfill(nofclOnTrack, nofclOffTrack, reducedSet, modOn, ladOn, layOn, phiOn, bladeOn, diskOn, ringOn);
1198  if(nofclOnTrack!=0) meNClustersOnTrack_all->Fill(nofclOnTrack);
1199  if(nofclOffTrack!=0) meNClustersNotOnTrack_all->Fill(nofclOffTrack);
1200  //barrel
1201  if(DetId(detId).subdetId() == 1){
1202  if(nofclOnTrack!=0) meNClustersOnTrack_bpix->Fill(nofclOnTrack);
1203  if(nofclOffTrack!=0) meNClustersNotOnTrack_bpix->Fill(nofclOffTrack);
1204  //DBlayer = PixelBarrelName(DetId(detId)).layerName();
1205  switch(DBlayer){
1206  case 1: {
1207  if(nofclOnTrack!=0) meNClustersOnTrack_layer1->Fill(nofclOnTrack);
1208  if(nofclOffTrack!=0) meNClustersNotOnTrack_layer1->Fill(nofclOffTrack); break;
1209  }
1210  case 2: {
1211  if(nofclOnTrack!=0) meNClustersOnTrack_layer2->Fill(nofclOnTrack);
1212  if(nofclOffTrack!=0) meNClustersNotOnTrack_layer2->Fill(nofclOffTrack); break;
1213  }
1214  case 3: {
1215  if(nofclOnTrack!=0) meNClustersOnTrack_layer3->Fill(nofclOnTrack);
1216  if(nofclOffTrack!=0) meNClustersNotOnTrack_layer3->Fill(nofclOffTrack); break;
1217  }
1218  }
1219  }//end barrel
1220  //endcap
1221  if(DetId(detId).subdetId() == 2) {
1222  //DBdisk = PixelEndcapName(DetId(detId )).diskName();
1223  //z = clustgp.z();
1224  if(nofclOnTrack!=0) meNClustersOnTrack_fpix->Fill(nofclOnTrack);
1225  if(nofclOffTrack!=0) meNClustersNotOnTrack_fpix->Fill(nofclOffTrack);
1226  if(z>0){
1227  if(DBdisk==1) {
1228  if(nofclOnTrack!=0) meNClustersOnTrack_diskp1->Fill(nofclOnTrack);
1229  if(nofclOffTrack!=0) meNClustersNotOnTrack_diskp1->Fill(nofclOffTrack);
1230  }
1231  if(DBdisk==2) {
1232  if(nofclOnTrack!=0) meNClustersOnTrack_diskp2->Fill(nofclOnTrack);
1233  if(nofclOffTrack!=0) meNClustersNotOnTrack_diskp2->Fill(nofclOffTrack);
1234  }
1235  }
1236  if(z<0){
1237  if(DBdisk==1) {
1238  if(nofclOnTrack!=0) meNClustersOnTrack_diskm1->Fill(nofclOnTrack);
1239  if(nofclOffTrack!=0) meNClustersNotOnTrack_diskm1->Fill(nofclOffTrack);
1240  }
1241  if(DBdisk==2) {
1242  if(nofclOnTrack!=0) meNClustersOnTrack_diskm2->Fill(nofclOnTrack);
1243  if(nofclOffTrack!=0) meNClustersNotOnTrack_diskm2->Fill(nofclOffTrack);
1244  }
1245  }
1246  }
1247 
1248  }//end if it's a Pixel module
1249  }//end for loop over tracker detector geometry modules
1250 
1251 
1252  if(trackclusters>0) (meNofClustersOnTrack_)->Fill(0,trackclusters);
1253  if(barreltrackclusters>0)(meNofClustersOnTrack_)->Fill(1,barreltrackclusters);
1254  if(endcaptrackclusters>0)(meNofClustersOnTrack_)->Fill(2,endcaptrackclusters);
1255  if(otherclusters>0)(meNofClustersNotOnTrack_)->Fill(0,otherclusters);
1256  if(barrelotherclusters>0)(meNofClustersNotOnTrack_)->Fill(1,barrelotherclusters);
1257  if(endcapotherclusters>0)(meNofClustersNotOnTrack_)->Fill(2,endcapotherclusters);
1258  if(tracks>0)(meNofTracks_)->Fill(0,tracks);
1259  if(pixeltracks>0)(meNofTracks_)->Fill(1,pixeltracks);
1260  if(bpixtracks>0)(meNofTracks_)->Fill(2,bpixtracks);
1261  if(fpixtracks>0)(meNofTracks_)->Fill(3,fpixtracks);
1262 }
1263 void SiPixelTrackResidualSource::triplets(double x1,double y1,double z1,double x2,double y2,double z2,double x3,double y3,double z3,
1264  double ptsig, double & dca2,double & dz2, double kap) {
1265 
1266  //Define some constants
1267  using namespace std;
1268 
1269  //Curvature kap from global Track
1270 
1271  //inverse of the curvature is the radius in the transverse plane
1272  double rho = 1/kap;
1273  //Check that the hits are in the correct layers
1274  double r1 = sqrt( x1*x1 + y1*y1 );
1275  double r3 = sqrt( x3*x3 + y3*y3 );
1276 
1277  if( r3-r1 < 2.0 ) cout << "warn r1 = " << r1 << ", r3 = " << r3 << endl;
1278 
1279  // Calculate the centre of the helix in xy-projection with radius rho from the track.
1280  //start with a line (sekante) connecting the two points (x1,y1) and (x3,y3) vec_L = vec_x3-vec_x1
1281  //with L being the length of that vector.
1282  double L=sqrt((x3-x1)*(x3-x1)+(y3-y1)*(y3-y1));
1283  //lam is the line from the middel point of vec_q towards the center of the circle X0,Y0
1284  // we already have kap and rho = 1/kap
1285  double lam = sqrt(rho*rho - L*L/4);
1286 
1287  // There are two solutions, the sign of kap gives the information
1288  // which of them is correct.
1289  //
1290  if( kap > 0 ) lam = -lam;
1291 
1292  //
1293  // ( X0, Y0 ) is the centre of the circle that describes the helix in xy-projection.
1294  //
1295  double x0 = 0.5*( x1 + x3 ) + lam/L * ( -y1 + y3 );
1296  double y0 = 0.5*( y1 + y3 ) + lam/L * ( x1 - x3 );
1297 
1298  // Calculate the dipangle in z direction (needed later for z residual) :
1299  //Starting from the heliz equation whihc has to hold for both points z1,z3
1300  double num = ( y3 - y0 ) * ( x1 - x0 ) - ( x3 - x0 ) * ( y1 - y0 );
1301  double den = ( x1 - x0 ) * ( x3 - x0 ) + ( y1 - y0 ) * ( y3 - y0 );
1302  double tandip = kap * ( z3 - z1 ) / atan( num / den );
1303 
1304 
1305  // angle from first hit to dca point:
1306  //
1307  double dphi = atan( ( ( x1 - x0 ) * y0 - ( y1 - y0 ) * x0 )
1308  / ( ( x1 - x0 ) * x0 + ( y1 - y0 ) * y0 ) );
1309  //z position of the track based on the middle of the circle
1310  //track equation for the z component
1311  double uz0 = z1 + tandip * dphi * rho;
1312 
1314  //RESIDUAL IN R-PHI
1316  //Calculate distance dca2 from point (x2,y2) to the circle which is given by
1317  //the distance of the point to the middlepoint dcM = sqrt((x0-x2)^2+(y0-y2)) and rho
1318  //dca = rho +- dcM
1319  if(kap>0) dca2=rho-sqrt((x0-x2)*(x0-x2)+(y0-y2)*(y0-y2));
1320  else dca2=rho+sqrt((-x0+x2)*(-x0+x2)+(-y0+y2)*(-y0+y2));
1321 
1323  //RESIDUAL IN Z
1325  double xx =0 ;
1326  double yy =0 ;
1327  //sign of kappa determines the calculation
1328  //xx and yy are the new coordinates starting from x2, y2 that are on the track itself
1329  //vec_X2+-dca2*vec(X0-X2)/|(X0-X2)|
1330  if(kap<0){
1331  xx = x2+(dca2*((x0-x2))/sqrt((x0-x2)*(x0-x2)+(y0-y2)*(y0-y2)));
1332  yy = y2+(dca2*((y0-y2))/sqrt((x0-x2)*(x0-x2)+(y0-y2)*(y0-y2)));
1333  }
1334  else if(kap>=0){
1335  xx = x2-(dca2*((x0-x2))/sqrt((x0-x2)*(x0-x2)+(y0-y2)*(y0-y2)));
1336  yy = y2-(dca2*((y0-y2))/sqrt((x0-x2)*(x0-x2)+(y0-y2)*(y0-y2)));
1337  }
1338 
1339  //to get residual in z start with calculating the new uz2 position if one has moved to xx, yy
1340  //on the track. First calculate the change in phi2 with respect to the center X0, Y0
1341  double dphi2 = atan( ( ( xx - x0 ) * y0 - ( yy - y0 ) * x0 )
1342  / ( ( xx - x0 ) * x0 + ( yy - y0 ) * y0 ) );
1343  //Solve track equation for this new z depending on the dip angle of the track (see above
1344  //calculated based on X1, X3 and X0, use uz0 as reference point again.
1345  double uz2= uz0 - dphi2*tandip*rho;
1346 
1347  //subtract new z position from the old one
1348  dz2=z2-uz2;
1349 
1350  //if we are interested in the arclength this is unsigned though
1351  // double cosphi2 = (x2*xx+y2*yy)/(sqrt(x2*x2+y2*y2)*sqrt(xx*xx+yy*yy));
1352  //double arcdca2=sqrt(x2*x2+y2*y2)*acos(cosphi2);
1353 
1354 }
1355 
1356 
1357 DEFINE_FWK_MODULE(SiPixelTrackResidualSource); // define this as a plug-in
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:114
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
const_iterator begin() const
virtual LocalPoint localPosition(const MeasurementPoint &) const =0
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:722
const LocalTrajectoryParameters & localParameters() const
const_iterator end() const
last iterator over the map (read only)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void save(const std::string &filename, const std::string &path="", const std::string &pattern="", const std::string &rewrite="", SaveReferenceTag ref=SaveWithReference, int minStatus=dqm::qstatus::STATUS_OK, const std::string &fileupdate="RECREATE")
Definition: DQMStore.cc:2118
Definition: DDAxes.h:10
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
T y() const
Definition: PV3DBase.h:63
void setBinLabel(int bin, const std::string &label, int axis=1)
set bin label for x, y or z axis (axis=1, 2, 3 respectively)
#define abs(x)
Definition: mlp_lapack.h:159
data_type const * const_iterator
Definition: DetSetNew.h:25
const_iterator find(id_type i) const
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:35
SiPixelTrackResidualSource(const edm::ParameterSet &)
double charge(const std::vector< uint8_t > &Ampls)
float float float z
tuple gX
Definition: corrVsCorr.py:109
TrajectoryStateOnSurface innermostMeasurementState() const
virtual void beginRun(const edm::Run &r, edm::EventSetup const &iSetup)
void Fill(long long x)
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:250
Measurement2DPoint MeasurementPoint
Measurement points are two-dimensional by default.
int iEvent
Definition: GenABIO.cc:243
T mag() const
Definition: PV3DBase.h:67
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
T sqrt(T t)
Definition: SSEVec.h:48
T z() const
Definition: PV3DBase.h:64
void triplets(double x1, double y1, double z1, double x2, double y2, double z2, double x3, double y3, double z3, double ptsig, double &dc, double &dz, double kap)
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
LocalVector momentum() const
Momentum vector in the local frame.
const_iterator end() const
bool isValid() const
Definition: HandleBase.h:76
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:39
virtual const GeomDet * idToDet(DetId) const
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
double ndof() const
Definition: Vertex.h:89
unsigned int pxbLayer(const DetId &id) const
FreeTrajectoryState initialFreeState() const
bool failedToGet() const
Definition: HandleBase.h:80
Definition: DetId.h:20
std::map< uint32_t, SiPixelTrackResidualModule * > theSiPixelStructure
size_type size() const
map size
tuple tracks
Definition: testEve_cfg.py:39
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:13
const T & get() const
Definition: EventSetup.h:55
virtual const PixelTopology & specificTopology() const
Returns a reference to the pixel proxy topology.
key_type key() const
Accessor for product key.
Definition: Ref.h:266
int layerName() const
layer id
T const * product() const
Definition: ESHandle.h:62
long long int num
Definition: procUtils.cc:71
T const * product() const
Definition: Handle.h:74
tuple gY
Definition: corrVsCorr.py:110
double transverseCurvature() const
std::string const & label() const
Definition: InputTag.h:42
size_type size() const
Pixel cluster – collection of neighboring pixels above threshold.
tuple cout
Definition: gather_cfg.py:121
int diskName() const
disk id
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:6
const_iterator begin() const
first iterator over the map (read only)
virtual void analyze(const edm::Event &, const edm::EventSetup &)
Definition: DDAxes.h:10
bool isValid() const
Definition: ESHandle.h:37
MonitorElement * book2D(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Book 2D histogram.
Definition: DQMStore.cc:850
Detector det() const
get the detector field from this detid
Definition: DetId.h:37
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)
Definition: vlib.h:209
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:434
Definition: Run.h:36
bool setModuleFolder(const uint32_t &rawdetid=0, int type=0)
Set folder name for a module or plaquette.
Pixel Reconstructed Hit.
Definition: DDAxes.h:10