CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/CalibCalorimetry/EcalLaserAnalyzer/plugins/EcalPerEvtMatacqAnalyzer.cc

Go to the documentation of this file.
00001 /* 
00002  *  \class EcalPerEvtMatacqAnalyzer
00003  *
00004  *  $Date: 2012/02/09 10:07:37 $
00005  *  primary author: Gautier Hamel De Monchenault - CEA/Saclay
00006  *  author: Julie Malcles - CEA/Saclay
00007  */
00008 
00009 #include <TFile.h>
00010 #include <TTree.h>
00011 #include <TChain.h>
00012 
00013 #include "EcalPerEvtMatacqAnalyzer.h"
00014 
00015 #include <sstream>
00016 #include <iostream>
00017 #include <iomanip>
00018 
00019 #include <FWCore/MessageLogger/interface/MessageLogger.h>
00020 #include <FWCore/Utilities/interface/Exception.h>
00021 
00022 #include <FWCore/Framework/interface/Event.h>
00023 #include <FWCore/Framework/interface/MakerMacros.h>
00024 #include <FWCore/ParameterSet/interface/ParameterSet.h>
00025 #include <FWCore/Framework/interface/EventSetup.h>
00026 
00027 #include <DataFormats/EcalDigi/interface/EcalDigiCollections.h>
00028 #include <DataFormats/EcalDetId/interface/EcalDetIdCollections.h>
00029 #include <DataFormats/EcalRawData/interface/EcalRawDataCollections.h>
00030 
00031 
00032 using namespace std;
00033 
00034 //========================================================================
00035 EcalPerEvtMatacqAnalyzer::EcalPerEvtMatacqAnalyzer(const edm::ParameterSet& iConfig)
00036   :
00037   iEvent(0),
00038   // framework parameters with default values
00039 
00040   _presample(     iConfig.getUntrackedParameter< double       >( "nPresamples",   6.7 ) ),
00041   _nsamplesaftmax(iConfig.getUntrackedParameter< unsigned int >( "nSamplesAftMax", 80 ) ),
00042   _nsamplesbefmax(iConfig.getUntrackedParameter< unsigned int >( "nSamplesBefMax", 20 ) ),
00043   _noiseCut(      iConfig.getUntrackedParameter< unsigned int >( "noiseCut",        7 ) ),
00044   _parabnbefmax(  iConfig.getUntrackedParameter< unsigned int >( "paraBeforeMax",   8 ) ),
00045   _parabnaftmax(  iConfig.getUntrackedParameter< unsigned int >( "paraAfterMax",    7 ) ),
00046   _thres(         iConfig.getUntrackedParameter< unsigned int >( "threshold",      10 ) ),
00047   _lowlev(        iConfig.getUntrackedParameter< unsigned int >( "lowLevel",       20 ) ),
00048   _highlev(       iConfig.getUntrackedParameter< unsigned int >( "highLevel",      80 ) ),
00049   _nevlasers(     iConfig.getUntrackedParameter< unsigned int >( "nEventLaser",   600 ) )
00050 
00051 //========================================================================
00052 {
00053 
00054 
00055   //now do what ever initialization is needed
00056 
00057   resdir_                 = iConfig.getUntrackedParameter<std::string>("resDir");
00058 
00059   digiCollection_         = iConfig.getParameter<std::string>("digiCollection");
00060   digiProducer_           = iConfig.getParameter<std::string>("digiProducer");
00061   
00062   eventHeaderCollection_  = iConfig.getParameter<std::string>("eventHeaderCollection");
00063   eventHeaderProducer_    = iConfig.getParameter<std::string>("eventHeaderProducer");
00064 
00065 }
00066 
00067 //========================================================================
00068 EcalPerEvtMatacqAnalyzer::~EcalPerEvtMatacqAnalyzer(){
00069 //========================================================================
00070 
00071   // do anything here that needs to be done at desctruction time
00072   // (e.g. close files, deallocate resources etc.)
00073 
00074 }
00075 
00076 
00077 
00078 //========================================================================
00079 void EcalPerEvtMatacqAnalyzer::beginJob() {
00080 //========================================================================
00081 
00082     //Initializations
00083 
00084     IsFileCreated=0;
00085     IsTreeCreated=0;
00086 
00087 }
00088 
00089 
00090 //========================================================================
00091 void EcalPerEvtMatacqAnalyzer:: analyze( const edm::Event & e, const  edm::EventSetup& c){
00092 //========================================================================
00093 
00094   ++iEvent;
00095 
00096   // retrieving MATACQ :
00097   edm::Handle<EcalMatacqDigiCollection> pmatacqDigi;
00098   const EcalMatacqDigiCollection* matacqDigi=0;
00099   try {
00100     e.getByLabel(digiProducer_,digiCollection_, pmatacqDigi); 
00101     matacqDigi=pmatacqDigi.product();
00102   }catch ( std::exception& ex ) {
00103     std::cerr << "Error! can't get the product " << digiCollection_.c_str() << std::endl;
00104 
00105   }
00106   
00107   // retrieving DCC header
00108 
00109   edm::Handle<EcalRawDataCollection> pDCCHeader;
00110   const  EcalRawDataCollection* DCCHeader=0;
00111   try {
00112      e.getByLabel(digiProducer_, pDCCHeader); 
00113      //e.getByLabel(eventHeaderProducer_,eventHeaderCollection_, pDCCHeader);
00114     DCCHeader=pDCCHeader.product();
00115   }catch ( std::exception& ex ) {
00116     std::cerr << "Error! can't get the product " << eventHeaderCollection_.c_str() << std::endl;
00117   }
00118 
00119 
00120   // ====================================
00121   // Decode Basic DCCHeader Information 
00122   // ====================================
00123 
00124   for ( EcalRawDataCollection::const_iterator headerItr= DCCHeader->begin();headerItr != DCCHeader->end(); 
00125     ++headerItr ) {
00126     event=headerItr->getLV1();
00127     EcalDCCHeaderBlock::EcalDCCEventSettings settings = headerItr->getEventSettings(); 
00128 
00129     laser_color = (int) settings.wavelength;
00130     
00131     // Get run type and run number 
00132 
00133     runType=headerItr->getRunType();
00134     runNum=headerItr->getRunNumber();
00135     
00136     // Cut on runType
00137     
00138     if(runType!=EcalDCCHeaderBlock::LASER_STD && runType!=EcalDCCHeaderBlock::LASER_GAP 
00139        && runType!=EcalDCCHeaderBlock::LASER_POWER_SCAN && runType!=EcalDCCHeaderBlock::LASER_DELAY_SCAN) return; 
00140     
00141     // Define output results files' names
00142     
00143     if (IsFileCreated==0){
00144 
00145       stringstream namefile;
00146 
00147       namefile << resdir_ <<"/MatacqPerEvt-Run"<<runNum<<".root";        
00148       outfile=namefile.str();    
00149       
00150       outFile = new TFile(outfile.c_str(),"RECREATE");
00151       
00152       
00153       // declaration of the tree to fill
00154       
00155       tree = new TTree("MatacqTree","MatacqTree");
00156 
00157       IsFileCreated=1;
00158       
00159     }
00160   }
00161 
00162 
00163 // ===========================
00164 // Decode Matacq Information
00165 // ===========================
00166 
00167   int iCh=0;
00168   double max=0;
00169 
00170   for(EcalMatacqDigiCollection::const_iterator it = matacqDigi->begin(); it!=matacqDigi->end(); ++it){ // Loop on matacq channel 
00171     
00172     // 
00173     const EcalMatacqDigi& digis = *it;
00174     
00175     if(digis.size()==0 || iCh>=N_channels) continue; 
00176 
00177     max=0;
00178     maxsamp=0;
00179     nsamples=digis.size();
00180 
00181     if(IsTreeCreated==0){
00182       
00183       //List of branches
00184       
00185       stringstream mat;
00186       mat << "matacq["<<nsamples<<"]/D"<< endl;
00187  
00188       tree->Branch( "event",       &event,        "event/I"          );
00189       tree->Branch( "laser_color", &laser_color , "laser_color/I"    );
00190       //      tree->Branch( "nsamples",    &nsamples ,    "nsamples/I"       );
00191       tree->Branch( "matacq",      &matacq ,       mat.str().c_str() );
00192       tree->Branch( "maxsamp",     &maxsamp ,     "maxsamp/I"        );
00193       tree->Branch( "ttrig",       &ttrig ,       "ttrig/D"          );
00194       
00195       tree->SetBranchAddress( "event",       &event       );
00196       tree->SetBranchAddress( "laser_color", &laser_color );
00197       tree->SetBranchAddress( "matacq",      matacq       ); 
00198       //      tree->SetBranchAddress( "nsamples",    &nsamples    );
00199       tree->SetBranchAddress( "maxsamp",     &maxsamp     );
00200       tree->SetBranchAddress( "ttrig",       &ttrig       );
00201       
00202       IsTreeCreated=1;
00203     }
00204 
00205     ttrig=digis.tTrig();
00206     
00207     for(int i=0; i<digis.size(); ++i){ // Loop on matacq samples      
00208       matacq[i]=digis.adcCount(i);
00209       if(matacq[i]>max) {
00210         max=matacq[i];
00211         maxsamp=i;
00212       }
00213     }  
00214     
00215     
00216     iCh++; 
00217   }
00218   
00219   tree->Fill();
00220   
00221 } // analyze
00222 
00223 
00224 //========================================================================
00225 void EcalPerEvtMatacqAnalyzer::endJob() 
00226 {
00227   
00228   tree->Write();
00229   outFile->Close();
00230 
00231 
00232 }
00233 
00234 DEFINE_FWK_MODULE(EcalPerEvtMatacqAnalyzer);
00235