/*! Propagate a loitering trajectory, filling the lists of sampleTimes * and samples with the results of each step. Errors during propagation * are indicated by setting the error flag in the PropagationFeedback * object. * * The return value of propagate is the final state after propagation * is complete (i.e. the last entry in the samples list.) */ sta::StateVector ScenarioLoiteringTrajectory::propagate(PropagationFeedback& propFeedback, const sta::StateVector& initialState, QList<double>& sampleTimes, QList<sta::StateVector>& samples) { QTextStream out (stdout); double mu = centralBody()->mu(); const ScenarioExtendedTimeline* timeline = simulationParameters()->timeline(); // Creating the list of perturbations that will influence the propagation ScenarioSpaceVehicle* spacevehicle = dynamic_cast<ScenarioSpaceVehicle*>(this->parent()->parent()); ScenarioProperties* vehicleproperties = spacevehicle->properties(); QList<Perturbations*> perturbationsList = environment()->createListPerturbations(vehicleproperties); double timelineDuration = sta::daysToSecs(timeline->endTime() - timeline->startTime()); double dt = trajectoryPropagation()->timeStep(); if (dt == 0.0) { propFeedback.raiseError(QObject::tr("Time step is zero!")); return initialState; } // We don't output values at every integration step. Instead use the time step // from simulation parameters. The actual output step used will not necessarily // match the requested output step: the code below sets it to be an integer // multiple of the integration step. double requestedOutputTimeStep = simulationParameters()->timeline()->timeStep(); double outputTimeStep; unsigned int outputRate; if (requestedOutputTimeStep < dt) { outputRate = 1; outputTimeStep = dt; } else { outputRate = (unsigned int) floor(requestedOutputTimeStep / dt + 0.5); outputTimeStep = outputRate * dt; } if (timelineDuration / outputTimeStep > MAX_OUTPUT_STEPS) { propFeedback.raiseError(QObject::tr("Number of propagation steps exceeds %1. Try increasing the simulation time step.").arg(MAX_OUTPUT_STEPS)); return initialState; } // Calculate initial keplerian elements in case the propagator Two Body will be used sta::KeplerianElements foundKeplerianElements = cartesianTOorbital(mu, initialState); double sma = foundKeplerianElements.SemimajorAxis; double e = foundKeplerianElements.Eccentricity; double inclination = foundKeplerianElements.Inclination; double raan = foundKeplerianElements.AscendingNode; double argOfPeriapsis = foundKeplerianElements.ArgumentOfPeriapsis; double meanAnomaly = foundKeplerianElements.MeanAnomaly; double perigee = sma * (1-e); if (perigee<centralBody()->meanRadius()) { QMessageBox::warning(NULL, QObject::tr("The trajectory has been not propagated"), QObject::tr("The perigee distance is smaller than the main body radius.")); return initialState.zero(); } sta::StateVector stateVector = initialState; // deviation, reference, and q will be used only in Encke propagation sta::StateVector deviation(Vector3d::Zero(), Vector3d::Zero()); sta::StateVector reference = initialState; double q = 0.0; sampleTimes << timeline->startTime(); samples << stateVector; double time = timeline->startTime(); //mjd QFile ciccio("data/PerturbationsData.stae"); QTextStream cicciostream(&ciccio); ciccio.open(QIODevice::WriteOnly); unsigned int steps = 0; for (double t = dt; t < timelineDuration + dt; t += dt) { JulianDate jd = timeline->startTime() + sta::secsToDays(t); // Choosing the propagator and propagating the trajectory if (trajectoryPropagation()->propagator() == "TWO BODY") { double perigee=sma*(1-e); if (perigee<centralBody()->meanRadius()) { QMessageBox::warning(NULL, QObject::tr("The trajectory has been not propagated"), QObject::tr("The perigee distance is smaller than the main body radius.")); return stateVector.zero(); } double argOfPeriapsisUpdated = 0.0; double meanAnomalyUpdated = 0.0; double raanUpdated = 0.0; stateVector = propagateTWObody(mu, sma, e, inclination, argOfPeriapsis, raan, meanAnomaly, trajectoryPropagation()->timeStep(), raanUpdated, argOfPeriapsisUpdated, meanAnomalyUpdated); argOfPeriapsis = argOfPeriapsisUpdated; meanAnomaly = meanAnomalyUpdated; raan = raanUpdated; } else if (trajectoryPropagation()->propagator() == "COWELL") { stateVector = propagateCOWELL(mu, stateVector, trajectoryPropagation()->timeStep(), perturbationsList, time, trajectoryPropagation()->integrator(), propFeedback); } else if (trajectoryPropagation()->propagator() == "ENCKE") { deviation = propagateENCKE(mu, reference, trajectoryPropagation()->timeStep(),perturbationsList, time, stateVector, deviation, q, trajectoryPropagation()->integrator(), propFeedback); // PropagateTWObody is used to propagate the reference trajectory double argOfPeriapsisUpdated = 0.0; double meanAnomalyUpdated = 0.0; double raanUpdated = 0.0; reference = propagateTWObody(mu, sma, e, inclination, argOfPeriapsis, raan, meanAnomaly, trajectoryPropagation()->timeStep(), raanUpdated, argOfPeriapsisUpdated, meanAnomalyUpdated); argOfPeriapsis = argOfPeriapsisUpdated; meanAnomaly = meanAnomalyUpdated; raan = raanUpdated; // Calculating the perturbed trajectory stateVector = reference + deviation; q = deviation.position.dot(reference.position + 0.5 * deviation.position) / pow(reference.position.norm(), 2.0); // // Rectification of the reference trajectory, when the deviation is too large. // if (q > 0.01) // { // sta::KeplerianElements keplerian = cartesianTOorbital(mu, stateVector); // // sma = keplerian.SemimajorAxis; // e = keplerian.Eccentricity; // inclination = keplerian.Inclination; // argOfPeriapsis = keplerian.ArgumentOfPeriapsis; // raan = keplerian.AscendingNode; // meanAnomaly = keplerian.MeanAnomaly; // // q = 0; // reference = stateVector; // deviation = sta::StateVector(null, null); // } } else if (trajectoryPropagation()->propagator() == "GAUSS") { stateVector = propagateGAUSS(mu, stateVector, trajectoryPropagation()->timeStep(), perturbationsList, time, trajectoryPropagation()->integrator()); } KeplerianElements kep = cartesianTOorbital(mu, stateVector); cicciostream.setRealNumberPrecision(8); //cicciostream << kep.SemimajorAxis << " "; //cicciostream << kep.Eccentricity << " "; cicciostream << kep.Inclination << " "; //cicciostream << kep.ArgumentOfPeriapsis << " "; //cicciostream << kep.AscendingNode << " "; //cicciostream << kep.TrueAnomaly << " "; // //Treat the debris perturbation if selected by the user // foreach (Perturbations* perturbation, perturbationsList) // if (dynamic_cast<DebrisPerturbations*>(perturbation)) // { // DebrisPerturbations* debris = dynamic_cast<DebrisPerturbations*>(perturbation); // double gravityAcceleration = (-pow(initialState.position.norm(),-3.0) * mu * initialState.position).norm(); // double perturbedAcceleration = gravityAcceleration + debris->calculatePerturbingEffect(initialState, sta::daysToSecs(jd)); // } // Append a trajectory sample every outputRate integration steps (and // always at the last step.) if (steps % outputRate == 0 || t >= timelineDuration) { sampleTimes << jd; samples << stateVector; } ++steps; time += sta::secsToDays(dt); }; //out << "samples size: " << samples.size() << endl; return stateVector; }
int main (int argc, char** argv) { gROOT->SetStyle("Plain"); TChain * chain = new TChain ("EcalCosmicsAnalysis") ; chain->Add ("/afs/cern.ch/user/m/mattia/MuonTree_43439/MuonTree_43439_*.root") ; EcalCosmicsAnalysisVariables treeVars ; chain->SetBranchAddress ("runId", &treeVars.runId) ; chain->SetBranchAddress ("eventId", &treeVars.eventId) ; chain->SetBranchAddress ("timeStampLow", &treeVars.timeStampLow) ; chain->SetBranchAddress ("timeStampHigh", &treeVars.timeStampHigh) ; chain->SetBranchAddress ("isECALL1", &treeVars.isECALL1) ; chain->SetBranchAddress ("isHCALL1", &treeVars.isHCALL1) ; chain->SetBranchAddress ("isDTL1", &treeVars.isDTL1) ; chain->SetBranchAddress ("isRPCL1", &treeVars.isRPCL1) ; chain->SetBranchAddress ("isCSCL1", &treeVars.isCSCL1) ; chain->SetBranchAddress ("nCosmicsCluster", &treeVars.nCosmicsCluster) ; chain->SetBranchAddress ("cosmicClusterEnergy", treeVars.cosmicClusterEnergy) ; chain->SetBranchAddress ("cosmicClusterE1", treeVars.cosmicClusterE1) ; chain->SetBranchAddress ("cosmicClusterE2", treeVars.cosmicClusterE2) ; chain->SetBranchAddress ("cosmicClusterE9", treeVars.cosmicClusterE9) ; chain->SetBranchAddress ("cosmicClusterE25", treeVars.cosmicClusterE25) ; chain->SetBranchAddress ("cosmicClusterTime", treeVars.cosmicClusterTime) ; chain->SetBranchAddress ("cosmicClusterEta", treeVars.cosmicClusterEta) ; chain->SetBranchAddress ("cosmicClusterPhi", treeVars.cosmicClusterPhi) ; chain->SetBranchAddress ("cosmicClusterXtals", treeVars.cosmicClusterXtals) ; chain->SetBranchAddress ("cosmicClusterXtalsAbove3Sigma", treeVars.cosmicClusterXtalsAbove3Sigma) ; chain->SetBranchAddress ("cosmicClusterMaxId", treeVars.cosmicClusterMaxId) ; chain->SetBranchAddress ("cosmicCluster2ndId", treeVars.cosmicCluster2ndId) ; chain->SetBranchAddress ("nRecoMuons", &treeVars.nRecoMuons) ; chain->SetBranchAddress ("muonPt", treeVars.muonPt) ; chain->SetBranchAddress ("muonEta", treeVars.muonEta) ; chain->SetBranchAddress ("muonPhi", treeVars.muonPhi) ; chain->SetBranchAddress ("muonNChi2", treeVars.muonNChi2) ; chain->SetBranchAddress ("muonNDof", treeVars.muonNDof) ; chain->SetBranchAddress ("muonNHits", treeVars.muonNHits) ; chain->SetBranchAddress ("muonCharge", treeVars.muonCharge) ; chain->SetBranchAddress ("muonQOverP", treeVars.muonQOverP) ; chain->SetBranchAddress ("muond0", treeVars.muond0) ; chain->SetBranchAddress ("muondz", treeVars.muondz) ; chain->SetBranchAddress ("muonTkAtEcalEta", treeVars.muonTkAtEcalEta) ; chain->SetBranchAddress ("muonTkAtEcalPhi", treeVars.muonTkAtEcalPhi) ; chain->SetBranchAddress ("muonTkAtHcalEta", treeVars.muonTkAtHcalEta) ; chain->SetBranchAddress ("muonTkAtHcalPhi", treeVars.muonTkAtHcalPhi) ; chain->SetBranchAddress ("muonEcalEnergy3x3", treeVars.muonEcalEnergy3x3) ; chain->SetBranchAddress ("muonEcalEnergy5x5", treeVars.muonEcalEnergy5x5) ; chain->SetBranchAddress ("muonEcalEnergyCrossed", treeVars.muonEcalEnergyCrossed) ; chain->SetBranchAddress ("muonHcalEnergy3x3", treeVars.muonHcalEnergy3x3) ; chain->SetBranchAddress ("muonHcalEnergyCrossed", treeVars.muonHcalEnergyCrossed) ; chain->SetBranchAddress ("muonNCrossedEcalDetId", treeVars.muonNCrossedEcalDetId) ; chain->SetBranchAddress ("muonMaxEneEcalDetIdCrossed", treeVars.muonMaxEneEcalDetIdCrossed) ; chain->SetBranchAddress ("cosmicClusterEnergyXtals", treeVars.cosmicClusterEnergyXtals) ; chain->SetBranchAddress ("cosmicClusterLengthXtals_0", treeVars.cosmicClusterLengthXtals_0) ; chain->SetBranchAddress ("cosmicClusterLengthXtals_1", treeVars.cosmicClusterLengthXtals_1) ; TApplication *theApp = new TApplication( "app", &argc, argv ); //eta phi //TH2F Occupancy("Occupancy","Occupancy",170,-1.47,1.47,360,-3.14,3.14); TH2F Occupancy("Occupancy","Occupancy",170,-85.,85.,360,0.,360.); TH2F EnergyOnCrystals("EnergyOnCrystals","EnergyOnCrystals",170,-1.47,1.47,360,-3.14,3.14); TH2F MeanEnergy("MeanEnergy","MeanEnergy",170,-85.,85.,360,0.,360.); TH2F EoPCrystals("EoPCrystals","EoPCrystals",170,-1.47,1.47,360,-3.14,3.14); int nEvents = (int) chain->GetEntries () ; //PG loop over entries for (int iEvent = 0 ; iEvent < nEvents ; ++iEvent) //for (int iEvent = 0 ; iEvent < 1000000 ; ++iEvent) { if(iEvent%10000 == 0) std::cout << "event n. " << iEvent << std::endl; chain->GetEntry (iEvent) ; //base selections if (treeVars.nCosmicsCluster != 2) continue ; if(deltaPhi(treeVars.cosmicClusterPhi[0],treeVars.cosmicClusterPhi[1]) < 3.14159265358979 / 2./*90gradi*/) continue; //TAGLIO IN DELTAPHI EBDetId ciccio(treeVars.cosmicClusterMaxId); //SOSTITUIRE POSIZIONE Occupancy.Fill(ciccio.ieta(),ciccio.iphi()); //Occupancy.Fill(treeVars.cosmicClusterEta[0],treeVars.cosmicClusterPhi[0]); //Occupancy.Fill(treeVars.cosmicClusterEta[1],treeVars.cosmicClusterPhi[1]); EnergyOnCrystals.Fill(treeVars.cosmicClusterEta[0],treeVars.cosmicClusterPhi[0],treeVars.cosmicClusterE1[0]); EnergyOnCrystals.Fill(treeVars.cosmicClusterEta[1],treeVars.cosmicClusterPhi[1],treeVars.cosmicClusterE1[1]); //EoPCrystals.Fill(treeVars.cosmicClusterEta[0],treeVars.cosmicClusterPhi[0],enerTop/lunghTop); //EoPCrystals.Fill(treeVars.cosmicClusterEta[1],treeVars.cosmicClusterPhi[1],enerBot/lunghBot); } //PG loop over entries //MF loop over crystals double nOverCrystals = 0; //numero eventi per cristallo double EOverCrystals = 0; //energia x cristallo for(int indexeta = 0 ; indexeta < 170 ; indexeta++) // eta 170,-1.47,1.47, for(int indexphi = 0 ; indexphi < 360 ; indexphi++) // phi 360,-3.14,3.14 { nOverCrystals = Occupancy.GetBinContent(indexeta,indexphi); EOverCrystals = EnergyOnCrystals.GetBinContent(indexeta,indexphi); if(nOverCrystals==0) EOverCrystals = 0; MeanEnergy.Fill(-85+indexeta,indexphi,EOverCrystals/nOverCrystals); } //MF loop over crystals //Writing Histos TFile out ("Mappe.root","recreate") ; TDirectory* Rings = gDirectory->mkdir("Rings"); TDirectory* Slices = gDirectory->mkdir("Slices"); Occupancy.Write(); EnergyOnCrystals.Write(); EoPCrystals.Write(); MeanEnergy.Write(); return(0); }