CMS 3D CMS Logo

MinBias.cc
Go to the documentation of this file.
1 // user include files
5 
6 using namespace std;
7 namespace cms
8 {
9 MinBias::MinBias(const edm::ParameterSet& iConfig)
10 {
11  // get names of modules, producing object collections
12  hbheLabel_= iConfig.getParameter<std::string>("hbheInput");
13  hoLabel_= iConfig.getParameter<std::string>("hoInput");
14  hfLabel_= iConfig.getParameter<std::string>("hfInput");
15  hbheToken_= mayConsume<HBHERecHitCollection>(edm::InputTag(hbheLabel_));
16  hoToken_=mayConsume<HORecHitCollection>(edm::InputTag(hoLabel_));
17  hfToken_=mayConsume<HFRecHitCollection>(edm::InputTag(hfLabel_));
18  allowMissingInputs_=iConfig.getUntrackedParameter<bool>("AllowMissingInputs",false);
19  // get name of output file with histogramms
20  fOutputFileName = iConfig.getUntrackedParameter<std::string>("HistOutFile");
21 
22 }
23 
24 
25 MinBias::~MinBias()
26 {
27 
28  // do anything here that needs to be done at desctruction time
29  // (e.g. close files, deallocate resources etc.)
30 
31 }
32 
34 {
35  hOutputFile = new TFile( fOutputFileName.c_str(), "RECREATE" ) ;
36  myTree = new TTree("RecJet","RecJet Tree");
37  myTree->Branch("mydet", &mydet, "mydet/I");
38  myTree->Branch("mysubd", &mysubd, "mysubd/I");
39  myTree->Branch("depth", &depth, "depth/I");
40  myTree->Branch("ieta", &ieta, "ieta/I");
41  myTree->Branch("iphi", &iphi, "iphi/I");
42  myTree->Branch("eta", &eta, "eta/F");
43  myTree->Branch("phi", &phi, "phi/F");
44  myTree->Branch("mom1", &mom1, "mom1/F");
45  myTree->Branch("mom2", &mom2, "mom2/F");
46  myTree->Branch("mom3", &mom3, "mom3/F");
47  myTree->Branch("mom4", &mom4, "mom4/F");
48 
49  ievent = 0;
50 
51 }
52 
53 void MinBias::endJob()
54 {
55 
56  const std::vector<DetId>& did = geo->getSubdetectorGeometry( DetId::Hcal, 1 )->getValidDetIds() ;
57  int i=0;
58  for(std::vector<DetId>::const_iterator id=did.begin(); id != did.end(); id++)
59  {
60 // if( (*id).det() == DetId::Hcal ) {
61  GlobalPoint pos = geo->getPosition(*id);
62  mydet = ((*id).rawId()>>28)&0xF;
63  mysubd = ((*id).rawId()>>25)&0x7;
64  depth = HcalDetId(*id).depth();
65  ieta = HcalDetId(*id).ieta();
66  iphi = HcalDetId(*id).iphi();
67  phi = pos.phi();
68  eta = pos.eta();
69  if ( theFillDetMap0[*id] > 0. )
70  {
71  mom1 = theFillDetMap1[*id]/theFillDetMap0[*id];
72  mom2 = theFillDetMap2[*id]/theFillDetMap0[*id]-(mom1*mom1);
73  mom3 = theFillDetMap3[*id]/theFillDetMap0[*id]-3.*mom1*theFillDetMap2[*id]/theFillDetMap0[*id]+
74  2.*pow(mom2,3);
75  mom4 = (theFillDetMap4[*id]-4.*mom1*theFillDetMap3[*id]+6.*pow(mom1,2)*theFillDetMap2[*id])/theFillDetMap0[*id]-3.*pow(mom1,4);
76 
77  } else
78  {
79  mom1 = 0.; mom2 = 0.; mom3 = 0.; mom4 = 0.;
80  }
81  std::cout<<" Detector "<<(*id).rawId()<<" mydet "<<mydet<<" "<<mysubd<<" "<<depth<<" "<<
82  HcalDetId(*id).subdet()<<" "<<ieta<<" "<<iphi<<" "<<pos.eta()<<" "<<pos.phi()<<std::endl;
83  std::cout<<" Energy "<<mom1<<" "<<mom2<<std::endl;
84  myTree->Fill();
85  i++;
86 // }
87  }
88  std::cout<<" The number of CaloDet records "<<did.size()<<std::endl;
89  std::cout<<" The number of Hcal records "<<i<<std::endl;
90 
91 
92  std::cout << "===== Start writing user histograms =====" << std::endl;
93  hOutputFile->SetCompressionLevel(2);
94  hOutputFile->cd();
95  myTree->Write();
96  hOutputFile->Close() ;
97  std::cout << "===== End writing user histograms =======" << std::endl;
98 }
99 
100 
101 //
102 // member functions
103 //
104 
105 // ------------ method called to produce the data ------------
106 void
108 {
109 
110  using namespace edm;
111  if(ievent == 0 ){
113  iSetup.get<CaloGeometryRecord>().get(pG);
114  geo = pG.product();
115  std::vector<DetId> did = geo->getValidDetIds();
116 
117  for(std::vector<DetId>::const_iterator id=did.begin(); id != did.end(); id++)
118  {
119  if( (*id).det() == DetId::Hcal ) {
120  theFillDetMap0[*id] = 0.;
121  theFillDetMap1[*id] = 0.;
122  theFillDetMap2[*id] = 0.;
123  theFillDetMap3[*id] = 0.;
124  theFillDetMap4[*id] = 0.;
125  }
126  }
127  }
128 
129 
130 
131  if (!hbheLabel_.empty()) {
133  iEvent.getByToken(hbheToken_,hbhe);
134  if (!hbhe.isValid()) {
135  // can't find it!
136  if (!allowMissingInputs_) {
137  *hbhe; // will throw the proper exception
138  }
139  } else {
140  for(HBHERecHitCollection::const_iterator hbheItr = (*hbhe).begin();
141  hbheItr != (*hbhe).end(); ++hbheItr)
142  {
143  DetId id = (hbheItr)->detid();
144  if( (*hbheItr).energy() > 0. ) std::cout<<" Energy = "<<(*hbheItr).energy()<<std::endl;
145  theFillDetMap0[id] = theFillDetMap0[id]+ 1.;
146  theFillDetMap1[id] = theFillDetMap1[id]+(*hbheItr).energy();
147  theFillDetMap2[id] = theFillDetMap2[id]+pow((*hbheItr).energy(),2);
148  theFillDetMap3[id] = theFillDetMap3[id]+pow((*hbheItr).energy(),3);
149  theFillDetMap4[id] = theFillDetMap4[id]+pow((*hbheItr).energy(),4);
150  }
151  }
152  }
153 
154  if (!hoLabel_.empty()) {
156  iEvent.getByToken(hoToken_,ho);
157  if (!ho.isValid()) {
158  // can't find it!
159  if (!allowMissingInputs_) {
160  *ho; // will throw the proper exception
161  }
162  } else {
163  for(HORecHitCollection::const_iterator hoItr = (*ho).begin();
164  hoItr != (*ho).end(); ++hoItr)
165  {
166  DetId id = (hoItr)->detid();
167  theFillDetMap0[id] = theFillDetMap0[id]+ 1.;
168  theFillDetMap1[id] = theFillDetMap1[id]+(*hoItr).energy();
169  theFillDetMap2[id] = theFillDetMap2[id]+pow((*hoItr).energy(),2);
170  theFillDetMap3[id] = theFillDetMap3[id]+pow((*hoItr).energy(),3);
171  theFillDetMap4[id] = theFillDetMap4[id]+pow((*hoItr).energy(),4);
172  }
173  }
174  }
175 
176  if (!hfLabel_.empty()) {
178  iEvent.getByToken(hfToken_,hf);
179  if (!hf.isValid()) {
180  // can't find it!
181  if (!allowMissingInputs_) {
182  *hf; // will throw the proper exception
183  }
184  } else {
185  for(HFRecHitCollection::const_iterator hfItr = (*hf).begin();
186  hfItr != (*hf).end(); ++hfItr)
187  {
188  DetId id = (hfItr)->detid();
189  theFillDetMap0[id] = theFillDetMap0[id]+ 1.;
190  theFillDetMap1[id] = theFillDetMap1[id]+(*hfItr).energy();
191  theFillDetMap2[id] = theFillDetMap2[id]+pow((*hfItr).energy(),2);
192  theFillDetMap3[id] = theFillDetMap3[id]+pow((*hfItr).energy(),3);
193  theFillDetMap4[id] = theFillDetMap4[id]+pow((*hfItr).energy(),4);
194  }
195  }
196  }
197 
198 }
199 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:49
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
def analyze(function, filename, filter=None)
Definition: Profiling.py:11
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
std::vector< HBHERecHit >::const_iterator const_iterator
void beginJob()
Definition: Breakpoints.cc:15
int depth() const
get the tower depth
Definition: HcalDetId.cc:108
int iEvent
Definition: GenABIO.cc:230
int ieta() const
get the cell ieta
Definition: HcalDetId.h:56
bool isValid() const
Definition: HandleBase.h:74
int iphi() const
get the cell iphi
Definition: HcalDetId.cc:103
Definition: DetId.h:18
const T & get() const
Definition: EventSetup.h:56
std::vector< DetId > getValidDetIds() const
Get the list of all valid detector ids.
Definition: CaloGeometry.cc:92
T eta() const
Definition: PV3DBase.h:76
HLT enums.
T const * product() const
Definition: ESHandle.h:86
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40