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.25 2012/09/11 09:37:41 clseitz 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) {
507  std::string outputFile = pSet_.getParameter<std::string>("outputFile");
508  LogInfo("PixelDQM") << " - saving histograms to "<< outputFile.data();
509  dbe_->save(outputFile);
510  }
511  LogInfo("PixelDQM") << endl; // dbe_->showDirStructure();
512 }
513 
514 
516 
517  // retrieve TrackerGeometry again and MagneticField for use in transforming
518  // a TrackCandidate's P(ersistent)TrajectoryStateoOnDet (PTSoD) to a TrajectoryStateOnSurface (TSoS)
520  iSetup.get<TrackerDigiGeometryRecord>().get(TG);
521  const TrackerGeometry* theTrackerGeometry = TG.product();
522 
523  //analytic triplet method to calculate the track residuals in the pixe barrel detector
524 
525  //--------------------------------------------------------------------
526  // beam spot:
527  //
529  iEvent.getByLabel( "offlineBeamSpot", rbs );
530  math::XYZPoint bsP = math::XYZPoint(0,0,0);
531  if( !rbs.failedToGet() && rbs.isValid() )
532  {
533  bsP = math::XYZPoint( rbs->x0(), rbs->y0(), rbs->z0() );
534  }
535 
536  //--------------------------------------------------------------------
537  // primary vertices:
538  //
540  iEvent.getByLabel("offlinePrimaryVertices", vertices );
541 
542  if( vertices.failedToGet() ) return;
543  if( !vertices.isValid() ) return;
544 
545  math::XYZPoint vtxN = math::XYZPoint(0,0,0);
546  math::XYZPoint vtxP = math::XYZPoint(0,0,0);
547 
548  double bestNdof = 0;
549  double maxSumPt = 0;
550  reco::Vertex bestPvx;
551  for(reco::VertexCollection::const_iterator iVertex = vertices->begin();
552  iVertex != vertices->end(); ++iVertex ) {
553  if( iVertex->ndof() > bestNdof ) {
554  bestNdof = iVertex->ndof();
555  vtxN = math::XYZPoint( iVertex->x(), iVertex->y(), iVertex->z() );
556  }//ndof
557  if( iVertex->p4().pt() > maxSumPt ) {
558  maxSumPt = iVertex->p4().pt();
559  vtxP = math::XYZPoint( iVertex->x(), iVertex->y(), iVertex->z() );
560  bestPvx = *iVertex;
561  }//sumpt
562 
563  }//vertex
564 
565  if( maxSumPt < 1 ) return;
566 
567  if( maxSumPt < 1 ) vtxP = vtxN;
568 
569  //---------------------------------------------
570  //get Tracks
571  //
573  iEvent.getByLabel( "generalTracks", TracksForRes );
574  //
575  // transient track builder, needs B-field from data base (global tag in .py)
576  //
578  iSetup.get<TransientTrackRecord>().get( "TransientTrackBuilder", theB );
579 
580  //get the TransienTrackingRecHitBuilder needed for extracting the global position of the hits in the pixel
581  edm::ESHandle<TransientTrackingRecHitBuilder> theTrackerRecHitBuilder;
582  iSetup.get<TransientRecHitRecord>().get(ttrhbuilder_,theTrackerRecHitBuilder);
583 
584  //check that tracks are valid
585  if( TracksForRes.failedToGet() ) return;
586  if( !TracksForRes.isValid() ) return;
587 
588  //get tracker geometry
590  iSetup.get<TrackerDigiGeometryRecord>().get(pDD);
591 
592  if( !pDD.isValid() ) {
593  cout << "Unable to find TrackerDigiGeometry. Return\n";
594  return;
595  }
596 
597  int kk = -1;
598  //----------------------------------------------------------------------------
599  // Residuals:
600  //
601  for( reco::TrackCollection::const_iterator iTrack = TracksForRes->begin();
602  iTrack != TracksForRes->end(); ++iTrack ) {
603  //count
604  kk++;
605  //Calculate minimal track pt before curling
606  // cpt = cqRB = 0.3*R[m]*B[T] = 1.14*R[m] for B=3.8T
607  // D = 2R = 2*pt/1.14
608  // calo: D = 1.3 m => pt = 0.74 GeV/c
609  double pt = iTrack->pt();
610  if( pt < 0.75 ) continue;// curls up
611  if( abs( iTrack->dxy(vtxP) ) > 5*iTrack->dxyError() ) continue; // not prompt
612 
613  double charge = iTrack->charge();
614 
615  reco::TransientTrack tTrack = theB->build(*iTrack);
616  //get curvature of the track, needed for the residuals
617  double kap = tTrack.initialFreeState().transverseCurvature();
618  //needed for the TransienTrackingRecHitBuilder
620  if( iTrack->extra().isNonnull() &&iTrack->extra().isAvailable() ){
621 
622  double x1 = 0;
623  double y1 = 0;
624  double z1 = 0;
625  double x2 = 0;
626  double y2 = 0;
627  double z2 = 0;
628  double x3 = 0;
629  double y3 = 0;
630  double z3 = 0;
631  int n1 = 0;
632  int n2 = 0;
633  int n3 = 0;
634 
635  //for saving the pixel barrel hits
636  vector<TransientTrackingRecHit::RecHitPointer> GoodPixBarrelHits;
637  //looping through the RecHits of the track
638  for( trackingRecHit_iterator irecHit = iTrack->recHitsBegin();
639  irecHit != iTrack->recHitsEnd(); ++irecHit){
640 
641  if( (*irecHit)->isValid() ){
642  DetId detId = (*irecHit)->geographicalId();
643  // enum Detector { Tracker=1, Muon=2, Ecal=3, Hcal=4, Calo=5 };
644  if( detId.det() != 1 ){
645  if(debug_){
646  cout << "rec hit ID = " << detId.det() << " not in tracker!?!?\n";
647  }
648  continue;
649  }
650  uint32_t subDet = detId.subdetId();
651 
652  // enum SubDetector{ PixelBarrel=1, PixelEndcap=2 };
653  // enum SubDetector{ TIB=3, TID=4, TOB=5, TEC=6 };
654 
655  TransientTrackingRecHit::RecHitPointer trecHit = theTrackerRecHitBuilder->build( &*(*irecHit), initialTSOS);
656 
657 
658  double gX = trecHit->globalPosition().x();
659  double gY = trecHit->globalPosition().y();
660  double gZ = trecHit->globalPosition().z();
661 
662 
663  if( subDet == PixelSubdetector::PixelBarrel ) {
664 
665  int ilay = PXBDetId(detId).layer();
666 
667  if( ilay == 1 ){
668  n1++;
669  x1 = gX;
670  y1 = gY;
671  z1 = gZ;
672 
673  GoodPixBarrelHits.push_back((trecHit));
674  }//PXB1
675  if( ilay == 2 ){
676 
677  n2++;
678  x2 = gX;
679  y2 = gY;
680  z2 = gZ;
681 
682  GoodPixBarrelHits.push_back((trecHit));
683 
684  }//PXB2
685  if( ilay == 3 ){
686 
687  n3++;
688  x3 = gX;
689  y3 = gY;
690  z3 = gZ;
691  GoodPixBarrelHits.push_back((trecHit));
692  }
693  }//PXB
694 
695 
696  }//valid
697  }//loop rechits
698 
699  //CS extra plots
700 
701 
702  if( n1+n2+n3 == 3 && n1*n2*n3 > 0) {
703  for( unsigned int i = 0; i < GoodPixBarrelHits.size(); i++){
704 
705  if( GoodPixBarrelHits[i]->isValid() ){
706  DetId detId = GoodPixBarrelHits[i]->geographicalId().rawId();
707  int ilay = PXBDetId(detId).layer();
708  if(pt > ptminres_){
709 
710  double dca2 = 0.0, dz2=0.0;
711  double ptsig = pt;
712  if(charge<0.) ptsig = -pt;
713  //Filling the histograms in modules
714 
715  MeasurementPoint Test;
716  MeasurementPoint Test2;
717  Test=MeasurementPoint(0,0);
718  Test2=MeasurementPoint(0,0);
719  Measurement2DVector residual;
720 
721  if( ilay == 1 ){
722 
723  triplets(x2,y2,z2,x1,y1,z1,x3,y3,z3,ptsig,dca2,dz2, kap);
724 
725  Test=MeasurementPoint(dca2*1E4,dz2*1E4);
726  residual=Test-Test2;
727  }
728 
729  if( ilay == 2 ){
730 
731  triplets(x1,y1,z1,x2,y2,z2,x3,y3,z3,ptsig,dca2,dz2, kap);
732 
733  Test=MeasurementPoint(dca2*1E4,dz2*1E4);
734  residual=Test-Test2;
735 
736  }
737 
738  if( ilay == 3 ){
739 
740  triplets(x1,y1,z1,x3,y3,z3,x2,y2,z2,ptsig,dca2,dz2, kap);
741 
742  Test=MeasurementPoint(dca2*1E4,dz2*1E4);
743  residual=Test-Test2;
744  }
745  // fill the residual histograms
746 
747  std::map<uint32_t, SiPixelTrackResidualModule*>::iterator pxd = theSiPixelStructure.find(detId);
748  if (pxd!=theSiPixelStructure.end()) (*pxd).second->fill(residual, reducedSet, modOn, ladOn, layOn, phiOn, bladeOn, diskOn, ringOn);
749  }//three hits
750  }//is valid
751  }//rechits loop
752  }//pt 4
753  }
754 
755 
756  }//-----Tracks
758  //get trajectories
759  edm::Handle<std::vector<Trajectory> > trajCollectionHandle;
760  iEvent.getByLabel(tracksrc_,trajCollectionHandle);
761  const std::vector<Trajectory> trajColl = *(trajCollectionHandle.product());
762 
763  //get tracks
764  edm::Handle<std::vector<reco::Track> > trackCollectionHandle;
765  iEvent.getByLabel(tracksrc_,trackCollectionHandle);
766  const std::vector<reco::Track> trackColl = *(trackCollectionHandle.product());
767 
768  //get the map
770  iEvent.getByLabel(tracksrc_,match);
771  const TrajTrackAssociationCollection ttac = *(match.product());
772 
773  // get clusters
775  iEvent.getByLabel( clustersrc_, clusterColl );
776  const edmNew::DetSetVector<SiPixelCluster> clustColl = *(clusterColl.product());
777 
778  if(debug_){
779  std::cout << "Trajectories\t : " << trajColl.size() << std::endl;
780  std::cout << "recoTracks \t : " << trackColl.size() << std::endl;
781  std::cout << "Map entries \t : " << ttac.size() << std::endl;
782  }
783 
784  std::set<SiPixelCluster> clusterSet;
785  TrajectoryStateCombiner tsoscomb;
786  int tracks=0, pixeltracks=0, bpixtracks=0, fpixtracks=0;
787  int trackclusters=0, barreltrackclusters=0, endcaptrackclusters=0;
788  int otherclusters=0, barrelotherclusters=0, endcapotherclusters=0;
789 
790  //Loop over map entries
791  for(TrajTrackAssociationCollection::const_iterator it = ttac.begin();it != ttac.end(); ++it){
792  const edm::Ref<std::vector<Trajectory> > traj_iterator = it->key;
793  // Trajectory Map, extract Trajectory for this track
794  reco::TrackRef trackref = it->val;
795  tracks++;
796 
797  bool isBpixtrack = false, isFpixtrack = false, crossesPixVol=false;
798 
799  //find out whether track crosses pixel fiducial volume (for cosmic tracks)
800 
801  double d0 = (*trackref).d0(), dz = (*trackref).dz();
802 
803  if(abs(d0)<15 && abs(dz)<50) crossesPixVol = true;
804 
805  std::vector<TrajectoryMeasurement> tmeasColl =traj_iterator->measurements();
806  std::vector<TrajectoryMeasurement>::const_iterator tmeasIt;
807  //loop on measurements to find out whether there are bpix and/or fpix hits
808  for(tmeasIt = tmeasColl.begin();tmeasIt!=tmeasColl.end();tmeasIt++){
809  if(! tmeasIt->updatedState().isValid()) continue;
810  TransientTrackingRecHit::ConstRecHitPointer testhit = tmeasIt->recHit();
811  if(! testhit->isValid() || testhit->geographicalId().det() != DetId::Tracker) continue;
812  uint testSubDetID = (testhit->geographicalId().subdetId());
813  if(testSubDetID==PixelSubdetector::PixelBarrel) isBpixtrack = true;
814  if(testSubDetID==PixelSubdetector::PixelEndcap) isFpixtrack = true;
815  }//end loop on measurements
816  if(isBpixtrack) {
817  bpixtracks++;
818  if(debug_) std::cout << "bpixtrack\n";
819  }
820  if(isFpixtrack) {
821  fpixtracks++;
822  if(debug_) std::cout << "fpixtrack\n";
823  }
824  if(isBpixtrack || isFpixtrack){
825  pixeltracks++;
826 
827  if(crossesPixVol) meNofTracksInPixVol_->Fill(0,1);
828 
829  std::vector<TrajectoryMeasurement> tmeasColl = traj_iterator->measurements();
830  for(std::vector<TrajectoryMeasurement>::const_iterator tmeasIt = tmeasColl.begin(); tmeasIt!=tmeasColl.end(); tmeasIt++){
831  if(! tmeasIt->updatedState().isValid()) continue;
832 
833  TrajectoryStateOnSurface tsos = tsoscomb( tmeasIt->forwardPredictedState(), tmeasIt->backwardPredictedState() );
835  if(! hit->isValid() || hit->geographicalId().det() != DetId::Tracker ) {
836  continue;
837  } else {
838 
839 // //residual
840  const DetId & hit_detId = hit->geographicalId();
841  //uint IntRawDetID = (hit_detId.rawId());
842  uint IntSubDetID = (hit_detId.subdetId());
843 
844  if(IntSubDetID == 0 ) continue; // don't look at SiStrip hits!
845 
846  // get the enclosed persistent hit
847  const TrackingRecHit *persistentHit = hit->hit();
848  // check if it's not null, and if it's a valid pixel hit
849  if ((persistentHit != 0) && (typeid(*persistentHit) == typeid(SiPixelRecHit))) {
850  // tell the C++ compiler that the hit is a pixel hit
851  const SiPixelRecHit* pixhit = static_cast<const SiPixelRecHit*>( hit->hit() );
852  //Hit probability:
853  float hit_prob = -1.;
854  if(pixhit->hasFilledProb()){
855  hit_prob = pixhit->clusterProbability(0);
856  //std::cout<<"HITPROB= "<<hit_prob<<std::endl;
857  if(hit_prob<pow(10.,-15.)) NLowProb++;
858  NTotal++;
859  if(NTotal>0) meHitProbability->Fill(float(NLowProb/NTotal));
860  }
861 
862  // get the edm::Ref to the cluster
863  edm::Ref<edmNew::DetSetVector<SiPixelCluster>, SiPixelCluster> const& clust = (*pixhit).cluster();
864  // check if the ref is not null
865  if (clust.isNonnull()) {
866 
867  //define tracker and pixel geometry and topology
868  const TrackerGeometry& theTracker(*theTrackerGeometry);
869  const PixelGeomDetUnit* theGeomDet = static_cast<const PixelGeomDetUnit*> (theTracker.idToDet(hit_detId) );
870  //test if PixelGeomDetUnit exists
871  if(theGeomDet == 0) {
872  if(debug_) std::cout << "NO THEGEOMDET\n";
873  continue;
874  }
875 
876  const PixelTopology * topol = &(theGeomDet->specificTopology());
877  //fill histograms for clusters on tracks
878  //correct SiPixelTrackResidualModule
879  std::map<uint32_t, SiPixelTrackResidualModule*>::iterator pxd = theSiPixelStructure.find((*hit).geographicalId().rawId());
880 
881  //CHARGE CORRECTION (for track impact angle)
882  // calculate alpha and beta from cluster position
884  LocalVector localDir = ltp.momentum()/ltp.momentum().mag();
885 
886  float clust_alpha = atan2(localDir.z(), localDir.x());
887  float clust_beta = atan2(localDir.z(), localDir.y());
888  double corrCharge = clust->charge() * sqrt( 1.0 / ( 1.0/pow( tan(clust_alpha), 2 ) +
889  1.0/pow( tan(clust_beta ), 2 ) +
890  1.0 )
891  )/1000.;
892 
893  if (pxd!=theSiPixelStructure.end()) (*pxd).second->fill((*clust), true, corrCharge, reducedSet, modOn, ladOn, layOn, phiOn, bladeOn, diskOn, ringOn);
894 
895 
896  trackclusters++;
897  //CORR CHARGE
898  meClChargeOnTrack_all->Fill(corrCharge);
899  meClSizeOnTrack_all->Fill((*clust).size());
900  meClSizeXOnTrack_all->Fill((*clust).sizeX());
901  meClSizeYOnTrack_all->Fill((*clust).sizeY());
902  clusterSet.insert(*clust);
903 
904  //find cluster global position (rphi, z)
905  // get cluster center of gravity (of charge)
906  float xcenter = clust->x();
907  float ycenter = clust->y();
908  // get the cluster position in local coordinates (cm)
909  LocalPoint clustlp = topol->localPosition( MeasurementPoint(xcenter, ycenter) );
910  // get the cluster position in global coordinates (cm)
911  GlobalPoint clustgp = theGeomDet->surface().toGlobal( clustlp );
912 
913  //find location of hit (barrel or endcap, same for cluster)
914  bool barrel = DetId((*hit).geographicalId()).subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel);
915  bool endcap = DetId((*hit).geographicalId()).subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap);
916  if(barrel) {
917  barreltrackclusters++;
918  //CORR CHARGE
919  meClChargeOnTrack_bpix->Fill(corrCharge);
920  meClSizeOnTrack_bpix->Fill((*clust).size());
921  meClSizeXOnTrack_bpix->Fill((*clust).sizeX());
922  meClSizeYOnTrack_bpix->Fill((*clust).sizeY());
923  uint32_t DBlayer = PixelBarrelName(DetId((*hit).geographicalId())).layerName();
924  float phi = clustgp.phi();
925  float z = clustgp.z();
926  switch(DBlayer){
927  case 1: {
928  meClPosLayer1OnTrack->Fill(z,phi);
929  meClChargeOnTrack_layer1->Fill(corrCharge);
930  meClSizeOnTrack_layer1->Fill((*clust).size());
931  meClSizeXOnTrack_layer1->Fill((*clust).sizeX());
932  meClSizeYOnTrack_layer1->Fill((*clust).sizeY());
933  break;
934  }
935  case 2: {
936  meClPosLayer2OnTrack->Fill(z,phi);
937  meClChargeOnTrack_layer2->Fill(corrCharge);
938  meClSizeOnTrack_layer2->Fill((*clust).size());
939  meClSizeXOnTrack_layer2->Fill((*clust).sizeX());
940  meClSizeYOnTrack_layer2->Fill((*clust).sizeY());
941  break;
942  }
943  case 3: {
944  meClPosLayer3OnTrack->Fill(z,phi);
945  meClChargeOnTrack_layer3->Fill(corrCharge);
946  meClSizeOnTrack_layer3->Fill((*clust).size());
947  meClSizeXOnTrack_layer3->Fill((*clust).sizeX());
948  meClSizeYOnTrack_layer3->Fill((*clust).sizeY());
949  break;
950  }
951 
952  }
953 
954  }
955  if(endcap) {
956  endcaptrackclusters++;
957  //CORR CHARGE
958  meClChargeOnTrack_fpix->Fill(corrCharge);
959  meClSizeOnTrack_fpix->Fill((*clust).size());
960  meClSizeXOnTrack_fpix->Fill((*clust).sizeX());
961  meClSizeYOnTrack_fpix->Fill((*clust).sizeY());
962  uint32_t DBdisk = PixelEndcapName(DetId((*hit).geographicalId())).diskName();
963  float x = clustgp.x();
964  float y = clustgp.y();
965  float z = clustgp.z();
966  if(z>0){
967  if(DBdisk==1) {
969  meClChargeOnTrack_diskp1->Fill(corrCharge);
970  meClSizeOnTrack_diskp1->Fill((*clust).size());
971  meClSizeXOnTrack_diskp1->Fill((*clust).sizeX());
972  meClSizeYOnTrack_diskp1->Fill((*clust).sizeY());
973  }
974  if(DBdisk==2) {
976  meClChargeOnTrack_diskp2->Fill(corrCharge);
977  meClSizeOnTrack_diskp2->Fill((*clust).size());
978  meClSizeXOnTrack_diskp2->Fill((*clust).sizeX());
979  meClSizeYOnTrack_diskp2->Fill((*clust).sizeY());
980  }
981  }
982  else{
983  if(DBdisk==1) {
985  meClChargeOnTrack_diskm1->Fill(corrCharge);
986  meClSizeOnTrack_diskm1->Fill((*clust).size());
987  meClSizeXOnTrack_diskm1->Fill((*clust).sizeX());
988  meClSizeYOnTrack_diskm1->Fill((*clust).sizeY());
989  }
990  if(DBdisk==2) {
992  meClChargeOnTrack_diskm2->Fill(corrCharge);
993  meClSizeOnTrack_diskm2->Fill((*clust).size());
994  meClSizeXOnTrack_diskm2->Fill((*clust).sizeX());
995  meClSizeYOnTrack_diskm2->Fill((*clust).sizeY());
996  }
997  }
998  }
999 
1000  }//end if (cluster exists)
1001 
1002  }//end if (persistent hit exists and is pixel hit)
1003 
1004  }//end of else
1005 
1006 
1007  }//end for (all traj measurements of pixeltrack)
1008  }//end if (is pixeltrack)
1009  else {
1010  if(debug_) std::cout << "no pixeltrack:\n";
1011  if(crossesPixVol) meNofTracksInPixVol_->Fill(1,1);
1012  }
1013 
1014  }//end loop on map entries
1015 
1016  //find clusters that are NOT on track
1017  //edmNew::DetSet<SiPixelCluster>::const_iterator di;
1018  if(debug_) std::cout << "clusters not on track: (size " << clustColl.size() << ") ";
1019 
1020  for(TrackerGeometry::DetContainer::const_iterator it = TG->dets().begin(); it != TG->dets().end(); it++){
1021  //if(dynamic_cast<PixelGeomDetUnit*>((*it))!=0){
1022  DetId detId = (*it)->geographicalId();
1023  if(detId>=302055684 && detId<=352477708){ // make sure it's a Pixel module WITHOUT using dynamic_cast!
1024  int nofclOnTrack = 0, nofclOffTrack=0;
1025  uint32_t DBlayer=10, DBdisk=10;
1026  float z=0.;
1027  //set layer/disk
1028  if(DetId(detId).subdetId() == 1) { // Barrel module
1029  DBlayer = PixelBarrelName(DetId(detId)).layerName();
1030  }
1031  if(DetId(detId).subdetId() == 2){ // Endcap module
1032  DBdisk = PixelEndcapName(DetId(detId )).diskName();
1033  }
1035  if( isearch != clustColl.end() ) { // Not an empty iterator
1037  for(di=isearch->begin(); di!=isearch->end(); di++){
1038  unsigned int temp = clusterSet.size();
1039  clusterSet.insert(*di);
1040  //check if cluster is off track
1041  if(clusterSet.size()>temp) {
1042  otherclusters++;
1043  nofclOffTrack++;
1044  //fill histograms for clusters off tracks
1045  //correct SiPixelTrackResidualModule
1046  std::map<uint32_t, SiPixelTrackResidualModule*>::iterator pxd = theSiPixelStructure.find((*it)->geographicalId().rawId());
1047 
1048  if (pxd!=theSiPixelStructure.end()) (*pxd).second->fill((*di), false, -1., reducedSet, modOn, ladOn, layOn, phiOn, bladeOn, diskOn, ringOn);
1049 
1050 
1051 
1052  meClSizeNotOnTrack_all->Fill((*di).size());
1053  meClSizeXNotOnTrack_all->Fill((*di).sizeX());
1054  meClSizeYNotOnTrack_all->Fill((*di).sizeY());
1055  meClChargeNotOnTrack_all->Fill((*di).charge()/1000);
1056 
1058  //find cluster global position (rphi, z) get cluster
1059  //define tracker and pixel geometry and topology
1060  const TrackerGeometry& theTracker(*theTrackerGeometry);
1061  const PixelGeomDetUnit* theGeomDet = static_cast<const PixelGeomDetUnit*> (theTracker.idToDet(detId) );
1062  //test if PixelGeomDetUnit exists
1063  if(theGeomDet == 0) {
1064  if(debug_) std::cout << "NO THEGEOMDET\n";
1065  continue;
1066  }
1067  const PixelTopology * topol = &(theGeomDet->specificTopology());
1068 
1069  //center of gravity (of charge)
1070  float xcenter = di->x();
1071  float ycenter = di->y();
1072  // get the cluster position in local coordinates (cm)
1073  LocalPoint clustlp = topol->localPosition( MeasurementPoint(xcenter, ycenter) );
1074  // get the cluster position in global coordinates (cm)
1075  GlobalPoint clustgp = theGeomDet->surface().toGlobal( clustlp );
1076 
1078 
1079  //barrel
1080  if(DetId(detId).subdetId() == 1) {
1081  meClSizeNotOnTrack_bpix->Fill((*di).size());
1082  meClSizeXNotOnTrack_bpix->Fill((*di).sizeX());
1083  meClSizeYNotOnTrack_bpix->Fill((*di).sizeY());
1084  meClChargeNotOnTrack_bpix->Fill((*di).charge()/1000);
1085  barrelotherclusters++;
1086  //DBlayer = PixelBarrelName(DetId(detId)).layerName();
1087  float phi = clustgp.phi();
1088  //float r = clustgp.perp();
1089  z = clustgp.z();
1090  switch(DBlayer){
1091  case 1: {
1092  meClPosLayer1NotOnTrack->Fill(z,phi);
1093  meClSizeNotOnTrack_layer1->Fill((*di).size());
1094  meClSizeXNotOnTrack_layer1->Fill((*di).sizeX());
1095  meClSizeYNotOnTrack_layer1->Fill((*di).sizeY());
1096  meClChargeNotOnTrack_layer1->Fill((*di).charge()/1000);
1097  break;
1098  }
1099  case 2: {
1100  meClPosLayer2NotOnTrack->Fill(z,phi);
1101  meClSizeNotOnTrack_layer2->Fill((*di).size());
1102  meClSizeXNotOnTrack_layer2->Fill((*di).sizeX());
1103  meClSizeYNotOnTrack_layer2->Fill((*di).sizeY());
1104  meClChargeNotOnTrack_layer2->Fill((*di).charge()/1000);
1105  break;
1106  }
1107  case 3: {
1108  meClPosLayer3NotOnTrack->Fill(z,phi);
1109  meClSizeNotOnTrack_layer3->Fill((*di).size());
1110  meClSizeXNotOnTrack_layer3->Fill((*di).sizeX());
1111  meClSizeYNotOnTrack_layer3->Fill((*di).sizeY());
1112  meClChargeNotOnTrack_layer3->Fill((*di).charge()/1000);
1113  break;
1114  }
1115 
1116  }
1117  }
1118  //endcap
1119  if(DetId(detId).subdetId() == 2) {
1120  meClSizeNotOnTrack_fpix->Fill((*di).size());
1121  meClSizeXNotOnTrack_fpix->Fill((*di).sizeX());
1122  meClSizeYNotOnTrack_fpix->Fill((*di).sizeY());
1123  meClChargeNotOnTrack_fpix->Fill((*di).charge()/1000);
1124  endcapotherclusters++;
1125  //DBdisk = PixelEndcapName(DetId(detId )).diskName();
1126  float x = clustgp.x();
1127  float y = clustgp.y();
1128  z = clustgp.z();
1129  if(z>0){
1130  if(DBdisk==1) {
1132  meClSizeNotOnTrack_diskp1->Fill((*di).size());
1133  meClSizeXNotOnTrack_diskp1->Fill((*di).sizeX());
1134  meClSizeYNotOnTrack_diskp1->Fill((*di).sizeY());
1135  meClChargeNotOnTrack_diskp1->Fill((*di).charge()/1000);
1136  }
1137  if(DBdisk==2) {
1139  meClSizeNotOnTrack_diskp2->Fill((*di).size());
1140  meClSizeXNotOnTrack_diskp2->Fill((*di).sizeX());
1141  meClSizeYNotOnTrack_diskp2->Fill((*di).sizeY());
1142  meClChargeNotOnTrack_diskp2->Fill((*di).charge()/1000);
1143  }
1144  }
1145  else{
1146  if(DBdisk==1) {
1148  meClSizeNotOnTrack_diskm1->Fill((*di).size());
1149  meClSizeXNotOnTrack_diskm1->Fill((*di).sizeX());
1150  meClSizeYNotOnTrack_diskm1->Fill((*di).sizeY());
1151  meClChargeNotOnTrack_diskm1->Fill((*di).charge()/1000);
1152  }
1153  if(DBdisk==2) {
1155  meClSizeNotOnTrack_diskm2->Fill((*di).size());
1156  meClSizeXNotOnTrack_diskm2->Fill((*di).sizeX());
1157  meClSizeYNotOnTrack_diskm2->Fill((*di).sizeY());
1158  meClChargeNotOnTrack_diskm2->Fill((*di).charge()/1000);
1159  }
1160  }
1161 
1162  }
1163  }// end "if cluster off track"
1164  else {
1165  nofclOnTrack++;
1166  if(z == 0 && DBdisk != 10){
1167  //find cluster global position (rphi, z) get cluster
1168  //define tracker and pixel geometry and topology
1169  const TrackerGeometry& theTracker(*theTrackerGeometry);
1170  const PixelGeomDetUnit* theGeomDet = static_cast<const PixelGeomDetUnit*> (theTracker.idToDet(detId) );
1171  //test if PixelGeomDetUnit exists
1172  if(theGeomDet == 0) {
1173  if(debug_) std::cout << "NO THEGEOMDET\n";
1174  continue;
1175  }
1176  const PixelTopology * topol = &(theGeomDet->specificTopology());
1177  //center of gravity (of charge)
1178  float xcenter = di->x();
1179  float ycenter = di->y();
1180  // get the cluster position in local coordinates (cm)
1181  LocalPoint clustlp = topol->localPosition( MeasurementPoint(xcenter, ycenter) );
1182  // get the cluster position in global coordinates (cm)
1183  GlobalPoint clustgp = theGeomDet->surface().toGlobal( clustlp );
1184  z = clustgp.z();
1185  }
1186  }
1187  }
1188  }
1189  //++ fill the number of clusters on a module
1190  std::map<uint32_t, SiPixelTrackResidualModule*>::iterator pxd = theSiPixelStructure.find((*it)->geographicalId().rawId());
1191  if (pxd!=theSiPixelStructure.end()) (*pxd).second->nfill(nofclOnTrack, nofclOffTrack, reducedSet, modOn, ladOn, layOn, phiOn, bladeOn, diskOn, ringOn);
1192  if(nofclOnTrack!=0) meNClustersOnTrack_all->Fill(nofclOnTrack);
1193  if(nofclOffTrack!=0) meNClustersNotOnTrack_all->Fill(nofclOffTrack);
1194  //barrel
1195  if(DetId(detId).subdetId() == 1){
1196  if(nofclOnTrack!=0) meNClustersOnTrack_bpix->Fill(nofclOnTrack);
1197  if(nofclOffTrack!=0) meNClustersNotOnTrack_bpix->Fill(nofclOffTrack);
1198  //DBlayer = PixelBarrelName(DetId(detId)).layerName();
1199  switch(DBlayer){
1200  case 1: {
1201  if(nofclOnTrack!=0) meNClustersOnTrack_layer1->Fill(nofclOnTrack);
1202  if(nofclOffTrack!=0) meNClustersNotOnTrack_layer1->Fill(nofclOffTrack); break;
1203  }
1204  case 2: {
1205  if(nofclOnTrack!=0) meNClustersOnTrack_layer2->Fill(nofclOnTrack);
1206  if(nofclOffTrack!=0) meNClustersNotOnTrack_layer2->Fill(nofclOffTrack); break;
1207  }
1208  case 3: {
1209  if(nofclOnTrack!=0) meNClustersOnTrack_layer3->Fill(nofclOnTrack);
1210  if(nofclOffTrack!=0) meNClustersNotOnTrack_layer3->Fill(nofclOffTrack); break;
1211  }
1212  }
1213  }//end barrel
1214  //endcap
1215  if(DetId(detId).subdetId() == 2) {
1216  //DBdisk = PixelEndcapName(DetId(detId )).diskName();
1217  //z = clustgp.z();
1218  if(nofclOnTrack!=0) meNClustersOnTrack_fpix->Fill(nofclOnTrack);
1219  if(nofclOffTrack!=0) meNClustersNotOnTrack_fpix->Fill(nofclOffTrack);
1220  if(z>0){
1221  if(DBdisk==1) {
1222  if(nofclOnTrack!=0) meNClustersOnTrack_diskp1->Fill(nofclOnTrack);
1223  if(nofclOffTrack!=0) meNClustersNotOnTrack_diskp1->Fill(nofclOffTrack);
1224  }
1225  if(DBdisk==2) {
1226  if(nofclOnTrack!=0) meNClustersOnTrack_diskp2->Fill(nofclOnTrack);
1227  if(nofclOffTrack!=0) meNClustersNotOnTrack_diskp2->Fill(nofclOffTrack);
1228  }
1229  }
1230  if(z<0){
1231  if(DBdisk==1) {
1232  if(nofclOnTrack!=0) meNClustersOnTrack_diskm1->Fill(nofclOnTrack);
1233  if(nofclOffTrack!=0) meNClustersNotOnTrack_diskm1->Fill(nofclOffTrack);
1234  }
1235  if(DBdisk==2) {
1236  if(nofclOnTrack!=0) meNClustersOnTrack_diskm2->Fill(nofclOnTrack);
1237  if(nofclOffTrack!=0) meNClustersNotOnTrack_diskm2->Fill(nofclOffTrack);
1238  }
1239  }
1240  }
1241 
1242  }//end if it's a Pixel module
1243  }//end for loop over tracker detector geometry modules
1244 
1245 
1246  if(trackclusters>0) (meNofClustersOnTrack_)->Fill(0,trackclusters);
1247  if(barreltrackclusters>0)(meNofClustersOnTrack_)->Fill(1,barreltrackclusters);
1248  if(endcaptrackclusters>0)(meNofClustersOnTrack_)->Fill(2,endcaptrackclusters);
1249  if(otherclusters>0)(meNofClustersNotOnTrack_)->Fill(0,otherclusters);
1250  if(barrelotherclusters>0)(meNofClustersNotOnTrack_)->Fill(1,barrelotherclusters);
1251  if(endcapotherclusters>0)(meNofClustersNotOnTrack_)->Fill(2,endcapotherclusters);
1252  if(tracks>0)(meNofTracks_)->Fill(0,tracks);
1253  if(pixeltracks>0)(meNofTracks_)->Fill(1,pixeltracks);
1254  if(bpixtracks>0)(meNofTracks_)->Fill(2,bpixtracks);
1255  if(fpixtracks>0)(meNofTracks_)->Fill(3,fpixtracks);
1256 }
1257 void SiPixelTrackResidualSource::triplets(double x1,double y1,double z1,double x2,double y2,double z2,double x3,double y3,double z3,
1258  double ptsig, double & dca2,double & dz2, double kap) {
1259 
1260  //Define some constants
1261  using namespace std;
1262 
1263  //Curvature kap from global Track
1264 
1265  //inverse of the curvature is the radius in the transverse plane
1266  double rho = 1/kap;
1267  //Check that the hits are in the correct layers
1268  double r1 = sqrt( x1*x1 + y1*y1 );
1269  double r3 = sqrt( x3*x3 + y3*y3 );
1270 
1271  if( r3-r1 < 2.0 ) cout << "warn r1 = " << r1 << ", r3 = " << r3 << endl;
1272 
1273  // Calculate the centre of the helix in xy-projection with radius rho from the track.
1274  //start with a line (sekante) connecting the two points (x1,y1) and (x3,y3) vec_L = vec_x3-vec_x1
1275  //with L being the length of that vector.
1276  double L=sqrt((x3-x1)*(x3-x1)+(y3-y1)*(y3-y1));
1277  //lam is the line from the middel point of vec_q towards the center of the circle X0,Y0
1278  // we already have kap and rho = 1/kap
1279  double lam = sqrt(rho*rho - L*L/4);
1280 
1281  // There are two solutions, the sign of kap gives the information
1282  // which of them is correct.
1283  //
1284  if( kap > 0 ) lam = -lam;
1285 
1286  //
1287  // ( X0, Y0 ) is the centre of the circle that describes the helix in xy-projection.
1288  //
1289  double x0 = 0.5*( x1 + x3 ) + lam/L * ( -y1 + y3 );
1290  double y0 = 0.5*( y1 + y3 ) + lam/L * ( x1 - x3 );
1291 
1292  // Calculate the dipangle in z direction (needed later for z residual) :
1293  //Starting from the heliz equation whihc has to hold for both points z1,z3
1294  double num = ( y3 - y0 ) * ( x1 - x0 ) - ( x3 - x0 ) * ( y1 - y0 );
1295  double den = ( x1 - x0 ) * ( x3 - x0 ) + ( y1 - y0 ) * ( y3 - y0 );
1296  double tandip = kap * ( z3 - z1 ) / atan( num / den );
1297 
1298 
1299  // angle from first hit to dca point:
1300  //
1301  double dphi = atan( ( ( x1 - x0 ) * y0 - ( y1 - y0 ) * x0 )
1302  / ( ( x1 - x0 ) * x0 + ( y1 - y0 ) * y0 ) );
1303  //z position of the track based on the middle of the circle
1304  //track equation for the z component
1305  double uz0 = z1 + tandip * dphi * rho;
1306 
1308  //RESIDUAL IN R-PHI
1310  //Calculate distance dca2 from point (x2,y2) to the circle which is given by
1311  //the distance of the point to the middlepoint dcM = sqrt((x0-x2)^2+(y0-y2)) and rho
1312  //dca = rho +- dcM
1313  if(kap>0) dca2=rho-sqrt((x0-x2)*(x0-x2)+(y0-y2)*(y0-y2));
1314  else dca2=rho+sqrt((-x0+x2)*(-x0+x2)+(-y0+y2)*(-y0+y2));
1315 
1317  //RESIDUAL IN Z
1319  double xx =0 ;
1320  double yy =0 ;
1321  //sign of kappa determines the calculation
1322  //xx and yy are the new coordinates starting from x2, y2 that are on the track itself
1323  //vec_X2+-dca2*vec(X0-X2)/|(X0-X2)|
1324  if(kap<0){
1325  xx = x2+(dca2*((x0-x2))/sqrt((x0-x2)*(x0-x2)+(y0-y2)*(y0-y2)));
1326  yy = y2+(dca2*((y0-y2))/sqrt((x0-x2)*(x0-x2)+(y0-y2)*(y0-y2)));
1327  }
1328  else if(kap>=0){
1329  xx = x2-(dca2*((x0-x2))/sqrt((x0-x2)*(x0-x2)+(y0-y2)*(y0-y2)));
1330  yy = y2-(dca2*((y0-y2))/sqrt((x0-x2)*(x0-x2)+(y0-y2)*(y0-y2)));
1331  }
1332 
1333  //to get residual in z start with calculating the new uz2 position if one has moved to xx, yy
1334  //on the track. First calculate the change in phi2 with respect to the center X0, Y0
1335  double dphi2 = atan( ( ( xx - x0 ) * y0 - ( yy - y0 ) * x0 )
1336  / ( ( xx - x0 ) * x0 + ( yy - y0 ) * y0 ) );
1337  //Solve track equation for this new z depending on the dip angle of the track (see above
1338  //calculated based on X1, X3 and X0, use uz0 as reference point again.
1339  double uz2= uz0 - dphi2*tandip*rho;
1340 
1341  //subtract new z position from the old one
1342  dz2=z2-uz2;
1343 
1344  //if we are interested in the arclength this is unsigned though
1345  // double cosphi2 = (x2*xx+y2*yy)/(sqrt(x2*x2+y2*y2)*sqrt(xx*xx+yy*yy));
1346  //double arcdca2=sqrt(x2*x2+y2*y2)*acos(cosphi2);
1347 
1348 }
1349 
1350 
1351 DEFINE_FWK_MODULE(SiPixelTrackResidualSource); // define this as a plug-in
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:78
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:717
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:2113
Definition: DDAxes.h:10
Geom::Phi< T > phi() const
Definition: PV3DBase.h:68
T y() const
Definition: PV3DBase.h:62
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
SiPixelTrackResidualSource(const edm::ParameterSet &)
double charge(const std::vector< uint8_t > &Ampls)
double double double z
tuple gX
Definition: corrVsCorr.py:109
unsigned int layer() const
layer id
Definition: PXBDetId.h:35
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:66
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
T sqrt(T t)
Definition: SSEVec.h:46
T z() const
Definition: PV3DBase.h:63
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:356
double ndof() const
Definition: Vertex.h:89
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:25
size_type size() const
Pixel cluster – collection of neighboring pixels above threshold.
const BoundPlane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:35
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:845
Detector det() const
get the detector field from this detid
Definition: DetId.h:37
T x() const
Definition: PV3DBase.h:61
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:429
Definition: Run.h:33
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