Esempio n. 1
0
int main() {
  std::vector<std::pair<std::string, std::string>> sames = {
    std::make_pair("/tmp/rcas/tmp/f.root", "n"),
    std::make_pair("/tmp/rcas/tmp/nt.root", "nt")
  };
  std::map<std::string, std::future<FiledNtuple>> nt_map;
  std::vector<std::future<FiledNtuple>> nts;

  for (int n=0; n<2000; ++n) {
    for (unsigned i=0; i<2; ++i) {
      nts.push_back(
        std::async([i, sames]() {
          TFile* f(TFile::Open(sames[i].first.c_str()));
          TNtuple* nt;
          f->GetObject(sames[i].second.c_str(), nt);

          return FiledNtuple {f, nt};
        }));
      nt_map[sames[i].first] =
        std::async([i, sames]() {
          TFile* f(TFile::Open(sames[i].first.c_str()));
          TNtuple* nt;
          f->GetObject(sames[i].second.c_str(), nt);

          nt->SetDirectory(nullptr);
          f->Close();
          f = nullptr;

          return FiledNtuple {f, nt};
        }
      );
    }
  }

  for (auto& nti : nt_map) {
    std::cout << nti.first <<"\t" << nti.second.get().nt->GetEntries() << std::endl;
  }

  std::cout << "##############################\n";

  for (auto it=nts.rbegin(); it!=nts.rend(); ++it) {
    auto nt = (*it).get();
    std::cout << nt.nt->GetName() <<" "<< nt.nt->GetEntries() << std::endl;
  }
}
Esempio n. 2
0
Occupancy::Occupancy(const Mechanics::Device* device,
                     TDirectory* dir,
                     const char* suffix) :
  // Base class is initialized here and manages directory / device
  SingleAnalyzer(device, dir, suffix),
  totalHitOccupancy(0)
{
  assert(device && "Analyzer: can't initialize with null device");

  // Makes or gets a directory called from inside _dir with this name
  TDirectory* plotDir = makeGetDirectory("Occupancy");

  std::stringstream name; // Build name strings for each histo
  std::stringstream title; // Build title strings for each histo

  // Generate a histogram for each sensor in the device
  for (unsigned int nsens = 0; nsens < _device->getNumSensors(); nsens++)
  {
    Mechanics::Sensor* sensor = _device->getSensor(nsens);

    name.str(""); title.str("");
    name << sensor->getName() << "HitOccupancy" << _nameSuffix;
    title << sensor->getName() << " Pixel Occupancy"
          << ";X pixel"
          << ";Y pixel"
          << ";Hits / pixel";
    TH2D* hist = new TH2D(name.str().c_str(), title.str().c_str(),
                          sensor->getNumX(), 0 - 0.5, sensor->getNumX() - 0.5,
                          sensor->getNumY(), 0 - 0.5, sensor->getNumY() - 0.5);
    hist->SetDirectory(plotDir);
    _hitOcc.push_back(hist);

    const double lowX = sensor->getOffX() - sensor->getPosSensitiveX() / 2.0;
    const double uppX = sensor->getOffX() + sensor->getPosSensitiveX() / 2.0;
    const double lowY = sensor->getOffY() - sensor->getPosSensitiveY() / 2.0;
    const double uppY = sensor->getOffY() + sensor->getPosSensitiveY() / 2.0;

    name.str(""); title.str("");
    name << sensor->getName() << "ClusterOccupancy" << _nameSuffix;
    title << sensor->getName() << " Cluster Occupancy"
          << ";X position [" << _device->getSpaceUnit() << "]"
          << ";Y position [" << _device->getSpaceUnit() << "]"
          << ";Clusters / pixel";
    TH2D* histClust = new TH2D(name.str().c_str(), title.str().c_str(),
                               sensor->getPosNumX(), lowX, uppX,
                               sensor->getPosNumY(), lowY, uppY);
    histClust->SetDirectory(plotDir);
    _clusterOcc.push_back(histClust);

    name.str(""); title.str("");
    name << sensor->getName() << "ClusterNtuple" << _nameSuffix;
    title << sensor->getName() << " Cluster Ntuple"
          << ";X position [" << _device->getSpaceUnit() << "]"
          << ";Y position [" << _device->getSpaceUnit() << "]"
          << ";Clusters / pixel";
    TNtuple* clusterNt = new TNtuple(name.str().c_str(), title.str().c_str(),
                               "hits:x:y:tot:nclus:time:dist");
    clusterNt->SetDirectory(plotDir);
    _clusterNtuple.push_back(clusterNt);
  }
}
Esempio n. 3
0
void jettrigger()
{
  TFile *f = new TFile("jettrig.root");
  TNtuple *nt = (TNtuple *)f->Get("nt");

//Declaration of leaves types
   Float_t         pt;
   Float_t         eta;
   Float_t         phi;
   Float_t         mass;
   Float_t         jt40;
   Float_t         jt60;
   Float_t         jt80;
   Float_t         jt100;
   Float_t         pscl40;
   Float_t         pscl60;
   Float_t         pscl80;
   Float_t         pscl100;
  

   // Set branch addresses.
   nt->SetBranchAddress("pt",&pt);
   nt->SetBranchAddress("eta",&eta);
   nt->SetBranchAddress("phi",&phi);
   nt->SetBranchAddress("mass",&mass);
   nt->SetBranchAddress("jt40",&jt40);
   nt->SetBranchAddress("jt60",&jt60);
   nt->SetBranchAddress("jt80",&jt80);
   nt->SetBranchAddress("jt100",&jt100);
   nt->SetBranchAddress("pscl40",&pscl40);
   nt->SetBranchAddress("pscl60",&pscl60);
   nt->SetBranchAddress("pscl80",&pscl80);
   nt->SetBranchAddress("pscl100",&pscl100);
  
   TFile *fout = new TFile("jettrig_withweight.root","recreate");
   TNtuple *ntout = new TNtuple("ntweight","ntweight","pt:eta:phi:mass:jt40:jt60:jt80:jt100:pscl40:pscl60:pscl80:weightJet:weight12003");
   //TTree *ntout=new TTree("ntweight","ntweight");
   ntout->SetDirectory(fout);

   /*   ntout->Branch("pt",&pt);
   ntout->Branch("eta",&eta);
   ntout->Branch("phi",&phi);
   ntout->Branch("mass",&mass);
   ntout->Branch("jt40",&jt40);
   ntout->Branch("jt60",&jt60);
   ntout->Branch("jt80",&jt80);
   ntout->Branch("jt100",&jt100);
   ntout->Branch("pscl40",&pscl40);
   ntout->Branch("pscl60",&pscl60);
   ntout->Branch("pscl80",&pscl80);
   ntout->Branch("pscl100",&pscl100);
   ntout->Branch("weight",&weight);
   */
   Long64_t nentries = nt->GetEntries();
   cout<<nentries<<endl;

   int oneperc = nentries/100;
   Long64_t nbytes = 0;

   //#ifndef __CINT__
   //#pragma omp parallel for ordered schedule(dynamic)
   //#endif
   for (Long64_t i=0; i<nentries;i++) {
           nbytes += nt->GetEntry(i);

      if (i % oneperc == 0) cout<<"\r"<<i/oneperc<<"%   "<<flush;

      float weightJet = 0, weight12003 = 0;

      if (jt40 && !jt60 && !jt80 && !jt100) weight12003 = 1/pscl40;
      if (jt60 && !jt80 && !jt100) weight12003 = 1;
      if (jt80 && !jt100) weight12003 = 1;
      if (jt100) weight12003 = 1;

      if (jt40 && pt>40 && pt<60) weightJet = pscl40;
      if (jt60 && pt>60 && pt<80) weightJet = pscl60;
      if (jt80 && pt>80 && pt<100) weightJet = pscl80;
      if (jt100 && pt>100) weightJet = pscl100;

      //#ifndef __CINT__
      //#pragma omp ordered
      //#endif
	ntout->Fill(pt,eta,phi,mass,jt40,jt60,jt80,jt100,pscl40,pscl60,pscl80,weightJet,weight12003);

   }
   cout<<endl;
   cout<<ntout->GetEntries()<<endl;
   ntout->Write();
   fout->Close();
   f->Close();

   f = new TFile("jettrig_withweight.root");
   nt = (TNtuple *)f->Get("ntweight");
   cout<<nt->GetEntries()<<endl;
   f->Close();

}