Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 10:41:36

0001 /**
0002  * \file testChannel.cc
0003  *
0004  * \author P. Govoni (pietro.govoni@cernNOSPAM.ch)
0005  *
0006  */
0007 
0008 #include "DataFormats/EcalRawData/interface/EcalDCCHeaderBlock.h"
0009 #include "DataFormats/EcalRawData/interface/EcalRawDataCollections.h"
0010 
0011 #include "TFile.h"
0012 #include "TString.h"
0013 
0014 #include "CalibCalorimetry/EcalPedestalOffsets/interface/testChannel.h"
0015 
0016 //! ctor
0017 testChannel::testChannel(const edm::ParameterSet &paramSet)
0018     : m_digiProducerToken(
0019           consumes<EBDigiCollection>(edm::InputTag(paramSet.getParameter<std::string>("digiProducer")))),
0020       m_headerProducerToken(
0021           consumes<EcalRawDataCollection>(edm::InputTag(paramSet.getParameter<std::string>("headerProducer")))),
0022       m_xmlFile(paramSet.getParameter<std::string>("xmlFile")),
0023       m_DACmin(paramSet.getParameter<int>("DACmin")),
0024       m_DACmax(paramSet.getParameter<int>("DACmax")),
0025       m_RMSmax(paramSet.getParameter<double>("RMSmax")),
0026       m_bestPed(paramSet.getParameter<int>("bestPed")),
0027       m_xtal(paramSet.getParameter<int>("xtal")),
0028       m_pedVSDAC("pedVSDAC", "pedVSDAC", 100, 150, 250, m_DACmax - m_DACmin, m_DACmin, m_DACmax),
0029       m_singlePedVSDAC_1("singlePedVSDAC_1",
0030                          "pedVSDAC (g1) for xtal " + TString(m_xtal),
0031                          100,
0032                          150,
0033                          250,
0034                          m_DACmax - m_DACmin,
0035                          m_DACmin,
0036                          m_DACmax),
0037       m_singlePedVSDAC_2("singlePedVSDAC_2",
0038                          "pedVSDAC (g2) for xtal " + TString(m_xtal),
0039                          100,
0040                          150,
0041                          250,
0042                          m_DACmax - m_DACmin,
0043                          m_DACmin,
0044                          m_DACmax),
0045       m_singlePedVSDAC_3("singlePedVSDAC_3",
0046                          "pedVSDAC (g3) for xtal " + TString(m_xtal),
0047                          100,
0048                          150,
0049                          250,
0050                          m_DACmax - m_DACmin,
0051                          m_DACmin,
0052                          m_DACmax) {
0053   edm::LogInfo("testChannel") << " reading "
0054                               << " m_DACmin: " << m_DACmin << " m_DACmax: " << m_DACmax << " m_RMSmax: " << m_RMSmax
0055                               << " m_bestPed: " << m_bestPed;
0056 }
0057 
0058 //! dtor
0059 testChannel::~testChannel() {}
0060 
0061 //! begin the job
0062 void testChannel::beginJob() { LogDebug("testChannel") << "entering beginJob ..."; }
0063 
0064 //! perform te analysis
0065 void testChannel::analyze(edm::Event const &event, edm::EventSetup const &eventSetup) {
0066   LogDebug("testChannel") << "entering analyze ...";
0067 
0068   // get the headers
0069   // (one header for each supermodule)
0070   const edm::Handle<EcalRawDataCollection> &DCCHeaders = event.getHandle(m_headerProducerToken);
0071   if (!DCCHeaders.isValid()) {
0072     edm::LogError("testChannel") << "Error! can't get the product for EcalRawDataCollection";
0073   }
0074 
0075   std::map<int, int> DACvalues;
0076 
0077   // loop over the headers
0078   for (EcalRawDataCollection::const_iterator headerItr = DCCHeaders->begin(); headerItr != DCCHeaders->end();
0079        ++headerItr) {
0080     EcalDCCHeaderBlock::EcalDCCEventSettings settings = headerItr->getEventSettings();
0081     DACvalues[getHeaderSMId(headerItr->id())] = settings.ped_offset;
0082     //       std::cout << "DCCid: " << headerItr->id () << "" ;
0083     //       std::cout << "Ped offset DAC: " << settings.ped_offset << "" ;
0084   }  //! loop over the headers
0085 
0086   // get the digis
0087   // (one digi for each crystal)
0088   const edm::Handle<EBDigiCollection> &pDigis = event.getHandle(m_digiProducerToken);
0089   if (!pDigis.isValid()) {
0090     edm::LogError("testChannel") << "Error! can't get the product for EBDigiCollection";
0091   }
0092 
0093   // loop over the digis
0094   for (EBDigiCollection::const_iterator itdigi = pDigis->begin(); itdigi != pDigis->end(); ++itdigi) {
0095     EBDataFrame df(*itdigi);
0096     int gainId = df.sample(0).gainId();
0097     int crystalId = EBDetId(itdigi->id()).ic();
0098     int smId = EBDetId(itdigi->id()).ism();
0099 
0100     edm::LogInfo("testChannel") << "channel " << event.id() << "\tcry: " << crystalId << "\tG: " << gainId
0101                                 << "\tDAC: " << DACvalues[smId];
0102 
0103     // loop over the samples
0104     for (int iSample = 0; iSample < EBDataFrame::MAXSAMPLES; ++iSample) {
0105       edm::LogInfo("testChannel") << "\t`-->" << df.sample(iSample).adc();
0106       m_pedVSDAC.Fill(df.sample(iSample).adc(), DACvalues[smId]);
0107       if (crystalId == m_xtal) {
0108         if (gainId == 1)
0109           m_singlePedVSDAC_1.Fill(df.sample(iSample).adc(), DACvalues[smId]);
0110         if (gainId == 2)
0111           m_singlePedVSDAC_2.Fill(df.sample(iSample).adc(), DACvalues[smId]);
0112         if (gainId == 3)
0113           m_singlePedVSDAC_3.Fill(df.sample(iSample).adc(), DACvalues[smId]);
0114       }
0115     }  // loop over the samples
0116   }    // loop over the digis
0117 }
0118 
0119 //! perform the minimiation and write results
0120 void testChannel::endJob() {
0121   char ccout[80];
0122   sprintf(ccout, "out_%d.root", m_xtal);
0123   TFile out(ccout, "RECREATE");
0124   out.cd();
0125   m_pedVSDAC.Write();
0126   m_singlePedVSDAC_1.Write();
0127   m_singlePedVSDAC_2.Write();
0128   m_singlePedVSDAC_3.Write();
0129   TProfile *profilo1 = m_singlePedVSDAC_1.ProfileX();
0130   TProfile *profilo2 = m_singlePedVSDAC_2.ProfileX();
0131   TProfile *profilo3 = m_singlePedVSDAC_3.ProfileX();
0132   profilo1->Write("singleProfile_1");
0133   profilo2->Write("singleProfile_2");
0134   profilo3->Write("singleProfile_3");
0135   out.Close();
0136 }
0137 
0138 /*
0139 void testChannel::writeDb (EcalCondDBInterface* econn,
0140                            MonRunIOV* moniov)
0141 {}
0142 */
0143 
0144 int testChannel::getHeaderSMId(const int headerId) {
0145   // PG FIXME temporary solution
0146   // PG FIXME check it is consistent with the TB!
0147   return 1;
0148 }
0149 
0150 void testChannel::subscribe() {}
0151 
0152 void testChannel::subscribeNew() {}
0153 
0154 void testChannel::unsubscribe() {}