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 
25 
29 
35 using namespace std;
36 
37 //========================================================================
39  //========================================================================
40  : iEvent(0),
41 
42  // framework parameters with default values
43  _dataType(iConfig.getUntrackedParameter<std::string>("dataType", "h4")) // h4 or p5
44 
45 //========================================================================
46 
47 {
48  //now do what ever initialization is needed
49 
50  resdir_ = iConfig.getUntrackedParameter<std::string>("resDir");
51  statusfile_ = iConfig.getUntrackedParameter<std::string>("statusFile");
52 
53  eventHeaderCollection_ = iConfig.getParameter<std::string>("eventHeaderCollection");
54  eventHeaderProducer_ = iConfig.getParameter<std::string>("eventHeaderProducer");
55 }
56 
57 //========================================================================
59  //========================================================================
60 
61  // do anything here that needs to be done at desctruction time
62  // (e.g. close files, deallocate resources etc.)
63 }
64 
65 //========================================================================
67  //========================================================================
68 
69  // Initializations
70 
71  nSM = 0;
72  fedID = 0;
73  runType = -999;
74  runNum = -999;
75  event = 0;
76 }
77 
78 //========================================================================
80  //========================================================================
81 
82  ++iEvent;
83 
84  // retrieving DCC header
86  const EcalRawDataCollection* DCCHeader = nullptr;
87  try {
88  e.getByLabel(eventHeaderProducer_, eventHeaderCollection_, pDCCHeader);
89  DCCHeader = pDCCHeader.product();
90  } catch (std::exception& ex) {
91  std::cerr << "Error! can't get the product retrieving DCC header " << eventHeaderCollection_.c_str() << std::endl;
92  }
93 
94  // retrieving TB event header
95 
96  edm::Handle<EcalTBEventHeader> pEventHeader;
97  const EcalTBEventHeader* evtHeader = nullptr;
98  if (_dataType == "h4") {
99  try {
100  e.getByLabel(eventHeaderProducer_, pEventHeader);
101  evtHeader = pEventHeader.product(); // get a ptr to the product
102  } catch (std::exception& ex) {
103  std::cerr << "Error! can't get the product " << eventHeaderProducer_.c_str() << std::endl;
104  }
105 
106  timeStampCur = evtHeader->begBurstTimeSec();
107  nSM = evtHeader->smInBeam();
108  }
109 
110  // Get Timestamp
111 
112  edm::Timestamp Time = e.time();
113 
114  if (_dataType != "h4") {
115  timeStampCur = Time.value();
116  }
117 
118  // ====================================
119  // Decode Basic DCCHeader Information
120  // ====================================
121 
122  for (EcalRawDataCollection::const_iterator headerItr = DCCHeader->begin(); headerItr != DCCHeader->end();
123  ++headerItr) {
124  // Get run type and run number
125  runType = headerItr->getRunType();
126  runNum = headerItr->getRunNumber();
127  event = headerItr->getLV1();
128  dccID = headerItr->getDccInTCCCommand();
129  fedID = headerItr->fedId();
130 
131  short VFEGain = headerItr->getMgpaGain();
132  short MEMGain = headerItr->getMemGain();
133 
134  // Retrieve laser color and event number
135 
136  EcalDCCHeaderBlock::EcalDCCEventSettings settings = headerItr->getEventSettings();
137 
138  int laser_color = settings.wavelength;
139  int laser_power = settings.LaserPower;
140  int laser_filter = settings.LaserFilter;
141  int laser_delay = settings.delay;
142  if (laser_color < 0)
143  return;
144  // int laser_ = settings.MEMVinj;
145 
146  bool isLas = false;
147  bool isTP = false;
148  bool isPed = false;
149 
152  isLas = true;
153 
156  isTP = true;
157 
160  isPed = true;
161 
162  // take event only if the fed corresponds to the DCC in TCC
163  // and fill gain stuff with value of 1st event
164 
165  if (600 + dccID != fedID)
166  continue;
167 
168  bool doesExist = false;
169 
170  if ((isFedLasCreated.count(fedID) == 1 && isLas) || (isFedTPCreated.count(fedID) == 1 && isTP) ||
171  (isFedPedCreated.count(fedID) == 1 && isPed))
172  doesExist = true;
173  else if (isLas)
174  isFedLasCreated[fedID] = 1;
175  else if (isTP)
176  isFedTPCreated[fedID] = 1;
177  else if (isPed)
178  isFedPedCreated[fedID] = 1;
179 
180  if (!doesExist) {
181  // create new entry for laser
182 
183  if (isLas) {
184  fedIDsLas.push_back(fedID);
185  dccIDsLas.push_back(dccID);
186 
189 
190  nEvtsLas[fedID] = 1;
192 
193  if (laser_color == iBLUE) {
194  nBlueLas[fedID] = 1;
195  laserPowerBlue[fedID] = laser_power;
196  laserFilterBlue[fedID] = laser_filter;
197  laserDelayBlue[fedID] = laser_delay;
198  } else if (laser_color == iIR) {
199  nRedLas[fedID] = 1;
200  laserPowerRed[fedID] = laser_power;
201  laserFilterRed[fedID] = laser_filter;
202  laserDelayRed[fedID] = laser_delay;
203  }
204 
205  MGPAGainLas[fedID] = VFEGain;
207 
208  }
209 
210  // or create new entry for test-pulse
211  else if (isTP) {
212  fedIDsTP.push_back(fedID);
213  dccIDsTP.push_back(dccID);
214 
215  nEvtsTP[fedID] = 1;
217 
220 
221  MGPAGainTP[fedID] = VFEGain;
223 
224  // or create new entry for pedestal
225 
226  } else if (isPed) {
227  fedIDsPed.push_back(fedID);
228  dccIDsPed.push_back(dccID);
229 
230  nEvtsPed[fedID] = 1;
232 
235 
236  MGPAGainPed[fedID] = VFEGain;
238  }
239 
240  } else {
241  if (isLas) {
242  nEvtsLas[fedID]++;
243  if (laser_color == iBLUE)
244  nBlueLas[fedID]++;
245  else if (laser_color == iIR)
246  nRedLas[fedID]++;
247 
252 
253  } else if (isTP) {
254  nEvtsTP[fedID]++;
259  } else if (isPed) {
260  nEvtsPed[fedID]++;
265  }
266  }
267  }
268 
269 } // analyze
270 
271 //========================================================================
273  //========================================================================
274 
275  // Create output status file
276 
277  std::stringstream namefile;
278  namefile << resdir_ << "/" << statusfile_;
279 
280  string statusfile = namefile.str();
281 
282  std::ofstream statusFile(statusfile.c_str(), std::ofstream::out);
283 
284  if (!fedIDsLas.empty() && fedIDsLas.size() == dccIDsLas.size()) {
285  statusFile << "+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=" << std::endl;
286  statusFile << " LASER Events " << std::endl;
287  statusFile << "+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=" << std::endl;
288 
289  for (unsigned int i = 0; i < fedIDsLas.size(); i++) {
290  statusFile << "RUNTYPE = " << runTypeLas[fedIDsLas.at(i)] << std::endl;
291  statusFile << "FEDID = " << fedIDsLas.at(i) << std::endl;
292  statusFile << "DCCID = " << dccIDsLas.at(i) << std::endl;
293  statusFile << "TIMESTAMP_BEG = " << timeStampBegLas[fedIDsLas.at(i)] << std::endl;
294  statusFile << "TIMESTAMP_END = " << timeStampEndLas[fedIDsLas.at(i)] << std::endl;
295  statusFile << "MPGA_GAIN = " << MGPAGainLas[fedIDsLas.at(i)] << std::endl;
296  statusFile << "MEM_GAIN = " << MEMGainLas[fedIDsLas.at(i)] << std::endl;
297  statusFile << "EVENTS = " << nEvtsLas[fedIDsLas.at(i)] << std::endl;
298 
299  if (nBlueLas[fedIDsLas.at(i)] > 0) {
300  statusFile << " blue laser events = " << nBlueLas[fedIDsLas.at(i)] << std::endl;
301  statusFile << " blue laser power = " << laserPowerBlue[fedIDsLas.at(i)] << std::endl;
302  statusFile << " blue laser filter = " << laserFilterBlue[fedIDsLas.at(i)] << std::endl;
303  statusFile << " blue laser delay = " << laserDelayBlue[fedIDsLas.at(i)] << std::endl;
304  }
305 
306  if (nRedLas[fedIDsLas.at(i)] > 0) {
307  statusFile << " ired laser events = " << nRedLas[fedIDsLas.at(i)] << std::endl;
308  statusFile << " ired laser power = " << laserPowerRed[fedIDsLas.at(i)] << std::endl;
309  statusFile << " ired laser filter = " << laserFilterRed[fedIDsLas.at(i)] << std::endl;
310  statusFile << " ired laser delay = " << laserDelayRed[fedIDsLas.at(i)] << std::endl;
311  }
312 
313  if (i < fedIDsLas.size() - 1)
314  statusFile << "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=" << std::endl;
315  else
316  statusFile << " " << std::endl;
317  }
318  }
319 
320  if (!fedIDsTP.empty() && fedIDsTP.size() == dccIDsTP.size()) {
321  statusFile << "+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=" << std::endl;
322  statusFile << " TESTPULSE Events " << std::endl;
323  statusFile << "+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=" << std::endl;
324 
325  for (unsigned int i = 0; i < fedIDsTP.size(); i++) {
326  statusFile << "RUNTYPE = " << runTypeTP[fedIDsTP.at(i)] << std::endl;
327  statusFile << "FEDID = " << fedIDsTP.at(i) << std::endl;
328  statusFile << "DCCID = " << dccIDsTP.at(i) << std::endl;
329  statusFile << "TIMESTAMP_BEG = " << timeStampBegTP[fedIDsTP.at(i)] << std::endl;
330  statusFile << "TIMESTAMP_END = " << timeStampEndTP[fedIDsTP.at(i)] << std::endl;
331  statusFile << "MPGA_GAIN = " << MGPAGainTP[fedIDsTP.at(i)] << std::endl;
332  statusFile << "MEM_GAIN = " << MEMGainTP[fedIDsTP.at(i)] << std::endl;
333  statusFile << "EVENTS = " << nEvtsTP[fedIDsTP.at(i)] << std::endl;
334  if (i < fedIDsTP.size() - 1)
335  statusFile << "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=" << std::endl;
336  else
337  statusFile << " " << std::endl;
338  }
339  }
340 
341  if (!fedIDsPed.empty() && fedIDsPed.size() == dccIDsPed.size()) {
342  statusFile << "+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=" << std::endl;
343  statusFile << " PEDESTAL Events " << std::endl;
344  statusFile << "+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=" << std::endl;
345 
346  for (unsigned int i = 0; i < fedIDsPed.size(); i++) {
347  statusFile << "RUNTYPE = " << runTypePed[fedIDsPed.at(i)] << std::endl;
348  statusFile << "FEDID = " << fedIDsPed.at(i) << std::endl;
349  statusFile << "DCCID = " << dccIDsPed.at(i) << std::endl;
350  statusFile << "TIMESTAMP_BEG = " << timeStampBegPed[fedIDsPed.at(i)] << std::endl;
351  statusFile << "TIMESTAMP_END = " << timeStampEndPed[fedIDsPed.at(i)] << std::endl;
352  statusFile << "MPGA_GAIN = " << MGPAGainPed[fedIDsPed.at(i)] << std::endl;
353  statusFile << "MEM_GAIN = " << MEMGainPed[fedIDsPed.at(i)] << std::endl;
354  statusFile << "EVENTS = " << nEvtsPed[fedIDsPed.at(i)] << std::endl;
355  if (i < fedIDsPed.size() - 1)
356  statusFile << "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=" << std::endl;
357  else
358  statusFile << " " << std::endl;
359  }
360  }
361  statusFile << " ... header done" << std::endl;
362 
363  statusFile.close();
364 }
365 
std::map< int, int > nRedLas
std::map< int, int > laserDelayRed
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
std::vector< int > dccIDsPed
std::map< int, short > MGPAGainLas
std::map< int, int > laserPowerRed
std::map< int, int > runTypePed
std::vector< int > fedIDsTP
~EcalStatusAnalyzer() override
void analyze(const edm::Event &e, const edm::EventSetup &c) override
std::map< int, unsigned long long > timeStampEndTP
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
T const * product() const
Definition: Handle.h:70
void endJob() override
std::vector< T >::const_iterator const_iterator
std::map< int, unsigned long long > timeStampEndLas
std::string eventHeaderCollection_
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
T getUntrackedParameter(std::string const &, T const &) const
std::map< int, int > nEvtsTP
std::vector< int > fedIDsLas
int begBurstTimeSec() const
Returns the begin burst time (sec)
std::vector< int > fedIDsPed
int iEvent
Definition: GenABIO.cc:224
std::map< int, int > runTypeTP
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.
std::map< int, int > isFedTPCreated
const_iterator begin() const
std::map< int, int > laserDelayBlue
const_iterator end() const
std::map< int, int > laserFilterRed
std::map< int, short > MGPAGainPed
std::map< int, unsigned long long > timeStampEndPed
std::map< int, short > MEMGainPed
std::map< int, short > MGPAGainTP
void beginJob() override
std::vector< int > dccIDsLas
unsigned long long timeStampCur
std::map< int, int > nEvtsPed
std::map< int, int > laserFilterBlue
std::map< int, int > laserPowerBlue