CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RctDigiToSourceCardText.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: RctDigiToSourceCardText
4 // Class: RctDigiToSourceCardText
5 //
11 //
12 // Original Author: Alex Tapper
13 // Created: Fri Feb 16 14:52:19 CET 2007
14 //
15 //
16 
18 #include "FWCore/ServiceRegistry/interface/Service.h" // Framework services
20 
21 using namespace edm;
22 using namespace std;
23 
24 // Set constant
25 const static int NUM_RCT_CRATES = 18;
26 
28  m_rctInputLabel(iConfig.getParameter<edm::InputTag>("RctInputLabel")),
29  m_textFileName(iConfig.getParameter<std::string>("TextFileName")),
30  m_nevt(0)
31 {
32  // Open the output file
33  m_file.open(m_textFileName.c_str(),std::ios::out);
34 
35  if(!m_file.good())
36  {
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 
46 
48 {
49  // Close the output file
50  m_file.close();
51 }
52 
53 // ------------ method called to for each event ------------
55 {
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(); iem++){
81  if (iem->isolated()){
82  eIsoRank[iem->rctCrate()][numIsoEM[iem->rctCrate()]]=iem->rank();
83  eIsoCardId[iem->rctCrate()][numIsoEM[iem->rctCrate()]]=iem->rctCard();
84  eIsoRegionId[iem->rctCrate()][numIsoEM[iem->rctCrate()]]=iem->rctRegion();
85  numIsoEM[iem->rctCrate()]++;
86  } else {
87  eNonIsoRank[iem->rctCrate()][numNonIsoEM[iem->rctCrate()]]=iem->rank();
88  eNonIsoCardId[iem->rctCrate()][numNonIsoEM[iem->rctCrate()]]=iem->rctCard();
89  eNonIsoRegionId[iem->rctCrate()][numNonIsoEM[iem->rctCrate()]]=iem->rctRegion();
90  numNonIsoEM[iem->rctCrate()]++;
91  }
92  // Debug info
93  LogDebug("Electrons") << "Rank=" << iem->rank()
94  << " Card=" << iem->rctCard()
95  << " Region=" << iem->rctRegion()
96  << " Crate=" << iem->rctCrate()
97  << " Isolated=" << iem->isolated();
98  }
99 
100  // Arrays to hold region variables
101  unsigned short RC[18][7][2]={{{0}}};
102  unsigned short RCof[18][7][2]={{{0}}};
103  unsigned short RCtau[18][7][2]={{{0}}};
104  unsigned short HF[18][4][2]={{{0}}};
105  unsigned short HFQ[18][4][2]={{{0}}};
106  unsigned short MIPbits[18][7][2]={{{0}}};
107  unsigned short Qbits[18][7][2]={{{0}}};
108 
109  // Fill regions
110  for (L1CaloRegionCollection::const_iterator irgn=rgn->begin(); irgn!=rgn->end(); irgn++){
111  if (irgn->id().isHf()){
112  HF[irgn->rctCrate()][irgn->id().rctEta()-7][irgn->id().rctPhi()]=irgn->et();
113  HFQ[irgn->rctCrate()][irgn->id().rctEta()-7][irgn->id().rctPhi()]=irgn->fineGrain();
114  // Debug info
115  LogDebug("HFRegions") << "Et=" << irgn->et()
116  << " FineGrain=" << irgn->fineGrain()
117  << " Eta=" << irgn->id().rctEta()
118  << " Phi=" << irgn->id().rctPhi()
119  << " Crate=" << irgn->rctCrate();
120  } else {
121  RC[irgn->rctCrate()][irgn->rctCard()][irgn->rctRegionIndex()]=irgn->et();
122  RCof[irgn->rctCrate()][irgn->rctCard()][irgn->rctRegionIndex()]=irgn->overFlow();
123  RCtau[irgn->rctCrate()][irgn->rctCard()][irgn->rctRegionIndex()]=irgn->tauVeto();
124  MIPbits[irgn->rctCrate()][irgn->rctCard()][irgn->rctRegionIndex()]=irgn->mip();
125  Qbits[irgn->rctCrate()][irgn->rctCard()][irgn->rctRegionIndex()]=irgn->quiet();
126  // Debug info
127  LogDebug("Regions") << "Et=" << irgn->et()
128  << " OverFlow=" << irgn->overFlow()
129  << " tauVeto=" << irgn->tauVeto()
130  << " mip=" << irgn->mip()
131  << " quiet=" << irgn->quiet()
132  << " Card=" << irgn->rctCard()
133  << " Region=" << irgn->rctRegionIndex()
134  << " Crate=" << irgn->rctCrate();
135  }
136  }
137 
138  for (int crate=0; crate<NUM_RCT_CRATES; crate++){
139 
140  // Logical Card ID = Source Card number
141  RoutingMode=0;
142  m_scRouting.RoutingModetoLogicalCardID(logicalCardID,RoutingMode,crate);
143 
144  // Convert electrons to SC format
145  m_scRouting.EMUtoSTRING(logicalCardID,
146  m_nevt,
147  eIsoRank[crate],
148  eIsoCardId[crate],
149  eIsoRegionId[crate],
150  eNonIsoRank[crate],
151  eNonIsoCardId[crate],
152  eNonIsoRegionId[crate],
153  MIPbits[crate],
154  Qbits[crate],
155  dataString);
156 
157  // Write electrons
158  m_file << dataString;
159 
160  // Logical Card ID = Source Card number
161  RoutingMode=1;
162  m_scRouting.RoutingModetoLogicalCardID(logicalCardID,RoutingMode,crate);
163 
164  // Convert regions to SC format
165  m_scRouting.RC56HFtoSTRING(logicalCardID,
166  m_nevt,
167  RC[crate],
168  RCof[crate],
169  RCtau[crate],
170  HF[crate],
171  HFQ[crate],
172  dataString);
173 
174  // Write regions
175  m_file << dataString;
176 
177  // Logical Card ID = Source Card number
178  RoutingMode=2;
179  m_scRouting.RoutingModetoLogicalCardID(logicalCardID,RoutingMode,crate);
180 
181  // Convert regions to SC format
182  m_scRouting.RC012toSTRING(logicalCardID,
183  m_nevt,
184  RC[crate],
185  RCof[crate],
186  RCtau[crate],
187  dataString);
188 
189  // Write regions
190  m_file << dataString;
191 
192  // This is to 9 only as this is the shared source card
193  if (crate<9){
194  // Logical Card ID = Source Card number
195  RoutingMode=3;
196  m_scRouting.RoutingModetoLogicalCardID(logicalCardID,RoutingMode,crate);
197 
198  // Convert regions to SC format
199  m_scRouting.RC234toSTRING(logicalCardID,
200  m_nevt,
201  RC[crate],
202  RCof[crate],
203  RCtau[crate],
204  RC[crate+9],
205  RCof[crate+9],
206  RCtau[crate+9],
207  dataString);
208 
209  // Write regions
210  m_file << dataString;
211  }
212 
213  }
214 
215  // Force write to file
216  m_file << flush;
217 
218  m_nevt++;
219 }
220 
#define LogDebug(id)
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
virtual void analyze(const edm::Event &, const edm::EventSetup &)
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:243
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:390
tuple out
Definition: dbtoconf.py:99
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