CbmRoot
Loading...
Searching...
No Matches
CbmTrdHitProducerQa.cxx
Go to the documentation of this file.
1/* Copyright (C) 2005-2019 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Matus Kalisky, Florian Uhlig, Denis Bertini [committer] */
4
5// -----------------------------------------------------------------------
6// ----- CbmTrdHitProducerQa -----
7// ----- Created 13/12/05 by M. Kalisky -----
8// -----------------------------------------------------------------------
9
10#include "CbmTrdHitProducerQa.h"
11
12#include "CbmDigiManager.h"
13#include "CbmMCDataArray.h"
14#include "CbmMCDataManager.h"
15#include "CbmMCTrack.h"
16#include "CbmMatch.h"
17#include "CbmQaCanvas.h"
18#include "CbmTrdDigi.h"
19#include "CbmTrdHit.h"
20#include "CbmTrdPoint.h"
21#include "FairBaseParSet.h"
22#include "FairDetector.h"
23#include "FairRootManager.h"
24#include "FairRunAna.h"
25#include "FairRuntimeDb.h"
26#include "TClonesArray.h"
27#include "TH1F.h"
28#include "TMath.h"
29#include "TObjArray.h"
30
31#include <iostream>
32using std::cout;
33using std::endl;
34
35// ---- Default constructor -------------------------------------------------
36
38// --------------------------------------------------------------------------
39
40// ---- Standard constructor ------------------------------------------------
41CbmTrdHitProducerQa::CbmTrdHitProducerQa(const char* name, const char*)
42 : FairTask(name)
43 , fOutFolder("TrdHitProducerQA", "TrdHitProducerQA")
44{
45}
46// --------------------------------------------------------------------------
47
48// ---- Destructor ---------------------------------------------------------
50// --------------------------------------------------------------------------
51
52// ---- Initialisation ------------------------------------------------------
54{
55 fOutFolder.Clear();
56 histFolder = fOutFolder.AddFolder("hist", "Histogramms");
57
58 const int nStations = fNoTrdStations * fNoTrdPerStation;
59
60 for (int i = 0; i < nStations; i++) {
61 fvhHitPullX.push_back(new TH1F(Form("L%iHitPullX", i), "", 500, -50, 50));
62 fvhHitPullY.push_back(new TH1F(Form("L%iHitPullY", i), "", 500, -50, 50));
63 fvhHitPullT.push_back(new TH1F(Form("L%iHitPullT", i), "", 500, -50, 50));
64 fvhHitPullX[i]->SetCanExtend(TH1::kAllAxes);
65 fvhHitPullY[i]->SetCanExtend(TH1::kAllAxes);
66 fvhHitPullT[i]->SetCanExtend(TH1::kAllAxes);
67 histFolder->Add(fvhHitPullX[i]);
68 histFolder->Add(fvhHitPullY[i]);
69 histFolder->Add(fvhHitPullT[i]);
70
71 fvhHitResX.push_back(new TH1F(Form("L%iHitResX", i), "", 500, -50, 50));
72 fvhHitResY.push_back(new TH1F(Form("L%iHitResY", i), "", 500, -50, 50));
73 fvhHitResT.push_back(new TH1F(Form("L%iHitResT", i), "", 500, -50, 50));
74 fvhHitResX[i]->SetCanExtend(TH1::kAllAxes);
75 fvhHitResY[i]->SetCanExtend(TH1::kAllAxes);
76 fvhHitResT[i]->SetCanExtend(TH1::kAllAxes);
77 histFolder->Add(fvhHitResX[i]);
78 histFolder->Add(fvhHitResY[i]);
79 histFolder->Add(fvhHitResT[i]);
80
81 fvhedEcut.push_back(new TH1F(Form("L%iedEcut", i), Form("dEdx of e- for layer %i, mom. cut", i), 600, 0., 60.));
82 fvhedEall.push_back(new TH1F(Form("L%iedEall", i), Form("dEdx of e- for layer %i", i), 600, 0., 60.));
83
84 fvhpidEcut.push_back(new TH1F(Form("L%ipidEcut", i), Form("dEdx of pi- for layer %i, mom. cut", i), 600, 0., 60.));
85 fvhpidEall.push_back(new TH1F(Form("L%ipidEall", i), Form("dEdx of pi- for layer %i", i), 600, 0., 60.));
86
87 histFolder->Add(fvhedEcut[i]);
88 histFolder->Add(fvhedEall[i]);
89 histFolder->Add(fvhpidEcut[i]);
90 histFolder->Add(fvhpidEall[i]);
91
92 fvdECanvas.push_back(new CbmQaCanvas(Form("cL%iEnergyLoss", i), Form("Energy Loss Layer %i", i), 2 * 400, 2 * 400));
93 fvdECanvas[i]->Divide2D(4);
94 fOutFolder.Add(fvdECanvas[i]);
95
96 fvPullCanvas.push_back(
97 new CbmQaCanvas(Form("cL%iPull", i), Form("Pull Distribution Layer %i", i), 3 * 400, 2 * 400));
98 fvPullCanvas[i]->Divide2D(6);
100 }
101
102 // Get pointer to the ROOT I/O manager
103 FairRootManager* rootMgr = FairRootManager::Instance();
104 if (nullptr == rootMgr) {
105 cout << "-E- CbmTrdHitProducerQa::Init : "
106 << "ROOT manager is not instantiated !" << endl;
107 return kFATAL;
108 }
109
110 // Get a pointer to the previous already existing data level
112 if (nullptr == fDigiMan) {
113 cout << "-W- CbmTrdHitProducerQa::Init : "
114 << "no digi manager found !" << endl;
115 return kERROR;
116 }
117 fDigiMan->Init();
118
119 CbmMCDataManager* mcManager = (CbmMCDataManager*) FairRootManager::Instance()->GetObject("MCDataManager");
120
121 // Get pointer to TRD point array
122 fTrdPoints = mcManager->InitBranch("TrdPoint");
123 if (nullptr == fTrdPoints) {
124 cout << "-W- CbmTrdHitProducerQa::Init : "
125 << "no TRD point array !" << endl;
126 return kERROR;
127 }
128
129 // Get pointer to TRD hit array
130 fTrdHitCollection = (TClonesArray*) rootMgr->GetObject("TrdHit");
131 if (nullptr == fTrdHitCollection) {
132 cout << "-W- CbmTrdHitProducerQa::Init : "
133 << "no TRD hit array !" << endl;
134 return kERROR;
135 }
136
137 // Get MCTrack array
138 fMCTrackArray = mcManager->InitBranch("MCTrack");
139 if (nullptr == fMCTrackArray) {
140 cout << "-E- CbmTrdHitProducerQa::Init : No MCTrack array!" << endl;
141 return kFATAL;
142 }
143
144 // Get pointer to TRD digi array match
146 cout << GetName() << ": no TRD match branch in digi manager." << endl;
147 return kERROR;
148 }
149
150 return kSUCCESS;
151}
152
153// --------------------------------------------------------------------------
154
155
156// ---- Task execution ------------------------------------------------------
158{
159 // Loop over TRD hits
160 for (int iHit = 0; iHit < fTrdHitCollection->GetEntriesFast(); iHit++) {
161 const CbmTrdHit* trdHit = (CbmTrdHit*) fTrdHitCollection->At(iHit);
162 if (nullptr == trdHit) continue;
163
164 const CbmMatch* trdDigiMatch = fDigiMan->GetMatch(ECbmModuleId::kTrd, trdHit->GetRefId());
165 if (nullptr == trdDigiMatch) continue;
166
167 if (0 == trdDigiMatch->GetNofLinks()) continue; // catch case w/o links as then MatchedLink is invalid
168 const CbmTrdPoint* trdPoint =
169 dynamic_cast<CbmTrdPoint*>(fTrdPoints->Get(trdDigiMatch->GetMatchedLink())); // file, event, object
170 if (nullptr == trdPoint) continue;
171
172 const int planeId = trdHit->GetPlaneId();
173
174 if (planeId >= fNoTrdStations * fNoTrdPerStation) {
175 cout << GetName() << ": Warning, TRD plane out of bounds, skipping hit."
176 << " (" << planeId << " VS " << fNoTrdStations << " x " << fNoTrdPerStation << ")" << endl;
177 continue;
178 }
179
180 //get particle ID of track corresponding to point
181 const int fileId = trdDigiMatch->GetMatchedLink().GetFile();
182 const int event = trdDigiMatch->GetMatchedLink().GetEntry();
183 const int index = trdPoint->GetTrackID();
184 const CbmMCTrack* track = dynamic_cast<CbmMCTrack*>(fMCTrackArray->Get(fileId, event, index));
185 const int partID = track->GetPdgCode();
186
187 const float momentum = TMath::Sqrt((trdPoint->GetPx() * trdPoint->GetPx()) + (trdPoint->GetPy() * trdPoint->GetPy())
188 + (trdPoint->GetPz() * trdPoint->GetPz()));
189
190 //electrons
191 if ((TMath::Abs(partID) == 11) && (momentum > fMomCutLower) && (momentum < fMomCutUpper)) {
192 fvhedEcut[planeId]->Fill((trdHit->GetELoss()) * 1000000);
193 }
194 if (TMath::Abs(partID) == 11) {
195 fvhedEall[planeId]->Fill((trdHit->GetELoss()) * 1000000);
196 }
197
198 //pions
199 if ((TMath::Abs(partID) == 211) && (momentum > fMomCutLower) && (momentum < fMomCutUpper)) {
200 fvhpidEcut[planeId]->Fill((trdHit->GetELoss()) * 1000000);
201 }
202 if (TMath::Abs(partID) == 211) {
203 fvhpidEall[planeId]->Fill((trdHit->GetELoss()) * 1000000);
204 }
205
206 // compute the Hit pulls for X and Y coordinate
207 const float hitPosX = trdHit->GetX();
208 const float pointPosX = (trdPoint->GetX() + trdPoint->GetXOut()) / 2.;
209 const float hitResX = hitPosX - pointPosX;
210 const float hitPullX = hitResX / trdHit->GetDx();
211
212 const float hitPosY = trdHit->GetY();
213 const float pointPosY = (trdPoint->GetY() + trdPoint->GetYOut()) / 2.;
214 const float hitResY = hitPosY - pointPosY;
215 const float hitPullY = hitResY / trdHit->GetDy();
216
217 const double hitPosT = trdHit->GetTime();
218 const double pointPosT = trdPoint->GetTime();
219 const double hitResT = hitPosT - pointPosT;
220 const double hitPullT = hitResT / trdHit->GetTimeError();
221
222 // fill histograms
223 fvhHitPullX[planeId]->Fill(hitPullX);
224 fvhHitPullY[planeId]->Fill(hitPullY);
225 fvhHitPullT[planeId]->Fill(hitPullT);
226
227 fvhHitResX[planeId]->Fill(hitResX);
228 fvhHitResY[planeId]->Fill(hitResY);
229 fvhHitResT[planeId]->Fill(hitResT);
230 }
231}
232// --------------------------------------------------------------------------
233
234// ---- Finish --------------------------------------------------------------
236// --------------------------------------------------------------------------
237
238// ---- Write test histograms ------------------------------------------------
240{
241 for (size_t i = 0; i < fvdECanvas.size(); i++) {
242 fvdECanvas[i]->cd(1);
243 fvhedEcut[i]->DrawCopy("", "");
244
245 fvdECanvas[i]->cd(2);
246 fvhedEall[i]->DrawCopy("", "");
247
248 fvdECanvas[i]->cd(3);
249 fvhpidEcut[i]->DrawCopy("", "");
250
251 fvdECanvas[i]->cd(4);
252 fvhpidEall[i]->DrawCopy("", "");
253 }
254
255 for (size_t i = 0; i < fvPullCanvas.size(); i++) {
256 fvPullCanvas[i]->cd(1);
257 fvhHitPullX[i]->DrawCopy("", "");
258
259 fvPullCanvas[i]->cd(2);
260 fvhHitPullY[i]->DrawCopy("", "");
261
262 fvPullCanvas[i]->cd(3);
263 fvhHitPullT[i]->DrawCopy("", "");
264
265 fvPullCanvas[i]->cd(4);
266 fvhHitResX[i]->DrawCopy("", "");
267
268 fvPullCanvas[i]->cd(5);
269 fvhHitResY[i]->DrawCopy("", "");
270
271 fvPullCanvas[i]->cd(6);
272 fvhHitResT[i]->DrawCopy("", "");
273 }
274
275 FairSink* sink = FairRootManager::Instance()->GetSink();
276 sink->WriteObject(&fOutFolder, nullptr);
277}
278// --------------------------------------------------------------------------
279
@ kTrd
Transition Radiation Detector.
static FairRootManager * rootMgr
Definition of the CbmQaCanvas class.
ClassImp(CbmTrdHitProducerQa)
Class for hits in TRD detector.
static Bool_t IsMatchPresent(ECbmModuleId systemId)
Presence of a digi match branch.
InitStatus Init()
Initialisation.
static CbmDigiManager * Instance()
Static instance.
const CbmMatch * GetMatch(ECbmModuleId systemId, UInt_t index) const
Get a match object.
double GetTimeError() const
Definition CbmHit.h:77
double GetTime() const
Definition CbmHit.h:76
int32_t GetRefId() const
Definition CbmHit.h:73
TObject * Get(const CbmLink *lnk)
Task class creating and managing CbmMCDataArray objects.
CbmMCDataObject * GetObject(const char *name)
CbmMCDataArray * InitBranch(const char *name)
int32_t GetPdgCode() const
Definition CbmMCTrack.h:68
int32_t GetNofLinks() const
Definition CbmMatch.h:42
const CbmLink & GetMatchedLink() const
Definition CbmMatch.h:41
double GetDy() const
Definition CbmPixelHit.h:76
double GetDx() const
Definition CbmPixelHit.h:75
double GetY() const
Definition CbmPixelHit.h:74
double GetX() const
Definition CbmPixelHit.h:73
std::vector< TH1F * > fvhHitPullY
std::vector< CbmQaCanvas * > fvPullCanvas
CbmDigiManager * fDigiMan
subfolder for histograms
std::vector< CbmQaCanvas * > fvdECanvas
std::vector< TH1F * > fvhedEcut
std::vector< TH1F * > fvhpidEall
TFolder * histFolder
output folder with histos and canvases
virtual void Exec(Option_t *option)
CbmMCDataArray * fTrdPoints
std::vector< TH1F * > fvhHitResX
CbmMCDataArray * fMCTrackArray
TClonesArray * fTrdHitCollection
std::vector< TH1F * > fvhpidEcut
std::vector< TH1F * > fvhHitResT
std::vector< TH1F * > fvhHitResY
std::vector< TH1F * > fvhHitPullX
std::vector< TH1F * > fvhHitPullT
std::vector< TH1F * > fvhedEall
data class for a reconstructed Energy-4D measurement in the TRD
Definition CbmTrdHit.h:40
double GetELoss() const
Definition CbmTrdHit.h:79
int32_t GetPlaneId() const
Inherited from CbmBaseHit.
Definition CbmTrdHit.h:73
double GetYOut() const
Definition CbmTrdPoint.h:69
double GetXOut() const
Definition CbmTrdPoint.h:68