-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNtupleMaker.cc
1186 lines (1048 loc) · 53.6 KB
/
NtupleMaker.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
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//////////////////////////////////////////////////////////////////////
// Making Ntuples for GEM CSC analysis //
// Author: Sifu Luo //
// [email protected] //
//////////////////////////////////////////////////////////////////////
// CMSSW
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/one/EDAnalyzer.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "FWCore/ServiceRegistry/interface/Service.h"
// GEMCode
#include "GEMCode/GEMValidation/interface/MatcherManager.h"
// NtupleMaker tools
#include "GEMCode/GEMValidation/test/TreeDigi.cc"
#include "GEMCode/GEMValidation/test/GEMTool.cc"
// Other tools
#include "CommonTools/UtilAlgos/interface/TFileService.h"
// Muons
#include "DataFormats/L1Trigger/interface/Muon.h"
#include "L1Trigger/L1TMuon/interface/MuonRawDigiTranslator.h"
#include "L1Trigger/L1TMuon/interface/RegionalMuonRawDigiTranslator.h"
#include "DataFormats/L1TMuon/interface/RegionalMuonCandFwd.h"
#include "DataFormats/L1TMuon/interface/RegionalMuonCand.h"
#include "L1Trigger/L1TMuon/interface/MicroGMTConfiguration.h"
// KBMTF
#include "DataFormats/L1TMuon/interface/L1MuKBMTrack.h"
#include "DataFormats/L1Trigger/interface/BXVector.h"
// ROOT
#include <TROOT.h>
#include <TTree.h>
// STD
#include <iomanip>
#include <sstream>
#include <iostream>
#include <memory>
#include <string>
#include <math.h>
#include <bitset>
#include <fstream>
#include <cmath>
#include <vector>
#include <set>
#include <sstream>
#include <stdexcept>
// Unclear headers
#include "DataFormats/Common/interface/Handle.h"
#include "DataFormats/Common/interface/Ref.h"
#include "DataFormats/L1TrackTrigger/interface/TTTypes.h"
#include "DataFormats/L1TrackTrigger/interface/TTCluster.h"
#include "DataFormats/L1TrackTrigger/interface/TTStub.h"
#include "DataFormats/L1TrackTrigger/interface/TTTrack.h"
#include "SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h"
#include "SimDataFormats/TrackingAnalysis/interface/TrackingVertex.h"
#include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
#include "SimDataFormats/TrackingHit/interface/PSimHit.h"
#include "SimTracker/TrackTriggerAssociation/interface/TTClusterAssociationMap.h"
#include "SimTracker/TrackTriggerAssociation/interface/TTStubAssociationMap.h"
#include "SimTracker/TrackTriggerAssociation/interface/TTTrackAssociationMap.h"
// #include "Geometry/Records/interface/StackedTrackerGeometryRecord.h"
#include "DataFormats/JetReco/interface/GenJetCollection.h"
#include "DataFormats/JetReco/interface/GenJet.h"
#include "MagneticField/Engine/interface/MagneticField.h"
#include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
// #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
#include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
// #include "Geometry/TrackerGeometryBuilder/interface/RectangularPixelTopology.h"
#include "Geometry/CommonDetUnit/interface/GeomDetType.h"
#include "Geometry/CommonDetUnit/interface/GeomDet.h"
#include "Geometry/CommonTopologies/interface/PixelGeomDetUnit.h"
#include "Geometry/CommonTopologies/interface/PixelGeomDetType.h"
// #include "Geometry/TrackerGeometryBuilder/interface/PixelTopologyBuilder.h"
// #include "Geometry/Records/interface/StackedTrackerGeometryRecord.h"
#include "Geometry/CommonDetUnit/interface/TrackingGeometry.h"
#include "DataFormats/CSCDigi/interface/CSCALCTDigi.h"
#include "DataFormats/CSCDigi/interface/CSCCLCTDigi.h"
using namespace std;
using namespace edm;
class NtupleMaker : public edm::one::EDAnalyzer<> {
public:
explicit NtupleMaker(const edm::ParameterSet& iConfig);
virtual ~NtupleMaker();
virtual void beginJob();
virtual void endJob();
virtual void analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup);
virtual void PrintHits(int iset, int idigi = -1);
virtual int SaveHitMatrix(std::vector< std::vector<unsigned short> > hits, std::vector<int>* b_hit, std::vector<int>* b_pos, bool doprint = false, bool isclct = false);
virtual std::vector<int> IntsToBinary(int n);
virtual GlobalPoint getGlobalPointDigi(unsigned int rawId, const GEMDigi& d);
protected:
private:
// ParameterSet passed from python configuration
edm::ParameterSet config;
int MyProcess;
bool DebugMode;
double TP_minPt;
double TP_maxEta;
double TP_maxZ0;
bool IsRun4;
bool useGEMs;
bool Print_matchCscStubs;
bool Print_allCscStubs;
bool Print_all;
bool Print_ALCT;
bool Print_CLCT;
int nEventMultiHitLayer;
edm::InputTag TrackingParticleInputTag;
std::string getFloatPointDataWord(const l1t::RegionalMuonCand& l1mu) const;
std::string getGlobalPhi(const l1t::RegionalMuonCand& l1mu) const;
edm::EDGetToken m_emtfToken;
// edm::EDGetToken m_bmtfToken;
// edm::EDGetToken m_omtfToken;
edm::EDGetTokenT< std::vector< TrackingParticle > > TrackingParticleToken_;
edm::EDGetTokenT<edm::SimVertexContainer> simVertexInput_;
edm::EDGetTokenT<CSCCorrelatedLCTDigiCollection> lctToken_;
edm::EDGetTokenT<CSCALCTDigiCollection> alctToken_;
edm::EDGetTokenT<CSCCLCTDigiCollection> clctToken_;
edm::EDGetTokenT<GEMDigiCollection> gemDigiToken_;
edm::EDGetTokenT<GEMPadDigiCollection> gemPadDigiToken_;
edm::EDGetTokenT<GEMPadDigiClusterCollection> gemPadDigiClusterToken_;
edm::ESGetToken<CSCL1TPLookupTableCCLUT, CSCL1TPLookupTableCCLUTRcd> pLookupTableCCLUTToken_;
edm::ESGetToken<CSCL1TPLookupTableME11ILT, CSCL1TPLookupTableME11ILTRcd> pLookupTableME11ILTToken_;
edm::ESGetToken<CSCL1TPLookupTableME21ILT, CSCL1TPLookupTableME21ILTRcd> pLookupTableME21ILTToken_;
// Ntuple
TTree* eventTree;
GEMTool* GEMConverter;
// Regional Muon candidates
// std::vector<int>* m_EMTF_muon_n;
// std::vector<float>* m_EMTF_muon_pt;
// std::vector<float>* m_EMTF_muon_eta;
// std::vector<float>* m_EMTF_muon_phi;
// std::vector<int>* m_EMTF_muon_c;
// std::vector<int>* m_OMTF_muon_n;
// std::vector<float>* m_OMTF_muon_pt;
// std::vector<float>* m_OMTF_muon_eta;
// std::vector<float>* m_OMTF_muon_phi;
// std::vector<int>* m_OMTF_muon_c;
//
// std::vector<int>* m_BMTF_muon_n;
// std::vector<float>* m_BMTF_muon_pt;
// std::vector<float>* m_BMTF_muon_eta;
// std::vector<float>* m_BMTF_muon_phi;
// std::vector<int>* m_BMTF_muon_c;
std::vector<float>* m_matchmuon_pt;
std::vector<float>* m_matchmuon_eta;
std::vector<float>* m_matchmuon_phi;
std::vector<int>* m_matchmuon_charge;
std::vector<int>* m_matchmuon_type;
std::vector<int>* m_matchmuon_quality;
TreeDigi *tp, *cscSimHit, *gemSimHit;
TreeDigi *allCscStubsLCT, *allCscStubsALCT, *allCscStubsCLCT;
TreeDigi *allALCT, *allCLCT, *allGemDigi;
TreeDigi *matchCscStubsLCT, *matchCscStubsALCT, *matchCscStubsCLCT, *matchGemDigi;
TreeDigi *matchCscGEM1, *matchCscGEM2, *allCscGEM1, *allCscGEM2, *matchGemPadDigi, *allGemPadDigi;
TreeDigi *matchGemPadDigiCluster, *allGemPadDigiCluster;
std::unique_ptr<MatcherManager> match;
// const TrackingGeometry* geometry_;
edm::ESGetToken<GEMGeometry, MuonGeometryRecord> geomToken_;
const GEMGeometry* gemGeometry_;
};
NtupleMaker::NtupleMaker(edm::ParameterSet const& iConfig) :
config(iConfig)
{
MyProcess = iConfig.getParameter< int >("MyProcess");
DebugMode = iConfig.getParameter< bool >("DebugMode");
TP_minPt = iConfig.getParameter< double >("TP_minPt");
TP_maxEta = iConfig.getParameter< double >("TP_maxEta");
TP_maxZ0 = iConfig.getParameter< double >("TP_maxZ0");
IsRun4 = iConfig.getParameter< bool >("IsRun4");
Print_matchCscStubs = iConfig.getParameter< bool >("Print_matchCscStubs");
Print_allCscStubs = iConfig.getParameter< bool >("Print_allCscStubs");
Print_all = iConfig.getParameter< bool >("Print_all");
Print_ALCT = iConfig.getParameter< bool >("Print_ALCT");
Print_CLCT = iConfig.getParameter< bool >("Print_CLCT");
useGEMs = iConfig.getParameter< bool >("useGEMs");
TrackingParticleInputTag = iConfig.getParameter<edm::InputTag>("TrackingParticleInputTag");
TrackingParticleToken_ = consumes< std::vector< TrackingParticle > >(TrackingParticleInputTag);
// m_emtfToken = consumes<l1t::RegionalMuonCandBxCollection>(edm::InputTag("simEmtfDigis","EMTF"));
// m_bmtfToken = consumes<l1t::RegionalMuonCandBxCollection>(edm::InputTag(IsRun4 ? "simBmtfDigis": "gmtStage2Digis","BMTF"));
// m_omtfToken = consumes<l1t::RegionalMuonCandBxCollection>(edm::InputTag(IsRun4 ? "simOmtfDigis": "gmtStage2Digis","OMTF"));
const auto& simVertex = iConfig.getParameter<edm::ParameterSet>("simVertex");
simVertexInput_ = consumes<edm::SimVertexContainer>(simVertex.getParameter<edm::InputTag>("inputTag"));
const auto& P_cscLCT = iConfig.getParameter<edm::ParameterSet>("cscLCT");
lctToken_ = consumes<CSCCorrelatedLCTDigiCollection>(P_cscLCT.getParameter<edm::InputTag>("inputTag"));
const auto& P_cscALCT = iConfig.getParameter<edm::ParameterSet>("cscALCT");
alctToken_ = consumes<CSCALCTDigiCollection>(P_cscALCT.getParameter<edm::InputTag>("inputTag"));
const auto& P_cscCLCT = iConfig.getParameter<edm::ParameterSet>("cscCLCT");
clctToken_ = consumes<CSCCLCTDigiCollection>(P_cscCLCT.getParameter<edm::InputTag>("inputTag"));
const auto& P_gemDigi = iConfig.getParameter<edm::ParameterSet>("gemStripDigi");
gemDigiToken_ = consumes<GEMDigiCollection>(P_gemDigi.getParameter<edm::InputTag>("inputTag"));
const auto& P_gemPadDigi = iConfig.getParameter<edm::ParameterSet>("gemPadDigi");
gemPadDigiToken_ = consumes<GEMPadDigiCollection>(P_gemPadDigi.getParameter<edm::InputTag>("inputTag"));
const auto& P_gemPadDigiCluster = iConfig.getParameter<edm::ParameterSet>("gemPadCluster");
gemPadDigiClusterToken_ = consumes<GEMPadDigiClusterCollection>(P_gemPadDigiCluster.getParameter<edm::InputTag>("inputTag"));
// const auto& P_gemcscParams = iConfig.getParameter<edm::ParameterSet>("gemcscPSets");
// GEMConverter = new GEMTool();
// pLookupTableCCLUTToken_ = esConsumes<CSCL1TPLookupTableCCLUT, CSCL1TPLookupTableCCLUTRcd>();
pLookupTableME11ILTToken_ = esConsumes<CSCL1TPLookupTableME11ILT, CSCL1TPLookupTableME11ILTRcd>();
pLookupTableME21ILTToken_ = esConsumes<CSCL1TPLookupTableME21ILT, CSCL1TPLookupTableME21ILTRcd>();
geomToken_ = esConsumes<GEMGeometry, MuonGeometryRecord>();
match.reset(new MatcherManager(iConfig, consumesCollector()));
}
NtupleMaker::~NtupleMaker()
{
}
void NtupleMaker::endJob()
{
cerr << "Number of event with layers having multiple hits: " << nEventMultiHitLayer <<endl;
cerr << "NtupleMaker::endJob" << endl;
}
void NtupleMaker::beginJob()
{
cerr << "NtupleMaker::beginJob" << endl;
// if (true) {
// cout << " Types of LCTs:" <<endl;
// CSCCorrelatedLCTDigi tmplct;
// tmplct.setType(CSCCorrelatedLCTDigi::CLCTALCT); 0 //CLCTALCT
// cout << tmplct.getType()<<" , ";
// tmplct.setType(CSCCorrelatedLCTDigi::ALCTCLCT); 1 //ALCTCLCT
// cout << tmplct.getType()<<" , ";
// tmplct.setType(CSCCorrelatedLCTDigi::ALCTCLCTGEM); 2 //ALCTCLCTGEM
// cout << tmplct.getType()<<" , ";
// tmplct.setType(CSCCorrelatedLCTDigi::ALCTCLCT2GEM);3 //ALCTCLCT2GEM
// cout << tmplct.getType()<<" , ";
// tmplct.setType(CSCCorrelatedLCTDigi::ALCT2GEM); 4 //ALCT2GEM
// cout << tmplct.getType()<<" , ";
// tmplct.setType(CSCCorrelatedLCTDigi::CLCT2GEM); 5 //CLCT2GEM
// cout << tmplct.getType()<<" , ";
// tmplct.setType(CSCCorrelatedLCTDigi::CLCTONLY); 6 //CLCTONLY
// cout << tmplct.getType()<<" , ";
// tmplct.setType(CSCCorrelatedLCTDigi::ALCTONLY); 7 //ALCTONLY
// cout << tmplct.getType()<<endl;
// }
nEventMultiHitLayer = 0;
edm::Service<TFileService> fs;
// m_EMTF_muon_n = new std::vector<int>;
// m_EMTF_muon_pt = new std::vector<float>;
// m_EMTF_muon_eta = new std::vector<float>;
// m_EMTF_muon_phi = new std::vector<float>;
// m_EMTF_muon_c = new std::vector<int>;
// m_OMTF_muon_n = new std::vector<int>;
// m_OMTF_muon_pt = new std::vector<float>;
// m_OMTF_muon_eta = new std::vector<float>;
// m_OMTF_muon_phi = new std::vector<float>;
// m_OMTF_muon_c = new std::vector<int>;
//
// m_BMTF_muon_n = new std::vector<int>;
// m_BMTF_muon_pt = new std::vector<float>;
// m_BMTF_muon_eta = new std::vector<float>;
// m_BMTF_muon_phi = new std::vector<float>;
// m_BMTF_muon_c = new std::vector<int>;
m_matchmuon_pt = new std::vector<float>;
m_matchmuon_eta = new std::vector<float>;
m_matchmuon_phi = new std::vector<float>;
m_matchmuon_charge = new std::vector<int>;
m_matchmuon_type = new std::vector<int>;
m_matchmuon_quality = new std::vector<int>;
eventTree = fs->make<TTree>("eventTree", "Event tree");
// eventTree->Branch("EMTF_muon_n", &m_EMTF_muon_n);
// eventTree->Branch("EMTF_muon_pt", &m_EMTF_muon_pt);
// eventTree->Branch("EMTF_muon_eta", &m_EMTF_muon_eta);
// eventTree->Branch("EMTF_muon_phi", &m_EMTF_muon_phi);
// eventTree->Branch("EMTF_muon_c", &m_EMTF_muon_c);
// eventTree->Branch("OMTF_muon_n", &m_OMTF_muon_n);
// eventTree->Branch("OMTF_muon_pt", &m_OMTF_muon_pt);
// eventTree->Branch("OMTF_muon_eta", &m_OMTF_muon_eta);
// eventTree->Branch("OMTF_muon_phi", &m_OMTF_muon_phi);
// eventTree->Branch("OMTF_muon_c", &m_OMTF_muon_c);
//
// eventTree->Branch("BMTF_muon_n", &m_BMTF_muon_n);
// eventTree->Branch("BMTF_muon_pt", &m_BMTF_muon_pt);
// eventTree->Branch("BMTF_muon_eta", &m_BMTF_muon_eta);
// eventTree->Branch("BMTF_muon_phi", &m_BMTF_muon_phi);
// eventTree->Branch("BMTF_muon_c", &m_BMTF_muon_c);
eventTree->Branch("matchmuon_pt", &m_matchmuon_pt);
eventTree->Branch("matchmuon_eta", &m_matchmuon_eta);
eventTree->Branch("matchmuon_phi", &m_matchmuon_phi);
eventTree->Branch("matchmuon_charge",&m_matchmuon_charge);
eventTree->Branch("matchmuon_type",&m_matchmuon_type);
eventTree->Branch("matchmuon_quality",&m_matchmuon_quality);
// GEMConverter->Init(P_gemcscParams);
GEMConverter = new GEMTool();
tp = new TreeDigi();
cscSimHit = new TreeDigi();
gemSimHit = new TreeDigi();
allCscStubsLCT = new TreeDigi();
allCscStubsALCT = new TreeDigi();
allCscStubsCLCT = new TreeDigi();
allALCT = new TreeDigi();
allCLCT = new TreeDigi();
allGemDigi = new TreeDigi();
matchCscStubsLCT = new TreeDigi();
matchCscStubsALCT = new TreeDigi();
matchCscStubsCLCT = new TreeDigi();
matchGemDigi = new TreeDigi();
matchCscGEM1 = new TreeDigi();
matchCscGEM2 = new TreeDigi();
allCscGEM1 = new TreeDigi();
allCscGEM2 = new TreeDigi();
matchGemPadDigi = new TreeDigi();
allGemPadDigi = new TreeDigi();
matchGemPadDigiCluster = new TreeDigi();
allGemPadDigiCluster = new TreeDigi();
tp ->Init(eventTree,"tp" ,"TP" ,GEMConverter ,false);
cscSimHit ->Init(eventTree,"cscSimHit" ,"SimHit" ,GEMConverter ,true);
gemSimHit ->Init(eventTree,"gemSimHit" ,"SimHit" ,GEMConverter ,true);
allCscStubsLCT ->Init(eventTree,"allCscStubsLCT" ,"LCT" ,GEMConverter ,false);
allCscStubsALCT ->Init(eventTree,"allCscStubsALCT" ,"ALCT" ,GEMConverter ,false);
allCscStubsCLCT ->Init(eventTree,"allCscStubsCLCT" ,"CLCT" ,GEMConverter ,false);
allALCT ->Init(eventTree,"allALCT" ,"ALCT" ,GEMConverter ,false);
allCLCT ->Init(eventTree,"allCLCT" ,"CLCT" ,GEMConverter ,false);
allGemDigi ->Init(eventTree,"allGemDigi" ,"GEM" ,GEMConverter ,false);
matchCscStubsLCT ->Init(eventTree,"matchCscStubsLCT" ,"LCT" ,GEMConverter ,true);
matchCscStubsALCT ->Init(eventTree,"matchCscStubsALCT" ,"ALCT" ,GEMConverter ,false);
matchCscStubsCLCT ->Init(eventTree,"matchCscStubsCLCT" ,"CLCT" ,GEMConverter ,false);
matchGemDigi ->Init(eventTree,"matchGemDigi" ,"GEM" ,GEMConverter ,true);
matchCscGEM1 ->Init(eventTree,"matchCscGEM1" ,"GEMPad" ,GEMConverter ,true);
matchCscGEM2 ->Init(eventTree,"matchCscGEM2" ,"GEMPad" ,GEMConverter ,true);
allCscGEM1 ->Init(eventTree,"allCscGEM1" ,"GEMPad" ,GEMConverter ,true);
allCscGEM2 ->Init(eventTree,"allCscGEM2" ,"GEMPad" ,GEMConverter ,true);
matchGemPadDigi ->Init(eventTree,"matchGemPadDigi" ,"GEMPad" ,GEMConverter ,true);
allGemPadDigi ->Init(eventTree,"allGemPadDigi" ,"GEMPad" ,GEMConverter ,false);
matchGemPadDigiCluster->Init(eventTree,"matchGemPadDigiCluster","GEMPadDigiCluster",GEMConverter ,true);
allGemPadDigiCluster ->Init(eventTree,"allGemPadDigiCluster" ,"GEMPadDigiCluster",GEMConverter ,false);
}
void NtupleMaker::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
{
if (DebugMode) cout <<endl<<endl<< "Starting a new event-------------------------------------------------------------------------------------------------------" << endl;
if (!(MyProcess==13 || MyProcess==11 || MyProcess==211 || MyProcess==6 || MyProcess==15 || MyProcess==1)) {
cout << "The specified MyProcess is invalid! Exiting..." << endl;
return;
}
// m_EMTF_muon_n->clear();
// m_EMTF_muon_pt->clear();
// m_EMTF_muon_eta->clear();
// m_EMTF_muon_phi->clear();
// m_EMTF_muon_c->clear();
// m_OMTF_muon_n->clear();
// m_OMTF_muon_pt->clear();
// m_OMTF_muon_eta->clear();
// m_OMTF_muon_phi->clear();
// m_OMTF_muon_c->clear();
//
// m_BMTF_muon_n->clear();
// m_BMTF_muon_pt->clear();
// m_BMTF_muon_eta->clear();
// m_BMTF_muon_phi->clear();
// m_BMTF_muon_c->clear();
m_matchmuon_pt->clear();
m_matchmuon_eta->clear();
m_matchmuon_phi->clear();
m_matchmuon_charge->clear();
m_matchmuon_type->clear();
m_matchmuon_quality->clear();
tp->Reset();
cscSimHit->Reset();
gemSimHit->Reset();
allCscStubsLCT->Reset();
allCscStubsALCT->Reset();
allCscStubsCLCT->Reset();
allALCT->Reset();
allCLCT->Reset();
allGemDigi->Reset();
matchCscStubsLCT->Reset();
matchCscStubsALCT->Reset();
matchCscStubsCLCT->Reset();
matchGemDigi->Reset();
matchCscGEM1->Reset();
matchCscGEM2->Reset();
allCscGEM1->Reset();
allCscGEM2->Reset();
matchGemPadDigi->Reset();
allGemPadDigi->Reset();
matchGemPadDigiCluster->Reset();
allGemPadDigiCluster->Reset();
if (DebugMode) cout << "Finished branch initialization" << endl;
edm::Handle< std::vector< TrackingParticle > > TrackingParticleHandle;
iEvent.getByToken(TrackingParticleToken_, TrackingParticleHandle);
// edm::ESHandle<TrackerGeometry> geometryHandle;
// iSetup.get<TrackerDigiGeometryRecord>().get(geometryHandle);
//
// edm::ESHandle<TrackerTopology> tTopoHandle;
// iSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
//
// edm::ESHandle<TrackerGeometry> tGeomHandle;
// iSetup.get<TrackerDigiGeometryRecord>().get(tGeomHandle);
match->init(iEvent,iSetup);
edm::Handle<edm::SimVertexContainer> sim_vertices;
iEvent.getByToken(simVertexInput_, sim_vertices);
const edm::SimVertexContainer & sim_vert = *sim_vertices.product();
gemGeometry_ = &iSetup.getData(geomToken_);
// edm::ESHandle<CSCL1TPLookupTableCCLUT> confCCLUT = setup.getHandle(pLookupTableCCLUTToken_);
edm::ESHandle<CSCL1TPLookupTableME11ILT> confME11 = iSetup.getHandle(pLookupTableME11ILTToken_);
edm::ESHandle<CSCL1TPLookupTableME21ILT> confME21 = iSetup.getHandle(pLookupTableME21ILTToken_);
GEMConverter->Init(confME11.product(), confME21.product());
int tp_index = 0;
std::vector< TrackingParticle >::const_iterator iterTP;
if (DebugMode) cout << "Started TP iteration" << endl;
for (iterTP = TrackingParticleHandle->begin(); iterTP != TrackingParticleHandle->end(); ++iterTP) {
if (DebugMode) cout << "Started "<< tp_index << " TP information Collecting" << endl;
edm::Ptr< TrackingParticle > tp_ptr(TrackingParticleHandle, tp_index);
int tmp_eventid = iterTP->eventId().event();
if (MyProcess != 1 && tmp_eventid > 0) continue; //only care about tracking particles from the primary interaction (except for MyProcess==1, i.e. looking at all TPs)
float tmp_tp_pt = iterTP->pt();
float tmp_tp_eta = iterTP->eta();
float tmp_tp_phi = iterTP->phi();
float tmp_tp_vz = iterTP->vz();
float tmp_tp_vx = iterTP->vx();
float tmp_tp_vy = iterTP->vy();
int tmp_tp_pdgid = iterTP->pdgId();
float tmp_tp_z0_prod = tmp_tp_vz;
float tmp_tp_d0_prod = -tmp_tp_vx*sin(tmp_tp_phi) + tmp_tp_vy*cos(tmp_tp_phi);
if (MyProcess==13 && abs(tmp_tp_pdgid) != 13) continue;
if (MyProcess==11 && abs(tmp_tp_pdgid) != 11) continue;
if ((MyProcess==6 || MyProcess==15 || MyProcess==211) && abs(tmp_tp_pdgid) != 211) continue;
if (tmp_tp_pt < TP_minPt) continue;
if (fabs(tmp_tp_eta) > TP_maxEta) continue;
// Calculation of d0 and z0
float tmp_tp_t = tan(2.0*atan(1.0)-2.0*atan(exp(-tmp_tp_eta)));
float delx = -tmp_tp_vx;
float dely = -tmp_tp_vy;
float A = 0.01*0.5696;
float Kmagnitude = A / tmp_tp_pt;
float tmp_tp_charge = tp_ptr->charge();
float K = Kmagnitude * tmp_tp_charge;
float d = 0;
float tmp_tp_x0p = delx - (d + 1./(2. * K)*sin(tmp_tp_phi));
float tmp_tp_y0p = dely + (d + 1./(2. * K)*cos(tmp_tp_phi));
float tmp_tp_rp = sqrt(tmp_tp_x0p*tmp_tp_x0p + tmp_tp_y0p*tmp_tp_y0p);
float tmp_tp_d0 = tmp_tp_charge*tmp_tp_rp - (1. / (2. * K));
tmp_tp_d0 = tmp_tp_d0*(-1); //fix d0 sign
static double pi = 4.0*atan(1.0);
float delphi = tmp_tp_phi-atan2(-K*tmp_tp_x0p,K*tmp_tp_y0p);
if (delphi<-pi) delphi+=2.0*pi;
if (delphi>pi) delphi-=2.0*pi;
float tmp_tp_z0 = tmp_tp_vz+tmp_tp_t*delphi/(2.0*K);
// ----------------------------------------------------------------------------------------------
if (fabs(tmp_tp_z0) > TP_maxZ0) continue;
float dxy = sqrt(tmp_tp_vx*tmp_tp_vx + tmp_tp_vy*tmp_tp_vy);
float tmp_tp_dxy = dxy;
if (MyProcess==6 && (dxy > 1.0)) continue;
tp->pt->push_back(tmp_tp_pt);
tp->eta->push_back(tmp_tp_eta);
tp->phi->push_back(tmp_tp_phi);
tp->dxy->push_back(tmp_tp_dxy);
tp->z0->push_back(tmp_tp_z0);
tp->d0->push_back(tmp_tp_d0);
tp->z0_prod->push_back(tmp_tp_z0_prod);
tp->d0_prod->push_back(tmp_tp_d0_prod);
tp->pdgid->push_back(tmp_tp_pdgid);
tp->eventid->push_back(tmp_eventid);
tp->charge->push_back(tmp_tp_charge);
const SimTrack& t(tp_ptr->g4Tracks()[0]);
if(abs(t.type())==13){
if (DebugMode) cout << "Finished " << tp_index << " TP information and started matcher as this TP is a muon" <<endl;
const SimVertex v = (t.vertIndex() < int(sim_vert.size())) ? sim_vert[t.vertIndex()] : SimVertex();
match->match(t, v);
std::shared_ptr<CSCSimHitMatcher> cscsimhits = match->cscSimHits();
std::shared_ptr<GEMSimHitMatcher> gemsimhits = match->gemSimHits();
const auto& cscIds = cscsimhits->detIds();
for (const auto& p1 : cscIds) {
CSCDetId id1(p1);
const auto& hits = cscsimhits->hitsInDetId(p1);
for (auto& hit : hits) {
PSimHitContainer hitc;
hitc.push_back(hit);
GlobalPoint gp = cscsimhits->simHitsMeanPosition(hitc);
cscSimHit->FillGP(gp);
cscSimHit->FillSimHit(id1, tp_index);
}
}
// for (int istation = 1; istation < 5; ++istation) {
// const auto& cscIds = cscsimhits->chamberIdsStation(istation);
// for (const auto& p1 : cscIds) {
// const auto& hits = cscsimhits->hitsInChamber(p1);
// for (auto& hit : hits) {
// PSimHitContainer hitc;
// hitc.push_back(hit);
// GlobalPoint gp = cscsimhits->simHitsMeanPosition(hitc);
// cscSimHit->FillGP(gp);
// cscSimHit->FillSimHit(istation, tp_index);
// }
// }
// }
if (DebugMode) cout << "cscSimHits Finished, starting gemSimHits" << endl;
const auto& gemIds = gemsimhits->detIds();
for (const auto&p1 :gemIds) {
GEMDetId id1(p1);
const auto& hits = gemsimhits->hitsInDetId(p1);
for (auto& hit : hits) {
PSimHitContainer hitc;
hitc.push_back(hit);
GlobalPoint gp = gemsimhits->simHitsMeanPosition(hitc);
gemSimHit->FillGP(gp);
gemSimHit->FillSimHit(id1, tp_index);
}
}
if (DebugMode) cout << "gemSimhits Finished, starting muonCandidate" <<endl;
auto muonCandidate = match->l1Muons()->emtfCand();
if(muonCandidate){
//std::cout<<"found match, extract information"<<std::endl;
m_matchmuon_pt->push_back(muonCandidate->pt());
m_matchmuon_eta->push_back(muonCandidate->eta());
m_matchmuon_phi->push_back(muonCandidate->phi());
m_matchmuon_charge->push_back(muonCandidate->charge());
m_matchmuon_quality->push_back(muonCandidate->quality());
int type=-1;
m_matchmuon_type->push_back(type);
}
else{
m_matchmuon_pt->push_back(-999.);
m_matchmuon_eta->push_back(-999.);
m_matchmuon_phi->push_back(-999.);
m_matchmuon_charge->push_back(-999);
m_matchmuon_type->push_back(-999);
m_matchmuon_quality->push_back(-999);
}
//CSCStubMatcher
auto cscStubs = match->cscStubs();
if (DebugMode) cout << "Started Loop over matchCscStubsA/CLCT (match->cscStubs()) " << endl;
int digicount = 0;
for (int detid_int : cscStubs->chamberIdsLCT(0)) {
CSCDetId detid_(detid_int);
int digi_index = 0;
bool doprinta = Print_matchCscStubs && Print_ALCT;
bool doprintc = Print_matchCscStubs && Print_CLCT;
for (auto digi_ : cscStubs->lctsInChamber(detid_) ){
if (DebugMode) cout << "" << endl;
auto gp = cscStubs->getGlobalPosition(detid_int,digi_);
// bool brokenlct = false;
// if ((detid_.station() == 1 && detid.ring() == 4 && digi_.getStrip() < 128) || (detid_.station() == 1 && detid.ring() == 1 && digi_.getStrip() >127)) brokenlct = true;
// if (brokenlct) {
// CSCDetId det2(detid_.zendcap(), detid_.station(), 5 - detid_.ring(), detid_.chamber(), detid_.layer());
// auto gp2 = cscStubs->getGlobalPosition(det2.rawId(), digi_);
// }
matchCscStubsLCT->FillGP(gp);
matchCscStubsLCT->FillLCT(digi_,detid_,tp_index);
if (Print_matchCscStubs) cout << "detid_int = " <<detid_int<<", detid = " << int(detid_) << ", rawId = " << detid_.rawId() << endl;
if (detid_int != (int)detid_.rawId()) cout << "Inconsistent raw ID and original int detid" <<endl;
// matchCscStubsALCT
const auto& alctDigi = digi_.getALCT();
std::vector< std::vector<unsigned short> > alcthits = alctDigi.getHits();
if (doprinta) cout << "For matchCscStubsALCTs; DetId: "<< detid_.rawId() <<", Digi Index: " << digi_index << ", keywire: "<< alctDigi.getKeyWG()<<" , lctDigiWire = "<<digi_.getKeyWG()<<endl;
if (alctDigi.getKeyWG() != digi_.getKeyWG() && digi_.getType() != 5 && digi_.getType() !=6 ) cout << "Inconsistent keywire in matchCscStubsLCT:" << " lctDigiWire = "<<digi_.getKeyWG() << " alctDigiWire = "<< alctDigi.getKeyWG()<< " lct type = " << digi_.getType() <<endl;
int alctmultihit = SaveHitMatrix(alcthits, matchCscStubsALCT->hit, matchCscStubsALCT->position,doprinta,false);
if (doprinta && alctmultihit) cout << "ALCT Multihit found for matchCscStubsALCT" << endl;
matchCscStubsALCT->FillALCT(alctDigi,detid_);
// matchCscStubsCLCT
const auto& clctDigi = digi_.getCLCT();
std::vector< std::vector<unsigned short> > clcthits = clctDigi.getHits();
if (doprintc) cout << "For matchCscStubsCLCTs; DetId: "<< detid_.rawId() <<", Digi Index: " << digi_index << ", strip: "<< clctDigi.getStrip() <<" , lctDigiStrip = "<< digi_.getStrip()<<endl;
// if (clctDigi.getStrip() != digi_.getStrip()) cout << "Inconsistent strip: clctDigiStrip = "<< clctDigi.getStrip() <<" , lctDigiStrip = "<< digi_.getStrip() <<endl;
if (clctDigi.getSlope() != digi_.getSlope()) cout << "Inconsistent Slope in matchCscStubsLCT: clctDigiSlope = "<< clctDigi.getSlope() <<" , lctDigiSlope = "<< digi_.getSlope() <<endl;
int clctmultihit = SaveHitMatrix(clcthits, matchCscStubsCLCT->hit, matchCscStubsCLCT->position,doprintc,true);
if (doprintc && clctmultihit) cout << "CLCT Multihit found for matchCscStubsCLCT" << endl;
matchCscStubsCLCT->FillCLCT(clctDigi,detid_);
// GEMPad for matchCscStubs
if (DebugMode) cout << " Finishing a matchCscStub, starting matchedCscStub GEMPads" <<endl;
if (detid_.ring() == 1 and (detid_.station() == 1 or detid_.station() == 2)) {
bool matchl1(false), matchl2(false), printgem(false);
GEMDetId PadGemDetId(detid_.zendcap(), 1, detid_.station(), 1, detid_.chamber(), 0);
if (digi_.getGEM1().pad() != 255 || digi_.getGEM2().pad() != 255 || digi_.getGEM1().nPartitions() != 8 || digi_.getGEM2().nPartitions() != 8) {
if (DebugMode) {
printgem = true;
cout << "In station " << detid_.station() << " , ring " << detid_.ring() << " , eta = " << gp.eta() << " , matchCscStubsLCT rawId: " <<detid_.rawId() << endl;
}
}
for (auto id : match->gemDigis()->detIdsPad()) { // std::set<unsigned int>
GEMDetId id_ = GEMDetId(id);
if (id_.rawId() != id) cout << "Inconsistence in GEMDetId Convertion" <<endl;
if (id_.region() != detid_.zendcap() || id_.ring() != 1 || id_.station() != detid_.station() || id_.chamber() != detid_.chamber()) continue;
for (const auto& p : match->gemDigis()->padsInDetId(id)) {
if (id_.layer() == 1 && p == digi_.getGEM1() && matchl1 == false) {
auto gp = match->gemDigis()->getGlobalPointPad(id_, p);
matchCscGEM1->FillGP(gp);
matchCscGEM1->FillGEMPad(p,id_,digicount);
matchl1 = true;
PadGemDetId = id_;
}
if (id_.layer() == 2 && p == digi_.getGEM2() && matchl2 == false) {
auto gp = match->gemDigis()->getGlobalPointPad(id_, p);
matchCscGEM1->FillGP(gp);
matchCscGEM2->FillGEMPad(p,id_,digicount);
matchl2 = true;
PadGemDetId = id_;
}
}
}
matchCscStubsLCT->FillLCTGEMPads(digi_, PadGemDetId, "");
if (!matchl1) {
matchCscGEM1->FillGP0();
GEMDetId PadGemDetId1(detid_.zendcap(), 1, detid_.station(), 1, detid_.chamber(), 0);
matchCscGEM1->FillGEMPad0(PadGemDetId1,digicount);
}
if (!matchl2) {
matchCscGEM2->FillGP0();
GEMDetId PadGemDetId2(detid_.zendcap(), 1, detid_.station(), 2, detid_.chamber(), 0);
matchCscGEM2->FillGEMPad0(PadGemDetId2,digicount);
}
if (printgem) {
cout << "MatchCSCStubs GEM1 pad = " << digi_.getGEM1().pad() << ", part = " << digi_.getGEM1().nPartitions() << (digi_.getGEM1().isValid()? ", Valid " : ", Invalid ") << (matchl1 ? ", Filled" : ", Not Filled") << endl;
cout << "MatchCSCStubs GEM2 pad = " << digi_.getGEM2().pad() << ", part = " << digi_.getGEM2().nPartitions() << (digi_.getGEM2().isValid()? ", Valid " : ", Invalid ") << (matchl2 ? ", Filled" : ", Not Filled") << endl;
}
}
else {
matchCscStubsLCT->FillLCTGEMPads0(digi_);
}
digicount++;
}
}
if (DebugMode) cout << "Finished Loop over matchCscStubsA/CLCT (match->cscStubs()) " << endl;
auto gemDigis_ = match->gemDigis();
const auto& detidsDigi = gemDigis_->detIdsDigi();
// if (detidsDigi.size() == 0) cout << "!!!! detidsDigi is empty" <<endl;
// else cout << "~~~~ detidsDigi is not empty" <<endl;
for (const auto& id : detidsDigi) {
// if (gemDigis_->digisInDetId(id).size() == 0) cout << "!!!! digisInDetId is empty while there are " << detidsDigi.size() << " detIds"<< endl;
for (auto gemdigi : gemDigis_->digisInDetId(id) ){
if (DebugMode) cout << "Starting processing a matchgemdigi" <<endl;
auto gp = gemDigis_->getGlobalPointDigi(id, gemdigi);
matchGemDigi->FillGP(gp);
if (DebugMode) cout << "gp filled" <<endl;
matchGemDigi->FillGEM(gemdigi,GEMDetId(id),tp_index);
if (DebugMode) cout << "gem saved" <<endl;
}
}
if (DebugMode) cout << "Finished Loop over matchGemDigi (match->gemDigis()) " << endl;
// matchGemPadDigi
const auto& detIdsPad = gemDigis_->detIdsPad();
for (const auto& id : detIdsPad) {
GEMDetId gemid(id);
for (auto pad : gemDigis_->padsInDetId(id)) {
auto gp = gemDigis_->getGlobalPointPad(id, pad);
matchGemPadDigi->FillGP(gp);
matchGemPadDigi->FillGEMPad(pad, GEMDetId(id), tp_index);
}
}
if (DebugMode) cout << "Finished Loop over matchGemPadDigi" <<endl;
// matchGemPadDigiCluster
const auto& detIdsCluster = gemDigis_->detIdsCluster();
for (const auto& id : detIdsCluster) {
for (auto cl : gemDigis_->clustersInDetId(id)) {
GEMPadDigi mid = GEMPadDigi(cl.pads()[cl.pads().size() / 2], cl.bx(), cl.station(), cl.nPartitions());
auto gp = gemDigis_->getGlobalPointPad(id, mid);
matchGemPadDigiCluster->FillGP(gp);
matchGemPadDigiCluster->FillGEMPadDigiCluster(cl, GEMDetId(id), tp_index);
}
}
if (DebugMode) cout << "Finished Loop over matchGemPadDigiCluster" <<endl;
} // End of Muon Loop
else{
m_matchmuon_pt->push_back(-999.);
m_matchmuon_eta->push_back(-999.);
m_matchmuon_phi->push_back(-999.);
m_matchmuon_charge->push_back(-999);
m_matchmuon_type->push_back(-999);
m_matchmuon_quality->push_back(-999);
}
tp_index++;
} // End of Tracking Particle Loop
if (DebugMode) cout << "Finished TP Iteration" << endl<< endl;
// Handle< BXVector<l1t::RegionalMuonCand> > emtfs;
// Handle< BXVector<l1t::RegionalMuonCand> > omtfs;
// Handle< BXVector<l1t::RegionalMuonCand> > bmtfs;
// iEvent.getByToken(m_emtfToken,emtfs);
// iEvent.getByToken(m_omtfToken,omtfs);
// iEvent.getByToken(m_bmtfToken,bmtfs);
// int nEMTF=0;
// for (auto it = emtfs->begin(0); it != emtfs->end(0); it++){
// m_EMTF_muon_eta->push_back(it->hwEta()*0.010875);
// int globPhi=l1t::MicroGMTConfiguration::calcGlobalPhi(it->hwPhi(), it->trackFinderType(), it->processor());
// m_EMTF_muon_phi->push_back(globPhi*2*M_PI/576.);
// m_EMTF_muon_pt->push_back(it->hwPt()*0.5);
// if(!it->hwSignValid()) m_EMTF_muon_c->push_back(0);
// else{
// if(it->hwSign()) m_EMTF_muon_c->push_back(-1);
// else m_EMTF_muon_c->push_back(1);
// }
// ++nEMTF;
// }
// m_EMTF_muon_n->push_back(nEMTF);
// int nOMTF=0;
// for (auto it = omtfs->begin(0); it != omtfs->end(0); it++){
// m_OMTF_muon_eta->push_back(it->hwEta()*0.010875);
// m_OMTF_muon_phi->push_back(l1t::MicroGMTConfiguration::calcGlobalPhi(it->hwPhi(), it->trackFinderType(), it->processor())*2*M_PI/576.);
// m_OMTF_muon_pt->push_back(it->hwPt()*0.5);
// if(!it->hwSignValid()) m_OMTF_muon_c->push_back(0);
// else{
// if(it->hwSign()) m_OMTF_muon_c->push_back(-1);
// else m_OMTF_muon_c->push_back(1);
// }
// ++nOMTF;
// }
// m_OMTF_muon_n->push_back(nOMTF);
//
// int nBMTF=0;
// for (auto it = bmtfs->begin(0); it != bmtfs->end(0); it++){
// m_BMTF_muon_eta->push_back(it->hwEta()*0.010875);
// m_BMTF_muon_phi->push_back(l1t::MicroGMTConfiguration::calcGlobalPhi(it->hwPhi(), it->trackFinderType(), it->processor())*2*M_PI/576.);
// m_BMTF_muon_pt->push_back(it->hwPt()*0.5);
// if(!it->hwSignValid()) m_BMTF_muon_c->push_back(0);
// else{
// if(it->hwSign()) m_BMTF_muon_c->push_back(-1);
// else m_BMTF_muon_c->push_back(1);
// }
// ++nBMTF;
// }
// m_BMTF_muon_n->push_back(nBMTF);
if (DebugMode) cout << "Finished regional Muons started allCscStubs (CSCCorrelatedLCTDigiCollection)" << endl;
edm::Handle<CSCCorrelatedLCTDigiCollection> lctsH_;
iEvent.getByToken(lctToken_, lctsH_);
const CSCCorrelatedLCTDigiCollection& lcts = *lctsH_.product();
int allCscStubs_index = 0;
int digicount = 0;
for (auto it = lcts.begin(); it != lcts.end(); ++it) {
const auto& digivec = (*it).second;
const CSCDetId& detid_ = (*it).first;
int digi_index = 0;
bool doprinta = Print_allCscStubs && Print_ALCT;
bool doprintc = Print_allCscStubs && Print_CLCT;
for (auto itdigi = digivec.first; itdigi != digivec.second; ++itdigi) {
if (DebugMode) cout << " Started "<< digi_index << "th Digi for "<< allCscStubs_index << "th allCscStubsLCTs" <<endl;
int ring = detid_.ring();
// if (detid_.station() == 1 && detid_.ring() == 1 && itdigi->getStrip() >= 128) ring = 4;
CSCDetId detid(detid_.endcap(), detid_.station(), ring, detid_.chamber(), detid_.layer());
auto gp = match->cscStubs()->getGlobalPosition(detid.rawId(), *itdigi);
allCscStubsLCT->FillGP(gp);
allCscStubsLCT->FillLCT(*itdigi,detid);
// allCscStubsALCTs
if (DebugMode) cout << " Started allCSCStubsALCT"<< endl;
const auto& alctDigi = (*itdigi).getALCT();
std::vector< std::vector<unsigned short> > alcthits = alctDigi.getHits();
if (doprinta) cout << "For allCscStubsALCTs; DetId: "<< detid.rawId() <<", Digi Index: " << digi_index << ", keywire: "<< alctDigi.getKeyWG()<<" , lctDigiWire = "<<(*itdigi).getKeyWG() << endl;
if (alctDigi.getKeyWG() != (*itdigi).getKeyWG() && (*itdigi).getType() != 5 && (*itdigi).getType() !=6 ) cout << "Inconsistence keywire in allCscStubsLCT:" << " lctDigiWire = "<<(*itdigi).getKeyWG() << " alctDigiWire = " << alctDigi.getKeyWG() << " lct type = " << (*itdigi).getType() <<endl;
int alctmultihit = SaveHitMatrix(alcthits, allCscStubsALCT->hit, allCscStubsALCT->position,doprinta,false);
if (doprinta && alctmultihit) cout << "ALCT Multihit found for allCscStubsALCT" << endl;
allCscStubsALCT->FillALCT(alctDigi,detid);
// allCscStubsCLCTs
if (DebugMode) cout << " Started allCSCStubsCLCT"<< endl;
const auto& clctDigi = (*itdigi).getCLCT();
std::vector< std::vector<unsigned short> > clcthits = clctDigi.getHits();
if (doprintc) cout << "For allCscStubsCLCTs; DetId: "<< detid.rawId() <<", Digi Index:" << digi_index << ", strip: "<< clctDigi.getStrip() <<" , lctDigiStrip = "<< (*itdigi).getStrip()<<endl;
// if (clctDigi.getStrip() != (*itdigi).getStrip()) cout << "Inconsistence strip: clctDigiStrip = "<< clctDigi.getStrip() <<" , lctDigiStrip = "<< (*itdigi).getStrip() <<endl;
if (clctDigi.getSlope() != (*itdigi).getSlope()) cout << "Inconsistence slope in allCscStubsLCT: clctDigiSlope = "<< clctDigi.getSlope() <<" , lctDigiSlope = "<< (*itdigi).getSlope() <<endl;
int clctmultihit = SaveHitMatrix(clcthits, allCscStubsCLCT->hit, allCscStubsCLCT->position,doprintc,true);
if (doprintc && clctmultihit) cout << "CLCT Multihit found for allCscStubsCLCT" << endl;
allCscStubsCLCT->FillCLCT(clctDigi,detid);
// GEMPad for allCscStubs
if (DebugMode) cout << " Finishing a allCscStub, starting allCscStub GEMPads" <<endl;
if (detid.ring() == 1 and (detid.station() == 1 or detid.station() == 2)) {
bool matchl1(false), matchl2(false), printgem(false);
GEMDetId PadGemDetId(detid.zendcap(), 1, detid.station(), 1, detid.chamber(), 0);
if ((*itdigi).getGEM1().pad() != 255 || (*itdigi).getGEM2().pad() != 255 || (*itdigi).getGEM1().nPartitions() != 8 || (*itdigi).getGEM2().nPartitions() != 8) {
if (DebugMode) {
printgem = true;
cout << "In station " << detid.station() << " , ring " << detid.ring() << " , eta = " << gp.eta() << " , allCscStubsLCT rawId: " << detid.rawId() << endl;
}
}
for (auto id : match->gemDigis()->detIdsPad()) { //std::set<unsigned int>
GEMDetId id_ = GEMDetId(id);
if (id_.rawId() != id) cout << "Inconsistence in GEMDetId Convertion" <<endl;
if (id_.region() != detid.zendcap() || id_.ring() != 1 || id_.station() != detid.station() || id_.chamber() != detid.chamber()) continue;
for (const auto& p : match->gemDigis()->padsInDetId(id)) {
if (id_.layer() == 1 && p == (*itdigi).getGEM1() && matchl1 == false) {
auto gp = match->gemDigis()->getGlobalPointPad(id_, p);
allCscGEM1->FillGP(gp);
allCscGEM1->FillGEMPad(p,id_,digicount);
matchl1 = true;
PadGemDetId = id_;
}
if (id_.layer() == 2 && p == (*itdigi).getGEM2() && matchl2 == false) {
auto gp = match->gemDigis()->getGlobalPointPad(id_, p);
allCscGEM2->FillGP(gp);
allCscGEM2->FillGEMPad(p,id_,digicount);
matchl2 = true;
PadGemDetId = id_;
}
}
}
allCscStubsLCT->FillLCTGEMPads((*itdigi), PadGemDetId, "");
if (!matchl1) {
allCscGEM1->FillGP0();
GEMDetId PadGemDetId1(detid.zendcap(), 1, detid.station(), 1, detid.chamber(), 0);
allCscGEM1->FillGEMPad0(PadGemDetId1,digicount);
}
if (!matchl2) {
allCscGEM2->FillGP0();
GEMDetId PadGemDetId2(detid.zendcap(), 1, detid.station(), 2, detid.chamber(), 0);
allCscGEM2->FillGEMPad0(PadGemDetId2,digicount);
}
if (printgem) {
cout << "AllCSCStubs GEM1 pad = " << (*itdigi).getGEM1().pad() << " , part = " << (*itdigi).getGEM1().nPartitions() << ((*itdigi).getGEM1().isValid()? ", Valid " : ", Invalid ") << (matchl1 ? ", Filled " : ", Not Filled") <<endl;
cout << "AllCSCStubs GEM2 pad = " << (*itdigi).getGEM2().pad() << " , part = " << (*itdigi).getGEM2().nPartitions() << ((*itdigi).getGEM2().isValid()? ", Valid " : ", Invalid ") << (matchl2 ? ", Filled " : ", Not Filled") <<endl;
}
}
else {
allCscStubsLCT->FillLCTGEMPads0(*itdigi);
}
digi_index++;
digicount++;
}
allCscStubs_index++;
}
if (DebugMode) cout <<endl<< "Finished allCscStubs, started allALCT (CSCALCTDigiCollection)" << endl;
bool multihit = false;
int digi_index = 0;
// allALCTs
edm::Handle<CSCALCTDigiCollection> alctsH_;
iEvent.getByToken(alctToken_, alctsH_);
const CSCALCTDigiCollection& alcts = *alctsH_.product();
for (auto it = alcts.begin(); it != alcts.end(); ++it) {
const auto& digivec = (*it).second;
const auto& detid = (*it).first;
for (auto itdigi = digivec.first; itdigi != digivec.second; ++itdigi) {
std::vector< std::vector<unsigned short> > alcthits = ((*itdigi).getHits());
if (Print_all && Print_ALCT) cout << "For allALCTs; DetId: "<< detid.rawId() <<", Digi Index:" << digi_index << ", keywire: "<< (*itdigi).getKeyWG()<< endl;
int alctmultihit = SaveHitMatrix(alcthits, allALCT->hit, allALCT->position,Print_all&&Print_ALCT,false);
if (alctmultihit) multihit = true;
if (Print_all && Print_ALCT && alctmultihit) cout << "ALCT Multihit found for allALCT" << endl;
allALCT->FillALCT(*itdigi,detid);
++digi_index;
}
}
if (DebugMode) cout << "Finished allALCT, started allCLCT" << endl;
// allCLCTs
digi_index = 0;
edm::Handle<CSCCLCTDigiCollection> clctsH_;
iEvent.getByToken(clctToken_, clctsH_);
const CSCCLCTDigiCollection& clcts = *clctsH_.product();
for (auto it = clcts.begin(); it != clcts.end(); ++it) {
const auto& digivec = (*it).second;
const auto& detid = (*it).first;
for (auto itdigi = digivec.first; itdigi != digivec.second; ++itdigi) {
std::vector< std::vector<unsigned short> > clcthits = ((*itdigi).getHits());
if (Print_all && Print_CLCT) cout << "For allCLCTs; DetId: "<< detid.rawId() <<", Digi Index:" << digi_index<< ", strip: "<< (*itdigi).getStrip() << endl;
int clctmultihit = SaveHitMatrix(clcthits, allCLCT->hit, allCLCT->position,Print_all&&Print_CLCT,true);
if (clctmultihit) multihit = true;
if (Print_all && Print_CLCT && clctmultihit) cout << "CLCT Multihit found for allCLCT" << endl;
allCLCT->FillCLCT(*itdigi,detid);
++digi_index;
}
}
if (multihit) nEventMultiHitLayer++;
// if (floor(double(m_allCLCT_hit->size()) / 6.0 ) != m_allCLCT_detId->size()) {
// throw std::runtime_error("Hit size mismatch Digi size");
// }
// 0 for allA/CLCT, 1 for allCscStubsA/CLCT, 2 for matchCscStubsA/CLCT
if (Print_all) PrintHits(0);
if (Print_allCscStubs) PrintHits(1);
if (Print_matchCscStubs) PrintHits(2);
if (DebugMode) cout << "Finished allCLCT, started GEMDigis" << endl;
// All GEMDigis
edm::Handle<GEMDigiCollection> gemDigisH_;
iEvent.getByToken(gemDigiToken_,gemDigisH_);
const GEMDigiCollection& gems = *gemDigisH_.product();
for (auto it = gems.begin(); it != gems.end(); ++it) {
const auto& digivec = (*it).second;
const GEMDetId& detid = (*it).first;
for (auto itdigi = digivec.first; itdigi != digivec.second; ++itdigi) {
auto gp = match->gemDigis()->getGlobalPointDigi(detid, *itdigi);
allGemDigi->FillGP(gp);
allGemDigi->FillGEM(*itdigi,detid);
}
}
if (DebugMode) cout << "Finished GEMDigis, started GEMPadDigi" << endl;
// GEMPadDigi
edm::Handle<GEMPadDigiCollection> gemPadDigisH_;
iEvent.getByToken(gemPadDigiToken_, gemPadDigisH_);