Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-23 03:25:36

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 //#include "CalibFormats/HcalObjects/interface/HcalDbService.h"
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               //<< correction->delay(*hitItr)
0042               << " Timebin " << correction->timeBin(hit) << std::endl;
0043   }
0044 }
0045 
0046 int main() {
0047   // make a silly little hit in each subdetector, which should
0048   // correspond to a 100 GeV particle
0049 
0050   HcalCastorDetId castorDetId(HcalCastorDetId::Section(2), true, 1, 1);
0051   PCaloHit castorHit(castorDetId.rawId(), 50.0, 0.123);
0052 
0053   // assert(castorDetId.zside() == true);
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     DEBUG
0063   HcalGenericDetId genericId(castorDetId);
0064 
0065   std::cout<<"generic Id "<< genericId <<std::endl;
0066   std::cout<< genericId.det() <<" "<< genericId.subdetId() <<std::endl;
0067 
0068   std::cout<<"castor id "<< castorDetId <<std::endl;
0069   std::cout<< castorDetId.det() <<" "<< castorDetId.subdetId() <<std::endl;
0070 
0071   std::cout<<"should be: "<< DetId::Calo <<" "<< HcalCastorDetId::SubdetectorId
0072   <<std::endl;
0073   */
0074   /*
0075     DEBUG
0076   vector<HcalCastorDetId> hcastorDetIds;
0077   hcastorDetIds.push_back(castorDetId);
0078 
0079   vector<HcalCastorDetId>::iterator testDetId = hcastorDetIds.begin();
0080   std::cout<< (*testDetId).zside() <<" "
0081            << (*testDetId).sector() <<" "
0082            << (*testDetId).module() <<std::endl;
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   // make 1 GeV pileup hit
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(&parameterMap, &castorShapeIntegrator);
0108 
0109   CastorHitCorrection hitCorrection(&parameterMap);
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   // make a calibration service by hand
0124   for (vector<DetId>::const_iterator detItr = allDetIds.begin(); detItr != allDetIds.end(); ++detItr) {
0125     /* check CastorCondObjectContainer!
0126           pedestals.addValues(*detItr,
0127        CastorDbHardcode::makePedestal(*detItr).getValues ());
0128           *pedestalWidths.setWidth(*detItr) =
0129        CastorDbHardcode::makePedestalWidth(*detItr); gains.addValues(*detItr,
0130        CastorDbHardcode::makeGain(*detItr).getValues ());
0131           gainWidths.addValues(*detItr,
0132        CastorDbHardcode::makeGainWidth(*detItr).getValues ());
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   /* obsolete stuff
0141 
0142     pedestals.sort();
0143     pedestalWidths.sort();
0144     gains.sort();
0145     gainWidths.sort();
0146 
0147 
0148   //  std::cout << "TEST Pedestal " << pedestals.getValue(barrelDetId,  1) <<
0149   std::endl; std::cout << "Castor pedestals " << pedestals.getValue(castorDetId,
0150   1) << std::endl; std::cout << "Castor pedestal widths " <<
0151   pedestalWidths.getWidth(castorDetId,  1) << std::endl; std::cout << "Castor
0152   gains " << gains.getValue(castorDetId,  1) << std::endl; std::cout << "Castor
0153   gain widths " << gainWidths.getValue(castorDetId,  1) << std::endl;
0154 
0155   */
0156 
0157   CastorDbService calibratorHandle;
0158 
0159   //  CastorDbService calibratorHandle;
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(&parameterMap, addNoise);
0170   CastorCoderFactory coderFactory(CastorCoderFactory::NOMINAL);
0171   CastorElectronicsSim electronicsSim(&amplifier, &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   // something breaks here!
0183   testHitCorrection(&hitCorrection, hits);
0184   castorDigitizer.add(hits, 0, &randomEngine);
0185   // TODO Add pileups
0186   // testHitCorrection(&hitCorrection, pileups);
0187   // castorDigitizer.add(pileups, -3);
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 }