#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using std::cout; using std::endl; bool operator<(const TVector3& left, const TVector3& right){ return left.X() < right.X() || (left.X() == right.X() && (left.Y() < right.Y() || (left.Y() == right.Y() && left.Z() < right.Z()))); } std::ostream& operator<<(std::ostream& stream,const TVector3& vect){ return stream<<"("<IsAttached()){ COMETError("Bad input file: "<GetFilePointer()); TGeoManager* geometry=gGeoManager; if(!geometry){ COMETError("Cannot fetch geometry from file: "<CheckPath(test_volume.c_str())){ geometry->cd(test_volume.c_str()); }else{ COMETError("Cannot find requested volume: "<Close(); delete file; return NULL; } } return geometry; } bool ScanFirstGeometry(TGeoManager* geometry, PointSelector* selector, PointDetailsList& outList){ gGeoManager=geometry; cout<<"Scanning first geometry: "<GetNextPoint(point, true)){ TGeoNode* volume=GetNode(geometry,point); COMETNamedTrace("FirstScan","point ["<< i<<"]: "<GetName() <<", "<GetVolume()->GetTitle()); outList[point].first=PointDetails(volume); i++; } return true; } bool ScanSecondGeometry(TGeoManager* geometry,PointDetailsList& outList,PointDiffLists& outDiff){ gGeoManager=geometry; cout<<"Scanning second geometry: "<first; TGeoNode* volume=GetNode(geometry,point); if(!volume) i_point->second.second=PointDetails(); else i_point->second.second=PointDetails(volume); const PointDetails& inGeom_one=i_point->second.first; const PointDetails& inGeom_two=i_point->second.second; if(inGeom_one != inGeom_two){ outDiff.AddDiff(point,PointPair(inGeom_one,inGeom_two)); } if(i%tenPerCent==0) cout<<" "<first; const PointDetails& inGeom_one=i_point->second.first; const PointDetails& inGeom_two=i_point->second.second; cout << "Position : " << point; if (printFirst && printSecond) cout << " Vol 1: " << inGeom_one << ", Vol 2: " << inGeom_two; else if (printFirst) cout << " Vol: " << inGeom_one; else if (printSecond) cout << " Vol: " << inGeom_two; cout << endl; } return true; } void PrintDiff(const PointDiffLists& allDiffLists, bool everything){ cout<<"Number of points identified as having changed: "< severityTally; std::map occurrenceTally; for(PointDiffLists::const_iterator i_list=allDiffLists.begin(); i_list!=allDiffLists.end(); ++i_list){ for(PointDetailsList::const_iterator i_point=i_list->begin(); i_point!=i_list->end(); ++i_point){ std::string difference=i_point->second.toString(); if (everything) cout<<"Point ["<first<<" => "<second.GetDifferenceSeverity()]; ++count; } } if(severityTally.empty()) return; cout<<"Summary of differences: "< sortedOccurenceTally; for(std::map::const_iterator i_type= occurrenceTally.begin(); i_type!=occurrenceTally.end();++i_type){ sortedOccurenceTally.insert(std::make_pair(i_type->second,i_type->first)); } for(std::multimap::const_iterator i_type= sortedOccurenceTally.begin(); i_type!=sortedOccurenceTally.end();++i_type){ cout<<" * "<first<<" point(s) changed as: "<second<::const_iterator i_severity= severityTally.begin(); i_severity!=severityTally.end();++i_severity){ std::string changed; if(i_severity->first & PointPair::kPathName) changed+="path_name"; if(i_severity->first & PointPair::kMaterial) changed+=(changed.empty()?"":" & ")+std::string("material"); if(i_severity->first & PointPair::kOverlap) changed+=(changed.empty()?"":" & ")+std::string("overlap"); cout<<" * "<second<<" points had changes to "<IsZombie()){ cout<<"Cannot create output file: "<Write(); outfile->Write(); outfile->Close(); return true; } void SavePoints(const PointDetailsList& list,int style, int colour, std::string name){ if(list.empty()) return; TPolyMarker3D *marker = new TPolyMarker3D(); //TPointSet3D *marker = new TPointSet3D(); marker->SetMarkerStyle(style); marker->SetMarkerColor(colour); int count=0; for(PointDetailsList::const_iterator i_point=list.begin(); i_point!=list.end(); ++i_point){ const TVector3& vect=i_point->first; marker->SetNextPoint(vect.X(), vect.Y(),vect.Z()); ++count; //std::string description=i_point->second.toString(); //marker->SetPointId(new TNamed(description.c_str(),description.c_str())); if(name.empty()) { name=i_point->second.SeverityString(); } } marker->Write(name.c_str()); } TGeoNode* GetNode(TGeoManager* geometry, const TVector3& position){ geometry->PushPath(); geometry->GetTopNode()->cd(); TGeoNode* volume=geometry->FindNode(position.X(),position.Y(),position.Z()); geometry->PopPath(); return volume; } PointSelector* BuildPointSelector(const std::string& options, int totalPoints, TGeoManager* geom_one){ // Set the geometry manager gGeoManager=geom_one; // Get the options as a TString TString optionsStr = TString(options); optionsStr.ToLower(); // Split the options string SubStrings allOptions; SplitString(options, allOptions); // Return random daughter points if required if (allOptions[0] == "random") return new RandomDaughterPoints(totalPoints, geom_one); // Return beamline coordinate points else if (allOptions[0] == "beamline") return new PointsAlongBeamLine(totalPoints, geom_one); // Return points from a file else if (allOptions[0] == "fromfile"){ if (allOptions.size() < 2) COMETError("Need to provide a file name for the \"fromfile\"" " selector"); else return new PointsFromFile(totalPoints, allOptions[1]); } else COMETError("Unrecognized point selector " << optionsStr); // Return null as an error return NULL; } void SplitString(const std::string& inputString, SubStrings& outStrings, char delim){ // Make a TString copy of the input string TString inTString(inputString); // Ensure we do not loop forever int inf_loop = 0; // Keep splitting on white space delimieters while (!inTString.IsNull()) { // Trim leading or trailing white space, so we can cut on an aribitrary // amount of white space inTString.Remove(TString::kBoth, delim); // Find the first new white space int firstPos = inTString.First(delim); if (inTString.CountChar(delim) == 0) firstPos = inTString.Length(); // Make a substring up to this point TString nextName = inTString(0, firstPos); outStrings.push_back(nextName.Data()); // Remove this sub string from the copy of the input name inTString.Remove(0,firstPos); // If we hit an infinite loop, something is VERY wrong inf_loop++; if (inf_loop > 50) { COMETError("Infinite loop when trying to split \"" << inputString << "\""); // Lazy error throwing throw; } } } } }