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 //
16 
19 
20 #include "TFile.h"
21 #include <cmath>
22 #include <iostream>
23 #include <iomanip>
24 #include <memory>
25 #include <vector>
26 
27 //#define EDM_ML_DEBUG
28 
30  edm::ParameterSet m_Anal = p.getParameter<edm::ParameterSet>("DoCastorAnalysis");
31  verbosity = m_Anal.getParameter<int>("Verbosity");
32 
33  TreeFileName = m_Anal.getParameter<std::string>("CastorTreeFileName");
34 
35  if (verbosity > 0) {
36  edm::LogVerbatim("ForwardSim") << std::endl;
37  edm::LogVerbatim("ForwardSim") << "============================================================================";
38  edm::LogVerbatim("ForwardSim") << "DoCastorAnalysis:: Initialized as observer";
39 
40  edm::LogVerbatim("ForwardSim") << " Castor Tree will be created";
41  edm::LogVerbatim("ForwardSim") << " Castor Tree will be in file: " << TreeFileName;
42 #ifdef EDM_ML_DEBUG
43  getchar();
44 #endif
45  edm::LogVerbatim("ForwardSim") << "============================================================================";
46  edm::LogVerbatim("ForwardSim") << std::endl;
47  }
48 
49  edm::LogVerbatim("ForwardSim") << "DoCastorAnalysis: output event root file created";
50  TString treefilename = TreeFileName;
51  CastorOutputEventFile = new TFile(treefilename, "RECREATE");
52 
53  CastorTree = new TTree("Sim", "Sim");
54 
55  CastorTree->Branch("simhit_x", "std::vector<double>", &psimhit_x);
56  CastorTree->Branch("simhit_y", "std::vector<double>", &psimhit_y);
57  CastorTree->Branch("simhit_z", "std::vector<double>", &psimhit_z);
58 
59  CastorTree->Branch("simhit_eta", "std::vector<double>", &psimhit_eta);
60  CastorTree->Branch("simhit_phi", "std::vector<double>", &psimhit_phi);
61  CastorTree->Branch("simhit_energy", "std::vector<double>", &psimhit_energy);
62 
63  // CastorTree->Branch("simhit_time","std::vector<double>",&psimhit_time);
64  CastorTree->Branch("simhit_sector", "std::vector<int>", &psimhit_sector);
65  CastorTree->Branch("simhit_module", "std::vector<int>", &psimhit_module);
66 
67  CastorTree->Branch("simhit_etot", &simhit_etot, "simhit_etot/D");
68 }
69 
71  //destructor of DoCastorAnalysis
72 
74  //-- CastorOutputEventFile->Write();
75  CastorTree->Write("", TObject::kOverwrite);
76  edm::LogVerbatim("ForwardSim") << "DoCastorAnalysis: Ntuple event written";
77 #ifdef EDM_ML_DEBUG
78  getchar();
79 #endif
80  CastorOutputEventFile->Close();
81  edm::LogVerbatim("ForwardSim") << "DoCastorAnalysis: Event file closed";
82 #ifdef EDM_ML_DEBUG
83  getchar();
84 #endif
85 
86  if (verbosity > 0) {
87  edm::LogVerbatim("ForwardSim") << std::endl << "DoCastorAnalysis: end of process";
88 #ifdef EDM_ML_DEBUG
89  getchar();
90 #endif
91  }
92 }
93 
94 //=================================================================== per EVENT
95 
96 void DoCastorAnalysis::update(const BeginOfJob* job) { edm::LogVerbatim("ForwardSim") << " Starting new job "; }
97 
98 //==================================================================== per RUN
99 
101  edm::LogVerbatim("ForwardSim") << std::endl << "DoCastorAnalysis: Starting Run";
102 
103  // edm::LogVerbatim("ForwardSim") << "DoCastorAnalysis: output event root file created";
104  // TString treefilename = TreeFileName;
105  // CastorOutputEventFile = new TFile(treefilename,"RECREATE");
106 
107  eventIndex = 1;
108 }
109 
111  edm::LogVerbatim("ForwardSim") << "DoCastorAnalysis: Processing Event Number: " << eventIndex;
112  eventIndex++;
113 }
114 
115 //================= End of EVENT ===============
116 
118  // Look for the Hit Collection
119 
120  // access to the G4 hit collections
121  G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
122 
123  int CAFIid = G4SDManager::GetSDMpointer()->GetCollectionID("CastorFI");
124  CaloG4HitCollection* theCAFI = (CaloG4HitCollection*)allHC->GetHC(CAFIid);
125 
126  CastorNumberingScheme* theCastorNumScheme = new CastorNumberingScheme();
127 
128  unsigned int volumeID = 0;
129  // std::map<int,float,std::less<int> > themap;
130 
131  int nentries = theCAFI->entries();
132 #ifdef EDM_ML_DEBUG
133  edm::LogVerbatim("ForwardSim") << "nentries in CAFI: " << nentries;
134  getchar();
135 #endif
136 
137  psimhit_x = &simhit_x;
138  psimhit_x->clear();
139  psimhit_x->reserve(nentries);
140 
141  psimhit_y = &simhit_y;
142  psimhit_y->clear();
143  psimhit_y->reserve(nentries);
144 
145  psimhit_z = &simhit_z;
146  psimhit_z->clear();
147  psimhit_z->reserve(nentries);
148 
150  psimhit_eta->clear();
151  psimhit_eta->reserve(nentries);
152 
154  psimhit_phi->clear();
155  psimhit_phi->reserve(nentries);
156 
158  psimhit_energy->clear();
159  psimhit_energy->reserve(nentries);
160 
161  //psimhit_time=&simhit_time;
162  //psimhit_time->clear();
163  //psimhit_time->reserve(nentries);
164 
166  psimhit_sector->clear();
167  psimhit_sector->reserve(nentries);
168 
170  psimhit_module->clear();
171  psimhit_module->reserve(nentries);
172 
173  simhit_etot = 0;
174 
175  if (nentries > 0) {
176  for (int ihit = 0; ihit < nentries; ihit++) {
177  CaloG4Hit* aHit = (*theCAFI)[ihit];
178  volumeID = aHit->getUnitID();
179 
180  //themap[volumeID] += aHit->getEnergyDeposit();
181  int zside, sector, zmodule;
182 
183  theCastorNumScheme->unpackIndex(volumeID, zside, sector, zmodule);
184 
185  double energy = aHit->getEnergyDeposit() / GeV;
186  //double time = aHit->getTimeSlice();
187 
188  math::XYZPoint pos = aHit->getPosition();
189  double theta = pos.theta();
190  double eta = -log(tan(theta / 2.));
191  double phi = pos.phi();
192 
193  psimhit_x->push_back(pos.x());
194  psimhit_y->push_back(pos.y());
195  psimhit_z->push_back(pos.z());
196 
197  psimhit_eta->push_back(eta);
198  psimhit_phi->push_back(phi);
199  psimhit_energy->push_back(energy);
200 
201  // psimhit_time->push_back(time);
202  psimhit_sector->push_back(sector);
203  psimhit_module->push_back(zmodule);
204 
205  simhit_etot += energy;
206 
207 #ifdef EDM_ML_DEBUG
208  edm::LogVerbatim("ForwardSim") << "hit " << ihit + 1 << " : x = " << (*psimhit_x)[ihit]
209  << " , eta = " << (*psimhit_eta)[ihit] << " , phi = " << (*psimhit_phi)[ihit]
210  << " , energy = " << (*psimhit_energy)[ihit];
211 #endif
212  }
213 
214  //if (debug) edm::LogVerbatim("ForwardSim") << " total energy = " << simhit_etot;
215 #ifdef EDM_ML_DEBUG
216  getchar();
217 #endif
218  CastorTree->Fill();
219 
220  } // nentries > 0
221  delete theCastorNumScheme;
222 }
223 
225 
226 void DoCastorAnalysis::update(const G4Step* aStep) { ; }
MessageLogger.h
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:66
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:70
DoCastorAnalysis::psimhit_module
std::vector< int > * psimhit_module
Definition: DoCastorAnalysis.h:99
CaloG4Hit::getEnergyDeposit
double getEnergyDeposit() const
Definition: CaloG4Hit.h:78
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
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
AlCaHLTBitMon_ParallelJobs.p
def p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
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:96
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
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
DoCastorAnalysis::~DoCastorAnalysis
~DoCastorAnalysis() override
Definition: DoCastorAnalysis.cc:70
DDAxes::phi
DoCastorAnalysis::DoCastorAnalysis
DoCastorAnalysis(const edm::ParameterSet &p)
Definition: DoCastorAnalysis.cc:29
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
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
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
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