Example #1
0
//Function needed to dEdx cut described below
Float_t choose_dedx(Particle *particle, TString system)
{
	static Int_t vtpc1_part;
	static Int_t vtpc2_part;
	static Int_t mtpc_part;

	if(!(system.CompareTo("pp")))
		return particle->GetdEdx();
	else if(!(system.CompareTo("PbPb")))
	{
		vtpc1_part = particle->GetNdEdxVtpc1();
		vtpc2_part = particle->GetNdEdxVtpc2();
		mtpc_part = particle->GetNdEdxMtpc();

		//std::cout << "dE/dx: VTPC1 part: " << vtpc1_part << "\tVTPC2 part: " << vtpc2_part << "\tMTPC part: " << mtpc_part << std::endl;
		if((vtpc1_part == 0) && (vtpc2_part == 0) && (mtpc_part == 0))
		{
			std::cout << "WTF? Particle with no dE/dx information!" << std::endl;
			return 0;
		}
		else
		{
			if(mtpc_part > 0)
				return (particle->GetdEdxMtpc());
			else if(vtpc2_part >= vtpc1_part)
				return (particle->GetdEdxVtpc2());
			else
				return (particle->GetdEdxVtpc1());
		}
	}
	else
		return -1;
}
BranchBase::BranchBase(TString input_files)
{
	TString sMC = "MC";
	TString sDataHI = "DATA_hi";
	TString sDataPP = "DATA_pp";
	TString runType = "";

  	TChain * chain = new TChain("HeavyIonD3PD","");

  	//bool dataType = openFromFileList(input_files, chain);
  	runType = openFromFileList(input_files, chain);
	//if(dataType) runType = "DATA";
	//else runType = "MC";

	if (runType.CompareTo(sMC)==0) {
		isMC = true;
		std::cout << "Skimming Monte Carlo." << std::endl;
	}
	else if (runType.CompareTo(sDataHI)==0) {
		isData = true;
		std::cout << "Skimming Heavy Ion Data." << std::endl;
	}
	else if (runType.CompareTo(sDataPP)==0) {
		isData = true;
		isPP   = true;
		std::cout << "Skimming pp @2.76TeV Data." << std::endl;
	}
	else {
		std::cout << "Must choose DATA or MC. Abort." << std::endl;
		exit(0);
	 }	
  	//Init(chain);
	#include "SetBranchAddress.h"
}
int main(int argc, const char * argv[]){

    TupleMaker_min tm; 
    if (argc < 2) {help(); return 1;}
    TString tmp = argv[1];
    if (!tmp.CompareTo("-h") || !tmp.CompareTo("--help")) {
        help();
        return 0;
    } else if (!tmp.CompareTo("-w")) {
        if (argc < 5 ) { help(); return 1;}
        //USAGE 2
        tm.output_fname = argv[2];
        tm.input_fname = argv[3];
        for (size_t i=4; i<argc; i++) tm.weights_fname.push_back(argv[i]);
        tm.MakeNtupleWithWeights();
        return 0;
    } else if(argc>=2) {
        // USAGE 1
        //tm.ebeam       = ResbosRootNtuple::GetConfValue<double>("config_dump.txt","ebeam");
        tm.input_fname = argv[1];
        if (argc > 2) for (int i_wt = 2; i_wt < argc; i_wt++){
            tm.weights_fname.push_back(argv[i_wt]);
        }
        tm.MakeProfile();
        return 0;
    } else {
        help(); return 1;
    }


    return 0;
}
void CompileCorrectGammaV2(){
    
     
     //*****************************************************************************************
    // Find out which user is running the code and set RooUnfold directory accordingly
    // RooUnfold is a separate piece of software which needs to be compiled on your system
    // Please download it from https://github.com/skluth/RooUnfold and compile it!
    // Afterwards you have to add the location of the software here for your system
    //*****************************************************************************************
    TString homedirectory = gSystem->HomeDirectory();
	cout << "***************************************" << endl;
	cout << "HomeDirectory: " << homedirectory.Data() << endl;
	cout << "***************************************" << endl;
    if (homedirectory.CompareTo("/home/admin1") == 0){   
        gSystem->AddIncludePath("-I/home/admin1/leardini/photonconv/AnalysisSoftware/RooUnfold/RooUnfold-master/RooUnfold/src"); 
        gSystem->Load("/home/admin1/leardini/photonconv/AnalysisSoftware/RooUnfold/RooUnfold-master/libRooUnfold");
    } else if (homedirectory.CompareTo("/home/fbock") == 0){   
        gSystem->AddIncludePath("-I/home/fbock/Photon/Software/photonconv/AnalysisSoftware/RooUnfold/src"); 
		gSystem->Load("/home/fbock/Photon/Software/photonconv/AnalysisSoftware/RooUnfold/libRooUnfold");
	} else if (homedirectory.CompareTo("/home/daniel") == 0){
		gSystem->AddIncludePath("-I/home/daniel/data/work/photonconv/AnalysisSoftware/RooUnfold/src");
		gSystem->Load("/home/daniel/data/work/photonconv/AnalysisSoftware/RooUnfold/libRooUnfold");
    } else if (homedirectory.CompareTo("/Users/lucasaltenkaemper") == 0) {
        gSystem->AddIncludePath("-I/Volumes/MacintoshHD/Documents/Studium/Master/Thesis/photonconv/AnalysisSoftware/RooUnfold/src");
        gSystem->Load("/Volumes/MacintoshHD/Documents/Studium/Master/Thesis/photonconv/AnalysisSoftware/RooUnfold/libRooUnfold");
    } else {
        cout << "You have not defined where RooUnfold can be found on your system! This macro can't run without it!" << endl;
        return;
    }

    gROOT->LoadMacro("TaskV1/CorrectGammaV2.C+");

    return;
}
Example #5
0
void DisplayTele(TXMLEngine* xml, XMLNodePointer_t node, Int_t level, const char* search ) 
{
 
  TString tel;
  TString sat;

  tel.Append( xml->GetNodeName(node)  );
  //    printf("<%s>\n", tel.Data() );


  if ( (leveloffset<0) ){
    if (tel.CompareTo( search )==0){
      leveloffset=level;  sprintf( output, "%s", "" );
      //   printf("Found level offset.... ==%d\n", leveloffset );
    }else{//neni to on, hledej
       // display all child nodes   
      XMLNodePointer_t child = xml->GetChild(node);
      while (child!=0) {
	DisplayTele(xml, child, level+1, search ); 
         child = xml->GetNext(child);
      }//while
    }
  }// HLEDEJ dokud neinicializujes



  if (leveloffset>=0){ // 
    if ( tel.CompareTo( search  )==0){
      //      printf("%*c<%s>\n",level+1,' ', addr[ level- leveloffset ].c_str()   );
      // display all child nodes   
      if (getattrlevel<=level){
	//	  printf("reached attr  level .... ==%d\n", level );

	// display attributes
	XMLAttrPointer_t attr = xml->GetFirstAttr(node);
	while (attr!=0) {
	  sat=xml->GetAttrName(attr);
	  //	  printf(" Checking   attr =%s/%s\n", sat.Data(), addr[ getattrlevel ].c_str()  );
	  if ( sat.CompareTo( addr[ getattrlevel ].c_str() )==0){
	    sprintf( output, "%s",   xml->GetAttrValue(attr) );
	    printf("%*c  attr <%s = %s>\n",level+1,' ',
		   sat.Data() ,  output  );
	  }// attr OK
	  // printf("%*c attr: %s value: %s\n",level+1,' ', xml->GetAttrName(attr), xml->GetAttrValue(attr));
	  attr = xml->GetNextAttr(attr);  
	}//display attributes
     }else{ 
      XMLNodePointer_t child = xml->GetChild(node);
      while (child!=0) {
	//	printf("searching %s\n", addr[level- leveloffset +1].c_str()  );
	DisplayTele(xml, child, level+1, addr[level- leveloffset +1].c_str() ); 
         child = xml->GetNext(child);
      }//reached attrlevel
      }//else attrlevel  
    }//compare OK
    
  }
  return;
}//DisplayTele------------------------------------------
Example #6
0
Bool_t InputHandlerSetup(TString format = "esd", Bool_t useKine = kTRUE)
{
  format.ToLower();

  IlcAnalysisManager *mgr = IlcAnalysisManager::GetAnalysisManager();

  IlcAnalysisDataContainer *cin = mgr->GetCommonInputContainer();

  if (cin) return;

  if (!format.CompareTo("esd"))
    {
      IlcESDInputHandler *esdInputHandler = 
	dynamic_cast<IlcESDInputHandler*>(IlcAnalysisManager::GetAnalysisManager()->
					  GetInputEventHandler());

      if (!esdInputHandler)
	{
	  Info("CustomAnalysisTaskInputSetup", "Creating esdInputHandler ...");
	  esdInputHandler = new IlcESDInputHandler();
	  mgr->SetInputEventHandler(esdInputHandler);
	}

      if (useKine)
	{
	  IlcMCEventHandler* mcInputHandler = 
	    dynamic_cast<IlcMCEventHandler*>(IlcAnalysisManager::GetAnalysisManager()->
					     GetMCtruthEventHandler());

	  if (!mcInputHandler)
	    {
	      Info("CustomAnalysisTaskInputSetup", "Creating mcInputHandler ...");
	      IlcMCEventHandler* mcInputHandler = new IlcMCEventHandler();
	      mgr->SetMCtruthEventHandler(mcInputHandler);
	    }
	}

    }
  else if (!format.CompareTo("aod"))
    {
      IlcAODInputHandler *aodInputHandler = 
	dynamic_cast<IlcAODInputHandler*>(IlcAnalysisManager::GetAnalysisManager()->
					  GetInputEventHandler());

      if (!aodInputHandler)
	{
	  Info("CustomAnalysisTaskInputSetup", "Creating aodInputHandler ...");
	  aodInputHandler = new IlcAODInputHandler();
	  mgr->SetInputEventHandler(aodInputHandler);
	}
    }
  else
    {
      IlcWarning("Wrong input format!!! Only ESD and AOD are supported. Skipping Task ...");
      return kFALSE;
    }

  return kTRUE;
}
Example #7
0
void SetupAnalysis(TString mode,
		   TString analysisMode="full",
		   Bool_t useMC = kFALSE,
		   Int_t nEvents=1.0*1e9, 
		   Int_t nEventsSkip=0,
		   TString format="esd")
{
  
  // ILC stuff
  IlcAnalysisManager *mgr = IlcAnalysisManager::GetAnalysisManager();
  if (!mgr) mgr = new IlcAnalysisManager("CAF train");
  
  // Create and configure the alien handler plugin 
  gROOT->LoadMacro("CreateAnalysisPlugin.C"); 
  IlcAnalysisGrid *alienHandler = CreateAnalysisPlugin(analysisMode);   
  if (!alienHandler) return;
  mgr->SetGridHandler(alienHandler);
  
  // input handler for esd or AOD, real or MC data
  InputHandlerSetup(format,useMC);

  // physics selection
  if(!format.CompareTo("esd")){
    gROOT->LoadMacro("$ILC_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C");
    IlcPhysicsSelectionTask* physSelTask = AddTaskPhysicsSelection(kFALSE);
    if(useMC) physSelTask->GetPhysicsSelection()->SetAnalyzeMC();   
    IlcPhysicsSelection* physSel = physSelTask->GetPhysicsSelection();
    physSel->AddBackgroundIdentification(new IlcBackgroundSelection());
  }
  
  gROOT->ProcessLine(Form(".include %s/include",gSystem->ExpandPathName("$ILC_ROOT")));
  
  gROOT->LoadMacro("IlcAnalysisTaskEfficiency.cxx+g");
  
  // load and run AddTask macro
  gROOT->LoadMacro("AddTaskEfficiency.C");
  

  IlcAnalysisTaskSE* task1 = AddTaskEfficiency(-1);
  if(!task1){
    Printf("AddTask could not be run.");
  }

  // Run analysis
  mgr->InitAnalysis();
  
  if ((!mode.CompareTo("proof")) ||(!mode.CompareTo("local"))) {
    mgr->StartAnalysis(mode.Data(),nEvents,nEventsSkip);
  }
  else {
    mgr->StartAnalysis(mode.Data());
    
  }
  
}
Bool_t AddAMEventMixingTest(TString analysisSource = "proof", TString analysisMode = "test",TString input="aod",TString inputMC="", TString postfix = "",TString idStr="0")
{
  
   Bool_t useEventMixingPar      = 1;
   Int_t usePhysSel              = 1;
   Bool_t useMC = !inputMC.CompareTo("mc");

   input.ToLower();

   // ALICE stuff
   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
   if (!mgr) { Printf("Error[AddAMEventMixingTest] mgr is null !!!"); return kFALSE; }
   
   
   AliAnalysisGrid *analysisPlugin = mgr->GetGridHandler();
   if (!analysisPlugin) { Printf("Error[AddAMEventMixingTest] : analysisPlugin is null !!!"); return kFALSE; }

   TString myAdditionalLibs;
   if (useEventMixingPar) { AliAnalysisAlien::SetupPar("EventMixing"); myAdditionalLibs += " EventMixing.par"; }
   else { gSystem->Load("libEventMixing.so"); myAdditionalLibs += " libEventMixing.so"; }
   
   gROOT->LoadMacro("AliAnalysisTaskEx02.cxx++g");
   analysisPlugin->SetAnalysisSource("AliAnalysisTaskEx02.cxx+");
   myAdditionalLibs+=" AliAnalysisTaskEx02.h AliAnalysisTaskEx02.cxx";
   analysisPlugin->SetAdditionalLibs(myAdditionalLibs.Data());
   

  AliMultiInputEventHandler *multiInputHandler = mgr->GetInputEventHandler();

   if (usePhysSel && !input.CompareTo("esd")) {
      gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C");
      AddTaskPhysicsSelection(useMC);

      // maybe we can put it in $ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C
      AliMultiInputEventHandler *multiIH = dynamic_cast<AliMultiInputEventHandler *>(mgr->GetInputEventHandler());
      if (multiIH){
         AliESDInputHandler *esdIH = dynamic_cast<AliESDInputHandler *>(multiIH->GetFirstInputEventHandler());
         if (esdIH) esdIH->SetEventSelection(multiIH->GetEventSelection());
         AliAODInputHandler *aodIH = dynamic_cast<AliAODInputHandler *>(multiIH->GetFirstInputEventHandler());
         if (aodIH) aodIH->SetEventSelection(multiIH->GetEventSelection());
      }
   }

  // add mixing handler (uncomment to turn on Mixnig)
  gROOT->LoadMacro("AddMixingHandler.C");
  AddMixingHandler(multiInputHandler, input, useMC,postfix);

   // load and run AddTask macro
   gROOT->LoadMacro("AddEventMixingTestTask.C");
   AddEventMixingTestTask(input, useMC, postfix);

   return kTRUE;
}
Example #9
0
/******************************************************************************
 * CutElectronN::CutElectronN(EventContainer *EventContainerObj, TString electronType)    *
 *                                                                            *
 * Parameterized Constructor                                                  *
 *                                                                            *
 * Input:  Event Object class                                                 *
 * Output: None                                                               *
 ******************************************************************************/
CutElectronN::CutElectronN(EventContainer *EventContainerObj, TString electronTypePassed)
{
  // Check electronType parameter
  if( electronTypePassed.CompareTo("All") && electronTypePassed.CompareTo("UnIsolated") && electronTypePassed.CompareTo("Isolated") && 
      electronTypePassed.CompareTo("Tight") && electronTypePassed.CompareTo("PtEtaCut") && electronTypePassed.CompareTo("Veto") ){
    std::cout << "ERROR " << "<CutElectronN::CutElectronN()> " 
	      << "Must pass Tight, PtEtaCut, Veto, All, UnIsolated, or Isolated to constructor" << std::endl;
    exit(8);
  } //if
  electronType = electronTypePassed;

  // Set Event Container
  SetEventContainer(EventContainerObj);
} // CutElectronN
Example #10
0
bool NonFriendBranch(TTree *t, TString branchName)
{
  if (t->GetBranch(branchName)==0) return true;
  TString branchtree = t->GetBranch(branchName)->GetTree()->GetName();
  TString treename = t->GetName();
  return branchtree.CompareTo(treename) == 0;
}
Example #11
0
AliAnalysisAlien *CreateGridHandler(){
        //
        // Setup main settings of the Alien plugin
        //
        AliAnalysisAlien *plugin = new AliAnalysisAlien();
        plugin->SetRunMode(g_plugin_mode.Data());
        if(!g_plugin_mode.CompareTo("Terminate"))
                plugin->SetMergeViaJDL(kFALSE);
        else
                plugin->SetMergeViaJDL(kTRUE);
        plugin->SetOverwriteMode();
        plugin->SetNtestFiles(1);

        plugin->SetAPIVersion("V1.1x");
        plugin->SetROOTVersion(g_root_version.Data());
        plugin->SetAliROOTVersion(g_aliroot_version.Data());

        plugin->SetOutputToRunNo();
        plugin->AddIncludePath("-I. .I$ALIEN_ROOT/api/lib -I$ROOTSYS/lib -I$ROOTSYS/include -I$ALICE_ROOT/include -I$ALICE_ROOT/PWGHF/ -I$ALICE_ROOT/PWGHF/hfe/macros -I$ALICE_ROOT/PWGHF/hfe -I$ALICE_ROOT/ANALYSIS -I$ALICE_ROOT/TENDER/Tender -I$ALICE_ROOT/TENDER/TenderSupplies -I$ALICE_ROOT/PWG/ -I$ALICE_ROOT/PWG/FLOW -I$ALICE_ROOT/PWG/Base -I$ALICE_ROOT/PWG/Tasks");
        plugin->SetAdditionalLibs("libGui.so  libXMLParser.so libSTEERBase.so libESD.so libAOD.so libCDB.so libANALYSIS.so libANALYSISalice.so libCORRFW.so  libPWGflowBase.so libPWGflowTasks.so libPWGHFhfe.so libTender.so libProof.so libRAWDatabase.so libSTEER.so libTOFbase.so libPWGTRD.so");
   
        plugin->SetDefaultOutputs(kFALSE);
        plugin->SetOutputFiles("AnalysisResults.root"); 
        plugin->SetExecutableCommand("aliroot -b -q");
        plugin->SetTTL(30000);
        plugin->SetInputFormat("xml-single");
        plugin->SetPrice(1);      
        plugin->SetSplitMode("se");
        return plugin;
}
Example #12
0
void RsnSetData(AliAnalysisAlien *plugin,TString dsConf,Int_t numRuns = 1000,Int_t numRunsSkip=0,Int_t maxRunsPerMaster = 1000) {

   Bool_t dsFound = kTRUE;
   Int_t nRunsPerMaster = 0;

   Bool_t valid = kTRUE;
   TString legoTrainPath = AliAnalysisManager::GetGlobalStr("rsnLegoTrainPath",valid);

   if (gSystem->AccessPathName(dsConf.Data())) dsConf.Prepend(Form("%s/",legoTrainPath.Data()));
   dsConf = gSystem->ExpandPathName(dsConf.Data());

   if (dsConf.Contains(".txt")) {
      ifstream in;
      in.open(dsConf.Data());
      if (!in.is_open()) Fatal("RsnSetData",Form("File %s was not found !!!",dsConf.Data()));
      Printf("DS config file : %s",dsConf.Data());
      TString line;
      Bool_t isRun = kFALSE;
      while (in.good())
      {
         in >> line;
         if (line.IsNull()) continue;
         if (line.Contains("BASE")) {
            GetParameterFromConfig(line);
            plugin->SetGridDataDir(line.Data());
            Printf("BASE -> %s",line.Data());
            continue;
         }
         if (line.Contains("PREFIX")) {
            GetParameterFromConfig(line);
            plugin->SetRunPrefix(line.Data());
            Printf("PREFIX -> %s",line.Data());
            continue;
         }
         if (line.Contains("DATA_PATTERN")) {
            GetParameterFromConfig(line);
            plugin->SetDataPattern(line.Data());
            Printf("DATA_PATTERN -> %s",line.Data());
            continue;
         }
         if (!line.CompareTo("RUNS")) {
            isRun = kTRUE;
            in >> line;
         }
         if (isRun) {
            if (numRunsSkip>0) {
               numRunsSkip--;
               continue;
            } else {
               if (nRunsPerMaster < numRuns ) {
                  Printf("Adding RUN : %s",line.Data());
                  plugin->AddRunNumber(line.Data());
                  nRunsPerMaster++;
               } else {
                  break;
               }

            }
         }
      }
Example #13
0
//___________________________________________________________
void runAlien(TString data, TString mode = "test", Bool_t MC = kFALSE){  
  if(!gSystem->Getenv("ALICE_ROOT")){
    printf("AliRoot has to be initialized\n");  
    return;
  }
  
  // check for valid modes
  const int kModes = 5;
  TString allowed_modes[kModes] = {"proof", "prooftest", "test", "full", "submit"}; 
  Bool_t isValid = kFALSE;
  mode.ToLower();
  for(int imode = 0; imode < kModes; imode++){
    if(!mode.CompareTo(allowed_modes[imode])) isValid = kTRUE;
  }
  if(!isValid){
    printf("invalid analysis mode selected\n");
    return;
  }
  analysis_mode = mode; 
  Bool_t proofmode = mode.Contains("proof");
  // libraries to be loaded
  gSystem->Load("libANALYSIS");
  gSystem->Load("libANALYSISalice");
  gSystem->Load("libCORRFW");
  gSystem->Load("libPWGhfe");
  
  // Create Analysis Manager
  AliAnalysisManager *runAnalysis = new AliAnalysisManager("Heavy Flavour Electron Analysis");
  runAnalysis->SetCommonFileName(output_file.Data());
  runAnalysis->SetInputEventHandler(new AliESDInputHandler); 
  if(MC) runAnalysis->SetMCtruthEventHandler(new AliMCEventHandler);
  AliAnalysisAlien *alienhandler = CreateAlienHandler(proofmode);
  printf("alienhandler %p\n", alienhandler);
  runAnalysis->SetGridHandler(alienhandler);
  //return;
  
  // Specify input (runs or dataset)
  if(!proofmode){
    // Query sample ID and runs
    TString sample;
    TArrayI listofruns;
    DecodeDataString(data, sample, listofruns);
    AddInput(alienhandler, sample, listofruns, MC);
  } else {
    alienhandler->SetProofDataSet(data);
  }

  // Add Tasks
  gROOT->LoadMacro(Form("%s/OADB/macros/AddTaskPhysicsSelection.C", gSystem->Getenv("ALICE_ROOT")));
  gROOT->LoadMacro(Form("%s/PWG3/hfe/macros/AddTaskHFE.C", gSystem->Getenv("ALICE_ROOT")));
  AddTaskPhysicsSelection(MC);
  AddTaskHFE();     // @TODO: MC and PbPb flag to be fixed

  // Run Analysis
  TString anamode = proofmode ? "proof" : "grid";
  if(runAnalysis->InitAnalysis()){
    runAnalysis->PrintStatus();
    runAnalysis->StartAnalysis(anamode);
  }
}
Example #14
0
bool IsMC(const TString &val){
        // 
        // Determine whether sample is MC or Data
        //
        if(!val.CompareTo("MC")) return true;
        return false;
}
vector<double>  AlphaTCut_pushback( TString AlhaTBin){
  vector<double> hname;
  if( AlhaTBin.CompareTo("g055") == 0 ){
    hname.push_back(0.55);
    hname.push_back(1E30);
  }
  if( AlhaTBin.CompareTo("052To053") == 0 ){
    hname.push_back(0.52);
    hname.push_back(0.53);
  }
  if( AlhaTBin.CompareTo("053To055") == 0 ){
    hname.push_back(0.53);
    hname.push_back(0.55);
  }
  return hname;
}
Example #16
0
Bool_t RunAnalysisManager(TString anSrc = "proof", TString anMode = "test", Long64_t nEvents = 1e10, Long64_t nSkip = 0) {

   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();

   if (!mgr) { Printf("Error [RunAnalysisManager] : mgr is null !!!"); return kFALSE; }

   // Run analysis
   mgr->InitAnalysis();
   mgr->PrintStatus();

   if ((!anSrc.CompareTo("proof")) || (!anSrc.CompareTo("local"))) {
      mgr->StartAnalysis(anSrc.Data(), nEvents, nSkip);
   } else {
      mgr->StartAnalysis(anSrc.Data());
   }

   return kTRUE;
}
Example #17
0
double GetWeight(TString filename){

  double wt =0.0;
  for(int i=0; i<nGen; i++) {
    TString st2 = basedir + inFileNames[i];
    if(  filename.CompareTo(st2) == 0) wt = weight[i]; 
  }

  return wt;
}
Example #18
0
Bool_t CreateInputHandlers(TString input,TString inputMC,Bool_t useAODOut=kFALSE,Bool_t useMultiHandler=kTRUE) {

   input.ToLower();
   inputMC.ToLower();

   Bool_t useMC = !inputMC.CompareTo("mc");


   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
   if (!mgr) { Printf("Error [CreateInputHandlers] : mgr is null !!!"); return kFALSE; }

   if (useMultiHandler) {
      AliMultiInputEventHandler *inputHandler = new AliMultiInputEventHandler();
      if (!input.CompareTo("esd")) {
         Printf("Adding ESD Input Handler ...");
         inputHandler->AddInputEventHandler(new AliESDInputHandler());
         if (useMC) inputHandler->AddInputEventHandler(new AliMCEventHandler());
      } else if (!input.CompareTo("aod")) {
         inputHandler->AddInputEventHandler(new AliAODInputHandler());
      }

      mgr->SetInputEventHandler(inputHandler);
   } else {
      if (!input.CompareTo("esd")) {
         mgr->SetInputEventHandler(new AliESDInputHandler());
         if (useMC) mgr->SetMCtruthEventHandler(new AliMCEventHandler());
      } else if (!input.CompareTo("aod")) {
         mgr->SetInputEventHandler(new AliAODInputHandler());
      }
   }

   if (useAODOut) {
      AliAODHandler *aodHandler   = new AliAODHandler();
      aodHandler->SetOutputFileName("AliAOD.root");
      mgr->SetOutputEventHandler(aodHandler);
   }

   return kTRUE;
}
Example #19
0
void runLocal(TString dataset, TString treename = "", Long64_t nentries=TChain::kBigNumber,  Long64_t firstentry = 0)
{
	ProofAna* ana = new ProofAna();

	//Need to provide a TList for local running
	TList* list = new TList();
	ana->SetInputList(list);

	// Load dataset manager stuff, uses same local datasets as PROOF-Lite by design
	TString defaultdir(gSystem->HomeDirectory());
	defaultdir.Append("/.proof");
	TString dsetdir(gEnv->GetValue("ProofLite.Sandbox",defaultdir.Data()));
	dsetdir.Append("/datasets");
	dsetdir.Prepend("dir:");
	TDataSetManagerFile mgr(dsetdir);

	TString dsetfile(dataset);
	dsetfile.Append(".txt");
	dsetfile.Prepend("../filelists/");

	//Register dataset, if non-existent
	if(!mgr.ExistsDataSet(dataset)) {
		TFileCollection* dset = new TFileCollection(dataset,"",dsetfile);
		mgr.RegisterDataSet(dataset,dset,"V"); //This seems to return true regardless of success or failure at the moment
		if(treename.CompareTo("")!=0) {
			cout << "Setting default tree to " << treename << " (local and lite running)" << endl;
			TProof* lite = TProof::Open("lite://");
			if(lite->SetDataSetTreeName(dataset,treename)) {
				cout << "Failure to set default tree to " << treename << endl;
				return;
			}
			delete lite;
		}
	}
	mgr.ShowDataSets();

	// And yes, all this dataset garbage was to get the default tree name
	TFileCollection* dset = mgr.GetDataSet(dataset);
	TString defaultTree = dset->GetDefaultTreeName();

	// Make TChain from TFileCollection...doesn't seem like there is a more direct way
	if(defaultTree.First("/")==0) defaultTree.Remove(0,1);
	TChain* T = new TChain(defaultTree);
	TList* filelist = (TList*)dset->GetList();
	TIter next(filelist);
	TFileInfo* fileinfo = 0;
	while ((fileinfo = (TFileInfo*)next())) T->AddFile(fileinfo->GetCurrentUrl()->GetUrl());

	// Process TChain
	T->Process(ana,"", nentries, firstentry);
}
Example #20
0
int checkoutfilelist()
{
	TString outfilelist = "outfilelist.list";
//*************************************************************************************************
	TString infilename = 0;
	TString outfilename1 = 0; // good file
	TString outfilename2 = 0; // bad  file
	TString goodbye	="Goodbye";
	TString current="NULL";
	int i=0;

	cout<<"========================================================="<<endl;
	cout<<"    Checking : "<<endl;
	cout<<"========================================================="<<endl;

	TString rmBad  = Form("rm -r Badfilelist.log");	system(rmBad.Data());
	TString rmGood = Form("rm -r Goodfilelist.log");system(rmGood.Data());

	ifstream inlist;inlist.open(outfilelist.Data(),ios::in);
	if(!inlist){cerr<<"outfilelist.open failed!"<<endl;return 0;}

	for(int i=0;;i++)
	{
		inlist>>infilename;
		if(inlist.eof())break;
		if(i%100==0) cout<<"Processing No."<<i<<endl;
		outfilename1	= Form("Goodfilelist.log"); // good file
		outfilename2	= Form("Badfilelist.log"); // bad  file

		ifstream infile;	infile.open(infilename.Data(),ios::in);	if(!infile) cerr<<"infile.open failed!"<<endl;
		ofstream outfile1;	outfile1.open(outfilename1.Data(),ios::app);if(!outfile1)cerr<<"outfile1.open failed!"<<endl;
		ofstream outfile2;	outfile2.open(outfilename2.Data(),ios::app);if(!outfile2)cerr<<"outfile2.open failed!"<<endl;

		infile.seekg(-9,ios::end);
//		char c;
//		c=infile.peek();
//		cout<<"peek="<<c<<endl;
		infile>>current;
//		cout<<current<<endl;
//		cout<<goodbye<<endl;

		if(goodbye.CompareTo(current)!=0) outfile2<<infilename<<endl;
		else outfile1<<infilename<<endl;
		infile.close();
		outfile1.close();
		outfile2.close();
	}
	return 0;
}
Example #21
0
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
void check_for_file(TString &prev_line, TString txt = "../../data/daqcapture.dq0")
{
	char txtline[256];

	ifstream captured_file(txt);
	captured_file.getline(txtline,sizeof(txtline));
	if(strlen(txtline)==0)
	{	
		cout<<"Error reading "<<txt<<endl;
		return;
	}
	//cout<<txtline<<"\n";
	if( !prev_line.CompareTo(txtline) ) return;
	cout<<"File changed from "<<prev_line<<" to "<<txtline<<endl;
	prev_line = txtline;
	txt = "../../data/";
	txt += txtline;
	cout<<"File to process: "<<txt<<endl;
	process_file(txt,-1);
}
Example #22
0
void runGridpPb(const char *config = "config.txt"){
        //
        // run analysis 
        //

        TGrid::Connect("alien://");

        // Create Lookup with sample information
        TMap sampleinfos;
        Generate_Sample_Lookup(sampleinfos);

        ConfigParser(config);

        // Configure alien plugin
        AliAnalysisAlien *plugin = CreateGridHandler();
        if(!CreateTrainDir(plugin, sampleinfos)){
                printf("Cannot setup output directory\n");
                return;
        }
        if(!MakeSample(plugin, sampleinfos)){
                printf("Cannot create data sample\n");
                return;
        }
        if(!g_plugin_mode.CompareTo("full")){
                // full mode, creating config files for the merging stage
                GenerateMergeConfigs();
        }

        AliAnalysisManager *mgr = new AliAnalysisManager("tpctofanalysis");
        mgr->SetGridHandler(plugin);
        
        SetupTrain(sampleinfos);

        // Run train
        if (!mgr->InitAnalysis()) return;
        mgr->PrintStatus();
        // Start analysis in grid.
        mgr->StartAnalysis("grid");
} 
Example #23
0
void MySetupAnalysisPluginProof(AliAnalysisAlien *plugin,
                                TString analysisMode) {

  plugin->SetProofParameter("PROOF_UseMergers", "-1");
  if (!analysisMode.CompareTo("full"))
    plugin->SetProofParameter("PROOF_ForceLocal", "1");
  plugin->SetProofCluster("alice-caf.cern.ch");
  plugin->SetProofCluster("lite://");
  // May need to reset proof. Supported modes: 0-no reset, 1-soft, 2-hard
  plugin->SetProofReset(0);
  // May limit the number of workers per slave. If used with SetNproofWorkers,
  // SetParallel(nproofworkers) will be called after connection
  //   plugin->SetNproofWorkers(1);
  //    plugin->SetNproofWorkersPerSlave(1);
  // May request connection to alien upon connection to grid
  //    plugin->SetProofConnectGrid(kTRUE);

  //    plugin->SetNproofWorkers(10);
  // May use a specific version of root installed in proof
  //     plugin->SetRootVersionForProof("VO_ALICE@ROOT::v5-28-00d");
  //     plugin->SetRootVersionForProof("current");
  // May set the aliroot mode. Check http://aaf.cern.ch/node/83
  plugin->SetAliRootMode("default"); // Loads AF libs by default
  //     plugin->SetAliRootMode("ALIROOT"); // Loads AF libs by default
  // May request ClearPackages (individual ClearPackage not supported)
  //    plugin->SetClearPackages();
  // Plugin test mode works only providing a file containing test file locations

  // test file
  plugin->SetFileForTestMode("input.txt");

  // list of datasets in txt file
  plugin->SetProofDataSet("ds.txt");

  //++++++++++++++ end PROOF ++++++++++++++++
}
Example #24
0
//--------------------------------------------------------------------------------------------------
void runEMU(const char *fileset    = "0000",
	  const char *skim       = "noskim",
	  const char *dataset    = "p10-pj15-v36",
	  const char *book       = "local/filefi/016",
	  const char *catalogDir = "/home/cmsprod/catalog",
	  const char *outputName = "htt",
	  int         nEvents    = 1000)
{
  printf("\n==== Enter macro  ====\n");

  //------------------------------------------------------------------------------------------------
  // some parameters get passed through the environment
  //------------------------------------------------------------------------------------------------
  char json[1024], overlap[1024], src[1024];
  float overlapCut = -1;


  if (gSystem->Getenv("MIT_PROD_JSON"))
    sprintf(json,   "%s",gSystem->Getenv("MIT_PROD_JSON"));
  else {
    printf(" JSON file was not properly defined. EXIT!\n");
    return;
  } 
  TString jsonFile = TString("/home/cmsprod/json/") + TString(json);
  Bool_t  isData   = (jsonFile.CompareTo("/home/cmsprod/json/~") != 0);

  if (gSystem->Getenv("MIT_PROD_OVERLAP")) {
    sprintf(overlap,"%s",gSystem->Getenv("MIT_PROD_OVERLAP"));
    if (EOF == sscanf(overlap,"%f",&overlapCut)) {
      printf(" Overlap was not properly defined. EXIT!\n");
      return;
    }
  }
  else {
    printf(" OVERLAP file was not properly defined. EXIT!\n");
    return;
  } 

  if (gSystem->Getenv("src"))
    sprintf(src,   "%s",gSystem->Getenv("src"));
  else {
    printf(" src dir not defined. EXIT!\n");
    return;
  } 

  printf("\n Initialization worked. \n\n");

  //------------------------------------------------------------------------------------------------
  // some global setups
  //------------------------------------------------------------------------------------------------
  using namespace std;
  using namespace mithep;
  gDebugMask  = Debug::kAnalysis;
  gDebugLevel = 1;

  //------------------------------------------------------------------------------------------------
  // set up information
  //------------------------------------------------------------------------------------------------ 
  Bool_t applyISRFilter = kFALSE;
  Bool_t applyMllGenCut = kFALSE;

  RunLumiSelectionMod *runLumiSel = new RunLumiSelectionMod;
  runLumiSel->SetAcceptMC(kTRUE);                          // Monte Carlo events are always accepted

  // if([json is not ~] and [json is not -])
  if ((jsonFile.CompareTo("/home/cmsprod/json/~") != 0) &&    //if not MC and 
      (jsonFile.CompareTo("/home/cmsprod/json/-") != 0)   ) { //if json file not absent
    runLumiSel->AddJSONFile(jsonFile.Data());
  }
  if ((jsonFile.CompareTo("/home/cmsprod/json/-") == 0)   ) {
    printf("\n WARNING -- Looking at data without JSON file: always accept.\n\n");
    runLumiSel->SetAbortIfNotAccepted(kFALSE);   // accept all events if there is no valid JSON file
  }

  printf("\n Run lumi worked. \n\n");

  //GeneratorMod
  GeneratorMod *generatorMod = new GeneratorMod;
  generatorMod->SetPrintDebug(kFALSE);
  generatorMod->SetPtLeptonMin(0.0);
  generatorMod->SetEtaLeptonMax(2.7);
  generatorMod->SetPtPhotonMin(15.0);
  generatorMod->SetEtaPhotonMax(2.7);
  generatorMod->SetPtRadPhotonMin(10.0);
  generatorMod->SetEtaRadPhotonMax(2.7);
  generatorMod->SetIsData(isData); 
  generatorMod->SetFillHist(!isData);
  if(applyMllGenCut == kTRUE){
    generatorMod->SetPdgIdCut(23);
    generatorMod->SetMassMinCut( 0.);
    generatorMod->SetMassMaxCut(50.);
  }
  generatorMod->SetApplyISRFilter(applyISRFilter);

  //------------------------------------------------------------------------------------------------
  // HLT information
  //------------------------------------------------------------------------------------------------
  HLTMod *hltMod = new HLTMod;
  if (isData) {
//   valentina:
//     hltMod->AddTrigger("HLT_Mu17_Ele8_CaloIdL_v1",150000,161176);
//     hltMod->AddTrigger("HLT_Mu8_Ele17_CaloIdL_v1",150000,161176);
//     hltMod->AddTrigger("HLT_Mu17_Ele8_CaloIdL_v2",161179,999999);
//     hltMod->AddTrigger("HLT_Mu8_Ele17_CaloIdL_v2",161179,999999);
    hltMod->AddTrigger("HLT_Mu9",132440,147119);
    hltMod->AddTrigger("HLT_Mu15",147120,9999999);
  }
  else {
    hltMod->AddTrigger("HLT_Mu9");
    hltMod->AddTrigger("HLT_Mu15");
//     hltMod->AddTrigger("HLT_Ele10_SW_L1R_v2");
  }
  hltMod->SetTrigObjsName("MyHltObjs");
  hltMod->SetAbortIfNotAccepted(kTRUE);
//   hltMod->SetPrintTable(kTRUE);
  //------------------------------------------------------------------------------------------------
  // select events with a good primary vertex
  //------------------------------------------------------------------------------------------------
  GoodPVFilterMod *goodPVFilterMod = new GoodPVFilterMod;
  goodPVFilterMod->SetMinVertexNTracks(0);
  goodPVFilterMod->SetMinNDof(4);  // should be 4
  goodPVFilterMod->SetMaxAbsZ(24.0);
  goodPVFilterMod->SetMaxRho(2.0);

  //------------------------------------------------------------------------------------------------
  // Publisher Modules
  //------------------------------------------------------------------------------------------------
  PublisherMod<PFJet,Jet> *pubPFJet = new PublisherMod<PFJet,Jet>("JetPub");
  pubPFJet->SetInputName("AKt5PFJets");
  pubPFJet->SetOutputName("PubAKt5PFJets");

  PublisherMod<Met,Met> *pubTCMet = new PublisherMod<Met,Met>("MetTCPub");
  pubTCMet->SetInputName("TCMet");
  pubTCMet->SetOutputName("PubTCMet");

  PublisherMod<PFMet,Met> *pubPFMet = new PublisherMod<PFMet,Met>("MetPFPub");
  pubPFMet->SetInputName("PFMet");
  pubPFMet->SetOutputName("PubPFMet");

  PublisherMod<CaloMet> *pubCaloMet = new PublisherMod<CaloMet>("CaloMetPub");
  //  pubCaloMet->SetName("CaloMetPub");
  pubCaloMet->SetInputName("CorMuonMet");
  pubCaloMet->SetOutputName("pubCaloMet");

  //------------------------------------------------------------------------------------------------
  // Apply Jet Corrections
  //------------------------------------------------------------------------------------------------
  JetCorrectionMod *jetCorr = new JetCorrectionMod;
  jetCorr->SetInputName(pubPFJet->GetOutputName());
  jetCorr->SetCorrectedName("CorrectedJets");//corrected jets are PF jets!
  jetCorr->ApplyL1FastJetCorrection(); // <<==== apply default L1 correction
  string path(string(src)+"/MitPhysics/data/");
  jetCorr->AddCorrectionFromFile(path+string("START38_V13_AK5PF_L2Relative.txt"));
  jetCorr->AddCorrectionFromFile(path+string("START38_V13_AK5PF_L3Absolute.txt"));
  if(isData) {
    jetCorr->AddCorrectionFromFile(path+string("START38_V13_AK5PF_L2L3Residual.txt"));
  }
  //------------------------------------------------------------------------------------------------
  // Apply Met Corrections
  //------------------------------------------------------------------------------------------------
  CaloMetCorrectionMod *metCaloCorr = new CaloMetCorrectionMod;
  metCaloCorr->SetInputName(pubCaloMet->GetOutputName());
  metCaloCorr->SetCorrectedJetsName(jetCorr->GetOutputName());
  metCaloCorr->SetOutputName("pubCaloCorrectedMet");

  //------------------------------------------------------------------------------------------------
  // object id and cleaning sequence
  //------------------------------------------------------------------------------------------------
  MuonIDMod           *muonId        = new MuonIDMod;
  muonId->SetClassType("Global"); // def is "Global"
  muonId->SetIDType("WWMuId");  // def is "WWMuId"
  muonId->SetIsoType("TrackCaloSliding"); // this is def
  muonId->SetApplyD0Cut(kTRUE);  // def is 1
  muonId->SetPtMin(15.0); // def is 10
  muonId->SetEtaCut(2.4); // def is 2.4

  ElectronIDMod       *electronId    = new ElectronIDMod;
  electronId->SetIDType("CustomTight"); // def is "CustomTight"
  electronId->SetIsoType("TrackJuraSliding"); // this is default
  electronId->SetApplyConversionFilterType1(kTRUE); // default is 1
  electronId->SetApplyConversionFilterType2(kFALSE); // default is 0
  electronId->SetChargeFilter(kTRUE); // def is 1
  electronId->SetApplyD0Cut(kTRUE); // def is 1
  electronId->SetNExpectedHitsInnerCut(0); // def is 999
  electronId->SetPtMin(15.0); // def is 10
  electronId->SetEtaMax(2.5); // def is 2.5

  PhotonIDMod         *photonId      = new PhotonIDMod;

  PFTauIDMod          *pfTauId        = new PFTauIDMod;
  pfTauId->SetIsHPSSel(kTRUE);
  pfTauId->SetPtMin(20.0);

  JetIDMod            *pfJetId       = new JetIDMod;
  pfJetId->SetInputName(jetCorr->GetOutputName());
  pfJetId->SetPtCut(20.0); // def is 35
  pfJetId->SetEtaMaxCut(5.0); // def is 5
  pfJetId->SetJetEEMFractionMinCut(0.01); // def is 0.01
  pfJetId->SetOutputName("GoodPFJets");

  ElectronCleaningMod *electronCleaning     = new ElectronCleaningMod;
  PhotonCleaningMod   *photonCleaning       = new PhotonCleaningMod;
  PFTauCleaningMod    *pfTauCleaning        = new PFTauCleaningMod;
  JetCleaningMod      *pfJetCleaning      = new JetCleaningMod;
  pfJetCleaning->SetGoodJetsName(pfJetId->GetOutputName());
  pfJetCleaning->SetCleanJetsName("CleanPFJets");

  //------------------------------------------------------------------------------------------------
  // merge modules
  //------------------------------------------------------------------------------------------------
  MergeLeptonsMod *mergeLeptonsMod = new MergeLeptonsMod;
  mergeLeptonsMod->SetMuonsName    (muonId->GetOutputName());
  mergeLeptonsMod->SetElectronsName(electronCleaning->GetOutputName());

  //------------------------------------------------------------------------------------------------
  // acceptance modules (gen -> reco)
  //------------------------------------------------------------------------------------------------
  //------------------------------------------------------------------------------------------------
  // id efficiency modules (reco -> id)
  //------------------------------------------------------------------------------------------------
  //------------------------------------------------------------------------------------------------
  // analysis modules
  //------------------------------------------------------------------------------------------------
  EMUAnalysis2 *analysisModEMU = new EMUAnalysis2;
  analysisModEMU->SetTrigObjsName  (hltMod           -> GetOutputName());
  analysisModEMU->SetMuonName      (muonId           -> GetOutputName());
  analysisModEMU->SetElecName      (electronCleaning -> GetOutputName());
  analysisModEMU->SetJetName       (pfJetCleaning    -> GetOutputName());
//   analysisModEMU->SetHistNamePref  ("hXXXXX");

  //------------------------------------------------------------------------------------------------
  // making analysis chain
  //------------------------------------------------------------------------------------------------
  // just in case we have run lumi sel
  if ((jsonFile.CompareTo("/home/cmsprod/json/~") != 0) &&
      (jsonFile.CompareTo("/home/cmsprod/json/-") != 0)   )
    runLumiSel->Add(generatorMod);

  generatorMod      ->Add(hltMod);
  hltMod            ->Add(goodPVFilterMod);
  goodPVFilterMod   ->Add(muonId);
  muonId            ->Add(electronId);
  electronId        ->Add(photonId);
  photonId          ->Add(pubPFJet);
  pubPFJet          ->Add(pubTCMet); 
  pubTCMet          ->Add(pubPFMet);
  pubPFMet          ->Add(pubCaloMet);
  pubCaloMet        ->Add(pfTauId);
  pfTauId           ->Add(jetCorr);
  jetCorr           ->Add(metCaloCorr);
  metCaloCorr       ->Add(pfJetId);
  pfJetId           ->Add(electronCleaning);
  electronCleaning  ->Add(photonCleaning);
  photonCleaning    ->Add(pfTauCleaning);
  pfTauCleaning     ->Add(pfJetCleaning);
  pfJetCleaning     ->Add(mergeLeptonsMod);

  mergeLeptonsMod   ->Add(analysisModEMU);

  //------------------------------------------------------------------------------------------------
  // setup analysis
  //------------------------------------------------------------------------------------------------

  Analysis *ana = new Analysis;
  ana->SetUseHLT(kTRUE);
  ana->SetKeepHierarchy(kTRUE);
  if (nEvents >= 0)
    ana->SetProcessNEvents(nEvents);
  if ((jsonFile.CompareTo("/home/cmsprod/json/~") != 0) &&
      (jsonFile.CompareTo("/home/cmsprod/json/-") != 0)   )
    ana->SetSuperModule(runLumiSel);
  else
    ana->SetSuperModule(generatorMod);
  ana->SetPrintScale(100);

  //------------------------------------------------------------------------------------------------
  // organize input
  //------------------------------------------------------------------------------------------------
  Catalog *c = new Catalog(catalogDir);
  TString skimdataset = TString(dataset)+TString("/") +TString(skim);
  Dataset *d = NULL;
  if (TString(skim).CompareTo("noskim") == 0)
    d = c->FindDataset(book,dataset,fileset);
  else 
    d = c->FindDataset(book,skimdataset.Data(),fileset);
  ana->AddDataset(d);
  //ana->AddFile("root://castorcms//castor/cern.ch/user/p/paus/filler/011/s09-ttbar-7-mc3/*.root");
  //ana->AddFile("hgg-skim_r10a-eg-pr-v4_noskim_0000_000.root");
  //ana->AddFile("hgg-skim_p10-h110gg-gf-v26_noskim_0000_000.root");

  //------------------------------------------------------------------------------------------------
  // organize output
  //------------------------------------------------------------------------------------------------
  TString rootFile = TString(outputName);
  rootFile += TString("_") + TString(dataset) + TString("_") + TString(skim);
  if (TString(fileset) != TString(""))
    rootFile += TString("_") + TString(fileset);
  rootFile += TString(".root");
  ana->SetOutputName(rootFile.Data());
//  use current directory:
//  ana->SetOutputName((TString(outputName)+TString(".root")).Data());
  ana->SetCacheSize(64*1024*1024);

  //------------------------------------------------------------------------------------------------
  // Say what we are doing
  //------------------------------------------------------------------------------------------------
  printf("\n==== PARAMETER SUMMARY FOR THIS JOB ====\n");
  printf("\n JSON file: %s\n  and overlap cut: %f (%s)\n",jsonFile.Data(),overlapCut,overlap);
  printf("\n Rely on Catalog: %s\n",catalogDir);
  printf("  -> Book: %s  Dataset: %s  Skim: %s  Fileset: %s <-\n",book,dataset,skim,fileset);
  printf("\n Root output: %s\n\n",rootFile.Data());  
  printf("\n========================================\n");

  //------------------------------------------------------------------------------------------------
  // run the analysis after successful initialisation
  //------------------------------------------------------------------------------------------------
  ana->Run(!gROOT->IsBatch());

  return;
}
Example #25
0
//--------------------------------------------------------------------------------------------------
void runFlatMonoJet(const char *fileset    = "0000",
		    const char *skim       = "noskim",
		    const char *dataset    = "s12-wjets-ptw100-v7a", 
		    const char *book       = "t2mit/filefi/031",
		    const char *catalogDir = "/home/cmsprod/catalog",
		    const char *outputName = "MonoJet_August13",
		    int         nEvents    = 100)
{
  //------------------------------------------------------------------------------------------------
  // some parameters get passed through the environment
  //------------------------------------------------------------------------------------------------
  char json[1024], overlap[1024];
  float overlapCut = -1;
  
  if (gSystem->Getenv("MIT_PROD_JSON"))
    sprintf(json,   "%s",gSystem->Getenv("MIT_PROD_JSON"));
  else {
    sprintf(json, "%s", "~");
  } 
  
  TString jsonFile = TString("/home/cmsprod/cms/json/") + TString(json);
  std::cout<<"JSON "<<jsonFile<<std::endl;
  Bool_t  isData   = ( (jsonFile.CompareTo("/home/cmsprod/cms/json/~") != 0) );
    
  std::cout<<"*********** Is data?? **********"<<isData<<std::endl;

  if (gSystem->Getenv("MIT_PROD_OVERLAP")) {
    sprintf(overlap,"%s",gSystem->Getenv("MIT_PROD_OVERLAP"));
    if (EOF == sscanf(overlap,"%f",&overlapCut)) {
      printf(" Overlap was not properly defined. EXIT!\n");
      return;
    }
  }
  else {
     sprintf(overlap,"%s", "-1.0");
    //printf(" OVERLAP file was not properly defined. EXIT!\n");
    //return;
  } 

  printf("\n Initialization worked \n");

  //------------------------------------------------------------------------------------------------
  // some global setups
  //------------------------------------------------------------------------------------------------
  using namespace mithep;
  gDebugMask  = Debug::kGeneral;
  gDebugLevel = 3;

  //------------------------------------------------------------------------------------------------
  // set up information
  //------------------------------------------------------------------------------------------------
  RunLumiSelectionMod *runLumiSel = new RunLumiSelectionMod;      
  runLumiSel->SetAcceptMC(!isData);
  runLumiSel->SetAbortIfNotAccepted(kFALSE);   // accept all events if there is no valid JSON file

  // only select on run- and lumisection numbers when valid json file present
  if ((jsonFile.CompareTo("/home/cmsprod/cms/json/~") != 0) &&
      (jsonFile.CompareTo("/home/cmsprod/cms/json/-") != 0)   ) {
    runLumiSel->AddJSONFile(jsonFile.Data());
  }
  if ((jsonFile.CompareTo("/home/cmsprod/cms/json/-") == 0)   ) {
    printf("\n WARNING -- Looking at data without JSON file: always accept.\n\n");
  }

  printf("\n Run lumi worked\n");

  // Generator info
  GeneratorMod *generatorMod = new GeneratorMod;
  generatorMod->SetPrintDebug(kFALSE);
  generatorMod->SetPtLeptonMin(0.0);
  generatorMod->SetEtaLeptonMax(2.7);
  generatorMod->SetPtPhotonMin(0.0);
  generatorMod->SetEtaPhotonMax(2.7);
  generatorMod->SetPtRadPhotonMin(0.0);
  generatorMod->SetEtaRadPhotonMax(2.7);
  generatorMod->SetIsData(isData);
  generatorMod->SetFillHist(!isData);
  generatorMod->SetApplyISRFilter(kFALSE);
  generatorMod->SetApplyVVFilter(kFALSE);
  generatorMod->SetApplyVGFilter(kFALSE);
  generatorMod->SetFilterBTEvents(kFALSE);

  //-----------------------------------------------------------------------------------------------------------
  // HLT information : trigger not applied (neither for data nor for MC, store info to apply selection offline
  //-----------------------------------------------------------------------------------------------------------
  HLTMod *hltModP = new HLTMod("HLTModP");

  // monojet triggers
  TString monoJetTriggers[12] = {"HLT_MonoCentralPFJet80_PFMETnoMu105_NHEF0p95_v4", "HLT_MonoCentralPFJet80_PFMETnoMu105_NHEF0p95_v3", "HLT_MonoCentralPFJet80_PFMETnoMu105_NHEF0p95_v1", "HLT_MonoCentralPFJet80_PFMETnoMu95_NHEF0p95_v5", "HLT_MonoCentralPFJet80_PFMETnoMu95_NHEF0p95_v4", "HLT_MonoCentralPFJet80_PFMETnoMu95_NHEF0p95_v3", "HLT_MonoCentralPFJet80_PFMETnoMu95_NHEF0p95_v2","HLT_MET120_HBHENoiseCleaned_v6", "HLT_MET120_HBHENoiseCleaned_v5", "HLT_MET120_HBHENoiseCleaned_v4", "HLT_MET120_HBHENoiseCleaned_v3", "HLT_MET120_HBHENoiseCleaned_v2"};
  for (int i=0; i<12; i++) {
    hltModP->AddTrigger(monoJetTriggers[i],0,999999); //jet 85 , met 90
    hltModP->AddTrigger(TString("!"+monoJetTriggers[i]),0,999999); //jet 85 , met 90
  }

  // VBF triggers
  TString vbfTriggers[12] = {"HLT_DiPFJet40_PFMETnoMu65_MJJ800VBF_AllJets_v9", "HLT_DiPFJet40_PFMETnoMu65_MJJ800VBF_AllJets_v8", "HLT_DiPFJet40_PFMETnoMu65_MJJ800VBF_AllJets_v6", "HLT_DiPFJet40_PFMETnoMu65_MJJ800VBF_AllJets_v5", "HLT_DiPFJet40_PFMETnoMu65_MJJ800VBF_AllJets_v4", "HLT_DiPFJet40_PFMETnoMu65_MJJ800VBF_AllJets_v3", "HLT_DiPFJet40_PFMETnoMu65_MJJ800VBF_AllJets_v2"};
  for (int i=0; i<12; i++) {
    hltModP->AddTrigger(vbfTriggers[i],0,999999); //jet 85 , met 90
    hltModP->AddTrigger(TString("!"+vbfTriggers[i]),0,999999); //jet 85 , met 90
  }

  hltModP->SetBitsName("HLTBits");
  hltModP->SetTrigObjsName("MyHltPhotObjs");
  hltModP->SetAbortIfNotAccepted(isData);
  hltModP->SetPrintTable(kFALSE); // set to true to print HLT table

  //------------------------------------------------------------------------------------------------
  // split pfcandidates to PFPU and PFnoPU
  //------------------------------------------------------------------------------------------------
  SeparatePileUpMod* SepPUMod = new SeparatePileUpMod;
  //  SepPUMod->SetUseAllVerteces(kFALSE);
  // SepPUMod->SetVertexName("OutVtxCiC");
  SepPUMod->SetPFNoPileUpName("pfnopileupcands");
  SepPUMod->SetPFPileUpName("pfpileupcands");
  SepPUMod->SetCheckClosestZVertex(kFALSE);
  
  //------------------------------------------------------------------------------------------------
  // select events with a good primary vertex
  //------------------------------------------------------------------------------------------------
  GoodPVFilterMod *goodPVFilterMod = new GoodPVFilterMod;
  goodPVFilterMod->SetMinVertexNTracks(0);
  goodPVFilterMod->SetMinNDof         (4.0);
  goodPVFilterMod->SetMaxAbsZ         (24.0);
  goodPVFilterMod->SetMaxRho          (2.0);
  goodPVFilterMod->SetIsMC(!isData);
  goodPVFilterMod->SetVertexesName("PrimaryVertexes");
  
  //------------------------------------------------------------------------------------------------
  // object id and cleaning sequence
  //------------------------------------------------------------------------------------------------
  //-----------------------------------
  // Lepton Selection 
  //-----------------------------------
  ElectronIDMod* eleIdMod = new ElectronIDMod;
  eleIdMod->SetPtMin(10.);  
  eleIdMod->SetEtaMax(2.5);
  eleIdMod->SetApplyEcalFiducial(true);
  eleIdMod->SetIDType("VBTFWorkingPoint95Id");  
  eleIdMod->SetIsoType("PFIso");
  eleIdMod->SetApplyConversionFilterType1(kTRUE);
  eleIdMod->SetApplyConversionFilterType2(kFALSE);
  eleIdMod->SetChargeFilter(kFALSE);
  eleIdMod->SetApplyD0Cut(kTRUE);
  eleIdMod->SetApplyDZCut(kTRUE);
  eleIdMod->SetWhichVertex(0);
  eleIdMod->SetNExpectedHitsInnerCut(0);  
  eleIdMod->SetGoodElectronsName("GoodElectronsBS");
  eleIdMod->SetRhoType(RhoUtilities::CMS_RHO_RHOKT6PFJETS); 

  MuonIDMod* muonIdGammaGamma = new MuonIDMod;
  // base kinematics
  muonIdGammaGamma->SetPtMin(10.);
  muonIdGammaGamma->SetEtaCut(2.4);
  // base ID
  muonIdGammaGamma->SetIDType("NoId");
  muonIdGammaGamma->SetClassType("GlobalorTracker");
  muonIdGammaGamma->SetWhichVertex(0); // this is a 'hack'.. but hopefully good enough...
  muonIdGammaGamma->SetD0Cut(0.02);
  muonIdGammaGamma->SetDZCut(0.5);
  muonIdGammaGamma->SetIsoType("PFIsoBetaPUCorrected"); //h
  muonIdGammaGamma->SetPFIsoCut(0.2); //h
  muonIdGammaGamma->SetOutputName("HggLeptonTagMuons");
  muonIdGammaGamma->SetPFNoPileUpName("pfnopileupcands");
  muonIdGammaGamma->SetPFPileUpName("pfpileupcands");
  muonIdGammaGamma->SetPVName(Names::gkPVBeamSpotBrn); 

  MuonIDMod *muonIdWW = new MuonIDMod;
  muonIdWW->SetOutputName("HWWMuons");
  muonIdWW->SetIntRadius(0.0);
  muonIdWW->SetClassType("GlobalTracker");
  muonIdWW->SetIDType("WWMuIdV4");
  muonIdWW->SetIsoType("IsoRingsV0_BDTG_Iso");
  muonIdWW->SetApplyD0Cut(kTRUE);
  muonIdWW->SetApplyDZCut(kTRUE);
  muonIdWW->SetWhichVertex(0);
  muonIdWW->SetRhoType(RhoUtilities::CMS_RHO_RHOKT6PFJETS);
  muonIdWW->SetPtMin(10.);
  muonIdWW->SetEtaCut(2.4);

  //MuonIDMod *muonId = muonIdWW;
  MuonIDMod *muonId = muonIdGammaGamma;
  
  ElectronCleaningMod *electronCleaning = new ElectronCleaningMod;
  electronCleaning->SetCleanMuonsName(muonId->GetOutputName());
  electronCleaning->SetGoodElectronsName(eleIdMod->GetOutputName());
  electronCleaning->SetCleanElectronsName("CleanElectrons");

  MergeLeptonsMod *merger = new MergeLeptonsMod;
  merger->SetMuonsName(muonId->GetOutputName());
  merger->SetElectronsName(electronCleaning->GetOutputName());
  merger->SetMergedName("MergedLeptons");

  //-----------------------------------
  // Photon Regression + ID 
  //-----------------------------------
  PhotonMvaMod *photreg = new PhotonMvaMod;
  photreg->SetRegressionVersion(3);
  photreg->SetRegressionWeights(std::string((gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/gbrv3ph_52x.root")).Data()));
  photreg->SetOutputName("GoodPhotonsRegr");
  photreg->SetApplyShowerRescaling(kTRUE);
  photreg->SetMinNumPhotons(0);
  photreg->SetIsData(isData);

  PhotonIDMod *photonIDMod = new PhotonIDMod;
  photonIDMod->SetPtMin(0.0);
  photonIDMod->SetOutputName("GoodPhotons");
  photonIDMod->SetIDType("BaseLineCiCPFNoPresel");
  photonIDMod->SetIsoType("NoIso");
  photonIDMod->SetApplyElectronVeto(kTRUE);
  photonIDMod->SetApplyPixelSeed(kTRUE);
  photonIDMod->SetApplyConversionId(kTRUE);
  photonIDMod->SetApplyFiduciality(kTRUE);       
  photonIDMod->SetIsData(isData);
  photonIDMod->SetPhotonsFromBranch(kFALSE);
  photonIDMod->SetInputName(photreg->GetOutputName());
  //get the photon with regression energy  
  photonIDMod->DoMCSmear(kTRUE);
  photonIDMod->DoDataEneCorr(kTRUE);
  //------------------------------------------Energy smear and scale--------------------------------------------------------------
  photonIDMod->SetMCSmearFactors2012HCP(0.0111,0.0111,0.0107,0.0107,0.0155,0.0194,0.0295,0.0276,0.037,0.0371);
  photonIDMod->AddEnCorrPerRun2012HCP(190645,190781,0.9964,0.9964,1.0020,1.0020,0.9893,1.0028,0.9871,0.9937,0.9839,0.9958);
  photonIDMod->AddEnCorrPerRun2012HCP(190782,191042,1.0024,1.0024,1.0079,1.0079,0.9923,1.0058,0.9911,0.9977,0.9886,1.0005);
  photonIDMod->AddEnCorrPerRun2012HCP(191043,193555,0.9935,0.9935,0.9991,0.9991,0.9861,0.9997,0.9894,0.9960,0.9864,0.9982);
  photonIDMod->AddEnCorrPerRun2012HCP(193556,194150,0.9920,0.9920,0.9976,0.9976,0.9814,0.9951,0.9896,0.9962,0.9872,0.9990);
  photonIDMod->AddEnCorrPerRun2012HCP(194151,194532,0.9925,0.9925,0.9981,0.9981,0.9826,0.9963,0.9914,0.9980,0.9874,0.9993);
  photonIDMod->AddEnCorrPerRun2012HCP(194533,195113,0.9927,0.9927,0.9983,0.9983,0.9844,0.9981,0.9934,0.9999,0.9878,0.9996);
  photonIDMod->AddEnCorrPerRun2012HCP(195114,195915,0.9929,0.9929,0.9984,0.9984,0.9838,0.9974,0.9942,1.0007,0.9878,0.9997);
  photonIDMod->AddEnCorrPerRun2012HCP(195916,198115,0.9919,0.9919,0.9975,0.9975,0.9827,0.9964,0.9952,1.0017,0.9869,0.9987);
  photonIDMod->AddEnCorrPerRun2012HCP(198116,199803,0.9955,0.9955,1.0011,1.0011,0.9859,0.9995,0.9893,0.9959,0.9923,1.0041);
  photonIDMod->AddEnCorrPerRun2012HCP(199804,200048,0.9967,0.9967,1.0023,1.0023,0.9870,1.0006,0.9893,0.9959,0.9937,1.0055);
  photonIDMod->AddEnCorrPerRun2012HCP(200049,200151,0.9980,0.9980,1.0036,1.0036,0.9877,1.0012,0.9910,0.9976,0.9980,1.0097);
  photonIDMod->AddEnCorrPerRun2012HCP(200152,200490,0.9958,0.9958,1.0013,1.0013,0.9868,1.0004,0.9922,0.9988,0.9948,1.0065);
  photonIDMod->AddEnCorrPerRun2012HCP(200491,200531,0.9979,0.9979,1.0035,1.0035,0.9876,1.0012,0.9915,0.9981,0.9979,1.0096);
  photonIDMod->AddEnCorrPerRun2012HCP(200532,201656,0.9961,0.9961,1.0017,1.0017,0.9860,0.9996,0.9904,0.9970,0.9945,1.0063);
  photonIDMod->AddEnCorrPerRun2012HCP(201657,202305,0.9969,0.9969,1.0025,1.0025,0.9866,1.0002,0.9914,0.9980,0.9999,1.0116);
  photonIDMod->AddEnCorrPerRun2012HCP(202305,203002,0.9982,0.9982,1.0038,1.0038,0.9872,1.0008,0.9934,1.0000,1.0018,1.0135);
  photonIDMod->AddEnCorrPerRun2012HCP(203003,203984,1.0006,1.0006,1.0061,1.0061,0.9880,1.0017,0.9919,0.9988,0.9992,1.0104);     
  photonIDMod->AddEnCorrPerRun2012HCP(203985,205085,0.9993,0.9993,1.0048,1.0048,0.9903,1.0040,0.9928,0.9997,0.9987,1.0099);     
  photonIDMod->AddEnCorrPerRun2012HCP(205086,205310,1.0004,1.0004,1.0059,1.0059,0.9901,1.0037,0.9987,1.0055,1.0091,1.0202);     
  photonIDMod->AddEnCorrPerRun2012HCP(205311,206207,1.0000,1.0000,1.0055,1.0055,0.9891,1.0028,0.9948,1.0017,1.0032,1.0144);     
  photonIDMod->AddEnCorrPerRun2012HCP(206208,206483,1.0003,1.0003,1.0058,1.0058,0.9895,1.0032,0.9921,0.9989,1.0056,1.0167);     
  photonIDMod->AddEnCorrPerRun2012HCP(206484,206597,1.0005,1.0005,1.0060,1.0060,0.9895,1.0032,0.9968,1.0036,1.0046,1.0158);     
  photonIDMod->AddEnCorrPerRun2012HCP(206598,206896,1.0006,1.0006,1.0061,1.0061,0.9881,1.0017,0.9913,0.9982,1.0050,1.0162);     
  photonIDMod->AddEnCorrPerRun2012HCP(206897,207220,1.0006,1.0006,1.0061,1.0061,0.9884,1.0021,0.9909,0.9978,1.0053,1.0165);     
  photonIDMod->AddEnCorrPerRun2012HCP(207221,208686,1.0006,1.0006,1.0061,1.0061,0.9894,1.0030,0.9951,1.0020,1.0060,1.0172);     
  //---------------------------------shower shape scale--------------------------------------------------------------------------------
  photonIDMod->SetDoShowerShapeScaling(kTRUE);
  photonIDMod->SetShowerShapeType("2012ShowerShape");
  photonIDMod->Set2012HCP(kTRUE);

  PFTauIDMod *pftauIDMod = new PFTauIDMod;
  pftauIDMod->SetPFTausName("HPSTaus");
  pftauIDMod->SetIsLooseId(kFALSE);

  PhotonCleaningMod *photonCleaningMod = new PhotonCleaningMod;
  photonCleaningMod->SetCleanElectronsName(electronCleaning->GetOutputName());
  photonCleaningMod->SetGoodPhotonsName(photonIDMod->GetOutputName());
  photonCleaningMod->SetCleanPhotonsName("CleanPhotons");

  PFTauCleaningMod *pftauCleaningMod = new PFTauCleaningMod;
  pftauCleaningMod->SetGoodPFTausName(pftauIDMod->GetGoodPFTausName());
  pftauCleaningMod->SetCleanMuonsName(muonId->GetOutputName());

  PublisherMod<PFJet,Jet> *pubJet = new PublisherMod<PFJet,Jet>("JetPub");
  pubJet->SetInputName("AKt5PFJets");
  pubJet->SetOutputName("PubAKt5PFJets");

  JetCorrectionMod *jetCorr = new JetCorrectionMod;
  if(isData){ 
    jetCorr->AddCorrectionFromFile(std::string((gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/Summer13_V1_DATA_L1FastJet_AK5PF.txt")).Data())); 
    jetCorr->AddCorrectionFromFile(std::string((gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/Summer13_V1_DATA_L2Relative_AK5PF.txt")).Data())); 
    jetCorr->AddCorrectionFromFile(std::string((gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/Summer13_V1_DATA_L3Absolute_AK5PF.txt")).Data())); 
    jetCorr->AddCorrectionFromFile(std::string((gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/Summer13_V1_DATA_L2L3Residual_AK5PF.txt")).Data()));
  }                                                                                      
  else {                                                                                 
    jetCorr->AddCorrectionFromFile(std::string((gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/Summer13_V1_MC_L1FastJet_AK5PF.txt")).Data())); 
    jetCorr->AddCorrectionFromFile(std::string((gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/Summer13_V1_MC_L2Relative_AK5PF.txt")).Data())); 
    jetCorr->AddCorrectionFromFile(std::string((gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/Summer13_V1_MC_L3Absolute_AK5PF.txt")).Data())); 
  }
  jetCorr->SetInputName(pubJet->GetOutputName());
  jetCorr->SetCorrectedName("CorrectedJets");    

  JetIDMod *theJetID = new JetIDMod;
  theJetID->SetInputName(jetCorr->GetOutputName());
  theJetID->SetPtCut(30.0);
  theJetID->SetEtaMaxCut(4.7);
  theJetID->SetJetEEMFractionMinCut(0.00);
  theJetID->SetOutputName("GoodJets");
  theJetID->SetApplyBetaCut(kFALSE);
  theJetID->SetApplyMVACut(kTRUE);

  JetCleaningMod *theJetCleaning = new JetCleaningMod;
  theJetCleaning->SetCleanElectronsName(electronCleaning->GetOutputName());
  theJetCleaning->SetCleanMuonsName(muonId->GetOutputName());
  theJetCleaning->SetCleanPhotonsName(photonCleaningMod->GetOutputName());
  theJetCleaning->SetApplyPhotonRemoval(kTRUE);
  theJetCleaning->SetGoodJetsName(theJetID->GetOutputName());
  theJetCleaning->SetCleanJetsName("CleanJets");
        
  MetCorrectionMod *metCorrT0T1Shift = new MetCorrectionMod;
  metCorrT0T1Shift->SetInputName("PFMet");
  metCorrT0T1Shift->SetJetsName(pubJet->GetOutputName());    
  metCorrT0T1Shift->SetCorrectedJetsName(jetCorr->GetOutputName());    
  metCorrT0T1Shift->SetCorrectedName("PFMetT0T1Shift");   
  metCorrT0T1Shift->ApplyType0(kTRUE);   
  metCorrT0T1Shift->ApplyType1(kTRUE);   
  metCorrT0T1Shift->ApplyShift(kTRUE);   
  metCorrT0T1Shift->IsData(isData);
  metCorrT0T1Shift->SetPrint(kFALSE);

  MonoJetTreeWriter *jetplusmettree = new MonoJetTreeWriter("MonoJetTreeWriter");
  jetplusmettree->SetTriggerObjectsName(hltModP->GetOutputName());
  jetplusmettree->SetMetName(metCorrT0T1Shift->GetOutputName()); //corrected met
  jetplusmettree->SetMetFromBranch(kFALSE);
  jetplusmettree->SetPhotonsFromBranch(kFALSE);
  jetplusmettree->SetPhotonsName(photonCleaningMod->GetOutputName());
  jetplusmettree->SetElectronsFromBranch(kFALSE);
  jetplusmettree->SetElectronsName(electronCleaning->GetOutputName());
  jetplusmettree->SetMuonsFromBranch(kFALSE);
  jetplusmettree->SetMuonsName(muonId->GetOutputName());
  jetplusmettree->SetTausFromBranch(kFALSE);
  jetplusmettree->SetTausName(pftauCleaningMod->GetOutputName());
  jetplusmettree->SetJetsFromBranch(kFALSE);
  jetplusmettree->SetJetsName(theJetCleaning->GetOutputName());
  jetplusmettree->SetPVFromBranch(kFALSE);
  jetplusmettree->SetPVName(goodPVFilterMod->GetOutputName());
  jetplusmettree->SetLeptonsName(merger->GetOutputName());
  jetplusmettree->SetIsData(isData);
  jetplusmettree->SetProcessID(0);
  jetplusmettree->SetFillNtupleType(0);


  //------------------------------------------------------------------------------------------------
  // making analysis chain
  //------------------------------------------------------------------------------------------------
  // this is how it always starts
  runLumiSel->Add(generatorMod);
  generatorMod->Add(goodPVFilterMod);
  goodPVFilterMod->Add(hltModP);

  // photon regression
  hltModP->Add(photreg);
  // simple object id modules
  photreg          ->Add(SepPUMod); 
  SepPUMod         ->Add(muonId);
  muonId           ->Add(eleIdMod);
  eleIdMod	   ->Add(electronCleaning);
  electronCleaning ->Add(merger);
  merger           ->Add(photonIDMod);
  photonIDMod	   ->Add(photonCleaningMod);
  photonCleaningMod->Add(pftauIDMod);
  pftauIDMod       ->Add(pftauCleaningMod);
  pftauCleaningMod ->Add(pubJet);
  pubJet           ->Add(jetCorr);
  jetCorr          ->Add(metCorrT0T1Shift);
  metCorrT0T1Shift ->Add(theJetID);
  theJetID         ->Add(theJetCleaning);
  theJetCleaning   ->Add(jetplusmettree);

  //------------------------------------------------------------------------------------------------
  // setup analysis
  //------------------------------------------------------------------------------------------------
  Analysis *ana = new Analysis;
  ana->SetUseHLT(kTRUE);
  ana->SetKeepHierarchy(kTRUE);
  ana->SetSuperModule(runLumiSel);
  ana->SetPrintScale(100);
  if (nEvents >= 0) ana->SetProcessNEvents(nEvents);
  
  //------------------------------------------------------------------------------------------------
  // organize input
  //------------------------------------------------------------------------------------------------
  Catalog *c = new Catalog(catalogDir);
  TString skimdataset = TString(dataset)+TString("/") +TString(skim);
  Dataset *d = NULL;
  TString bookstr = book;
  if (TString(skim).CompareTo("noskim") == 0) {
    d = c->FindDataset(bookstr,dataset,fileset, true); // chaching on
    //d = c->FindDataset(bookstr,dataset,fileset, false); // chaching off
  }
  else {
    d = c->FindDataset(bookstr,skimdataset.Data(),fileset, true);
    //d = c->FindDataset(bookstr,skimdataset.Data(),fileset, false);
  }
  ana->AddDataset(d);
  //ana->AddFile("/mnt/hadoop/cms/store/user/paus/filefi/032/r12a-met-j22-v1/C4AC0AB8-BA82-E211-B238-003048678FF4.root");
  

  //------------------------------------------------------------------------------------------------
  // organize output
  //------------------------------------------------------------------------------------------------
  TString rootFile = TString(outputName);
  rootFile += TString("_") + TString(dataset) + TString("_") + TString(skim);
  if (TString(fileset) != TString(""))
    rootFile += TString("_") + TString(fileset);
  rootFile += TString(".root");
  ana->SetOutputName(rootFile.Data());
  //ana->SetCacheSize(64*1024*1024);
  ana->SetCacheSize(0);

  //------------------------------------------------------------------------------------------------
  // Say what we are doing
  //------------------------------------------------------------------------------------------------
  printf("\n==== PARAMETER SUMMARY FOR THIS JOB ====\n");
  printf("\n JSON file: %s\n  and overlap cut: %f (%s)\n",jsonFile.Data(),overlapCut,overlap);
  printf("\n Rely on Catalog: %s\n",catalogDir);
  printf("  -> Book: %s  Dataset: %s  Skim: %s  Fileset: %s <-\n",book,dataset,skim,fileset);
  printf("\n Root output: %s\n\n",rootFile.Data());  
  printf("\n========================================\n");

  //------------------------------------------------------------------------------------------------
  // run the analysis after successful initialisation
  //------------------------------------------------------------------------------------------------
  ana->Run(!gROOT->IsBatch());

  return;
}
Example #26
0
void runGRJETSv11(TString mode       = "lite",            // local, lite, or cluster
               TString identifier = "run1",               // tag 
               TString dataset    = "Wprime1200.GRJETSv11",  // dataset name as in the fileList  
               TString username   = "swiatlow",           // username (e.g. swiatlow, fizisist)
               bool mcweights     = false,                 // use mc weights?
               bool doHists       = true,                 // do histograms or enable dataset mode 
               bool doSys         = false,                // do systematics 
               bool debug         = false,                // turn on debugging
               int  nWorkers      = 4                     //specify number of workers for proof(-1 for all available)
             ) 
{
    
    ///----------------------------------------------------------------
    /// Load libraries , set the config file, treenam, and cluster info
    ///----------------------------------------------------------------

    TString gridusername = "mswiatlo";
    cout << "trying to load libraries" << endl;
    loadLibraries();

    cout << " Libraries loaded " << endl;

    // SetConfig
    TString configfile("../config/grjetsv11.config");

    // Change if defaulting to wrong TTree, otherwise leave
    TString treename("jets");
    
    // Best to leave alone  
    TString pathLite("");

    TString pathCluster("root://atlprf01.slac.stanford.edu:2094//atlas/output/");

    pathCluster.Append(username);
    pathCluster.Append("/");



    // Determine eventbuilder from dataset name
    TString eventbuilder(dataset);
    eventbuilder.Remove(0,eventbuilder.Last('.')+1);
    
    ///----------------------------------------------------------------
    /// Filename paths, URLs for PROOF running
    ///----------------------------------------------------------------
    TString url(mode);
    TString path("");
    if (mode.CompareTo("lite")==0) {
        url = "lite://";
        path = pathLite;
    }
    else if(mode.CompareTo("cluster")==0) {
      url = TString(username+"@atlprf01.slac.stanford.edu");
      path = pathCluster;
    }
    // Make an options file, edit as needed
    TFile* options = new TFile("options.root","RECREATE");

    ///----------------------------------------------------------------
    /// Overall Configuration
    ///----------------------------------------------------------------
    bool doPRW           = false;
    bool doBasic         = true;
    bool doTruthLinks    = false;
    bool doTrackJetLinks = true;
    bool doTruthJetLinks = true;
    bool doJetStructure  = true;
    bool doConstituents  = true;
    bool doTruthConstit  = true;
    bool doParentChild   = true;
    bool doTrack         = true;
    bool doLCCluster     = true;
    bool doEMCluster     = false;
    bool doTruth         = true;
    bool doVertex        = true;
    bool doPhotons       = false;
    
    /// JET TYPES
    bool doSomeJetTypes  = false;
    bool doMinJetTypes   = true;
    
    /// SELECTIONS
    float minJetPt       =  20.000;
    float maxJetEta      =   3.199;
    float minFatJetPt    = 100.000;
    float minJetJVF      =   0.750;
    float maxJetTrkDR    =   0.300;
    float maxJetTruthDR  =   0.300;
    TString badJetType   = "AntiKt4LCTopoAOD";
    TString badJetDef    = "isBadLooseMinus";
    
    /// Substructure
    int   nStdJetCut     = 4;
    float lowMassCRcut   = 100.000;
    float threeBodyCRcut =   0.700;
    
    ///----------------------------------------------------------------
    /// Jet types
    ///----------------------------------------------------------------
    
    TString aktCal = "AntiKt10LCTopo";
    TString aktTrk = "AntiKt10TrackZ";
    TString aktTru = "AntiKt10Truth";
    TString caCal  = "CamKt12LCTopo";
    TString caTrk  = "CamKt12TrackZ";
    TString caTru  = "CamKt12Truth";
    
    TString aktCalTrim = "AntiKt10LCTopoTrimmedPtFrac1SmallR20,AntiKt10LCTopoTrimmedPtFrac3SmallR20,AntiKt10LCTopoTrimmedPtFrac5SmallR20,AntiKt10LCTopoTrimmedPtFrac1SmallR30,AntiKt10LCTopoTrimmedPtFrac3SmallR30,AntiKt10LCTopoTrimmedPtFrac5SmallR30";
    TString aktCalPrun = "AntiKt10LCTopoPrunedKtRcutFactor10Zcut5,AntiKt10LCTopoPrunedKtRcutFactor20Zcut5,AntiKt10LCTopoPrunedKtRcutFactor30Zcut5,AntiKt10LCTopoPrunedKtRcutFactor10Zcut10,AntiKt10LCTopoPrunedKtRcutFactor20Zcut10,AntiKt10LCTopoPrunedKtRcutFactor30Zcut10";
    TString aktTrkTrim = "AntiKt10TrackZTrimmedPtFrac1SmallR20,AntiKt10TrackZTrimmedPtFrac3SmallR20,AntiKt10TrackZTrimmedPtFrac5SmallR20,AntiKt10TrackZTrimmedPtFrac1SmallR30,AntiKt10TrackZTrimmedPtFrac3SmallR30,AntiKt10TrackZTrimmedPtFrac5SmallR30";
    TString aktTrkPrun = "AntiKt10TrackZPrunedKtRcutFactor10Zcut5,AntiKt10TrackZPrunedKtRcutFactor20Zcut5,AntiKt10TrackZPrunedKtRcutFactor30Zcut5,AntiKt10TrackZPrunedKtRcutFactor10Zcut10,AntiKt10TrackZPrunedKtRcutFactor20Zcut10,AntiKt10TrackZPrunedKtRcutFactor30Zcut10";
    TString aktTruTrim = "AntiKt10TruthTrimmedPtFrac1SmallR20,AntiKt10TruthTrimmedPtFrac3SmallR20,AntiKt10TruthTrimmedPtFrac5SmallR20,AntiKt10TruthTrimmedPtFrac1SmallR30,AntiKt10TruthTrimmedPtFrac3SmallR30,AntiKt10TruthTrimmedPtFrac5SmallR30";
    TString aktTruPrun = "AntiKt10TruthPrunedKtRcutFactor10Zcut5,AntiKt10TruthPrunedKtRcutFactor20Zcut5,AntiKt10TruthPrunedKtRcutFactor30Zcut5,AntiKt10TruthPrunedKtRcutFactor10Zcut10,AntiKt10TruthPrunedKtRcutFactor20Zcut10,AntiKt10TruthPrunedKtRcutFactor30Zcut10";
    
    TString caCalTrim  = "CamKt12LCTopoTrimmedPtFrac1SmallR20,CamKt12LCTopoTrimmedPtFrac3SmallR20,CamKt12LCTopoTrimmedPtFrac5SmallR20,CamKt12LCTopoTrimmedPtFrac1SmallR30,CamKt12LCTopoTrimmedPtFrac3SmallR30,CamKt12LCTopoTrimmedPtFrac5SmallR30";
    TString caCalPrun  = "CamKt12LCTopoPrunedKtRcutFactor10Zcut5,CamKt12LCTopoPrunedKtRcutFactor20Zcut5,CamKt12LCTopoPrunedKtRcutFactor30Zcut5,CamKt12LCTopoPrunedKtRcutFactor10Zcut10,CamKt12LCTopoPrunedKtRcutFactor20Zcut10,CamKt12LCTopoPrunedKtRcutFactor30Zcut10";
    TString caCalFilt  = "CamKt12LCTopoSplitFilteredmassFraction20minSplitR0,CamKt12LCTopoSplitFilteredmassFraction33minSplitR0,CamKt12LCTopoSplitFilteredmassFraction67minSplitR0";
    TString caTrkTrim  = "CamKt12TrackZTrimmedPtFrac1SmallR20,CamKt12TrackZTrimmedPtFrac3SmallR20,CamKt12TrackZTrimmedPtFrac5SmallR20,CamKt12TrackZTrimmedPtFrac1SmallR30,CamKt12TrackZTrimmedPtFrac3SmallR30,CamKt12TrackZTrimmedPtFrac5SmallR30";
    TString caTrkPrun  = "CamKt12TrackZPrunedKtRcutFactor10Zcut5,CamKt12TrackZPrunedKtRcutFactor20Zcut5,CamKt12TrackZPrunedKtRcutFactor30Zcut5,CamKt12TrackZPrunedKtRcutFactor10Zcut10,CamKt12TrackZPrunedKtRcutFactor20Zcut10,CamKt12TrackZPrunedKtRcutFactor30Zcut10";
    TString caTrkFilt  = "CamKt12TrackZSplitFilteredmassFraction20minSplitR0,CamKt12TrackZSplitFilteredmassFraction33minSplitR0,CamKt12TrackZSplitFilteredmassFraction67minSplitR0";
    TString caTruTrim  = "CamKt12TruthTrimmedPtFrac1SmallR20,CamKt12TruthTrimmedPtFrac3SmallR20,CamKt12TruthTrimmedPtFrac5SmallR20,CamKt12TruthTrimmedPtFrac1SmallR30,CamKt12TruthTrimmedPtFrac3SmallR30,CamKt12TruthTrimmedPtFrac5SmallR30";
    TString caTruPrun  = "CamKt12TruthPrunedKtRcutFactor10Zcut5,CamKt12TruthPrunedKtRcutFactor20Zcut5,CamKt12TruthPrunedKtRcutFactor30Zcut5,CamKt12TruthPrunedKtRcutFactor10Zcut10,CamKt12TruthPrunedKtRcutFactor20Zcut10,CamKt12TruthPrunedKtRcutFactor30Zcut10";
    TString caTruFilt  = "CamKt12TruthSplitFilteredmassFraction20minSplitR0,CamKt12TruthSplitFilteredmassFraction33minSplitR0,CamKt12TruthSplitFilteredmassFraction67minSplitR0";
    
    
    //// Make derived lists
    TString aktData = aktCal + "," + aktTrk + "," + aktCalTrim + "," + aktCalPrun + "," + aktTrkTrim + "," + aktTrkPrun;
    TString aktMC   = aktTru + "," + aktTruTrim + "," + aktTruPrun;
    
    TString caData = caCal + "," + caTrk + "," + caCalTrim + "," + caCalPrun + "," + caCalFilt + "," + caTrkTrim + "," + caTrkPrun + "," + caTrkFilt;
    TString caMC   = caTru + "," + caTruTrim + "," + caTruPrun + "," + caTruFilt;
    
    
    //// DEFAULT FULL LIST
    TString jetTypes = aktData + "," + caData;
    if (!dataset.Contains("data")) jetTypes += "," + aktMC + "," + caMC;

    //// REDUCED SET OF JETS
    if (doSomeJetTypes) {
      jetTypes   = "AntiKt10LCTopo,CamKt12LCTopo,AntiKt10LCTopoTrimmedPtFrac3SmallR30,AntiKt10LCTopoTrimmedPtFrac5SmallR30,CamKt12LCTopoSplitFilteredmassFraction67minSplitR0,AntiKt10TrackZ,CamKt12TrackZ,AntiKt10TrackZTrimmedPtFrac3SmallR30,AntiKt10TrackZTrimmedPtFrac5SmallR30,CamKt12TrackZSplitFilteredmassFraction67minSplitR0";
        if (!dataset.Contains("data")) jetTypes += ",AntiKt10Truth,CamKt12Truth,AntiKt10TruthTrimmedPtFrac3SmallR30,AntiKt10TruthTrimmedPtFrac5SmallR30,CamKt12TruthSplitFilteredmassFraction67minSplitR0";
    }
    
    else if (!doSomeJetTypes && doMinJetTypes) {
      jetTypes   = "AntiKt10LCTopo,CamKt12LCTopo,AntiKt10LCTopoTrimmedPtFrac5SmallR30,CamKt12LCTopoSplitFilteredmassFraction67minSplitR0,AntiKt10TrackZ,CamKt12TrackZ,AntiKt10TrackZTrimmedPtFrac5SmallR30,CamKt12TrackZSplitFilteredmassFraction67minSplitR0";
        if (!dataset.Contains("data")) jetTypes += ",AntiKt10Truth,CamKt12Truth,AntiKt10TruthTrimmedPtFrac5SmallR30,CamKt12TruthSplitFilteredmassFraction67minSplitR0";
    }
        
    //jetTypes = aktCal + "," + aktTrk + "," + aktCalTrim + "," + aktTrkTrim;
    //jetTypes = caCal + "," + caTrk + "," + caCalTrim + "," + caTrkTrim;
    //jetTypes = aktCalPrun + "," + aktTrkPrun + "," + caCalPrun + "," + caTrkPrun;
    //jetTypes = caCalFilt + "," + caTrkFilt;
  
    
    // Be careful when loading up subjettypes and btagtypes: check that 
    // these exist in the D3PD before trying to register them!
    TString subjetTypes = "AntiKt10LCTopoTrimmedSubjetsPtFrac3SmallR30,AntiKt10TrackZTrimmedSubjetsPtFrac3SmallR30,AntiKt10TruthTrimmedSubjetsPtFrac3SmallR30";
    TString btagTypes = "AntiKt10LCTopoTrimmedSubjetsPtFrac3SmallR30";


    ///---------------------------------------------------------------
    /// New jet types! These will be constructed on the fly
    ///---------------------------------------------------------------

    TString baseCustomTrimming = "AntiKtLCTopo15";
    TString ptFracCustomTrimming = "0.05";
    TString smallRCustomTrimming = "0.3";


    ///----------------------------------------------------------------
    /// Nominal Configuration
    ///----------------------------------------------------------------
    Config* chain = new Config("chain",configfile);
    chain->AddVec("ANALYSIS");


    Config* setup = new Config("setup", configfile);
    setup->Set("ANALYSIS","GRJETSexample_setup");
    setup->Set("DEBUG",debug);
    chain->Add("ANALYSIS",setup);

    Config* example = new Config("example", configfile);
    example->Set("ANALYSIS","GRJETSexample");
    example->Set("DEBUG",debug);
    chain->Add("ANALYSIS",example);
    

    cout << endl << "+++ Using jet types: " << jetTypes << endl << endl;


    chain->Set("MCWEIGHTS"       , mcweights       );
    chain->Set("DEBUG"           , debug           );
    chain->Set("PILE"            , doPRW           );
    chain->Set("DOBASIC"         , doBasic         );
    chain->Set("DOTRUTHLINKS"    , doTruthLinks    );
    chain->Set("DOTRACKJETLINKS" , doTrackJetLinks );
    chain->Set("DOTRUTHJETLINKS" , doTruthJetLinks );
    chain->Set("DOJETSTRUCT"     , doJetStructure  );
    chain->Set("DOCONSTIT"       , doConstituents  );
    chain->Set("DOTRUTHCONSTIT"  , doTruthConstit  );
    chain->Set("DOPARENTCHILD"   , doParentChild   );
    chain->Set("DOTRACK"         , doTrack         );
    chain->Set("DOLCCLUSTER"     , doLCCluster     );
    chain->Set("DOEMCLUSTER"     , doEMCluster     );
    chain->Set("DOTRUTH"         , doTruth         );
    chain->Set("DOVTX"           , doVertex        );
    chain->Set("DOPHOTON"        , doPhotons       );
    
    /// Set Systematics
    chain->Set("DOTRACKSYST"     , false           );
    chain->Set("DOJETSYS"        , 0               );
    
    /// Set cuts and jet types and such
    chain->Set("BASECUSTOMTRIMMING",   baseCustomTrimming);
    chain->Set("PTFRACCUSTOMTRIMMING", ptFracCustomTrimming);
    chain->Set("SMALLRCUSTOMTRIMMING", smallRCustomTrimming);
    chain->Set("JETTYPES"       , jetTypes         );
    chain->Set("SUBJETTYPES"    , subjetTypes      );
    chain->Set("BTAGTYPES"      , btagTypes        );
    chain->Set("BADJETTYPE"     , badJetType       );
    chain->Set("BADJETDEF"      , badJetDef        );
    chain->Set("MINJETPT"       , minJetPt         );
    chain->Set("MAXJETETA"      , maxJetEta        );
    chain->Set("MINFATJETPT"    , minFatJetPt      );
    chain->Set("MAXFATJETETA"   , maxJetEta        );
    chain->Set("MINJETJVF"      , minJetJVF        );
    chain->Set("MAXJETTRKJETDR" , maxJetTrkDR      );
    chain->Set("MAXTRUTHJETDR"  , maxJetTruthDR    );
    
    chain->Set("NStdJetCut"     , 4                );
    chain->Set("LowMassCRcut"   , 100.             );
    chain->Set("ThreeBodyCRcut" , 0.7              );
    chain->Set("y12CRcut"       , 0.4              );
    
    ///----------------------------------------------------------------
    /// Trigger Information
    ///----------------------------------------------------------------
    TString trigTypes  = "EF_j360_a10tcem";
    TString trigParams = "jet_AntiKt10LCTopo_pt";
    TString trigCuts   = "450000.";               /// NEEDS TO BE IN MEV
    TString trigLumis  = "5725.04";               /// UPDATE ME!
    
    chain->Set("TRIGTYPES"      , trigTypes      );
    chain->Set("TRIGPARAM"      , trigParams     );
    chain->Set("TRIGCUT"        , trigCuts       );
    chain->Set("TRIGLUMI"       , trigLumis      );
    
    ///----------------------------------------------------------------
    /// Luminosity for trigger weighting
    ///----------------------------------------------------------------
    Float_t lumiVal = 5725.04;
    
    chain->Set("LUMI"           , lumiVal        );
    
    chain->Write();

    if (chain->Exists("GRL")) WriteGRLObject(chain->String("GRL"));  
  
		
	

    ///----------------------------------------------------------------
    /// ProofAna global Config object
    ///----------------------------------------------------------------
    Config* confProofAna = new Config("ProofAna");
    
    confProofAna->Set("DEBUG"          , false        );  // "false", 0, "0" etc. also works
    confProofAna->Set("SAVETIMERS"     , false        );  // ProofAna timer histos in output file 
    confProofAna->Set("IDENTIFIER"     , identifier   );
    confProofAna->Set("DATASET"        , dataset      );
    confProofAna->Set("OUTPUTPATH"     , path         );
    confProofAna->Set("EVENTBUILDER"   , eventbuilder );
    if (!doHists) 
      confProofAna->Set("MERGE"        , false        );     // enable dataset mode
    
    ///----------------------------------------------------------------
    /// Read information used in MC weighting, multi-dataset jobs
    ///----------------------------------------------------------------
    ReadDatasetInfo(dataset  , confProofAna  ); 
    WriteGroomedPRWO(options , "EF_j360_a10tcem_PeriodB" );
    confProofAna->Write();  
    options->Close();
    delete options;


    cout << "All setup, ready to go " << endl;    
    // Decide to run local or on the cluster
    if (mode.CompareTo("local") == 0) runLocal(dataset, treename);
    else if(mode.CompareTo("lite")==0||mode.CompareTo("cluster")==0) 
      runProof(url,dataset,-1,treename);
    else if(mode.CompareTo("grid")==0){
      TString gridname = "user."+gridusername+"."+identifier;
      cout << "submitting with gridname " << gridname << endl;
      runGrid(gridname);
    }   
    gSystem->Unlink("options.root");
}
Example #27
0
void run_sim()
{
    TString transport = "TGeant4";
    Bool_t userPList = kFALSE; // option for TGeant4

    TString outFile = "sim.root";
    TString parFile = "par.root";

    Bool_t magnet = kTRUE;
    Float_t fieldScale = -0.68;

    TString generator1 = "box";
    TString generator2 = "ascii";
    TString generator3 = "r3b";
    TString generator = generator1;
    TString inputFile = "";

    Int_t nEvents = 1;
    Bool_t storeTrajectories = kTRUE;
    Int_t randomSeed = 335566; // 0 for time-dependent random numbers

    // Target type
    TString target1 = "LeadTarget";
    TString target2 = "Para";
    TString target3 = "Para45";
    TString target4 = "LiH";
    TString targetType = target4;

    // ------------------------------------------------------------------------
    // Stable part ------------------------------------------------------------

    TString dir = getenv("VMCWORKDIR");

    // ----    Debug option   -------------------------------------------------
    gDebug = 0;

    // -----   Timer   --------------------------------------------------------
    TStopwatch timer;
    timer.Start();

    // -----   Create simulation run   ----------------------------------------
    FairRunSim* run = new FairRunSim();
    run->SetName(transport);            // Transport engine
    run->SetOutputFile(outFile.Data()); // Output file
    FairRuntimeDb* rtdb = run->GetRuntimeDb();

    //  R3B Special Physics List in G4 case
    if ((userPList == kTRUE) && (transport.CompareTo("TGeant4") == 0))
    {
        run->SetUserConfig("g4R3bConfig.C");
        run->SetUserCuts("SetCuts.C");
    }

    // -----   Create media   -------------------------------------------------
    run->SetMaterials("media_r3b.geo"); // Materials

    // -----   Create R3B geometry --------------------------------------------
    // R3B Cave definition
    FairModule* cave = new R3BCave("CAVE");
    cave->SetGeometryFileName("r3b_cave.geo");
    run->AddModule(cave);

    // To skip the detector comment out the line with: run->AddModule(...

    // Target
    run->AddModule(new R3BTarget(targetType, "target_" + targetType + ".geo.root"));

    // GLAD
    //run->AddModule(new R3BGladMagnet("glad_v17_flange.geo.root")); // GLAD should not be moved or rotated

    // PSP
    run->AddModule(new R3BPsp("psp_v13a.geo.root", {}, -221., -89., 94.1));

    // R3B SiTracker Cooling definition
    //run->AddModule(new R3BVacVesselCool(targetType, "vacvessel_v14a.geo.root"));

    // STaRTrack
    //run->AddModule(new R3BSTaRTra("startra_v16-300_2layers.geo.root", { 0., 0., 20. }));

    // CALIFA
    R3BCalifa* califa = new R3BCalifa("califa_10_v8.11.geo.root");
    califa->SelectGeometryVersion(10);
    // Selecting the Non-uniformity of the crystals (1 means +-1% max deviation)
    califa->SetNonUniformity(1.0);
    //run->AddModule(califa);

    // Tof
    //run->AddModule(new R3BTof("tof_v17a.geo.root", { -417.359574, 2.400000, 960.777114 }, { "", -90., +31., 90. }));

    // mTof
    run->AddModule(new R3BmTof("mtof_v17a.geo.root", { -155.824045, 0.523976, 761.870346 }, { "", -90., +16.7, 90. }));

    // MFI
    //run->AddModule(new R3BMfi("mfi_v17a.geo.root", { -63.82, 0., 520.25 }, { "", 90., +13.5, 90. })); // s412

    // NeuLAND
    // run->AddModule(new R3BNeuland("neuland_test.geo.root", { 0., 0., 1400. + 12 * 5. }));

    // -----   Create R3B  magnetic field ----------------------------------------
    // NB: <D.B>
    // If the Global Position of the Magnet is changed
    // the Field Map has to be transformed accordingly
    R3BGladFieldMap* magField = new R3BGladFieldMap("R3BGladMap");
    magField->SetScale(fieldScale);

    if (magnet == kTRUE)
    {
        run->SetField(magField);
    }
    else
    {
        run->SetField(NULL);
    }

    // -----   Create PrimaryGenerator   --------------------------------------
    // 1 - Create the Main API class for the Generator
    FairPrimaryGenerator* primGen = new FairPrimaryGenerator();

    if (generator.CompareTo("box") == 0)
    {
        FairIonGenerator* boxGen = new FairIonGenerator(50, 128, 50, 1, 0., 0., 1.3, 0., 0., 0.);
        primGen->AddGenerator(boxGen);
    }

    if (generator.CompareTo("ascii") == 0)
    {
        R3BAsciiGenerator* gen = new R3BAsciiGenerator((dir + "/input/" + inputFile).Data());
        primGen->AddGenerator(gen);
    }

    run->SetGenerator(primGen);

    run->SetStoreTraj(storeTrajectories);

    FairLogger::GetLogger()->SetLogVerbosityLevel("LOW");
    FairLogger::GetLogger()->SetLogScreenLevel("INFO");

    // -----   Initialize simulation run   ------------------------------------
    run->Init();
    TVirtualMC::GetMC()->SetRandom(new TRandom3(randomSeed));

    // ------  Increase nb of step for CALO
    Int_t nSteps = -15000;
    TVirtualMC::GetMC()->SetMaxNStep(nSteps);

    // -----   Runtime database   ---------------------------------------------
    R3BFieldPar* fieldPar = (R3BFieldPar*)rtdb->getContainer("R3BFieldPar");
    if (NULL != magField)
    {
        fieldPar->SetParameters(magField);
        fieldPar->setChanged();
    }
    Bool_t kParameterMerged = kTRUE;
    FairParRootFileIo* parOut = new FairParRootFileIo(kParameterMerged);
    parOut->open(parFile.Data());
    rtdb->setOutput(parOut);
    rtdb->saveOutput();
    rtdb->print();

    // -----   Start run   ----------------------------------------------------
    if (nEvents > 0)
    {
        run->Run(nEvents);
    }

    // -----   Finish   -------------------------------------------------------
    timer.Stop();
    Double_t rtime = timer.RealTime();
    Double_t ctime = timer.CpuTime();
    cout << endl << endl;
    cout << "Macro finished succesfully." << endl;
    cout << "Output file is " << outFile << endl;
    cout << "Parameter file is " << parFile << endl;
    cout << "Real time " << rtime << " s, CPU time " << ctime << "s" << endl << endl;

    cout << " Test passed" << endl;
    cout << " All ok " << endl;

    // Snap a picture of the geometry
    // If this crashes, set "OpenGL.SavePicturesViaFBO: no" in your .rootrc
    /*gStyle->SetCanvasPreferGL(kTRUE);
    gGeoManager->GetTopVolume()->Draw("ogl");
    TGLViewer* v = (TGLViewer*)gPad->GetViewer3D();
    v->SetStyle(TGLRnrCtx::kOutline);
    v->RequestDraw();
    v->SavePicture("run_sim-side.png");
    v->SetPerspectiveCamera(TGLViewer::kCameraPerspXOZ, 25., 0, 0, -90. * TMath::DegToRad(), 0. * TMath::DegToRad());
    v->SavePicture("run_sim-top.png");*/
}
Example #28
0
void splitNtupleByGenInfo(TString inputFilepath = "/eos/uscms/store/user/aperloff/MatrixElement/Summer12ME8TeV/MEInput/", TString outputDir = "./", TString hTo = "WW", bool eventNtupleOnly = true, TString postfix = "") {

   TString folderName = "";
   if(eventNtupleOnly)
      folderName = "PS/";
   TString inputTreeName = "";
   if(eventNtupleOnly)
      inputTreeName = "jets2p";
   else
      inputTreeName = "METree";

   cout << "Opening input files ... ";
   TFile* ifile;
   TString ifilename;
   if(eventNtupleOnly) {
      ifilename = inputFilepath+"WH_ZH_TTH_HTo"+hTo+"_M125"+postfix+".root";
      ifile = new TFile(ifilename.Data(),"READ");
   }
   else {
      ifilename = inputFilepath+"microWH_ZH_TTH_HTo"+hTo+"_M125"+postfix+"_BaseCuts.root";
      ifile = new TFile(ifilename.Data(),"READ");
   }
   cout << "DONE" << endl;
   cout << "\t" << ifilename << endl;

   cout << "Making all of the input ntuples ... ";
   EventNtuple *ntuple      = new EventNtuple();
   METree *metree           = new METree();
   MicroNtuple *mnt         = new MicroNtuple();
   cout << "DONE" << endl;

   cout << "Setting up EventNtuple ... " << flush;
   TTree *t1 = (TTree*)gDirectory->Get(folderName+inputTreeName);
   if(eventNtupleOnly)
      t1->SetBranchAddress("EvtNtuple", &ntuple);
   else
      t1->SetBranchAddress("EvtTree", &ntuple);
   int nEventNtuple = static_cast<int>(t1->GetEntries());
   cout << "DONE" << endl;

   cout << endl << "Setting up the output file and chain ... " << flush;
   TString prefix = "";
   if(!eventNtupleOnly) {
      prefix = "micro";
      postfix += "_BaseCuts";
   }
   TFile WHFile(outputDir+prefix+"WH_HTo"+hTo+"_M125"+postfix+".root", "RECREATE");
   if(eventNtupleOnly) {
      WHFile.mkdir("PS");
      WHFile.cd("PS");
   }
   TChain *WHEventNtuple = (TChain*)t1->CloneTree(0);

   TFile ZHFile(outputDir+prefix+"ZH_HTo"+hTo+"_M125"+postfix+".root", "RECREATE");
   if(eventNtupleOnly) {
      ZHFile.mkdir("PS");
      ZHFile.cd("PS");
   }
   TChain *ZHEventNtuple = (TChain*)t1->CloneTree(0);

   TFile TTHFile(outputDir+prefix+"TTH_HTo"+hTo+"_M125"+postfix+".root", "RECREATE");
   if(eventNtupleOnly) {
      TTHFile.mkdir("PS");
      TTHFile.cd("PS");
   }
   TChain *TTHEventNtuple = (TChain*)t1->CloneTree(0);
   cout << "DONE" << endl;

   cout << endl << "Looping through the input EventNtuple/MicroNtuple ... " << endl;
   int nMatchedToWH = 0, nMatchedToZH = 0, nMatchedToTTH = 0, nUnmatched = 0, nMultiMatch = 0;
   vector<pair<int,int> > MultiMatchSampleEvents, UnmatchedSampleEvents;
   for(int ientry=0; ientry<nEventNtuple; ientry++) {
      t1->GetEntry(ientry);
      loadbar(ientry+1,nEventNtuple);

      int nW = 0, nZ = 0, nT = 0, nH = 0;
      for (unsigned int i=0; i<ntuple->genParticleCollection.size() && i< 30; i++) {
         if(abs(ntuple->genParticleCollection[i].pdgId)==24) {
            nW++;
            for (int j=0; j<ntuple->genParticleCollection[i].numberOfMothers; j++) {
               if (abs(ntuple->genParticleCollection[ntuple->genParticleCollection[i].motherPositions[j]].pdgId)==6)
                  nW--;
            }
         }
         if(abs(ntuple->genParticleCollection[i].pdgId)==23)
            nZ++;
         if(abs(ntuple->genParticleCollection[i].pdgId)==6)
            nT++;
         if(abs(ntuple->genParticleCollection[i].pdgId)==25)
            nH++;
      }

      if(hTo.CompareTo("WW")==0) {
         if(nW >= 3 && nZ == 0 && nT < 2 && nH == 1) {
            WHEventNtuple->Fill();
            nMatchedToWH++;
         }
         else if(nW == 2 && nZ == 1 && nT == 0 && nH == 1) {
            ZHEventNtuple->Fill();
            nMatchedToZH++;
         }
         else if(nW == 2 && nZ == 0 && nT == 2 && nH == 1) {
            TTHEventNtuple->Fill();
            nMatchedToTTH++;
         }
         else if((nW > 2 && nZ > 0 && nT == 0 && nH > 0) ||
                 (nW > 2 && nZ == 0 && nT > 0 && nH > 0) ||
                 (nW == 2 && nZ > 0 && nT > 0 && nH > 0)){
            nMultiMatch++;
            MultiMatchSampleEvents.push_back(make_pair(ientry,ntuple->event));
         }
         else {
            nUnmatched++;
            UnmatchedSampleEvents.push_back(make_pair(ientry,ntuple->event));
         }
      }
      else if(hTo.CompareTo("ZZ")==0) {
         if(ntuple->event == 201693) {
            ZHEventNtuple->Fill();
            nMatchedToZH++;
         }
         else if(nW == 1 && nZ == 2 && nT < 2 && nH == 1) {
            WHEventNtuple->Fill();
            nMatchedToWH++;
         }
         else if(nW == 0 && nZ >= 3 && nT == 0 && nH == 1) {
            ZHEventNtuple->Fill();
            nMatchedToZH++;
         }
         else if(nW == 0 && nZ == 2 && nT == 2 && nH == 1) {
            TTHEventNtuple->Fill();
            nMatchedToTTH++;
         }
         else if((nW > 0 && nZ > 2 && nT == 0 && nH > 0) ||
                 (nW > 0 && nZ == 2 && nT > 0 && nH > 0) ||
                 (nW == 0 && nZ > 2 && nT > 0 && nH > 0)){
            nMultiMatch++;
            MultiMatchSampleEvents.push_back(make_pair(ientry,ntuple->event));
         }
         else {
            nUnmatched++;
            UnmatchedSampleEvents.push_back(make_pair(ientry,ntuple->event));
         }
      }
   }

   cout << endl << "Printing the matching information ... " << endl;
   cout << "\t" << setw(12) << "Sample"     << setw(12) << "nMatched"    << endl
        << "\t" << setw(12) << "------"     << setw(12) << "--------"    << endl
        << "\t" << setw(12) << "Original"   << setw(12) << nEventNtuple  << endl
        << "\t" << setw(12) << "------"     << setw(12) << "--------"    << endl
        << "\t" << setw(12) << "WH"         << setw(12) << nMatchedToWH  << endl
        << "\t" << setw(12) << "ZH"         << setw(12) << nMatchedToZH  << endl
        << "\t" << setw(12) << "TTH"        << setw(12) << nMatchedToTTH << endl
        << "\t" << setw(12) << "MultiMatch" << setw(12) << nMultiMatch   << endl
        << "\t" << setw(12) << "Unmatched"  << setw(12) << nUnmatched    << endl
        << "\t" << setw(12) << "------"     << setw(12) << "--------"    << endl
        << "\t" << setw(12) << "Total"      << setw(12) << nMatchedToWH+nMatchedToZH+nMatchedToTTH+nMultiMatch+nUnmatched << endl;

   cout << endl << "If MultiMatch or Unmatched events, print the first 10 sample (entry,event) for each ... " << endl;
   cout << "\tMultiMatch: ";
   for(unsigned int i=0; i<MultiMatchSampleEvents.size() && i<10; i++) {
      cout << "(" << MultiMatchSampleEvents[i].first << "," << MultiMatchSampleEvents[i].second << ")";
      if(i==9 || i==MultiMatchSampleEvents.size()-1)
         cout << endl;
      else
         cout << ", ";
   }
   if(MultiMatchSampleEvents.size()==0)
      cout << endl;
   cout << "\tUnmatched: ";
   for(unsigned int i=0; i<UnmatchedSampleEvents.size() && i<10; i++) {
      cout << "(" << UnmatchedSampleEvents[i].first << "," << UnmatchedSampleEvents[i].second << ")";
      if(i==9 || i==UnmatchedSampleEvents.size()-1)
         cout << endl;
      else
         cout << ", ";
   }
   if(UnmatchedSampleEvents.size()==0)
      cout << endl;

   cout << "Write the output TTrees in the appropriate files ... " << flush;
   if(eventNtupleOnly)
      WHFile.cd("PS");
   WHEventNtuple->AutoSave();
   WHEventNtuple->Write();
   if(eventNtupleOnly)
      ZHFile.cd("PS");
   ZHEventNtuple->AutoSave();
   ZHEventNtuple->Write();
   if(eventNtupleOnly)
      TTHFile.cd("PS");
   TTHEventNtuple->AutoSave();
   TTHEventNtuple->Write();
   cout << "DONE" << endl;

   cout << "Close all the files ... " << flush;
   ifile->Close();
   WHFile.Close();
   ZHFile.Close();
   TTHFile.Close();
   cout << "DONE" << endl;

}
Example #29
0
void r3ball_batch(Int_t nEvents = 1,
	    TObjArray& fDetList,
	    TString Target = "LeadTarget",
		Bool_t fVis=kFALSE,
		TString fMC="TGeant3",
	    TString fGenerator="box",
	    Bool_t fUserPList= kFALSE,
		Bool_t fR3BMagnet= kTRUE,
		Double_t fEnergyP=1.0,
		Int_t fMult=1, 
		Int_t fGeoVer=5, 
		Double_t fNonUni=1.0	
			)
{


  TString dir = getenv("VMCWORKDIR");
  TString r3bdir = dir + "/macros";

  TString r3b_geomdir = dir + "/geometry";
  gSystem->Setenv("GEOMPATH",r3b_geomdir.Data());

  TString r3b_confdir = dir + "gconfig";
  gSystem->Setenv("CONFIG_DIR",r3b_confdir.Data());

// Output files
  TString OutFile = "r3bsim.root";
  TString ParFile = "r3bpar.root";


  // In general, the following parts need not be touched
  // ========================================================================

  // ----    Debug option   -------------------------------------------------
  gDebug = 0;
  // ------------------------------------------------------------------------

  // -----   Timer   --------------------------------------------------------
  TStopwatch timer;
  timer.Start();
  // ------------------------------------------------------------------------

 
  // -----   Create simulation run   ----------------------------------------
  FairRunSim* run = new FairRunSim();
  run->SetName(fMC.Data());                  // Transport engine
  run->SetOutputFile(OutFile.Data());        // Output file
  FairRuntimeDb* rtdb = run->GetRuntimeDb();

  //  R3B Special Physics List in G4 case
  if ( (fUserPList  == kTRUE ) &&
       (fMC.CompareTo("TGeant4")   == 0)
      ){
       run->SetUserConfig("g4R3bConfig.C");
       run->SetUserCuts("SetR3BCuts.C");
   }


  // -----   Create media   -------------------------------------------------
  run->SetMaterials("media_r3b.geo");       // Materials
  

  // Magnetic field map type
   Int_t fFieldMap = 0;


  // Global Transformations
  //- Two ways for a Volume Rotation are supported
  //-- 1) Global Rotation (Euler Angles definition)
  //-- This represent the composition of : first a rotation about Z axis with
  //-- angle phi, then a rotation with theta about the rotated X axis, and
  //-- finally a rotation with psi about the new Z axis.
  Double_t phi,theta,psi;

  //-- 2) Rotation in Ref. Frame of the Volume
  //-- Rotation is Using Local Ref. Frame axis angles
  Double_t thetaX,thetaY,thetaZ;


  //- Global Translation  Lab. frame.
  Double_t tx,ty,tz;

  // - Polar angular limits
  Double_t minTheta=35., maxTheta=55.;


  // -----   Create R3B geometry --------------------------------------------
  //R3B Cave definition
  FairModule* cave= new R3BCave("CAVE");
  cave->SetGeometryFileName("r3b_cave.geo");
  run->AddModule(cave);


  //R3B Target definition
  if (fDetList.FindObject("TARGET") ) {
      R3BModule* target= new R3BTarget(Target.Data());
      // Global Lab. Rotation
      phi    =  0.0; // (deg)
      theta  =  0.0; // (deg)
      psi    =  0.0; // (deg)
      // Rotation in Ref. Frame.
      thetaX =  0.0; // (deg)
      thetaY =  0.0; // (deg)
      thetaZ =  0.0; // (deg)
      // Global translation in Lab
      tx    =  0.0; // (cm)
      ty    =  0.0; // (cm)
      tz    =  0.0; // (cm)
     //target->SetRotAnglesEuler(phi,theta,psi);
     target->SetRotAnglesXYZ(thetaX,thetaY,thetaZ);
     target->SetTranslation(tx,ty,tz);
      run->AddModule(target);
  }

  //R3B Magnet definition
  if (fDetList.FindObject("ALADIN") ) {
    fFieldMap = 0;
    R3BModule* mag = new R3BMagnet("AladinMagnet");
    mag->SetGeometryFileName("aladin_v13a.geo.root");
    run->AddModule(mag);
  }

    //R3B Magnet definition
  if (fDetList.FindObject("GLAD") ) {
      fFieldMap = 1;
      R3BModule* mag = new R3BGladMagnet("GladMagnet");
      // Global position of the Module
      phi   =  0.0; // (deg)
      theta =  0.0; // (deg)
      psi   =  0.0; // (deg)
      // Rotation in Ref. Frame.
      thetaX =  0.0; // (deg)
      thetaY =  0.0; // (deg)
      thetaZ =  0.0; // (deg)
      // Global translation in Lab
      tx    =  0.0; // (cm)
      ty    =  0.0; // (cm)
      tz    =  0.0; // (cm)
      //mag->SetRotAnglesEuler(phi,theta,psi);
      mag->SetRotAnglesXYZ(thetaX,thetaY,thetaZ);
      mag->SetTranslation(tx,ty,tz);
      run->AddModule(mag);
  }

  if (fDetList.FindObject("CRYSTALBALL") ) {
      //R3B Crystal Calorimeter
      R3BDetector* xball = new R3BXBall("XBall", kTRUE);
      xball->SetGeometryFileName("cal_v13a.geo.root");
      run->AddModule(xball);
  }

  if (fDetList.FindObject("CALIFA") ) {
    // CALIFA Calorimeter
    R3BDetector* calo = new R3BCalo("Califa", kTRUE);
    ((R3BCalo *)calo)->SelectGeometryVersion(10);
    //Selecting the Non-uniformity of the crystals (1 means +-1% max deviation)
    ((R3BCalo *)calo)->SetNonUniformity(1.0);
    calo->SetGeometryFileName("califa_v13_811.geo.root");
    run->AddModule(calo);
  }

  // Tracker
  if (fDetList.FindObject("TRACKER")  ) {
      R3BDetector* tra = new R3BTra("Tracker", kTRUE);
      // Global position of the Module
      phi   =  0.0; // (deg)
      theta =  0.0; // (deg)
      psi   =  0.0; // (deg)
      // Rotation in Ref. Frame.
      thetaX =  0.0; // (deg)
      thetaY =  0.0; // (deg)
      thetaZ =  0.0; // (deg)
      // Global translation in Lab
      tx    =  0.0; // (cm)
      ty    =  0.0; // (cm)
      tz    =  0.0; // (cm)
      //tra->SetRotAnglesEuler(phi,theta,psi);
      tra->SetRotAnglesXYZ(thetaX,thetaY,thetaZ);
      tra->SetTranslation(tx,ty,tz);
      // User defined Energy CutOff
      Double_t fCutOffSi = 1.0e-06;  // Cut-Off -> 10KeV only in Si
      ((R3BTra*) tra)->SetEnergyCutOff(fCutOffSi);
      run->AddModule(tra);
  }
  
  // DCH drift chambers
  if (fDetList.FindObject("DCH") ) {
      R3BDetector* dch = new R3BDch("Dch", kTRUE);
      ((R3BDch*) dch )->SetHeliumBag(kTRUE);
      // Global position of the Module
      phi   =  0.0; // (deg)
      theta =  0.0; // (deg)
      psi   =  0.0; // (deg)
      // Rotation in Ref. Frame.
      thetaX =  0.0; // (deg)
      thetaY =  0.0; // (deg)
      thetaZ =  0.0; // (deg)
      // Global translation in Lab
      tx    =  0.0; // (cm)
      ty    =  0.0; // (cm)
      tz    =  0.0; // (cm)
     //dch->SetRotAnglesEuler(phi,theta,psi);
      dch->SetRotAnglesXYZ(thetaX,thetaY,thetaZ);
      dch->SetTranslation(tx,ty,tz);
      run->AddModule(dch);
  }

  // Tof
  if (fDetList.FindObject("TOF") ) {
      R3BDetector* tof = new R3BTof("Tof", kTRUE);
      // Global position of the Module
      thetaX   =  0.0; // (deg)
      thetaY   =  0.0; // (deg)
      thetaZ   =  0.0; // (deg)
      // Rotation in Ref. Frame.
      thetaX =  0.0; // (deg)
      thetaY =  0.0; // (deg)
      thetaZ =  0.0; // (deg)
      // Global translation in Lab
      tx       =  0.0; // (cm)
      ty       =  0.0; // (cm)
      tz       =  0.0; // (cm)
      tof->SetRotAnglesXYZ(thetaX,thetaY,thetaZ);
      tof->SetTranslation(tx,ty,tz);
      // User defined Energy CutOff
      Double_t fCutOffSci = 1.0e-05;  // Cut-Off -> 10.KeV only in Sci.
      ((R3BTof*) tof)->SetEnergyCutOff(fCutOffSci);
      run->AddModule(tof);
  }

  // mTof
  if (fDetList.FindObject("MTOF") ) {
      R3BDetector* mTof = new R3BmTof("mTof", kTRUE);
      // Global position of the Module
      phi   =  0.0; // (deg)
      theta =  0.0; // (deg)
      psi   =  0.0; // (deg)
      // Rotation in Ref. Frame.
      thetaX =  0.0; // (deg)
      thetaY =  0.0; // (deg)
      thetaZ =  0.0; // (deg)
      // Global translation in Lab
      tx    =  0.0; // (cm)
      ty    =  0.0; // (cm)
      tz    =  0.0; // (cm)
      //mTof->SetRotAnglesEuler(phi,theta,psi);
      mTof->SetRotAnglesXYZ(thetaX,thetaY,thetaZ);
      mTof->SetTranslation(tx,ty,tz);
      // User defined Energy CutOff
      Double_t fCutOffSci = 1.0e-05;  // Cut-Off -> 10.KeV only in Sci.
      ((R3BmTof*) mTof)->SetEnergyCutOff(fCutOffSci);
      run->AddModule(mTof);
  }

  // GFI detector
  if (fDetList.FindObject("GFI") ) {
      R3BDetector* gfi = new R3BGfi("Gfi", kTRUE);
      // Global position of the Module
      phi   =  0.0; // (deg)
      theta =  0.0; // (deg)
      psi   =  0.0; // (deg)
      // Rotation in Ref. Frame.
      thetaX =  0.0; // (deg)
      thetaY =  0.0; // (deg)
      thetaZ =  0.0; // (deg)
      // Global translation in Lab
      tx    =  0.0; // (cm)
      ty    =  0.0; // (cm)
      tz    =  0.0; // (cm)
      gfi->SetRotAnglesXYZ(thetaX,thetaY,thetaZ);
      gfi->SetTranslation(tx,ty,tz);
      // User defined Energy CutOff
      Double_t fCutOffSci = 1.0e-05;  // Cut-Off -> 10.KeV only in Sci.
      ((R3BGfi*) gfi)->SetEnergyCutOff(fCutOffSci);
      run->AddModule(gfi);
  }

  // Land Detector
  if (fDetList.FindObject("LAND") ) {
      R3BDetector* land = new R3BLand("Land", kTRUE);
      land->SetGeometryFileName("land_v12a_10m.geo.root");
      run->AddModule(land);
  }

  // Chimera
  if (fDetList.FindObject("CHIMERA") ) {
      R3BDetector* chim = new R3BChimera("Chimera", kTRUE);
      chim->SetGeometryFileName("chimera.root");
      // Global position of the Module
      thetaX   =  0.0; // (deg)
      thetaY   =  0.0; // (deg)
      thetaZ   =  0.0; // (deg)
      // Rotation in Ref. Frame.
      thetaX =  0.0; // (deg)
      thetaY =  0.0; // (deg)
      thetaZ =  0.0; // (deg)
      // Global translation in Lab
      tx       =  0.0; // (cm)
      ty       =  0.0; // (cm)
      tz       =  0.0; // (cm)
      chim->SetRotAnglesXYZ(thetaX,thetaY,thetaZ);
      chim->SetTranslation(tx,ty,tz);
      // User defined Energy CutOff
      //Double_t fCutOffSci = 1.0e-05;  // Cut-Off -> 10.KeV only in Sci.
      //((R3BChimera*) chim)->SetEnergyCutOff(fCutOffSci);
      run->AddModule(chim);
  }

  // Luminosity detector
  if (fDetList.FindObject("LUMON") ) {
      R3BDetector* lumon = new ELILuMon("LuMon", kTRUE);
      //lumon->SetGeometryFileName("lumon.root");
      // Global position of the Module
      thetaX   =  0.0; // (deg)
      thetaY   =  0.0; // (deg)
      thetaZ   =  0.0; // (deg)
      // Rotation in Ref. Frame.
      thetaX =  0.0; // (deg)
      thetaY =  0.0; // (deg)
      thetaZ =  0.0; // (deg)
      // Global translation in Lab
      tx       =  0.0; // (cm)
      ty       =  0.0; // (cm)
      tz       =  200.0; // (cm)
      lumon->SetRotAnglesXYZ(thetaX,thetaY,thetaZ);
      lumon->SetTranslation(tx,ty,tz);
      // User defined Energy CutOff
      //Double_t fCutOffSci = 1.0e-05;  // Cut-Off -> 10.KeV only in Sci.
      //((ELILuMon*) lumon)->SetEnergyCutOff(fCutOffSci);
      run->AddModule(lumon);
  }


  
  // -----   Create R3B  magnetic field ----------------------------------------
  Int_t typeOfMagneticField = 0;
  Int_t fieldScale = 1;
  Bool_t fVerbose = kFALSE;

  //NB: <D.B>
  // If the Global Position of the Magnet is changed
  // the Field Map has to be transformed accordingly

  if (fFieldMap == 0) {
    R3BFieldMap* magField = new R3BFieldMap(typeOfMagneticField,fVerbose);
    magField->SetPosition(0., 0., 0.);
    magField->SetScale(fieldScale);

    if ( fR3BMagnet == kTRUE ) {
	run->SetField(magField);
    } else {
	run->SetField(NULL);
    }
  } else if(fFieldMap == 1){
    R3BGladFieldMap* magField = new R3BGladFieldMap("R3BGladMap");
    magField->SetPosition(0., 0., +350-119.94);
    magField->SetScale(fieldScale);

    if ( fR3BMagnet == kTRUE ) {
	run->SetField(magField);
    } else {
	run->SetField(NULL);
    }
  }  //! end of field map section



  // -----   Create PrimaryGenerator   --------------------------------------

  // 1 - Create the Main API class for the Generator
  FairPrimaryGenerator* primGen = new FairPrimaryGenerator();


  if (fGenerator.CompareTo("box") == 0  ) {
  // 2- Define the BOX generator
  Double_t pdgId=211; // pion beam
  Double_t theta1= 0.;  // polar angle distribution
  Double_t theta2= 7.;
  Double_t momentum=.8; // 10 GeV/c
  FairBoxGenerator* boxGen = new FairBoxGenerator(pdgId, 50);
  boxGen->SetThetaRange (   theta1,   theta2);
  boxGen->SetPRange     (momentum,momentum*2.);
  boxGen->SetPhiRange   (0.,360.);
  boxGen->SetXYZ(0.0,0.0,-1.5);
  // add the box generator
  primGen->AddGenerator(boxGen);
  } 
	
  if (fGenerator.CompareTo("gammas") == 0  ) {
	// 2- Define the CALIFA Test gamma generator
	Double_t pdgId=22; // 22 for gamma emission, 2212 for proton emission 
	Double_t theta1=minTheta;  // polar angle distribution: lower edge
	Double_t theta2=maxTheta;  // polar angle distribution: upper edge	
	Double_t momentum=fEnergyP; // GeV/c 
	//Double_t momentum=0.808065; // 0.808065 GeV/c (300MeV Kin Energy for protons) 
	//Double_t momentum=0.31016124; // 0.31016124 GeV/c (50MeV Kin Energy for protons)
	//Double_t momentum=0.4442972; // 0.4442972 GeV/c (100MeV Kin Energy for protons)
	//Double_t momentum=0.5509999; // 0.5509999 GeV/c (150MeV Kin Energy for protons)
	//Double_t momentum=0.64405; // 0.64405 GeV/c (200MeV Kin Energy for protons) 
	Int_t multiplicity = fMult;
	R3BCALIFATestGenerator* gammasGen = new R3BCALIFATestGenerator(pdgId, multiplicity);
	gammasGen->SetThetaRange(theta1,theta2);
	gammasGen->SetCosTheta();
	gammasGen->SetPRange(momentum,momentum);
        gammasGen->SetPhiRange(0.,360.);

	gammasGen->SetBoxXYZ(-0.1,0.1,-0.1,0.1,-0.1,0.1);
	gammasGen->SetLorentzBoost(0.8197505718204776); //beta=0.81975 for 700 A MeV
	// add the gamma generator
	primGen->AddGenerator(gammasGen);
  } 
	

 if (fGenerator.CompareTo("r3b") == 0  ) {
  R3BSpecificGenerator *pR3bGen = new R3BSpecificGenerator();

  // R3bGen properties
  pR3bGen->SetBeamInteractionFlag("off");
  pR3bGen->SetBeamInteractionFlag("off");
  pR3bGen->SetRndmFlag("off");
  pR3bGen->SetRndmEneFlag("off");
  pR3bGen->SetBoostFlag("off");
  pR3bGen->SetReactionFlag("on");
  pR3bGen->SetGammasFlag("off");
  pR3bGen->SetDecaySchemeFlag("off");
  pR3bGen->SetDissociationFlag("off");
  pR3bGen->SetBackTrackingFlag("off");
  pR3bGen->SetSimEmittanceFlag("off");

  // R3bGen Parameters
  pR3bGen->SetBeamEnergy(1.); // Beam Energy in GeV
  pR3bGen->SetSigmaBeamEnergy(1.e-03); // Sigma(Ebeam) GeV
  pR3bGen->SetParticleDefinition(2212); // Use Particle Pdg Code
  pR3bGen->SetEnergyPrim(0.3); // Particle Energy in MeV
  Int_t fMultiplicity = 50;
  pR3bGen->SetNumberOfParticles(fMultiplicity); // Mult.

  // Reaction type
  //        1: "Elas"
  //        2: "iso"
  //        3: "Trans"
  pR3bGen->SetReactionType("Elas");

  // Target  type
  //        1: "LeadTarget"
  //        2: "Parafin0Deg"
  //        3: "Parafin45Deg"
  //        4: "LiH"

  pR3bGen->SetTargetType(Target.Data());
  Double_t thickness = (0.11/2.)/10.;  // cm
  pR3bGen->SetTargetHalfThicknessPara(thickness); // cm
  pR3bGen->SetTargetThicknessLiH(3.5); // cm
  pR3bGen->SetTargetRadius(1.); // cm

  pR3bGen->SetSigmaXInEmittance(1.); //cm
  pR3bGen->SetSigmaXPrimeInEmittance(0.0001); //cm

  // Dump the User settings
  pR3bGen->PrintParameters();  
  primGen->AddGenerator(pR3bGen);
  }


  run->SetGenerator(primGen);


  //-------Set visualisation flag to true------------------------------------
  if (fVis==kTRUE){
     run->SetStoreTraj(kTRUE);
  }else{
     run->SetStoreTraj(kFALSE);
  }   

  // -----   Initialize simulation run   ------------------------------------
  run->Init();

  // ------  Increase nb of step for CALO
  Int_t nSteps = -15000;
  gMC->SetMaxNStep(nSteps);

  // -----   Runtime database   ---------------------------------------------
  Bool_t kParameterMerged = kTRUE;
  FairParRootFileIo* parOut = new FairParRootFileIo(kParameterMerged);
  parOut->open(ParFile.Data());
  rtdb->setOutput(parOut);
  rtdb->saveOutput();
  rtdb->print();
   
  // -----   Start run   ----------------------------------------------------
  if (nEvents>0) run->Run(nEvents);
  
  // -----   Finish   -------------------------------------------------------
  timer.Stop();
  Double_t rtime = timer.RealTime();
  Double_t ctime = timer.CpuTime();
  cout << endl << endl;
  cout << "Macro finished succesfully." << endl;
  cout << "Output file is "    << OutFile << endl;
  cout << "Parameter file is " << ParFile << endl;
  cout << "Real time " << rtime << " s, CPU time " << ctime 
       << "s" << endl << endl;
  // ------------------------------------------------------------------------

  cout << " Test passed" << endl;
  cout << " All ok " << endl;

}
Example #30
0
//--------------------------------------------------------------------------------------------------
void runBavanti(const char *fileset    = "0000",
		const char *skim       = "noskim",
		const char *dataset    = "r12b-smu-j22-v1",
		const char *book       = "t2mit/filefi/032",
		const char *catalogDir = "/home/cmsprod/catalog",
		const char *outputName = "boostedv",
		int         nEvents    = 1000)
{
  //------------------------------------------------------------------------------------------------
  // some parameters get passed through the environment
  //------------------------------------------------------------------------------------------------
  TString cataDir  = Utils::GetCatalogDir(catalogDir);
  TString mitData  = Utils::GetEnv("MIT_DATA");
  TString json     = Utils::GetEnv("MIT_PROD_JSON");
  TString jsonFile = Utils::GetJsonFile("/home/cmsprod/cms/json");

  Bool_t  isData   = (json.CompareTo("~") != 0);
  printf("\n Initialization worked. Data?: %d\n\n",isData);

  //------------------------------------------------------------------------------------------------
  // some global setups
  //------------------------------------------------------------------------------------------------
  // debugging config
  using namespace mithep;
  gDebugMask  = (Debug::EDebugMask) (Debug::kGeneral | Debug::kTreeIO);
  gDebugLevel = 3;

  // Caching and how
  Int_t local = 1, cacher = 1;

  // local =   0 - as is,
  //           1 - /mt/hadoop  (MIT:SmartCache - preload one-by-one)
  //           2 - /mnt/hadoop (MIT:SmartCache - preload complete fileset)
  //           3 - ./          (xrdcp          - preload one-by-one)
  // cacher =  0 - no file by file caching
  //           1 - file by file caching on

  //------------------------------------------------------------------------------------------------
  // set up information for master module
  //------------------------------------------------------------------------------------------------
  RunLumiSelectionMod *runLumiSel = new RunLumiSelectionMod;
  runLumiSel->SetAcceptMC(kTRUE);                          // Monte Carlo events are always accepted
  
  // only select on run- and lumisection numbers when valid json file present
  if (json.CompareTo("~") != 0 && json.CompareTo("-") != 0) {
    printf(" runBoostedV() - adding jsonFile: %s\n",jsonFile.Data());
    runLumiSel->AddJSONFile(jsonFile.Data());
  }
  if (json.CompareTo("-") == 0) {
    printf("\n WARNING -- Looking at data without JSON file: always accept.\n\n");
    runLumiSel->SetAbortIfNotAccepted(kFALSE);   // accept all events if there is no valid JSON file
  }
  printf("\n Run lumi worked. \n\n");

  //------------------------------------------------------------------------------------------------
  // setup analysis
  //------------------------------------------------------------------------------------------------
  Analysis *ana = new Analysis;
  ana->SetUseCacher(cacher);
  ana->SetUseHLT(kTRUE);
  ana->SetKeepHierarchy(kTRUE);
  ana->SetSuperModule(runLumiSel);
  ana->SetPrintScale(100);
  if (nEvents >= 0)
    ana->SetProcessNEvents(nEvents);

  //------------------------------------------------------------------------------------------------
  // organize input
  //------------------------------------------------------------------------------------------------
  Catalog *c = new Catalog(cataDir.Data());
  TString skimdataset = TString(dataset)+TString("/") +TString(skim);
  Dataset *d = NULL;
  TString bookstr = book;
  if (TString(skim).CompareTo("noskim") == 0)
    d = c->FindDataset(bookstr,dataset,fileset,local);
  else 
    d = c->FindDataset(bookstr,skimdataset.Data(),fileset,local);
  ana->AddDataset(d);

  //------------------------------------------------------------------------------------------------
  // organize output
  //------------------------------------------------------------------------------------------------
  TString rootFile = TString(outputName);
  rootFile += TString("_") + TString(dataset) + TString("_") + TString(skim);
  if (TString(fileset) != TString(""))
    rootFile += TString("_") + TString(fileset);
  ana->SetOutputName(rootFile + TString(".root"));
  ana->SetCacheSize(0);

  //------------------------------------------------------------------------------------------------
  // select events with a good primary vertex
  //------------------------------------------------------------------------------------------------
  GoodPVFilterMod *goodPvFilterMod = new GoodPVFilterMod;
  goodPvFilterMod->SetMinVertexNTracks(0);
  goodPvFilterMod->SetMinNDof(4.0);
  goodPvFilterMod->SetMaxAbsZ(24.0);
  goodPvFilterMod->SetMaxRho(2.0);
  goodPvFilterMod->SetIsMC(!isData);
  goodPvFilterMod->SetVertexesName("PrimaryVertexes");

  //------------------------------------------------------------------------------------------------
  // object id and cleaning sequence
  //------------------------------------------------------------------------------------------------

  MuonIDMod *muonId = new MuonIDMod;
  muonId->SetOutputName("CleanMuons");
  muonId->SetIntRadius(0.0);
  muonId->SetClassType("GlobalTracker");
  muonId->SetIDType("WWMuIdV4");
  muonId->SetIsoType("IsoRingsV0_BDTG_Iso");
  muonId->SetApplyD0Cut(kTRUE);
  muonId->SetApplyDZCut(kTRUE);
  muonId->SetWhichVertex(0);
  muonId->SetRhoType(RhoUtilities::CMS_RHO_RHOKT6PFJETS);
  muonId->SetPtMin(10.);
  muonId->SetEtaCut(2.4);

  //------------------------------------------------------------------------------------------------
  // save the interesting collection using the skim modules and the output module
  //------------------------------------------------------------------------------------------------
  SkimMod<Track> *skmGlobalMuonTracks = new SkimMod<Track>;
  skmGlobalMuonTracks->SetBranchName("GlobalMuonTracks");
  skmGlobalMuonTracks->SetColFromBranch(kTRUE);
  skmGlobalMuonTracks->SetColMarkFilter(kTRUE);
  skmGlobalMuonTracks->SetPublishArray(kFALSE);

  SkimMod<Track> *skmStandaloneMuonTracks = new SkimMod<Track>;
  skmStandaloneMuonTracks->SetBranchName("StandaloneMuonTracks");
  skmStandaloneMuonTracks->SetColFromBranch(kTRUE);
  skmStandaloneMuonTracks->SetColMarkFilter(kTRUE);
  skmStandaloneMuonTracks->SetPublishArray(kFALSE);

  SkimMod<Track> *skmStandaloneMuonTracksWVtxConstraint = new SkimMod<Track>;
  skmStandaloneMuonTracksWVtxConstraint->SetBranchName("StandaloneMuonTracksWVtxConstraint");
  skmStandaloneMuonTracksWVtxConstraint->SetColFromBranch(kTRUE);
  skmStandaloneMuonTracksWVtxConstraint->SetColMarkFilter(kTRUE);
  skmStandaloneMuonTracksWVtxConstraint->SetPublishArray(kFALSE);

  SkimMod<Track> *skmTracks = new SkimMod<Track>;
  skmTracks->SetBranchName("Tracks");
  skmTracks->SetColFromBranch(kTRUE);
  skmTracks->SetColMarkFilter(kTRUE);
  skmTracks->SetPublishArray(kFALSE);

  SkimMod<Muon> *skmMuons = new SkimMod<Muon>;
  skmMuons->SetBranchName("Muons");
  skmMuons->SetColFromBranch(kTRUE);
  skmMuons->SetColMarkFilter(kTRUE);
  skmMuons->SetPublishArray(kTRUE);

  OutputMod *outMod1 = new OutputMod;
  outMod1->Drop("*");
  outMod1->Keep("Muons");
  outMod1->Keep("GlobalMuonTracks");
  outMod1->Keep("StandaloneMuonTracks");
  outMod1->Keep("StandaloneMuonTracksWVtxConstraint");
  outMod1->Keep("Tracks");
  outMod1->SetKeepTamBr(kTRUE);
  outMod1->SetFileName("bambu");

  OutputMod *outMod2 = new OutputMod;
  outMod2->Drop("*");
  outMod2->AddNewBranch(TString("SkmMuons"));
  outMod2->AddNewBranch(TString("SkmGlobalMuonTracks"));
  outMod1->AddNewBranch(TString("SkmStandaloneMuonTracks"));
  outMod1->AddNewBranch(TString("SkmStandaloneMuonTracksWVtxConstraint"));
  outMod2->AddNewBranch(TString("SkmTracks"));
  outMod2->SetKeepTamBr(kFALSE);
  outMod2->SetFileName("bavanti");

  //------------------------------------------------------------------------------------------------
  // making analysis chain
  //------------------------------------------------------------------------------------------------
  runLumiSel                           ->Add(goodPvFilterMod);
  //goodPvFilterMod                      ->Add(skmGlobalMuonTracks);
  goodPvFilterMod                      ->Add(muonId);
  muonId                               ->Add(skmGlobalMuonTracks);
  skmGlobalMuonTracks                  ->Add(skmStandaloneMuonTracks);
  skmStandaloneMuonTracks              ->Add(skmStandaloneMuonTracksWVtxConstraint);
  skmStandaloneMuonTracksWVtxConstraint->Add(skmTracks);
  skmTracks                            ->Add(skmMuons);
  skmMuons                             ->Add(outMod1);
  outMod1                              ->Add(outMod2);
  
  //muonId             ->Add(outMod1);
  //muonId             ->Add(skmMuons);
  //skmMuons           ->Add(outMod1);
  //muonId             ->Add(skmMuons);
  //skmMuons           ->Add(skmGlobalMuonTracks);
  //skmGlobalMuonTracks->Add(outMod1);
  //outMod1            ->Add(outMod2);
  //------------------------------------------------------------------------------------------------
  // Say what we are doing
  //------------------------------------------------------------------------------------------------
  printf("\n==== PARAMETER SUMMARY FOR THIS JOB ====\n");
  printf("\n JSON file: %s\n",jsonFile.Data());
  printf("\n Rely on Catalog: %s\n",cataDir.Data());
  printf("  -> Book: %s  Dataset: %s  Skim: %s  Fileset: %s <-\n",book,dataset,skim,fileset);
  printf("\n Root output:   %s\n",rootFile.Data());  
  printf("\n========================================\n");

  //------------------------------------------------------------------------------------------------
  // run the analysis after successful initialisation
  //------------------------------------------------------------------------------------------------
  ana->Run(!gROOT->IsBatch());

  return;
}