00001 /* 00002 * \class EcalStatusAnalyzer 00003 * 00004 * $Date: 2012/02/09 10:07:37 $ 00005 * author: Julie Malcles - CEA/Saclay 00006 * author: Gautier Hamel De Monchenault - CEA/Saclay 00007 */ 00008 00009 #include "EcalStatusAnalyzer.h" 00010 00011 #include "TFile.h" 00012 #include "TTree.h" 00013 #include "TCut.h" 00014 #include "TPaveText.h" 00015 #include "TBranch.h" 00016 00017 #include <fstream> 00018 #include <iostream> 00019 #include <iomanip> 00020 #include <sstream> 00021 #include <ctime> 00022 00023 #include "FWCore/MessageLogger/interface/MessageLogger.h" 00024 #include <DataFormats/EcalDigi/interface/EcalDigiCollections.h> 00025 #include <FWCore/Utilities/interface/Exception.h> 00026 00027 #include <FWCore/Framework/interface/Event.h> 00028 #include <FWCore/Framework/interface/MakerMacros.h> 00029 #include <FWCore/ParameterSet/interface/ParameterSet.h> 00030 00031 #include <DataFormats/EcalDigi/interface/EcalDigiCollections.h> 00032 #include <DataFormats/EcalDetId/interface/EcalDetIdCollections.h> 00033 #include <DataFormats/EcalRawData/interface/EcalRawDataCollections.h> 00034 #include <TBDataFormats/EcalTBObjects/interface/EcalTBEventHeader.h> 00035 #include <DataFormats/Provenance/interface/Timestamp.h> 00036 using namespace std; 00037 00038 //======================================================================== 00039 EcalStatusAnalyzer::EcalStatusAnalyzer(const edm::ParameterSet& iConfig) 00040 //======================================================================== 00041 : 00042 iEvent(0), 00043 00044 // framework parameters with default values 00045 _dataType( iConfig.getUntrackedParameter< std::string >( "dataType", "h4" ) ) // h4 or p5 00046 00047 //======================================================================== 00048 00049 { 00050 00051 //now do what ever initialization is needed 00052 00053 resdir_ = iConfig.getUntrackedParameter<std::string>("resDir"); 00054 statusfile_ = iConfig.getUntrackedParameter<std::string>("statusFile"); 00055 00056 eventHeaderCollection_ = iConfig.getParameter<std::string>("eventHeaderCollection"); 00057 eventHeaderProducer_ = iConfig.getParameter<std::string>("eventHeaderProducer"); 00058 00059 } 00060 00061 00062 //======================================================================== 00063 EcalStatusAnalyzer::~EcalStatusAnalyzer(){ 00064 //======================================================================== 00065 00066 00067 // do anything here that needs to be done at desctruction time 00068 // (e.g. close files, deallocate resources etc.) 00069 00070 } 00071 00072 00073 00074 //======================================================================== 00075 void EcalStatusAnalyzer::beginJob() { 00076 //======================================================================== 00077 00078 00079 00080 // Initializations 00081 00082 00083 nSM=0; 00084 fedID=0; 00085 runType=-999; 00086 runNum=-999; 00087 event=0; 00088 00089 00090 } 00091 00092 00093 //======================================================================== 00094 void EcalStatusAnalyzer:: analyze( const edm::Event & e, const edm::EventSetup& c){ 00095 //======================================================================== 00096 00097 ++iEvent; 00098 00099 // retrieving DCC header 00100 edm::Handle<EcalRawDataCollection> pDCCHeader; 00101 const EcalRawDataCollection* DCCHeader=0; 00102 try { 00103 e.getByLabel(eventHeaderProducer_,eventHeaderCollection_, pDCCHeader); 00104 DCCHeader=pDCCHeader.product(); 00105 }catch ( std::exception& ex ) { 00106 std::cerr << "Error! can't get the product retrieving DCC header " << eventHeaderCollection_.c_str() << std::endl; 00107 } 00108 00109 // retrieving TB event header 00110 00111 edm::Handle<EcalTBEventHeader> pEventHeader; 00112 const EcalTBEventHeader* evtHeader=0; 00113 if ( _dataType == "h4" ){ 00114 try { 00115 e.getByLabel( eventHeaderProducer_ , pEventHeader ); 00116 evtHeader = pEventHeader.product(); // get a ptr to the product 00117 } catch ( std::exception& ex ) { 00118 std::cerr << "Error! can't get the product " << eventHeaderProducer_.c_str() << std::endl; 00119 } 00120 00121 timeStampCur=evtHeader->begBurstTimeSec(); 00122 nSM=evtHeader->smInBeam(); 00123 00124 } 00125 00126 // Get Timestamp 00127 00128 edm::Timestamp Time=e.time(); 00129 00130 if ( _dataType != "h4" ){ 00131 timeStampCur = Time.value(); 00132 } 00133 00134 // ==================================== 00135 // Decode Basic DCCHeader Information 00136 // ==================================== 00137 00138 for ( EcalRawDataCollection::const_iterator headerItr= DCCHeader->begin();headerItr != DCCHeader->end(); 00139 ++headerItr ) { 00140 00141 // Get run type and run number 00142 runType=headerItr->getRunType(); 00143 runNum=headerItr->getRunNumber(); 00144 event=headerItr->getLV1(); 00145 dccID=headerItr->getDccInTCCCommand(); 00146 fedID=headerItr->fedId(); 00147 00148 short VFEGain=headerItr->getMgpaGain() ; 00149 short MEMGain=headerItr->getMemGain() ; 00150 00151 00152 // Retrieve laser color and event number 00153 00154 EcalDCCHeaderBlock::EcalDCCEventSettings settings = headerItr->getEventSettings(); 00155 00156 int laser_color = settings.wavelength; 00157 int laser_power = settings.LaserPower ; 00158 int laser_filter = settings.LaserFilter ; 00159 int laser_delay = settings.delay ; 00160 if( laser_color <0 ) return; 00161 // int laser_ = settings.MEMVinj; 00162 00163 bool isLas=false; 00164 bool isTP=false; 00165 bool isPed=false; 00166 00167 if(runType==EcalDCCHeaderBlock::LASER_STD || runType==EcalDCCHeaderBlock::LASER_GAP 00168 || runType==EcalDCCHeaderBlock::LASER_POWER_SCAN || runType==EcalDCCHeaderBlock::LASER_DELAY_SCAN) isLas=true; 00169 00170 else if(runType==EcalDCCHeaderBlock::TESTPULSE_MGPA || runType==EcalDCCHeaderBlock::TESTPULSE_GAP 00171 || runType==EcalDCCHeaderBlock::TESTPULSE_SCAN_MEM ) isTP=true; 00172 00173 else if(runType==EcalDCCHeaderBlock::PEDESTAL_STD || runType==EcalDCCHeaderBlock::PEDESTAL_OFFSET_SCAN 00174 || runType==EcalDCCHeaderBlock::PEDESTAL_25NS_SCAN ) isPed=true; 00175 00176 00177 // take event only if the fed corresponds to the DCC in TCC 00178 // and fill gain stuff with value of 1st event 00179 00180 00181 if( 600+dccID != fedID ) continue; 00182 00183 00184 bool doesExist=false; 00185 00186 if( (isFedLasCreated.count(fedID)==1 && isLas ) || ( isFedTPCreated.count(fedID)==1 && isTP ) || ( isFedPedCreated.count(fedID)==1 && isPed )) doesExist=true; 00187 else if(isLas) isFedLasCreated[fedID]=1; 00188 else if(isTP) isFedTPCreated[fedID]=1; 00189 else if(isPed) isFedPedCreated[fedID]=1; 00190 00191 00192 00193 if(!doesExist){ 00194 00195 // create new entry for laser 00196 00197 if (isLas){ 00198 00199 fedIDsLas.push_back(fedID); 00200 dccIDsLas.push_back(dccID); 00201 00202 timeStampBegLas[fedID]=timeStampCur; 00203 timeStampEndLas[fedID]=timeStampCur; 00204 00205 nEvtsLas[fedID]=1; 00206 runTypeLas[fedID]=runType; 00207 00208 if (laser_color==iBLUE) { 00209 nBlueLas[fedID]=1; 00210 laserPowerBlue[fedID] = laser_power; 00211 laserFilterBlue[fedID]= laser_filter; 00212 laserDelayBlue[fedID] = laser_delay; 00213 }else if (laser_color==iIR) { 00214 nRedLas[fedID]=1; 00215 laserPowerRed[fedID] = laser_power; 00216 laserFilterRed[fedID]= laser_filter; 00217 laserDelayRed[fedID] = laser_delay; 00218 } 00219 00220 MGPAGainLas[fedID]=VFEGain; 00221 MEMGainLas[fedID]=MEMGain; 00222 00223 00224 } 00225 00226 // or create new entry for test-pulse 00227 else if (isTP){ 00228 00229 fedIDsTP.push_back(fedID); 00230 dccIDsTP.push_back(dccID); 00231 00232 nEvtsTP[fedID]=1; 00233 runTypeTP[fedID]=runType; 00234 00235 timeStampBegTP[fedID]=timeStampCur; 00236 timeStampEndTP[fedID]=timeStampCur; 00237 00238 MGPAGainTP[fedID]=VFEGain; 00239 MEMGainTP[fedID]=MEMGain; 00240 00241 // or create new entry for pedestal 00242 00243 } else if (isPed){ 00244 00245 fedIDsPed.push_back(fedID); 00246 dccIDsPed.push_back(dccID); 00247 00248 nEvtsPed[fedID]=1; 00249 runTypePed[fedID]=runType; 00250 00251 timeStampBegPed[fedID]=timeStampCur; 00252 timeStampEndPed[fedID]=timeStampCur; 00253 00254 MGPAGainPed[fedID]=VFEGain; 00255 MEMGainPed[fedID]=MEMGain; 00256 00257 } 00258 00259 }else{ 00260 if (isLas){ 00261 nEvtsLas[fedID]++; 00262 if (laser_color==iBLUE)nBlueLas[fedID]++; 00263 else if (laser_color==iIR)nRedLas[fedID]++; 00264 00265 if(timeStampCur<timeStampBegLas[fedID])timeStampBegLas[fedID]=timeStampCur; 00266 if(timeStampCur>timeStampEndLas[fedID])timeStampEndLas[fedID]=timeStampCur; 00267 00268 }else if (isTP){ 00269 nEvtsTP[fedID]++; 00270 if(timeStampCur<timeStampBegTP[fedID])timeStampBegTP[fedID]=timeStampCur; 00271 if(timeStampCur>timeStampEndTP[fedID])timeStampEndTP[fedID]=timeStampCur; 00272 }else if (isPed){ 00273 nEvtsPed[fedID]++; 00274 if(timeStampCur<timeStampBegPed[fedID])timeStampBegPed[fedID]=timeStampCur; 00275 if(timeStampCur>timeStampEndPed[fedID])timeStampEndPed[fedID]=timeStampCur; 00276 } 00277 } 00278 } 00279 00280 }// analyze 00281 00282 00283 //======================================================================== 00284 void EcalStatusAnalyzer::endJob() { 00285 //======================================================================== 00286 00287 // Create output status file 00288 00289 std::stringstream namefile; 00290 namefile << resdir_ <<"/"<<statusfile_; 00291 00292 string statusfile=namefile.str(); 00293 00294 ofstream statusFile(statusfile.c_str(), ofstream::out); 00295 00296 00297 if(fedIDsLas.size()!=0 && fedIDsLas.size()==dccIDsLas.size()){ 00298 00299 statusFile <<"+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+="<<std::endl; 00300 statusFile <<" LASER Events "<<std::endl; 00301 statusFile <<"+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+="<<std::endl; 00302 00303 for(unsigned int i=0;i<fedIDsLas.size();i++){ 00304 00305 statusFile <<"RUNTYPE = "<< runTypeLas[fedIDsLas.at(i)]<< std::endl; 00306 statusFile <<"FEDID = "<< fedIDsLas.at(i) << std::endl; 00307 statusFile <<"DCCID = "<< dccIDsLas.at(i) << std::endl; 00308 statusFile <<"TIMESTAMP_BEG = "<<timeStampBegLas[fedIDsLas.at(i)] << std::endl; 00309 statusFile <<"TIMESTAMP_END = "<<timeStampEndLas[fedIDsLas.at(i)] << std::endl; 00310 statusFile <<"MPGA_GAIN = "<<MGPAGainLas[fedIDsLas.at(i)] << std::endl; 00311 statusFile <<"MEM_GAIN = "<<MEMGainLas[fedIDsLas.at(i)] << std::endl; 00312 statusFile <<"EVENTS = "<< nEvtsLas[fedIDsLas.at(i)]<< std::endl; 00313 00314 if(nBlueLas[fedIDsLas.at(i)]>0){ 00315 statusFile <<" blue laser events = "<< nBlueLas[fedIDsLas.at(i)]<< std::endl; 00316 statusFile <<" blue laser power = "<< laserPowerBlue[fedIDsLas.at(i)]<< std::endl; 00317 statusFile <<" blue laser filter = "<< laserFilterBlue[fedIDsLas.at(i)]<< std::endl; 00318 statusFile <<" blue laser delay = "<< laserDelayBlue[fedIDsLas.at(i)]<< std::endl; 00319 } 00320 00321 if(nRedLas[fedIDsLas.at(i)]>0){ 00322 statusFile <<" ired laser events = "<< nRedLas[fedIDsLas.at(i)]<< std::endl; 00323 statusFile <<" ired laser power = "<< laserPowerRed[fedIDsLas.at(i)]<< std::endl; 00324 statusFile <<" ired laser filter = "<< laserFilterRed[fedIDsLas.at(i)]<< std::endl; 00325 statusFile <<" ired laser delay = "<< laserDelayRed[fedIDsLas.at(i)]<< std::endl; 00326 } 00327 00328 if(i<fedIDsLas.size()-1) statusFile <<"-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="<<std::endl; 00329 else statusFile <<" "<<std::endl; 00330 } 00331 } 00332 00333 if(fedIDsTP.size()!=0 && fedIDsTP.size()==dccIDsTP.size()){ 00334 00335 statusFile <<"+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+="<<std::endl; 00336 statusFile <<" TESTPULSE Events "<<std::endl; 00337 statusFile <<"+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+="<<std::endl; 00338 00339 for(unsigned int i=0;i<fedIDsTP.size();i++){ 00340 00341 statusFile <<"RUNTYPE = "<< runTypeTP[fedIDsTP.at(i)]<< std::endl; 00342 statusFile <<"FEDID = "<< fedIDsTP.at(i) << std::endl; 00343 statusFile <<"DCCID = "<< dccIDsTP.at(i) << std::endl; 00344 statusFile <<"TIMESTAMP_BEG = "<<timeStampBegTP[fedIDsTP.at(i)] << std::endl; 00345 statusFile <<"TIMESTAMP_END = "<<timeStampEndTP[fedIDsTP.at(i)] << std::endl; 00346 statusFile <<"MPGA_GAIN = "<<MGPAGainTP[fedIDsTP.at(i)] << std::endl; 00347 statusFile <<"MEM_GAIN = "<<MEMGainTP[fedIDsTP.at(i)] << std::endl; 00348 statusFile <<"EVENTS = "<< nEvtsTP[fedIDsTP.at(i)]<< std::endl; 00349 if(i<fedIDsTP.size()-1) statusFile <<"-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="<<std::endl; 00350 else statusFile <<" "<<std::endl; 00351 } 00352 } 00353 00354 if(fedIDsPed.size()!=0 && fedIDsPed.size()==dccIDsPed.size()){ 00355 00356 statusFile <<"+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+="<<std::endl; 00357 statusFile <<" PEDESTAL Events "<<std::endl; 00358 statusFile <<"+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+="<<std::endl; 00359 00360 for(unsigned int i=0;i<fedIDsPed.size();i++){ 00361 00362 statusFile <<"RUNTYPE = "<< runTypePed[fedIDsPed.at(i)]<< std::endl; 00363 statusFile <<"FEDID = "<< fedIDsPed.at(i) << std::endl; 00364 statusFile <<"DCCID = "<< dccIDsPed.at(i) << std::endl; 00365 statusFile <<"TIMESTAMP_BEG = "<<timeStampBegPed[fedIDsPed.at(i)] << std::endl; 00366 statusFile <<"TIMESTAMP_END = "<<timeStampEndPed[fedIDsPed.at(i)] << std::endl; 00367 statusFile <<"MPGA_GAIN = "<<MGPAGainPed[fedIDsPed.at(i)] << std::endl; 00368 statusFile <<"MEM_GAIN = "<<MEMGainPed[fedIDsPed.at(i)] << std::endl; 00369 statusFile <<"EVENTS = "<< nEvtsPed[fedIDsPed.at(i)]<< std::endl; 00370 if(i<fedIDsPed.size()-1) statusFile <<"-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="<<std::endl; 00371 else statusFile <<" "<<std::endl; 00372 } 00373 } 00374 statusFile <<" ... header done"<<std::endl; 00375 00376 statusFile.close(); 00377 00378 } 00379 00380 00381 DEFINE_FWK_MODULE(EcalStatusAnalyzer); 00382