Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DEventProcessor_bcal_hists.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: DEventProcessor_bcal_hists.cc
4 // Created: Mon Apr 3 11:38:03 EDT 2006
5 // Creator: davidl (on Darwin swire-b241.jlab.org 8.4.0 powerpc)
6 //
7 
9 
10 #include <TLorentzVector.h>
11 
12 #include "DANA/DApplication.h"
13 #include "BCAL/DBCALShower.h"
14 #include "BCAL/DBCALTruthShower.h"
15 #include "BCAL/DHDDMBCALHit.h"
16 #include "FCAL/DFCALCluster.h"
17 #include "TRACKING/DMCThrown.h"
18 
19 // The executable should define the ROOTfile global variable. It will
20 // be automatically linked when dlopen is called.
21 extern TFile *ROOTfile;
22 
23 // Routine used to create our DEventProcessor
24 extern "C"{
25 void InitPlugin(JApplication *app){
26  InitJANAPlugin(app);
27  app->AddProcessor(new DEventProcessor_bcal_hists());
28 }
29 } // "C"
30 
31 
32 #define FCAL_Z_OFFSET 640.0-65.0 // I don't know what this value is ???
33 
34 //------------------
35 // init
36 //------------------
38 {
39  // Create THROWN directory
40  TDirectory *dir = new TDirectoryFile("BCAL","BCAL");
41  dir->cd();
42 
43  two_gamma_mass = new TH1F("two_gamma_mass","two_gamma_mass",100, 0.0, 0.300);
44  two_gamma_mass_corr = new TH1F("two_gamma_mass_corr","two_gamma_mass_corr",100, 0.0, 0.300);
45  two_gamma_mass_cut = new TH1F("two_gamma_mass_cut","two_gamma_mass_cut",100, 0.0, 0.300);
46  bcal_fcal_two_gamma_mass = new TH1F("fcal_two_gamma_mass","bcal_fcal_two_gamma_mass",100, 0.0, 0.300);
47  bcal_fcal_two_gamma_mass_cut = new TH1F("fcal_two_gamma_mass_cut","bcal_fcal_two_gamma_mass_cut",100, 0.0, 0.300);
48  xy_shower = new TH2F("xy_shower","xy_shower",100, -100.0, 100., 100 , -100.0, 100.0);
49  z_shower = new TH1F("z_shower","z_shower",450, -50.0, 400);
50  E_shower = new TH1F("E_shower","E_shower", 200, 0.0, 6.0);
51 
52  Erec_over_Ethrown_vs_z = new TH2F("Erec_over_Ethrown_vs_z","Erec_over_Ethrown_vs_z", 200, -50.0, 600.0, 200, 0.0, 2.0);
53  Ecorr_over_Erec_vs_z = new TH2F("Ecorr_over_Erec_vs_z","Ecorr_over_Erec_vs_z", 200, -50.0, 600.0, 200, 0.0, 4.0);
54  Ereconstructed_vs_Ethrown = new TH2F("Ereconstructed_vs_Ethrown","BCAL total reconstructed E to total thrown E", 200, 0.0, 6.0, 200, 0.0, 6.0);
55 
56  Etot_truth = new TH1F("Etot_truth", "Sum of all truth showers (GeV)", 200, 0.0, 6.0);
57  Etot_hits = new TH1F("Etot_hits", "Sum of all hits (GeV)", 200, 0.0, 6.0);
58  Etruth_over_Ethrown_vs_z = new TH2F("Etruth_over_Ethrown_vs_z","Etruth_over_Ethrown_vs_z", 200, -50.0, 600.0, 200, 0.0, 2.0);
59 
60  Edeposited_over_Ethrown_vs_z = new TH2F("Edeposited_over_Ethrown_vs_z","Edeposited_over_Ethrown_vs_z", 80, -50.0, 450.0, 200, 0.0, 2.0);
61 
62  // Go back up to the parent directory
63  dir->cd("../");
64 
65  return NOERROR;
66 }
67 
68 //------------------
69 // brun
70 //------------------
71 jerror_t DEventProcessor_bcal_hists::brun(JEventLoop *eventLoop, int32_t runnumber)
72 {
73  return NOERROR;
74 }
75 
76 //------------------
77 // evnt
78 //------------------
79 jerror_t DEventProcessor_bcal_hists::evnt(JEventLoop *loop, uint64_t eventnumber)
80 {
81  vector<const DBCALShower*> showers;
82  vector<const DFCALCluster*> fcal_showers;
83  vector<const DBCALTruthShower*> truthshowers;
84  vector<const DMCThrown*> mcthrowns;
85  vector<const DHDDMBCALHit*> bcalhits;
86  loop->Get(showers, "KLOE" );
87  //loop->Get(fcal_showers);
88  loop->Get(truthshowers);
89  loop->Get(mcthrowns);
90  loop->Get(bcalhits);
91 
92  LockState();
93 
94  // Single shower params
95  double Etot_reconstructed = 0.0;
96  for(unsigned int i=0; i<showers.size(); i++){
97  const DBCALShower *s = showers[i];
98  xy_shower->Fill(s->x, s->y);
99  z_shower->Fill(s->z);
100  E_shower->Fill(s->Ecorr);
101  Etot_reconstructed += s->Ecorr;
102  }
103 
104  // 2-gamma inv. mass
105  for(unsigned int i=0; i<showers.size(); i++){
106  const DBCALShower *s1 = showers[i];
107  double dx = s1->x;
108  double dy = s1->y;
109  double dz = s1->z - 65.0;
110  double R = sqrt(dx*dx + dy*dy + dz*dz);
111  double E = s1->Ecorr;
112  double Edave = s1->Ecorr*(1.106+(dz+65.0-208.4)*(dz+65.0-208.4)*6.851E-6);
113  TLorentzVector p1(E*dx/R, E*dy/R, E*dz/R, E);
114  TLorentzVector p1dave(Edave*dx/R, Edave*dy/R, Edave*dz/R, Edave);
115 
116  for(unsigned int j=i+1; j<showers.size(); j++){
117  const DBCALShower *s2 = showers[j];
118  dx = s2->x;
119  dy = s2->y;
120  dz = s2->z - 65.0; // shift to coordinate relative to center of target
121  R = sqrt(dx*dx + dy*dy + dz*dz);
122  double E = s2->Ecorr;
123  double Edave = s2->Ecorr*(1.106+(dz+65.0-208.4)*(dz+65.0-208.4)*6.851E-6);
124  TLorentzVector p2(E*dx/R, E*dy/R, E*dz/R, E);
125  TLorentzVector p2dave(Edave*dx/R, Edave*dy/R, Edave*dz/R, Edave);
126 
127  TLorentzVector ptot = p1+p2;
128  two_gamma_mass->Fill(ptot.M());
129  TLorentzVector ptotdave = p1dave+p2dave;
130  two_gamma_mass_corr->Fill(ptotdave.M());
131 
132  if(showers.size()==2)two_gamma_mass_cut->Fill(ptotdave.M());
133  }
134 
135  for(unsigned int j=0; j<fcal_showers.size(); j++){
136  const DFCALCluster *s2 = fcal_showers[j];
137  dx = s2->getCentroid().X();
138  dy = s2->getCentroid().Y();
139  dz = FCAL_Z_OFFSET; // shift to coordinate relative to center of target
140  R = sqrt(dx*dx + dy*dy + dz*dz);
141  double E = s2->getEnergy();
142  TLorentzVector p2(E*dx/R, E*dy/R, E*dz/R, E);
143 
144  TLorentzVector ptot = p1dave+p2;
145  bcal_fcal_two_gamma_mass->Fill(ptot.M());
146 
147  if(showers.size()==1 && fcal_showers.size()==1){
148  bcal_fcal_two_gamma_mass_cut->Fill(ptot.M());
149  }
150  }
151 
152  }
153 
154  // Total energy in hits
155  double Ehit_tot = 0.0;
156  for(unsigned int i=0; i<bcalhits.size(); i++){
157  Ehit_tot += bcalhits[i]->E;
158  }
159  Etot_hits->Fill(Ehit_tot);
160 
161  // Truth values
162  double Etruth_tot = 0.0;
163  double z_truth = 0.0;
164  for(unsigned int i=0; i<truthshowers.size(); i++){
165  Etruth_tot += truthshowers[i]->E;
166  z_truth += truthshowers[i]->E*truthshowers[i]->z;
167  }
168  z_truth/=Etruth_tot;
169  Etot_truth->Fill(Etruth_tot);
170 
171  // Compare to thrown values
172  double Etot_thrown=0.0;
173  for(unsigned int i=0; i<mcthrowns.size(); i++){
174  Etot_thrown += mcthrowns[i]->energy();
175  for(unsigned int j=0; j<showers.size(); j++){
176  double z = showers[j]->z;
177  Erec_over_Ethrown_vs_z->Fill(z, showers[j]->Ecorr/mcthrowns[i]->energy());
178 
179  double Ecorr = showers[j]->Ecorr*(1.106+(z-208.4)*(z-208.4)*6.851E-6);
180  Ecorr_over_Erec_vs_z->Fill(z, mcthrowns[i]->energy()/Ecorr);
181  }
182  }
183 
184  Ereconstructed_vs_Ethrown->Fill(Etot_thrown, Etot_reconstructed);
185  Etruth_over_Ethrown_vs_z->Fill(z_truth, Etruth_tot/Etot_thrown);
186 
187  // Single thrown particle
188  if(mcthrowns.size()==1){
189  const DMCThrown* mcthrown = mcthrowns[0];
190  if(mcthrown->momentum().Theta()>0.0001){
191  double z = mcthrown->position().Z() + 65.0/tan(mcthrown->momentum().Theta());
192  double Ethrown = 1.0; // for some reason, mcthrown->E is zero right now.
193  // I fudge this for now since I know all of the events thrw 1.0GeV
194  Edeposited_over_Ethrown_vs_z->Fill(z, Ehit_tot/Ethrown);
195  }
196  }
197 
198  UnlockState();
199 
200  return NOERROR;
201 }
202 
203 //------------------
204 // erun
205 //------------------
207 {
208  // Any final calculations on histograms (like dividing them)
209  // should be done here. This may get called more than once.
210  return NOERROR;
211 }
212 
213 //------------------
214 // fini
215 //------------------
217 {
218  return NOERROR;
219 }
220 
DVector3 getCentroid() const
Definition: DFCALCluster.h:183
TFile * ROOTfile
jerror_t init(void)
Called once at program start.
jerror_t brun(JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
const DVector3 & position(void) const
jerror_t evnt(JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.
double getEnergy() const
Definition: DFCALCluster.h:155
InitPlugin_t InitPlugin
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.
#define FCAL_Z_OFFSET
jerror_t fini(void)
Called after last event of last event source has been processed.
double sqrt(double)
const DVector3 & momentum(void) const
TDirectory * dir
Definition: bcal_hist_eff.C:31