Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JEventProcessor_pedestals.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: JEventProcessor_pedestals.cc
4 // Created: Fri Jun 20 22:13:58 EDT 2014
5 // Creator: davidl (on Darwin harriet.local 13.2.0 i386)
6 //
7 
8 #include <TDirectoryFile.h>
9 
10 
12 using namespace jana;
13 using namespace std;
14 
15 
16 #include <DAQ/Df250PulseData.h>
17 #include <DAQ/Df250PulseIntegral.h>
18 #include <DAQ/Df125PulseIntegral.h>
19 #include <DAQ/DF1TDCHit.h>
20 #include <DAQ/DModuleType.h>
21 
22 // Routine used to create our JEventProcessor
23 #include <JANA/JApplication.h>
24 #include <JANA/JFactory.h>
25 extern "C"{
26 void InitPlugin(JApplication *app){
27  InitJANAPlugin(app);
28  app->AddProcessor(new JEventProcessor_pedestals());
29 }
30 } // "C"
31 
32 
33 //------------------
34 // JEventProcessor_pedestals (Constructor)
35 //------------------
37 {
38  //pthread_mutex_init(&mutex, NULL);
39 
40 }
41 
42 //------------------
43 // ~JEventProcessor_pedestals (Destructor)
44 //------------------
46 {
47 
48 }
49 
50 //------------------
51 // init
52 //------------------
54 {
55  return NOERROR;
56 }
57 
58 //------------------
59 // brun
60 //------------------
61 jerror_t JEventProcessor_pedestals::brun(JEventLoop *eventLoop, int32_t runnumber)
62 {
63  return NOERROR;
64 }
65 
66 //------------------
67 // evnt
68 //------------------
69 jerror_t JEventProcessor_pedestals::evnt(JEventLoop *loop, uint64_t eventnumber)
70 {
71  vector<const Df250PulseData*> df250dats;
72  vector<const Df250PulseIntegral*> df250pis;
73  vector<const Df125PulseIntegral*> df125pis;
74  loop->Get(df250pis);
75  loop->Get(df125pis);
76 
77  // Lock ROOT mutex
78  japp->RootWriteLock();
79 
80  for(unsigned int i=0; i<df250dats.size(); i++){
81  TH2D *h = GetHist(df250dats[i]);
82  // save single-sample pedestal
83  if(h) h->Fill(df250dats[i]->pedestal/df250dats[i]->nsamples_pedestal, (double)df250dats[i]->channel);
84  }
85 
86  for(unsigned int i=0; i<df250pis.size(); i++){
87  TH2D *h = GetHist(df250pis[i]);
88  if(h) h->Fill(df250pis[i]->pedestal, (double)df250pis[i]->channel);
89  }
90 
91  for(unsigned int i=0; i<df125pis.size(); i++){
92  TH2D *h = GetHist(df125pis[i]);
93  if(h) h->Fill(df125pis[i]->pedestal, (double)df125pis[i]->channel);
94  }
95 
96  // Unlock ROOT mutex
97  japp->RootUnLock();
98 
99  return NOERROR;
100 }
101 
102 //------------------
103 // erun
104 //------------------
106 {
107  return NOERROR;
108 }
109 
110 //------------------
111 // fini
112 //------------------
114 {
115  return NOERROR;
116 }
117 
118 //------------------
119 // GetHist
120 //------------------
122 {
123  TH2D *h = NULL;
124 
125  // Lock mutex
126  //pthread_mutex_lock(&mutex);
127 
128  // First, check of histogram already exists for this crate, slot, channel
129  csc_t csc(hit->rocid, hit->slot, 0);
130  map<csc_t, TH2D*>::iterator iter = all_hists.find(csc);
131  if(iter != all_hists.end()) h= iter->second;
132 
133  // Create histogram if not already existing
134  if(!h){
135 
136  TDirectory *save_dir = gDirectory;
137 
138  // Make sure rocid directory exists
139  char rocdirname[256];
140  sprintf(rocdirname, "rocid%02d", hit->rocid);
141  TDirectory *rocdir = (TDirectory*)gDirectory->FindObject(rocdirname);
142  if(!rocdir) rocdir = new TDirectoryFile(rocdirname, rocdirname);
143  rocdir->cd();
144 
145  // Determine module type
147  if(dynamic_cast<const Df250PulseIntegral*>(hit) != NULL) mod_type = DModuleType::FADC250;
148  else if(dynamic_cast<const Df125PulseIntegral*>(hit) != NULL) mod_type = DModuleType::FADC125;
149 
150  int Nchan = 0;
151  int Nbins = 100;
152  double xmin = -100.0;
153  double xmax = +100.0;
154  switch(mod_type){
156  Nchan = 16;
157  Nbins = 1050;
158  xmin = -1000.0;
159  xmax = 20000.0;
160  break;
162  Nchan = 72;
163  Nbins = 1050;
164  xmin = -1000.0;
165  xmax = 100000.0;
166  break;
167  case DModuleType::F1TDC32: Nchan = 32; break;
168  case DModuleType::F1TDC48: Nchan = 48; break;
169  default:
170  //pthread_mutex_unlock(&mutex);
171  return NULL;
172  }
173 
174  // Create histogram
175  char hname[256];
176  char title[256];
177  sprintf(hname, "slot%02d", hit->slot);
178  string mod_name = DModuleType::GetName(mod_type);
179  sprintf(title, "Pedestals for %s roc=%d slot=%d", mod_name.c_str(), hit->rocid, hit->slot);
180  h = new TH2D(hname, title, Nbins, xmin, xmax, Nchan, -0.5, (double)Nchan-0.5);
181  h->SetXTitle("measured pedestal (scaled to total samples)");
182  // h->SetYTitle("channel"); // somehow, this causes crashes when running root on the file later on ??!!
183  h->SetStats(0);
184 
185  // Store histo in map
186  all_hists[csc] = h;
187 
188  // Restore ROOT directory
189  save_dir->cd();
190  }
191 
192  // Unlock mutex
193  //pthread_mutex_unlock(&mutex);
194 
195  return h;
196 }
197 
198 
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.
sprintf(text,"Post KinFit Cut")
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.
JApplication * japp
InitPlugin_t InitPlugin
This class holds the Crate, Slot, Channel address for a digitized value from the DAQ system...
Definition: DDAQAddress.h:26
TH2D * GetHist(const DDAQAddress *hit)
string GetName(void) const
Definition: DModuleType.h:143
jerror_t init(void)
Called once at program start.
static TH1I * pedestal[nChan]
uint32_t rocid
Definition: DDAQAddress.h:32
jerror_t fini(void)
Called after last event of last event source has been processed.
uint32_t slot
Definition: DDAQAddress.h:33