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 
35 
36  emTree = fs->make<TTree>("emTree", "L1 RCT EM tree");
37  // emTree->Branch("emRank",emRank,"emRank/I");
38  // emTree->Branch("emIeta",emIeta,"emIeta/I");
39  // emTree->Branch("emIphi",emIphi,"emIphi/I");
40  // emTree->Branch("emIso" ,emIso ,"emIso/I");
41  emTree->Branch("emRank", &emRank);
42  emTree->Branch("emIeta", &emIeta);
43  emTree->Branch("emIphi", &emIphi);
44  emTree->Branch("emIso", &emIso);
45 
46  h_emRank = fs->make<TH1F>("emRank", "emRank", 64, 0., 64.);
48  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.);
53  fs->make<TH2F>("emRank2D", "emRank2D", 22, 0., 22., 18, 0., 18.);
55  fs->make<TH2F>("emIso2D", "emIso2D", 22, 0., 22., 18, 0., 18.);
57  fs->make<TH2F>("emNonIso2D", "emNonIso2D", 22, 0., 22., 18, 0., 18.);
59  fs->make<TH1F>("emCandTimeSample", "emCandTimeSample", 5, -2., 2.);
60 
61  h_regionSum = fs->make<TH1F>("regionSum", "regionSum", 100, 0., 100.);
62  h_regionIeta = fs->make<TH1F>("regionIeta", "regionIeta", 22, 0., 22.);
63  h_regionIphi = fs->make<TH1F>("regionIphi", "regionIphi", 18, 0., 18.);
64  h_regionMip = fs->make<TH1F>("regionMip", "regionMipBit", 2, 0., 2.);
66  fs->make<TH2F>("regionSum2D", "regionSum2D", 22, 0., 22., 18, 0., 18.);
68  fs->make<TH2F>("regionFG2D", "regionFG2D", 22, 0., 22., 18, 0., 18.);
69 
70  h_towerMip = fs->make<TH1F>("towerMip", "towerMipBit", 2, 0., 2.);
71 
73  fs->make<TH1F>("ecalTimeSample", "ecalTimeSample", 10, 0., 10.);
75  fs->make<TH1F>("hcalTimeSample", "hcalTimeSample", 10, 0., 10.);
76 
77  // get names of modules, producing object collections
78 }
79 
81 
82  // do anything here that needs to be done at destruction time
83  // (e.g. close files, deallocate resources etc.)
84 }
85 
86 //
87 // member functions
88 //
89 
90 // ------------ method called to produce the data ------------
92  const edm::EventSetup &iSetup) {
93  using namespace edm;
94 #ifdef THIS_IS_AN_EVENT_EXAMPLE
96  iEvent.getByLabel("example", pIn);
97 #endif
98 
99 #ifdef THIS_IS_AN_EVENTSETUP_EXAMPLE
100  ESHandle<SetupData> pSetup;
101  iSetup.get<SetupRecord>().get(pSetup);
102 #endif
103 
104  // as in L1GctTestAnalyzer.cc
105  Handle<L1CaloEmCollection> rctEmCands;
109 
110  L1CaloEmCollection::const_iterator em;
111  L1CaloRegionCollection::const_iterator rgn;
114 
115  iEvent.getByLabel(rctDigisLabel, rctEmCands);
116  iEvent.getByLabel(rctDigisLabel, rctRegions);
117  iEvent.getByLabel(ecalDigisLabel, ecalColl);
118  iEvent.getByLabel(hcalDigisLabel, hcalColl);
119 
120  // for sorting later
121  L1CaloEmCollection *myL1EmColl = new L1CaloEmCollection;
122 
123  for (ecal = ecalColl->begin(); ecal != ecalColl->end(); ecal++) {
124  for (unsigned short sample = 0; sample < (*ecal).size(); sample++) {
125  h_ecalTimeSample->Fill(sample);
126  }
127  }
128 
129  for (hcal = hcalColl->begin(); hcal != hcalColl->end(); hcal++) {
130  h_towerMip->Fill((*hcal).SOI_fineGrain());
131  for (unsigned short sample = 0; sample < (*hcal).size(); sample++) {
132  h_hcalTimeSample->Fill(sample);
133  }
134  }
135 
136  if (showEmCands) {
137  // std::cout << std::endl << "L1 RCT EmCand objects" << std::endl;
138  }
139  for (em = rctEmCands->begin(); em != rctEmCands->end(); em++) {
140  // std::cout << "(Analyzer)\n" << (*em) << std::endl;
141 
142  L1CaloEmCand *myL1EmCand = new L1CaloEmCand(*em);
143  (*myL1EmColl).push_back(*myL1EmCand);
144  delete myL1EmCand;
145 
146  h_emCandTimeSample->Fill((*em).bx());
147  if ((*em).bx() == 0) {
148  unsigned short n_emcands = 0;
149  // std::cout << std::endl << "rank: " << (*em).rank() ;
150 
151  if ((*em).rank() > 0) {
152  h_emRank->Fill((*em).rank());
153  h_emIeta->Fill((*em).regionId().ieta());
154  h_emIphi->Fill((*em).regionId().iphi());
155  h_emIso->Fill((*em).isolated());
156  h_emRankInIetaIphi->Fill((*em).regionId().ieta(),
157  (*em).regionId().iphi(), (*em).rank());
158  if ((*em).isolated()) {
159  h_emIsoInIetaIphi->Fill((*em).regionId().ieta(),
160  (*em).regionId().iphi());
161  } else {
162  h_emNonIsoInIetaIphi->Fill((*em).regionId().ieta(),
163  (*em).regionId().iphi());
164  }
165  }
166 
167  if (showEmCands) {
168  if ((*em).rank() > 0) {
169  // std::cout << std::endl << "rank: " << (*em).rank();
170  unsigned short rgnPhi = 999;
171  unsigned short rgn = (unsigned short)(*em).rctRegion();
172  unsigned short card = (unsigned short)(*em).rctCard();
173  unsigned short crate = (unsigned short)(*em).rctCrate();
174 
175  if (card == 6) {
176  rgnPhi = rgn;
177  } else if (card < 6) {
178  rgnPhi = (card % 2);
179  } else {
180  std::cout << "rgnPhi not assigned (still " << rgnPhi
181  << ") -- Weird card number! " << card;
182  }
183 
184  // unsigned short phi_bin = ((crate % 9) * 2) + rgnPhi;
185  short eta_bin = (card / 2) * 2 + 1;
186  if (card < 6) {
187  eta_bin = eta_bin + rgn;
188  }
189  if (crate < 9) {
190  eta_bin = -eta_bin;
191  }
192  n_emcands++;
193 
194  // std::cout << /* "rank: " << (*em).rank() << */ "
195  // eta_bin: " << eta_bin << " phi_bin: " << phi_bin << ". crate: "
196  // << crate << " card: " << card << " region: " << rgn << ".
197  // isolated: " << (*em).isolated();
198  }
199  }
200  } else {
201  h_emRankOutOfTime->Fill((*em).rank());
202  }
203  }
204  if (showEmCands) {
205  // std::cout << std::endl;
206  }
207 
208  // next: SORT THESE GUYS so they're entered into the tree highest first
209  // std::sort(rctEmCands->begin(),rctEmCands->end(),compareEmCands);
210  // for (em=rctEmCands->begin(); em!=rctEmCands->end(); em++)
211  std::sort(myL1EmColl->begin(), myL1EmColl->end(), compareEmCands);
212  std::reverse(myL1EmColl->begin(), myL1EmColl->end()); // whoops!
213  for (em = myL1EmColl->begin(); em != myL1EmColl->end(); em++) {
214  emRank.push_back((*em).rank());
215  emIeta.push_back((*em).regionId().ieta());
216  emIphi.push_back((*em).regionId().iphi());
217  emIso.push_back((*em).isolated());
218  }
219  emTree->Fill();
220 
221  if (showRegionSums) {
222  std::cout << "Regions" << std::endl;
223  }
224  for (rgn = rctRegions->begin(); rgn != rctRegions->end(); rgn++) {
225  if ((*rgn).bx() == 0) {
226  if (showRegionSums && (*rgn).et() > 0) {
227  std::cout << /* "(Analyzer)\n" << */ (*rgn) << std::endl;
228  }
229  if ((*rgn).et() > 0) {
230  h_regionSum->Fill((*rgn).et());
231  h_regionIeta->Fill((*rgn).gctEta());
232  h_regionIphi->Fill((*rgn).gctPhi());
233  h_regionSumInIetaIphi->Fill((*rgn).gctEta(), (*rgn).gctPhi(),
234  (*rgn).et());
235  h_regionFGInIetaIphi->Fill((*rgn).gctEta(), (*rgn).gctPhi(),
236  (*rgn).fineGrain());
237  }
238  h_regionMip->Fill((*rgn).mip());
239  }
240  }
241  if (showRegionSums) {
242  std::cout << std::endl;
243  }
244 
245  emRank.clear();
246  emIeta.clear();
247  emIphi.clear();
248  emIso.clear();
249 
250  delete myL1EmColl;
251 }
252 
254  const L1CaloEmCand &cand2) {
255  return (cand1.rank() < cand2.rank());
256 }
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:18
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
~L1RCTTestAnalyzer() override
int iEvent
Definition: GenABIO.cc:224
std::vector< int > emRank
unsigned rank() const
get rank bits
Definition: L1CaloEmCand.h:44
edm::InputTag rctDigisLabel
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:480
L1RCTTestAnalyzer(const edm::ParameterSet &)
edm::InputTag hcalDigisLabel
const_iterator end() const
edm::InputTag ecalDigisLabel
HLT enums.
T get() const
Definition: EventSetup.h:71
std::vector< int > emIso
const_iterator begin() const
std::vector< int > emIphi