AlcapDAQ  1
MPileUpPerBlock.cpp
Go to the documentation of this file.
1 /********************************************************************\
2 
3  Name: MPileUpPerBlock
4  Created by: John R Quirk
5 
6  Contents: A module to plot the number of muSC events per MIDAS block
7 
8 \********************************************************************/
9 
10 /* Standard includes */
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string>
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 using std::pair;
28 
29 /*-- Module declaration --------------------------------------------*/
30 INT MPileUpPerBlock_init(void);
31 INT MPileUpPerBlock(EVENT_HEADER*, void*);
32 
33 extern HNDLE hDB;
34 extern TGlobalData* gData;
35 extern TSetupData* gSetup;
36 
37 static TH1I* hPileUpPerBlock;
38 
39 // Time windows
40 static const double pileup_tw = 10000.; // ns
41 
42 
44 {
45  "MPileUpPerBlock", /* module name */
46  "John R Quirk", /* author */
47  MPileUpPerBlock, /* event routine */
48  NULL, /* BOR routine */
49  NULL, /* EOR routine */
50  MPileUpPerBlock_init, /* init routine */
51  NULL, /* exit routine */
52  NULL, /* parameter structure */
53  0, /* structure size */
54  NULL, /* initial parameters */
55 };
56 
60 {
61 
62  hPileUpPerBlock = new TH1I("hPileUpPerBlock","Number of Pile Up; Percent; Counts",100,0.,1);
63  return SUCCESS;
64 }
65 
66 
67 INT MPileUpPerBlock(EVENT_HEADER *pheader, void *pevent)
68 {
69 
70  unsigned int nPileUp = 0;
71 
72  // We assume the existance of all necessary TPI vectors
73  std::map< std::string, std::vector<TPulseIsland*> >& tpis = gData->fPulseIslandToChannelMap;
74  std::map< std::string, std::string >& dets = gSetup->fBankToDetectorMap;
75  std::map< std::string, std::vector<TPulseIsland*> >::iterator iBank;
76  std::vector<TPulseIsland*> *musc_pulses = NULL;
77  std::vector<TPulseIsland*>::iterator curr_musc_pulse, next_musc_pulse;
78 
79  for (iBank = tpis.begin(); iBank != tpis.end(); iBank++) {
80  if (dets.at(iBank->first) == "muSC") {
81  musc_pulses = &tpis.at(iBank->first);
82  curr_musc_pulse = musc_pulses->begin();
83  next_musc_pulse = curr_musc_pulse + 1;
84  }
85  }
86 
87  double cTime = 0;
88  for (; curr_musc_pulse != musc_pulses->end();) {
89  if ((*next_musc_pulse)->GetPulseTime() - (*curr_musc_pulse)->GetPulseTime() < pileup_tw)
90  nPileUp++;
91  curr_musc_pulse++;
92  next_musc_pulse++;
93  }
94 
95  hPileUpPerBlock->Fill(nPileUp);
96 
97  return SUCCESS;
98 }