AlcapDAQ  1
MHitTime.cpp
Go to the documentation of this file.
1 /********************************************************************\
2 
3  Name: MHitTime
4  Created by: John R Quirk
5 
6  Contents: A module that plots the time of hits relative to muSC
7 
8 \********************************************************************/
9 
10 /* Standard includes */
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string>
14 #include <sstream>
15 
16 /* MIDAS includes */
17 
18 /* ROOT includes */
19 #include <TH1I.h>
20 
21 /* AlCap includes */
22 #include "TGlobalData.h"
23 #include "TSetupData.h"
24 
25 using std::string;
26 using std::map;
27 using std::vector;
28 using std::pair;
29 
30 /*-- Module declaration --------------------------------------------*/
31 INT MHitTime_init(void);
32 INT MHitTime(EVENT_HEADER*, void*);
33 
34 extern HNDLE hDB;
35 extern TGlobalData* gData;
36 extern TSetupData* gSetup;
37 
38 static TH1I* hTime_MuSC;
39 static std::map< std::string, TH1I* > hEventTimes;
40 static std::map< std::string, TH1I* > hBlockTimes;
41 
42 const static double BLOCKLENGTH = 10000000.; // ns
43 const static double CUTWINDOW = 10000.; // ns
44 
45 ANA_MODULE MHitTime_module =
46 {
47  "MHitTime", /* module name */
48  "John R Quirk", /* author */
49  MHitTime, /* event routine */
50  NULL, /* BOR routine */
51  NULL, /* EOR routine */
52  MHitTime_init, /* init routine */
53  NULL, /* exit routine */
54  NULL, /* parameter structure */
55  0, /* structure size */
56  NULL, /* initial parameters */
57 };
58 
59 
61 {
62 
63  std::map< std::string, std::vector<TPulseIsland*> >& tpis = gData->fPulseIslandToChannelMap;
64  std::map< std::string, std::vector<TPulseIsland*> >::iterator iBank;
65  std::map< std::string, std::string> dets = gSetup->fBankToDetectorMap;
66 
67  std::string cBank, cDet;
68  hBlockTimes.clear();
69  hEventTimes.clear();
70  hTime_MuSC = new TH1I("hTime_MuSC", "Hit Times of MuSC;Block Hit Time (ns);Counts",
71  100, 0., BLOCKLENGTH);
72  for (iBank = tpis.begin(); iBank != tpis.end(); iBank++) {
73  cBank = iBank->first;
74  cDet = dets[cBank];
75  if (cDet == "muSC")
76  continue;
77  hBlockTimes[cDet] = new TH1I(("hBlockTime_" + cDet).c_str(), ("Block Hit Times of " + cDet + ";Time (ns); Counts").c_str(),
78  100, 0., BLOCKLENGTH);
79  hEventTimes[cDet] = new TH1I(("hEventTime_" + cDet).c_str(), ("Event Hit Times of " + cDet +";Time (ns); Counts").c_str(),
80  100, 0., CUTWINDOW);
81  }
82  return SUCCESS;
83 }
84 
85 
86 INT MHitTime(EVENT_HEADER *pheader, void *pevent)
87 {
88 
89  // We assume the existance of all necessary TPI vectors
90  std::map< std::string, std::vector<TPulseIsland*> >& tpis = gData->fPulseIslandToChannelMap;
91  std::map< std::string, std::string>& dets = gSetup->fBankToDetectorMap;
92  std::map< std::string, std::string>& banks = gSetup->fDetectorToBankMap;
93 
94  std::vector<TPulseIsland*> muons = tpis.at(banks.at("muSC"));
95 
96  std::map< std::string, std::vector<TPulseIsland*> >::iterator iBank;
97  std::map< std::string, std::string>::iterator iDet;
98  std::vector<TPulseIsland*>::iterator cMuon;
99  std::map< std::string, std::vector<TPulseIsland*>::iterator > pulses;
100  for (iBank = tpis.begin(); iBank != tpis.end(); iBank++)
101  if(iBank->first != banks.at("muSC"))
102  pulses[iBank->first] = iBank->second.begin();
103 
104 
105  double t_mu;
106  double t[2];
107  std::string cDet, cBank;
108  for (cMuon = muons.begin(); cMuon != muons.end(); cMuon++) {
109  t_mu = (*cMuon)->GetPulseTime();
110  hTime_MuSC->Fill(t_mu);
111  for (iDet = dets.begin(); iDet != dets.end(); iDet++) {
112  cBank = iDet->first;
113  cDet = iDet->second;
114  std::vector<TPulseIsland*>::iterator& cPulse = pulses.at(cBank);
115  if (cPulse == tpis.at(cBank).end())
116  continue;
117  t[0] = (*cPulse)->GetPulseTime();
118  t[1] = t[0] - t_mu;
119  hBlockTimes.at(cDet)->Fill(t[0]);
120  while (t[1] < 0.) {
121  cPulse++;
122  t[0] = (*cPulse)->GetPulseTime();
123  t[1] = t[0] - t_mu;
124  hBlockTimes.at(cDet)->Fill(t[0]);
125  }
126  while (t[1] < CUTWINDOW) {
127  hEventTimes.at(cDet)->Fill(t[1]);
128  cPulse++;
129  t[0] = (*cPulse)->GetPulseTime();
130  t[1] = t[0] - t_mu;
131  hBlockTimes.at(cDet)->Fill(t[0]);
132  }
133  }
134  }
135 
136  // Are there any pulses left?
137  for (iDet = dets.begin(); iDet != dets.end(); iDet++) {
138  cBank = iDet->first;
139  cDet = iDet->second;
140  std::vector<TPulseIsland*>::iterator cPulse = pulses.at(cBank);
141  while(cPulse != tpis.at(cBank).end()) {
142  t[0] = (*cPulse)->GetPulseTime();
143  hBlockTimes[cDet]->Fill(t[0]);
144  cPulse++;
145  }
146  }
147 
148  return SUCCESS;
149 }