CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/IORawData/CaloPatterns/src/HtrXmlPattern.cc

Go to the documentation of this file.
00001 #include "DataFormats/Common/interface/Handle.h"
00002 #include "FWCore/Framework/interface/ESHandle.h"
00003 #include "CalibFormats/HcalObjects/interface/HcalDbService.h"
00004 #include "CalibFormats/HcalObjects/interface/HcalDbRecord.h"
00005 
00006 #include "DataFormats/HcalDigi/interface/HcalDigiCollections.h"
00007 #include "CondFormats/HcalObjects/interface/HcalElectronicsMap.h"
00008 #include "CalibCalorimetry/HcalAlgos/interface/HcalDbHardcode.h"
00009 
00010 #include "HtrXmlPattern.h"
00011 #include "HtrXmlPatternTool.h"
00012 #include "HtrXmlPatternToolParameters.h"
00013 
00014 HtrXmlPattern::HtrXmlPattern(const edm::ParameterSet& iConfig)
00015 {
00016   m_filled=0;
00017   m_fill_by_hand        = iConfig.getUntrackedParameter<bool>("fill_by_hand");
00018   m_hand_pattern_number = iConfig.getUntrackedParameter<int> ("hand_pattern_number");
00019   m_sets_to_show        = iConfig.getUntrackedParameter<int> ("sets_to_show");
00020   m_write_root_file     = iConfig.getUntrackedParameter<bool>("write_root_file");
00021 
00022   m_toolparameters = new HtrXmlPatternToolParameters;
00023   m_toolparameters->m_show_errors            = iConfig.getUntrackedParameter<bool>       ("show_errors");
00024   m_toolparameters->m_presamples_per_event   = iConfig.getUntrackedParameter<int>        ("presamples_per_event");
00025   m_toolparameters->m_samples_per_event      = iConfig.getUntrackedParameter<int>        ("samples_per_event");
00026 
00027   m_toolparameters->m_XML_file_mode          = iConfig.getUntrackedParameter<int>        ("XML_file_mode");
00028   m_toolparameters->m_file_tag               = iConfig.getUntrackedParameter<std::string>("file_tag");
00029   m_toolparameters->m_user_output_directory  = iConfig.getUntrackedParameter<std::string>("user_output_directory");
00030 
00031   std::string out_dir=m_toolparameters->m_user_output_directory;
00032   while (out_dir.find_last_of('/')==out_dir.length()-1) out_dir.erase(out_dir.find_last_of('/'));
00033   m_toolparameters->m_output_directory=out_dir+"/"+(m_toolparameters->m_file_tag)+"/";
00034 
00035   m_tool = new HtrXmlPatternTool(m_toolparameters);
00036 }
00037 
00038 
00039 HtrXmlPattern::~HtrXmlPattern()
00040 {
00041   delete m_tool;
00042   delete m_toolparameters;
00043 }
00044 
00045 // ------------ method called to for each event  ------------
00046 void HtrXmlPattern::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00047 {
00048    using namespace std;
00049 
00050    if (m_filled) return;
00051 
00052    edm::ESHandle<HcalDbService> pSetup;
00053    iSetup.get<HcalDbRecord>().get( pSetup );
00054    const HcalElectronicsMap* readoutMap=pSetup->getHcalMapping();
00055 
00056    if (m_fill_by_hand) {
00057      do_hand_fill(readoutMap);
00058      m_filled=1;
00059      return;
00060    }
00061   
00062    std::vector<edm::Handle<HBHEDigiCollection> > hbhe;
00063    std::vector<edm::Handle<HODigiCollection> > ho;
00064    std::vector<edm::Handle<HFDigiCollection> > hf;
00065    std::vector<edm::Handle<ZDCDigiCollection> > zdc;
00066    std::vector<edm::Handle<HcalCalibDigiCollection> > hc;
00067    std::vector<edm::Handle<HcalTrigPrimDigiCollection> > htp;
00068    std::vector<edm::Handle<HcalHistogramDigiCollection> > hh;  
00069 
00070    iEvent.getManyByType(hbhe);
00071    if (hbhe.empty()) {
00072      cout << "No HB/HE Digis." << endl;
00073    } else {
00074      std::vector<edm::Handle<HBHEDigiCollection> >::iterator i;
00075      for (i=hbhe.begin(); i!=hbhe.end(); i++) {
00076        const HBHEDigiCollection& c=*(*i);
00077    
00078        int count=0;
00079        for (HBHEDigiCollection::const_iterator j=c.begin(); j!=c.end(); j++) {
00080          const HcalElectronicsId HEID = readoutMap->lookup(j->id());
00081          m_tool->Fill(HEID,j);
00082 
00083          if ( count++<m_sets_to_show || m_sets_to_show<0 ) {
00084            cout << *j << std::endl;
00085            cout << HEID << endl;
00086            cout << "count: " << count << endl;
00087          }
00088        }
00089        if (m_sets_to_show!=0) cout << "HB/HE count: " << count << endl;
00090      }
00091   }
00092   
00093    iEvent.getManyByType(hf);
00094    if (hf.empty()) {
00095      cout << "No HF Digis." << endl;
00096   } else {
00097      std::vector<edm::Handle<HFDigiCollection> >::iterator i;
00098      for (i=hf.begin(); i!=hf.end(); i++) {
00099        const HFDigiCollection& c=*(*i);
00100    
00101        int count=0;
00102        for (HFDigiCollection::const_iterator j=c.begin(); j!=c.end(); j++) {
00103          const HcalElectronicsId HEID = readoutMap->lookup(j->id());
00104          m_tool->Fill(HEID,j);
00105          
00106          if ( count++<m_sets_to_show || m_sets_to_show<0 ) {
00107            cout << *j << std::endl;
00108            cout << HEID << endl;
00109            cout << "count: " << count << endl;
00110          }
00111        }
00112        if (m_sets_to_show!=0) cout << "HF    count: " << count << endl;
00113      }
00114   }
00115    
00116    iEvent.getManyByType(ho);
00117    if (ho.empty()) {
00118      cout << "No HO Digis." << endl;
00119   } else {
00120      std::vector<edm::Handle<HODigiCollection> >::iterator i;
00121      for (i=ho.begin(); i!=ho.end(); i++) {
00122        const HODigiCollection& c=*(*i);
00123        
00124        int count=0;
00125        for (HODigiCollection::const_iterator j=c.begin(); j!=c.end(); j++) {
00126          const HcalElectronicsId HEID = readoutMap->lookup(j->id());
00127          m_tool->Fill(HEID,j);
00128          
00129          if ( count++<m_sets_to_show || m_sets_to_show<0 ) {
00130            cout << *j << std::endl;
00131            cout << HEID << endl;
00132            cout << "count: " << count << endl;
00133          }
00134        }
00135        if (m_sets_to_show!=0) cout << "HO    count: " << count << endl;
00136      }
00137   }
00138 
00139    cout << endl;    
00140 
00141 }
00142 
00143 
00144 void HtrXmlPattern::do_hand_fill(const HcalElectronicsMap *emap)
00145 {
00146   HtrXmlPatternSet *hxps=m_tool->GetPatternSet();
00147 
00148   for (int iCrate=0;iCrate<ChannelPattern::NUM_CRATES;iCrate++) {
00149     CrateData *cd=hxps->getCrate(iCrate);
00150     if (!cd) continue;
00151     for (int iSlot=0;iSlot<ChannelPattern::NUM_SLOTS;iSlot++) {
00152       for (int iTb=0;iTb<2;iTb++) {
00153         HalfHtrData* hhd=cd->getHalfHtrData(iSlot,iTb);
00154         if (!hhd) continue;
00155         for (int iChannel=1;iChannel<25;iChannel++) {
00156           ChannelPattern *cp=hhd->getPattern(iChannel);
00157           if (!cp) continue;
00158           cp->Fill_by_hand(emap,m_hand_pattern_number);
00159         }
00160       }      
00161     }
00162   }
00163 
00164 }
00165 
00166 // ------------ method called once each job just after ending the event loop  ------------
00167 void 
00168 HtrXmlPattern::endJob() {
00169   bool modeg0=m_toolparameters->m_XML_file_mode>0;
00170   if (modeg0 || m_write_root_file) m_tool->prepareDirs();
00171   if (modeg0)                      m_tool->writeXML();
00172   if (m_write_root_file)           m_tool->createHists();
00173 }