Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:46:50

0001 /* 
0002  *  \class EcalPerEvtMatacqAnalyzer
0003  *
0004  *  primary author: Gautier Hamel De Monchenault - CEA/Saclay
0005  *  author: Julie Malcles - CEA/Saclay
0006  */
0007 
0008 #include <TFile.h>
0009 #include <TTree.h>
0010 #include <TChain.h>
0011 
0012 #include "EcalPerEvtMatacqAnalyzer.h"
0013 
0014 #include <sstream>
0015 #include <iostream>
0016 #include <iomanip>
0017 
0018 #include <FWCore/MessageLogger/interface/MessageLogger.h>
0019 #include <FWCore/Utilities/interface/Exception.h>
0020 
0021 #include <FWCore/Framework/interface/Event.h>
0022 #include <FWCore/Framework/interface/MakerMacros.h>
0023 #include <FWCore/ParameterSet/interface/ParameterSet.h>
0024 #include <FWCore/Framework/interface/EventSetup.h>
0025 
0026 #include <DataFormats/EcalDigi/interface/EcalDigiCollections.h>
0027 #include <DataFormats/EcalDetId/interface/EcalDetIdCollections.h>
0028 #include <DataFormats/EcalRawData/interface/EcalRawDataCollections.h>
0029 
0030 using namespace std;
0031 
0032 //========================================================================
0033 EcalPerEvtMatacqAnalyzer::EcalPerEvtMatacqAnalyzer(const edm::ParameterSet& iConfig)
0034     : iEvent(0),
0035       // framework parameters with default values
0036 
0037       _presample(iConfig.getUntrackedParameter<double>("nPresamples", 6.7)),
0038       _nsamplesaftmax(iConfig.getUntrackedParameter<unsigned int>("nSamplesAftMax", 80)),
0039       _nsamplesbefmax(iConfig.getUntrackedParameter<unsigned int>("nSamplesBefMax", 20)),
0040       _noiseCut(iConfig.getUntrackedParameter<unsigned int>("noiseCut", 7)),
0041       _parabnbefmax(iConfig.getUntrackedParameter<unsigned int>("paraBeforeMax", 8)),
0042       _parabnaftmax(iConfig.getUntrackedParameter<unsigned int>("paraAfterMax", 7)),
0043       _thres(iConfig.getUntrackedParameter<unsigned int>("threshold", 10)),
0044       _lowlev(iConfig.getUntrackedParameter<unsigned int>("lowLevel", 20)),
0045       _highlev(iConfig.getUntrackedParameter<unsigned int>("highLevel", 80)),
0046       _nevlasers(iConfig.getUntrackedParameter<unsigned int>("nEventLaser", 600))
0047 
0048 //========================================================================
0049 {
0050   //now do what ever initialization is needed
0051 
0052   resdir_ = iConfig.getUntrackedParameter<std::string>("resDir");
0053 
0054   digiCollection_ = iConfig.getParameter<std::string>("digiCollection");
0055   digiProducer_ = iConfig.getParameter<std::string>("digiProducer");
0056 
0057   eventHeaderCollection_ = iConfig.getParameter<std::string>("eventHeaderCollection");
0058   eventHeaderProducer_ = iConfig.getParameter<std::string>("eventHeaderProducer");
0059 }
0060 
0061 //========================================================================
0062 EcalPerEvtMatacqAnalyzer::~EcalPerEvtMatacqAnalyzer() {
0063   //========================================================================
0064 
0065   // do anything here that needs to be done at desctruction time
0066   // (e.g. close files, deallocate resources etc.)
0067 }
0068 
0069 //========================================================================
0070 void EcalPerEvtMatacqAnalyzer::beginJob() {
0071   //========================================================================
0072 
0073   //Initializations
0074 
0075   IsFileCreated = 0;
0076   IsTreeCreated = 0;
0077 }
0078 
0079 //========================================================================
0080 void EcalPerEvtMatacqAnalyzer::analyze(const edm::Event& e, const edm::EventSetup& c) {
0081   //========================================================================
0082 
0083   ++iEvent;
0084 
0085   // retrieving MATACQ :
0086   edm::Handle<EcalMatacqDigiCollection> pmatacqDigi;
0087   const EcalMatacqDigiCollection* matacqDigi = nullptr;
0088   try {
0089     e.getByLabel(digiProducer_, digiCollection_, pmatacqDigi);
0090     matacqDigi = pmatacqDigi.product();
0091   } catch (std::exception& ex) {
0092     std::cerr << "Error! can't get the product " << digiCollection_.c_str() << std::endl;
0093   }
0094 
0095   // retrieving DCC header
0096 
0097   edm::Handle<EcalRawDataCollection> pDCCHeader;
0098   const EcalRawDataCollection* DCCHeader = nullptr;
0099   try {
0100     e.getByLabel(digiProducer_, pDCCHeader);
0101     //e.getByLabel(eventHeaderProducer_,eventHeaderCollection_, pDCCHeader);
0102     DCCHeader = pDCCHeader.product();
0103   } catch (std::exception& ex) {
0104     std::cerr << "Error! can't get the product " << eventHeaderCollection_.c_str() << std::endl;
0105   }
0106 
0107   // ====================================
0108   // Decode Basic DCCHeader Information
0109   // ====================================
0110 
0111   for (EcalRawDataCollection::const_iterator headerItr = DCCHeader->begin(); headerItr != DCCHeader->end();
0112        ++headerItr) {
0113     event = headerItr->getLV1();
0114     EcalDCCHeaderBlock::EcalDCCEventSettings settings = headerItr->getEventSettings();
0115 
0116     laser_color = (int)settings.wavelength;
0117 
0118     // Get run type and run number
0119 
0120     runType = headerItr->getRunType();
0121     runNum = headerItr->getRunNumber();
0122 
0123     // Cut on runType
0124 
0125     if (runType != EcalDCCHeaderBlock::LASER_STD && runType != EcalDCCHeaderBlock::LASER_GAP &&
0126         runType != EcalDCCHeaderBlock::LASER_POWER_SCAN && runType != EcalDCCHeaderBlock::LASER_DELAY_SCAN)
0127       return;
0128 
0129     // Define output results files' names
0130 
0131     if (IsFileCreated == 0) {
0132       stringstream namefile;
0133 
0134       namefile << resdir_ << "/MatacqPerEvt-Run" << runNum << ".root";
0135       outfile = namefile.str();
0136 
0137       outFile = new TFile(outfile.c_str(), "RECREATE");
0138 
0139       // declaration of the tree to fill
0140 
0141       tree = new TTree("MatacqTree", "MatacqTree");
0142 
0143       IsFileCreated = 1;
0144     }
0145   }
0146 
0147   // ===========================
0148   // Decode Matacq Information
0149   // ===========================
0150 
0151   int iCh = 0;
0152   double max = 0;
0153 
0154   for (EcalMatacqDigiCollection::const_iterator it = matacqDigi->begin(); it != matacqDigi->end();
0155        ++it) {  // Loop on matacq channel
0156 
0157     //
0158     const EcalMatacqDigi& digis = *it;
0159 
0160     if (digis.size() == 0 || iCh >= N_channels)
0161       continue;
0162 
0163     max = 0;
0164     maxsamp = 0;
0165     nsamples = digis.size();
0166 
0167     if (IsTreeCreated == 0) {
0168       //List of branches
0169 
0170       stringstream mat;
0171       mat << "matacq[" << nsamples << "]/D" << endl;
0172 
0173       tree->Branch("event", &event, "event/I");
0174       tree->Branch("laser_color", &laser_color, "laser_color/I");
0175       //      tree->Branch( "nsamples",    &nsamples ,    "nsamples/I"       );
0176       tree->Branch("matacq", &matacq, mat.str().c_str());
0177       tree->Branch("maxsamp", &maxsamp, "maxsamp/I");
0178       tree->Branch("ttrig", &ttrig, "ttrig/D");
0179 
0180       tree->SetBranchAddress("event", &event);
0181       tree->SetBranchAddress("laser_color", &laser_color);
0182       tree->SetBranchAddress("matacq", matacq);
0183       //      tree->SetBranchAddress( "nsamples",    &nsamples    );
0184       tree->SetBranchAddress("maxsamp", &maxsamp);
0185       tree->SetBranchAddress("ttrig", &ttrig);
0186 
0187       IsTreeCreated = 1;
0188     }
0189 
0190     ttrig = digis.tTrig();
0191 
0192     for (int i = 0; i < digis.size(); ++i) {  // Loop on matacq samples
0193       matacq[i] = digis.adcCount(i);
0194       if (matacq[i] > max) {
0195         max = matacq[i];
0196         maxsamp = i;
0197       }
0198     }
0199 
0200     iCh++;
0201   }
0202 
0203   tree->Fill();
0204 
0205 }  // analyze
0206 
0207 //========================================================================
0208 void EcalPerEvtMatacqAnalyzer::endJob() {
0209   tree->Write();
0210   outFile->Close();
0211 }
0212 
0213 DEFINE_FWK_MODULE(EcalPerEvtMatacqAnalyzer);