34int main(
int argc,
const char** argv)
36 bpo::variables_map vm;
37 bpo::options_description opt_general(
"Usage:\n " + std::string(argv[0]) +
39 " Tool will recalibrate phos calib digits and produce inv. mass histos\n"
40 "Commands / Options");
41 bpo::options_description opt_hidden(
"");
42 bpo::options_description opt_all;
43 bpo::positional_options_description opt_pos;
46 auto add_option = opt_general.add_options();
47 add_option(
"help,h",
"Print this help message");
48 add_option(
"input,i", bpo::value<std::string>()->default_value(
"list"),
"List of input *.root files");
49 add_option(
"calib,c", bpo::value<std::string>()->default_value(
"Calib.root"),
"Current calibration");
50 add_option(
"badmap,b", bpo::value<std::string>()->default_value(
"BadMap.root"),
"Bad channels map or none");
51 add_option(
"ptmin,p", bpo::value<float>()->default_value(0.5),
"Min pT for inv mass analysis");
52 opt_all.add(opt_general).add(opt_hidden);
53 bpo::store(bpo::command_line_parser(argc, argv).options(opt_all).positional(opt_pos).run(), vm);
55 if (vm.count(
"help") || argc == 1) {
56 std::cout << opt_general << std::endl;
60 }
catch (bpo::error& e) {
61 std::cerr <<
"ERROR: " << e.what() << std::endl
63 std::cerr << opt_general << std::endl;
65 }
catch (std::exception& e) {
66 std::cerr << e.what() <<
", application will now exit" << std::endl;
70 std::string input =
"list";
71 if (vm.count(
"input")) {
72 input = vm[
"input"].as<std::string>();
74 std::cerr <<
"Please provide input file list with option --input-files list" << std::endl;
79 std::string calibFile =
"Calib.root";
80 if (vm.count(
"calib")) {
81 calibFile = vm[
"calib"].as<std::string>();
84 std::string badmapFile;
85 if (vm.count(
"badmap")) {
86 badmapFile = vm[
"badmap"].as<std::string>();
89 if (vm.count(
"ptmin")) {
90 ptMin = vm[
"ptmin"].as<
float>();
97 if (!badmapFile.empty() && badmapFile !=
"none") {
98 TFile* fBadMap = TFile::Open(badmapFile.c_str());
99 if (fBadMap->IsOpen()) {
103 std::cout <<
"Using empty bad map" << std::endl;
107 std::cout <<
"Using empty bad map" << std::endl;
111 TChain*
chain =
new TChain(
"phosCalibDig");
112 std::ifstream fin(input);
113 if (!fin.is_open()) {
114 std::cerr <<
"can not open file " << input << std::endl;
120 if (!fname.empty()) {
121 chain->AddFile(fname.c_str());
128 static constexpr int nChannels = 14336 - 1793;
129 static constexpr int offset = 1793;
130 static constexpr int nMass = 150.;
131 static constexpr float massMax = 0.3;
132 static constexpr int npt = 200;
133 static constexpr float ptMax = 20;
134 TH1F* hNev =
new TH1F(
"hNev",
"Number of events", 2, 0., 2.);
135 TH2F* hNonLinRe =
new TH2F(
"hNonLinRe",
"Nonlinearity", npt, 0, ptMax, nMass, 0., massMax);
136 TH2F* hNonLinMi =
new TH2F(
"hNonLinMi",
"Nonlinearity", npt, 0, ptMax, nMass, 0., massMax);
140 std::vector<uint32_t>*
digits =
nullptr;
147 std::vector<o2::phos::CluElement> cluelements;
148 std::vector<o2::phos::Cluster>
clusters;
149 std::list<o2::phos::Cluster> mixedClu;
153 boost::timer::progress_display progress(100);
154 for (
int i = 0;
i <
chain->GetEntries();
i++) {
156 if (
i % (
chain->GetEntries() / 100) == 0) {
161 int bc = -1,
orbit = -1, currentCluIndex = -1;
162 while (d !=
digits->end()) {
164 if (
h.mMarker == 16383) {
172 c.getLocalPosition(
x,
z);
175 float e =
c.getEnergy();
176 double sc = e / globaPos.Mag();
177 TLorentzVector
v(sc * globaPos.X(), sc * globaPos.Y(), sc * globaPos.Z(), e);
179 for (
short ip =
buffer.size(); ip--;) {
180 const TLorentzVector& vp =
buffer.getEntry(ip);
181 TLorentzVector
sum =
v + vp;
182 if (
buffer.isCurrentEvent(ip)) {
184 hNonLinRe->Fill(e,
sum.M());
186 if (
sum.Pt() > ptMin) {
187 hMassPerCellRe->Fill(absId,
sum.M());
191 hNonLinMi->Fill(e,
sum.M());
193 if (
sum.Pt() > ptMin) {
194 hMassPerCellMi->Fill(absId,
sum.M());
204 currentCluIndex = -1;
209 std::cout <<
"No orbit number, exit" << std::endl;
219 std::cout <<
"Corrupted data: no header" << std::endl;
227 float e = calibParams->
getGain(absId) * adcCounts;
228 bool isHG = cd.
mHgLg;
229 float x = 0.,
z = 0.;
232 if (cluIndex != currentCluIndex) {
233 if (currentCluIndex >= 0) {
234 clu->setLastCluEl(cluelements.size());
240 clu->setFirstCluEl(cluelements.size());
241 currentCluIndex = cluIndex;
243 cluelements.emplace_back(absId, isHG, e, 0.,
x,
z, -1, 0.);
247 TFile fout(
"histos.root",
"recreate");
251 hMassPerCellRe->Write();
252 hMassPerCellMi->Write();
263 float fullEnergy = 0.;
264 uint32_t iFirst =
clu->getFirstCluEl(), iLast =
clu->getLastCluEl();
267 for (uint32_t
i = iFirst;
i < iLast;
i++) {
268 float ei = cluel[
i].energy;
274 clu->setEnergy(fullEnergy);
275 if (fullEnergy <= 0) {
281 float localPosX = 0., localPosZ = 0.;
283 float invE = 1. / fullEnergy;
284 for (uint32_t
i = iFirst;
i < iLast;
i++) {
299 clu->setLocalPosition(localPosX, localPosZ);