Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DEventProcessor_mcthrown_hists.cc
Go to the documentation of this file.
1 // $Id: DEventProcessor_mcthrown_hists.cc 1816 2006-06-06 14:38:18Z davidl $
2 //
3 // File: DEventProcessor_mcthrown_hists.cc
4 // Created: Sun Apr 24 06:45:21 EDT 2005
5 // Creator: davidl (on Darwin Harriet.local 7.8.0 powerpc)
6 //
7 
8 #include <iostream>
9 #include <cmath>
10 using namespace std;
11 
12 #include <TThread.h>
13 
14 #include <JANA/JApplication.h>
15 #include <JANA/JEventLoop.h>
16 using namespace jana;
17 
19 #include "TRACKING/DMCThrown.h"
20 
21 // The executable should define the ROOTfile global variable. It will
22 // be automatically linked when dlopen is called.
23 //extern TFile *ROOTfile;
24 
25 // Routine used to create our JEventProcessor
26 extern "C"{
27 void InitPlugin(JApplication *app){
28  InitJANAPlugin(app);
29  app->AddProcessor(new DEventProcessor_mcthrown_hists());
30 }
31 }
32 
33 //------------------
34 // DEventProcessor_mcthrown_hists
35 //------------------
37 {
38 }
39 
40 //------------------
41 // ~DEventProcessor_mcthrown_hists
42 //------------------
44 {
45 }
46 
47 //------------------
48 // init
49 //------------------
51 {
52  // open ROOT file (if needed)
53  //if(ROOTfile != NULL) ROOTfile->cd();
54 
55  // Create THROWN directory
56  TDirectory *dir = new TDirectoryFile("THROWN","THROWN");
57  dir->cd();
58 
59  // Create histograms
60  pmom = new TH1F("pmom","Thrown momentum in GeV/c",1200, 0.0, 12.0);
61  theta = new TH1F("theta","Thrown theta in degrees",1000, 0.0, 180.0);
62  phi = new TH1F("phi","Thrown phi in radians",200, 0.0, 2.0*M_PI);
63  energy = new TH1F("energy","Thrown energy in GeV",1200, 0.0, 12.0);
64  pmom_vs_theta = new TH2F("pmom_vs_theta","Thrown momentum vs. #theta",1000, 0.0, 180.0, 300, 0.0, 10.0);
65  pmom_vs_theta_pip = new TH2F("pmom_vs_theta_pip","Thrown momentum vs. #theta for #pi^{+}",1000, 0.0, 180.0, 300, 0.0, 10.0);
66  pmom_vs_theta_pim = new TH2F("pmom_vs_theta_pim","Thrown momentum vs. #theta for #pi^{-}",1000, 0.0, 180.0, 300, 0.0, 10.0);
67  pmom_vs_theta_Kp = new TH2F("pmom_vs_theta_Kp","Thrown momentum vs. #theta for K^{+}",1000, 0.0, 180.0, 300, 0.0, 10.0);
68  pmom_vs_theta_Km = new TH2F("pmom_vs_theta_Km","Thrown momentum vs. #theta for K^{-}",1000, 0.0, 180.0, 300, 0.0, 10.0);
69  pmom_vs_theta_proton = new TH2F("pmom_vs_theta_proton","Thrown momentum vs. #theta for protons",1000, 0.0, 180.0, 300, 0.0, 10.0);
70  pmom_vs_theta_neutron = new TH2F("pmom_vs_theta_neutron","Thrown momentum vs. #theta for neutrons",1000, 0.0, 180.0, 300, 0.0, 10.0);
71  pmom_vs_theta_gamma = new TH2F("pmom_vs_theta_gamma","Thrown momentum vs. theta for gammas",1000, 0.0, 180.0, 300, 0.0, 10.0);
72 
73  vertex = new TH3F("vertex", "Position of vertex from which thrown particles were thrown", 50, -5.0, 5.0, 50, -5.0, 5.0, 150, 0.0, 150.0);
74 
75  Nparticles_per_event = new TH1F("Nparticles_per_event","Number of thrown particles per event",21, -0.5, 20.5);
76  particle_type = new TH1F("particle_type","GEANT3 particle type of thrown particles",101, -0.5, 100.5);
77 
78  // Go back up to the parent directory
79  dir->cd("../");
80 
81  return NOERROR;
82 }
83 
84 //------------------
85 // evnt
86 //------------------
87 jerror_t DEventProcessor_mcthrown_hists::evnt(JEventLoop *loop, uint64_t eventnumber)
88 {
89  vector<const DMCThrown*> mcthrowns;
90  loop->Get(mcthrowns);
91 
92  // FILL HISTOGRAMS
93  // Since we are filling histograms local to this plugin, it will not interfere with other ROOT operations: can use plugin-wide ROOT fill lock
94  japp->RootFillLock(this); //ACQUIRE ROOT FILL LOCK
95 
96  // Loop over thrown tracks
97  Nparticles_per_event->Fill(mcthrowns.size());
98  for(unsigned int i=0;i<mcthrowns.size();i++){
99  const DMCThrown *mcthrown = mcthrowns[i];
100 
101  pmom->Fill(mcthrown->momentum().Mag());
102  theta->Fill(mcthrown->momentum().Theta()*57.3);
103  phi->Fill(mcthrown->momentum().Phi());
104  energy->Fill(mcthrown->energy());
105  pmom_vs_theta->Fill(mcthrown->momentum().Theta()*57.3, mcthrown->momentum().Mag());
106  vertex->Fill(mcthrown->position().X(), mcthrown->position().Y(), mcthrown->position().Z());
107 
108  particle_type->Fill(mcthrown->type);
109 
110  switch(mcthrown->type){
111  case 1:
112  pmom_vs_theta_gamma->Fill(mcthrown->momentum().Theta()*57.3, mcthrown->momentum().Mag());
113  break;
114  case 8:
115  pmom_vs_theta_pip->Fill(mcthrown->momentum().Theta()*57.3, mcthrown->momentum().Mag());
116  break;
117  case 9:
118  pmom_vs_theta_pim->Fill(mcthrown->momentum().Theta()*57.3, mcthrown->momentum().Mag());
119  break;
120  case 11:
121  pmom_vs_theta_Kp->Fill(mcthrown->momentum().Theta()*57.3, mcthrown->momentum().Mag());
122  break;
123  case 12:
124  pmom_vs_theta_Km->Fill(mcthrown->momentum().Theta()*57.3, mcthrown->momentum().Mag());
125  break;
126  case 13:
127  pmom_vs_theta_neutron->Fill(mcthrown->momentum().Theta()*57.3, mcthrown->momentum().Mag());
128  break;
129  case 14:
130  pmom_vs_theta_proton->Fill(mcthrown->momentum().Theta()*57.3, mcthrown->momentum().Mag());
131  break;
132  }
133  }
134 
135  japp->RootFillUnLock(this); //RELEASE ROOT FILL LOCK
136 
137  return NOERROR;
138 }
139 
140 //------------------
141 // erun
142 //------------------
144 {
145 
146  return NOERROR;
147 }
148 
149 //------------------
150 // fini
151 //------------------
153 {
154  return NOERROR;
155 }
double energy(void) const
const DVector3 & position(void) const
jerror_t evnt(JEventLoop *loop, uint64_t eventnumber)
Invoked via DEventProcessor virtual method.
jerror_t erun(void)
Invoked via DEventProcessor virtual method.
JApplication * japp
jerror_t init(void)
Invoked via DEventProcessor virtual method.
InitPlugin_t InitPlugin
jerror_t fini(void)
Invoked via DEventProcessor virtual method.
const DVector3 & momentum(void) const
TDirectory * dir
Definition: bcal_hist_eff.C:31
int type
GEANT particle ID.
Definition: DMCThrown.h:20