BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
CbmStsSimulationQa.cxx
Go to the documentation of this file.
1// -------------------------------------------------------------------------
2// ----- CbmStsSimulationQa source file -----
3// ----- Created 02/02/07 by R. Karabowicz -----
4// -------------------------------------------------------------------------
5
7
8#include "CbmStsPoint.h"
9// #include "CbmStsTrack.h"
10// #include "CbmStsTrackMatch.h"
11#include "BmnDetectorList.h"
12#include "CbmGeoStsPar.h"
13#include "CbmMCTrack.h"
14#include "FairGeoNode.h"
15#include "FairGeoPassivePar.h"
16#include "FairGeoTransform.h"
17#include "FairGeoVector.h"
18#include "FairMCPoint.h"
19#include "FairRootManager.h"
20#include "FairRunAna.h"
21#include "FairRuntimeDb.h"
22#include "TCanvas.h"
23#include "TClonesArray.h"
24#include "TFile.h"
25#include "TH1F.h"
26#include "TH2F.h"
27#include "TH3F.h"
28#include "TLegend.h"
29#include "TList.h"
30#include "TPad.h"
31#include "TPaveText.h"
32#include "TVector3.h"
33
34#include <iomanip>
35#include <iostream>
36
37using std::cout;
38using std::endl;
39using std::flush;
40using std::setprecision;
41
42// ----- Default constructor -------------------------------------------
67
68// ----- Standard constructor ------------------------------------------
70 : FairTask("STS Simulation QA", iVerbose)
71 , fMCTracks()
72 , fSTSPoints()
73 , fPassGeo()
74 , fStsGeo()
75 , fTargetPos()
76 , fNStations(0)
77 , fhMomAll()
78 , fhYPtMapAll()
79 , fhPdgCodeAll()
81 , fhMomRec()
82 , fhYPtMapRec()
83 , fhPdgCodeRec()
87 , fhNofEvents()
89 , fHistoList()
90 , fNEvents(0)
93{
94 fOnlineAnalysis = visualizeBool;
95}
96
97// ----- Destructor ----------------------------------------------------
99{
100
101 fHistoList->Delete();
102 delete fHistoList;
103}
104
105// ----- Public method SetParContainers --------------------------------
107{
108
109 // Get Run
110 FairRunAna* run = FairRunAna::Instance();
111 if (!run) {
112 cout << "-E- " << GetName() << "::SetParContainers: No FairRunAna!" << endl;
113 return;
114 }
115
116 // Get Runtime Database
117 FairRuntimeDb* runDb = run->GetRuntimeDb();
118 if (!run) {
119 cout << "-E- " << GetName() << "::SetParContainers: No runtime database!" << endl;
120 return;
121 }
122
123 // Get passive geometry parameters
124 fPassGeo = (FairGeoPassivePar*)runDb->getContainer("FairGeoPassivePar");
125 if (!fPassGeo) {
126 cout << "-E- " << GetName() << "::SetParContainers: "
127 << "No passive geometry parameters!" << endl;
128 return;
129 }
130
131 // Get STS geometry parameters
132 fStsGeo = (CbmGeoStsPar*)runDb->getContainer("CbmGeoStsPar");
133 if (!fStsGeo) {
134 cout << "-E- " << GetName() << "::SetParContainers: "
135 << "No Sts geometry parameters!" << endl;
136 return;
137 }
138}
139// -------------------------------------------------------------------------
140
141// ----- Public method Init --------------------------------------------
143{
144
145 cout << "===========================================================" << endl;
146 ;
147 cout << GetName() << ": Initialising..." << endl;
148
149 // Get RootManager
150 FairRootManager* ioman = FairRootManager::Instance();
151 if (!ioman) {
152 cout << "-E- " << GetName() << "::Init: "
153 << "RootManager not instantised!" << endl;
154 return kFATAL;
155 }
156
157 // Get MCTrack array
158 fMCTracks = (TClonesArray*)ioman->GetObject("MCTrack");
159 if (!fMCTracks) {
160 cout << "-E- " << GetName() << "::Init: No MCTrack array!" << endl;
161 return kERROR;
162 }
163
164 // Get StsPoints array
165 fSTSPoints = (TClonesArray*)ioman->GetObject("StsPoint");
166 if (!fSTSPoints) {
167 // cout << "-E- " << GetName() << "::Init: No StsPoint array!" << endl;
168 return kERROR;
169 }
170
171 // Get the geometry of target and Sts
172 InitStatus geoStatus = GetGeometry();
173 if (geoStatus != kSUCCESS) {
174 cout << "-E- " << GetName() << "::Init: Error in reading geometry!" << endl;
175 return geoStatus;
176 }
177
178 // Create histograms
179 CreateHistos();
180 Reset();
181 if (fOnlineAnalysis) {
182 fOnlineCanvas = new TCanvas("StsSimOnline", "Sts simulation online", 10, 10, 600, 600);
183 fOnlinePad[0] = new TPad("titlePad", "Title pad", 0.00, 0.90, 1.00, 1.00);
184 fOnlinePad[1] = new TPad("momentumPad", "Momentum pad", 0.00, 0.35, 0.50, 0.90);
185 fOnlinePad[2] = new TPad("printoutPad", "Print information pad ", 0.10, 0.10, 0.35, 0.35);
186 fOnlinePad[3] = new TPad("pointPad", "Points per track pad", 0.50, 0.50, 1.00, 0.90);
187 fOnlinePad[4] = new TPad("stationPad1", "Points on 1st station pad", 0.50, 0.25, 0.75, 0.50);
188 fOnlinePad[5] = new TPad("stationPad2", "Points on 3rd station pad", 0.75, 0.25, 1.00, 0.50);
189 fOnlinePad[6] = new TPad("stationPad3", "Points on 5th station pad", 0.50, 0.00, 0.75, 0.25);
190 fOnlinePad[7] = new TPad("stationPad4", "Points on 7th station pad", 0.75, 0.00, 1.00, 0.25);
191 fOnlinePad[1]->SetLogy();
192 for (Int_t ipad = 0; ipad < 8; ipad++) {
193 fOnlinePad[ipad]->SetFillColor(0);
194 fOnlinePad[ipad]->SetBorderMode(0);
195 fOnlinePad[ipad]->Draw();
196 }
197
198 fOnlinePad[0]->cd();
199 TLegend* brp = new TLegend(0.1, 0.1, 0.9, 0.9, "Online Sts simulation");
200 brp->SetTextAlign(22);
201 brp->SetTextSize(0.6);
202 brp->SetTextColor(1);
203 brp->SetBorderSize(0);
204 brp->SetFillColor(0);
205 brp->Draw();
206 fOnlinePad[0]->Update();
207 }
208
209 fhNofStsStations->SetBinContent(1, fNStations);
210
211 // Output
212 cout << " Number of Sts stations : " << fNStations << endl;
213 if (fActive)
214 cout << " ***** Task is ACTIVE *****" << endl;
215 cout << "===========================================================" << endl << endl;
216
217 return geoStatus;
218}
219// -------------------------------------------------------------------------
220
221// ----- Public method ReInit ------------------------------------------
223{
224
225 cout << "===========================================================" << endl;
226 ;
227 cout << GetName() << ": Reinitialising..." << endl;
228
229 // Get the geometry of target and Sts
230 InitStatus geoStatus = GetGeometry();
231 if (geoStatus != kSUCCESS) {
232 cout << "-E- " << GetName() << "::ReInit: Error in reading geometry!" << endl;
233 return geoStatus;
234 }
235
236 // Output
237 cout << " Number of Sts stations : " << fNStations << endl;
238 if (fActive)
239 cout << " ***** Task is ACTIVE *****" << endl;
240 cout << "===========================================================" << endl << endl;
241
242 return geoStatus;
243}
244// -------------------------------------------------------------------------
245
246// ----- Public method Exec --------------------------------------------
248{
249 // cout << "EXEC" << endl;
250
251 Int_t nofMCTracks = fMCTracks->GetEntriesFast();
252 Int_t nofSTSPoints = fSTSPoints->GetEntriesFast();
253
254 for (Int_t itr = 0; itr < nofMCTracks; itr++) {
255 CbmMCTrack* mctrack = (CbmMCTrack*)fMCTracks->At(itr);
256 Int_t pdgCode = mctrack->GetPdgCode();
257
258 // reject funny particles
259 if ((pdgCode == 10010020) || (pdgCode == 10010030) || (pdgCode == 50000050) || (pdgCode == 50010051)
260 || (pdgCode == 10020040))
261 continue;
262
263 TVector3 mom;
264 mctrack->GetMomentum(mom);
265 Float_t pT = mom.Pt();
266 Float_t p = mom.Mag();
267
268 TVector3 startvtx;
269 mctrack->GetStartVertex(startvtx);
270 Float_t vertexZ = startvtx.z();
271
272 TLorentzVector mom4;
273 mctrack->Get4Momentum(mom4);
274 Float_t rapidity = mom4.Rapidity();
275
276 Int_t stsPoints = mctrack->GetNPoints(kGEM);
277
278 if (stsPoints > 0 && vertexZ <= 100) {
279 fhMomAll->Fill(p);
280 fhYPtMapAll->Fill(rapidity, pT);
281 fhPdgCodeAll->Fill(pdgCode);
282 fhStsPointsAll->Fill(stsPoints);
283 fhMomStsPoints->Fill(stsPoints, p);
284 }
285 if (stsPoints > 3 && vertexZ <= 100) {
286 fhMomRec->Fill(p);
287 fhYPtMapRec->Fill(rapidity, pT);
288 fhPdgCodeRec->Fill(pdgCode);
289 fhStsPointsRec->Fill(stsPoints);
290 }
291 }
292
293 // cout << "track loop done" << endl;
294
295 for (Int_t ipnt = 0; ipnt < nofSTSPoints; ipnt++) {
296 CbmStsPoint* stsPoint = (CbmStsPoint*)fSTSPoints->At(ipnt);
297 Float_t z = stsPoint->GetZ(); // [cm]
298 Float_t x = stsPoint->GetX(z); // [cm]
299 Float_t y = stsPoint->GetY(z); // [cm]
300
301 fhStsPointsPosition->Fill(z, x, y);
302 // cout << "filled 3d, MCId = " << stsPoint->GetDetectorID()
303 // << " nr = " << fStationNrFromMcId[stsPoint->GetDetectorID()] << endl;
304 fhStationPoints[fStationNrFromMcId[stsPoint->GetDetectorID()]]->Fill(x, y);
305 // cout << "filled 2d for MCId = " << stsPoint->GetDetectorID()
306 // << " and station nr = " << fStationNrFromMcId[stsPoint->GetDetectorID()] << endl;
307 }
308
309 // cout << "hello" << endl;
310
311 Double_t tracksPerEvent = (Double_t)(fhMomAll->GetEntries()) / ((Double_t)fNEvents + 1);
312 Double_t pointsPerEvent = (Double_t)(fhStsPointsPosition->GetEntries()) / ((Double_t)fNEvents + 1);
313
314 if (fOnlineAnalysis) {
315 fOnlinePad[1]->cd();
316 fhMomRec->Draw();
317 fOnlinePad[1]->Update();
318 fOnlinePad[2]->cd();
319 TPaveText* printoutPave = new TPaveText(0.1, 0.1, 0.9, 0.9);
320 printoutPave->SetTextAlign(22);
321 printoutPave->SetTextSize(0.1);
322 printoutPave->SetTextColor(1);
323 printoutPave->SetBorderSize(0);
324 printoutPave->SetFillColor(0);
325 printoutPave->AddText(Form("%i events", fNEvents + 1));
326 printoutPave->AddText(Form("tracks/event = %3.2f", tracksPerEvent));
327 printoutPave->AddText(Form("points/event = %3.2f", pointsPerEvent));
328 fOnlinePad[2]->Clear();
329 printoutPave->Draw();
330 fOnlinePad[2]->Update();
331 fOnlinePad[3]->cd();
332 fhStsPointsRec->Draw();
333 fOnlinePad[3]->Update();
334
335 if (fNStations) {
336 fOnlinePad[4]->cd();
337 fhStationPoints[0]->Draw("colz");
338 fOnlinePad[4]->Update();
339 if (fNStations > 2) {
340 fOnlinePad[5]->cd();
341 fhStationPoints[2]->Draw("colz");
342 fOnlinePad[5]->Update();
343 if (fNStations > 4) {
344 fOnlinePad[6]->cd();
345 fhStationPoints[4]->Draw("colz");
346 fOnlinePad[6]->Update();
347 if (fNStations > 6) {
348 fOnlinePad[7]->cd();
349 fhStationPoints[6]->Draw("colz");
350 fOnlinePad[7]->Update();
351 }
352 }
353 }
354 }
355 }
356
357 // cout << "\rEvent #" << fNEvents+1 << flush;
358 cout << endl << endl;
359 cout << "=======================================================" << endl;
360 cout << "===== StsSimulationQa: " << endl;
361 cout << "===== \rEvent #" << fNEvents + 1 << endl;
362 cout << "===== " << setprecision(6) << tracksPerEvent << " tracks/event" << endl;
363 cout << "===== " << setprecision(7) << pointsPerEvent << " points/event" << endl;
364 cout << "=======================================================" << endl;
365
366 fNEvents++;
367
368 fhNofEvents->SetBinContent(1, fNEvents);
369}
370// -------------------------------------------------------------------------
371
372// ----- Private method Finish -----------------------------------------
374{
375 // Run summary to screen
376 // cout << endl << endl;
377 // cout << "======================================================="<< endl;
378 // cout << " StsSimulationQa: Run summary" << endl << endl;
379 // cout << "======================================================="
380 // << endl;
381 // cout << endl << endl;
382
383 gDirectory->mkdir("STSSimulationQA");
384 gDirectory->cd("STSSimulationQA");
385 TIter next(fHistoList);
386 while (TH1* histo = ((TH1*)next()))
387 histo->Write();
388 gDirectory->cd("..");
389}
390// -------------------------------------------------------------------------
391
392// ----- Private method GetGeometry ------------------------------------
394{
395
396 cout << "GET GEOMETRY" << endl;
397 // Get Sts geometry
398 if (!fStsGeo) {
399 cout << "-W- " << GetName() << "::GetGeometry: No passive geometry!" << endl;
400 fNStations = 0;
401 return kERROR;
402 }
403 TObjArray* stsNodes = fStsGeo->GetGeoSensitiveNodes();
404 if (!stsNodes) {
405 cout << "-E- " << GetName() << "::GetGeometry: No Sts node array" << endl;
406 fNStations = 0;
407 return kERROR;
408 }
409 Int_t tempNofStations = stsNodes->GetEntries();
410
411 // cout << "There are " << tempNofStations << " nodes" << (tempNofStations > 10 ? "!!!" : "" ) << endl;
412
413 TString geoNodeName;
414 fNStations = 0;
415 TString stationNames[10];
416 for (Int_t ist = 0; ist < tempNofStations; ist++) {
417 FairGeoNode* stsNode = (FairGeoNode*)stsNodes->At(ist);
418 if (!stsNode) {
419 cout << "-W- CbmStsDigiScheme::Init: station#" << ist << " not found among sensitive nodes " << endl;
420 continue;
421 }
422 geoNodeName = stsNode->GetName();
423 TArrayD* params = stsNode->getParameters();
424
425 Bool_t stationKnown = kFALSE;
426 // check if the node belongs to some station, save the MCId and outer radius
427 for (Int_t ikst = 0; ikst < fNStations; ikst++)
428 if (geoNodeName.Contains(stationNames[ikst])) {
429 FairGeoTransform* transform = stsNode->getLabTransform();
430 FairGeoVector translat = transform->getTranslation();
431 FairGeoTransform center = stsNode->getCenterPosition();
432 FairGeoVector centerV = center.getTranslation();
433 Double_t radialSize = TMath::Sqrt(
434 (translat.X() + centerV.X() + params->At(0)) * (translat.X() + centerV.X() + params->At(0))
435 + (translat.Y() + centerV.Y() + params->At(1)) * (translat.Y() + centerV.Y() + params->At(1)));
436 if (radialSize > fStationRadius[ikst]) {
437 // cout << "Found bigger radius for station " << ikst << " -> " << radialSize << endl;
438 fStationRadius[ikst] = radialSize;
439 }
440 fStationNrFromMcId[stsNode->getMCid()] = ikst;
441 stationKnown = kTRUE;
442 }
443
444 if (stationKnown)
445 continue;
446
447 // if not known, register it and save MCId
448 fStationNrFromMcId[stsNode->getMCid()] = fNStations;
449
450 if (geoNodeName.Length() == 12)
451 fStationRadius[fNStations] = params->At(1);
452 else {
453 FairGeoTransform* transform = stsNode->getLabTransform();
454 FairGeoVector translat = transform->getTranslation();
455 FairGeoTransform center = stsNode->getCenterPosition();
456 FairGeoVector centerV = center.getTranslation();
457 Double_t radialSize = TMath::Sqrt(
458 (translat.X() + centerV.X() + params->At(0)) * (translat.X() + centerV.X() + params->At(0))
459 + (translat.Y() + centerV.Y() + params->At(1)) * (translat.Y() + centerV.Y() + params->At(1)));
460 fStationRadius[fNStations] = radialSize;
461 }
462 // it will work only if the node name is organized as:
463 // for station name is "stsstationXX", where XX is the station number (f.e. XX=07 for station number 7)
464 // for sector name is "stsstationXXanythingHereToDistinguishDifferentSectors"
465 geoNodeName.Remove(12, geoNodeName.Length() - 12);
466 stationNames[fNStations] = geoNodeName.Data();
467 fNStations++;
468
469 // cout << "station #" << fNStations << " has MCID = " << stsNode->getMCid() << " and name " <<
470 // stsNode->GetName() << endl;
471
472 // fStationsMCId[fNStations] = stsNode->getMCid(); // not used
473 }
474 // cout << "There are " << fNStations << " stations" << endl;
475
476 return kSUCCESS;
477}
478// -------------------------------------------------------------------------
479
480// ----- Private method CreateHistos -----------------------------------
482{
483
484 fHistoList = new TList();
485
486 fhMomAll = new TH1F("hMomAll", "Momentum - all in STS", 100, 0, 50);
487 fhMomAll->SetXTitle("p [GeV/c]");
488 fhMomAll->SetYTitle("yield [a.u.]");
489 fhYPtMapAll = new TH2F("hYPtMapAll", "Rapidity - trans. mom. map - all in STS", 100, -3, 7, 100, 0, 5);
490 fhYPtMapAll->SetXTitle("rapidity");
491 fhYPtMapAll->SetYTitle("p_{t} [GeV/c]");
492 fhPdgCodeAll = new TH1F("hPdgCodeAll", "PDG code - all in STS", 1000, -500, 500);
494 new TH1F("hStsPointsAll", "STSPoints per track - all in STS", 2 * fNStations, 0.5, 2 * fNStations + 0.5);
495 fhStsPointsAll->SetXTitle("nof points");
496 fhStsPointsAll->SetYTitle("yield [a.u.]");
497 fhMomRec = new TH1F("hMomRec", "Momentum - rec in STS", 100, 0, 50);
498 fhMomRec->SetXTitle("p [GeV/c]");
499 fhMomRec->SetYTitle("yield [a.u.]");
500 fhYPtMapRec = new TH2F("hYPtMapRec", "Rapidity - trans. mom. map - rec in STS", 100, -3, 7, 100, 0, 5);
501 fhYPtMapRec->SetXTitle("rapidity");
502 fhYPtMapRec->SetYTitle("p_{t} [GeV/c]");
503 fhPdgCodeRec = new TH1F("hPdgCodeRec", "PDG code - rec in STS", 1000, -500, 500);
505 new TH1F("hStsPointsRec", "STSPoints per track - rec in STS", 2 * fNStations, 0.5, 2 * fNStations + 0.5);
506 fhStsPointsRec->SetXTitle("nof points");
507 fhStsPointsRec->SetYTitle("yield [a.u.]");
508 fhMomStsPoints = new TH2F("hMomStsPoints", "momentum vs STSPoints per track", 1000, 0, 9, 100, 0, 50);
509 fhStsPointsPosition = new TH3F("hStsPointsPosition", "STS hits", 100, 0, 100, 100, -50, 50, 100, -50, 50);
510 fHistoList->Add(fhMomAll);
514 fHistoList->Add(fhMomRec);
520
521 for (Int_t ist = 0; ist < fNStations; ist++) {
522 Int_t histSize = (Int_t)(1.05 * fStationRadius[ist]) + 1;
523 fhStationPoints[ist] = new TH2F(Form("hStationPoints%i", ist + 1), Form("Points at station %i", ist + 1),
524 40 * histSize, -histSize, histSize, 40 * histSize, -histSize, histSize);
525 fhStationPoints[ist]->SetXTitle("x [cm]");
526 fhStationPoints[ist]->SetYTitle("y [cm]");
527 fHistoList->Add(fhStationPoints[ist]);
528 }
529
530 fhNofEvents = new TH1F("hNofEvents", "Number of events", 1, 0., 1.);
531 fhNofStsStations = new TH1F("hNofStsStations", "Number of stations", 1, 0., 1.);
534}
535// -------------------------------------------------------------------------
536
537// ----- Private method Reset ------------------------------------------
539{
540 fNEvents = 0;
541}
542// -------------------------------------------------------------------------
bool Bool_t
int Int_t
float Float_t
constexpr Bool_t kFALSE
double Double_t
constexpr Bool_t kTRUE
const char Option_t
#define gDirectory
char * Form(const char *fmt,...)
@ kGEM
CbmMCTrack.h.
Definition CbmMCTrack.h:26
Long64_t GetNPoints(DetectorId detId) const
Accessors to the number of MCPoints in the detectors.
void GetMomentum(TVector3 &momentum) const
Definition CbmMCTrack.h:139
void Get4Momentum(TLorentzVector &momentum) const
Definition CbmMCTrack.h:144
void GetStartVertex(TVector3 &vertex) const
Definition CbmMCTrack.h:149
Int_t GetPdgCode() const
Accessors.
Definition CbmMCTrack.h:56
Double_t GetY(Double_t z) const
Double_t GetX(Double_t z) const
Point coordinates at given z from linear extrapolation.
virtual void SetParContainers()
Set parameter containers.
FairGeoPassivePar * fPassGeo
Geometry parameters.
TClonesArray * fSTSPoints
virtual void Finish()
Finish.
Int_t fStationNrFromMcId[10000]
virtual ~CbmStsSimulationQa()
Destructor.
TH1F * fhMomAll
Histograms.
InitStatus GetGeometry()
Read the geometry parameters.
TClonesArray * fMCTracks
Pointers to data arrays.
TList * fHistoList
List of histograms.
virtual void Exec(Option_t *opt)
Execution.
virtual InitStatus ReInit()
Reinitialisation.
CbmStsSimulationQa()
Default constructor.
void Reset()
Reset histograms and counters.
void CreateHistos()
Create histograms.
virtual InitStatus Init()
Initialisation.
Double_t At(Int_t i) const
virtual void SetFillColor(Color_t fcolor)
virtual void SetTextAlign(Short_t align=11)
virtual void SetTextColor(Color_t tcolor=1)
virtual void SetTextSize(Float_t tsize=1)
void Draw(Option_t *option="") override
Double_t Rapidity() const
Int_t GetEntries() const override
TObject * At(Int_t idx) const override
virtual TText * AddText(const char *label)
void Draw(Option_t *option="") override
virtual void SetBorderSize(Int_t bordersize=4)
Ssiz_t Length() const
const char * Data() const
TString & Remove(EStripType s, char c)
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Double_t z() const
Double_t Mag() const
Double_t Pt() const
Double_t Sqrt(Double_t x)