@@ -31,7 +31,8 @@ void Digitizer::init()
3131 mCalibParams .reset (new CalibParams (1 )); // test default calibration
3232 LOG (INFO) << " [CPVDigitizer] No reading calibration from ccdb requested, set default" ;
3333 } else {
34- LOG (INFO) << " [CPVDigitizer] can not gey calibration object from ccdb yet" ;
34+ LOG (INFO) << " [CPVDigitizer] can not get calibration object from ccdb yet. Using default" ;
35+ mCalibParams .reset (new CalibParams (1 )); // test default calibration
3536 // o2::ccdb::CcdbApi ccdb;
3637 // std::map<std::string, std::string> metadata; // do we want to store any meta data?
3738 // ccdb.init("http://ccdb-test.cern.ch:8080"); // or http://localhost:8080 for a local installation
@@ -41,6 +42,45 @@ void Digitizer::init()
4142 // }
4243 }
4344 }
45+ if (!mPedestals ) {
46+ if (o2::cpv::CPVSimParams::Instance ().mCCDBPath .compare (" localtest" ) == 0 ) {
47+ mPedestals .reset (new Pedestals (1 )); // test default calibration
48+ LOG (INFO) << " [CPVDigitizer] No reading calibration from ccdb requested, set default" ;
49+ } else {
50+ LOG (INFO) << " [CPVDigitizer] can not get pedestal object from ccdb yet. Using default" ;
51+ mPedestals .reset (new Pedestals (1 )); // test default calibration
52+ // o2::ccdb::CcdbApi ccdb;
53+ // std::map<std::string, std::string> metadata; // do we want to store any meta data?
54+ // ccdb.init("http://ccdb-test.cern.ch:8080"); // or http://localhost:8080 for a local installation
55+ // mPedestals = ccdb.retrieveFromTFileAny<o2::cpv::Pedestals>("CPV/Calib", metadata, mEventTime);
56+ // if (!mPedestals) {
57+ // LOG(FATAL) << "[CPVDigitizer] can not get calibration object from ccdb";
58+ // }
59+ }
60+ }
61+ if (!mBadMap ) {
62+ if (o2::cpv::CPVSimParams::Instance ().mCCDBPath .compare (" localtest" ) == 0 ) {
63+ mBadMap .reset (new BadChannelMap (1 )); // test default calibration
64+ LOG (INFO) << " [CPVDigitizer] No reading calibration from ccdb requested, set default" ;
65+ } else {
66+ LOG (INFO) << " [CPVDigitizer] can not get bad channel map object from ccdb yet. Using default" ;
67+ mBadMap .reset (new BadChannelMap (1 )); // test default calibration
68+ // o2::ccdb::CcdbApi ccdb;
69+ // std::map<std::string, std::string> metadata; // do we want to store any meta data?
70+ // ccdb.init("http://ccdb-test.cern.ch:8080"); // or http://localhost:8080 for a local installation
71+ // mBadMap = ccdb.retrieveFromTFileAny<o2::cpv::BadChannelMap>("CPV/Calib", metadata, mEventTime);
72+ // if (!mBadMap) {
73+ // LOG(FATAL) << "[CPVDigitizer] can not get calibration object from ccdb";
74+ // }
75+ }
76+ }
77+
78+ // signal thresolds for digits
79+ // note that digits are calibrated objects
80+ for (int i = 0 ; i < NCHANNELS; i++) {
81+ mDigitThresholds [i] = o2::cpv::CPVSimParams::Instance ().mZSnSigmas *
82+ mPedestals ->getPedSigma (i) * mCalibParams ->getGain (i);
83+ }
4484}
4585
4686// _______________________________________________________________________
@@ -60,14 +100,11 @@ void Digitizer::processHits(const std::vector<Hit>* hits, const std::vector<Digi
60100 mArrayD [i].reset ();
61101 }
62102
63- if (digitsBg.size () == 0 ) { // no digits provided: try simulate noise
103+ if (digitsBg.size () == 0 ) { // no digits provided: try simulate pedestal noise (do it only once)
64104 for (int i = NCHANNELS; i--;) {
65- float energy = simulateNoise ();
66- energy = uncalibrate (energy, i);
67- if (energy > o2::cpv::CPVSimParams::Instance ().mZSthreshold ) {
68- mArrayD [i].setAmplitude (energy);
69- mArrayD [i].setAbsId (i);
70- }
105+ float amplitude = simulatePedestalNoise (i);
106+ mArrayD [i].setAmplitude (amplitude);
107+ mArrayD [i].setAbsId (i);
71108 }
72109 } else { // if digits exist, no noise should be added
73110 for (auto & dBg : digitsBg) { // digits are sorted and unique
@@ -79,12 +116,12 @@ void Digitizer::processHits(const std::vector<Hit>* hits, const std::vector<Digi
79116 for (auto & h : *hits) {
80117 int i = h.GetDetectorID ();
81118 if (mArrayD [i].getAmplitude () > 0 ) {
82- mArrayD [i].setAmplitude (mArrayD [i].getAmplitude () + uncalibrate ( h.GetEnergyLoss (), i ));
119+ mArrayD [i].setAmplitude (mArrayD [i].getAmplitude () + h.GetEnergyLoss ());
83120 } else {
84- mArrayD [i].setAmplitude (uncalibrate ( h.GetEnergyLoss (), i ));
121+ mArrayD [i].setAmplitude (h.GetEnergyLoss ());
85122 mArrayD [i].setAbsId (i);
86123 }
87- if (mArrayD [i].getAmplitude () > o2::cpv::CPVSimParams::Instance (). mZSthreshold ) {
124+ if (mArrayD [i].getAmplitude () > mDigitThresholds [i] ) {
88125 int labelIndex = mArrayD [i].getLabel ();
89126 if (labelIndex == -1 ) { // no digit or noisy
90127 labelIndex = labels.getIndexedSize ();
@@ -109,23 +146,22 @@ void Digitizer::processHits(const std::vector<Hit>* hits, const std::vector<Digi
109146 }
110147 }
111148
149+ // finalize output digits
112150 for (int i = 0 ; i < NCHANNELS; i++) {
113- if (mArrayD [i].getAmplitude () > o2::cpv::CPVSimParams::Instance ().mZSthreshold ) {
151+ if (!mBadMap ->isChannelGood (i)) {
152+ continue ; // bad channel -> skip this digit
153+ }
154+ if (mArrayD [i].getAmplitude () > mDigitThresholds [i]) {
114155 digitsOut.push_back (mArrayD [i]);
115156 }
116157 }
117158}
118159
119- float Digitizer::simulateNoise () { return gRandom ->Gaus (0 ., o2::cpv::CPVSimParams::Instance ().mNoise ); }
120-
121- // _______________________________________________________________________
122- float Digitizer::uncalibrate (const float e, const int absId)
160+ float Digitizer::simulatePedestalNoise (int absId)
123161{
124- // Decalibrate CPV digit, i.e. transform from amplitude to ADC counts a factor read from CDB
125- float calib = mCalibParams ->getGain (absId);
126- if (calib > 0 ) {
127- return e / calib;
128- } else {
129- return 0 ; // TODO apply de-calibration from OCDB
162+ // this function is to simulate pedestal and its noise (ADC counts)
163+ if (absId < 0 || absId >= NCHANNELS) {
164+ return 0 .;
130165 }
166+ return gRandom ->Gaus (0 , mPedestals ->getPedSigma (absId) * mCalibParams ->getGain (absId));
131167}
0 commit comments