CMS 3D CMS Logo

DoCastorAnalysis.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Forward
4 // Class : DoCastorAnalysis
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: P. Katsas
10 // Created: 02/2007
11 //
15 
18 
19 #include "TFile.h"
20 #include <cmath>
21 #include <iostream>
22 #include <iomanip>
23 #include <memory>
24 #include <vector>
25 
26 #define debug 0
27 
29  edm::ParameterSet m_Anal = p.getParameter<edm::ParameterSet>("DoCastorAnalysis");
30  verbosity = m_Anal.getParameter<int>("Verbosity");
31 
32  TreeFileName = m_Anal.getParameter<std::string>("CastorTreeFileName");
33 
34  if (verbosity > 0) {
35  std::cout << std::endl;
36  std::cout << "============================================================================" << std::endl;
37  std::cout << "DoCastorAnalysis:: Initialized as observer" << std::endl;
38 
39  std::cout << " Castor Tree will be created" << std::endl;
40  std::cout << " Castor Tree will be in file: " << TreeFileName << std::endl;
41  if (debug)
42  getchar();
43 
44  std::cout << "============================================================================" << std::endl;
45  std::cout << std::endl;
46  }
47 
48  std::cout << "DoCastorAnalysis: output event root file created" << std::endl;
49  TString treefilename = TreeFileName;
50  CastorOutputEventFile = new TFile(treefilename, "RECREATE");
51 
52  CastorTree = new TTree("Sim", "Sim");
53 
54  CastorTree->Branch("simhit_x", "std::vector<double>", &psimhit_x);
55  CastorTree->Branch("simhit_y", "std::vector<double>", &psimhit_y);
56  CastorTree->Branch("simhit_z", "std::vector<double>", &psimhit_z);
57 
58  CastorTree->Branch("simhit_eta", "std::vector<double>", &psimhit_eta);
59  CastorTree->Branch("simhit_phi", "std::vector<double>", &psimhit_phi);
60  CastorTree->Branch("simhit_energy", "std::vector<double>", &psimhit_energy);
61 
62  // CastorTree->Branch("simhit_time","std::vector<double>",&psimhit_time);
63  CastorTree->Branch("simhit_sector", "std::vector<int>", &psimhit_sector);
64  CastorTree->Branch("simhit_module", "std::vector<int>", &psimhit_module);
65 
66  CastorTree->Branch("simhit_etot", &simhit_etot, "simhit_etot/D");
67 }
68 
70  //destructor of DoCastorAnalysis
71 
73  //-- CastorOutputEventFile->Write();
74  CastorTree->Write("", TObject::kOverwrite);
75  std::cout << "DoCastorAnalysis: Ntuple event written" << std::endl;
76  if (debug)
77  getchar();
78  CastorOutputEventFile->Close();
79  std::cout << "DoCastorAnalysis: Event file closed" << std::endl;
80  if (debug)
81  getchar();
82 
83  if (verbosity > 0) {
84  std::cout << std::endl << "DoCastorAnalysis: end of process" << std::endl;
85  if (debug)
86  getchar();
87  }
88 }
89 
90 //=================================================================== per EVENT
91 
92 void DoCastorAnalysis::update(const BeginOfJob* job) { std::cout << " Starting new job " << std::endl; }
93 
94 //==================================================================== per RUN
95 
97  std::cout << std::endl << "DoCastorAnalysis: Starting Run" << std::endl;
98 
99  // std::cout << "DoCastorAnalysis: output event root file created"<< std::endl;
100  // TString treefilename = TreeFileName;
101  // CastorOutputEventFile = new TFile(treefilename,"RECREATE");
102 
103  eventIndex = 1;
104 }
105 
107  std::cout << "DoCastorAnalysis: Processing Event Number: " << eventIndex << std::endl;
108  eventIndex++;
109 }
110 
111 //================= End of EVENT ===============
112 
114  // Look for the Hit Collection
115 
116  // access to the G4 hit collections
117  G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
118 
119  int CAFIid = G4SDManager::GetSDMpointer()->GetCollectionID("CastorFI");
120  CaloG4HitCollection* theCAFI = (CaloG4HitCollection*)allHC->GetHC(CAFIid);
121 
122  CastorNumberingScheme* theCastorNumScheme = new CastorNumberingScheme();
123 
124  unsigned int volumeID = 0;
125  // std::map<int,float,std::less<int> > themap;
126 
127  int nentries = theCAFI->entries();
128  if (debug)
129  std::cout << "nentries in CAFI: " << nentries << std::endl;
130  if (debug)
131  getchar();
132 
133  psimhit_x = &simhit_x;
134  psimhit_x->clear();
135  psimhit_x->reserve(nentries);
136 
137  psimhit_y = &simhit_y;
138  psimhit_y->clear();
139  psimhit_y->reserve(nentries);
140 
141  psimhit_z = &simhit_z;
142  psimhit_z->clear();
143  psimhit_z->reserve(nentries);
144 
146  psimhit_eta->clear();
147  psimhit_eta->reserve(nentries);
148 
150  psimhit_phi->clear();
151  psimhit_phi->reserve(nentries);
152 
154  psimhit_energy->clear();
155  psimhit_energy->reserve(nentries);
156 
157  //psimhit_time=&simhit_time;
158  //psimhit_time->clear();
159  //psimhit_time->reserve(nentries);
160 
162  psimhit_sector->clear();
163  psimhit_sector->reserve(nentries);
164 
166  psimhit_module->clear();
167  psimhit_module->reserve(nentries);
168 
169  simhit_etot = 0;
170 
171  if (nentries > 0) {
172  for (int ihit = 0; ihit < nentries; ihit++) {
173  CaloG4Hit* aHit = (*theCAFI)[ihit];
174  volumeID = aHit->getUnitID();
175 
176  //themap[volumeID] += aHit->getEnergyDeposit();
177  int zside, sector, zmodule;
178 
179  theCastorNumScheme->unpackIndex(volumeID, zside, sector, zmodule);
180 
181  double energy = aHit->getEnergyDeposit() / GeV;
182  //double time = aHit->getTimeSlice();
183 
184  math::XYZPoint pos = aHit->getPosition();
185  double theta = pos.theta();
186  double eta = -log(tan(theta / 2.));
187  double phi = pos.phi();
188 
189  psimhit_x->push_back(pos.x());
190  psimhit_y->push_back(pos.y());
191  psimhit_z->push_back(pos.z());
192 
193  psimhit_eta->push_back(eta);
194  psimhit_phi->push_back(phi);
195  psimhit_energy->push_back(energy);
196 
197  // psimhit_time->push_back(time);
198  psimhit_sector->push_back(sector);
199  psimhit_module->push_back(zmodule);
200 
201  simhit_etot += energy;
202 
203  if (debug)
204  std::cout << "hit " << ihit + 1 << " : x = " << (*psimhit_x)[ihit] << " , eta = " << (*psimhit_eta)[ihit]
205  << " , phi = " << (*psimhit_phi)[ihit] << " , energy = " << (*psimhit_energy)[ihit] << std::endl;
206  }
207 
208  //if(debug) std::cout<<" total energy = "<<simhit_etot<<std::endl;
209  if (debug)
210  getchar();
211  CastorTree->Fill();
212 
213  } // nentries > 0
214  delete theCastorNumScheme;
215 }
216 
218 
219 void DoCastorAnalysis::update(const G4Step* aStep) { ; }
DoCastorAnalysis.h
DoCastorAnalysis::CastorOutputEventFile
TFile * CastorOutputEventFile
Definition: DoCastorAnalysis.h:87
DoCastorAnalysis::simhit_sector
std::vector< int > simhit_sector
Definition: DoCastorAnalysis.h:94
DoCastorAnalysis::psimhit_sector
std::vector< int > * psimhit_sector
Definition: DoCastorAnalysis.h:99
ecaldqm::zside
int zside(DetId const &)
Definition: EcalDQMCommonUtils.cc:189
CaloG4HitCollection.h
CaloG4Hit::getUnitID
uint32_t getUnitID() const
Definition: CaloG4Hit.h:65
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
gather_cfg.cout
cout
Definition: gather_cfg.py:144
pos
Definition: PixelAliasList.h:18
DoCastorAnalysis::simhit_etot
double simhit_etot
Definition: DoCastorAnalysis.h:102
DoCastorAnalysis::eventIndex
int eventIndex
Definition: DoCastorAnalysis.h:90
CastorNumberingScheme.h
DoCastorAnalysis::TreeFileName
std::string TreeFileName
Definition: DoCastorAnalysis.h:85
DoCastorAnalysis::simhit_energy
std::vector< double > simhit_energy
Definition: DoCastorAnalysis.h:93
PVValHelper::eta
Definition: PVValidationHelpers.h:69
DoCastorAnalysis::psimhit_module
std::vector< int > * psimhit_module
Definition: DoCastorAnalysis.h:99
CaloG4Hit::getEnergyDeposit
double getEnergyDeposit() const
Definition: CaloG4Hit.h:77
theta
Geom::Theta< T > theta() const
Definition: Basic3DVectorLD.h:150
HCALHighEnergyHPDFilter_cfi.energy
energy
Definition: HCALHighEnergyHPDFilter_cfi.py:5
BeginOfJob
Definition: BeginOfJob.h:8
DoCastorAnalysis::simhit_module
std::vector< int > simhit_module
Definition: DoCastorAnalysis.h:94
EndOfEvent
Definition: EndOfEvent.h:6
DoCastorAnalysis::psimhit_z
std::vector< double > * psimhit_z
Definition: DoCastorAnalysis.h:97
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
DoCastorAnalysis::verbosity
int verbosity
Definition: DoCastorAnalysis.h:83
DoCastorAnalysis::simhit_z
std::vector< double > simhit_z
Definition: DoCastorAnalysis.h:92
edm::ParameterSet
Definition: ParameterSet.h:47
math::XYZPoint
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
DoCastorAnalysis::psimhit_x
std::vector< double > * psimhit_x
Definition: DoCastorAnalysis.h:97
CastorNumberingScheme
Definition: CastorNumberingScheme.h:30
CastorNumberingScheme::unpackIndex
static void unpackIndex(const uint32_t &idx, int &z, int &sector, int &zmodule)
Definition: CastorNumberingScheme.cc:193
GeV
const double GeV
Definition: MathUtil.h:16
DoCastorAnalysis::update
void update(const BeginOfJob *run) override
This routine will be called when the appropriate signal arrives.
Definition: DoCastorAnalysis.cc:92
DoCastorAnalysis::simhit_x
std::vector< double > simhit_x
Definition: DoCastorAnalysis.h:92
funct::tan
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
BeginOfEvent
Definition: BeginOfEvent.h:6
BeginOfRun
Definition: BeginOfRun.h:6
EndOfRun
Definition: EndOfRun.h:6
DoCastorAnalysis::simhit_eta
std::vector< double > simhit_eta
Definition: DoCastorAnalysis.h:93
CaloG4Hit
Definition: CaloG4Hit.h:32
CaloG4Hit::getPosition
math::XYZPoint getPosition() const
Definition: CaloG4Hit.h:52
DoCastorAnalysis::psimhit_energy
std::vector< double > * psimhit_energy
Definition: DoCastorAnalysis.h:98
DoCastorAnalysis::~DoCastorAnalysis
~DoCastorAnalysis() override
Definition: DoCastorAnalysis.cc:69
DDAxes::phi
DoCastorAnalysis::DoCastorAnalysis
DoCastorAnalysis(const edm::ParameterSet &p)
Definition: DoCastorAnalysis.cc:28
DoCastorAnalysis::CastorTree
TTree * CastorTree
Definition: DoCastorAnalysis.h:88
DoCastorAnalysis::psimhit_phi
std::vector< double > * psimhit_phi
Definition: DoCastorAnalysis.h:98
writedatasetfile.run
run
Definition: writedatasetfile.py:27
DoCastorAnalysis::psimhit_y
std::vector< double > * psimhit_y
Definition: DoCastorAnalysis.h:97
DoCastorAnalysis::simhit_phi
std::vector< double > simhit_phi
Definition: DoCastorAnalysis.h:93
Point3D.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
CaloG4HitCollection
G4THitsCollection< CaloG4Hit > CaloG4HitCollection
Definition: CaloG4HitCollection.h:11
dqm-mbProfile.log
log
Definition: dqm-mbProfile.py:17
debug
#define debug
Definition: DoCastorAnalysis.cc:26
CaloG4Hit.h
DoCastorAnalysis::simhit_y
std::vector< double > simhit_y
Definition: DoCastorAnalysis.h:92
DoCastorAnalysis::psimhit_eta
std::vector< double > * psimhit_eta
Definition: DoCastorAnalysis.h:98