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
HcalPedestalMCWidths Class Reference

#include <HcalPedestalMCWidths.h>

Inheritance diagram for HcalPedestalMCWidths:
edm::EDAnalyzer

Public Member Functions

void analyze (const edm::Event &event, const edm::EventSetup &eventSetup)
 
 HcalPedestalMCWidths (const edm::ParameterSet &ps)
 
virtual ~HcalPedestalMCWidths ()
 
- Public Member Functions inherited from edm::EDAnalyzer
 EDAnalyzer ()
 
std::string workerType () const
 
virtual ~EDAnalyzer ()
 

Private Attributes

std::vector< MCWidthsBunchBunches
 
bool firsttime
 
TProfile * HBMeans [10]
 
TProfile * HEMeans [10]
 
TProfile * HFMeans [10]
 
bool histflag
 
TProfile * HOMeans [10]
 
std::string pedsADCfilename
 
int runnum
 
TFile * theFile
 
std::string widthsfilename
 

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)
 
static void prevalidate (ConfigurationDescriptions &)
 
- Protected Member Functions inherited from edm::EDAnalyzer
CurrentProcessingContext const * currentContext () const
 

Detailed Description

Definition at line 68 of file HcalPedestalMCWidths.h.

Constructor & Destructor Documentation

HcalPedestalMCWidths::HcalPedestalMCWidths ( const edm::ParameterSet ps)

Definition at line 10 of file HcalPedestalMCWidths.cc.

References firsttime, edm::ParameterSet::getUntrackedParameter(), and histflag.

11 {
12  firsttime = true;
13  histflag = ps.getUntrackedParameter<bool>("saveHists",true);
14 }
T getUntrackedParameter(std::string const &, T const &) const
HcalPedestalMCWidths::~HcalPedestalMCWidths ( )
virtual

Definition at line 17 of file HcalPedestalMCWidths.cc.

References HcalCovarianceMatrices::addValues(), Bunches, gather_cfg::cout, HcalDbASCIIIO::dumpObject(), HcalObjRepresent::Fill(), HBMeans, HEMeans, HFMeans, histflag, HOMeans, i, edm::detail::isnan(), j, gen::k, EdgesToViz::outfile, HcalCovarianceMatrix::setValue(), theFile, and widthsfilename.

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 }
int i
Definition: DBlmapReader.cc:9
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
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
int j
Definition: DBlmapReader.cc:9
int k[5][pyjets_maxn]
void setValue(int capid, int i, int j, float val)
bool dumpObject(std::ostream &fOutput, const HcalPedestals &fObject)
tuple cout
Definition: gather_cfg.py:121

Member Function Documentation

void HcalPedestalMCWidths::analyze ( const edm::Event event,
const edm::EventSetup eventSetup 
)
virtual

Implements edm::EDAnalyzer.

Definition at line 100 of file HcalPedestalMCWidths.cc.

References a, HcalQIESample::adc(), HcalElectronicsMap::allPrecisionId(), Bunches, HcalQIESample::capid(), MCWidthsBunch::detid, firsttime, edm::EventSetup::get(), edm::Event::getByType(), HBMeans, HEMeans, HFMeans, HOMeans, i, HFDataFrame::id(), HBHEDataFrame::id(), HODataFrame::id(), edm::EventBase::id(), j, gen::k, MCWidthsBunch::num, MCWidthsBunch::prod, edm::ESHandle< class >::product(), DetId::rawId(), edm::EventID::run(), runnum, HBHEDataFrame::sample(), HFDataFrame::sample(), HODataFrame::sample(), MCWidthsBunch::sig, theFile, MCWidthsBunch::usedflag, and widthsfilename.

101 {
102  using namespace edm;
103  using namespace std;
104 
105  edm::Handle<HBHEDigiCollection> hbhe; e.getByType(hbhe);
106  edm::Handle<HODigiCollection> ho; e.getByType(ho);
107  edm::Handle<HFDigiCollection> hf; e.getByType(hf);
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 }
int i
Definition: DBlmapReader.cc:9
int num[4][10][10]
int adc() const
get the ADC sample
Definition: HcalQIESample.h:24
float sig[4][10][10]
std::vector< T >::const_iterator const_iterator
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
const HcalQIESample & sample(int i) const
access a sample
Definition: HFDataFrame.h:39
int j
Definition: DBlmapReader.cc:9
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]
T const * product() const
Definition: ESHandle.h:62
double a
Definition: hdecay.h:121
const HcalDetId & id() const
Definition: HBHEDataFrame.h:22
const HcalDetId & id() const
Definition: HFDataFrame.h:22

Member Data Documentation

std::vector<MCWidthsBunch> HcalPedestalMCWidths::Bunches
private

Definition at line 80 of file HcalPedestalMCWidths.h.

Referenced by analyze(), and ~HcalPedestalMCWidths().

bool HcalPedestalMCWidths::firsttime
private

Definition at line 93 of file HcalPedestalMCWidths.h.

Referenced by analyze(), and HcalPedestalMCWidths().

TProfile* HcalPedestalMCWidths::HBMeans[10]
private

Definition at line 87 of file HcalPedestalMCWidths.h.

Referenced by analyze(), and ~HcalPedestalMCWidths().

TProfile* HcalPedestalMCWidths::HEMeans[10]
private

Definition at line 88 of file HcalPedestalMCWidths.h.

Referenced by analyze(), and ~HcalPedestalMCWidths().

TProfile* HcalPedestalMCWidths::HFMeans[10]
private

Definition at line 89 of file HcalPedestalMCWidths.h.

Referenced by analyze(), and ~HcalPedestalMCWidths().

bool HcalPedestalMCWidths::histflag
private

Definition at line 94 of file HcalPedestalMCWidths.h.

Referenced by HcalPedestalMCWidths(), and ~HcalPedestalMCWidths().

TProfile* HcalPedestalMCWidths::HOMeans[10]
private

Definition at line 90 of file HcalPedestalMCWidths.h.

Referenced by analyze(), and ~HcalPedestalMCWidths().

std::string HcalPedestalMCWidths::pedsADCfilename
private

Definition at line 82 of file HcalPedestalMCWidths.h.

int HcalPedestalMCWidths::runnum
private

Definition at line 85 of file HcalPedestalMCWidths.h.

Referenced by analyze().

TFile* HcalPedestalMCWidths::theFile
private

Definition at line 92 of file HcalPedestalMCWidths.h.

Referenced by analyze(), and ~HcalPedestalMCWidths().

std::string HcalPedestalMCWidths::widthsfilename
private

Definition at line 83 of file HcalPedestalMCWidths.h.

Referenced by analyze(), and ~HcalPedestalMCWidths().