Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:14:58

0001 #include "EcalMatacqHist.h"
0002 
0003 #include "TProfile.h"
0004 #include <sstream>
0005 #include <iostream>
0006 #include <iomanip>
0007 #include <DataFormats/EcalDigi/interface/EcalDigiCollections.h>
0008 #include <FWCore/Utilities/interface/Exception.h>
0009 
0010 EcalMatacqHist::EcalMatacqHist(const edm::ParameterSet& ps) : iEvent(0) {
0011   outFileName = ps.getUntrackedParameter<std::string>("outputRootFile", "matacqHist.root");
0012   nTimePlots = ps.getUntrackedParameter<int>("nTimePlots", 10);
0013   firstTimePlotEvent = ps.getUntrackedParameter<int>("firstTimePlotEvent", 1);
0014   hTTrigMin = ps.getUntrackedParameter<double>("hTTrigMin", 0.);
0015   hTTrigMax = ps.getUntrackedParameter<double>("hTTrigMax", 2000.);
0016   TDirectory* dsave = gDirectory;
0017   outFile = std::unique_ptr<TFile>(new TFile(outFileName.c_str(), "RECREATE"));
0018   if (outFile->IsZombie()) {
0019     std::cout << "EcalMatacqHist: Failed to create file " << outFileName << " No histogram will be created.\n";
0020   }
0021 
0022   hTTrig = new TH1D("tTrig", "Trigger time in ns", 100, hTTrigMin, hTTrigMax);
0023   dsave->cd();
0024 }
0025 
0026 EcalMatacqHist::~EcalMatacqHist() {
0027   if (!outFile->IsZombie()) {
0028     TDirectory* dsave = gDirectory;
0029     outFile->cd();
0030     for (std::vector<TProfile>::iterator it = profiles.begin(); it != profiles.end(); ++it) {
0031       it->Write();
0032     }
0033     if (hTTrig != 0)
0034       hTTrig->Write();
0035     dsave->cd();
0036   }
0037 }
0038 
0039 void EcalMatacqHist::analyze(const edm::Event& e, const edm::EventSetup& c) {
0040   ++iEvent;
0041   if (outFile->IsZombie())
0042     return;
0043   TDirectory* dsave = gDirectory;
0044   outFile->cd();
0045   // retrieving MATACQ digis:
0046   edm::Handle<EcalMatacqDigiCollection> digiColl;
0047   e.getByLabel("ecalEBunpacker", digiColl);
0048 
0049   unsigned iCh = 0;
0050   for (EcalMatacqDigiCollection::const_iterator it = digiColl->begin(); it != digiColl->end(); ++it, ++iCh) {
0051     const EcalMatacqDigi& digis = *it;
0052 
0053     if (digis.size() == 0)
0054       continue;
0055 
0056     if (iEvent >= firstTimePlotEvent && iEvent < firstTimePlotEvent + nTimePlots) {
0057       int nSamples = digis.size();
0058       std::stringstream title;
0059       std::stringstream name;
0060       name << "matacq" << digis.chId() << "_" << std::setfill('0') << std::setw(4) << iEvent;
0061       title << "Matacq channel " << digis.chId() << ", event " << iEvent << ", Ts = " << digis.ts() * 1.e9 << "ns";
0062       float tTrig_s = digis.tTrig();
0063       if (tTrig_s < 999.) {
0064         title << ", t_trig = " << tTrig_s * 1.e9 << "ns";
0065       }
0066       TH1D h1(name.str().c_str(), title.str().c_str(), nSamples, -.5, -.5 + nSamples);
0067       for (int i = 0; i < digis.size(); ++i) {
0068         h1.Fill(i, digis.adcCount(i));
0069       }
0070       h1.Write();
0071     }
0072 
0073     //profile
0074     //init:
0075     if (iCh >= profiles.size()) {  //profile not yet allocated for this matacq ch.
0076       std::stringstream profTitle;
0077       profTitle << "Matacq channel " << digis.chId() << " profile";
0078       std::stringstream profileName;
0079       profileName << "matacq" << digis.chId();
0080       profiles.push_back(
0081           TProfile(profileName.str().c_str(), profTitle.str().c_str(), digis.size(), -.5, -.5 + digis.size(), "I"));
0082       profiles.back().SetDirectory(0);  //mem. management done by std::vector
0083       profChId.push_back(digis.chId());
0084     }
0085 
0086     for (int i = 0; i < digis.size(); ++i) {
0087       if (profChId[iCh] == digis.chId()) {
0088         profiles[iCh].Fill(i, digis.adcCount(i));
0089       } else {
0090         throw cms::Exception("EcalMatacqHist",
0091                              "Order or number of matacq channels is not the "
0092                              "same in the different event. Such a "
0093                              "configuration is not supported by "
0094                              "EcalMatacqHist");
0095       }
0096       hTTrig->Fill(digis.tTrig() * 1.e9);
0097     }
0098   }
0099   dsave->cd();
0100 }  // analyze
0101 
0102 DEFINE_FWK_MODULE(EcalMatacqHist);