CMS 3D CMS Logo

RctDigiToSourceCardText.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: RctDigiToSourceCardText
4 // Class: RctDigiToSourceCardText
5 //
13 //
14 // Original Author: Alex Tapper
15 // Created: Fri Feb 16 14:52:19 CET 2007
16 //
17 //
18 
20 #include "FWCore/ServiceRegistry/interface/Service.h" // Framework services
22 
23 using namespace edm;
24 using namespace std;
25 
26 // Set constant
27 const static int NUM_RCT_CRATES = 18;
28 
30  const edm::ParameterSet &iConfig)
31  : m_rctInputLabel(iConfig.getParameter<edm::InputTag>("RctInputLabel")),
32  m_textFileName(iConfig.getParameter<std::string>("TextFileName")),
33  m_nevt(0) {
34  // Open the output file
35  m_file.open(m_textFileName.c_str(), std::ios::out);
36 
37  if (!m_file.good()) {
38  throw cms::Exception("RctDigiToSourceCardTextFileOpenError")
39  << "RctDigiToSourceCardText::RctDigiToSourceCardText : "
40  << " couldn't open the file " << m_textFileName << " for writing"
41  << std::endl;
42  }
43 
44  // Make a SC routing object
46 }
47 
49  // Close the output file
50  m_file.close();
51 }
52 
53 // ------------ method called to for each event ------------
55  const edm::EventSetup &iSetup) {
56 
57  // get the RCT data
60  iEvent.getByLabel(m_rctInputLabel, em);
61  iEvent.getByLabel(m_rctInputLabel, rgn);
62 
63  // General variables
64  int RoutingMode;
65  unsigned short logicalCardID;
66  std::string dataString;
67 
68  // Arrays to hold electron variables
69  unsigned short eIsoRank[18][4] = {{0}};
70  unsigned short eIsoCardId[18][4] = {{0}};
71  unsigned short eIsoRegionId[18][4] = {{0}};
72  unsigned short eNonIsoRank[18][4] = {{0}};
73  unsigned short eNonIsoCardId[18][4] = {{0}};
74  unsigned short eNonIsoRegionId[18][4] = {{0}};
75 
76  // Fill electrons
77  unsigned numIsoEM[18] = {0};
78  unsigned numNonIsoEM[18] = {0};
79 
80  for (L1CaloEmCollection::const_iterator iem = em->begin(); iem != em->end();
81  iem++) {
82  if (iem->isolated()) {
83  eIsoRank[iem->rctCrate()][numIsoEM[iem->rctCrate()]] = iem->rank();
84  eIsoCardId[iem->rctCrate()][numIsoEM[iem->rctCrate()]] = iem->rctCard();
85  eIsoRegionId[iem->rctCrate()][numIsoEM[iem->rctCrate()]] =
86  iem->rctRegion();
87  numIsoEM[iem->rctCrate()]++;
88  } else {
89  eNonIsoRank[iem->rctCrate()][numNonIsoEM[iem->rctCrate()]] = iem->rank();
90  eNonIsoCardId[iem->rctCrate()][numNonIsoEM[iem->rctCrate()]] =
91  iem->rctCard();
92  eNonIsoRegionId[iem->rctCrate()][numNonIsoEM[iem->rctCrate()]] =
93  iem->rctRegion();
94  numNonIsoEM[iem->rctCrate()]++;
95  }
96  // Debug info
97  LogDebug("Electrons") << "Rank=" << iem->rank()
98  << " Card=" << iem->rctCard()
99  << " Region=" << iem->rctRegion()
100  << " Crate=" << iem->rctCrate()
101  << " Isolated=" << iem->isolated();
102  }
103 
104  // Arrays to hold region variables
105  unsigned short RC[18][7][2] = {{{0}}};
106  unsigned short RCof[18][7][2] = {{{0}}};
107  unsigned short RCtau[18][7][2] = {{{0}}};
108  unsigned short HF[18][4][2] = {{{0}}};
109  unsigned short HFQ[18][4][2] = {{{0}}};
110  unsigned short MIPbits[18][7][2] = {{{0}}};
111  unsigned short Qbits[18][7][2] = {{{0}}};
112 
113  // Fill regions
114  for (L1CaloRegionCollection::const_iterator irgn = rgn->begin();
115  irgn != rgn->end(); irgn++) {
116  if (irgn->id().isHf()) {
117  HF[irgn->rctCrate()][irgn->id().rctEta() - 7][irgn->id().rctPhi()] =
118  irgn->et();
119  HFQ[irgn->rctCrate()][irgn->id().rctEta() - 7][irgn->id().rctPhi()] =
120  irgn->fineGrain();
121  // Debug info
122  LogDebug("HFRegions")
123  << "Et=" << irgn->et() << " FineGrain=" << irgn->fineGrain()
124  << " Eta=" << irgn->id().rctEta() << " Phi=" << irgn->id().rctPhi()
125  << " Crate=" << irgn->rctCrate();
126  } else {
127  RC[irgn->rctCrate()][irgn->rctCard()][irgn->rctRegionIndex()] =
128  irgn->et();
129  RCof[irgn->rctCrate()][irgn->rctCard()][irgn->rctRegionIndex()] =
130  irgn->overFlow();
131  RCtau[irgn->rctCrate()][irgn->rctCard()][irgn->rctRegionIndex()] =
132  irgn->tauVeto();
133  MIPbits[irgn->rctCrate()][irgn->rctCard()][irgn->rctRegionIndex()] =
134  irgn->mip();
135  Qbits[irgn->rctCrate()][irgn->rctCard()][irgn->rctRegionIndex()] =
136  irgn->quiet();
137  // Debug info
138  LogDebug("Regions") << "Et=" << irgn->et()
139  << " OverFlow=" << irgn->overFlow()
140  << " tauVeto=" << irgn->tauVeto()
141  << " mip=" << irgn->mip()
142  << " quiet=" << irgn->quiet()
143  << " Card=" << irgn->rctCard()
144  << " Region=" << irgn->rctRegionIndex()
145  << " Crate=" << irgn->rctCrate();
146  }
147  }
148 
149  for (int crate = 0; crate < NUM_RCT_CRATES; crate++) {
150 
151  // Logical Card ID = Source Card number
152  RoutingMode = 0;
153  m_scRouting.RoutingModetoLogicalCardID(logicalCardID, RoutingMode, crate);
154 
155  // Convert electrons to SC format
157  logicalCardID, m_nevt, eIsoRank[crate], eIsoCardId[crate],
158  eIsoRegionId[crate], eNonIsoRank[crate], eNonIsoCardId[crate],
159  eNonIsoRegionId[crate], MIPbits[crate], Qbits[crate], dataString);
160 
161  // Write electrons
162  m_file << dataString;
163 
164  // Logical Card ID = Source Card number
165  RoutingMode = 1;
166  m_scRouting.RoutingModetoLogicalCardID(logicalCardID, RoutingMode, crate);
167 
168  // Convert regions to SC format
169  m_scRouting.RC56HFtoSTRING(logicalCardID, m_nevt, RC[crate], RCof[crate],
170  RCtau[crate], HF[crate], HFQ[crate], dataString);
171 
172  // Write regions
173  m_file << dataString;
174 
175  // Logical Card ID = Source Card number
176  RoutingMode = 2;
177  m_scRouting.RoutingModetoLogicalCardID(logicalCardID, RoutingMode, crate);
178 
179  // Convert regions to SC format
180  m_scRouting.RC012toSTRING(logicalCardID, m_nevt, RC[crate], RCof[crate],
181  RCtau[crate], dataString);
182 
183  // Write regions
184  m_file << dataString;
185 
186  // This is to 9 only as this is the shared source card
187  if (crate < 9) {
188  // Logical Card ID = Source Card number
189  RoutingMode = 3;
190  m_scRouting.RoutingModetoLogicalCardID(logicalCardID, RoutingMode, crate);
191 
192  // Convert regions to SC format
193  m_scRouting.RC234toSTRING(logicalCardID, m_nevt, RC[crate], RCof[crate],
194  RCtau[crate], RC[crate + 9], RCof[crate + 9],
195  RCtau[crate + 9], dataString);
196 
197  // Write regions
198  m_file << dataString;
199  }
200  }
201 
202  // Force write to file
203  m_file << flush;
204 
205  m_nevt++;
206 }
#define LogDebug(id)
void analyze(const edm::Event &, const edm::EventSetup &) override
void RC012toSTRING(unsigned short &logicalCardID, unsigned short &eventNumber, unsigned short(&RC)[7][2], unsigned short(&RCof)[7][2], unsigned short(&RCtau)[7][2], std::string &dataString) const
std::ofstream m_file
file handle
edm::InputTag m_rctInputLabel
Label for RCT digis.
void RC234toSTRING(unsigned short &logicalCardID, unsigned short &eventNumber, unsigned short(&RC)[7][2], unsigned short(&RCof)[7][2], unsigned short(&RCtau)[7][2], unsigned short(&sisterRC)[7][2], unsigned short(&sisterRCof)[7][2], unsigned short(&sisterRCtau)[7][2], std::string &dataString) const
void RoutingModetoLogicalCardID(unsigned short &logicalCardID, int &RoutingMode, int &RCTCrateNumber) const
int iEvent
Definition: GenABIO.cc:224
std::string m_textFileName
Name out output file.
void EMUtoSTRING(unsigned short &logicalCardID, unsigned short &eventNumber, unsigned short(&eIsoRank)[4], unsigned short(&eIsoCardId)[4], unsigned short(&eIsoRegionId)[4], unsigned short(&eNonIsoRank)[4], unsigned short(&eNonIsoCardId)[4], unsigned short(&eNonIsoRegionId)[4], unsigned short(&MIPbits)[7][2], unsigned short(&Qbits)[7][2], std::string &dataString) const
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:480
RctDigiToSourceCardText(const edm::ParameterSet &)
unsigned short m_nevt
event counter
void RC56HFtoSTRING(unsigned short &logicalCardID, unsigned short &eventNumber, unsigned short(&RC)[7][2], unsigned short(&RCof)[7][2], unsigned short(&RCtau)[7][2], unsigned short(&HF)[4][2], unsigned short(&HFQ)[4][2], std::string &dataString) const
SourceCardRouting m_scRouting
source card router
HLT enums.
static const int NUM_RCT_CRATES