ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/TreeFiller/src/FillerPixelHits.cc
Revision: 1.5
Committed: Wed Nov 25 14:45:40 2009 UTC (15 years, 5 months ago) by loizides
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_012c
Changes since 1.4: +5 -5 lines
Log Message:
Added pixels

File Contents

# Content
1 // $Id: FillerPixelHits.cc,v 1.4 2009/11/19 14:35:23 loizides Exp $
2
3 #include "MitProd/TreeFiller/interface/FillerPixelHits.h"
4 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
5 #include "DataFormats/GeometryVector/interface/LocalPoint.h"
6 #include "DataFormats/SiPixelDetId/interface/PXBDetId.h"
7 #include "DataFormats/SiPixelDetId/interface/PXFDetId.h"
8 #include "DataFormats/TrackerRecHit2D/interface/SiPixelRecHitCollection.h"
9 #include "FWCore/Framework/interface/ESHandle.h"
10 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
11 #include "Geometry/TrackerTopology/interface/RectangularPixelTopology.h"
12 #include "Geometry/TrackerGeometryBuilder/interface/PixelGeomDetUnit.h"
13 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
14 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
15 #include "MitAna/DataTree/interface/Names.h"
16 #include "MitAna/DataTree/interface/PixelHitCol.h"
17 #include "MitProd/ObjectService/interface/ObjectService.h"
18
19 using namespace std;
20 using namespace edm;
21 using namespace mithep;
22
23 //--------------------------------------------------------------------------------------------------
24 FillerPixelHits::FillerPixelHits(const ParameterSet &cfg, const char *name, bool active) :
25 BaseFiller(cfg,name,active),
26 edmName_(Conf().getUntrackedParameter<string>("edmName","siPixelRecHits")),
27 mitName_(Conf().getUntrackedParameter<string>("mitName",Names::gkPixelHitBrn)),
28 phits_(new mithep::PixelHitArr(1000))
29 {
30 // Constructor.
31 }
32
33 //--------------------------------------------------------------------------------------------------
34 FillerPixelHits::~FillerPixelHits()
35 {
36 // Destructor.
37
38 delete phits_;
39 }
40
41 //--------------------------------------------------------------------------------------------------
42 void FillerPixelHits::BookDataBlock(TreeWriter &tws, const edm::EventSetup &es)
43 {
44 // Add tracks branch to tree, publish and get tracker geometry.
45
46 tws.AddBranch(mitName_,&phits_);
47 OS()->add<PixelHitArr>(phits_,mitName_);
48 }
49
50 //--------------------------------------------------------------------------------------------------
51 void FillerPixelHits::FillDataBlock(const edm::Event &event,
52 const edm::EventSetup &setup)
53 {
54 // Fill pixel hits from edm collection into our collection.
55
56 phits_->Delete();
57
58 // initialize handle and get product
59 Handle<SiPixelRecHitCollection> hRecHits;
60 GetProduct(edmName_, hRecHits, event);
61
62 const SiPixelRecHitCollection *hits = hRecHits.product();
63 if (!hits->size())
64 return;
65
66 // get tracker geometry
67 edm::ESHandle<TrackerGeometry> trackerHandle;
68 setup.get<TrackerDigiGeometryRecord>().get(trackerHandle);
69 const TrackerGeometry *tgeo = trackerHandle.product();
70
71 for(SiPixelRecHitCollection::DataContainer::const_iterator hit = hits->data().begin(),
72 end = hits->data().end(); hit != end; ++hit) {
73
74 if (!hit->isValid())
75 continue;
76
77 DetId id(hit->geographicalId());
78
79 int type = 0;
80 if(id.subdetId() == int(PixelSubdetector::PixelBarrel)) {
81 PXBDetId pid(id);
82 type = pid.layer();
83 } else if (id.subdetId() == int(PixelSubdetector::PixelEndcap)) {
84 PXFDetId pid(id);
85 if (pid.disk()==0)
86 type = 11;
87 else
88 type = 12;
89 if (pid.side()!=0)
90 type = -type;
91 } else {
92 continue;
93 }
94
95 bool isAnyPixelOnEdge = false;
96 const PixelGeomDetUnit *pgdu =
97 static_cast<const PixelGeomDetUnit*>(tgeo->idToDetUnit(id));
98 if (1) {
99 const RectangularPixelTopology *pixTopo =
100 static_cast<const RectangularPixelTopology*>(&pgdu->specificTopology());
101 const vector<SiPixelCluster::Pixel> pixels(hit->cluster()->pixels());
102 for(std::vector<SiPixelCluster::Pixel>::const_iterator pixel = pixels.begin();
103 pixel != pixels.end(); ++pixel) {
104 int pixelX = pixel->x;
105 int pixelY = pixel->y;
106 if(pixTopo->isItEdgePixelInX(pixelX) || pixTopo->isItEdgePixelInY(pixelY)) {
107 isAnyPixelOnEdge = true;
108 break;
109 }
110 }
111 }
112
113 LocalPoint lpos = LocalPoint(hit->localPosition().x(),
114 hit->localPosition().y(),
115 hit->localPosition().z());
116 GlobalPoint gpos = pgdu->toGlobal(lpos);
117 mithep::PixelHit *newhit = phits_->Allocate();
118 new (newhit) mithep::PixelHit(gpos.x(),gpos.y(),gpos.z());
119 newhit->SetType(type);
120 newhit->SetQuality(hit->rawQualityWord());
121 newhit->SetCharge(static_cast<int>(hit->cluster()->charge()));
122 newhit->SetSizeX(hit->cluster()->sizeX());
123 newhit->SetSizeY(hit->cluster()->sizeY());
124 newhit->SetAnyPixelIsOnEdge(isAnyPixelOnEdge);
125 }
126 phits_->Trim();
127 }