10#include <framework/datastore/StoreObjPtr.h>
11#include <framework/datastore/StoreArray.h>
12#include <framework/dataobjects/EventMetaData.h>
15#include <trg/ecl/modules/trgeclQAM/TRGECLQAMModule.h>
25#include <RooRealVar.h>
26#include <RooDataHist.h>
27#include <RooGaussian.h>
28#include <RooAddModel.h>
30#include <RooArgList.h>
31#include <RooNovosibirsk.h>
51 return string(
"TRGECLQAMModule 1.00");
58 m_nevent(1), m_outputfile(
"")
61 string desc =
"TRGECLQAMModule(" +
version() +
")";
100 B2DEBUG(100,
"TRGECLQAMModule ... created");
108 B2DEBUG(100,
"TRGECLQAMModule ... destructed ");
117 B2DEBUG(100,
"TRGECLQAMModule::initialize ... options");
135 B2DEBUG(200,
"TRGECLQAMModule ... beginRun called ");
145 B2DEBUG(200,
"TRGECLFAMMoudle ... event called");
156 int TCId = (m_TRGECLUnpacker->
getTCId());
160 if (TCId < 1 || TCId > 576 || HitEnergy == 0) {
continue;}
178 const int* clE = m_TRGECLUnpackerEvt->
getCLEnergy();
182 for (
int i = 0; i < 6; i++) {
186 sort(clER, clER + 6);
209 for (
int TCId = 1; TCId < 577; TCId++) {
211 mean_FWD +=
TCID[TCId - 1];
212 }
else if (TCId < 513) {
213 mean_BAR +=
TCID[TCId - 1];
215 mean_BWD +=
TCID[TCId - 1];
219 mean_BAR /= (512 - 80);
220 mean_BWD /= (576 - 512);
222 for (
int TCId = 1; TCId < 577; TCId++) {
224 if (
TCID[TCId - 1] < mean_FWD * 0.1)
m_FWD++;
225 }
else if (TCId < 513) {
226 if (
TCID[TCId - 1] < mean_BAR * 0.1)
m_BAR++;
228 if (
TCID[TCId - 1] < mean_BWD * 0.1)
m_BWD++;
233 const int etot_size =
etot.size();
234 for (
int i = 0; i < etot_size; i++) {
239 RooRealVar* E_tot =
new RooRealVar(
"E_tot",
"E_tot", 0, 4000);
240 RooDataHist* data_E_tot =
new RooDataHist(
"data_E_tot",
"dataset with E_tot", *E_tot,
h_etot);
241 RooRealVar* mean_check =
new RooRealVar(
"mean_check",
"Mean for checking", 2000, 1000, 3000);
242 RooRealVar* sigma_check =
new RooRealVar(
"sigma_check",
"Sigma for checking", 100, 0, 300);
243 RooGaussian* gauss_check =
new RooGaussian(
"gauss_check",
"Gaussian for checking", *E_tot, *mean_check, *sigma_check);
244 gauss_check->fitTo(*data_E_tot);
245 double mean_ch = mean_check->getVal();
247 RooRealVar* mean_E_tot =
new RooRealVar(
"mean_E_tot",
"Mean of Gaussian", mean_ch, mean_ch - 200, mean_ch + 200);
250 RooRealVar* sigma1_E_tot =
new RooRealVar(
"sigma1_E_tot",
"Width of Gaussian", 30, 0, 60);
251 RooGaussian* gauss1_E_tot =
new RooGaussian(
"gauss1_E_tot",
"gauss(x,mean,sigma)", *E_tot, *mean_E_tot, *sigma1_E_tot);
252 RooRealVar* sigma2_E_tot =
new RooRealVar(
"sigma2_E_tot",
"Width of Gaussian", 100, 30, 250);
253 RooGaussian* gauss2_E_tot =
new RooGaussian(
"gauss2_E_tot",
"gauss(x,mean,sigma)", *E_tot, *mean_E_tot, *sigma2_E_tot);
255 RooRealVar* frac_core_E_tot =
new RooRealVar(
"frac_core",
"core fraction", 0.85, 0.0, 1.0);
256 RooAddModel* gaussm_E_tot =
new RooAddModel(
"gaussm",
"core+tail gauss", RooArgList(*gauss1_E_tot, *gauss2_E_tot),
257 RooArgList(*frac_core_E_tot));
261 gaussm_E_tot->fitTo(*data_E_tot, RooFit::Range(mean_ch - 300, mean_ch + 300));
263 RooPlot* xframe_E_tot = E_tot->frame(RooFit::Title(
"energy_tot"));
265 data_E_tot->plotOn(xframe_E_tot, RooFit::MarkerStyle(7));
267 gaussm_E_tot->plotOn(xframe_E_tot, RooFit::Name(
"Cal_energy"), RooFit::LineColor(2));
268 double v_m_E_tot = mean_E_tot->getVal();
269 double e_m_E_tot = mean_E_tot->getError();
271 double v1_s1_E_tot = sigma1_E_tot->getVal();
273 double v2_s1_E_tot = sigma2_E_tot->getVal();
276 double frac_E_tot = frac_core_E_tot->getVal();
277 double v_s1_E_tot = v1_s1_E_tot * (frac_E_tot) + v2_s1_E_tot * (1 - frac_E_tot);
281 for (
long unsigned int ii = 0; ii <
caltime.size(); ii++) {
287 RooRealVar T_c(
"T_c",
"T_c", -100, 100);
288 RooDataHist data_T_c(
"data_T_c",
"dataset with T_c", T_c,
h_caltime);
290 RooRealVar mean_T_c(
"mean_T_c",
"Mean of Gaussian", 0, -100, 100);
291 RooRealVar sigma1_T_c(
"sigma1_T_c",
"Width of Gaussian", 10, 0, 50);
292 RooGaussian gauss1_T_c(
"gauss1_T_c",
"gauss(x,mean,sigma)", T_c, mean_T_c, sigma1_T_c);
293 RooRealVar sigma2_T_c(
"sigma2_T_c",
"Width of Gaussian", 30, 10, 100);
294 RooGaussian gauss2_T_c(
"gauss2_T_c",
"gauss(x,mean,sigma)", T_c, mean_T_c, sigma2_T_c);
296 RooRealVar frac_core_T_c(
"frac_core",
"core fraction", 0.85, 0.0, 1.0);
297 RooAddModel gaussm_T_c(
"gaussm",
"core+tail gauss", RooArgList(gauss1_T_c, gauss2_T_c), RooArgList(frac_core_T_c));
299 gaussm_T_c.fitTo(data_T_c, RooFit::Range(-45, 45));
300 RooPlot* xframe_T_c = T_c.frame(RooFit::Title(
"Caltime"));
301 data_T_c.plotOn(xframe_T_c, RooFit::MarkerStyle(7));
302 gaussm_T_c.plotOn(xframe_T_c, RooFit::Name(
"Caltime"), RooFit::LineColor(2));
303 gaussm_T_c.plotOn(xframe_T_c, RooFit::Components(
"gauss1_T_c"), RooFit::LineColor(kGreen));
304 gaussm_T_c.plotOn(xframe_T_c, RooFit::Components(
"gauss2_T_c"), RooFit::LineColor(kMagenta));
306 xframe_T_c->GetXaxis()->SetTitle(
"Caltime[ns]");
307 xframe_T_c->GetYaxis()->SetTitle(
"Entries");
309 double v_m_T_c = mean_T_c.getVal();
310 double e_m_T_c = mean_T_c.getError();
312 double v1_s1_T_c = sigma1_T_c.getVal();
314 double v2_s1_T_c = sigma2_T_c.getVal();
317 double frac_T_c = frac_core_T_c.getVal();
318 double v_s1_T_c = v1_s1_T_c * (frac_T_c) + v2_s1_T_c * (1 - frac_T_c);
323 const int cluster_size =
cluster.size();
324 for (
int ii = 0; ii < cluster_size; ii++) {
328 RooRealVar x(
"x",
"esum", 0, 4000);
329 RooDataHist dh(
"dh",
"ecltrg", x,
h_clusterE);
331 RooRealVar mean(
"mean",
"mean", 2000, 1000, 2500);
332 RooRealVar sigma(
"sigma",
"sigma", 150, 0, 300);
333 RooRealVar tail(
"tail",
"tail", 0.45, 0, 1);
334 RooNovosibirsk novo(
"novo",
"", x, mean, sigma, tail);
335 novo.fitTo(dh, RooFit::Extended(0), RooFit::Range(1500, 2200));
338 double clusterE_vm, clusterE_em, clusterE_vs;
340 clusterE_vm = mean.getVal();
341 clusterE_em = mean.getError();
342 clusterE_vs = sigma.getVal();
346 TFile file(outputfile,
"RECREATE");
347 TTree* tree =
new TTree(
"tree",
"tree");
368 tree->Branch(
"m_nRun", &
m_nRun,
"m_nRun/I");
369 tree->Branch(
"m_nevent", &nevent,
"m_nevent/I");
370 tree->Branch(
"m_FWD", &FWD,
"m_FWD/D");
371 tree->Branch(
"m_BAR", &BAR,
"m_BAR/D");
372 tree->Branch(
"m_BWD", &BWD,
"m_BWD/D");
373 tree->Branch(
"m_ALL", &ALL,
"m_ALL/D");
374 tree->Branch(
"m_etot_mean", &
m_etot_mean,
"m_etot_mean/D");
375 tree->Branch(
"m_etot_error", &
m_etot_error,
"m_etot_error/D");
376 tree->Branch(
"m_etot_sigma", &
m_etot_sigma,
"m_etot_sigma/D");
377 tree->Branch(
"m_caltime_mean", &
m_caltime_mean,
"m_caltime_mean/D");
378 tree->Branch(
"m_caltime_error", &
m_caltime_error,
"m_caltime_error/D");
379 tree->Branch(
"m_caltime_sigma", &
m_caltime_sigma,
"m_caltime_sigma/D");
380 tree->Branch(
"m_clusterE_mean", &clusterE_vm,
"m_clusterE_mean/D");
381 tree->Branch(
"m_clusterE_error", &clusterE_em,
"m_clusterE_error/D");
382 tree->Branch(
"m_clusterE_sigma", &clusterE_vs,
"m_clusterE_sigma/D");
390 B2INFO(
"ECL Trigger QAM result "
392 <<
LogVar(
"Total Event", nevent)
393 <<
LogVar(
"The # of Low Hit TC in Forward Endcap", FWD)
394 <<
LogVar(
"The # of Low Hit TC in Barrel", BAR)
395 <<
LogVar(
"The # of Low Hit TC in Backward Endcap", BWD)
400 <<
LogVar(
"Cluster Energy Peak", clusterE_vm)
401 <<
LogVar(
"Cluster Energy Peak width", clusterE_vs));
404 B2DEBUG(100,
"TRGECLQAMModule ... endRun called ");
412 B2DEBUG(100,
"TRGECLQAMModule ... terminate called ");
void setDescription(const std::string &description)
Sets the description of the module.
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Type-safe access to single objects in the data store.
TH1F * h_caltime
Caltime Histogram.
double m_ALL
Total proble TC.
double m_etot_sigma
Total Energy sigma.
StoreArray< TRGECLUnpackerEvtStore > m_TRGECLUnpackerEvtStore
ECL Trigger Unpacker Event output.
std::vector< int > caltime
Caltime check.
double m_BAR
Barrel problem TC.
double m_BWD
BWD problem TC.
TH1F * h_clusterE
Cluster Energy Histogram.
std::string m_outputfile
Output Root File Name.
double m_etot_mean
Total Energy mean.
std::vector< int > etot
tcenergy check
double m_caltime_mean
Caltime mean.
TH1F * h_etot
Total Energy Histogram.
StoreArray< TRGECLUnpackerStore > m_TRGECLUnpackerStore
ECL Trigger Unpacker TC output.
std::vector< int > cluster
Cluster Energy Vector.
double m_etot_error
Total Energy error.
double m_caltime_error
Caltime error.
int m_nevent
The # of Events.
Double_t m_FWD
FWD problem TC.
StoreObjPtr< TRGSummary > m_TRGSummary
Trigger Summary.
int clusterE
Cluster Energy.
double m_caltime_sigma
Caltime sigma.
int get3DBhabhaS() const
The method to get 3D Bhabha selection bit.
const int * getCLEnergy() const
The mothod to get Cluster energy.
int getTCCALTime() const
The method to get cal timing.
int getTCEnergy() const
The method to get deposited energy.
int getTCId() const
The method to get cell id.
Class to store variables with their name which were sent to the logging service.
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
virtual ~TRGECLQAMModule()
Destrunctor.
virtual void initialize() override
initialize
virtual void event() override
Event.
virtual void endRun() override
End Run.
virtual void terminate() override
terminate
TRGECLQAMModule()
Costructor.
virtual void beginRun() override
begin Run
std::string version() const
version
Abstract base class for different kinds of events.