CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RawToDigiConverter.cc
Go to the documentation of this file.
1 /****************************************************************************
2 *
3 * This is a part of TOTEM offline software.
4 * Authors:
5 * Jan Kašpar (jan.kaspar@gmail.com)
6 * Seyed Mohsen Etesami (setesami@cern.ch)
7 ****************************************************************************/
8 
10 
12 
14 
17 
19 
20 //----------------------------------------------------------------------------------------------------
21 
22 using namespace std;
23 using namespace edm;
24 
25 //----------------------------------------------------------------------------------------------------
26 
28  verbosity(conf.getUntrackedParameter<unsigned int>("verbosity", 0)),
29  printErrorSummary(conf.getUntrackedParameter<unsigned int>("printErrorSummary", 1)),
30  printUnknownFrameSummary(conf.getUntrackedParameter<unsigned int>("printUnknownFrameSummary", 1)),
31 
32  testFootprint(conf.getParameter<unsigned int>("testFootprint")),
33  testCRC(conf.getParameter<unsigned int>("testCRC")),
34  testID(conf.getParameter<unsigned int>("testID")),
35  testECMostFrequent(conf.getParameter<unsigned int>("testECMostFrequent")),
36  testBCMostFrequent(conf.getParameter<unsigned int>("testBCMostFrequent")),
37 
38  EC_min(conf.getUntrackedParameter<unsigned int>("EC_min", 10)),
39  BC_min(conf.getUntrackedParameter<unsigned int>("BC_min", 10)),
40 
41  EC_fraction(conf.getUntrackedParameter<double>("EC_fraction", 0.6)),
42  BC_fraction(conf.getUntrackedParameter<double>("BC_fraction", 0.6))
43 {
44 }
45 
46 //----------------------------------------------------------------------------------------------------
47 
49  map<TotemFramePosition, RawToDigiConverter::Record> &records)
50 {
51  // EC and BC checks (wrt. the most frequent value), BC checks per subsystem
54 
55 
56  // initialise structure merging vfat frame data with the mapping
57  for (auto &p : mapping.VFATMapping)
58  {
59  TotemVFATStatus st;
60  st.setMissing(true);
61  records[p.first] = { &p.second, NULL, st };
62  }
63 
64  // event error message buffer
65  stringstream ees;
66 
67  // associate data frames with records
68  for (VFATFrameCollection::Iterator fr(&input); !fr.IsEnd(); fr.Next())
69  {
70  // frame error message buffer
71  stringstream fes;
72 
73  bool problemsPresent = false;
74  bool stopProcessing = false;
75 
76  // skip data frames not listed in the DAQ mapping
77  auto records_it = records.find(fr.Position());
78  if (records_it == records.end())
79  {
80  unknownSummary[fr.Position()]++;
81  continue;
82  }
83 
84  // update record
85  Record &record = records_it->second;
86  record.frame = fr.Data();
87  record.status.setMissing(false);
90 
91  // check footprint
92  if (testFootprint != tfNoTest && !record.frame->checkFootprint())
93  {
94  problemsPresent = true;
95 
96  if (verbosity > 0)
97  fes << " invalid footprint\n";
98 
99  if ((testFootprint == tfErr))
100  {
101  record.status.setFootprintError();
102  stopProcessing = true;
103  }
104  }
105 
106  // check CRC
107  if (testCRC != tfNoTest && !record.frame->checkCRC())
108  {
109  problemsPresent = true;
110 
111  if (verbosity > 0)
112  fes << " CRC failure\n";
113 
114  if (testCRC == tfErr)
115  {
116  record.status.setCRCError();
117  stopProcessing = true;
118  }
119  }
120  // check the id mismatch
121  if (testID != tfNoTest && record.frame->isIDPresent() && (record.frame->getChipID() & 0xFFF) != (record.info->hwID & 0xFFF))
122  {
123  if (verbosity > 0)
124  fes << " ID mismatch (data: 0x" << hex << record.frame->getChipID()
125  << ", mapping: 0x" << record.info->hwID << dec << ", symbId: " << record.info->symbolicID.symbolicID << ")\n";
126 
127  if (testID == tfErr)
128  {
129  record.status.setIDMismatch();
130  stopProcessing = true;
131  }
132  }
133 
134  // if there were errors, put the information to ees buffer
135  if (verbosity > 0 && problemsPresent)
136  {
137  string message = (stopProcessing) ? "(and will be dropped)" : "(but will be used though)";
138  if (verbosity > 2)
139  {
140  ees << " Frame at " << fr.Position() << " seems corrupted " << message << ":\n";
141  ees << fes.rdbuf();
142  } else
143  ees << " Frame at " << fr.Position() << " seems corrupted " << message << ".\n";
144  }
145 
146  // if there were serious errors, do not process this frame
147  if (stopProcessing)
148  continue;
149 
150  // fill EC and BC values to the statistics
151  if (fr.Data()->isECPresent())
152  ECChecker.Fill(fr.Data()->getEC(), fr.Position());
153 
154  if (fr.Data()->isBCPresent())
155  BCChecker.Fill(fr.Data()->getBC(), fr.Position());
156  }
157 
158  // analyze EC and BC statistics
160  ECChecker.Analyze(records, (testECMostFrequent == tfErr), ees);
161 
163  BCChecker.Analyze(records, (testBCMostFrequent == tfErr), ees);
164 
165  // add error message for missing frames
166  if (verbosity > 1)
167  {
168  for (const auto &p : records)
169  {
170  if (p.second.status.isMissing())
171  ees << "Frame for VFAT " << p.first << " is not present in the data.\n";
172  }
173  }
174 
175  // print error message
176  if (verbosity > 0 && !ees.rdbuf()->str().empty())
177  {
178  if (verbosity > 1)
179  LogProblem("Totem") << "Error in RawToDigiConverter::RunCommon > " << "event contains the following problems:\n" << ees.rdbuf() << endl;
180  else
181  LogProblem("Totem") << "Error in RawToDigiConverter::RunCommon > " << "event contains problems." << endl;
182  }
183 
184  // increase error counters
185  if (printErrorSummary)
186  {
187  for (const auto &it : records)
188  {
189  if (!it.second.status.isOK())
190  {
191  auto &m = errorSummary[it.first];
192  m[it.second.status]++;
193  }
194  }
195  }
196 }
197 
198 //----------------------------------------------------------------------------------------------------
199 
201  const TotemDAQMapping &mapping, const TotemAnalysisMask &analysisMask,
203 {
204  // structure merging vfat frame data with the mapping
205  map<TotemFramePosition, Record> records;
206 
207  // common processing - frame validation
208  RunCommon(input, mapping, records);
209 
210  // second loop over data
211  for (auto &p : records)
212  {
213  Record &record = p.second;
214 
215  // calculate ids
216  TotemRPDetId chipId(record.info->symbolicID.symbolicID);
217  uint8_t chipPosition = chipId.chip();
218  TotemRPDetId detId = chipId.getPlaneId();
219 
220  // update chipPosition in status
221  record.status.setChipPosition(chipPosition);
222 
223  // produce digi only for good frames
224  if (record.status.isOK())
225  {
226  // find analysis mask (needs a default=no mask, if not in present the mapping)
228  anMa.fullMask = false;
229 
230  auto analysisIter = analysisMask.analysisMask.find(record.info->symbolicID);
231  if (analysisIter != analysisMask.analysisMask.end())
232  {
233  // if there is some information about masked channels - save it into conversionStatus
234  anMa = analysisIter->second;
235  if (anMa.fullMask)
236  record.status.setFullyMaskedOut();
237  else
238  record.status.setPartiallyMaskedOut();
239  }
240 
241  // create the digi
242  unsigned short offset = chipPosition * 128;
243  const vector<unsigned char> &activeChannels = record.frame->getActiveChannels();
244 
245  for (auto ch : activeChannels)
246  {
247  // skip masked channels
248  if (!anMa.fullMask && anMa.maskedChannels.find(ch) == anMa.maskedChannels.end())
249  {
250  DetSet<TotemRPDigi> &digiDetSet = rpData.find_or_insert(detId);
251  digiDetSet.push_back(TotemRPDigi(offset + ch));
252  }
253  }
254  }
255 
256  // save status
257  DetSet<TotemVFATStatus> &statusDetSet = finalStatus.find_or_insert(detId);
258  statusDetSet.push_back(record.status);
259  }
260 }
261 
262 //----------------------------------------------------------------------------------------------------
263 
266 {
267  // structure merging vfat frame data with the mapping
268  map<TotemFramePosition, Record> records;
269 
270  // common processing - frame validation
271  RunCommon(coll, mapping, records);
272 
273  // second loop over data
274  for (auto &p : records)
275  {
276  Record &record = p.second;
277 
278  // calculate ids
280 
281  if (record.status.isOK())
282  {
283  const VFATFrame *fr = record.frame;
284  DiamondVFATFrame *diamondframe = (DiamondVFATFrame*) fr;
285 
286  // update Event Counter in status
287  record.status.setEC(record.frame->getEC() & 0xFF);
288 
289  // create the digi
290  DetSet<CTPPSDiamondDigi> &digiDetSet = digi.find_or_insert(detId);
291  digiDetSet.push_back(CTPPSDiamondDigi(diamondframe->getLeadingEdgeTime(),diamondframe->getTrailingEdgeTime(),diamondframe->getThresholdVoltage(),diamondframe->getMultihit(),diamondframe->getHptdcErrorFlag()));
292  }
293 
294  // save status
295  DetSet<TotemVFATStatus> &statusDetSet = status.find_or_insert(detId);
296  statusDetSet.push_back(record.status);
297  }
298 }
299 
300 //----------------------------------------------------------------------------------------------------
301 
303 {
304  if (printErrorSummary)
305  {
306  LogVerbatim("Totem") << "* Error summary (error signature : number of such events)" << endl;
307  for (const auto &vit : errorSummary)
308  {
309  LogVerbatim("Totem") << vit.first << endl;
310 
311  for (const auto &it : vit.second)
312  LogVerbatim("Totem") << " " << it.first << " : " << it.second << endl;
313  }
314  }
315 
317  {
318  LogVerbatim("Totem") << "* Frames found in data, but not in the mapping (frame position : number of events)" << endl;
319  for (const auto &it : unknownSummary)
320  LogVerbatim("Totem") << " " << it.first << " : " << it.second << endl;
321  }
322 }
Detector ID class for TOTEM Si strip detectors.
Definition: TotemRPDetId.h:30
void Run(const VFATFrameCollection &coll, const TotemDAQMapping &mapping, const TotemAnalysisMask &mask, edm::DetSetVector< TotemRPDigi > &digi, edm::DetSetVector< TotemVFATStatus > &status)
Creates RP digi.
bool isOK() const
Contains data on masked channels of a VFAT.
void push_back(const T &t)
Definition: DetSet.h:68
unsigned int testECMostFrequent
Channel-mask mapping.
unsigned int printErrorSummary
void setCRCError(bool val=true)
Class for finding the most popular both EC and BC counter, and filling the conversion status &#39;wrong E...
uint32_t chip() const
Definition: TotemRPDetId.h:60
JetCorrectorParameters::Record record
Definition: classes.h:7
uint32_t getLeadingEdgeTime() const
get timing infromation
void Analyze(T &status, bool error, std::ostream &es)
summarizes and fill the status (wrong EC and BC progress error for some frames)
TotemSymbID symbolicID
the symbolic id
#define NULL
Definition: scimark2.h:8
void setNumberOfClusters(uint8_t v)
bool checkFootprint() const
Definition: VFATFrame.cc:63
RawToDigiConverter(const edm::ParameterSet &conf)
virtual bool checkCRC() const
Definition: VFATFrame.cc:79
uint8_t getNumberOfClusters() const
Definition: VFATFrame.h:125
uint32_t getThresholdVoltage() const
VFATFrame::word getMultihit() const
unsigned int testFootprint
flags for which tests to run
std::map< TotemSymbID, TotemVFATAnalysisMask > analysisMask
void setFullyMaskedOut()
static std::string const input
Definition: EdmProvDump.cc:44
reference find_or_insert(det_id_type id)
Definition: DetSetVector.h:254
the VFATFrameCollection interator
unsigned int printUnknownFrameSummary
bool isNumberOfClustersPresent() const
Returns true if the CRC word is present in the frame.
Definition: VFATFrame.h:107
The mapping between FramePosition and VFATInfo.
const TotemVFATInfo * info
bool fullMask
whether all channels of the VFAT shall be masked
void PrintSummaries()
Print error summaries.
void setMissing(bool val=true)
unsigned int symbolicID
chip ID, raw integer representation of DetId class
Definition: TotemSymbId.h:21
void setFootprintError(bool val=true)
uint32_t getTrailingEdgeTime() const
void setNumberOfClustersSpecified(bool v)
unsigned char verbosity
JetCorrectorParametersCollection coll
Definition: classes.h:10
std::map< TotemFramePosition, unsigned int > unknownSummary
VFATFrame::word getHptdcErrorFlag() const
VFATFrame::word getEC() const
Returns Event Counter (EV&lt;7:0&gt;).
Definition: VFATFrame.h:52
unsigned int hwID
the hardware ID (16 bit)
unsigned int testBCMostFrequent
std::map< TotemFramePosition, TotemVFATInfo > VFATMapping
void setEC(const uint8_t ec)
void Fill(word counter, TotemFramePosition fr)
add new value to map, counter takes value of EC or BC number
void setPartiallyMaskedOut()
std::set< unsigned char > maskedChannels
list of channels to be masked
std::map< TotemFramePosition, std::map< TotemVFATStatus, unsigned int > > errorSummary
error summaries
Detector ID class for CTPPS Timing Diamond detectors. Bits [19:31] : Assigend in CTPPSDetId Calss Bit...
bool IsEnd()
returns whether the iterator points over the end of the collection
void setIDMismatch(bool val=true)
bool isIDPresent() const
Returns true if the ID word is present in the frame.
Definition: VFATFrame.h:95
double EC_fraction
the minimal required (relative) occupancy of the most frequent counter value to be accepted ...
VFATFrame::word getChipID() const
Returns ChipID (ChipID&lt;11:0&gt;).
Definition: VFATFrame.h:64
void setChipPosition(uint8_t _cp)
virtual std::vector< unsigned char > getActiveChannels() const
Definition: VFATFrame.cc:38
TotemRPDetId getPlaneId() const
Definition: TotemRPDetId.h:73
void RunCommon(const VFATFrameCollection &input, const TotemDAQMapping &mapping, std::map< TotemFramePosition, Record > &records)
Common processing for all VFAT based sub-systems.
unsigned int EC_min
the minimal required number of frames to determine the most frequent counter value ...
tuple status
Definition: mps_update.py:57