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