CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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  : m_rctInputLabel(iConfig.getParameter<edm::InputTag>("RctInputLabel")),
31  m_textFileName(iConfig.getParameter<std::string>("TextFileName")),
32  m_nevt(0) {
33  // Open the output file
34  m_file.open(m_textFileName.c_str(), std::ios::out);
35 
36  if (!m_file.good()) {
37  throw cms::Exception("RctDigiToSourceCardTextFileOpenError")
38  << "RctDigiToSourceCardText::RctDigiToSourceCardText : "
39  << " couldn't open the file " << m_textFileName << " for writing" << std::endl;
40  }
41 
42  // Make a SC routing object
44 }
45 
47  // Close the output file
48  m_file.close();
49 }
50 
51 // ------------ method called to for each event ------------
53  // get the RCT data
56  iEvent.getByLabel(m_rctInputLabel, em);
57  iEvent.getByLabel(m_rctInputLabel, rgn);
58 
59  // General variables
60  int RoutingMode;
61  unsigned short logicalCardID;
62  std::string dataString;
63 
64  // Arrays to hold electron variables
65  unsigned short eIsoRank[18][4] = {{0}};
66  unsigned short eIsoCardId[18][4] = {{0}};
67  unsigned short eIsoRegionId[18][4] = {{0}};
68  unsigned short eNonIsoRank[18][4] = {{0}};
69  unsigned short eNonIsoCardId[18][4] = {{0}};
70  unsigned short eNonIsoRegionId[18][4] = {{0}};
71 
72  // Fill electrons
73  unsigned numIsoEM[18] = {0};
74  unsigned numNonIsoEM[18] = {0};
75 
76  for (L1CaloEmCollection::const_iterator iem = em->begin(); iem != em->end(); iem++) {
77  if (iem->isolated()) {
78  eIsoRank[iem->rctCrate()][numIsoEM[iem->rctCrate()]] = iem->rank();
79  eIsoCardId[iem->rctCrate()][numIsoEM[iem->rctCrate()]] = iem->rctCard();
80  eIsoRegionId[iem->rctCrate()][numIsoEM[iem->rctCrate()]] = iem->rctRegion();
81  numIsoEM[iem->rctCrate()]++;
82  } else {
83  eNonIsoRank[iem->rctCrate()][numNonIsoEM[iem->rctCrate()]] = iem->rank();
84  eNonIsoCardId[iem->rctCrate()][numNonIsoEM[iem->rctCrate()]] = iem->rctCard();
85  eNonIsoRegionId[iem->rctCrate()][numNonIsoEM[iem->rctCrate()]] = iem->rctRegion();
86  numNonIsoEM[iem->rctCrate()]++;
87  }
88  // Debug info
89  LogDebug("Electrons") << "Rank=" << iem->rank() << " Card=" << iem->rctCard() << " Region=" << iem->rctRegion()
90  << " Crate=" << iem->rctCrate() << " Isolated=" << iem->isolated();
91  }
92 
93  // Arrays to hold region variables
94  unsigned short RC[18][7][2] = {{{0}}};
95  unsigned short RCof[18][7][2] = {{{0}}};
96  unsigned short RCtau[18][7][2] = {{{0}}};
97  unsigned short HF[18][4][2] = {{{0}}};
98  unsigned short HFQ[18][4][2] = {{{0}}};
99  unsigned short MIPbits[18][7][2] = {{{0}}};
100  unsigned short Qbits[18][7][2] = {{{0}}};
101 
102  // Fill regions
103  for (L1CaloRegionCollection::const_iterator irgn = rgn->begin(); irgn != rgn->end(); irgn++) {
104  if (irgn->id().isHf()) {
105  HF[irgn->rctCrate()][irgn->id().rctEta() - 7][irgn->id().rctPhi()] = irgn->et();
106  HFQ[irgn->rctCrate()][irgn->id().rctEta() - 7][irgn->id().rctPhi()] = irgn->fineGrain();
107  // Debug info
108  LogDebug("HFRegions") << "Et=" << irgn->et() << " FineGrain=" << irgn->fineGrain()
109  << " Eta=" << irgn->id().rctEta() << " Phi=" << irgn->id().rctPhi()
110  << " Crate=" << irgn->rctCrate();
111  } else {
112  RC[irgn->rctCrate()][irgn->rctCard()][irgn->rctRegionIndex()] = irgn->et();
113  RCof[irgn->rctCrate()][irgn->rctCard()][irgn->rctRegionIndex()] = irgn->overFlow();
114  RCtau[irgn->rctCrate()][irgn->rctCard()][irgn->rctRegionIndex()] = irgn->tauVeto();
115  MIPbits[irgn->rctCrate()][irgn->rctCard()][irgn->rctRegionIndex()] = irgn->mip();
116  Qbits[irgn->rctCrate()][irgn->rctCard()][irgn->rctRegionIndex()] = irgn->quiet();
117  // Debug info
118  LogDebug("Regions") << "Et=" << irgn->et() << " OverFlow=" << irgn->overFlow() << " tauVeto=" << irgn->tauVeto()
119  << " mip=" << irgn->mip() << " quiet=" << irgn->quiet() << " Card=" << irgn->rctCard()
120  << " Region=" << irgn->rctRegionIndex() << " Crate=" << irgn->rctCrate();
121  }
122  }
123 
124  for (int crate = 0; crate < NUM_RCT_CRATES; crate++) {
125  // Logical Card ID = Source Card number
126  RoutingMode = 0;
127  m_scRouting.RoutingModetoLogicalCardID(logicalCardID, RoutingMode, crate);
128 
129  // Convert electrons to SC format
130  m_scRouting.EMUtoSTRING(logicalCardID,
131  m_nevt,
132  eIsoRank[crate],
133  eIsoCardId[crate],
134  eIsoRegionId[crate],
135  eNonIsoRank[crate],
136  eNonIsoCardId[crate],
137  eNonIsoRegionId[crate],
138  MIPbits[crate],
139  Qbits[crate],
140  dataString);
141 
142  // Write electrons
143  m_file << dataString;
144 
145  // Logical Card ID = Source Card number
146  RoutingMode = 1;
147  m_scRouting.RoutingModetoLogicalCardID(logicalCardID, RoutingMode, crate);
148 
149  // Convert regions to SC format
151  logicalCardID, m_nevt, RC[crate], RCof[crate], RCtau[crate], HF[crate], HFQ[crate], dataString);
152 
153  // Write regions
154  m_file << dataString;
155 
156  // Logical Card ID = Source Card number
157  RoutingMode = 2;
158  m_scRouting.RoutingModetoLogicalCardID(logicalCardID, RoutingMode, crate);
159 
160  // Convert regions to SC format
161  m_scRouting.RC012toSTRING(logicalCardID, m_nevt, RC[crate], RCof[crate], RCtau[crate], dataString);
162 
163  // Write regions
164  m_file << dataString;
165 
166  // This is to 9 only as this is the shared source card
167  if (crate < 9) {
168  // Logical Card ID = Source Card number
169  RoutingMode = 3;
170  m_scRouting.RoutingModetoLogicalCardID(logicalCardID, RoutingMode, crate);
171 
172  // Convert regions to SC format
173  m_scRouting.RC234toSTRING(logicalCardID,
174  m_nevt,
175  RC[crate],
176  RCof[crate],
177  RCtau[crate],
178  RC[crate + 9],
179  RCof[crate + 9],
180  RCtau[crate + 9],
181  dataString);
182 
183  // Write regions
184  m_file << dataString;
185  }
186  }
187 
188  // Force write to file
189  m_file << flush;
190 
191  m_nevt++;
192 }
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:500
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
static const int NUM_RCT_CRATES
#define LogDebug(id)