AlcapDAQ  1
Normalization.cpp
Go to the documentation of this file.
1 #include "Normalization.h"
2 #include "TGlobalData.h"
3 #include "TSetupData.h"
4 
5 #include <iostream>
6 #include <string>
7 #include <vector>
8 #include <map>
9 
10 static TH1F* hNumberOfMuons;
11 
12 Normalization::Normalization(char *HistogramDirectoryName, int threshold = 350) :
13  FillHistBase(HistogramDirectoryName), fNMuons(0), fThreshold(threshold) {
14 
15  N_MU = 0;
16 
17  hNumberOfMuons = new TH1F("hNumberOfMuons", "hNumberOfMuons", 1,0,1);
18 
19  gDirectory->cd("/");
20 }
21 
23 }
24 
26 
27  // Make sure no other module changed N_MU
28  if (N_MU != fNMuons) {
29  std::cout << "ERROR: Normalization::N_MU changed unexpectadly!" << std::endl;
30  return -1;
31  }
32  fNMuons = 0;
33 
34  // Find the bankname associated with muSc
35  std::string bankname = "";
36  std::map<std::string, std::string>& B2D = gSetup->fBankToDetectorMap;
37  static std::map<std::string, std::string>::iterator iBank;
38  for (iBank = B2D.begin(); iBank != B2D.end(); ++iBank) {
39  if (iBank->second == "muSc") {
40  bankname = iBank->first;
41  break;
42  }
43  }
44 
45  // Make certain we found muSc
46  if (bankname == "") {
47  std::cout << "Warning: Could not find muSc pulses! (TPulseIsland* vector not found, N_MU set to zero)" << std::endl;
49  return 0;
50  }
51 
52  // Count the muons
53  std::vector<TPulseIsland*>& pulses = gData->fPulseIslandToChannelMap.at(bankname);
54  static std::vector<TPulseIsland*>::iterator iPulse;
55  for (iPulse = pulses.begin(); iPulse != pulses.end(); ++iPulse)
56  if (IsOverThreshold(iPulse))
57  ++fNMuons;
58 
59  N_MU = fNMuons;
60  hNumberOfMuons->Fill("muons", fNMuons);
61 
62  return 0;
63 }
64 
65 bool Normalization::IsOverThreshold(std::vector<TPulseIsland*>::iterator& pulse) {
66 
67  std::vector<int> samples = (*pulse)->GetSamples();
68  static std::vector<int>::iterator iSample;
69  for (iSample = samples.begin(); iSample != samples.end(); ++iSample)
70  if (*iSample > fThreshold)
71  return true;
72 
73  return false;
74 }
75 
77  return N_MU;
78 }
79 
80 unsigned int Normalization::N_MU = 0;