CMS 3D CMS Logo

EcalStatusAnalyzer.cc
Go to the documentation of this file.
1 /*
2  * \class EcalStatusAnalyzer
3  *
4  * author: Julie Malcles - CEA/Saclay
5  * author: Gautier Hamel De Monchenault - CEA/Saclay
6  */
7 
8 #include "EcalStatusAnalyzer.h"
9 
10 #include "TFile.h"
11 #include "TTree.h"
12 #include "TCut.h"
13 #include "TPaveText.h"
14 #include "TBranch.h"
15 
16 #include <fstream>
17 #include <iostream>
18 #include <iomanip>
19 #include <sstream>
20 #include <ctime>
21 
24 
28 
31 
32 //========================================================================
34  //========================================================================
35  : iEvent(0),
36 
37  // framework parameters with default values
38  _dataType(iConfig.getUntrackedParameter<std::string>("dataType", "h4")), // h4 or p5
39  resdir_(iConfig.getUntrackedParameter<std::string>("resDir")),
40  statusfile_(iConfig.getUntrackedParameter<std::string>("statusFile")),
41  eventHeaderCollection_(iConfig.getParameter<std::string>("eventHeaderCollection")),
42  eventHeaderProducer_(iConfig.getParameter<std::string>("eventHeaderProducer")),
43  dccToken_(consumes<EcalRawDataCollection>(edm::InputTag(eventHeaderProducer_, eventHeaderCollection_))),
44  headToken_(consumes<EcalTBEventHeader>(edm::InputTag(eventHeaderProducer_)))
45 //========================================================================
46 
47 {
48  //now do what ever initialization is needed
49 }
50 
51 //========================================================================
53  //========================================================================
54 
55  // Initializations
56 
57  nSM = 0;
58  fedID = 0;
59  runType = -999;
60  runNum = -999;
61  event = 0;
62 }
63 
64 //========================================================================
66  //========================================================================
67 
68  ++iEvent;
69 
70  // retrieving DCC header
71  const edm::Handle<EcalRawDataCollection>& pDCCHeader = e.getHandle(dccToken_);
72  const EcalRawDataCollection* DCCHeader = (pDCCHeader.isValid()) ? pDCCHeader.product() : nullptr;
73  if (!pDCCHeader.isValid()) {
74  edm::LogWarning("EcalStatusAnalyzer")
75  << "Error! can't get the product retrieving DCC header " << eventHeaderCollection_.c_str();
76  }
77 
78  // retrieving TB event header
79 
80  const edm::Handle<EcalTBEventHeader>& pEventHeader = e.getHandle(headToken_);
81  const EcalTBEventHeader* evtHeader = (pEventHeader.isValid()) ? pEventHeader.product() : nullptr;
82  if (_dataType == "h4") {
83  if (!pEventHeader.isValid()) {
84  edm::LogWarning("EcalStatusAnalyzer") << "Error! can't get the product " << eventHeaderProducer_.c_str();
85  }
86  timeStampCur = evtHeader->begBurstTimeSec();
87  nSM = evtHeader->smInBeam();
88  }
89 
90  // Get Timestamp
91 
92  edm::Timestamp Time = e.time();
93 
94  if (_dataType != "h4") {
95  timeStampCur = Time.value();
96  }
97 
98  // ====================================
99  // Decode Basic DCCHeader Information
100  // ====================================
101 
102  for (EcalRawDataCollection::const_iterator headerItr = DCCHeader->begin(); headerItr != DCCHeader->end();
103  ++headerItr) {
104  // Get run type and run number
105  runType = headerItr->getRunType();
106  runNum = headerItr->getRunNumber();
107  event = headerItr->getLV1();
108  dccID = headerItr->getDccInTCCCommand();
109  fedID = headerItr->fedId();
110 
111  short VFEGain = headerItr->getMgpaGain();
112  short MEMGain = headerItr->getMemGain();
113 
114  // Retrieve laser color and event number
115 
116  EcalDCCHeaderBlock::EcalDCCEventSettings settings = headerItr->getEventSettings();
117 
118  int laser_color = settings.wavelength;
119  int laser_power = settings.LaserPower;
120  int laser_filter = settings.LaserFilter;
121  int laser_delay = settings.delay;
122  if (laser_color < 0)
123  return;
124  // int laser_ = settings.MEMVinj;
125 
126  bool isLas = false;
127  bool isTP = false;
128  bool isPed = false;
129 
132  isLas = true;
133 
136  isTP = true;
137 
140  isPed = true;
141 
142  // take event only if the fed corresponds to the DCC in TCC
143  // and fill gain stuff with value of 1st event
144 
145  if (600 + dccID != fedID)
146  continue;
147 
148  bool doesExist = false;
149 
150  if ((isFedLasCreated.count(fedID) == 1 && isLas) || (isFedTPCreated.count(fedID) == 1 && isTP) ||
151  (isFedPedCreated.count(fedID) == 1 && isPed))
152  doesExist = true;
153  else if (isLas)
154  isFedLasCreated[fedID] = 1;
155  else if (isTP)
156  isFedTPCreated[fedID] = 1;
157  else if (isPed)
158  isFedPedCreated[fedID] = 1;
159 
160  if (!doesExist) {
161  // create new entry for laser
162 
163  if (isLas) {
164  fedIDsLas.push_back(fedID);
165  dccIDsLas.push_back(dccID);
166 
169 
170  nEvtsLas[fedID] = 1;
172 
173  if (laser_color == iBLUE) {
174  nBlueLas[fedID] = 1;
175  laserPowerBlue[fedID] = laser_power;
176  laserFilterBlue[fedID] = laser_filter;
177  laserDelayBlue[fedID] = laser_delay;
178  } else if (laser_color == iIR) {
179  nRedLas[fedID] = 1;
180  laserPowerRed[fedID] = laser_power;
181  laserFilterRed[fedID] = laser_filter;
182  laserDelayRed[fedID] = laser_delay;
183  }
184 
185  MGPAGainLas[fedID] = VFEGain;
187 
188  }
189 
190  // or create new entry for test-pulse
191  else if (isTP) {
192  fedIDsTP.push_back(fedID);
193  dccIDsTP.push_back(dccID);
194 
195  nEvtsTP[fedID] = 1;
197 
200 
201  MGPAGainTP[fedID] = VFEGain;
203 
204  // or create new entry for pedestal
205 
206  } else if (isPed) {
207  fedIDsPed.push_back(fedID);
208  dccIDsPed.push_back(dccID);
209 
210  nEvtsPed[fedID] = 1;
212 
215 
216  MGPAGainPed[fedID] = VFEGain;
218  }
219 
220  } else {
221  if (isLas) {
222  nEvtsLas[fedID]++;
223  if (laser_color == iBLUE)
224  nBlueLas[fedID]++;
225  else if (laser_color == iIR)
226  nRedLas[fedID]++;
227 
232 
233  } else if (isTP) {
234  nEvtsTP[fedID]++;
239  } else if (isPed) {
240  nEvtsPed[fedID]++;
245  }
246  }
247  }
248 
249 } // analyze
250 
251 //========================================================================
253  //========================================================================
254 
255  // Create output status file
256 
257  std::stringstream namefile;
258  namefile << resdir_ << "/" << statusfile_;
259 
260  std::string statusfile = namefile.str();
261 
262  std::ofstream statusFile(statusfile.c_str(), std::ofstream::out);
263 
264  if (!fedIDsLas.empty() && fedIDsLas.size() == dccIDsLas.size()) {
265  statusFile << "+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=" << std::endl;
266  statusFile << " LASER Events " << std::endl;
267  statusFile << "+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=" << std::endl;
268 
269  for (unsigned int i = 0; i < fedIDsLas.size(); i++) {
270  statusFile << "RUNTYPE = " << runTypeLas[fedIDsLas.at(i)] << std::endl;
271  statusFile << "FEDID = " << fedIDsLas.at(i) << std::endl;
272  statusFile << "DCCID = " << dccIDsLas.at(i) << std::endl;
273  statusFile << "TIMESTAMP_BEG = " << timeStampBegLas[fedIDsLas.at(i)] << std::endl;
274  statusFile << "TIMESTAMP_END = " << timeStampEndLas[fedIDsLas.at(i)] << std::endl;
275  statusFile << "MPGA_GAIN = " << MGPAGainLas[fedIDsLas.at(i)] << std::endl;
276  statusFile << "MEM_GAIN = " << MEMGainLas[fedIDsLas.at(i)] << std::endl;
277  statusFile << "EVENTS = " << nEvtsLas[fedIDsLas.at(i)] << std::endl;
278 
279  if (nBlueLas[fedIDsLas.at(i)] > 0) {
280  statusFile << " blue laser events = " << nBlueLas[fedIDsLas.at(i)] << std::endl;
281  statusFile << " blue laser power = " << laserPowerBlue[fedIDsLas.at(i)] << std::endl;
282  statusFile << " blue laser filter = " << laserFilterBlue[fedIDsLas.at(i)] << std::endl;
283  statusFile << " blue laser delay = " << laserDelayBlue[fedIDsLas.at(i)] << std::endl;
284  }
285 
286  if (nRedLas[fedIDsLas.at(i)] > 0) {
287  statusFile << " ired laser events = " << nRedLas[fedIDsLas.at(i)] << std::endl;
288  statusFile << " ired laser power = " << laserPowerRed[fedIDsLas.at(i)] << std::endl;
289  statusFile << " ired laser filter = " << laserFilterRed[fedIDsLas.at(i)] << std::endl;
290  statusFile << " ired laser delay = " << laserDelayRed[fedIDsLas.at(i)] << std::endl;
291  }
292 
293  if (i < fedIDsLas.size() - 1)
294  statusFile << "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=" << std::endl;
295  else
296  statusFile << " " << std::endl;
297  }
298  }
299 
300  if (!fedIDsTP.empty() && fedIDsTP.size() == dccIDsTP.size()) {
301  statusFile << "+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=" << std::endl;
302  statusFile << " TESTPULSE Events " << std::endl;
303  statusFile << "+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=" << std::endl;
304 
305  for (unsigned int i = 0; i < fedIDsTP.size(); i++) {
306  statusFile << "RUNTYPE = " << runTypeTP[fedIDsTP.at(i)] << std::endl;
307  statusFile << "FEDID = " << fedIDsTP.at(i) << std::endl;
308  statusFile << "DCCID = " << dccIDsTP.at(i) << std::endl;
309  statusFile << "TIMESTAMP_BEG = " << timeStampBegTP[fedIDsTP.at(i)] << std::endl;
310  statusFile << "TIMESTAMP_END = " << timeStampEndTP[fedIDsTP.at(i)] << std::endl;
311  statusFile << "MPGA_GAIN = " << MGPAGainTP[fedIDsTP.at(i)] << std::endl;
312  statusFile << "MEM_GAIN = " << MEMGainTP[fedIDsTP.at(i)] << std::endl;
313  statusFile << "EVENTS = " << nEvtsTP[fedIDsTP.at(i)] << std::endl;
314  if (i < fedIDsTP.size() - 1)
315  statusFile << "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=" << std::endl;
316  else
317  statusFile << " " << std::endl;
318  }
319  }
320 
321  if (!fedIDsPed.empty() && fedIDsPed.size() == dccIDsPed.size()) {
322  statusFile << "+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=" << std::endl;
323  statusFile << " PEDESTAL Events " << std::endl;
324  statusFile << "+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=" << std::endl;
325 
326  for (unsigned int i = 0; i < fedIDsPed.size(); i++) {
327  statusFile << "RUNTYPE = " << runTypePed[fedIDsPed.at(i)] << std::endl;
328  statusFile << "FEDID = " << fedIDsPed.at(i) << std::endl;
329  statusFile << "DCCID = " << dccIDsPed.at(i) << std::endl;
330  statusFile << "TIMESTAMP_BEG = " << timeStampBegPed[fedIDsPed.at(i)] << std::endl;
331  statusFile << "TIMESTAMP_END = " << timeStampEndPed[fedIDsPed.at(i)] << std::endl;
332  statusFile << "MPGA_GAIN = " << MGPAGainPed[fedIDsPed.at(i)] << std::endl;
333  statusFile << "MEM_GAIN = " << MEMGainPed[fedIDsPed.at(i)] << std::endl;
334  statusFile << "EVENTS = " << nEvtsPed[fedIDsPed.at(i)] << std::endl;
335  if (i < fedIDsPed.size() - 1)
336  statusFile << "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=" << std::endl;
337  else
338  statusFile << " " << std::endl;
339  }
340  }
341  statusFile << " ... header done" << std::endl;
342 
343  statusFile.close();
344 }
345 
std::map< int, int > nRedLas
std::map< int, int > laserDelayRed
std::vector< int > dccIDsPed
std::map< int, short > MGPAGainLas
std::map< int, int > laserPowerRed
std::map< int, int > runTypePed
std::vector< int > fedIDsTP
void analyze(const edm::Event &e, const edm::EventSetup &c) override
std::map< int, unsigned long long > timeStampEndTP
T const * product() const
Definition: Handle.h:70
void endJob() override
std::vector< T >::const_iterator const_iterator
const std::string eventHeaderCollection_
std::map< int, unsigned long long > timeStampEndLas
std::map< int, short > MEMGainTP
std::map< int, int > nEvtsLas
EcalStatusAnalyzer(const edm::ParameterSet &iConfig)
std::map< int, unsigned long long > timeStampBegTP
std::map< int, int > isFedLasCreated
std::vector< int > dccIDsTP
std::map< int, short > MEMGainLas
std::map< int, int > isFedPedCreated
std::map< int, unsigned long long > timeStampBegPed
std::map< int, int > nEvtsTP
std::vector< int > fedIDsLas
const std::string statusfile_
int begBurstTimeSec() const
Returns the begin burst time (sec)
std::vector< int > fedIDsPed
int iEvent
Definition: GenABIO.cc:224
std::map< int, int > runTypeTP
const std::string eventHeaderProducer_
std::map< int, int > runTypeLas
std::map< int, unsigned long long > timeStampBegLas
std::map< int, int > nBlueLas
short smInBeam() const
Returns the burst number.
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::map< int, int > isFedTPCreated
const_iterator begin() const
std::map< int, int > laserDelayBlue
const std::string _dataType
const_iterator end() const
const edm::EDGetTokenT< EcalTBEventHeader > headToken_
std::map< int, int > laserFilterRed
std::map< int, short > MGPAGainPed
std::map< int, unsigned long long > timeStampEndPed
const std::string resdir_
std::map< int, short > MEMGainPed
bool isValid() const
Definition: HandleBase.h:70
std::map< int, short > MGPAGainTP
void beginJob() override
HLT enums.
std::vector< int > dccIDsLas
unsigned long long timeStampCur
const edm::EDGetTokenT< EcalRawDataCollection > dccToken_
Log< level::Warning, false > LogWarning
std::map< int, int > nEvtsPed
std::map< int, int > laserFilterBlue
std::map< int, int > laserPowerBlue