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