forked from cms-sw/cmssw
/
StdHitNtuplizer.cc
840 lines (727 loc) · 31.6 KB
/
StdHitNtuplizer.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
// File: StdHitNtuplizer.cc
// Description: see StdHitNtuplizer.h
// Authors: H. Cheung
//--------------------------------------------------------------
#include "SLHCUpgradeSimulations/Geometry/test/StdHitNtuplizer.h"
#include "FWCore/PluginManager/interface/ModuleDef.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
// DataFormats
#include "DataFormats/TrackerRecHit2D/interface/SiPixelRecHitCollection.h"
#include "DataFormats/Common/interface/Handle.h"
#include "DataFormats/Common/interface/OwnVector.h"
#include "DataFormats/TrajectorySeed/interface/TrajectorySeedCollection.h"
#include "DataFormats/TrackCandidate/interface/TrackCandidateCollection.h"
#include "DataFormats/TrackReco/interface/Track.h"
#include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
#include "SimTracker/TrackerHitAssociation/interface/TrackerHitAssociator.h"
#include "SimDataFormats/Track/interface/SimTrack.h"
#include "SimDataFormats/Track/interface/SimTrackContainer.h"
#include "SimDataFormats/Vertex/interface/SimVertex.h"
#include "SimDataFormats/Vertex/interface/SimVertexContainer.h"
#include "DataFormats/DetId/interface/DetId.h"
#include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
#include "Geometry/Records/interface/IdealGeometryRecord.h"
#include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"
#include "DataFormats/Common/interface/DetSetVector.h"
#include "DataFormats/SiPixelCluster/interface/SiPixelCluster.h"
#include "DataFormats/Common/interface/Ref.h"
#include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
// Geometry
#include "MagneticField/Engine/interface/MagneticField.h"
#include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
#include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
#include "Geometry/TrackerGeometryBuilder/interface/RectangularPixelTopology.h"
#include "Geometry/TrackerGeometryBuilder/interface/PixelTopologyBuilder.h"
#include "Geometry/CommonDetUnit/interface/GeomDetType.h"
#include "Geometry/CommonDetUnit/interface/GeomDetUnit.h"
// For ROOT
#include <TROOT.h>
#include <TTree.h>
#include <TFile.h>
#include <TF1.h>
#include <TH2F.h>
#include <TH1F.h>
// STD
#include <memory>
#include <string>
#include <iostream>
using namespace std;
using namespace edm;
using namespace reco;
StdHitNtuplizer::StdHitNtuplizer(edm::ParameterSet const& conf) :
conf_(conf),
trackerHitAssociatorConfig_(conf, consumesCollector()),
src_( conf.getParameter<edm::InputTag>( "src" ) ),
rphiRecHits_( conf.getParameter<edm::InputTag>("rphiRecHits") ),
stereoRecHits_( conf.getParameter<edm::InputTag>("stereoRecHits") ),
matchedRecHits_( conf.getParameter<edm::InputTag>("matchedRecHits") ),
tfile_(0),
pixeltree_(0),
striptree_(0),
pixeltree2_(0)
{
}
StdHitNtuplizer::~StdHitNtuplizer() { }
void StdHitNtuplizer::endJob()
{
std::cout << " StdHitNtuplizer::endJob" << std::endl;
tfile_->Write();
tfile_->Close();
}
void StdHitNtuplizer::beginJob()
{
std::cout << " StdHitNtuplizer::beginJob" << std::endl;
std::string outputFile = conf_.getParameter<std::string>("OutputFile");
tfile_ = new TFile ( outputFile.c_str() , "RECREATE" );
pixeltree_ = new TTree("PixelNtuple","Pixel hit analyzer ntuple");
striptree_ = new TTree("StripNtuple","Strip hit analyzer ntuple");
pixeltree2_ = new TTree("Pixel2Ntuple","Track Pixel hit analyzer ntuple");
int bufsize = 64000;
//Common Branch
pixeltree_->Branch("evt", &evt_, "run/I:evtnum/I", bufsize);
pixeltree_->Branch("pixel_recHit", &recHit_,
"x/F:y:xx:xy:yy:row:col:gx:gy:gz:subid/I:layer:nsimhit:hx/F:hy:tx:ty:theta:phi", bufsize);
pixeltree2_->Branch("evt", &evt_, "run/I:evtnum/I", bufsize);
pixeltree2_->Branch("pixel_recHit", &recHit_,
"x/F:y:xx:xy:yy:row:col:gx:gy:gz:subid/I:layer:nsimhit:hx/F:hy:tx:ty:theta:phi", bufsize);
// Strip Branches
striptree_->Branch("evt", &evt_, "run/I:evtnum/I", bufsize);
striptree_->Branch("strip_recHit", &striprecHit_,
"x/F:y:xx:xy:yy:row:col:gx:gy:gz:subid/I:layer:nsimhit:hx/F:hy:tx:ty:theta:phi", bufsize);
}
// Functions that gets called by framework every event
void StdHitNtuplizer::analyze(const edm::Event& e, const edm::EventSetup& es)
{
//Retrieve tracker topology from geometry
edm::ESHandle<TrackerTopology> tTopoHandle;
es.get<IdealGeometryRecord>().get(tTopoHandle);
const TrackerTopology* const tTopo = tTopoHandle.product();
// geometry setup
edm::ESHandle<TrackerGeometry> geometry;
es.get<TrackerDigiGeometryRecord>().get(geometry);
const TrackerGeometry* theGeometry = &(*geometry);
// fastsim rechits
//edm::Handle<SiTrackerGSRecHit2DCollection> theGSRecHits;
//edm::InputTag hitProducer;
//hitProducer = conf_.getParameter<edm::InputTag>("HitProducer");
//e.getByLabel(hitProducer, theGSRecHits);
edm::Handle<SiPixelRecHitCollection> recHitColl;
e.getByLabel( src_, recHitColl);
// for finding matched simhit
TrackerHitAssociator associate( e, trackerHitAssociatorConfig_ );
// std::cout << " Step A: Standard RecHits found " << (recHitColl.product())->dataSize() << std::endl;
if((recHitColl.product())->dataSize() > 0) {
SiPixelRecHitCollection::const_iterator recHitIdIterator = (recHitColl.product())->begin();
SiPixelRecHitCollection::const_iterator recHitIdIteratorEnd = (recHitColl.product())->end();
std::string detname ;
std::vector<PSimHit> matched;
std::vector<PSimHit>::const_iterator closest_simhit;
// Loop over Detector IDs
for ( ; recHitIdIterator != recHitIdIteratorEnd; recHitIdIterator++) {
SiPixelRecHitCollection::DetSet detset = *recHitIdIterator;
if( detset.empty() ) continue;
DetId detId = DetId(detset.detId()); // Get the Detid object
//unsigned int detType=detId.det(); // det type, tracker=1
const GeomDet* geomDet( theGeometry->idToDet(detId) );
// Loop over rechits for this detid
SiPixelRecHitCollection::DetSet::const_iterator rechitRangeIteratorBegin = detset.begin();
SiPixelRecHitCollection::DetSet::const_iterator rechitRangeIteratorEnd = detset.end();
SiPixelRecHitCollection::DetSet::const_iterator iterRecHit;
for ( iterRecHit = rechitRangeIteratorBegin;
iterRecHit != rechitRangeIteratorEnd; ++iterRecHit) {
// get matched simhit
matched.clear();
matched = associate.associateHit(*iterRecHit);
if ( !matched.empty() ) {
float closest = 9999.9;
std::vector<PSimHit>::const_iterator closestit = matched.begin();
LocalPoint lp = iterRecHit->localPosition();
float rechit_x = lp.x();
float rechit_y = lp.y();
//loop over simhits and find closest
for (std::vector<PSimHit>::const_iterator m = matched.begin(); m<matched.end(); m++)
{
float sim_x1 = (*m).entryPoint().x();
float sim_x2 = (*m).exitPoint().x();
float sim_xpos = 0.5*(sim_x1+sim_x2);
float sim_y1 = (*m).entryPoint().y();
float sim_y2 = (*m).exitPoint().y();
float sim_ypos = 0.5*(sim_y1+sim_y2);
float x_res = fabs(sim_xpos - rechit_x);
float y_res = fabs(sim_ypos - rechit_y);
float dist = sqrt(x_res*x_res + y_res*y_res);
if ( dist < closest ) {
closest = dist;
closestit = m;
}
} // end of simhit loop
closest_simhit = closestit;
} // end matched emtpy
/////comment out begin
/*
unsigned int subdetId = detId.subdetId();
int layerNumber=0;
int ringNumber = 0;
int stereo = 0;
if ( subdetId == StripSubdetector::TIB) {
detname = "TIB";
layerNumber = tTopo->tibLayer(detId.rawId);
stereo = tTopo->tibStereo(detId.rawId);
} else if ( subdetId == StripSubdetector::TOB ) {
detname = "TOB";
layerNumber = tTopo->tobLayer(detId.rawId);
stereo = tTopo->tobStereo(detId.rawId);
} else if ( subdetId == StripSubdetector::TID) {
detname = "TID";
layerNumber = tTopo->tidWheel(detId.rawId);
ringNumber = tTopo->tidRing(detId.rawId);
stereo = tTopo->tidStereo(detId.rawId);
} else if ( subdetId == StripSubdetector::TEC ) {
detname = "TEC";
layerNumber = tTopo->tecWheel(detId.rawId);
ringNumber = tTopo->tecRing(detId.rawId);
stereo = tTopo->tecStereo(detId.rawId);
} else if ( subdetId == PixelSubdetector::PixelBarrel ) {
detname = "PXB";
layerNumber = tTopo->pxbLayer(detId.rawId);
stereo = 1;
} else if ( subdetId == PixelSubdetector::PixelEndcap ) {
detname = "PXF";
layerNumber = tTopo->pxfDisk(detId.rawId);
stereo = 1;
}
std::cout << "Found SiPixelRecHit in " << detname << " from detid " << detId.rawId()
<< " subdet = " << subdetId
<< " layer = " << layerNumber
<< " Stereo = " << stereo
<< std::endl;
std::cout << "Rechit global x/y/z/r : "
<< geomDet->surface().toGlobal(iterRecHit->localPosition()).x() << " "
<< geomDet->surface().toGlobal(iterRecHit->localPosition()).y() << " "
<< geomDet->surface().toGlobal(iterRecHit->localPosition()).z() << " "
<< geomDet->surface().toGlobal(iterRecHit->localPosition()).perp() << std::endl;
*/
//comment out end
unsigned int subid = detId.subdetId();
int layer_num = 0;
if ( (subid==1)||(subid==2) ) {
// 1 = PXB, 2 = PXF
if ( subid == PixelSubdetector::PixelBarrel ) {
layer_num = tTopo->pxbLayer(detId.rawId());
} else if ( subid == PixelSubdetector::PixelEndcap ) {
layer_num = tTopo->pxfDisk(detId.rawId());
}
int num_simhit = matched.size();
fillPRecHit(subid, layer_num, iterRecHit, num_simhit, closest_simhit, geomDet);
fillEvt(e);
pixeltree_->Fill();
init();
// more info
/*
LocalPoint lp = iterRecHit->localPosition();
LocalError le = iterRecHit->localPositionError();
std::cout << "Filled SiPixelRecHit in " << detname << " from detid " << detId.rawId()
<< " subdet = " << subdetId
<< " layer = " << layerNumber
<< "global x/y/z/r = "
<< geomDet->surface().toGlobal(lp).x() << " "
<< geomDet->surface().toGlobal(lp).y() << " "
<< geomDet->surface().toGlobal(lp).z() << " "
<< geomDet->surface().toGlobal(lp).perp()
<< " err x/y = " << sqrt(le.xx()) << " " << sqrt(le.yy())
<< " and num matched simhits = " << num_simhit << std::endl;
*/
}
} // end of rechit loop
} // end of detid loop
} // end of loop test on recHitColl size
// Now loop over recotracks
edm::Handle<View<reco::Track> > trackCollection;
edm::InputTag trackProducer;
trackProducer = conf_.getParameter<edm::InputTag>("trackProducer");
e.getByLabel(trackProducer, trackCollection);
/*
std::cout << " num of reco::Tracks with "
<< trackProducer.process()<<":"
<< trackProducer.label()<<":"
<< trackProducer.instance()
<< ": " << trackCollection->size() << "\n";
*/
int rT = 0;
for(View<reco::Track>::size_type i=0; i<trackCollection->size(); ++i){
++rT;
RefToBase<reco::Track> track(trackCollection, i);
// std::cout << " num of hits for track " << rT << " = " << track->recHitsSize() << std::endl;
for(trackingRecHit_iterator ih=track->recHitsBegin(); ih != track->recHitsEnd(); ++ih) {
TrackingRecHit * hit = (*ih)->clone();
const DetId& detId = hit->geographicalId();
const GeomDet* geomDet( theGeometry->idToDet(detId) );
/////comment out begin
/*
unsigned int subdetId = detId.subdetId();
int layerNumber=0;
int ringNumber = 0;
int stereo = 0;
std::string detname;
if ( subdetId == StripSubdetector::TIB) {
detname = "TIB";
layerNumber = tTopo->tibLayer(detId.rawId);
stereo = tTopo->tibStereo(detId.rawId);
} else if ( subdetId == StripSubdetector::TOB ) {
detname = "TOB";
layerNumber = tTopo->tobLayer(detId.rawId);
stereo = tTopo->tobStereo(detId.rawId);
} else if ( subdetId == StripSubdetector::TID) {
detname = "TID";
layerNumber = tTopo->tidWheel(detId.rawId);
ringNumber = tTopo->tidRing(detId.rawId);
stereo = tTopo->tidStereo(detId.rawId);
} else if ( subdetId == StripSubdetector::TEC ) {
detname = "TEC";
layerNumber = tTopo->tecWheel(detId.rawId);
ringNumber = tTopo->tecRing(detId.rawId);
stereo = tTopo->tecStereo(detId.rawId);
} else if ( subdetId == PixelSubdetector::PixelBarrel ) {
detname = "PXB";
layerNumber = tTopo->pxbLayer(detId.rawId);
stereo = 1;
} else if ( subdetId == PixelSubdetector::PixelEndcap ) {
detname = "PXF";
layerNumber = tTopo->pxfDisk(detId.rawId);
stereo = 1;
}
*/
// std::cout << "RecHit in " << detname << " from detid " << detId.rawId()
// << " subdet = " << subdetId
// << " layer = " << layerNumber
// << " Stereo = " << stereo
// << std::endl;
if(hit->isValid()) {
unsigned int subid = detId.subdetId();
if ( (subid==1)||(subid==2) ) {
// 1 = PXB, 2 = PXF
fillPRecHit(subid, ih, geomDet);
fillEvt(e);
pixeltree2_->Fill();
init();
/*
TrackingRecHit * hit = (*ih)->clone();
LocalPoint lp = hit->localPosition();
LocalError le = hit->localPositionError();
// std::cout << " lp x,y = " << lp.x() << " " << lp.y() << " lpe xx,xy,yy = "
// << le.xx() << " " << le.xy() << " " << le.yy() << std::endl;
std::cout << "Found RecHit in " << detname << " from detid " << detId.rawId()
<< " subdet = " << subdetId
<< " layer = " << layerNumber
<< "global x/y/z/r = "
<< geomDet->surface().toGlobal(lp).x() << " "
<< geomDet->surface().toGlobal(lp).y() << " "
<< geomDet->surface().toGlobal(lp).z() << " "
<< geomDet->surface().toGlobal(lp).perp()
<< " err x/y = " << sqrt(le.xx()) << " " << sqrt(le.yy()) << std::endl;
*/
}
}
delete hit;
} //end of loop on tracking rechits
} // end of loop on recotracks
// now for strip rechits
edm::Handle<SiStripRecHit2DCollection> rechitsrphi;
edm::Handle<SiStripRecHit2DCollection> rechitsstereo;
edm::Handle<SiStripMatchedRecHit2DCollection> rechitsmatched;
e.getByLabel(rphiRecHits_, rechitsrphi);
e.getByLabel(stereoRecHits_, rechitsstereo);
e.getByLabel(matchedRecHits_, rechitsmatched);
//std::cout << " Step A: Standard Strip RPHI RecHits found " << rechitsrphi.product()->dataSize() << std::endl;
//std::cout << " Step A: Standard Strip Stereo RecHits found " << rechitsstereo.product()->dataSize() << std::endl;
//std::cout << " Step A: Standard Strip Matched RecHits found " << rechitsmatched.product()->dataSize() << std::endl;
if(rechitsrphi->size() > 0) {
//Loop over all rechits in RPHI collection (can also loop only over DetId)
// SiStripRecHit2DCollectionOld::const_iterator theRecHitRangeIteratorBegin = rechitsrphi->begin();
// SiStripRecHit2DCollectionOld::const_iterator theRecHitRangeIteratorEnd = rechitsrphi->end();
// SiStripRecHit2DCollectionOld::const_iterator iterRecHit;
SiStripRecHit2DCollection::const_iterator recHitIdIterator = (rechitsrphi.product())->begin();
SiStripRecHit2DCollection::const_iterator recHitIdIteratorEnd = (rechitsrphi.product())->end();
std::string detname ;
// for ( iterRecHit = theRecHitRangeIteratorBegin;
// iterRecHit != theRecHitRangeIteratorEnd; ++iterRecHit) {
// Loop over Detector IDs
for ( ; recHitIdIterator != recHitIdIteratorEnd; recHitIdIterator++) {
SiStripRecHit2DCollection::DetSet detset = *recHitIdIterator;
if( detset.empty() ) continue;
DetId detId = DetId(detset.detId()); // Get the Detid object
// const DetId& detId = iterRecHit->geographicalId();
const GeomDet* geomDet( theGeometry->idToDet(detId) );
// Loop over rechits for this detid
SiStripRecHit2DCollection::DetSet::const_iterator rechitRangeIteratorBegin = detset.begin();
SiStripRecHit2DCollection::DetSet::const_iterator rechitRangeIteratorEnd = detset.end();
SiStripRecHit2DCollection::DetSet::const_iterator iterRecHit;
for ( iterRecHit = rechitRangeIteratorBegin;
iterRecHit != rechitRangeIteratorEnd; ++iterRecHit) {
/////comment out begin
/*
unsigned int subdetId = detId.subdetId();
int layerNumber=0;
int ringNumber = 0;
int stereo = 0;
if ( subdetId == StripSubdetector::TIB) {
detname = "TIB";
layerNumber = tTopo->tibLayer(detId.rawId);
stereo = tTopo->tibStereo(detId.rawId);
} else if ( subdetId == StripSubdetector::TOB ) {
detname = "TOB";
layerNumber = tTopo->tobLayer(detId.rawId);
stereo = tTopo->tobStereo(detId.rawId);
} else if ( subdetId == StripSubdetector::TID) {
detname = "TID";
layerNumber = tTopo->tidWheel(detId.rawId);
ringNumber = tTopo->tidRing(detId.rawId);
stereo = tTopo->tidStereo(detId.rawId);
} else if ( subdetId == StripSubdetector::TEC ) {
detname = "TEC";
layerNumber = tTopo->tecWheel(detId.rawId);
ringNumber = tTopo->tecRing(detId.rawId);
stereo = tTopo->tecStereo(detId.rawId);
} else if ( subdetId == PixelSubdetector::PixelBarrel ) {
detname = "PXB";
layerNumber = tTopo->pxbLayer(detId.rawId);
stereo = 1;
} else if ( subdetId == PixelSubdetector::PixelEndcap ) {
detname = "PXF";
layerNumber = tTopo->pxfDisk(detId.rawId);
stereo = 1;
}
*/
// std::cout << "Found SiStripRPhiRecHit in " << detname << " from detid " << detId.rawId()
// << " subdet = " << subdetId
// << " layer = " << layerNumber
// << " Stereo = " << stereo
// << std::endl;
// std::cout << "Rechit global x/y/z/r : "
// << geomDet->surface().toGlobal(iterRecHit->localPosition()).x() << " "
// << geomDet->surface().toGlobal(iterRecHit->localPosition()).y() << " "
// << geomDet->surface().toGlobal(iterRecHit->localPosition()).z() << " "
// << geomDet->surface().toGlobal(iterRecHit->localPosition()).perp() << std::endl;
//comment out end
unsigned int subid = detId.subdetId();
fillSRecHit(subid, iterRecHit, geomDet);
fillEvt(e);
striptree_->Fill();
init();
} // end of rechit loop
} // end of detid loop
} // end of loop test on rechit size
// now stereo hits
if(rechitsstereo.product()->dataSize() > 0) {
//Loop over all rechits in RPHI collection (can also loop only over DetId)
// SiStripRecHit2DCollectionOld::const_iterator theRecHitRangeIteratorBegin = rechitsstereo->begin();
// SiStripRecHit2DCollectionOld::const_iterator theRecHitRangeIteratorEnd = rechitsstereo->end();
// SiStripRecHit2DCollectionOld::const_iterator iterRecHit;
SiStripRecHit2DCollection::const_iterator recHitIdIterator = (rechitsstereo.product())->begin();
SiStripRecHit2DCollection::const_iterator recHitIdIteratorEnd = (rechitsstereo.product())->end();
std::string detname ;
// Loop over Detector IDs
for ( ; recHitIdIterator != recHitIdIteratorEnd; recHitIdIterator++) {
SiStripRecHit2DCollection::DetSet detset = *recHitIdIterator;
// for ( iterRecHit = theRecHitRangeIteratorBegin;
// iterRecHit != theRecHitRangeIteratorEnd; ++iterRecHit) {
if( detset.empty() ) continue;
DetId detId = DetId(detset.detId()); // Get the Detid object
// const DetId& detId = iterRecHit->geographicalId();
const GeomDet* geomDet( theGeometry->idToDet(detId) );
// Loop over rechits for this detid
SiStripRecHit2DCollection::DetSet::const_iterator rechitRangeIteratorBegin = detset.begin();
SiStripRecHit2DCollection::DetSet::const_iterator rechitRangeIteratorEnd = detset.end();
SiStripRecHit2DCollection::DetSet::const_iterator iterRecHit;
for ( iterRecHit = rechitRangeIteratorBegin;
iterRecHit != rechitRangeIteratorEnd; ++iterRecHit) {
/////comment out begin
/* unsigned int subdetId = detId.subdetId();
int layerNumber=0;
int ringNumber = 0;
int stereo = 0;
if ( subdetId == StripSubdetector::TIB) {
detname = "TIB";
layerNumber = tTopo->tibLayer(detId.rawId);
stereo = tTopo->tibStereo(detId.rawId);
} else if ( subdetId == StripSubdetector::TOB ) {
detname = "TOB";
layerNumber = tTopo->tobLayer(detId.rawId);
stereo = tTopo->tobStereo(detId.rawId);
} else if ( subdetId == StripSubdetector::TID) {
detname = "TID";
layerNumber = tTopo->tidWheel(detId.rawId);
ringNumber = tTopo->tidRing(detId.rawId);
stereo = tTopo->tidStereo(detId.rawId);
} else if ( subdetId == StripSubdetector::TEC ) {
detname = "TEC";
layerNumber = tTopo->tecWheel(detId.rawId);
ringNumber = tTopo->tecRing(detId.rawId);
stereo = tTopo->tecStereo(detId.rawId);
} else if ( subdetId == PixelSubdetector::PixelBarrel ) {
detname = "PXB";
layerNumber = tTopo->pxbLayer(detId.rawId);
stereo = 1;
} else if ( subdetId == PixelSubdetector::PixelEndcap ) {
detname = "PXF";
layerNumber = tTopo->pxfDisk(detId.rawId);
stereo = 1;
}
*/
// std::cout << "Found SiStripStereoRecHit in " << detname << " from detid " << detId.rawId()
// << " subdet = " << subdetId
// << " layer = " << layerNumber
// << " Stereo = " << stereo
// << std::endl;
// std::cout << "Rechit global x/y/z/r : "
// << geomDet->surface().toGlobal(iterRecHit->localPosition()).x() << " "
// << geomDet->surface().toGlobal(iterRecHit->localPosition()).y() << " "
// << geomDet->surface().toGlobal(iterRecHit->localPosition()).z() << " "
// << geomDet->surface().toGlobal(iterRecHit->localPosition()).perp() << std::endl;
//comment out end
unsigned int subid = detId.subdetId();
fillSRecHit(subid, iterRecHit, geomDet);
fillEvt(e);
striptree_->Fill();
init();
} // end of rechit loop
} // end of detid loop
} // end of loop test on rechit size
// now matched hits
if(rechitsmatched.product()->dataSize() > 0) {
//Loop over all rechits in RPHI collection (can also loop only over DetId)
//SiStripMatchedRecHit2DCollectionOld::const_iterator theRecHitRangeIteratorBegin = rechitsmatched->begin();
//SiStripMatchedRecHit2DCollectionOld::const_iterator theRecHitRangeIteratorEnd = rechitsmatched->end();
//SiStripMatchedRecHit2DCollectionOld::const_iterator iterRecHit;
SiStripMatchedRecHit2DCollection::const_iterator recHitIdIterator = (rechitsmatched.product())->begin();
SiStripMatchedRecHit2DCollection::const_iterator recHitIdIteratorEnd = (rechitsmatched.product())->end();
std::string detname ;
// Loop over Detector IDs
for ( ; recHitIdIterator != recHitIdIteratorEnd; recHitIdIterator++) {
SiStripMatchedRecHit2DCollection::DetSet detset = *recHitIdIterator;
if( detset.empty() ) continue;
DetId detId = DetId(detset.detId()); // Get the Detid object
// for ( iterRecHit = theRecHitRangeIteratorBegin;
// iterRecHit != theRecHitRangeIteratorEnd; ++iterRecHit) {
// const DetId& detId = iterRecHit->geographicalId();
const GeomDet* geomDet( theGeometry->idToDet(detId) );
// Loop over rechits for this detid
SiStripMatchedRecHit2DCollection::DetSet::const_iterator rechitRangeIteratorBegin = detset.begin();
SiStripMatchedRecHit2DCollection::DetSet::const_iterator rechitRangeIteratorEnd = detset.end();
SiStripMatchedRecHit2DCollection::DetSet::const_iterator iterRecHit;
for ( iterRecHit = rechitRangeIteratorBegin;
iterRecHit != rechitRangeIteratorEnd; ++iterRecHit) {
/////comment out begin
/*
unsigned int subdetId = detId.subdetId();
int layerNumber=0;
int ringNumber = 0;
int stereo = 0;
if ( subdetId == StripSubdetector::TIB) {
detname = "TIB";
layerNumber = tTopo->tibLayer(detId.rawId);
stereo = tTopo->tibStereo(detId.rawId);
} else if ( subdetId == StripSubdetector::TOB ) {
detname = "TOB";
layerNumber = tTopo->tobLayer(detId.rawId);
stereo = tTopo->tobStereo(detId.rawId);
} else if ( subdetId == StripSubdetector::TID) {
detname = "TID";
layerNumber = tTopo->tidWheel(detId.rawId);
ringNumber = tTopo->tidRing(detId.rawId);
stereo = tTopo->tidStereo(detId.rawId);
} else if ( subdetId == StripSubdetector::TEC ) {
detname = "TEC";
layerNumber = tTopo->tecWheel(detId.rawId);
ringNumber = tTopo->tecRing(detId.rawId);
stereo = tTopo->tecStereo(detId.rawId);
} else if ( subdetId == PixelSubdetector::PixelBarrel ) {
detname = "PXB";
layerNumber = tTopo->pxbLayer(detId.rawId);
stereo = 1;
} else if ( subdetId == PixelSubdetector::PixelEndcap ) {
detname = "PXF";
layerNumber = tTopo->pxfDisk(detId.rawId);
stereo = 1;
}
*/
// std::cout << "Found SiStripMatchedRecHit in " << detname << " from detid " << detId.rawId()
// << " subdet = " << subdetId
// << " layer = " << layerNumber
// << " Stereo = " << stereo
// << std::endl;
// std::cout << "Rechit global x/y/z/r : "
// << geomDet->surface().toGlobal(iterRecHit->localPosition()).x() << " "
// << geomDet->surface().toGlobal(iterRecHit->localPosition()).y() << " "
// << geomDet->surface().toGlobal(iterRecHit->localPosition()).z() << " "
// << geomDet->surface().toGlobal(iterRecHit->localPosition()).perp() << std::endl;
//comment out end
unsigned int subid = detId.subdetId();
fillSRecHit(subid, iterRecHit, geomDet);
fillEvt(e);
striptree_->Fill();
init();
} // end of rechit loop
} // end of detidt loop
} // end of loop test on rechit size
} // end analyze function
void StdHitNtuplizer::fillSRecHit(const int subid,
SiStripRecHit2DCollection::DetSet::const_iterator pixeliter,
const GeomDet* theGeom)
{
LocalPoint lp = pixeliter->localPosition();
LocalError le = pixeliter->localPositionError();
striprecHit_.x = lp.x();
striprecHit_.y = lp.y();
striprecHit_.xx = le.xx();
striprecHit_.xy = le.xy();
striprecHit_.yy = le.yy();
GlobalPoint GP = theGeom->surface().toGlobal(pixeliter->localPosition());
striprecHit_.gx = GP.x();
striprecHit_.gy = GP.y();
striprecHit_.gz = GP.z();
striprecHit_.subid = subid;
}
void StdHitNtuplizer::fillSRecHit(const int subid,
SiStripMatchedRecHit2DCollection::DetSet::const_iterator pixeliter,
const GeomDet* theGeom)
{
LocalPoint lp = pixeliter->localPosition();
LocalError le = pixeliter->localPositionError();
striprecHit_.x = lp.x();
striprecHit_.y = lp.y();
striprecHit_.xx = le.xx();
striprecHit_.xy = le.xy();
striprecHit_.yy = le.yy();
GlobalPoint GP = theGeom->surface().toGlobal(pixeliter->localPosition());
striprecHit_.gx = GP.x();
striprecHit_.gy = GP.y();
striprecHit_.gz = GP.z();
striprecHit_.subid = subid;
}
void StdHitNtuplizer::fillSRecHit(const int subid,
SiTrackerGSRecHit2DCollection::const_iterator pixeliter,
const GeomDet* theGeom)
{
LocalPoint lp = pixeliter->localPosition();
LocalError le = pixeliter->localPositionError();
striprecHit_.x = lp.x();
striprecHit_.y = lp.y();
striprecHit_.xx = le.xx();
striprecHit_.xy = le.xy();
striprecHit_.yy = le.yy();
//MeasurementPoint mp = topol->measurementPosition(LocalPoint(striprecHit_.x, striprecHit_.y));
//striprecHit_.row = mp.x();
//striprecHit_.col = mp.y();
GlobalPoint GP = theGeom->surface().toGlobal(pixeliter->localPosition());
striprecHit_.gx = GP.x();
striprecHit_.gy = GP.y();
striprecHit_.gz = GP.z();
striprecHit_.subid = subid;
}
void StdHitNtuplizer::fillPRecHit(const int subid,
const int layer_num,
SiPixelRecHitCollection::DetSet::const_iterator pixeliter,
const int num_simhit,
std::vector<PSimHit>::const_iterator closest_simhit,
const GeomDet* PixGeom)
{
LocalPoint lp = pixeliter->localPosition();
LocalError le = pixeliter->localPositionError();
recHit_.x = lp.x();
recHit_.y = lp.y();
recHit_.xx = le.xx();
recHit_.xy = le.xy();
recHit_.yy = le.yy();
//MeasurementPoint mp = topol->measurementPosition(LocalPoint(recHit_.x, recHit_.y));
//recHit_.row = mp.x();
//recHit_.col = mp.y();
GlobalPoint GP = PixGeom->surface().toGlobal(pixeliter->localPosition());
recHit_.gx = GP.x();
recHit_.gy = GP.y();
recHit_.gz = GP.z();
recHit_.subid = subid;
recHit_.layer = layer_num;
recHit_.nsimhit = num_simhit;
//std::cout << "num_simhit = " << num_simhit << std::endl;
if(num_simhit > 0) {
float sim_x1 = (*closest_simhit).entryPoint().x();
float sim_x2 = (*closest_simhit).exitPoint().x();
recHit_.hx = 0.5*(sim_x1+sim_x2);
float sim_y1 = (*closest_simhit).entryPoint().y();
float sim_y2 = (*closest_simhit).exitPoint().y();
recHit_.hy = 0.5*(sim_y1+sim_y2);
//std::cout << "num_simhit x, y = " << 0.5*(sim_x1+sim_x2) << " " << 0.5*(sim_y1+sim_y2) << std::endl;
}
/*
std::cout << "Found RecHit in " << subid
<< " global x/y/z : "
<< PixGeom->surface().toGlobal(pixeliter->localPosition()).x() << " "
<< PixGeom->surface().toGlobal(pixeliter->localPosition()).y() << " "
<< PixGeom->surface().toGlobal(pixeliter->localPosition()).z() << std::endl;
*/
}
void StdHitNtuplizer::fillPRecHit(const int subid,
trackingRecHit_iterator ih,
const GeomDet* PixGeom)
{
TrackingRecHit * pixeliter = (*ih)->clone();
LocalPoint lp = pixeliter->localPosition();
LocalError le = pixeliter->localPositionError();
recHit_.x = lp.x();
recHit_.y = lp.y();
recHit_.xx = le.xx();
recHit_.xy = le.xy();
recHit_.yy = le.yy();
GlobalPoint GP = PixGeom->surface().toGlobal(pixeliter->localPosition());
recHit_.gx = GP.x();
recHit_.gy = GP.y();
recHit_.gz = GP.z();
delete pixeliter;
recHit_.subid = subid;
}
void
StdHitNtuplizer::fillEvt(const edm::Event& E)
{
evt_.run = E.id().run();
evt_.evtnum = E.id().event();
}
void StdHitNtuplizer::init()
{
evt_.init();
recHit_.init();
striprecHit_.init();
}
void StdHitNtuplizer::evt::init()
{
int dummy_int = 9999;
run = dummy_int;
evtnum = dummy_int;
}
void StdHitNtuplizer::RecHit::init()
{
float dummy_float = 9999.0;
x = dummy_float;
y = dummy_float;
xx = dummy_float;
xy = dummy_float;
yy = dummy_float;
row = dummy_float;
col = dummy_float;
gx = dummy_float;
gy = dummy_float;
gz = dummy_float;
layer = 0;
nsimhit = 0;
hx = dummy_float;
hy = dummy_float;
tx = dummy_float;
ty = dummy_float;
theta = dummy_float;
phi = dummy_float;
}
//define this as a plug-in
DEFINE_FWK_MODULE(StdHitNtuplizer);