Main Page | Packages | Class Hierarchy | Class List | Directories | File List | Class Members | Related Pages

Herwig.java

Go to the documentation of this file.
00001 package cedar.jetweb.generator;
00002 
00003 import java.util.HashMap;
00004 import java.util.Map;
00005 import java.util.Map.Entry;
00006 import java.util.Vector;
00007 
00008 import java.io.BufferedWriter;
00009 import java.io.IOException;
00010 
00011 import cedar.jetweb.JetWebException;
00012 
00013 import cedar.jetweb.model.MCProcessType;
00014 //import cedar.jetweb.model.Collision;
00015 import cedar.jetweb.model.Model;
00016 import cedar.jetweb.db.DBGeneratorManager;
00017 import cedar.jetweb.job.Cut;
00018 import cedar.jetweb.job.CutCollection;
00019 
00023 public class Herwig extends Generator {
00024 
00025     private HashMap<Integer, String> processNameMap_ = null;
00026     private HashMap<String, Vector<Integer>> processSelectorMap_ = 
00027     new HashMap<String, Vector<Integer>>();
00028     private boolean processNamesInit_ = true;
00029 
00030     private HashMap<String, String> allowedCuts_ = 
00031     new HashMap<String, String>();
00032 
00033     private boolean allowedCutsInit_ = true;
00034 
00038     protected Herwig(String version) {
00039     generatorName = "herwig";
00040     generatorVersion = version;
00041 
00042     }
00043 
00049     public String getProcessSelector(MCProcessType proc) {
00050 
00051     StringBuffer sel = new StringBuffer("");
00052     if(processNamesInit_) initProcessNames();
00053 
00054     Vector<Integer> PIds = proc.getCompatibleProcesses();
00055 
00056     Integer iprocNumber = 1;
00057     boolean found = false;
00058     for(Integer Id: PIds){
00059 
00060         MCProcessType subProc = new MCProcessType(Id);
00061         
00062         Vector<Integer> iprocs = 
00063         processSelectorMap_.get(subProc.getMCProcessName());
00064         
00065         if(iprocs!=null){
00066         found = true;
00067         for(Integer iproc: iprocs){
00068             sel.append("IPROC "+iprocNumber+" = "+iproc+"\n");
00069             ++iprocNumber;
00070         }
00071         sel.append("C\n");
00072         }
00073     }
00074     
00075     if(found) return sel.toString();
00076 
00077     if (proc.getMCProcessName().equals(MCProcessType.HIGHET)){
00078         if (proc.isPhotoproduction()){      
00079         sel.append("IPROC 1 = 5000\n");
00080         sel.append("IPROC 2 = 1500\n");
00081         return sel.toString();
00082         } else if (proc.isPP()){        
00083         sel.append("IPROC 1 = 1500\n");
00084         return sel.toString();
00085         } else if (proc.isGammaGamma()){
00086         sel.append("IPROC 1 = 6000\n");
00087         sel.append("IPROC 2 = 5000\n");
00088         sel.append("IPROC 3 = 1500\n");
00089         return sel.toString();
00090         } else {
00091         return "C Unknown process type";
00092         }
00093     } else if (proc.getMCProcessName().equals(MCProcessType.CHARM)){
00094         if (proc.isPhotoproduction()){      
00095         sel.append("IPROC 1 = 5004\n");
00096         sel.append("IPROC 2 = 1504\n");
00097         return sel.toString();
00098         } else if (proc.isPP()){        
00099         sel.append("IPROC 1 = 1504\n");
00100         return sel.toString();
00101         } else if (proc.isGammaGamma()){
00102         sel.append("IPROC 1 = 6004\n");
00103         sel.append("IPROC 2 = 5004\n");
00104         sel.append("IPROC 3 = 1504\n");
00105         return sel.toString();
00106         } else {
00107         return "C Unknown process type";
00108         }
00109     } else if (proc.getMCProcessName().equals(MCProcessType.BEAUTY)){
00110         if (proc.isPhotoproduction()){      
00111         sel.append("IPROC 1 = 5005\n");
00112         sel.append("IPROC 2 = 1505\n");
00113         return sel.toString();
00114         } else if (proc.isPP()){        
00115         sel.append("IPROC 1 = 1505\n");
00116         return sel.toString();
00117         } else if (proc.isGammaGamma()){
00118         sel.append("IPROC 1 = 6005\n");
00119         sel.append("IPROC 2 = 5005\n");
00120         sel.append("IPROC 3 = 1505\n");
00121         return sel.toString();
00122         } else {
00123         return "C Unknown process type";
00124         }
00125     } else {
00126         return "C Unknown process type";
00127     }
00128     }
00129 
00134     //public String getMCProcessName(HashMap<String,HashMap<Integer,Integer>> parameters) 
00135     public String getMCProcessName(HashMap<String, Object> parameters)
00136     throws JetWebException{
00137 
00138     Integer iproc = (Integer) parameters.get("IPROC");
00139 
00140     //  HashMap<Integer,Integer> iprocArray = parameters.get("IPROC");
00141 
00142     //Integer iproc = iprocArray.get(new Integer(1));
00143     if(iproc==null){
00144         throw new JetWebException
00145         ("IPROC not present in intParameters",
00146          "cedar.jetweb.generator.herwig: getMCProcessType()");
00147     }
00148 
00149     if(processNamesInit_) initProcessNames();
00150 
00151     String processName = processNameMap_.get(iproc);
00152     if(processName==null){
00153         throw new JetWebException
00154         ("Unknown IPROC number = "+iproc,
00155          "cedar.jetweb.generator.herwig: getMCProcessType()");
00156     }
00157 
00158     return processName;
00159     }
00160 
00161 
00162     public boolean processTrumps(Generator gen){
00163     Integer iproc= intParameters.get("IPROC");
00164     if(iproc==1500){
00165         iproc = gen.getIntParameters().get("IPROC");
00166         if(iproc==5000) return true;
00167     }
00168     return false;
00169     }
00170 
00171     public boolean checkParameters(){
00172     return true;
00173     }
00174 
00175     protected String getParticleName(String pName){
00176     return pName;
00177     }
00178 
00179     public void writeSteering(BufferedWriter ofile, Model model, 
00180                   MCProcessType proc) 
00181     throws JetWebException {
00182 
00183     try {
00184         // Common, except PDFs
00185         writeCommonFFKey(ofile,proc);
00186         // Turn on the appropriate HZTool routines
00187         writePapersFFKey(ofile,proc);
00188         // PDFs
00189         writePDFFFKey(ofile,model,proc);
00190         // All the other parameters
00191         writeGenFFKey(ofile,proc);
00192 
00193     } catch (IOException io) {
00194         throw new JetWebException(io,"Herwig.writeSteering failed in write to "+ofile);
00195     }
00196 
00197     }
00198 
00199     private void initAllowedCuts(){
00200     if(!allowedCutsInit_) return;
00201     allowedCutsInit_ = false;
00202     allowedCuts_.put("PTMin", "PTMIN");
00203     }
00204 
00205     //initialises the mapping between iproc and process name strings
00206     private void initProcessNames(){
00207     if(!processNamesInit_) return;
00208     processNamesInit_ = false;
00209 
00210     processSelectorMap_ = new HashMap<String, Vector<Integer>>();
00211 
00212     Vector<Integer> iprocs = new Vector<Integer>();
00213 
00214     iprocs.add(1500);
00215     
00216     processSelectorMap_.put(MCProcessType.PARTONPARTON, iprocs);
00217 
00218     iprocs = new Vector<Integer>();
00219     iprocs.add(1504);
00220     processSelectorMap_.put(MCProcessType.CHARMPARTONPARTON, iprocs);
00221 
00222     iprocs = new Vector<Integer>();
00223     iprocs.add(1505);
00224     processSelectorMap_.put(MCProcessType.BEAUTYPARTONPARTON, iprocs);
00225 
00226     iprocs = new Vector<Integer>();
00227 
00228     iprocs.add(5000);
00229     
00230     processSelectorMap_.put(MCProcessType.PHOTONPARTON, iprocs);
00231 
00232     iprocs = new Vector<Integer>();
00233     iprocs.add(5004);
00234     processSelectorMap_.put(MCProcessType.CHARMPHOTONPARTON, iprocs);
00235 
00236     iprocs = new Vector<Integer>();
00237     iprocs.add(5005);
00238     processSelectorMap_.put(MCProcessType.BEAUTYPHOTONPARTON, iprocs);
00239 
00240     iprocs = new Vector<Integer>();
00241 
00242     iprocs.add(6000);
00243 
00244     processSelectorMap_.put(MCProcessType.PHOTONPHOTON, iprocs);
00245 
00246     iprocs = new Vector<Integer>();
00247     iprocs.add(6004);
00248     processSelectorMap_.put(MCProcessType.CHARMPHOTONPHOTON, iprocs);
00249     
00250     iprocs = new Vector<Integer>();
00251     iprocs.add(6005);
00252     processSelectorMap_.put(MCProcessType.BEAUTYPHOTONPHOTON, iprocs);
00253 
00254     iprocs = new Vector<Integer>();
00255 
00256     iprocs.add(8000);
00257 
00258     processSelectorMap_.put(MCProcessType.MINBIAS, iprocs);
00259 
00260     processNameMap_ = new HashMap<Integer, String>();
00261     
00262     
00263     for(Integer sue=0; sue!=20000; sue+=10000){
00264 
00265         for(Integer iproc=100; iproc!=1146; ++iproc){
00266         processNameMap_.put(iproc+sue, MCProcessType.ANNIHILATION);
00267         }
00268 
00269         processNameMap_.put(1500+sue, MCProcessType.PARTONPARTON);
00270         processNameMap_.put(1504+sue, MCProcessType.CHARMPARTONPARTON);
00271         processNameMap_.put(1505+sue, MCProcessType.BEAUTYPARTONPARTON);
00272         processNameMap_.put(5000+sue, MCProcessType.PHOTONPARTON);
00273         processNameMap_.put(5004+sue, MCProcessType.CHARMPHOTONPARTON);
00274         processNameMap_.put(5005+sue, MCProcessType.BEAUTYPHOTONPARTON);
00275         processNameMap_.put(8000+sue, MCProcessType.MINBIAS);
00276         
00277         for(Integer iproc=9000; iproc!=9131; ++iproc){
00278         processNameMap_.put(iproc+sue, MCProcessType.DIS);
00279 
00280         if(iproc.toString().charAt(3)=='4') 
00281             processNameMap_.put(iproc+sue, MCProcessType.CHARMDIS);
00282         if(iproc.toString().charAt(3)=='5') 
00283             processNameMap_.put(iproc+sue, MCProcessType.BEAUTYDIS);
00284 
00285         if(iproc==9120)
00286             processNameMap_.put(iproc+sue, MCProcessType.CHARMDIS);
00287         if(iproc==9121)
00288             processNameMap_.put(iproc+sue, MCProcessType.BEAUTYDIS);
00289         
00290         
00291         if(iproc==9107) iproc+=3;
00292         if(iproc==9122) iproc+=8;
00293         }
00294     }
00295     
00296     return;
00297     }
00298 
00302     public boolean inModel(String pName){
00303     if (pName.equalsIgnoreCase("IPROC")) return false;
00304     if (pName.equalsIgnoreCase("PTMIN")) return false;
00305     if (pName.equalsIgnoreCase("JIMMY") || 
00306         pName.equalsIgnoreCase("PTJIM") ||
00307         pName.equalsIgnoreCase("PHRAD") ||
00308         pName.equalsIgnoreCase("PRRAD")){
00309         Integer iproc = intParameters.get("IPROC");
00310         if(iproc!=null && iproc==5000){
00311         return false;
00312         }
00313     }
00314     return true;
00315     }
00319     public boolean inProcessType(String pName){
00320     if (pName.equalsIgnoreCase("IPROC")) return true;
00321     return false;
00322     }
00323 
00328     public boolean inCuts(String pName){
00329     if (pName.equalsIgnoreCase("PTMIN")) return true;
00330     return false;
00331     }
00332 
00333     public Herwig addCut(Cut cut){
00334 
00335     if(allowedCutsInit_) initAllowedCuts();
00336 
00337     if(cuts_==null) cuts_ = new CutCollection();
00338 
00339     String cutName = allowedCuts_.get(cut.getName());
00340     
00341     //if cut not known by Herwig then return
00342     if(cutName==null) return this;
00343 
00344     // if existing cut in the collection supersedes this one 
00345     // then don't do anything
00346     if(!cuts_.addCut(cut)) return this;
00347     
00348     realParameters.put(cutName, cut.getValue());
00349 
00350     return this;
00351     }
00352 
00353     public CutCollection getCutCollection(){
00354 
00355     if(!dirtyCuts_) return cuts_;
00356     dirtyCuts_ = false;
00357     cuts_ = new CutCollection();
00358 
00359     if(allowedCutsInit_) initAllowedCuts();
00360 
00361     for(Map.Entry entry: allowedCuts_.entrySet()){
00362         String param = (String)entry.getValue();
00363         String name = (String)entry.getKey();
00364         Double value = realParameters.get(param);
00365 
00366 
00367         Cut tmp = new Cut(name, value);
00368         cuts_.addCut(tmp);
00369     }
00370 
00371     return cuts_;
00372     }
00373 
00374     public Double getPthat(){
00375     
00376     return  realParameters.get("PTMIN"); 
00377     
00378     }
00379     
00380 }
00381 
00382 
00383 /*
00384 
00385 
00386         // Choose ptmin. This should depend upon
00387         // process & generator, not depending on the model.
00388         // i.e. it is the kinematic cut (CKIN(3), PTMIN etc) not a
00389         // model parameter.
00390         if (line.startsWith("PTMIN")) {
00391             line = "PTMIN "+" to be done!";
00392         }
00393 
00394         // Choose ptjim.
00395         if (line.startsWith("PTJIM")) {
00396             line = "PTJIM "+model.getPtjim();
00397         }
00398 
00399         // Choose proton radius
00400         if (line.startsWith("PRRAD")) {
00401             line = "PRRAD "+model.getProtonRadius();
00402         }
00403         // Choose proton radius
00404         if (line.startsWith("PHRAD")) {
00405             line = "PHRAD "+model.getPhotonRadius();
00406         }
00407         // Choose underlying event model
00408         if (line.startsWith("JIMMY")) {
00409             line = "JIMMY "+model.getJimmy();
00410         }
00411         // Choose proton & photon intrinsic kt
00412         if (line.startsWith("PTRMS ")) {
00413             line = "PTRMS "+model.getPtrms();
00414         }
00415         // Choose Qspac
00416         if (line.startsWith("QSPAC")) {
00417             line = "QSPAC "+model.getQspac();
00418         }
00419         // Choose CLMAX
00420         if (line.startsWith("CLMAX")) {
00421             line = "CLMAX "+model.getClmax();
00422         }
00423         // Choose QCDLAM
00424         if (line.startsWith("QCDLAM")) {
00425             line = "QCDLAM "+model.getQcdlam();
00426         }
00427         // Choose VQCUT
00428         if (line.startsWith("VQCUT")) {
00429             line = "VQCUT "+model.getVqcut();
00430         }
00431         // Choose PRSOF
00432         if (line.startsWith("PRSOF")) {
00433             line = "PRSOF "+model.getPrsof();
00434         }
00435         // Choose IOPREM
00436         if (line.startsWith("IOPREM")) {
00437             line = "IOPREM "+model.getIoprem();
00438         }
00439         // Choose BTCLM
00440         if (line.startsWith("BTCLM")) {
00441             line = "BTCLM "+model.getBtclm();
00442         }
00443         // Choose PHAD
00444         if (line.startsWith("PHAD")) {
00445             line = "PHAD "+model.getPhad();
00446         }
00447         // Choose Psplt1
00448         if (line.startsWith("PSPLT1")) {
00449             line = "PSPLT1 "+model.getPsplt1();
00450         }
00451         // Choose Psplt2
00452         if (line.startsWith("PSPLT2")) {
00453             line = "PSPLT2 "+model.getPsplt2();
00454         }
00455 
00456         // Choose the process for HERWIG
00457         // This is a hack. 
00458         // It needs to be done more generally using a proper Generator class.
00459         if (line.startsWith("IPROC")){
00460             if (proc.getMCProcessName().equals(MCProcessType.HIGHET)){
00461             // Note that SUE is still on. To turn it off,
00462             // PRSOF has to be set to 0.
00463             line = "IPROC 1500";
00464             }
00465         }
00466 
00467         newCards.write(line);
00468         newCards.newLine();
00469 
00470         //  Now the detailed parameter list for PYTHIA.
00471         if (line.startsWith("c Detailed Pythia parameters")){
00472 
00473             Map mstp = new TreeMap(model.getMstp());
00474             Map parp = new TreeMap(model.getParp());
00475 
00476             Iterator iparam = mstp.entrySet().iterator();
00477             while (iparam.hasNext()){
00478             Entry mstpEntry = (Entry)iparam.next();
00479 
00480             Integer mstpValue = (Integer)mstpEntry.getValue();
00481             Integer key = (Integer)mstpEntry.getKey();
00482             if (mstpValue!=null) {
00483                 newCards.write("MSTP "+key+"="+mstpValue);
00484                 newCards.newLine();
00485             }
00486             }
00487  
00488             iparam = parp.entrySet().iterator();
00489             while (iparam.hasNext()){
00490             Entry parpEntry = (Entry)iparam.next();
00491 
00492             Double parpValue = (Double)parpEntry.getValue();
00493             Integer key = (Integer)parpEntry.getKey();
00494             if (parpValue!=null) {
00495                 newCards.write("PARP "+key+"="
00496                        +JetWebConfig.getFormat().format(parpValue.floatValue()));
00497                 newCards.newLine();
00498             }
00499             } 
00500 
00501             Map mstj = new TreeMap(model.getMstj());
00502             Map parj = new TreeMap(model.getParj());
00503 
00504             iparam = mstj.entrySet().iterator();
00505             while (iparam.hasNext()){
00506             Entry mstjEntry = (Entry)iparam.next();
00507 
00508             Integer mstjValue = (Integer)mstjEntry.getValue();
00509             Integer key = (Integer)mstjEntry.getKey();
00510             if (mstjValue!=null) {
00511                 newCards.write("MSTJ "+key+"="+mstjValue);
00512                 newCards.newLine();
00513             }
00514             }
00515  
00516             iparam = parj.entrySet().iterator();
00517             while (iparam.hasNext()){
00518             Entry parjEntry = (Entry)iparam.next();
00519 
00520             Double parjValue = (Double)parjEntry.getValue();
00521             Integer key = (Integer)parjEntry.getKey();
00522             if (parjValue!=null) {
00523                 newCards.write("PARJ "+key+"="
00524                        +JetWebConfig.getFormat().format(parjValue.floatValue()));
00525                 newCards.newLine();
00526             }
00527             } 
00528         }
00529 
00530         if (line.startsWith("c List of HZTOOL routines")){
00531             //newCards.write(line);
00532             //newCards.newLine();
00533             HashSet paperSwitches = new HashSet(PaperBank.getNPapers());
00534 
00535             Enumeration plotList = PaperBank.getAllPlots();
00536             while (plotList.hasMoreElements()){
00537             RealPlot plot = (RealPlot)plotList.nextElement();
00538             if (plot.getCollisionId()==collision.getId()){
00539                 paperSwitches.add(new Integer(plot.getPaperId()));
00540             }
00541             }
00542             for (Iterator papersOn = paperSwitches.iterator();papersOn.hasNext();){
00543             newCards.write("ROUTINE "+(Integer)papersOn.next()+" = TRUE");
00544             newCards.newLine();
00545             }
00546             
00547 
00548         }
00549         }
00550 
00551 
00552 
00553         */
00554 
00555     /*
00556     // Special check on some HERWIG parameters to make sure
00557     // they are consistent.  Must all move to the herwig class
00558     // soon
00559     if (getGenerator().equalsIgnoreCase("herwig")){
00560         try {
00561         
00562         // If JIMMY is off, set its parameters to the default values.
00563         if ( getRunSeries().getJimmy().intValue()==0){
00564             if (getRunSeries().getMCProcessType().hasPhoton()){
00565             runSeries.setPhad(JetWebConfig.DefaultPhad);
00566             runSeries.setPhotonRadius(JetWebConfig.DefaultPhrad);
00567             }
00568             if (getRunSeries().getMCProcessType().hasProton()){
00569             runSeries.setProtonRadius(JetWebConfig.DefaultPrrad);
00570             }
00571             runSeries.setPtjim(JetWebConfig.DefaultPtjim);
00572         }
00573         
00574         } catch (Exception e){
00575         valid=false;
00576         System.out.println("Logfile WARNING: badly populated HERWIG params");
00577         }
00578         
00579     }
00580     */

Generated Wed Jan 17 09:14:27 GMT 2007