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