void newCode(const GlobalPoint & P1, const GlobalPoint & P2) { typedef TkRotation2D<double> Rotation; typedef Basic2DVector<double> Point2D; Rotation theRotation = Rotation(P1.basicVector().xy()); Point2D p1 = transform(P1.basicVector().xy(), theRotation); // (1./P1.xy().mag(),0); Point2D p2 = transform(P2.basicVector().xy(), theRotation); std::cout << "\nnew for " << P1 <<", " << P2 << std::endl; std::cout << theRotation << std::endl; std::cout << p1.x() << " " << p1.y() << std::endl; std::cout << p2.x() << " " << p2.y() << std::endl; std::cout << transformBack(p1, theRotation) << std::endl; std::cout << transformBack(p2, theRotation) << std::endl; }
float MtfCoordinateConverter::convertRpc(uint32_t detUnitId, int16_t strip) { const RPCDetId id(detUnitId); const RPCRoll* roll = geoRpc->roll(id); /* std::cout<<__FUNCTION__<<":"<<__LINE__ <<" detUnitId: "<<detUnitId <<id <<" roll: "<<" "<<roll<<std::endl; */ const LocalPoint lp = roll->centreOfStrip(strip); const GlobalPoint gp = roll->toGlobal(lp); float globalPhi = gp.phi().value(); return globalPhi; }
//copied from L1TriggerDPGUpgrade/L1TMuon/interface/GeometryTranslator.cc float MtfCoordinateConverter::convertCsc(uint32_t detUnitId, uint16_t halfstrip, uint16_t pattern, uint16_t keyWG) { const CSCDetId id(detUnitId); // we should change this to weak_ptrs at some point // requires introducing std::shared_ptrs to geometry std::unique_ptr<const CSCChamber> chamb(geoCsc->chamber(id)); std::unique_ptr<const CSCLayerGeometry> layer_geom( chamb->layer(CSCConstants::KEY_ALCT_LAYER)->geometry() ); std::unique_ptr<const CSCLayer> layer( chamb->layer(CSCConstants::KEY_ALCT_LAYER) ); //const unsigned maxStrips = layer_geom->numberOfStrips(); // so we can extend this later // assume TMB2007 half-strips only as baseline double offset = 0.0; switch(1) { case 1: offset = CSCPatternLUT::get2007Position(pattern); } const unsigned halfstrip_offs = unsigned(0.5 + halfstrip + offset); const unsigned strip = halfstrip_offs/2 + 1; // geom starts from 1 // the rough location of the hit at the ALCT key layer // we will refine this using the half strip information const LocalPoint coarse_lp = layer_geom->stripWireGroupIntersection(strip,keyWG); const GlobalPoint coarse_gp = layer->surface().toGlobal(coarse_lp); // the strip width/4.0 gives the offset of the half-strip // center with respect to the strip center const double hs_offset = layer_geom->stripPhiPitch()/4.0; // determine handedness of the chamber const bool ccw = isCSCCounterClockwise(layer); // we need to subtract the offset of even half strips and add the odd ones const double phi_offset = ( ( halfstrip_offs%2 ? 1 : -1)* ( ccw ? -hs_offset : hs_offset ) ); // the global eta calculation uses the middle of the strip // so no need to increment it const GlobalPoint final_gp( GlobalPoint::Polar( coarse_gp.theta(), (coarse_gp.phi().value() + phi_offset), coarse_gp.mag() ) ); // We need to add in some notion of the 'error' on trigger primitives // like the width of the wire group by the width of the strip // or something similar // release ownership of the pointers chamb.release(); layer_geom.release(); layer.release(); float globalPhi = final_gp.phi().value(); return globalPhi; }
void oldCode(const GlobalPoint & P1, const GlobalPoint & P2) { typedef TkRotation<double> Rotation; typedef Basic2DVector<double> Point2D; GlobalVector aX = GlobalVector( P1.x(), P1.y(), 0.).unit(); GlobalVector aY( -aX.y(), aX.x(), 0.); GlobalVector aZ( 0., 0., 1.); TkRotation<double > theRotation = Rotation(aX,aY,aZ); PointUV p1(Point2D(P1.x(),P1.y()), &theRotation); PointUV p2(Point2D(P2.x(),P2.y()), &theRotation); std::cout << "\nold for " << P1 <<", " << P2 << std::endl; std::cout << theRotation << std::endl; std::cout << p1.u() << " " << p1.v() << std::endl; std::cout << p2.u() << " " << p2.v() << std::endl; std::cout << p1.unmap() << std::endl; std::cout << p2.unmap() << std::endl; }
int main (int argc, char** argv) { std::string fileName (argv[1]) ; boost::shared_ptr<edm::ProcessDesc> processDesc = edm::readConfigFile (fileName) ; boost::shared_ptr<edm::ParameterSet> parameterSet = processDesc->getProcessPSet () ; edm::ParameterSet subPSetSelections = parameterSet->getParameter<edm::ParameterSet> ("selections") ; edm::ParameterSet subPSetInput = parameterSet->getParameter<edm::ParameterSet> ("inputNtuples") ; std::vector<std::string> inputFiles = subPSetInput.getParameter<std::vector<std::string> > ("inputFiles") ; // load ntuple TChain *chain = new TChain ("EcalCosmicsAnalysis") ; EcalCosmicsTreeContent treeVars ; setBranchAddresses (chain, treeVars) ; // input files for (std::vector<std::string>::const_iterator listIt = inputFiles.begin () ; listIt != inputFiles.end () ; ++listIt) { std::cout << *listIt << " " << std::endl ; chain->Add (listIt->c_str ()) ; } int nEntries = chain->GetEntries () ; std::cout << "FOUND " << nEntries << " ENTRIES\n" ; // Output file std::string outputRootName = "CRAFT_MATCHdistr.root" ; TFile outputRootFile (outputRootName.c_str (), "recreate") ; outputRootFile.cd () ; // output distributions TH2F looseAssoc_DETAvsDPHI ("looseAssoc_DETAvsDPHI", "looseAssoc_DETAvsDPHI", PHI_BIN, PHI_MIN, PHI_MAX, 2*ETA_BIN, 2*ETA_MIN, 2*ETA_MAX) ; TH1F looseAssoc_DR ("looseAssoc_DR", "looseAssoc_DR", 2*PHI_BIN, 0., 2*PHI_MAX) ; TH1F EoverP_loose ("EoverP_loose", "EoverP_loose", 1000, 0., 5.) ; TH2F tightAssoc_DETAvsDPHI ("tightAssoc_DETAvsDPHI", "tightAssoc_DETAvsDPHI", PHI_BIN, -0.5, 0.5, ETA_BIN, -0.5, 0.5) ; TH1F tightAssoc_DR ("tightAssoc_DR", "tightAssoc_DR", 2*PHI_BIN, 0., 2*PHI_MAX) ; TH1F EoverP_tight ("EoverP_tight", "EoverP_tight", 1000, 0., 5.) ; TProfile EoverPvsETA_tight ("EoverPvsETA_tight", "EoverPvsETA_tight", ETA_BIN, ETA_MIN, ETA_MAX) ; TProfile EoverPvsPHI_tight ("EoverPvsPHI_tight", "EoverPvsPHI_tight", PHI_BIN, PHI_MIN, PHI_MAX) ; TProfile EoverPvsPT_tight ("EoverPvsPT_tight", "EoverPvsPT_tight", P_BIN, P_MIN, P_MAX) ; TProfile dEvsdX_tight ("dEvsdX_tight", "dEvsdX_tight", 200, 0., 100.) ; // loop over entries for (int entry = 0; entry < nEntries; ++entry) { if ((entry % 100000) == 0) std::cout << "Reading entry " << entry << std::endl; chain->GetEntry (entry) ; // if (entry == 100000) break ; // association MU-SC std::vector<ect::association> looseAssoc ; ect::fillAssocVector (looseAssoc, treeVars) ; ect::selectOnDR (looseAssoc, treeVars, 1000000.) ; std::vector<ect::association> tightAssoc ; ect::fillAssocVector (tightAssoc, treeVars) ; ect::selectOnDR (tightAssoc, treeVars, 0.1) ; //loop on associations vector for (unsigned int i = 0 ; i < looseAssoc.size () ; ++i) { int MUindex = looseAssoc.at (i).first ; int SCindex = looseAssoc.at (i).second ; int muonLeg = treeVars.muonLeg[MUindex]; float muonP = 0.; float muonPt = 0.; float muond0 = treeVars.muond0[MUindex]; float muondz = treeVars.muondz[MUindex]; float muonPhi = 0.; float muonEta = 0.; float muonTkLengthInEcal = treeVars.muonTkLengthInEcalDetail[MUindex]; float muonTkLengthInEcalCurved = treeVars.muonTkLengthInEcalDetailCurved[MUindex]; float superClusterRawEnergy = treeVars.superClusterRawEnergy[SCindex]; GlobalPoint muonTkInternalPointInEcal (treeVars.muonTkInternalPointInEcalX[MUindex], treeVars.muonTkInternalPointInEcalY[MUindex], treeVars.muonTkInternalPointInEcalZ[MUindex]) ; float Dphi = treeVars.superClusterPhi[SCindex] - muonTkInternalPointInEcal.phi () ; float Deta = treeVars.superClusterEta[SCindex] - muonTkInternalPointInEcal.eta () ; if (muonLeg == 1) { muonP = treeVars.muonInnTkInnerHitP[MUindex]; muonPt = treeVars.muonInnTkInnerHitPt[MUindex]; muonPhi = treeVars.muonInnTkInnerHitPhi[MUindex]; muonEta = treeVars.muonInnTkInnerHitEta[MUindex]; } else if (muonLeg == -1) { muonP = treeVars.muonInnTkOuterHitP[MUindex]; muonPt = treeVars.muonInnTkOuterHitPt[MUindex]; muonPhi = treeVars.muonInnTkOuterHitPhi[MUindex]; muonEta = treeVars.muonInnTkOuterHitEta[MUindex]; } looseAssoc_DETAvsDPHI.Fill (Dphi, Deta) ; looseAssoc_DR.Fill (sqrt (Dphi*Dphi + Deta*Deta)) ; if (muonLeg == -1) { EoverP_loose.Fill (superClusterRawEnergy/muonP) ; } } for (unsigned int i = 0 ; i < tightAssoc.size () ; ++i) { int MUindex = tightAssoc.at (i).first ; int SCindex = tightAssoc.at (i).second ; int muonLeg = treeVars.muonLeg[MUindex]; float muonP = 0.; float muonPt = 0.; float muond0 = treeVars.muond0[MUindex]; float muondz = treeVars.muondz[MUindex]; float muonPhi = 0.; float muonEta = 0.; float muonTkLengthInEcal = treeVars.muonTkLengthInEcalDetail[MUindex]; float muonTkLengthInEcalCurved = treeVars.muonTkLengthInEcalDetailCurved[MUindex]; float superClusterRawEnergy = treeVars.superClusterRawEnergy[SCindex]/4*0.9 ; GlobalPoint muonTkInternalPointInEcal (treeVars.muonTkInternalPointInEcalX[MUindex], treeVars.muonTkInternalPointInEcalY[MUindex], treeVars.muonTkInternalPointInEcalZ[MUindex]) ; float Dphi = treeVars.superClusterPhi[SCindex] - muonTkInternalPointInEcal.phi () ; float Deta = treeVars.superClusterEta[SCindex] - muonTkInternalPointInEcal.eta () ; if (muonLeg == 1) { muonP = treeVars.muonInnTkInnerHitP[MUindex]; muonPt = treeVars.muonInnTkInnerHitPt[MUindex]; muonPhi = treeVars.muonInnTkInnerHitPhi[MUindex]; muonEta = treeVars.muonInnTkInnerHitEta[MUindex]; } else if (muonLeg == -1) { muonP = treeVars.muonInnTkOuterHitP[MUindex]; muonPt = treeVars.muonInnTkOuterHitPt[MUindex]; muonPhi = treeVars.muonInnTkOuterHitPhi[MUindex]; muonEta = treeVars.muonInnTkOuterHitEta[MUindex]; } tightAssoc_DETAvsDPHI.Fill (Dphi, Deta) ; tightAssoc_DR.Fill (sqrt (Dphi*Dphi + Deta*Deta)) ; if (muonLeg == -1) { EoverP_tight.Fill (superClusterRawEnergy/muonP) ; EoverPvsETA_tight.Fill (muonEta, superClusterRawEnergy/muonP) ; EoverPvsPHI_tight.Fill (muonPhi, superClusterRawEnergy/muonP) ; EoverPvsPT_tight.Fill (muonPt, superClusterRawEnergy/muonP) ; if(muonTkLengthInEcal > 0.) { dEvsdX_tight.Fill (muonTkLengthInEcal, superClusterRawEnergy) ; } } } } //PG loop over entries // Save histograms looseAssoc_DETAvsDPHI.Write () ; looseAssoc_DR.Write () ; EoverP_loose.Write () ; tightAssoc_DETAvsDPHI.Write () ; tightAssoc_DR.Write () ; EoverP_tight.Write () ; EoverPvsETA_tight.Write () ; EoverPvsPHI_tight.Write () ; EoverPvsPT_tight.Write () ; dEvsdX_tight.Write () ; outputRootFile.Close () ; return 0 ; }