AlcapDAQ  1
MStoppedMuonsPerBlock.cpp
Go to the documentation of this file.
1 /********************************************************************\
2 
3  Name: MStoppedMuonsPerBlock
4  Created by: John R Quirk
5 
6  Contents: A module to plot the number of stopped muons per block
7 
8 \********************************************************************/
9 
10 /* Standard includes */
11 #include <stdlib.h>
12 #include <string>
13 #include <map>
14 
15 /* MIDAS includes */
16 
17 /* ROOT includes */
18 #include <TH1I.h>
19 
20 /* AlCap includes */
21 #include "TGlobalData.h"
22 #include "TSetupData.h"
23 
24 using std::string;
25 using std::map;
26 using std::vector;
27 
28 
29 /*-- Module declaration --------------------------------------------*/
31 INT MStoppedMuonsPerBlock(EVENT_HEADER*, void*);
32 
33 extern HNDLE hDB;
34 extern TGlobalData* gData;
35 extern TSetupData* gSetup;
36 
38 
39 // Time windows
40 static const double tw_muveto = 100.;
41 static const double tw_sc = 100.;
42 static const double tw_si = 100.;
43 
44 
46 {
47  "MStoppedMuonsPerBlock", /* module name */
48  "John R Quirk", /* author */
49  MStoppedMuonsPerBlock, /* event routine */
50  NULL, /* BOR routine */
51  NULL, /* EOR routine */
52  MStoppedMuonsPerBlock_init, /* init routine */
53  NULL, /* exit routine */
54  NULL, /* parameter structure */
55  0, /* structure size */
56  NULL, /* initial parameters */
57 };
58 
62 {
63 
64  hNumberOfStoppedMuonsPerBlock = new TH1I("hNumberOfStoppedMuons","Number of (Possibly) Stopped Muons",2000,0.,2000.);
65  return SUCCESS;
66 }
67 
68 
69 INT MStoppedMuonsPerBlock(EVENT_HEADER *pheader, void *pevent)
70 {
71 
72  unsigned int nStopped = 0;
73 
74  // We assume the existance of all necessary TPI vectors
75  std::map< std::string, std::vector<TPulseIsland*> >& tpis = gData->fPulseIslandToChannelMap;
76  std::map< std::string, std::string>& dets = gSetup->fBankToDetectorMap;
77  std::map< std::string, std::vector<TPulseIsland*> >::iterator iBank;
78  std::vector<TPulseIsland*> *musc_pulses = NULL, *muveto_pulses = NULL, *scr_pulses = NULL, *scl_pulses = NULL;
79  std::vector< std::vector<TPulseIsland*>* > sir_pulses, sil_pulses;
80  std::vector<TPulseIsland*>::iterator c_musc_pulse, c_muveto_pulse, c_scr_pulse, c_scl_pulse;
81  std::vector< std::vector<TPulseIsland*>::iterator > c_sir_pulse, c_sil_pulse;
82 
83  std::string cDet, cBank;
84  int nSiL = 0, nSiR = 0;
85  for (iBank = tpis.begin(); iBank != tpis.end(); iBank++) {
86  cBank = iBank->first;
87  cDet = dets[cBank];
88  if (cDet == "muSc") {
89  musc_pulses = &tpis.at(cBank);
90  c_musc_pulse = musc_pulses->begin();
91  } else if (cDet == "muVeto"){
92  muveto_pulses = &tpis.at(cBank);
93  c_muveto_pulse = muveto_pulses->begin();
94  } else if (cDet == "ScR") {
95  scr_pulses = &tpis.at(cBank);
96  c_scr_pulse = scr_pulses->begin();
97  } else if (cDet == "ScL") {
98  scl_pulses = &tpis.at(cBank);
99  c_scl_pulse = scl_pulses->begin();
100  } else if (cDet.substr(0,2) == "Si" && cDet.substr(cDet.size()-5,4) == "fast") {
101  if(cDet[2] == 'R') {
102  sir_pulses.push_back(&tpis.at(cBank));
103  c_sir_pulse.push_back(std::vector<TPulseIsland*>::iterator());
104  nSiR++;
105  } else {
106  sil_pulses.push_back(&tpis.at(cBank));
107  c_sil_pulse.push_back(std::vector<TPulseIsland*>::iterator());
108  nSiL++;
109  }
110  }
111  }
112 
113 
114  double cTime = 0;
115  for (; c_musc_pulse != musc_pulses->end(); c_musc_pulse++) {
116  cTime = (*c_musc_pulse)->GetPulseTime();
117 
118  while ((*c_muveto_pulse)->GetPulseTime() < cTime)
119  c_muveto_pulse++;
120  while ((*c_scl_pulse)->GetPulseTime() < cTime)
121  c_scl_pulse++;
122  while ((*c_scr_pulse)->GetPulseTime() < cTime)
123  c_scr_pulse++;
124  for(int iSiR = 0; iSiR < nSiR; iSiR++)
125  while ((*c_sir_pulse[iSiR])->GetPulseTime() < cTime)
126  c_sir_pulse[iSiR]++;
127  for (int iSiL = 0; iSiL < nSiL; iSiL++)
128  while ((*c_sil_pulse[iSiL])->GetPulseTime() < cTime)
129  c_sil_pulse[iSiL]++;
130 
131  if ((*c_muveto_pulse)->GetPulseTime() - cTime < tw_muveto)
132  continue;
133  if ((*c_scr_pulse)->GetPulseTime() - cTime < tw_sc)
134  continue;
135  if ((*c_scl_pulse)->GetPulseTime() - cTime < tw_sc)
136  continue;
137  for (int iSiR = 0; iSiR < nSiR; iSiR++)
138  if ((*c_sir_pulse[iSiR])->GetPulseTime() - cTime < tw_si)
139  continue;
140  for (int iSiL = 0; iSiL < nSiL; iSiL++)
141  if ((*c_sil_pulse[iSiL])->GetPulseTime() - cTime < tw_si)
142  continue;
143 
144  nStopped++;
145  }
146 
147  hNumberOfStoppedMuonsPerBlock->Fill(nStopped);
148 
149  return SUCCESS;
150 }