CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
SiStripGainCosmicCalculator Class Reference

#include <SiStripGainCosmicCalculator.h>

Inheritance diagram for SiStripGainCosmicCalculator:
ConditionDBWriter< SiStripApvGain > edm::EDAnalyzer edm::EDConsumerBase

Public Member Functions

 SiStripGainCosmicCalculator (const edm::ParameterSet &)
 
 ~SiStripGainCosmicCalculator () override
 
- Public Member Functions inherited from ConditionDBWriter< SiStripApvGain >
 ConditionDBWriter (const edm::ParameterSet &iConfig)
 
 ~ConditionDBWriter () override
 
- Public Member Functions inherited from edm::EDAnalyzer
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzer ()
 
SerialTaskQueueglobalLuminosityBlocksQueue ()
 
SerialTaskQueueglobalRunsQueue ()
 
ModuleDescription const & moduleDescription () const
 
std::string workerType () const
 
 ~EDAnalyzer () override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Member Functions

void algoAnalyze (const edm::Event &, const edm::EventSetup &) override
 
void algoBeginJob (const edm::EventSetup &) override
 
void algoEndJob () override
 
SiStripApvGaingetNewObject () override
 
std::pair< double, double > getPeakOfLandau (TH1F *inputHisto)
 
double moduleThickness (const uint32_t detid, const edm::EventSetup *iSetup)
 
double moduleWidth (const uint32_t detid, const edm::EventSetup *iSetup)
 

Private Attributes

std::vector< uint32_t > detModulesToBeExcluded
 
const edm::EventSetupeventSetupCopy_
 
double ExpectedChargeDeposition
 
TObjArray * HlistAPVPairs
 
TObjArray * HlistOtherHistos
 
double MaxChi2OverNDF
 
unsigned int MinNrEntries
 
TString outputFileName
 
bool outputHistogramsInRootFile
 
bool printdebug_
 
std::vector< uint32_t > SelectedDetIds
 
std::map< uint32_t, double > thickness_map
 
uint32_t total_nr_of_events
 
std::string TrackLabel
 
std::string TrackProducer
 
const TrackerTopologytTopo
 

Additional Inherited Members

- Public Types inherited from edm::EDAnalyzer
typedef EDAnalyzer ModuleType
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::EDAnalyzer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &)
 
static bool wantsGlobalLuminosityBlocks ()
 
static bool wantsGlobalRuns ()
 
static bool wantsStreamLuminosityBlocks ()
 
static bool wantsStreamRuns ()
 
- Protected Member Functions inherited from ConditionDBWriter< SiStripApvGain >
void setDoStore (const bool doStore)
 When set to false the payload will not be written to the db. More...
 
void storeOnDbNow ()
 
cond::Time_t timeOfLastIOV ()
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Definition at line 25 of file SiStripGainCosmicCalculator.h.

Constructor & Destructor Documentation

SiStripGainCosmicCalculator::SiStripGainCosmicCalculator ( const edm::ParameterSet iConfig)
explicit

Definition at line 37 of file SiStripGainCosmicCalculator.cc.

References detModulesToBeExcluded, ExpectedChargeDeposition, edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), MaxChi2OverNDF, MinNrEntries, outputFileName, outputHistogramsInRootFile, printdebug_, AlCaHLTBitMon_QueryRunRegistry::string, TrackLabel, and tTopo.

38  edm::LogInfo("SiStripGainCosmicCalculator::SiStripGainCosmicCalculator");
40  edm::LogInfo("SiStripApvGainCalculator::SiStripApvGainCalculator")<<"ExpectedChargeDeposition="<<ExpectedChargeDeposition;
41 
42  TrackProducer = iConfig.getParameter<std::string>("TrackProducer");
43  TrackLabel = iConfig.getParameter<std::string>("TrackLabel");
44 
45  detModulesToBeExcluded.clear(); detModulesToBeExcluded = iConfig.getParameter< std::vector<unsigned> >("detModulesToBeExcluded");
46  MinNrEntries = iConfig.getUntrackedParameter<unsigned>("minNrEntries", 20);
47  MaxChi2OverNDF = iConfig.getUntrackedParameter<double>("maxChi2OverNDF", 5.);
48 
49  outputHistogramsInRootFile = iConfig.getParameter<bool>("OutputHistogramsInRootFile");
50  outputFileName = iConfig.getParameter<std::string>("OutputFileName");
51 
52  edm::LogInfo("SiStripApvGainCalculator")<<"Clusters from "<<detModulesToBeExcluded.size()<<" modules will be ignored in the calibration:";
53  edm::LogInfo("SiStripApvGainCalculator")<<"The calibration for these DetIds will be set to a default value";
54  for( std::vector<uint32_t>::const_iterator imod = detModulesToBeExcluded.begin(); imod != detModulesToBeExcluded.end(); imod++){
55  edm::LogInfo("SiStripApvGainCalculator")<<"exclude detid = "<< *imod;
56  }
57 
58  printdebug_ = iConfig.getUntrackedParameter<bool>("printDebug", false);
59  tTopo = nullptr;
60 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
std::vector< uint32_t > detModulesToBeExcluded
SiStripGainCosmicCalculator::~SiStripGainCosmicCalculator ( )
override

Definition at line 63 of file SiStripGainCosmicCalculator.cc.

63  {
64  edm::LogInfo("SiStripGainCosmicCalculator::~SiStripGainCosmicCalculator");
65 }

Member Function Documentation

void SiStripGainCosmicCalculator::algoAnalyze ( const edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivatevirtual

Reimplemented from ConditionDBWriter< SiStripApvGain >.

Definition at line 144 of file SiStripGainCosmicCalculator.cc.

References SiStripRecHit2D::cluster(), funct::cos(), HcalObjRepresent::Fill(), edm::Event::getByLabel(), HlistAPVPairs, HlistOtherHistos, createfilelist::int, TrackingRecHit::localPosition(), moduleThickness(), moduleWidth(), edm::Handle< T >::product(), total_nr_of_events, findElectronsInSiStrips_cfi::trackCollection, TrackLabel, l1t::tracks, and PV3DBase< T, PVType, FrameType >::x().

144  {
145  using namespace edm;
147 
148  //TO BE RESTORED
149  // anglefinder_->init(event,iSetup);
150 
151 
152  // get seeds
153 // edm::Handle<TrajectorySeedCollection> seedcoll;
154 // event.getByType(seedcoll);
155  // get tracks
157  const reco::TrackCollection *tracks=trackCollection.product();
158 
159 // // get magnetic field
160 // edm::ESHandle<MagneticField> esmagfield;
161 // es.get<IdealMagneticFieldRecord>().get(esmagfield);
162 // magfield=&(*esmagfield);
163  // loop over tracks
164  for(reco::TrackCollection::const_iterator itr = tracks->begin(); itr != tracks->end(); itr++){ // looping over tracks
165 
166  //TO BE RESTORED
167  // std::vector<std::pair<const TrackingRecHit *,float> >hitangle =anglefinder_->findtrackangle((*(*seedcoll).begin()),*itr);
168  std::vector<std::pair<const TrackingRecHit *,float> >hitangle;// =anglefinder_->findtrackangle((*(*seedcoll).begin()),*itr);
169 
170  for(std::vector<std::pair<const TrackingRecHit *,float> >::const_iterator hitangle_iter=hitangle.begin();hitangle_iter!=hitangle.end();hitangle_iter++){
171  const TrackingRecHit * trechit = hitangle_iter->first;
172  float local_angle=hitangle_iter->second;
173  LocalPoint local_position= trechit->localPosition();
174  const SiStripRecHit2D* sistripsimplehit=dynamic_cast<const SiStripRecHit2D*>(trechit);
175  const SiStripMatchedRecHit2D* sistripmatchedhit=dynamic_cast<const SiStripMatchedRecHit2D*>(trechit);
176 // std::cout<<" hit/matched "<<std::ios::hex<<sistripsimplehit<<" "<<sistripmatchedhit<<std::endl;
177  ((TH1F*) HlistOtherHistos->FindObject("LocalAngle"))->Fill(local_angle);
178  ((TH1F*) HlistOtherHistos->FindObject("LocalAngleAbsoluteCosine"))->Fill(fabs(cos(local_angle)));
179  if(sistripsimplehit){
180  ((TH1F*) HlistOtherHistos->FindObject("SiStripRecHitType"))->Fill(1.);
181  const SiStripRecHit2D::ClusterRef & cluster=sistripsimplehit->cluster();
182  const auto & ampls = cluster->amplitudes();
183  uint32_t thedetid = 0; // is zero since long time cluster->geographicalId();
184  double module_width = moduleWidth(thedetid, &iSetup);
185  ((TH1F*) HlistOtherHistos->FindObject("LocalPosition_cm"))->Fill(local_position.x());
186  ((TH1F*) HlistOtherHistos->FindObject("LocalPosition_normalized"))->Fill(local_position.x()/module_width);
187  double module_thickness = moduleThickness(thedetid, &iSetup);
188  int ifirststrip= cluster->firstStrip();
189  int theapvpairid = int(float(ifirststrip)/256.);
190  TH1F* histopointer = (TH1F*) HlistAPVPairs->FindObject(Form("ChargeAPVPair_%i_%i",thedetid,theapvpairid));
191  if( histopointer ){
192  short cCharge = 0;
193  for(unsigned int iampl = 0; iampl<ampls.size(); iampl++){
194  cCharge += ampls[iampl];
195  }
196  double cluster_charge_over_path = ((double)cCharge) * fabs(cos(local_angle)) / ( 10. * module_thickness);
197  histopointer->Fill(cluster_charge_over_path);
198  }
199  }else{
200  if(sistripmatchedhit) ((TH1F*) HlistOtherHistos->FindObject("SiStripRecHitType"))->Fill(2.);
201  }
202  }
203  }
204 }
double moduleThickness(const uint32_t detid, const edm::EventSetup *iSetup)
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
double moduleWidth(const uint32_t detid, const edm::EventSetup *iSetup)
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
ClusterRef cluster() const
virtual LocalPoint localPosition() const =0
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:475
T const * product() const
Definition: Handle.h:81
HLT enums.
T x() const
Definition: PV3DBase.h:62
void SiStripGainCosmicCalculator::algoBeginJob ( const edm::EventSetup iSetup)
overrideprivatevirtual

Reimplemented from ConditionDBWriter< SiStripApvGain >.

Definition at line 70 of file SiStripGainCosmicCalculator.cc.

References SiStripDetCabling::addActiveDetectorsRawIds(), gather_cfg::cout, detModulesToBeExcluded, TrackerGeometry::dets(), eventSetupCopy_, cmsRelvalreport::exit, edm::EventSetup::get(), SiStripSubStructure::getTIBDetectors(), SiStripSubStructure::getTOBDetectors(), HlistAPVPairs, HlistOtherHistos, StripTopology::nstrips(), AlCaHLTBitMon_ParallelJobs::p, edm::ESHandle< T >::product(), SelectedDetIds, thickness_map, total_nr_of_events, and tTopo.

71 {
72  //Retrieve tracker topology from geometry
74  iSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
75  tTopo = tTopoHandle.product();
76 
77  eventSetupCopy_ = &iSetup;
78  std::cout<<"SiStripGainCosmicCalculator::algoBeginJob called"<<std::endl;
80  HlistAPVPairs = new TObjArray(); HlistOtherHistos = new TObjArray();
81  //
82  HlistOtherHistos->Add(new TH1F( Form("APVPairCorrections"), Form("APVPairCorrections"), 50,-1.,4.));
83  HlistOtherHistos->Add(new TH1F(Form("APVPairCorrectionsTIB1mono"),Form("APVPairCorrectionsTIB1mono"),50,-1.,4.));
84  HlistOtherHistos->Add(new TH1F(Form("APVPairCorrectionsTIB1stereo"),Form("APVPairCorrectionsTIB1stereo"),50,-1.,4.));
85  HlistOtherHistos->Add(new TH1F(Form("APVPairCorrectionsTIB2"),Form("APVPairCorrectionsTIB2"),50,-1.,4.));
86  HlistOtherHistos->Add(new TH1F(Form("APVPairCorrectionsTOB1"),Form("APVPairCorrectionsTOB1"),50,-1.,4.));
87  HlistOtherHistos->Add(new TH1F(Form("APVPairCorrectionsTOB2"),Form("APVPairCorrectionsTOB2"),50,-1.,4.));
88  HlistOtherHistos->Add(new TH1F(Form("LocalAngle"),Form("LocalAngle"),70,-0.1,3.4));
89  HlistOtherHistos->Add(new TH1F(Form("LocalAngleAbsoluteCosine"),Form("LocalAngleAbsoluteCosine"),48,-0.1,1.1));
90  HlistOtherHistos->Add(new TH1F(Form("LocalPosition_cm"),Form("LocalPosition_cm"),100,-5.,5.));
91  HlistOtherHistos->Add(new TH1F(Form("LocalPosition_normalized"),Form("LocalPosition_normalized"),100,-1.1,1.1));
92  TH1F* local_histo = new TH1F(Form("SiStripRecHitType"),Form("SiStripRecHitType"),2,0.5,2.5); HlistOtherHistos->Add(local_histo);
93  local_histo->GetXaxis()->SetBinLabel(1,"simple"); local_histo->GetXaxis()->SetBinLabel(2,"matched");
94 
95  // get cabling and find out list of active detectors
96  edm::ESHandle<SiStripDetCabling> siStripDetCabling; iSetup.get<SiStripDetCablingRcd>().get(siStripDetCabling);
97  std::vector<uint32_t> activeDets; activeDets.clear();
98  SelectedDetIds.clear();
99  siStripDetCabling->addActiveDetectorsRawIds(activeDets);
100 // SelectedDetIds = activeDets; // all active detector modules
101  // use SiStripSubStructure for selecting certain regions
102  SiStripSubStructure::getTIBDetectors(activeDets, SelectedDetIds, tTopo, 0, 0, 0, 0); // this adds rawDetIds to SelectedDetIds
103  SiStripSubStructure::getTOBDetectors(activeDets, SelectedDetIds, tTopo, 0, 0, 0); // this adds rawDetIds to SelectedDetIds
104  // get tracker geometry and find nr. of apv pairs for each active detector
105  edm::ESHandle<TrackerGeometry> tkGeom; iSetup.get<TrackerDigiGeometryRecord>().get( tkGeom );
106  for(TrackerGeometry::DetContainer::const_iterator it = tkGeom->dets().begin(); it != tkGeom->dets().end(); it++){ // loop over detector modules
107  if( dynamic_cast<const StripGeomDetUnit*>((*it))!=nullptr){
108  uint32_t detid= ((*it)->geographicalId()).rawId();
109  // get thickness for all detector modules, not just for active, this is strange
110  double module_thickness = (*it)->surface().bounds().thickness(); // get thickness of detector from GeomDet (DetContainer == vector<GeomDet*>)
111  thickness_map.insert(std::make_pair(detid,module_thickness));
112  //
113  bool is_active_detector = false;
114  for(std::vector<uint32_t>::iterator iactive = SelectedDetIds.begin(); iactive != SelectedDetIds.end(); iactive++){
115  if( *iactive == detid ){
116  is_active_detector = true;
117  break; // leave for loop if found matching detid
118  }
119  }
120  //
121  bool exclude_this_detid = false;
122  for( std::vector<uint32_t>::const_iterator imod = detModulesToBeExcluded.begin(); imod != detModulesToBeExcluded.end(); imod++ ){
123  if(*imod == detid) exclude_this_detid = true; // found in exclusion list
124  break;
125  }
126  //
127  if(is_active_detector && (!exclude_this_detid)){ // check whether is active detector and that should not be excluded
128  const StripTopology& p = dynamic_cast<const StripGeomDetUnit*>((*it))->specificTopology();
129  unsigned short NAPVPairs = p.nstrips()/256;
130  if( NAPVPairs<2 || NAPVPairs>3 ) {
131  edm::LogError("SiStripGainCosmicCalculator")<<"Problem with Number of strips in detector: "<<p.nstrips()<<" Exiting program";
132  exit(1);
133  }
134  for(int iapp = 0; iapp<NAPVPairs; iapp++){
135  TString hid = Form("ChargeAPVPair_%i_%i",detid,iapp);
136  HlistAPVPairs->Add(new TH1F(hid,hid,45,0.,1350.)); // multiply by 3 to take into account division by width
137  }
138  }
139  }
140  }
141 }
std::vector< uint32_t > SelectedDetIds
void getTIBDetectors(const std::vector< uint32_t > &inputDetRawIds, std::vector< uint32_t > &tibDetRawIds, const TrackerTopology *trackerTopology, uint32_t layer=0, uint32_t bkw_frw=0, uint32_t int_ext=0, uint32_t string=0)
void addActiveDetectorsRawIds(std::vector< uint32_t > &) const
const edm::EventSetup * eventSetupCopy_
const DetContainer & dets() const override
Returm a vector of all GeomDet (including all GeomDetUnits)
std::map< uint32_t, double > thickness_map
virtual int nstrips() const =0
const T & get() const
Definition: EventSetup.h:59
std::vector< uint32_t > detModulesToBeExcluded
void getTOBDetectors(const std::vector< uint32_t > &inputDetRawIds, std::vector< uint32_t > &tobDetRawIds, const TrackerTopology *trackerTopology, uint32_t layer=0, uint32_t bkw_frw=0, uint32_t rod=0)
T const * product() const
Definition: ESHandle.h:86
void SiStripGainCosmicCalculator::algoEndJob ( )
overrideprivatevirtual

Reimplemented from ConditionDBWriter< SiStripApvGain >.

Definition at line 67 of file SiStripGainCosmicCalculator.cc.

67  {
68 }
SiStripApvGain * SiStripGainCosmicCalculator::getNewObject ( )
overrideprivatevirtual

Implements ConditionDBWriter< SiStripApvGain >.

Definition at line 279 of file SiStripGainCosmicCalculator.cc.

References FedChannelConnection::ccuAddr(), FedChannelConnection::ccuChan(), gather_cfg::cout, eventSetupCopy_, FedChannelConnection::fecCrate(), FedChannelConnection::fecRing(), FedChannelConnection::fecSlot(), HcalObjRepresent::Fill(), edm::EventSetup::get(), SiStripDetCabling::getConnection(), getPeakOfLandau(), HlistAPVPairs, HlistOtherHistos, moduleThickness(), moduleWidth(), GetRecoTauVFromDQM_MC_cff::obj, estimatePileup_makeJSON::outputfile, outputFileName, outputHistogramsInRootFile, DetId::rawId(), DetId::subdetId(), StripSubdetector::TIB, TrackerTopology::tibGlued(), TrackerTopology::tibLayer(), TrackerTopology::tibStereo(), StripSubdetector::TOB, TrackerTopology::tobLayer(), total_nr_of_events, and tTopo.

279  {
280  std::cout<<"SiStripGainCosmicCalculator::getNewObject called"<<std::endl;
281 
282  std::cout<<"total_nr_of_events="<<total_nr_of_events<<std::endl;
283  // book some more histograms
284  TH1F *ChargeOfEachAPVPair = new TH1F("ChargeOfEachAPVPair","ChargeOfEachAPVPair",1,0,1); ChargeOfEachAPVPair->SetCanExtend(TH1::kAllAxes);
285  TH1F *EntriesApvPairs = new TH1F("EntriesApvPairs","EntriesApvPairs",1,0,1); EntriesApvPairs->SetCanExtend(TH1::kAllAxes);
286  TH1F * NrOfEntries = new TH1F("NrOfEntries","NrOfEntries",351,-0.5,350.5);// NrOfEntries->SetCanExtend(TH1::kAllAxes);
287  TH1F * ModuleThickness = new TH1F("ModuleThickness","ModuleThickness",2,0.5,2.5); HlistOtherHistos->Add(ModuleThickness);
288  ModuleThickness->GetXaxis()->SetBinLabel(1,"320mu"); ModuleThickness->GetXaxis()->SetBinLabel(2,"500mu"); ModuleThickness->SetYTitle("Nr APVPairs");
289  TH1F * ModuleWidth = new TH1F("ModuleWidth","ModuleWidth",5,0.5,5.5); HlistOtherHistos->Add(ModuleWidth);
290  ModuleWidth->GetXaxis()->SetBinLabel(1,"6.144cm"); ModuleWidth->GetXaxis()->SetBinLabel(2,"7.14cm");
291  ModuleWidth->GetXaxis()->SetBinLabel(3,"9.3696cm"); ModuleWidth->GetXaxis()->SetBinLabel(4,"10.49cm");
292  ModuleWidth->GetXaxis()->SetBinLabel(5,"12.03cm");
293  ModuleWidth->SetYTitle("Nr APVPairs");
294  // loop over single histograms and extract peak value of charge
295  HlistAPVPairs->Sort(); // sort alfabetically
296  TIter hiterator(HlistAPVPairs);
297  double MeanCharge = 0.;
298  double NrOfApvPairs = 0.;
299  TH1F *MyHisto = (TH1F*)hiterator();
300  while( MyHisto ){
301  TString histo_title = MyHisto->GetTitle();
302  if(histo_title.Contains("ChargeAPVPair_")){
303  std::pair<double,double> two_values = getPeakOfLandau(MyHisto);
304  double local_nrofadcs = two_values.first;
305  double local_sigma = two_values.second;
306  ChargeOfEachAPVPair->Fill(histo_title, local_nrofadcs);
307  int ichbin = ChargeOfEachAPVPair->GetXaxis()->FindBin(histo_title.Data());
308  ChargeOfEachAPVPair->SetBinError(ichbin,local_sigma);
309  EntriesApvPairs->Fill(histo_title, MyHisto->GetEntries());
310  NrOfEntries->Fill(MyHisto->GetEntries());
311  if(local_nrofadcs > 0){ // if nr of adcs is negative, the fitting routine could not extract meaningfull numbers
312  MeanCharge += local_nrofadcs;
313  NrOfApvPairs += 1.; // count nr of apv pairs since do not know whether nr of bins of histogram is the same
314  }
315  }
316  MyHisto = (TH1F*)hiterator();
317  }
318  ChargeOfEachAPVPair->LabelsDeflate("X"); EntriesApvPairs->LabelsDeflate("X"); // trim nr. of bins to match active labels
319  HlistOtherHistos->Add(ChargeOfEachAPVPair);
320  HlistOtherHistos->Add(EntriesApvPairs);
321  HlistOtherHistos->Add(NrOfEntries);
322  MeanCharge = MeanCharge / NrOfApvPairs;
323  // calculate correction
324  TH1F* CorrectionOfEachAPVPair = (TH1F*) ChargeOfEachAPVPair->Clone("CorrectionOfEachAPVPair");
325  TH1F *ChargeOfEachAPVPairControlView = new TH1F("ChargeOfEachAPVPairControlView","ChargeOfEachAPVPairControlView",1,0,1); ChargeOfEachAPVPairControlView->SetCanExtend(TH1::kAllAxes);
326 TH1F *CorrectionOfEachAPVPairControlView = new TH1F("CorrectionOfEachAPVPairControlView","CorrectionOfEachAPVPairControlView",1,0,1); CorrectionOfEachAPVPairControlView->SetCanExtend(TH1::kAllAxes);
327  std::ofstream APVPairTextOutput("apvpair_corrections.txt");
328  APVPairTextOutput<<"# MeanCharge = "<<MeanCharge<<std::endl;
329  APVPairTextOutput<<"# Nr. of APVPairs = "<<NrOfApvPairs<<std::endl;
330  for(int ibin=1; ibin <= ChargeOfEachAPVPair->GetNbinsX(); ibin++){
331  TString local_bin_label = ChargeOfEachAPVPair->GetXaxis()->GetBinLabel(ibin);
332  double local_charge_over_path = ChargeOfEachAPVPair->GetBinContent(ibin);
333  if(local_bin_label.Contains("ChargeAPVPair_") && local_charge_over_path > 0.0000001){ // calculate correction only for meaningful numbers
334  uint32_t extracted_detid; std::istringstream read_label((local_bin_label(14,9)).Data()); read_label >> extracted_detid;
335  unsigned short extracted_apvpairid; std::istringstream read_apvpair((local_bin_label(24,1)).Data()); read_apvpair >> extracted_apvpairid;
336  double local_error_of_charge = ChargeOfEachAPVPair->GetBinError(ibin);
337  double local_correction = -0.5;
338  double local_error_correction = 0.;
339  local_correction = MeanCharge / local_charge_over_path; // later use ExpectedChargeDeposition instead of MeanCharge
340  local_error_correction = local_correction * local_error_of_charge / local_charge_over_path;
341  if(local_error_correction>1.8){ // understand why error too large sometimes
342  std::cout<<"too large error "<<local_error_correction<<" for histogram "<<local_bin_label<<std::endl;
343  }
344  double nr_of_entries = EntriesApvPairs->GetBinContent(ibin);
345  APVPairTextOutput<<local_bin_label<<" "<<local_correction<<" "<<local_charge_over_path<<" "<<nr_of_entries<<std::endl;
346  CorrectionOfEachAPVPair->SetBinContent(ibin, local_correction);
347  CorrectionOfEachAPVPair->SetBinError(ibin, local_error_correction);
348  ((TH1F*) HlistOtherHistos->FindObject("APVPairCorrections"))->Fill(local_correction);
349  DetId thedetId = DetId(extracted_detid);
350  unsigned int generalized_layer = 0;
351  // calculate generalized_layer: 31,32 = TIB1, 33 = TIB2, 33 = TIB3, 51 = TOB1, 52 = TOB2, 60 = TEC
352  if(thedetId.subdetId()==StripSubdetector::TIB){
353 
354  generalized_layer = 10*thedetId.subdetId() + tTopo->tibLayer(thedetId.rawId()) + tTopo->tibStereo(thedetId.rawId());
355  if(tTopo->tibLayer(thedetId.rawId())==2){
356  generalized_layer++;
357  if (tTopo->tibGlued(thedetId.rawId())) edm::LogError("ClusterMTCCFilter")<<"WRONGGGG"<<std::endl;
358  }
359  }else{
360  generalized_layer = 10*thedetId.subdetId();
361  if(thedetId.subdetId()==StripSubdetector::TOB){
362 
363  generalized_layer += tTopo->tobLayer(thedetId.rawId());
364  }
365  }
366  if(generalized_layer==31){
367  ((TH1F*) HlistOtherHistos->FindObject("APVPairCorrectionsTIB1mono"))->Fill(local_correction);
368  }
369  if(generalized_layer==32){
370  ((TH1F*) HlistOtherHistos->FindObject("APVPairCorrectionsTIB1stereo"))->Fill(local_correction);
371  }
372  if(generalized_layer==33){
373  ((TH1F*) HlistOtherHistos->FindObject("APVPairCorrectionsTIB2"))->Fill(local_correction);
374  }
375  if(generalized_layer==51){
376  ((TH1F*) HlistOtherHistos->FindObject("APVPairCorrectionsTOB1"))->Fill(local_correction);
377  }
378  if(generalized_layer==52){
379  ((TH1F*) HlistOtherHistos->FindObject("APVPairCorrectionsTOB2"))->Fill(local_correction);
380  }
381  // control view
382  edm::ESHandle<SiStripDetCabling> siStripDetCabling; eventSetupCopy_->get<SiStripDetCablingRcd>().get(siStripDetCabling);
383  const FedChannelConnection& fedchannelconnection = siStripDetCabling->getConnection( extracted_detid, extracted_apvpairid );
384  std::ostringstream local_key;
385  // in S. Mersi's analysis the APVPair id seems to be used instead of the lldChannel, hence use the same here
386  local_key<<"fecCrate"<<fedchannelconnection.fecCrate()<<"_fecSlot"<<fedchannelconnection.fecSlot()<<"_fecRing"<<fedchannelconnection.fecRing()<<"_ccuAddr"<<fedchannelconnection.ccuAddr()<<"_ccuChan"<<fedchannelconnection.ccuChan()<<"_apvPair"<<extracted_apvpairid;
387  TString control_key = local_key.str();
388  ChargeOfEachAPVPairControlView->Fill(control_key,local_charge_over_path);
389  int ibin1 = ChargeOfEachAPVPairControlView->GetXaxis()->FindBin(control_key);
390  ChargeOfEachAPVPairControlView->SetBinError(ibin1,local_error_of_charge);
391  CorrectionOfEachAPVPairControlView->Fill(control_key, local_correction);
392  int ibin2 = CorrectionOfEachAPVPairControlView->GetXaxis()->FindBin(control_key);
393  CorrectionOfEachAPVPairControlView->SetBinError(ibin2, local_error_correction);
394  // thickness of each module
395  double module_thickness = moduleThickness(extracted_detid, eventSetupCopy_);
396  if( fabs(module_thickness - 0.032)<0.001 ) ModuleThickness->Fill(1);
397  if( fabs(module_thickness - 0.05)<0.001 ) ModuleThickness->Fill(2);
398  // width of each module
399  double module_width = moduleWidth(extracted_detid, eventSetupCopy_);
400  if(fabs(module_width-6.144)<0.01) ModuleWidth->Fill(1);
401  if(fabs(module_width-7.14)<0.01) ModuleWidth->Fill(2);
402  if(fabs(module_width-9.3696)<0.01) ModuleWidth->Fill(3);
403  if(fabs(module_width-10.49)<0.01) ModuleWidth->Fill(4);
404  if(fabs(module_width-12.03)<0.01) ModuleWidth->Fill(5);
405  }
406  }
407  HlistOtherHistos->Add(CorrectionOfEachAPVPair);
408  ChargeOfEachAPVPairControlView->LabelsDeflate("X");
409  CorrectionOfEachAPVPairControlView->LabelsDeflate("X");
410  HlistOtherHistos->Add(ChargeOfEachAPVPairControlView);
411  HlistOtherHistos->Add(CorrectionOfEachAPVPairControlView);
412  // output histograms to file
413 
414 
416  TFile *outputfile = new TFile(outputFileName,"RECREATE");
417  HlistAPVPairs->Write();
418  HlistOtherHistos->Write();
419  outputfile->Close();
420  }
421 
423 
424 // for(std::map<uint32_t,OptoScanAnalysis*>::const_iterator it = analyses.begin(); it != analyses.end(); it++){
425 // //Generate Gain for det detid
426 // std::vector<float> theSiStripVector;
427 // for(unsigned short j=0; j<it->second; j++){
428 // float gain;
429 
430 // // if(sigmaGain_/meanGain_ < 0.00001) gain = meanGain_;
431 // // else{
432 // gain = CLHEP::RandGauss::shoot(meanGain_, sigmaGain_);
433 // if(gain<=minimumPosValue_) gain=minimumPosValue_;
434 // // }
435 
436 // if (printdebug_)
437 // edm::LogInfo("SiStripGainCalculator") << "detid " << it->first << " \t"
438 // << " apv " << j << " \t"
439 // << gain << " \t"
440 // << std::endl;
441 // theSiStripVector.push_back(gain);
442 // }
443 // SiStripApvGain::Range range(theSiStripVector.begin(),theSiStripVector.end());
444 // if ( ! obj->put(it->first,range) )
445 // edm::LogError("SiStripGainCalculator")<<"[SiStripGainCalculator::beginJob] detid already exists"<<std::endl;
446 // }
447 
448  return obj;
449 }
const uint16_t & fecSlot() const
const uint16_t & fecCrate() const
const FedChannelConnection & getConnection(uint32_t det_id, unsigned short apv_pair) const
unsigned int tibLayer(const DetId &id) const
double moduleThickness(const uint32_t detid, const edm::EventSetup *iSetup)
const edm::EventSetup * eventSetupCopy_
double moduleWidth(const uint32_t detid, const edm::EventSetup *iSetup)
std::pair< double, double > getPeakOfLandau(TH1F *inputHisto)
uint32_t rawId() const
get the raw id
Definition: DetId.h:44
const uint16_t & fecRing() const
Class containning control, module, detector and connection information, at the level of a FED channel...
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
const uint16_t & ccuChan() const
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:38
const uint16_t & ccuAddr() const
Definition: DetId.h:18
uint32_t tibGlued(const DetId &id) const
const T & get() const
Definition: EventSetup.h:59
uint32_t tibStereo(const DetId &id) const
unsigned int tobLayer(const DetId &id) const
std::pair< double, double > SiStripGainCosmicCalculator::getPeakOfLandau ( TH1F *  inputHisto)
private

Definition at line 208 of file SiStripGainCosmicCalculator.cc.

References vertices_cff::chi2, gather_cfg::cout, relativeConstraints::error, MaxChi2OverNDF, and MinNrEntries.

Referenced by getNewObject().

208  { // automated fitting with finding of the appropriate nr. of ADCs
209  // set some default dummy value and return if no entries
210  double adcs = -0.5; double error = 0.; double nr_of_entries = inputHisto->GetEntries();
211  if(nr_of_entries < MinNrEntries){
212  return std::make_pair(adcs,error);
213  }
214 //
215 // // fit with initial setting of parameter values
216 // double rms_of_histogram = inputHisto->GetRMS();
217 // TF1 *landaufit = new TF1("landaufit","landau",0.,450.);
218 // landaufit->SetParameters(nr_of_entries,mean_of_histogram,rms_of_histogram);
219 // inputHisto->Fit("landaufit","0Q+");
220 // delete landaufit;
221 //
222  // perform fit with standard landau
223  // make our own copy to avoid problems with threads
224  std::unique_ptr<TF1> fitfunction( new TF1("landaufit","landau") );
225  inputHisto->Fit(fitfunction.get(),"0Q");
226  adcs = fitfunction->GetParameter("MPV");
227  error = fitfunction->GetParError(1); // MPV is parameter 1 (0=constant, 1=MPV, 2=Sigma)
228  double chi2 = fitfunction->GetChisquare();
229  double ndf = fitfunction->GetNDF();
230  double chi2overndf = chi2 / ndf;
231  // in case things went wrong, try to refit in smaller range
232  if(adcs< 2. || (error/adcs)>1.8 ){
233  inputHisto->Fit(fitfunction.get(),"0Q",nullptr,0.,400.);
234  std::cout<<"refitting landau for histogram "<<inputHisto->GetTitle()<<std::endl;
235  std::cout<<"initial error/adcs ="<<error<<" / "<<adcs<<std::endl;
236  std::cout<<"new error/adcs ="<<fitfunction->GetParError(1)<<" / "<<fitfunction->GetParameter("MPV")<<std::endl;
237  adcs = fitfunction->GetParameter("MPV");
238  error = fitfunction->GetParError(1); // MPV is parameter 1 (0=constant, 1=MPV, 2=Sigma)
239  chi2 = fitfunction->GetChisquare();
240  ndf = fitfunction->GetNDF();
241  chi2overndf = chi2 / ndf;
242  }
243  // if still wrong, give up
244  if(adcs<2. || chi2overndf>MaxChi2OverNDF){
245  adcs = -0.5; error = 0.;
246  }
247  return std::make_pair(adcs,error);
248 }
double SiStripGainCosmicCalculator::moduleThickness ( const uint32_t  detid,
const edm::EventSetup iSetup 
)
private

Definition at line 265 of file SiStripGainCosmicCalculator.cc.

References Surface::bounds(), gather_cfg::cout, edm::EventSetup::get(), TrackerGeometry::idToDetUnit(), GeomDet::surface(), and Bounds::thickness().

Referenced by algoAnalyze(), and getNewObject().

266 { //dk: copied from A. Giammanco and hacked
267  edm::ESHandle<TrackerGeometry> tkGeom; iSetup->get<TrackerDigiGeometryRecord>().get( tkGeom );
268  double module_thickness=0.;
269  const GeomDetUnit* it = tkGeom->idToDetUnit(DetId(detid));
270  if (dynamic_cast<const StripGeomDetUnit*>(it)==nullptr && dynamic_cast<const PixelGeomDetUnit*>(it)==nullptr) {
271  std::cout << "this detID doesn't seem to belong to the Tracker" << std::endl;
272  }else{
273  module_thickness = it->surface().bounds().thickness();
274  }
275  return module_thickness;
276 }
const Bounds & bounds() const
Definition: Surface.h:120
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:42
const TrackerGeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
Definition: DetId.h:18
virtual float thickness() const =0
const T & get() const
Definition: EventSetup.h:59
double SiStripGainCosmicCalculator::moduleWidth ( const uint32_t  detid,
const edm::EventSetup iSetup 
)
private

Definition at line 251 of file SiStripGainCosmicCalculator.cc.

References Surface::bounds(), gather_cfg::cout, edm::EventSetup::get(), TrackerGeometry::idToDetUnit(), GeomDet::surface(), and Bounds::width().

Referenced by algoAnalyze(), and getNewObject().

252 { //dk: copied from A. Giammanco and hacked, module_width values : 10.49 12.03 6.144 7.14 9.3696
253  edm::ESHandle<TrackerGeometry> tkGeom; iSetup->get<TrackerDigiGeometryRecord>().get( tkGeom );
254  double module_width=0.;
255  const GeomDetUnit* it = tkGeom->idToDetUnit(DetId(detid));
256  if (dynamic_cast<const StripGeomDetUnit*>(it)==nullptr && dynamic_cast<const PixelGeomDetUnit*>(it)==nullptr) {
257  std::cout << "this detID doesn't seem to belong to the Tracker" << std::endl;
258  }else{
259  module_width = it->surface().bounds().width();
260  }
261  return module_width;
262 }
const Bounds & bounds() const
Definition: Surface.h:120
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:42
virtual float width() const =0
const TrackerGeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
Definition: DetId.h:18
const T & get() const
Definition: EventSetup.h:59

Member Data Documentation

std::vector<uint32_t> SiStripGainCosmicCalculator::detModulesToBeExcluded
private

Definition at line 48 of file SiStripGainCosmicCalculator.h.

Referenced by algoBeginJob(), and SiStripGainCosmicCalculator().

const edm::EventSetup* SiStripGainCosmicCalculator::eventSetupCopy_
private

Definition at line 49 of file SiStripGainCosmicCalculator.h.

Referenced by algoBeginJob(), and getNewObject().

double SiStripGainCosmicCalculator::ExpectedChargeDeposition
private

Definition at line 45 of file SiStripGainCosmicCalculator.h.

Referenced by SiStripGainCosmicCalculator().

TObjArray* SiStripGainCosmicCalculator::HlistAPVPairs
private

Definition at line 42 of file SiStripGainCosmicCalculator.h.

Referenced by algoAnalyze(), algoBeginJob(), and getNewObject().

TObjArray* SiStripGainCosmicCalculator::HlistOtherHistos
private

Definition at line 43 of file SiStripGainCosmicCalculator.h.

Referenced by algoAnalyze(), algoBeginJob(), and getNewObject().

double SiStripGainCosmicCalculator::MaxChi2OverNDF
private

Definition at line 51 of file SiStripGainCosmicCalculator.h.

Referenced by getPeakOfLandau(), and SiStripGainCosmicCalculator().

unsigned int SiStripGainCosmicCalculator::MinNrEntries
private

Definition at line 50 of file SiStripGainCosmicCalculator.h.

Referenced by getPeakOfLandau(), and SiStripGainCosmicCalculator().

TString SiStripGainCosmicCalculator::outputFileName
private
bool SiStripGainCosmicCalculator::outputHistogramsInRootFile
private

Definition at line 52 of file SiStripGainCosmicCalculator.h.

Referenced by getNewObject(), and SiStripGainCosmicCalculator().

bool SiStripGainCosmicCalculator::printdebug_
private

Definition at line 54 of file SiStripGainCosmicCalculator.h.

Referenced by SiStripGainCosmicCalculator().

std::vector<uint32_t> SiStripGainCosmicCalculator::SelectedDetIds
private

Definition at line 47 of file SiStripGainCosmicCalculator.h.

Referenced by algoBeginJob().

std::map<uint32_t, double> SiStripGainCosmicCalculator::thickness_map
private

Definition at line 46 of file SiStripGainCosmicCalculator.h.

Referenced by algoBeginJob().

uint32_t SiStripGainCosmicCalculator::total_nr_of_events
private

Definition at line 44 of file SiStripGainCosmicCalculator.h.

Referenced by algoAnalyze(), algoBeginJob(), and getNewObject().

std::string SiStripGainCosmicCalculator::TrackLabel
private

Definition at line 40 of file SiStripGainCosmicCalculator.h.

Referenced by algoAnalyze(), and SiStripGainCosmicCalculator().

std::string SiStripGainCosmicCalculator::TrackProducer
private

Definition at line 39 of file SiStripGainCosmicCalculator.h.

const TrackerTopology* SiStripGainCosmicCalculator::tTopo
private