10#include <ecl/modules/eclGammaGammaECollector/eclGammaGammaECollectorModule.h>
13#include <ecl/dataobjects/ECLDigit.h>
14#include <ecl/dataobjects/ECLElementNumbers.h>
15#include <ecl/dbobjects/ECLCrystalCalib.h>
18#include <analysis/ClusterUtility/ClusterUtils.h>
19#include <analysis/utility/PCmsLabTransform.h>
20#include <framework/dataobjects/EventMetaData.h>
21#include <framework/gearbox/Const.h>
22#include <framework/geometry/VectorUtil.h>
23#include <mdst/dataobjects/ECLCluster.h>
24#include <mdst/dataobjects/HitPatternCDC.h>
25#include <mdst/dataobjects/Track.h>
26#include <mdst/dataobjects/TrackFitResult.h>
27#include <mdst/dataobjects/TRGSummary.h>
30#include <Math/Vector3D.h>
31#include <Math/Vector4D.h>
50 m_ECLExpGammaGammaE(
"ECLExpGammaGammaE"),
51 m_ElectronicsCalib(
"ECLCrystalElectronics"), m_GammaGammaECalib(
"ECLCrystalEnergyGammaGamma")
54 setDescription(
"Calibration Collector Module for ECL single crystal energy calibration using gamma gamma events");
58 addParam(
"minPairMass",
m_minPairMass,
"minimum invariant mass of the pair of photons (GeV/c^2)", 9.);
81 registerObject<TH2F>(
"EnVsCrysID", EnVsCrysID);
83 auto ExpEvsCrys =
new TH1F(
"ExpEvsCrys",
"Sum expected energy vs crystal ID;crystal ID;Energy (GeV)",
85 registerObject<TH1F>(
"ExpEvsCrys", ExpEvsCrys);
87 auto ElecCalibvsCrys =
new TH1F(
"ElecCalibvsCrys",
"Sum electronics calib const vs crystal ID;crystal ID;calibration constant",
89 registerObject<TH1F>(
"ElecCalibvsCrys", ElecCalibvsCrys);
91 auto InitialCalibvsCrys =
new TH1F(
"InitialCalibvsCrys",
94 registerObject<TH1F>(
"InitialCalibvsCrys", InitialCalibvsCrys);
96 auto CalibEntriesvsCrys =
new TH1F(
"CalibEntriesvsCrys",
"Entries in calib vs crys histograms;crystal ID;Entries per crystal",
99 registerObject<TH1F>(
"CalibEntriesvsCrys", CalibEntriesvsCrys);
102 auto RawDigitAmpvsCrys =
new TH2F(
"RawDigitAmpvsCrys",
"Digit Amplitude vs crystal ID;crystal ID;Amplitude",
105 registerObject<TH2F>(
"RawDigitAmpvsCrys", RawDigitAmpvsCrys);
110 registerObject<TH2F>(
"RawDigitTimevsCrys", RawDigitTimevsCrys);
112 auto TimeMinusAverage =
new TH1F(
"TimeMinusAverage",
"Photon time - average / dt99;(T-T_ave)/dt99 ", 100, -10, 10);
113 registerObject<TH1F>(
"TimeMinusAverage", TimeMinusAverage);
118 B2INFO(
"Input parameters to eclGammaGammaECollector:");
140 for (
int ic = 1; ic < 9000; ic += 1000) {
141 B2INFO(
"DB constants for cellID=" << ic <<
": ExpGammaGammaE = " <<
ExpGammaGammaE[ic - 1] <<
" ElectronicsCalib = " <<
149 if (
ExpGammaGammaE[crysID] == 0) {B2FATAL(
"eclGammaGammaECollector: ExpGammaGammaE = 0 for crysID = " << crysID);}
150 if (
GammaGammaECalib[crysID] == 0) {B2FATAL(
"eclGammaGammaECollector: GammaGammaECalib = 0 for crysID = " << crysID);}
170 getObjectPtr<TH1F>(
"ExpEvsCrys")->Fill(crysID + 0.001,
ExpGammaGammaE[crysID]);
171 getObjectPtr<TH1F>(
"ElecCalibvsCrys")->Fill(crysID + 0.001,
ElectronicsCalib[crysID]);
172 getObjectPtr<TH1F>(
"InitialCalibvsCrys")->Fill(crysID + 0.001,
GammaGammaECalib[crysID]);
173 getObjectPtr<TH1F>(
"CalibEntriesvsCrys")->Fill(crysID + 0.001);
180 bool newConst =
false;
188 B2INFO(
"ECLCrystalElectronics has changed, exp = " <<
m_evtMetaData->getExperiment() <<
" run = " <<
m_evtMetaData->getRun());
193 B2INFO(
"ECLCrystalEnergyGammaGamma has changed, exp = " <<
m_evtMetaData->getExperiment() <<
" run = " <<
m_evtMetaData->getRun());
198 for (
int ic = 1; ic < 9000; ic += 1000) {
199 B2INFO(
"DB constants for cellID=" << ic <<
": ExpGammaGammaE = " <<
ExpGammaGammaE[ic - 1] <<
" ElectronicsCalib = " <<
207 if (
ExpGammaGammaE[crysID] == 0) {B2FATAL(
"eclGammaGammaECollector: ExpGammaGammaE = 0 for crysID = " << crysID);}
208 if (
GammaGammaECalib[crysID] == 0) {B2FATAL(
"eclGammaGammaECollector: GammaGammaECalib = 0 for crysID = " << crysID);}
215 unsigned int L1TriggerResults =
m_TRGResults->getTRGSummary(0);
216 if (L1TriggerResults == 0) {
return;}
226 double z0 = temptrackFit->
getZ0();
227 double d0 = temptrackFit->
getD0();
228 double pValue = temptrackFit->
getPValue();
233 if (nGoodTrk > 0) {
return;}
238 int icMax[2] = { -1, -1};
239 double maxClustE[2] = { -1., -1.};
241 for (
int ic = 0; ic < nclust; ic++) {
244 if (eClust > maxClustE[0]) {
245 maxClustE[1] = maxClustE[0];
247 maxClustE[0] = eClust;
249 }
else if (eClust > maxClustE[1]) {
250 maxClustE[1] = eClust;
259 if (icMax[0] == -1 || icMax[1] == -1) {
return;}
262 if (theta0 < thetaLabMin || theta0 >
thetaLabMax || theta1 < thetaLabMin || theta1 >
thetaLabMax) {
return;}
269 double taverage = (t0 / (t990 * t990) + t1 / (t991 * t991)) / (1. / (t990 * t990) + 1. / (t991 * t991));
270 if (abs(t0 - taverage) > t990 *
m_maxTime || abs(t1 - taverage) > t991 *
m_maxTime) {
return;}
274 const ROOT::Math::XYZVector clustervertex = cUtil.
GetIPPosition();
277 ROOT::Math::XYZVector p30;
278 VectorUtil::setMagThetaPhi(p30, maxClustE[0], theta0, phi0);
282 ROOT::Math::XYZVector p31;
283 VectorUtil::setMagThetaPhi(p31, maxClustE[1], theta1, phi1);
286 double pairmass = (p40 + p41).M();
291 ROOT::Math::PxPyPzEVector p40COM = boostrotate.
rotateLabToCms() * p40;
292 ROOT::Math::PxPyPzEVector p41COM = boostrotate.
rotateLabToCms() * p41;
293 double dphi = abs(p41COM.Phi() - p40COM.Phi()) * TMath::RadToDeg();
294 if (dphi > 180.) {dphi = 360. - dphi;}
299 int crysIDMax[2] = { -1, -1};
300 for (
int ic = 0; ic < 2; ic++) {
309 int crysID = eclDigit.getCellId() - 1;
310 getObjectPtr<TH2F>(
"RawDigitAmpvsCrys")->Fill(crysID + 0.001, eclDigit.getAmp());
315 getObjectPtr<TH2F>(
"RawDigitTimevsCrys")->Fill(crysID + 0.001, eclDigit.getTimeFit());
323 for (
int ic = 0; ic < 2; ic++) {
333 for (
int ic = 0; ic < 2; ic++) {
334 if (crysIDMax[ic] >= 0) {
336 getObjectPtr<TH2F>(
"EnVsCrysID")->Fill(crysIDMax[ic] + 0.001,
338 getObjectPtr<TH1F>(
"ExpEvsCrys")->Fill(crysIDMax[ic] + 0.001,
ExpGammaGammaE[crysIDMax[ic]]);
339 getObjectPtr<TH1F>(
"ElecCalibvsCrys")->Fill(crysIDMax[ic] + 0.001,
ElectronicsCalib[crysIDMax[ic]]);
340 getObjectPtr<TH1F>(
"InitialCalibvsCrys")->Fill(crysIDMax[ic] + 0.001,
GammaGammaECalib[crysIDMax[ic]]);
341 getObjectPtr<TH1F>(
"CalibEntriesvsCrys")->Fill(crysIDMax[ic] + 0.001);
344 if (crysIDMax[0] >= 0 && crysIDMax[1] >= 0) {
345 getObjectPtr<TH1F>(
"TimeMinusAverage")->Fill((t0 - taverage) / t990);
346 getObjectPtr<TH1F>(
"TimeMinusAverage")->Fill((t1 - taverage) / t991);
Calibration collector module base class.
Class to provide momentum-related information from ECLClusters.
const ROOT::Math::PxPyPzEVector Get4MomentumFromCluster(const ECLCluster *cluster, ECLCluster::EHypothesisBit hypo)
Returns four momentum vector.
const ROOT::Math::XYZVector GetIPPosition()
Returns default IP position from beam parameters.
Provides a type-safe way to pass members of the chargedStableSet set.
EHypothesisBit
The hypothesis bits for this ECLCluster (Connected region (CR) is split using this hypothesis.
@ c_nPhotons
CR is split into n photons (N1)
unsigned short getNHits() const
Get the total Number of CDC hits in the fit.
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...
Values of the result of a track fit with a given particle hypothesis.
double getPValue() const
Getter for Chi2 Probability of the track fit.
double getD0() const
Getter for d0.
double getTransverseMomentum() const
Getter for the absolute value of the transverse momentum at the perigee.
double getZ0() const
Getter for z0.
HitPatternCDC getHitPatternCDC() const
Getter for the hit pattern in the CDC;.
DBObjPtr< ECLCrystalCalib > m_ECLExpGammaGammaE
Expected energies from database.
double maxD0
(cm) maximum abs(D0) of a good track
double minTrkpt
(GeV/c) minimum pt of a good track
StoreArray< ECLDigit > m_eclDigitArray
Required input array of ECLDigits.
DBObjPtr< ECLCrystalCalib > m_GammaGammaECalib
Existing single crystal calibration from DB; will be updated by CAF.
bool m_requireL1
require events to satisfy a level 1 trigger (true)
double m_maxTime
maximum photon (time - <t>)/dt99 (1)
double m_mindPhi
minimum delta phi between clusters (179 deg)
StoreArray< ECLCluster > m_eclClusterArray
Required input array of ECLClusters.
StoreObjPtr< TRGSummary > m_TRGResults
dataStore TRGSummary
std::vector< float > ExpGammaGammaE
vector obtained from DB object
double thetaLabMin
Some other useful quantities.
bool storeCalib
force the input calibration constants to be saved first event
std::vector< float > EperCrys
ECL digit energy for each crystal.
void collect() override
Select events and crystals and accumulate histograms.
double m_minPairMass
minimum invariant mass of the pair of photons (9 GeV/c^2)
StoreObjPtr< EventMetaData > m_evtMetaData
dataStore EventMetaData
std::vector< float > ElectronicsCalib
vector obtained from DB object
eclGammaGammaECollectorModule()
Constructor: Sets the description, the properties and the parameters of the module.
int minCDChits
minimum CDC hits for a good track
double minpValue
minimum p value of a good track
void prepare() override
Define histograms and read payloads from DB.
double maxZ0
(cm) maximum abs(Z0) of a good track
double thetaLabMax
m_thetaLabMaxDeg converted to radians (coneversion in Module::init)
double m_thetaLabMaxDeg
maximum photon theta in lab (180 degrees)
double m_thetaLabMinDeg
Parameters to control the job.
DBObjPtr< ECLCrystalCalib > m_ElectronicsCalib
Electronics calibration from database.
bool m_measureTrueEnergy
use eclCalDigit to determine MC deposited energy (false)
std::vector< float > GammaGammaECalib
vector obtained from DB object
double m_expectedEnergyScale
scale expected energies for non-4S calibration (1.)
StoreArray< Track > m_trackArray
Required arrays.
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.
const int c_NCrystals
Number of crystals.
Abstract base class for different kinds of events.