Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "EcalMatacqHist2.h"
0002 
0003 #include "TH1D.h"
0004 #include "TProfile.h"
0005 #include <sstream>
0006 #include <iostream>
0007 #include <iomanip>
0008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0009 #include <DataFormats/EcalDigi/interface/EcalDigiCollections.h>
0010 #include <FWCore/Utilities/interface/Exception.h>
0011 
0012 
0013 EcalMatacqHist2::EcalMatacqHist2(const edm::ParameterSet& ps):
0014   iEvent(0){
0015   outFileName= ps.getUntrackedParameter<std::string>("outputRootFile", "matacqHist.root");
0016   nTimePlots = ps.getUntrackedParameter<int>("nTimePlots", 10);
0017   firstTimePlotEvent = ps.getUntrackedParameter<int>("firstTimePlotEvent",
0018                              1);
0019   hTTrigMin = ps.getUntrackedParameter<double>("hTTrigMin", 0.);
0020   hTTrigMax = ps.getUntrackedParameter<double>("hTTrigMax", 2000.);
0021   matacqProducer_ = ps.getParameter<std::string>("matacqProducer");
0022   TDirectory* dsave = gDirectory;
0023   outFile = std::unique_ptr<TFile> (new TFile(outFileName.c_str(), "RECREATE"));
0024   if(outFile->IsZombie()){
0025     std::cout << "EcalMatacqHist2: Failed to create file " << outFileName
0026      << " No histogram will be created.\n";
0027   }
0028 
0029   hTTrig =  new TH1D("tTrig", "Trigger time in ns",
0030               100,
0031               hTTrigMin,
0032               hTTrigMax);
0033   dsave->cd();
0034 }
0035 
0036 EcalMatacqHist2::~EcalMatacqHist2(){
0037   if(!outFile->IsZombie()){
0038     TDirectory* dsave = gDirectory;
0039     outFile->cd();
0040     for(std::vector<TProfile>::iterator it = profiles.begin();
0041        it != profiles.end();
0042        ++it){
0043       it->Write();
0044     }
0045     if(hTTrig!=0) hTTrig->Write();
0046     dsave->cd();
0047   }
0048 }
0049 
0050 void
0051 EcalMatacqHist2:: analyze( const edm::Event & e, const  edm::EventSetup& c){
0052   ++iEvent;
0053   if(outFile->IsZombie()) return;
0054   TDirectory* dsave = gDirectory;
0055   outFile->cd();
0056 
0057   edm::TimeValue_t t = e.time().value();
0058 
0059   time_t ts = t >>32;
0060   time_t tus = t & 0xFFFFFFFF;
0061   char buf[256];
0062   strftime(buf, sizeof(buf), "%F %R %S s", localtime(&ts));
0063    
0064   std::cerr << std::flush;
0065   std::cout << "---- > Event data: " << buf
0066         << " " << tus << "us" << std::endl;
0067   
0068   // retrieving MATACQ digis:
0069   edm::Handle<EcalMatacqDigiCollection> digiColl;
0070   if(e.getByLabel(matacqProducer_, "", digiColl)){
0071     unsigned iCh=0;
0072     for(EcalMatacqDigiCollection::const_iterator it = digiColl->begin();
0073     it!=digiColl->end(); ++it, ++iCh){
0074       
0075       const EcalMatacqDigi& digis = *it;
0076 
0077       std::cout << "Matacq digi size: " << digis.size() << std::endl;
0078       
0079       if(digis.size()==0) continue;
0080       
0081       if(iEvent >= firstTimePlotEvent
0082      && iEvent < firstTimePlotEvent + nTimePlots){
0083       int nSamples = digis.size();
0084       std::stringstream title;
0085       std::stringstream name;
0086       name << "matacq" << digis.chId() << "_"
0087        << std::setfill('0') << std::setw(4) << iEvent;
0088       title << "Matacq channel " <<  digis.chId() << ", event " << iEvent
0089         << ", Ts = " << digis.ts()*1.e9 << "ns";
0090       float tTrig_s = digis.tTrig();
0091       if(tTrig_s<999.){
0092     title << ", t_trig = " << tTrig_s * 1.e9 << "ns";
0093       }
0094       TH1D h1(name.str().c_str(), title.str().c_str(),
0095           nSamples, -.5, -.5+nSamples);
0096       for(int i=0; i<digis.size(); ++i){
0097     h1.Fill(i, digis.adcCount(i));
0098       }
0099       h1.Write();
0100     }
0101     
0102     //profile
0103     //init:
0104     if(iCh>=profiles.size()){ //profile not yet allocated for this matacq ch.
0105       std::stringstream profTitle;
0106       profTitle << "Matacq channel " <<  digis.chId()
0107         << " profile";
0108       std::stringstream profileName;
0109       profileName << "matacq" << digis.chId();
0110       profiles.push_back(TProfile(profileName.str().c_str(),
0111                   profTitle.str().c_str(),
0112                   digis.size(),
0113                   -.5,
0114                   -.5+digis.size(),
0115                   "I"));
0116       profiles.back().SetDirectory(0);//mem. management done by std::vector
0117       profChId.push_back(digis.chId());
0118     }
0119     
0120     for(int i=0; i<digis.size(); ++i){
0121       if(profChId[iCh]==digis.chId()){
0122     profiles[iCh].Fill(i, digis.adcCount(i));
0123       } else{
0124     throw cms::Exception("EcalMatacqHist2",
0125                  "Order or number of matacq channels is not the "
0126                  "same in the different event. Such a "
0127                  "configuration is not supported by "
0128                  "EcalMatacqHist2");
0129       }
0130       hTTrig->Fill(digis.tTrig()*1.e9);
0131     }
0132     }
0133   } else{
0134     edm::LogInfo("No matacq digi found");
0135   }
0136   dsave->cd();
0137 } // analyze
0138 
0139 
0140 DEFINE_FWK_MODULE(EcalMatacqHist2);