File indexing completed on 2024-04-06 12:29:21
0001 #include "CalibCalorimetry/CastorCalib/interface/CastorDbHardcode.h"
0002 #include "CalibFormats/CastorObjects/interface/CastorDbService.h"
0003 #include "DataFormats/HcalDetId/interface/HcalCastorDetId.h"
0004 #include "DataFormats/HcalDigi/interface/CastorDataFrame.h"
0005 #include "SimCalorimetry/CaloSimAlgos/interface/CaloHitResponse.h"
0006 #include "SimCalorimetry/CaloSimAlgos/interface/CaloShapeIntegrator.h"
0007 #include "SimCalorimetry/CaloSimAlgos/interface/CaloTDigitizer.h"
0008 #include "SimCalorimetry/CastorSim/interface/CastorElectronicsSim.h"
0009 #include "SimCalorimetry/CastorSim/interface/CastorShape.h"
0010 #include "SimCalorimetry/CastorSim/interface/CastorSimParameterMap.h"
0011 #include "SimDataFormats/CaloHit/interface/PCaloHit.h"
0012
0013 #include "CLHEP/Random/JamesRandom.h"
0014 #include "CondFormats/CastorObjects/interface/CastorGainWidths.h"
0015 #include "CondFormats/CastorObjects/interface/CastorGains.h"
0016 #include "CondFormats/CastorObjects/interface/CastorPedestalWidths.h"
0017 #include "CondFormats/CastorObjects/interface/CastorPedestals.h"
0018 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
0019 #include "Geometry/ForwardGeometry/interface/CastorHardcodeGeometryLoader.h"
0020 #include "Geometry/HcalTowerAlgo/interface/HcalHardcodeGeometryLoader.h"
0021 #include "SimCalorimetry/CastorSim/interface/CastorAmplifier.h"
0022 #include "SimCalorimetry/CastorSim/interface/CastorCoderFactory.h"
0023 #include "SimCalorimetry/CastorSim/interface/CastorDigitizerTraits.h"
0024 #include "SimCalorimetry/CastorSim/interface/CastorHitCorrection.h"
0025 #include "SimCalorimetry/CastorSim/interface/CastorHitFilter.h"
0026 #include <iostream>
0027 #include <iterator>
0028 #include <vector>
0029 using namespace std;
0030 using namespace cms;
0031
0032 void testHitCorrection(CastorHitCorrection *correction, std::vector<PCaloHit> &hits) {
0033 correction->fillChargeSums(hits);
0034 for (PCaloHit &hit : hits) {
0035 DetId detId(hit.id());
0036 if (detId.det() == DetId::Calo && detId.subdetId() == HcalCastorDetId::SubdetectorId) {
0037 std::cout << "Castor -- ";
0038 }
0039 std::cout << "HIT charge " << correction->charge(hit)
0040 << " delay "
0041
0042 << " Timebin " << correction->timeBin(hit) << std::endl;
0043 }
0044 }
0045
0046 int main() {
0047
0048
0049
0050 HcalCastorDetId castorDetId(HcalCastorDetId::Section(2), true, 1, 1);
0051 PCaloHit castorHit(castorDetId.rawId(), 50.0, 0.123);
0052
0053
0054
0055 std::cout << castorDetId << std::endl;
0056 std::cout << castorHit << std::endl;
0057
0058 vector<DetId> hcastorDetIds;
0059 hcastorDetIds.push_back(castorDetId);
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085 vector<DetId> allDetIds;
0086 allDetIds.insert(allDetIds.end(), hcastorDetIds.begin(), hcastorDetIds.end());
0087 vector<PCaloHit> hits;
0088 hits.push_back(castorHit);
0089
0090 string hitsName = "CastorHits";
0091 vector<string> caloDets;
0092
0093 CrossingFrame<PCaloHit> crossingFrame(-5, 5, 25, hitsName, 0);
0094 edm::EventID eventId;
0095 crossingFrame.addSignals(&hits, eventId);
0096
0097
0098 PCaloHit castorPileup(castorDetId.rawId(), 3.52, 0.);
0099
0100 vector<PCaloHit> pileups;
0101 pileups.push_back(castorPileup);
0102 CastorSimParameterMap parameterMap;
0103 CastorShape castorShape;
0104
0105 CaloShapeIntegrator castorShapeIntegrator(&castorShape);
0106
0107 CaloHitResponse castorResponse(¶meterMap, &castorShapeIntegrator);
0108
0109 CastorHitCorrection hitCorrection(¶meterMap);
0110 castorResponse.setHitCorrection(&hitCorrection);
0111
0112 CLHEP::HepJamesRandom randomEngine;
0113
0114 CastorHitFilter castorHitFilter;
0115
0116 castorResponse.setHitFilter(&castorHitFilter);
0117
0118 CastorPedestals pedestals;
0119 CastorPedestalWidths pedestalWidths;
0120 CastorGains gains;
0121 CastorGainWidths gainWidths;
0122
0123
0124 for (vector<DetId>::const_iterator detItr = allDetIds.begin(); detItr != allDetIds.end(); ++detItr) {
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134 pedestals.addValues(CastorDbHardcode::makePedestal(*detItr));
0135 pedestalWidths.addValues(CastorDbHardcode::makePedestalWidth(*detItr));
0136 gains.addValues(CastorDbHardcode::makeGain(*detItr));
0137 gainWidths.addValues(CastorDbHardcode::makeGainWidth(*detItr));
0138 }
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157 CastorDbService calibratorHandle;
0158
0159
0160 calibratorHandle.setData(&pedestals);
0161 calibratorHandle.setData(&pedestalWidths);
0162 calibratorHandle.setData(&gains);
0163 calibratorHandle.setData(&gainWidths);
0164 calibratorHandle.buildCalibrations();
0165 calibratorHandle.buildCalibWidths();
0166 cout << "set data" << std::endl;
0167 bool addNoise = false;
0168
0169 CastorAmplifier amplifier(¶meterMap, addNoise);
0170 CastorCoderFactory coderFactory(CastorCoderFactory::NOMINAL);
0171 CastorElectronicsSim electronicsSim(&lifier, &coderFactory);
0172 amplifier.setDbService(&calibratorHandle);
0173 parameterMap.setDbService(&calibratorHandle);
0174
0175 CaloTDigitizer<CastorDigitizerTraits> castorDigitizer(&castorResponse, &electronicsSim, addNoise);
0176
0177 castorDigitizer.setDetIds(hcastorDetIds);
0178 cout << "setDetIds" << std::endl;
0179 unique_ptr<CastorDigiCollection> castorResult(new CastorDigiCollection);
0180 cout << "castorResult" << std::endl;
0181 cout << "test hit correction" << std::endl;
0182
0183 testHitCorrection(&hitCorrection, hits);
0184 castorDigitizer.add(hits, 0, &randomEngine);
0185
0186
0187
0188
0189 cout << "castordigitizer.run" << std::endl;
0190 castorDigitizer.run(*castorResult, &randomEngine);
0191
0192 cout << "Castor Frames" << std::endl;
0193 copy(castorResult->begin(), castorResult->end(), std::ostream_iterator<CastorDataFrame>(std::cout, "\n"));
0194
0195 return 0;
0196 }