Public Member Functions | Private Attributes | List of all members
emshower::EMPi0Energy Class Reference
Inheritance diagram for emshower::EMPi0Energy:
art::EDAnalyzer art::detail::Analyzer art::detail::LegacyModule art::Observer art::ModuleBase

Public Member Functions

 EMPi0Energy (fhicl::ParameterSet const &pset)
 
void analyze (art::Event const &evt)
 
void reconfigure (fhicl::ParameterSet const &p)
 
void reset ()
 
double ConvertChargeToEnergy (double charge, int plane)
 
double FindDepositedEnergy (int trackID)
 
int FindTrackID (detinfo::DetectorClocksData const &clockData, art::Ptr< recob::Hit > const &hit)
 
int FindTrueTrack (detinfo::DetectorClocksData const &clockData, std::vector< art::Ptr< recob::Hit > > const &clusterHits)
 
double FindVertexDetectorDistance (const simb::MCParticle *particle)
 
- Public Member Functions inherited from art::EDAnalyzer
 EDAnalyzer (fhicl::ParameterSet const &pset)
 
template<typename Config >
 EDAnalyzer (Table< Config > const &config)
 
std::string workerType () const
 
- Public Member Functions inherited from art::detail::Analyzer
virtual ~Analyzer () noexcept
 
 Analyzer (fhicl::ParameterSet const &pset)
 
template<typename Config >
 Analyzer (Table< Config > const &config)
 
void doBeginJob (SharedResources const &resources)
 
void doEndJob ()
 
void doRespondToOpenInputFile (FileBlock const &fb)
 
void doRespondToCloseInputFile (FileBlock const &fb)
 
void doRespondToOpenOutputFiles (FileBlock const &fb)
 
void doRespondToCloseOutputFiles (FileBlock const &fb)
 
bool doBeginRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doEndRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doBeginSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEndSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEvent (EventPrincipal &ep, ModuleContext const &mc, std::atomic< std::size_t > &counts_run, std::atomic< std::size_t > &counts_passed, std::atomic< std::size_t > &counts_failed)
 
- Public Member Functions inherited from art::Observer
 ~Observer () noexcept
 
 Observer (Observer const &)=delete
 
 Observer (Observer &&)=delete
 
Observeroperator= (Observer const &)=delete
 
Observeroperator= (Observer &&)=delete
 
void registerProducts (ProductDescriptions &, ModuleDescription const &)
 
void fillDescriptions (ModuleDescription const &)
 
fhicl::ParameterSetID selectorConfig () const
 
- Public Member Functions inherited from art::ModuleBase
virtual ~ModuleBase () noexcept
 
 ModuleBase ()
 
ModuleDescription const & moduleDescription () const
 
void setModuleDescription (ModuleDescription const &)
 
std::array< std::vector< ProductInfo >, NumBranchTypes > const & getConsumables () const
 
void sortConsumables (std::string const &current_process_name)
 
template<typename T , BranchType BT>
ViewToken< T > consumesView (InputTag const &tag)
 
template<typename T , BranchType BT>
ViewToken< T > mayConsumeView (InputTag const &tag)
 

Private Attributes

TTree * fTree
 
double trueEnergyPi0
 
double trueEnergyHighEPhoton
 
double trueEnergyLowEPhoton
 
int trueTrackIDPi0
 
int trueTrackIDHighEPhoton
 
int trueTrackIDLowEPhoton
 
double depositHighEPhoton
 
double depositLowEPhoton
 
double vertexDetectorDistHighEPhoton
 
double vertexDetectorDistLowEPhoton
 
int nclusters
 
int cluster_plane [kMaxClusters]
 
int cluster_size [kMaxClusters]
 
int cluster_truetrackid [kMaxClusters]
 
double cluster_charge [kMaxClusters]
 
double cluster_energy [kMaxClusters]
 
std::string fHitsModuleLabel
 
std::string fClusterModuleLabel
 
art::ServiceHandle< art::TFileService > tfs
 
art::ServiceHandle< cheat::BackTrackerServicebacktracker
 
art::ServiceHandle< cheat::ParticleInventoryServiceparticleinventory
 
art::ServiceHandle< geo::Geometrygeom
 
double Uintercept
 
double Ugradient
 
double Vintercept
 
double Vgradient
 
double Zintercept
 
double Zgradient
 

Additional Inherited Members

- Public Types inherited from art::EDAnalyzer
using WorkerType = WorkerT< EDAnalyzer >
 
using ModuleType = EDAnalyzer
 
- Protected Member Functions inherited from art::Observer
std::string const & processName () const
 
bool wantAllEvents () const noexcept
 
bool wantEvent (ScheduleID id, Event const &e) const
 
Handle< TriggerResultsgetTriggerResults (Event const &e) const
 
 Observer (fhicl::ParameterSet const &config)
 
 Observer (std::vector< std::string > const &select_paths, std::vector< std::string > const &reject_paths, fhicl::ParameterSet const &config)
 
- Protected Member Functions inherited from art::ModuleBase
ConsumesCollectorconsumesCollector ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > consumes (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > consumesView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void consumesMany ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > mayConsume (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > mayConsumeView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void mayConsumeMany ()
 

Detailed Description

Definition at line 55 of file EMPi0Energy_module.cc.

Constructor & Destructor Documentation

emshower::EMPi0Energy::EMPi0Energy ( fhicl::ParameterSet const &  pset)

Definition at line 105 of file EMPi0Energy_module.cc.

105  : EDAnalyzer(pset) {
106  this->reconfigure(pset);
107  fTree = tfs->make<TTree>("EMPi0Energy","EMPi0Energy");
108  fTree->Branch("TrueEnergyPi0", &trueEnergyPi0);
109  fTree->Branch("TrueEnergyHighEPhoton", &trueEnergyHighEPhoton);
110  fTree->Branch("TrueEnergyLowEPhoton", &trueEnergyLowEPhoton);
111  fTree->Branch("TrueTrackIDPi0", &trueTrackIDPi0);
112  fTree->Branch("TrueTrackIDHighEPhoton", &trueTrackIDHighEPhoton);
113  fTree->Branch("TrueTrackIDLowEPhoton", &trueTrackIDLowEPhoton);
114  fTree->Branch("DepositHighEPhoton", &depositHighEPhoton);
115  fTree->Branch("DepositLowEPhoton", &depositLowEPhoton);
116  fTree->Branch("VertexDetectorDistHighEPhoton",&vertexDetectorDistHighEPhoton);
117  fTree->Branch("VertexDetectorDistLowEPhoton", &vertexDetectorDistLowEPhoton);
118  fTree->Branch("NClusters", &nclusters);
119  fTree->Branch("Cluster_Plane", cluster_plane, "cluster_plane[NClusters]/I");
120  fTree->Branch("Cluster_Size", cluster_size, "cluster_size[NClusters]/I");
121  fTree->Branch("Cluster_TrueTrackID", cluster_truetrackid,"cluster_truetrackid[NClusters]/I");
122  fTree->Branch("Cluster_Charge", cluster_charge, "cluster_charge[NClusters]/D");
123  fTree->Branch("Cluster_Energy", cluster_energy, "cluster_energy[NClusters]/D");
124 
125  Uintercept = -1519.33; Ugradient = 148867;
126  Vintercept = -1234.91; Vgradient = 149458;
127  Zintercept = -1089.73; Zgradient = 145372;
128 
129 }
double cluster_charge[kMaxClusters]
art::ServiceHandle< art::TFileService > tfs
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
int cluster_truetrackid[kMaxClusters]
double cluster_energy[kMaxClusters]
int cluster_size[kMaxClusters]
int cluster_plane[kMaxClusters]
void reconfigure(fhicl::ParameterSet const &p)

Member Function Documentation

void emshower::EMPi0Energy::analyze ( art::Event const &  evt)
virtual

Analyse function to save information for calibrating shower energies This is written assuming single pi0 per event

Implements art::EDAnalyzer.

Definition at line 136 of file EMPi0Energy_module.cc.

136  {
137 
138  /// Analyse function to save information for calibrating shower energies
139  /// This is written assuming single pi0 per event
140 
141  this->reset();
142 
143  // Get the hits out of the event record
144  std::vector<art::Ptr<recob::Hit> > hits;
145  auto hitHandle = evt.getHandle<std::vector<recob::Hit> >(fHitsModuleLabel);
146  if (hitHandle)
147  art::fill_ptr_vector(hits, hitHandle);
148 
149  // Get the clusters out of the event record
150  std::vector<art::Ptr<recob::Cluster> > clusters;
151  auto clusterHandle = evt.getHandle<std::vector<recob::Cluster> >(fClusterModuleLabel);
152  if (clusterHandle)
153  art::fill_ptr_vector(clusters, clusterHandle);
154 
155  art::FindManyP<recob::Hit> fmh(clusterHandle, evt, fClusterModuleLabel);
156 
157  // Look at the clusters
158  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
159  for (unsigned int clus = 0; clus < clusters.size(); ++clus) {
160 
161  art::Ptr<recob::Cluster> cluster = clusters.at(clus);
162  std::vector<art::Ptr<recob::Hit> > hits = fmh.at(clus);
163 
164  // Find the charge deposited by hits in this cluster in this plane
165  double charge = 0;
166  for (std::vector<art::Ptr<recob::Hit> >::iterator hit = hits.begin(); hit != hits.end(); ++hit)
167  charge += ((*hit)->Integral() * TMath::Exp((500 * (*hit)->PeakTime())/3e6));
168 
169  cluster_plane [clus] = cluster->Plane().Plane;
170  cluster_size [clus] = hits.size();
171  cluster_truetrackid[clus] = this->FindTrueTrack(clockData, hits);
172  cluster_charge [clus] = charge;
173  cluster_energy [clus] = this->ConvertChargeToEnergy(charge, cluster->Plane().Plane);
174 
175  }
176 
177  // Event level information
178 
179  nclusters = clusters.size();
180 
181  // Get the pi0 and the decay photons
182  const sim::ParticleList& trueParticles = particleinventory->ParticleList();
183  const simb::MCParticle* truePi0 = trueParticles.Primary(0);
184  if (truePi0->NumberDaughters() != 2) return;
185  const simb::MCParticle* truePhoton1 = particleinventory->TrackIdToParticle_P(truePi0->Daughter(0));
186  const simb::MCParticle* truePhoton2 = particleinventory->TrackIdToParticle_P(truePi0->Daughter(1));
187 
188  // Make sure photon 1 energy > photon 2 energy
189  if (truePhoton1->Momentum().E() < truePhoton2->Momentum().E()) {
190  const simb::MCParticle* tmp = truePhoton2;
191  truePhoton2 = truePhoton1;
192  truePhoton1 = tmp;
193  }
194 
195  trueEnergyPi0 = truePi0->Momentum().E();
196  trueTrackIDPi0 = truePi0->TrackId();
197 
198  trueEnergyHighEPhoton = truePhoton1->Momentum().E();
199  trueEnergyLowEPhoton = truePhoton2->Momentum().E();
200  trueTrackIDHighEPhoton = truePhoton1->TrackId();
201  trueTrackIDLowEPhoton = truePhoton2->TrackId();
202 
203  // Find the energy deposited on each plane in the TPC
206 
207  // Find the distance between the particle vertex and the edge of the detector
210 
211  fTree->Fill();
212 
213  return;
214 
215 }
double cluster_charge[kMaxClusters]
const simb::MCParticle * TrackIdToParticle_P(int id) const
struct vector vector
geo::PlaneID Plane() const
Returns the plane ID this cluster lies on.
Definition: Cluster.h:744
Cluster finding and building.
int NumberDaughters() const
Definition: MCParticle.h:217
int TrackId() const
Definition: MCParticle.h:210
int Daughter(const int i) const
Definition: MCParticle.cxx:112
double FindVertexDetectorDistance(const simb::MCParticle *particle)
art::ServiceHandle< cheat::ParticleInventoryService > particleinventory
double ConvertChargeToEnergy(double charge, int plane)
double FindDepositedEnergy(int trackID)
int cluster_truetrackid[kMaxClusters]
string tmp
Definition: languages.py:63
PlaneID_t Plane
Index of the plane within its TPC.
Definition: geo_types.h:493
double cluster_energy[kMaxClusters]
Detector simulation of raw signals on wires.
const sim::ParticleList & ParticleList() const
int cluster_size[kMaxClusters]
const TLorentzVector & Momentum(const int i=0) const
Definition: MCParticle.h:220
int cluster_plane[kMaxClusters]
int FindTrueTrack(detinfo::DetectorClocksData const &clockData, std::vector< art::Ptr< recob::Hit > > const &clusterHits)
TCEvent evt
Definition: DataStructs.cxx:7
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:297
double emshower::EMPi0Energy::ConvertChargeToEnergy ( double  charge,
int  plane 
)

Converts charge to energy

Definition at line 217 of file EMPi0Energy_module.cc.

217  {
218 
219  /// Converts charge to energy
220 
221  double energy = 0;
222 
223  switch (plane) {
224  case 0:
225  energy = (double)(charge - Uintercept)/(double)Ugradient;
226  break;
227  case 1:
228  energy = (double)(charge - Vintercept)/(double)Vgradient;
229  break;
230  case 2:
231  energy = (double)(charge - Zintercept)/(double)Zgradient;
232  break;
233  }
234 
235  return energy;
236 
237 }
double emshower::EMPi0Energy::FindDepositedEnergy ( int  trackID)

Definition at line 239 of file EMPi0Energy_module.cc.

239  {
240 
241  std::vector<sim::IDE> ides;
242  for( auto ide_P : backtracker->TrackIdToSimIDEs_Ps(trackID) ){
243  ides.push_back(*ide_P);
244  }
245 
246  double deposit = 0;
247 
248  for (std::vector<sim::IDE>::iterator ideIt = ides.begin(); ideIt != ides.end(); ++ideIt)
249  deposit += ideIt->energy;
250 
251  // Put energies in GeV units
252  deposit /= 1000;
253 
254  return deposit;
255 
256 }
intermediate_table::iterator iterator
art::ServiceHandle< cheat::BackTrackerService > backtracker
std::vector< const sim::IDE * > TrackIdToSimIDEs_Ps(int const &id) const
int emshower::EMPi0Energy::FindTrackID ( detinfo::DetectorClocksData const &  clockData,
art::Ptr< recob::Hit > const &  hit 
)

Find the true track ID this hit is associated with

Definition at line 258 of file EMPi0Energy_module.cc.

259  {
260 
261  /// Find the true track ID this hit is associated with
262 
263  double particleEnergy = 0;
264  int likelyTrackID = 0;
265  std::vector<sim::TrackIDE> trackIDs = backtracker->HitToTrackIDEs(clockData, hit);
266  for (unsigned int idIt = 0; idIt < trackIDs.size(); ++idIt) {
267  if (trackIDs.at(idIt).energy > particleEnergy) {
268  particleEnergy = trackIDs.at(idIt).energy;
269  likelyTrackID = TMath::Abs(trackIDs.at(idIt).trackID);
270  }
271  }
272  return likelyTrackID;
273 }
std::vector< sim::TrackIDE > HitToTrackIDEs(detinfo::DetectorClocksData const &clockData, recob::Hit const &hit) const
art::ServiceHandle< cheat::BackTrackerService > backtracker
int emshower::EMPi0Energy::FindTrueTrack ( detinfo::DetectorClocksData const &  clockData,
std::vector< art::Ptr< recob::Hit > > const &  clusterHits 
)

Find the true track which is most associated to this cluster

Definition at line 275 of file EMPi0Energy_module.cc.

276  {
277 
278  /// Find the true track which is most associated to this cluster
279 
280  std::map<int,double> trackMap;
281  for (std::vector<art::Ptr<recob::Hit> >::const_iterator clusHitIt = clusterHits.begin(); clusHitIt != clusterHits.end(); ++clusHitIt) {
282  art::Ptr<recob::Hit> hit = *clusHitIt;
283  int trackID = FindTrackID(clockData, hit);
284  trackMap[trackID] += hit->Integral();
285  }
286  //return std::max_element(trackMap.begin(), trackMap.end(), [](const std::pair<int,double>& p1, const std::pair<int,double>& p2) {return p1.second < p2.second;} )->first;
287  double highestCharge = 0;
288  int clusterTrack = 0;
289  for (std::map<int,double>::iterator trackIt = trackMap.begin(); trackIt != trackMap.end(); ++trackIt)
290  if (trackIt->second > highestCharge) {
291  highestCharge = trackIt->second;
292  clusterTrack = trackIt->first;
293  }
294  return clusterTrack;
295 }
intermediate_table::iterator iterator
struct vector vector
float Integral() const
Integral under the calibrated signal waveform of the hit, in tick x ADC units.
Definition: Hit.h:224
Detector simulation of raw signals on wires.
int FindTrackID(detinfo::DetectorClocksData const &clockData, art::Ptr< recob::Hit > const &hit)
double emshower::EMPi0Energy::FindVertexDetectorDistance ( const simb::MCParticle particle)

Finds the rough distance from the end of a particle track to the edge of the detector, along the direction of the particle

Definition at line 297 of file EMPi0Energy_module.cc.

297  {
298 
299  /// Finds the rough distance from the end of a particle track to the edge of the detector, along the direction of the particle
300 
301  TVector3 end = TVector3(particle->EndX(),particle->EndY(),particle->EndZ());
302  TVector3 direction = TVector3(particle->Px(),particle->Py(),particle->Pz()).Unit();
303 
304  int distanceStep = 1, steps = 0;
305  TVector3 pos;
306  bool inTPC = true;
307 
308  while (inTPC) {
309  pos = end + ( (steps*distanceStep) * direction );
310  double currentPos[3]; currentPos[0] = pos.X(); currentPos[1] = pos.Y(); currentPos[2] = pos.Z();
311  if (!geom->FindTPCAtPosition(currentPos).isValid)
312  inTPC = false;
313  ++steps;
314  }
315 
316  double distance = (end - pos).Mag();
317 
318  return distance;
319 
320 }
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
double Py(const int i=0) const
Definition: MCParticle.h:231
double EndZ() const
Definition: MCParticle.h:228
bool isValid
Whether this ID points to a valid element.
Definition: geo_types.h:211
double Px(const int i=0) const
Definition: MCParticle.h:230
double EndY() const
Definition: MCParticle.h:227
art::ServiceHandle< geo::Geometry > geom
geo::TPCID FindTPCAtPosition(double const worldLoc[3]) const
Returns the ID of the TPC at specified location.
double distance(double x1, double y1, double z1, double x2, double y2, double z2)
double Pz(const int i=0) const
Definition: MCParticle.h:232
double EndX() const
Definition: MCParticle.h:226
void emshower::EMPi0Energy::reconfigure ( fhicl::ParameterSet const &  p)

Definition at line 131 of file EMPi0Energy_module.cc.

131  {
132  fHitsModuleLabel = pset.get<std::string>("HitsModuleLabel");
133  fClusterModuleLabel = pset.get<std::string>("ClusterModuleLabel");
134 }
std::string string
Definition: nybbler.cc:12
void emshower::EMPi0Energy::reset ( )

Definition at line 322 of file EMPi0Energy_module.cc.

322  {
323  trueEnergyPi0 = 0;
326  trueTrackIDPi0 = 0;
329  depositHighEPhoton = 0;
330  depositLowEPhoton = 0;
333  nclusters = 0;
334  for (int cluster = 0; cluster < kMaxClusters; ++cluster) {
335  cluster_plane [cluster] = 0;
336  cluster_size [cluster] = 0;
338  cluster_charge [cluster] = 0;
339  cluster_energy [cluster] = 0;
340  }
341 }
double cluster_charge[kMaxClusters]
void cluster(In first, In last, Out result, Pred *pred)
Definition: NNClusters.h:41
Cluster finding and building.
int cluster_truetrackid[kMaxClusters]
const int kMaxClusters
double cluster_energy[kMaxClusters]
int cluster_size[kMaxClusters]
int cluster_plane[kMaxClusters]

Member Data Documentation

art::ServiceHandle<cheat::BackTrackerService> emshower::EMPi0Energy::backtracker
private

Definition at line 94 of file EMPi0Energy_module.cc.

double emshower::EMPi0Energy::cluster_charge[kMaxClusters]
private

Definition at line 88 of file EMPi0Energy_module.cc.

double emshower::EMPi0Energy::cluster_energy[kMaxClusters]
private

Definition at line 89 of file EMPi0Energy_module.cc.

int emshower::EMPi0Energy::cluster_plane[kMaxClusters]
private

Definition at line 85 of file EMPi0Energy_module.cc.

int emshower::EMPi0Energy::cluster_size[kMaxClusters]
private

Definition at line 86 of file EMPi0Energy_module.cc.

int emshower::EMPi0Energy::cluster_truetrackid[kMaxClusters]
private

Definition at line 87 of file EMPi0Energy_module.cc.

double emshower::EMPi0Energy::depositHighEPhoton
private

Definition at line 80 of file EMPi0Energy_module.cc.

double emshower::EMPi0Energy::depositLowEPhoton
private

Definition at line 81 of file EMPi0Energy_module.cc.

std::string emshower::EMPi0Energy::fClusterModuleLabel
private

Definition at line 92 of file EMPi0Energy_module.cc.

std::string emshower::EMPi0Energy::fHitsModuleLabel
private

Definition at line 91 of file EMPi0Energy_module.cc.

TTree* emshower::EMPi0Energy::fTree
private

Definition at line 73 of file EMPi0Energy_module.cc.

art::ServiceHandle<geo::Geometry> emshower::EMPi0Energy::geom
private

Definition at line 96 of file EMPi0Energy_module.cc.

int emshower::EMPi0Energy::nclusters
private

Definition at line 84 of file EMPi0Energy_module.cc.

art::ServiceHandle<cheat::ParticleInventoryService> emshower::EMPi0Energy::particleinventory
private

Definition at line 95 of file EMPi0Energy_module.cc.

art::ServiceHandle<art::TFileService> emshower::EMPi0Energy::tfs
private

Definition at line 93 of file EMPi0Energy_module.cc.

double emshower::EMPi0Energy::trueEnergyHighEPhoton
private

Definition at line 75 of file EMPi0Energy_module.cc.

double emshower::EMPi0Energy::trueEnergyLowEPhoton
private

Definition at line 76 of file EMPi0Energy_module.cc.

double emshower::EMPi0Energy::trueEnergyPi0
private

Definition at line 74 of file EMPi0Energy_module.cc.

int emshower::EMPi0Energy::trueTrackIDHighEPhoton
private

Definition at line 78 of file EMPi0Energy_module.cc.

int emshower::EMPi0Energy::trueTrackIDLowEPhoton
private

Definition at line 79 of file EMPi0Energy_module.cc.

int emshower::EMPi0Energy::trueTrackIDPi0
private

Definition at line 77 of file EMPi0Energy_module.cc.

double emshower::EMPi0Energy::Ugradient
private

Definition at line 99 of file EMPi0Energy_module.cc.

double emshower::EMPi0Energy::Uintercept
private

Definition at line 99 of file EMPi0Energy_module.cc.

double emshower::EMPi0Energy::vertexDetectorDistHighEPhoton
private

Definition at line 82 of file EMPi0Energy_module.cc.

double emshower::EMPi0Energy::vertexDetectorDistLowEPhoton
private

Definition at line 83 of file EMPi0Energy_module.cc.

double emshower::EMPi0Energy::Vgradient
private

Definition at line 100 of file EMPi0Energy_module.cc.

double emshower::EMPi0Energy::Vintercept
private

Definition at line 100 of file EMPi0Energy_module.cc.

double emshower::EMPi0Energy::Zgradient
private

Definition at line 101 of file EMPi0Energy_module.cc.

double emshower::EMPi0Energy::Zintercept
private

Definition at line 101 of file EMPi0Energy_module.cc.


The documentation for this class was generated from the following file: