inline_heavyhadspec_w.cc

Go to the documentation of this file.
00001 // $Id: inline_heavyhadspec_w.cc,v 1.2 2008/11/04 18:43:57 edwards Exp $
00002 /*! \file
00003  * \brief Inline construction of heavy hadron spectrum in SU(3)
00004  *
00005  */
00006 
00007 #include "meas/inline/hadron/inline_heavyhadspec_w.h"
00008 #include "meas/hadron/heavy_hadrons_su3_w.h"
00009 #include "meas/inline/abs_inline_measurement_factory.h"
00010 #include "meas/glue/mesplq.h"
00011 #include "util/ft/sftmom.h"
00012 #include "util/info/proginfo.h"
00013 #include "io/param_io.h"
00014 #include "io/qprop_io.h"
00015 #include "meas/inline/make_xml_file.h"
00016 #include "meas/inline/io/named_objmap.h"
00017 #include "meas/smear/no_quark_displacement.h"
00018 
00019 namespace Chroma 
00020 { 
00021   namespace InlineHeavyHadSpecEnv 
00022   { 
00023     namespace
00024     {
00025       AbsInlineMeasurement* createMeasurement(XMLReader& xml_in, 
00026                                               const std::string& path) 
00027       {
00028         return new InlineHeavyHadSpec(InlineHeavyHadSpecParams(xml_in, path));
00029       }
00030 
00031       //! Local registration flag
00032       bool registered = false;
00033     }
00034 
00035     const std::string name = "HEAVY_HADRON_SPECTRUM";
00036 
00037     //! Register all the factories
00038     bool registerAll() 
00039     {
00040       bool success = true; 
00041       if (! registered)
00042       {
00043         success &= TheInlineMeasurementFactory::Instance().registerObject(name, createMeasurement);
00044         registered = true;
00045       }
00046       return success;
00047     }
00048   }
00049 
00050 
00051 
00052   //! Reader for parameters
00053   void read(XMLReader& xml, const string& path, InlineHeavyHadSpecParams::Param_t& param)
00054   {
00055     XMLReader paramtop(xml, path);
00056 
00057     int version;
00058     read(paramtop, "version", version);
00059 
00060     switch (version) 
00061     {
00062     case 1:
00063       break;
00064 
00065     default:
00066       QDPIO::cerr << "Input parameter version " << version << " unsupported." << endl;
00067       QDP_abort(1);
00068     }
00069 
00070     read(paramtop, "time_rev", param.time_rev);
00071 
00072     read(paramtop, "mom2_max", param.mom2_max);
00073     read(paramtop, "avg_equiv_mom", param.avg_equiv_mom);
00074   }
00075 
00076 
00077   //! Writer for parameters
00078   void write(XMLWriter& xml, const string& path, const InlineHeavyHadSpecParams::Param_t& param)
00079   {
00080     push(xml, path);
00081 
00082     int version = 1;
00083     write(xml, "version", version);
00084 
00085     write(xml, "time_rev", param.time_rev);
00086 
00087     write(xml, "mom2_max", param.mom2_max);
00088     write(xml, "avg_equiv_mom", param.avg_equiv_mom);
00089 
00090     pop(xml);
00091   }
00092 
00093 
00094   //! Propagator input
00095   void read(XMLReader& xml, const string& path, InlineHeavyHadSpecParams::NamedObject_t::Props_t& input)
00096   {
00097     XMLReader inputtop(xml, path);
00098 
00099     read(inputtop, "first_id", input.first_id);
00100     read(inputtop, "second_id", input.second_id);
00101   }
00102 
00103   //! Propagator output
00104   void write(XMLWriter& xml, const string& path, const InlineHeavyHadSpecParams::NamedObject_t::Props_t& input)
00105   {
00106     push(xml, path);
00107 
00108     write(xml, "first_id", input.first_id);
00109     write(xml, "second_id", input.second_id);
00110 
00111     pop(xml);
00112   }
00113 
00114 
00115   //! Propagator input
00116   void read(XMLReader& xml, const string& path, InlineHeavyHadSpecParams::NamedObject_t& input)
00117   {
00118     XMLReader inputtop(xml, path);
00119 
00120     read(inputtop, "gauge_id", input.gauge_id);
00121     read(inputtop, "sink_pairs", input.sink_pairs);
00122   }
00123 
00124   //! Propagator output
00125   void write(XMLWriter& xml, const string& path, const InlineHeavyHadSpecParams::NamedObject_t& input)
00126   {
00127     push(xml, path);
00128 
00129     write(xml, "gauge_id", input.gauge_id);
00130     write(xml, "sink_pairs", input.sink_pairs);
00131 
00132     pop(xml);
00133   }
00134 
00135 
00136   // Param stuff
00137   InlineHeavyHadSpecParams::InlineHeavyHadSpecParams()
00138   { 
00139     frequency = 0; 
00140   }
00141 
00142   InlineHeavyHadSpecParams::InlineHeavyHadSpecParams(XMLReader& xml_in, const std::string& path) 
00143   {
00144     try 
00145     {
00146       XMLReader paramtop(xml_in, path);
00147 
00148       if (paramtop.count("Frequency") == 1)
00149         read(paramtop, "Frequency", frequency);
00150       else
00151         frequency = 1;
00152 
00153       // Parameters for source construction
00154       read(paramtop, "Param", param);
00155 
00156       // Read in the output propagator/source configuration info
00157       read(paramtop, "NamedObject", named_obj);
00158 
00159       // Possible alternate XML file pattern
00160       if (paramtop.count("xml_file") != 0) 
00161       {
00162         read(paramtop, "xml_file", xml_file);
00163       }
00164     }
00165     catch(const std::string& e) 
00166     {
00167       QDPIO::cerr << __func__ << ": Caught Exception reading XML: " << e << endl;
00168       QDP_abort(1);
00169     }
00170   }
00171 
00172 
00173   void
00174   InlineHeavyHadSpecParams::write(XMLWriter& xml_out, const std::string& path) 
00175   {
00176     push(xml_out, path);
00177     
00178     Chroma::write(xml_out, "Param", param);
00179     Chroma::write(xml_out, "NamedObject", named_obj);
00180     QDP::write(xml_out, "xml_file", xml_file);
00181 
00182     pop(xml_out);
00183   }
00184 
00185 
00186 
00187   // Anonymous namespace
00188   namespace 
00189   {
00190     //! Useful structure holding sink props
00191     struct SinkPropContainer_t
00192     {
00193       ForwardProp_t prop_header;
00194       string quark_propagator_id;
00195       Real Mass;
00196     
00197       multi1d<int> bc; 
00198     
00199       string source_type;
00200       string source_disp_type;
00201       string sink_type;
00202       string sink_disp_type;
00203     };
00204 
00205 
00206     //! Useful structure holding sink props
00207     struct AllSinkProps_t
00208     {
00209       SinkPropContainer_t  sink_prop_1;
00210       SinkPropContainer_t  sink_prop_2;
00211     };
00212 
00213 
00214     //! Read a sink prop
00215     void readSinkProp(SinkPropContainer_t& s, const std::string& id)
00216     {
00217       try
00218       {
00219         // Try a cast to see if it succeeds
00220         const LatticePropagator& foo = 
00221           TheNamedObjMap::Instance().getData<LatticePropagator>(id);
00222 
00223         // Snarf the data into a copy
00224         s.quark_propagator_id = id;
00225         
00226         // Snarf the prop info. This is will throw if the prop_id is not there
00227         XMLReader prop_file_xml, prop_record_xml;
00228         TheNamedObjMap::Instance().get(id).getFileXML(prop_file_xml);
00229         TheNamedObjMap::Instance().get(id).getRecordXML(prop_record_xml);
00230    
00231         // Try to invert this record XML into a ChromaProp struct
00232         // Also pull out the id of this source
00233         {
00234           string xpath;
00235           read(prop_record_xml, "/SinkSmear", s.prop_header);
00236           
00237           read(prop_record_xml, "/SinkSmear/PropSource/Source/SourceType", s.source_type);
00238           xpath = "/SinkSmear/PropSource/Source/Displacement/DisplacementType";
00239           if (prop_record_xml.count(xpath) != 0)
00240             read(prop_record_xml, xpath, s.source_disp_type);
00241           else
00242             s.source_disp_type = NoQuarkDisplacementEnv::getName();
00243 
00244           read(prop_record_xml, "/SinkSmear/PropSink/Sink/SinkType", s.sink_type);
00245           xpath = "/SinkSmear/PropSink/Sink/Displacement/DisplacementType";
00246           if (prop_record_xml.count(xpath) != 0)
00247             read(prop_record_xml, xpath, s.sink_disp_type);
00248           else
00249             s.sink_disp_type = NoQuarkDisplacementEnv::getName();
00250         }
00251       }
00252       catch( std::bad_cast ) 
00253       {
00254         QDPIO::cerr << InlineHeavyHadSpecEnv::name << ": caught dynamic cast error" 
00255                     << endl;
00256         QDP_abort(1);
00257       }
00258       catch (const string& e) 
00259       {
00260         QDPIO::cerr << InlineHeavyHadSpecEnv::name << ": error message: " << e 
00261                     << endl;
00262         QDP_abort(1);
00263       }
00264 
00265 
00266       // Derived from input prop
00267       // Hunt around to find the mass
00268       // NOTE: this may be problematic in the future if actions are used with no
00269       // clear def. of a Mass
00270       QDPIO::cout << "Try action and mass" << endl;
00271       s.Mass = getMass(s.prop_header.prop_header.fermact);
00272 
00273       // Only baryons care about boundaries
00274       // Try to find them. If not present, assume dirichlet.
00275       // This turns off any attempt to time reverse which is the
00276       // only thing that the BC are affecting.
00277       s.bc.resize(Nd);
00278       s.bc = 0;
00279     
00280       try
00281       {
00282         s.bc = getFermActBoundary(s.prop_header.prop_header.fermact);
00283       }
00284       catch (const string& e) 
00285       {
00286         QDPIO::cerr << InlineHeavyHadSpecEnv::name 
00287                     << ": caught exception. No BC found in these headers. Will assume dirichlet: " << e 
00288                     << endl;
00289       }
00290 
00291       QDPIO::cout << "FermAct = " << s.prop_header.prop_header.fermact.id << endl;
00292       QDPIO::cout << "Mass = " << s.Mass << endl;
00293     }
00294 
00295 
00296     //! Read all sinks
00297     void readAllSinks(AllSinkProps_t& s, 
00298                       InlineHeavyHadSpecParams::NamedObject_t::Props_t sink_pair)
00299     {
00300       QDPIO::cout << "Attempt to parse forward propagator = " << sink_pair.first_id << endl;
00301       readSinkProp(s.sink_prop_1, sink_pair.first_id);
00302       QDPIO::cout << "Forward propagator successfully parsed" << endl;
00303 
00304       QDPIO::cout << "Attempt to parse forward propagator = " << sink_pair.second_id << endl;
00305       readSinkProp(s.sink_prop_2, sink_pair.second_id);
00306       QDPIO::cout << "Forward propagator successfully parsed" << endl;
00307     }
00308 
00309   } // namespace anonymous
00310 
00311 
00312 
00313   // Function call
00314   void 
00315   InlineHeavyHadSpec::operator()(unsigned long update_no,
00316                             XMLWriter& xml_out) 
00317   {
00318     // If xml file not empty, then use alternate
00319     if (params.xml_file != "")
00320     {
00321       string xml_file = makeXMLFileName(params.xml_file, update_no);
00322 
00323       push(xml_out, "heavyhadspec");
00324       write(xml_out, "update_no", update_no);
00325       write(xml_out, "xml_file", xml_file);
00326       pop(xml_out);
00327 
00328       XMLFileWriter xml(xml_file);
00329       func(update_no, xml);
00330     }
00331     else
00332     {
00333       func(update_no, xml_out);
00334     }
00335   }
00336 
00337 
00338   // Real work done here
00339   void 
00340   InlineHeavyHadSpec::func(unsigned long update_no,
00341                       XMLWriter& xml_out) 
00342   {
00343     START_CODE();
00344 
00345     StopWatch snoop;
00346     snoop.reset();
00347     snoop.start();
00348 
00349     // Test and grab a reference to the gauge field
00350     XMLBufferWriter gauge_xml;
00351     try
00352     {
00353       TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.gauge_id);
00354       TheNamedObjMap::Instance().get(params.named_obj.gauge_id).getRecordXML(gauge_xml);
00355     }
00356     catch( std::bad_cast ) 
00357     {
00358       QDPIO::cerr << InlineHeavyHadSpecEnv::name << ": caught dynamic cast error" 
00359                   << endl;
00360       QDP_abort(1);
00361     }
00362     catch (const string& e) 
00363     {
00364       QDPIO::cerr << InlineHeavyHadSpecEnv::name << ": map call failed: " << e 
00365                   << endl;
00366       QDP_abort(1);
00367     }
00368     const multi1d<LatticeColorMatrix>& u = 
00369       TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.gauge_id);
00370 
00371     push(xml_out, "heavyhadspec");
00372     write(xml_out, "update_no", update_no);
00373 
00374     QDPIO::cout << " HEAVYHADSPEC: SU(3) heavy hadron spectroscopy for Wilson-like fermions" << endl;
00375     QDPIO::cout << endl << "     Gauge group: SU(" << Nc << ")" << endl;
00376     QDPIO::cout << "     volume: " << Layout::lattSize()[0];
00377     for (int i=1; i<Nd; ++i) {
00378       QDPIO::cout << " x " << Layout::lattSize()[i];
00379     }
00380     QDPIO::cout << endl;
00381 
00382     proginfo(xml_out);    // Print out basic program info
00383 
00384     // Write out the input
00385     params.write(xml_out, "Input");
00386 
00387     // Write out the config info
00388     write(xml_out, "Config_info", gauge_xml);
00389 
00390     push(xml_out, "Output_version");
00391     write(xml_out, "out_version", 15);
00392     pop(xml_out);
00393 
00394 
00395     // First calculate some gauge invariant observables just for info.
00396     MesPlq(xml_out, "Observables", u);
00397 
00398     // Keep an array of all the xml output buffers
00399     push(xml_out, "Wilson_hadron_measurements");
00400 
00401     // Now loop over the various fermion pairs
00402     for(int lpair=0; lpair < params.named_obj.sink_pairs.size(); ++lpair)
00403     {
00404       const InlineHeavyHadSpecParams::NamedObject_t::Props_t named_obj = params.named_obj.sink_pairs[lpair];
00405 
00406       push(xml_out, "elem");
00407 
00408       AllSinkProps_t all_sinks;
00409       readAllSinks(all_sinks, named_obj);
00410 
00411       // Derived from input prop
00412       multi1d<int> t_srce
00413                   = all_sinks.sink_prop_1.prop_header.source_header.getTSrce();
00414       int j_decay = all_sinks.sink_prop_1.prop_header.source_header.j_decay;
00415       int t0      = all_sinks.sink_prop_1.prop_header.source_header.t_source;
00416 
00417       // Sanity checks
00418       {
00419         if (all_sinks.sink_prop_2.prop_header.source_header.j_decay != j_decay)
00420         {
00421           QDPIO::cerr << "Error!! j_decay must be the same for all propagators " << endl;
00422           QDP_abort(1);
00423         }
00424         if (all_sinks.sink_prop_2.prop_header.source_header.t_source != 
00425             all_sinks.sink_prop_1.prop_header.source_header.t_source)
00426         {
00427           QDPIO::cerr << "Error!! t_source must be the same for all propagators " << endl;
00428           QDP_abort(1);
00429         }
00430         if (all_sinks.sink_prop_1.source_type != all_sinks.sink_prop_2.source_type)
00431         {
00432           QDPIO::cerr << "Error!! source_type must be the same in a pair " << endl;
00433           QDP_abort(1);
00434         }
00435         if (all_sinks.sink_prop_1.sink_type != all_sinks.sink_prop_2.sink_type)
00436         {
00437           QDPIO::cerr << "Error!! source_type must be the same in a pair " << endl;
00438           QDP_abort(1);
00439         }
00440       }
00441 
00442       // Only baryons care about bc
00443       int bc_spec = 0;
00444       bc_spec = all_sinks.sink_prop_1.bc[j_decay] ;
00445       if (all_sinks.sink_prop_2.bc[j_decay] != bc_spec)
00446         {
00447           QDPIO::cerr << "Error!! bc must be the same for all propagators " << endl;
00448           QDP_abort(1);
00449         }
00450       
00451 
00452 
00453       // Initialize the slow Fourier transform phases
00454       SftMom phases(params.param.mom2_max, t_srce, params.param.avg_equiv_mom,
00455                     j_decay);
00456 
00457       // Keep a copy of the phases with NO momenta
00458       SftMom phases_nomom(0, true, j_decay);
00459 
00460       // Masses
00461       write(xml_out, "Mass_1", all_sinks.sink_prop_1.Mass);
00462       write(xml_out, "Mass_2", all_sinks.sink_prop_2.Mass);
00463       write(xml_out, "t0", t0);
00464 
00465       // Save prop input
00466       push(xml_out, "Forward_prop_headers");
00467       write(xml_out, "First_forward_prop", all_sinks.sink_prop_1.prop_header);
00468       write(xml_out, "Second_forward_prop", all_sinks.sink_prop_2.prop_header);
00469       pop(xml_out);
00470 
00471       // Sanity check - write out the norm2 of the forward prop in the j_decay direction
00472       // Use this for any possible verification
00473       push(xml_out, "Forward_prop_correlator");
00474       {
00475         const LatticePropagator& sink_prop_1 = 
00476           TheNamedObjMap::Instance().getData<LatticePropagator>(all_sinks.sink_prop_1.quark_propagator_id);
00477         const LatticePropagator& sink_prop_2 = 
00478           TheNamedObjMap::Instance().getData<LatticePropagator>(all_sinks.sink_prop_2.quark_propagator_id);
00479 
00480         write(xml_out, "forward_prop_corr_1", sumMulti(localNorm2(sink_prop_1), phases.getSet()));
00481         write(xml_out, "forward_prop_corr_2", sumMulti(localNorm2(sink_prop_2), phases.getSet()));
00482       }
00483       pop(xml_out);
00484 
00485 
00486       push(xml_out, "SourceSinkType");
00487       {
00488         QDPIO::cout << "Source_type_1 = " << all_sinks.sink_prop_1.source_type << endl;
00489         QDPIO::cout << "Sink_type_1 = " << all_sinks.sink_prop_1.sink_type << endl;
00490         QDPIO::cout << "Source_type_2 = " << all_sinks.sink_prop_2.source_type << endl;
00491         QDPIO::cout << "Sink_type_2 = " << all_sinks.sink_prop_2.sink_type << endl;
00492 
00493         write(xml_out, "source_type_1", all_sinks.sink_prop_1.source_type);
00494         write(xml_out, "source_disp_type_1", all_sinks.sink_prop_1.source_disp_type);
00495         write(xml_out, "sink_type_1", all_sinks.sink_prop_1.sink_type);
00496         write(xml_out, "sink_disp_type_1", all_sinks.sink_prop_1.sink_disp_type);
00497 
00498         write(xml_out, "source_type_2", all_sinks.sink_prop_2.source_type);
00499         write(xml_out, "source_disp_type_2", all_sinks.sink_prop_2.source_disp_type);
00500         write(xml_out, "sink_type_2", all_sinks.sink_prop_2.sink_type);
00501         write(xml_out, "sink_disp_type_2", all_sinks.sink_prop_2.sink_disp_type);
00502       }
00503       pop(xml_out);
00504 
00505 
00506       // References for use later
00507       const LatticePropagator& sink_prop_1 = 
00508         TheNamedObjMap::Instance().getData<LatticePropagator>(all_sinks.sink_prop_1.quark_propagator_id);
00509       const LatticePropagator& sink_prop_2 = 
00510         TheNamedObjMap::Instance().getData<LatticePropagator>(all_sinks.sink_prop_2.quark_propagator_id);
00511 
00512 
00513       // Construct group name for output
00514       string src_type;
00515       if (all_sinks.sink_prop_1.source_type == "POINT_SOURCE")
00516         src_type = "Point";
00517       else if (all_sinks.sink_prop_1.source_type == "SF_POINT_SOURCE")
00518         src_type = "Point";
00519       else if (all_sinks.sink_prop_1.source_type == "SHELL_SOURCE")
00520         src_type = "Shell";
00521       else if (all_sinks.sink_prop_1.source_type == "SF_SHELL_SOURCE")
00522         src_type = "Shell";
00523       else if (all_sinks.sink_prop_1.source_type == "WALL_SOURCE")
00524         src_type = "Wall";
00525       else if (all_sinks.sink_prop_1.source_type == "SF_WALL_SOURCE")
00526         src_type = "Wall";
00527       else
00528       {
00529         QDPIO::cerr << "Unsupported source type = " << all_sinks.sink_prop_1.source_type << endl;
00530         QDP_abort(1);
00531       }
00532 
00533       string snk_type;
00534       if (all_sinks.sink_prop_1.sink_type == "POINT_SINK")
00535         snk_type = "Point";
00536       else if (all_sinks.sink_prop_1.sink_type == "SHELL_SINK")
00537         snk_type = "Shell";
00538       else if (all_sinks.sink_prop_1.sink_type == "WALL_SINK")
00539         snk_type = "Wall";
00540       else
00541       {
00542         QDPIO::cerr << "Unsupported sink type = " << all_sinks.sink_prop_1.sink_type << endl;
00543         QDP_abort(1);
00544       }
00545 
00546       string source_sink_type = src_type + "_" + snk_type;
00547       QDPIO::cout << "Source type = " << src_type << endl;
00548       QDPIO::cout << "Sink type = "   << snk_type << endl;
00549 
00550       
00551       static_light_su3(u, sink_prop_1, sink_prop_2, t_srce,
00552                        phases_nomom,xml_out, 
00553                        source_sink_type + "_Heavy_Hadrons_SU3");
00554         
00555       pop(xml_out);  // array element
00556     }
00557     pop(xml_out);  // Wilson_spectroscopy
00558     pop(xml_out);  // heavyhadspec
00559 
00560     snoop.stop();
00561     QDPIO::cout << InlineHeavyHadSpecEnv::name << ": total time = "
00562                 << snoop.getTimeInSeconds() 
00563                 << " secs" << endl;
00564 
00565     QDPIO::cout << InlineHeavyHadSpecEnv::name << ": ran successfully" << endl;
00566 
00567     END_CODE();
00568   } 
00569 
00570 };

Generated on Mon Mar 15 04:32:44 2010 for CHROMA by  doxygen 1.4.7