CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalPedestalMCWidths.cc
Go to the documentation of this file.
1 // Original Author: Steven Won
2 // Created: Fri May 2 15:34:43 CEST 2008
3 // Written to replace the combination of HcalPedestalAnalyzer and HcalPedestalAnalysis
4 // This code runs 1000x faster and produces all outputs from a single run
5 // (ADC, fC in .txt plus an .xml file)
6 //
7 #include <memory>
9 
11 {
12  firsttime = true;
13  histflag = ps.getUntrackedParameter<bool>("saveHists",true);
14 }
15 
16 
18 {
20  std::ofstream outfile(widthsfilename.c_str());
21  std::vector<MCWidthsBunch>::iterator bunch_it;
22  for(bunch_it=Bunches.begin(); bunch_it != Bunches.end(); bunch_it++)
23  {
24  if(!bunch_it->usedflag) continue;
25 
26  HcalCovarianceMatrix item(bunch_it->detid.rawId());
27  for(int i = 0; i != 4; i++){
28  for(int j = 0; j != 10; j++){
29  for(int k = 0; k != 10; k++){
30  bunch_it->sig[i][j][k] = (bunch_it->prod[i][j][k]/bunch_it->num[i][j][k]);//-(bunch_it->cap[i]*bunch_it->cap[(i+j)%4]);
31  if(!std::isnan(bunch_it->sig[i][j][k]))
32  {
33  item.setValue(i,j,k,bunch_it->sig[i][j][k]);
34  }else{
35  item.setValue(i,j,k,0.0);
36  }
37  }
38  }
39  }
40 
41  rawCovItem->addValues(item);
42 
43  if(histflag)
44  {
45  if(bunch_it->detid.subdet() == 1){
46  for(int i = 0; i != 4; i++){
47  for(int j = 0; j != 10; j++){
48  for(int k = j; k != 10; k++)
49  if(!std::isnan(bunch_it->sig[i][j][k])) HBMeans[j]->Fill(k-j,bunch_it->sig[i][j][k]);
50  }
51  }
52  }
53  if(bunch_it->detid.subdet() == 2){
54  for(int i = 0; i != 4; i++){
55  for(int j = 0; j != 10; j++){
56  for(int k = j; k != 10; k++)
57  if(!std::isnan(bunch_it->sig[i][j][k])) HEMeans[j]->Fill(k-j,bunch_it->sig[i][j][k]);
58  }
59  }
60  }
61  if(bunch_it->detid.subdet() == 3){
62  for(int i = 0; i != 4; i++){
63  for(int j = 0; j != 10; j++){
64  for(int k = j; k != 10; k++)
65  if(!std::isnan(bunch_it->sig[i][j][k])) HFMeans[j]->Fill(k-j,bunch_it->sig[i][j][k]);
66  }
67  }
68  }
69  if(bunch_it->detid.subdet() == 4){
70  for(int i = 0; i != 4; i++){
71  for(int j = 0; j != 10; j++){
72  for(int k = j; k != 10; k++)
73  if(!std::isnan(bunch_it->sig[i][j][k])) HOMeans[j]->Fill(k-j,bunch_it->sig[i][j][k]);
74  }
75  }
76  }
77 
78 
79  }
80  }
81  HcalDbASCIIIO::dumpObject (outfile, (*rawCovItem) );
82 
83  if(histflag)
84  {
85  theFile->cd();
86  std::cout << "Writing histograms..." << std::endl;
87  for(int i = 0; i != 10; i++){
88  HBMeans[i]->Write();
89  HFMeans[i]->Write();
90  HEMeans[i]->Write();
91  HOMeans[i]->Write();
92  }
93  }
94  theFile->Close();
95  std::cout << "ROOT file closed.\n";
96 }
97 
98 // ------------ method called to for each event ------------
99 void
101 {
102  using namespace edm;
103  using namespace std;
104 
108  edm::ESHandle<HcalDbService> conditions;
109  iSetup.get<HcalDbRecord>().get(conditions);
110 
112  iSetup.get<HcalPedestalsRcd>().get(refPeds);
113  const HcalPedestals* myRefPeds = refPeds.product();
114 
115  if(firsttime)
116  {
117  runnum = e.id().run();
118  std::string runnum_string;
119  std::stringstream tempstringout;
120  tempstringout << runnum;
121  runnum_string = tempstringout.str();
122  widthsfilename = runnum_string + "-MCwidths.txt";
123  std::string rootfilename = runnum_string + "-MCwidths.root";
124  theFile = new TFile(rootfilename.c_str(), "RECREATE");
125 
126  for(int i = 0; i!= 10; i++)
127  {
128  tempstringout.str("");
129  tempstringout << i;
130  std::string histname3 = tempstringout.str();
131  std::string histname2 = "Mean covariance TS ";
132  std::string histname1 = "HB ";
133  std::string histname = histname1 + histname2 + histname3;
134  HBMeans[i] = new TProfile(histname.c_str(),histname1.c_str(), 10, -0.50, 9.5);
135  histname1 = "HE ";
136  histname = histname1 + histname2 + histname3;
137  HEMeans[i] = new TProfile(histname.c_str(),histname1.c_str(), 10, -0.50, 9.5);
138  histname1 = "HF ";
139  histname = histname1 + histname2 + histname3;
140  HFMeans[i] = new TProfile(histname.c_str(),histname1.c_str(), 10, -0.50, 9.5);
141  histname1 = "HO ";
142  histname = histname1 + histname2 + histname3;
143  HOMeans[i] = new TProfile(histname.c_str(),histname1.c_str(), 10, -0.50, 9.5);
144  }
145 
147  iSetup.get<HcalElectronicsMapRcd>().get(refEMap);
148  const HcalElectronicsMap* myRefEMap = refEMap.product();
149  std::vector<HcalGenericDetId> listEMap = myRefEMap->allPrecisionId();
150  for (std::vector<HcalGenericDetId>::const_iterator it = listEMap.begin(); it != listEMap.end(); it++)
151  {
152  HcalGenericDetId mygenid(it->rawId());
153  if(mygenid.isHcalDetId())
154  {
156  HcalDetId chanid(mygenid.rawId());
157  a.detid = chanid;
158  a.usedflag = false;
159  for(int i = 0; i != 4; i++)
160  {
161  for(int j = 0; j != 10; j++){
162  for(int k = 0; k != 10; k++)
163  {
164  a.sig[i][j][k] = 0;
165  a.prod[i][j][k] = 0;
166  a.num[i][j][k] = 0;
167  }}
168  }
169  Bunches.push_back(a);
170  }
171  }
172  firsttime = false;
173  }
174 
175  std::vector<MCWidthsBunch>::iterator bunch_it;
176 
177  for(HBHEDigiCollection::const_iterator j = hbhe->begin(); j != hbhe->end(); j++)
178  {
179  const HBHEDataFrame digi = (const HBHEDataFrame)(*j);
180  for(bunch_it = Bunches.begin(); bunch_it != Bunches.end(); bunch_it++)
181  if(bunch_it->detid.rawId() == digi.id().rawId()) break;
182  DetId searchid(digi.id().rawId());
183  const HcalPedestal* peds = (myRefPeds->getValues( searchid ));
184  bunch_it->usedflag = true;
185  int firstcapid = digi.sample(0).capid();
186  for(int ts = 0; ts != 10; ts++)
187  {
188  for(int j = ts; j != 10; j++){
189  bunch_it->num[firstcapid][ts][j] += 1;
190  bunch_it->prod[firstcapid][ts][j] +=
191  ((digi.sample(j).adc()-peds->getValue(firstcapid))
192  *(digi.sample(ts).adc()-peds->getValue(digi.sample(ts).capid())));
193  }
194  }
195  }
196 
197  for(HODigiCollection::const_iterator j = ho->begin(); j != ho->end(); j++)
198  {
199  const HODataFrame digi = (const HODataFrame)(*j);
200  for(bunch_it = Bunches.begin(); bunch_it != Bunches.end(); bunch_it++)
201  if(bunch_it->detid.rawId() == digi.id().rawId()) break;
202  DetId searchid(digi.id().rawId());
203  const HcalPedestal* peds = (myRefPeds->getValues( searchid ));
204  bunch_it->usedflag = true;
205  int firstcapid = digi.sample(0).capid();
206  for(int ts = 0; ts != 10; ts++)
207  {
208  for(int j = ts; j != 10; j++){
209  bunch_it->num[firstcapid][ts][j] += 1;
210  bunch_it->prod[firstcapid][ts][j] +=
211  ((digi.sample(j).adc()-peds->getValue(firstcapid))
212  *(digi.sample(ts).adc()-peds->getValue(digi.sample(ts).capid())));
213  }
214  }
215  }
216 
217  for(HFDigiCollection::const_iterator j = hf->begin(); j != hf->end(); j++)
218  {
219  const HFDataFrame digi = (const HFDataFrame)(*j);
220  for(bunch_it = Bunches.begin(); bunch_it != Bunches.end(); bunch_it++)
221  if(bunch_it->detid.rawId() == digi.id().rawId()) break;
222  DetId searchid(digi.id().rawId());
223  const HcalPedestal* peds = (myRefPeds->getValues( searchid ));
224  bunch_it->usedflag = true;
225  int firstcapid = digi.sample(0).capid();
226  for(int ts = 0; ts != 10; ts++)
227  {
228  for(int j = ts; j != 10; j++){
229  bunch_it->num[firstcapid][ts][j] += 1;
230  bunch_it->prod[firstcapid][ts][j] +=
231  ((digi.sample(j).adc()-peds->getValue(firstcapid))
232  *(digi.sample(ts).adc()-peds->getValue(digi.sample(ts).capid())));
233  }
234  }
235 
236  }
237 //this is the last brace
238 }
239 
240 //define this as a plug-in
RunNumber_t run() const
Definition: EventID.h:42
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
int num[4][10][10]
HcalPedestalMCWidths(const edm::ParameterSet &ps)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
int adc() const
get the ADC sample
Definition: HcalQIESample.h:24
float sig[4][10][10]
std::vector< T >::const_iterator const_iterator
bool getByType(Handle< PROD > &result) const
Definition: Event.h:403
const HcalQIESample & sample(int i) const
access a sample
Definition: HODataFrame.h:40
const HcalDetId & id() const
Definition: HODataFrame.h:23
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
std::vector< MCWidthsBunch > Bunches
bool addValues(const HcalCovarianceMatrix &myHcalCovarianceMatrix, bool h2mode_=false)
list outfile
Definition: EdgesToViz.py:91
bool isnan(float x)
Definition: math.h:13
const HcalQIESample & sample(int i) const
access a sample
Definition: HFDataFrame.h:39
int j
Definition: DBlmapReader.cc:9
void analyze(const edm::Event &event, const edm::EventSetup &eventSetup)
std::vector< HcalGenericDetId > allPrecisionId() const
int k[5][pyjets_maxn]
Definition: DetId.h:20
int capid() const
get the Capacitor id
Definition: HcalQIESample.h:28
const HcalQIESample & sample(int i) const
access a sample
Definition: HBHEDataFrame.h:39
float prod[4][10][10]
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
void setValue(int capid, int i, int j, float val)
edm::EventID id() const
Definition: EventBase.h:56
bool dumpObject(std::ostream &fOutput, const HcalPedestals &fObject)
double a
Definition: hdecay.h:121
const HcalDetId & id() const
Definition: HBHEDataFrame.h:22
tuple cout
Definition: gather_cfg.py:41
const HcalDetId & id() const
Definition: HFDataFrame.h:22