diff --git a/DDAlign/src/GlobalDetectorAlignment.cpp b/DDAlign/src/GlobalDetectorAlignment.cpp index 73a8293a7..ecff68eb7 100644 --- a/DDAlign/src/GlobalDetectorAlignment.cpp +++ b/DDAlign/src/GlobalDetectorAlignment.cpp @@ -71,22 +71,22 @@ namespace { TGeoMatrix* mm = n->GetNode()->GetMatrix(); bool dbg = GlobalDetectorAlignment::debug(); if ( dbg ) { - printout(dd4hep::INFO,"Alignment","DELTA matrix of %s",n->GetName()); + printout(dd4hep::INFO,"Alignment","DELTA matrix of %s", n->GetName()); transform->Print(); - dd4hep::printout(dd4hep::INFO,"Alignment","OLD matrix of %s",n->GetName()); + dd4hep::printout(dd4hep::INFO,"Alignment","OLD matrix of %s", n->GetName()); mm->Print(); } transform->MultiplyLeft(mm); // orig * delta n->Align(transform, 0, check, overlap); if ( dbg ) { - dd4hep::printout(dd4hep::INFO,"Alignment","NEW matrix of %s",n->GetName()); + dd4hep::printout(dd4hep::INFO,"Alignment","NEW matrix of %s", n->GetName()); n->GetNode()->GetMatrix()->Print(); } /* printout(dd4hep::INFO,"Alignment","Apply new relative matrix mother to daughter:"); transform->Print(); transform->MultiplyLeft(mm); // orig * delta - printout(dd4hep::INFO,"Alignment","With deltas %s ....",n->GetName()); + printout(dd4hep::INFO,"Alignment","With deltas %s ....", n->GetName()); transform->Print(); n->Align(transform, 0, check, overlap); diff --git a/DDG4/plugins/Geant4EventReaderHepMC.cpp b/DDG4/plugins/Geant4EventReaderHepMC.cpp index c9b3e5580..a761ad0a2 100644 --- a/DDG4/plugins/Geant4EventReaderHepMC.cpp +++ b/DDG4/plugins/Geant4EventReaderHepMC.cpp @@ -575,7 +575,7 @@ int HepMC::read_vertex(EventStream &info, std::istream& is, std::istringstream & int HepMC::read_event_header(EventStream &info, std::istringstream & input, EventHeader& header) { // read values into temp variables, then fill GenEvent - int random_states_size = 0; + int size = 0; input >> header.id; if( info.io_type == gen || info.io_type == extascii ) { int nmpi = -1; @@ -592,33 +592,36 @@ int HepMC::read_event_header(EventStream &info, std::istringstream & input, Even if( info.io_type == gen || info.io_type == extascii ) input >> header.bp1 >> header.bp2; - input >> random_states_size; printout(DEBUG,"HepMC","++ Event header: %s",input.str().c_str()); + input >> size; input.clear(); - if( input.fail() ) return 0; - + if( input.fail() ) + return 0; + if( size < 0 || size > USHRT_MAX ) + return 0; - for(int i = 0; i < random_states_size; ++i ) { + for(int i = 0; i < size; ++i ) { long val = 0e0; input >> val; header.random.emplace_back(val); if( input.fail() ) return 0; } - size_t weights_size = 0; - input >> weights_size; - if( input.fail() ) return 0; + input >> size; + if( input.fail() ) + return 0; + if( size < 0 || size > USHRT_MAX ) + return 0; std::vector wgt; - for(size_t ii = 0; ii < weights_size; ++ii ) { + for( int ii = 0; ii < size; ++ii ) { float val = 0e0; input >> val; wgt.emplace_back(val); if( input.fail() ) return 0; } - // weight names will be added later if they exist - if( weights_size > 0 ) header.weights = std::move(wgt); + if( !wgt.empty() ) header.weights = std::move(wgt); return 1; } diff --git a/UtilityApps/src/materialBudget.cpp b/UtilityApps/src/materialBudget.cpp index e514c2ad2..47960495f 100644 --- a/UtilityApps/src/materialBudget.cpp +++ b/UtilityApps/src/materialBudget.cpp @@ -18,19 +18,15 @@ // //========================================================================== -#include - // Framework include files -#include #include #include +#include #include -// #include -// #include -// #include #include #include +#include #include #include @@ -61,8 +57,8 @@ namespace { double theta0 = atan2( r, z ) ; Vector3D v = ( theta > theta0 ? - Vector3D( r , phi , r / tan( theta ) , Vector3D::cylindrical ) : - Vector3D( z * tan( theta ) , phi , z , Vector3D::cylindrical ) ) ; + Vector3D( r , phi , r / tan( theta ) , Vector3D::cylindrical ) : + Vector3D( z * tan( theta ) , phi , z , Vector3D::cylindrical ) ) ; return v ; } @@ -81,7 +77,7 @@ int main_wrapper(int argc, char** argv) { std::cout << " usage: materialBudget compact.xml steering.txt" << std::endl << " -> create histograms with the material budget as seen from the IP within fixed ranges of (rmin, rmax, zmin. zmax)" << std::endl << " see example steering file for details ..." << std::endl - << " -x : dump example steering file " << std::endl + << " -x : dump example steering file " << std::endl << std::endl; exit(1); } @@ -155,9 +151,9 @@ int main_wrapper(int argc, char** argv) { subdets.emplace_back( det ); } - if ( !iss.eof() || iss.fail() ){ + if ( iss.fail() ){ std::cout << " ERROR parsing line : " << line << std::endl ; - exit(1) ; + ::exit(EINVAL); } } @@ -172,17 +168,13 @@ int main_wrapper(int argc, char** argv) { Detector& description = Detector::getInstance(); description.fromXML(compactFile ) ; - //----- open root file and book histograms TFile* rootFile = new TFile(outFileName.c_str(),"recreate"); - - for(auto& det : subdets){ - + for( auto& det : subdets ) { std::string hxn(det.name), hxnn(det.name) ; std::string hln(det.name), hlnn(det.name) ; - if( etaMax > 0. ) { // use eta - + if( etaMax > 0. ) { // use eta hxn += "x0" ; hxnn += " integrated X0 vs eta" ; det.hx = new TH1F( hxn.c_str(), hxnn.c_str(), nbins, etaMin , etaMax ) ; @@ -190,9 +182,8 @@ int main_wrapper(int argc, char** argv) { hln += "lambda" ; hlnn += " integrated int. lengths vs eta" ; det.hl = new TH1F( hln.c_str(), hlnn.c_str(), nbins, etaMin , etaMax ) ; - - } else { // use polar angle - + } + else { // use polar angle hxn += "x0" ; hxnn += " integrated X0 vs -theta" ; det.hx = new TH1F( hxn.c_str(), hxnn.c_str(), nbins, -thetaMax , -thetaMin ) ; @@ -201,7 +192,6 @@ int main_wrapper(int argc, char** argv) { hlnn += " integrated int. lengths vs -theta" ; det.hl = new TH1F( hln.c_str(), hlnn.c_str(), nbins, -thetaMax , -thetaMin ) ; } - } //------------------------- @@ -216,7 +206,6 @@ int main_wrapper(int argc, char** argv) { double dEta = (etaMax-etaMin)/nbins ; std::cout << "====================================================================================================" << std::endl ; - std::cout << "theta:f/" ; for(auto& det : subdets){ std::cout << det.name << "_x0:f/" << det.name << "_lam:f/" ; } std::cout << std::endl ; @@ -225,58 +214,42 @@ int main_wrapper(int argc, char** argv) { std::cout << "Unreasonable number of bins: " << nbins << std::endl; ::exit(EINVAL); } - - for(int i=0 ; i< nbins ;++i){ + for(int i=0 ; i< nbins ;++i){ double theta = ( etaMax > 0. ? 2. * atan ( exp ( - ( etaMin + (0.5+i)*dEta) ) ) : ( thetaMin + (0.5+i)*dTheta ) ) ; + std::stringstream line; - std::cout << std::scientific << theta << " " ; - - for(auto& det : subdets){ - + line << std::scientific << theta << " " ; + for( auto& det : subdets ) { Vector3D p0 = pointOnCylinder( theta, det.r0 , det.z0 , phi0 ) ;// double theta, double r, double z, double phi) - Vector3D p1 = pointOnCylinder( theta, det.r1 , det.z1 , phi0 ) ;// double theta, double r, double z, double phi) - const MaterialVec& materials = matMgr.materialsBetween(p0, p1); - double sum_x0(0.), sum_lambda(0.),path_length(0.); - for( auto amat : materials ){ - TGeoMaterial* mat = amat.first->GetMaterial(); - double length = amat.second; - double nx0 = length / mat->GetRadLen(); - sum_x0 += nx0; - double nLambda = length / mat->GetIntLen(); - sum_lambda += nLambda; - path_length += length; + for( auto amat : materials ) { + TGeoMaterial* mat = amat.first->GetMaterial(); + double length = amat.second; + double nx0 = length / mat->GetRadLen(); + sum_x0 += nx0; + double nLambda = length / mat->GetIntLen(); + sum_lambda += nLambda; + path_length += length; } - double binX = ( etaMax > 0. ? (etaMin + (0.5+i)*dEta) : -theta/M_PI*180. ) ; - det.hx->Fill( binX , sum_x0 ) ; det.hl->Fill( binX , sum_lambda ) ; - - std::cout << std::scientific << sum_x0 << " " << sum_lambda << " " ; // << path_length ; - + line << std::scientific << sum_x0 << " " << sum_lambda << " " ; // << path_length ; } - std::cout << std::endl ; + std::cout << line.str() << std::endl; } std::cout << "====================================================================================================" << std::endl ; - - rootFile->Write(); rootFile->Close(); - return 0; } - - void dumpExampleSteering(){ - - std::cout << "# Example steering file for materialBudget (taken from ILD_l5_v02)" << std::endl ; std::cout << std::endl ; std::cout << "# root output file" << std::endl ; @@ -302,6 +275,5 @@ void dumpExampleSteering(){ std::cout << "subdet tpc 0. 0. 1.692100e+02 2.225000e+02" << std::endl ; std::cout << "subdet outtpc 0. 0. 1.769800e+02 2.350000e+02" << std::endl ; std::cout << "subdet set 0. 0. 1.775200e+02 2.300000e+02" << std::endl ; - - exit(0); + ::exit(0); }