8#include "CbmStsPoint.h"
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"
28#include "TClonesArray.h"
42using std::setprecision;
62 fhStsPointsPosition(),
67 fOnlineAnalysis(kFALSE),
73: FairTask(
"STS Simulation QA", iVerbose),
89 fhStsPointsPosition(),
94 fOnlineAnalysis(kFALSE),
97 fOnlineAnalysis = visualizeBool;
103 fHistoList->Delete();
112 FairRunAna*
run = FairRunAna::Instance();
114 cout <<
"-E- " << GetName() <<
"::SetParContainers: No FairRunAna!"
120 FairRuntimeDb* runDb =
run->GetRuntimeDb();
122 cout <<
"-E- " << GetName() <<
"::SetParContainers: No runtime database!"
130 cout <<
"-E- " << GetName() <<
"::SetParContainers: "
131 <<
"No passive geometry parameters!" << endl;
136 fStsGeo = (
CbmGeoStsPar*) runDb->getContainer(
"CbmGeoStsPar");
138 cout <<
"-E- " << GetName() <<
"::SetParContainers: "
139 <<
"No Sts geometry parameters!" << endl;
151 cout <<
"==========================================================="
153 cout << GetName() <<
": Initialising..." << endl;
156 FairRootManager* ioman = FairRootManager::Instance();
158 cout <<
"-E- " << GetName() <<
"::Init: "
159 <<
"RootManager not instantised!" << endl;
164 fMCTracks = (TClonesArray*) ioman->GetObject(
"MCTrack");
166 cout <<
"-E- " << GetName() <<
"::Init: No MCTrack array!" << endl;
171 fSTSPoints = (TClonesArray*) ioman->GetObject(
"StsPoint");
172 if ( ! fSTSPoints ) {
178 InitStatus geoStatus = GetGeometry();
179 if ( geoStatus != kSUCCESS ) {
180 cout <<
"-E- " << GetName() <<
"::Init: Error in reading geometry!"
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();
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);
213 fOnlinePad[0]->Update();
216 fhNofStsStations->SetBinContent(1,fNStations);
219 cout <<
" Number of Sts stations : " << fNStations << endl;
220 if (fActive) cout <<
" ***** Task is ACTIVE *****" << endl;
221 cout <<
"==========================================================="
234 cout <<
"==========================================================="
236 cout << GetName() <<
": Reinitialising..." << endl;
239 InitStatus geoStatus = GetGeometry();
240 if ( geoStatus != kSUCCESS ) {
241 cout <<
"-E- " << GetName() <<
"::ReInit: Error in reading geometry!"
247 cout <<
" Number of Sts stations : " << fNStations << endl;
248 if (fActive) cout <<
" ***** Task is ACTIVE *****" << endl;
249 cout <<
"==========================================================="
263 Int_t nofMCTracks = fMCTracks->GetEntriesFast();
264 Int_t nofSTSPoints = fSTSPoints->GetEntriesFast();
266 for ( Int_t itr = 0 ; itr < nofMCTracks ; itr++ ) {
271 if ( ( pdgCode == 10010020) ||
272 ( pdgCode == 10010030) ||
273 ( pdgCode == 50000050) ||
274 ( pdgCode == 50010051) ||
275 ( pdgCode == 10020040) )
280 Float_t pT = mom.Pt();
281 Float_t p = mom.Mag();
285 Float_t vertexZ = startvtx.z();
289 Float_t rapidity = mom4.Rapidity();
293 if(stsPoints>0 && vertexZ<=100) {
295 fhYPtMapAll ->Fill(rapidity,pT);
296 fhPdgCodeAll ->Fill(pdgCode);
297 fhStsPointsAll->Fill(stsPoints);
298 fhMomStsPoints->Fill(stsPoints,p);
300 if(stsPoints>3 && vertexZ<=100) {
302 fhYPtMapRec ->Fill(rapidity,pT);
303 fhPdgCodeRec ->Fill(pdgCode);
304 fhStsPointsRec->Fill(stsPoints);
310 for ( Int_t ipnt = 0 ; ipnt < nofSTSPoints ; ipnt++ ) {
312 Float_t z = stsPoint->GetZ();
313 Float_t x = stsPoint->
GetX(z);
314 Float_t y = stsPoint->
GetY(z);
316 fhStsPointsPosition->Fill(z,x,y);
319 fhStationPoints[fStationNrFromMcId[stsPoint->GetDetectorID()]]->Fill(x,y);
326 Double_t tracksPerEvent = (Double_t)(fhMomAll->GetEntries())/((Double_t)fNEvents+1);
327 Double_t pointsPerEvent = (Double_t)(fhStsPointsPosition->GetEntries())/((Double_t)fNEvents+1);
329 if ( fOnlineAnalysis ) {
332 fOnlinePad[1]->Update();
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();
347 fhStsPointsRec->Draw();
348 fOnlinePad[3]->Update();
352 fhStationPoints[0]->Draw(
"colz");
353 fOnlinePad[4]->Update();
354 if ( fNStations>2 ) {
356 fhStationPoints[2]->Draw(
"colz");
357 fOnlinePad[5]->Update();
358 if ( fNStations>4 ) {
360 fhStationPoints[4]->Draw(
"colz");
361 fOnlinePad[6]->Update();
362 if ( fNStations>6 ) {
364 fhStationPoints[6]->Draw(
"colz");
365 fOnlinePad[7]->Update();
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;
385 fhNofEvents->SetBinContent(1,fNEvents);
392void CbmStsSimulationQa::Finish()
402 gDirectory->mkdir(
"STSSimulationQA");
403 gDirectory->cd(
"STSSimulationQA");
404 TIter next(fHistoList);
405 while ( TH1* histo = ((TH1*)next()) ) histo->Write();
406 gDirectory->cd(
"..");
413InitStatus CbmStsSimulationQa::GetGeometry() {
415 cout <<
"GET GEOMETRY" << endl;
418 cout <<
"-W- " << GetName() <<
"::GetGeometry: No passive geometry!"
425 cout <<
"-E- " << GetName() <<
"::GetGeometry: No Sts node array"
430 Int_t tempNofStations = stsNodes->GetEntries();
436 TString stationNames[10];
437 for ( Int_t ist = 0 ; ist < tempNofStations ; ist++ ) {
438 FairGeoNode* stsNode = (FairGeoNode*)stsNodes->At(ist);
440 cout <<
"-W- CbmStsDigiScheme::Init: station#" << ist
441 <<
" not found among sensitive nodes " << endl;
444 geoNodeName = stsNode->GetName();
445 TArrayD* params = stsNode->getParameters();
447 Bool_t stationKnown = kFALSE;
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] ) {
461 fStationRadius[ikst] = radialSize;
463 fStationNrFromMcId[stsNode->getMCid()] = ikst;
464 stationKnown = kTRUE;
467 if ( stationKnown )
continue;
470 fStationNrFromMcId[stsNode->getMCid()] = fNStations;
472 if ( geoNodeName.Length() == 12 )
473 fStationRadius[fNStations] = params->At(1);
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;
488 geoNodeName.Remove(12,geoNodeName.Length()-12);
489 stationNames[fNStations] = geoNodeName.Data();
506void CbmStsSimulationQa::CreateHistos() {
508 fHistoList =
new TList();
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);
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]);
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);
557void CbmStsSimulationQa::Reset() {
TObjArray * GetGeoSensitiveNodes()
Long64_t GetNPoints(DetectorId detId) const
void GetMomentum(TVector3 &momentum) const
void Get4Momentum(TLorentzVector &momentum) const
void GetStartVertex(TVector3 &vertex) const
Double_t GetY(Double_t z) const
Double_t GetX(Double_t z) const
virtual void SetParContainers()
virtual ~CbmStsSimulationQa()
virtual void Exec(Option_t *opt)
virtual InitStatus ReInit()
virtual InitStatus Init()