Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JEventProcessor_FCALpedestals.cc
Go to the documentation of this file.
2 #include <JANA/JApplication.h>
3 #include "FCAL/DFCALShower.h"
4 #include "FCAL/DFCALGeometry.h"
5 #include "FCAL/DFCALHit.h"
6 #include "FCAL/DFCALDigiHit.h"
7 #include "FCAL/DFCALCluster.h"
9 #include "PID/DVertex.h"
10 #include "DVector3.h"
12 #include <TTree.h>
13 #include "DVector3.h"
14 #include "PID/DParticleID.h"
15 #include "TRIGGER/DTrigger.h"
16 #include "GlueX.h"
17 #include <vector>
18 #include <map>
19 #include <deque>
20 #include <string>
21 #include <iostream>
22 #include <algorithm>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <TDirectory.h>
26 #include <TH1I.h>
27 #include <TH2F.h>
28 
29 using namespace jana;
30 
31 // Routine used to create our JEventProcessor
32 #include <JANA/JApplication.h>
33 #include <JANA/JFactory.h>
34 
35 //FCAL has only 2800 active channels but and a bunch of inactive blocks. Redundancy in number of channels is to make sure there are enough histograms available to fill all active channels.
36 const int nChan = 2800;
37 
38 // Define Histograms
39 static TH1I* pedestal[nChan];
40 
41 extern "C"{
42  void InitPlugin(JApplication *app){
43  InitJANAPlugin(app);
44  app->AddProcessor(new JEventProcessor_FCALpedestals());
45  }
46 } // "C"
47 
48 
49 //------------------
50 // JEventProcessor_FCALpedestals (Constructor)
51 //------------------
53 {
54 
55 }
56 
57 //------------------
58 // ~JEventProcessor_FCALpedestals (Destructor)
59 //------------------
61 {
62 
63 }
64 
65 //------------------
66 // init
67 //------------------
69 {
70  // This is called once at program startup. If you are creating
71  // and filling historgrams in this plugin, you should lock the
72  // ROOT mutex like this:
73  //
74  TDirectory *main = gDirectory;
75  gDirectory->mkdir("FCAL_pedestals")->cd();
76 
77 
78  for (int i = 0; i < nChan; ++i) {
79  pedestal[i] = new TH1I(Form("pedestal_%i",i),Form("Pedestal for Channel %i",i),500,90,120);
80  }
81 
82  main->cd();
83 
84  return NOERROR;
85 }
86 
87 //------------------
88 // brun
89 //------------------
90 jerror_t JEventProcessor_FCALpedestals::brun(JEventLoop *eventLoop,
91  int32_t runnumber)
92 {
93 
94  // get the FCAL z position from the global geometry interface
95  DApplication *dapp =
96  dynamic_cast<DApplication*>(eventLoop->GetJApplication());
97  const DGeometry *geom = dapp->GetDGeometry(runnumber);
98  if( geom ) {
99 
100  geom->GetFCALZ( m_FCALfront );
101  }
102  else{
103 
104  cerr << "No geometry accessbile." << endl;
105  return RESOURCE_UNAVAILABLE;
106  }
107 
108  return NOERROR;
109 }
110 
111 //------------------
112 // evnt
113 //------------------
114 jerror_t JEventProcessor_FCALpedestals::evnt(JEventLoop *eventLoop,
115  uint64_t eventnumber)
116 {
117  // select events with physics events, i.e., not LED and other front panel triggers
118  const DTrigger* locTrigger = NULL;
119  eventLoop->GetSingle(locTrigger);
120  if(locTrigger->Get_L1FrontPanelTriggerBits() != 0)
121  return NOERROR;
122 
123 
124 
125  // we need an FCAL Geometry object
126  vector< const DFCALGeometry* > geomVec;
127  eventLoop->Get( geomVec );
128 
129  if( geomVec.size() != 1 ){
130 
131  cerr << "No geometry accessbile." << endl;
132  return RESOURCE_UNAVAILABLE;
133  }
134 
135  fcalGeom = geomVec[0];
136 
137  vector< const DFCALDigiHit* > digiHits;
138  eventLoop->Get( digiHits );
139 
140  // FILL HISTOGRAMS
141  // Since we are filling histograms local to this plugin, it will not interfere with other ROOT operations: can use plugin-wide ROOT fill lock
142  japp->RootFillLock(this); //ACQUIRE ROOT FILL LOCK
143 
144  for( vector< const DFCALDigiHit* >::const_iterator dHitItr = digiHits.begin();
145  dHitItr != digiHits.end(); ++dHitItr ){
146  const DFCALDigiHit& dHit = (**dHitItr);
147 
148  m_r = dHit.row ;
149  m_c = dHit.column ;
150  if( !fcalGeom->isBlockActive( m_r, m_c ) ) continue;
151  m_chan = fcalGeom->channel( dHit.row, dHit.column );
152  m_pedestal = dHit.pedestal / dHit.nsamples_pedestal;
153 
154  if( m_pedestal > 0 ) {
155  pedestal[m_chan]->Fill(m_pedestal);
156  }
157  }
158 
159  japp->RootFillUnLock(this); //RELEASE ROOT FILL LOCK
160 
161  return NOERROR;
162 }
163 
164 //------------------
165 // erun
166 //------------------
168 {
169  // This is called whenever the run number changes, before it is
170  // changed to give you a chance to clean up before processing
171  // events from the next run number.
172  return NOERROR;
173 }
174 
175 //------------------
176 // fini
177 //------------------
179 {
180 
181  // Called before program exit after event processing is finished.
182  return NOERROR;
183 }
184 
185 
DApplication * dapp
uint32_t Get_L1FrontPanelTriggerBits(void) const
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
bool GetFCALZ(double &z_fcal) const
z-location of front face of CCAL in cm
Definition: DGeometry.cc:1718
JApplication * japp
uint32_t pedestal
pedestal info used by FPGA (if any)
Definition: DFCALDigiHit.h:22
InitPlugin_t InitPlugin
jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.
DGeometry * GetDGeometry(unsigned int run_number)
uint32_t nsamples_pedestal
number of samples used in pedestal
Definition: DFCALDigiHit.h:25
static TH1I * pedestal[nChan]
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.
jerror_t init(void)
Called once at program start.
jerror_t fini(void)
Called after last event of last event source has been processed.
int main(int argc, char *argv[])
Definition: gendoc.cc:6