CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiStripGainFromAsciiFile.cc
Go to the documentation of this file.
4 
6 
8 
9 
10 #include <iostream>
11 #include <fstream>
12 #include <sstream>
13 
14 
16 
17 
18  Asciifilename_=iConfig.getParameter<std::string>("InputFileName");
19  referenceValue_ = iConfig.getParameter<double>("referenceValue");
20  fp_ = iConfig.getUntrackedParameter<edm::FileInPath>("file",edm::FileInPath("CalibTracker/SiStripCommon/data/SiStripDetInfo.dat"));
21 }
22 
23 
25  edm::LogInfo("SiStripGainFromAsciiFile::~SiStripGainFromAsciiFile");
26 }
27 
29 
31 
32  uint32_t detid;
33  FibersGain FG;
34 
35  std::stringstream ss;
36  ss.str("");
37  ss << "[SiStripGainFromAsciiFile::getNewObject]\n Reading Ascii File\n";
38  std::ifstream infile;
39  infile.open (Asciifilename_.c_str());
40  if (infile.is_open()){
41  while (infile.good()){
42  infile >> detid >> FG.fiber[0] >> FG.fiber[1] >> FG.fiber[2];
43  ss << detid << " " << FG.fiber[0] << " " << FG.fiber[1] << " " << FG.fiber[2] << std::endl;
44  GainsMap.insert(std::pair<unsigned int,FibersGain>(detid,FG));
45  }
46  infile.close();
47  edm::LogInfo("SiStripGainFromAsciiFile") << ss.str();
48  } else {
49  edm::LogError("SiStripGainFromAsciiFile")<< " [SiStripGainFromAsciiFile::getNewObject] Error opening file " << Asciifilename_ << std::endl;
50  assert(0);
51  }
52 
53 
54 
56 
57  const std::vector<uint32_t> DetIds = reader.getAllDetIds();
58 
59  ss.str("");
60  ss << "[SiStripGainFromAsciiFile::getNewObject]\n Filling SiStripApvGain object";
61  short nApvPair;
62  for(std::vector<uint32_t>::const_iterator it=DetIds.begin(); it!=DetIds.end(); it++){
63 
64  if (DetId(*it).det()!=DetId::Tracker)
65  continue;
66 
67  nApvPair=reader.getNumberOfApvsAndStripLength(*it).first/2;
68 
69  ss << "Looking at detid " << *it << " nApvPairs " << nApvPair << std::endl;
70 
71  __gnu_cxx::hash_map< unsigned int,FibersGain>::const_iterator iter=GainsMap.find(*it);
72 
73  if (iter!=GainsMap.end()){
74  FG = iter->second;
75  ss << " " << FG.fiber[0] << " " << FG.fiber[1] << " " << FG.fiber[2] << std::endl;
76  }
77  else {
78  ss << "Hard reset for detid " << *it << std::endl;
80  }
81 
82  std::vector<float> DetGainsVector;
83 
84  if (nApvPair==2){
85  DetGainsVector.push_back(FG.fiber[0]/referenceValue_);
86  DetGainsVector.push_back(FG.fiber[0]/referenceValue_);
87  DetGainsVector.push_back(FG.fiber[2]/referenceValue_);
88  DetGainsVector.push_back(FG.fiber[2]/referenceValue_);
89  } else if (nApvPair==3){
90  DetGainsVector.push_back(FG.fiber[0]/referenceValue_);
91  DetGainsVector.push_back(FG.fiber[0]/referenceValue_);
92  DetGainsVector.push_back(FG.fiber[1]/referenceValue_);
93  DetGainsVector.push_back(FG.fiber[1]/referenceValue_);
94  DetGainsVector.push_back(FG.fiber[2]/referenceValue_);
95  DetGainsVector.push_back(FG.fiber[2]/referenceValue_);
96  } else {
97  edm::LogError("SiStripGainFromAsciiFile") << " SiStripGainFromAsciiFile::getNewObject] ERROR for detid " << *it << " not expected number of APV pairs " << nApvPair <<std::endl;
98  }
99 
100  SiStripApvGain::Range range(DetGainsVector.begin(),DetGainsVector.end());
101  if ( ! obj->put(*it,range) ){
102  edm::LogError("SiStripGainFromAsciiFile")<<" [SiStripGainFromAsciiFile::getNewObject] detid already exists"<<std::endl;
103  ss <<" [SiStripGainFromAsciiFile::getNewObject] detid already exists"<<std::endl;
104  }
105  }
106  edm::LogInfo("SiStripGainFromAsciiFile") << ss.str();
107 
108  return obj;
109 }
110 
111 
112 
113 
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
SiStripGainFromAsciiFile(const edm::ParameterSet &)
assert(m_qm.get())
__gnu_cxx::hash_map< unsigned int, FibersGain > GainsMap
bool put(const uint32_t &detID, Range input)
std::pair< ContainerIterator, ContainerIterator > Range
Definition: DetId.h:18
std::string fullPath() const
Definition: FileInPath.cc:165
Detector det() const
get the detector field from this detid
Definition: DetId.h:35