33#include <FairRootManager.h>
34#include <FairRunAna.h>
35#include <FairRuntimeDb.h>
40#include <TClonesArray.h>
41#include <TDatabasePDG.h>
42#include <TGenericClassInfo.h>
43#include <TGeoManager.h>
47#include <TParameter.h>
48#include <TParticlePDG.h>
84 for (
unsigned int i = 0; i <
fHistList.size(); i++) {
137 FairRunAna* ana = FairRunAna::Instance();
139 LOG(fatal) <<
"No FairRunAna instance";
142 FairRuntimeDb* rtdb = ana->GetRuntimeDb();
144 LOG(fatal) <<
"No FairRuntimeDb instance";
166 TObjArray* topNodes = gGeoManager->GetTopNode()->GetNodes();
167 for (
Int_t iTopNode = 0; iTopNode < topNodes->GetEntriesFast(); iTopNode++) {
168 TGeoNode* topNode =
static_cast<TGeoNode*
>(topNodes->At(iTopNode));
169 if (TString(topNode->GetName()).Contains(
"trd")) {
177 LOG(info) <<
"TRD is not in the setup, do nothing";
184 LOG(error) <<
"No CbmTrdParSetDigi container in FairRuntimeDb";
189 LOG(error) <<
"No CbmTrdParSetGeo container in FairRuntimeDb";
193 FairRootManager* manager = FairRootManager::Instance();
199 LOG(error) <<
"No time slice found";
203 fHits =
dynamic_cast<TClonesArray*
>(manager->GetObject(
"TrdHit"));
206 LOG(error) <<
"No TRD hit array found";
210 fClusters =
dynamic_cast<TClonesArray*
>(manager->GetObject(
"TrdCluster"));
213 LOG(error) <<
"No TRD cluster array found";
226 fHitMatches =
dynamic_cast<TClonesArray*
>(manager->GetObject(
"TrdHitMatch"));
232 LOG(error) <<
": No MCEventList data!";
237 LOG(error) <<
"No MC tracks found";
242 LOG(error) <<
"No MC points found";
247 LOG(error) <<
"No TRD hit matches found";
252 LOG(error) <<
"No TRD digi matches found";
262 Int_t layerCounter = 0;
263 TObjArray* topNodes = gGeoManager->GetTopNode()->GetNodes();
264 for (
Int_t iTopNode = 0; iTopNode < topNodes->GetEntriesFast(); iTopNode++) {
265 TGeoNode* topNode =
static_cast<TGeoNode*
>(topNodes->At(iTopNode));
266 if (TString(topNode->GetName()).Contains(
"trd")) {
267 TObjArray* layers = topNode->GetNodes();
268 for (
Int_t iLayer = 0; iLayer < layers->GetEntriesFast(); iLayer++) {
269 TGeoNode* layer =
static_cast<TGeoNode*
>(layers->At(iLayer));
270 if (TString(layer->GetName()).Contains(
"layer")) {
282 LOG(error) <<
"can not count TRD tracking stations";
287 fHitsMc =
new TClonesArray(
"CbmTrdHitMC", 100);
288 manager->Register(
"TrdHitMC",
"TRD",
fHitsMc, IsOutputBranchPersistent(
"TrdHitMC"));
293 gStyle->SetOptStat(0);
298 for (
unsigned int i = 0; i <
fHistList.size(); i++) {
315 Form(
"MC Points per Hit: Station %i;N mc points / hit", i), 10, -0.5, 9.5);
324 Form(
"Hits per MC Point: Station %i; N hits / mc point", i), 10, -0.5, 9.5);
335 double dr =
sqrt(dx * dx + dy * dy);
337 fhEfficiencyR.emplace_back(Form(
"hEfficiencyR%i", i), Form(
"Efficiency R: Station %i;R [cm]", i), 100, 0, dr);
342 fhEfficiencyXY.emplace_back(Form(
"hEfficiencyXY%i", i), Form(
"Efficiency XY: Station %i;X [cm];Y [cm]", i), 50, -dx,
389 LOG(debug) <<
"Event: " <<
fNevents.GetVal();
397 FairSink* sink = FairRootManager::Instance()->GetSink();
399 sink->WriteObject(&
GetQa(),
nullptr);
419 LOG(fatal) <<
" No Geo params for station " << iStation <<
" module " << ModuleId <<
" found ";
423 double staZ = pGeo->
GetZ();
426 if ((iStation > 0) && (staZ <= lastZ)) {
427 LOG(error) <<
"TRD trackig stations are not properly ordered in Z";
456 std::vector<std::vector<int>> pointNhits;
457 pointNhits.resize(nMcEvents);
458 for (
int iE = 0; iE < nMcEvents; iE++) {
461 int nPoints =
fMcPoints->Size(fileId, eventId);
462 pointNhits[iE].resize(nPoints, 0);
465 for (
Int_t iHit = 0; iHit < nHits; iHit++) {
469 LOG(error) <<
"TRD hit N " << iHit <<
" doesn't exist";
477 LOG(error) <<
"Unknown detector class type " << hit->
GetClassType() <<
" for TRD hit N " << iHit;
485 LOG(fatal) <<
"TRD hit layer id " << StationIndex <<
" is out of range";
490 if (clusterId < 0 || clusterId >= nClusters) {
491 LOG(error) <<
"TRD cluster id " << clusterId <<
" is out of range";
497 LOG(error) <<
"TRD cluster N " << clusterId <<
" doesn't exist";
502 LOG(error) <<
"TRD hit address " << address <<
" differs from its cluster address " << cluster->
GetAddress();
508 if (nClusterDigis <= 0) {
509 LOG(error) <<
"hit match for TRD cluster " << clusterId <<
" has no digis ";
520 for (
Int_t iDigi = 0; iDigi < nClusterDigis; iDigi++) {
522 if (digiIdx < 0 || digiIdx >= nDigis) {
523 LOG(fatal) <<
"TRD cluster: digi index " << digiIdx <<
" out of range ";
528 LOG(fatal) <<
"TRD digi " << iDigi <<
" not found";
533 std::stringstream ss;
534 ss <<
"TRD hit address " << address <<
" differs from its digi address " << digi->
GetAddressModule();
536 LOG(error) << ss.str();
544 if (!tdigi) tdigi = digi->
GetTime();
546 default: LOG(fatal) <<
"TRD digi type neither SPADIC or FASP";
return;
552 LOG(fatal) <<
"TRD digi match " << digiIdx <<
" not found";
567 if (hitMatch ==
nullptr) {
568 std::stringstream ss;
569 ss <<
"hit match for TRD hit " << iHit <<
" doesn't exist";
571 LOG(error) << ss.str();
576 std::stringstream ss;
577 ss <<
"hit match for TRD hit " << iHit <<
" doesn't correspond to digi matches";
579 LOG(error) << ss.str();
587 for (
int i = 0; i < myHitMatch.
GetNofLinks(); i++) {
592 if (iE < 0 || iE >= nMcEvents) {
593 std::stringstream ss;
594 ss <<
"link points to a non-existing MC event";
596 LOG(error) << ss.str();
599 if (link.
GetIndex() >= (
int) pointNhits[iE].size()) {
600 std::stringstream ss;
601 ss <<
"link points to a non-existing MC index";
603 LOG(error) << ss.str();
616 std::stringstream ss;
617 ss <<
"hit from noise [INFO]";
624 std::stringstream ss;
625 ss <<
"link points to a non-existing MC point";
627 LOG(error) << ss.str();
632 std::stringstream ss;
633 ss <<
"mc point module address differs from the hit module address";
635 LOG(error) << ss.str();
643 int ModuleId =
fTrdDigiPar->GetModuleId(StationIndex);
647 LOG(fatal) <<
" No Geo params for station " << StationIndex <<
" module " << ModuleId <<
" found ";
651 double staZ = pGeo->
GetZ();
652 if ((staZ < p->GetZIn() - 1.) || (staZ > p->
GetZOut() + 1.)) {
653 std::stringstream ss;
654 ss <<
"TRD station " << StationIndex <<
": active material Z[" << p->
GetZIn() <<
" cm," << p->
GetZOut()
655 <<
" cm] is too far from the nominal station Z " << staZ <<
" cm";
657 LOG(error) << ss.str();
661 if (fabs(hit->
GetZ() - staZ) > 1.) {
662 std::stringstream ss;
663 ss <<
"TRD station " << StationIndex <<
": hit Z " << hit->
GetZ()
664 <<
" cm, is too far from the nominal station Z " << staZ <<
" cm";
666 LOG(error) << ss.str();
673 if (nHitPoints != 1) {
674 std::stringstream ss;
675 ss <<
"hit from mixed hit [INFO] nPoints=" << nHitPoints;
682 std::stringstream ss;
683 ss <<
"MC event time doesn't exist for a TRD link";
685 LOG(error) << ss.str();
689 double x = p->GetX();
690 double y = p->GetY();
691 double z = p->GetZ();
692 double t = t0 + p->GetTime();
693 double px = p->GetPx();
694 double py = p->GetPy();
695 double pz = p->GetPz();
698 if (fabs(p->
GetPzOut()) < 0.01)
continue;
701 double dz = hit->
GetZ() - z;
709 CbmLink mcTrackLink = bestLink;
710 mcTrackLink.
SetIndex(p->GetTrackID());
713 std::stringstream ss;
714 ss <<
"MC track " << p->GetTrackID() <<
" doesn't exist";
716 LOG(error) << ss.str();
720 if (pdg < 9999999 && ((TParticlePDG*) TDatabasePDG::Instance()->GetParticle(pdg))) {
721 mass = TDatabasePDG::Instance()->GetParticle(pdg)->Mass();
726 constexpr double speedOfLight = 29.979246;
729 t += dz / (pz * speedOfLight) *
sqrt(mass * mass + mom3.Mag2());
731 double du = hit->
GetX() -
x;
732 double dv = hit->
GetY() -
y;
733 double dt = hit->
GetTime() - t;
734 double su = hmc->
GetDx();
735 double sv = hit->
GetDy();
740 if (StationIndex % 2) {
755 if ((su < 1.e-5) || (sv < 1.e-5) || (st < 1.e-5)) {
756 std::stringstream ss;
757 ss <<
"TRD hit errors are not properly set: errX " << hit->
GetDx() <<
" errY " << hit->
GetDy() <<
" errT ";
759 LOG(error) << ss.str();
778 for (
int iE = 0; iE < nMcEvents; iE++) {
781 int nPoints =
fMcPoints->Size(fileId, eventId);
782 for (
int ip = 0; ip < nPoints; ip++) {
785 LOG(error) <<
"MC point doesn't exist";
791 LOG(fatal) <<
"TRD hit layer id " << StationIndex <<
" for module " << address <<
" is out of range";
795 fhEfficiencyR[StationIndex].Fill(
sqrt(p->GetX() * p->GetX() + p->GetY() * p->GetY()), (pointNhits[iE][ip] > 0));
796 fhEfficiencyXY[StationIndex].Fill(p->GetX(), p->GetY(), (pointNhits[iE][ip] > 0));
805 gStyle->SetPaperSize(20, 20);
820 for (UInt_t i = 0; i <
fHistList.size(); i++) {
824 for (UInt_t i = 0; i < 6; i++) {
@ kTrd
Transition Radiation Detector.
Definition of the CbmQaCanvas class.
Useful utilities for CBM QA tasks.
ClassImp(CbmTrdCalibTracker)
Data Container for TRD clusters.
Class for hits in TRD detector.
friend fvec sqrt(const fvec &a)
int32_t GetAddress() const
int32_t GetDigi(int32_t index) const
Get digi at position index.
int32_t GetNofDigis() const
Number of digis in cluster.
const Digi * Get(Int_t index) const
Get a digi object.
static CbmDigiManager * Instance()
Static instance.
double GetTimeError() const
int32_t GetAddress() const
void SetIndex(int32_t index)
Task class creating and managing CbmMCDataArray objects.
Container class for MC events with number, file and start time.
int32_t GetPdgCode() const
void AddLinks(const CbmMatch &match)
const CbmLink & GetLink(int32_t i) const
int32_t GetNofLinks() const
const CbmLink & GetMatchedLink() const
Bookkeeping of time-slice content.
static uint32_t GetLayerId(uint32_t address)
Return layer ID from address.
static uint32_t GetModuleAddress(uint32_t address)
Return unique module ID from address.
std::vector< CbmQaHist< TH1D > * > fHistList
List of the above histogramms.
CbmQaHist< TH1D > fh1DpullV
CbmQaHist< TH1D > fh2DresidualY
TClonesArray * fClusters
Data.
CbmQaHist< TH1D > fh2DresidualX
CbmQaCanvas fCanvPointsPerHit
CbmMCDataArray * fMcTracks
std::vector< CbmQaHist< TH1I > > fhHitsPerPoint
hits efficiency
CbmQaHist< TH1D > fh1DpullU
Histogram for PULL Distribution.
CbmTimeSlice * fTimeSlice
CbmQaHist< TH1D > fh1DresidualV
void Finish()
FairTask: Action at end of run. For this task and all of the subtasks.
CbmQaHist< TH1D > fh1DresidualU
number of processed events
TParameter< int > fNevents
subfolder for histograms
std::vector< CbmQaHist< TProfile > > fhEfficiencyR
CbmTrdCalibTracker(const char *name="TrdQaTracker", Int_t verbose=1)
Constructor.
void DeInit()
Free the memory etc.
CbmQaHist< TH1D > fh2DpullY
CbmQaCanvas fCanvResidual
Canvaces: collection of histogramms.
CbmMCDataManager * fMcManager
CbmTrdParSetDigi * fTrdDigiPar
CbmQaHist< TH1D > fh2DresidualT
CbmMCDataArray * fMcPoints
CbmDigiManager * fDigiManager
CbmQaHist< TH1D > fh2DpullT
CbmTrdParSetGeo * fTrdGeoPar
InitStatus ReInit()
FairTask: Reinitialisation.
CbmQaCanvas fCanvEfficiencyXY
void ResolutionQa()
Analysis of hit uncertainty (pull) distributions.
std::vector< CbmQaHist< TProfile2D > > fhEfficiencyXY
hits efficiency
void SetParContainers()
FairTask: Intialise parameter containers.
TClonesArray * fHitMatches
void Exec(Option_t *)
TTask: Process a timeslice.
CbmQaCanvas fCanvEfficiencyR
InitStatus GeometryQa()
Check the geometry.
CbmQaHist< TH1D > fh2DpullX
std::vector< CbmQaHist< TH1I > > fhPointsPerHit
hits purity
TClonesArray * fHitsMc
Output.
CbmQaHist< TH1D > fh1DresidualT
TFolder * fHistFolder
output folder with histos and canvases
CbmQaCanvas fCanvHitsPerPoint
CbmQaHist< TH1D > fh1DpullT
~CbmTrdCalibTracker()
Destructor.
CbmMCEventList * fMcEventList
MC data.
Data Container for TRD clusters.
int32_t GetAddressModule() const
Getter module address in the experiment.
uint64_t GetTimeDAQ() const
Getter for global DAQ time [clk]. Differs for each ASIC. [In FASP case DAQ time is already stored in ...
eCbmTrdAsicType GetType() const
Channel FEE SPADIC/FASP according to CbmTrdAsicType.
double GetTime() const
Getter for physical time [ns]. Accounts for clock representation of each ASIC. In SPADIC case physica...
TRD hit to MC point correlation class.
size_t AddPoint(const CbmTrdPoint *p, double t, int id)
Add MC points to the hit. The first time this function is called is for the best matched MC point.
void SetErrorMsg(std::string msg)
Store error message.
void AddCluster(const CbmTrdCluster *c)
Copy cluster details.
size_t PurgeSignals()
Applies to TRD2D and remove 0 charges from the boundaries of the cluster.
size_t AddSignal(const CbmTrdDigi *d, uint64_t t0)
Add signal values in the increasing order of pad index.
double GetDx() const
Calculate residuals in the bending plane.
data class for a reconstructed Energy-4D measurement in the TRD
bool GetClassType() const
Definition of geometry for one TRD module.
virtual Double_t GetZ() const
int32_t GetModuleAddress() const
std::tuple< double, double > FitKaniadakisGaussian(TH1 *pHist)
Fit a histogram with Kaniadakis Gaussian Distribution.