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