CMS 3D CMS Logo

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