CMS 3D CMS Logo

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