CMS 3D CMS Logo

L1RCTTestAnalyzer.cc
Go to the documentation of this file.
1 // system include files
2 #include <memory>
3 
4 // user include files
7 
10 
12 
14 
16 
18 
19 using std::cout;
20 using std::endl;
21 using std::string;
22 
23 //
24 // constructors and destructor
25 //
27  : showEmCands(iConfig.getUntrackedParameter<bool>("showEmCands")),
28  showRegionSums(iConfig.getUntrackedParameter<bool>("showRegionSums")),
29  ecalDigisLabel(iConfig.getParameter<edm::InputTag>("ecalDigisLabel")),
30  hcalDigisLabel(iConfig.getParameter<edm::InputTag>("hcalDigisLabel")),
31  rctDigisLabel(iConfig.getParameter<edm::InputTag>("rctDigisLabel")) {
32  // now do what ever initialization is needed
33 
34  usesResource(TFileService::kSharedResource);
36 
37  emTree = fs->make<TTree>("emTree", "L1 RCT EM tree");
38  // emTree->Branch("emRank",emRank,"emRank/I");
39  // emTree->Branch("emIeta",emIeta,"emIeta/I");
40  // emTree->Branch("emIphi",emIphi,"emIphi/I");
41  // emTree->Branch("emIso" ,emIso ,"emIso/I");
42  emTree->Branch("emRank", &emRank);
43  emTree->Branch("emIeta", &emIeta);
44  emTree->Branch("emIphi", &emIphi);
45  emTree->Branch("emIso", &emIso);
46 
47  h_emRank = fs->make<TH1F>("emRank", "emRank", 64, 0., 64.);
48  h_emRankOutOfTime = fs->make<TH1F>("emRankOutOfTime", "emRankOutOfTime", 64, 0., 64.);
49  h_emIeta = fs->make<TH1F>("emIeta", "emIeta", 22, 0., 22.);
50  h_emIphi = fs->make<TH1F>("emIphi", "emIphi", 18, 0., 18.);
51  h_emIso = fs->make<TH1F>("emIso", "emIso", 2, 0., 2.);
52  h_emRankInIetaIphi = fs->make<TH2F>("emRank2D", "emRank2D", 22, 0., 22., 18, 0., 18.);
53  h_emIsoInIetaIphi = fs->make<TH2F>("emIso2D", "emIso2D", 22, 0., 22., 18, 0., 18.);
54  h_emNonIsoInIetaIphi = fs->make<TH2F>("emNonIso2D", "emNonIso2D", 22, 0., 22., 18, 0., 18.);
55  h_emCandTimeSample = fs->make<TH1F>("emCandTimeSample", "emCandTimeSample", 5, -2., 2.);
56 
57  h_regionSum = fs->make<TH1F>("regionSum", "regionSum", 100, 0., 100.);
58  h_regionIeta = fs->make<TH1F>("regionIeta", "regionIeta", 22, 0., 22.);
59  h_regionIphi = fs->make<TH1F>("regionIphi", "regionIphi", 18, 0., 18.);
60  h_regionMip = fs->make<TH1F>("regionMip", "regionMipBit", 2, 0., 2.);
61  h_regionSumInIetaIphi = fs->make<TH2F>("regionSum2D", "regionSum2D", 22, 0., 22., 18, 0., 18.);
62  h_regionFGInIetaIphi = fs->make<TH2F>("regionFG2D", "regionFG2D", 22, 0., 22., 18, 0., 18.);
63 
64  h_towerMip = fs->make<TH1F>("towerMip", "towerMipBit", 2, 0., 2.);
65 
66  h_ecalTimeSample = fs->make<TH1F>("ecalTimeSample", "ecalTimeSample", 10, 0., 10.);
67  h_hcalTimeSample = fs->make<TH1F>("hcalTimeSample", "hcalTimeSample", 10, 0., 10.);
68 
69  // get names of modules, producing object collections
70 }
71 
73  // do anything here that needs to be done at destruction time
74  // (e.g. close files, deallocate resources etc.)
75 }
76 
77 //
78 // member functions
79 //
80 
81 // ------------ method called to produce the data ------------
83  using namespace edm;
84 #ifdef THIS_IS_AN_EVENT_EXAMPLE
86  iEvent.getByLabel("example", pIn);
87 #endif
88 
89 #ifdef THIS_IS_AN_EVENTSETUP_EXAMPLE
90  ESHandle<SetupData> pSetup;
91  iSetup.get<SetupRecord>().get(pSetup);
92 #endif
93 
94  // as in L1GctTestAnalyzer.cc
95  Handle<L1CaloEmCollection> rctEmCands;
99 
100  L1CaloEmCollection::const_iterator em;
101  L1CaloRegionCollection::const_iterator rgn;
104 
105  iEvent.getByLabel(rctDigisLabel, rctEmCands);
106  iEvent.getByLabel(rctDigisLabel, rctRegions);
107  iEvent.getByLabel(ecalDigisLabel, ecalColl);
108  iEvent.getByLabel(hcalDigisLabel, hcalColl);
109 
110  // for sorting later
111  L1CaloEmCollection *myL1EmColl = new L1CaloEmCollection;
112 
113  for (ecal = ecalColl->begin(); ecal != ecalColl->end(); ecal++) {
114  for (unsigned short sample = 0; sample < (*ecal).size(); sample++) {
115  h_ecalTimeSample->Fill(sample);
116  }
117  }
118 
119  for (hcal = hcalColl->begin(); hcal != hcalColl->end(); hcal++) {
120  h_towerMip->Fill((*hcal).SOI_fineGrain());
121  for (unsigned short sample = 0; sample < (*hcal).size(); sample++) {
122  h_hcalTimeSample->Fill(sample);
123  }
124  }
125 
126  if (showEmCands) {
127  // std::cout << std::endl << "L1 RCT EmCand objects" << std::endl;
128  }
129  for (em = rctEmCands->begin(); em != rctEmCands->end(); em++) {
130  // std::cout << "(Analyzer)\n" << (*em) << std::endl;
131 
132  L1CaloEmCand *myL1EmCand = new L1CaloEmCand(*em);
133  (*myL1EmColl).push_back(*myL1EmCand);
134  delete myL1EmCand;
135 
136  h_emCandTimeSample->Fill((*em).bx());
137  if ((*em).bx() == 0) {
138  // std::cout << std::endl << "rank: " << (*em).rank() ;
139 
140  if ((*em).rank() > 0) {
141  h_emRank->Fill((*em).rank());
142  h_emIeta->Fill((*em).regionId().ieta());
143  h_emIphi->Fill((*em).regionId().iphi());
144  h_emIso->Fill((*em).isolated());
145  h_emRankInIetaIphi->Fill((*em).regionId().ieta(), (*em).regionId().iphi(), (*em).rank());
146  if ((*em).isolated()) {
147  h_emIsoInIetaIphi->Fill((*em).regionId().ieta(), (*em).regionId().iphi());
148  } else {
149  h_emNonIsoInIetaIphi->Fill((*em).regionId().ieta(), (*em).regionId().iphi());
150  }
151  }
152 
153  if (showEmCands) {
154  if ((*em).rank() > 0) {
155  // std::cout << std::endl << "rank: " << (*em).rank();
156  unsigned short rgnPhi = 999;
157  unsigned short rgn = (unsigned short)(*em).rctRegion();
158  unsigned short card = (unsigned short)(*em).rctCard();
159  unsigned short crate = (unsigned short)(*em).rctCrate();
160 
161  if (card == 6) {
162  rgnPhi = rgn;
163  } else if (card < 6) {
164  rgnPhi = (card % 2);
165  } else {
166  std::cout << "rgnPhi not assigned (still " << rgnPhi << ") -- Weird card number! " << card;
167  }
168 
169  // unsigned short phi_bin = ((crate % 9) * 2) + rgnPhi;
170  short eta_bin = (card / 2) * 2 + 1;
171  if (card < 6) {
172  eta_bin = eta_bin + rgn;
173  }
174  if (crate < 9) {
175  eta_bin = -eta_bin;
176  }
177 
178  // std::cout << /* "rank: " << (*em).rank() << */ "
179  // eta_bin: " << eta_bin << " phi_bin: " << phi_bin << ". crate: "
180  // << crate << " card: " << card << " region: " << rgn << ".
181  // isolated: " << (*em).isolated();
182  }
183  }
184  } else {
185  h_emRankOutOfTime->Fill((*em).rank());
186  }
187  }
188  if (showEmCands) {
189  // std::cout << std::endl;
190  }
191 
192  // next: SORT THESE GUYS so they're entered into the tree highest first
193  // std::sort(rctEmCands->begin(),rctEmCands->end(),compareEmCands);
194  // for (em=rctEmCands->begin(); em!=rctEmCands->end(); em++)
195  std::sort(myL1EmColl->begin(), myL1EmColl->end(), compareEmCands);
196  std::reverse(myL1EmColl->begin(), myL1EmColl->end()); // whoops!
197  for (em = myL1EmColl->begin(); em != myL1EmColl->end(); em++) {
198  emRank.push_back((*em).rank());
199  emIeta.push_back((*em).regionId().ieta());
200  emIphi.push_back((*em).regionId().iphi());
201  emIso.push_back((*em).isolated());
202  }
203  emTree->Fill();
204 
205  if (showRegionSums) {
206  std::cout << "Regions" << std::endl;
207  }
208  for (rgn = rctRegions->begin(); rgn != rctRegions->end(); rgn++) {
209  if ((*rgn).bx() == 0) {
210  if (showRegionSums && (*rgn).et() > 0) {
211  std::cout << /* "(Analyzer)\n" << */ (*rgn) << std::endl;
212  }
213  if ((*rgn).et() > 0) {
214  h_regionSum->Fill((*rgn).et());
215  h_regionIeta->Fill((*rgn).gctEta());
216  h_regionIphi->Fill((*rgn).gctPhi());
217  h_regionSumInIetaIphi->Fill((*rgn).gctEta(), (*rgn).gctPhi(), (*rgn).et());
218  h_regionFGInIetaIphi->Fill((*rgn).gctEta(), (*rgn).gctPhi(), (*rgn).fineGrain());
219  }
220  h_regionMip->Fill((*rgn).mip());
221  }
222  }
223  if (showRegionSums) {
224  std::cout << std::endl;
225  }
226 
227  emRank.clear();
228  emIeta.clear();
229  emIphi.clear();
230  emIso.clear();
231 
232  delete myL1EmColl;
233 }
234 
236  return (cand1.rank() < cand2.rank());
237 }
static const std::string kSharedResource
Definition: TFileService.h:76
void analyze(const edm::Event &, const edm::EventSetup &) override
std::vector< int > emIeta
std::vector< L1CaloEmCand > L1CaloEmCollection
static bool compareEmCands(const L1CaloEmCand &cand1, const L1CaloEmCand &cand2)
std::vector< T >::const_iterator const_iterator
Level-1 Region Calorimeter Trigger EM candidate.
Definition: L1CaloEmCand.h:17
~L1RCTTestAnalyzer() override
int iEvent
Definition: GenABIO.cc:224
std::vector< int > emRank
T get() const
Definition: EventSetup.h:79
edm::InputTag rctDigisLabel
const_iterator begin() const
L1RCTTestAnalyzer(const edm::ParameterSet &)
edm::InputTag hcalDigisLabel
const_iterator end() const
unsigned rank() const
get rank bits
Definition: L1CaloEmCand.h:42
edm::InputTag ecalDigisLabel
HLT enums.
std::vector< int > emIso
std::vector< int > emIphi