CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Attributes
cms::HcalConstantsASCIIWriter Class Reference

#include <HcalConstantsASCIIWriter.h>

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

Public Member Functions

virtual void analyze (const edm::Event &, const edm::EventSetup &)
 
virtual void beginJob ()
 
virtual void endJob ()
 
 HcalConstantsASCIIWriter (const edm::ParameterSet &)
 
 ~HcalConstantsASCIIWriter ()
 
- Public Member Functions inherited from edm::EDAnalyzer
 EDAnalyzer ()
 
std::string workerType () const
 
virtual ~EDAnalyzer ()
 

Private Attributes

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

Additional Inherited Members

- Public Types inherited from edm::EDAnalyzer
typedef EDAnalyzer ModuleType
 
typedef WorkerT< EDAnalyzerWorkerType
 
- Static Public Member Functions inherited from edm::EDAnalyzer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDAnalyzer
CurrentProcessingContext const * currentContext () const
 

Detailed Description

Definition at line 50 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().

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

Definition at line 43 of file HcalConstantsASCIIWriter.cc.

44 {
45 
46  // do anything here that needs to be done at desctruction time
47  // (e.g. close files, deallocate resources etc.)
48 
49 }

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(), HcalDbASCIIIO::dumpObject(), connectstrParser::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< class >::product(), csvReporter::r, and edm::second().

74 {
75 
76  std::cout<<" Start HcalConstantsASCIIWriter::analyze "<<std::endl;
77 
79  iSetup.get<HcalRespCorrsRcd>().get(r);
80  HcalRespCorrs* oldRespCorrs = new HcalRespCorrs(*r.product());
81 // std::vector<DetId> dd = oldRespCorrs->getAllChannels();
82 
84  iSetup.get<CaloGeometryRecord>().get(pG);
85  const CaloGeometry* geo = pG.product();
86 // iSetup.get<HcalDbRecord>().get(conditions);
87 
88  std::vector<DetId> did = geo->getValidDetIds();
89 
90 
91  std::map<HcalDetId,float> corrold;
92  //map<HcalDetId,float> corrnew;
93 
94  int mysubd,depth,ieta,iphi;
95  float coradd,corerr;
96 
97  std::vector<HcalDetId> theVector;
98  for(std::vector<DetId>::iterator i = did.begin(); i != did.end(); i++)
99  {
100  if( (*i).det() == DetId::Hcal ) {
101  HcalDetId hid = HcalDetId(*i);
102  theVector.push_back(hid);
103  corrold[hid] = (oldRespCorrs->getValues(*i))->getValue();
104  std::cout<<" Old calibration "<<hid.depth()<<" "<<hid.ieta()<<" "<<hid.iphi()<<std::endl;
105  }
106  }
107 
108  std::cout<<" Get old calibration "<<std::endl;
109 // Read new corrections from file
110 
112  std::string fDataFile = f1.fullPath();
113 
114  std::ifstream in( fDataFile.c_str() );
115  std::string line;
116 
117  double corrnew_p[5][5][45][75];
118  double corrnew_m[5][5][45][75];
119  std::cout<<" Start to read txt file "<<fDataFile.c_str()<<std::endl;
120  while( std::getline( in, line)){
121 
122 // std::cout<<" Line size "<<line.size()<< " "<<line<< std::endl;
123 
124  if(!line.size() || line[0]=='#') continue;
125  std::istringstream linestream(line);
126 
127  linestream>>mysubd>>depth>>ieta>>iphi>>coradd>>corerr;
128 // DetId mydid(DetId::Hcal,HcalSubdetector(mysubd));
129 // HcalDetId hid(HcalSubdetector(mysubd),ieta,iphi,depth);
130 // HcalDetId hid(mydid);
131 // std::cout<<" Check mysubd "<<hid.subdet()<<" depth "<<hid.depth()<<" ieta "<<hid.ieta()<<" iphi "<<hid.iphi()<<" "<<hid.rawId()<< std::endl;
132  int ietak = ieta;
133  if(ieta<0) ietak = -1*ieta;
134  if(ieta>0) corrnew_p[mysubd][depth][ietak][iphi] = coradd;
135  if(ieta<0) corrnew_m[mysubd][depth][ietak][iphi] = coradd;
136  std::cout<<" Try to initialize mysubd "<<mysubd<<" depth "<<depth<<" ieta "<<ieta<<" "<<ietak<<" iphi "<<iphi<<" "<<coradd<<
137  std::endl;
138  }
139 
140  HcalRespCorrs* mycorrections = new HcalRespCorrs();
141 
142  for(std::vector<HcalDetId>::iterator it = theVector.begin(); it != theVector.end(); it++)
143  {
144  float cc1 = (*corrold.find(*it)).second;
145  // float cc2 = (*corrnew.find(*it)).second;
146  float cc2 = 0.;
147  int ietak = (*it).ieta();
148 
149  if((*it).ieta()<0) ietak=-1*(*it).ieta();
150 
151  if((*it).ieta()>0) cc2 = corrnew_p[(*it).subdet()][(*it).depth()][ietak][(*it).iphi()];
152  if((*it).ieta()<0) cc2 = corrnew_m[(*it).subdet()][(*it).depth()][ietak][(*it).iphi()];
153 
154  float cc = cc1*cc2;
155  std::cout<<" Multiply "<<(*it).subdet()<<" "<<(*it).depth()<<" "<<(*it).ieta()<<" "<<ietak<<" "<<(*it).iphi()<<" "<<(*it).rawId()<<" "<<cc1<<" "<<cc2<<std::endl;
156 
157  // now make the basic object for one cell with HcalDetId myDetId containing the value myValue
158  HcalRespCorr item ((*it).rawId(), cc);
159  mycorrections->addValues(item);
160  }
161 
162  HcalRespCorrs mycc = *mycorrections;
164 
165 }
int i
Definition: DBlmapReader.cc:9
bool addValues(const Item &myItem, bool h2mode_=false)
U second(std::pair< T, U > const &p)
int depth() const
get the tower depth
Definition: HcalDetId.h:42
int ieta() const
get the cell ieta
Definition: HcalDetId.h:38
int iphi() const
get the cell iphi
Definition: HcalDetId.h:40
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
std::vector< DetId > getValidDetIds() const
Get the list of all valid detector ids.
Definition: CaloGeometry.cc:90
bool dumpObject(std::ostream &fOutput, const HcalPedestals &fObject)
const JetExtendedData & getValue(const Container &, const reco::JetBaseRef &)
get value for the association. Throw exception if no association found
tuple cout
Definition: gather_cfg.py:41
const Item * getValues(DetId fId) const
void cms::HcalConstantsASCIIWriter::beginJob ( void  )
virtual

Reimplemented from edm::EDAnalyzer.

Definition at line 51 of file HcalConstantsASCIIWriter.cc.

References gather_cfg::cout, connectstrParser::f1, and edm::FileInPath::fullPath().

52 {
54  std::string fDataFile = f1.fullPath();
55 
56  myout_hcal = new ofstream(fDataFile.c_str());
57  if(!myout_hcal) std::cout << " Output file not open!!! "<<std::endl;
58 
59 }
tuple cout
Definition: gather_cfg.py:41
void cms::HcalConstantsASCIIWriter::endJob ( void  )
virtual

Reimplemented from edm::EDAnalyzer.

Definition at line 61 of file HcalConstantsASCIIWriter.cc.

62 {
63  delete myout_hcal;
64 }

Member Data Documentation

std::string cms::HcalConstantsASCIIWriter::file_input
private

Definition at line 63 of file HcalConstantsASCIIWriter.h.

std::string cms::HcalConstantsASCIIWriter::file_output
private

Definition at line 64 of file HcalConstantsASCIIWriter.h.

std::ofstream* cms::HcalConstantsASCIIWriter::myout_hcal
private

Definition at line 62 of file HcalConstantsASCIIWriter.h.