CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalPulseCovariancesHandler.cc
Go to the documentation of this file.
2 
3 #include<iostream>
4 #include<fstream>
5 
7  : m_name(ps.getUntrackedParameter<std::string>("name","EcalPulseCovariancesHandler")) {
8 
9  std::cout << "EcalPulseCovariance Source handler constructor\n" << std::endl;
10  m_firstRun=static_cast<unsigned int>(atoi( ps.getParameter<std::string>("firstRun").c_str()));
11  m_filename=ps.getParameter<std::string>("inputFileName");
12  m_EBPulseShapeCovariance = ps.getParameter<std::vector<double> >("EBPulseShapeCovariance");
13  m_EEPulseShapeCovariance = ps.getParameter<std::vector<double> >("EEPulseShapeCovariance");
14 }
15 
17 {
18 }
19 
20 
22  // true means all is standard and OK
23  bool result=true;
24  for(int k=0; k<std::pow(EcalPulseShape::TEMPLATESAMPLES,2); ++k) {
27  if(fabs(item->covval[i][j]) > 1) result=false;
28  }
29  return result;
30 }
31 
33  for(int k=0; k<std::pow(EcalPulseShape::TEMPLATESAMPLES,2); ++k) {
36  item->covval[i][j] = isbarrel ? m_EBPulseShapeCovariance[k] : m_EEPulseShapeCovariance[k];
37  }
38 }
39 
41 {
42 
43  std::cout << "------- Ecal - > getNewObjects\n";
44 
45  // create the object pukse shapes
46  EcalPulseCovariances* pulsecovs = new EcalPulseCovariances();
47 
48  // read the templates from a text file
49  std::ifstream inputfile;
50  inputfile.open(m_filename.c_str());
52  unsigned int rawId;
53  int isbarrel;
55 
56  // keep track of bad crystals
57  int nEBbad(0), nEEbad(0);
58  int nEBgood(0), nEEgood(0);
59  std::vector<EBDetId> ebgood;
60  std::vector<EEDetId> eegood;
61 
62  // fill with the measured shapes only for data
63  if(m_firstRun > 1) {
64  while (std::getline(inputfile, line)) {
65  std::istringstream linereader(line);
66  linereader >> isbarrel >> rawId;
67  // std::cout << "Inserting template for crystal with rawId = " << rawId << " (isbarrel = " << isbarrel << ") " << std::endl;
68  for(int k=0; k<std::pow(EcalPulseShape::TEMPLATESAMPLES,2); ++k) {
71  linereader >> covvals[i][j];
72  }
73 
74  if (!linereader) {
75  std::cout << "Wrong format of the text file. Exit." << std::endl;
76  return;
77  }
79  for(int i=0; i<EcalPulseShape::TEMPLATESAMPLES; ++i) for(int j=0; j<EcalPulseShape::TEMPLATESAMPLES; ++j) item.covval[i][j] = covvals[i][j];
80 
81  if(isbarrel) {
82  EBDetId ebdetid(rawId);
83  if(!checkPulseCovariance(&item) ) nEBbad++;
84  else {
85  nEBgood++;
86  ebgood.push_back(ebdetid);
87  pulsecovs->insert(std::make_pair(ebdetid.rawId(),item));
88  }
89  } else {
90  EEDetId eedetid(rawId);
91  if(!checkPulseCovariance(&item) ) nEEbad++;
92  else {
93  nEEgood++;
94  eegood.push_back(eedetid);
95  pulsecovs->insert(std::make_pair(eedetid.rawId(),item));
96  }
97  }
98  }
99  }
100 
101  // now fill the bad crystals and simulation with the simulation values (from TB)
102  std::cout << "Filled the DB with the good measured ECAL templates. Now filling the others with the TB values" << std::endl;
103  for(int iEta=-EBDetId::MAX_IETA; iEta<=EBDetId::MAX_IETA ;++iEta) {
104  if(iEta==0) continue;
105  for(int iPhi=EBDetId::MIN_IPHI; iPhi<=EBDetId::MAX_IPHI; ++iPhi) {
106  if (EBDetId::validDetId(iEta,iPhi)) {
107  EBDetId ebdetid(iEta,iPhi,EBDetId::ETAPHIMODE);
108 
109  std::vector<EBDetId>::iterator it = find(ebgood.begin(),ebgood.end(),ebdetid);
110  if(it == ebgood.end()) {
112  fillSimPulseCovariance(&item,true);
113  pulsecovs->insert(std::make_pair(ebdetid.rawId(),item));
114  }
115  }
116  }
117  }
118 
119  for(int iZ=-1; iZ<2; iZ+=2) {
120  for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
121  for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
122  if (EEDetId::validDetId(iX,iY,iZ)) {
123  EEDetId eedetid(iX,iY,iZ);
124 
125  std::vector<EEDetId>::iterator it = find(eegood.begin(),eegood.end(),eedetid);
126  if(it == eegood.end()) {
128  fillSimPulseCovariance(&item,false);
129  pulsecovs->insert(std::make_pair(eedetid.rawId(),item));
130  }
131  }
132  }
133  }
134  }
135 
136  std::cout << "Inserted the pulse covariances into the new item object" << std::endl;
137 
138  unsigned int irun=m_firstRun;
139  Time_t snc= (Time_t) irun ;
140 
141  m_to_transfer.push_back(std::make_pair((EcalPulseCovariances*)pulsecovs,snc));
142 
143  std::cout << "Ecal - > end of getNewObjects -----------" << std::endl;
144  std::cout << "N. bad shapes for EB = " << nEBbad << std::endl;
145  std::cout << "N. bad shapes for EE = " << nEEbad << std::endl;
146  std::cout << "Written the object" << std::endl;
147 
148 }
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
static const int MIN_IPHI
Definition: EBDetId.h:142
void fillSimPulseCovariance(EcalPulseCovariances::Item *item, bool isbarrel)
static const int TEMPLATESAMPLES
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
static const int IX_MIN
Definition: EEDetId.h:294
static const int IY_MIN
Definition: EEDetId.h:298
static bool validDetId(int i, int j)
check if a valid index combination
Definition: EBDetId.h:124
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
tuple result
Definition: query.py:137
int j
Definition: DBlmapReader.cc:9
EcalPulseCovariancesMap EcalPulseCovariances
static const int ETAPHIMODE
Definition: EBDetId.h:166
float covval[EcalPulseShape::TEMPLATESAMPLES][EcalPulseShape::TEMPLATESAMPLES]
void insert(std::pair< uint32_t, Item > const &a)
static const int IX_MAX
Definition: EEDetId.h:302
static const int MAX_IPHI
Definition: EBDetId.h:144
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.h:248
static const int MAX_IETA
Definition: EBDetId.h:143
cond::Time_t Time_t
Definition: Time.h:17
tuple cout
Definition: gather_cfg.py:121
static const int IY_MAX
Definition: EEDetId.h:306
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
EcalPulseCovariancesHandler(edm::ParameterSet const &)
bool checkPulseCovariance(EcalPulseCovariances::Item *item)