Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting same size output file when running on multiple input files in MadAnalysis expert mode? #273

Open
meena91 opened this issue Nov 14, 2024 · 5 comments
Labels
❓question Further information is requested

Comments

@meena91
Copy link

meena91 commented Nov 14, 2024

Question

Dear Expert,
I tried below method to run on multiple files at one time, I am getting different root files but size and events are same in both root files.
Command to Run .ccp file is ./MadAnalysis5job input_files.txt.
Where input_files.txt has name of root files.

Could you please help me in this case?

bool ALP::Initialize(const MA5::Configuration& cfg, const std::mapstd::string,std::string& parameters)
{
gamma_size_gen_FSR= new TH1F("gamma_size_gen_FSR","",21,-0.5,20.5);

cout << "END Initialization" << endl;
return true;
}

void ALP::Finalize(const SampleFormat& summary, const std::vector& files)
{

const std::string outputDirectory = "output_files";
// Loop over all input files
for (size_t i = 0; i < files.size(); ++i)
{

const SampleFormat& file = files[i];

         std::string inputFileName = file.name();
    std::string baseName = inputFileName.substr(inputFileName.find_last_of("/\\") + 1);
    std::string outputFileName = outputDirectory + "/" + baseName;

	size_t pos = outputFileName.find(".root");
    if (pos != std::string::npos)
    {
 	  outputFileName.replace(pos, 5, "_output.root");
    }
    else
    {
        outputFileName += "_output.root";
    }

        TFile *output = new TFile(outputFileName.c_str(), "RECREATE");
    if (!output->IsOpen()) {
        std::cerr << "Failed to open output file: " << outputFileName << std::endl;
        continue;
    }

gamma_size_gen_FSR->Write();

bool ALP::Execute(SampleFormat& sample, const EventFormat& event)
{
std::vector<const MCParticleFormat*> gamma_FSR;
if (event.mc()!=0)
{
for (MAuint32 i = 0; i < event.mc()->particles().size(); i++) {
const MCParticleFormat* part = &(event.mc()->particles()[i]); // Access particle
gamma_FSR.push_back(part);
gamma_size_gen_FSR->Fill(gamma_FSR.size(),wgt);
}}
}

@meena91 meena91 added the ❓question Further information is requested label Nov 14, 2024
@BFuks
Copy link
Member

BFuks commented Nov 14, 2024

Hi Meena.

I do not understand what you are trying to do... Can you please be a bit more explicit. Thanks in advance. In principle, you are supposed to list all the paths to the root files in the input file, and MA5 will take care of the rest.

Cheers,

Benjamin

@meena91
Copy link
Author

meena91 commented Nov 15, 2024

Dear Benjamin,
I want to run sampleAnalyzer on multiples file and need different output files corresponding to each input files. But with the current above script, I am able to get different root files corresponding to each input files but size of the all files are same or events are same in all output files for same histogram.
Yes, I am giving list of all input files (with path) in .txt files.

Hopefully now I am clear, if not please let me know.

Thank you in advance,
Meena

@BFuks
Copy link
Member

BFuks commented Nov 15, 2024 via email

@meena91
Copy link
Author

meena91 commented Nov 15, 2024

Dear Benjamin,

Thank you for your reply. you mean I can kept only one .root file in one .txt file and 2nd root file in 2nd .txt file to get different output files.

Best Regards,
Meena

@BFuks
Copy link
Member

BFuks commented Nov 15, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
❓question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants