CMS 3D CMS Logo

Public Member Functions | Private Attributes

cms::HcalConstantsASCIIWriter Class Reference

#include <HcalConstantsASCIIWriter.h>

Inheritance diagram for cms::HcalConstantsASCIIWriter:
edm::EDAnalyzer

List of all members.

Public Member Functions

virtual void analyze (const edm::Event &, const edm::EventSetup &)
virtual void beginJob ()
virtual void endJob ()
 HcalConstantsASCIIWriter (const edm::ParameterSet &)
 ~HcalConstantsASCIIWriter ()

Private Attributes

std::string file_input
std::string file_output
std::ofstream * myout_hcal

Detailed Description

Definition at line 49 of file HcalConstantsASCIIWriter.h.


Constructor & Destructor Documentation

cms::HcalConstantsASCIIWriter::HcalConstantsASCIIWriter ( const edm::ParameterSet iConfig) [explicit]

Definition at line 36 of file HcalConstantsASCIIWriter.cc.

References edm::ParameterSet::getParameter().

{
  // get name of output file with histogramms
  file_input="Calibration/HcalCalibAlgos/data/"+iConfig.getParameter <std::string> ("fileInput")+".txt";
  file_output="Calibration/HcalCalibAlgos/data/"+iConfig.getParameter <std::string> ("fileOutput")+".txt"; 
}
cms::HcalConstantsASCIIWriter::~HcalConstantsASCIIWriter ( )

Definition at line 43 of file HcalConstantsASCIIWriter.cc.

{
 
   // do anything here that needs to be done at desctruction time
   // (e.g. close files, deallocate resources etc.)

}

Member Function Documentation

void cms::HcalConstantsASCIIWriter::analyze ( const edm::Event iEvent,
const edm::EventSetup iSetup 
) [virtual]

Implements edm::EDAnalyzer.

Definition at line 73 of file HcalConstantsASCIIWriter.cc.

References HcalCondObjectContainer< Item >::addValues(), gather_cfg::cout, HcalDetId::depth(), CastorDbASCIIIO::dumpObject(), validate-o2o-wbm::f1, edm::FileInPath::fullPath(), edm::EventSetup::get(), CaloGeometry::getValidDetIds(), reco::JetExtendedAssociation::getValue(), HcalCondObjectContainer< Item >::getValues(), DetId::Hcal, i, HcalDetId::ieta(), recoMuon::in, HcalDetId::iphi(), geometryCSVtoXML::line, edm::ESHandle< T >::product(), csvReporter::r, and edm::second().

{

  std::cout<<" Start HcalConstantsASCIIWriter::analyze "<<std::endl;
  
    edm::ESHandle<HcalRespCorrs> r;
    iSetup.get<HcalRespCorrsRcd>().get(r);
    HcalRespCorrs* oldRespCorrs = new HcalRespCorrs(*r.product());
//    std::vector<DetId> dd = oldRespCorrs->getAllChannels();
  
   edm::ESHandle<CaloGeometry> pG;
   iSetup.get<CaloGeometryRecord>().get(pG);
   const CaloGeometry* geo = pG.product();
//   iSetup.get<HcalDbRecord>().get(conditions);
   
   std::vector<DetId> did =  geo->getValidDetIds();

 
    std::map<HcalDetId,float> corrold;
    //map<HcalDetId,float> corrnew; 
    
    int mysubd,depth,ieta,iphi;
    float coradd,corerr;
     
    std::vector<HcalDetId> theVector; 
    for(std::vector<DetId>::iterator i = did.begin(); i != did.end(); i++)
    {
      if( (*i).det() == DetId::Hcal ) { 
      HcalDetId hid = HcalDetId(*i);
      theVector.push_back(hid);
      corrold[hid] = (oldRespCorrs->getValues(*i))->getValue();
      std::cout<<" Old calibration "<<hid.depth()<<" "<<hid.ieta()<<" "<<hid.iphi()<<std::endl;
      } 
    }

    std::cout<<" Get old calibration "<<std::endl;
// Read new corrections from file

    edm::FileInPath f1(file_input);
    std::string fDataFile = f1.fullPath();
     
    std::ifstream in( fDataFile.c_str() );
    std::string line;
    
   double corrnew_p[5][5][45][75]; 
   double corrnew_m[5][5][45][75];
   std::cout<<" Start to read txt file "<<fDataFile.c_str()<<std::endl; 
    while( std::getline( in, line)){

//    std::cout<<" Line size "<<line.size()<< " "<<line<< std::endl;

      if(!line.size() || line[0]=='#') continue;
      std::istringstream linestream(line);

      linestream>>mysubd>>depth>>ieta>>iphi>>coradd>>corerr;
//      DetId mydid(DetId::Hcal,HcalSubdetector(mysubd));
//      HcalDetId  hid(HcalSubdetector(mysubd),ieta,iphi,depth);
//        HcalDetId hid(mydid);
//      std::cout<<" Check mysubd "<<hid.subdet()<<" depth "<<hid.depth()<<" ieta "<<hid.ieta()<<" iphi "<<hid.iphi()<<" "<<hid.rawId()<< std::endl;
      int ietak = ieta; 
      if(ieta<0) ietak = -1*ieta;
      if(ieta>0) corrnew_p[mysubd][depth][ietak][iphi] =  coradd; 
      if(ieta<0) corrnew_m[mysubd][depth][ietak][iphi] =  coradd;
      std::cout<<" Try to initialize mysubd "<<mysubd<<" depth "<<depth<<" ieta "<<ieta<<" "<<ietak<<" iphi "<<iphi<<" "<<coradd<<
      std::endl;
    } 
    
    HcalRespCorrs* mycorrections = new HcalRespCorrs(); 
    
   for(std::vector<HcalDetId>::iterator it = theVector.begin(); it != theVector.end(); it++)
   {
     float cc1 = (*corrold.find(*it)).second;
 //    float cc2 = (*corrnew.find(*it)).second;
     float cc2 = 0.;
     int ietak = (*it).ieta();

     if((*it).ieta()<0) ietak=-1*(*it).ieta();

     if((*it).ieta()>0) cc2 = corrnew_p[(*it).subdet()][(*it).depth()][ietak][(*it).iphi()];
     if((*it).ieta()<0) cc2 = corrnew_m[(*it).subdet()][(*it).depth()][ietak][(*it).iphi()];

     float cc = cc1*cc2;
      std::cout<<" Multiply "<<(*it).subdet()<<" "<<(*it).depth()<<" "<<(*it).ieta()<<" "<<ietak<<" "<<(*it).iphi()<<" "<<(*it).rawId()<<" "<<cc1<<" "<<cc2<<std::endl;

  // now make the basic object for one cell with HcalDetId myDetId containing the value myValue
      HcalRespCorr item ((*it).rawId(), cc);
      mycorrections->addValues(item);
   }   

    HcalRespCorrs mycc = *mycorrections;
    HcalDbASCIIIO::dumpObject (*myout_hcal, mycc);

}
void cms::HcalConstantsASCIIWriter::beginJob ( void  ) [virtual]

Reimplemented from edm::EDAnalyzer.

Definition at line 51 of file HcalConstantsASCIIWriter.cc.

References gather_cfg::cout, validate-o2o-wbm::f1, and edm::FileInPath::fullPath().

{
    edm::FileInPath f1(file_output);
    std::string fDataFile = f1.fullPath();

  myout_hcal = new ofstream(fDataFile.c_str());
  if(!myout_hcal) std::cout << " Output file not open!!! "<<std::endl;
    
}
void cms::HcalConstantsASCIIWriter::endJob ( void  ) [virtual]

Reimplemented from edm::EDAnalyzer.

Definition at line 61 of file HcalConstantsASCIIWriter.cc.

{
   delete myout_hcal; 
}

Member Data Documentation

Definition at line 62 of file HcalConstantsASCIIWriter.h.

Definition at line 63 of file HcalConstantsASCIIWriter.h.

Definition at line 61 of file HcalConstantsASCIIWriter.h.