Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CaloCluster/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ cet_build_plugin(CaloClusterMaker art::module

Offline::CalorimeterGeom
Offline::GeometryService
Offline::ProditionsService
Offline::RecoDataProducts
)

Expand Down
21 changes: 13 additions & 8 deletions CaloCluster/src/CaloClusterMaker_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "Offline/RecoDataProducts/inc/CaloHit.hh"
#include "Offline/RecoDataProducts/inc/CaloCluster.hh"
#include "Offline/RecoDataProducts/inc/CaloProtoCluster.hh"
#include "Offline/ProditionsService/inc/ProditionsHandle.hh"

#include <iostream>
#include <string>
Expand Down Expand Up @@ -66,37 +67,41 @@ namespace mu2e {
private:
art::ProductToken<CaloProtoClusterCollection> mainToken_;
art::ProductToken<CaloProtoClusterCollection> splitToken_;
ProditionsHandle<Calorimeter> alignedCal_h;
double deltaTime_;
double maxDistSplit_;
double maxDistMain_;
int strategy_;
int diagLevel_;

std::vector<double> clusterTimeEnergy(const std::vector<art::Ptr<CaloHit>>& hits);
void makeCaloClusters(CaloClusterCollection&, const CaloProtoClusterCollection&, const CaloProtoClusterCollection&);
void makeCaloClusters(const Calorimeter& cal, CaloClusterCollection&,
const CaloProtoClusterCollection&,
const CaloProtoClusterCollection&);
};


//---------------------------------------------------------------------------------------------------------------
void CaloClusterMaker::produce(art::Event& event)
{
const Calorimeter& alignedCal = alignedCal_h.get(event.id());

const auto& caloClustersMain = *event.getValidHandle(mainToken_);
const auto& caloClustersSplit = *event.getValidHandle(splitToken_);

auto caloClusters = std::make_unique<CaloClusterCollection>();
makeCaloClusters(*caloClusters, caloClustersMain, caloClustersSplit);
makeCaloClusters(alignedCal, *caloClusters, caloClustersMain, caloClustersSplit);

event.put(std::move(caloClusters));
}


//---------------------------------------------------------------------------------------------------------------
void CaloClusterMaker::makeCaloClusters(CaloClusterCollection& caloClusters, const CaloProtoClusterCollection& caloClustersMain,
void CaloClusterMaker::makeCaloClusters(const Calorimeter& cal,
CaloClusterCollection& caloClusters,
const CaloProtoClusterCollection& caloClustersMain,
const CaloProtoClusterCollection& caloClustersSplit)
{
const Calorimeter& cal = *(GeomHandle<Calorimeter>());


ClusterAssociator associator(cal);
associator.associateSplitOff(caloClustersMain, caloClustersSplit, deltaTime_,maxDistSplit_);

Expand All @@ -116,8 +121,8 @@ namespace mu2e {
isSplit = true;

caloHitsPtrVector.insert(caloHitsPtrVector.end(),
caloClustersSplit.at(isplit).caloHitsPtrVector().begin(),
caloClustersSplit.at(isplit).caloHitsPtrVector().end());
caloClustersSplit.at(isplit).caloHitsPtrVector().begin(),
caloClustersSplit.at(isplit).caloHitsPtrVector().end());

if (diagLevel_ > 1) std::cout<<"Associated main cluster "<<imain <<" with split cluster "<<isplit<<std::endl;
}
Expand Down
2 changes: 2 additions & 0 deletions CaloCluster/src/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ mainlib = helper.make_mainlib ( [ 'mu2e_GeometryService',
'mu2e_RecoDataProducts',
'mu2e_CalorimeterGeom',
'mu2e_GlobalConstantsService',
'mu2e_CaloConditions',
'mu2e_DataProducts',
'mu2e_GeneralUtilities',
'art_Persistency_Common',
Expand Down Expand Up @@ -51,6 +52,7 @@ helper.make_plugins( [ mainlib,
'mu2e_CalorimeterGeom',
'mu2e_RecoDataProducts',
'mu2e_DataProducts',
'mu2e_DbTables',
'art_Framework_Core',
'art_Framework_Principal',
'art_Framework_Services_Registry',
Expand Down
7 changes: 3 additions & 4 deletions CaloConditions/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ cet_make_library(
src/CalSimParamsMaker.cc
src/CalDAQMap.cc
src/CalDAQMapMaker.cc
src/AlignedCalorimeterMaker.cc
LIBRARIES PUBLIC

CLHEP::CLHEP
cetlib_except::cetlib_except
Offline::CaloConfig
Offline::CalorimeterGeom
Offline::ConfigTools
Expand All @@ -18,10 +21,6 @@ cet_make_library(
Offline::ProditionsService
)

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/data/nominal.txt ${CURRENT_BINARY_DIR} data/nominal.txt)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/data/caloDMAP_nominal.dat ${CURRENT_BINARY_DIR} data/caloDMAP_nominal.dat)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/data/Sim_crystal.txt ${CURRENT_BINARY_DIR} data/Sim_crystal.txt)

install(DIRECTORY data DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/Offline/CaloConditions)

install_source(SUBDIRS src)
Expand Down
2 changes: 2 additions & 0 deletions CaloConditions/data/disk_align.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
0 0 0 0 0 0 0
1 0 0 0 0 0 0
6 changes: 6 additions & 0 deletions CaloConditions/fcl/prolog.fcl
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,10 @@ CalSimParams : {
useDb : false
}

alignedCalorimeter : {
filenameDisk : "Offline/CaloConditions/data/disk_align.txt"
verbose : 0
useDb : false
}

END_PROLOG
61 changes: 61 additions & 0 deletions CaloConditions/inc/AlignedCalorimeterCache.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#ifndef CaloConditions_AlignedCalorimeterCache_hh
#define CaloConditions_AlignedCalorimeterCache_hh
//
// hold a set of run-dependent conditions objects
// and update them when needed
//
#include "Offline/Mu2eInterfaces/inc/ProditionsCache.hh"
#include "Offline/DbService/inc/DbHandle.hh"
#include "Offline/DbTables/inc/CalAlignElement.hh"
#include "Offline/CaloConditions/inc/AlignedCalorimeterMaker.hh"


namespace mu2e {

class AlignedCalorimeterCache : public ProditionsCache {
public:
AlignedCalorimeterCache(AlignedCalConfig const& config):
ProditionsCache(Calorimeter::cxname,config.verbose()),
_useDb(config.useDb()),_maker(config) {}

void initialize() {
if (_useDb) {
_tadisk_p = std::make_unique<DbHandle<CalAlignDisk>>();
}
}

set_t makeSet(art::EventID const& eid) {
// get the tables up to date
ProditionsEntity::set_t cids;
if (_useDb) {
_tadisk_p->get(eid);
cids.insert(_tadisk_p->cid());
}
return cids;
}

DbIoV makeIov(art::EventID const& eid) {
DbIoV iov;
iov.setMax(); // start with full IOV range
if (_useDb) {
iov.overlap(_tadisk_p->iov());
}
return iov;
}

ProditionsEntity::ptr makeEntity(art::EventID const& eid) {
if(_useDb) {
return _maker.fromDb(_tadisk_p->getPtr(eid));
} else {
return _maker.fromFcl();
}
}


private:
bool _useDb;
AlignedCalorimeterMaker _maker;
std::unique_ptr<DbHandle<CalAlignDisk>> _tadisk_p;
};
}
#endif
33 changes: 33 additions & 0 deletions CaloConditions/inc/AlignedCalorimeterMaker.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#ifndef CaloConditions_AlignedCalorimeterMaker_hh
#define CaloConditions_AlignedCalorimeterMaker_hh
//
// Make AlignedCalorimeter from fcl or (eventually) database
//
#include "Offline/CalorimeterGeom/inc/DiskCalorimeter.hh"
#include "Offline/CaloConfig/inc/AlignedCalConfig.hh"
#include "Offline/DbTables/inc/CalAlignElement.hh"
#include "Offline/DbTables/inc/CalAlignParams.hh"

namespace mu2e {

class AlignedCalorimeterMaker {
typedef std::shared_ptr<DiskCalorimeter> ptr_t;

public:
AlignedCalorimeterMaker(const AlignedCalConfig& config):_config(config) {}
void alignCalorimeter(ptr_t ptr,
const std::vector<CalAlignParams>& disk_align_params);
ptr_t fromFcl();
ptr_t fromDb(CalAlignDisk::cptr_t cad_p);

private:
std::vector<CalAlignParams> readFile(const std::string& fileName, uint16_t nRowMax);
std::vector<CalAlignParams> readDb(CalAlignElement::cptr_t cptr, uint16_t nRowMax);

// this object needs to be thread safe,
// _config should only be initialized once
const AlignedCalConfig _config;
};
}

#endif
158 changes: 158 additions & 0 deletions CaloConditions/src/AlignedCalorimeterMaker.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
#include "cetlib_except/exception.h"
#include "Offline/CaloConditions/inc/AlignedCalorimeterMaker.hh"
#include "Offline/CalorimeterGeom/inc/DiskCalorimeter.hh"
#include "Offline/ConfigTools/inc/ConfigFileLookupPolicy.hh"
#include "Offline/GeometryService/inc/GeomHandle.hh"

#include "CLHEP/Vector/ThreeVector.h"
#include "CLHEP/Vector/Rotation.h"

#include <iostream>
#include <fstream>
#include <sstream>
#include <cmath>


namespace mu2e {

//-----------------------------------------------------------------------------------------
void AlignedCalorimeterMaker::alignCalorimeter(AlignedCalorimeterMaker::ptr_t ptr,
const std::vector<CalAlignParams>& disk_align_params)
{
DiskCalorimeter& cal = *ptr;

for (auto& disk : cal.disks()) {
// Use the const_cast bazooka here - this is the only place where
// Disk parameters should be modified by an external agent
auto& diskcc = const_cast<Disk&>(disk);
const auto& disk_align = disk_align_params.at(diskcc.id());

CLHEP::Hep3Vector shift(disk_align.dx(),disk_align.dy(),disk_align.dz());
CLHEP::HepRotation rotation(CLHEP::HepRotation::IDENTITY);
rotation.rotateX(disk_align.rx());
rotation.rotateY(disk_align.ry());
rotation.rotateZ(disk_align.rz());

diskcc.moveDisk(shift,rotation);
}
}



//-----------------------------------------------------------------------------------------
std::vector<CalAlignParams> AlignedCalorimeterMaker::readFile(const std::string& fileName, uint16_t nRowMax)
{
ConfigFileLookupPolicy configFile;
std::string fullFileName = configFile(fileName);
if (_config.verbose()>0) {
std::cout << "AlignedCalorimeterMaker::fromFcl reading from " << fullFileName << "\n";
}

std::ifstream ordFile;
ordFile.open(fullFileName);
if (!ordFile.is_open()) {
throw cet::exception("ALIGNEDCAL_OPEN_FAILED")
<< " failed to open file " << fullFileName << "\n";
}

std::vector<CalAlignParams> align_params;
uint16_t nRead(0);
std::string line;
while (std::getline(ordFile, line)) {
uint16_t index;
float dx,dy,dz,rx,ry,rz;

std::istringstream iss(line);
if (!(iss >> index >> dx >> dy >> dz >> rx >> ry >> rz)) {
throw cet::exception("ALIGNEDCAL_FORMAT")
<< "invalid format at line "<<nRead+1<<"\n";
}

// Check that there is nothing left on the line
iss >> std::ws;
if (!iss.eof()) {
throw cet::exception("ALIGNEDCAL_FORMAT")
<< "invalid format at line "<<nRead+1<<"\n";
}

if (index >= nRowMax) {
throw cet::exception("ALIGNEDCAL_RANGE") << "AlignedCalorimeterMaker read invalid offlineId "
<< index << "\n";
}
align_params.push_back(CalAlignParams(index,dx,dy,dz,rx,ry,rz));
++nRead;
}

if(nRead != nRowMax) {
throw cet::exception("ALIGNEDCAL_COUNT")
<< "AlignedCalorimeterMaker read the wrong number of id's "
<< nRead << ", expected " << nRowMax << "\n";
}

return align_params;
}



//-----------------------------------------------------------------------------------------
std::vector<CalAlignParams> AlignedCalorimeterMaker::readDb(CalAlignElement::cptr_t cptr, uint16_t nRowMax)
{
std::vector<CalAlignParams> align_params;
uint16_t nRead(0);

for (auto const& row : cptr->rows()) {
auto index = row.index();
auto dx = row.dx();
auto dy = row.dy();
auto dz = row.dz();
auto rx = row.rx();
auto ry = row.ry();
auto rz = row.rz();

if (index >= nRowMax) {
throw cet::exception("AlignedCalorimeterMAKER_RANGE") << "AlignedCalorimeterMaker read invalid offlineId " << index << "\n";
}
align_params.push_back(CalAlignParams(index,dx,dy,dz,rx,ry,rz));
++nRead;
}

if(nRead != nRowMax) {
throw cet::exception("AlignedCalorimeterMAKER_COUNT")
<< "AlignedCalorimeterMaker read the wrong number of id's "
<< nRead << ", expected " << nRowMax << "\n";
}
return align_params;
}


//-----------------------------------------------------------------------------------------
AlignedCalorimeterMaker::ptr_t AlignedCalorimeterMaker::fromFcl()
{
//Deep copy of the calorimeter to keep the original untouched
GeomHandle<DiskCalorimeter> cal_h;
auto ptr = std::make_shared<DiskCalorimeter>(*cal_h);

if ( _config.verbose() > 0 )
std::cout << "AlignedCalorimeterMaker::fromFcl now zero aligning Calorimeter\n";

auto disk_align_params = readFile(_config.filenameDisk(), CaloConst::_nDisk);
alignCalorimeter(ptr, disk_align_params);

return ptr;
}

//-----------------------------------------------------------------------------------------
AlignedCalorimeterMaker::ptr_t AlignedCalorimeterMaker::fromDb(CalAlignDisk::cptr_t cad_p)
{
GeomHandle<DiskCalorimeter> cal_h;
auto ptr = std::make_shared<DiskCalorimeter>(*cal_h);

if ( _config.verbose() > 0 )
std::cout << "AlignedCalorimeterMaker::fromDb now aligning Calorimeter \n";

auto disk_align_params = readDb(cad_p, CaloConst::_nDisk);
alignCalorimeter(ptr, disk_align_params);

return ptr;
}
}
2 changes: 1 addition & 1 deletion CaloConditions/src/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ mainlib = helper.make_mainlib ( [
'fhiclcpp_types',
'cetlib',
'cetlib_except',
#'CLHEP',
'CLHEP',
'MathCore',
'boost_system'
#rootlibs
Expand Down
1 change: 1 addition & 0 deletions CaloConfig/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ cet_make_library(INTERFACE INSTALLED_PATH_BASE Offline
inc/CalCalibConfig.hh
inc/CalDAQMapConfig.hh
inc/CalSimParamsConfig.hh
inc/AlignedCalConfig.hh
LIBRARIES INTERFACE

)
Expand Down
Loading