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