CbmRoot
CbmMvdReadoutCluster.cxx
Go to the documentation of this file.
1 // -------------------------------------------------------------------------
2 // ----- CbmMvdReadoutCluster source file -----
3 // ----- Created 17/10/16 by P. Sitzmann -----
4 // -------------------------------------------------------------------------
5 
6 #include "CbmMvdReadoutCluster.h"
7 
8 #include "CbmMvdCluster.h"
9 
10 //-- Include from Fair --//
11 #include "FairLogger.h"
12 
13 //-- Include from Root --//
14 #include "TCanvas.h"
15 #include "TClonesArray.h"
16 #include "TF1.h"
17 #include "TMath.h"
18 #include <TFile.h>
19 
20 #include <iostream>
21 #include <map>
22 #include <utility>
23 
24 using std::cout;
25 using std::endl;
26 using std::map;
27 using std::pair;
28 
29 // ----- Default constructor -------------------------------------------
31  : CbmMvdReadoutCluster::CbmMvdReadoutCluster("MvdReadoutCluster", 0) {}
32 // -------------------------------------------------------------------------
33 
34 // ----- Standard constructor ------------------------------------------
35 CbmMvdReadoutCluster::CbmMvdReadoutCluster(const char* name, Int_t iVerbose)
36  : FairTask(name, iVerbose)
37  , foutFile(nullptr)
38  , fshow(kFALSE)
39  , fWordsPerRegion()
40  , fWordsPerSuperRegion()
41  , fMvdCluster(nullptr)
42  , fEventNumber(0) {}
43 // -------------------------------------------------------------------------
44 
45 // ----- Destructor ----------------------------------------------------
47 // -------------------------------------------------------------------------
48 
49 // -------------------------------------------------------------------------
51  FairRootManager* ioman = FairRootManager::Instance();
52  if (!ioman) { LOG(fatal) << "RootManager not instantised!"; }
53 
54  fMvdCluster = (TClonesArray*) ioman->GetObject("MvdCluster");
55 
56  if (!fMvdCluster) LOG(fatal) << "Data array missing";
57 
59 
60  return kSUCCESS;
61 }
62 // -------------------------------------------------------------------------
63 
64 // -------------------------------------------------------------------------
66  for (Int_t i = 0; i < 350; ++i) {
67  fWordsPerRegion[i] = new TH1F(
68  Form("fWordsPerRegionSensor%d", i), "Words send to a region", 65, 0, 64);
69  fWordsPerSuperRegion[i] = new TH1F(Form("fWordsPerSuperRegionSensor%d", i),
70  "Words send to a region",
71  16,
72  0,
73  15);
74  }
75 }
76 // -------------------------------------------------------------------------
77 
78 
79 // -------------------------------------------------------------------------
80 void CbmMvdReadoutCluster::Exec(Option_t* /*opt*/) {
81  LOG(debug) << "//--------------- New Event " << fEventNumber
82  << " -----------------------\\";
83 
84  for (Int_t nClusters = 0; nClusters < fMvdCluster->GetEntriesFast();
85  ++nClusters) {
86  CbmMvdCluster* cluster = (CbmMvdCluster*) fMvdCluster->At(nClusters);
87  Int_t sensorNr = cluster->GetSensorNr();
88  map<pair<Int_t, Int_t>, Int_t> pixelMap = cluster->GetPixelMap();
89 
90  for (auto cntr = pixelMap.begin(); cntr != pixelMap.end(); ++cntr) {
91  Int_t xPix = cntr->first.first;
92  // Int_t yPix = cntr->first.second;
93  Int_t regionNr = (Int_t)(xPix / fPixelsPerRegion);
94  fWordsPerRegion[sensorNr]->Fill(regionNr);
95  Int_t superRegionNr = (Int_t)(xPix / fPixelsPerSuperRegion);
96  fWordsPerSuperRegion[sensorNr]->Fill(superRegionNr);
97  }
98  }
99 
100  LOG(debug) << "//--------------- End Event -----------------------\\";
101  fEventNumber++;
102 }
103 // -------------------------------------------------------------------------
104 
105 // -------------------------------------------------------------------------
107  foutFile->cd();
108 
109  Float_t scale = 1. / (Float_t) fEventNumber;
110  for (Int_t i = 0; i < 350; ++i) {
111  fWordsPerRegion[i]->Scale(scale, "nosw2");
112  fWordsPerSuperRegion[i]->Scale(scale, "nosw2");
113  }
114 
115  if (fshow) DrawHistograms();
116  WriteHistograms();
117 }
118 // -------------------------------------------------------------------------
119 
120 // -------------------------------------------------------------------------
122 
123  for (Int_t i = 0; i < 350; ++i) {
124  fWordsPerRegion[i]->Write();
125  }
126 
127  for (Int_t i = 0; i < 350; ++i) {
128  fWordsPerSuperRegion[i]->Write();
129  }
130 }
131 // -------------------------------------------------------------------------
132 
133 // -------------------------------------------------------------------------
135 // -------------------------------------------------------------------------
136 
CbmMvdReadoutCluster::Exec
void Exec(Option_t *opt)
Definition: CbmMvdReadoutCluster.cxx:80
CbmMvdReadoutCluster.h
CbmMvdReadoutCluster::fWordsPerRegion
TH1F * fWordsPerRegion[350]
Definition: CbmMvdReadoutCluster.h:45
CbmMvdReadoutCluster::DrawHistograms
void DrawHistograms()
Definition: CbmMvdReadoutCluster.cxx:134
CbmMvdReadoutCluster::Init
InitStatus Init()
Definition: CbmMvdReadoutCluster.cxx:50
CbmMvdReadoutCluster::fWordsPerSuperRegion
TH1F * fWordsPerSuperRegion[350]
Definition: CbmMvdReadoutCluster.h:46
i
int i
Definition: L1/vectors/P4_F32vec4.h:25
CbmMvdCluster::GetPixelMap
std::map< std::pair< Int_t, Int_t >, Int_t > GetPixelMap()
Definition: CbmMvdCluster.h:47
CbmMvdReadoutCluster
Definition: CbmMvdReadoutCluster.h:21
CbmMvdCluster
Definition: CbmMvdCluster.h:27
CbmMvdReadoutCluster::fEventNumber
Int_t fEventNumber
Definition: CbmMvdReadoutCluster.h:50
ClassImp
ClassImp(CbmMvdReadoutCluster)
CbmMvdReadoutCluster::CbmMvdReadoutCluster
CbmMvdReadoutCluster()
Definition: CbmMvdReadoutCluster.cxx:30
CbmMvdReadoutCluster::WriteHistograms
void WriteHistograms()
Definition: CbmMvdReadoutCluster.cxx:121
CbmMvdReadoutCluster::foutFile
TFile * foutFile
Definition: CbmMvdReadoutCluster.h:41
CbmMvdCluster::GetSensorNr
Int_t GetSensorNr()
Definition: CbmMvdCluster.h:51
CbmMvdReadoutCluster::SetupHistograms
void SetupHistograms()
Definition: CbmMvdReadoutCluster.cxx:65
CbmMvdReadoutCluster::fPixelsPerRegion
const Int_t fPixelsPerRegion
Definition: CbmMvdReadoutCluster.h:51
CbmMvdReadoutCluster::Finish
void Finish()
Definition: CbmMvdReadoutCluster.cxx:106
CbmMvdReadoutCluster::fshow
Bool_t fshow
Definition: CbmMvdReadoutCluster.h:43
CbmMvdReadoutCluster::~CbmMvdReadoutCluster
~CbmMvdReadoutCluster()
Definition: CbmMvdReadoutCluster.cxx:46
CbmMvdReadoutCluster::fPixelsPerSuperRegion
const Int_t fPixelsPerSuperRegion
Definition: CbmMvdReadoutCluster.h:52
CbmMvdReadoutCluster::fMvdCluster
TClonesArray * fMvdCluster
Definition: CbmMvdReadoutCluster.h:48
CbmMvdCluster.h