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 // $Id: RctDigiToSourceCardText.cc,v 1.3 2009/03/26 14:53:03 tapper Exp $
15 //
16 //
17 
19 #include "FWCore/ServiceRegistry/interface/Service.h" // Framework services
21 
22 using namespace edm;
23 using namespace std;
24 
25 // Set constant
26 const static int NUM_RCT_CRATES = 18;
27 
29  m_rctInputLabel(iConfig.getParameter<edm::InputTag>("RctInputLabel")),
30  m_textFileName(iConfig.getParameter<std::string>("TextFileName")),
31  m_nevt(0)
32 {
33  // Open the output file
34  m_file.open(m_textFileName.c_str(),std::ios::out);
35 
36  if(!m_file.good())
37  {
38  throw cms::Exception("RctDigiToSourceCardTextFileOpenError")
39  << "RctDigiToSourceCardText::RctDigiToSourceCardText : "
40  << " couldn't open the file " << m_textFileName << " for writing" << std::endl;
41  }
42 
43  // Make a SC routing object
45 }
46 
47 
49 {
50  // Close the output file
51  m_file.close();
52 }
53 
54 // ------------ method called to for each event ------------
56 {
57 
58  // get the RCT data
61  iEvent.getByLabel(m_rctInputLabel, em);
62  iEvent.getByLabel(m_rctInputLabel, rgn);
63 
64  // General variables
65  int RoutingMode;
66  unsigned short logicalCardID;
67  std::string dataString;
68 
69  // Arrays to hold electron variables
70  unsigned short eIsoRank[18][4]={{0}};
71  unsigned short eIsoCardId[18][4]={{0}};
72  unsigned short eIsoRegionId[18][4]={{0}};
73  unsigned short eNonIsoRank[18][4]={{0}};
74  unsigned short eNonIsoCardId[18][4]={{0}};
75  unsigned short eNonIsoRegionId[18][4]={{0}};
76 
77  // Fill electrons
78  unsigned numIsoEM[18]={0};
79  unsigned numNonIsoEM[18]={0};
80 
81  for (L1CaloEmCollection::const_iterator iem=em->begin(); iem!=em->end(); 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()]]=iem->rctRegion();
86  numIsoEM[iem->rctCrate()]++;
87  } else {
88  eNonIsoRank[iem->rctCrate()][numNonIsoEM[iem->rctCrate()]]=iem->rank();
89  eNonIsoCardId[iem->rctCrate()][numNonIsoEM[iem->rctCrate()]]=iem->rctCard();
90  eNonIsoRegionId[iem->rctCrate()][numNonIsoEM[iem->rctCrate()]]=iem->rctRegion();
91  numNonIsoEM[iem->rctCrate()]++;
92  }
93  // Debug info
94  LogDebug("Electrons") << "Rank=" << iem->rank()
95  << " Card=" << iem->rctCard()
96  << " Region=" << iem->rctRegion()
97  << " Crate=" << iem->rctCrate()
98  << " Isolated=" << iem->isolated();
99  }
100 
101  // Arrays to hold region variables
102  unsigned short RC[18][7][2]={{{0}}};
103  unsigned short RCof[18][7][2]={{{0}}};
104  unsigned short RCtau[18][7][2]={{{0}}};
105  unsigned short HF[18][4][2]={{{0}}};
106  unsigned short HFQ[18][4][2]={{{0}}};
107  unsigned short MIPbits[18][7][2]={{{0}}};
108  unsigned short Qbits[18][7][2]={{{0}}};
109 
110  // Fill regions
111  for (L1CaloRegionCollection::const_iterator irgn=rgn->begin(); irgn!=rgn->end(); irgn++){
112  if (irgn->id().isHf()){
113  HF[irgn->rctCrate()][irgn->id().rctEta()-7][irgn->id().rctPhi()]=irgn->et();
114  HFQ[irgn->rctCrate()][irgn->id().rctEta()-7][irgn->id().rctPhi()]=irgn->fineGrain();
115  // Debug info
116  LogDebug("HFRegions") << "Et=" << irgn->et()
117  << " FineGrain=" << irgn->fineGrain()
118  << " Eta=" << irgn->id().rctEta()
119  << " Phi=" << irgn->id().rctPhi()
120  << " Crate=" << irgn->rctCrate();
121  } else {
122  RC[irgn->rctCrate()][irgn->rctCard()][irgn->rctRegionIndex()]=irgn->et();
123  RCof[irgn->rctCrate()][irgn->rctCard()][irgn->rctRegionIndex()]=irgn->overFlow();
124  RCtau[irgn->rctCrate()][irgn->rctCard()][irgn->rctRegionIndex()]=irgn->tauVeto();
125  MIPbits[irgn->rctCrate()][irgn->rctCard()][irgn->rctRegionIndex()]=irgn->mip();
126  Qbits[irgn->rctCrate()][irgn->rctCard()][irgn->rctRegionIndex()]=irgn->quiet();
127  // Debug info
128  LogDebug("Regions") << "Et=" << irgn->et()
129  << " OverFlow=" << irgn->overFlow()
130  << " tauVeto=" << irgn->tauVeto()
131  << " mip=" << irgn->mip()
132  << " quiet=" << irgn->quiet()
133  << " Card=" << irgn->rctCard()
134  << " Region=" << irgn->rctRegionIndex()
135  << " Crate=" << irgn->rctCrate();
136  }
137  }
138 
139  for (int crate=0; crate<NUM_RCT_CRATES; crate++){
140 
141  // Logical Card ID = Source Card number
142  RoutingMode=0;
143  m_scRouting.RoutingModetoLogicalCardID(logicalCardID,RoutingMode,crate);
144 
145  // Convert electrons to SC format
146  m_scRouting.EMUtoSTRING(logicalCardID,
147  m_nevt,
148  eIsoRank[crate],
149  eIsoCardId[crate],
150  eIsoRegionId[crate],
151  eNonIsoRank[crate],
152  eNonIsoCardId[crate],
153  eNonIsoRegionId[crate],
154  MIPbits[crate],
155  Qbits[crate],
156  dataString);
157 
158  // Write electrons
159  m_file << dataString;
160 
161  // Logical Card ID = Source Card number
162  RoutingMode=1;
163  m_scRouting.RoutingModetoLogicalCardID(logicalCardID,RoutingMode,crate);
164 
165  // Convert regions to SC format
166  m_scRouting.RC56HFtoSTRING(logicalCardID,
167  m_nevt,
168  RC[crate],
169  RCof[crate],
170  RCtau[crate],
171  HF[crate],
172  HFQ[crate],
173  dataString);
174 
175  // Write regions
176  m_file << dataString;
177 
178  // Logical Card ID = Source Card number
179  RoutingMode=2;
180  m_scRouting.RoutingModetoLogicalCardID(logicalCardID,RoutingMode,crate);
181 
182  // Convert regions to SC format
183  m_scRouting.RC012toSTRING(logicalCardID,
184  m_nevt,
185  RC[crate],
186  RCof[crate],
187  RCtau[crate],
188  dataString);
189 
190  // Write regions
191  m_file << dataString;
192 
193  // This is to 9 only as this is the shared source card
194  if (crate<9){
195  // Logical Card ID = Source Card number
196  RoutingMode=3;
197  m_scRouting.RoutingModetoLogicalCardID(logicalCardID,RoutingMode,crate);
198 
199  // Convert regions to SC format
200  m_scRouting.RC234toSTRING(logicalCardID,
201  m_nevt,
202  RC[crate],
203  RCof[crate],
204  RCtau[crate],
205  RC[crate+9],
206  RCof[crate+9],
207  RCtau[crate+9],
208  dataString);
209 
210  // Write regions
211  m_file << dataString;
212  }
213 
214  }
215 
216  // Force write to file
217  m_file << flush;
218 
219  m_nevt++;
220 }
221 
#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:359
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