18#include "FairRadLenPoint.h"
19#include "FairRootManager.h"
21#include "TClonesArray.h"
22#include "TGeoManager.h"
24#include "TProfile2D.h"
26#include "boost/assign/list_of.hpp"
31#include <boost/algorithm/string.hpp>
37using boost::assign::list_of;
64 static Int_t eventNo = 0;
66 if (0 == eventNo % 10000) {
67 std::cout <<
"-I- CbmLitRadLengthQa::Exec: eventNo=" << eventNo << std::endl;
87 TDirectory* oldir = gDirectory;
88 TFile* outFile = FairRootManager::Instance()->GetOutFile();
89 if (outFile != NULL) {
93 gDirectory->cd(oldir->GetPath());
104 FairRootManager* ioman = FairRootManager::Instance();
105 assert(ioman != NULL);
106 fRadLen = (TClonesArray*) ioman->GetObject(
"RadLen");
111 const Int_t nofBins = 500;
112 const Int_t nofBinsX = 500;
113 const Int_t nofBinsY = 500;
114 const Int_t nofBinsSiliconThicknessX = 500;
115 const Int_t nofBinsSiliconThicknessY = 500;
116 const Double_t minX = -250.1;
117 const Double_t maxX = 249.9;
118 const Double_t minY = -250.1;
119 const Double_t maxY = 249.9;
120 vector<string> detNames = list_of(
"Total")(
"Mvd")(
"Sts")(
"Rich")(
"Trd")(
"Much")(
"Tof");
121 Int_t nofDetNames = detNames.size();
122 for (Int_t iDet = 0; iDet < nofDetNames; iDet++) {
123 string detName = detNames[iDet];
130 if (!createHistograms)
continue;
131 string rtname =
"hrl_RadThickness_" + detName;
132 fHM->
Add(rtname +
"_H1",
new TH1D(
string(rtname +
"_H1").c_str(),
133 string(rtname +
"_H1;Radiation thickness [%];Entries").c_str(), nofBins, 0, 0));
134 fHM->
Add(rtname +
"_P2",
new TProfile2D(
string(rtname +
"_P2").c_str(),
135 string(rtname +
"_P2;X [cm];Y [cm];Radiation thickness [%]").c_str(),
136 nofBinsX, minX, maxX, nofBinsY, minY, maxY));
137 string tname =
"hrl_Thickness_" + detName;
138 fHM->
Add(tname +
"_H1",
new TH1D(
string(tname +
"_H1").c_str(),
139 string(tname +
"_H1;Thickness [cm];Entries").c_str(), nofBins, 0, 0));
141 new TProfile2D(
string(tname +
"_P2").c_str(),
string(tname +
"_P2;X [cm];Y [cm];Thickness [cm]").c_str(),
142 nofBinsX, minX, maxX, nofBinsY, minY, maxY));
143 string tsname =
"hrl_ThicknessSilicon_" + detName;
144 fHM->
Add(tsname +
"_H1",
new TH1D(
string(tsname +
"_H1").c_str(),
145 string(tsname +
"_H1;Thickness [cm];Entries").c_str(), nofBins, 0, 0));
147 new TProfile2D(
string(tsname +
"_P2").c_str(),
string(tsname +
"_P2;X [cm];Y [cm];Thickness [cm]").c_str(),
148 nofBinsSiliconThicknessX, minX, maxX, nofBinsSiliconThicknessY, minY, maxY));
152 vector<string> trackingDetNames = list_of(
"Mvd")(
"Sts")(
"Trd")(
"Much")(
"MuchAbsorber");
153 Int_t nofTrackingDetNames = trackingDetNames.size();
154 for (Int_t iDet = 0; iDet < nofTrackingDetNames; iDet++) {
155 string dname = trackingDetNames[iDet];
160 : (dname ==
"MuchAbsorber")
163 for (Int_t iStation = 0; iStation < nofStations; iStation++) {
164 string name =
"hrl_RadThickness_" + dname +
"_" +
ToString<Int_t>(iStation) +
"_H1";
165 fHM->
Add(name,
new TH1D(name.c_str(),
string(name +
";Radiation thickness [%];Entries").c_str(), nofBins, 0, 0));
166 name =
"hrl_RadThickness_" + dname +
"_" +
ToString<Int_t>(iStation) +
"_P2";
167 fHM->
Add(name,
new TProfile2D(name.c_str(),
string(name +
";X [cm];Y [cm];Radiation thickness [%]").c_str(),
168 nofBinsX, minX, maxX, nofBinsY, minY, maxY));
169 name =
"hrl_Thickness_" + dname +
"_" +
ToString<Int_t>(iStation) +
"_H1";
170 fHM->
Add(name,
new TH1D(name.c_str(),
string(name +
";Thickness [cm];Entries").c_str(), nofBins, 0, 0));
171 name =
"hrl_Thickness_" + dname +
"_" +
ToString<Int_t>(iStation) +
"_P2";
172 fHM->
Add(name,
new TProfile2D(name.c_str(),
string(name +
";X [cm];Y [cm];Thickness [cm]").c_str(), nofBinsX,
173 minX, maxX, nofBinsY, minY, maxY));
174 name =
"hrl_ThicknessSilicon_" + dname +
"_" +
ToString<Int_t>(iStation) +
"_H1";
175 fHM->
Add(name,
new TH1D(name.c_str(),
string(name +
";Thickness [cm];Entries").c_str(), nofBins, 0, 0));
176 name =
"hrl_ThicknessSilicon_" + dname +
"_" +
ToString<Int_t>(iStation) +
"_P2";
177 fHM->
Add(name,
new TProfile2D(name.c_str(),
string(name +
";X [cm];Y [cm];Thickness [cm]").c_str(),
178 nofBinsSiliconThicknessX, minX, maxX, nofBinsSiliconThicknessY, minY, maxY));
198 map<Int_t, Double_t> radThicknessOnTrack;
199 map<Int_t, Double_t> thicknessOnTrack;
200 map<Int_t, Double_t> thicknessSiliconOnTrack;
202 Double_t
x = 0.,
y = 0.;
203 Double_t r2max = std::numeric_limits<Double_t>::min();
204 for (Int_t iRL = 0; iRL <
fRadLen->GetEntriesFast(); iRL++) {
205 FairRadLenPoint* point = (FairRadLenPoint*)
fRadLen->At(iRL);
207 TVector3
pos = point->GetPosition();
208 TVector3 posOut = point->GetPositionOut();
209 TVector3 res = posOut -
pos;
210 TVector3 middle = (
pos + posOut) * 0.5;
214 gGeoManager->FindNode(posOut.X(), posOut.Y(), posOut.Z());
215 Bool_t isOutside = gGeoManager->IsOutside();
216 gGeoManager->FindNode(middle.X(), middle.Y(), middle.Z());
217 TString path = gGeoManager->GetPath();
218 if (!isOutside && path.Contains(TRegexp(pathPattern.c_str()))) {
219 Double_t r2 = posOut.X() * posOut.X() + posOut.Y() * posOut.Y();
225 const Double_t thickness = res.Mag();
226 const Double_t radThickness = 100 * thickness / point->GetRadLength();
227 const Double_t thicknessSilicon = (
SILICON_RAD_LENGTH / point->GetRadLength()) * thickness;
228 radThicknessOnTrack[point->GetTrackID()] += radThickness;
229 thicknessOnTrack[point->GetTrackID()] += thickness;
230 thicknessSiliconOnTrack[point->GetTrackID()] += thicknessSilicon;
234 map<Int_t, Double_t>::const_iterator it;
235 for (it = radThicknessOnTrack.begin(); it != radThicknessOnTrack.end(); it++) {
236 Double_t rl = (*it).second;
237 fHM->
H1(
"hrl_RadThickness_" + detName +
"_H1")->Fill(rl);
238 fHM->
P2(
"hrl_RadThickness_" + detName +
"_P2")->Fill(
x,
y, rl);
241 for (it = thicknessOnTrack.begin(); it != thicknessOnTrack.end(); it++) {
242 Double_t tl = (*it).second;
243 fHM->
H1(
"hrl_Thickness_" + detName +
"_H1")->Fill(tl);
244 fHM->
P2(
"hrl_Thickness_" + detName +
"_P2")->Fill(
x,
y, tl);
247 for (it = thicknessSiliconOnTrack.begin(); it != thicknessSiliconOnTrack.end(); it++) {
248 Double_t tl = (*it).second;
249 fHM->
H1(
"hrl_ThicknessSilicon_" + detName +
"_H1")->Fill(tl);
250 fHM->
P2(
"hrl_ThicknessSilicon_" + detName +
"_P2")->Fill(
x,
y, tl);
263 map<Int_t, map<Int_t, Double_t>> radThicknessOnTrack;
264 map<Int_t, map<Int_t, Double_t>> thicknessOnTrack;
265 map<Int_t, map<Int_t, Double_t>> thicknessSiliconOnTrack;
266 map<Int_t, map<Int_t, pair<Double_t, Double_t>>>
272 for (Int_t iRL = 0; iRL <
fRadLen->GetEntriesFast(); iRL++) {
273 FairRadLenPoint* point = (FairRadLenPoint*)
fRadLen->At(iRL);
274 Int_t trackId = point->GetTrackID();
277 TVector3
pos = point->GetPosition();
278 TVector3 posOut = point->GetPositionOut();
279 TVector3 res = posOut -
pos;
280 TVector3 middle = (
pos + posOut) * 0.5;
284 gGeoManager->FindNode(middle.X(), middle.Y(), middle.Z());
285 TString path = gGeoManager->GetPath();
286 Int_t stationId = getStationId(path);
289 if (stationId >= 0) {
293 pair<Double_t, Double_t>& xy = xyOnTrack[trackId][stationId];
294 xy.first = posOut.X();
295 xy.second = posOut.Y();
298 const Double_t thickness = res.Mag();
299 const Double_t radThickness = 100 * thickness / point->GetRadLength();
300 const Double_t thicknessSilicon = (
SILICON_RAD_LENGTH / point->GetRadLength()) * thickness;
301 radThicknessOnTrack[trackId][stationId] += radThickness;
302 thicknessOnTrack[trackId][stationId] += thickness;
303 thicknessSiliconOnTrack[trackId][stationId] += thicknessSilicon;
307 FillHistosDetector(radThicknessOnTrack,
"hrl_RadThickness_" + detName +
"_", xyOnTrack);
309 FillHistosDetector(thicknessSiliconOnTrack,
"hrl_ThicknessSilicon_" + detName +
"_", xyOnTrack);
313 map<Int_t, map<Int_t, pair<Double_t, Double_t>>>& xyOnTrack)
315 map<Int_t, map<Int_t, Double_t>>::const_iterator it1;
316 for (it1 = parMap.begin(); it1 != parMap.end(); it1++) {
317 Int_t trackId = (*it1).first;
318 map<Int_t, Double_t>::const_iterator it2;
319 for (it2 = (*it1).second.begin(); it2 != (*it1).second.end(); it2++) {
320 Int_t station = (*it2).first;
321 Double_t param = (*it2).second;
323 fHM->
H1(name)->Fill(param);
325 const pair<Double_t, Double_t>& xy = xyOnTrack[trackId][station];
326 fHM->
P2(name)->Fill(xy.first, xy.second, param);
333 std::cout <<
"-W- CbmLitRadLengthQa::GetMvdStationId: function not implemented\n";
340 Bool_t nodeExists =
false;
341 if (nodePath.Contains(TRegexp(
"/cave_1/STS_v[0-9][0-9][a-z]_0/Station[0-9][0-9]_.+"))) {
342 station = std::atoi(
string((gGeoManager->GetPath() + 26), 2).c_str());
345 return (nodeExists) ? (station - 1) : -1;
351 if (nodePath.Contains(TRegexp(
"/cave_1/trd_v13[a-z]_0/layer[0-9][0-9]_[0-9][0-9][0-9][0-9][0-9]/"
352 "module[0-9]_.+"))) {
353 layerId = std::atoi(
string(nodePath.Data() + 24, 2).c_str()) - 1;
355 else if (nodePath.Contains(TRegexp(
"/cave_1/trd_v13[a-z]_[0-9][a-z]_0/"
356 "layer[0-9][0-9]_[0-9][0-9][0-9][0-9][0-"
357 "9]/module[0-9]_.+"))) {
358 layerId = std::atoi(
string(nodePath.Data() + 27, 2).c_str()) - 1;
367 Bool_t nodeExists =
false;
368 if (nodePath.Contains(TRegexp(
"/cave_1/much_0/muchstation[0-9][0-9]_0/"
369 "muchstation[0-9][0-9]layer[0-9]_0/.+"))) {
370 station = std::atoi(
string(gGeoManager->GetPath() + 42, 2).c_str());
371 layer = std::atoi(
string(1, *(gGeoManager->GetPath() + 49)).c_str());
381 Int_t absorberId = -1;
382 if (nodePath.Contains(TRegexp(
"/cave_1/much_0/muchabsorber[0-9][0-9]_0"))) {
383 absorberId = std::atoi(
string(gGeoManager->GetPath() + 27, 2).c_str()) - 1;
401 string pattern = (detName ==
"Mvd" || detName ==
"Sts" || detName ==
"Trd" || detName ==
"Much")
402 ?
"hrl_ThicknessSilicon_" + detName +
"_.+_P2"
403 :
"hrl_ThicknessSilicon_" + detName +
"_P2";
405 if (histos.empty())
return;
406 TFile* oldFile = gFile;
407 TDirectory* oldDirectory = gDirectory;
408 TFile* file =
new TFile(
string(
fOutputDir +
"/" + boost::algorithm::to_lower_copy(detName) +
".silicon.root").c_str(),
410 for (vector<TH1*>::const_iterator it = histos.begin(); it != histos.end(); it++) {
413 if (detName ==
"Much") {
414 vector<TH1*> histos1 =
fHM->
H1Vector(
"hrl_ThicknessSilicon_MuchAbsorber_.+_P2");
415 for (vector<TH1*>::const_iterator it = histos1.begin(); it != histos1.end(); it++) {
422 gDirectory = oldDirectory;
std::string ToString(ECbmModuleId modId)
@ kMvd
Micro-Vertex Detector.
@ kTrd
Transition Radiation Detector.
@ kTof
Time-of-flight Detector.
@ kSts
Silicon Tracking System.
@ kMuch
Muon detection system.
@ kRich
Ring-Imaging Cherenkov Detector.
Helper functions for drawing 1D and 2D histograms and graphs.
Create report for radiation length QA.
ClassImp(CbmLitRadLengthQa)
FairTask for estimation of radiation length in the detector.
Tracking geometry constructor.
Helper class to convert unique channel ID back and forth.
void ShrinkEmptyBinsH2ByPattern(const std::string &pattern)
Shrink empty bins in H2.
std::vector< TH1 * > H1Vector(const std::vector< std::string > &names) const
Return vector of pointers to TH1 histogram.
TProfile2D * P2(const std::string &name) const
Return pointer to TProfile2D.
void WriteToFile()
Write all objects to current opened file.
void Add(const std::string &name, TNamed *object)
Add new named object to manager.
std::string ToString() const
Return string representation of class.
TH1 * H1(const std::string &name) const
Return pointer to TH1 histogram.
void DetermineSetup()
Determines detector presence using TGeoManager.
bool GetDet(ECbmModuleId detId) const
Return detector presence in setup.
Create report for radiation length QA.
virtual InitStatus Init()
Derived from FairTask.
void CreateHistograms()
Create histograms.
static Int_t GetMuchAbsorberId(const TString &nodePath)
Return MUCH absorber ID by path to the node or -1 in case node does not exists.
virtual ~CbmLitRadLengthQa()
Destructor.
void ReadDataBranches()
Read data branches.
virtual void Finish()
Derived from FairTask.
static Int_t GetMvdStationId(const TString &nodePath)
Return MVD station ID by path to the node or -1 in case node does not exists.
void SaveMaterialBudgetToFile()
Save silicon equivalent histograms to a separate files for each detector.
virtual void Exec(Option_t *opt)
Derived from FairTask.
static Int_t GetMuchStationId(const TString &nodePath)
Return MUCH station ID by path to the node or -1 in case node does not exists.
static const Double_t SILICON_RAD_LENGTH
CbmLitRadLengthQa()
Constructor.
void ExecDetector(const string &pathPattern, const string &detName)
Execute total radiation length for a particular detector.
void SaveDetectorMaterialBudgetToFile(const string &detName)
static Int_t GetStsStationId(const TString &nodePath)
Return STS station ID by path to the node or -1 in case node does not exists.
void FillHistosDetector(const map< Int_t, map< Int_t, Double_t > > &parMap, const string &histName, map< Int_t, map< Int_t, pair< Double_t, Double_t > > > &xyOnTrack)
static Int_t GetTrdStationId(const TString &nodePath)
Return TRD station ID by path to the node or -1 in case node does not exists.
Int_t GetNofStsStations()
Return number of stations in STS.
static CbmLitTrackingGeometryConstructor * Instance()
Return pointer to singleton object.
Int_t ConvertMuchToAbsoluteStationNr(Int_t station, Int_t layer)
Int_t GetNofMvdStations()
Return number of stations in MVD.
Int_t GetNofMuchStations()
Return number of stations in MUCH.
Int_t GetNofMuchAbsorbers()
Return number of MUCH absorbers.
Int_t GetNofTrdStations()
Return number of stations in TRD.
Base class for simulation reports.
void Create(CbmHistManager *histManager, const std::string &outputDir)
Main function which creates report data.
std::string ToString(const T &value)