CbmRoot
CbmPsdHitProducer.cxx
Go to the documentation of this file.
1 // -------------------------------------------------------------------------
2 // ----- CbmPsdHitProducer source file -----
3 // ----- Created 15/05/12 by Alla & SELIM -----
4 // -------------------------------------------------------------------------
5 #include <fstream>
6 #include <iostream>
7 #include <map>
8 
9 #include "TClonesArray.h"
10 #include "TMath.h"
11 #include <TFile.h>
12 
13 #include "FairRootManager.h"
14 
15 #include "CbmDigiManager.h"
16 #include "CbmPsdDigi.h"
17 #include "CbmPsdHit.h"
18 #include "CbmPsdHitProducer.h"
19 
20 #include "FairLogger.h"
21 
22 using std::cout;
23 using std::endl;
24 
25 
26 // ----- Default constructor -------------------------------------------
28  : FairTask("Ideal Psd Hit Producer", 1)
29  , fNHits(0)
30  , fHitArray(NULL)
31  , fDigiMan(nullptr)
32  , fXi()
33  , fYi()
34  , fhModXNewEn(NULL) {
35  // Reset();
36 }
37 // -------------------------------------------------------------------------
38 
39 
40 // ----- Destructor ----------------------------------------------------
42  if (fHitArray) {
43  fHitArray->Delete();
44  delete fHitArray;
45  }
46 }
47 // -------------------------------------------------------------------------
48 
49 
50 // ----- Public method Init --------------------------------------------
52 
53  //ifstream fxypos("psd_geo_xy.txt");
54  //for (Int_t ii=1; ii<50; ii++) { //SELIM: 49 modules, including central & corner modules (rejected in analysis/flow/eventPlane.cxx)
55  // fxypos>>fXi[ii]>>fYi[ii];
56  // cout<<ii<<" "<<fXi[ii]<<" "<<fYi[ii]<<endl;
57  //}
58  //fxypos.close();
59 
60  fhModXNewEn = new TH1F("hModXNewEn", "X distr, En", 300, -150., 150.);
61  fhModXNewEn->Print();
62 
63  // Get RootManager
64  FairRootManager* ioman = FairRootManager::Instance();
65  if (!ioman) {
66  LOG(fatal)
67  << "-W- CbmPsdHitProducer::Init: RootManager not instantised!"; //FLORIAN & SELIM
68  return kFATAL;
69  }
70 
71  // --- Initialise digi manager
73  digiMan->Init();
74  // --- Check input branch (PsdDigi). If not present, set task inactive.
75  if (!digiMan->IsPresent(ECbmModuleId::kPsd)) {
76  LOG(error) << GetName() << ": No PsdDigi input array present; "
77  << "task will be inactive.";
78  return kERROR;
79  }
80 
81 
82  // Create and register output array
83  fHitArray = new TClonesArray("CbmPsdHit", 1000);
84  ioman->Register(
85  "PsdHit", "PSD", fHitArray, IsOutputBranchPersistent("PsdHit"));
86 
87  fHitArray->Dump();
88  cout << "-I- CbmPsdHitProducer: Intialisation successfull " << kSUCCESS
89  << endl;
90  return kSUCCESS;
91 }
92 
93 
94 // -------------------------------------------------------------------------
95 
96 
97 // ----- Public method Exec --------------------------------------------
98 void CbmPsdHitProducer::Exec(Option_t* /*opt*/) {
99 
100  cout << " CbmPsdHitProducer::Exec(Option_t* /*opt*/) " << endl;
101  fhModXNewEn->Print();
102 
103  // Reset output array
104  Reset();
105 
106  // Declare some variables
107  const CbmPsdDigi* dig = NULL;
108 
109  /*
110  Double_t edep[NPsdMod];//marina
111  for (Int_t imod=0; imod<NPsdMod; imod++) { edep[imod]=0.; }//marina
112 */
113 
114  std::map<int, Double_t> edepmap;
115 
116  // Loop over PsdDigits
117  Int_t nDigi = fDigiMan->GetNofDigis(ECbmModuleId::kPsd);
118  cout << " nDigits " << nDigi << endl;
119 
120  for (Int_t idig = 0; idig < nDigi; idig++) {
121  dig = fDigiMan->Get<CbmPsdDigi>(idig);
122  if (!dig) continue;
123  Int_t mod = dig->GetModuleID();
124  // Int_t sec = dig->GetSectionID();
125  Double_t eDep = (Double_t) dig->GetEdep();
126  //edep[mod-1] += (Double_t) dig->GetEdep(); //DEBUG: SELIM
127 
128  auto insert_result = edepmap.insert(std::make_pair(mod, eDep));
129  if (!insert_result.second) { // entry was here before
130  (*insert_result.first).second += eDep;
131  }
132 
133  } // Loop over MCPoints
134 
135  fNHits = 0;
136  for (auto edep_entry : edepmap) {
137  int modID = edep_entry.first;
138  Double_t eDep = edep_entry.second;
139  new ((*fHitArray)[fNHits]) CbmPsdHit(modID, eDep);
140  fNHits++;
141  }
142 
143  /*
144  for (Int_t imod=0; imod<NPsdMod; imod++) //marina
145  {
146  if (edep[imod]>0.)
147  {
148  new ((*fHitArray)[fNHits]) CbmPsdHit(imod+1, edep[imod]);
149  fNHits++;
150  //cout<<"MARINA CbmPsdHitProducer " <<fNHits <<" " <<imod+1 <<" " <<edep[imod] <<endl;
151  //fhModXNewEn->Fill(fXi[imod],TMath::Sqrt(edep[imod]) );
152  //cout<<"CbmPsdHitProducer "<<fNHits<<" "<<imod<<" "<<edep[imod]<<endl;
153  }
154  }
155  */
156 
157  // Event summary
158  cout << "-I- CbmPsdHitProducer: " << fNHits << " CbmPsdHits created." << endl;
159 }
160 // -------------------------------------------------------------------------
162  cout << " CbmPsdHitProducer::Finish() " << endl;
163  TFile* outfile = new TFile("EdepHistos.root", "RECREATE");
164  outfile->cd();
165  fhModXNewEn->Write();
166  //outfile->Close(); //SELIM
167 }
168 
169 // ----- Private method Reset ------------------------------------------
171  fNHits = 0;
172  if (fHitArray) fHitArray->Delete();
173 }
174 
175 
CbmPsdDigi.h
CbmPsdHit.h
CbmDigiManager::Init
InitStatus Init()
Initialisation.
Definition: CbmDigiManager.cxx:71
CbmDigiManager::GetNofDigis
static Int_t GetNofDigis(ECbmModuleId systemId)
Definition: CbmDigiManager.cxx:62
CbmPsdHitProducer::Init
virtual InitStatus Init()
Definition: CbmPsdHitProducer.cxx:51
CbmDigiManager::IsPresent
static Bool_t IsPresent(ECbmModuleId systemId)
Presence of a digi branch.
Definition: CbmDigiManager.cxx:112
CbmPsdHitProducer::~CbmPsdHitProducer
~CbmPsdHitProducer()
Definition: CbmPsdHitProducer.cxx:41
CbmDigiManager::Instance
static CbmDigiManager * Instance()
Static instance.
Definition: CbmDigiManager.h:93
CbmPsdHitProducer::Exec
virtual void Exec(Option_t *opt)
Definition: CbmPsdHitProducer.cxx:98
CbmDigiManager::Get
const Digi * Get(Int_t index) const
Get a digi object.
Definition: CbmDigiManager.h:52
CbmPsdHitProducer::fHitArray
TClonesArray * fHitArray
Definition: CbmPsdHitProducer.h:51
ClassImp
ClassImp(CbmConverterManager) InitStatus CbmConverterManager
Definition: CbmConverterManager.cxx:12
CbmDigiManager
CbmDigiManager.
Definition: CbmDigiManager.h:37
fDigiMan
CbmDigiManager * fDigiMan
Definition: CbmTofAnaTestbeam.cxx:88
CbmPsdHitProducer.h
CbmPsdHitProducer::fDigiMan
CbmDigiManager * fDigiMan
Definition: CbmPsdHitProducer.h:54
CbmPsdHitProducer
Definition: CbmPsdHitProducer.h:27
CbmPsdDigi::GetModuleID
Double_t GetModuleID() const
Module Identifier.
Definition: CbmPsdDigi.h:105
CbmDigiManager.h
CbmPsdHitProducer::fNHits
Int_t fNHits
Definition: CbmPsdHitProducer.h:48
CbmPsdHitProducer::fhModXNewEn
TH1F * fhModXNewEn
Definition: CbmPsdHitProducer.h:64
ECbmModuleId::kPsd
@ kPsd
Projectile spectator detector.
CbmPsdDigi
Data class for PSD digital information.
Definition: CbmPsdDigi.h:31
CbmPsdHitProducer::Finish
virtual void Finish()
Definition: CbmPsdHitProducer.cxx:161
CbmPsdHitProducer::Reset
void Reset()
Definition: CbmPsdHitProducer.cxx:170
CbmPsdHitProducer::CbmPsdHitProducer
CbmPsdHitProducer()
Definition: CbmPsdHitProducer.cxx:27
CbmPsdHit
Definition: CbmPsdHit.h:20
CbmPsdDigi::GetEdep
Double_t GetEdep() const
Energy deposit.
Definition: CbmPsdDigi.h:99